2 /***************************************************************************
3 * Copyright (C) 2003-2007 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 require_once 'banana/banana.inc.php';
24 function hook_formatDisplayHeader($_header, $_text, $in_spool = false
)
27 case 'from': case 'to': case 'cc': case 'reply-to':
28 $addresses = preg_split("/ *, */", $_text);
30 foreach ($addresses as $address) {
31 $address = BananaMessage
::formatFrom(trim($address));
32 if ($_header == 'from') {
33 if ($id = Banana
::$message->getHeaderValue('x-org-id')) {
34 return $address . ' <a href="profile/' . $id . '" class="popup2" title="' . $id . '">'
35 . '<img src="images/icons/user_suit.gif" title="fiche" alt="" /></a>';
36 } elseif ($id = Banana
::$message->getHeaderValue('x-org-mail')) {
37 list($id, $domain) = explode('@', $id);
38 return $address . ' <a href="profile/' . $id . '" class="popup2" title="' . $id . '">'
39 . '<img src="images/icons/user_suit.gif" title="fiche" alt="" /></a>';
53 $text = stripslashes($_text);
54 if (preg_match('/^(.+?)\s*\[=> (.*?)\]\s*$/u', $text, $matches)) {
57 if (Banana
::$group == $group) {
58 $link = ' [=> ' . $group . ']';
60 $link = ' [=> ' . Banana
::$page->makeLink(array('group' => $group, 'text' => $group)) . ']';
63 $text = banana_catchFormats(banana_htmlentities($text));
65 return array($text, $link);
72 function hook_checkcancel($_headers)
74 return ($_headers['x-org-id'] == S
::v('forlife') or S
::has_perms());
77 function hook_makeLink($params) {
79 $base = $globals->baseurl
. '/banana';
80 if (isset($params['page'])) {
81 return $base . '/' . $params['page'];
83 if (@$params['action'] == 'subscribe') {
84 return $base . '/subscription';
86 if (isset($params['xface'])) {
87 return $base . '/xface/' . strtr(base64_encode($params['xface']), '+/', '.:');
90 if (!isset($params['group'])) {
93 $base .= '/' . $params['group'];
95 if (isset($params['first'])) {
96 return $base . '/from/' . $params['first'];
98 if (isset($params['artid'])) {
99 if (@$params['part'] == 'xface') {
101 } elseif (@$params['action'] == 'new') {
103 } elseif (@$params['action'] == 'cancel') {
108 if (isset($params['part']) && $params['part'] != 'xface') {
109 return $base . '/' . $params['artid'] . '?part=' . urlencode($params['part']);
111 return $base . '/' . $params['artid'];
115 if (@$params['action'] == 'new') {
116 return $base . '/new';
121 function hook_makeImg($img, $alt, $height, $width)
123 $url = 'images/banana/' . $img;
125 if (!is_null($width)) {
126 $width = ' width="' . $width . '"';
128 if (!is_null($height)) {
129 $height = ' height="' . $height . '"';
132 return '<img src="' . $url . '"' . $height . $width . ' alt="' . $alt . '" />';
135 class PlatalBanana
extends Banana
137 function __construct($params = null
)
140 Banana
::$msgedit_canattach = false
;
141 array_push(Banana
::$msgparse_headers, 'x-org-id', 'x-org-mail');
142 Banana
::$nntp_host = 'news://web_'.S
::v('forlife')
143 . ":{$globals->banana->password}@{$globals->banana->server}:{$globals->banana->port}/";
144 parent
::__construct($params);
147 public function run()
149 global $platal, $globals;
151 // Update last unread time
153 if (!is_null($this->params
) && isset($this->params
['updateall'])) {
154 $time = intval($this->params
['updateall']);
155 $_SESSION['banana_last'] = $time;
158 // Get user profile from SQL
159 $req = XDB
::query("SELECT nom, mail, sig,
160 FIND_IN_SET('threads',flags), FIND_IN_SET('automaj',flags)
161 FROM {$globals->banana->table_prefix}profils
162 WHERE uid={?}", S
::i('uid'));
163 if (!(list($nom,$mail,$sig,$disp,$maj) = $req->fetchOneRow())) {
164 $nom = S
::v('prenom')." ".S
::v('nom');
165 $mail = S
::v('forlife')."@polytechnique.org";
166 $sig = $nom." (".S
::v('promo').")";
174 // Build user profile
177 FROM {$globals->banana->table_prefix}abos
178 LEFT JOIN {$globals->banana->table_prefix}list ON list.fid=abos.fid
179 WHERE uid={?}", S
::i('uid'));
180 Banana
::$profile['headers']['From'] = utf8_encode("$nom <$mail>");
181 Banana
::$profile['headers']['Organization'] = 'Utilisateur de Polytechnique.org';
182 Banana
::$profile['signature'] = utf8_encode($sig);
183 Banana
::$profile['display'] = $disp;
184 Banana
::$profile['autoup'] = $maj;
185 Banana
::$profile['lastnews'] = S
::v('banana_last');
186 Banana
::$profile['subscribe'] = $req->fetchColumn();
188 // Update the "unread limit"
189 if (!is_null($time)) {
190 XDB
::execute("UPDATE auth_user_quick
191 SET banana_last = FROM_UNIXTIME({?})
196 // Register custom Banana links and tabs
197 if (!Banana
::$profile['autoup']) {
198 Banana
::$page->registerAction('<a href=\'javascript:dynpostkv("'
199 . $platal->path
. '", "updateall", ' . time() . ')\'>'
200 . 'Marquer tous les messages comme lus'
201 . '</a>', array('forums', 'thread', 'message'));
203 Banana
::$page->registerPage('profile', utf8_encode('Préférences'), null
);
207 return parent
::run();
210 protected function action_saveSubs($groups)
215 Banana
::$profile['subscribe'] = array();
216 XDB
::execute("DELETE FROM {$globals->banana->table_prefix}abos WHERE uid={?}", $uid);
217 if (!count($groups)) {
221 $req = XDB
::iterRow("SELECT fid,nom FROM {$globals->banana->table_prefix}list");
223 while (list($fid,$fnom) = $req->next()) {
227 $diff = array_diff($groups, array_keys($fids));
228 foreach ($diff as $g) {
229 XDB
::execute("INSERT INTO {$globals->banana->table_prefix}list (nom) VALUES ({?})", $g);
230 $fids[$g] = XDB
::insertId();
233 foreach ($groups as $g) {
234 XDB
::execute("INSERT INTO {$globals->banana->table_prefix}abos (fid,uid) VALUES ({?},{?})",
236 Banana
::$profile['subscribe'][] = $g;