Commit | Line | Data |
---|---|---|
24cec3d8 | 1 | <?php |
2 | /*************************************************************************** | |
179afa7f | 3 | * Copyright (C) 2003-2008 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 | { | |
e3a55098 | 27 | return ($_headers['x-org-id'] == S::v('hruid') or S::has_perms()); |
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'); |
e3a55098 | 42 | Banana::$nntp_host = 'news://web_' . $user->login() |
24cec3d8 | 43 | . ":{$globals->banana->password}@{$globals->banana->server}:{$globals->banana->port}/"; |
1515e65a | 44 | if (S::has_perms()) { |
45 | Banana::$msgshow_mimeparts[] = 'source'; | |
46 | } | |
81e9c63f | 47 | Banana::$debug_nntp = ($globals->debug & DEBUG_BT); |
48 | Banana::$debug_smarty = ($globals->debug & DEBUG_SMARTY); | |
6544d0e1 | 49 | if (!S::v('core_rss_hash')) { |
50 | Banana::$feed_active = false; | |
51 | } | |
b8458bd1 | 52 | parent::__construct($params, 'NNTP', 'PlatalBananaPage'); |
ed0c62e4 | 53 | if (@$params['action'] == 'profile') { |
b5163f52 FB |
54 | Banana::$action = 'profile'; |
55 | } | |
24cec3d8 | 56 | } |
57 | ||
58 | public function run() | |
59 | { | |
60 | global $platal, $globals; | |
61 | ||
62 | // Update last unread time | |
63 | $time = null; | |
64 | if (!is_null($this->params) && isset($this->params['updateall'])) { | |
65 | $time = intval($this->params['updateall']); | |
66 | $_SESSION['banana_last'] = $time; | |
67 | } | |
68 | ||
69 | // Get user profile from SQL | |
70 | $req = XDB::query("SELECT nom, mail, sig, | |
71 | FIND_IN_SET('threads',flags), FIND_IN_SET('automaj',flags) | |
72 | FROM {$globals->banana->table_prefix}profils | |
73 | WHERE uid={?}", S::i('uid')); | |
74 | if (!(list($nom,$mail,$sig,$disp,$maj) = $req->fetchOneRow())) { | |
75 | $nom = S::v('prenom')." ".S::v('nom'); | |
e3a55098 | 76 | $mail = $this->user->forlifeEmail(); |
24cec3d8 | 77 | $sig = $nom." (".S::v('promo').")"; |
78 | $disp = 0; | |
79 | $maj = 1; | |
80 | } | |
81 | if ($maj) { | |
82 | $time = time(); | |
83 | } | |
84 | ||
85 | // Build user profile | |
eaf30d86 PH |
86 | $req = XDB::query(" |
87 | SELECT nom | |
24cec3d8 | 88 | FROM {$globals->banana->table_prefix}abos |
89 | LEFT JOIN {$globals->banana->table_prefix}list ON list.fid=abos.fid | |
90 | WHERE uid={?}", S::i('uid')); | |
fa2056fe | 91 | Banana::$profile['headers']['From'] = "$nom <$mail>"; |
437a98e0 | 92 | Banana::$profile['headers']['Organization'] = make_Organization(); |
fa2056fe | 93 | Banana::$profile['signature'] = $sig; |
24cec3d8 | 94 | Banana::$profile['display'] = $disp; |
95 | Banana::$profile['autoup'] = $maj; | |
96 | Banana::$profile['lastnews'] = S::v('banana_last'); | |
97 | Banana::$profile['subscribe'] = $req->fetchColumn(); | |
98 | ||
eaf30d86 | 99 | // Update the "unread limit" |
24cec3d8 | 100 | if (!is_null($time)) { |
101 | XDB::execute("UPDATE auth_user_quick | |
102 | SET banana_last = FROM_UNIXTIME({?}) | |
103 | WHERE user_id={?}", | |
104 | $time, S::i('uid')); | |
105 | } | |
106 | ||
4f355064 | 107 | if (!empty($GLOBALS['IS_XNET_SITE'])) { |
108 | Banana::$page->killPage('forums'); | |
109 | Banana::$page->killPage('subscribe'); | |
110 | Banana::$spool_boxlist = false; | |
eaf30d86 | 111 | } else { |
4f355064 | 112 | // Register custom Banana links and tabs |
113 | if (!Banana::$profile['autoup']) { | |
114 | Banana::$page->registerAction('<a href=\'javascript:dynpostkv("' | |
115 | . $platal->path . '", "updateall", ' . time() . ')\'>' | |
116 | . 'Marquer tous les messages comme lus' | |
117 | . '</a>', array('forums', 'thread', 'message')); | |
eaf30d86 | 118 | } |
4f355064 | 119 | Banana::$page->registerPage('profile', 'Préférences', null); |
120 | } | |
24cec3d8 | 121 | |
b5163f52 FB |
122 | // Run Bananai |
123 | if (Banana::$action == 'profile') { | |
124 | Banana::$page->run(); | |
125 | return $this->action_updateProfile(); | |
126 | } else { | |
127 | return parent::run(); | |
128 | } | |
24cec3d8 | 129 | } |
130 | ||
b2bffbe6 | 131 | public function post($dest, $reply, $subject, $body) |
132 | { | |
133 | global $globals; | |
e3a55098 | 134 | $res = XDB::query('SELECT nom, prenom, promo |
b2bffbe6 | 135 | FROM auth_user_md5 AS u |
e3a55098 VZ |
136 | WHERE u.user_id = {?}', $this->user->id()); |
137 | list($nom, $prenom, $promo) = $res->fetchOneRow(); | |
138 | Banana::$profile['headers']['From'] = "$prenom $nom ($promo) <{$this->user->bestEmail()}>"; | |
437a98e0 | 139 | Banana::$profile['headers']['Organization'] = make_Organization(); |
b2bffbe6 | 140 | return parent::post($dest, $reply, $subject, $body); |
141 | } | |
142 | ||
24cec3d8 | 143 | protected function action_saveSubs($groups) |
144 | { | |
145 | global $globals; | |
146 | $uid = S::v('uid'); | |
147 | ||
148 | Banana::$profile['subscribe'] = array(); | |
149 | XDB::execute("DELETE FROM {$globals->banana->table_prefix}abos WHERE uid={?}", $uid); | |
150 | if (!count($groups)) { | |
151 | return true; | |
152 | } | |
153 | ||
154 | $req = XDB::iterRow("SELECT fid,nom FROM {$globals->banana->table_prefix}list"); | |
155 | $fids = array(); | |
156 | while (list($fid,$fnom) = $req->next()) { | |
157 | $fids[$fnom] = $fid; | |
158 | } | |
159 | ||
160 | $diff = array_diff($groups, array_keys($fids)); | |
161 | foreach ($diff as $g) { | |
162 | XDB::execute("INSERT INTO {$globals->banana->table_prefix}list (nom) VALUES ({?})", $g); | |
163 | $fids[$g] = XDB::insertId(); | |
164 | } | |
165 | ||
166 | foreach ($groups as $g) { | |
167 | XDB::execute("INSERT INTO {$globals->banana->table_prefix}abos (fid,uid) VALUES ({?},{?})", | |
168 | $fids[$g], $uid); | |
169 | Banana::$profile['subscribe'][] = $g; | |
170 | } | |
171 | } | |
b5163f52 FB |
172 | |
173 | protected function action_updateProfile() | |
174 | { | |
175 | global $page, $globals; | |
176 | ||
177 | if (!(Post::has('action') && Post::has('banananame') && Post::has('bananasig') | |
178 | && Post::has('bananadisplay') && Post::has('bananamail') | |
179 | && Post::has('bananaupdate') && Post::v('action')=="Enregistrer" )) | |
180 | { | |
181 | $req = XDB::query(" | |
182 | SELECT nom, mail, sig, | |
183 | FIND_IN_SET('threads', flags), | |
184 | FIND_IN_SET('automaj', flags), | |
185 | FIND_IN_SET('xface', flags) | |
186 | FROM forums.profils | |
187 | WHERE uid = {?}", S::v('uid')); | |
188 | if (!(list($nom, $mail, $sig, $disp, $maj, $xface) = $req->fetchOneRow())) { | |
189 | $nom = S::v('prenom').' '.S::v('nom'); | |
e3a55098 | 190 | $mail = $this->user->forlifeEmail(); |
b5163f52 FB |
191 | $sig = $nom.' ('.S::v('promo').')'; |
192 | $disp = 0; | |
193 | $maj = 0; | |
194 | $xface = 0; | |
195 | } | |
196 | $page->assign('nom' , $nom); | |
197 | $page->assign('mail', $mail); | |
198 | $page->assign('sig', $sig); | |
199 | $page->assign('disp', $disp); | |
200 | $page->assign('maj', $maj); | |
201 | $page->assign('xface', $xface); | |
202 | } else { | |
203 | $flags = array(); | |
204 | if (Post::b('bananadisplay')) { | |
205 | $flags[] = 'threads'; | |
206 | } | |
207 | if (Post::b('bananaupdate')) { | |
208 | $flags[] = 'automaj'; | |
209 | } | |
210 | if (Post::b('bananaxface')) { | |
211 | $flags[] = 'xface'; | |
212 | } | |
213 | XDB::execute("REPLACE INTO forums.profils (uid, sig, mail, nom, flags) | |
214 | VALUES ({?}, {?}, {?}, {?}, {?})", | |
215 | S::v('uid'), Post::v('bananasig'), | |
216 | Post::v('bananamail'), Post::v('banananame'), | |
217 | implode(',', $flags)); | |
218 | } | |
219 | return null; | |
220 | } | |
24cec3d8 | 221 | } |
222 | ||
a7de4ef7 | 223 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
24cec3d8 | 224 | ?> |