2 /***************************************************************************
3 * Copyright (C) 2003-2008 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 class ForumsBanana
extends Banana
34 public function __construct($forlife, $params = null
)
36 $this->forlife
= $forlife;
39 Banana
::$msgedit_canattach = false
;
40 Banana
::$spool_root = $globals->banana
->spool_root
;
41 array_push(Banana
::$msgparse_headers, 'x-org-id', 'x-org-mail');
42 Banana
::$nntp_host = 'news://web_'.$forlife
43 . ":{$globals->banana->password}@{$globals->banana->server}:{$globals->banana->port}/";
45 Banana
::$msgshow_mimeparts[] = 'source';
47 Banana
::$debug_nntp = ($globals->debug
& DEBUG_BT
);
48 Banana
::$debug_smarty = ($globals->debug
& DEBUG_SMARTY
);
49 if (!S
::v('core_rss_hash')) {
50 Banana
::$feed_active = false
;
52 parent
::__construct($params, 'NNTP', 'PlatalBananaPage');
53 if (@$params['action'] == 'profile') {
54 Banana
::$action = 'profile';
60 global $platal, $globals;
62 // Update last unread time
64 if (!is_null($this->params
) && isset($this->params
['updateall'])) {
65 $time = intval($this->params
['updateall']);
66 $_SESSION['banana_last'] = $time;
69 // Get user profile from SQL
70 $req = XDB
::query("SELECT nom, mail, sig,
71 FIND_IN_SET('threads',flags), FIND_IN_SET('automaj',flags)
72 FROM {$globals->banana->table_prefix}profils
73 WHERE uid={?}", S
::i('uid'));
74 if (!(list($nom,$mail,$sig,$disp,$maj) = $req->fetchOneRow())) {
75 $nom = S
::v('prenom')." ".S
::v('nom');
76 $mail = S
::v('forlife')."@" . $globals->mail
->domain
;
77 $sig = $nom." (".S
::v('promo').")";
88 FROM {$globals->banana->table_prefix}abos
89 LEFT JOIN {$globals->banana->table_prefix}list ON list.fid=abos.fid
90 WHERE uid={?}", S
::i('uid'));
91 Banana
::$profile['headers']['From'] = "$nom <$mail>";
92 Banana
::$profile['headers']['Organization'] = make_Organization();
93 Banana
::$profile['signature'] = $sig;
94 Banana
::$profile['display'] = $disp;
95 Banana
::$profile['autoup'] = $maj;
96 Banana
::$profile['lastnews'] = S
::v('banana_last');
97 Banana
::$profile['subscribe'] = $req->fetchColumn();
99 // Update the "unread limit"
100 if (!is_null($time)) {
101 XDB
::execute("UPDATE auth_user_quick
102 SET banana_last = FROM_UNIXTIME({?})
107 if (!empty($GLOBALS['IS_XNET_SITE'])) {
108 Banana
::$page->killPage('forums');
109 Banana
::$page->killPage('subscribe');
110 Banana
::$spool_boxlist = false
;
112 // Register custom Banana links and tabs
113 if (!Banana
::$profile['autoup']) {
114 Banana
::$page->registerAction('<a href=\'javascript:dynpostkv("'
115 . $platal->path
. '", "updateall", ' . time() . ')\'>'
116 . 'Marquer tous les messages comme lus'
117 . '</a>', array('forums', 'thread', 'message'));
119 Banana
::$page->registerPage('profile', 'Préférences', null
);
123 if (Banana
::$action == 'profile') {
124 Banana
::$page->run();
125 return $this->action_updateProfile();
127 return parent
::run();
131 public function post($dest, $reply, $subject, $body)
134 $res = XDB
::query('SELECT nom, prenom, promo, b.alias AS bestalias
135 FROM auth_user_md5 AS u
136 INNER JOIN aliases AS a ON (a.id = u.user_id)
137 INNER JOIN aliases AS b ON (b.id = a.id AND FIND_IN_SET(\'bestalias\', b.flags))
138 WHERE a.alias = {?}', $this->forlife
);
139 list($nom, $prenom, $promo, $bestalias) = $res->fetchOneRow();
140 Banana
::$profile['headers']['From'] = "$prenom $nom ($promo) <$bestalias@{$globals->mail->domain}>";
141 Banana
::$profile['headers']['Organization'] = make_Organization();
142 return parent
::post($dest, $reply, $subject, $body);
145 protected function action_saveSubs($groups)
150 Banana
::$profile['subscribe'] = array();
151 XDB
::execute("DELETE FROM {$globals->banana->table_prefix}abos WHERE uid={?}", $uid);
152 if (!count($groups)) {
156 $req = XDB
::iterRow("SELECT fid,nom FROM {$globals->banana->table_prefix}list");
158 while (list($fid,$fnom) = $req->next()) {
162 $diff = array_diff($groups, array_keys($fids));
163 foreach ($diff as $g) {
164 XDB
::execute("INSERT INTO {$globals->banana->table_prefix}list (nom) VALUES ({?})", $g);
165 $fids[$g] = XDB
::insertId();
168 foreach ($groups as $g) {
169 XDB
::execute("INSERT INTO {$globals->banana->table_prefix}abos (fid,uid) VALUES ({?},{?})",
171 Banana
::$profile['subscribe'][] = $g;
175 protected function action_updateProfile()
177 global $page, $globals;
179 if (!(Post
::has('action') && Post
::has('banananame') && Post
::has('bananasig')
180 && Post
::has('bananadisplay') && Post
::has('bananamail')
181 && Post
::has('bananaupdate') && Post
::v('action')=="Enregistrer" ))
184 SELECT nom, mail, sig,
185 FIND_IN_SET('threads', flags),
186 FIND_IN_SET('automaj', flags),
187 FIND_IN_SET('xface', flags)
189 WHERE uid = {?}", S
::v('uid'));
190 if (!(list($nom, $mail, $sig, $disp, $maj, $xface) = $req->fetchOneRow())) {
191 $nom = S
::v('prenom').' '.S
::v('nom');
192 $mail = S
::v('forlife').'@'.$globals->mail
->domain
;
193 $sig = $nom.' ('.S
::v('promo').')';
198 $page->assign('nom' , $nom);
199 $page->assign('mail', $mail);
200 $page->assign('sig', $sig);
201 $page->assign('disp', $disp);
202 $page->assign('maj', $maj);
203 $page->assign('xface', $xface);
206 if (Post
::b('bananadisplay')) {
207 $flags[] = 'threads';
209 if (Post
::b('bananaupdate')) {
210 $flags[] = 'automaj';
212 if (Post
::b('bananaxface')) {
215 XDB
::execute("REPLACE INTO forums.profils (uid, sig, mail, nom, flags)
216 VALUES ({?}, {?}, {?}, {?}, {?})",
217 S
::v('uid'), Post
::v('bananasig'),
218 Post
::v('bananamail'), Post
::v('banananame'),
219 implode(',', $flags));
225 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: