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