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