예제 #1
0
    bailOut(App::$l10n->t('checksum is not set.'));
}
if (is_array($value)) {
    $value = array_map('strip_tags', $value);
    // NOTE: Important, otherwise the compound value will be
    // set in the order the fields appear in the form!
    ksort($value);
    //if($name == 'CATEGORIES') {
    //	$value = VCard::escapeDelimiters($value, ',');
    //} else {
    //	$value = VCard::escapeDelimiters($value, ';');
    //}
} else {
    $value = trim(strip_tags($value));
}
$vcard = App::getContactVCard($id);
if (!$vcard) {
    bailOut(App::$l10n->t('Couldn\'t find vCard for %d.', array($id)));
}
$property = null;
if (in_array($name, $multi_properties)) {
    if ($checksum !== 'new') {
        $line = App::getPropertyLineByChecksum($vcard, $checksum);
        if (is_null($line)) {
            bailOut(App::$l10n->t('Information about vCard is incorrect. Please reload the page: ') . $checksum);
        }
        $property = $vcard->children[$line];
        $element = $property->name;
        if ($element != $name) {
            bailOut(App::$l10n->t('Something went FUBAR. ') . $name . ' != ' . $element);
        }
 /**
  * @param $properties
  * @return mixed
  */
 public function createOrUpdate($properties)
 {
     $id = null;
     $vcard = null;
     if (array_key_exists('id', $properties)) {
         // TODO: test if $id belongs to this addressbook
         $id = $properties['id'];
         // TODO: Test $vcard
         $vcard = App::getContactVCard($properties['id']);
         foreach (array_keys($properties) as $name) {
             if (isset($vcard->{$name})) {
                 unset($vcard->{$name});
             }
         }
     } else {
         $vcard = \Sabre\VObject\Component::create('VCARD');
         $uid = substr(md5(rand() . time()), 0, 10);
         $vcard->add('UID', $uid);
         try {
             $id = VCard::add($this->id, $vcard, null, true);
         } catch (Exception $e) {
             \OCP\Util::writeLog('contacts', __METHOD__ . ' ' . $e->getMessage(), \OCP\Util::ERROR);
             return false;
         }
     }
     foreach ($properties as $name => $value) {
         switch ($name) {
             case 'ADR':
             case 'N':
                 if (is_array($value)) {
                     $property = \Sabre\VObject\Property::create($name);
                     $property->setParts($value);
                     $vcard->add($property);
                 } else {
                     $vcard->{$name} = $value;
                 }
                 break;
             case 'BDAY':
                 // TODO: try/catch
                 $date = new \DateTime($value);
                 $vcard->BDAY = $date->format('Y-m-d');
                 $vcard->BDAY->VALUE = 'DATE';
                 break;
             case 'EMAIL':
             case 'TEL':
             case 'IMPP':
                 // NOTE: We don't know if it's GTalk, Jabber etc. only the protocol
             // NOTE: We don't know if it's GTalk, Jabber etc. only the protocol
             case 'URL':
                 if (is_array($value)) {
                     foreach ($value as $val) {
                         $vcard->add($name, strip_tags($val));
                     }
                 } else {
                     $vcard->add($name, strip_tags($value));
                 }
             default:
                 $vcard->{$name} = $value;
                 break;
         }
     }
     try {
         VCard::edit($id, $vcard);
     } catch (Exception $e) {
         \OCP\Util::writeLog('contacts', __METHOD__ . ' ' . $e->getMessage(), \OCP\Util::ERROR);
         return false;
     }
     $asarray = VCard::structureContact($vcard);
     $asarray['id'] = $id;
     return $asarray;
 }