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