Ooops, forgotten files
[platal.git] / include / vcard.inc.php
CommitLineData
89460d9c 1<?php
2/***************************************************************************
3 * Copyright (C) 2003-2006 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
5 * *
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. *
10 * *
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. *
15 * *
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 *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22require_once('xorg.misc.inc.php');
23require_once('user.func.inc.php');
24
25class VCard
26{
27 var $users = array();
28
29 function VCard($users, $freetext = null)
30 {
31 if (is_array($users)) {
32 foreach ($users as $user) {
33 $this->add_user($user, $freetext);
34 }
35 } else {
36 $this->add_user($users, $freetext);
37 }
38 }
39
40 // {{{ text formatting stuff
41
42 function escape($text)
43 {
44 return preg_replace('/[,;:]/', '\\\\$0', $text);
45 }
46
47 function format_adr($params, &$smarty)
48 {
49 // $adr1, $adr2, $adr3, $postcode, $city, $region, $country
50 extract($params['adr']);
51 $adr = trim($adr1);
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);
60 }
61
62 function text_encode($text, $escape = true)
63 {
64 if ($escape) {
65 $text = $this->escape($text);
66 }
67 return preg_replace("/(\r\n|\n|\r)/", '\n', $text);
68 }
69
70 // }}}
71 // {{{ function add_user()
72
73 function add_user($x, $freetext)
74 {
75 global $globals;
76
77 $login = get_user_forlife($x);
78 $user = get_user_details($login);
79
80 if (strlen(trim($user['freetext']))) {
81 $user['freetext'] = html_entity_decode($user['freetext']);
82 }
83 if (!is_null($freetext)) {
84 if (strlen(trim($user['freetext']))) {
85 $user['freetext'] = $freetext . "\n" . $user['freetext'];
86 } else {
87 $user['freetext'] = $freetext;
88 }
89 }
90
91 // alias virtual
92 $res = XDB::query(
93 "SELECT alias
94 FROM virtual
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}'",
99 S::v('uid'),
100 $user['forlife'].'@'.$globals->mail->domain,
101 $user['forlife'].'@'.$globals->mail->domain2);
102
103 $user['virtualalias'] = $res->fetchOneCell();
104
105 // get photo
106 $res = XDB::query(
107 "SELECT attach, attachmime
108 FROM photo AS p
109 INNER JOIN aliases AS a ON (a.id = p.uid AND a.type = 'a_vie')
110 WHERE a.alias = {?}", $login);
111 if ($res->numRows()) {
112 $user['photo'] = $res->fetchOneAssoc();
113 }
114 $this->users[] = $user;
115 }
116
117 // }}}
118 // {{{ function do_page()
119
120 function do_page(&$page)
121 {
122 $page->changeTpl('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);
126
127 header("Pragma: ");
128 header("Cache-Control: ");
129 header("Content-type: text/x-vcard; charset=iso-8859-15");
130 header("Content-Transfer-Encoding: 8bit");
131 }
132
133 // }}}
134}
135
136// vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
137?>