2 /***************************************************************************
3 * Copyright (C) 2003-2011 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 require_once 'banana/hooks.inc.php';
24 function hook_checkcancel($_headers)
26 return ($_headers['x-org-id'] == S
::v('hruid') or S
::admin());
29 function hook_makeLink($params)
31 global $platal, $globals;
32 $base = $globals->baseurl
. '/' . $platal->ns
. 'lists/moderate/' . ModerationBanana
::$listname . '?';
34 foreach ($params as $key=>$value) {
35 if ($key == 'artid') {
38 if ($key == 'group') {
41 if ($key == 'action' && $value != 'showext') {
47 $get .= $key . '=' . $value;
52 class ModerationBanana
extends Banana
54 static public $listname;
55 static public $domain;
56 static public $client;
58 function __construct(User
$user, $params = null
)
60 ini_set('memory_limit', '128M');
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->spoolroot
. '/spool/banana/';
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');
80 class ModerationPage
extends BananaPage
82 protected function prepare()
84 $this->killPage('subscribe');
85 $this->killPage('forums');
86 $this->assign('noactions', true
);
87 return parent
::prepare();
90 public function trig($msg)
92 Platal
::page()->trigError($msg);
97 class BananaMLInterface
implements BananaProtocoleInterface
99 private $infos; //(list, addr, host, desc, info, diff, ins, priv, sub, own, nbsub)
100 private $helds; //(id, sender, size, subj, date)
102 public function __construct()
104 $this->infos
= ModerationBanana
::$client->get_members(ModerationBanana
::$listname);
105 $this->infos
= $this->infos
[0];
107 $mods = ModerationBanana
::$client->get_pending_ops(ModerationBanana
::$listname);
108 $this->helds
= $mods[1];
111 public function isValid()
113 return !is_null(ModerationBanana
::$client);
116 public function lastErrNo()
121 public function lastError()
126 public function getDescription()
128 return $this->infos
['desc'];
131 public function getBoxList($mode = Banana
::BOXES_ALL
, $since = 0, $withstats = false
)
133 return array(Banana
::$group => Array(
134 'desc' => $this->infos
['desc'],
135 'msgnum' => count($this->helds
),
136 'unread' => count($this->helds
)));
139 public function &getMessage($id)
142 $msg = ModerationBanana
::$client->get_pending_mail(ModerationBanana
::$listname, $id, 1);
144 $message = new BananaMessage(html_entity_decode($msg));
149 public function getMessageSource($id)
151 return ModerationBanana
::$client->get_pending_mail(ModerationBanana
::$listname, $id, 1);
154 public function getIndexes()
157 foreach ($this->helds
as &$desc) {
158 $ids[] = intval($desc['id']);
161 return array(count($ids), min($ids), max($ids));
164 public function &getMessageHeaders($firstid, $lastid, array $msg_headers = array())
166 $conv = array('from' => 'sender', 'subject' => 'subj', 'date' => 'stamp', 'message-id' => 'id');
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();
176 if ($mlhdr == 'id') {
177 $headers[$id][$hdr] = $desc['stamp'] . '$' . $desc['id'] . '@' . Banana
::$group;
179 $headers[$id][$hdr] = isset($desc[$mlhdr]) ?
banana_html_entity_decode($desc[$mlhdr]) : null
;
186 public function updateSpool(array &$messages) { }
188 public function getNewIndexes($since)
191 foreach ($this->helds
as &$desc) {
192 if ($desc['stamp'] > $since) {
193 $ids[] = intval($desc['id']);
200 public function canSend()
205 public function canCancel()
210 public function requestedHeaders()
215 public function send(BananaMessage
$message)
220 public function cancel(BananaMessage
$message)
225 public function name()
227 return 'MLModeration';
230 public function filename()
232 return ModerationBanana
::$domain . '_' . ModerationBanana
::$listname;
235 public function backtrace()
241 // vim:set et sw=4 sts=4 ts=4 enc=utf-8: