Commit | Line | Data |
---|---|---|
24cec3d8 | 1 | <?php |
2 | /*************************************************************************** | |
8d84c630 | 3 | * Copyright (C) 2003-2009 Polytechnique.org * |
24cec3d8 | 4 | * http://opensource.polytechnique.org/ * |
5 | * * | |
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. * | |
10 | * * | |
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. * | |
15 | * * | |
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 * | |
18 | * Foundation, Inc., * | |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * | |
20 | ***************************************************************************/ | |
21 | ||
22 | require_once 'banana/banana.inc.php'; | |
23 | require_once 'banana/hooks.inc.php'; | |
24 | ||
25 | function hook_checkcancel($_headers) | |
26 | { | |
dd70cd28 | 27 | return ($_headers['x-org-id'] == S::v('hruid') or S::admin()); |
24cec3d8 | 28 | } |
29 | ||
fa7d6c7b | 30 | class ForumsBanana extends Banana |
24cec3d8 | 31 | { |
e3a55098 | 32 | private $user; |
b2bffbe6 | 33 | |
e3a55098 | 34 | public function __construct(User &$user, $params = null) |
24cec3d8 | 35 | { |
e3a55098 | 36 | $this->user = &$user; |
b2bffbe6 | 37 | |
24cec3d8 | 38 | global $globals; |
39 | Banana::$msgedit_canattach = false; | |
580d1c7d | 40 | Banana::$spool_root = $globals->banana->spool_root; |
24cec3d8 | 41 | array_push(Banana::$msgparse_headers, 'x-org-id', 'x-org-mail'); |
ad59fc86 | 42 | Banana::$nntp_host = self::buildURL($user->login()); |
dd70cd28 | 43 | if (S::admin()) { |
1515e65a | 44 | Banana::$msgshow_mimeparts[] = 'source'; |
45 | } | |
81e9c63f | 46 | Banana::$debug_nntp = ($globals->debug & DEBUG_BT); |
47 | Banana::$debug_smarty = ($globals->debug & DEBUG_SMARTY); | |
8c12f931 FB |
48 | Banana::$feed_active = S::hasAuthToken(); |
49 | ||
b8458bd1 | 50 | parent::__construct($params, 'NNTP', 'PlatalBananaPage'); |
ed0c62e4 | 51 | if (@$params['action'] == 'profile') { |
b5163f52 FB |
52 | Banana::$action = 'profile'; |
53 | } | |
24cec3d8 | 54 | } |
55 | ||
ad59fc86 FB |
56 | public static function buildURL($login = null) |
57 | { | |
58 | global $globals; | |
59 | $scheme = ($globals->banana->port == 563) ? "nntps" : "news"; | |
60 | $user = $globals->banana->web_user; | |
61 | if ($login != null) { | |
62 | $user .= '_' . $login; | |
63 | } | |
64 | return $scheme . '://' . $user | |
65 | . ":{$globals->banana->password}@{$globals->banana->server}:{$globals->banana->port}/"; | |
66 | ||
67 | } | |
68 | ||
2bd55de5 FB |
69 | private function fetchProfile() |
70 | { | |
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 | |
77 | FROM forum_profiles | |
78 | WHERE uid = {?}", $this->user->id()); | |
79 | if ($req->numRows()) { | |
80 | $infos = $req->fetchOneAssoc(); | |
81 | } else { | |
82 | $infos = array(); | |
83 | } | |
84 | if (empty($infos['name'])) { | |
85 | $infos = array('name' => $this->user->fullName(), | |
86 | 'mail' => $this->user->forlifeEmail(), | |
87 | 'sig' => $this->user->displayName(), | |
88 | 'threads' => false, | |
89 | 'maj' => true, | |
90 | 'xface' => false, | |
91 | 'tree_unread' => 'o', | |
92 | 'tree_read' => 'dg' ); | |
93 | } | |
94 | return $infos; | |
95 | } | |
96 | ||
24cec3d8 | 97 | public function run() |
98 | { | |
99 | global $platal, $globals; | |
100 | ||
101 | // Update last unread time | |
102 | $time = null; | |
103 | if (!is_null($this->params) && isset($this->params['updateall'])) { | |
104 | $time = intval($this->params['updateall']); | |
7d15f750 | 105 | S::set('banana_last', $time); |
24cec3d8 | 106 | } |
107 | ||
2bd55de5 FB |
108 | $infos = $this->fetchProfile(); |
109 | if ($infos['maj']) { | |
24cec3d8 | 110 | $time = time(); |
111 | } | |
112 | ||
113 | // Build user profile | |
7d15f750 FB |
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()); | |
2bd55de5 | 118 | Banana::$profile['headers']['From'] = $infos['name'] . ' <' . $infos['mail'] . '>'; |
437a98e0 | 119 | Banana::$profile['headers']['Organization'] = make_Organization(); |
2bd55de5 FB |
120 | Banana::$profile['signature'] = $infos['sig']; |
121 | Banana::$profile['display'] = $infos['threads']; | |
122 | Banana::$profile['autoup'] = $infos['maj']; | |
24cec3d8 | 123 | Banana::$profile['lastnews'] = S::v('banana_last'); |
124 | Banana::$profile['subscribe'] = $req->fetchColumn(); | |
2bd55de5 FB |
125 | Banana::$tree_unread = $infos['tree_unread']; |
126 | Banana::$tree_read = $infos['tree_read']; | |
24cec3d8 | 127 | |
eaf30d86 | 128 | // Update the "unread limit" |
24cec3d8 | 129 | if (!is_null($time)) { |
7d15f750 FB |
130 | XDB::execute('UPDATE forum_profiles |
131 | SET last_seen = FROM_UNIXTIME({?}) | |
132 | WHERE uid = {?}', | |
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); | |
138 | } | |
24cec3d8 | 139 | } |
140 | ||
4f355064 | 141 | if (!empty($GLOBALS['IS_XNET_SITE'])) { |
142 | Banana::$page->killPage('forums'); | |
143 | Banana::$page->killPage('subscribe'); | |
144 | Banana::$spool_boxlist = false; | |
eaf30d86 | 145 | } else { |
4f355064 | 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')); | |
eaf30d86 | 152 | } |
4f355064 | 153 | Banana::$page->registerPage('profile', 'Préférences', null); |
154 | } | |
24cec3d8 | 155 | |
b5163f52 FB |
156 | // Run Bananai |
157 | if (Banana::$action == 'profile') { | |
158 | Banana::$page->run(); | |
159 | return $this->action_updateProfile(); | |
160 | } else { | |
161 | return parent::run(); | |
162 | } | |
24cec3d8 | 163 | } |
164 | ||
b2bffbe6 | 165 | public function post($dest, $reply, $subject, $body) |
166 | { | |
167 | global $globals; | |
7d15f750 | 168 | Banana::$profile['headers']['From'] = $this->user->fullName() . ' <' . $this->user->bestEmail() . '>'; |
437a98e0 | 169 | Banana::$profile['headers']['Organization'] = make_Organization(); |
b2bffbe6 | 170 | return parent::post($dest, $reply, $subject, $body); |
171 | } | |
172 | ||
24cec3d8 | 173 | protected function action_saveSubs($groups) |
174 | { | |
175 | global $globals; | |
7d15f750 | 176 | $uid = $this->user->id(); |
24cec3d8 | 177 | |
178 | Banana::$profile['subscribe'] = array(); | |
7d15f750 FB |
179 | XDB::execute('DELETE FROM forum_subs |
180 | WHERE uid = {?}', $this->user->id()); | |
24cec3d8 | 181 | if (!count($groups)) { |
182 | return true; | |
183 | } | |
184 | ||
27fd34d1 FB |
185 | $fids = XDB::fetchAllAssoc('name', 'SELECT fid, name |
186 | FROM forums'); | |
24cec3d8 | 187 | $diff = array_diff($groups, array_keys($fids)); |
188 | foreach ($diff as $g) { | |
7d15f750 FB |
189 | XDB::execute('INSERT INTO forums (name) |
190 | VALUES ({?})', $g); | |
24cec3d8 | 191 | $fids[$g] = XDB::insertId(); |
192 | } | |
193 | ||
194 | foreach ($groups as $g) { | |
7d15f750 FB |
195 | XDB::execute('INSERT INTO forum_subs (fid, uid) |
196 | VALUES ({?}, {?})', | |
24cec3d8 | 197 | $fids[$g], $uid); |
198 | Banana::$profile['subscribe'][] = $g; | |
199 | } | |
200 | } | |
b5163f52 FB |
201 | |
202 | protected function action_updateProfile() | |
203 | { | |
d7610c35 | 204 | global $globals; |
7d15f750 | 205 | $page =& Platal::page(); |
b5163f52 | 206 | |
43cddb05 FB |
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); | |
211 | } | |
212 | $page->assign('colors', $colors); | |
213 | ||
214 | if (Post::has('action') && Post::v('action') == 'Enregistrer') { | |
215 | S::assert_xsrf_token(); | |
7d15f750 | 216 | $flags = new PlFlagSet(); |
b5163f52 | 217 | if (Post::b('bananadisplay')) { |
748b472c | 218 | $flags->addFlag('threads'); |
b5163f52 FB |
219 | } |
220 | if (Post::b('bananaupdate')) { | |
748b472c | 221 | $flags->addFlag('automaj'); |
b5163f52 FB |
222 | } |
223 | if (Post::b('bananaxface')) { | |
748b472c | 224 | $flags->addFlag('xface'); |
b5163f52 | 225 | } |
43cddb05 FB |
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'); | |
748b472c | 230 | } else { |
7d15f750 FB |
231 | $last_seen = XDB::query('SELECT last_seen |
232 | FROM forum_profiles | |
233 | WHERE uid = {?}', $this->user->id()); | |
234 | if ($last_seen->numRows() > 0) { | |
235 | $last_seen = $last_seen->fetchOneCell(); | |
236 | } else { | |
237 | $last_seen = '0000-00-00'; | |
238 | } | |
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'); | |
748b472c FB |
245 | } |
246 | } | |
247 | ||
2bd55de5 | 248 | $infos = $this->fetchProfile(); |
5660032a SJ |
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']); | |
2bd55de5 | 255 | $page->assign('unread', $infos['tree_unread']); |
5660032a | 256 | $page->assign('read', $infos['tree_read']); |
b5163f52 FB |
257 | return null; |
258 | } | |
24cec3d8 | 259 | } |
260 | ||
a7de4ef7 | 261 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
24cec3d8 | 262 | ?> |