86d13b5ba1d4cffdefa787bf0ece2c13dfc36ed8
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('hruid') or S
::has_perms());
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 = 'news://web_' . $user->login()
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 Banana
::$feed_active = S
::hasAuthToken();
51 parent
::__construct($params, 'NNTP', 'PlatalBananaPage');
52 if (@$params['action'] == 'profile') {
53 Banana
::$action = 'profile';
57 private function fetchProfile()
59 // Get user profile from SQL
60 $req = XDB
::query("SELECT name, mail, sig,
61 FIND_IN_SET('threads',flags) AS threads,
62 FIND_IN_SET('automaj',flags) AS maj,
63 FIND_IN_SET('xface', flags) AS xface,
64 tree_unread, tree_read
66 WHERE uid = {?}", $this->user
->id());
67 if ($req->numRows()) {
68 $infos = $req->fetchOneAssoc();
72 if (empty($infos['name'])) {
73 $infos = array('name' => $this->user
->fullName(),
74 'mail' => $this->user
->forlifeEmail(),
75 'sig' => $this->user
->displayName(),
80 'tree_read' => 'dg' );
87 global $platal, $globals;
89 // Update last unread time
91 if (!is_null($this->params
) && isset($this->params
['updateall'])) {
92 $time = intval($this->params
['updateall']);
93 S
::set('banana_last', $time);
96 $infos = $this->fetchProfile();
101 // Build user profile
102 $req = XDB
::query("SELECT name
103 FROM forum_subs AS fs
104 LEFT JOIN forums AS f ON (f.fid = fs.fid)
105 WHERE uid={?}", $this->user
->id());
106 Banana
::$profile['headers']['From'] = $infos['name'] . ' <' . $infos['mail'] . '>';
107 Banana
::$profile['headers']['Organization'] = make_Organization();
108 Banana
::$profile['signature'] = $infos['sig'];
109 Banana
::$profile['display'] = $infos['threads'];
110 Banana
::$profile['autoup'] = $infos['maj'];
111 Banana
::$profile['lastnews'] = S
::v('banana_last');
112 Banana
::$profile['subscribe'] = $req->fetchColumn();
113 Banana
::$tree_unread = $infos['tree_unread'];
114 Banana
::$tree_read = $infos['tree_read'];
116 // Update the "unread limit"
117 if (!is_null($time)) {
118 XDB
::execute('UPDATE forum_profiles
119 SET last_seen = FROM_UNIXTIME({?})
121 $time, $this->user
->id());
122 if (XDB
::affectedRows() == 0) {
123 XDB
::execute('INSERT INTO forum_profiles (uid, last_seen)
124 VALUES ({?}, FROM_UNIXTIME({?}))',
125 $this->user
->id(), $time);
129 if (!empty($GLOBALS['IS_XNET_SITE'])) {
130 Banana
::$page->killPage('forums');
131 Banana
::$page->killPage('subscribe');
132 Banana
::$spool_boxlist = false
;
134 // Register custom Banana links and tabs
135 if (!Banana
::$profile['autoup']) {
136 Banana
::$page->registerAction('<a href=\'javascript:dynpostkv("'
137 . $platal->path
. '", "updateall", ' . time() . ')\'>'
138 . 'Marquer tous les messages comme lus'
139 . '</a>', array('forums', 'thread', 'message'));
141 Banana
::$page->registerPage('profile', 'Préférences', null
);
145 if (Banana
::$action == 'profile') {
146 Banana
::$page->run();
147 return $this->action_updateProfile();
149 return parent
::run();
153 public function post($dest, $reply, $subject, $body)
156 Banana
::$profile['headers']['From'] = $this->user
->fullName() . ' <' . $this->user
->bestEmail() . '>';
157 Banana
::$profile['headers']['Organization'] = make_Organization();
158 return parent
::post($dest, $reply, $subject, $body);
161 protected function action_saveSubs($groups)
164 $uid = $this->user
->id();
166 Banana
::$profile['subscribe'] = array();
167 XDB
::execute('DELETE FROM forum_subs
168 WHERE uid = {?}', $this->user
->id());
169 if (!count($groups)) {
173 $fids = XDB
::fetchAllAssoc('name', 'SELECT fid, name
175 $diff = array_diff($groups, array_keys($fids));
176 foreach ($diff as $g) {
177 XDB
::execute('INSERT INTO forums (name)
179 $fids[$g] = XDB
::insertId();
182 foreach ($groups as $g) {
183 XDB
::execute('INSERT INTO forum_subs (fid, uid)
186 Banana
::$profile['subscribe'][] = $g;
190 protected function action_updateProfile()
193 $page =& Platal
::page();
195 $colors = glob(dirname(__FILE__
) . '/../../htdocs/images/banana/m2*.gif');
196 foreach ($colors as $key=>$path) {
197 $path = basename($path, '.gif');
198 $colors[$key] = substr($path, 2);
200 $page->assign('colors', $colors);
202 if (Post
::has('action') && Post
::v('action') == 'Enregistrer') {
203 S
::assert_xsrf_token();
204 $flags = new PlFlagSet();
205 if (Post
::b('bananadisplay')) {
206 $flags->addFlag('threads');
208 if (Post
::b('bananaupdate')) {
209 $flags->addFlag('automaj');
211 if (Post
::b('bananaxface')) {
212 $flags->addFlag('xface');
214 $unread = Post
::s('unread');
215 $read = Post
::s('read');
216 if (!in_array($unread, $colors) ||
!in_array($read, $colors)) {
217 $page->trigError('Le choix de type pour l\'arborescence est invalide');
219 $last_seen = XDB
::query('SELECT last_seen
221 WHERE uid = {?}', $this->user
->id());
222 if ($last_seen->numRows() > 0) {
223 $last_seen = $last_seen->fetchOneCell();
225 $last_seen = '0000-00-00';
227 XDB
::execute('REPLACE INTO forum_profiles (uid, sig, mail, name, flags, tree_unread, tree_read, last_seen)
228 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})',
229 $this->user
->id(), Post
::v('bananasig'),
230 Post
::v('bananamail'), Post
::v('banananame'),
231 $flags, $unread, $read, $last_seen);
232 $page->trigSuccess('Ton profil a été mis à jour');
236 $infos = $this->fetchProfile();
237 $page->assign('nom' , $infos['name']);
238 $page->assign('mail', $infos['mail']);
239 $page->assign('sig', $infos['sig']);
240 $page->assign('disp', $infos['threads']);
241 $page->assign('maj', $infos['maj']);
242 $page->assign('xface', $infos['xface']);
243 $page->assign('unread', $infos['tree_unread']);
244 $page->assign('read', $infos['tree_read']);
249 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: