| 1 | <?php |
| 2 | /*************************************************************************** |
| 3 | * Copyright (C) 2003-2014 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/hooks.inc.php'; |
| 23 | |
| 24 | function hook_checkcancel($_headers) |
| 25 | { |
| 26 | return ($_headers['x-org-id'] == S::v('hruid') or S::admin()); |
| 27 | } |
| 28 | |
| 29 | function hook_makeLink($params) |
| 30 | { |
| 31 | global $platal, $globals; |
| 32 | $base = $globals->baseurl . '/' . $platal->ns . 'lists/moderate/' . ModerationBanana::$listname . '?'; |
| 33 | $get = ''; |
| 34 | foreach ($params as $key=>$value) { |
| 35 | if ($key == 'artid') { |
| 36 | $key = 'mid'; |
| 37 | } |
| 38 | if ($key == 'group') { |
| 39 | continue; |
| 40 | } |
| 41 | if ($key == 'action' && $value != 'showext') { |
| 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 | |
| 58 | function __construct(User $user, $params = null) |
| 59 | { |
| 60 | ini_set('memory_limit', '128M'); |
| 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->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'); |
| 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 | Platal::page()->trigError($msg); |
| 93 | return true; |
| 94 | } |
| 95 | } |
| 96 | |
| 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 | { |
| 104 | $this->infos = ModerationBanana::$client->get_members(ModerationBanana::$listname); |
| 105 | $this->infos = $this->infos[0]; |
| 106 | |
| 107 | $mods = ModerationBanana::$client->get_pending_ops(ModerationBanana::$listname); |
| 108 | $this->helds = $mods[1]; |
| 109 | } |
| 110 | |
| 111 | public function isValid() |
| 112 | { |
| 113 | return !is_null(ModerationBanana::$client); |
| 114 | } |
| 115 | |
| 116 | public function lastErrNo() |
| 117 | { |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 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) { |
| 144 | $message = new BananaMessage(html_entity_decode($msg)); |
| 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 | |
| 215 | public function send(BananaMessage $message) |
| 216 | { |
| 217 | return true; |
| 218 | } |
| 219 | |
| 220 | public function cancel(BananaMessage $message) |
| 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 | } |
| 234 | |
| 235 | public function backtrace() |
| 236 | { |
| 237 | return null; |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | // vim:set et sw=4 sts=4 ts=4 fenc=utf-8: |
| 242 | ?> |