bleh
[platal.git] / modules / banana.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2008 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 class BananaModule extends PLModule
23 {
24 function handlers()
25 {
26 return array(
27 'banana' => $this->make_hook('banana', AUTH_COOKIE),
28 // 'banana/profile' => $this->make_hook('profile', AUTH_MDP),
29 // 'banana/subscribe' => $this->make_hook('subscription', AUTH_COOKIE),
30 'banana/rss' => $this->make_hook('rss', AUTH_PUBLIC, 'user', NO_HTTPS),
31 'admin/forums' => $this->make_hook('forums_bans', AUTH_MDP, 'admin'),
32 'forums/bans/service' => $this->make_hook('forums_bans_service', AUTH_PUBLIC)
33 );
34 }
35
36 function on_subscribe($forlife, $uid, $promo, $password)
37 {
38 $cible = array('xorg.general', 'xorg.pa.divers', 'xorg.pa.logements');
39 $p_for = "xorg.promo.x$promo";
40
41 // récupération de l'id du forum promo
42 $res = XDB::query("SELECT fid FROM forums.list WHERE nom={?}", $p_for);
43 if ($res->numRows()) {
44 $cible[] = $p_for;
45 } else { // pas de forum promo, il faut le créer
46 $res = XDB::query("SELECT SUM(perms IN ('admin','user') AND deces=0),COUNT(*)
47 FROM auth_user_md5 WHERE promo={?}", $promo);
48 list($effau, $effid) = $res->fetchOneRow();
49 if (5*$effau>$effid) { // + de 20% d'inscrits
50 $mymail = new PlMailer('admin/forums-promo.mail.tpl');
51 $mymail->assign('promo', $promo);
52 $mymail->send();
53 }
54 }
55
56 while (list ($key, $val) = each ($cible)) {
57 XDB::execute("INSERT INTO forums.abos (fid,uid)
58 SELECT fid,{?} FROM forums.list WHERE nom={?}", $uid, $val);
59 }
60 }
61
62 function handler_banana(&$page, $group = null, $action = null, $artid = null)
63 {
64 $page->changeTpl('banana/index.tpl');
65 $page->assign('xorg_title','Polytechnique.org - Forums & PA');
66
67 $get = Array();
68 if (Post::has('updateall')) {
69 $get['updateall'] = Post::v('updateall');
70 }
71 require_once 'banana/forum.inc.php';
72 get_banana_params($get, $group, $action, $artid);
73 run_banana($page, 'ForumsBanana', $get);
74 }
75
76 function handler_profile(&$page, $action = null)
77 {
78 global $globals;
79
80 $page->changeTpl('banana/profile.tpl');
81
82 if (!(Post::has('action') && Post::has('banananame') && Post::has('bananasig')
83 && Post::has('bananadisplay') && Post::has('bananamail')
84 && Post::has('bananaupdate') && Post::v('action')=="Enregistrer" ))
85 {
86 $req = XDB::query("
87 SELECT nom, mail, sig,
88 FIND_IN_SET('threads', flags),
89 FIND_IN_SET('automaj', flags),
90 FIND_IN_SET('xface', flags)
91 FROM forums.profils
92 WHERE uid = {?}", S::v('uid'));
93 if (!(list($nom, $mail, $sig, $disp, $maj, $xface) = $req->fetchOneRow())) {
94 $nom = S::v('prenom').' '.S::v('nom');
95 $mail = S::v('forlife').'@'.$globals->mail->domain;
96 $sig = $nom.' ('.S::v('promo').')';
97 $disp = 0;
98 $maj = 0;
99 $xface = 0;
100 }
101 $page->assign('nom' , $nom);
102 $page->assign('mail', $mail);
103 $page->assign('sig', $sig);
104 $page->assign('disp', $disp);
105 $page->assign('maj', $maj);
106 $page->assign('xface', $xface);
107 } else {
108 $flags = array();
109 if (Post::b('bananadisplay')) {
110 $flags[] = 'threads';
111 }
112 if (Post::b('bananaupdate')) {
113 $flags[] = 'automaj';
114 }
115 if (Post::b('bananaxface')) {
116 $flags[] = 'xface';
117 }
118 XDB::execute("REPLACE INTO forums.profils (uid, sig, mail, nom, flags)
119 VALUES ({?}, {?}, {?}, {?}, {?})",
120 S::v('uid'), Post::v('bananasig'),
121 Post::v('bananamail'), Post::v('banananame'),
122 implode(',', $flags));
123 }
124 }
125
126 function handler_rss(&$page, $group, $alias, $hash, $file = null)
127 {
128 if (is_null($file)) {
129 if (is_null($hash)) {
130 exit;
131 }
132 $this->handler_rss($page, null, $group, $alias, $hash);
133 }
134 require_once('rss.inc.php');
135 $uid = init_rss(null, $alias, $hash);
136 if (!$uid) {
137 exit;
138 }
139 $res = XDB::query("SELECT id AS uid, alias AS forlife
140 FROM aliases
141 WHERE type = 'a_vie' AND id = {?}", $uid);
142 $row = $res->fetchOneAssoc();
143 $_SESSION = array_merge($row, $_SESSION);
144
145 require_once 'banana/forum.inc.php';
146 $banana = new ForumsBanana(S::v('forlife'), array('group' => $group, 'action' => 'rss2'));
147 $banana->run();
148 exit;
149 }
150
151 function handler_forums_bans(&$page, $action = 'list', $id = null)
152 {
153 $page->assign('xorg_title','Polytechnique.org - Administration - Bannissements des forums');
154 $page->assign('title', 'Gestion des mises au ban');
155 $table_editor = new PLTableEditor('admin/forums','forums.innd','id_innd');
156 $table_editor->describe('ipmin','min plage IP',true);
157 $table_editor->describe('ipmax','max plage IP',true);
158 $table_editor->describe('uid','utilisateur',true);
159 $table_editor->describe('write_perm','perm. poster',true);
160 $table_editor->describe('read_perm','perm. lire',true);
161 $table_editor->describe('priority','priorite',true);
162 $table_editor->describe('comment','commentaire',true);
163 $table_editor->apply($page, $action, $id);
164 }
165
166 function handler_forums_bans_service(&$page, $action = 'list', $id = null)
167 {
168 global $globals;
169
170 $ips = array_flip(explode(' ', $globals->banana->bans_authorized_ips));
171
172 if ($ips && isset($ips[$_SERVER['REMOTE_ADDR']])) {
173
174 $res = XDB::query("SELECT priority, read_perm, write_perm, comment
175 FROM forums.innd AS i
176 INNER JOIN x4dat.aliases AS a ON ( a.id = i.uid AND a.type='a_vie' )
177 INNER JOIN x4dat.aliases AS b ON ( b.id = a.id AND b.type != 'homonyme' )
178 WHERE b.alias = '".addslashes(Env::v('forlife'))."'");
179 $ban = $res->fetchOneAssoc();
180 echo $res['priority']."\n".$res['read_perm']."\n".$res['write_perm']."\n".$res['comment']."\n";
181 }
182 exit();
183 }
184
185 static function run_banana(&$page, $params = null)
186 {
187 $page->changeTpl('banana/index.tpl');
188 $page->assign('xorg_title','Polytechnique.org - Forums & PA');
189
190 require_once 'banana/forum.inc.php';
191 run_banana($page, 'ForumsBanana', $params);
192 }
193 }
194
195 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
196 ?>