0337d704 |
1 | <?php |
2 | /*************************************************************************** |
50a40a33 |
3 | * Copyright (C) 2003-2006 Polytechnique.org * |
0337d704 |
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 | |
57e834ac |
22 | require_once 'banana/banana.inc.php'; |
0337d704 |
23 | |
98c14aa5 |
24 | function hook_formatDisplayHeader($_header, $_text) { |
7da8ef90 |
25 | global $banana; |
98c14aa5 |
26 | if ($_header == 'from') { |
27 | $id = $banana->post->headers['x-org-id']; |
28 | $_text = formatFrom($_text); |
7da8ef90 |
29 | return $_text . ' <a href="profile/' . $id . '" class="popup2" title="' . $id . '">' |
30 | . '<img src="images/loupe.gif" alt="fiche" title="fiche" /></a>'; |
0337d704 |
31 | } |
32 | } |
33 | |
34 | function hook_checkcancel($_headers) { |
cab08090 |
35 | return ($_headers['x-org-id'] == S::v('forlife') or S::has_perms()); |
0337d704 |
36 | } |
37 | |
aafe5c09 |
38 | function hook_shortcuts() |
39 | { |
a8f6aabb |
40 | return array('profile' => array('<a href="banana/profile">Préférences</a>', |
c3235940 |
41 | 'Préférences')); |
aafe5c09 |
42 | } |
43 | |
3d9b1d30 |
44 | function hook_makeLink($params) { |
7da8ef90 |
45 | $base = 'banana'; |
f107d806 |
46 | if ($params['subscribe'] == 1) { |
47 | return $base . '/subscription'; |
48 | } |
49 | if (isset($params['xface'])) { |
7e6495d4 |
50 | return $base . '/xface/' . strtr(base64_encode($params['xface']), '+/', '.:'); |
f107d806 |
51 | } |
52 | |
53 | if (!isset($params['group'])) { |
54 | return $base; |
55 | } |
56 | $base .= '/' . $params['group']; |
57 | |
58 | if (isset($params['first'])) { |
59 | return $base . '/from/' . $params['first']; |
60 | } |
61 | if (isset($params['artid'])) { |
62 | if ($params['action'] == 'new') { |
63 | $base .= '/reply'; |
64 | } elseif ($params['action'] == 'cancel') { |
65 | $base .= '/cancel'; |
66 | } else { |
67 | $base .= '/read'; |
68 | } |
69 | return $base . '/' . $params['artid']; |
70 | } |
57e834ac |
71 | |
f107d806 |
72 | if ($params['action'] == 'new') { |
73 | return $base . '/new'; |
74 | } |
75 | return $base; |
3d9b1d30 |
76 | } |
77 | |
cce828e5 |
78 | function hook_makeImg($img, $alt, $height, $width) |
63e3b9ae |
79 | { |
7da8ef90 |
80 | $url = 'images/banana/' . $img; |
63e3b9ae |
81 | |
82 | if (!is_null($width)) { |
83 | $width = ' width="' . $width . '"'; |
84 | } |
cce828e5 |
85 | if (!is_null($height)) { |
86 | $height = ' height="' . $height . '"'; |
87 | } |
57e834ac |
88 | |
cce828e5 |
89 | return '<img src="' . $url . '"' . $height . $width . ' alt="' . $alt . '" />'; |
63e3b9ae |
90 | } |
91 | |
0a611890 |
92 | function hook_getSubject(&$subject) |
93 | { |
94 | if (preg_match('!(.*\S)\s*\[=> ([^\]\s]+)\]!', $subject, $matches)) { |
95 | $subject = $matches[1]; |
96 | global $banana; |
97 | if ($banana->state['group'] == $matches[2]) { |
98 | return ' [=> ' . $matches[2] . ']'; |
99 | } else { |
a8f6aabb |
100 | return ' [=> ' . makeHREF(array('group' => $matches[2]), $matches[2]) . ']'; |
0a611890 |
101 | } |
102 | } |
103 | return null; |
104 | } |
105 | |
0337d704 |
106 | class PlatalBanana extends Banana |
107 | { |
a8f6aabb |
108 | var $profile = array('name' => '', 'sig' => '', |
109 | 'org' => 'Utilisateur de Polytechnique.org', |
110 | 'customhdr' =>'', 'display' => 0, 'lastnews' => 0, |
111 | 'locale' => 'fr_FR', 'subscribe' => array()); |
4475197c |
112 | var $can_attach = false; |
0337d704 |
113 | |
114 | function PlatalBanana() |
115 | { |
116 | global $globals; |
7da8ef90 |
117 | |
cab08090 |
118 | $uid = S::v('uid'); |
08cce2ff |
119 | $req = XDB::query( |
0337d704 |
120 | "SELECT nom, mail, sig, FIND_IN_SET('threads',flags), FIND_IN_SET('automaj',flags) |
121 | FROM {$globals->banana->table_prefix}profils |
122 | WHERE uid={?}", $uid); |
123 | |
124 | if (!(list($nom,$mail,$sig,$disp,$maj) = $req->fetchOneRow())) { |
cab08090 |
125 | $nom = S::v('prenom')." ".S::v('nom'); |
126 | $mail = S::v('forlife')."@polytechnique.org"; |
127 | $sig = $nom." (".S::v('promo').")"; |
0337d704 |
128 | $disp = 0; |
129 | $maj = 1; |
130 | } |
131 | $this->profile['name'] = "$nom <$mail>"; |
132 | $this->profile['sig'] = $sig; |
133 | $this->profile['display'] = $disp; |
134 | $this->profile['autoup'] = $maj; |
cab08090 |
135 | $this->profile['lastnews'] = S::v('banana_last'); |
57e834ac |
136 | |
0337d704 |
137 | if ($maj) { |
a8f6aabb |
138 | XDB::execute("UPDATE auth_user_quick SET banana_last={?} WHERE user_id={?}", |
139 | gmdate("YmdHis"), $uid); |
0337d704 |
140 | } |
141 | |
08cce2ff |
142 | $req = XDB::query(" |
f585e5a4 |
143 | SELECT nom |
0337d704 |
144 | FROM {$globals->banana->table_prefix}abos |
145 | LEFT JOIN {$globals->banana->table_prefix}list ON list.fid=abos.fid |
146 | WHERE uid={?}", $uid); |
147 | $this->profile['subscribe'] = $req->fetchColumn(); |
148 | |
98c14aa5 |
149 | array_splice($this->show_hdr, count($this->show_hdr) - 2, 0); |
0337d704 |
150 | array_splice($this->parse_hdr, count($this->parse_hdr) - 2, 0, 'x-org-id'); |
151 | |
cab08090 |
152 | $this->host = 'news://web_'.S::v('forlife') |
0337d704 |
153 | .":{$globals->banana->password}@{$globals->banana->server}:{$globals->banana->port}/"; |
154 | |
155 | parent::Banana(); |
156 | } |
157 | |
3d9b1d30 |
158 | function run($params = null) |
0337d704 |
159 | { |
a3a049fc |
160 | global $banana; |
0337d704 |
161 | |
5e2307dc |
162 | if (Get::v('banana') == 'updateall' |
a8f6aabb |
163 | || (!is_null($params) && isset($params['banana']) && $params['banana'] == 'updateall')) { |
164 | XDB::execute('UPDATE auth_user_quick SET banana_last={?} WHERE user_id={?}', |
165 | gmdate('YmdHis'), S::v('uid')); |
0337d704 |
166 | $_SESSION['banana_last'] = time(); |
0337d704 |
167 | } |
3d9b1d30 |
168 | return Banana::run('PlatalBanana', $params); |
0337d704 |
169 | } |
170 | |
171 | function action_saveSubs() |
172 | { |
173 | global $globals; |
cab08090 |
174 | $uid = S::v('uid'); |
0337d704 |
175 | |
a8f6aabb |
176 | $this->profile['subscribe'] = array(); |
08cce2ff |
177 | XDB::execute("DELETE FROM {$globals->banana->table_prefix}abos WHERE uid={?}", $uid); |
0337d704 |
178 | if (!count($_POST['subscribe'])) { |
179 | return true; |
180 | } |
57e834ac |
181 | |
08cce2ff |
182 | $req = XDB::iterRow("SELECT fid,nom FROM {$globals->banana->table_prefix}list"); |
0337d704 |
183 | $fids = array(); |
184 | while (list($fid,$fnom) = $req->next()) { |
185 | $fids[$fnom] = $fid; |
186 | } |
187 | |
188 | $diff = array_diff($_POST['subscribe'], array_keys($fids)); |
189 | foreach ($diff as $g) { |
08cce2ff |
190 | XDB::execute("INSERT INTO {$globals->banana->table_prefix}list (nom) VALUES ({?})", $g); |
0337d704 |
191 | $fids[$g] = mysql_insert_id(); |
192 | } |
193 | |
194 | foreach ($_POST['subscribe'] as $g) { |
a8f6aabb |
195 | XDB::execute("INSERT INTO {$globals->banana->table_prefix}abos (fid,uid) VALUES ({?},{?})", |
196 | $fids[$g], $uid); |
0337d704 |
197 | $this->profile['subscribe'][] = $g; |
198 | } |
199 | } |
200 | } |
201 | |
202 | ?> |