migrate rss.php
[platal.git] / modules / platal.php
CommitLineData
e59506eb 1<?php
2/***************************************************************************
3 * Copyright (C) 2003-2006 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
22class PlatalModule extends PLModule
23{
24 function handlers()
25 {
26 return array(
4da0b8d7 27 // Preferences thingies
28 'prefs' => $this->make_hook('prefs', AUTH_COOKIE),
29 'prefs/rss' => $this->make_hook('prefs_rss', AUTH_COOKIE),
30 'skin' => $this->make_hook('skin', AUTH_COOKIE),
31
32 // password related thingies
33 'password' => $this->make_hook('password', AUTH_MDP),
34 'tmpPWD' => $this->make_hook('tmpPWD', AUTH_PUBLIC),
35
36 // happenings related thingies
37 'rss' => $this->make_hook('rss', AUTH_PUBLIC),
e59506eb 38 );
39 }
40
7927d719 41 function __set_rss_state($state)
42 {
43 global $globals;
44
45 if ($state) {
46 $_SESSION['core_rss_hash'] = rand_url_id(16);
47 $globals->xdb->execute('UPDATE auth_user_quick
48 SET core_rss_hash={?} WHERE user_id={?}',
49 Session::get('core_rss_hash'),
50 Session::getInt('uid'));
51 } else {
52 $globals->xdb->execute('UPDATE auth_user_quick
53 SET core_rss_hash="" WHERE user_id={?}',
54 Session::getInt('uid'));
55 Session::kill('core_rss_hash');
56 }
57 }
58
e59506eb 59 function handler_prefs(&$page)
60 {
61 global $globals;
62
63 $page->changeTpl('preferences.tpl');
64 $page->assign('xorg_title','Polytechnique.org - Mes préférences');
65
66 if (Env::has('mail_fmt')) {
67 $fmt = Env::get('mail_fmt');
68 if ($fmt != 'texte') $fmt = 'html';
69 $globals->xdb->execute("UPDATE auth_user_quick
70 SET core_mail_fmt = '$fmt'
71 WHERE user_id = {?}",
72 Session::getInt('uid'));
73 $_SESSION['mail_fmt'] = $fmt;
74 redirect('preferences');
75 }
76
77 if (Env::has('rss')) {
7927d719 78 $this->__set_rss_state(Env::getBool('rss'));
e59506eb 79 }
80
81 $page->assign('prefs', $globals->hook->prefs());
a2558f2b 82
83 return PL_OK;
e59506eb 84 }
9bae6004 85
4da0b8d7 86 function handler_prefs_rss(&$page)
7927d719 87 {
88 global $globals;
89
90 $page->changeTpl('filrss.tpl');
91
92 $page->assign('goback', Env::get('referer', 'login'));
93
94 if (Env::get('act_rss') == 'Activer') {
95 $this->__set_rss_state(true);
96 $page->trig("Ton Fil RSS est activé.");
97 }
98
99 return PL_OK;
100 }
101
7c77c3ee 102 function handler_password(&$page)
103 {
104 global $globals;
105
106 if (Post::has('response2')) {
107 require_once 'secure_hash.inc.php';
108
109 $_SESSION['password'] = $password = Post::get('response2');
110
111 $globals->xdb->execute('UPDATE auth_user_md5
112 SET password={?}
113 WHERE user_id={?}', $password,
114 Session::getInt('uid'));
115
116 $log =& Session::getMixed('log');
117 $log->log('passwd', '');
118
119 if (Cookie::get('ORGaccess')) {
120 setcookie('ORGaccess', hash_encrypt($password), (time()+25920000), '/', '' ,0);
121 }
122
123 $page->changeTpl('motdepasse.success.tpl');
124 $page->run();
125 }
126
127 $page->changeTpl('motdepasse.tpl');
128 $page->addJsLink('javascript/motdepasse.js');
129 $page->assign('xorg_title','Polytechnique.org - Mon mot de passe');
130
131 return PL_OK;
132 }
133
6c49d0af 134 function handler_tmpPWD(&$page, $certif = null)
135 {
136 global $globals;
137
138 $globals->xdb->execute('DELETE FROM perte_pass
139 WHERE DATE_SUB(NOW(), INTERVAL 380 MINUTE) > created');
140
141 $res = $globals->xdb->query('SELECT uid FROM perte_pass WHERE certificat={?}', $certif);
142 $ligne = $res->fetchOneAssoc();
143 if (!$ligne) {
144 $page->changeTpl('index.tpl');
145 $page->kill("Cette adresse n'existe pas ou n'existe plus sur le serveur.");
146 }
147
148 $uid = $ligne["uid"];
149 if (Post::has('response2')) {
150 $password = Post::get('response2');
151 $logger = new DiogenesCoreLogger($uid);
152 $globals->xdb->query('UPDATE auth_user_md5 SET password={?}
153 WHERE user_id={?} AND perms IN("admin","user")',
154 $password, $uid);
155 $globals->xdb->query('DELETE FROM perte_pass WHERE certificat={?}', $certif);
156 $logger->log("passwd","");
157 $page->changeTpl('tmpPWD.success.tpl');
158 } else {
159 $page->changeTpl('motdepasse.tpl');
160 $page->addJsLink('javascript/motdepasse.js');
161 }
162
163 return PL_OK;
164 }
165
9bae6004 166 function handler_skin(&$page)
167 {
168 global $globals;
169
170 if (!$globals->skin->enable) {
f09cee18 171 redirect('./');
9bae6004 172 }
f09cee18 173
174 $page->changeTpl('skins.tpl');
9bae6004 175 $page->assign('xorg_title','Polytechnique.org - Skins');
176
177 if (Env::has('newskin')) { // formulaire soumis, traitons les données envoyées
178 $globals->xdb->execute('UPDATE auth_user_quick
179 SET skin={?} WHERE user_id={?}',
180 Env::getInt('newskin'),
181 Session::getInt('uid'));
182 set_skin();
183 }
184
185 $sql = "SELECT s.*,auteur,count(*) AS nb
186 FROM skins AS s
187 LEFT JOIN auth_user_quick AS a ON s.id=a.skin
188 WHERE skin_tpl != '' AND ext != ''
189 GROUP BY id ORDER BY s.date DESC";
190 $page->assign_by_ref('skins', $globals->xdb->iterator($sql));
191 return PL_OK;
192 }
4da0b8d7 193
194 function handler_rss(&$page, $user = null, $hash = null)
195 {
196 global $globals;
197
198 require_once 'rss.inc.php';
199
200 $uid = init_rss('rss.tpl', $user, $hash);
201
202 $rss = $globals->xdb->iterator(
203 'SELECT e.id, e.titre, e.texte, e.creation_date
204 FROM auth_user_md5 AS u
205 INNER JOIN evenements AS e ON ( (e.promo_min = 0 || e.promo_min <= u.promo)
206 AND (e.promo_max = 0 || e.promo_max >= u.promo) )
207 WHERE u.user_id = {?} AND FIND_IN_SET(e.flags, "valide")
208 AND peremption >= NOW()', $uid);
209 $page->assign('rss', $rss);
210
211 return PL_OK;
212 }
e59506eb 213}
214
215?>