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