Close #407: RSS feed for Forums and MLs
[platal.git] / include / banana / moderate.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 $platal, $globals;
3e949cf9 33 $base = $globals->baseurl . '/' . $platal->ns . 'lists/moderate/' . ModerationBanana::$listname . '?';
24cec3d8 34 $get = '';
35 foreach ($params as $key=>$value) {
36 if ($key == 'artid') {
37 $key = 'mid';
38 }
39 if ($key == 'group') {
40 continue;
41 }
d96379f6 42 if ($key == 'action' && $value != 'showext') {
24cec3d8 43 continue;
44 }
45 if (!empty($get)) {
46 $get .= '&';
47 }
48 $get .= $key . '=' . $value;
49 }
50 return $base . $get;
51}
52
53class ModerationBanana extends Banana
54{
55 static public $listname;
56 static public $domain;
57 static public $client;
58
59 function __construct($params = null, &$client)
60 {
61 global $globals;
62 ModerationBanana::$client = $client;
63 ModerationBanana::$listname = $params['listname'];
64 ModerationBanana::$domain = isset($params['domain']) ? $params['domain'] : $globals->mail->domain;
65 $params['group'] = ModerationBanana::$listname . '@' . ModerationBanana::$domain;
580d1c7d 66 Banana::$spool_root = $globals->banana->spool_root;
24cec3d8 67 Banana::$spool_boxlist = false;
68 Banana::$msgshow_withthread = false;
69 Banana::$withtabs = false;
1515e65a 70 Banana::$msgshow_externalimages = false;
71 Banana::$msgshow_mimeparts[] = 'source';
6544d0e1 72 Banana::$feed_active = false;
24cec3d8 73 array_push(Banana::$msgparse_headers, 'x-org-id', 'x-org-mail');
74 parent::__construct($params, 'MLInterface', 'ModerationPage');
75 }
76}
77
78require_once('banana/page.inc.php');
79
80class ModerationPage extends BananaPage
81{
82 protected function prepare()
83 {
84 $this->killPage('subscribe');
85 $this->killPage('forums');
86 $this->assign('noactions', true);
87 return parent::prepare();
88 }
89
90 public function trig($msg)
91 {
92 global $page;
93 if ($page) {
2d967f8c 94 $page->trig($msg);
24cec3d8 95 }
96 return true;
97 }
98}
99
100require_once('banana/protocoleinterface.inc.php');
101require_once('banana/message.inc.php');
102
103class BananaMLInterface implements BananaProtocoleInterface
104{
105 private $infos; //(list, addr, host, desc, info, diff, ins, priv, sub, own, nbsub)
106 private $helds; //(id, sender, size, subj, date)
107
108 public function __construct()
109 {
110 $this->infos = ModerationBanana::$client->get_members(ModerationBanana::$listname);
111 $this->infos = $this->infos[0];
112
113 $mods = ModerationBanana::$client->get_pending_ops(ModerationBanana::$listname);
114 $this->helds = $mods[1];
115 }
116
117 public function isValid()
118 {
119 return !is_null(ModerationBanana::$client);
120 }
121
122 public function lastErrNo()
123 {
124 return 0;
125 }
126
127 public function lastError()
128 {
129 return null;
130 }
131
132 public function getDescription()
133 {
134 return $this->infos['desc'];
135 }
136
137 public function getBoxList($mode = Banana::BOXES_ALL, $since = 0, $withstats = false)
138 {
139 return array(Banana::$group => Array(
140 'desc' => $this->infos['desc'],
141 'msgnum' => count($this->helds),
142 'unread' => count($this->helds)));
143 }
144
145 public function &getMessage($id)
146 {
147 $message = null;
148 $msg = ModerationBanana::$client->get_pending_mail(ModerationBanana::$listname, $id, 1);
149 if ($msg) {
ea626742 150 $message = new BananaMessage(html_entity_decode($msg));
24cec3d8 151 }
152 return $message;
153 }
154
155 public function getMessageSource($id)
156 {
157 return ModerationBanana::$client->get_pending_mail(ModerationBanana::$listname, $id, 1);
158 }
159
160 public function getIndexes()
161 {
162 $ids = array();
163 foreach ($this->helds as &$desc) {
164 $ids[] = intval($desc['id']);
165 }
166 sort($ids);
167 return array(count($ids), min($ids), max($ids));
168 }
169
170 public function &getMessageHeaders($firstid, $lastid, array $msg_headers = array())
171 {
172 $conv = array('from' => 'sender', 'subject' => 'subj', 'date' => 'stamp', 'message-id' => 'id');
173 $headers = array();
174 foreach ($msg_headers as $hdr) {
175 $hdr = strtolower($hdr);
176 $mlhdr = isset($conv[$hdr]) ? $conv[$hdr] : $hdr;
177 foreach ($this->helds as &$desc) {
178 $id = intval($desc['id']);
179 if (!isset($headers[$id])) {
180 $headers[$id] = array();
181 }
182 if ($mlhdr == 'id') {
183 $headers[$id][$hdr] = $desc['stamp'] . '$' . $desc['id'] . '@' . Banana::$group;
184 } else {
185 $headers[$id][$hdr] = isset($desc[$mlhdr]) ? banana_html_entity_decode($desc[$mlhdr]) : null;
186 }
187 }
188 }
189 return $headers;
190 }
191
192 public function updateSpool(array &$messages) { }
193
194 public function getNewIndexes($since)
195 {
196 $ids = array();
197 foreach ($this->helds as &$desc) {
198 if ($desc['stamp'] > $since) {
199 $ids[] = intval($desc['id']);
200 }
201 }
202 sort($ids);
203 return $ids;
204 }
205
206 public function canSend()
207 {
208 return false;
209 }
210
211 public function canCancel()
212 {
213 return false;
214 }
215
216 public function requestedHeaders()
217 {
218 return array();
219 }
220
221 public function send(BananaMessage &$message)
222 {
223 return true;
224 }
225
226 public function cancel(BananaMessage &$message)
227 {
228 return true;
229 }
230
231 public function name()
232 {
233 return 'MLModeration';
234 }
235
236 public function filename()
237 {
238 return ModerationBanana::$domain . '_' . ModerationBanana::$listname;
239 }
d3f26be9 240
241 public function backtrace()
242 {
243 return null;
244 }
24cec3d8 245}
246
a7de4ef7 247// vim:set et sw=4 sts=4 ts=4 enc=utf-8:
24cec3d8 248?>