X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fvcard.inc.php;h=ebda6af26110e1acb3019887a62c23cbaa4a61df;hb=e6bf921624e50f7abdd9a1862d0b7ef4f1053090;hp=f357f74d638a3f516b9772bc879f5beef573120d;hpb=787bb3d745141f2f85bd947ad7dd775d2c63f908;p=platal.git diff --git a/include/vcard.inc.php b/include/vcard.inc.php index f357f74..ebda6af 100644 --- a/include/vcard.inc.php +++ b/include/vcard.inc.php @@ -1,6 +1,6 @@ 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 str_replace(';', '\\\\;', $text); + } else { + return str_replace(array(';', ','), array('\\\\;', '\\\\,'), $text); + } } public static function format_adr($params, &$smarty) @@ -135,11 +141,11 @@ class VCard $adr = trim("$adr\n$adr2"); $adr = trim("$adr\n$adr3"); return VCard::text_encode(';;' - . VCard::escape($adr) . ';' - . VCard::escape($city) . ';' - . VCard::escape($region) . ';' - . VCard::escape($postcode) . ';' - . VCard::escape($country), false); + . (VCard::$windows ? VCard::escape($adr) : $adr) . ';' + . (VCard::$windows ? VCard::escape($city) : $city) . ';' + . (VCard::$windows ? VCard::escape($region) : $region) . ';' + . (VCard::$windows ? VCard::escape($postcode) : $postcode) . ';' + . (VCard::$windows ? VCard::escape($country) : $country), false); } public static function text_encode($text, $escape = true) @@ -150,7 +156,10 @@ class VCard if ($escape) { $text = VCard::escape($text); } - return preg_replace("/(\r\n|\n|\r)/", '\n', $text); + if (VCard::$windows) { + $text = utf8_decode($text); + } + return str_replace(array("\r\n", "\n", "\r"), '\n', $text); } public function do_page(&$page)