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