diff options
Diffstat (limited to 'vendor/sabre/vobject/lib/Component/VCard.php')
-rw-r--r-- | vendor/sabre/vobject/lib/Component/VCard.php | 314 |
1 files changed, 145 insertions, 169 deletions
diff --git a/vendor/sabre/vobject/lib/Component/VCard.php b/vendor/sabre/vobject/lib/Component/VCard.php index bca623d5e..860e45ffa 100644 --- a/vendor/sabre/vobject/lib/Component/VCard.php +++ b/vendor/sabre/vobject/lib/Component/VCard.php @@ -15,8 +15,8 @@ use Sabre\Xml; * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ -class VCard extends VObject\Document { - +class VCard extends VObject\Document +{ /** * The default name for this component. * @@ -24,7 +24,7 @@ class VCard extends VObject\Document { * * @var string */ - static $defaultName = 'VCARD'; + public static $defaultName = 'VCARD'; /** * Caching the version number. @@ -38,7 +38,7 @@ class VCard extends VObject\Document { * * @var array */ - static $componentMap = [ + public static $componentMap = [ 'VCARD' => 'Sabre\\VObject\\Component\\VCard', ]; @@ -47,23 +47,23 @@ class VCard extends VObject\Document { * * @var array */ - static $valueMap = [ - 'BINARY' => 'Sabre\\VObject\\Property\\Binary', - 'BOOLEAN' => 'Sabre\\VObject\\Property\\Boolean', - 'CONTENT-ID' => 'Sabre\\VObject\\Property\\FlatText', // vCard 2.1 only - 'DATE' => 'Sabre\\VObject\\Property\\VCard\\Date', - 'DATE-TIME' => 'Sabre\\VObject\\Property\\VCard\\DateTime', + public static $valueMap = [ + 'BINARY' => 'Sabre\\VObject\\Property\\Binary', + 'BOOLEAN' => 'Sabre\\VObject\\Property\\Boolean', + 'CONTENT-ID' => 'Sabre\\VObject\\Property\\FlatText', // vCard 2.1 only + 'DATE' => 'Sabre\\VObject\\Property\\VCard\\Date', + 'DATE-TIME' => 'Sabre\\VObject\\Property\\VCard\\DateTime', 'DATE-AND-OR-TIME' => 'Sabre\\VObject\\Property\\VCard\\DateAndOrTime', // vCard only - 'FLOAT' => 'Sabre\\VObject\\Property\\FloatValue', - 'INTEGER' => 'Sabre\\VObject\\Property\\IntegerValue', - 'LANGUAGE-TAG' => 'Sabre\\VObject\\Property\\VCard\\LanguageTag', - 'TIMESTAMP' => 'Sabre\\VObject\\Property\\VCard\\TimeStamp', - 'TEXT' => 'Sabre\\VObject\\Property\\Text', - 'TIME' => 'Sabre\\VObject\\Property\\Time', - 'UNKNOWN' => 'Sabre\\VObject\\Property\\Unknown', // jCard / jCal-only. - 'URI' => 'Sabre\\VObject\\Property\\Uri', - 'URL' => 'Sabre\\VObject\\Property\\Uri', // vCard 2.1 only - 'UTC-OFFSET' => 'Sabre\\VObject\\Property\\UtcOffset', + 'FLOAT' => 'Sabre\\VObject\\Property\\FloatValue', + 'INTEGER' => 'Sabre\\VObject\\Property\\IntegerValue', + 'LANGUAGE-TAG' => 'Sabre\\VObject\\Property\\VCard\\LanguageTag', + 'TIMESTAMP' => 'Sabre\\VObject\\Property\\VCard\\TimeStamp', + 'TEXT' => 'Sabre\\VObject\\Property\\Text', + 'TIME' => 'Sabre\\VObject\\Property\\Time', + 'UNKNOWN' => 'Sabre\\VObject\\Property\\Unknown', // jCard / jCal-only. + 'URI' => 'Sabre\\VObject\\Property\\Uri', + 'URL' => 'Sabre\\VObject\\Property\\Uri', // vCard 2.1 only + 'UTC-OFFSET' => 'Sabre\\VObject\\Property\\UtcOffset', ]; /** @@ -71,72 +71,70 @@ class VCard extends VObject\Document { * * @var array */ - static $propertyMap = [ - + public static $propertyMap = [ // vCard 2.1 properties and up - 'N' => 'Sabre\\VObject\\Property\\Text', - 'FN' => 'Sabre\\VObject\\Property\\FlatText', - 'PHOTO' => 'Sabre\\VObject\\Property\\Binary', - 'BDAY' => 'Sabre\\VObject\\Property\\VCard\\DateAndOrTime', - 'ADR' => 'Sabre\\VObject\\Property\\Text', - 'LABEL' => 'Sabre\\VObject\\Property\\FlatText', // Removed in vCard 4.0 - 'TEL' => 'Sabre\\VObject\\Property\\FlatText', - 'EMAIL' => 'Sabre\\VObject\\Property\\FlatText', + 'N' => 'Sabre\\VObject\\Property\\Text', + 'FN' => 'Sabre\\VObject\\Property\\FlatText', + 'PHOTO' => 'Sabre\\VObject\\Property\\Binary', + 'BDAY' => 'Sabre\\VObject\\Property\\VCard\\DateAndOrTime', + 'ADR' => 'Sabre\\VObject\\Property\\Text', + 'LABEL' => 'Sabre\\VObject\\Property\\FlatText', // Removed in vCard 4.0 + 'TEL' => 'Sabre\\VObject\\Property\\FlatText', + 'EMAIL' => 'Sabre\\VObject\\Property\\FlatText', 'MAILER' => 'Sabre\\VObject\\Property\\FlatText', // Removed in vCard 4.0 - 'GEO' => 'Sabre\\VObject\\Property\\FlatText', - 'TITLE' => 'Sabre\\VObject\\Property\\FlatText', - 'ROLE' => 'Sabre\\VObject\\Property\\FlatText', - 'LOGO' => 'Sabre\\VObject\\Property\\Binary', + 'GEO' => 'Sabre\\VObject\\Property\\FlatText', + 'TITLE' => 'Sabre\\VObject\\Property\\FlatText', + 'ROLE' => 'Sabre\\VObject\\Property\\FlatText', + 'LOGO' => 'Sabre\\VObject\\Property\\Binary', // 'AGENT' => 'Sabre\\VObject\\Property\\', // Todo: is an embedded vCard. Probably rare, so // not supported at the moment - 'ORG' => 'Sabre\\VObject\\Property\\Text', - 'NOTE' => 'Sabre\\VObject\\Property\\FlatText', - 'REV' => 'Sabre\\VObject\\Property\\VCard\\TimeStamp', - 'SOUND' => 'Sabre\\VObject\\Property\\FlatText', - 'URL' => 'Sabre\\VObject\\Property\\Uri', - 'UID' => 'Sabre\\VObject\\Property\\FlatText', + 'ORG' => 'Sabre\\VObject\\Property\\Text', + 'NOTE' => 'Sabre\\VObject\\Property\\FlatText', + 'REV' => 'Sabre\\VObject\\Property\\VCard\\TimeStamp', + 'SOUND' => 'Sabre\\VObject\\Property\\FlatText', + 'URL' => 'Sabre\\VObject\\Property\\Uri', + 'UID' => 'Sabre\\VObject\\Property\\FlatText', 'VERSION' => 'Sabre\\VObject\\Property\\FlatText', - 'KEY' => 'Sabre\\VObject\\Property\\FlatText', - 'TZ' => 'Sabre\\VObject\\Property\\Text', + 'KEY' => 'Sabre\\VObject\\Property\\FlatText', + 'TZ' => 'Sabre\\VObject\\Property\\Text', // vCard 3.0 properties - 'CATEGORIES' => 'Sabre\\VObject\\Property\\Text', + 'CATEGORIES' => 'Sabre\\VObject\\Property\\Text', 'SORT-STRING' => 'Sabre\\VObject\\Property\\FlatText', - 'PRODID' => 'Sabre\\VObject\\Property\\FlatText', - 'NICKNAME' => 'Sabre\\VObject\\Property\\Text', - 'CLASS' => 'Sabre\\VObject\\Property\\FlatText', // Removed in vCard 4.0 + 'PRODID' => 'Sabre\\VObject\\Property\\FlatText', + 'NICKNAME' => 'Sabre\\VObject\\Property\\Text', + 'CLASS' => 'Sabre\\VObject\\Property\\FlatText', // Removed in vCard 4.0 // rfc2739 properties - 'FBURL' => 'Sabre\\VObject\\Property\\Uri', - 'CAPURI' => 'Sabre\\VObject\\Property\\Uri', - 'CALURI' => 'Sabre\\VObject\\Property\\Uri', + 'FBURL' => 'Sabre\\VObject\\Property\\Uri', + 'CAPURI' => 'Sabre\\VObject\\Property\\Uri', + 'CALURI' => 'Sabre\\VObject\\Property\\Uri', 'CALADRURI' => 'Sabre\\VObject\\Property\\Uri', // rfc4770 properties 'IMPP' => 'Sabre\\VObject\\Property\\Uri', // vCard 4.0 properties - 'SOURCE' => 'Sabre\\VObject\\Property\\Uri', - 'XML' => 'Sabre\\VObject\\Property\\FlatText', - 'ANNIVERSARY' => 'Sabre\\VObject\\Property\\VCard\\DateAndOrTime', + 'SOURCE' => 'Sabre\\VObject\\Property\\Uri', + 'XML' => 'Sabre\\VObject\\Property\\FlatText', + 'ANNIVERSARY' => 'Sabre\\VObject\\Property\\VCard\\DateAndOrTime', 'CLIENTPIDMAP' => 'Sabre\\VObject\\Property\\Text', - 'LANG' => 'Sabre\\VObject\\Property\\VCard\\LanguageTag', - 'GENDER' => 'Sabre\\VObject\\Property\\Text', - 'KIND' => 'Sabre\\VObject\\Property\\FlatText', - 'MEMBER' => 'Sabre\\VObject\\Property\\Uri', - 'RELATED' => 'Sabre\\VObject\\Property\\Uri', + 'LANG' => 'Sabre\\VObject\\Property\\VCard\\LanguageTag', + 'GENDER' => 'Sabre\\VObject\\Property\\Text', + 'KIND' => 'Sabre\\VObject\\Property\\FlatText', + 'MEMBER' => 'Sabre\\VObject\\Property\\Uri', + 'RELATED' => 'Sabre\\VObject\\Property\\Uri', // rfc6474 properties 'BIRTHPLACE' => 'Sabre\\VObject\\Property\\FlatText', 'DEATHPLACE' => 'Sabre\\VObject\\Property\\FlatText', - 'DEATHDATE' => 'Sabre\\VObject\\Property\\VCard\\DateAndOrTime', + 'DEATHDATE' => 'Sabre\\VObject\\Property\\VCard\\DateAndOrTime', // rfc6715 properties - 'EXPERTISE' => 'Sabre\\VObject\\Property\\FlatText', - 'HOBBY' => 'Sabre\\VObject\\Property\\FlatText', - 'INTEREST' => 'Sabre\\VObject\\Property\\FlatText', + 'EXPERTISE' => 'Sabre\\VObject\\Property\\FlatText', + 'HOBBY' => 'Sabre\\VObject\\Property\\FlatText', + 'INTEREST' => 'Sabre\\VObject\\Property\\FlatText', 'ORG-DIRECTORY' => 'Sabre\\VObject\\Property\\FlatText', - ]; /** @@ -144,23 +142,22 @@ class VCard extends VObject\Document { * * @return int */ - function getDocumentType() { - + public function getDocumentType() + { if (!$this->version) { - - $version = (string)$this->VERSION; + $version = (string) $this->VERSION; switch ($version) { - case '2.1' : + case '2.1': $this->version = self::VCARD21; break; - case '3.0' : + case '3.0': $this->version = self::VCARD30; break; - case '4.0' : + case '4.0': $this->version = self::VCARD40; break; - default : + default: // We don't want to cache the version if it's unknown, // because we might get a version property in a bit. return self::UNKNOWN; @@ -168,7 +165,6 @@ class VCard extends VObject\Document { } return $this->version; - } /** @@ -185,11 +181,11 @@ class VCard extends VObject\Document { * * @return VCard */ - function convert($target) { - + public function convert($target) + { $converter = new VObject\VCardConverter(); - return $converter->convert($this, $target); + return $converter->convert($this, $target); } /** @@ -221,8 +217,8 @@ class VCard extends VObject\Document { * * @return array */ - function validate($options = 0) { - + public function validate($options = 0) + { $warnings = []; $versionMap = [ @@ -232,29 +228,28 @@ class VCard extends VObject\Document { ]; $version = $this->select('VERSION'); - if (count($version) === 1) { - $version = (string)$this->VERSION; - if ($version !== '2.1' && $version !== '3.0' && $version !== '4.0') { + if (1 === count($version)) { + $version = (string) $this->VERSION; + if ('2.1' !== $version && '3.0' !== $version && '4.0' !== $version) { $warnings[] = [ - 'level' => 3, + 'level' => 3, 'message' => 'Only vcard version 4.0 (RFC6350), version 3.0 (RFC2426) or version 2.1 (icm-vcard-2.1) are supported.', - 'node' => $this, + 'node' => $this, ]; if ($options & self::REPAIR) { $this->VERSION = $versionMap[self::DEFAULT_VERSION]; } } - if ($version === '2.1' && ($options & self::PROFILE_CARDDAV)) { + if ('2.1' === $version && ($options & self::PROFILE_CARDDAV)) { $warnings[] = [ - 'level' => 3, + 'level' => 3, 'message' => 'CardDAV servers are not allowed to accept vCard 2.1.', - 'node' => $this, + 'node' => $this, ]; } - } $uid = $this->select('UID'); - if (count($uid) === 0) { + if (0 === count($uid)) { if ($options & self::PROFILE_CARDDAV) { // Required for CardDAV $warningLevel = 3; @@ -269,23 +264,22 @@ class VCard extends VObject\Document { $warningLevel = 1; } $warnings[] = [ - 'level' => $warningLevel, + 'level' => $warningLevel, 'message' => $message, - 'node' => $this, + 'node' => $this, ]; } $fn = $this->select('FN'); - if (count($fn) !== 1) { - + if (1 !== count($fn)) { $repaired = false; - if (($options & self::REPAIR) && count($fn) === 0) { + if (($options & self::REPAIR) && 0 === count($fn)) { // We're going to try to see if we can use the contents of the // N property. if (isset($this->N)) { - $value = explode(';', (string)$this->N); + $value = explode(';', (string) $this->N); if (isset($value[1]) && $value[1]) { - $this->FN = $value[1] . ' ' . $value[0]; + $this->FN = $value[1].' '.$value[0]; } else { $this->FN = $value[0]; } @@ -293,20 +287,19 @@ class VCard extends VObject\Document { // Otherwise, the ORG property may work } elseif (isset($this->ORG)) { - $this->FN = (string)$this->ORG; + $this->FN = (string) $this->ORG; $repaired = true; // Otherwise, the EMAIL property may work } elseif (isset($this->EMAIL)) { - $this->FN = (string)$this->EMAIL; + $this->FN = (string) $this->EMAIL; $repaired = true; } - } $warnings[] = [ - 'level' => $repaired ? 1 : 3, + 'level' => $repaired ? 1 : 3, 'message' => 'The FN property must appear in the VCARD component exactly 1 time', - 'node' => $this, + 'node' => $this, ]; } @@ -314,7 +307,6 @@ class VCard extends VObject\Document { parent::validate($options), $warnings ); - } /** @@ -332,50 +324,49 @@ class VCard extends VObject\Document { * * @var array */ - function getValidationRules() { - + public function getValidationRules() + { return [ - 'ADR' => '*', - 'ANNIVERSARY' => '?', - 'BDAY' => '?', - 'CALADRURI' => '*', - 'CALURI' => '*', - 'CATEGORIES' => '*', + 'ADR' => '*', + 'ANNIVERSARY' => '?', + 'BDAY' => '?', + 'CALADRURI' => '*', + 'CALURI' => '*', + 'CATEGORIES' => '*', 'CLIENTPIDMAP' => '*', - 'EMAIL' => '*', - 'FBURL' => '*', - 'IMPP' => '*', - 'GENDER' => '?', - 'GEO' => '*', - 'KEY' => '*', - 'KIND' => '?', - 'LANG' => '*', - 'LOGO' => '*', - 'MEMBER' => '*', - 'N' => '?', - 'NICKNAME' => '*', - 'NOTE' => '*', - 'ORG' => '*', - 'PHOTO' => '*', - 'PRODID' => '?', - 'RELATED' => '*', - 'REV' => '?', - 'ROLE' => '*', - 'SOUND' => '*', - 'SOURCE' => '*', - 'TEL' => '*', - 'TITLE' => '*', - 'TZ' => '*', - 'URL' => '*', - 'VERSION' => '1', - 'XML' => '*', + 'EMAIL' => '*', + 'FBURL' => '*', + 'IMPP' => '*', + 'GENDER' => '?', + 'GEO' => '*', + 'KEY' => '*', + 'KIND' => '?', + 'LANG' => '*', + 'LOGO' => '*', + 'MEMBER' => '*', + 'N' => '?', + 'NICKNAME' => '*', + 'NOTE' => '*', + 'ORG' => '*', + 'PHOTO' => '*', + 'PRODID' => '?', + 'RELATED' => '*', + 'REV' => '?', + 'ROLE' => '*', + 'SOUND' => '*', + 'SOURCE' => '*', + 'TEL' => '*', + 'TITLE' => '*', + 'TZ' => '*', + 'URL' => '*', + 'VERSION' => '1', + 'XML' => '*', // FN is commented out, because it's already handled by the // validate function, which may also try to repair it. // 'FN' => '+', 'UID' => '?', ]; - } /** @@ -392,12 +383,11 @@ class VCard extends VObject\Document { * * @return VObject\Property|null */ - function preferred($propertyName) { - + public function preferred($propertyName) + { $preferred = null; $lastPref = 101; foreach ($this->select($propertyName) as $field) { - $pref = 101; if (isset($field['TYPE']) && $field['TYPE']->has('PREF')) { $pref = 1; @@ -409,10 +399,9 @@ class VCard extends VObject\Document { $preferred = $field; $lastPref = $pref; } - } - return $preferred; + return $preferred; } /** @@ -426,7 +415,8 @@ class VCard extends VObject\Document { * * @return VObject\Property|null */ - function getByType($propertyName, $type) { + public function getByType($propertyName, $type) + { foreach ($this->select($propertyName) as $field) { if (isset($field['TYPE']) && $field['TYPE']->has($type)) { return $field; @@ -439,14 +429,13 @@ class VCard extends VObject\Document { * * @return array */ - protected function getDefaults() { - + protected function getDefaults() + { return [ 'VERSION' => '4.0', - 'PRODID' => '-//Sabre//Sabre VObject ' . VObject\Version::VERSION . '//EN', - 'UID' => 'sabre-vobject-' . VObject\UUIDUtil::getUUID(), + 'PRODID' => '-//Sabre//Sabre VObject '.VObject\Version::VERSION.'//EN', + 'UID' => 'sabre-vobject-'.VObject\UUIDUtil::getUUID(), ]; - } /** @@ -455,8 +444,8 @@ class VCard extends VObject\Document { * * @return array */ - function jsonSerialize() { - + public function jsonSerialize() + { // A vcard does not have sub-components, so we're overriding this // method to remove that array element. $properties = []; @@ -469,23 +458,19 @@ class VCard extends VObject\Document { strtolower($this->name), $properties, ]; - } /** * This method serializes the data into XML. This is used to create xCard or * xCal documents. * - * @param Xml\Writer $writer XML writer. - * - * @return void + * @param Xml\Writer $writer XML writer */ - function xmlSerialize(Xml\Writer $writer) { - + public function xmlSerialize(Xml\Writer $writer) + { $propertiesByGroup = []; foreach ($this->children() as $property) { - $group = $property->group; if (!isset($propertiesByGroup[$group])) { @@ -493,25 +478,20 @@ class VCard extends VObject\Document { } $propertiesByGroup[$group][] = $property; - } $writer->startElement(strtolower($this->name)); foreach ($propertiesByGroup as $group => $properties) { - if (!empty($group)) { - $writer->startElement('group'); $writer->writeAttribute('name', strtolower($group)); - } foreach ($properties as $property) { switch ($property->name) { - case 'VERSION': - continue; + break; case 'XML': $value = $property->getParts(); @@ -522,18 +502,15 @@ class VCard extends VObject\Document { default: $property->xmlSerialize($writer); break; - } } if (!empty($group)) { $writer->endElement(); } - } $writer->endElement(); - } /** @@ -543,16 +520,15 @@ class VCard extends VObject\Document { * * @return string */ - function getClassNameForPropertyName($propertyName) { - + public function getClassNameForPropertyName($propertyName) + { $className = parent::getClassNameForPropertyName($propertyName); // In vCard 4, BINARY no longer exists, and we need URI instead. - if ($className == 'Sabre\\VObject\\Property\\Binary' && $this->getDocumentType() === self::VCARD40) { + if ('Sabre\\VObject\\Property\\Binary' == $className && self::VCARD40 === $this->getDocumentType()) { return 'Sabre\\VObject\\Property\\Uri'; } - return $className; + return $className; } - } |