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;
62 $pass = $globals->banana
->password
;
64 $pass = $globals->banana
->web_pass
;
66 return $scheme . '://' . $user
67 . ":{$pass}@{$globals->banana->server}:{$globals->banana->port}/";
71 private function fetchProfile()
73 // Get user profile from SQL
74 $req = XDB
::query("SELECT name, mail, sig,
75 FIND_IN_SET('threads',flags) AS threads,
76 FIND_IN_SET('automaj',flags) AS maj,
77 FIND_IN_SET('xface', flags) AS xface,
78 tree_unread, tree_read
80 WHERE uid = {?}", $this->user
->id());
81 if ($req->numRows()) {
82 $infos = $req->fetchOneAssoc();
86 if (empty($infos['name'])) {
87 $infos = array('name' => $this->user
->fullName(),
88 'mail' => $this->user
->forlifeEmail(),
89 'sig' => $this->user
->displayName(),
94 'tree_read' => 'dg' );
101 global $platal, $globals;
103 // Update last unread time
105 if (!is_null($this->params
) && isset($this->params
['updateall'])) {
106 $time = intval($this->params
['updateall']);
107 $this->user
->banana_last
= $time;
110 $infos = $this->fetchProfile();
115 // Build user profile
116 $req = XDB
::query("SELECT name
117 FROM forum_subs AS fs
118 LEFT JOIN forums AS f ON (f.fid = fs.fid)
119 WHERE uid={?}", $this->user
->id());
120 Banana
::$profile['headers']['From'] = $infos['name'] . ' <' . $infos['mail'] . '>';
121 Banana
::$profile['headers']['Organization'] = make_Organization();
122 Banana
::$profile['signature'] = $infos['sig'];
123 Banana
::$profile['display'] = $infos['threads'];
124 Banana
::$profile['autoup'] = $infos['maj'];
125 Banana
::$profile['lastnews'] = $this->user
->banana_last
;
126 Banana
::$profile['subscribe'] = $req->fetchColumn();
127 Banana
::$tree_unread = $infos['tree_unread'];
128 Banana
::$tree_read = $infos['tree_read'];
130 // Update the "unread limit"
131 if (!is_null($time)) {
132 XDB
::execute('UPDATE forum_profiles
133 SET last_seen = FROM_UNIXTIME({?})
135 $time, $this->user
->id());
136 if (XDB
::affectedRows() == 0) {
137 XDB
::execute('INSERT IGNORE INTO forum_profiles (uid, last_seen)
138 VALUES ({?}, FROM_UNIXTIME({?}))',
139 $this->user
->id(), $time);
143 if (!empty($GLOBALS['IS_XNET_SITE'])) {
144 Banana
::$page->killPage('forums');
145 Banana
::$page->killPage('subscribe');
146 Banana
::$spool_boxlist = false
;
148 // Register custom Banana links and tabs
149 if (!Banana
::$profile['autoup']) {
150 Banana
::$page->registerAction('<a href=\'javascript:dynpostkv("'
151 . $platal->path
. '", "updateall", ' . time() . ')\'>'
152 . 'Marquer tous les messages comme lus'
153 . '</a>', array('forums', 'thread', 'message'));
155 Banana
::$page->registerPage('profile', 'Préférences', null
);
159 if (Banana
::$action == 'profile') {
160 Banana
::$page->run();
161 return $this->action_updateProfile();
163 return parent
::run();
167 public function post($dest, $reply, $subject, $body)
170 Banana
::$profile['headers']['From'] = $this->user
->fullName() . ' <' . $this->user
->bestEmail() . '>';
171 Banana
::$profile['headers']['Organization'] = make_Organization();
172 return parent
::post($dest, $reply, $subject, $body);
175 protected function action_saveSubs($groups)
178 $uid = $this->user
->id();
180 Banana
::$profile['subscribe'] = array();
181 XDB
::execute('DELETE FROM forum_subs
182 WHERE uid = {?}', $this->user
->id());
183 if (!count($groups)) {
187 $fids = XDB
::fetchAllAssoc('name', 'SELECT fid, name
189 $diff = array_diff($groups, array_keys($fids));
190 foreach ($diff as $g) {
191 XDB
::execute('INSERT INTO forums (name)
193 $fids[$g] = XDB
::insertId();
196 foreach ($groups as $g) {
197 XDB
::execute('INSERT INTO forum_subs (fid, uid)
200 Banana
::$profile['subscribe'][] = $g;
204 protected function action_updateProfile()
207 $page =& Platal
::page();
209 $colors = glob(dirname(__FILE__
) . '/../../htdocs/images/banana/m2*.gif');
210 foreach ($colors as $key=>$path) {
211 $path = basename($path, '.gif');
212 $colors[$key] = substr($path, 2);
214 $page->assign('colors', $colors);
216 if (Post
::has('action') && Post
::v('action') == 'Enregistrer') {
217 S
::assert_xsrf_token();
218 $flags = new PlFlagSet();
219 if (Post
::b('bananadisplay')) {
220 $flags->addFlag('threads');
222 if (Post
::b('bananaupdate')) {
223 $flags->addFlag('automaj');
225 if (Post
::b('bananaxface')) {
226 $flags->addFlag('xface');
228 $unread = Post
::s('unread');
229 $read = Post
::s('read');
230 if (!in_array($unread, $colors) ||
!in_array($read, $colors)) {
231 $page->trigError('Le choix de type pour l\'arborescence est invalide');
233 $last_seen = XDB
::query('SELECT last_seen
235 WHERE uid = {?}', $this->user
->id());
236 if ($last_seen->numRows() > 0) {
237 $last_seen = $last_seen->fetchOneCell();
239 $last_seen = '0000-00-00';
241 XDB
::execute('REPLACE INTO forum_profiles (uid, sig, mail, name, flags, tree_unread, tree_read, last_seen)
242 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})',
243 $this->user
->id(), Post
::v('bananasig'),
244 Post
::v('bananamail'), Post
::v('banananame'),
245 $flags, $unread, $read, $last_seen);
246 $page->trigSuccess('Ton profil a été mis à jour');
250 $infos = $this->fetchProfile();
251 $page->assign('nom' , $infos['name']);
252 $page->assign('mail', $infos['mail']);
253 $page->assign('sig', $infos['sig']);
254 $page->assign('disp', $infos['threads']);
255 $page->assign('maj', $infos['maj']);
256 $page->assign('xface', $infos['xface']);
257 $page->assign('unread', $infos['tree_unread']);
258 $page->assign('read', $infos['tree_read']);
263 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: