Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'apps/contacts/lib/vcard.php')
-rw-r--r--apps/contacts/lib/vcard.php123
1 files changed, 31 insertions, 92 deletions
diff --git a/apps/contacts/lib/vcard.php b/apps/contacts/lib/vcard.php
index 74bc0f92f1b..a573f40f7d9 100644
--- a/apps/contacts/lib/vcard.php
+++ b/apps/contacts/lib/vcard.php
@@ -91,24 +91,24 @@ class OC_Contacts_VCard{
*/
public static function add($id,$data){
$fn = null;
- $uri = null;
- $card = self::parse($data);
+ $card = OC_VObject::parse($data);
if(!is_null($card)){
- foreach($card->children as $property){
- if($property->name == 'FN'){
- $fn = $property->value;
- }
- elseif(is_null($uri) && $property->name == 'UID' ){
- $uri = $property->value.'.vcf';
- }
- }
- if(is_null($uri)){
- $uid = self::createUID();
- $uri = $uid.'.vcf';
- $card->add(new Sabre_VObject_Property('UID',$uid));
+ $fn = $card->getAsString('FN');
+ $uid = $card->getAsString('UID');
+ if(is_null($uid)){
+ $card->setUID();
+ $uid = $card->getAsString('UID');
$data = $card->serialize();
};
+ $uri = $uid.'.vcf';
+ // VCARD must have a version
+ $version = $card->getAsString('VERSION');
+ // Add version if needed
+ if(is_null($version)){
+ $card->add(new Sabre_VObject_Property('VERSION','3.0'));
+ $data = $card->serialize();
+ }
}
else{
// that's hard. Creating a UID and not saving it
@@ -121,7 +121,7 @@ class OC_Contacts_VCard{
OC_Contacts_Addressbook::touch($id);
- return OC_DB::insertid();
+ return OC_DB::insertid('*PREFIX*contacts_cards');
}
/**
@@ -133,7 +133,7 @@ class OC_Contacts_VCard{
*/
public static function addFromDAVData($id,$uri,$data){
$fn = null;
- $card = self::parse($data);
+ $card = OC_VObject::parse($data);
if(!is_null($card)){
foreach($card->children as $property){
if($property->name == 'FN'){
@@ -147,7 +147,7 @@ class OC_Contacts_VCard{
OC_Contacts_Addressbook::touch($id);
- return OC_DB::insertid();
+ return OC_DB::insertid('*PREFIX*contacts_cards');
}
/**
@@ -160,7 +160,7 @@ class OC_Contacts_VCard{
$oldcard = self::find($id);
$fn = null;
- $card = self::parse($data);
+ $card = OC_VObject::parse($data);
if(!is_null($card)){
foreach($card->children as $property){
if($property->name == 'FN'){
@@ -188,7 +188,7 @@ class OC_Contacts_VCard{
$oldcard = self::findWhereDAVDataIs($aid,$uri);
$fn = null;
- $card = self::parse($data);
+ $card = OC_VObject::parse($data);
if(!is_null($card)){
foreach($card->children as $property){
if($property->name == 'FN'){
@@ -239,61 +239,6 @@ class OC_Contacts_VCard{
}
/**
- * @brief Escapes semicolons
- * @param string $value
- * @return string
- */
- public static function escapeSemicolons($value){
- foreach($value as &$i ){
- $i = implode("\\\\;", explode(';', $i));
- }
- return implode(';',$value);
- }
-
- /**
- * @brief Creates an array out of a multivalue property
- * @param string $value
- * @return array
- */
- 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;
- }
-
- /**
- * @brief Add property to vcard object
- * @param object $vcard
- * @param object $name of property
- * @param object $value of property
- * @param object $paramerters of property
- */
- public static function addVCardProperty($vcard, $name, $value, $parameters=array()){
- if(is_array($value)){
- $value = OC_Contacts_VCard::escapeSemicolons($value);
- }
- $property = new Sabre_VObject_Property( $name, $value );
- $parameternames = array_keys($parameters);
- foreach($parameternames as $i){
- $property->parameters[] = new Sabre_VObject_Parameter($i,$parameters[$i]);
- }
-
- $vcard->add($property);
- return $property;
- }
-
- /**
* @brief Data structure of vCard
* @param object $property
* @return associative array
@@ -329,7 +274,7 @@ class OC_Contacts_VCard{
$value = $property->value;
$value = htmlspecialchars($value);
if($property->name == 'ADR' || $property->name == 'N'){
- $value = self::unescapeSemicolons($value);
+ $value = OC_VObject::unescapeSemicolons($value);
}
$temp = array(
'name' => $property->name,
@@ -342,24 +287,18 @@ class OC_Contacts_VCard{
$parameter->name = 'PREF';
$parameter->value = '1';
}
- $temp['parameters'][$parameter->name] = $parameter->value;
+ if ($property->name == 'TEL' && $parameter->name == 'TYPE'){
+ if (isset($temp['parameters'][$parameter->name])){
+ $temp['parameters'][$parameter->name][] = $parameter->value;
+ }
+ else{
+ $temp['parameters'][$parameter->name] = array($parameter->value);
+ }
+ }
+ else{
+ $temp['parameters'][$parameter->name] = $parameter->value;
+ }
}
return $temp;
}
-
- /**
- * @brief Parses a vcard file
- * @param string vCard
- * @return Sabre_VObject or null
- *
- * Will retun the vobject if sabre DAV is able to parse the file.
- */
- public static function parse($data){
- try {
- $card = Sabre_VObject_Reader::read($data);
- return $card;
- } catch (Exception $e) {
- return null;
- }
- }
}