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