From fa7d6c7bcc7d547b3a17db356d1a38eb0a24f638 Mon Sep 17 00:00:00 2001 From: x2003bruneau Date: Sun, 14 Jan 2007 21:05:18 +0000 Subject: [PATCH] Banana for ML archives git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1336 839d8a87-29fc-0310-9880-83ba4fa771e5 --- ChangeLog | 1 + configs/platal.ini | 2 +- include/banana/forum.inc.php | 2 +- include/banana/ml.inc.php | 142 ++++++++++++++++++++++++++++++++++++++++ include/banana/moderate.inc.php | 2 +- modules/banana.php | 36 +++++----- modules/lists.php | 50 +++++++------- templates/lists/archives.tpl | 63 +----------------- 8 files changed, 193 insertions(+), 105 deletions(-) create mode 100644 include/banana/ml.inc.php diff --git a/ChangeLog b/ChangeLog index a987c47..7ae1f4a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -21,6 +21,7 @@ New: * Lists: - Use Banana to power mail moderation -FRU + - Use Banana to browse mail archives -FRU * Newsletter: - New skin -mYk diff --git a/configs/platal.ini b/configs/platal.ini index 83a3ea1..5dc1918 100644 --- a/configs/platal.ini +++ b/configs/platal.ini @@ -28,7 +28,7 @@ alias_dom2 = "" rpchost = "localhost" rpcport = 4949 -spool = "/var/spool/platal/archives/" +spool = "/var/lib/mailman/archives/private" vhost_sep = "_" diff --git a/include/banana/forum.inc.php b/include/banana/forum.inc.php index ca845dd..651fdb8 100644 --- a/include/banana/forum.inc.php +++ b/include/banana/forum.inc.php @@ -46,7 +46,7 @@ function hook_makeLink($params) return $base . hook_platalMessageLink($params); } -class PlatalForums extends Banana +class ForumsBanana extends Banana { function __construct($params = null) { diff --git a/include/banana/ml.inc.php b/include/banana/ml.inc.php new file mode 100644 index 0000000..cc6a2ee --- /dev/null +++ b/include/banana/ml.inc.php @@ -0,0 +1,142 @@ +baseurl . $platal->ns . '/lists/archives/' . MLBanana::$listname; + return $base . hook_platalMessageLink($params); +} + +class MLBanana extends Banana +{ + static public $listname; + static public $domain; + + function __construct($params = null) + { + Banana::$spool_boxlist = false; + Banana::$msgedit_canattach = true; + array_push(Banana::$msgparse_headers, 'x-org-id', 'x-org-mail'); + + MLBanana::$listname = $params['listname']; + MLBanana::$domain = $params['domain']; + $params['group'] = $params['listname'] . '@' . $params['domain']; + parent::__construct($params, 'MLArchive'); + } + + public function run() + { + global $platal, $globals; + +/* // Update last unread time + $time = null; + if (!is_null($this->params) && isset($this->params['updateall'])) { + $time = intval($this->params['updateall']); + $_SESSION['banana_last'] = $time; + } + + // Get user profile from SQL + $req = XDB::query("SELECT nom, mail, sig, + FIND_IN_SET('threads',flags), FIND_IN_SET('automaj',flags) + FROM {$globals->banana->table_prefix}profils + WHERE uid={?}", S::i('uid')); + if (!(list($nom,$mail,$sig,$disp,$maj) = $req->fetchOneRow())) { + $nom = S::v('prenom')." ".S::v('nom'); + $mail = S::v('forlife')."@polytechnique.org"; + $sig = $nom." (".S::v('promo').")"; + $disp = 0; + $maj = 1; + } + if ($maj) { + $time = time(); + } + + // Build user profile + $req = XDB::query(" + SELECT nom + FROM {$globals->banana->table_prefix}abos + LEFT JOIN {$globals->banana->table_prefix}list ON list.fid=abos.fid + WHERE uid={?}", S::i('uid')); + Banana::$profile['headers']['From'] = utf8_encode("$nom <$mail>"); + Banana::$profile['headers']['Organization'] = 'Utilisateur de Polytechnique.org'; + Banana::$profile['signature'] = utf8_encode($sig); + Banana::$profile['display'] = $disp; + Banana::$profile['autoup'] = $maj; + Banana::$profile['lastnews'] = S::v('banana_last'); + Banana::$profile['subscribe'] = $req->fetchColumn(); + + // Update the "unread limit" + if (!is_null($time)) { + XDB::execute("UPDATE auth_user_quick + SET banana_last = FROM_UNIXTIME({?}) + WHERE user_id={?}", + $time, S::i('uid')); + } + + // Register custom Banana links and tabs + if (!Banana::$profile['autoup']) { + Banana::$page->registerAction('path . '", "updateall", ' . time() . ')\'>' + . 'Marquer tous les messages comme lus' + . '', array('forums', 'thread', 'message')); + } + Banana::$page->registerPage('profile', utf8_encode('Préférences'), null); +*/ Banana::$page->killPage('forums'); + Banana::$page->killPage('subscribe'); + + // Run Banana + return parent::run(); + } +} + +require_once('banana/mbox.inc.php'); + +class BananaMLArchive extends BananaMBox +{ + public function name() + { + return 'MLArchives'; + } + + public function filename() + { + return MLBanana::$domain . '_' . MLBanana::$listname; + } + + protected function getFileName($box) + { + global $globals; + $base = $globals->lists->spool; + $file = MLBanana::$domain . $globals->lists->vhost_sep . MLBanana::$listname . '.mbox'; + return "$base/$file/$file"; + } +} + +?> diff --git a/include/banana/moderate.inc.php b/include/banana/moderate.inc.php index 0faf662..08168ac 100644 --- a/include/banana/moderate.inc.php +++ b/include/banana/moderate.inc.php @@ -30,7 +30,7 @@ function hook_checkcancel($_headers) function hook_makeLink($params) { global $platal, $globals; - $base = $globals->baseurl . '/' . $platal->ns . '/lists/moderate/' . ModerationBanana::$listname . '?'; + $base = $globals->baseurl . $platal->ns . '/lists/moderate/' . ModerationBanana::$listname . '?'; $get = ''; foreach ($params as $key=>$value) { if ($key == 'artid') { diff --git a/modules/banana.php b/modules/banana.php index 9a1ebca..efa90c0 100644 --- a/modules/banana.php +++ b/modules/banana.php @@ -69,25 +69,23 @@ class BananaModule extends PLModule if (!is_null($action)) { if ($action == 'new') { $get['action'] = 'new'; - } elseif ($action == 'reply' && !is_null($artid)) { - $get['action'] = 'new'; - $get['artid'] = $artid; - } elseif ($action == 'cancel' && !is_null($artid)) { - $get['action'] = $action; - $get['artid'] = $artid; - } elseif ($action == 'from' && !is_null($artid)) { - $get['first'] = $artid; - } elseif ($action == 'read' && !is_null($artid)) { - $get['artid'] = $artid; - $get['part'] = @$_GET['part']; - } elseif ($action == 'source' && !is_null($artid)) { - $get['artid'] = $artid; - $get['part'] = 'source'; - } elseif ($action == 'xface' && !is_null($artid)) { - $get['artid'] = $artid; - $get['part'] = 'xface'; + } elseif (!is_null($artid)) { + $get['artid'] = $artid; + if ($action == 'reply') { + $get['action'] = 'new'; + } elseif ($action == 'cancel') { + $get['action'] = $action; + } elseif ($action == 'from') { + $get['first'] = $artid; + } elseif ($action == 'read') { + $get['part'] = @$_GET['part']; + } elseif ($action == 'source') { + $get['part'] = 'source'; + } elseif ($action == 'xface') { + $get['part'] = 'xface'; + } } - } + } return BananaModule::run_banana($page, $get); } @@ -151,7 +149,7 @@ class BananaModule extends PLModule require_once 'banana/forum.inc.php'; - $banana = new PlatalForums($params); + $banana = new ForumsBanana($params); $res = $banana->run(); $page->assign_by_ref('banana', $banana); $page->assign('banana_res', $res); diff --git a/modules/lists.php b/modules/lists.php index efd529d..31c6965 100644 --- a/modules/lists.php +++ b/modules/lists.php @@ -317,7 +317,7 @@ class ListsModule extends PLModule } } - function handler_archives(&$page, $liste = null) + function handler_archives(&$page, $liste = null, $action = null, $artid = null) { global $globals; @@ -329,33 +329,39 @@ class ListsModule extends PLModule $page->changeTpl('lists/archives.tpl'); - $page->addCssLink('lists.archives.css'); if (list($det) = $this->client->get_members($liste)) { if (substr($liste,0,5) != 'promo' && ($det['ins'] || $det['priv']) - && !$det['own'] && ($det['sub'] < 2)) - { + && !$det['own'] && ($det['sub'] < 2)) { $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter"); - } elseif (Get::has('file')) { - $file = Get::v('file'); - $rep = Get::v('rep'); - if (strstr('/', $file)!==false || !preg_match(',^\d+/\d+$,', $rep)) { - $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter"); - } else { - $page->assign('archives', $globals->lists->spool - ."/{$domain}{$globals->lists->vhost_sep}$liste/$rep/$file"); - } - } else { - $archs = Array(); - foreach (glob($globals->lists->spool - ."/{$domain}{$globals->lists->vhost_sep}$liste/*/*") as $rep) - { - if (preg_match(",/(\d*)/(\d*)$,", $rep, $matches)) { - $archs[intval($matches[1])][intval($matches[2])] = true; + } + $get = Array('listname' => $liste, 'domain' => $domain); + if (Post::has('updateall')) { + $get['updateall'] = Post::v('updateall'); + } + if (!is_null($action)) { + if ($action == 'new') { + $get['action'] = 'new'; + } elseif (!is_null($artid)) { + $get['artid'] = $artid; + if ($action == 'reply') { + $get['action'] = 'new'; + } elseif ($action == 'cancel') { + $get['action'] = $action; + } elseif ($action == 'from') { + $get['first'] = $artid; + } elseif ($action == 'read') { + $get['part'] = @$_GET['part']; + } elseif ($action == 'source') { + $get['part'] = 'source'; + } elseif ($action == 'xface') { + $get['part'] = 'xface'; } } - $page->assign('archs', $archs); - $page->assign('range', range(1,12)); } + require_once('banana/ml.inc.php'); + $banana = new MLBanana($get); + $page->assign('banana', $banana->run()); + $page->addCssLink('banana.css'); } else { $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter"); } diff --git a/templates/lists/archives.tpl b/templates/lists/archives.tpl index b3a9738..07ae353 100644 --- a/templates/lists/archives.tpl +++ b/templates/lists/archives.tpl @@ -20,69 +20,10 @@ {* *} {**************************************************************************} - {include file="lists/header_listes.tpl" on=archives} +

Archives

-{if $archs} -

Archives de la liste {$platal->argv[1]}

- -

Triés par fils de discussion

- - - - - - - {foreach from=$archs item=m key=y} - - - {foreach from=$range item=i} - - {if $i eq 6}{/if} - {/foreach} - - {/foreach} -
Année - Mois -
{$y} - {if $m[$i]} - {"0000-$i-01"|date_format:"%B"} - {else} -   - {/if} -
- -

Triés par date

- - - - - - - {foreach from=$archs item=m key=y} - - - {foreach from=$range item=i} - - {if $i eq 6}{/if} - {/foreach} - - {/foreach} -
Année - Mois -
{$y} - {if $m[$i]} - {"0000-$i-01"|date_format:"%B"} - {else} -   - {/if} -
-{elseif $archives} -{tidy} -{include file="$archives"} -{/tidy} -{/if} - +{$banana|smarty:nodefaults} {* vim:set et sw=2 sts=2 sws=2: *} -- 2.1.4