Some improvements for banana 'stand-alone'
[banana.git] / examples / index.php
CommitLineData
90962c86 1<?php
2/********************************************************************************
dfb752b1 3* index.php : Banana NNTP client example
90962c86 4* -----------
5*
6* This file is part of the banana distribution
7* Copyright: See COPYING files that comes with this distribution
8********************************************************************************/
9
4cc7f778 10require_once("banana/banana.inc.php");
fe44f824 11
12session_start();
13
dfb752b1 14// Some configuration
15Banana::$nntp_host = 'news://user:password@host:119/'; // where is the news server
16Banana::$spool_root = dirname(__FILE__) . '/spool'; // where to store cache files
17Banana::$debug_nntp = false; // if true, show the NNTP backtrace
18Banana::$debug_smarty = false; // if true, shos php-error in page generation
19Banana::$feed_active = true; // Activate RSS feed
068c6301 20Banana::$feed_updateOnDemand = true; // Update the feed cache when it is acceeded
dfb752b1 21
22// Implement a Banana which stores subscription list in a cookie
fe44f824 23class MyBanana extends Banana
24{
25 protected function action_saveSubs($groups)
26 {
27 parent::action_saveSubs($groups);
dfb752b1 28 setcookie('banana_subs', serialize(Banana::$profile['subscribe']), time() + 25920000);
fe44f824 29 return true;
30 }
31}
32
068c6301 33// Minimalist login
34if ((@$_GET['action'] == 'rss2') &&
35 (!isset($_SESSION['banana_email']) || isset($_POST['change_login']) || isset($_POST['valid_change']))) {
e83d5aa0 36 if (isset($_COOKIE['banana_login']) && !isset($_POST['change_login']) && !isset($_POST['valid_change'])) {
37 $_SESSION['banana_email'] = $_COOKIE['banana_email'];
38 } elseif (isset($_POST['valid_change'])) {
39 $_SESSION['banana_name'] = $_POST['name'];
40 $_SESSION['banana_email'] = $_POST['email'];
41 setcookie('banana_name', $_POST['name'], time() + 25920000);
42 setcookie('banana_email', $_POST['email'], time() + 25920000);
43 } else {
44?>
45<html xmlns="http://www.w3.org/1999/xhtml">
46 <head>
47 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
48 <meta name="description" content="WebForum2/Banana" />
49 <link href="css/style.css" type="text/css" rel="stylesheet" media="screen" />
50 <link href="css/banana.css" type="text/css" rel="stylesheet" media="screen">
51 <title>Banana, a NNTP<->Web Gateway</title>
52 </head>
53 <body>
54 <div class="bloc">
55 <h1>Les Forums de Banana</h1>
56 Merci d'entrer vos identifiants pour accéder à Banana :
57 <form action="" method="post">
58 <div class="banana" style="margin: auto; width: 50%">
59 Nom : <input type="text" name="name" size="40" /><br />
60 Email : <input type="text" name="email" size="40" />
61 <div class="center">
62 <input type="submit" name="valid_change" value="Valider" />
63 </div>
64 </div>
65 </form>
66 <div class="foot">
67 <em>Banana</em>, a Web interface for a NNTP Server<br />
68 Developed under GPL License for <a href="http://www.polytechnique.org">Polytechnique.org</a><br />
69 Use <em>silk</em> icons from <a href="http://www.famfamfam.com/lab/icons/silk/">www.famfamfam.com</a>
70 </div>
71 </div>
72 </body>
73</html>
74<?php
75 exit;
76 }
77}
78
dfb752b1 79// Restore subscription list
fe44f824 80if (isset($_COOKIE['banana_subs'])) {
81 Banana::$profile['subscribe'] = unserialize($_COOKIE['banana_subs']);
82}
dfb752b1 83
84// Compute and set last visit time
fe44f824 85if (!isset($_SESSION['banana_lastnews']) && isset($_COOKIE['banana_lastnews'])) {
86 $_SESSION['banana_lastnews'] = $_COOKIE['banana_lastnews'];
dfb752b1 87} else if (!isset($_SESSION['banana_lastnews'])) {
88 $_SESSION['banana_lastnews'] = 0;
fe44f824 89}
e83d5aa0 90Banana::$profile['signature'] = $_SESSION['banana_name'];
91Banana::$profile['headers']['From'] = '"' . $_SESSION['banana_name'] . '" <' . $_SESSION['banana_email'] . '>';
dfb752b1 92Banana::$profile['lastnews'] = $_SESSION['banana_lastnews'];
93setcookie('banana_lastnews', time(), time() + 25920000);
fe44f824 94
dfb752b1 95// Run Bananan
96$banana = new MyBanana(); // Create the instance of Banana
97$res = $banana->run(); // Run banana, and generate the XHTML output
98$css = $banana->css(); // Get the CSS code to add in my page headers
99$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
100$bt = $banana->backtrace(); // Get protocole execution backtrace
90962c86 101
fe44f824 102session_write_close();
103
dfb752b1 104// Genererate the page
90962c86 105?>
0e25d15d 106<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
107<html xmlns="http://www.w3.org/1999/xhtml">
8d99c683 108 <head>
62add405 109 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
110 <meta name="description" content="WebForum2/Banana" />
111 <link href="css/style.css" type="text/css" rel="stylesheet" media="screen" />
112 <link href="css/banana.css" type="text/css" rel="stylesheet" media="screen" />
dfb752b1 113<?php if ($feed) { ?>
114 <link rel="alternate" type="application/rss+xml" title="Banana :: Abonnements" href="<?php echo htmlentities($feed); ?>" />
115<?php } ?>
1ee29bd5 116<?php if ($css) { ?>
117 <style type="text/css">
118 <?php echo $css; ?>
119 </style>
120<?php } ?>
8d99c683 121 <title>
122 Banana, a NNTP<->Web Gateway
123 </title>
124 </head>
125 <body>
126 <div class="bloc">
fe44f824 127 <h1>Les Forums de Banana</h1>
128 <?php echo $res; ?>
e83d5aa0 129 <div>
130 <div style="padding-top: 1ex; float: right; text-align: right; font-size: small">
131 <form action="" method="post">
132 Vous êtes :<br />
133 <?php echo $_SESSION['banana_name'] . ' &lt;' . $_SESSION['banana_email'] . '&gt;'; ?><br />
134 <input type="submit" name="change_login" value="Changer" />
135 </form>
136 </div>
8d99c683 137 <div class="foot">
138 <em>Banana</em>, a Web interface for a NNTP Server<br />
e83d5aa0 139 Developed under GPL License for <a href="http://www.polytechnique.org">Polytechnique.org</a><br />
35bf53d0 140 Use <em>silk</em> icons from <a href="http://www.famfamfam.com/lab/icons/silk/">www.famfamfam.com</a>
8d99c683 141 </div>
e83d5aa0 142 </div>
1ee29bd5 143<?php
dfb752b1 144 // Generate the protocole Backtrace at the bottom of the page
1ee29bd5 145 if ($bt) {
146 echo "<div class=\"backtrace\">";
147 foreach ($bt as &$entry) {
148 echo "<div><pre>" . $entry['action'] . "</pre>";
149 echo "<p style=\"padding-left: 4em;\">"
150 . "Exécution en " . sprintf("%.3fs", $entry['time']) . "<br />"
151 . "Retour : " . $entry['code'] . "<br />"
152 . "Lignes : " . $entry['response'] . "</p></div>";
153 }
154 echo "</div>";
155 }
156?>
8d99c683 157 </div>
158 </body>
159</html>
608f5b71 160<?php
d5588318 161
162// vim:set et sw=4 sts=4 ts=4
608f5b71 163?>