eecfc2ccecd0f15793df924d7b04dc33c8c73e3f
[platal.git] / modules / banana.php
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(
27 'banana' => $this->make_hook('banana', AUTH_COOKIE),
28 'banana/profile' => $this->make_hook('profile', AUTH_MDP),
29 'banana/subscription' => $this->make_hook('subscription', AUTH_COOKIE),
30 'banana/xface' => $this->make_hook('xface', AUTH_COOKIE),
31 );
32 }
33
34 function handler_banana(&$page, $group = null, $action = null, $artid = null)
35 {
36 $get = Array();
37 if (!is_null($group)) {
38 $get['group'] = $group;
39 }
40 if (Post::has('updateall')) {
41 $get['banana'] = 'updateall';
42 }
43 if (!is_null($action)) {
44 if ($action == 'new') {
45 $get['action'] = 'new';
46 } elseif ($action == 'reply' && !is_null($artid)) {
47 $get['action'] = 'new';
48 $get['artid'] = $artid;
49 } elseif ($action == 'cancel' && !is_null($artid)) {
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);
59 }
60
61 function handler_profile(&$page, $action = null)
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')
69 && Post::has('bananaupdate') && Post::v('action')=="OK" ))
70 {
71 $req = XDB::query("
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
75 WHERE uid = {?}", S::v('uid'));
76 if (!(list($nom,$mail,$sig,$disp,$maj) = $req->fetchOneRow())) {
77 $nom = S::v('prenom').' '.S::v('nom');
78 $mail = S::v('forlife').'@'.$globals->mail->domain;
79 $sig = $nom.' ('.S::v('promo').')';
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 {
89 XDB::execute(
90 'REPLACE INTO forums.profils (uid,sig,mail,nom,flags)
91 VALUES ({?},{?},{?},{?},{?})',
92 S::v('uid'), Post::v('bananasig'),
93 Post::v('bananamail'), Post::v('banananame'),
94 (Post::b('bananadisplay') ? 'threads,' : '') .
95 (Post::b('bananaupdate') ? 'automaj' : '')
96 );
97 }
98 }
99
100 function handler_subscription(&$page)
101 {
102 return $this->run_banana($page, Array('subscribe' => 1));
103 }
104
105 function handler_xface(&$page, $face = null)
106 {
107 header('Content-Type: image/gif');
108 passthru('echo ' . escapeshellarg(base64_decode(strtr($face, '.:', '+/')))
109 . '| uncompface -X '
110 . '| convert -transparent white xbm:- gif:-');
111 }
112
113 function run_banana(&$page, $params = null)
114 {
115 $page->changeTpl('banana/index.tpl');
116 $page->addCssLink('css/banana.css');
117 $page->assign('xorg_title','Polytechnique.org - Forums & PA');
118
119 require_once('banana.inc.php');
120
121 $res = PlatalBanana::run($params);
122 $page->assign_by_ref('banana', $banana);
123 $page->assign('banana_res', $res);
124 }
125 }
126
127 ?>