merge with master
[platal.git] / include / banana / ml.inc.php
index cc6a2ee..1a5413f 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2007 Polytechnique.org                              *
+ *  Copyright (C) 2003-2008 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
 require_once 'banana/banana.inc.php';
 require_once 'banana/hooks.inc.php';
 
-function hook_checkcancel($_headers)
+class PlatalBananaMLPage extends PlatalBananaPage
 {
-    return ($_headers['x-org-id'] == S::v('forlife') or S::has_perms());
+    public function __construct()
+    {
+        parent::__construct();
+        global $platal;
+        $this->handler = 'BananaMLHandler';
+        $this->base    = $platal->pl_self(1);
+    }
 }
 
-function hook_makeLink($params)
+class BananaMLHandler extends BananaHandler
 {
-    global $globals, $platal;
-    $base = $globals->baseurl . $platal->ns . '/lists/archives/' . MLBanana::$listname;
-    return $base . hook_platalMessageLink($params);
+    public function template()
+    {
+        return 'lists/archives.tpl';
+    }
 }
 
 class MLBanana extends Banana
@@ -39,77 +46,47 @@ class MLBanana extends Banana
     static public $listname;
     static public $domain;
 
-    function __construct($params = null)
+    function __construct($forlife, $params = null)
     {
+        global $globals;
+        Banana::$spool_root = $globals->banana->spool_root;
         Banana::$spool_boxlist = false;
         Banana::$msgedit_canattach = true;
+        Banana::$debug_mbox = ($globals->debug & DEBUG_BT);
+        Banana::$debug_smarty = ($globals->debug & DEBUG_SMARTY);
+        Banana::$mbox_helper = $globals->banana->mbox_helper;
+        Banana::$feed_updateOnDemand = true;
+        if (S::has_perms()) {
+            Banana::$msgshow_mimeparts[] = 'source';
+        }
         array_push(Banana::$msgparse_headers, 'x-org-id', 'x-org-mail');
-        
+        if (!S::v('core_rss_hash')) {
+            Banana::$feed_active = false;
+        }
+
         MLBanana::$listname = $params['listname'];
         MLBanana::$domain   = $params['domain'];
         $params['group'] = $params['listname'] . '@' . $params['domain'];
-        parent::__construct($params, 'MLArchive');
+        parent::__construct($params, 'MLArchive', 'PlatalBananaMLPage');
     }
 
     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();
-        }
+        $nom  = S::v('prenom') . ' ' . S::v('nom');
+        $mail = S::v('bestalias') . '@' . $globals->mail->domain;
+        $sig  = $nom . ' (' . S::v('promo') . ')';
+        Banana::$msgedit_headers['X-Org-Mail'] = S::v('forlife') . '@' . $globals->mail->domain;
 
         // 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'));
-        }
+        Banana::$profile['headers']['From']         = "$nom <$mail>";
+        Banana::$profile['headers']['Organization'] = make_Organization();
+        Banana::$profile['signature']               = $sig;
 
-        // 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'); 
+        // Page design
+        Banana::$page->killPage('forums');
+        Banana::$page->killPage('subscribe');
 
         // Run Banana
         return parent::run();
@@ -125,18 +102,50 @@ class BananaMLArchive extends BananaMBox
         return 'MLArchives';
     }
 
+    public function getBoxList($mode = Banana::BOXES_ALL, $since = 0, $withstats = false)
+    {
+        global $globals;
+        $spool = $globals->lists->spool . '/';
+        $list = glob($spool . '*.mbox/*.mbox');
+        if ($list === false) {
+            return array();
+        }
+        $groups = array();
+        foreach ($list as $path) {
+            $path = substr($path, strpos($path, 'mbox/') + 5);
+            $path = substr($path, 0, -5);
+            list($domain, $listname) = explode($globals->lists->vhost_sep, $path, 2);
+            $group = $listname . '@' . $domain;
+            $groups[$group] = array('desc' => null, 'msgnum' => null, 'unread' => null);
+        }
+        return $groups;
+    }
+
     public function filename()
     {
-        return MLBanana::$domain . '_' . MLBanana::$listname;
+        if (MLBanana::$listname) {
+            $listname = MLBanana::$listname;
+            $domain   = MLBanana::$domain;
+        } else {
+            list($listname, $domain) = explode('@', Banana::$group);
+        }
+        return $domain . '_' . $listname;
     }
 
-    protected function getFileName($box)
+    protected function getFileName()
     {
         global $globals;
         $base = $globals->lists->spool;
-        $file = MLBanana::$domain . $globals->lists->vhost_sep . MLBanana::$listname . '.mbox';
+        if (MLBanana::$listname) {
+            $listname = MLBanana::$listname;
+            $domain   = MLBanana::$domain;
+        } else {
+            list($listname, $domain) = explode('@', Banana::$group);
+        }
+        $file = $domain . $globals->lists->vhost_sep . $listname . '.mbox';
         return "$base/$file/$file";
     }
 }
 
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>