f881814f377ecc13664987e539642a7e4b4acf38
2 /***************************************************************************
3 * Copyright (C) 2003-2013 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 dirname(__FILE__
) . '/../../banana/banana/banana.inc.php';
23 require_once dirname(__FILE__
) . '/../../banana/banana/message.func.inc.php';
25 function hook_formatDisplayHeader($_header, $_text, $in_spool = false
)
28 case 'from': case 'to': case 'cc': case 'reply-to':
29 $addresses = preg_split("/ *, */", $_text);
31 foreach ($addresses as $address) {
32 $address = BananaMessage
::formatFrom(trim($address), Banana
::$message->getHeaderValue('subject'));
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>';
54 $text = stripslashes($_text);
55 if (preg_match('/^(.+?)\s*\[=> (.*?)\]\s*$/u', $text, $matches)) {
58 if (Banana
::$group == $group) {
59 $link = ' [=> ' . $group . ']';
61 $link = ' [=> ' . Banana
::$page->makeLink(array('group' => $group, 'text' => $group)) . ']';
64 $text = banana_catchFormats(banana_htmlentities($text));
66 return array($text, $link);
73 function hook_platalRSS($group)
80 return '/rss/' . $group . S
::v('hruid') . '/' . S
::user()->token
. '/rss.xml';
83 function hook_platalMessageLink($params)
86 if (isset($params['first'])) {
87 return $base . '/from/' . $params['first'];
89 if (isset($params['artid'])) {
90 if (@$params['part'] == 'xface') {
92 } elseif (@$params['action'] == 'new') {
94 } elseif (@$params['action'] == 'cancel') {
96 } elseif (@$params['part']) {
97 if (strpos($params['part'], '.') !== false
) {
98 $params['artid'] .= '?part=' . urlencode($params['part']);
101 $base .= '/' . str_replace('/', '.', $params['part']);
106 return $base . '/' . $params['artid'];
109 if (@$params['action'] == 'new') {
110 return $base . '/new';
115 function hook_makeImg($img, $alt, $height, $width)
118 $url = $globals->baseurl
. '/images/banana/' . $img;
120 if (!is_null($width)) {
121 $width = ' width="' . $width . '"';
123 if (!is_null($height)) {
124 $height = ' height="' . $height . '"';
127 return '<img src="' . $url . '"' . $height . $width . ' alt="' . $alt . '" />';
130 if (!function_exists('hook_makeLink')) {
131 function hook_makeLink($params)
133 global $globals, $platal;
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) {
137 $base = $globals->baseurl
. '/banana';
139 return $base . hook_platalRSS(@$params['group']);
141 if (isset($params['page'])) {
142 return $base . '/' . $params['page'];
144 if (@$params['action'] == 'subscribe') {
145 return $base . '/subscribe';
148 if (!isset($params['group'])) {
151 $base .= '/' . $params['group'];
152 } else if (Banana
::$protocole->name() == 'NNTP' && $xnet) {
154 return $globals->baseurl
. '/banana' . hook_platalRSS(@$params['group']);
156 $base = $globals->baseurl
. '/' . $platal->ns
. 'forum';
157 } else if (Banana
::$protocole->name() == 'MLArchives') {
159 return $globals->baseurl
. '/' . $platal->ns
. hook_platalRSS(MLBanana
::$listname);
160 } elseif (php_sapi_name() == 'cli') {
161 $base = "http://listes.polytechnique.org/archives/" . str_replace('@', '_', $params['group']);
163 $base = $globals->baseurl
. '/' . $platal->ns
. 'lists/archives/' . MLBanana
::$listname;
166 $base = $base . hook_platalMessageLink($params);
167 if (@$params['action'] == 'showext') {
168 $base .= '?action=showext';
174 function hook_hasXFace($headers)
176 return isset($headers['x-org-id']) ||
isset($headers['x-org-mail']);
179 function hook_getXFace($headers)
182 foreach (array('x-org-id', 'x-org-mail') as $key) {
183 if (isset($headers[$key])) {
184 $login = $headers[$key];
188 if (is_null($login)) {
189 // No login, fallback to default handler
192 if (isset($headers['x-face'])) {
193 $user = User
::getSilent($login);
194 $res = XDB
::query("SELECT pf.uid
195 FROM forum_profiles AS pf
196 WHERE pf.uid = {?} AND FIND_IN_SET('xface', pf.flags)",
198 if ($res->numRows()) {
199 // User wants his xface to be showed, fallback to default handler
204 http_redirect($global->baseurl
. '/photo/' . $login);
207 function hook_makeJs($src)
209 Platal
::page()->addJsLink("$src.js");
213 function make_Organization()
216 $perms = S
::v('perms');
217 $group = $globals->asso('nom');
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";
225 return "Utilisateur de Polytechnique.org";
228 function get_banana_params(array &$get, $group = null
, $action = null
, $artid = null
)
230 if ($group == 'forums') {
232 } else if ($group == 'thread') {
233 $group = S
::v('banana_group');
234 } else if ($group == 'message') {
236 $group = S
::v('banana_group');
237 $artid = S
::i('banana_artid');
238 } else if ($action == 'message') {
240 $artid = S
::i('banana_artid');
241 } else if ($group == 'subscribe' ||
$group == 'subscription') {
244 $get['action'] = 'subscribe';
245 } else if ($group == 'profile') {
248 $get['action'] = 'profile';
250 if (!is_null($group)) {
251 $get['group'] = $group;
253 if (!is_null($action)) {
254 if ($action == 'new') {
255 $get['action'] = 'new';
256 } elseif (!is_null($artid)) {
257 $get['artid'] = $artid;
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';
272 $get['part'] = str_replace('.', '/', $action);
274 if (Get
::v('action') == 'showext') {
275 $get['action'] = 'showext';
281 class PlatalBananaPage
extends BananaPage
286 public function __construct()
289 Banana
::$withtabs = false
;
290 $this->handler
= 'BananaHandler';
291 $this->base
= $platal->pl_self(0);
292 parent
::__construct();
295 protected function prepare()
297 $tpl = parent
::prepare();
299 $wiz = new PlWizard('Banana', PlPage
::getCoreTpl('plwizard.tpl'), true
, false
);
300 foreach ($this->pages
as $name=>&$mpage) {
301 $wiz->addPage($this->handler
, $mpage['text'], $name);
303 $wiz->apply(Platal
::page(), $this->base
, $this->page
);
310 public function __construct(PlWizard
$wiz)
314 public function template()
316 return 'banana/index.tpl';
319 public function prepare(PlPage
$page, $id)
323 public function success() { }
325 public function process(&$success)
327 return PlWizard
::CURRENT_PAGE
;
331 function run_banana($page, $class, array $args)
334 $banana = new $class($user, $args);
335 $page->assign('banana', $banana->run());
336 $page->addCssInline($banana->css());
337 $page->addCssLink('banana.css');
338 $rss = $banana->feed();
340 if (Banana
::$group) {
341 $page->setRssLink('Banana :: ' . Banana
::$group, $rss);
343 $page->setRssLink('Banana :: Abonnements', $rss);
346 $bt = $banana->backtrace();
348 new PlBacktrace(Banana
::$protocole->name(), $banana->backtrace(), 'response', 'time');
352 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: