Fix splitting up names when exporting to N properties of vCards.
authorJan Schneider <jan@horde.org>
Mon, 17 Jan 2011 14:13:46 +0000 (15:13 +0100)
committerJan Schneider <jan@horde.org>
Mon, 17 Jan 2011 14:14:00 +0000 (15:14 +0100)
turba/docs/CHANGES
turba/lib/Driver.php

index b8bd31c..d561482 100644 (file)
@@ -16,6 +16,7 @@ v3.0-git
 v2.3.6-cvs
 ----------
 
+[jan] Fix splitting up names when exporting to N properties of vCards.
 [jan] Only set the encoding parameter for binary data in vCards, if data is not
       empty (Bug #9413).
 [jan] Fix searching for fields matching an email address if using 'emails'
index bedaeaf..ec8ef1b 100644 (file)
@@ -1617,16 +1617,14 @@ class Turba_Driver implements Countable
 
         // No explicit firstname/lastname in data source: we have to guess.
         if (!isset($hash['lastname']) && isset($hash['name'])) {
-            $i = strpos($hash['name'], ',');
-            if (is_int($i)) {
+            if (($pos = strpos($hash['name'], ',')) !== false) {
                 // Assume Last, First
-                $hash['lastname'] = Horde_String::substr($hash['name'], 0, $i);
-                $hash['firstname'] = trim(Horde_String::substr($hash['name'], $i + 1));
-            } elseif (is_int(strpos($hash['name'], ' '))) {
+                $hash['lastname'] = Horde_String::substr($hash['name'], 0, $pos);
+                $hash['firstname'] = trim(Horde_String::substr($hash['name'], $pos + 1));
+            } elseif (($pos = Horde_String::rpos($hash['name'], ' ')) !== false) {
                 // Assume everything after last space as lastname
-                $i = strrpos($hash['name'], ' ');
-                $hash['lastname'] = trim(Horde_String::substr($hash['name'], $i + 1));
-                $hash['firstname'] = Horde_String::substr($hash['name'], 0, $i);
+                $hash['lastname'] = trim(Horde_String::substr($hash['name'], $pos + 1));
+                $hash['firstname'] = Horde_String::substr($hash['name'], 0, $pos);
             } else {
                 $hash['lastname'] = $hash['name'];
                 $hash['firstname'] = '';