summaryrefslogtreecommitdiffstats
path: root/apps/contacts
diff options
context:
space:
mode:
Diffstat (limited to 'apps/contacts')
-rw-r--r--apps/contacts/ajax/addcard.php2
-rw-r--r--apps/contacts/ajax/addcontact.php2
-rw-r--r--apps/contacts/ajax/addproperty.php2
-rw-r--r--apps/contacts/ajax/deleteproperty.php2
-rw-r--r--apps/contacts/ajax/savecrop.php2
-rw-r--r--apps/contacts/ajax/saveproperty.php2
-rw-r--r--apps/contacts/ajax/setproperty.php2
-rw-r--r--apps/contacts/import.php14
-rw-r--r--apps/contacts/lib/app.php2
-rw-r--r--apps/contacts/lib/vcard.php109
10 files changed, 51 insertions, 88 deletions
diff --git a/apps/contacts/ajax/addcard.php b/apps/contacts/ajax/addcard.php
index b1dc69a4691..49a4a16170b 100644
--- a/apps/contacts/ajax/addcard.php
+++ b/apps/contacts/ajax/addcard.php
@@ -92,7 +92,7 @@ foreach( $add as $propname){
}
}
}
-$id = OC_Contacts_VCard::add($aid,$vcard->serialize());
+$id = OC_Contacts_VCard::add($aid,$vcard);
if(!$id) {
OC_JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('There was an error adding the contact.'))));
OC_Log::write('contacts','ajax/addcard.php: Recieved non-positive ID on adding card: '.$id, OC_Log::ERROR);
diff --git a/apps/contacts/ajax/addcontact.php b/apps/contacts/ajax/addcontact.php
index 5d17631caa4..839a3919981 100644
--- a/apps/contacts/ajax/addcontact.php
+++ b/apps/contacts/ajax/addcontact.php
@@ -52,7 +52,7 @@ $vcard->setUID();
$vcard->setString('FN',$fn);
$vcard->setString('N',$n);
-$id = OC_Contacts_VCard::add($aid,$vcard->serialize());
+$id = OC_Contacts_VCard::add($aid,$vcard);
if(!$id) {
OC_JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('There was an error adding the contact.'))));
OC_Log::write('contacts','ajax/addcontact.php: Recieved non-positive ID on adding card: '.$id, OC_Log::ERROR);
diff --git a/apps/contacts/ajax/addproperty.php b/apps/contacts/ajax/addproperty.php
index 028974e1c66..b6b5dc7c416 100644
--- a/apps/contacts/ajax/addproperty.php
+++ b/apps/contacts/ajax/addproperty.php
@@ -113,7 +113,7 @@ foreach ($parameters as $key=>$element) {
}
$checksum = md5($vcard->children[$line]->serialize());
-if(!OC_Contacts_VCard::edit($id,$vcard->serialize())) {
+if(!OC_Contacts_VCard::edit($id,$vcard)) {
OC_JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Error adding contact property.'))));
OC_Log::write('contacts','ajax/addproperty.php: Error updating contact property: '.$name, OC_Log::ERROR);
exit();
diff --git a/apps/contacts/ajax/deleteproperty.php b/apps/contacts/ajax/deleteproperty.php
index a9afffaad4c..ab0958cac58 100644
--- a/apps/contacts/ajax/deleteproperty.php
+++ b/apps/contacts/ajax/deleteproperty.php
@@ -39,7 +39,7 @@ if(is_null($line)){
unset($vcard->children[$line]);
-if(!OC_Contacts_VCard::edit($id,$vcard->serialize())) {
+if(!OC_Contacts_VCard::edit($id,$vcard)) {
OC_JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Error deleting contact property.'))));
OC_Log::write('contacts','ajax/deleteproperty.php: Error deleting contact property', OC_Log::ERROR);
exit();
diff --git a/apps/contacts/ajax/savecrop.php b/apps/contacts/ajax/savecrop.php
index 1a84f6fdfae..ffbfaeb6e38 100644
--- a/apps/contacts/ajax/savecrop.php
+++ b/apps/contacts/ajax/savecrop.php
@@ -95,7 +95,7 @@ if(file_exists($tmp_path)) {
OC_Log::write('contacts','savecrop.php: files: Adding PHOTO property.', OC_Log::DEBUG);
$card->addProperty('PHOTO', $image->__toString(), array('ENCODING' => 'b', 'TYPE' => $image->mimeType()));
}
- if(!OC_Contacts_VCard::edit($id,$card->serialize())) {
+ if(!OC_Contacts_VCard::edit($id,$card)) {
bailOut('Error saving contact.');
}
unlink($tmpfname);
diff --git a/apps/contacts/ajax/saveproperty.php b/apps/contacts/ajax/saveproperty.php
index 6f8366243fe..db209fedfc7 100644
--- a/apps/contacts/ajax/saveproperty.php
+++ b/apps/contacts/ajax/saveproperty.php
@@ -122,7 +122,7 @@ switch($element) {
$checksum = md5($vcard->children[$line]->serialize());
debug('New checksum: '.$checksum);
-if(!OC_Contacts_VCard::edit($id,$vcard->serialize())) {
+if(!OC_Contacts_VCard::edit($id,$vcard)) {
OC_JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Error updating contact property.'))));
OC_Log::write('contacts','ajax/setproperty.php: Error updating contact property: '.$value, OC_Log::ERROR);
exit();
diff --git a/apps/contacts/ajax/setproperty.php b/apps/contacts/ajax/setproperty.php
index f9e2a8e8647..8e07b4a8f1c 100644
--- a/apps/contacts/ajax/setproperty.php
+++ b/apps/contacts/ajax/setproperty.php
@@ -80,7 +80,7 @@ foreach($missingparameters as $i){
// NOTE: This checksum is not used..?
$checksum = md5($vcard->children[$line]->serialize());
-if(!OC_Contacts_VCard::edit($id,$vcard->serialize())) {
+if(!OC_Contacts_VCard::edit($id,$vcard)) {
OC_JSON::error(array('data' => array('message' => $l->t('Error updating contact property.'))));
OC_Log::write('contacts','ajax/setproperty.php: Error updating contact property: '.$value, OC_Log::ERROR);
exit();
diff --git a/apps/contacts/import.php b/apps/contacts/import.php
index 4638bf0d73c..04cfc397d56 100644
--- a/apps/contacts/import.php
+++ b/apps/contacts/import.php
@@ -97,11 +97,15 @@ if(is_writable('import_tmp/')){
fclose($progressfopen);
}
if(count($parts) == 1){
- OC_Contacts_VCard::add($id, $file);
-}else{
- foreach($importready as $import){
- OC_Contacts_VCard::add($id, $import);
+ $importready = array($file);
+}
+foreach($importready as $import){
+ $card = OC_VObject::parse($import);
+ if (!$card) {
+ OC_Log::write('contacts','Import: skipping card. Error parsing VCard: '.$import, OC_Log::ERROR);
+ continue; // Ditch cards that can't be parsed by Sabre.
}
+ OC_Contacts_VCard::add($id, $card);
}
//done the import
if(is_writable('import_tmp/')){
@@ -113,4 +117,4 @@ sleep(3);
if(is_writable('import_tmp/')){
unlink($progressfile);
}
-OC_JSON::success(); \ No newline at end of file
+OC_JSON::success();
diff --git a/apps/contacts/lib/app.php b/apps/contacts/lib/app.php
index ce52df4b75e..e8c3087c8a2 100644
--- a/apps/contacts/lib/app.php
+++ b/apps/contacts/lib/app.php
@@ -92,7 +92,7 @@ class OC_Contacts_App {
OC_Log::write('contacts','getContactVCard, found FN field: '.$vcard->__get('FN'), OC_Log::DEBUG);
$n = implode(';', array_reverse(array_slice(explode(' ', $vcard->__get('FN')), 0, 2))).';;;';
$vcard->setString('N', $n);
- OC_Contacts_VCard::edit( $id, $vcard->serialize());
+ OC_Contacts_VCard::edit( $id, $vcard);
} else { // Else just add an empty 'N' field :-P
$vcard->setString('N', 'Unknown;Name;;;');
}
diff --git a/apps/contacts/lib/vcard.php b/apps/contacts/lib/vcard.php
index 0b8d95a2d97..9324f158cc7 100644
--- a/apps/contacts/lib/vcard.php
+++ b/apps/contacts/lib/vcard.php
@@ -217,31 +217,35 @@ 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)){
- 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;
};
+ 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;
}
@@ -255,49 +259,31 @@ class OC_Contacts_VCard{
*/
public static function addFromDAVData($id,$uri,$data){
$card = OC_VObject::parse($data);
- if(!is_null($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);
}
/**
* @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)){
- 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));
@@ -315,27 +301,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)){
- 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);
}
/**
@@ -352,14 +319,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