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