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