Update example files
authorx2003bruneau <x2003bruneau@9869982d-c50d-0410-be91-f2a2ec7c7c7b>
Sun, 25 Feb 2007 20:36:48 +0000 (20:36 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 4 Jan 2008 23:35:32 +0000 (00:35 +0100)
Better behaviour for feed output

git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@216 9869982d-c50d-0410-be91-f2a2ec7c7c7b

banana/banana.inc.php.in
banana/page.inc.php
examples/index.php
examples/spoolgen.php

index fde1931..ac38001 100644 (file)
@@ -269,7 +269,8 @@ class Banana
             $error = $this->action_listBoxes();
             break;
           case Banana::ACTION_BOX_FEED:
-            return $this->action_feed(); // generate its own xml
+            $this->action_feed(); // generate its own xml
+            break;
           case Banana::ACTION_MSG_LIST:
             $error = $this->action_showThread(Banana::$group, Banana::$first);
             break;
@@ -360,7 +361,7 @@ class Banana
         Banana::load('feed');
         if (Banana::$group) {
             $feed =& BananaFeed::getFeed();
-            return $feed->toXML();
+            $feed->toXML();
         }
         if (Banana::$profile['subscribe']) {
             $subfeed = null;
@@ -372,9 +373,9 @@ class Banana
                 $feed =& BananaFeed::getFeed();
                 $subfeed =& BananaFeed::merge($subfeed, $feed, _b_('Abonnements'), _b_('Mes abonnements Banana'));
             }
-            return $subfeed->toXML();
+            $subfeed->toXML();
         }
-        return Banana::$page->feed();
+        Banana::$page->feed();
     }
 
     protected function action_showThread($group, $first)
index 446621b..4fe806d 100644 (file)
@@ -154,7 +154,9 @@ class BananaPage extends Smarty
         $this->assign('title_prefix', Banana::$feed_namePrefix);
         $this->assign('language', $lg);
         $this->register_function('rss_date', 'rss_date');
-        return $this->_run($tpl);
+        header('Content-Type: application/rss+xml; charset=utf-8');
+        echo $this->_run($tpl);
+        exit;
     }
 
     /** Code generation
index 9f59c9f..5a64fb0 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /********************************************************************************
-* index.php : main page (newsgroups list)
+* index.php : Banana NNTP client example
 * -----------
 *
 * This file is part of the banana distribution
@@ -11,34 +11,48 @@ require_once("banana/banana.inc.php");
 
 session_start();
 
+// Some configuration
+Banana::$nntp_host  = 'news://user:password@host:119/'; // where is the news server
+Banana::$spool_root  = dirname(__FILE__) . '/spool'; // where to store cache files
+Banana::$debug_nntp   = false; // if true, show the NNTP backtrace
+Banana::$debug_smarty = false; // if true, shos php-error in page generation
+Banana::$feed_active  = true;  // Activate RSS feed
+
+// Implement a Banana which stores subscription list in a cookie
 class MyBanana extends Banana
 {
     protected function action_saveSubs($groups)
     {
         parent::action_saveSubs($groups);
-        setcookie('banana_subs', serialize(Banana::$profile['subscribe']));
+        setcookie('banana_subs', serialize(Banana::$profile['subscribe']), time() + 25920000);
         return true;
     }
 }
 
+// Restore subscription list
 if (isset($_COOKIE['banana_subs'])) {
     Banana::$profile['subscribe'] = unserialize($_COOKIE['banana_subs']);
 }
+
+// Compute and set last visit time
 if (!isset($_SESSION['banana_lastnews']) && isset($_COOKIE['banana_lastnews'])) {
     $_SESSION['banana_lastnews'] = $_COOKIE['banana_lastnews'];
+} else if (!isset($_SESSION['banana_lastnews'])) {
+    $_SESSION['banana_lastnews'] = 0;
 }
-if (isset($_SESSION['banana_lastnews'])) {
-    Banana::$profile['lastnews'] = $_SESSION['banana_lastnews'];
-}
-setcookie('banana_lastnews', time());
+Banana::$profile['lastnews'] = $_SESSION['banana_lastnews'];
+setcookie('banana_lastnews', time(),  time() + 25920000);
 
-$banana = new MyBanana();
-$res = $banana->run();
-$css = $banana->css();
-$bt  = $banana->backtrace();
+// Run Bananan
+$banana = new MyBanana();    // Create the instance of Banana
+$res  = $banana->run();       // Run banana, and generate the XHTML output
+$css  = $banana->css();       // Get the CSS code to add in my page headers
+$feed = $banana->feed();      // Get a link to banana's feed. You need to use Banana::refreshAllFeeds in a cron or enable Banana::$feed_updateOnDemand in order to keep up-to-date feeds
+$bt   = $banana->backtrace(); // Get protocole execution backtrace
 
 session_write_close();
 
+// Genererate the page
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
@@ -47,6 +61,9 @@ session_write_close();
     <meta name="description" content="WebForum2/Banana">
     <link href="css/style.css" type="text/css" rel="stylesheet" media="screen">
     <link href="css/banana.css" type="text/css" rel="stylesheet" media="screen">
+<?php if ($feed) { ?>
+    <link rel="alternate" type="application/rss+xml" title="Banana :: Abonnements" href="<?php echo htmlentities($feed); ?>" />
+<?php } ?>
 <?php if ($css) { ?>
     <style type="text/css">
         <?php echo $css; ?>
@@ -66,6 +83,7 @@ session_write_close();
         Use <em>silk</em> icons from <a href="http://www.famfamfam.com/lab/icons/silk/">www.famfamfam.com</a>
       </div>
 <?php
+    // Generate the protocole Backtrace at the bottom of the page
     if ($bt) {
         echo "<div class=\"backtrace\">";
         foreach ($bt as &$entry) {
index 16663ee..2c017eb 100644 (file)
 
 require_once("banana/banana.inc.php");
 
-$opt = getopt('u:p:h');
+$opt = getopt('u:P:p:hfr:');
 
 if(isset($opt['h'])) {
     echo <<<EOF
-usage: spoolgen.php [ -u user ] [ -p pass ]
+usage: spoolgen.php [-h] [-f] [ -u user ] [ -p pass ] [ -P port ] [ -r spool_root ]
     create all spools, using user user and pass pass
+    if -f is set, also refresh the RSS feed
 EOF;
     exit;
 }
 
-Banana::$nntp_host = "news://{$opt['u']}:{$opt['p']}@localhost:119/\n";
-Banana::createAllSpool(array('NNTP'));
+if (!isset($opt['P'])) {
+    $opt['P'] = '119';
+}
 
+Banana::$nntp_host = "news://{$opt['u']}:{$opt['p']}@localhost:{$opt['P']}/\n";
+if (isset($opt['r'])) {
+    Banana::$spool_root = $opt['r'];
+}
+if (isset($opt['f'])) {
+    Banana::createAllSpool(array('NNTP'));
+} else {
+    Banana::refreshAllFeeds(array('NNTP'));
+}
 // vim:set et sw=4 sts=4 ts=4
 ?>