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