/** * @brief Gets the VCard as an OC_VObject * @returns The card or null if the card could not be parsed. */ public static function getContactVCard($id) { $card = self::getContactObject($id); $vcard = OC_VObject::parse($card['carddata']); // Try to fix cards with missing 'N' field from pre ownCloud 4. Hot damn, this is ugly... if (!is_null($vcard) && !$vcard->__isset('N')) { $version = OCP\App::getAppVersion('contacts'); if ($version >= 5) { OCP\Util::writeLog('contacts', 'OC_Contacts_App::getContactVCard. Deprecated check for missing N field', OCP\Util::DEBUG); } OCP\Util::writeLog('contacts', 'getContactVCard, Missing N field', OCP\Util::DEBUG); if ($vcard->__isset('FN')) { OCP\Util::writeLog('contacts', 'getContactVCard, found FN field: ' . $vcard->__get('FN'), OCP\Util::DEBUG); $n = implode(';', array_reverse(array_slice(explode(' ', $vcard->__get('FN')), 0, 2))) . ';;;'; $vcard->setString('N', $n); OC_Contacts_VCard::edit($id, $vcard); } else { // Else just add an empty 'N' field :-P $vcard->setString('N', 'Unknown;Name;;;'); } } if (!is_null($vcard) && !isset($vcard->REV)) { $rev = new DateTime('@' . $card['lastmodified']); $vcard->setString('REV', $rev->format(DateTime::W3C)); } return $vcard; }
debug('Setting string:' . $name . ' ' . $value); $vcard->children[$line]->setValue($value); break; case 'EMAIL': case 'TEL': case 'ADR': // should I delete the property if empty or throw an error? debug('Setting element: (EMAIL/TEL/ADR)' . $element); $vcard->children[$line]->setValue($value); $vcard->children[$line]->parameters = array(); if (!is_null($parameters)) { debug('Setting parameters: ' . $parameters); foreach ($parameters as $key => $parameter) { debug('Adding parameter: ' . $key); foreach ($parameter as $val) { debug('Adding parameter: ' . $key . '=>' . $val); $vcard->children[$line]->add(new Sabre_VObject_Parameter($key, strtoupper(strip_tags($val)))); } } } break; } // Do checksum and be happy $checksum = md5($vcard->children[$line]->serialize()); } //debug('New checksum: '.$checksum); if (!OC_Contacts_VCard::edit($id, $vcard)) { bailOut(OC_Contacts_App::$l10n->t('Error updating contact property.')); exit; } OCP\JSON::success(array('data' => array('line' => $line, 'checksum' => $checksum, 'oldchecksum' => $_POST['checksum'])));
OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('contacts'); $card = OC_Contacts_VCard::find($id); if ($card === false) { OC_JSON::error(array('data' => array('message' => $l10n->t('Contact could not be found.')))); exit; } $addressbook = OC_Contacts_Addressbook::find($card['addressbookid']); if ($addressbook === false || $addressbook['userid'] != OC_USER::getUser()) { OC_JSON::error(array('data' => array('message' => $l10n->t('This is not your contact.')))); exit; } $vcard = OC_Contacts_VCard::parse($card['carddata']); // Check if the card is valid if (is_null($vcard)) { OC_JSON::error(array('data' => array('message' => $l10n->t('vCard could not be read.')))); exit; } $line = null; for ($i = 0; $i < count($vcard->children); $i++) { if (md5($vcard->children[$i]->serialize()) == $checksum) { $line = $i; } } if (is_null($line)) { OC_JSON::error(array('data' => array('message' => $l10n->t('Information about vCard is incorrect. Please reload the page.')))); exit; } unset($vcard->children[$line]); OC_Contacts_VCard::edit($id, $vcard->serialize()); OC_JSON::success(array('data' => array('id' => $id)));