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 |
10 | require_once("banana/banana.inc.php"); |
fe44f824 |
11 | |
12 | session_start(); |
13 | |
dfb752b1 |
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 |
fe44f824 |
22 | class MyBanana extends Banana |
23 | { |
24 | protected function action_saveSubs($groups) |
25 | { |
26 | parent::action_saveSubs($groups); |
dfb752b1 |
27 | setcookie('banana_subs', serialize(Banana::$profile['subscribe']), time() + 25920000); |
fe44f824 |
28 | return true; |
29 | } |
30 | } |
31 | |
dfb752b1 |
32 | // Restore subscription list |
fe44f824 |
33 | if (isset($_COOKIE['banana_subs'])) { |
34 | Banana::$profile['subscribe'] = unserialize($_COOKIE['banana_subs']); |
35 | } |
dfb752b1 |
36 | |
37 | // Compute and set last visit time |
fe44f824 |
38 | if (!isset($_SESSION['banana_lastnews']) && isset($_COOKIE['banana_lastnews'])) { |
39 | $_SESSION['banana_lastnews'] = $_COOKIE['banana_lastnews']; |
dfb752b1 |
40 | } else if (!isset($_SESSION['banana_lastnews'])) { |
41 | $_SESSION['banana_lastnews'] = 0; |
fe44f824 |
42 | } |
dfb752b1 |
43 | Banana::$profile['lastnews'] = $_SESSION['banana_lastnews']; |
44 | setcookie('banana_lastnews', time(), time() + 25920000); |
fe44f824 |
45 | |
dfb752b1 |
46 | // Run Bananan |
47 | $banana = new MyBanana(); // Create the instance of Banana |
48 | $res = $banana->run(); // Run banana, and generate the XHTML output |
49 | $css = $banana->css(); // Get the CSS code to add in my page headers |
50 | $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 |
51 | $bt = $banana->backtrace(); // Get protocole execution backtrace |
90962c86 |
52 | |
fe44f824 |
53 | session_write_close(); |
54 | |
dfb752b1 |
55 | // Genererate the page |
90962c86 |
56 | ?> |
0e25d15d |
57 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
58 | <html xmlns="http://www.w3.org/1999/xhtml"> |
8d99c683 |
59 | <head> |
62add405 |
60 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
61 | <meta name="description" content="WebForum2/Banana" /> |
62 | <link href="css/style.css" type="text/css" rel="stylesheet" media="screen" /> |
63 | <link href="css/banana.css" type="text/css" rel="stylesheet" media="screen" /> |
dfb752b1 |
64 | <?php if ($feed) { ?> |
65 | <link rel="alternate" type="application/rss+xml" title="Banana :: Abonnements" href="<?php echo htmlentities($feed); ?>" /> |
66 | <?php } ?> |
1ee29bd5 |
67 | <?php if ($css) { ?> |
68 | <style type="text/css"> |
69 | <?php echo $css; ?> |
70 | </style> |
71 | <?php } ?> |
8d99c683 |
72 | <title> |
73 | Banana, a NNTP<->Web Gateway |
74 | </title> |
75 | </head> |
76 | <body> |
77 | <div class="bloc"> |
fe44f824 |
78 | <h1>Les Forums de Banana</h1> |
79 | <?php echo $res; ?> |
8d99c683 |
80 | <div class="foot"> |
81 | <em>Banana</em>, a Web interface for a NNTP Server<br /> |
82 | Developed under GPL License for <a href="http://www.polytechnique.org">Polytechnique.org</a> |
35bf53d0 |
83 | Use <em>silk</em> icons from <a href="http://www.famfamfam.com/lab/icons/silk/">www.famfamfam.com</a> |
8d99c683 |
84 | </div> |
1ee29bd5 |
85 | <?php |
dfb752b1 |
86 | // Generate the protocole Backtrace at the bottom of the page |
1ee29bd5 |
87 | if ($bt) { |
88 | echo "<div class=\"backtrace\">"; |
89 | foreach ($bt as &$entry) { |
90 | echo "<div><pre>" . $entry['action'] . "</pre>"; |
91 | echo "<p style=\"padding-left: 4em;\">" |
92 | . "Exécution en " . sprintf("%.3fs", $entry['time']) . "<br />" |
93 | . "Retour : " . $entry['code'] . "<br />" |
94 | . "Lignes : " . $entry['response'] . "</p></div>"; |
95 | } |
96 | echo "</div>"; |
97 | } |
98 | ?> |
8d99c683 |
99 | </div> |
100 | </body> |
101 | </html> |
608f5b71 |
102 | <?php |
d5588318 |
103 | |
104 | // vim:set et sw=4 sts=4 ts=4 |
608f5b71 |
105 | ?> |