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