Adds XSRF protection to the XnetLists module.
[platal.git] / include / banana / ml.inc.php
CommitLineData
fa7d6c7b 1<?php
2/***************************************************************************
179afa7f 3 * Copyright (C) 2003-2008 Polytechnique.org *
fa7d6c7b 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
22require_once 'banana/banana.inc.php';
23require_once 'banana/hooks.inc.php';
24
d300e6f3
FB
25class PlatalBananaMLPage extends PlatalBananaPage
26{
27 public function __construct()
28 {
29 parent::__construct();
30 global $platal;
31 $this->handler = 'BananaMLHandler';
32 $this->base = $platal->pl_self(1);
33 }
34}
35
36class BananaMLHandler extends BananaHandler
37{
38 public function template()
39 {
40 return 'lists/archives.tpl';
41 }
42}
43
fa7d6c7b 44class MLBanana extends Banana
45{
46 static public $listname;
47 static public $domain;
48
b2bffbe6 49 function __construct($forlife, $params = null)
fa7d6c7b 50 {
f9182d1d 51 global $globals;
580d1c7d 52 Banana::$spool_root = $globals->banana->spool_root;
fa7d6c7b 53 Banana::$spool_boxlist = false;
54 Banana::$msgedit_canattach = true;
81e9c63f 55 Banana::$debug_mbox = ($globals->debug & DEBUG_BT);
56 Banana::$debug_smarty = ($globals->debug & DEBUG_SMARTY);
d3f26be9 57 Banana::$mbox_helper = $globals->banana->mbox_helper;
831ff3e3 58 Banana::$feed_updateOnDemand = true;
1515e65a 59 if (S::has_perms()) {
60 Banana::$msgshow_mimeparts[] = 'source';
eaf30d86 61 }
fa7d6c7b 62 array_push(Banana::$msgparse_headers, 'x-org-id', 'x-org-mail');
6544d0e1 63 if (!S::v('core_rss_hash')) {
64 Banana::$feed_active = false;
65 }
ea626742 66
fa7d6c7b 67 MLBanana::$listname = $params['listname'];
68 MLBanana::$domain = $params['domain'];
69 $params['group'] = $params['listname'] . '@' . $params['domain'];
d300e6f3 70 parent::__construct($params, 'MLArchive', 'PlatalBananaMLPage');
fa7d6c7b 71 }
72
73 public function run()
74 {
75 global $platal, $globals;
76
315fa6ae 77 $nom = S::v('prenom') . ' ' . S::v('nom');
78 $mail = S::v('bestalias') . '@' . $globals->mail->domain;
79 $sig = $nom . ' (' . S::v('promo') . ')';
80 Banana::$msgedit_headers['X-Org-Mail'] = S::v('forlife') . '@' . $globals->mail->domain;
81
82 // Build user profile
2d967f8c 83 Banana::$profile['headers']['From'] = "$nom <$mail>";
437a98e0 84 Banana::$profile['headers']['Organization'] = make_Organization();
2d967f8c 85 Banana::$profile['signature'] = $sig;
eaf30d86 86
315fa6ae 87 // Page design
c93959a9 88 Banana::$page->killPage('forums');
eaf30d86 89 Banana::$page->killPage('subscribe');
fa7d6c7b 90
91 // Run Banana
92 return parent::run();
93 }
94}
95
96require_once('banana/mbox.inc.php');
97
98class BananaMLArchive extends BananaMBox
99{
100 public function name()
101 {
102 return 'MLArchives';
103 }
104
5760f76b 105 public function getBoxList($mode = Banana::BOXES_ALL, $since = 0, $withstats = false)
106 {
107 global $globals;
108 $spool = $globals->lists->spool . '/';
dee14597 109 $list = glob($spool . '*.mbox/*.mbox');
5760f76b 110 if ($list === false) {
111 return array();
112 }
113 $groups = array();
114 foreach ($list as $path) {
dee14597 115 $path = substr($path, strpos($path, 'mbox/') + 5);
5760f76b 116 $path = substr($path, 0, -5);
117 list($domain, $listname) = explode($globals->lists->vhost_sep, $path, 2);
118 $group = $listname . '@' . $domain;
119 $groups[$group] = array('desc' => null, 'msgnum' => null, 'unread' => null);
120 }
121 return $groups;
122 }
123
fa7d6c7b 124 public function filename()
125 {
5760f76b 126 if (MLBanana::$listname) {
127 $listname = MLBanana::$listname;
128 $domain = MLBanana::$domain;
129 } else {
130 list($listname, $domain) = explode('@', Banana::$group);
131 }
132 return $domain . '_' . $listname;
fa7d6c7b 133 }
134
3e949cf9 135 protected function getFileName()
fa7d6c7b 136 {
137 global $globals;
138 $base = $globals->lists->spool;
5760f76b 139 if (MLBanana::$listname) {
140 $listname = MLBanana::$listname;
141 $domain = MLBanana::$domain;
142 } else {
143 list($listname, $domain) = explode('@', Banana::$group);
144 }
145 $file = $domain . $globals->lists->vhost_sep . $listname . '.mbox';
fa7d6c7b 146 return "$base/$file/$file";
147 }
148}
149
a7de4ef7 150// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
fa7d6c7b 151?>