Fix xface with last banana and make white region transparent
[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),
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';
46 } elseif (($action == 'reply' || $action == 'cancel') && !is_null($artid)) {
47 $get['action'] = $action;
48 $get['artid'] = $artid;
49 } elseif ($action == 'from' && !is_null($artid)) {
50 $get['first'] = $artid;
51 } elseif ($action == 'read' && !is_null($artid)) {
52 $get['artid'] = $artid;
53 }
54 }
55 return BananaModule::run_banana($page, $get);
f585e5a4 56 }
57
3d9b1d30 58 function handler_profile(&$page, $action = null)
f585e5a4 59 {
60 global $globals;
61
62 $page->changeTpl('banana/profile.tpl');
63
64 if (!(Post::has('action') && Post::has('banananame') && Post::has('bananasig')
65 && Post::has('bananadisplay') && Post::has('bananamail')
66 && Post::has('bananaupdate') && Post::get('action')=="OK" ))
67 {
68 $req = $globals->xdb->query("
69 SELECT nom,mail,sig,if(FIND_IN_SET('threads',flags),'1','0'),
70 IF(FIND_IN_SET('automaj',flags),'1','0')
71 FROM forums.profils
72 WHERE uid = {?}", Session::getInt('uid'));
73 if (!(list($nom,$mail,$sig,$disp,$maj) = $req->fetchOneRow())) {
74 $nom = Session::get('prenom').' '.Session::get('nom');
75 $mail = Session::get('forlife').'@'.$globals->mail->domain;
76 $sig = $nom.' ('.Session::getInt('promo').')';
77 $disp = 0;
78 $maj = 0;
79 }
80 $page->assign('nom' , $nom);
81 $page->assign('mail', $mail);
82 $page->assign('sig' , $sig);
83 $page->assign('disp', $disp);
84 $page->assign('maj' , $maj);
85 } else {
86 $globals->xdb->execute(
87 'REPLACE INTO forums.profils (uid,sig,mail,nom,flags)
88 VALUES ({?},{?},{?},{?},{?})',
a3a1d23b 89 Session::getInt('uid'), Post::get('bananasig'),
90 Post::get('bananamail'), Post::get('banananame'),
91 (Post::getBool('bananadisplay') ? 'threads,' : '') .
92 (Post::getBool('bananaupdate') ? 'automaj' : '')
f585e5a4 93 );
94 }
95
96 return PL_OK;
97 }
3d9b1d30 98
a3a1d23b 99 function handler_subscription(&$page)
100 {
101 return $this->run_banana($page, Array('subscribe' => 1));
102 }
3d9b1d30 103
7e6495d4 104 function handler_xface(&$page, $face = null)
f107d806 105 {
106 header('Content-Type: image/jpeg');
7e6495d4 107 passthru('echo ' . escapeshellarg(base64_decode(strtr($face, '.:', '+/')))
f107d806 108 . '| uncompface -X '
7e6495d4 109 . '| convert -transparent white xbm:- gif:-');
f107d806 110 return PL_OK;
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
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 return PL_OK;
a3a1d23b 126 }
f585e5a4 127}
128
129?>