本文整理汇总了PHP中Sabre\VObject\Property::getParts方法的典型用法代码示例。如果您正苦于以下问题:PHP Property::getParts方法的具体用法?PHP Property::getParts怎么用?PHP Property::getParts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sabre\VObject\Property
的用法示例。
在下文中一共展示了Property::getParts方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: serializeProperty
/**
* Colorizes a property.
*
* @param Property $property
* @return void
*/
protected function serializeProperty(Property $property)
{
if ($property->group) {
$this->cWrite('default', $property->group);
$this->cWrite('red', '.');
}
$str = '';
$this->cWrite('yellow', $property->name);
foreach ($property->parameters as $param) {
$this->cWrite('red', ';');
$this->cWrite('blue', $param->serialize());
}
$this->cWrite('red', ':');
if ($property instanceof Property\Binary) {
$this->cWrite('default', 'embedded binary stripped. (' . strlen($property->getValue()) . ' bytes)');
} else {
$parts = $property->getParts();
$first1 = true;
// Looping through property values
foreach ($parts as $part) {
if ($first1) {
$first1 = false;
} else {
$this->cWrite('red', $property->delimiter);
}
$first2 = true;
// Looping through property sub-values
foreach ((array) $part as $subPart) {
if ($first2) {
$first2 = false;
} else {
// The sub-value delimiter is always comma
$this->cWrite('red', ',');
}
$subPart = strtr($subPart, ['\\' => $this->colorize('purple', '\\\\', 'green'), ';' => $this->colorize('purple', '\\;', 'green'), ',' => $this->colorize('purple', '\\,', 'green'), "\n" => $this->colorize('purple', "\\n\n\t", 'green'), "\r" => ""]);
$this->cWrite('green', $subPart);
}
}
}
$this->cWrite("default", "\n");
}
示例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;
}
示例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;
}