/** * Store feeds into the Contacts * @param array $feed */ public static function parseFeed($feed) { $userid = \OCP\User::getUser(); foreach ($feed as $source) { $entry = Adapter::translateContact($source); if (isset($entry[self::CONTACT_GID]) && !empty($entry[self::CONTACT_GID])) { $oldContactId = self::findByGid($userid, $entry[self::CONTACT_GID]); if ($oldContactId) { //If exists and should not be updated - skip if (self::needUpdate($oldContactId)) { $vcard = self::toVcard($entry); \OCA\Contacts\VCard::edit($oldContactId, $vcard); } continue; } } $vcard = self::toVcard($entry); $bookid = self::getBookId($userid); \OCA\Contacts\VCard::add($bookid, $vcard); } \OCA\Contacts\App::getCategories(); }
} break; case 'EMAIL': case 'TEL': case 'IMPP': case 'URL': debug('Setting element: (EMAIL/TEL/ADR)' . $element); $property->setValue($value); break; default: $vcard->{$name} = $value; break; } setParameters($property, $parameters, true); // Do checksum and be happy if (in_array($name, $multi_properties)) { $checksum = substr(md5($property->serialize()), 0, 8); } } //debug('New checksum: '.$checksum); //$vcard->children[$line] = $property; ??? try { VCard::edit($id, $vcard); } catch (Exception $e) { bailOut($e->getMessage()); } if (in_array($name, $multi_properties)) { \OCP\JSON::success(array('data' => array('line' => $line, 'checksum' => $checksum, 'oldchecksum' => $_POST['checksum'], 'lastmodified' => App::lastModified($vcard)->format('U')))); } else { \OCP\JSON::success(array('data' => array('lastmodified' => App::lastModified($vcard)->format('U')))); }
/** * @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; }