当前位置: 首页>>代码示例>>PHP>>正文


PHP Property::serialize方法代码示例

本文整理汇总了PHP中Sabre\VObject\Property::serialize方法的典型用法代码示例。如果您正苦于以下问题:PHP Property::serialize方法的具体用法?PHP Property::serialize怎么用?PHP Property::serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sabre\VObject\Property的用法示例。


在下文中一共展示了Property::serialize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: serialize

 /**
  * 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;
     }
 }
开发者ID:pkdevboxy,项目名称:webmail-lite,代码行数:79,代码来源:Text.php

示例2: structureProperty

 /**
  * @brief Data structure of properties
  * @param object $property
  * @return associative array
  *
  * returns an associative array with
  * ['name'] name of property
  * ['value'] htmlspecialchars escaped value of property
  * ['parameters'] associative array name=>value
  * ['checksum'] checksum of whole property
  * NOTE: $value is not escaped anymore. It shouldn't make any difference
  * but we should look out for any problems.
  */
 public static function structureProperty(\Sabre\VObject\Property $property)
 {
     if (!in_array($property->name, App::$index_properties)) {
         return;
     }
     $value = $property->getValue();
     if ($property->name == 'ADR' || $property->name == 'N' || $property->name == 'ORG' || $property->name == 'CATEGORIES') {
         $value = $property->getParts();
         if ($property->name == 'CATEGORIES') {
             $value = str_replace(';', ',', $value);
         }
         if ($property->name == 'N') {
             //$value = stripslashes($value);
             //	\OCP\Util::writeLog('contactsplus','NAME VAL: '.$value, \OCP\Util::DEBUG);
         }
         $value = array_map('trim', $value);
     } elseif ($property->name == 'BDAY') {
         if (strlen($value) >= 8 && is_int(substr($value, 0, 4)) && is_int(substr($value, 4, 2)) && is_int(substr($value, 6, 2))) {
             $value = substr($value, 0, 4) . '-' . substr($value, 4, 2) . '-' . substr($value, 6, 2);
         } else {
             if ($value[5] !== '-' || $value[7] !== '-') {
                 try {
                     // Skype exports as e.g. Jan 14, 1996
                     $date = new \DateTime($value);
                     $value = $date->format('Y-m-d');
                 } catch (\Exception $e) {
                     \OCP\Util::writeLog('contactsplus', __METHOD__ . ' Error parsing date: ' . $value, \OCP\Util::DEBUG);
                     return;
                 }
             }
         }
     } elseif ($property->name == 'PHOTO') {
         $value = true;
     } elseif ($property->name == 'IMPP') {
         if (strpos($value, ':') !== false) {
             $value = explode(':', $value);
             $protocol = array_shift($value);
             if (!isset($property['X-SERVICE-TYPE'])) {
                 $property['X-SERVICE-TYPE'] = strtoupper($protocol);
             }
             $value = implode('', $value);
         }
     }
     if (is_string($value)) {
         $value = strtr($value, array('\\,' => ',', '\\;' => ';'));
     }
     $temp = array('value' => $value, 'parameters' => array());
     // This cuts around a 3rd off of the json response size.
     if (in_array($property->name, App::$multi_properties)) {
         $temp['checksum'] = substr(md5($property->serialize()), 0, 8);
     }
     foreach ($property->parameters as $parameter) {
         // Faulty entries by kaddressbook
         // Actually TYPE=PREF is correct according to RFC 2426
         // but this way is more handy in the UI. Tanghus.
         if ($parameter->name == 'TYPE' && strtoupper($parameter->getValue()) == 'PREF') {
             $parameter->name = 'PREF';
             $parameter->setValue('1');
         }
         // NOTE: Apparently Sabre_VObject_Reader can't always deal with value list parameters
         // like TYPE=HOME,CELL,VOICE. Tanghus.
         // TODO: Check if parameter is has commas and split + merge if so.
         if ($parameter->name == 'TYPE') {
             $pvalue = $parameter->getValue();
             if (is_string($pvalue) && strpos($pvalue, ',') !== false) {
                 $pvalue = array_map('trim', explode(',', $pvalue));
             }
             $pvalue = is_array($pvalue) ? $pvalue : array($pvalue);
             if (isset($temp['parameters'][$parameter->name])) {
                 $temp['parameters'][$parameter->name][] = \OCP\Util::sanitizeHTML($pvalue);
             } else {
                 $temp['parameters'][$parameter->name] = \OCP\Util::sanitizeHTML($pvalue);
             }
         } else {
             //$value = strtr($value, array('\,' => ',', '\;' => ';'));
             $temp['parameters'][$parameter->name] = \OCP\Util::sanitizeHTML($parameter->getValue());
         }
     }
     return $temp;
 }
