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