[Svn] r4231 - in branches/devel-addressbook: program/include program/steps/addressbook skins/default

trac at roundcube.net trac at roundcube.net
Wed Nov 17 14:35:58 CET 2010


Author: thomasb
Date: 2010-11-17 07:35:58 -0600 (Wed, 17 Nov 2010)
New Revision: 4231

Modified:
   branches/devel-addressbook/program/include/rcube_contacts.php
   branches/devel-addressbook/program/include/rcube_vcard.php
   branches/devel-addressbook/program/steps/addressbook/func.inc
   branches/devel-addressbook/program/steps/addressbook/show.inc
   branches/devel-addressbook/skins/default/addressbook.css
Log:
Improve vcard field name assignments

Modified: branches/devel-addressbook/program/include/rcube_contacts.php
===================================================================
--- branches/devel-addressbook/program/include/rcube_contacts.php	2010-11-17 12:50:33 UTC (rev 4230)
+++ branches/devel-addressbook/program/include/rcube_contacts.php	2010-11-17 13:35:58 UTC (rev 4231)
@@ -482,7 +482,7 @@
         
         if ($sql_arr['vcard']) {
           $vcard = new rcube_vcard($sql_arr['vcard']);
-          $record += $vcard->get_assoc();
+          $record += $vcard->get_assoc() + $sql_arr;
         }
         else
           $record += $sql_arr;

Modified: branches/devel-addressbook/program/include/rcube_vcard.php
===================================================================
--- branches/devel-addressbook/program/include/rcube_vcard.php	2010-11-17 12:50:33 UTC (rev 4230)
+++ branches/devel-addressbook/program/include/rcube_vcard.php	2010-11-17 13:35:58 UTC (rev 4231)
@@ -33,6 +33,7 @@
     'N' => array(array('','','','','')),
   );
   private $fieldmap = array('phone' => 'TEL', 'birthday' => 'BDAY', 'website' => 'URL', 'notes' => 'NOTE', 'email' => 'EMAIL', 'address' => 'ADR');
+  private $typemap = array('iPhone' => 'mobile', 'CELL' => 'mobile');
 
   public $business = false;
   public $displayname;
