diff options
Diffstat (limited to '3rdparty/Sabre/VObject/Property')
-rw-r--r-- | 3rdparty/Sabre/VObject/Property/Compound.php | 129 | ||||
-rw-r--r--[-rwxr-xr-x] | 3rdparty/Sabre/VObject/Property/DateTime.php | 91 | ||||
-rw-r--r--[-rwxr-xr-x] | 3rdparty/Sabre/VObject/Property/MultiDateTime.php | 32 |
3 files changed, 178 insertions, 74 deletions
diff --git a/3rdparty/Sabre/VObject/Property/Compound.php b/3rdparty/Sabre/VObject/Property/Compound.php new file mode 100644 index 00000000000..e2c18e7726e --- /dev/null +++ b/3rdparty/Sabre/VObject/Property/Compound.php @@ -0,0 +1,129 @@ +<?php + +namespace Sabre\VObject\Property; + +use Sabre\VObject; + +/** +* Compound property. +* +* This class adds (de)serialization of compound properties to/from arrays. +* +* Currently the following properties from RFC 6350 are mapped to use this +* class: +* +* N: Section 6.2.2 +* ADR: Section 6.3.1 +* ORG: Section 6.6.4 +* CATEGORIES: Section 6.7.1 +* +* In order to use this correctly, you must call setParts and getParts to +* retrieve and modify dates respectively. +* +* @author Thomas Tanghus (http://tanghus.net/) +* @author Lars Kneschke +* @author Evert Pot (http://www.rooftopsolutions.nl/) +* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved. +* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License +*/ + +/** +* This class represents a compound property in a vCard. +*/ +class Compound extends VObject\Property { + + /** + * If property names are added to this map, they will be (de)serialised as arrays + * using the getParts() and setParts() methods. + * The keys are the property names, values are delimiter chars. + * + * @var array + */ + static public $delimiterMap = array( + 'N' => ';', + 'ADR' => ';', + 'ORG' => ';', + 'CATEGORIES' => ',', + ); + + /** + * The currently used delimiter. + * + * @var string + */ + protected $delimiter = null; + + /** + * Get a compound value as an array. + * + * @param $name string + * @return array + */ + public function getParts() { + + if (is_null($this->value)) { + return array(); + } + + $delimiter = $this->getDelimiter(); + + // split by any $delimiter which is NOT prefixed by a slash. + // Note that this is not a a perfect solution. If a value is prefixed + // by two slashes, it should actually be split anyway. + // + // Hopefully we can fix this better in a future version, where we can + // break compatibility a bit. + $compoundValues = preg_split("/(?<!\\\)$delimiter/", $this->value); + + // remove slashes from any semicolon and comma left escaped in the single values + $compoundValues = array_map( + function($val) { + return strtr($val, array('\,' => ',', '\;' => ';')); + }, $compoundValues); + + return $compoundValues; + + } + + /** + * Returns the delimiter for this property. + * + * @return string + */ + public function getDelimiter() { + + if (!$this->delimiter) { + if (isset(self::$delimiterMap[$this->name])) { + $this->delimiter = self::$delimiterMap[$this->name]; + } else { + // To be a bit future proof, we are going to default the + // delimiter to ; + $this->delimiter = ';'; + } + } + return $this->delimiter; + + } + + /** + * Set a compound value as an array. + * + * + * @param $name string + * @return array + */ + public function setParts(array $values) { + + // add slashes to all semicolons and commas in the single values + $values = array_map( + function($val) { + return strtr($val, array(',' => '\,', ';' => '\;')); + }, $values); + + $this->setValue( + implode($this->getDelimiter(), $values) + ); + + } + +} diff --git a/3rdparty/Sabre/VObject/Property/DateTime.php b/3rdparty/Sabre/VObject/Property/DateTime.php index fe2372caa81..556cd441d8a 100755..100644 --- a/3rdparty/Sabre/VObject/Property/DateTime.php +++ b/3rdparty/Sabre/VObject/Property/DateTime.php @@ -1,5 +1,9 @@ <?php +namespace Sabre\VObject\Property; + +use Sabre\VObject; + /** * DateTime property * @@ -13,13 +17,11 @@ * If you use the 'value' or properties directly, this object does not keep * reference and results might appear incorrectly. * - * @package Sabre - * @subpackage VObject * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved. * @author Evert Pot (http://www.rooftopsolutions.nl/) * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License */ -class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property { +class DateTime extends VObject\Property { /** * Local 'floating' time @@ -44,7 +46,7 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property { /** * DateTime representation * - * @var DateTime + * @var \DateTime */ protected $dateTime; @@ -58,11 +60,11 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property { /** * Updates the Date and Time. * - * @param DateTime $dt + * @param \DateTime $dt * @param int $dateType * @return void */ - public function setDateTime(DateTime $dt, $dateType = self::LOCALTZ) { + public function setDateTime(\DateTime $dt, $dateType = self::LOCALTZ) { switch($dateType) { @@ -73,7 +75,7 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property { $this->offsetSet('VALUE','DATE-TIME'); break; case self::UTC : - $dt->setTimeZone(new DateTimeZone('UTC')); + $dt->setTimeZone(new \DateTimeZone('UTC')); $this->setValue($dt->format('Ymd\\THis\\Z')); $this->offsetUnset('VALUE'); $this->offsetUnset('TZID'); @@ -93,7 +95,7 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property { $this->offsetSet('VALUE','DATE'); break; default : - throw new InvalidArgumentException('You must pass a valid dateType constant'); + throw new \InvalidArgumentException('You must pass a valid dateType constant'); } $this->dateTime = $dt; @@ -106,7 +108,7 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property { * * If no value was set, this method returns null. * - * @return DateTime|null + * @return \DateTime|null */ public function getDateTime() { @@ -152,11 +154,11 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property { * * @param string|null $propertyValue The string to parse (yymmdd or * ymmddThhmmss, etc..) - * @param Sabre_VObject_Property|null $property The instance of the + * @param \Sabre\VObject\Property|null $property The instance of the * property we're parsing. * @return array */ - static public function parseData($propertyValue, Sabre_VObject_Property $property = null) { + static public function parseData($propertyValue, VObject\Property $property = null) { if (is_null($propertyValue)) { return array(null, null); @@ -167,14 +169,14 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property { $regex = "/^$date(T$time(?P<isutc>Z)?)?$/"; if (!preg_match($regex, $propertyValue, $matches)) { - throw new InvalidArgumentException($propertyValue . ' is not a valid DateTime or Date string'); + throw new \InvalidArgumentException($propertyValue . ' is not a valid \DateTime or Date string'); } if (!isset($matches['hour'])) { // Date-only return array( self::DATE, - new DateTime($matches['year'] . '-' . $matches['month'] . '-' . $matches['date'] . ' 00:00:00'), + new \DateTime($matches['year'] . '-' . $matches['month'] . '-' . $matches['date'] . ' 00:00:00', new \DateTimeZone('UTC')), ); } @@ -187,8 +189,8 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property { $matches['second']; if (isset($matches['isutc'])) { - $dt = new DateTime($dateStr,new DateTimeZone('UTC')); - $dt->setTimeZone(new DateTimeZone('UTC')); + $dt = new \DateTime($dateStr,new \DateTimeZone('UTC')); + $dt->setTimeZone(new \DateTimeZone('UTC')); return array( self::UTC, $dt @@ -198,56 +200,27 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property { // Finding the timezone. $tzid = $property['TZID']; if (!$tzid) { + // This was a floating time string. This implies we use the + // timezone from date_default_timezone_set / date.timezone ini + // setting. return array( self::LOCAL, - new DateTime($dateStr) + new \DateTime($dateStr) ); } - try { - // tzid an Olson identifier? - $tz = new DateTimeZone($tzid->value); - } catch (Exception $e) { - - // Not an Olson id, we're going to try to find the information - // through the time zone name map. - $newtzid = Sabre_VObject_WindowsTimezoneMap::lookup($tzid->value); - if (is_null($newtzid)) { - - // Not a well known time zone name either, we're going to try - // to find the information through the VTIMEZONE object. - - // First we find the root object - $root = $property; - while($root->parent) { - $root = $root->parent; - } - - if (isset($root->VTIMEZONE)) { - foreach($root->VTIMEZONE as $vtimezone) { - if (((string)$vtimezone->TZID) == $tzid) { - if (isset($vtimezone->{'X-LIC-LOCATION'})) { - $newtzid = (string)$vtimezone->{'X-LIC-LOCATION'}; - } else { - // No libical location specified. As a last resort we could - // try matching $vtimezone's DST rules against all known - // time zones returned by DateTimeZone::list* - - // TODO - } - } - } - } - } - - try { - $tz = new DateTimeZone($newtzid); - } catch (Exception $e) { - // If all else fails, we use the default PHP timezone - $tz = new DateTimeZone(date_default_timezone_get()); - } + // To look up the timezone, we must first find the VCALENDAR component. + $root = $property; + while($root->parent) { + $root = $root->parent; } - $dt = new DateTime($dateStr, $tz); + if ($root->name === 'VCALENDAR') { + $tz = VObject\TimeZoneUtil::getTimeZone((string)$tzid, $root); + } else { + $tz = VObject\TimeZoneUtil::getTimeZone((string)$tzid); + } + + $dt = new \DateTime($dateStr, $tz); $dt->setTimeZone($tz); return array( diff --git a/3rdparty/Sabre/VObject/Property/MultiDateTime.php b/3rdparty/Sabre/VObject/Property/MultiDateTime.php index ae53ab6a617..629ef4a1340 100755..100644 --- a/3rdparty/Sabre/VObject/Property/MultiDateTime.php +++ b/3rdparty/Sabre/VObject/Property/MultiDateTime.php @@ -1,5 +1,9 @@ <?php +namespace Sabre\VObject\Property; + +use Sabre\VObject; + /** * Multi-DateTime property * @@ -13,13 +17,11 @@ * If you use the 'value' or properties directly, this object does not keep * reference and results might appear incorrectly. * - * @package Sabre - * @subpackage VObject * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved. * @author Evert Pot (http://www.rooftopsolutions.nl/) * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License */ -class Sabre_VObject_Property_MultiDateTime extends Sabre_VObject_Property { +class MultiDateTime extends VObject\Property { /** * DateTime representation @@ -31,7 +33,7 @@ class Sabre_VObject_Property_MultiDateTime extends Sabre_VObject_Property { /** * dateType * - * This is one of the Sabre_VObject_Property_DateTime constants. + * This is one of the Sabre\VObject\Property\DateTime constants. * * @var int */ @@ -44,17 +46,17 @@ class Sabre_VObject_Property_MultiDateTime extends Sabre_VObject_Property { * @param int $dateType * @return void */ - public function setDateTimes(array $dt, $dateType = Sabre_VObject_Property_DateTime::LOCALTZ) { + public function setDateTimes(array $dt, $dateType = VObject\Property\DateTime::LOCALTZ) { foreach($dt as $i) - if (!$i instanceof DateTime) - throw new InvalidArgumentException('You must pass an array of DateTime objects'); + if (!$i instanceof \DateTime) + throw new \InvalidArgumentException('You must pass an array of DateTime objects'); $this->offsetUnset('VALUE'); $this->offsetUnset('TZID'); switch($dateType) { - case Sabre_VObject_Property_DateTime::LOCAL : + case DateTime::LOCAL : $val = array(); foreach($dt as $i) { $val[] = $i->format('Ymd\\THis'); @@ -62,16 +64,16 @@ class Sabre_VObject_Property_MultiDateTime extends Sabre_VObject_Property { $this->setValue(implode(',',$val)); $this->offsetSet('VALUE','DATE-TIME'); break; - case Sabre_VObject_Property_DateTime::UTC : + case DateTime::UTC : $val = array(); foreach($dt as $i) { - $i->setTimeZone(new DateTimeZone('UTC')); + $i->setTimeZone(new \DateTimeZone('UTC')); $val[] = $i->format('Ymd\\THis\\Z'); } $this->setValue(implode(',',$val)); $this->offsetSet('VALUE','DATE-TIME'); break; - case Sabre_VObject_Property_DateTime::LOCALTZ : + case DateTime::LOCALTZ : $val = array(); foreach($dt as $i) { $val[] = $i->format('Ymd\\THis'); @@ -80,7 +82,7 @@ class Sabre_VObject_Property_MultiDateTime extends Sabre_VObject_Property { $this->offsetSet('VALUE','DATE-TIME'); $this->offsetSet('TZID', $dt[0]->getTimeZone()->getName()); break; - case Sabre_VObject_Property_DateTime::DATE : + case DateTime::DATE : $val = array(); foreach($dt as $i) { $val[] = $i->format('Ymd'); @@ -89,7 +91,7 @@ class Sabre_VObject_Property_MultiDateTime extends Sabre_VObject_Property { $this->offsetSet('VALUE','DATE'); break; default : - throw new InvalidArgumentException('You must pass a valid dateType constant'); + throw new \InvalidArgumentException('You must pass a valid dateType constant'); } $this->dateTimes = $dt; @@ -121,7 +123,7 @@ class Sabre_VObject_Property_MultiDateTime extends Sabre_VObject_Property { list( $type, $dt - ) = Sabre_VObject_Property_DateTime::parseData($val, $this); + ) = DateTime::parseData($val, $this); $dts[] = $dt; $this->dateType = $type; } @@ -154,7 +156,7 @@ class Sabre_VObject_Property_MultiDateTime extends Sabre_VObject_Property { list( $type, $dt - ) = Sabre_VObject_Property_DateTime::parseData($val, $this); + ) = DateTime::parseData($val, $this); $dts[] = $dt; $this->dateType = $type; } |