Commit | Line | Data |
---|---|---|
24cec3d8 | 1 | <?php |
2 | /*************************************************************************** | |
12262f13 | 3 | * Copyright (C) 2003-2011 Polytechnique.org * |
24cec3d8 | 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 | ||
c3b581dc FB |
22 | require_once dirname(__FILE__) . '/../../banana/banana/banana.inc.php'; |
23 | require_once dirname(__FILE__) . '/../../banana/banana/message.func.inc.php'; | |
24cec3d8 | 24 | |
25 | function hook_formatDisplayHeader($_header, $_text, $in_spool = false) | |
26 | { | |
27 | switch ($_header) { | |
28 | case 'from': case 'to': case 'cc': case 'reply-to': | |
29 | $addresses = preg_split("/ *, */", $_text); | |
30 | $text = ''; | |
31 | foreach ($addresses as $address) { | |
81f8c83c | 32 | $address = BananaMessage::formatFrom(trim($address), Banana::$message->getHeaderValue('subject')); |
24cec3d8 | 33 | if ($_header == 'from') { |
34 | if ($id = Banana::$message->getHeaderValue('x-org-id')) { | |
35 | return $address . ' <a href="profile/' . $id . '" class="popup2" title="' . $id . '">' | |
36 | . '<img src="images/icons/user_suit.gif" title="fiche" alt="" /></a>'; | |
37 | } elseif ($id = Banana::$message->getHeaderValue('x-org-mail')) { | |
38 | list($id, $domain) = explode('@', $id); | |
39 | return $address . ' <a href="profile/' . $id . '" class="popup2" title="' . $id . '">' | |
40 | . '<img src="images/icons/user_suit.gif" title="fiche" alt="" /></a>'; | |
41 | } else { | |
42 | return $address; | |
eaf30d86 | 43 | } |
24cec3d8 | 44 | } |
45 | if (!empty($text)) { | |
46 | $text .= ', '; | |
47 | } | |
48 | $text .= $address; | |
49 | } | |
50 | return $text; | |
51 | ||
52 | case 'subject': | |
53 | $link = null; | |
54 | $text = stripslashes($_text); | |
55 | if (preg_match('/^(.+?)\s*\[=> (.*?)\]\s*$/u', $text, $matches)) { | |
56 | $text = $matches[1]; | |
57 | $group = $matches[2]; | |
58 | if (Banana::$group == $group) { | |
59 | $link = ' [=> ' . $group . ']'; | |
60 | } else { | |
61 | $link = ' [=> ' . Banana::$page->makeLink(array('group' => $group, 'text' => $group)) . ']'; | |
62 | } | |
63 | } | |
64 | $text = banana_catchFormats(banana_htmlentities($text)); | |
65 | if ($in_spool) { | |
66 | return array($text, $link); | |
67 | } | |
68 | return $text . $link; | |
69 | } | |
70 | return null; | |
71 | } | |
72 | ||
6544d0e1 | 73 | function hook_platalRSS($group) |
74 | { | |
75 | if ($group) { | |
76 | $group .= '/'; | |
77 | } else { | |
78 | $group = ''; | |
79 | } | |
2ab3486b | 80 | return '/rss/' . $group . S::v('hruid') . '/' . S::user()->token . '/rss.xml'; |
6544d0e1 | 81 | } |
82 | ||
24cec3d8 | 83 | function hook_platalMessageLink($params) |
84 | { | |
85 | $base = ''; | |
86 | if (isset($params['first'])) { | |
87 | return $base . '/from/' . $params['first']; | |
88 | } | |
89 | if (isset($params['artid'])) { | |
90 | if (@$params['part'] == 'xface') { | |
91 | $base .= '/xface'; | |
92 | } elseif (@$params['action'] == 'new') { | |
93 | $base .= '/reply'; | |
94 | } elseif (@$params['action'] == 'cancel') { | |
95 | $base .= '/cancel'; | |
1515e65a | 96 | } elseif (@$params['part']) { |
97 | if (strpos($params['part'], '.') !== false) { | |
98 | $params['artid'] .= '?part=' . urlencode($params['part']); | |
99 | $base = '/read'; | |
100 | } else { | |
101 | $base .= '/' . str_replace('/', '.', $params['part']); | |
102 | } | |
24cec3d8 | 103 | } else { |
104 | $base .= '/read'; | |
105 | } | |
1515e65a | 106 | return $base . '/' . $params['artid']; |
24cec3d8 | 107 | } |
108 | ||
109 | if (@$params['action'] == 'new') { | |
110 | return $base . '/new'; | |
111 | } | |
112 | return $base; | |
113 | } | |
114 | ||
115 | function hook_makeImg($img, $alt, $height, $width) | |
116 | { | |
c6c10b6b | 117 | global $globals; |
118 | $url = $globals->baseurl . '/images/banana/' . $img; | |
24cec3d8 | 119 | |
120 | if (!is_null($width)) { | |
121 | $width = ' width="' . $width . '"'; | |
122 | } | |
123 | if (!is_null($height)) { | |
124 | $height = ' height="' . $height . '"'; | |
125 | } | |
126 | ||
127 | return '<img src="' . $url . '"' . $height . $width . ' alt="' . $alt . '" />'; | |
128 | } | |
129 | ||
4f355064 | 130 | if (!function_exists('hook_makeLink')) { |
6544d0e1 | 131 | function hook_makeLink($params) |
132 | { | |
133 | global $globals, $platal; | |
4f355064 | 134 | $xnet = !empty($GLOBALS['IS_XNET_SITE']); |
135 | $feed = (@$params['action'] == 'rss' || @$params['action'] == 'rss2' || @$params['action'] == 'atom'); | |
136 | if (Banana::$protocole->name() == 'NNTP' && !$xnet) { | |
6544d0e1 | 137 | $base = $globals->baseurl . '/banana'; |
4f355064 | 138 | if ($feed) { |
6544d0e1 | 139 | return $base . hook_platalRSS(@$params['group']); |
140 | } | |
141 | if (isset($params['page'])) { | |
142 | return $base . '/' . $params['page']; | |
143 | } | |
144 | if (@$params['action'] == 'subscribe') { | |
b8458bd1 | 145 | return $base . '/subscribe'; |
6544d0e1 | 146 | } |
eaf30d86 | 147 | |
6544d0e1 | 148 | if (!isset($params['group'])) { |
149 | return $base; | |
150 | } | |
151 | $base .= '/' . $params['group']; | |
4f355064 | 152 | } else if (Banana::$protocole->name() == 'NNTP' && $xnet) { |
153 | if ($feed) { | |
45319df1 | 154 | return $globals->baseurl . '/banana' . hook_platalRSS(@$params['group']); |
eaf30d86 PH |
155 | } |
156 | $base = $globals->baseurl . '/' . $platal->ns . 'forum'; | |
6544d0e1 | 157 | } else if (Banana::$protocole->name() == 'MLArchives') { |
4f355064 | 158 | if ($feed) { |
440b63df | 159 | return $globals->baseurl . '/' . $platal->ns . hook_platalRSS(MLBanana::$listname); |
19413120 | 160 | } elseif (php_sapi_name() == 'cli') { |
161 | $base = "http://listes.polytechnique.org/archives/" . str_replace('@', '_', $params['group']); | |
162 | } else { | |
440b63df | 163 | $base = $globals->baseurl . '/' . $platal->ns . 'lists/archives/' . MLBanana::$listname; |
6544d0e1 | 164 | } |
6544d0e1 | 165 | } |
166 | $base = $base . hook_platalMessageLink($params); | |
167 | if (@$params['action'] == 'showext') { | |
168 | $base .= '?action=showext'; | |
169 | } | |
170 | return $base; | |
171 | } | |
4f355064 | 172 | } |
173 | ||
bd4d80f0 FB |
174 | function hook_hasXFace($headers) |
175 | { | |
176 | return isset($headers['x-org-id']) || isset($headers['x-org-mail']); | |
177 | } | |
178 | ||
179 | function hook_getXFace($headers) | |
180 | { | |
7d15f750 FB |
181 | $login = null; |
182 | foreach (array('x-org-id', 'x-org-mail') as $key) { | |
183 | if (isset($headers[$key])) { | |
184 | $login = $headers[$key]; | |
185 | break; | |
186 | } | |
bd4d80f0 | 187 | } |
7d15f750 FB |
188 | if (is_null($login)) { |
189 | // No login, fallback to default handler | |
bd4d80f0 FB |
190 | return false; |
191 | } | |
192 | if (isset($headers['x-face'])) { | |
7d15f750 | 193 | $user = User::getSilent($login); |
5660032a | 194 | $res = XDB::query("SELECT pf.uid |
7d15f750 | 195 | FROM forum_profiles AS pf |
5660032a | 196 | WHERE pf.uid = {?} AND FIND_IN_SET('xface', pf.flags)", |
7d15f750 | 197 | $user->id()); |
bd4d80f0 | 198 | if ($res->numRows()) { |
7d15f750 | 199 | // User wants his xface to be showed, fallback to default handler |
bd4d80f0 FB |
200 | return false; |
201 | } | |
202 | } | |
0d3bc556 FB |
203 | global $globals; |
204 | http_redirect($global->baseurl . '/photo/' . $login); | |
bd4d80f0 FB |
205 | } |
206 | ||
51e10229 | 207 | function hook_makeJs($src) |
208 | { | |
d7610c35 | 209 | Platal::page()->addJsLink("$src.js"); |
51e10229 | 210 | return ' '; |
211 | } | |
212 | ||
437a98e0 FB |
213 | function make_Organization() |
214 | { | |
215 | global $globals; | |
216 | $perms = S::v('perms'); | |
217 | $group = $globals->asso('nom'); | |
dd70cd28 | 218 | if (S::admin()) { |
437a98e0 FB |
219 | return "Administrateur de Polytechnique.org"; |
220 | } else if ($group && $perms->hasFlag('groupadmin')) { | |
221 | return "Animateur de $group"; | |
222 | } else if ($group && $perms->hasFlag('groupmember')) { | |
223 | return "Membre de $group"; | |
224 | } | |
225 | return "Utilisateur de Polytechnique.org"; | |
226 | } | |
227 | ||
4f355064 | 228 | function get_banana_params(array &$get, $group = null, $action = null, $artid = null) |
229 | { | |
b5163f52 FB |
230 | if ($group == 'forums') { |
231 | $group = null; | |
232 | } else if ($group == 'thread') { | |
233 | $group = S::v('banana_group'); | |
234 | } else if ($group == 'message') { | |
235 | $action = 'read'; | |
236 | $group = S::v('banana_group'); | |
237 | $artid = S::i('banana_artid'); | |
f27bf43a FB |
238 | } else if ($action == 'message') { |
239 | $action = 'read'; | |
240 | $artid = S::i('banana_artid'); | |
b5163f52 FB |
241 | } else if ($group == 'subscribe' || $group == 'subscription') { |
242 | $group = null; | |
243 | $action = null; | |
244 | $get['action'] = 'subscribe'; | |
245 | } else if ($group == 'profile') { | |
246 | $group = null; | |
247 | $action = null; | |
248 | $get['action'] = 'profile'; | |
249 | } | |
4f355064 | 250 | if (!is_null($group)) { |
251 | $get['group'] = $group; | |
252 | } | |
253 | if (!is_null($action)) { | |
254 | if ($action == 'new') { | |
eaf30d86 | 255 | $get['action'] = 'new'; |
4f355064 | 256 | } elseif (!is_null($artid)) { |
eaf30d86 | 257 | $get['artid'] = $artid; |
4f355064 | 258 | if ($action == 'reply') { |
259 | $get['action'] = 'new'; | |
260 | } elseif ($action == 'cancel') { | |
261 | $get['action'] = $action; | |
262 | } elseif ($action == 'from') { | |
263 | $get['first'] = $artid; | |
264 | unset($get['artid']); | |
265 | } elseif ($action == 'read') { | |
266 | $get['part'] = @$_GET['part']; | |
267 | } elseif ($action == 'source') { | |
268 | $get['part'] = 'source'; | |
269 | } elseif ($action == 'xface') { | |
270 | $get['part'] = 'xface'; | |
271 | } elseif ($action) { | |
272 | $get['part'] = str_replace('.', '/', $action); | |
273 | } | |
eaf30d86 PH |
274 | if (Get::v('action') == 'showext') { |
275 | $get['action'] = 'showext'; | |
276 | } | |
4f355064 | 277 | } |
278 | } | |
279 | } | |
280 | ||
b8458bd1 FB |
281 | class PlatalBananaPage extends BananaPage |
282 | { | |
d300e6f3 FB |
283 | protected $handler; |
284 | protected $base; | |
285 | ||
b8458bd1 FB |
286 | public function __construct() |
287 | { | |
d300e6f3 | 288 | global $platal; |
b8458bd1 | 289 | Banana::$withtabs = false; |
d300e6f3 FB |
290 | $this->handler = 'BananaHandler'; |
291 | $this->base = $platal->pl_self(0); | |
b8458bd1 FB |
292 | parent::__construct(); |
293 | } | |
294 | ||
295 | protected function prepare() | |
296 | { | |
297 | $tpl = parent::prepare(); | |
d7610c35 | 298 | global $wiz; |
6d20fb1d | 299 | $wiz = new PlWizard('Banana', PlPage::getCoreTpl('plwizard.tpl'), true, false); |
b8458bd1 | 300 | foreach ($this->pages as $name=>&$mpage) { |
d300e6f3 | 301 | $wiz->addPage($this->handler, $mpage['text'], $name); |
b8458bd1 | 302 | } |
d7610c35 | 303 | $wiz->apply(Platal::page(), $this->base, $this->page); |
b8458bd1 FB |
304 | return $tpl; |
305 | } | |
306 | } | |
307 | ||
308 | class BananaHandler | |
309 | { | |
26ba053e | 310 | public function __construct(PlWizard $wiz) |
b8458bd1 FB |
311 | { |
312 | } | |
313 | ||
314 | public function template() | |
315 | { | |
316 | return 'banana/index.tpl'; | |
317 | } | |
318 | ||
26ba053e | 319 | public function prepare(PlPage $page, $id) |
b8458bd1 FB |
320 | { |
321 | } | |
322 | ||
eb563236 SJ |
323 | public function success() { } |
324 | ||
325 | public function process(&$success) | |
b8458bd1 FB |
326 | { |
327 | return PlWizard::CURRENT_PAGE; | |
328 | } | |
329 | } | |
330 | ||
26ba053e | 331 | function run_banana($page, $class, array $args) |
4f355064 | 332 | { |
d60f6cc6 | 333 | $user = S::user(); |
2bd55de5 | 334 | $banana = new $class($user, $args); |
4f355064 | 335 | $page->assign('banana', $banana->run()); |
336 | $page->addCssInline($banana->css()); | |
337 | $page->addCssLink('banana.css'); | |
338 | $rss = $banana->feed(); | |
339 | if ($rss) { | |
340 | if (Banana::$group) { | |
341 | $page->setRssLink('Banana :: ' . Banana::$group, $rss); | |
342 | } else { | |
343 | $page->setRssLink('Banana :: Abonnements', $rss); | |
344 | } | |
345 | } | |
346 | $bt = $banana->backtrace(); | |
347 | if ($bt) { | |
348 | new PlBacktrace(Banana::$protocole->name(), $banana->backtrace(), 'response', 'time'); | |
eaf30d86 | 349 | } |
4f355064 | 350 | } |
6544d0e1 | 351 | |
a7de4ef7 | 352 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
24cec3d8 | 353 | ?> |