2 /***************************************************************************
3 * Copyright (C) 2003-2010 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/hooks.inc.php';
24 function hook_checkcancel($_headers)
26 return ($_headers['x-org-id'] == S
::v('hruid') or S
::admin());
29 class ForumsBanana
extends Banana
33 public function __construct(User
&$user, $params = null
)
38 Banana
::$msgedit_canattach = false
;
39 Banana
::$spool_root = $globals->spoolroot
. '/spool/banana/';
40 array_push(Banana
::$msgparse_headers, 'x-org-id', 'x-org-mail');
41 Banana
::$nntp_host = self
::buildURL($user->login());
43 Banana
::$msgshow_mimeparts[] = 'source';
45 Banana
::$debug_nntp = ($globals->debug
& DEBUG_BT
);
46 Banana
::$debug_smarty = ($globals->debug
& DEBUG_SMARTY
);
47 Banana
::$feed_active = S
::hasAuthToken();
49 parent
::__construct($params, 'NNTP', 'PlatalBananaPage');
50 if (@$params['action'] == 'profile') {
51 Banana
::$action = 'profile';
55 public static function buildURL($login = null
)
58 $scheme = ($globals->banana
->port
== 563) ?
"nntps" : "news";
59 $user = $globals->banana
->web_user
;
61 $user .= '_' . $login;
63 return $scheme . '://' . $user
64 . ":{$globals->banana->password}@{$globals->banana->server}:{$globals->banana->port}/";
68 private function fetchProfile()
70 // Get user profile from SQL
71 $req = XDB
::query("SELECT name, mail, sig,
72 FIND_IN_SET('threads',flags) AS threads,
73 FIND_IN_SET('automaj',flags) AS maj,
74 FIND_IN_SET('xface', flags) AS xface,
75 tree_unread, tree_read
77 WHERE uid = {?}", $this->user
->id());
78 if ($req->numRows()) {
79 $infos = $req->fetchOneAssoc();
83 if (empty($infos['name'])) {
84 $infos = array('name' => $this->user
->fullName(),
85 'mail' => $this->user
->forlifeEmail(),
86 'sig' => $this->user
->displayName(),
91 'tree_read' => 'dg' );
98 global $platal, $globals;
100 // Update last unread time
102 if (!is_null($this->params
) && isset($this->params
['updateall'])) {
103 $time = intval($this->params
['updateall']);
104 $this->user
->banana_last
= $time;
107 $infos = $this->fetchProfile();
112 // Build user profile
113 $req = XDB
::query("SELECT name
114 FROM forum_subs AS fs
115 LEFT JOIN forums AS f ON (f.fid = fs.fid)
116 WHERE uid={?}", $this->user
->id());
117 Banana
::$profile['headers']['From'] = $infos['name'] . ' <' . $infos['mail'] . '>';
118 Banana
::$profile['headers']['Organization'] = make_Organization();
119 Banana
::$profile['signature'] = $infos['sig'];
120 Banana
::$profile['display'] = $infos['threads'];
121 Banana
::$profile['autoup'] = $infos['maj'];
122 Banana
::$profile['lastnews'] = $this->user
->banana_last
;
123 Banana
::$profile['subscribe'] = $req->fetchColumn();
124 Banana
::$tree_unread = $infos['tree_unread'];
125 Banana
::$tree_read = $infos['tree_read'];
127 // Update the "unread limit"
128 if (!is_null($time)) {
129 XDB
::execute('UPDATE forum_profiles
130 SET last_seen = FROM_UNIXTIME({?})
132 $time, $this->user
->id());
133 if (XDB
::affectedRows() == 0) {
134 XDB
::execute('INSERT IGNORE INTO forum_profiles (uid, last_seen)
135 VALUES ({?}, FROM_UNIXTIME({?}))',
136 $this->user
->id(), $time);
140 if (!empty($GLOBALS['IS_XNET_SITE'])) {
141 Banana
::$page->killPage('forums');
142 Banana
::$page->killPage('subscribe');
143 Banana
::$spool_boxlist = false
;
145 // Register custom Banana links and tabs
146 if (!Banana
::$profile['autoup']) {
147 Banana
::$page->registerAction('<a href=\'javascript:dynpostkv("'
148 . $platal->path
. '", "updateall", ' . time() . ')\'>'
149 . 'Marquer tous les messages comme lus'
150 . '</a>', array('forums', 'thread', 'message'));
152 Banana
::$page->registerPage('profile', 'Préférences', null
);
156 if (Banana
::$action == 'profile') {
157 Banana
::$page->run();
158 return $this->action_updateProfile();
160 return parent
::run();
164 public function post($dest, $reply, $subject, $body)
167 Banana
::$profile['headers']['From'] = $this->user
->fullName() . ' <' . $this->user
->bestEmail() . '>';
168 Banana
::$profile['headers']['Organization'] = make_Organization();
169 return parent
::post($dest, $reply, $subject, $body);
172 protected function action_saveSubs($groups)
175 $uid = $this->user
->id();
177 Banana
::$profile['subscribe'] = array();
178 XDB
::execute('DELETE FROM forum_subs
179 WHERE uid = {?}', $this->user
->id());
180 if (!count($groups)) {
184 $fids = XDB
::fetchAllAssoc('name', 'SELECT fid, name
186 $diff = array_diff($groups, array_keys($fids));
187 foreach ($diff as $g) {
188 XDB
::execute('INSERT INTO forums (name)
190 $fids[$g] = XDB
::insertId();
193 foreach ($groups as $g) {
194 XDB
::execute('INSERT INTO forum_subs (fid, uid)
197 Banana
::$profile['subscribe'][] = $g;
201 protected function action_updateProfile()
204 $page =& Platal
::page();
206 $colors = glob(dirname(__FILE__
) . '/../../htdocs/images/banana/m2*.gif');
207 foreach ($colors as $key=>$path) {
208 $path = basename($path, '.gif');
209 $colors[$key] = substr($path, 2);
211 $page->assign('colors', $colors);
213 if (Post
::has('action') && Post
::v('action') == 'Enregistrer') {
214 S
::assert_xsrf_token();
215 $flags = new PlFlagSet();
216 if (Post
::b('bananadisplay')) {
217 $flags->addFlag('threads');
219 if (Post
::b('bananaupdate')) {
220 $flags->addFlag('automaj');
222 if (Post
::b('bananaxface')) {
223 $flags->addFlag('xface');
225 $unread = Post
::s('unread');
226 $read = Post
::s('read');
227 if (!in_array($unread, $colors) ||
!in_array($read, $colors)) {
228 $page->trigError('Le choix de type pour l\'arborescence est invalide');
230 $last_seen = XDB
::query('SELECT last_seen
232 WHERE uid = {?}', $this->user
->id());
233 if ($last_seen->numRows() > 0) {
234 $last_seen = $last_seen->fetchOneCell();
236 $last_seen = '0000-00-00';
238 XDB
::execute('REPLACE INTO forum_profiles (uid, sig, mail, name, flags, tree_unread, tree_read, last_seen)
239 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})',
240 $this->user
->id(), Post
::v('bananasig'),
241 Post
::v('bananamail'), Post
::v('banananame'),
242 $flags, $unread, $read, $last_seen);
243 $page->trigSuccess('Ton profil a été mis à jour');
247 $infos = $this->fetchProfile();
248 $page->assign('nom' , $infos['name']);
249 $page->assign('mail', $infos['mail']);
250 $page->assign('sig', $infos['sig']);
251 $page->assign('disp', $infos['threads']);
252 $page->assign('maj', $infos['maj']);
253 $page->assign('xface', $infos['xface']);
254 $page->assign('unread', $infos['tree_unread']);
255 $page->assign('read', $infos['tree_read']);
260 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: