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 |
22 | require_once 'banana/banana.inc.php'; |
0337d704 |
23 | |
98c14aa5 |
24 | function 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 . '">' |
9f94a7d4 |
30 | . '<img src="images/icons/user_suit.gif" title="fiche" alt="" /></a>'; |
0337d704 |
31 | } |
32 | } |
33 | |
34 | function hook_checkcancel($_headers) { |
cab08090 |
35 | return ($_headers['x-org-id'] == S::v('forlife') or S::has_perms()); |
0337d704 |
36 | } |
37 | |
aafe5c09 |
38 | function 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 | |
38d87ed9 |
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">' |
85b9d118 |
53 | . '<a href=\'javascript:dynpostkv("' . $platal->path . '", "updateall", ' . time() . ')\'>' |
38d87ed9 |
54 | . 'Marquer tous les messages comme lus' |
55 | . '</a>' |
56 | . '</p>'; |
57 | } |
58 | |
3d9b1d30 |
59 | function hook_makeLink($params) { |
9a102e9d |
60 | global $globals; |
61 | $base = $globals->baseurl . '/banana'; |
f107d806 |
62 | if ($params['subscribe'] == 1) { |
63 | return $base . '/subscription'; |
64 | } |
65 | if (isset($params['xface'])) { |
7e6495d4 |
66 | return $base . '/xface/' . strtr(base64_encode($params['xface']), '+/', '.:'); |
f107d806 |
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 | } |
57e834ac |
87 | |
f107d806 |
88 | if ($params['action'] == 'new') { |
89 | return $base . '/new'; |
90 | } |
91 | return $base; |
3d9b1d30 |
92 | } |
93 | |
cce828e5 |
94 | function hook_makeImg($img, $alt, $height, $width) |
63e3b9ae |
95 | { |
7da8ef90 |
96 | $url = 'images/banana/' . $img; |
63e3b9ae |
97 | |
98 | if (!is_null($width)) { |
99 | $width = ' width="' . $width . '"'; |
100 | } |
cce828e5 |
101 | if (!is_null($height)) { |
102 | $height = ' height="' . $height . '"'; |
103 | } |
57e834ac |
104 | |
cce828e5 |
105 | return '<img src="' . $url . '"' . $height . $width . ' alt="' . $alt . '" />'; |
63e3b9ae |
106 | } |
107 | |
0a611890 |
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]) { |
1f8bb12e |
114 | return ' [=> ' . $matches[2] . ']'; |
0a611890 |
115 | } else { |
1f8bb12e |
116 | return ' [=> ' . makeHREF(array('group' => $matches[2]), $matches[2]) . ']'; |
0a611890 |
117 | } |
118 | } |
119 | return null; |
120 | } |
121 | |
0337d704 |
122 | class PlatalBanana extends Banana |
123 | { |
a8f6aabb |
124 | var $profile = array('name' => '', 'sig' => '', |
125 | 'org' => 'Utilisateur de Polytechnique.org', |
126 | 'customhdr' =>'', 'display' => 0, 'lastnews' => 0, |
127 | 'locale' => 'fr_FR', 'subscribe' => array()); |
4475197c |
128 | var $can_attach = false; |
0337d704 |
129 | |
130 | function PlatalBanana() |
131 | { |
132 | global $globals; |
7da8ef90 |
133 | |
cab08090 |
134 | $uid = S::v('uid'); |
08cce2ff |
135 | $req = XDB::query( |
0337d704 |
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())) { |
cab08090 |
141 | $nom = S::v('prenom')." ".S::v('nom'); |
142 | $mail = S::v('forlife')."@polytechnique.org"; |
143 | $sig = $nom." (".S::v('promo').")"; |
0337d704 |
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; |
cab08090 |
151 | $this->profile['lastnews'] = S::v('banana_last'); |
57e834ac |
152 | |
0337d704 |
153 | if ($maj) { |
a98727b9 |
154 | XDB::execute("UPDATE auth_user_quick SET banana_last=FROM_UNIXTIME({?}) WHERE user_id={?}", |
155 | time(), $uid); |
0337d704 |
156 | } |
157 | |
08cce2ff |
158 | $req = XDB::query(" |
f585e5a4 |
159 | SELECT nom |
0337d704 |
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 | |
98c14aa5 |
165 | array_splice($this->show_hdr, count($this->show_hdr) - 2, 0); |
0337d704 |
166 | array_splice($this->parse_hdr, count($this->parse_hdr) - 2, 0, 'x-org-id'); |
167 | |
cab08090 |
168 | $this->host = 'news://web_'.S::v('forlife') |
0337d704 |
169 | .":{$globals->banana->password}@{$globals->banana->server}:{$globals->banana->port}/"; |
170 | |
171 | parent::Banana(); |
172 | } |
173 | |
3d9b1d30 |
174 | function run($params = null) |
0337d704 |
175 | { |
a3a049fc |
176 | global $banana; |
0337d704 |
177 | |
85b9d118 |
178 | $time = null; |
179 | if (!is_null($params) && isset($params['updateall'])) { |
180 | $time = (int)$params['updateall']; |
181 | } |
182 | if (!is_null($time)) { |
a98727b9 |
183 | XDB::execute('UPDATE auth_user_quick SET banana_last=FROM_UNIXTIME({?}) WHERE user_id={?}', |
85b9d118 |
184 | $time, S::v('uid')); |
185 | $_SESSION['banana_last'] = $time; |
0337d704 |
186 | } |
3d9b1d30 |
187 | return Banana::run('PlatalBanana', $params); |
0337d704 |
188 | } |
189 | |
190 | function action_saveSubs() |
191 | { |
192 | global $globals; |
cab08090 |
193 | $uid = S::v('uid'); |
0337d704 |
194 | |
a8f6aabb |
195 | $this->profile['subscribe'] = array(); |
08cce2ff |
196 | XDB::execute("DELETE FROM {$globals->banana->table_prefix}abos WHERE uid={?}", $uid); |
0337d704 |
197 | if (!count($_POST['subscribe'])) { |
198 | return true; |
199 | } |
57e834ac |
200 | |
08cce2ff |
201 | $req = XDB::iterRow("SELECT fid,nom FROM {$globals->banana->table_prefix}list"); |
0337d704 |
202 | $fids = array(); |
203 | while (list($fid,$fnom) = $req->next()) { |
204 | $fids[$fnom] = $fid; |
205 | } |
206 | |
207 | $diff = array_diff($_POST['subscribe'], array_keys($fids)); |
208 | foreach ($diff as $g) { |
08cce2ff |
209 | XDB::execute("INSERT INTO {$globals->banana->table_prefix}list (nom) VALUES ({?})", $g); |
0337d704 |
210 | $fids[$g] = mysql_insert_id(); |
211 | } |
212 | |
213 | foreach ($_POST['subscribe'] as $g) { |
a8f6aabb |
214 | XDB::execute("INSERT INTO {$globals->banana->table_prefix}abos (fid,uid) VALUES ({?},{?})", |
215 | $fids[$g], $uid); |
0337d704 |
216 | $this->profile['subscribe'][] = $g; |
217 | } |
218 | } |
219 | } |
220 | |
221 | ?> |