24cec3d8 |
1 | <?php |
2 | /*************************************************************************** |
3 | * Copyright (C) 2003-2007 Polytechnique.org * |
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 | require_once 'banana/hooks.inc.php'; |
24 | |
25 | function hook_checkcancel($_headers) |
26 | { |
27 | return ($_headers['x-org-id'] == S::v('forlife') or S::has_perms()); |
28 | } |
29 | |
30 | function hook_makeLink($params) |
31 | { |
32 | global $globals; |
33 | $base = $globals->baseurl . '/banana'; |
34 | if (isset($params['page'])) { |
35 | return $base . '/' . $params['page']; |
36 | } |
37 | if (@$params['action'] == 'subscribe') { |
38 | return $base . '/subscription'; |
39 | } |
40 | |
41 | if (!isset($params['group'])) { |
42 | return $base; |
43 | } |
44 | $base .= '/' . $params['group']; |
d96379f6 |
45 | $base = $base . hook_platalMessageLink($params); |
46 | if (@$params['action'] == 'showext') { |
47 | $base .= '?action=showext'; |
48 | } |
49 | return $base; |
24cec3d8 |
50 | } |
51 | |
fa7d6c7b |
52 | class ForumsBanana extends Banana |
24cec3d8 |
53 | { |
54 | function __construct($params = null) |
55 | { |
56 | global $globals; |
57 | Banana::$msgedit_canattach = false; |
58 | array_push(Banana::$msgparse_headers, 'x-org-id', 'x-org-mail'); |
59 | Banana::$nntp_host = 'news://web_'.S::v('forlife') |
60 | . ":{$globals->banana->password}@{$globals->banana->server}:{$globals->banana->port}/"; |
1515e65a |
61 | if (S::has_perms()) { |
62 | Banana::$msgshow_mimeparts[] = 'source'; |
63 | } |
24cec3d8 |
64 | parent::__construct($params); |
65 | } |
66 | |
67 | public function run() |
68 | { |
69 | global $platal, $globals; |
70 | |
71 | // Update last unread time |
72 | $time = null; |
73 | if (!is_null($this->params) && isset($this->params['updateall'])) { |
74 | $time = intval($this->params['updateall']); |
75 | $_SESSION['banana_last'] = $time; |
76 | } |
77 | |
78 | // Get user profile from SQL |
79 | $req = XDB::query("SELECT nom, mail, sig, |
80 | FIND_IN_SET('threads',flags), FIND_IN_SET('automaj',flags) |
81 | FROM {$globals->banana->table_prefix}profils |
82 | WHERE uid={?}", S::i('uid')); |
83 | if (!(list($nom,$mail,$sig,$disp,$maj) = $req->fetchOneRow())) { |
84 | $nom = S::v('prenom')." ".S::v('nom'); |
85 | $mail = S::v('forlife')."@polytechnique.org"; |
86 | $sig = $nom." (".S::v('promo').")"; |
87 | $disp = 0; |
88 | $maj = 1; |
89 | } |
90 | if ($maj) { |
91 | $time = time(); |
92 | } |
93 | |
94 | // Build user profile |
95 | $req = XDB::query(" |
96 | SELECT nom |
97 | FROM {$globals->banana->table_prefix}abos |
98 | LEFT JOIN {$globals->banana->table_prefix}list ON list.fid=abos.fid |
99 | WHERE uid={?}", S::i('uid')); |
100 | Banana::$profile['headers']['From'] = utf8_encode("$nom <$mail>"); |
101 | Banana::$profile['headers']['Organization'] = 'Utilisateur de Polytechnique.org'; |
102 | Banana::$profile['signature'] = utf8_encode($sig); |
103 | Banana::$profile['display'] = $disp; |
104 | Banana::$profile['autoup'] = $maj; |
105 | Banana::$profile['lastnews'] = S::v('banana_last'); |
106 | Banana::$profile['subscribe'] = $req->fetchColumn(); |
107 | |
108 | // Update the "unread limit" |
109 | if (!is_null($time)) { |
110 | XDB::execute("UPDATE auth_user_quick |
111 | SET banana_last = FROM_UNIXTIME({?}) |
112 | WHERE user_id={?}", |
113 | $time, S::i('uid')); |
114 | } |
115 | |
116 | // Register custom Banana links and tabs |
117 | if (!Banana::$profile['autoup']) { |
118 | Banana::$page->registerAction('<a href=\'javascript:dynpostkv("' |
119 | . $platal->path . '", "updateall", ' . time() . ')\'>' |
120 | . 'Marquer tous les messages comme lus' |
121 | . '</a>', array('forums', 'thread', 'message')); |
122 | } |
123 | Banana::$page->registerPage('profile', utf8_encode('Préférences'), null); |
124 | |
125 | |
126 | // Run Banana |
127 | return parent::run(); |
128 | } |
129 | |
130 | protected function action_saveSubs($groups) |
131 | { |
132 | global $globals; |
133 | $uid = S::v('uid'); |
134 | |
135 | Banana::$profile['subscribe'] = array(); |
136 | XDB::execute("DELETE FROM {$globals->banana->table_prefix}abos WHERE uid={?}", $uid); |
137 | if (!count($groups)) { |
138 | return true; |
139 | } |
140 | |
141 | $req = XDB::iterRow("SELECT fid,nom FROM {$globals->banana->table_prefix}list"); |
142 | $fids = array(); |
143 | while (list($fid,$fnom) = $req->next()) { |
144 | $fids[$fnom] = $fid; |
145 | } |
146 | |
147 | $diff = array_diff($groups, array_keys($fids)); |
148 | foreach ($diff as $g) { |
149 | XDB::execute("INSERT INTO {$globals->banana->table_prefix}list (nom) VALUES ({?})", $g); |
150 | $fids[$g] = XDB::insertId(); |
151 | } |
152 | |
153 | foreach ($groups as $g) { |
154 | XDB::execute("INSERT INTO {$globals->banana->table_prefix}abos (fid,uid) VALUES ({?},{?})", |
155 | $fids[$g], $uid); |
156 | Banana::$profile['subscribe'][] = $g; |
157 | } |
158 | } |
159 | } |
160 | |
161 | ?> |