* description TEXT,
* ctag INT(11) UNSIGNED NOT NULL DEFAULT '1'
* );
- *
+ *
* CREATE TABLE contacts_cards (
* id INT(11) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
* addressbookid INT(11) UNSIGNED NOT NULL,
public static function allAddressbooks($uid){
$stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE userid = ?' );
$result = $stmt->execute(array($uid));
-
+
$addressbooks = array();
while( $row = $result->fetchRow()){
$addressbooks[] = $row;
return $addressbooks;
}
-
+
/**
* @brief Returns the list of addressbooks for a principal (DAV term of user)
* @param string $principaluri
*/
public static function addAddressbookFromDAVData($principaluri,$uri,$name,$description){
$userid = self::extractUserID($principaluri);
-
+
$stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*contacts_addressbooks (userid,displayname,uri,description,ctag) VALUES(?,?,?,?,?)' );
$result = $stmt->execute(array($userid,$name,$uri,$description,1));
if(is_null($description)){
$description = $addressbook['description'];
}
-
+
$stmt = OC_DB::prepare( 'UPDATE *PREFIX*contacts_addressbooks SET displayname=?,description=?, ctag=ctag+1 WHERE id=?' );
$result = $stmt->execute(array($name,$description,$id));
public static function deleteAddressbook($id){
$stmt = OC_DB::prepare( 'DELETE FROM *PREFIX*contacts_addressbooks WHERE id = ?' );
$stmt->execute(array($id));
-
+
$stmt = OC_DB::prepare( 'DELETE FROM *PREFIX*contacts_cards WHERE addressbookid = ?' );
$stmt->execute(array($id));
return $addressbooks;
}
-
+
/**
* @brief Returns a card
* @param integer $id
public static function addCard($id,$data){
$fn = null;
$uri = null;
- if(self::isValidVObject($data)){
- $card = Sabre_VObject_Reader::read($data);
+
+ $card = self::parse($data);
+ if(!is_null($card)){
foreach($card->children as $property){
if($property->name == 'FN'){
$fn = $property->value;
*/
public static function addCardFromDAVData($id,$uri,$data){
$fn = null;
- if(self::isValidVObject($data)){
- $card = Sabre_VObject_Reader::read($data);
+ $card = self::parse($data);
+ if(!is_null($card)){
foreach($card->children as $property){
if($property->name == 'FN'){
$fn = $property->value;
public static function editCard($id, $data){
$oldcard = self::findCard($id);
$fn = null;
- if(self::isValidVObject($data)){
- $card = Sabre_VObject_Reader::read($data);
+
+ $card = self::parse($data);
+ if(!is_null($card)){
foreach($card->children as $property){
if($property->name == 'FN'){
$fn = $property->value;
$oldcard = self::findCardWhereDAVDataIs($aid,$uri);
$fn = null;
- if(self::isValidVObject($data)){
+ $card = self::parse($data);
+ if(!is_null($card)){
$card = Sabre_VObject_Reader::read($data);
foreach($card->children as $property){
if($property->name == 'FN'){
return true;
}
-
+
/**
* @brief deletes a card
* @param integer $id id of card
return true;
}
-
+
/**
* @brief Creates a URI for Addressbook
* @param string $name name of the addressbook
public static function createUID(){
return substr(md5(rand().time()),0,10);
}
-
+
/**
* @brief gets the userid from a principal path
* @return string
}
return $details;
}
-
+
/**
* @brief Data structure of properties
* @param object $property
* @return associative array
*
- * returns an associative array with
+ * returns an associative array with
* ['name'] name of property
* ['value'] htmlspecialchars escaped value of property
* ['parameters'] associative array name=>value
}
/**
- * @brief Checks if SabreDAV can parse the file
+ * @brief Parses a vcard file
* @param string vCard
- * @return boolean
+ * @return Sabre_VObject or null
*
- * The code is largely copypasted from Sabre_VObject_Reader
+ * Will retun the vobject if sabre DAV is able to parse the file.
*/
- public static function isValidVObject($data){
+ public static function parse($data){
try {
- Sabre_VObject_Reader::read($data);
- return true;
+ $card = Sabre_VObject_Reader::read($data);
+ return $card;
} catch (Exception $e) {
- return false;
+ return null;
}
}
}