f585e5a4 |
1 | <?php |
2 | /*************************************************************************** |
3 | * Copyright (C) 2003-2006 Polytechnique.org * |
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), |
f107d806 |
30 | 'banana/xface' => $this->make_hook('xface', AUTH_COOKIE), |
a3a1d23b |
31 | ); |
f585e5a4 |
32 | } |
33 | |
3d9b1d30 |
34 | function handler_banana(&$page, $group = null, $action = null, $artid = null) |
f585e5a4 |
35 | { |
a3a1d23b |
36 | $get = Array(); |
37 | if (!is_null($group)) { |
38 | $get['group'] = $group; |
39 | } |
7e6495d4 |
40 | if (Post::has('updateall')) { |
41 | $get['banana'] = 'updateall'; |
42 | } |
a3a1d23b |
43 | if (!is_null($action)) { |
44 | if ($action == 'new') { |
45 | $get['action'] = 'new'; |
aafe5c09 |
46 | } elseif ($action == 'reply' && !is_null($artid)) { |
47 | $get['action'] = 'new'; |
48 | $get['artid'] = $artid; |
49 | } elseif ($action == 'cancel' && !is_null($artid)) { |
a3a1d23b |
50 | $get['action'] = $action; |
51 | $get['artid'] = $artid; |
52 | } elseif ($action == 'from' && !is_null($artid)) { |
53 | $get['first'] = $artid; |
54 | } elseif ($action == 'read' && !is_null($artid)) { |
55 | $get['artid'] = $artid; |
56 | } |
57 | } |
58 | return BananaModule::run_banana($page, $get); |
f585e5a4 |
59 | } |
60 | |
3d9b1d30 |
61 | function handler_profile(&$page, $action = null) |
f585e5a4 |
62 | { |
63 | global $globals; |
64 | |
65 | $page->changeTpl('banana/profile.tpl'); |
66 | |
67 | if (!(Post::has('action') && Post::has('banananame') && Post::has('bananasig') |
68 | && Post::has('bananadisplay') && Post::has('bananamail') |
5e2307dc |
69 | && Post::has('bananaupdate') && Post::v('action')=="OK" )) |
f585e5a4 |
70 | { |
08cce2ff |
71 | $req = XDB::query(" |
f585e5a4 |
72 | SELECT nom,mail,sig,if(FIND_IN_SET('threads',flags),'1','0'), |
73 | IF(FIND_IN_SET('automaj',flags),'1','0') |
74 | FROM forums.profils |
cab08090 |
75 | WHERE uid = {?}", S::v('uid')); |
f585e5a4 |
76 | if (!(list($nom,$mail,$sig,$disp,$maj) = $req->fetchOneRow())) { |
cab08090 |
77 | $nom = S::v('prenom').' '.S::v('nom'); |
78 | $mail = S::v('forlife').'@'.$globals->mail->domain; |
79 | $sig = $nom.' ('.S::v('promo').')'; |
f585e5a4 |
80 | $disp = 0; |
81 | $maj = 0; |
82 | } |
83 | $page->assign('nom' , $nom); |
84 | $page->assign('mail', $mail); |
85 | $page->assign('sig' , $sig); |
86 | $page->assign('disp', $disp); |
87 | $page->assign('maj' , $maj); |
88 | } else { |
08cce2ff |
89 | XDB::execute( |
f585e5a4 |
90 | 'REPLACE INTO forums.profils (uid,sig,mail,nom,flags) |
91 | VALUES ({?},{?},{?},{?},{?})', |
5e2307dc |
92 | S::v('uid'), Post::v('bananasig'), |
93 | Post::v('bananamail'), Post::v('banananame'), |
94 | (Post::b('bananadisplay') ? 'threads,' : '') . |
95 | (Post::b('bananaupdate') ? 'automaj' : '') |
f585e5a4 |
96 | ); |
97 | } |
f585e5a4 |
98 | } |
3d9b1d30 |
99 | |
a3a1d23b |
100 | function handler_subscription(&$page) |
101 | { |
102 | return $this->run_banana($page, Array('subscribe' => 1)); |
103 | } |
3d9b1d30 |
104 | |
7e6495d4 |
105 | function handler_xface(&$page, $face = null) |
f107d806 |
106 | { |
a011eab2 |
107 | header('Content-Type: image/gif'); |
7e6495d4 |
108 | passthru('echo ' . escapeshellarg(base64_decode(strtr($face, '.:', '+/'))) |
f107d806 |
109 | . '| uncompface -X ' |
7e6495d4 |
110 | . '| convert -transparent white xbm:- gif:-'); |
f107d806 |
111 | } |
112 | |
a3a1d23b |
113 | function run_banana(&$page, $params = null) |
114 | { |
3d9b1d30 |
115 | $page->changeTpl('banana/index.tpl'); |
116 | $page->addCssLink('css/banana.css'); |
117 | $page->assign('xorg_title','Polytechnique.org - Forums & PA'); |
118 | |
57e834ac |
119 | require_once dirname(__FILE__).'/banana/banana.inc.php'; |
3d9b1d30 |
120 | |
121 | $res = PlatalBanana::run($params); |
122 | $page->assign_by_ref('banana', $banana); |
123 | $page->assign('banana_res', $res); |
a3a1d23b |
124 | } |
f585e5a4 |
125 | } |
126 | |
127 | ?> |