Banana for ML archives
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sun, 14 Jan 2007 21:05:18 +0000 (21:05 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sun, 14 Jan 2007 21:05:18 +0000 (21:05 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1336 839d8a87-29fc-0310-9880-83ba4fa771e5

ChangeLog
configs/platal.ini
include/banana/forum.inc.php
include/banana/ml.inc.php [new file with mode: 0644]
include/banana/moderate.inc.php
modules/banana.php
modules/lists.php
templates/lists/archives.tpl

index a987c47..7ae1f4a 100644 (file)
--- 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
index 83a3ea1..5dc1918 100644 (file)
@@ -28,7 +28,7 @@ alias_dom2 = ""
 rpchost   = "localhost"
 rpcport   = 4949
 
-spool     = "/var/spool/platal/archives/"
+spool     = "/var/lib/mailman/archives/private"
 vhost_sep = "_"
 
 
index ca845dd..651fdb8 100644 (file)
@@ -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 (file)
index 0000000..cc6a2ee
--- /dev/null
@@ -0,0 +1,142 @@
+<?php
+/***************************************************************************
+ *  Copyright (C) 2003-2007 Polytechnique.org                              *
+ *  http://opensource.polytechnique.org/                                   *
+ *                                                                         *
+ *  This program is free software; you can redistribute it and/or modify   *
+ *  it under the terms of the GNU General Public License as published by   *
+ *  the Free Software Foundation; either version 2 of the License, or      *
+ *  (at your option) any later version.                                    *
+ *                                                                         *
+ *  This program is distributed in the hope that it will be useful,        *
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
+ *  GNU General Public License for more details.                           *
+ *                                                                         *
+ *  You should have received a copy of the GNU General Public License      *
+ *  along with this program; if not, write to the Free Software            *
+ *  Foundation, Inc.,                                                      *
+ *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
+ ***************************************************************************/
+
+require_once 'banana/banana.inc.php';
+require_once 'banana/hooks.inc.php';
+
+function hook_checkcancel($_headers)
+{
+    return ($_headers['x-org-id'] == S::v('forlife') or S::has_perms());
+}
+
+function hook_makeLink($params)
+{
+    global $globals, $platal;
+    $base = $globals->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('<a href=\'javascript:dynpostkv("'
+                                . $platal->path . '", "updateall", ' . time() . ')\'>'
+                                . 'Marquer tous les messages comme lus'
+                                . '</a>', 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";
+    }
+}
+
+?>
index 0faf662..08168ac 100644 (file)
@@ -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') {
index 9a1ebca..efa90c0 100644 (file)
@@ -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);
index efd529d..31c6965 100644 (file)
@@ -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");
         }
index b3a9738..07ae353 100644 (file)
 {*                                                                        *}
 {**************************************************************************}
 
-
 {include file="lists/header_listes.tpl" on=archives}
 
+<h1>Archives</h1>
 
-{if $archs}
-<h1>Archives de la liste {$platal->argv[1]}</h1>
-
-<h2>Triés par fils de discussion</h2>
-
-<table class="tinybicol" cellspacing="0" cellpadding="0">
-  <tr>
-    <th>Année</th>
-    <th colspan="6">
-      Mois
-    </th>
-  </tr>
-  {foreach from=$archs item=m key=y}
-  <tr class="center {if $y is odd}pair{else}impair{/if}">
-    <td class="titre" rowspan="2">{$y}</td>
-    {foreach from=$range item=i}
-    <td>
-      {if $m[$i]}
-      <a href="{$platal->pl_self(1)}?rep={$y}/{$i|string_format:"%02u"}&amp;file=threads.html">{"0000-$i-01"|date_format:"%B"}</a>
-      {else}
-      &nbsp;
-      {/if}
-    </td>
-    {if $i eq 6}</tr><tr class="center {if $y is odd}pair{else}impair{/if}">{/if}
-    {/foreach}
-  </tr>
-  {/foreach}
-</table>
-
-<h2>Triés par date</h2>
-
-<table class="tinybicol" cellspacing="0" cellpadding="0">
-  <tr>
-    <th>Année</th>
-    <th colspan="6">
-      Mois
-    </th>
-  </tr>
-  {foreach from=$archs item=m key=y}
-  <tr class="center {if $y is odd}pair{else}impair{/if}">
-    <td class="titre" rowspan="2">{$y}</td>
-    {foreach from=$range item=i}
-    <td>
-      {if $m[$i]}
-      <a href="{$platal->pl_self(1)}?rep={$y}/{$i|string_format:"%02u"}&amp;file=dates.html">{"0000-$i-01"|date_format:"%B"}</a>
-      {else}
-      &nbsp;
-      {/if}
-    </td>
-    {if $i eq 6}</tr><tr class="center {if $y is odd}pair{else}impair{/if}">{/if}
-    {/foreach}
-  </tr>
-  {/foreach}
-</table>
-{elseif $archives}
-{tidy}
-{include file="$archives"}
-{/tidy}
-{/if}
-
+{$banana|smarty:nodefaults}
 
 {* vim:set et sw=2 sts=2 sws=2: *}