2 /***************************************************************************
3 * Copyright (C) 2003-2008 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 class BananaModule
extends PLModule
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
)
36 function on_subscribe($forlife, $uid, $promo, $password)
38 $cible = array('xorg.general', 'xorg.pa.divers', 'xorg.pa.logements');
39 $p_for = "xorg.promo.x$promo";
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()) {
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);
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);
62 function handler_banana(&$page, $group = null
, $action = null
, $artid = null
)
64 $page->changeTpl('banana/index.tpl');
65 $page->assign('xorg_title','Polytechnique.org - Forums & PA');
68 if (Post
::has('updateall')) {
69 $get['updateall'] = Post
::v('updateall');
71 require_once 'banana/forum.inc.php';
72 get_banana_params($get, $group, $action, $artid);
73 run_banana($page, 'ForumsBanana', $get);
76 function handler_profile(&$page, $action = null
)
80 $page->changeTpl('banana/profile.tpl');
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" ))
87 SELECT nom, mail, sig,
88 FIND_IN_SET('threads', flags),
89 FIND_IN_SET('automaj', flags),
90 FIND_IN_SET('xface', flags)
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').')';
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);
109 if (Post
::b('bananadisplay')) {
110 $flags[] = 'threads';
112 if (Post
::b('bananaupdate')) {
113 $flags[] = 'automaj';
115 if (Post
::b('bananaxface')) {
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));
126 function handler_rss(&$page, $group, $alias, $hash, $file = null
)
128 if (is_null($file)) {
129 if (is_null($hash)) {
132 $this->handler_rss($page, null
, $group, $alias, $hash);
134 require_once('rss.inc.php');
135 $uid = init_rss(null
, $alias, $hash);
139 $res = XDB
::query("SELECT id AS uid, alias AS forlife
141 WHERE type = 'a_vie' AND id = {?}", $uid);
142 $row = $res->fetchOneAssoc();
143 $_SESSION = array_merge($row, $_SESSION);
145 require_once 'banana/forum.inc.php';
146 $banana = new ForumsBanana(S
::v('forlife'), array('group' => $group, 'action' => 'rss2'));
151 function handler_forums_bans(&$page, $action = 'list', $id = null
)
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);
166 function handler_forums_bans_service(&$page, $action = 'list', $id = null
)
170 $ips = array_flip(explode(' ', $globals->banana
->bans_authorized_ips
));
172 if ($ips && isset($ips[$_SERVER['REMOTE_ADDR']])) {
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";
185 static function run_banana(&$page, $params = null
)
187 $page->changeTpl('banana/index.tpl');
188 $page->assign('xorg_title','Polytechnique.org - Forums & PA');
190 require_once 'banana/forum.inc.php';
191 run_banana($page, 'ForumsBanana', $params);
195 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: