2 /***************************************************************************
3 * Copyright (C) 2003-2006 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');
29 function VCard($users, $freetext = null
)
31 if (is_array($users)) {
32 foreach ($users as $user) {
33 $this->add_user($user, $freetext);
36 $this->add_user($users, $freetext);
40 function escape($text)
42 return preg_replace('/[,;:]/', '\\\\$0', $text);
45 function format_adr($params, &$smarty)
47 // $adr1, $adr2, $adr3, $postcode, $city, $region, $country
48 extract($params['adr']);
50 $adr = trim("$adr\n$adr2");
51 $adr = trim("$adr\n$adr3");
52 return $this->text_encode(';;'
53 . $this->escape($adr) . ';'
54 . $this->escape($city) . ';'
55 . $this->escape($region) . ';'
56 . $this->escape($postcode) . ';'
57 . $this->escape($country), false
);
60 function text_encode($text, $escape = true
)
63 $text = $this->escape($text);
65 return preg_replace("/(\r\n|\n|\r)/", '\n', $text);
68 function add_user($x, $freetext)
72 $login = get_user_forlife($x);
73 $user = get_user_details($login);
75 if (strlen(trim($user['freetext']))) {
76 $user['freetext'] = html_entity_decode($user['freetext']);
78 if (!is_null($freetext)) {
79 if (strlen(trim($user['freetext']))) {
80 $user['freetext'] = $freetext . "\n" . $user['freetext'];
82 $user['freetext'] = $freetext;
90 INNER JOIN virtual_redirect USING(vid)
91 INNER JOIN auth_user_quick ON ( user_id = {?} AND emails_alias_pub = 'public' )
92 WHERE ( redirect={?} OR redirect={?} )
93 AND alias LIKE '%@{$globals->mail->alias_dom}'",
95 $user['forlife'].'@'.$globals->mail
->domain
,
96 $user['forlife'].'@'.$globals->mail
->domain2
);
98 $user['virtualalias'] = $res->fetchOneCell();
102 "SELECT attach, attachmime
104 INNER JOIN aliases AS a ON (a.id = p.uid AND a.type = 'a_vie')
105 WHERE a.alias = {?}", $login);
106 if ($res->numRows()) {
107 $user['photo'] = $res->fetchOneAssoc();
109 $this->users
[] = $user;
112 function do_page(&$page)
114 $page->changeTpl('vcard.tpl', NO_SKIN
);
115 $page->register_modifier('vcard_enc', array($this, 'text_encode'));
116 $page->register_function('format_adr', array($this, 'format_adr'));
117 $page->assign_by_ref('users', $this->users
);
120 header("Cache-Control: ");
121 header("Content-type: text/x-vcard; charset=iso-8859-15");
122 header("Content-Transfer-Encoding: 8bit");
126 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: