X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fvcard.inc.php;h=0671343f40ddface5cacec1ef4600f270bb263d5;hb=bd4f648ba40d48ad6bf8b60d5707f2a9324c450c;hp=bec45bbe16108e36fa0c03925c07935d14856621;hpb=29b12e6ef20d42ac06842bf65fb47277bcc91a4d;p=platal.git diff --git a/include/vcard.inc.php b/include/vcard.inc.php index bec45bb..0671343 100644 --- a/include/vcard.inc.php +++ b/include/vcard.inc.php @@ -1,6 +1,6 @@ user_list[] = get_user_forlife($user); - $this->count++; + $user = User::getSilent($user); + if ($user) { + $this->user_list[] = $user; + $this->count++; + } } public function first() @@ -63,7 +65,7 @@ class VCardIterator } global $globals; $login = array_shift($this->user_list); - $user = get_user_details($login); + $user = get_user_details($login->login()); if (strlen(trim($user['freetext']))) { $user['freetext'] = pl_entity_decode($user['freetext']); @@ -84,20 +86,19 @@ class VCardIterator INNER JOIN auth_user_quick ON ( user_id = {?} AND emails_alias_pub = 'public' ) WHERE ( redirect={?} OR redirect={?} ) AND alias LIKE '%@{$globals->mail->alias_dom}'", - S::v('uid'), + $user['user_id'], $user['forlife'].'@'.$globals->mail->domain, $user['forlife'].'@'.$globals->mail->domain2); - + $user['virtualalias'] = $res->fetchOneCell(); - $user['gpxs_vcardjoin'] = join(',', array_map(array('VCard', 'text_encode'), $user['gpxs_name'])); - $user['binets_vcardjoin'] = join(',', array_map(array('VCard', 'text_encode'), $user['binets'])); + $user['gpxs_vcardjoin'] = join(', ', array_map(array('VCard', 'text_encode'), $user['gpxs_name'])); + $user['binets_vcardjoin'] = join(', ', array_map(array('VCard', 'text_encode'), $user['binets'])); // get photo if ($this->photos) { $res = XDB::query( - "SELECT attach, attachmime - FROM photo AS p - INNER JOIN aliases AS a ON (a.id = p.uid AND a.type = 'a_vie') - WHERE a.alias = {?}", $login); + "SELECT attach, attachmime + FROM photo AS p + WHERE u.user_id = {?}", $login->id()); if ($res->numRows()) { $user['photo'] = $res->fetchOneAssoc(); } @@ -108,11 +109,13 @@ class VCardIterator 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 +127,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 +142,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 +157,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) @@ -163,7 +173,6 @@ class VCard header("Pragma: "); header("Cache-Control: "); header("Content-type: text/x-vcard; charset=UTF-8"); - header("Content-Transfer-Encoding: 8bit"); } }