Changeset 5010 in subversion
- Timestamp:
- Aug 3, 2011 5:20:52 AM (22 months ago)
- Location:
- trunk/roundcubemail/program
- Files:
-
- 4 edited
-
include/rcube_contacts.php (modified) (1 diff)
-
include/rcube_vcard.php (modified) (10 diffs)
-
steps/addressbook/export.inc (modified) (1 diff)
-
steps/addressbook/import.inc (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/roundcubemail/program/include/rcube_contacts.php
r4932 r5010 582 582 $write_sql = array(); 583 583 $record = $this->get_record($id, true); 584 console($save_cols); 584 585 $save_cols = $this->convert_save_data($save_cols, $record); 585 586 console($save_cols); 586 587 foreach ($save_cols as $col => $value) { 587 588 $write_sql[] = sprintf("%s=%s", $this->db->quoteIdentifier($col), $this->db->quote($value)); -
trunk/roundcubemail/program/include/rcube_vcard.php
r5004 r5010 34 34 'N' => array(array('','','','','')), 35 35 ); 36 private $fieldmap = array(36 static private $fieldmap = array( 37 37 'phone' => 'TEL', 38 38 'birthday' => 'BDAY', … … 70 70 * Constructor 71 71 */ 72 public function __construct($vcard = null, $charset = RCMAIL_CHARSET, $detect = false) 73 { 72 public function __construct($vcard = null, $charset = RCMAIL_CHARSET, $detect = false, $fieldmap = array()) 73 { 74 if (!empty($fielmap)) 75 $this->extend_fieldmap($fieldmap); 76 74 77 if (!empty($vcard)) 75 78 $this->load($vcard, $charset, $detect); … … 147 150 148 151 // convert from raw vcard data into associative data for Roundcube 149 foreach (array_flip( $this->fieldmap) as $tag => $col) {152 foreach (array_flip(self::$fieldmap) as $tag => $col) { 150 153 foreach ((array)$this->raw[$tag] as $i => $raw) { 151 154 if (is_array($raw)) { 152 155 $k = -1; 153 156 $key = $col; 154 155 $subtype = $typemap[$raw['type'][++$k]] ? $typemap[$raw['type'][$k]] : strtolower($raw['type'][$k]); 156 while ($k < count($raw['type']) && ($subtype == 'internet' || $subtype == 'pref'))157 $subtype = ''; 158 159 if (!empty($raw['type'])) { 157 160 $subtype = $typemap[$raw['type'][++$k]] ? $typemap[$raw['type'][$k]] : strtolower($raw['type'][$k]); 161 while ($k < count($raw['type']) && ($subtype == 'internet' || $subtype == 'pref')) 162 $subtype = $typemap[$raw['type'][++$k]] ? $typemap[$raw['type'][$k]] : strtolower($raw['type'][$k]); 163 } 158 164 159 165 // read vcard 2.1 subtype … … 168 174 169 175 // force subtype if none set 170 if ( preg_match('/^(email|phone|address|website)/', $key) && !$subtype)176 if (!$subtype && preg_match('/^(email|phone|address|website)/', $key)) 171 177 $subtype = 'other'; 172 178 … … 221 227 { 222 228 if (!$fields) 223 $fields = array_merge(array_values( $this->fieldmap), array_keys($this->immap), array('FN','N','ORG','NICKNAME','EMAIL','ADR','BDAY'));229 $fields = array_merge(array_values(self::$fieldmap), array_keys($this->immap), array('FN','N','ORG','NICKNAME','EMAIL','ADR','BDAY')); 224 230 225 231 foreach ($fields as $f) … … 324 330 $type = $this->phonetypemap[$type]; 325 331 326 if (($tag = $this->fieldmap[$field]) && (is_array($value) || strlen($value))) {332 if (($tag = self::$fieldmap[$field]) && (is_array($value) || strlen($value))) { 327 333 $index = count($this->raw[$tag]); 328 334 $this->raw[$tag][$index] = (array)$value; … … 391 397 392 398 /** 399 * Extends fieldmap definition 400 */ 401 public function extend_fieldmap($map) 402 { 403 if (is_array($map)) 404 self::$fieldmap = array_merge($map, self::$fieldmap); 405 } 406 407 408 /** 393 409 * Factory method to import a vcard file 394 410 * … … 421 437 if (preg_match('/^END:VCARD$/i', $line)) { 422 438 // parse vcard 423 $obj = new rcube_vcard(self::cleanup($vcard_block), $charset, true );439 $obj = new rcube_vcard(self::cleanup($vcard_block), $charset, true, self::$fieldmap); 424 440 if (!empty($obj->displayname) || !empty($obj->email)) 425 441 $out[] = $obj; … … 621 637 } 622 638 639 // skip empty entries 640 if (self::is_empty($value)) 641 continue; 642 623 643 $vcard .= self::vcard_quote($type) . $attr . ':' . self::vcard_quote($value) . "\n"; 624 644 } … … 669 689 return strtr($s, array("\r" => '', '\\\\' => '\\', '\n' => "\n", '\N' => "\n", '\,' => ',', '\;' => ';', '\:' => ':')); 670 690 } 691 } 692 693 694 /** 695 * Check if vCard entry is empty: empty string or an array with 696 * all entries empty. 697 * 698 * @param mixed $value Attribute value (string or array) 699 * 700 * @return bool True if the value is empty, False otherwise 701 */ 702 private static function is_empty($value) 703 { 704 foreach ((array)$value as $v) { 705 if (((string)$v) !== '') { 706 return false; 707 } 708 } 709 710 return true; 671 711 } 672 712 -
trunk/roundcubemail/program/steps/addressbook/export.inc
r4850 r5010 78 78 // copy values into vcard object 79 79 else { 80 $vcard = new rcube_vcard($row['vcard']); 80 $vcard = new rcube_vcard(); 81 $vcard->extend_fieldmap($CONTACTS->vcard_map); 82 $vcard->load($row['vcard']); 81 83 $vcard->reset(); 82 84 -
trunk/roundcubemail/program/steps/addressbook/import.inc
r4890 r5010 139 139 140 140 // let rcube_vcard do the hard work :-) 141 $vcards = rcube_vcard::import(file_get_contents($_FILES['_file']['tmp_name'])); 141 $vcard_o = new rcube_vcard(); 142 $vcard_o->extend_fieldmap($CONTACTS->vcard_map); 143 144 $vcards = $vcard_o->import(file_get_contents($_FILES['_file']['tmp_name'])); 142 145 143 146 // no vcards detected
Note: See TracChangeset
for help on using the changeset viewer.
