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