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), |
28 | 'banana/profile' => $this->make_hook('profile', AUTH_MDP), |
a3a1d23b |
29 | 'banana/subscription' => $this->make_hook('subscription', AUTH_COOKIE), |
6544d0e1 |
30 | 'banana/rss' => $this->make_hook('rss', AUTH_PUBLIC), |
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 | |
a7de4ef7 |
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; |
a7de4ef7 |
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 | { |
a3a1d23b |
62 | $get = Array(); |
63 | if (!is_null($group)) { |
64 | $get['group'] = $group; |
65 | } |
7e6495d4 |
66 | if (Post::has('updateall')) { |
85b9d118 |
67 | $get['updateall'] = Post::v('updateall'); |
7e6495d4 |
68 | } |
a3a1d23b |
69 | if (!is_null($action)) { |
70 | if ($action == 'new') { |
71 | $get['action'] = 'new'; |
fa7d6c7b |
72 | } elseif (!is_null($artid)) { |
73 | $get['artid'] = $artid; |
74 | if ($action == 'reply') { |
75 | $get['action'] = 'new'; |
76 | } elseif ($action == 'cancel') { |
77 | $get['action'] = $action; |
78 | } elseif ($action == 'from') { |
79 | $get['first'] = $artid; |
82838f55 |
80 | unset($get['artid']); |
fa7d6c7b |
81 | } elseif ($action == 'read') { |
82 | $get['part'] = @$_GET['part']; |
83 | } elseif ($action == 'source') { |
84 | $get['part'] = 'source'; |
85 | } elseif ($action == 'xface') { |
86 | $get['part'] = 'xface'; |
1515e65a |
87 | } elseif ($action) { |
88 | $get['part'] = str_replace('.', '/', $action); |
89 | } |
a3a1d23b |
90 | } |
fa7d6c7b |
91 | } |
a3a1d23b |
92 | return BananaModule::run_banana($page, $get); |
f585e5a4 |
93 | } |
94 | |
3d9b1d30 |
95 | function handler_profile(&$page, $action = null) |
f585e5a4 |
96 | { |
97 | global $globals; |
98 | |
99 | $page->changeTpl('banana/profile.tpl'); |
100 | |
101 | if (!(Post::has('action') && Post::has('banananame') && Post::has('bananasig') |
102 | && Post::has('bananadisplay') && Post::has('bananamail') |
5e2307dc |
103 | && Post::has('bananaupdate') && Post::v('action')=="OK" )) |
f585e5a4 |
104 | { |
08cce2ff |
105 | $req = XDB::query(" |
f585e5a4 |
106 | SELECT nom,mail,sig,if(FIND_IN_SET('threads',flags),'1','0'), |
107 | IF(FIND_IN_SET('automaj',flags),'1','0') |
108 | FROM forums.profils |
cab08090 |
109 | WHERE uid = {?}", S::v('uid')); |
f585e5a4 |
110 | if (!(list($nom,$mail,$sig,$disp,$maj) = $req->fetchOneRow())) { |
cab08090 |
111 | $nom = S::v('prenom').' '.S::v('nom'); |
112 | $mail = S::v('forlife').'@'.$globals->mail->domain; |
113 | $sig = $nom.' ('.S::v('promo').')'; |
f585e5a4 |
114 | $disp = 0; |
115 | $maj = 0; |
116 | } |
117 | $page->assign('nom' , $nom); |
118 | $page->assign('mail', $mail); |
119 | $page->assign('sig' , $sig); |
120 | $page->assign('disp', $disp); |
121 | $page->assign('maj' , $maj); |
122 | } else { |
08cce2ff |
123 | XDB::execute( |
f585e5a4 |
124 | 'REPLACE INTO forums.profils (uid,sig,mail,nom,flags) |
125 | VALUES ({?},{?},{?},{?},{?})', |
5e2307dc |
126 | S::v('uid'), Post::v('bananasig'), |
127 | Post::v('bananamail'), Post::v('banananame'), |
128 | (Post::b('bananadisplay') ? 'threads,' : '') . |
129 | (Post::b('bananaupdate') ? 'automaj' : '') |
f585e5a4 |
130 | ); |
131 | } |
f585e5a4 |
132 | } |
3d9b1d30 |
133 | |
a3a1d23b |
134 | function handler_subscription(&$page) |
135 | { |
5f4a0314 |
136 | return $this->run_banana($page, Array('action' => 'subscribe')); |
a3a1d23b |
137 | } |
3d9b1d30 |
138 | |
6544d0e1 |
139 | function handler_rss(&$page, $group, $alias, $hash, $file = null) |
f107d806 |
140 | { |
6544d0e1 |
141 | if (is_null($file)) { |
142 | if (is_null($hash)) { |
143 | exit; |
144 | } |
145 | $this->handler_rss($page, null, $group, $alias, $hash); |
146 | } |
147 | require_once('rss.inc.php'); |
148 | $uid = init_rss(null, $alias, $hash); |
149 | if (!$uid) { |
150 | exit; |
151 | } |
152 | $res = XDB::query("SELECT id AS uid, alias AS forlife |
153 | FROM aliases |
154 | WHERE type = 'a_vie' AND id = {?}", $uid); |
155 | $row = $res->fetchOneAssoc(); |
156 | $_SESSION = array_merge($row, $_SESSION); |
157 | |
158 | require_once 'banana/forum.inc.php'; |
159 | $banana = new ForumsBanana(array('group' => $group, 'action' => 'rss2')); |
160 | echo $banana->run(); |
161 | exit; |
f107d806 |
162 | } |
163 | |
5f4a0314 |
164 | static function run_banana(&$page, $params = null) |
a3a1d23b |
165 | { |
3d9b1d30 |
166 | $page->changeTpl('banana/index.tpl'); |
3d9b1d30 |
167 | $page->assign('xorg_title','Polytechnique.org - Forums & PA'); |
168 | |
24cec3d8 |
169 | require_once 'banana/forum.inc.php'; |
3d9b1d30 |
170 | |
fa7d6c7b |
171 | $banana = new ForumsBanana($params); |
5f4a0314 |
172 | $res = $banana->run(); |
3d9b1d30 |
173 | $page->assign_by_ref('banana', $banana); |
174 | $page->assign('banana_res', $res); |
ea626742 |
175 | $page->addCssInline($banana->css()); |
176 | $page->addCssLink('banana.css'); |
6544d0e1 |
177 | $rss = $banana->feed(); |
178 | if ($rss) { |
179 | if (@$params['group']) { |
180 | $page->setRssLink('Banana :: ' . $params['group'], $rss); |
181 | } else { |
182 | $page->setRssLink('Banana :: Abonnements', $rss); |
183 | } |
184 | } |
d3f26be9 |
185 | new PlBacktrace('NNTP', $banana->backtrace(), 'response', 'time'); |
a3a1d23b |
186 | } |
f585e5a4 |
187 | } |
188 | |
a7de4ef7 |
189 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
f585e5a4 |
190 | ?> |