Moving to GitHub.
[platal.git] / include / banana / ml.inc.php
CommitLineData
fa7d6c7b 1<?php
2/***************************************************************************
c441aabe 3 * Copyright (C) 2003-2014 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
fa7d6c7b 22require_once 'banana/hooks.inc.php';
23
d300e6f3
FB
24class PlatalBananaMLPage extends PlatalBananaPage
25{
26 public function __construct()
27 {
28 parent::__construct();
29 global $platal;
30 $this->handler = 'BananaMLHandler';
31 $this->base = $platal->pl_self(1);
32 }
33}
34
35class BananaMLHandler extends BananaHandler
36{
37 public function template()
38 {
39 return 'lists/archives.tpl';
40 }
41}
42
fa7d6c7b 43class MLBanana extends Banana
44{
45 static public $listname;
46 static public $domain;
03264abd 47 private $user;
fa7d6c7b 48
26ba053e 49 function __construct(User $user, $params = null)
fa7d6c7b 50 {
f9182d1d 51 global $globals;
03264abd
VZ
52 $this->user = &$user;
53
5f0ecf6c 54 Banana::$spool_root = $globals->spoolroot . '/spool/banana/';
fa7d6c7b 55 Banana::$spool_boxlist = false;
56 Banana::$msgedit_canattach = true;
81e9c63f 57 Banana::$debug_mbox = ($globals->debug & DEBUG_BT);
58 Banana::$debug_smarty = ($globals->debug & DEBUG_SMARTY);
5f0ecf6c 59 Banana::$mbox_helper = $globals->spoolroot . '/banana/mbox-helper/mbox-helper';
831ff3e3 60 Banana::$feed_updateOnDemand = true;
dd70cd28 61 if (S::admin()) {
1515e65a 62 Banana::$msgshow_mimeparts[] = 'source';
eaf30d86 63 }
fa7d6c7b 64 array_push(Banana::$msgparse_headers, 'x-org-id', 'x-org-mail');
8c12f931 65 Banana::$feed_active = S::hasAuthToken();
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');
03264abd 78 $mail = $this->user->bestEmail();
315fa6ae 79 $sig = $nom . ' (' . S::v('promo') . ')';
03264abd 80 Banana::$msgedit_headers['X-Org-Mail'] = $this->user->forlifeEmail();
315fa6ae 81
43cddb05 82 // Tree color
7d15f750
FB
83 $req = XDB::query('SELECT tree_unread, tree_read
84 FROM forum_profiles
85 WHERE uid= {?}', $this->user->id());
43cddb05 86 if (!(list($unread, $read) = $req->fetchOneRow())) {
2a0d8734 87 $unread = 'o';
43cddb05
FB
88 $read = 'dg';
89 }
90 Banana::$tree_unread = $unread;
91 Banana::$tree_read = $read;
92
315fa6ae 93 // Build user profile
2d967f8c 94 Banana::$profile['headers']['From'] = "$nom <$mail>";
437a98e0 95 Banana::$profile['headers']['Organization'] = make_Organization();
2d967f8c 96 Banana::$profile['signature'] = $sig;
eaf30d86 97
315fa6ae 98 // Page design
c93959a9 99 Banana::$page->killPage('forums');
eaf30d86 100 Banana::$page->killPage('subscribe');
fa7d6c7b 101
102 // Run Banana
103 return parent::run();
104 }
105}
106
de201e9f 107require_once dirname(__FILE__) . '/../../banana/banana/mbox.inc.php';
fa7d6c7b 108
109class BananaMLArchive extends BananaMBox
110{
111 public function name()
112 {
113 return 'MLArchives';
114 }
115
5760f76b 116 public function getBoxList($mode = Banana::BOXES_ALL, $since = 0, $withstats = false)
117 {
118 global $globals;
119 $spool = $globals->lists->spool . '/';
dee14597 120 $list = glob($spool . '*.mbox/*.mbox');
5760f76b 121 if ($list === false) {
122 return array();
123 }
124 $groups = array();
125 foreach ($list as $path) {
dee14597 126 $path = substr($path, strpos($path, 'mbox/') + 5);
5760f76b 127 $path = substr($path, 0, -5);
128 list($domain, $listname) = explode($globals->lists->vhost_sep, $path, 2);
129 $group = $listname . '@' . $domain;
130 $groups[$group] = array('desc' => null, 'msgnum' => null, 'unread' => null);
131 }
132 return $groups;
133 }
134
fa7d6c7b 135 public function filename()
136 {
5760f76b 137 if (MLBanana::$listname) {
138 $listname = MLBanana::$listname;
139 $domain = MLBanana::$domain;
140 } else {
141 list($listname, $domain) = explode('@', Banana::$group);
142 }
143 return $domain . '_' . $listname;
fa7d6c7b 144 }
145
3e949cf9 146 protected function getFileName()
fa7d6c7b 147 {
148 global $globals;
149 $base = $globals->lists->spool;
5760f76b 150 if (MLBanana::$listname) {
151 $listname = MLBanana::$listname;
152 $domain = MLBanana::$domain;
153 } else {
154 list($listname, $domain) = explode('@', Banana::$group);
155 }
156 $file = $domain . $globals->lists->vhost_sep . $listname . '.mbox';
fa7d6c7b 157 return "$base/$file/$file";
158 }
159}
160
448c8cdc 161// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
fa7d6c7b 162?>