Fucking ugly hack to make vcard works properly on the fucking ugly Windows.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 15 Sep 2007 16:55:33 +0000 (18:55 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 15 Sep 2007 16:55:33 +0000 (18:55 +0200)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
include/vcard.inc.php

index f357f74..f858b8a 100644 (file)
@@ -108,11 +108,13 @@ class VCardIterator implements PlIterator
 
 class VCard
 {
+    static private $windows = false;
     private $iterator = null;
 
     public function __construct($users, $photos = true, $freetext = null)
     {
         $this->iterator = new VCardIterator($photos, $freetext);
+        VCard::$windows  = (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false);
         if (is_array($users)) {
             foreach ($users as $user) {
                 $this->iterator->add_user($user);
@@ -124,7 +126,11 @@ class VCard
 
     public static function escape($text)
     {
-        return preg_replace('/[,;]/', '\\\\$0', $text);
+        if (VCard::$windows) {
+            return preg_replace('/;/', '\\\\$0', $text);
+        } else {
+            return preg_replace('/[,;]/', '\\\\$0', $text);
+        }
     }
 
     public static function format_adr($params, &$smarty)
@@ -150,6 +156,9 @@ class VCard
         if ($escape) {
             $text = VCard::escape($text);
         }
+        if (VCard::$windows) {
+            $text = utf8_decode($text);
+        }
         return preg_replace("/(\r\n|\n|\r)/", '\n', $text);
     }