Fix xface in case it contains '/'
[platal.git] / include / banana.inc.php
CommitLineData
0337d704 1<?php
2/***************************************************************************
50a40a33 3 * Copyright (C) 2003-2006 Polytechnique.org *
0337d704 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
22require_once('banana/banana.inc.php');
23
98c14aa5 24function hook_formatDisplayHeader($_header, $_text) {
25 global $globals, $banana;
26 if ($_header == 'from') {
27 $id = $banana->post->headers['x-org-id'];
28 $_text = formatFrom($_text);
29 return $_text . ' <a href="' . $globals->baseurl . '/profile/'
30 . $id . '" class="popup2" title="' . $id . '">'
31 . '<img src="' . $globals->baseurl . '/images/loupe.gif" alt="fiche" title="fiche" />'
32 . '</a>';
0337d704 33 }
34}
35
36function hook_checkcancel($_headers) {
37 return ($_headers['x-org-id'] == Session::get('forlife') or has_perms());
38}
39
3d9b1d30 40function hook_makeLink($params) {
f107d806 41 global $globals;
42 $base = $globals->baseurl . '/banana';
43 if ($params['subscribe'] == 1) {
44 return $base . '/subscription';
45 }
46 if (isset($params['xface'])) {
47 return $base . '/xface/' . $params['xface'];
48 }
49
50 if (!isset($params['group'])) {
51 return $base;
52 }
53 $base .= '/' . $params['group'];
54
55 if (isset($params['first'])) {
56 return $base . '/from/' . $params['first'];
57 }
58 if (isset($params['artid'])) {
59 if ($params['action'] == 'new') {
60 $base .= '/reply';
61 } elseif ($params['action'] == 'cancel') {
62 $base .= '/cancel';
63 } else {
64 $base .= '/read';
65 }
66 return $base . '/' . $params['artid'];
67 }
68
69 if ($params['action'] == 'new') {
70 return $base . '/new';
71 }
72 return $base;
3d9b1d30 73}
74
cce828e5 75function hook_makeImg($img, $alt, $height, $width)
63e3b9ae 76{
77 global $globals;
78 $url = $globals->baseurl . '/images/banana/' . $img . '.gif';
79
80 if (!is_null($width)) {
81 $width = ' width="' . $width . '"';
82 }
cce828e5 83 if (!is_null($height)) {
84 $height = ' height="' . $height . '"';
85 }
63e3b9ae 86
cce828e5 87 return '<img src="' . $url . '"' . $height . $width . ' alt="' . $alt . '" />';
63e3b9ae 88}
89
0a611890 90function hook_getSubject(&$subject)
91{
92 if (preg_match('!(.*\S)\s*\[=> ([^\]\s]+)\]!', $subject, $matches)) {
93 $subject = $matches[1];
94 global $banana;
95 if ($banana->state['group'] == $matches[2]) {
96 return ' [=> ' . $matches[2] . ']';
97 } else {
98 return ' [=> ' . makeHREF(Array('group' => $matches[2]), $matches[2]) . ']';
99 }
100 }
101 return null;
102}
103
0337d704 104class PlatalBanana extends Banana
105{
4475197c 106 var $profile = Array( 'name' => '', 'sig' => '', 'org' => 'Utilisateur de Polytechnique.org',
0337d704 107 'customhdr' =>'', 'display' => 0, 'lastnews' => 0, 'locale' => 'fr_FR', 'subscribe' => array());
4475197c 108 var $can_attach = false;
0337d704 109
110 function PlatalBanana()
111 {
112 global $globals;
113
114 $uid = Session::getInt('uid');
115 $req = $globals->xdb->query(
116 "SELECT nom, mail, sig, FIND_IN_SET('threads',flags), FIND_IN_SET('automaj',flags)
117 FROM {$globals->banana->table_prefix}profils
118 WHERE uid={?}", $uid);
119
120 if (!(list($nom,$mail,$sig,$disp,$maj) = $req->fetchOneRow())) {
121 $nom = Session::get('prenom')." ".Session::get('nom');
122 $mail = Session::get('forlife')."@polytechnique.org";
123 $sig = $nom." (".Session::getInt('promo').")";
124 $disp = 0;
125 $maj = 1;
126 }
127 $this->profile['name'] = "$nom <$mail>";
128 $this->profile['sig'] = $sig;
129 $this->profile['display'] = $disp;
130 $this->profile['autoup'] = $maj;
131 $this->profile['lastnews'] = Session::get('banana_last');
132
133 if ($maj) {
134 $globals->xdb->execute("UPDATE auth_user_quick SET banana_last={?} WHERE user_id={?}", gmdate("YmdHis"), $uid);
135 }
136
f585e5a4 137 $req = $globals->xdb->query("
138 SELECT nom
0337d704 139 FROM {$globals->banana->table_prefix}abos
140 LEFT JOIN {$globals->banana->table_prefix}list ON list.fid=abos.fid
141 WHERE uid={?}", $uid);
142 $this->profile['subscribe'] = $req->fetchColumn();
143
98c14aa5 144 array_splice($this->show_hdr, count($this->show_hdr) - 2, 0);
0337d704 145 array_splice($this->parse_hdr, count($this->parse_hdr) - 2, 0, 'x-org-id');
146
147 $this->host = 'news://web_'.Session::get('forlife')
148 .":{$globals->banana->password}@{$globals->banana->server}:{$globals->banana->port}/";
149
150 parent::Banana();
151 }
152
3d9b1d30 153 function run($params = null)
0337d704 154 {
155 global $banana, $globals;
156
3d9b1d30 157 if (Get::get('banana') == 'updateall'
f107d806 158 || (!is_null($params) && isset($params['banana']) && $params['banana'] == 'updateall')) {
0337d704 159 $globals->xdb->execute('UPDATE auth_user_quick SET banana_last={?} WHERE user_id={?}', gmdate('YmdHis'), Session::getInt('uid'));
160 $_SESSION['banana_last'] = time();
0337d704 161 }
3d9b1d30 162 return Banana::run('PlatalBanana', $params);
0337d704 163 }
164
165 function action_saveSubs()
166 {
167 global $globals;
168 $uid = Session::getInt('uid');
169
170 $this->profile['subscribe'] = Array();
171 $globals->xdb->execute("DELETE FROM {$globals->banana->table_prefix}abos WHERE uid={?}", $uid);
172 if (!count($_POST['subscribe'])) {
173 return true;
174 }
175
176 $req = $globals->xdb->iterRow("SELECT fid,nom FROM {$globals->banana->table_prefix}list");
177 $fids = array();
178 while (list($fid,$fnom) = $req->next()) {
179 $fids[$fnom] = $fid;
180 }
181
182 $diff = array_diff($_POST['subscribe'], array_keys($fids));
183 foreach ($diff as $g) {
184 $globals->xdb->execute("INSERT INTO {$globals->banana->table_prefix}list (nom) VALUES ({?})", $g);
185 $fids[$g] = mysql_insert_id();
186 }
187
188 foreach ($_POST['subscribe'] as $g) {
189 $globals->xdb->execute("INSERT INTO {$globals->banana->table_prefix}abos (fid,uid) VALUES ({?},{?})", $fids[$g], $uid);
190 $this->profile['subscribe'][] = $g;
191 }
192 }
193}
194
195?>