| | |
| | | +-----------------------------------------------------------------------+ |
| | | | Author: Thomas Bruederli <roundcube@gmail.com> | |
| | | +-----------------------------------------------------------------------+ |
| | | |
| | | $Id$ |
| | | |
| | | */ |
| | | |
| | | |
| | | /** |
| | | * Abstract skeleton of an address book/repository |
| | | * |
| | | * @package Addressbook |
| | | * @package Framework |
| | | * @subpackage Addressbook |
| | | */ |
| | | abstract class rcube_addressbook |
| | | { |
| | |
| | | // check validity of email addresses |
| | | foreach ($this->get_col_values('email', $save_data, true) as $email) { |
| | | if (strlen($email)) { |
| | | if (!$rcmail->check_email(rcube_idn_to_ascii($email))) { |
| | | if (!rcube_utils::check_email(rcube_utils::idn_to_ascii($email))) { |
| | | $error = $rcmail->gettext(array('name' => 'emailformaterror', 'vars' => array('email' => $email))); |
| | | $this->set_error(self::ERROR_VALIDATE, $error); |
| | | return false; |
| | |
| | | function get_col_values($col, $data, $flat = false) |
| | | { |
| | | $out = array(); |
| | | foreach ($data as $c => $values) { |
| | | foreach ((array)$data as $c => $values) { |
| | | if ($c === $col || strpos($c, $col.':') === 0) { |
| | | if ($flat) { |
| | | $out = array_merge($out, (array)$values); |
| | |
| | | $out[$type] = array_merge((array)$out[$type], (array)$values); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // remove duplicates |
| | | if ($flat && !empty($out)) { |
| | | $out = array_unique($out); |
| | | } |
| | | |
| | | return $out; |
| | |
| | | * |
| | | * @param string Input string (UTF-8) |
| | | * @return string Normalized string |
| | | * @deprecated since 0.9-beta |
| | | */ |
| | | protected static function normalize_string($str) |
| | | { |
| | | // split by words |
| | | $arr = explode(" ", preg_replace( |
| | | array('/[\s;\+\-\/]+/i', '/(\d)[-.\s]+(\d)/', '/\s\w{1,3}\s/'), |
| | | array(' ', '\\1\\2', ' '), |
| | | $str)); |
| | | |
| | | foreach ($arr as $i => $part) { |
| | | if (utf8_encode(utf8_decode($part)) == $part) { // is latin-1 ? |
| | | $arr[$i] = utf8_encode(strtr(strtolower(strtr(utf8_decode($part), |
| | | 'ÇçäâàåéêëèïîìÅÉöôòüûùÿøØáíóúñÑÁÂÀãÃÊËÈÍÎÏÓÔõÕÚÛÙýÝ', |
| | | 'ccaaaaeeeeiiiaeooouuuyooaiounnaaaaaeeeiiioooouuuyy')), |
| | | array('ß' => 'ss', 'ae' => 'a', 'oe' => 'o', 'ue' => 'u'))); |
| | | } |
| | | else |
| | | $arr[$i] = mb_strtolower($part); |
| | | } |
| | | |
| | | return join(" ", $arr); |
| | | return rcube_utils::normalize_string($str); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Compose a valid display name from the given structured contact data |
| | |
| | | $fn = $contact['name']; |
| | | |
| | | if (!$fn) // default display name composition according to vcard standard |
| | | $fn = join(' ', array_filter(array($contact['prefix'], $contact['firstname'], $contact['middlename'], $contact['surname'], $contact['suffix']))); |
| | | $fn = trim(join(' ', array_filter(array($contact['prefix'], $contact['firstname'], $contact['middlename'], $contact['surname'], $contact['suffix'])))); |
| | | |
| | | // use email address part for name |
| | | $email = is_array($contact['email']) ? $contact['email'][0] : $contact['email']; |