summaryrefslogtreecommitdiffstats
path: root/apps/contacts/lib
diff options
context:
space:
mode:
Diffstat (limited to 'apps/contacts/lib')
-rw-r--r--apps/contacts/lib/addressbook.php71
-rw-r--r--apps/contacts/lib/connector_sabre.php26
2 files changed, 72 insertions, 25 deletions
diff --git a/apps/contacts/lib/addressbook.php b/apps/contacts/lib/addressbook.php
index c0f26c7df55..b7444653907 100644
--- a/apps/contacts/lib/addressbook.php
+++ b/apps/contacts/lib/addressbook.php
@@ -167,14 +167,14 @@ class OC_Contacts_Addressbook{
$uri = $property->value.'.vcf';
}
}
- $uri = self::createUID().'.vcf';
+ if(is_null($uri)) $uri = self::createUID().'.vcf';
$stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*contacts_cards (addressbookid,fullname,carddata,uri,lastmodified) VALUES(?,?,?,?,?)' );
$result = $stmt->execute(array($id,$fn,$data,$uri,time()));
- self::touch($id);
+ self::touchAddressbook($id);
- return OC_DB::insertid;
+ return OC_DB::insertid();
}
public static function addCardFromDAVData($id,$uri,$data){
@@ -189,13 +189,13 @@ class OC_Contacts_Addressbook{
$stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*contacts_cards (addressbookid,fullname,carddata,uri,lastmodified) VALUES(?,?,?,?,?)' );
$result = $stmt->execute(array($id,$fn,$data,$uri,time()));
- self::touch($id);
+ self::touchAddressbook($id);
- return OC_DB::insertid;
+ return OC_DB::insertid();
}
public static function editCard($id, $data){
- $oldcard = self::findCard($id,$aid,$uri);
+ $oldcard = self::findCard($id);
$fn = null;
$card = Sabre_VObject_Reader::read($data);
foreach($card->children as $property){
@@ -207,7 +207,7 @@ class OC_Contacts_Addressbook{
$stmt = OC_DB::prepare( 'UPDATE *PREFIX*contacts_cards SET fullname = ?,carddata = ?, lastmodified = ? WHERE id = ?' );
$result = $stmt->execute(array($fn,$data,time(),$id));
- self::touch($oldcard['addressbookid']);
+ self::touchAddressbook($oldcard['addressbookid']);
return true;
}
@@ -226,20 +226,20 @@ class OC_Contacts_Addressbook{
$stmt = OC_DB::prepare( 'UPDATE *PREFIX*contacts_cards SET fullname = ?,carddata = ?, lastmodified = ? WHERE id = ?' );
$result = $stmt->execute(array($fn,$data,time(),$oldcard['id']));
- self::touch($oldcard['addressbookid']);
+ self::touchAddressbook($oldcard['addressbookid']);
return true;
}
public static function deleteCard($id){
- $stmt = OC_DB::prepare( 'DELETE FROM *PREFIX*contacts_addressbooks WHERE id = ?' );
+ $stmt = OC_DB::prepare( 'DELETE FROM *PREFIX*contacts_cards WHERE id = ?' );
$stmt->execute(array($id));
return true;
}
public static function deleteCardFromDAVData($aid,$uri){
- $stmt = OC_DB::prepare( 'DELETE FROM *PREFIX*contacts_addressbooks WHERE addressbookid = ? AND uri=?' );
+ $stmt = OC_DB::prepare( 'DELETE FROM *PREFIX*contacts_cards WHERE addressbookid = ? AND uri=?' );
$stmt->execute(array($aid,$uri));
return true;
@@ -265,23 +265,60 @@ class OC_Contacts_Addressbook{
return $userid;
}
+ public static function escapeSemicolons($value){
+ foreach($value as &$i ){
+ $i = implode("\\\\;", explode(';', $i));
+ } unset($i);
+ return implode(';',$value);
+ }
+
+ public static function unescapeSemicolons($value){
+ $array = explode(';',$value);
+ for($i=0;$i<count($array);$i++){
+ if(substr($array[$i],-2,2)=="\\\\"){
+ if(isset($array[$i+1])){
+ $array[$i] = substr($array[$i],0,count($array[$i])-2).';'.$array[$i+1];
+ unset($array[$i+1]);
+ }
+ else{
+ $array[$i] = substr($array[$i],0,count($array[$i])-2).';';
+ }
+ $i = $i - 1;
+ }
+ }
+ return $array;
+ }
+
public static function structureContact($object){
$details = array();
+ $line = 0;
foreach($object->children as $property){
- $temp = array(
- 'name' => $property->name,
- 'value' => ($property->name == 'PHOTO' || $property->name == 'LOGO' ? null : $property->value ),
- 'parameters' => array());
- foreach($property->parameters as $parameter){
- $temp['parameters'][] = array( 'name' => $parameter->name, 'value' => $parameter->value);
- }
+ $temp = self::structureProperty($property,$line);
if(array_key_exists($property->name,$details)){
$details[$property->name][] = $temp;
}
else{
$details[$property->name] = array($temp);
}
+ $line++;
}
return $details;
}
+
+ public static function structureProperty($property,$line=null){
+ $value = $property->value;
+ if($property->name == 'ADR'){
+ $value = self::unescapeSemicolons($value);
+ }
+ $temp = array(
+ 'name' => $property->name,
+ 'value' => $value,
+ 'line' => $line,
+ 'parameters' => array(),
+ 'checksum' => md5($property->serialize()));
+ foreach($property->parameters as $parameter){
+ $temp['parameters'][$parameter->name] = $parameter->value;
+ }
+ return $temp;
+ }
}
diff --git a/apps/contacts/lib/connector_sabre.php b/apps/contacts/lib/connector_sabre.php
index 98e2598b3a7..96a90dfc5de 100644
--- a/apps/contacts/lib/connector_sabre.php
+++ b/apps/contacts/lib/connector_sabre.php
@@ -1,13 +1,23 @@
<?php
-
/**
- * PDO CardDAV backend
- *
- * @package Sabre
- * @subpackage CardDAV
- * @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
- * @author Evert Pot (http://www.rooftopsolutions.nl/)
- * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
+ * ownCloud - Addressbook
+ *
+ * @author Jakob Sack
+ * @copyright 2011 Jakob Sack mail@jakobsack.de
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
*/
/**