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