| | |
| | | /** |
| | | * CSV to vCard data converter |
| | | * |
| | | * @package Roundcube Framework |
| | | * @author Aleksander Machniak <alec@alec.pl> |
| | | * @package Framework |
| | | * @subpackage Addressbook |
| | | * @author Aleksander Machniak <alec@alec.pl> |
| | | */ |
| | | class rcube_csv2vcard |
| | | { |
| | |
| | | //'company_main_phone' => '', |
| | | 'department' => 'department', |
| | | //'email_2_address' => '', //@TODO |
| | | //'email_2_type' => '', //@TODO |
| | | //'email_2_type' => '', |
| | | //'email_3_address' => '', //@TODO |
| | | //'email_3_type' => '', //@TODO |
| | | //'email_3_type' => '', |
| | | 'email_address' => 'email:main', |
| | | //'email_type' => '', //@TODO |
| | | //'email_type' => '', |
| | | 'first_name' => 'firstname', |
| | | 'gender' => 'gender', |
| | | 'home_city' => 'locality:home', |
| | |
| | | //'company_main_phone' => "Company Main Phone", |
| | | 'department' => "Department", |
| | | //'directory_server' => "Directory Server", |
| | | //'email_2_address' => "E-mail 2 Address", //@TODO |
| | | //'email_2_type' => "E-mail 2 Type", //@TODO |
| | | //'email_3_address' => "E-mail 3 Address", //@TODO |
| | | //'email_3_type' => "E-mail 3 Type", //@TODO |
| | | //'email_2_address' => "E-mail 2 Address", |
| | | //'email_2_type' => "E-mail 2 Type", |
| | | //'email_3_address' => "E-mail 3 Address", |
| | | //'email_3_type' => "E-mail 3 Type", |
| | | 'email_address' => "E-mail Address", |
| | | //'email_type' => "E-mail Type", //@TODO |
| | | //'email_type' => "E-mail Type", |
| | | 'first_name' => "First Name", |
| | | 'gender' => "Gender", |
| | | 'home_city' => "Home City", |
| | |
| | | 'work_zipcode' => "Work ZipCode", |
| | | ); |
| | | |
| | | protected $local_label_map = array(); |
| | | protected $vcards = array(); |
| | | protected $map = array(); |
| | | protected $map = array(); |
| | | |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | if (!empty($map)) { |
| | | $this->label_map = array_merge($this->label_map, $map); |
| | | $this->local_label_map = array_merge($this->label_map, $map); |
| | | } |
| | | } |
| | | |
| | | $this->label_map = array_flip($this->label_map); |
| | | $this->local_label_map = array_flip($this->local_label_map); |
| | | } |
| | | |
| | | /** |
| | |
| | | * Parse CSV header line, detect fields mapping |
| | | */ |
| | | protected function parse_header($elements) |
| | | { |
| | | for ($i = 0, $size = count($elements); $i<$size; $i++) { |
| | | { |
| | | $map1 = array(); |
| | | $map2 = array(); |
| | | $size = count($elements); |
| | | |
| | | // check English labels |
| | | for ($i = 0; $i < $size; $i++) { |
| | | $label = $this->label_map[$elements[$i]]; |
| | | if ($label && !empty($this->csv2vcard_map[$label])) { |
| | | $this->map[$i] = $this->csv2vcard_map[$label]; |
| | | $map1[$i] = $this->csv2vcard_map[$label]; |
| | | } |
| | | } |
| | | // check localized labels |
| | | if (!empty($this->local_label_map)) { |
| | | for ($i = 0; $i < $size; $i++) { |
| | | $label = $this->local_label_map[$elements[$i]]; |
| | | if ($label && !empty($this->csv2vcard_map[$label])) { |
| | | $map2[$i] = $this->csv2vcard_map[$label]; |
| | | } |
| | | } |
| | | } |
| | | |
| | | $this->map = count($map1) >= count($map2) ? $map1 : $map2; |
| | | } |
| | | |
| | | /** |
| | |
| | | $contact['birthday'] = $contact['birthday-y'] .'-' .$contact['birthday-m'] . '-' . $contact['birthday-d']; |
| | | } |
| | | |
| | | foreach (array('birthday', 'anniversary') as $key) { |
| | | if (!empty($contact[$key]) && $contact[$key] == '0/0/00') { // @TODO: localization? |
| | | unset($contact[$key]); |
| | | } |
| | | } |
| | | |
| | | if (!empty($contact['gender']) && ($gender = strtolower($contact['gender']))) { |
| | | if (!in_array($gender, array('male', 'female'))) { |
| | | unset($contact['gender']); |
| | | } |
| | | } |
| | | |
| | | // Create vcard object |
| | | $vcard = new rcube_vcard(); |
| | | foreach ($contact as $name => $value) { |