994ca8d5bc9c1a0af1627230d14372dc31da1eee
2 /***************************************************************************
3 * Copyright (C) 2003-2007 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 require_once('xorg.misc.inc.php');
23 require_once('user.func.inc.php');
30 function VCard($users, $photos = true
, $freetext = null
)
32 $this->photos
= $photos;
33 if (is_array($users)) {
34 foreach ($users as $user) {
35 $this->add_user($user, $freetext);
38 $this->add_user($users, $freetext);
42 function escape($text)
44 return preg_replace('/[,;:]/', '\\\\$0', $text);
47 function format_adr($params, &$smarty)
49 // $adr1, $adr2, $adr3, $postcode, $city, $region, $country
50 extract($params['adr']);
52 $adr = trim("$adr\n$adr2");
53 $adr = trim("$adr\n$adr3");
54 return $this->text_encode(';;'
55 . $this->escape($adr) . ';'
56 . $this->escape($city) . ';'
57 . $this->escape($region) . ';'
58 . $this->escape($postcode) . ';'
59 . $this->escape($country), false
);
62 function text_encode($text, $escape = true
)
64 if (is_array($text)) {
65 return implode(',', array_map(array($this, 'text_encode'), $text));
68 $text = $this->escape($text);
70 return preg_replace("/(\r\n|\n|\r)/", '\n', $text);
73 function add_user($x, $freetext)
77 $login = get_user_forlife($x);
78 $user = get_user_details($login);
80 if (strlen(trim($user['freetext']))) {
81 $user['freetext'] = html_entity_decode($user['freetext']);
83 if (!is_null($freetext)) {
84 if (strlen(trim($user['freetext']))) {
85 $user['freetext'] = $freetext . "\n" . $user['freetext'];
87 $user['freetext'] = $freetext;
95 INNER JOIN virtual_redirect USING(vid)
96 INNER JOIN auth_user_quick ON ( user_id = {?} AND emails_alias_pub = 'public' )
97 WHERE ( redirect={?} OR redirect={?} )
98 AND alias LIKE '%@{$globals->mail->alias_dom}'",
100 $user['forlife'].'@'.$globals->mail
->domain
,
101 $user['forlife'].'@'.$globals->mail
->domain2
);
103 $user['virtualalias'] = $res->fetchOneCell();
104 $user['gpxs_vcardjoin'] = join(',', array_map(array($this, 'text_encode'), $user['gpxs_name']));
105 $user['binets_vcardjoin'] = join(',', array_map(array($this, 'text_encode'), $user['binets']));
109 "SELECT attach, attachmime
111 INNER JOIN aliases AS a ON (a.id = p.uid AND a.type = 'a_vie')
112 WHERE a.alias = {?}", $login);
113 if ($res->numRows()) {
114 $user['photo'] = $res->fetchOneAssoc();
117 $this->users
[] = $user;
120 function do_page(&$page)
122 $page->changeTpl('core/vcard.tpl', NO_SKIN
);
123 $page->register_modifier('vcard_enc', array($this, 'text_encode'));
124 $page->register_function('format_adr', array($this, 'format_adr'));
125 $page->assign_by_ref('users', $this->users
);
128 header("Cache-Control: ");
129 header("Content-type: text/x-vcard; charset=iso-8859-15");
130 header("Content-Transfer-Encoding: 8bit");
134 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: