Close #407: RSS feed for Forums and MLs
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sun, 25 Feb 2007 17:25:09 +0000 (17:25 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sun, 25 Feb 2007 17:25:09 +0000 (17:25 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1515 839d8a87-29fc-0310-9880-83ba4fa771e5

13 files changed:
ChangeLog
bin/banana.feedgen.php [new file with mode: 0755]
bin/banana.spoolgen.php
bin/connect.db.inc.php
bin/cron/banana.feedgen.php [new symlink]
configs/platal.cron.in
include/banana/forum.inc.php
include/banana/hooks.inc.php
include/banana/ml.inc.php
include/banana/moderate.inc.php
include/rss.inc.php
modules/banana.php
modules/lists.php

index 290a5f4..63227bc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -12,10 +12,14 @@ New:
 
 Bug/Wish:
 
+    * Banana:
+        - #407: RSS feed                                                   -FRU
+
     * Profile:
         - Better checks on image type for photos                           -FRU
 
     * Lists:
+        - #407: RSS feed                                                   -FRU
         - #636: Remove non-X from trombi                                   -FRU
         - #638: Sort trombi by promo then name                             -FRU
 
diff --git a/bin/banana.feedgen.php b/bin/banana.feedgen.php
new file mode 100755 (executable)
index 0000000..f1dc65a
--- /dev/null
@@ -0,0 +1,19 @@
+#!/usr/bin/php5
+<?php
+/********************************************************************************
+ * spoolgen.php : spool generation
+ * --------------
+ *
+ * This file is part of the banana distribution
+ * Copyright: See COPYING files that comes with this distribution
+ ********************************************************************************/
+
+require_once 'connect.db.inc.php';
+require_once dirname(__FILE__).'/../include/banana/ml.inc.php';
+
+Banana::$spool_root = $globals->banana->spool_root;
+Banana::$nntp_host = "news://{$globals->banana->web_user}:{$globals->banana->web_pass}@{$globals->banana->server}:{$globals->banana->port}/";
+Banana::refreshAllFeeds(array('NNTP', 'MLArchive'));
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+?>
index 07ceda8..c81ff44 100755 (executable)
@@ -11,6 +11,7 @@
 require_once 'connect.db.inc.php';
 require_once dirname(__FILE__).'/../include/banana/ml.inc.php';
 
+Banana::$spool_root = $globals->banana->spool_root;
 Banana::$nntp_host = "news://{$globals->banana->web_user}:{$globals->banana->web_pass}@{$globals->banana->server}:{$globals->banana->port}/";
 Banana::createAllSpool(array('NNTP', 'MLArchive'));
 system("chown -R www-data:www-data /var/spool/banana");
index 3e61ba1..1cade25 100644 (file)
@@ -26,5 +26,6 @@ require_once('xorg.misc.inc.php');
 
 require_once 'xdb.php';
 
+$globals->baseurl = "https://www.polytechnique.org";
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>
diff --git a/bin/cron/banana.feedgen.php b/bin/cron/banana.feedgen.php
new file mode 120000 (symlink)
index 0000000..355e1d0
--- /dev/null
@@ -0,0 +1 @@
+../banana.feedgen.php
\ No newline at end of file
index 546d3b3..10ebba3 100644 (file)
@@ -18,6 +18,9 @@ WD=/home/web/prod/platal/bin/cron
 # validations
 0 */3 * * *    web     cd $WD; ./cron_validations.php
 
+# flux rss de banana
+*/5 * * * *     web     cd $WD; ./banana.feedgen.php > /dev/null
+
 # AX spammer
 15 * * * *      web     cd $WD; ./axletter.send.php | mail -e -s "envoi d'un mail de l'AX" br@staff.m4x.org
 
index bd8ea66..3061c7a 100644 (file)
@@ -27,28 +27,6 @@ function hook_checkcancel($_headers)
     return ($_headers['x-org-id'] == S::v('forlife') or S::has_perms());
 }
 
-function hook_makeLink($params)
-{
-    global $globals;
-    $base = $globals->baseurl . '/banana';
-    if (isset($params['page'])) {
-        return $base . '/' . $params['page'];
-    }
-    if (@$params['action'] == 'subscribe') {
-        return $base . '/subscription';
-    }
-
-    if (!isset($params['group'])) {
-        return $base;
-    }
-    $base .= '/' . $params['group'];
-    $base = $base . hook_platalMessageLink($params);
-    if (@$params['action'] == 'showext') {
-        $base .= '?action=showext';
-    }
-    return $base;
-}
-
 class ForumsBanana extends Banana
 {
     function __construct($params = null)
@@ -63,6 +41,9 @@ class ForumsBanana extends Banana
             Banana::$msgshow_mimeparts[] = 'source';
         }
         Banana::$debug_nntp = ($globals->debug & 1);
+        if (!S::v('core_rss_hash')) {
+            Banana::$feed_active = false;
+        }
         parent::__construct($params);
     }
 
index 1ce979d..493e560 100644 (file)
@@ -69,6 +69,16 @@ function hook_formatDisplayHeader($_header, $_text, $in_spool = false)
     return null;
 }
 
+function hook_platalRSS($group)
+{
+    if ($group) {
+        $group .= '/';
+    } else {
+        $group = '';
+    }
+    return '/rss/' . $group . S::v('forlife') . '/' . S::v('core_rss_hash') . '/rss.xml';
+}
+
 function hook_platalMessageLink($params)
 {
     $base = '';
@@ -115,5 +125,38 @@ function hook_makeImg($img, $alt, $height, $width)
     return '<img src="' . $url . '"' . $height . $width . ' alt="' . $alt . '" />';
 }
 
+function hook_makeLink($params)
+{
+    global $globals, $platal;
+    if (Banana::$protocole->name() == 'NNTP') {
+        $base = $globals->baseurl . '/banana';
+        if (@$params['action'] == 'rss' || @$params['action'] == 'rss2' || @$params['action'] == 'atom') {
+            return $base . hook_platalRSS(@$params['group']);
+        }
+        if (isset($params['page'])) {
+            return $base . '/' . $params['page'];
+        }
+        if (@$params['action'] == 'subscribe') {
+            return $base . '/subscription';
+        }
+    
+        if (!isset($params['group'])) {
+            return $base;
+        }
+        $base .= '/' . $params['group'];
+    } else if (Banana::$protocole->name() == 'MLArchives') {
+        $base = $globals->baseurl . '/' . $platal->ns . 'lists/archives';
+        if (@$params['action'] == 'rss' || @$params['action'] == 'rss2' || @$params['action'] == 'atom') {
+            return $base . hook_platalRSS(MLBanana::$listname);
+        }
+        $base .= '/' . MLBanana::$listname;
+    }
+    $base = $base . hook_platalMessageLink($params);
+    if (@$params['action'] == 'showext') {
+        $base .= '?action=showext';
+    }
+    return $base;
+}
+
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>
index 9cc5ec0..b635346 100644 (file)
 require_once 'banana/banana.inc.php';
 require_once 'banana/hooks.inc.php';
 
-function hook_makeLink($params)
-{
-    global $globals, $platal;
-    $base = $globals->baseurl . '/' . $platal->ns . 'lists/archives/' . MLBanana::$listname;
-    $base = $base . hook_platalMessageLink($params);
-    if (@$params['action'] == 'showext') {
-        $base .= '?action=showext';
-    }
-    return $base;
-}
-
 class MLBanana extends Banana
 {
     static public $listname;
@@ -50,6 +39,9 @@ class MLBanana extends Banana
             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'];
index 138c653..e4c03af 100644 (file)
@@ -69,6 +69,7 @@ class ModerationBanana extends Banana
         Banana::$withtabs      = false;
         Banana::$msgshow_externalimages = false;
         Banana::$msgshow_mimeparts[] = 'source';
+        Banana::$feed_active = false;
         array_push(Banana::$msgparse_headers, 'x-org-id', 'x-org-mail');
         parent::__construct($params, 'MLInterface', 'ModerationPage');
     }
index dfa0c43..a52bfbe 100644 (file)
@@ -25,7 +25,7 @@ function _rss_encode_date($d) {
     } else {
         $t = strtotime($d);
     }
-    return utf8_encode(date('r', $t));
+    return date('r', $t);
 }
 
 function to_rss ($s)
index 2bf9797..85f8db7 100644 (file)
@@ -27,7 +27,7 @@ class BananaModule extends PLModule
             'banana'              => $this->make_hook('banana', AUTH_COOKIE),
             'banana/profile'      => $this->make_hook('profile', AUTH_MDP),
             'banana/subscription' => $this->make_hook('subscription', AUTH_COOKIE),
-            'banana/xface'        => $this->make_hook('xface', AUTH_COOKIE),
+            'banana/rss'          => $this->make_hook('rss', AUTH_PUBLIC),
         );
     }
 
@@ -136,12 +136,29 @@ class BananaModule extends PLModule
         return $this->run_banana($page, Array('action' => 'subscribe'));
     }
 
-    function handler_xface(&$page, $face = null)
+    function handler_rss(&$page, $group, $alias, $hash, $file = null)
     {
-        header('Content-Type: image/gif');
-        passthru('echo ' . escapeshellarg(base64_decode(strtr($face, '.:', '+/')))
-                . '| uncompface -X '
-                . '| convert -transparent white xbm:- gif:-');
+        if (is_null($file)) {
+            if (is_null($hash)) {
+                exit;
+            }
+            $this->handler_rss($page, null, $group, $alias, $hash);
+        }
+        require_once('rss.inc.php');
+        $uid = init_rss(null, $alias, $hash);
+        if (!$uid) {
+            exit;
+        }
+        $res = XDB::query("SELECT id AS uid, alias AS forlife
+                             FROM aliases
+                            WHERE type = 'a_vie' AND id = {?}", $uid);
+        $row = $res->fetchOneAssoc();
+        $_SESSION = array_merge($row, $_SESSION);
+
+        require_once 'banana/forum.inc.php';
+        $banana = new ForumsBanana(array('group' => $group, 'action' => 'rss2'));
+        echo $banana->run();
+        exit;
     }
 
     static function run_banana(&$page, $params = null)
@@ -157,6 +174,14 @@ class BananaModule extends PLModule
         $page->assign('banana_res', $res);
         $page->addCssInline($banana->css());
         $page->addCssLink('banana.css');
+        $rss = $banana->feed();
+        if ($rss) {
+            if (@$params['group']) {
+                $page->setRssLink('Banana :: ' . $params['group'], $rss);
+            } else {
+                $page->setRssLink('Banana :: Abonnements', $rss);
+            }
+        }
         new PlBacktrace('NNTP', $banana->backtrace(), 'response', 'time');
     }
 }
index 24a63a3..9ae5ce2 100644 (file)
@@ -33,6 +33,7 @@ class ListsModule extends PLModule
             'lists/members'   => $this->make_hook('members',   AUTH_COOKIE),
             'lists/trombi'    => $this->make_hook('trombi',    AUTH_COOKIE),
             'lists/archives'  => $this->make_hook('archives',  AUTH_COOKIE),
+            'lists/archives/rss' => $this->make_hook('rss',    AUTH_PUBLIC),
 
             'lists/moderate'  => $this->make_hook('moderate',  AUTH_MDP),
             'lists/admin'     => $this->make_hook('admin',     AUTH_MDP),
@@ -383,12 +384,44 @@ class ListsModule extends PLModule
             $page->assign('banana', $banana->run());
             $page->addCssInline($banana->css());
             $page->addCssLink('banana.css');
+            $rss = $banana->feed();
+            if ($rss) {
+                $page->setRssLink('Banana :: ' . $list, $rss);
+            }
             new PlBacktrace('MBox', $banana->backtrace(), 'response', 'time');
         } else {
             $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
         }
     }
 
+    function handler_rss(&$page, $liste = null, $alias = null, $hash = null)
+    {
+        require_once('rss.inc.php');
+        $uid = init_rss(null, $alias, $hash);
+        if (!$uid || !$liste) {
+            exit;
+        }
+
+        $res = XDB::query("SELECT user_id AS uid, password, alias AS forlife
+                             FROM auth_user_md5 AS u
+                       INNER JOIN aliases       AS a ON (a.id = u.user_id AND a.type = 'a_vie')
+                            WHERE u.user_id = {?}", $uid);
+        $row = $res->fetchOneAssoc();
+        $_SESSION = array_merge($row, $_SESSION);
+
+        $domain = $this->prepare_client($page);
+        if (list($det) = $this->client->get_members($liste)) {
+            if (substr($liste,0,5) != 'promo' && ($det['ins'] || $det['priv'])
+                    && !$det['own'] && ($det['sub'] < 2)) {
+                exit;  
+            }
+            require_once('banana/ml.inc.php');
+            $banana = new MLBanana(Array('listname' => $liste, 'domain' => $domain, 'action' => 'rss2'));
+            echo $banana->run();
+        }
+        exit;
+    }
+
     function moderate_mail($domain, $liste, $mid)
     {
         $mail   = $this->client->get_pending_mail($liste, $mid);