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