root/trunk/wifidog-auth/wifidog/classes/NodeLists/NodeListRSS.php @ 1253

Revision 1253, 16.3 KB (checked in by benoitg, 6 years ago)
  • Node.php: Improve getCurrentRealNode()
  • Implement #4: Allow the user to easily come back to the portal by typing in the root auth server adress from a hotspot.
  • Log the system information sent with the gateway since almost forever: sys_uptime, sys_memfree, sys_load, wifidog_uptime
  • NodeStatus?.php: Include the above information
  • node_list.html: Include wifidog_uptime if the hotspot is up.
  • Menu.php: Sort menus alphabetically according to the user's locale. TODO: Implement menu weights.
  • NodeLists?: Only list node types that have dependencies met in the menu. Refactor the NodeLists? for proper object-orientation.


Line 
1<?php
2
3/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5// +-------------------------------------------------------------------+
6// | WiFiDog Authentication Server                                     |
7// | =============================                                     |
8// |                                                                   |
9// | The WiFiDog Authentication Server is part of the WiFiDog captive  |
10// | portal suite.                                                     |
11// +-------------------------------------------------------------------+
12// | PHP version 5 required.                                           |
13// +-------------------------------------------------------------------+
14// | Homepage:     http://www.wifidog.org/                             |
15// | Source Forge: http://sourceforge.net/projects/wifidog/            |
16// +-------------------------------------------------------------------+
17// | This program is free software; you can redistribute it and/or     |
18// | modify it under the terms of the GNU General Public License as    |
19// | published by the Free Software Foundation; either version 2 of    |
20// | the License, or (at your option) any later version.               |
21// |                                                                   |
22// | This program is distributed in the hope that it will be useful,   |
23// | but WITHOUT ANY WARRANTY; without even the implied warranty of    |
24// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     |
25// | GNU General Public License for more details.                      |
26// |                                                                   |
27// | You should have received a copy of the GNU General Public License |
28// | along with this program; if not, contact:                         |
29// |                                                                   |
30// | Free Software Foundation           Voice:  +1-617-542-5942        |
31// | 59 Temple Place - Suite 330        Fax:    +1-617-542-2652        |
32// | Boston, MA  02111-1307,  USA       gnu@gnu.org                    |
33// |                                                                   |
34// +-------------------------------------------------------------------+
35
36/**
37 * @package    WiFiDogAuthServer
38 * @subpackage NodeLists
39 * @author     Max Horváth <max.horvath@freenet.de>
40 * @copyright  2006 Max Horváth, Horvath Web Consulting
41 * @version    Subversion $Id: Content.php 974 2006-02-25 15:08:12Z max-horvath $
42 * @link       http://www.wifidog.org/
43 */
44
45/**
46 * Load required classes
47 */
48require_once('classes/NodeList.php');
49require_once('classes/Network.php');
50require_once('classes/Node.php');
51require_once('classes/User.php');
52
53/**
54 * Defines the RSS type of node list
55 *
56 * @package    WiFiDogAuthServer
57 * @subpackage NodeLists
58 * @author     Max Horváth <max.horvath@freenet.de>
59 * @copyright  2006 Max Horváth, Horvath Web Consulting
60 * @copyright  2004-2007 Benoit Grégoire, Technologies Coeus inc.
61 */
62class NodeListRSS extends NodeList{
63
64    /**
65     * XML DOM Document that will contain all the data concerning the nodes
66     *
67     * @var object
68
69     */
70    private $_xmldoc;
71
72    /**
73     * Network to generate the list from
74     *
75     * @var object
76
77     */
78    private $_network;
79
80    /**
81     * Nodes to generate the list from
82     *
83     * @var array
84
85     */
86    private $_nodes;
87
88    /**
89     * Constructor
90     *
91     * @return void
92     */
93    public function __construct(&$network)
94    {
95       
96        $db = AbstractDb::getObject();
97
98        // Init XML Document
99        $this->_xmldoc = new DOMDocument("1.0", "UTF-8");
100        $this->_xmldoc->formatOutput = true;
101
102        // Init network
103        $this->_network = $network;
104
105        // Query the database, sorting by node name
106        $db->execSql("SELECT *, (CURRENT_TIMESTAMP-last_heartbeat_timestamp) AS since_last_heartbeat, EXTRACT(epoch FROM creation_date) as creation_date_epoch, CASE WHEN ((CURRENT_TIMESTAMP-last_heartbeat_timestamp) < interval '5 minutes') THEN true ELSE false END AS is_up FROM nodes WHERE network_id = '" . $db->escapeString($this->_network->getId()) . "' AND (node_deployment_status = 'DEPLOYED' OR node_deployment_status = 'NON_WIFIDOG_NODE') ORDER BY lower(name)", $this->_nodes, false);
107    }
108
109    /**
110     * Sets header of output
111     *
112     * @return void
113     */
114    public function setHeader()
115    {
116        header("Cache-control: private, no-cache, must-revalidate");
117        header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); # Past date
118        header("Pragma: no-cache");
119        header("Content-Type: text/xml; charset=UTF-8");
120    }
121
122    /**
123     * Retreives the output of this object.
124     *
125     * @return void
126     *
127     * @author     Benoit Grégoire <bock@step.polymtl.ca>
128     * @author     Francois Proulx <francois.proulx@gmail.com>
129     * @author     Max Horváth <max.horvath@freenet.de>
130     * @copyright  2004-2006 Benoit Grégoire, Technologies Coeus inc.
131     * @copyright  2004-2006 Francois Proulx, Technologies Coeus inc.
132     * @copyright  2006 Max Horváth, Horvath Web Consulting
133     */
134    public function getOutput()
135    {
136       
137        $db = AbstractDb::getObject();
138
139        // Root node
140        $_rss = $this->_xmldoc->createElement("rss");
141        $this->_xmldoc->appendChild($_rss);
142
143        $_rss->setAttribute('version', '2.0');
144
145        // channel
146        $_channel = $this->_xmldoc->createElement("channel");
147        $_rss->appendChild($_channel);
148
149        /*
150         * Required channel elements
151         */
152
153        // title
154        $_title = $this->_xmldoc->createElement("title");
155        $_title = $_channel->appendChild($_title);
156
157        $_textNode = $this->_xmldoc->createTextNode($this->_network->getName() . ": " . _("Newest Hotspots"));
158        $_title->appendChild($_textNode);
159
160        // link
161        $_link = $this->_xmldoc->createElement("link");
162        $_channel->appendChild($_link);
163        $_textNode = $this->_xmldoc->createTextNode($this->_network->getWebSiteURL());
164        $_link->appendChild($_textNode);
165
166        // description
167        $_description = $this->_xmldoc->createElement("description");
168        $_channel->appendChild($_description);
169        $_textNode = $this->_xmldoc->createTextNode(_("List of the most recent Hotspots opened by the network: ") . $this->_network->getName());
170        $_description->appendChild($_textNode);
171
172        /*
173         * Optional channel elements
174         */
175
176        // language
177        $_language = $this->_xmldoc->createElement("language");
178        $_channel->appendChild($_language);
179
180        if (User::getCurrentUser() != null) {
181            $_textNode = $this->_xmldoc->createTextNode(substr(User::getCurrentUser()->getPreferedLocale(), 0, 5));
182        } else {
183            $_textNode = $this->_xmldoc->createTextNode("en-US");
184        }
185        $_language->appendChild($_textNode);
186
187        // copyright
188        $_copyright = $this->_xmldoc->createElement("copyright");
189        $_channel->appendChild($_copyright);
190        $_textNode = $this->_xmldoc->createTextNode(_("Copyright ") . $this->_network->getName());
191        $_copyright->appendChild($_textNode);
192
193        // webMaster
194        if ($this->_network->getTechSupportEmail() != "") {
195            $_webMaster = $this->_xmldoc->createElement("webMaster");
196            $_channel->appendChild($_webMaster);
197            $_textNode = $this->_xmldoc->createTextNode($this->_network->getTechSupportEmail());
198            $_webMaster->appendChild($_textNode);
199        }
200
201        // pubDate
202        $_pubDate = $this->_xmldoc->createElement("pubDate");
203        $_channel->appendChild($_pubDate);
204        $_textNode = $this->_xmldoc->createTextNode(gmdate("D, d M Y H:i:s \G\M\T", time()));
205        $_pubDate->appendChild($_textNode);
206
207        /**
208         * lastBuildDate
209         *
210         * <lastBuildDate> -- The date-time the last time the content of the
211         * channel changed.
212         *
213         * Make a request through the database for the latest modification date
214         * of an object.
215         *
216         * @todo The latest modification date of an object should be an
217         *       object property
218         */
219        $db->execSqlUniqueRes("SELECT EXTRACT(epoch FROM MAX(creation_date)) as date_last_hotspot_opened FROM nodes WHERE network_id = '" . $db->escapeString($this->_network->getId()) . "' AND (node_deployment_status = 'DEPLOYED' OR node_deployment_status = 'NON_WIFIDOG_NODE')", $_lastHotspotRow, false);
220
221        $_lastBuildDate = $this->_xmldoc->createElement("lastBuildDate");
222        $_channel->appendChild($_lastBuildDate);
223        $_textNode = $this->_xmldoc->createTextNode(gmdate("D, d M Y H:i:s \G\M\T", $_lastHotspotRow['date_last_hotspot_opened']));
224        $_lastBuildDate->appendChild($_textNode);
225
226        // generator
227        $_generator = $this->_xmldoc->createElement("generator");
228        $_channel->appendChild($_generator);
229        $_textNode = $this->_xmldoc->createTextNode(WIFIDOG_NAME . " " . WIFIDOG_VERSION);
230        $_generator->appendChild($_textNode);
231
232        // docs
233        $_docs = $this->_xmldoc->createElement("docs");
234        $_channel->appendChild($_docs);
235        $_textNode = $this->_xmldoc->createTextNode("http://blogs.law.harvard.edu/tech/rss");
236        $_docs->appendChild($_textNode);
237
238        // image
239        /*if (defined('NETWORK_LOGO_NAME') && file_exists(WIFIDOG_ABS_FILE_PATH . "local_content/common/" . constant('NETWORK_LOGO_NAME'))) {
240            $_image = $this->_xmldoc->createElement("image");
241            $_channel->appendChild($_image);
242
243            // title
244            $_title = $this->_xmldoc->createElement("title");
245            $_image->appendChild($_title);
246            $_textNode = $this->_xmldoc->createTextNode($this->_network->getName() . ": " . _("Newest Hotspots"));
247            $_title->appendChild($_textNode);
248
249            // url
250            $_url = $this->_xmldoc->createElement("url");
251            $_image->appendChild($_url);
252            $_textNode = $this->_xmldoc->createTextNode(COMMON_CONTENT_URL . NETWORK_LOGO_NAME);
253            $_url->appendChild($_textNode);
254
255            // link
256            $_link = $this->_xmldoc->createElement("link");
257            $_image->appendChild($_link);
258            $_textNode = $this->_xmldoc->createTextNode($this->_network->getWebSiteURL());
259            $_link->appendChild($_textNode);
260
261            $_imageSize = @getimagesize(WIFIDOG_ABS_FILE_PATH . "local_content/common/" . NETWORK_LOGO_NAME);
262
263            if ($_imageSize) {
264                // width
265                $_width = $this->_xmldoc->createElement("width");
266                $_image->appendChild($_width);
267                $_textNode = $this->_xmldoc->createTextNode($_imageSize[0]);
268                $_width->appendChild($_textNode);
269
270                // height
271                $_height = $this->_xmldoc->createElement("height");
272                $_image->appendChild($_height);
273                $_textNode = $this->_xmldoc->createTextNode($_imageSize[1]);
274                $_height->appendChild($_textNode);
275            }
276
277            // description
278            $_description = $this->_xmldoc->createElement("description");
279            $_image->appendChild($_description);
280            $_textNode = $this->_xmldoc->createTextNode(_("List of the most recent Hotspots opened by the network: ") . $this->_network->getName());
281            $_description->appendChild($_textNode);
282        }*/
283
284        // Node details
285        if ($this->_nodes) {
286            foreach ($this->_nodes as $_nodeData) {
287                $_node = Node::getObject($_nodeData['node_id']);
288                $this->_network = $_node->getNetwork();
289
290                $_hotspot = $this->_xmldoc->createElement("item");
291                $_hotspot = $_channel->appendChild($_hotspot);
292
293                // Hotspot name
294                $_hotspotName = $this->_xmldoc->createElement("title", htmlspecialchars($_node->getName(), ENT_QUOTES));
295                $_hotspot->appendChild($_hotspotName);
296
297                // Hotspot Website URL
298                if ($_node->getWebSiteURL() != "") {
299                    $_hotspotUrl = $this->_xmldoc->createElement("link", htmlspecialchars($_node->getWebSiteURL(), ENT_QUOTES));
300                    $_hotspot->appendChild($_hotspotUrl);
301                }
302
303                // Hotspot name
304                $_hotspotDesc = $this->_xmldoc->createElement("description");
305                $_hotspot->appendChild($_hotspotDesc);
306
307                $_descriptionText = '<p>';
308
309                // Hotspot global status
310                if ($_node->getDeploymentStatus() != 'NON_WIFIDOG_NODE') {
311                    if ($_nodeData['is_up'] == 't') {
312                        $_descriptionText .= "<img src='" . COMMON_IMAGES_URL . "HotspotStatus/up.gif' alt='up' />";
313                    } else {
314                        $_descriptionText .= "<img src='" . COMMON_IMAGES_URL . "HotspotStatus/down.gif' alt='down' />";
315                    }
316                }
317
318                // Description
319                if ($_node->getDescription() != "") {
320                    $_descriptionText .= htmlspecialchars($_node->getDescription(), ENT_QUOTES);
321                }
322                $_descriptionText .= '</p>';
323                $_descriptionText .= '<p>';
324                $_descriptionText .= _("Address") . ": ";
325
326                // Civic number
327                if ($_node->getCivicNumber() != "") {
328                    $_descriptionText .= $_node->getCivicNumber() . ", ";
329                }
330
331                // Street address
332                if ($_node->getStreetName() != "") {
333                    $_descriptionText .= htmlspecialchars($_node->getStreetName(), ENT_QUOTES) . ", ";
334                }
335
336                // City
337                if ($_node->getCity() != "") {
338                    $_descriptionText .= htmlspecialchars($_node->getCity(), ENT_QUOTES) . ", ";
339                }
340
341                // Province
342                if ($_node->getProvince() != "") {
343                    $_descriptionText .= htmlspecialchars($_node->getProvince(), ENT_QUOTES) . ", ";
344                }
345
346                // Postal code
347                if ($_node->getPostalCode() != "") {
348                    $_descriptionText .= $_node->getPostalCode() . ", ";
349                }
350
351                // Country
352                if ($_node->getCountry() != "") {
353                    $_descriptionText .= htmlspecialchars($_node->getCountry(), ENT_QUOTES);
354                }
355
356                // Map Url
357                if ($_node->getMapURL() != "") {
358                    $_descriptionText .= " <a href='" . $_node->getMapURL() . "'>" . _("See Map") . "</a>";
359                }
360
361                // Mass transit info
362                if ($_node->getTransitInfo() != "") {
363                    $_descriptionText .= "<br />";
364                    $_descriptionText .= htmlspecialchars($_node->getTransitInfo(), ENT_QUOTES);
365                }
366
367                $_descriptionText .= "</p>";
368
369                if (($_node->getEmail() != "") || ($_node->getTelephone() != "")) {
370                    $_descriptionText .= "<p>";
371                    $_descriptionText .= _("Contact") . ": ";
372
373                    // Contact e-mail
374                    if ($_node->getEmail() != "") {
375                        $_descriptionText .= "<br /><a href='mailto:" . $_node->getEmail() . "'>" . $_node->getEmail() . "</a>";
376                    }
377
378                    // Contact phone
379                    if ($_node->getTelephone() != "") {
380                        $_descriptionText .= "<br />" . $_node->getTelephone();
381                    }
382
383                    $_descriptionText .= "</p>";
384                }
385
386                $_hotspotDesc->appendChild($this->_xmldoc->createTextNode($_descriptionText));
387
388                // guid
389                if ($_node->getWebSiteURL() != "") {
390                    $_guid = $this->_xmldoc->createElement("guid");
391                    $_guid->setAttribute('isPermaLink', 'false');
392                    $_hotspot->appendChild($_guid);
393                    $_textNode = $this->_xmldoc->createTextNode(htmlspecialchars($_node->getWebSiteURL(), ENT_QUOTES));
394                    $_guid->appendChild($_textNode);
395                }
396
397                // pubDate
398                $_hotspotOpeningDate = $this->_xmldoc->createElement("pubDate", gmdate("D, d M Y H:i:s \G\M\T", $_nodeData['creation_date_epoch']));
399                $_hotspot->appendChild($_hotspotOpeningDate);
400            }
401        }
402
403        echo $this->_xmldoc->saveXML();
404    }
405
406}
407
408/*
409 * Local variables:
410 * tab-width: 4
411 * c-basic-offset: 4
412 * c-hanging-comment-ender-p: nil
413 * End:
414 */
415
Note: See TracBrowser for help on using the browser.