2 /***************************************************************************
3 * Copyright (C) 2003-2007 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 'banana/banana.inc.php';
23 require_once 'banana/hooks.inc.php';
25 function hook_checkcancel($_headers)
27 return ($_headers['x-org-id'] == S
::v('forlife') or S
::has_perms());
30 function hook_makeLink($params)
33 $base = $globals->baseurl
. '/banana';
34 if (isset($params['page'])) {
35 return $base . '/' . $params['page'];
37 if (@$params['action'] == 'subscribe') {
38 return $base . '/subscription';
41 if (!isset($params['group'])) {
44 $base .= '/' . $params['group'];
45 $base = $base . hook_platalMessageLink($params);
46 if (@$params['action'] == 'showext') {
47 $base .= '?action=showext';
52 class ForumsBanana
extends Banana
54 function __construct($params = null
)
57 Banana
::$msgedit_canattach = false
;
58 Banana
::$spool_root = $globals->banana
->spool_root
;
59 array_push(Banana
::$msgparse_headers, 'x-org-id', 'x-org-mail');
60 Banana
::$nntp_host = 'news://web_'.S
::v('forlife')
61 . ":{$globals->banana->password}@{$globals->banana->server}:{$globals->banana->port}/";
63 Banana
::$msgshow_mimeparts[] = 'source';
65 Banana
::$debug_nntp = ($globals->debug
& 1);
66 parent
::__construct($params);
71 global $platal, $globals;
73 // Update last unread time
75 if (!is_null($this->params
) && isset($this->params
['updateall'])) {
76 $time = intval($this->params
['updateall']);
77 $_SESSION['banana_last'] = $time;
80 // Get user profile from SQL
81 $req = XDB
::query("SELECT nom, mail, sig,
82 FIND_IN_SET('threads',flags), FIND_IN_SET('automaj',flags)
83 FROM {$globals->banana->table_prefix}profils
84 WHERE uid={?}", S
::i('uid'));
85 if (!(list($nom,$mail,$sig,$disp,$maj) = $req->fetchOneRow())) {
86 $nom = S
::v('prenom')." ".S
::v('nom');
87 $mail = S
::v('forlife')."@polytechnique.org";
88 $sig = $nom." (".S
::v('promo').")";
99 FROM {$globals->banana->table_prefix}abos
100 LEFT JOIN {$globals->banana->table_prefix}list ON list.fid=abos.fid
101 WHERE uid={?}", S
::i('uid'));
102 Banana
::$profile['headers']['From'] = "$nom <$mail>";
103 Banana
::$profile['headers']['Organization'] = 'Utilisateur de Polytechnique.org';
104 Banana
::$profile['signature'] = $sig;
105 Banana
::$profile['display'] = $disp;
106 Banana
::$profile['autoup'] = $maj;
107 Banana
::$profile['lastnews'] = S
::v('banana_last');
108 Banana
::$profile['subscribe'] = $req->fetchColumn();
110 // Update the "unread limit"
111 if (!is_null($time)) {
112 XDB
::execute("UPDATE auth_user_quick
113 SET banana_last = FROM_UNIXTIME({?})
118 // Register custom Banana links and tabs
119 if (!Banana
::$profile['autoup']) {
120 Banana
::$page->registerAction('<a href=\'javascript:dynpostkv("'
121 . $platal->path
. '", "updateall", ' . time() . ')\'>'
122 . 'Marquer tous les messages comme lus'
123 . '</a>', array('forums', 'thread', 'message'));
125 Banana
::$page->registerPage('profile', 'Préférences', null
);
129 return parent
::run();
132 protected function action_saveSubs($groups)
137 Banana
::$profile['subscribe'] = array();
138 XDB
::execute("DELETE FROM {$globals->banana->table_prefix}abos WHERE uid={?}", $uid);
139 if (!count($groups)) {
143 $req = XDB
::iterRow("SELECT fid,nom FROM {$globals->banana->table_prefix}list");
145 while (list($fid,$fnom) = $req->next()) {
149 $diff = array_diff($groups, array_keys($fids));
150 foreach ($diff as $g) {
151 XDB
::execute("INSERT INTO {$globals->banana->table_prefix}list (nom) VALUES ({?})", $g);
152 $fids[$g] = XDB
::insertId();
155 foreach ($groups as $g) {
156 XDB
::execute("INSERT INTO {$globals->banana->table_prefix}abos (fid,uid) VALUES ({?},{?})",
158 Banana
::$profile['subscribe'][] = $g;
163 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: