e6dd6704ceee7e5a35b3f7d41b620955da62cdaa
[platal.git] / include / banana / ml.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2010 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 private $user;
49
50 function __construct(User &$user, $params = null)
51 {
52 global $globals;
53 $this->user = &$user;
54
55 Banana::$spool_root = $globals->banana->spool_root;
56 Banana::$spool_boxlist = false;
57 Banana::$msgedit_canattach = true;
58 Banana::$debug_mbox = ($globals->debug & DEBUG_BT);
59 Banana::$debug_smarty = ($globals->debug & DEBUG_SMARTY);
60 Banana::$mbox_helper = $globals->banana->mbox_helper;
61 Banana::$feed_updateOnDemand = true;
62 if (S::admin()) {
63 Banana::$msgshow_mimeparts[] = 'source';
64 }
65 array_push(Banana::$msgparse_headers, 'x-org-id', 'x-org-mail');
66 Banana::$feed_active = S::hasAuthToken();
67
68 MLBanana::$listname = $params['listname'];
69 MLBanana::$domain = $params['domain'];
70 $params['group'] = $params['listname'] . '@' . $params['domain'];
71 parent::__construct($params, 'MLArchive', 'PlatalBananaMLPage');
72 }
73
74 public function run()
75 {
76 global $platal, $globals;
77
78 $nom = S::v('prenom') . ' ' . S::v('nom');
79 $mail = $this->user->bestEmail();
80 $sig = $nom . ' (' . S::v('promo') . ')';
81 Banana::$msgedit_headers['X-Org-Mail'] = $this->user->forlifeEmail();
82
83 // Tree color
84 $req = XDB::query('SELECT tree_unread, tree_read
85 FROM forum_profiles
86 WHERE uid= {?}', $this->user->id());
87 if (!(list($unread, $read) = $req->fetchOneRow())) {
88 $unread = 'o';
89 $read = 'dg';
90 }
91 Banana::$tree_unread = $unread;
92 Banana::$tree_read = $read;
93
94 // Build user profile
95 Banana::$profile['headers']['From'] = "$nom <$mail>";
96 Banana::$profile['headers']['Organization'] = make_Organization();
97 Banana::$profile['signature'] = $sig;
98
99 // Page design
100 Banana::$page->killPage('forums');
101 Banana::$page->killPage('subscribe');
102
103 // Run Banana
104 return parent::run();
105 }
106 }
107
108 require_once('banana/mbox.inc.php');
109
110 class BananaMLArchive extends BananaMBox
111 {
112 public function name()
113 {
114 return 'MLArchives';
115 }
116
117 public function getBoxList($mode = Banana::BOXES_ALL, $since = 0, $withstats = false)
118 {
119 global $globals;
120 $spool = $globals->lists->spool . '/';
121 $list = glob($spool . '*.mbox/*.mbox');
122 if ($list === false) {
123 return array();
124 }
125 $groups = array();
126 foreach ($list as $path) {
127 $path = substr($path, strpos($path, 'mbox/') + 5);
128 $path = substr($path, 0, -5);
129 list($domain, $listname) = explode($globals->lists->vhost_sep, $path, 2);
130 $group = $listname . '@' . $domain;
131 $groups[$group] = array('desc' => null, 'msgnum' => null, 'unread' => null);
132 }
133 return $groups;
134 }
135
136 public function filename()
137 {
138 if (MLBanana::$listname) {
139 $listname = MLBanana::$listname;
140 $domain = MLBanana::$domain;
141 } else {
142 list($listname, $domain) = explode('@', Banana::$group);
143 }
144 return $domain . '_' . $listname;
145 }
146
147 protected function getFileName()
148 {
149 global $globals;
150 $base = $globals->lists->spool;
151 if (MLBanana::$listname) {
152 $listname = MLBanana::$listname;
153 $domain = MLBanana::$domain;
154 } else {
155 list($listname, $domain) = explode('@', Banana::$group);
156 }
157 $file = $domain . $globals->lists->vhost_sep . $listname . '.mbox';
158 return "$base/$file/$file";
159 }
160 }
161
162 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
163 ?>