summaryrefslogtreecommitdiffstats
path: root/apps/contacts/lib/vcard.php
diff options
context:
space:
mode:
authorThomas Tanghus <thomas@tanghus.net>2012-03-07 23:38:44 +0100
committerThomas Tanghus <thomas@tanghus.net>2012-03-07 23:38:44 +0100
commitae7aab2d6e727f9daf683056001a982aad242c93 (patch)
tree9dc0ade66c54dc846f4591587393aacd11be8622 /apps/contacts/lib/vcard.php
parent91d85e9b1640e9d62707cd1c232c8c7a9fc8b9c3 (diff)
parentd8cfe77ba5348d29a9e2b046e2c7efc1dd4758cb (diff)
downloadnextcloud-server-ae7aab2d6e727f9daf683056001a982aad242c93.tar.gz
nextcloud-server-ae7aab2d6e727f9daf683056001a982aad242c93.zip
Merge gitorious.org:owncloud/owncloud into vcategories
Conflicts: apps/contacts/ajax/saveproperty.php apps/contacts/lib/vcard.php
Diffstat (limited to 'apps/contacts/lib/vcard.php')
-rw-r--r--apps/contacts/lib/vcard.php120
1 files changed, 41 insertions, 79 deletions
diff --git a/apps/contacts/lib/vcard.php b/apps/contacts/lib/vcard.php
index 3c95dd19abf..50370370898 100644
--- a/apps/contacts/lib/vcard.php
+++ b/apps/contacts/lib/vcard.php
@@ -175,6 +175,9 @@ class OC_Contacts_VCard{
if($property->name == 'UID'){
$uid = $property->value;
}
+ if($property->name == 'ORG'){
+ $org = $property->value;
+ }
if($property->name == 'EMAIL' && is_null($email)){ // only use the first email as substitute for missing N or FN.
$email = $property->value;
}
@@ -185,6 +188,8 @@ class OC_Contacts_VCard{
$fn = join(' ', array_reverse(array_slice(explode(';', $n), 0, 2)));
} elseif($email) {
$fn = $email;
+ } elseif($org) {
+ $fn = $org;
} else {
$fn = 'Unknown Name';
}
@@ -218,32 +223,37 @@ class OC_Contacts_VCard{
/**
* @brief Adds a card
- * @param integer $id Addressbook id
- * @param string $data vCard file
- * @return insertid on success or null if card is not parseable.
+ * @param integer $aid Addressbook id
+ * @param OC_VObject $card vCard file
+ * @param string $uri the uri of the card, default based on the UID
+ * @return insertid on success or null if no card.
*/
- public static function add($id,$data){
- $fn = null;
-
- $card = OC_VObject::parse($data);
- if(!is_null($card)){
- OC_Contacts_App::$categories->loadFromVObject($card);
- self::updateValuesFromAdd($card);
- $data = $card->serialize();
- }
- else{
- OC_Log::write('contacts','OC_Contacts_VCard::add. Error parsing VCard: '.$data,OC_Log::ERROR);
- return null; // Ditch cards that can't be parsed by Sabre.
+ public static function add($aid, $card, $uri=null){
+ if(is_null($card)){
+ OC_Log::write('contacts','OC_Contacts_VCard::add. No vCard supplied', OC_Log::ERROR);
+ return null;
};
+ OC_Contacts_App::$categories->loadFromVObject($card);
+
+ self::updateValuesFromAdd($card);
+
$fn = $card->getAsString('FN');
- $uid = $card->getAsString('UID');
- $uri = $uid.'.vcf';
+ if (empty($fn)) {
+ $fn = null;
+ }
+
+ if (!$uri) {
+ $uid = $card->getAsString('UID');
+ $uri = $uid.'.vcf';
+ }
+
+ $data = $card->serialize();
$stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*contacts_cards (addressbookid,fullname,carddata,uri,lastmodified) VALUES(?,?,?,?,?)' );
- $result = $stmt->execute(array($id,$fn,$data,$uri,time()));
+ $result = $stmt->execute(array($aid,$fn,$data,$uri,time()));
$newid = OC_DB::insertid('*PREFIX*contacts_cards');
- OC_Contacts_Addressbook::touch($id);
+ OC_Contacts_Addressbook::touch($aid);
return $newid;
}
@@ -257,23 +267,7 @@ class OC_Contacts_VCard{
*/
public static function addFromDAVData($id,$uri,$data){
$card = OC_VObject::parse($data);
- if(!is_null($card)){
- OC_Contacts_App::$categories->loadFromVObject($card);
- self::updateValuesFromAdd($card);
- $data = $card->serialize();
- } else {
- OC_Log::write('contacts','OC_Contacts_VCard::addFromDAVData. Error parsing VCard: '.$data, OC_Log::ERROR);
- return null; // Ditch cards that can't be parsed by Sabre.
- };
- $fn = $card->getAsString('FN');
-
- $stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*contacts_cards (addressbookid,fullname,carddata,uri,lastmodified) VALUES(?,?,?,?,?)' );
- $result = $stmt->execute(array($id,$fn,$data,$uri,time()));
- $newid = OC_DB::insertid('*PREFIX*contacts_cards');
-
- OC_Contacts_Addressbook::touch($id);
-
- return $newid;
+ return self::add($id, $data, $uri);
}
/**
@@ -302,29 +296,25 @@ class OC_Contacts_VCard{
/**
* @brief edits a card
* @param integer $id id of card
- * @param string $data vCard file
+ * @param OC_VObject $card vCard file
* @return boolean
*/
- public static function edit($id, $data){
+ public static function edit($id, OC_VObject $card){
$oldcard = self::find($id);
- $fn = null;
- $card = OC_VObject::parse($data);
- if(!is_null($card)){
- OC_Contacts_App::$categories->loadFromVObject($card);
- foreach($card->children as $property){
- if($property->name == 'FN'){
- $fn = $property->value;
- break;
- }
- }
- } else {
+ if(is_null($card)) {
return false;
}
+
+ $fn = $card->getAsString('FN');
+ if (empty($fn)) {
+ $fn = null;
+ }
+
$now = new DateTime;
$card->setString('REV', $now->format(DateTime::W3C));
- $data = $card->serialize();
+ $data = $card->serialize();
$stmt = OC_DB::prepare( 'UPDATE *PREFIX*contacts_cards SET fullname = ?,carddata = ?, lastmodified = ? WHERE id = ?' );
$result = $stmt->execute(array($fn,$data,time(),$id));
@@ -342,28 +332,8 @@ class OC_Contacts_VCard{
*/
public static function editFromDAVData($aid,$uri,$data){
$oldcard = self::findWhereDAVDataIs($aid,$uri);
-
- $fn = null;
$card = OC_VObject::parse($data);
- if(!is_null($card)){
- OC_Contacts_App::$categories->loadFromVObject($card);
- foreach($card->children as $property){
- if($property->name == 'FN'){
- $fn = $property->value;
- break;
- }
- }
- }
- $now = new DateTime;
- $card->setString('REV', $now->format(DateTime::W3C));
- $data = $card->serialize();
-
- $stmt = OC_DB::prepare( 'UPDATE *PREFIX*contacts_cards SET fullname = ?,carddata = ?, lastmodified = ? WHERE id = ?' );
- $result = $stmt->execute(array($fn,$data,time(),$oldcard['id']));
-
- OC_Contacts_Addressbook::touch($oldcard['addressbookid']);
-
- return true;
+ return self::edit($oldcard['id'], $card);
}
/**
@@ -380,14 +350,6 @@ class OC_Contacts_VCard{
}
/**
- * @brief Creates a UID
- * @return string
- */
- public static function createUID(){
- return substr(md5(rand().time()),0,10);
- }
-
- /**
* @brief deletes a card with the data provided by sabredav
* @param integer $aid Addressbook id
* @param string $uri the uri of the card