f537fdafe37448709ee0d6e65a74f201138f102b
2 /***************************************************************************
3 * Copyright (C) 2003-2006 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 require_once('banana/banana.inc.php');
24 function hook_formatDisplayHeader($_header,$_text) {
26 if ($_header == 'x-org-id') {
27 return $_text . ' [<a href="' . $globals->baseurl
. '/fiche.php?user='
28 . $_text . '" class="popup2">fiche</a>]';
32 function hook_headerTranslate($hdr) {
33 if ($hdr == 'x-org-id') {
38 function hook_checkcancel($_headers) {
39 return ($_headers['x-org-id'] == Session
::get('forlife') or has_perms());
42 function hook_makeLink($params) {
44 $base = $globals->baseurl
. '/banana';
45 if ($params['subscribe'] == 1) {
46 return $base . '/subscription';
48 if (isset($params['xface'])) {
49 return $base . '/xface/' . $params['xface'];
52 if (!isset($params['group'])) {
55 $base .= '/' . $params['group'];
57 if (isset($params['first'])) {
58 return $base . '/from/' . $params['first'];
60 if (isset($params['artid'])) {
61 if ($params['action'] == 'new') {
63 } elseif ($params['action'] == 'cancel') {
68 return $base . '/' . $params['artid'];
71 if ($params['action'] == 'new') {
72 return $base . '/new';
77 function hook_makeImg($img, $alt, $height, $width)
80 $url = $globals->baseurl
. '/images/banana/' . $img . '.gif';
82 if (!is_null($width)) {
83 $width = ' width="' . $width . '"';
85 if (!is_null($height)) {
86 $height = ' height="' . $height . '"';
89 return '<img src="' . $url . '"' . $height . $width . ' alt="' . $alt . '" />';
92 class PlatalBanana
extends Banana
94 var $profile = Array( 'name' => '', 'sig' => '', 'org' => 'Utilisateur de Polytechnique.org',
95 'customhdr' =>'', 'display' => 0, 'lastnews' => 0, 'locale' => 'fr_FR', 'subscribe' => array());
96 var $can_attach = false
;
98 function PlatalBanana()
102 $uid = Session
::getInt('uid');
103 $req = $globals->xdb
->query(
104 "SELECT nom, mail, sig, FIND_IN_SET('threads',flags), FIND_IN_SET('automaj',flags)
105 FROM {$globals->banana->table_prefix}profils
106 WHERE uid={?}", $uid);
108 if (!(list($nom,$mail,$sig,$disp,$maj) = $req->fetchOneRow())) {
109 $nom = Session
::get('prenom')." ".Session
::get('nom');
110 $mail = Session
::get('forlife')."@polytechnique.org";
111 $sig = $nom." (".Session
::getInt('promo').")";
115 $this->profile
['name'] = "$nom <$mail>";
116 $this->profile
['sig'] = $sig;
117 $this->profile
['display'] = $disp;
118 $this->profile
['autoup'] = $maj;
119 $this->profile
['lastnews'] = Session
::get('banana_last');
122 $globals->xdb
->execute("UPDATE auth_user_quick SET banana_last={?} WHERE user_id={?}", gmdate("YmdHis"), $uid);
125 $req = $globals->xdb
->query("
127 FROM {$globals->banana->table_prefix}abos
128 LEFT JOIN {$globals->banana->table_prefix}list ON list.fid=abos.fid
129 WHERE uid={?}", $uid);
130 $this->profile
['subscribe'] = $req->fetchColumn();
132 array_splice($this->show_hdr
, count($this->show_hdr
) - 2, 0, 'x-org-id');
133 array_splice($this->parse_hdr
, count($this->parse_hdr
) - 2, 0, 'x-org-id');
135 $this->host
= 'news://web_'.Session
::get('forlife')
136 .":{$globals->banana->password}@{$globals->banana->server}:{$globals->banana->port}/";
141 function run($params = null
)
143 global $banana, $globals;
145 if (Get
::get('banana') == 'updateall'
146 ||
(!is_null($params) && isset($params['banana']) && $params['banana'] == 'updateall')) {
147 $globals->xdb
->execute('UPDATE auth_user_quick SET banana_last={?} WHERE user_id={?}', gmdate('YmdHis'), Session
::getInt('uid'));
148 $_SESSION['banana_last'] = time();
150 return Banana
::run('PlatalBanana', $params);
153 function action_saveSubs()
156 $uid = Session
::getInt('uid');
158 $this->profile
['subscribe'] = Array();
159 $globals->xdb
->execute("DELETE FROM {$globals->banana->table_prefix}abos WHERE uid={?}", $uid);
160 if (!count($_POST['subscribe'])) {
164 $req = $globals->xdb
->iterRow("SELECT fid,nom FROM {$globals->banana->table_prefix}list");
166 while (list($fid,$fnom) = $req->next()) {
170 $diff = array_diff($_POST['subscribe'], array_keys($fids));
171 foreach ($diff as $g) {
172 $globals->xdb
->execute("INSERT INTO {$globals->banana->table_prefix}list (nom) VALUES ({?})", $g);
173 $fids[$g] = mysql_insert_id();
176 foreach ($_POST['subscribe'] as $g) {
177 $globals->xdb
->execute("INSERT INTO {$globals->banana->table_prefix}abos (fid,uid) VALUES ({?},{?})", $fids[$g], $uid);
178 $this->profile
['subscribe'][] = $g;