/** * Returns the value of the specified attribute. * * @param string $attribute The attribute to retrieve. * * @return mixed The value of $attribute, an array (for photo type) * or the empty string. */ public function getValue($attribute) { global $attributes, $injector; if (isset($this->attributes[$attribute]) && ($hooks = $injector->getInstance('Horde_Core_Hooks')) && $hooks->hookExists('decode_attribute', 'turba')) { try { return $hooks->callHook('decode_attribute', 'turba', array($attribute, $this->attributes[$attribute], $this)); } catch (Turba_Exception $e) { } } elseif (isset($this->driver->map[$attribute]) && is_array($this->driver->map[$attribute])) { $args = array(); foreach ($this->driver->map[$attribute]['fields'] as $field) { $args[] = $this->getValue($field); } return Turba::formatCompositeField($this->driver->map[$attribute]['format'], $args); } elseif (!isset($this->attributes[$attribute])) { if (isset($attributes[$attribute]) && $attributes[$attribute]['type'] == 'Turba:TurbaTags' && ($uid = $this->getValue('__uid'))) { $this->synchronizeTags($injector->getInstance('Turba_Tagger')->getTags($uid, 'contact')); } else { return null; } } elseif (isset($attributes[$attribute]) && $attributes[$attribute]['type'] == 'image') { return empty($this->attributes[$attribute]) ? null : array('load' => array('data' => $this->attributes[$attribute], 'file' => basename(Horde::getTempFile('horde_form_', false, '', false, true)))); } return $this->attributes[$attribute]; }
/** * Function to convert a Horde_Icalendar_Vcard object into a Turba * Object Hash with Turba attributes suitable as a parameter for add(). * * @see add() * * @param Horde_Icalendar_Vcard $vcard The Horde_Icalendar_Vcard object * to parse. * * @return array A Turba attribute hash. */ public function toHash(Horde_Icalendar_Vcard $vcard) { $hash = array(); $attr = $vcard->getAllAttributes(); foreach ($attr as $item) { switch ($item['name']) { case 'UID': $hash['__uid'] = $item['value']; break; case 'FN': $hash['name'] = $item['value']; break; case 'N': $name = $item['values']; if (!empty($name[Horde_Icalendar_Vcard::N_FAMILY])) { $hash['lastname'] = $name[Horde_Icalendar_Vcard::N_FAMILY]; } if (!empty($name[Horde_Icalendar_Vcard::N_GIVEN])) { $hash['firstname'] = $name[Horde_Icalendar_Vcard::N_GIVEN]; } if (!empty($name[Horde_Icalendar_Vcard::N_ADDL])) { $hash['middlenames'] = $name[Horde_Icalendar_Vcard::N_ADDL]; } if (!empty($name[Horde_Icalendar_Vcard::N_PREFIX])) { $hash['namePrefix'] = $name[Horde_Icalendar_Vcard::N_PREFIX]; } if (!empty($name[Horde_Icalendar_Vcard::N_SUFFIX])) { $hash['nameSuffix'] = $name[Horde_Icalendar_Vcard::N_SUFFIX]; } break; case 'NICKNAME': case 'X-EPOCSECONDNAME': $hash['nickname'] = $item['value']; $hash['alias'] = $item['value']; break; // We use LABEL but also support ADR. // We use LABEL but also support ADR. case 'LABEL': if (isset($item['params']['HOME']) && !isset($hash['homeAddress'])) { $hash['homeAddress'] = $item['value']; } elseif (isset($item['params']['WORK']) && !isset($hash['workAddress'])) { $hash['workAddress'] = $item['value']; } elseif (!isset($hash['commonAddress'])) { $hash['commonAddress'] = $item['value']; } break; case 'ADR': if (isset($item['params']['TYPE'])) { if (!is_array($item['params']['TYPE'])) { $item['params']['TYPE'] = array($item['params']['TYPE']); } } else { $item['params']['TYPE'] = array(); if (isset($item['params']['WORK'])) { $item['params']['TYPE'][] = 'WORK'; } if (isset($item['params']['HOME'])) { $item['params']['TYPE'][] = 'HOME'; } if (count($item['params']['TYPE']) == 0) { $item['params']['TYPE'][] = 'COMMON'; } } $address = $item['values']; foreach ($item['params']['TYPE'] as $adr) { switch (Horde_String::upper($adr)) { case 'HOME': $prefix = 'home'; break; case 'WORK': $prefix = 'work'; break; default: $prefix = 'common'; } if (isset($hash[$prefix . 'Address'])) { continue; } $hash[$prefix . 'Address'] = ''; if (!empty($address[Horde_Icalendar_Vcard::ADR_STREET])) { $hash[$prefix . 'Street'] = $address[Horde_Icalendar_Vcard::ADR_STREET]; $hash[$prefix . 'Address'] .= $hash[$prefix . 'Street'] . "\n"; } if (!empty($address[Horde_Icalendar_Vcard::ADR_EXTEND])) { $hash[$prefix . 'Extended'] = $address[Horde_Icalendar_Vcard::ADR_EXTEND]; $hash[$prefix . 'Address'] .= $hash[$prefix . 'Extended'] . "\n"; } if (!empty($address[Horde_Icalendar_Vcard::ADR_POB])) { $hash[$prefix . 'POBox'] = $address[Horde_Icalendar_Vcard::ADR_POB]; $hash[$prefix . 'Address'] .= $hash[$prefix . 'POBox'] . "\n"; } if (!empty($address[Horde_Icalendar_Vcard::ADR_LOCALITY])) { $hash[$prefix . 'City'] = $address[Horde_Icalendar_Vcard::ADR_LOCALITY]; $hash[$prefix . 'Address'] .= $hash[$prefix . 'City']; } if (!empty($address[Horde_Icalendar_Vcard::ADR_REGION])) { $hash[$prefix . 'Province'] = $address[Horde_Icalendar_Vcard::ADR_REGION]; $hash[$prefix . 'Address'] .= ', ' . $hash[$prefix . 'Province']; } if (!empty($address[Horde_Icalendar_Vcard::ADR_POSTCODE])) { $hash[$prefix . 'PostalCode'] = $address[Horde_Icalendar_Vcard::ADR_POSTCODE]; $hash[$prefix . 'Address'] .= ' ' . $hash[$prefix . 'PostalCode']; } if (!empty($address[Horde_Icalendar_Vcard::ADR_COUNTRY])) { include 'Horde/Nls/Countries.php'; $country = array_search($address[Horde_Icalendar_Vcard::ADR_COUNTRY], $countries); if ($country === false) { $country = $address[Horde_Icalendar_Vcard::ADR_COUNTRY]; } $hash[$prefix . 'Country'] = $country; $hash[$prefix . 'Address'] .= "\n" . $address[Horde_Icalendar_Vcard::ADR_COUNTRY]; } $hash[$prefix . 'Address'] = trim($hash[$prefix . 'Address']); } break; case 'TZ': // We only support textual timezones. if (!isset($item['params']['VALUE']) || Horde_String::lower($item['params']['VALUE']) != 'text') { break; } $timezones = explode(';', $item['value']); $available_timezones = Horde_Nls::getTimezones(); foreach ($timezones as $timezone) { $timezone = trim($timezone); if (isset($available_timezones[$timezone])) { $hash['timezone'] = $timezone; break 2; } } break; case 'GEO': if (isset($item['params']['HOME'])) { $hash['homeLatitude'] = $item['value']['latitude']; $hash['homeLongitude'] = $item['value']['longitude']; } elseif (isset($item['params']['WORK'])) { $hash['workLatitude'] = $item['value']['latitude']; $hash['workLongitude'] = $item['value']['longitude']; } else { $hash['latitude'] = $item['value']['latitude']; $hash['longitude'] = $item['value']['longitude']; } break; case 'TEL': if (isset($item['params']['FAX'])) { if (isset($item['params']['WORK']) && !isset($hash['workFax'])) { $hash['workFax'] = $item['value']; } elseif (isset($item['params']['HOME']) && !isset($hash['homeFax'])) { $hash['homeFax'] = $item['value']; } elseif (!isset($hash['fax'])) { $hash['fax'] = $item['value']; } } elseif (isset($item['params']['PAGER']) && !isset($hash['pager'])) { $hash['pager'] = $item['value']; } elseif (isset($item['params']['TYPE'])) { if (!is_array($item['params']['TYPE'])) { $item['params']['TYPE'] = array($item['params']['TYPE']); } foreach ($item['params']['TYPE'] as &$type) { $type = Horde_String::upper($type); } // For vCard 3.0. if (in_array('CELL', $item['params']['TYPE'])) { if (in_array('HOME', $item['params']['TYPE']) && !isset($hash['homeCellPhone'])) { $hash['homeCellPhone'] = $item['value']; } elseif (in_array('WORK', $item['params']['TYPE']) && !isset($hash['workCellPhone'])) { $hash['workCellPhone'] = $item['value']; } elseif (!isset($hash['cellPhone'])) { $hash['cellPhone'] = $item['value']; } } elseif (in_array('FAX', $item['params']['TYPE'])) { if (in_array('HOME', $item['params']['TYPE']) && !isset($hash['homeFax'])) { $hash['homeFax'] = $item['value']; } elseif (in_array('WORK', $item['params']['TYPE']) && !isset($hash['workFax'])) { $hash['workFax'] = $item['value']; } elseif (!isset($hash['fax'])) { $hash['fax'] = $item['value']; } } elseif (in_array('VIDEO', $item['params']['TYPE'])) { if (in_array('HOME', $item['params']['TYPE']) && !isset($hash['homeVideoCall'])) { $hash['homeVideoCall'] = $item['value']; } elseif (in_array('WORK', $item['params']['TYPE']) && !isset($hash['workVideoCall'])) { $hash['workVideoCall'] = $item['value']; } elseif (!isset($hash['videoCall'])) { $hash['videoCall'] = $item['value']; } } elseif (in_array('PAGER', $item['params']['TYPE']) && !isset($hash['pager'])) { $hash['pager'] = $item['value']; } elseif (in_array('WORK', $item['params']['TYPE']) && !isset($hash['workPhone'])) { $hash['workPhone'] = $item['value']; } elseif (in_array('HOME', $item['params']['TYPE']) && !isset($hash['homePhone'])) { $hash['homePhone'] = $item['value']; } elseif (!isset($hash['phone'])) { $hash['phone'] = $item['value']; } } elseif (isset($item['params']['CELL'])) { if (isset($item['params']['WORK']) && !isset($hash['workCellPhone'])) { $hash['workCellPhone'] = $item['value']; } elseif (isset($item['params']['HOME']) && !isset($hash['homeCellPhone'])) { $hash['homeCellPhone'] = $item['value']; } elseif (!isset($hash['cellPhone'])) { $hash['cellPhone'] = $item['value']; } } elseif (isset($item['params']['VIDEO'])) { if (isset($item['params']['WORK']) && !isset($hash['workVideoCall'])) { $hash['workVideoCall'] = $item['value']; } elseif (isset($item['params']['HOME']) && !isset($hash['homeVideoCall'])) { $hash['homeVideoCall'] = $item['value']; } elseif (!isset($hash['videoCall'])) { $hash['videoCall'] = $item['value']; } } else { if (isset($item['params']['WORK']) && !isset($hash['workPhone'])) { $hash['workPhone'] = $item['value']; } elseif (isset($item['params']['HOME']) && !isset($hash['homePhone'])) { $hash['homePhone'] = $item['value']; } else { $hash['phone'] = $item['value']; } } break; case 'EMAIL': $email_set = false; if (isset($item['params']['HOME']) && (!isset($hash['homeEmail']) || isset($item['params']['PREF']))) { $e = Horde_Icalendar_Vcard::getBareEmail($item['value']); $hash['homeEmail'] = $e ? $e : ''; $email_set = true; } elseif (isset($item['params']['WORK']) && (!isset($hash['workEmail']) || isset($item['params']['PREF']))) { $e = Horde_Icalendar_Vcard::getBareEmail($item['value']); $hash['workEmail'] = $e ? $e : ''; $email_set = true; } elseif (isset($item['params']['TYPE'])) { if (!is_array($item['params']['TYPE'])) { $item['params']['TYPE'] = array($item['params']['TYPE']); } foreach ($item['params']['TYPE'] as &$type) { $type = Horde_String::upper($type); } if (in_array('HOME', $item['params']['TYPE']) && (!isset($hash['homeEmail']) || in_array('PREF', $item['params']['TYPE']))) { $e = Horde_Icalendar_Vcard::getBareEmail($item['value']); $hash['homeEmail'] = $e ? $e : ''; $email_set = true; } elseif (in_array('WORK', $item['params']['TYPE']) && (!isset($hash['workEmail']) || in_array('PREF', $item['params']['TYPE']))) { $e = Horde_Icalendar_Vcard::getBareEmail($item['value']); $hash['workEmail'] = $e ? $e : ''; $email_set = true; } } if (!$email_set && (!isset($hash['email']) || isset($item['params']['PREF']))) { $e = Horde_Icalendar_Vcard::getBareEmail($item['value']); $hash['email'] = $e ? $e : ''; } if (!isset($hash['emails'])) { $hash['emails'] = ''; } if ($e = Horde_Icalendar_Vcard::getBareEmail($item['value'])) { if (strlen($hash['emails'])) { $hash['emails'] .= ','; } $hash['emails'] .= $e; } break; case 'TITLE': $hash['title'] = $item['value']; break; case 'ROLE': $hash['role'] = $item['value']; break; case 'ORG': // The VCARD 2.1 specification requires the presence of two // SEMI-COLON separated fields: Organizational Name and // Organizational Unit. Additional fields are optional. $hash['company'] = !empty($item['values'][0]) ? $item['values'][0] : ''; $hash['department'] = !empty($item['values'][1]) ? $item['values'][1] : ''; break; case 'NOTE': $hash['notes'] = $item['value']; break; case 'CATEGORIES': $hash['businessCategory'] = $item['value']; $hash['__tags'] = $item['values']; break; case 'URL': if (isset($item['params']['HOME']) && !isset($hash['homeWebsite'])) { $hash['homeWebsite'] = $item['value']; } elseif (isset($item['params']['WORK']) && !isset($hash['workWebsite'])) { $hash['workWebsite'] = $item['value']; } elseif (!isset($hash['website'])) { $hash['website'] = $item['value']; } break; case 'BDAY': if (empty($item['value'])) { $hash['birthday'] = null; } else { $hash['birthday'] = $item['value']['year'] . '-' . $item['value']['month'] . '-' . $item['value']['mday']; } break; case 'PHOTO': case 'LOGO': if (isset($item['params']['VALUE']) && Horde_String::lower($item['params']['VALUE']) == 'uri') { // No support for URIs yet. break; } if (!isset($item['params']['ENCODING']) || Horde_String::lower($item['params']['ENCODING']) != 'b' && Horde_String::upper($item['params']['ENCODING']) != 'BASE64') { // Invalid property. break; } $type = Horde_String::lower($item['name']); $hash[$type] = base64_decode($item['value']); if (isset($item['params']['TYPE'])) { $hash[$type . 'type'] = $item['params']['TYPE']; } break; case 'X-SIP': if (isset($item['params']['POC']) && !isset($hash['ptt'])) { $hash['ptt'] = $item['value']; } elseif (isset($item['params']['VOIP']) && !isset($hash['voip'])) { $hash['voip'] = $item['value']; } elseif (isset($item['params']['SWIS']) && !isset($hash['shareView'])) { $hash['shareView'] = $item['value']; } elseif (!isset($hash['sip'])) { $hash['sip'] = $item['value']; } break; case 'X-WV-ID': $hash['imaddress'] = $item['value']; break; case 'X-ANNIVERSARY': if (empty($item['value'])) { $hash['anniversary'] = null; } else { $hash['anniversary'] = $item['value']['year'] . '-' . $item['value']['month'] . '-' . $item['value']['mday']; } break; case 'X-CHILDREN': $hash['children'] = $item['value']; break; case 'X-SPOUSE': $hash['spouse'] = $item['value']; break; } } /* Ensure we have a valid name field. */ if (empty($hash['name'])) { /* If name is a composite field, it won't be present in the * $this->fields array, so check for that as well. */ if (isset($this->map['name']) && is_array($this->map['name']) && !empty($this->map['name']['attribute'])) { $fieldarray = array(); foreach ($this->map['name']['fields'] as $mapfields) { $fieldarray[] = isset($hash[$mapfields]) ? $hash[$mapfields] : ''; } $hash['name'] = Turba::formatCompositeField($this->map['name']['format'], $fieldarray); } else { $hash['name'] = isset($hash['firstname']) ? $hash['firstname'] : ''; if (!empty($hash['lastname'])) { $hash['name'] .= ' ' . $hash['lastname']; } $hash['name'] = trim($hash['name']); } } // Ensure we have an 'email' field since we don't know for sure what // the source is, therefore we don't know the mappings available. Fixes // importing vCards that have all EMAIL properties with a TYPE // attribute. // See Bug: 12955 if (!isset($hash['email'])) { if (!empty($hash['homeEmail'])) { $hash['email'] = Horde_Icalendar_Vcard::getBareEmail($hash['homeEmail']); } else { if (!empty($hash['workEmail'])) { $hash['email'] = Horde_Icalendar_Vcard::getBareEmail($hash['workEmail']); } } } return $hash; }
/** * Extends parent function to build composed fields needed for the dn * based on the contents of $this->map. * * @param array $hash Hash using Turba keys. * * @return array Translated version of $hash. */ public function toDriverKeys(array $hash) { // First check for combined fields in the dn-fields and add them. if (is_array($this->_params['dn'])) { foreach ($this->_params['dn'] as $param) { foreach ($this->map as $turbaname => $ldapname) { if (is_array($ldapname) && isset($ldapname['attribute']) && $ldapname['attribute'] == $param) { $fieldarray = array(); foreach ($ldapname['fields'] as $mapfield) { $fieldarray[] = isset($hash[$mapfield]) ? $hash[$mapfield] : ''; } $hash[$turbaname] = Turba::formatCompositeField($ldapname['format'], $fieldarray); } } } } // Now convert the turba-fieldnames to ldap-fieldnames return parent::toDriverKeys($hash); }
/** * Returns the value of the specified attribute. * * @param string $attribute The attribute to retrieve. * * @return mixed The value of $attribute, an array (for photo type) * or the empty string. */ public function getValue($attribute) { global $attributes, $injector, $conf; if (isset($this->attributes[$attribute]) && ($hooks = $injector->getInstance('Horde_Core_Hooks')) && $hooks->hookExists('decode_attribute', 'turba')) { try { return $hooks->callHook('decode_attribute', 'turba', array($attribute, $this->attributes[$attribute], $this)); } catch (Turba_Exception $e) { } } elseif (isset($this->driver->map[$attribute]) && is_array($this->driver->map[$attribute])) { $args = array(); foreach ($this->driver->map[$attribute]['fields'] as $field) { $args[] = $this->getValue($field); } return Turba::formatCompositeField($this->driver->map[$attribute]['format'], $args); } elseif (isset($attributes[$attribute]) && $attributes[$attribute]['type'] == 'image') { // If there is no [$attribute], but we have a $attribute . '_orig', // then populate the $attribute data using default resizing config. if (empty($this->attributes[$attribute])) { if (!empty($this->attributes[$attribute . '_orig']) && (!empty($conf['photos']['height']) || !empty($conf['photos']['width']))) { // Do resizing $img = $injector->getInstance('Horde_Core_Factory_Image')->create(array('data' => $this->attributes[$attribute . '_orig'], 'type' => 'jpeg')); $img->resize($conf['photos']['width'], $conf['photos']['height']); $this->attributes[$attribute] = $img->raw(true); $this->store(); } } return empty($this->attributes[$attribute]) ? null : array('load' => array('data' => $this->attributes[$attribute], 'file' => basename(Horde::getTempFile('horde_form_', false, '', false, true)))); } elseif (!isset($this->attributes[$attribute])) { if (isset($attributes[$attribute]) && $attributes[$attribute]['type'] == 'Turba:TurbaTags' && ($uid = $this->getValue('__uid'))) { $this->synchronizeTags($injector->getInstance('Turba_Tagger')->getTags($uid, 'contact')); } else { return null; } } return $this->attributes[$attribute]; }