replace more icons
[platal.git] / modules / banana / 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
57e834ac 22require_once 'banana/banana.inc.php';
0337d704 23
98c14aa5 24function hook_formatDisplayHeader($_header, $_text) {
7da8ef90 25 global $banana;
98c14aa5 26 if ($_header == 'from') {
27 $id = $banana->post->headers['x-org-id'];
28 $_text = formatFrom($_text);
7da8ef90 29 return $_text . ' <a href="profile/' . $id . '" class="popup2" title="' . $id . '">'
7ac1ef77 30 . '<img src="images/icons/user_suit.gif" title="fiche" /></a>';
0337d704 31 }
32}
33
34function hook_checkcancel($_headers) {
cab08090 35 return ($_headers['x-org-id'] == S::v('forlife') or S::has_perms());
0337d704 36}
37
aafe5c09 38function hook_shortcuts()
39{
a8f6aabb 40 return array('profile' => array('<a href="banana/profile">Préférences</a>',
c3235940 41 'Préférences'));
aafe5c09 42}
43
3d9b1d30 44function hook_makeLink($params) {
9a102e9d 45 global $globals;
46 $base = $globals->baseurl . '/banana';
f107d806 47 if ($params['subscribe'] == 1) {
48 return $base . '/subscription';
49 }
50 if (isset($params['xface'])) {
7e6495d4 51 return $base . '/xface/' . strtr(base64_encode($params['xface']), '+/', '.:');
f107d806 52 }
53
54 if (!isset($params['group'])) {
55 return $base;
56 }
57 $base .= '/' . $params['group'];
58
59 if (isset($params['first'])) {
60 return $base . '/from/' . $params['first'];
61 }
62 if (isset($params['artid'])) {
63 if ($params['action'] == 'new') {
64 $base .= '/reply';
65 } elseif ($params['action'] == 'cancel') {
66 $base .= '/cancel';
67 } else {
68 $base .= '/read';
69 }
70 return $base . '/' . $params['artid'];
71 }
57e834ac 72
f107d806 73 if ($params['action'] == 'new') {
74 return $base . '/new';
75 }
76 return $base;
3d9b1d30 77}
78
cce828e5 79function hook_makeImg($img, $alt, $height, $width)
63e3b9ae 80{
7da8ef90 81 $url = 'images/banana/' . $img;
63e3b9ae 82
83 if (!is_null($width)) {
84 $width = ' width="' . $width . '"';
85 }
cce828e5 86 if (!is_null($height)) {
87 $height = ' height="' . $height . '"';
88 }
57e834ac 89
cce828e5 90 return '<img src="' . $url . '"' . $height . $width . ' alt="' . $alt . '" />';
63e3b9ae 91}
92
0a611890 93function hook_getSubject(&$subject)
94{
95 if (preg_match('!(.*\S)\s*\[=> ([^\]\s]+)\]!', $subject, $matches)) {
96 $subject = $matches[1];
97 global $banana;
98 if ($banana->state['group'] == $matches[2]) {
99 return ' [=> ' . $matches[2] . ']';
100 } else {
a8f6aabb 101 return ' [=> ' . makeHREF(array('group' => $matches[2]), $matches[2]) . ']';
0a611890 102 }
103 }
104 return null;
105}
106
0337d704 107class PlatalBanana extends Banana
108{
a8f6aabb 109 var $profile = array('name' => '', 'sig' => '',
110 'org' => 'Utilisateur de Polytechnique.org',
111 'customhdr' =>'', 'display' => 0, 'lastnews' => 0,
112 'locale' => 'fr_FR', 'subscribe' => array());
4475197c 113 var $can_attach = false;
0337d704 114
115 function PlatalBanana()
116 {
117 global $globals;
7da8ef90 118
cab08090 119 $uid = S::v('uid');
08cce2ff 120 $req = XDB::query(
0337d704 121 "SELECT nom, mail, sig, FIND_IN_SET('threads',flags), FIND_IN_SET('automaj',flags)
122 FROM {$globals->banana->table_prefix}profils
123 WHERE uid={?}", $uid);
124
125 if (!(list($nom,$mail,$sig,$disp,$maj) = $req->fetchOneRow())) {
cab08090 126 $nom = S::v('prenom')." ".S::v('nom');
127 $mail = S::v('forlife')."@polytechnique.org";
128 $sig = $nom." (".S::v('promo').")";
0337d704 129 $disp = 0;
130 $maj = 1;
131 }
132 $this->profile['name'] = "$nom <$mail>";
133 $this->profile['sig'] = $sig;
134 $this->profile['display'] = $disp;
135 $this->profile['autoup'] = $maj;
cab08090 136 $this->profile['lastnews'] = S::v('banana_last');
57e834ac 137
0337d704 138 if ($maj) {
a8f6aabb 139 XDB::execute("UPDATE auth_user_quick SET banana_last={?} WHERE user_id={?}",
140 gmdate("YmdHis"), $uid);
0337d704 141 }
142
08cce2ff 143 $req = XDB::query("
f585e5a4 144 SELECT nom
0337d704 145 FROM {$globals->banana->table_prefix}abos
146 LEFT JOIN {$globals->banana->table_prefix}list ON list.fid=abos.fid
147 WHERE uid={?}", $uid);
148 $this->profile['subscribe'] = $req->fetchColumn();
149
98c14aa5 150 array_splice($this->show_hdr, count($this->show_hdr) - 2, 0);
0337d704 151 array_splice($this->parse_hdr, count($this->parse_hdr) - 2, 0, 'x-org-id');
152
cab08090 153 $this->host = 'news://web_'.S::v('forlife')
0337d704 154 .":{$globals->banana->password}@{$globals->banana->server}:{$globals->banana->port}/";
155
156 parent::Banana();
157 }
158
3d9b1d30 159 function run($params = null)
0337d704 160 {
a3a049fc 161 global $banana;
0337d704 162
5e2307dc 163 if (Get::v('banana') == 'updateall'
a8f6aabb 164 || (!is_null($params) && isset($params['banana']) && $params['banana'] == 'updateall')) {
165 XDB::execute('UPDATE auth_user_quick SET banana_last={?} WHERE user_id={?}',
166 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
a8f6aabb 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 }
57e834ac 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) {
a8f6aabb 196 XDB::execute("INSERT INTO {$globals->banana->table_prefix}abos (fid,uid) VALUES ({?},{?})",
197 $fids[$g], $uid);
0337d704 198 $this->profile['subscribe'][] = $g;
199 }
200 }
201}
202
203?>