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