private function convert_save_data($save_data, $record = array())
 {
     $out = array();
     $words = '';
     // copy values into vcard object
     $vcard = new rcube_vcard($record['vcard'] ? $record['vcard'] : $save_data['vcard']);
     $vcard->reset();
     foreach ($save_data as $key => $values) {
         list($field, $section) = explode(':', $key);
         $fulltext = in_array($field, $this->fulltext_cols);
         // avoid casting DateTime objects to array
         if (is_object($values) && is_a($values, 'DateTime')) {
             $values = array(0 => $values);
         }
         foreach ((array) $values as $value) {
             if (isset($value)) {
                 $vcard->set($field, $value, $section);
             }
             if ($fulltext && is_array($value)) {
                 $words .= ' ' . rcube_utils::normalize_string(join(" ", $value));
             } else {
                 if ($fulltext && strlen($value) >= 3) {
                     $words .= ' ' . rcube_utils::normalize_string($value);
                 }
             }
         }
     }
     $out['vcard'] = $vcard->export(false);
     foreach ($this->table_cols as $col) {
         $key = $col;
         if (!isset($save_data[$key])) {
             $key .= ':home';
         }
         if (isset($save_data[$key])) {
             if (is_array($save_data[$key])) {
                 $out[$col] = join(self::SEPARATOR, $save_data[$key]);
             } else {
                 $out[$col] = $save_data[$key];
             }
         }
     }
     // save all e-mails in database column
     $out['email'] = join(self::SEPARATOR, $vcard->email);
     // join words for fulltext search
     $out['words'] = join(" ", array_unique(explode(" ", $words)));
     return $out;
 }
Esempio n. 2
0
 /**
  * Get vcard data for specified contact
  */
 private function get_contact_vcard($source, $cid, &$filename = null)
 {
     $rcmail = rcmail::get_instance();
     $source = $rcmail->get_address_book($source);
     $contact = $source->get_record($cid, true);
     if ($contact) {
         $fieldmap = $source ? $source->vcard_map : null;
         if (empty($contact['vcard'])) {
             $vcard = new rcube_vcard('', RCUBE_CHARSET, false, $fieldmap);
             $vcard->reset();
             foreach ($contact as $key => $values) {
                 list($field, $section) = explode(':', $key);
                 // avoid unwanted casting of DateTime objects to an array
                 // (same as in rcube_contacts::convert_save_data())
                 if (is_object($values) && is_a($values, 'DateTime')) {
                     $values = array($values);
                 }
                 foreach ((array) $values as $value) {
                     if (is_array($value) || is_a($value, 'DateTime') || @strlen($value)) {
                         $vcard->set($field, $value, strtoupper($section));
                     }
                 }
             }
             $contact['vcard'] = $vcard->export();
         }
         $name = rcube_addressbook::compose_list_name($contact);
         $filename = (self::parse_filename($name) ?: 'contact') . '.vcf';
         // fix folding and end-of-line chars
         $vcard = preg_replace('/\\r|\\n\\s+/', '', $contact['vcard']);
         $vcard = preg_replace('/\\n/', rcube_vcard::$eol, $vcard);
         return rcube_vcard::rfc2425_fold($vcard) . rcube_vcard::$eol;
     }
 }