@@ -105,21 +106,25 @@
   public function get_assoc()
   {
     $out = array('name' => $this->displayname);
+    $typemap = $this->typemap;
     
+    // copy name fields to output array
     foreach (array('firstname','surname','middlename','nickname','organization') as $col)
       $out[$col] = $this->$col;
     
+    // convert from raw vcard data into associative data for Roundcube
     foreach (array_flip($this->fieldmap) as $tag => $col) {
       foreach ((array)$this->raw[$tag] as $i => $raw) {
         if (is_array($raw)) {
-          $k = 0;
+          $k = -1;
           $key = $col;
-          $subtype = strtolower($raw['type'][$k++]);
+          $subtype = $typemap[$raw['type'][++$k]] ?: strtolower($raw['type'][$k]);
           while ($k < count($raw['type']) && ($subtype == 'internet' || $subtype == 'pref'))
-            $subtype = strtolower($raw['type'][$k++]);
+            $subtype = $typemap[$raw['type'][++$k]] ?: strtolower($raw['type'][$k]);
           if ($subtype)
             $key .= ':' . $subtype;
-            
+
+          // split ADR values into assoc array
           if ($tag == 'ADR') {
             list(,, $value['street'], $value['locality'], $value['region'], $value['zipcode'], $value['country']) = $raw;
             $out[$key][] = $value;
@@ -133,6 +138,13 @@
       }
     }
     
+    // handle special IM fields as used by Apple
+    foreach (array('X-JABBER' => 'jabber', 'X-ICQ' => 'icq', 'X-MSN' => 'msn', 'X-AIM' => 'aim', 'X-YAHOO' => 'yahoo') as $tag => $type) {
+      foreach ((array)$this->raw[$tag] as $i => $raw) {
+        $out['im:'.$type][] = $raw[0];
+      }
+    }
+    
     return $out;
   }
 
@@ -151,11 +163,12 @@
    *
    * @param string Field name
    * @param string Field value
-   * @param string Section name
+   * @param string Type/section name
    */
-  public function set($field, $value, $section = 'HOME')
+  public function set($field, $value, $type = 'HOME')
   {
     static $touched = array();
+    $typemap = array_flip($this->typemap);
     
     switch ($field) {
       case 'name':
@@ -183,7 +196,7 @@
         if (!$touched['EMAIL']++)
           $this->raw['EMAIL'] = array();
         $index = count($this->raw['EMAIL']);
-        $this->raw['EMAIL'][$index] = array(0 => $value, 'type' => array_filter(array('INTERNET', $section)));
+        $this->raw['EMAIL'][$index] = array(0 => $value, 'type' => array_filter(array('INTERNET', $type)));
         break;
 
       case 'address':
@@ -196,8 +209,8 @@
             $this->raw[$tag] = array();
           $index = count($this->raw[$tag]);
           $this->raw[$tag][$index] = (array)$value;
-          if ($section)
-            $this->raw[$tag][$index]['type'] = array($section);
+          if ($type)
+            $this->raw[$tag][$index]['type'] = array(($typemap[$type] ?: $type));
         }
         break;
     }

Modified: branches/devel-addressbook/program/steps/addressbook/func.inc
===================================================================
--- branches/devel-addressbook/program/steps/addressbook/func.inc	2010-11-17 12:50:33 UTC (rev 4230)
+++ branches/devel-addressbook/program/steps/addressbook/func.inc	2010-11-17 13:35:58 UTC (rev 4231)
@@ -310,7 +310,7 @@
                 foreach ($colnames as $col) {
                     if ($RCMAIL->action == 'show') {
                         if (!empty($record[$col]))
-                            $fields .= html::span('namefield', Q($record[$col])) . " ";
+                            $fields .= html::span('namefield ' . $col, Q($record[$col])) . " ";
                     }
                     else {
                         $colprop = (array)$fieldset['content'][$col] + (array)$coltypes[$col];

Modified: branches/devel-addressbook/program/steps/addressbook/show.inc
===================================================================
--- branches/devel-addressbook/program/steps/addressbook/show.inc	2010-11-17 12:50:33 UTC (rev 4230)
+++ branches/devel-addressbook/program/steps/addressbook/show.inc	2010-11-17 13:35:58 UTC (rev 4231)
@@ -73,7 +73,7 @@
               'phone' => array('size' => $i_size),
               'address' => array(),
               'birthday' => array('size' => $i_size),
-              'website' => array('size' => $i_size),
+              'website' => array('size' => $i_size, 'value' => array()),
               'im' => array('size' => $i_size),
             ),
         ),
@@ -88,7 +88,7 @@
             'content' => rcmail_contact_record_groups($record['ID']),
         ),
     );
-    
+/* FIXME: this destroys subtype assignments
     foreach ((array)$record as $field => $values) {
         if (strpos($field, 'email') === 0) {
             foreach ((array)$values as $email) {
@@ -100,8 +100,18 @@
                 ), Q($email));
             }
         }
+        else if (strpos($field, 'website') === 0) {
+            foreach ((array)$values as $url) {
+                $prefix = preg_match('![htfps]+://!', $url) ? '' : 'http://';
+                $form['info']['content']['website']['value'][] = html::a(array(
+                    'href' => $prefix . $url,
+                    'target' => '_blank',
+                    'class' => 'url',
+                ), Q($url));
+            }
+        }
     }
-
+*/
     return rcmail_contact_form($form, $record);
 }
 

Modified: branches/devel-addressbook/skins/default/addressbook.css
===================================================================
--- branches/devel-addressbook/skins/default/addressbook.css	2010-11-17 12:50:33 UTC (rev 4230)
+++ branches/devel-addressbook/skins/default/addressbook.css	2010-11-17 13:35:58 UTC (rev 4231)
@@ -238,7 +238,7 @@
 	padding: 0;
 }
 
-#contacthead span.namefield,
+#contacthead .names span.namefield,
 #contacthead input.ff_firstname,
 #contacthead input.ff_surname,
 #contacthead input.ff_middlename
@@ -246,6 +246,12 @@
 	font-size: 140%;
 }
 
+#contacthead span.nickname:before,
+#contacthead span.nickname:after
+{
+	content: '"';
+}
+
 #contacthead input
 {
 	margin-right: 6px;

_______________________________________________
http://lists.roundcube.net/mailman/listinfo/svn



More information about the Svn mailing list