mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-31 13:09:21 +03:00
Remote Synchronization (CardDAV) improvements:
now it supports address book url auto detection (and works with Google contacts, icloud and etc.)
This commit is contained in:
parent
92f2caf700
commit
1fb553e77e
249 changed files with 1338 additions and 1453 deletions
|
|
@ -0,0 +1,127 @@
|
|||
<?php
|
||||
|
||||
namespace SabreForRainLoop\VObject\Property;
|
||||
|
||||
use
|
||||
LogicException,
|
||||
SabreForRainLoop\VObject\Property;
|
||||
|
||||
/**
|
||||
* BINARY property
|
||||
*
|
||||
* This object represents BINARY values.
|
||||
*
|
||||
* Binary values are most commonly used by the iCalendar ATTACH property, and
|
||||
* the vCard PHOTO property.
|
||||
*
|
||||
* This property will transparently encode and decode to base64.
|
||||
*
|
||||
* @copyright Copyright (C) 2007-2013 fruux GmbH. All rights reserved.
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Binary extends Property {
|
||||
|
||||
/**
|
||||
* In case this is a multi-value property. This string will be used as a
|
||||
* delimiter.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $delimiter = null;
|
||||
|
||||
/**
|
||||
* Updates the current value.
|
||||
*
|
||||
* This may be either a single, or multiple strings in an array.
|
||||
*
|
||||
* @param string|array $value
|
||||
* @return void
|
||||
*/
|
||||
public function setValue($value) {
|
||||
|
||||
if(is_array($value)) {
|
||||
|
||||
if(count($value) === 1) {
|
||||
$this->value = $value[0];
|
||||
} else {
|
||||
throw new \InvalidArgumentException('The argument must either be a string or an array with only one child');
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
$this->value = $value;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a raw value coming from a mimedir (iCalendar/vCard) file.
|
||||
*
|
||||
* This has been 'unfolded', so only 1 line will be passed. Unescaping is
|
||||
* not yet done, but parameters are not included.
|
||||
*
|
||||
* @param string $val
|
||||
* @return void
|
||||
*/
|
||||
public function setRawMimeDirValue($val) {
|
||||
|
||||
$this->value = base64_decode($val);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a raw mime-dir representation of the value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRawMimeDirValue() {
|
||||
|
||||
return base64_encode($this->value);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of value.
|
||||
*
|
||||
* This corresponds to the VALUE= parameter. Every property also has a
|
||||
* 'default' valueType.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValueType() {
|
||||
|
||||
return 'BINARY';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value, in the format it should be encoded for json.
|
||||
*
|
||||
* This method must always return an array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getJsonValue() {
|
||||
|
||||
return array(base64_encode($this->getValue()));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the json value, as it would appear in a jCard or jCal object.
|
||||
*
|
||||
* The value must always be an array.
|
||||
*
|
||||
* @param array $value
|
||||
* @return void
|
||||
*/
|
||||
public function setJsonValue(array $value) {
|
||||
|
||||
$value = array_map('base64_decode', $value);
|
||||
parent::setJsonValue($value);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
namespace SabreForRainLoop\VObject\Property;
|
||||
|
||||
use
|
||||
SabreForRainLoop\VObject\Property;
|
||||
|
||||
/**
|
||||
* Boolean property
|
||||
*
|
||||
* This object represents BOOLEAN values. These are always the case-insenstive
|
||||
* string TRUE or FALSE.
|
||||
*
|
||||
* Automatic conversion to PHP's true and false are done.
|
||||
*
|
||||
* @copyright Copyright (C) 2007-2013 fruux GmbH. All rights reserved.
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Boolean extends Property {
|
||||
|
||||
/**
|
||||
* Sets a raw value coming from a mimedir (iCalendar/vCard) file.
|
||||
*
|
||||
* This has been 'unfolded', so only 1 line will be passed. Unescaping is
|
||||
* not yet done, but parameters are not included.
|
||||
*
|
||||
* @param string $val
|
||||
* @return void
|
||||
*/
|
||||
public function setRawMimeDirValue($val) {
|
||||
|
||||
$val = strtoupper($val)==='TRUE'?true:false;
|
||||
$this->setValue($val);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a raw mime-dir representation of the value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRawMimeDirValue() {
|
||||
|
||||
return $this->value?'TRUE':'FALSE';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of value.
|
||||
*
|
||||
* This corresponds to the VALUE= parameter. Every property also has a
|
||||
* 'default' valueType.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValueType() {
|
||||
|
||||
return 'BOOLEAN';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace SabreForRainLoop\VObject\Property;
|
||||
|
||||
/**
|
||||
* FlatText property
|
||||
*
|
||||
* This object represents certain TEXT values.
|
||||
*
|
||||
* Specifically, this property is used for text values where there is only 1
|
||||
* part. Semi-colons and colons will be de-escaped when deserializing, but if
|
||||
* any semi-colons or commas appear without a backslash, we will not assume
|
||||
* that they are delimiters.
|
||||
*
|
||||
* vCard 2.1 specifically has a whole bunch of properties where this may
|
||||
* happen, as it only defines a delimiter for a few properties.
|
||||
*
|
||||
* vCard 4.0 states something similar. An unescaped semi-colon _may_ be a
|
||||
* delimiter, depending on the property.
|
||||
*
|
||||
* @copyright Copyright (C) 2007-2013 fruux GmbH. All rights reserved.
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class FlatText extends Text {
|
||||
|
||||
/**
|
||||
* Field separator
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $delimiter = ',';
|
||||
|
||||
/**
|
||||
* Sets the value as a quoted-printable encoded string.
|
||||
*
|
||||
* Overriding this so we're not splitting on a ; delimiter.
|
||||
*
|
||||
* @param string $val
|
||||
* @return void
|
||||
*/
|
||||
public function setQuotedPrintableValue($val) {
|
||||
|
||||
$val = quoted_printable_decode($val);
|
||||
$this->setValue($val);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
|
||||
namespace SabreForRainLoop\VObject\Property;
|
||||
|
||||
use
|
||||
SabreForRainLoop\VObject\Property;
|
||||
|
||||
/**
|
||||
* Float property
|
||||
*
|
||||
* This object represents FLOAT values. These can be 1 or more floating-point
|
||||
* numbers.
|
||||
*
|
||||
* @copyright Copyright (C) 2007-2013 fruux GmbH. All rights reserved.
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Float extends Property {
|
||||
|
||||
/**
|
||||
* In case this is a multi-value property. This string will be used as a
|
||||
* delimiter.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $delimiter = ';';
|
||||
|
||||
/**
|
||||
* Sets a raw value coming from a mimedir (iCalendar/vCard) file.
|
||||
*
|
||||
* This has been 'unfolded', so only 1 line will be passed. Unescaping is
|
||||
* not yet done, but parameters are not included.
|
||||
*
|
||||
* @param string $val
|
||||
* @return void
|
||||
*/
|
||||
public function setRawMimeDirValue($val) {
|
||||
|
||||
$val = explode($this->delimiter, $val);
|
||||
foreach($val as &$item) {
|
||||
$item = (float)$item;
|
||||
}
|
||||
$this->setParts($val);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a raw mime-dir representation of the value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRawMimeDirValue() {
|
||||
|
||||
return implode(
|
||||
$this->delimiter,
|
||||
$this->getParts()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of value.
|
||||
*
|
||||
* This corresponds to the VALUE= parameter. Every property also has a
|
||||
* 'default' valueType.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValueType() {
|
||||
|
||||
return "FLOAT";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value, in the format it should be encoded for json.
|
||||
*
|
||||
* This method must always return an array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getJsonValue() {
|
||||
|
||||
$val = array_map(function($item) {
|
||||
|
||||
return (float)$item;
|
||||
|
||||
}, $this->getParts());
|
||||
|
||||
// Special-casing the GEO property.
|
||||
//
|
||||
// See:
|
||||
// http://tools.ietf.org/html/draft-ietf-jcardcal-jcal-04#section-3.4.1.2
|
||||
if ($this->name==='GEO') {
|
||||
return array($val);
|
||||
} else {
|
||||
return $val;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace SabreForRainLoop\VObject\Property\ICalendar;
|
||||
|
||||
use
|
||||
SabreForRainLoop\VObject\Property\Text;
|
||||
|
||||
/**
|
||||
* CalAddress property
|
||||
*
|
||||
* This object encodes CAL-ADDRESS values, as defined in rfc5545
|
||||
*
|
||||
* @copyright Copyright (C) 2007-2013 fruux GmbH. All rights reserved.
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class CalAddress extends Text {
|
||||
|
||||
/**
|
||||
* In case this is a multi-value property. This string will be used as a
|
||||
* delimiter.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $delimiter = null;
|
||||
|
||||
/**
|
||||
* Returns the type of value.
|
||||
*
|
||||
* This corresponds to the VALUE= parameter. Every property also has a
|
||||
* 'default' valueType.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValueType() {
|
||||
|
||||
return 'CAL-ADDRESS';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace SabreForRainLoop\VObject\Property\ICalendar;
|
||||
|
||||
use
|
||||
SabreForRainLoop\VObject\Property,
|
||||
SabreForRainLoop\VObject\Parser\MimeDir,
|
||||
SabreForRainLoop\VObject\DateTimeParser,
|
||||
SabreForRainLoop\VObject\TimeZoneUtil;
|
||||
|
||||
/**
|
||||
* DateTime property
|
||||
*
|
||||
* This object represents DATE values, as defined here:
|
||||
*
|
||||
* http://tools.ietf.org/html/rfc5545#section-3.3.5
|
||||
*
|
||||
* @copyright Copyright (C) 2007-2013 fruux GmbH. All rights reserved.
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Date extends DateTime {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,308 @@
|
|||
<?php
|
||||
|
||||
namespace SabreForRainLoop\VObject\Property\ICalendar;
|
||||
|
||||
use
|
||||
SabreForRainLoop\VObject\Property,
|
||||
SabreForRainLoop\VObject\Parser\MimeDir,
|
||||
SabreForRainLoop\VObject\DateTimeParser,
|
||||
SabreForRainLoop\VObject\TimeZoneUtil;
|
||||
|
||||
/**
|
||||
* DateTime property
|
||||
*
|
||||
* This object represents DATE-TIME values, as defined here:
|
||||
*
|
||||
* http://tools.ietf.org/html/rfc5545#section-3.3.4
|
||||
*
|
||||
* This particular object has a bit of hackish magic that it may also in some
|
||||
* cases represent a DATE value. This is because it's a common usecase to be
|
||||
* able to change a DATE-TIME into a DATE.
|
||||
*
|
||||
* @copyright Copyright (C) 2007-2013 fruux GmbH. All rights reserved.
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class DateTime extends Property {
|
||||
|
||||
/**
|
||||
* In case this is a multi-value property. This string will be used as a
|
||||
* delimiter.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $delimiter = ',';
|
||||
|
||||
/**
|
||||
* Sets a multi-valued property.
|
||||
*
|
||||
* You may also specify DateTime objects here.
|
||||
*
|
||||
* @param array $parts
|
||||
* @return void
|
||||
*/
|
||||
public function setParts(array $parts) {
|
||||
|
||||
if (isset($parts[0]) && $parts[0] instanceof \DateTime) {
|
||||
$this->setDateTimes($parts);
|
||||
} else {
|
||||
parent::setParts($parts);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the current value.
|
||||
*
|
||||
* This may be either a single, or multiple strings in an array.
|
||||
*
|
||||
* Instead of strings, you may also use DateTime here.
|
||||
*
|
||||
* @param string|array|\DateTime $value
|
||||
* @return void
|
||||
*/
|
||||
public function setValue($value) {
|
||||
|
||||
if (is_array($value) && isset($value[0]) && $value[0] instanceof \DateTime) {
|
||||
$this->setDateTimes($value);
|
||||
} elseif ($value instanceof \DateTime) {
|
||||
$this->setDateTimes(array($value));
|
||||
} else {
|
||||
parent::setValue($value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a raw value coming from a mimedir (iCalendar/vCard) file.
|
||||
*
|
||||
* This has been 'unfolded', so only 1 line will be passed. Unescaping is
|
||||
* not yet done, but parameters are not included.
|
||||
*
|
||||
* @param string $val
|
||||
* @return void
|
||||
*/
|
||||
public function setRawMimeDirValue($val) {
|
||||
|
||||
$this->setValue(explode($this->delimiter, $val));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a raw mime-dir representation of the value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRawMimeDirValue() {
|
||||
|
||||
return implode($this->delimiter, $this->getParts());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this is a DATE-TIME value, false if it's a DATE.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasTime() {
|
||||
|
||||
return strtoupper((string)$this['VALUE']) !== 'DATE';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a date-time value.
|
||||
*
|
||||
* Note that if this property contained more than 1 date-time, only the
|
||||
* first will be returned. To get an array with multiple values, call
|
||||
* getDateTimes.
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getDateTime() {
|
||||
|
||||
$dt = $this->getDateTimes();
|
||||
if (!$dt) return null;
|
||||
|
||||
return $dt[0];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns multiple date-time values.
|
||||
*
|
||||
* @return \DateTime[]
|
||||
*/
|
||||
public function getDateTimes() {
|
||||
|
||||
// Finding the timezone.
|
||||
$tz = $this['TZID'];
|
||||
|
||||
if ($tz) {
|
||||
$tz = TimeZoneUtil::getTimeZone((string)$tz, $this->root);
|
||||
}
|
||||
|
||||
$dts = array();
|
||||
foreach($this->getParts() as $part) {
|
||||
$dts[] = DateTimeParser::parse($part, $tz);
|
||||
}
|
||||
return $dts;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the property as a DateTime object.
|
||||
*
|
||||
* @param \DateTime $dt
|
||||
* @param bool isFloating If set to true, timezones will be ignored.
|
||||
* @return void
|
||||
*/
|
||||
public function setDateTime(\DateTime $dt, $isFloating = false) {
|
||||
|
||||
$this->setDateTimes(array($dt), $isFloating);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the property as multiple date-time objects.
|
||||
*
|
||||
* The first value will be used as a reference for the timezones, and all
|
||||
* the otehr values will be adjusted for that timezone
|
||||
*
|
||||
* @param \DateTime[] $dt
|
||||
* @param bool isFloating If set to true, timezones will be ignored.
|
||||
* @return void
|
||||
*/
|
||||
public function setDateTimes(array $dt, $isFloating = false) {
|
||||
|
||||
$values = array();
|
||||
|
||||
if($this->hasTime()) {
|
||||
|
||||
$tz = null;
|
||||
$isUtc = false;
|
||||
|
||||
foreach($dt as $d) {
|
||||
|
||||
if ($isFloating) {
|
||||
$values[] = $d->format('Ymd\\THis');
|
||||
continue;
|
||||
}
|
||||
if (is_null($tz)) {
|
||||
$tz = $d->getTimeZone();
|
||||
$isUtc = in_array($tz->getName() , array('UTC', 'GMT', 'Z'));
|
||||
if (!$isUtc) {
|
||||
$this->offsetSet('TZID', $tz->getName());
|
||||
}
|
||||
} else {
|
||||
$d->setTimeZone($tz);
|
||||
}
|
||||
|
||||
if ($isUtc) {
|
||||
$values[] = $d->format('Ymd\\THis\\Z');
|
||||
} else {
|
||||
$values[] = $d->format('Ymd\\THis');
|
||||
}
|
||||
|
||||
}
|
||||
if ($isUtc || $isFloating) {
|
||||
$this->offsetUnset('TZID');
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
foreach($dt as $d) {
|
||||
|
||||
$values[] = $d->format('Ymd');
|
||||
|
||||
}
|
||||
$this->offsetUnset('TZID');
|
||||
|
||||
}
|
||||
|
||||
$this->value = $values;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of value.
|
||||
*
|
||||
* This corresponds to the VALUE= parameter. Every property also has a
|
||||
* 'default' valueType.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValueType() {
|
||||
|
||||
return $this->hasTime()?'DATE-TIME':'DATE';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value, in the format it should be encoded for json.
|
||||
*
|
||||
* This method must always return an array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getJsonValue() {
|
||||
|
||||
$dts = $this->getDateTimes();
|
||||
$hasTime = $this->hasTime();
|
||||
|
||||
$tz = $dts[0]->getTimeZone();
|
||||
$isUtc = in_array($tz->getName() , array('UTC', 'GMT', 'Z'));
|
||||
|
||||
return array_map(function($dt) use ($hasTime, $isUtc) {
|
||||
|
||||
if ($hasTime) {
|
||||
return $dt->format('Y-m-d\\TH:i:s') . ($isUtc?'Z':'');
|
||||
} else {
|
||||
return $dt->format('Y-m-d');
|
||||
}
|
||||
|
||||
}, $dts);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the json value, as it would appear in a jCard or jCal object.
|
||||
*
|
||||
* The value must always be an array.
|
||||
*
|
||||
* @param array $value
|
||||
* @return void
|
||||
*/
|
||||
public function setJsonValue(array $value) {
|
||||
|
||||
// dates and times in jCal have one difference to dates and times in
|
||||
// iCalendar. In jCal date-parts are separated by dashes, and
|
||||
// time-parts are separated by colons. It makes sense to just remove
|
||||
// those.
|
||||
$this->setValue(array_map(function($item) {
|
||||
|
||||
return strtr($item, array(':'=>'', '-'=>''));
|
||||
|
||||
}, $value));
|
||||
|
||||
}
|
||||
/**
|
||||
* We need to intercept offsetSet, because it may be used to alter the
|
||||
* VALUE from DATE-TIME to DATE or vice-versa.
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function offsetSet($name, $value) {
|
||||
|
||||
parent::offsetSet($name, $value);
|
||||
if (strtoupper($name)!=='VALUE') {
|
||||
return;
|
||||
}
|
||||
|
||||
// This will ensure that dates are correctly encoded.
|
||||
$this->setDateTimes($this->getDateTimes());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
namespace SabreForRainLoop\VObject\Property\ICalendar;
|
||||
|
||||
use
|
||||
SabreForRainLoop\VObject\Property,
|
||||
SabreForRainLoop\VObject\Parser\MimeDir,
|
||||
SabreForRainLoop\VObject\DateTimeParser;
|
||||
|
||||
/**
|
||||
* Duration property
|
||||
*
|
||||
* This object represents DURATION values, as defined here:
|
||||
*
|
||||
* http://tools.ietf.org/html/rfc5545#section-3.3.6
|
||||
*
|
||||
* @copyright Copyright (C) 2007-2013 fruux GmbH. All rights reserved.
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Duration extends Property {
|
||||
|
||||
/**
|
||||
* In case this is a multi-value property. This string will be used as a
|
||||
* delimiter.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $delimiter = ',';
|
||||
|
||||
/**
|
||||
* Sets a raw value coming from a mimedir (iCalendar/vCard) file.
|
||||
*
|
||||
* This has been 'unfolded', so only 1 line will be passed. Unescaping is
|
||||
* not yet done, but parameters are not included.
|
||||
*
|
||||
* @param string $val
|
||||
* @return void
|
||||
*/
|
||||
public function setRawMimeDirValue($val) {
|
||||
|
||||
$this->setValue(explode($this->delimiter, $val));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a raw mime-dir representation of the value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRawMimeDirValue() {
|
||||
|
||||
return implode($this->delimiter, $this->getParts());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of value.
|
||||
*
|
||||
* This corresponds to the VALUE= parameter. Every property also has a
|
||||
* 'default' valueType.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValueType() {
|
||||
|
||||
return 'DURATION';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a DateInterval representation of the Duration property.
|
||||
*
|
||||
* If the property has more than one value, only the first is returned.
|
||||
*
|
||||
* @return \DateInterval
|
||||
*/
|
||||
public function getDateInterval() {
|
||||
|
||||
$parts = $this->getParts();
|
||||
$value = $parts[0];
|
||||
return DateTimeParser::parseDuration($value);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,126 @@
|
|||
<?php
|
||||
|
||||
namespace SabreForRainLoop\VObject\Property\ICalendar;
|
||||
|
||||
use
|
||||
SabreForRainLoop\VObject\Property,
|
||||
SabreForRainLoop\VObject\Parser\MimeDir,
|
||||
SabreForRainLoop\VObject\DateTimeParser;
|
||||
|
||||
/**
|
||||
* Period property
|
||||
*
|
||||
* This object represents PERIOD values, as defined here:
|
||||
*
|
||||
* http://tools.ietf.org/html/rfc5545#section-3.8.2.6
|
||||
*
|
||||
* @copyright Copyright (C) 2007-2013 fruux GmbH. All rights reserved.
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Period extends Property {
|
||||
|
||||
/**
|
||||
* In case this is a multi-value property. This string will be used as a
|
||||
* delimiter.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $delimiter = ',';
|
||||
|
||||
/**
|
||||
* Sets a raw value coming from a mimedir (iCalendar/vCard) file.
|
||||
*
|
||||
* This has been 'unfolded', so only 1 line will be passed. Unescaping is
|
||||
* not yet done, but parameters are not included.
|
||||
*
|
||||
* @param string $val
|
||||
* @return void
|
||||
*/
|
||||
public function setRawMimeDirValue($val) {
|
||||
|
||||
$this->setValue(explode($this->delimiter, $val));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a raw mime-dir representation of the value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRawMimeDirValue() {
|
||||
|
||||
return implode($this->delimiter, $this->getParts());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of value.
|
||||
*
|
||||
* This corresponds to the VALUE= parameter. Every property also has a
|
||||
* 'default' valueType.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValueType() {
|
||||
|
||||
return "PERIOD";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the json value, as it would appear in a jCard or jCal object.
|
||||
*
|
||||
* The value must always be an array.
|
||||
*
|
||||
* @param array $value
|
||||
* @return void
|
||||
*/
|
||||
public function setJsonValue(array $value) {
|
||||
|
||||
$value = array_map(function($item) {
|
||||
|
||||
return strtr(implode('/', $item), array(':' => '', '-' => ''));
|
||||
|
||||
}, $value);
|
||||
parent::setJsonValue($value);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value, in the format it should be encoded for json.
|
||||
*
|
||||
* This method must always return an array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getJsonValue() {
|
||||
|
||||
$return = array();
|
||||
foreach($this->getParts() as $item) {
|
||||
|
||||
list($start, $end) = explode('/', $item, 2);
|
||||
|
||||
$start = DateTimeParser::parseDateTime($start);
|
||||
|
||||
// This is a duration value.
|
||||
if ($end[0]==='P') {
|
||||
$return[] = array(
|
||||
$start->format('Y-m-d\\TH:i:s'),
|
||||
$end
|
||||
);
|
||||
} else {
|
||||
$end = DateTimeParser::parseDateTime($end);
|
||||
$return[] = array(
|
||||
$start->format('Y-m-d\\TH:i:s'),
|
||||
$end->format('Y-m-d\\TH:i:s'),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $return;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,189 @@
|
|||
<?php
|
||||
|
||||
namespace SabreForRainLoop\VObject\Property\ICalendar;
|
||||
|
||||
use
|
||||
SabreForRainLoop\VObject\Property,
|
||||
SabreForRainLoop\VObject\Parser\MimeDir;
|
||||
|
||||
/**
|
||||
* Recur property
|
||||
*
|
||||
* This object represents RECUR properties.
|
||||
* These values are just used for RRULE and the now deprecated EXRULE.
|
||||
*
|
||||
* The RRULE property may look something like this:
|
||||
*
|
||||
* RRULE:FREQ=MONTHLY;BYDAY=1,2,3;BYHOUR=5.
|
||||
*
|
||||
* This property exposes this as a key=>value array that is accessible using
|
||||
* getParts, and may be set using setParts.
|
||||
*
|
||||
* @copyright Copyright (C) 2007-2013 fruux GmbH. All rights reserved.
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Recur extends Property {
|
||||
|
||||
/**
|
||||
* Updates the current value.
|
||||
*
|
||||
* This may be either a single, or multiple strings in an array.
|
||||
*
|
||||
* @param string|array $value
|
||||
* @return void
|
||||
*/
|
||||
public function setValue($value) {
|
||||
|
||||
// If we're getting the data from json, we'll be receiving an object
|
||||
if ($value instanceof \StdClass) {
|
||||
$value = (array)$value;
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
$newVal = array();
|
||||
foreach($value as $k=>$v) {
|
||||
|
||||
if (is_string($v)) {
|
||||
$v = strtoupper($v);
|
||||
|
||||
// The value had multiple sub-values
|
||||
if (strpos($v,',')!==false) {
|
||||
$v = explode(',', $v);
|
||||
}
|
||||
} else {
|
||||
$v = array_map('strtoupper', $v);
|
||||
}
|
||||
|
||||
$newVal[strtoupper($k)] = $v;
|
||||
}
|
||||
$this->value = $newVal;
|
||||
} elseif (is_string($value)) {
|
||||
$value = strtoupper($value);
|
||||
$newValue = array();
|
||||
foreach(explode(';', $value) as $part) {
|
||||
|
||||
// Skipping empty parts.
|
||||
if (empty($part)) {
|
||||
continue;
|
||||
}
|
||||
list($partName, $partValue) = explode('=', $part);
|
||||
|
||||
// The value itself had multiple values..
|
||||
if (strpos($partValue,',')!==false) {
|
||||
$partValue=explode(',', $partValue);
|
||||
}
|
||||
$newValue[$partName] = $partValue;
|
||||
|
||||
}
|
||||
$this->value = $newValue;
|
||||
} else {
|
||||
throw new \InvalidArgumentException('You must either pass a string, or a key=>value array');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current value.
|
||||
*
|
||||
* This method will always return a singular value. If this was a
|
||||
* multi-value object, some decision will be made first on how to represent
|
||||
* it as a string.
|
||||
*
|
||||
* To get the correct multi-value version, use getParts.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValue() {
|
||||
|
||||
$out = array();
|
||||
foreach($this->value as $key=>$value) {
|
||||
$out[] = $key . '=' . (is_array($value)?implode(',', $value):$value);
|
||||
}
|
||||
return strtoupper(implode(';',$out));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a multi-valued property.
|
||||
*
|
||||
* @param array $parts
|
||||
* @return void
|
||||
*/
|
||||
public function setParts(array $parts) {
|
||||
|
||||
$this->setValue($parts);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a multi-valued property.
|
||||
*
|
||||
* This method always returns an array, if there was only a single value,
|
||||
* it will still be wrapped in an array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getParts() {
|
||||
|
||||
return $this->value;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a raw value coming from a mimedir (iCalendar/vCard) file.
|
||||
*
|
||||
* This has been 'unfolded', so only 1 line will be passed. Unescaping is
|
||||
* not yet done, but parameters are not included.
|
||||
*
|
||||
* @param string $val
|
||||
* @return void
|
||||
*/
|
||||
public function setRawMimeDirValue($val) {
|
||||
|
||||
$this->setValue($val);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a raw mime-dir representation of the value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRawMimeDirValue() {
|
||||
|
||||
return $this->getValue();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of value.
|
||||
*
|
||||
* This corresponds to the VALUE= parameter. Every property also has a
|
||||
* 'default' valueType.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValueType() {
|
||||
|
||||
return "RECUR";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value, in the format it should be encoded for json.
|
||||
*
|
||||
* This method must always return an array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getJsonValue() {
|
||||
|
||||
$values = array();
|
||||
foreach($this->getParts() as $k=>$v) {
|
||||
$values[strtolower($k)] = $v;
|
||||
}
|
||||
return array($values);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
namespace SabreForRainLoop\VObject\Property;
|
||||
|
||||
use
|
||||
SabreForRainLoop\VObject\Property;
|
||||
|
||||
/**
|
||||
* Integer property
|
||||
*
|
||||
* This object represents INTEGER values. These are always a single integer.
|
||||
* They may be preceeded by either + or -.
|
||||
*
|
||||
* @copyright Copyright (C) 2007-2013 fruux GmbH. All rights reserved.
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Integer extends Property {
|
||||
|
||||
/**
|
||||
* Sets a raw value coming from a mimedir (iCalendar/vCard) file.
|
||||
*
|
||||
* This has been 'unfolded', so only 1 line will be passed. Unescaping is
|
||||
* not yet done, but parameters are not included.
|
||||
*
|
||||
* @param string $val
|
||||
* @return void
|
||||
*/
|
||||
public function setRawMimeDirValue($val) {
|
||||
|
||||
$this->setValue((int)$val);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a raw mime-dir representation of the value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRawMimeDirValue() {
|
||||
|
||||
return $this->value;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of value.
|
||||
*
|
||||
* This corresponds to the VALUE= parameter. Every property also has a
|
||||
* 'default' valueType.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValueType() {
|
||||
|
||||
return "INTEGER";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value, in the format it should be encoded for json.
|
||||
*
|
||||
* This method must always return an array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getJsonValue() {
|
||||
|
||||
return array((int)$this->getValue());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,330 @@
|
|||
<?php
|
||||
|
||||
namespace SabreForRainLoop\VObject\Property;
|
||||
|
||||
use
|
||||
SabreForRainLoop\VObject\Property,
|
||||
SabreForRainLoop\VObject\Component,
|
||||
SabreForRainLoop\VObject\Parser\MimeDir,
|
||||
SabreForRainLoop\VObject\Document;
|
||||
|
||||
/**
|
||||
* Text property
|
||||
*
|
||||
* This object represents TEXT values.
|
||||
*
|
||||
* @copyright Copyright (C) 2007-2013 fruux GmbH. All rights reserved.
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Text extends Property {
|
||||
|
||||
/**
|
||||
* In case this is a multi-value property. This string will be used as a
|
||||
* delimiter.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $delimiter = ',';
|
||||
|
||||
/**
|
||||
* List of properties that are considered 'structured'.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $structuredValues = array(
|
||||
// vCard
|
||||
'N',
|
||||
'ADR',
|
||||
'ORG',
|
||||
'GENDER',
|
||||
|
||||
// iCalendar
|
||||
'REQUEST-STATUS',
|
||||
);
|
||||
|
||||
/**
|
||||
* Some text components have a minimum number of components.
|
||||
*
|
||||
* N must for instance be represented as 5 components, separated by ;, even
|
||||
* if the last few components are unused.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $minimumPropertyValues = array(
|
||||
'N' => 5,
|
||||
'ADR' => 7,
|
||||
);
|
||||
|
||||
/**
|
||||
* Creates the property.
|
||||
*
|
||||
* You can specify the parameters either in key=>value syntax, in which case
|
||||
* parameters will automatically be created, or you can just pass a list of
|
||||
* Parameter objects.
|
||||
*
|
||||
* @param Component $root The root document
|
||||
* @param string $name
|
||||
* @param string|array|null $value
|
||||
* @param array $parameters List of parameters
|
||||
* @param string $group The vcard property group
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Component $root, $name, $value = null, array $parameters = array(), $group = null) {
|
||||
|
||||
// There's two types of multi-valued text properties:
|
||||
// 1. multivalue properties.
|
||||
// 2. structured value properties
|
||||
//
|
||||
// The former is always separated by a comma, the latter by semi-colon.
|
||||
if (in_array($name, $this->structuredValues)) {
|
||||
$this->delimiter = ';';
|
||||
}
|
||||
|
||||
parent::__construct($root, $name, $value, $parameters, $group);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets a raw value coming from a mimedir (iCalendar/vCard) file.
|
||||
*
|
||||
* This has been 'unfolded', so only 1 line will be passed. Unescaping is
|
||||
* not yet done, but parameters are not included.
|
||||
*
|
||||
* @param string $val
|
||||
* @return void
|
||||
*/
|
||||
public function setRawMimeDirValue($val) {
|
||||
|
||||
$this->setValue(MimeDir::unescapeValue($val, $this->delimiter));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value as a quoted-printable encoded string.
|
||||
*
|
||||
* @param string $val
|
||||
* @return void
|
||||
*/
|
||||
public function setQuotedPrintableValue($val) {
|
||||
|
||||
$val = quoted_printable_decode($val);
|
||||
|
||||
// Quoted printable only appears in vCard 2.1, and the only character
|
||||
// that may be escaped there is ;. So we are simply splitting on just
|
||||
// that.
|
||||
//
|
||||
// We also don't have to unescape \\, so all we need to look for is a ;
|
||||
// that's not preceeded with a \.
|
||||
$regex = '# (?<!\\\\) ; #x';
|
||||
$matches = preg_split($regex, $val);
|
||||
$this->setValue($matches);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a raw mime-dir representation of the value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRawMimeDirValue() {
|
||||
|
||||
$val = $this->getParts();
|
||||
|
||||
if (isset($this->minimumPropertyValues[$this->name])) {
|
||||
$val = array_pad($val, $this->minimumPropertyValues[$this->name], '');
|
||||
}
|
||||
|
||||
foreach($val as &$item) {
|
||||
|
||||
if (!is_array($item)) {
|
||||
$item = array($item);
|
||||
}
|
||||
|
||||
foreach($item as &$subItem) {
|
||||
$subItem = strtr($subItem, array(
|
||||
'\\' => '\\\\',
|
||||
';' => '\;',
|
||||
',' => '\,',
|
||||
"\n" => '\n',
|
||||
"\r" => "",
|
||||
));
|
||||
}
|
||||
$item = implode(',', $item);
|
||||
|
||||
}
|
||||
|
||||
return implode($this->delimiter, $val);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value, in the format it should be encoded for json.
|
||||
*
|
||||
* This method must always return an array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getJsonValue() {
|
||||
|
||||
// Structured text values should always be returned as a single
|
||||
// array-item. Multi-value text should be returned as multiple items in
|
||||
// the top-array.
|
||||
if (in_array($this->name, $this->structuredValues)) {
|
||||
return array($this->getParts());
|
||||
} else {
|
||||
return $this->getParts();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of value.
|
||||
*
|
||||
* This corresponds to the VALUE= parameter. Every property also has a
|
||||
* 'default' valueType.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValueType() {
|
||||
|
||||
return "TEXT";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns the object back into a serialized blob.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function serialize() {
|
||||
|
||||
// We need to kick in a special type of encoding, if it's a 2.1 vcard.
|
||||
if ($this->root->getDocumentType() !== Document::VCARD21) {
|
||||
return parent::serialize();
|
||||
}
|
||||
|
||||
$val = $this->getParts();
|
||||
|
||||
if (isset($this->minimumPropertyValues[$this->name])) {
|
||||
$val = array_pad($val, $this->minimumPropertyValues[$this->name], '');
|
||||
}
|
||||
|
||||
// Imploding multiple parts into a single value, and splitting the
|
||||
// values with ;.
|
||||
if (count($val)>1) {
|
||||
foreach($val as $k=>$v) {
|
||||
$val[$k] = str_replace(';','\;', $v);
|
||||
}
|
||||
$val = implode(';', $val);
|
||||
} else {
|
||||
$val = $val[0];
|
||||
}
|
||||
|
||||
$str = $this->name;
|
||||
if ($this->group) $str = $this->group . '.' . $this->name;
|
||||
foreach($this->parameters as $param) {
|
||||
|
||||
if ($param->getValue() === 'QUOTED-PRINTABLE') {
|
||||
continue;
|
||||
}
|
||||
$str.=';' . $param->serialize();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// If the resulting value contains a \n, we must encode it as
|
||||
// quoted-printable.
|
||||
if (strpos($val,"\n") !== false) {
|
||||
|
||||
$str.=';ENCODING=QUOTED-PRINTABLE:';
|
||||
$lastLine=$str;
|
||||
$out = null;
|
||||
|
||||
// The PHP built-in quoted-printable-encode does not correctly
|
||||
// encode newlines for us. Specifically, the \r\n sequence must in
|
||||
// vcards be encoded as =0D=OA and we must insert soft-newlines
|
||||
// every 75 bytes.
|
||||
for($ii=0;$ii<strlen($val);$ii++) {
|
||||
$ord = ord($val[$ii]);
|
||||
// These characters are encoded as themselves.
|
||||
if ($ord >= 32 && $ord <=126) {
|
||||
$lastLine.=$val[$ii];
|
||||
} else {
|
||||
$lastLine.='=' . strtoupper(bin2hex($val[$ii]));
|
||||
}
|
||||
if (strlen($lastLine)>=75) {
|
||||
// Soft line break
|
||||
$out.=$lastLine. "=\r\n ";
|
||||
$lastLine = null;
|
||||
}
|
||||
|
||||
}
|
||||
if (!is_null($lastLine)) $out.= $lastLine . "\r\n";
|
||||
return $out;
|
||||
|
||||
} else {
|
||||
$str.=':' . $val;
|
||||
$out = '';
|
||||
while(strlen($str)>0) {
|
||||
if (strlen($str)>75) {
|
||||
$out.= mb_strcut($str,0,75,'utf-8') . "\r\n";
|
||||
$str = ' ' . mb_strcut($str,75,strlen($str),'utf-8');
|
||||
} else {
|
||||
$out.=$str . "\r\n";
|
||||
$str='';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $out;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the node for correctness.
|
||||
*
|
||||
* The following options are supported:
|
||||
* - Node::REPAIR - If something is broken, and automatic repair may
|
||||
* be attempted.
|
||||
*
|
||||
* An array is returned with warnings.
|
||||
*
|
||||
* Every item in the array has the following properties:
|
||||
* * level - (number between 1 and 3 with severity information)
|
||||
* * message - (human readable message)
|
||||
* * node - (reference to the offending node)
|
||||
*
|
||||
* @param int $options
|
||||
* @return array
|
||||
*/
|
||||
public function validate($options = 0) {
|
||||
|
||||
$warnings = parent::validate($options);
|
||||
|
||||
if (isset($this->minimumPropertyValues[$this->name])) {
|
||||
|
||||
$minimum = $this->minimumPropertyValues[$this->name];
|
||||
$parts = $this->getParts();
|
||||
if (count($parts) < $minimum) {
|
||||
$warnings[] = array(
|
||||
'level' => 1,
|
||||
'message' => 'This property must have at least ' . $minimum . ' components. It only has ' . count($parts),
|
||||
'node' => $this,
|
||||
);
|
||||
if ($options & self::REPAIR) {
|
||||
$parts = array_pad($parts, $minimum, '');
|
||||
$this->setParts($parts);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return $warnings;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
|
||||
namespace SabreForRainLoop\VObject\Property;
|
||||
|
||||
use SabreForRainLoop\VObject\DateTimeParser;
|
||||
|
||||
/**
|
||||
* Time property
|
||||
*
|
||||
* This object encodes TIME values.
|
||||
*
|
||||
* @copyright Copyright (C) 2007-2013 fruux GmbH. All rights reserved.
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Time extends Text {
|
||||
|
||||
/**
|
||||
* In case this is a multi-value property. This string will be used as a
|
||||
* delimiter.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $delimiter = null;
|
||||
|
||||
/**
|
||||
* Returns the type of value.
|
||||
*
|
||||
* This corresponds to the VALUE= parameter. Every property also has a
|
||||
* 'default' valueType.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValueType() {
|
||||
|
||||
return "TIME";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value, in the format it should be encoded for json.
|
||||
*
|
||||
* This method must always return an array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getJsonValue() {
|
||||
|
||||
$parts = DateTimeParser::parseVCardTime($this->getValue());
|
||||
|
||||
$timeStr = '';
|
||||
|
||||
// Hour
|
||||
if (!is_null($parts['hour'])) {
|
||||
$timeStr.=$parts['hour'];
|
||||
|
||||
if (!is_null($parts['minute'])) {
|
||||
$timeStr.=':';
|
||||
}
|
||||
} else {
|
||||
// We know either minute or second _must_ be set, so we insert a
|
||||
// dash for an empty value.
|
||||
$timeStr.='-';
|
||||
}
|
||||
|
||||
// Minute
|
||||
if (!is_null($parts['minute'])) {
|
||||
$timeStr.=$parts['minute'];
|
||||
|
||||
if (!is_null($parts['second'])) {
|
||||
$timeStr.=':';
|
||||
}
|
||||
} else {
|
||||
if (isset($parts['second'])) {
|
||||
// Dash for empty minute
|
||||
$timeStr.='-';
|
||||
}
|
||||
}
|
||||
|
||||
// Second
|
||||
if (!is_null($parts['second'])) {
|
||||
$timeStr.=$parts['second'];
|
||||
}
|
||||
|
||||
// Timezone
|
||||
if (!is_null($parts['timezone'])) {
|
||||
$timeStr.=$parts['timezone'];
|
||||
}
|
||||
|
||||
return array($timeStr);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace SabreForRainLoop\VObject\Property;
|
||||
|
||||
use
|
||||
SabreForRainLoop\VObject\Property,
|
||||
SabreForRainLoop\VObject\Component,
|
||||
SabreForRainLoop\VObject\Parser\MimeDir,
|
||||
SabreForRainLoop\VObject\Document;
|
||||
|
||||
/**
|
||||
* Unknown property
|
||||
*
|
||||
* This object represents any properties not recognized by the parser.
|
||||
* This type of value has been introduced by the jCal, jCard specs.
|
||||
*
|
||||
* @copyright Copyright (C) 2007-2013 fruux GmbH. All rights reserved.
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Unknown extends Text {
|
||||
|
||||
/**
|
||||
* Returns the value, in the format it should be encoded for json.
|
||||
*
|
||||
* This method must always return an array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getJsonValue() {
|
||||
|
||||
return array($this->getRawMimeDirValue());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of value.
|
||||
*
|
||||
* This corresponds to the VALUE= parameter. Every property also has a
|
||||
* 'default' valueType.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValueType() {
|
||||
|
||||
return "UNKNOWN";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
namespace SabreForRainLoop\VObject\Property;
|
||||
|
||||
use SabreForRainLoop\VObject\Property;
|
||||
|
||||
/**
|
||||
* URI property
|
||||
*
|
||||
* This object encodes URI values. vCard 2.1 calls these URL.
|
||||
*
|
||||
* @copyright Copyright (C) 2007-2013 fruux GmbH. All rights reserved.
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Uri extends Property {
|
||||
|
||||
/**
|
||||
* In case this is a multi-value property. This string will be used as a
|
||||
* delimiter.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $delimiter = null;
|
||||
|
||||
/**
|
||||
* Returns the type of value.
|
||||
*
|
||||
* This corresponds to the VALUE= parameter. Every property also has a
|
||||
* 'default' valueType.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValueType() {
|
||||
|
||||
return "URI";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a raw value coming from a mimedir (iCalendar/vCard) file.
|
||||
*
|
||||
* This has been 'unfolded', so only 1 line will be passed. Unescaping is
|
||||
* not yet done, but parameters are not included.
|
||||
*
|
||||
* @param string $val
|
||||
* @return void
|
||||
*/
|
||||
public function setRawMimeDirValue($val) {
|
||||
|
||||
$this->value = $val;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a raw mime-dir representation of the value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRawMimeDirValue() {
|
||||
|
||||
if (is_array($this->value)) {
|
||||
return $this->value[0];
|
||||
} else {
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace SabreForRainLoop\VObject\Property;
|
||||
|
||||
/**
|
||||
* UtcOffset property
|
||||
*
|
||||
* This object encodes UTC-OFFSET values.
|
||||
*
|
||||
* @copyright Copyright (C) 2007-2013 fruux GmbH. All rights reserved.
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class UtcOffset extends Text {
|
||||
|
||||
/**
|
||||
* In case this is a multi-value property. This string will be used as a
|
||||
* delimiter.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $delimiter = null;
|
||||
|
||||
/**
|
||||
* Returns the type of value.
|
||||
*
|
||||
* This corresponds to the VALUE= parameter. Every property also has a
|
||||
* 'default' valueType.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValueType() {
|
||||
|
||||
return "UTC-OFFSET";
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace SabreForRainLoop\VObject\Property\VCard;
|
||||
|
||||
use
|
||||
SabreForRainLoop\VObject\DateTimeParser;
|
||||
|
||||
/**
|
||||
* Date property
|
||||
*
|
||||
* This object encodes vCard DATE values.
|
||||
*
|
||||
* @copyright Copyright (C) 2007-2013 fruux GmbH. All rights reserved.
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class Date extends DateAndOrTime {
|
||||
|
||||
/**
|
||||
* Returns the type of value.
|
||||
*
|
||||
* This corresponds to the VALUE= parameter. Every property also has a
|
||||
* 'default' valueType.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValueType() {
|
||||
|
||||
return "DATE";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,144 @@
|
|||
<?php
|
||||
|
||||
namespace SabreForRainLoop\VObject\Property\VCard;
|
||||
|
||||
use
|
||||
SabreForRainLoop\VObject\DateTimeParser,
|
||||
SabreForRainLoop\VObject\Property\Text;
|
||||
|
||||
/**
|
||||
* DateAndOrTime property
|
||||
*
|
||||
* This object encodes DATE-AND-OR-TIME values.
|
||||
*
|
||||
* @copyright Copyright (C) 2007-2013 fruux GmbH. All rights reserved.
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class DateAndOrTime extends Text {
|
||||
|
||||
/**
|
||||
* Field separator
|
||||
*
|
||||
* @var null|string
|
||||
*/
|
||||
public $delimiter = null;
|
||||
|
||||
/**
|
||||
* Returns the type of value.
|
||||
*
|
||||
* This corresponds to the VALUE= parameter. Every property also has a
|
||||
* 'default' valueType.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValueType() {
|
||||
|
||||
return "DATE-AND-OR-TIME";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value, in the format it should be encoded for json.
|
||||
*
|
||||
* This method must always return an array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getJsonValue() {
|
||||
|
||||
$parts = DateTimeParser::parseVCardDateTime($this->getValue());
|
||||
|
||||
$dateStr = '';
|
||||
|
||||
// Year
|
||||
if (!is_null($parts['year'])) {
|
||||
$dateStr.=$parts['year'];
|
||||
|
||||
if (!is_null($parts['month'])) {
|
||||
// If a year and a month is set, we need to insert a separator
|
||||
// dash.
|
||||
$dateStr.='-';
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (!is_null($parts['month']) || !is_null($parts['date'])) {
|
||||
// Inserting two dashes
|
||||
$dateStr.='--';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Month
|
||||
|
||||
if (!is_null($parts['month'])) {
|
||||
$dateStr.=$parts['month'];
|
||||
|
||||
if (isset($parts['date'])) {
|
||||
// If month and date are set, we need the separator dash.
|
||||
$dateStr.='-';
|
||||
}
|
||||
} else {
|
||||
if (isset($parts['date'])) {
|
||||
// If the month is empty, and a date is set, we need a 'empty
|
||||
// dash'
|
||||
$dateStr.='-';
|
||||
}
|
||||
}
|
||||
|
||||
// Date
|
||||
if (!is_null($parts['date'])) {
|
||||
$dateStr.=$parts['date'];
|
||||
}
|
||||
|
||||
|
||||
// Early exit if we don't have a time string.
|
||||
if (is_null($parts['hour']) && is_null($parts['minute']) && is_null($parts['second'])) {
|
||||
return array($dateStr);
|
||||
}
|
||||
|
||||
$dateStr.='T';
|
||||
|
||||
// Hour
|
||||
if (!is_null($parts['hour'])) {
|
||||
$dateStr.=$parts['hour'];
|
||||
|
||||
if (!is_null($parts['minute'])) {
|
||||
$dateStr.=':';
|
||||
}
|
||||
} else {
|
||||
// We know either minute or second _must_ be set, so we insert a
|
||||
// dash for an empty value.
|
||||
$dateStr.='-';
|
||||
}
|
||||
|
||||
// Minute
|
||||
if (!is_null($parts['minute'])) {
|
||||
$dateStr.=$parts['minute'];
|
||||
|
||||
if (!is_null($parts['second'])) {
|
||||
$dateStr.=':';
|
||||
}
|
||||
} else {
|
||||
if (isset($parts['second'])) {
|
||||
// Dash for empty minute
|
||||
$dateStr.='-';
|
||||
}
|
||||
}
|
||||
|
||||
// Second
|
||||
if (!is_null($parts['second'])) {
|
||||
$dateStr.=$parts['second'];
|
||||
}
|
||||
|
||||
// Timezone
|
||||
if (!is_null($parts['timezone'])) {
|
||||
$dateStr.=$parts['timezone'];
|
||||
}
|
||||
|
||||
return array($dateStr);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace SabreForRainLoop\VObject\Property\VCard;
|
||||
|
||||
use
|
||||
SabreForRainLoop\VObject\DateTimeParser;
|
||||
|
||||
/**
|
||||
* DateTime property
|
||||
*
|
||||
* This object encodes DATE-TIME values for vCards.
|
||||
*
|
||||
* @copyright Copyright (C) 2007-2013 fruux GmbH. All rights reserved.
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class DateTime extends DateAndOrTime {
|
||||
|
||||
/**
|
||||
* Returns the type of value.
|
||||
*
|
||||
* This corresponds to the VALUE= parameter. Every property also has a
|
||||
* 'default' valueType.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValueType() {
|
||||
|
||||
return "DATE-TIME";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace SabreForRainLoop\VObject\Property\VCard;
|
||||
|
||||
use
|
||||
SabreForRainLoop\VObject\Property;
|
||||
|
||||
/**
|
||||
* LanguageTag property
|
||||
*
|
||||
* This object represents LANGUAGE-TAG values as used in vCards.
|
||||
*
|
||||
* @copyright Copyright (C) 2007-2013 fruux GmbH. All rights reserved.
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class LanguageTag extends Property {
|
||||
|
||||
/**
|
||||
* Sets a raw value coming from a mimedir (iCalendar/vCard) file.
|
||||
*
|
||||
* This has been 'unfolded', so only 1 line will be passed. Unescaping is
|
||||
* not yet done, but parameters are not included.
|
||||
*
|
||||
* @param string $val
|
||||
* @return void
|
||||
*/
|
||||
public function setRawMimeDirValue($val) {
|
||||
|
||||
$this->setValue($val);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a raw mime-dir representation of the value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRawMimeDirValue() {
|
||||
|
||||
return $this->value;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of value.
|
||||
*
|
||||
* This corresponds to the VALUE= parameter. Every property also has a
|
||||
* 'default' valueType.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValueType() {
|
||||
|
||||
return "LANGUAGE-TAG";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
namespace SabreForRainLoop\VObject\Property\VCard;
|
||||
|
||||
use
|
||||
SabreForRainLoop\VObject\DateTimeParser,
|
||||
SabreForRainLoop\VObject\Property\Text;
|
||||
|
||||
/**
|
||||
* TimeStamp property
|
||||
*
|
||||
* This object encodes TIMESTAMP values.
|
||||
*
|
||||
* @copyright Copyright (C) 2007-2013 fruux GmbH. All rights reserved.
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
|
||||
*/
|
||||
class TimeStamp extends Text {
|
||||
|
||||
/**
|
||||
* In case this is a multi-value property. This string will be used as a
|
||||
* delimiter.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $delimiter = null;
|
||||
|
||||
/**
|
||||
* Returns the type of value.
|
||||
*
|
||||
* This corresponds to the VALUE= parameter. Every property also has a
|
||||
* 'default' valueType.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValueType() {
|
||||
|
||||
return "TIMESTAMP";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value, in the format it should be encoded for json.
|
||||
*
|
||||
* This method must always return an array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getJsonValue() {
|
||||
|
||||
$parts = DateTimeParser::parseVCardDateTime($this->getValue());
|
||||
|
||||
$dateStr =
|
||||
$parts['year'] . '-' .
|
||||
$parts['month'] . '-' .
|
||||
$parts['date'] . 'T' .
|
||||
$parts['hour'] . ':' .
|
||||
$parts['minute'] . ':' .
|
||||
$parts['second'];
|
||||
|
||||
// Timezone
|
||||
if (!is_null($parts['timezone'])) {
|
||||
$dateStr.=$parts['timezone'];
|
||||
}
|
||||
|
||||
return array($dateStr);
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue