Banana for ML archives
[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_checkcancel($_headers)
26 {
27 return ($_headers['x-org-id'] == S::v('forlife') or S::has_perms());
28 }
29
30 function hook_makeLink($params)
31 {
32 global $globals, $platal;
33 $base = $globals->baseurl . $platal->ns . '/lists/archives/' . MLBanana::$listname;
34 return $base . hook_platalMessageLink($params);
35 }
36
37 class MLBanana extends Banana
38 {
39 static public $listname;
40 static public $domain;
41
42 function __construct($params = null)
43 {
44 Banana::$spool_boxlist = false;
45 Banana::$msgedit_canattach = true;
46 array_push(Banana::$msgparse_headers, 'x-org-id', 'x-org-mail');
47
48 MLBanana::$listname = $params['listname'];
49 MLBanana::$domain = $params['domain'];
50 $params['group'] = $params['listname'] . '@' . $params['domain'];
51 parent::__construct($params, 'MLArchive');
52 }
53
54 public function run()
55 {
56 global $platal, $globals;
57
58 /* // Update last unread time
59 $time = null;
60 if (!is_null($this->params) && isset($this->params['updateall'])) {
61 $time = intval($this->params['updateall']);
62 $_SESSION['banana_last'] = $time;
63 }
64
65 // Get user profile from SQL
66 $req = XDB::query("SELECT nom, mail, sig,
67 FIND_IN_SET('threads',flags), FIND_IN_SET('automaj',flags)
68 FROM {$globals->banana->table_prefix}profils
69 WHERE uid={?}", S::i('uid'));
70 if (!(list($nom,$mail,$sig,$disp,$maj) = $req->fetchOneRow())) {
71 $nom = S::v('prenom')." ".S::v('nom');
72 $mail = S::v('forlife')."@polytechnique.org";
73 $sig = $nom." (".S::v('promo').")";
74 $disp = 0;
75 $maj = 1;
76 }
77 if ($maj) {
78 $time = time();
79 }
80
81 // Build user profile
82 $req = XDB::query("
83 SELECT nom
84 FROM {$globals->banana->table_prefix}abos
85 LEFT JOIN {$globals->banana->table_prefix}list ON list.fid=abos.fid
86 WHERE uid={?}", S::i('uid'));
87 Banana::$profile['headers']['From'] = utf8_encode("$nom <$mail>");
88 Banana::$profile['headers']['Organization'] = 'Utilisateur de Polytechnique.org';
89 Banana::$profile['signature'] = utf8_encode($sig);
90 Banana::$profile['display'] = $disp;
91 Banana::$profile['autoup'] = $maj;
92 Banana::$profile['lastnews'] = S::v('banana_last');
93 Banana::$profile['subscribe'] = $req->fetchColumn();
94
95 // Update the "unread limit"
96 if (!is_null($time)) {
97 XDB::execute("UPDATE auth_user_quick
98 SET banana_last = FROM_UNIXTIME({?})
99 WHERE user_id={?}",
100 $time, S::i('uid'));
101 }
102
103 // Register custom Banana links and tabs
104 if (!Banana::$profile['autoup']) {
105 Banana::$page->registerAction('<a href=\'javascript:dynpostkv("'
106 . $platal->path . '", "updateall", ' . time() . ')\'>'
107 . 'Marquer tous les messages comme lus'
108 . '</a>', array('forums', 'thread', 'message'));
109 }
110 Banana::$page->registerPage('profile', utf8_encode('Préférences'), null);
111 */ Banana::$page->killPage('forums');
112 Banana::$page->killPage('subscribe');
113
114 // Run Banana
115 return parent::run();
116 }
117 }
118
119 require_once('banana/mbox.inc.php');
120
121 class BananaMLArchive extends BananaMBox
122 {
123 public function name()
124 {
125 return 'MLArchives';
126 }
127
128 public function filename()
129 {
130 return MLBanana::$domain . '_' . MLBanana::$listname;
131 }
132
133 protected function getFileName($box)
134 {
135 global $globals;
136 $base = $globals->lists->spool;
137 $file = MLBanana::$domain . $globals->lists->vhost_sep . MLBanana::$listname . '.mbox';
138 return "$base/$file/$file";
139 }
140 }
141
142 ?>