diff options
author | Manuel Jiménez Friaza <mjfriaza@openmailbox.org> | 2019-05-19 13:25:00 +0200 |
---|---|---|
committer | Manuel Jiménez Friaza <mjfriaza@openmailbox.org> | 2019-05-19 13:25:00 +0200 |
commit | 429140df97a2c273fba6974147ac2e48e7688263 (patch) | |
tree | 2e337542da1b0f4c9c383dfeb8a7d9eb63990a72 /vendor/sabre/vobject/lib/Property/Text.php | |
parent | f92d2e3f7c6573bd7bab04223c7e28662605c6d8 (diff) | |
parent | af2b263bc74b16601ec7c123a58f0549613aed27 (diff) | |
download | volse-hubzilla-429140df97a2c273fba6974147ac2e48e7688263.tar.gz volse-hubzilla-429140df97a2c273fba6974147ac2e48e7688263.tar.bz2 volse-hubzilla-429140df97a2c273fba6974147ac2e48e7688263.zip |
Merge remote-tracking branch 'upstream/dev' into dev
Diffstat (limited to 'vendor/sabre/vobject/lib/Property/Text.php')
-rw-r--r-- | vendor/sabre/vobject/lib/Property/Text.php | 131 |
1 files changed, 54 insertions, 77 deletions
diff --git a/vendor/sabre/vobject/lib/Property/Text.php b/vendor/sabre/vobject/lib/Property/Text.php index 47a86ccc9..23c945551 100644 --- a/vendor/sabre/vobject/lib/Property/Text.php +++ b/vendor/sabre/vobject/lib/Property/Text.php @@ -17,8 +17,8 @@ use Sabre\Xml; * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ -class Text extends Property { - +class Text extends Property +{ /** * In case this is a multi-value property. This string will be used as a * delimiter. @@ -53,7 +53,7 @@ class Text extends Property { * @var array */ protected $minimumPropertyValues = [ - 'N' => 5, + 'N' => 5, 'ADR' => 7, ]; @@ -64,16 +64,14 @@ class Text extends Property { * 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 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 + * @param array $parameters List of parameters + * @param string $group The vcard property group */ - function __construct(Component $root, $name, $value = null, array $parameters = [], $group = null) { - + public function __construct(Component $root, $name, $value = null, array $parameters = [], $group = null) + { // There's two types of multi-valued text properties: // 1. multivalue properties. // 2. structured value properties @@ -84,7 +82,6 @@ class Text extends Property { } parent::__construct($root, $name, $value, $parameters, $group); - } /** @@ -94,24 +91,19 @@ class Text extends Property { * not yet done, but parameters are not included. * * @param string $val - * - * @return void */ - function setRawMimeDirValue($val) { - + 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 */ - function setQuotedPrintableValue($val) { - + public function setQuotedPrintableValue($val) + { $val = quoted_printable_decode($val); // Quoted printable only appears in vCard 2.1, and the only character @@ -123,7 +115,6 @@ class Text extends Property { $regex = '# (?<!\\\\) ; #x'; $matches = preg_split($regex, $val); $this->setValue($matches); - } /** @@ -131,8 +122,8 @@ class Text extends Property { * * @return string */ - function getRawMimeDirValue() { - + public function getRawMimeDirValue() + { $val = $this->getParts(); if (isset($this->minimumPropertyValues[$this->name])) { @@ -140,7 +131,6 @@ class Text extends Property { } foreach ($val as &$item) { - if (!is_array($item)) { $item = [$item]; } @@ -150,19 +140,17 @@ class Text extends Property { $subItem, [ '\\' => '\\\\', - ';' => '\;', - ',' => '\,', + ';' => '\;', + ',' => '\,', "\n" => '\n', - "\r" => "", + "\r" => '', ] ); } $item = implode(',', $item); - } return implode($this->delimiter, $val); - } /** @@ -172,16 +160,16 @@ class Text extends Property { * * @return array */ - function getJsonValue() { - + 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 [$this->getParts()]; } - return $this->getParts(); + return $this->getParts(); } /** @@ -192,10 +180,9 @@ class Text extends Property { * * @return string */ - function getValueType() { - + public function getValueType() + { return 'TEXT'; - } /** @@ -203,10 +190,10 @@ class Text extends Property { * * @return string */ - function serialize() { - + 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) { + if (Document::VCARD21 !== $this->root->getDocumentType()) { return parent::serialize(); } @@ -228,22 +215,19 @@ class Text extends Property { } $str = $this->name; - if ($this->group) $str = $this->group . '.' . $this->name; + if ($this->group) { + $str = $this->group.'.'.$this->name; + } foreach ($this->parameters as $param) { - - if ($param->getValue() === 'QUOTED-PRINTABLE') { + if ('QUOTED-PRINTABLE' === $param->getValue()) { continue; } - $str .= ';' . $param->serialize(); - + $str .= ';'.$param->serialize(); } - - // If the resulting value contains a \n, we must encode it as // quoted-printable. - if (\strpos($val, "\n") !== false) { - + if (false !== \strpos($val, "\n")) { $str .= ';ENCODING=QUOTED-PRINTABLE:'; $lastLine = $str; $out = null; @@ -252,26 +236,27 @@ class Text extends Property { // 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++) { + 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])); + $lastLine .= '='.\strtoupper(\bin2hex($val[$ii])); } if (\strlen($lastLine) >= 75) { // Soft line break - $out .= $lastLine . "=\r\n "; + $out .= $lastLine."=\r\n "; $lastLine = null; } - } - if (!\is_null($lastLine)) $out .= $lastLine . "\r\n"; - return $out; + if (!\is_null($lastLine)) { + $out .= $lastLine."\r\n"; + } + return $out; } else { - $str .= ':' . $val; + $str .= ':'.$val; $str = \preg_replace( '/( @@ -285,24 +270,20 @@ class Text extends Property { // remove single space after last CRLF return \substr($str, 0, -1); - } - } /** * This method serializes only the value of a property. This is used to * create xCard or xCal documents. * - * @param Xml\Writer $writer XML writer. - * - * @return void + * @param Xml\Writer $writer XML writer */ - protected function xmlSerializeValue(Xml\Writer $writer) { - + protected function xmlSerializeValue(Xml\Writer $writer) + { $values = $this->getParts(); - $map = function($items) use ($values, $writer) { + $map = function ($items) use ($values, $writer) { foreach ($items as $i => $item) { $writer->writeElement( $item, @@ -312,7 +293,6 @@ class Text extends Property { }; switch ($this->name) { - // Special-casing the REQUEST-STATUS property. // // See: @@ -332,14 +312,14 @@ class Text extends Property { 'given', 'additional', 'prefix', - 'suffix' + 'suffix', ]); break; case 'GENDER': $map([ 'sex', - 'text' + 'text', ]); break; @@ -351,21 +331,20 @@ class Text extends Property { 'locality', 'region', 'code', - 'country' + 'country', ]); break; case 'CLIENTPIDMAP': $map([ 'sourceid', - 'uri' + 'uri', ]); break; default: parent::xmlSerializeValue($writer); } - } /** @@ -386,28 +365,26 @@ class Text extends Property { * * @return array */ - function validate($options = 0) { - + 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[] = [ - 'level' => $options & self::REPAIR ? 1 : 3, - 'message' => 'The ' . $this->name . ' property must have at least ' . $minimum . ' values. It only has ' . count($parts), - 'node' => $this, + 'level' => $options & self::REPAIR ? 1 : 3, + 'message' => 'The '.$this->name.' property must have at least '.$minimum.' values. It only has '.count($parts), + 'node' => $this, ]; if ($options & self::REPAIR) { $parts = array_pad($parts, $minimum, ''); $this->setParts($parts); } } - } - return $warnings; + return $warnings; } } |