开发者ID:ViToni,项目名称:contactsplus,代码行数:93,代码来源:vcard.php

示例3: serializeProperty

 /**
  * @brief Get data structure of property.
  * @param \Sabre\VObject\Property $property
  * @return associative array
  *
  * returns an associative array with
  * ['name'] name of property
  * ['value'] htmlspecialchars escaped value of property
  * ['parameters'] associative array name=>value
  * ['checksum'] checksum of whole property
  * NOTE: $value is not escaped anymore. It shouldn't make any difference
  * but we should look out for any problems.
  */
 public static function serializeProperty(\Sabre\VObject\Property $property)
 {
     if (!in_array($property->name, Properties::$index_properties)) {
         return;
     }
     $value = $property->value;
     if ($property->name == 'ADR' || $property->name == 'N' || $property->name == 'ORG' || $property->name == 'CATEGORIES') {
         $value = $property->getParts();
         $value = array_map('trim', $value);
     } elseif ($property->name == 'BDAY') {
         if (strpos($value, '-') === false) {
             if (strlen($value) >= 8) {
                 $value = substr($value, 0, 4) . '-' . substr($value, 4, 2) . '-' . substr($value, 6, 2);
             } else {
                 return null;
                 // Badly malformed :-(
             }
         }
     } elseif ($property->name == 'PHOTO') {
         $value = true;
     } elseif ($property->name == 'IMPP') {
         if (strpos($value, ':') !== false) {
             $value = explode(':', $value);
             $protocol = array_shift($value);
             if (!isset($property['X-SERVICE-TYPE'])) {
                 $property['X-SERVICE-TYPE'] = strtoupper($protocol);
             }
             $value = implode('', $value);
         }
     }
     if (is_string($value)) {
         $value = strtr($value, array('\\,' => ',', '\\;' => ';'));
     }
     $temp = array('value' => $value, 'parameters' => array());
     // This cuts around a 3rd off of the json response size.
     if (in_array($property->name, Properties::$multi_properties)) {
         $temp['checksum'] = substr(md5($property->serialize()), 0, 8);
     }
     foreach ($property->parameters as $parameter) {
         // Faulty entries by kaddressbook
         // Actually TYPE=PREF is correct according to RFC 2426
         // but this way is more handy in the UI. Tanghus.
         if ($parameter->name == 'TYPE' && strtoupper($parameter->value) == 'PREF') {
             $parameter->name = 'PREF';
             $parameter->value = '1';
         }
         // NOTE: Apparently Sabre_VObject_Reader can't always deal with value list parameters
         // like TYPE=HOME,CELL,VOICE. Tanghus.
         // TODO: Check if parameter is has commas and split + merge if so.
         if ($parameter->name == 'TYPE') {
             $pvalue = $parameter->value;
             if (is_string($pvalue) && strpos($pvalue, ',') !== false) {
                 $pvalue = array_map('trim', explode(',', $pvalue));
             }
             $pvalue = is_array($pvalue) ? $pvalue : array($pvalue);
             if (isset($temp['parameters'][$parameter->name])) {
                 $temp['parameters'][$parameter->name][] = \OCP\Util::sanitizeHTML($pvalue);
             } else {
                 $temp['parameters'][$parameter->name] = \OCP\Util::sanitizeHTML($pvalue);
             }
         } else {
             $temp['parameters'][$parameter->name] = \OCP\Util::sanitizeHTML($parameter->value);
         }
     }
     return $temp;
 }
开发者ID:omusico,项目名称:isle-web-framework,代码行数:79,代码来源:jsonserializer.php


注:本文中的Sabre\VObject\Property::serialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。