/** * (non-PHPdoc) * @see Addressbook_Convert_Contact_VCard_Abstract::_toTine20ModelParseEmail() */ protected function _toTine20ModelParseEmail(&$data, \Sabre\VObject\Property $property, \Sabre\VObject\Component\VCard $vcard) { if ($vcard->{'X-OUTLOOK-EMAIL-2'} && $vcard->{'X-OUTLOOK-EMAIL-2'}->getValue() == $property->getValue()) { $data['email_home'] = $property->getValue(); } elseif ($vcard->{'X-OUTLOOK-EMAIL-3'} && $vcard->{'X-OUTLOOK-EMAIL-3'}->getValue() == $property->getValue()) { // we don't map email3 } else { $data['email'] = $property->getValue(); } }
/** * (non-PHPdoc) * @see Addressbook_Convert_Contact_VCard_Abstract::_toTine20ModelParseTel() */ protected function _toTine20ModelParseTel(&$data, \Sabre\VObject\Property $property) { if (!isset($property['TYPE'])) { // CardDAVSync sends OTHER just as TEL:12345678 without any TYPE $data['tel_other'] = $property->getValue(); } parent::_toTine20ModelParseTel($data, $property); }
/** * (non-PHPdoc) * @see Addressbook_Convert_Contact_VCard_Abstract::_toTine20ModelParseEmail() */ protected function _toTine20ModelParseEmail(&$data, \Sabre\VObject\Property $property, \Sabre\VObject\Component\VCard $vcard) { $type = null; if ($property['TYPE']) { if ($property['TYPE']->has('pref')) { $type = 'work'; } } switch ($type) { case 'work': $data['email'] = $property->getValue(); break; default: $data['email_home'] = $property->getValue(); break; } }
/** * (non-PHPdoc) * @see Addressbook_Convert_Contact_VCard_Abstract::_toTine20ModelParseTel() */ protected function _toTine20ModelParseTel(&$data, \Sabre\VObject\Property $property) { $telField = null; if (isset($property['TYPE'])) { // CELL if ($property['TYPE']->has('cell') && $property['TYPE']->has('voice') && !$property['TYPE']->has('iphone')) { $telField = 'tel_cell'; } elseif ($property['TYPE']->has('cell') && $property['TYPE']->has('iphone')) { $telField = 'tel_cell_private'; } } if (!empty($telField)) { $data[$telField] = $property->getValue(); } else { parent::_toTine20ModelParseTel($data, $property); } }
/** * @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; }
/** * 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"); }
/** * (non-PHPdoc) * @see Addressbook_Convert_Contact_VCard_Abstract::_toTine20ModelParseEmail() */ protected function _toTine20ModelParseEmail(&$data, \Sabre\VObject\Property $property, \Sabre\VObject\Component\VCard $vcard) { /* * eM Client supports three types of mail */ if ($property['TYPE']->has('home')) { $data['email_home'] = $property->getValue(); } elseif ($property['TYPE']->has('work') && $data['email'] == '') { $data['email'] = $property->getValue(); } elseif ($property['TYPE']->has('pref') || $data['email'] == '') { $data['email'] = $property->getValue(); } }
/** * parse birthday * * @param array $data * @param Sabre\VObject\Property $property */ protected function _toTine20ModelParseBday(&$_data, \Sabre\VObject\Property $_property) { $tzone = new DateTimeZone(Tinebase_Core::getUserTimezone()); $_data['bday'] = new Tinebase_DateTime($_property->getValue(), $tzone); $_data['bday']->setTimezone(new DateTimeZone('UTC')); }
/** * get datetime from sabredav datetime property (user TZ is fallback) * * @param Sabre\VObject\Property $dateTimeProperty * @param boolean $_useUserTZ * @return Tinebase_DateTime * * @todo try to guess some common timezones */ protected function _convertToTinebaseDateTime(\Sabre\VObject\Property $dateTimeProperty, $_useUserTZ = FALSE) { $defaultTimezone = date_default_timezone_get(); date_default_timezone_set((string) Tinebase_Core::getUserTimezone()); if ($dateTimeProperty instanceof Sabre\VObject\Property\ICalendar\DateTime) { $dateTime = $dateTimeProperty->getDateTime(); $tz = $_useUserTZ || isset($dateTimeProperty['VALUE']) && strtoupper($dateTimeProperty['VALUE']) == 'DATE' ? (string) Tinebase_Core::getUserTimezone() : $dateTime->getTimezone(); $result = new Tinebase_DateTime($dateTime->format(Tinebase_Record_Abstract::ISO8601LONG), $tz); } else { $result = new Tinebase_DateTime($dateTimeProperty->getValue()); } date_default_timezone_set($defaultTimezone); return $result; }
/** * Decode properties for upgrading from v. 2.1 * * @param \Sabre\VObject\Property $property Reference to a \Sabre\VObject\Property. * The only encoding allowed in version 3.0 is 'b' for binary. All encoded strings * must therefore be decoded and the parameters removed. */ protected function decodeProperty(&$property) { foreach ($property->parameters as $key => &$parameter) { // Check for values without names which Sabre interprets // as names without values. if (trim($parameter->getValue()) === '') { $parameter->setValue($parameter->name); $parameter->name = $this->paramName($parameter->name); } // Check out for encoded string and decode them :-[ if (strtoupper($parameter->name) == 'ENCODING') { if (strtoupper($parameter->getValue()) == 'QUOTED-PRINTABLE') { $property->setValue(str_replace("\r\n", "\n", VObject\StringUtil::convertToUTF8(quoted_printable_decode($property->getValue())))); unset($property->parameters[$key]); } elseif (strtoupper($parameter->getValue()) == 'BASE64') { $parameter->setValue('b'); } } elseif (strtoupper($parameter->name) == 'CHARSET') { unset($property->parameters[$key]); } } }
/** * parse email address field * * @param array $data reference to tine20 data array * @param \Sabre\VObject\Property $property mail property * @param \Sabre\VObject\Component\VCard $vcard vcard object */ protected function _toTine20ModelParseEmail(&$data, \Sabre\VObject\Property $property, \Sabre\VObject\Component\VCard $vcard) { foreach ($property['TYPE'] as $typeProperty) { if (strtolower($typeProperty) == 'internet') { if (empty($data['email'])) { // do not replace existing value; this will first get the primary email mapped to work $data['email'] = $property->getValue(); } else { // secondary email goes to private $data['email_home'] = $property->getValue(); } } } }