2 /***************************************************************************
3 * Copyright (C) 2003-2009 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('hruid') or S
::admin());
30 class ForumsBanana
extends Banana
34 public function __construct(User
&$user, $params = null
)
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 = self
::buildURL($user->login());
44 Banana
::$msgshow_mimeparts[] = 'source';
46 Banana
::$debug_nntp = ($globals->debug
& DEBUG_BT
);
47 Banana
::$debug_smarty = ($globals->debug
& DEBUG_SMARTY
);
48 Banana
::$feed_active = S
::hasAuthToken();
50 parent
::__construct($params, 'NNTP', 'PlatalBananaPage');
51 if (@$params['action'] == 'profile') {
52 Banana
::$action = 'profile';
56 public static function buildURL($login = null
)
59 $scheme = ($globals->banana
->port
== 563) ?
"nntps" : "news";
60 $user = $globals->banana
->web_user
;
62 $user .= '_' . $login;
64 return $scheme . '://' . $user
65 . ":{$globals->banana->password}@{$globals->banana->server}:{$globals->banana->port}/";
69 private function fetchProfile()
71 // Get user profile from SQL
72 $req = XDB
::query("SELECT name, mail, sig,
73 FIND_IN_SET('threads',flags) AS threads,
74 FIND_IN_SET('automaj',flags) AS maj,
75 FIND_IN_SET('xface', flags) AS xface,
76 tree_unread, tree_read
78 WHERE uid = {?}", $this->user
->id());
79 if ($req->numRows()) {
80 $infos = $req->fetchOneAssoc();
84 if (empty($infos['name'])) {
85 $infos = array('name' => $this->user
->fullName(),
86 'mail' => $this->user
->forlifeEmail(),
87 'sig' => $this->user
->displayName(),
92 'tree_read' => 'dg' );
99 global $platal, $globals;
101 // Update last unread time
103 if (!is_null($this->params
) && isset($this->params
['updateall'])) {
104 $time = intval($this->params
['updateall']);
105 S
::set('banana_last', $time);
108 $infos = $this->fetchProfile();
113 // Build user profile
114 $req = XDB
::query("SELECT name
115 FROM forum_subs AS fs
116 LEFT JOIN forums AS f ON (f.fid = fs.fid)
117 WHERE uid={?}", $this->user
->id());
118 Banana
::$profile['headers']['From'] = $infos['name'] . ' <' . $infos['mail'] . '>';
119 Banana
::$profile['headers']['Organization'] = make_Organization();
120 Banana
::$profile['signature'] = $infos['sig'];
121 Banana
::$profile['display'] = $infos['threads'];
122 Banana
::$profile['autoup'] = $infos['maj'];
123 Banana
::$profile['lastnews'] = S
::v('banana_last');
124 Banana
::$profile['subscribe'] = $req->fetchColumn();
125 Banana
::$tree_unread = $infos['tree_unread'];
126 Banana
::$tree_read = $infos['tree_read'];
128 // Update the "unread limit"
129 if (!is_null($time)) {
130 XDB
::execute('UPDATE forum_profiles
131 SET last_seen = FROM_UNIXTIME({?})
133 $time, $this->user
->id());
134 if (XDB
::affectedRows() == 0) {
135 XDB
::execute('INSERT INTO forum_profiles (uid, last_seen)
136 VALUES ({?}, FROM_UNIXTIME({?}))',
137 $this->user
->id(), $time);
141 if (!empty($GLOBALS['IS_XNET_SITE'])) {
142 Banana
::$page->killPage('forums');
143 Banana
::$page->killPage('subscribe');
144 Banana
::$spool_boxlist = false
;
146 // Register custom Banana links and tabs
147 if (!Banana
::$profile['autoup']) {
148 Banana
::$page->registerAction('<a href=\'javascript:dynpostkv("'
149 . $platal->path
. '", "updateall", ' . time() . ')\'>'
150 . 'Marquer tous les messages comme lus'
151 . '</a>', array('forums', 'thread', 'message'));
153 Banana
::$page->registerPage('profile', 'Préférences', null
);
157 if (Banana
::$action == 'profile') {
158 Banana
::$page->run();
159 return $this->action_updateProfile();
161 return parent
::run();
165 public function post($dest, $reply, $subject, $body)
168 Banana
::$profile['headers']['From'] = $this->user
->fullName() . ' <' . $this->user
->bestEmail() . '>';
169 Banana
::$profile['headers']['Organization'] = make_Organization();
170 return parent
::post($dest, $reply, $subject, $body);
173 protected function action_saveSubs($groups)
176 $uid = $this->user
->id();
178 Banana
::$profile['subscribe'] = array();
179 XDB
::execute('DELETE FROM forum_subs
180 WHERE uid = {?}', $this->user
->id());
181 if (!count($groups)) {
185 $fids = XDB
::fetchAllAssoc('name', 'SELECT fid, name
187 $diff = array_diff($groups, array_keys($fids));
188 foreach ($diff as $g) {
189 XDB
::execute('INSERT INTO forums (name)
191 $fids[$g] = XDB
::insertId();
194 foreach ($groups as $g) {
195 XDB
::execute('INSERT INTO forum_subs (fid, uid)
198 Banana
::$profile['subscribe'][] = $g;
202 protected function action_updateProfile()
205 $page =& Platal
::page();
207 $colors = glob(dirname(__FILE__
) . '/../../htdocs/images/banana/m2*.gif');
208 foreach ($colors as $key=>$path) {
209 $path = basename($path, '.gif');
210 $colors[$key] = substr($path, 2);
212 $page->assign('colors', $colors);
214 if (Post
::has('action') && Post
::v('action') == 'Enregistrer') {
215 S
::assert_xsrf_token();
216 $flags = new PlFlagSet();
217 if (Post
::b('bananadisplay')) {
218 $flags->addFlag('threads');
220 if (Post
::b('bananaupdate')) {
221 $flags->addFlag('automaj');
223 if (Post
::b('bananaxface')) {
224 $flags->addFlag('xface');
226 $unread = Post
::s('unread');
227 $read = Post
::s('read');
228 if (!in_array($unread, $colors) ||
!in_array($read, $colors)) {
229 $page->trigError('Le choix de type pour l\'arborescence est invalide');
231 $last_seen = XDB
::query('SELECT last_seen
233 WHERE uid = {?}', $this->user
->id());
234 if ($last_seen->numRows() > 0) {
235 $last_seen = $last_seen->fetchOneCell();
237 $last_seen = '0000-00-00';
239 XDB
::execute('REPLACE INTO forum_profiles (uid, sig, mail, name, flags, tree_unread, tree_read, last_seen)
240 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})',
241 $this->user
->id(), Post
::v('bananasig'),
242 Post
::v('bananamail'), Post
::v('banananame'),
243 $flags, $unread, $read, $last_seen);
244 $page->trigSuccess('Ton profil a été mis à jour');
248 $infos = $this->fetchProfile();
249 $page->assign('nom' , $infos['name']);
250 $page->assign('mail', $infos['mail']);
251 $page->assign('sig', $infos['sig']);
252 $page->assign('disp', $infos['threads']);
253 $page->assign('maj', $infos['maj']);
254 $page->assign('xface', $infos['xface']);
255 $page->assign('unread', $infos['tree_unread']);
256 $page->assign('read', $infos['tree_read']);
261 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: