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