ebda6af26110e1acb3019887a62c23cbaa4a61df
2 /***************************************************************************
3 * Copyright (C) 2003-2008 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');
25 class VCardIterator
implements PlIterator
27 private $user_list = array();
29 private $freetext = null
;
30 private $photos = true
;
32 public function __construct($photos, $freetext)
34 $this->freetext
= $freetext;
35 $this->photos
= $photos;
38 public function add_user($user)
40 $this->user_list
[] = get_user_forlife($user);
44 public function first()
46 return count($this->user_list
) == $this->count
- 1;
49 public function last()
51 return count($this->user_list
) == 0;
54 public function total()
59 public function next()
61 if (!$this->user_list
) {
65 $login = array_shift($this->user_list
);
66 $user = get_user_details($login);
68 if (strlen(trim($user['freetext']))) {
69 $user['freetext'] = pl_entity_decode($user['freetext']);
71 if ($this->freetext
) {
72 if (strlen(trim($user['freetext']))) {
73 $user['freetext'] = $this->freetext
. "\n" . $user['freetext'];
75 $user['freetext'] = $this->freetext
;
83 INNER JOIN virtual_redirect USING(vid)
84 INNER JOIN auth_user_quick ON ( user_id = {?} AND emails_alias_pub = 'public' )
85 WHERE ( redirect={?} OR redirect={?} )
86 AND alias LIKE '%@{$globals->mail->alias_dom}'",
88 $user['forlife'].'@'.$globals->mail
->domain
,
89 $user['forlife'].'@'.$globals->mail
->domain2
);
91 $user['virtualalias'] = $res->fetchOneCell();
92 $user['gpxs_vcardjoin'] = join(',', array_map(array('VCard', 'text_encode'), $user['gpxs_name']));
93 $user['binets_vcardjoin'] = join(',', array_map(array('VCard', 'text_encode'), $user['binets']));
97 "SELECT attach, attachmime
99 INNER JOIN aliases AS a ON (a.id = p.uid AND a.type = 'a_vie')
100 WHERE a.alias = {?}", $login);
101 if ($res->numRows()) {
102 $user['photo'] = $res->fetchOneAssoc();
111 static private $windows = false
;
112 private $iterator = null
;
114 public function __construct($users, $photos = true
, $freetext = null
)
116 $this->iterator
= new VCardIterator($photos, $freetext);
117 VCard
::$windows = (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false
);
118 if (is_array($users)) {
119 foreach ($users as $user) {
120 $this->iterator
->add_user($user);
123 $this->iterator
->add_user($users);
127 public static function escape($text)
129 if (VCard
::$windows) {
130 return str_replace(';', '\\\\;', $text);
132 return str_replace(array(';', ','), array('\\\\;', '\\\\,'), $text);
136 public static function format_adr($params, &$smarty)
138 // $adr1, $adr2, $adr3, $postcode, $city, $region, $country
139 extract($params['adr']);
141 $adr = trim("$adr\n$adr2");
142 $adr = trim("$adr\n$adr3");
143 return VCard
::text_encode(';;'
144 . (VCard
::$windows ? VCard
::escape($adr) : $adr) . ';'
145 . (VCard
::$windows ? VCard
::escape($city) : $city) . ';'
146 . (VCard
::$windows ? VCard
::escape($region) : $region) . ';'
147 . (VCard
::$windows ? VCard
::escape($postcode) : $postcode) . ';'
148 . (VCard
::$windows ? VCard
::escape($country) : $country), false
);
151 public static function text_encode($text, $escape = true
)
153 if (is_array($text)) {
154 return implode(',', array_map(array('VCard', 'text_encode'), $text));
157 $text = VCard
::escape($text);
159 if (VCard
::$windows) {
160 $text = utf8_decode($text);
162 return str_replace(array("\r\n", "\n", "\r"), '\n', $text);
165 public function do_page(&$page)
167 $page->changeTpl('core/vcard.tpl', NO_SKIN
);
168 $page->register_modifier('vcard_enc', array($this, 'text_encode'));
169 $page->register_function('format_adr', array($this, 'format_adr'));
170 $page->assign_by_ref('users', $this->iterator
);
173 header("Cache-Control: ");
174 header("Content-type: text/x-vcard; charset=UTF-8");
175 header("Content-Transfer-Encoding: 8bit");
179 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: