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