Exemplo n.º 1
0
 /**
  * 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");
 }
Exemplo n.º 2
0
 /**
  * @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;
 }
Exemplo n.º 3
0
 /**
  * @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;
 }