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