Commit | Line | Data |
---|---|---|
24cec3d8 | 1 | <?php |
2 | /*************************************************************************** | |
3 | * Copyright (C) 2003-2007 Polytechnique.org * | |
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 | { | |
27 | return ($_headers['x-org-id'] == S::v('forlife') or S::has_perms()); | |
28 | } | |
29 | ||
fa7d6c7b | 30 | class ForumsBanana extends Banana |
24cec3d8 | 31 | { |
b2bffbe6 | 32 | private $forlife; |
33 | ||
34 | public function __construct($forlife, $params = null) | |
24cec3d8 | 35 | { |
b2bffbe6 | 36 | $this->forlife = $forlife; |
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'); |
b2bffbe6 | 42 | Banana::$nntp_host = 'news://web_'.$forlife |
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 | } | |
24cec3d8 | 52 | parent::__construct($params); |
53 | } | |
54 | ||
55 | public function run() | |
56 | { | |
57 | global $platal, $globals; | |
58 | ||
59 | // Update last unread time | |
60 | $time = null; | |
61 | if (!is_null($this->params) && isset($this->params['updateall'])) { | |
62 | $time = intval($this->params['updateall']); | |
63 | $_SESSION['banana_last'] = $time; | |
64 | } | |
65 | ||
66 | // Get user profile from SQL | |
67 | $req = XDB::query("SELECT nom, mail, sig, | |
68 | FIND_IN_SET('threads',flags), FIND_IN_SET('automaj',flags) | |
69 | FROM {$globals->banana->table_prefix}profils | |
70 | WHERE uid={?}", S::i('uid')); | |
71 | if (!(list($nom,$mail,$sig,$disp,$maj) = $req->fetchOneRow())) { | |
72 | $nom = S::v('prenom')." ".S::v('nom'); | |
1d55fe45 | 73 | $mail = S::v('forlife')."@" . $globals->mail->domain; |
24cec3d8 | 74 | $sig = $nom." (".S::v('promo').")"; |
75 | $disp = 0; | |
76 | $maj = 1; | |
77 | } | |
78 | if ($maj) { | |
79 | $time = time(); | |
80 | } | |
81 | ||
82 | // Build user profile | |
eaf30d86 PH |
83 | $req = XDB::query(" |
84 | SELECT nom | |
24cec3d8 | 85 | FROM {$globals->banana->table_prefix}abos |
86 | LEFT JOIN {$globals->banana->table_prefix}list ON list.fid=abos.fid | |
87 | WHERE uid={?}", S::i('uid')); | |
fa2056fe | 88 | Banana::$profile['headers']['From'] = "$nom <$mail>"; |
24cec3d8 | 89 | Banana::$profile['headers']['Organization'] = 'Utilisateur de Polytechnique.org'; |
fa2056fe | 90 | Banana::$profile['signature'] = $sig; |
24cec3d8 | 91 | Banana::$profile['display'] = $disp; |
92 | Banana::$profile['autoup'] = $maj; | |
93 | Banana::$profile['lastnews'] = S::v('banana_last'); | |
94 | Banana::$profile['subscribe'] = $req->fetchColumn(); | |
95 | ||
eaf30d86 | 96 | // Update the "unread limit" |
24cec3d8 | 97 | if (!is_null($time)) { |
98 | XDB::execute("UPDATE auth_user_quick | |
99 | SET banana_last = FROM_UNIXTIME({?}) | |
100 | WHERE user_id={?}", | |
101 | $time, S::i('uid')); | |
102 | } | |
103 | ||
4f355064 | 104 | if (!empty($GLOBALS['IS_XNET_SITE'])) { |
105 | Banana::$page->killPage('forums'); | |
106 | Banana::$page->killPage('subscribe'); | |
107 | Banana::$spool_boxlist = false; | |
eaf30d86 | 108 | } else { |
4f355064 | 109 | // Register custom Banana links and tabs |
110 | if (!Banana::$profile['autoup']) { | |
111 | Banana::$page->registerAction('<a href=\'javascript:dynpostkv("' | |
112 | . $platal->path . '", "updateall", ' . time() . ')\'>' | |
113 | . 'Marquer tous les messages comme lus' | |
114 | . '</a>', array('forums', 'thread', 'message')); | |
eaf30d86 | 115 | } |
4f355064 | 116 | Banana::$page->registerPage('profile', 'Préférences', null); |
117 | } | |
24cec3d8 | 118 | |
119 | // Run Banana | |
120 | return parent::run(); | |
121 | } | |
122 | ||
b2bffbe6 | 123 | public function post($dest, $reply, $subject, $body) |
124 | { | |
125 | global $globals; | |
126 | $res = XDB::query('SELECT nom, prenom, promo, b.alias AS bestalias | |
127 | FROM auth_user_md5 AS u | |
128 | INNER JOIN aliases AS a ON (a.id = u.user_id) | |
129 | INNER JOIN aliases AS b ON (b.id = a.id AND FIND_IN_SET(\'bestalias\', b.flags)) | |
130 | WHERE a.alias = {?}', $this->forlife); | |
131 | list($nom, $prenom, $promo, $bestalias) = $res->fetchOneRow(); | |
132 | Banana::$profile['headers']['From'] = "$prenom $nom ($promo) <$bestalias@{$globals->mail->domain}>"; | |
133 | Banana::$profile['headers']['Organization'] = 'Utilisateur de Polytechnique.org'; | |
134 | return parent::post($dest, $reply, $subject, $body); | |
135 | } | |
136 | ||
24cec3d8 | 137 | protected function action_saveSubs($groups) |
138 | { | |
139 | global $globals; | |
140 | $uid = S::v('uid'); | |
141 | ||
142 | Banana::$profile['subscribe'] = array(); | |
143 | XDB::execute("DELETE FROM {$globals->banana->table_prefix}abos WHERE uid={?}", $uid); | |
144 | if (!count($groups)) { | |
145 | return true; | |
146 | } | |
147 | ||
148 | $req = XDB::iterRow("SELECT fid,nom FROM {$globals->banana->table_prefix}list"); | |
149 | $fids = array(); | |
150 | while (list($fid,$fnom) = $req->next()) { | |
151 | $fids[$fnom] = $fid; | |
152 | } | |
153 | ||
154 | $diff = array_diff($groups, array_keys($fids)); | |
155 | foreach ($diff as $g) { | |
156 | XDB::execute("INSERT INTO {$globals->banana->table_prefix}list (nom) VALUES ({?})", $g); | |
157 | $fids[$g] = XDB::insertId(); | |
158 | } | |
159 | ||
160 | foreach ($groups as $g) { | |
161 | XDB::execute("INSERT INTO {$globals->banana->table_prefix}abos (fid,uid) VALUES ({?},{?})", | |
162 | $fids[$g], $uid); | |
163 | Banana::$profile['subscribe'][] = $g; | |
164 | } | |
165 | } | |
166 | } | |
167 | ||
a7de4ef7 | 168 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
24cec3d8 | 169 | ?> |