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