public function toString($userPasscode = null) { $userLevel = $this->getUserLevel($userPasscode); $vCard = new VCard('vcard.vcf'); $vCard->setLevel($userLevel); return $vCard->toHCard(); }
/** * @group default * @depends testQuestFNYes */ public function testQuestUndefinedYes() { $fragments = ['vcard' => '{{output,?x-undefined}}', 'output' => 'Output']; $template = new Template($fragments); $vcard = new vCard(); VCard::builder('x-undefined', false)->setValue('test')->pushTo($vcard); $output = $template->output($vcard); $this->assertEquals('Output', $output); }
/** * @dataProvider VCardTestSuite::validVCardProvider */ public function testReturnsWellFormedHtml($input) { if (!file_exists($input['filename'])) { $this->markTestSkipped('File: ' . $input['filename'] . "does not exist."); } $obj = new VCard($input['filename']); $obj->setLevel($input['level']); $this->assertFalse($this->getValidationError($obj->toHCard())); }
/** * @see Page::show() */ public function show() { parent::show(); $vCard = new VCard($this->user); header('Content-Type:text/x-vcard; charset=' . CHARSET); $filename = preg_match('/^[a-z0-9_]+$/i', $this->user->username) ? $this->user->username : $this->userID; header('Content-Disposition: attachment; filename="' . $filename . '.vcf"'); header('Content-Length: ' . strlen($vCard->getContent())); echo $vCard->getContent(); exit; }
function parse_vcards(&$lines) { $cards = array(); $card = new VCard(); while ($card->parse($lines)) { $property = $card->getProperty('N'); if (!$property) { return ""; } $n = $property->getComponents(); $tmp = array(); if ($n[3]) { $tmp[] = $n[3]; } // Mr. if ($n[1]) { $tmp[] = $n[1]; } // John if ($n[2]) { $tmp[] = $n[2]; } // Quinlan if ($n[4]) { $tmp[] = $n[4]; } // Esq. $ret = array(); if ($n[0]) { $ret[] = $n[0]; } $tmp = join(" ", $tmp); if ($tmp) { $ret[] = $tmp; } $key = join(", ", $ret); $cards[$key] = $card; // MDH: Create new VCard to prevent overwriting previous one (PHP5) $card = new VCard(); } ksort($cards); return $cards; }
public function formatItems($items, $format, $parameters = null) { $contacts = array(); if ($format == self::FORMAT_CONTACT) { foreach ($items as $item) { $contact = VCard::find($item['item_source']); $contact['fullname'] = $item['item_target']; $contacts[] = $contact; } } return $contacts; }
function search($query) { $addressbooks = Addressbook::all(\OCP\USER::getUser(), 1); if (count($addressbooks) == 0 || !\OCP\App::isEnabled('contacts')) { return array(); } $results = array(); $l = new \OC_l10n('contacts'); foreach ($addressbooks as $addressbook) { $vcards = VCard::all($addressbook['id']); foreach ($vcards as $vcard) { if (substr_count(strtolower($vcard['fullname']), strtolower($query)) > 0) { //$link = \OCP\Util::linkTo('contacts', 'index.php').'?id='.urlencode($vcard['id']); $link = 'javascript:openContact(' . $vcard['id'] . ')'; $results[] = new \OC_Search_Result($vcard['fullname'], '', $link, (string) $l->t('Contact')); //$name,$text,$link,$type } } } return $results; }
function search($query) { $unescape = function ($value) { return strtr($value, array('\\,' => ',', '\\;' => ';')); }; $searchresults = array(); $results = \OCP\Contacts::search($query, array('N', 'FN', 'EMAIL', 'NICKNAME', 'ORG')); $l = new \OC_l10n('contacts'); foreach ($results as $result) { $vcard = VCard::find($result['id']); $link = \OCP\Util::linkTo('contacts', 'index.php') . '#' . $vcard['id']; $props = array(); foreach (array('EMAIL', 'NICKNAME', 'ORG') as $searchvar) { if (isset($result[$searchvar]) && count($result[$searchvar]) > 0 && strlen($result[$searchvar][0]) > 3) { $props = array_merge($props, $result[$searchvar]); } } $props = array_map($unescape, $props); $searchresults[] = new \OC_Search_Result($vcard['fullname'], implode(', ', $props), $link, (string) $l->t('Contact')); //$name,$text,$link,$type } return $searchresults; }
private function isDuplicate($insertid) { $newobject = VCard::find($insertid); $stmt = \OCP\DB::prepare('SELECT COUNT(*) AS `COUNTING` FROM `' . App::ContactsTable . '` `CC` INNER JOIN `' . App::AddrBookTable . '` `CA` ON `CC`.`addressbookid`=`CA`.`id` WHERE `CC`.`fullname`= ? AND `CC`.`carddata`=? AND `CC`.`component`=? AND `CA`.`id` = ? AND `CA`.`userid` = ?'); $result = $stmt->execute(array($newobject['fullname'], $newobject['carddata'], 'VCARD', $this->id, $this->userid)); $result = $result->fetchRow(); if ($result['COUNTING'] >= 2) { return true; } return false; }
function handler_vcard($page, $photos = null) { global $globals; $vcard = new VCard($photos == 'photos', 'Membre du groupe ' . $globals->asso('nom')); $vcard->addProfiles($globals->asso()->getMembersFilter()->getProfiles(null, Profile::FETCH_ALL)); $vcard->show(); }
private function downloadVCard() { /* Bail out if we don't have a valid contact ID. */ if (!$this->isRequiredIDValid('contactID', $_GET)) { CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'Invalid contact ID.'); } $contactID = $_GET['contactID']; $contacts = new Contacts($this->_siteID); $contact = $contacts->get($contactID); $companies = new Companies($this->_siteID); $company = $companies->get($contact['companyID']); /* Bail out if we got an empty result set. */ if (empty($contact)) { CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'The specified contact ID could not be found.'); } /* Create a new vCard. */ $vCard = new VCard(); $vCard->setName($contact['lastName'], $contact['firstName']); if (!empty($contact['phoneWork'])) { $vCard->setPhoneNumber($contact['phoneWork'], 'PREF;WORK;VOICE'); } if (!empty($contact['phoneCell'])) { $vCard->setPhoneNumber($contact['phoneCell'], 'CELL;VOICE'); } /* FIXME: Add fax to contacts and use setPhoneNumber('WORK;FAX') here */ $addressLines = explode("\n", $contact['address']); $address1 = trim($addressLines[0]); if (isset($addressLines[1])) { $address2 = trim($addressLines[1]); } else { $address2 = ''; } $vCard->setAddress($address1, $address2, $contact['city'], $contact['state'], $contact['zip']); if (!empty($contact['email1'])) { $vCard->setEmail($contact['email1']); } if (!empty($company['url'])) { $vCard->setURL($company['url']); } $vCard->setTitle($contact['title']); $vCard->setOrganization($company['name']); if (!eval(Hooks::get('CONTACTS_GET_VCARD'))) { return; } $vCard->printVCardWithHeaders(); }
/** * @brief removes an address book * @param integer $id * @return boolean true on success, otherwise an exception will be thrown */ public static function delete($id) { $addressbook = self::find($id); if ($addressbook['userid'] != \OCP\User::getUser() && !\OC_Group::inGroup(OCP\User::getUser(), 'admin')) { $sharedAddressbook = \OCP\Share::getItemSharedWithBySource('addressbook', $id); if (!$sharedAddressbook || !($sharedAddressbook['permissions'] & \OCP\PERMISSION_DELETE)) { throw new Exception(App::$l10n->t('You do not have the permissions to delete this addressbook.')); } } // First delete cards belonging to this addressbook. $cards = VCard::all($id); foreach ($cards as $card) { try { VCard::delete($card['id']); } catch (Exception $e) { \OCP\Util::writeLog('contacts', __METHOD__ . ', exception deleting vCard ' . $card['id'] . ': ' . $e->getMessage(), \OCP\Util::ERROR); } } try { $stmt = \OCP\DB::prepare('DELETE FROM `*PREFIX*contacts_addressbooks` WHERE `id` = ?'); $stmt->execute(array($id)); } catch (\Exception $e) { \OCP\Util::writeLog('contacts', __METHOD__ . ', exception for ' . $id . ': ' . $e->getMessage(), \OCP\Util::ERROR); throw new Exception(App::$l10n->t('There was an error deleting this addressbook.')); } \OCP\Share::unshareAll('addressbook', $id); if (count(self::all(\OCP\User::getUser())) == 0) { self::addDefault(); } return true; }
$components = array(); $filter_fragment = SqlFilterCardDAV($qry_filters, $components); if ($filter_fragment !== false) { $where .= ' ' . $filter_fragment['sql']; $params = $filter_fragment['params']; } } else { dbg_error_log('cardquery', 'No query filters'); } $sql = 'SELECT * FROM caldav_data INNER JOIN addressbook_resource USING(dav_id)' . $where; if (isset($c->strict_result_ordering) && $c->strict_result_ordering) { $sql .= " ORDER BY dav_id"; } $qry = new AwlQuery($sql, $params); if ($qry->Exec("cardquery", __LINE__, __FILE__) && $qry->rows() > 0) { while ($address_object = $qry->Fetch()) { if (!$need_post_filter || apply_filter($qry_filters, $address_object)) { if ($bound_from != $target_collection->dav_name()) { $address_object->dav_name = str_replace($bound_from, $target_collection->dav_name(), $address_object->dav_name); } if (count($address_data_properties) > 0) { $vcard = new VCard($address_object->caldav_data); $vcard->MaskProperties($address_data_properties); $address_object->caldav_data = $vcard->Render(); } $responses[] = component_to_xml($properties, $address_object); } } } $multistatus = new XMLElement("multistatus", $responses, $reply->GetXmlNsArray()); $request->XMLResponse(207, $multistatus);
/** * get url from vcard * * @param VCard $_card * @param array $_data * @return array */ function _getUrl(VCard $_card, $_data) { $urlProperty = $_card->getProperty('URL') ? 'URL' : ($_card->getProperty('ITEM2.URL') ? 'ITEM2.URL' : ''); if (empty($urlProperty)) { return $_data; } $key = 'url'; if ($this->_options['urlIsHome']) { $key = 'url_home'; } $_data[$key] = $_card->getProperty($urlProperty)->value; $_data[$key] = preg_replace('/\\\\/', '', $_data[$key]); return $_data; }
/** * @brief removes an address book * @param integer $id * @return boolean true on success, otherwise an exception will be thrown */ public static function delete($id) { $addressbook = self::find($id); if ($addressbook['userid'] !== \OCP\User::getUser() && !\OC_Group::inGroup(\OCP\User::getUser(), 'admin')) { $sharedAddressbook = \OCP\Share::getItemSharedWithBySource(App::SHAREADDRESSBOOK, App::SHAREADDRESSBOOKPREFIX . $id); if (!$sharedAddressbook || !($sharedAddressbook['permissions'] & \OCP\PERMISSION_DELETE)) { throw new \Exception(App::$l10n->t('You do not have the permissions to delete this addressbook.')); } } // First delete cards belonging to this addressbook. $cards = VCard::all($id); foreach ($cards as $card) { try { VCard::delete($card['id']); } catch (\Exception $e) { \OCP\Util::writeLog(App::$appname, __METHOD__ . ', exception deleting vCard ' . $card['id'] . ': ' . $e->getMessage(), \OCP\Util::ERROR); } } try { $stmt = \OCP\DB::prepare('DELETE FROM `' . App::AddrBookTable . '` WHERE `id` = ?'); $stmt->execute(array($id)); } catch (\Exception $e) { \OCP\Util::writeLog(App::$appname, __METHOD__ . ', exception for ' . $id . ': ' . $e->getMessage(), \OCP\Util::ERROR); throw new \Exception(App::$l10n->t('There was an error deleting this addressbook.')); } \OCP\Share::unshareAll(App::SHAREADDRESSBOOK, App::SHAREADDRESSBOOKPREFIX . $id); \OCP\Util::emitHook('\\OCA\\ContactsPlus', 'deleteAddressbook', $id); return true; }
/** * @group default * @depends testImportVCardOneURL */ public function testImportVCardTwoURLs() { $url1 = "tweedldee"; $url2 = "tweedledum"; $input = self::$vcard_begin . "\r\n" . self::$vcard_version . "\r\n" . "URL:" . $url1 . "\r\n" . "URL:" . $url2 . "\r\n" . self::$vcard_end . "\r\n"; $vcards = $this->parser->importCards($input); $builder = VCard::builder('url'); $prop1 = $builder->setValue($url1)->build(); $prop2 = $builder->setValue($url2)->build(); $this->assertCount(1, $vcards); $this->assertCount(2, $vcards[0]->url); $this->assertEquals([$prop1, $prop2], $vcards[0]->url); }
protected function outputValue() { return VCard::escape($this->getValue()); }
/** * @brief transform a vcard into a ldap entry * @param VCard $vcard * @return array|false */ public function VCardToLdap($vcard) { $ldifReturn = array(); // Array to return foreach ($vcard->children() as $property) { // Basically, a $property can be converted into one or multiple ldif entries // and also some vcard properties can have data that can be split to fill different ldif entries $ldifArray = self::getLdifProperty($property); if (count($ldifArray) > 0) { self::updateLdifProperty($ldifReturn, $ldifArray); } } self::validateLdapEntry($ldifReturn); return $ldifReturn; }
function testVCardImportVCardWithoutUID() { $data = <<<EOT BEGIN:VCARD END:VCARD EOT; $tempFile = $this->createStream($data); $objects = new VCard($tempFile); $count = 0; while ($objects->getNext()) { $count++; } $this->assertEquals(1, $count); }
/** * @group default * @depends testSetAndBuild */ public function testOutputMediaType() { $builder = $this->specification->getBuilder(); $builder->setValue('http://example.com/logo.jpg')->setMediaType('image/png'); $property = $builder->build(); $this->assertEquals('LOGO;MEDIATYPE=image/png:' . VCard::escape('http://example.com/logo.jpg') . "\n", $property->output()); }
/** * If $vcard has a legacy AGENT property, convert it to a VCard 4.0 * RELATED property. * @param VCard $vcard The card to look for an AGENT in. * @return VCard|null If a new VCard was extracted and created, it is * returned, otherwise null. Even if there is an AGENT in the card, it * may be a text or uri value, in which case no new VCard is created. * @throws \DomainException If the AGENT is supposed to contain an * embedded card, but we cannot parse it. */ protected function handleAgent(VCard $vcard) { if (isset($vcard->agent)) { /* @var $agent Property */ $agent = $vcard->agent; /* @var $relatedBld TypedPropertyBuilder */ $relatedBld = VCard::builder('related')->addType('agent'); if ($agent->getValueType() === 'vcard') { $agentText = $agent->getValue(); $components = $this->getCardBody(\stripcslashes($agentText), self::$agentBodyRegExp); // Embedded AGENT VCards might not have VERSION but they only // existed in 3.0. $components['version'] = '3.0'; $agentCard = $this->parseCardBody($components); $relatedBld->setValueType('uri')->setValue($agentCard->getUID())->pushTo($vcard); $this->vcards[$agentCard->getUID()] = $agentCard; return $vcard; } else { $relatedBld->setValue($agent->getValue())->setValueType($agent->getValueType())->pushTo($vcard); return null; } } }
if ($n[4]) { $tmp[] = $n[4]; } // Esq. $ret = array(); if ($n[0]) { $ret[] = $n[0]; } $tmp = join(" ", $tmp); if ($tmp) { $ret[] = $tmp; } $key = join(", ", $ret); $cards[$key] = $card; // MDH: Create new VCard to prevent overwriting previous one (PHP5) $card = new VCard(); } ksort($cards); // extract the emails $contacts = array(); $i = 0; foreach ($cards as $card_name => $card) { $emails = array(); $properties = $card->getProperties('EMAIL'); if ($properties) { $count = 0; foreach ($properties as $property) { $emails[$count] = array($property->value); $count++; } }
/** * @dataProvider VCardTestSuite::validVCardProvider */ public function testOutputReturnsOnlyExpectedFieldSubsetForEveryone($input) { if (!file_exists($input['filename'])) { $this->markTestSkipped('File: ' . $input['filename'] . "does not exist."); } $obj = new VCard($input['filename']); $obj->setLevel(VCard::LEVEL_ALL); $output = $obj->toVCard(); $aOutput = explode("\n", $output); $prevLine = false; $inImage = false; foreach ($aOutput as $line => $item) { if ($prevLine) { $posPrev = mb_strpos($prevLine, '.'); $posCur = mb_strpos($item, '.'); if ($posPrev && $posCur && mb_substr($prevLine, 0, $posPrev) == mb_substr($item, 0, $posCur)) { continue; } } $prevLine = $item; $foundField = false; foreach ($obj->aFilters['boilerplate'] as $rule) { if (mb_strstr($item, $rule)) { $foundField = true; continue; } } if ('' == trim($item)) { $foundField = true; } foreach ($obj->aFilters['everyone'] as $rule) { if (mb_strstr($item, $rule)) { $foundField = true; if ('PHOTO;BASE64' == $rule) { $inImage = true; } else { $inImage = false; } continue; } } if ($inImage && !$foundField) { // do a regex to see if this is an image line // 78 chars of characters preceeded by two spaces if (preg_match('/^\\s\\s.*$/', $item)) { $foundField = true; } if ('==' == substr($item, -2)) { $inImage = false; } } $this->assertTrue($foundField, "Line {$line}: {$item}"); } }
/** * Fetches all records for generic, x-tended properties for which we have * no detailed specification. * @param string $uid The contact uid records are associated with. * Numeric, not null. * @return NULL|Property[] Returns an array of associated records, or null * if none found. */ private function fetchXtendedProperties($uid) { assert(isset($this->connection)); assert(!empty($uid)); assert(is_string($uid)); // Fetch each property record in turn $stmt = $this->prepareCannedQuery('fetch', 'xtended'); $stmt->bindValue(':id', $uid); $stmt->execute(); /** @var Property[] */ $properties = []; while ($result = $stmt->fetch(\PDO::FETCH_ASSOC)) { $builder = VCard::builder($result['name'], false); $builder->setValue($result['value']); // FIXME: Need to store this. $propertyID = $result['pid']; if (null !== $result['pref']) { $builder->setPref($result['pref']); } if (null !== $result['mediatype']) { $builder->setMediaType($result['mediatype']); } if (null !== $result['valuetype']) { $builder->setValueType($result['valuetype']); } if (null !== $result['propGroup']) { $builder->setGroup($result['propGroup']); } $this->fetchTypesForPropertyID($builder, $propertyID, 'xtended'); $properties[] = $builder->build(); } $stmt->closeCursor(); return empty($properties) ? null : $properties; }
/** * @param $id * @return mixed */ public function delete($id) { VCard::delete($id); }
/** * @param $id * @return mixed */ public function delete($id) { try { $query = 'SELECT * FROM `*PREFIX*contacts_cards` WHERE `id` = ? AND `addressbookid` = ?'; $stmt = \OCP\DB::prepare($query); $result = $stmt->execute(array($id, $this->id)); if (\OC_DB::isError($result)) { \OC_Log::write('contacts', __METHOD__ . 'DB error: ' . \OC_DB::getErrorMessage($result), \OCP\Util::ERROR); return false; } if ($result->numRows() === 0) { \OC_Log::write('contacts', __METHOD__ . 'Contact with id ' . $id . 'doesn\'t belong to addressbook with id ' . $this->id, \OCP\Util::ERROR); return false; } } catch (\Exception $e) { \OCP\Util::writeLog('contacts', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR); return false; } return VCard::delete($id); }
function handler_vcard($page, $photos = null) { $pf = new ProfileFilter(new UFC_Contact(S::user())); $vcard = new VCard($photos == 'photos'); $vcard->addProfiles($pf->getProfiles(null, Profile::FETCH_ALL)); $vcard->show(); }
/** * @dataProvider VCardTestSuite::invalidLevelProvider */ public function testReturnsFalseIfInvalidLevelInput($input) { $obj = new VCard('../testdata/test1.vcf'); $this->assertFalse($obj->setLevel($input)); }
function handler_vcard($page, $x = null) { if (is_null($x)) { return PL_NOT_FOUND; } global $globals; if (substr($x, -4) == '.vcf') { $x = substr($x, 0, strlen($x) - 4); } $vcard = new VCard(); $vcard->addProfile(Profile::get($x, Profile::FETCH_ALL)); $vcard->show(); }
/** * Look-up and return the requested property value or magic value. * @param VCard $vcard The vcard to find the property in. * @param Substitution $substitution The Substitution currently being * processed. * @param string $iterOver The name of a property being iterated over, or * null. * @param Property $iterItem The current value of the property being * iterated over, or null. * @return string */ private function i_processLookUp(VCard $vcard, Substitution $substitution, $iterOver, Property $iterItem = null) { assert(null !== $vcard); assert(null !== $substitution); assert($substitution->shouldLookUp()); $lookUpProperty = $substitution->getLookUp()['property']; assert(null !== $lookUpProperty); $value = ''; if ($substitution->isMagic()) { if ($lookUpProperty == "_id") { $value = urlencode((string) $vcard->fn[0]); } else { if ($lookUpProperty == "_rawvcard") { $value = $vcard->output(); } else { assert(false, 'bad magic:' . $lookUpProperty); } } } else { if ($substitution->lookUpIsStructured()) { $lookUpField = $substitution->getLookUp()['field']; // if we are already processing a list of #items... if ($lookUpProperty == $iterOver) { \assert($iterItem instanceof StructuredProperty); $value = $iterItem->getField($lookUpField); } else { // otherwise look it up and *take first one found* // FIXME: #64 $items = $vcard->{$lookUpProperty}; if (!empty($items)) { \assert($items[0] instanceof StructuredProperty); $value = htmlspecialchars($items[0]->getField($lookUpField) !== null ? $items[0]->getField($lookUpField) : ''); } } } else { if ($iterOver == $lookUpProperty) { $value = htmlspecialchars($iterItem); } else { $items = $vcard->{$lookUpProperty}; if (!empty($items)) { if (is_array($items)) { $value = htmlspecialchars(implode(" ", $items)); } else { $value = htmlspecialchars($items); } } } } } return $value; }