33ff53f9f362e46f6cbe8f60550611f2ef090521
[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 function hook_makeLink($params)
26 {
27 global $globals, $platal;
28 $base = $globals->baseurl . '/' . $platal->ns . 'lists/archives/' . MLBanana::$listname;
29 $base = $base . hook_platalMessageLink($params);
30 if (@$params['action'] == 'showext') {
31 $base .= '?action=showext';
32 }
33 return $base;
34 }
35
36 class MLBanana extends Banana
37 {
38 static public $listname;
39 static public $domain;
40
41 function __construct($params = null)
42 {
43 Banana::$spool_boxlist = false;
44 Banana::$msgedit_canattach = true;
45 if (S::has_perms()) {
46 Banana::$msgshow_mimeparts[] = 'source';
47 }
48 array_push(Banana::$msgparse_headers, 'x-org-id', 'x-org-mail');
49
50 MLBanana::$listname = $params['listname'];
51 MLBanana::$domain = $params['domain'];
52 $params['group'] = $params['listname'] . '@' . $params['domain'];
53 parent::__construct($params, 'MLArchive');
54 }
55
56 public function run()
57 {
58 global $platal, $globals;
59
60 $nom = S::v('prenom') . ' ' . S::v('nom');
61 $mail = S::v('bestalias') . '@' . $globals->mail->domain;
62 $sig = $nom . ' (' . S::v('promo') . ')';
63 Banana::$msgedit_headers['X-Org-Mail'] = S::v('forlife') . '@' . $globals->mail->domain;
64
65 // Build user profile
66 Banana::$profile['headers']['From'] = utf8_encode("$nom <$mail>");
67 Banana::$profile['headers']['Organization'] = 'Utilisateur de Polytechnique.org';
68 Banana::$profile['signature'] = utf8_encode($sig);
69
70 // Page design
71 Banana::$page->killPage('forums');
72 Banana::$page->killPage('subscribe');
73
74 // Run Banana
75 return parent::run();
76 }
77 }
78
79 require_once('banana/mbox.inc.php');
80
81 class BananaMLArchive extends BananaMBox
82 {
83 public function name()
84 {
85 return 'MLArchives';
86 }
87
88 public function getBoxList($mode = Banana::BOXES_ALL, $since = 0, $withstats = false)
89 {
90 global $globals;
91 $spool = $globals->lists->spool . '/';
92 $list = glob($spool . '*.mbox', GLOB_ONLYDIR);
93 if ($list === false) {
94 return array();
95 }
96 $groups = array();
97 foreach ($list as $path) {
98 $path = substr($path, strlen($spool));
99 $path = substr($path, 0, -5);
100 list($domain, $listname) = explode($globals->lists->vhost_sep, $path, 2);
101 $group = $listname . '@' . $domain;
102 $groups[$group] = array('desc' => null, 'msgnum' => null, 'unread' => null);
103 }
104 return $groups;
105 }
106
107 public function filename()
108 {
109 if (MLBanana::$listname) {
110 $listname = MLBanana::$listname;
111 $domain = MLBanana::$domain;
112 } else {
113 list($listname, $domain) = explode('@', Banana::$group);
114 }
115 return $domain . '_' . $listname;
116 }
117
118 protected function getFileName()
119 {
120 global $globals;
121 $base = $globals->lists->spool;
122 if (MLBanana::$listname) {
123 $listname = MLBanana::$listname;
124 $domain = MLBanana::$domain;
125 } else {
126 list($listname, $domain) = explode('@', Banana::$group);
127 }
128 $file = $domain . $globals->lists->vhost_sep . $listname . '.mbox';
129 return "$base/$file/$file";
130 }
131 }
132
133 ?>