root/trunk/wifidog-auth/wifidog/hotspot_status.php @ 678

Revision 678, 27.3 KB (checked in by fproulx, 8 years ago)

2005-07-25 Francois Proulx <francois.proulx@…>

  • Fixed bug in hotspot_status , added htmlspecialchars();
  • This solved the bug where ampersands would break the XML
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2
3/********************************************************************\
4 * This program is free software; you can redistribute it and/or    *
5 * modify it under the terms of the GNU General Public License as   *
6 * published by the Free Software Foundation; either version 2 of   *
7 * the License, or (at your option) any later version.              *
8 *                                                                  *
9 * This program is distributed in the hope that it will be useful,  *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
12 * GNU General Public License for more details.                     *
13 *                                                                  *
14 * You should have received a copy of the GNU General Public License*
15 * along with this program; if not, contact:                        *
16 *                                                                  *
17 * Free Software Foundation           Voice:  +1-617-542-5942       *
18 * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
19 * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
20 *                                                                  *
21 \********************************************************************/
22/**@file hotspot_status.php
23 * Network status page
24 * @author Copyright (C) 2004, 2005 Benoit Grégoire and François Proulx
25 */
26
27define('BASEPATH', './');
28require_once BASEPATH.'include/common.php';
29require_once BASEPATH.'include/common_interface.php';
30
31if (!empty ($_REQUEST['format']))
32        $format = $_REQUEST['format'];
33else
34        $format = null;
35
36$db->ExecSql("SELECT *, (NOW()-last_heartbeat_timestamp) AS since_last_heartbeat, EXTRACT(epoch FROM creation_date) as creation_date_epoch, CASE WHEN ((NOW()-last_heartbeat_timestamp) < interval '5 minutes') THEN true ELSE false END AS is_up FROM nodes WHERE node_deployment_status = 'DEPLOYED' OR node_deployment_status = 'NON_WIFIDOG_NODE' ORDER BY creation_date", $node_results, false);
37switch ($format)
38{
39        // XML format v1.0 by François proulx <francois.proulx@gmail.com>
40        case "XML":
41                require_once BASEPATH.'classes/Network.php';
42                require_once BASEPATH.'classes/Node.php';
43               
44                header("Cache-control: private, no-cache, must-revalidate");
45                header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); # Past date
46                header("Pragma: no-cache");
47               
48                ob_start();
49               
50                // Prepare an XML DOM Document that will contain all the data concerning the nodes
51                $xmldoc = new DOMDocument();
52                $xmldoc->formatOutput = true;
53               
54                // Root node
55                $hotspot_status_root_node = $xmldoc->createElement("wifidogHotspotsStatus");
56                $hotspot_status_root_node->setAttribute('version', '1.0');
57                $xmldoc->appendChild($hotspot_status_root_node);
58               
59                // Document metadata
60                $document_gendate_node = $xmldoc->createElement("generationDateTime", gmdate("Y-m-d\Th:m:s\Z"));
61                $hotspot_status_root_node->appendChild($document_gendate_node);
62               
63                // Network metadata
64                $network_metadata_node = $xmldoc->createElement("networkMetadata");
65                $network_metadata_node = $hotspot_status_root_node->appendChild($network_metadata_node);
66                $network_name_node = $xmldoc->createElement("networkUri", htmlspecialchars(HOTSPOT_NETWORK_URL, ENT_QUOTES));
67                $network_metadata_node->appendChild($network_name_node);
68                $network_name_node = $xmldoc->createElement("name", htmlspecialchars(HOTSPOT_NETWORK_NAME, ENT_QUOTES));
69                $network_metadata_node->appendChild($network_name_node);
70                $network_url_node = $xmldoc->createElement("websiteUrl", htmlspecialchars(HOTSPOT_NETWORK_URL, ENT_QUOTES));
71                $network_metadata_node->appendChild($network_url_node);
72                $network_mail_node = $xmldoc->createElement("techSupportEmail", TECH_SUPPORT_EMAIL);
73                $network_metadata_node->appendChild($network_mail_node);
74                $nodes_count_node = $xmldoc->createElement("hotspotsCount", count($node_results));
75                $network_metadata_node->appendChild($nodes_count_node);
76                $network_validusers_node = $xmldoc->createElement("validSubscribedUsersCount", $stats->getNumValidUsers());
77                $network_metadata_node->appendChild($network_validusers_node);
78               
79                // Get number of online users
80                $online_users_count = $stats->getNumOnlineUsers($node_id = null);
81                $network_onlineusers_node = $xmldoc->createElement("onlineUsersCount", $online_users_count);
82                $network_metadata_node->appendChild($network_onlineusers_node);
83               
84                if ($node_results)
85                {
86                        // Hotspots metadata
87                        $hotspots_metadata_node = $xmldoc->createElement("hotspots");
88                        $hotspots_metadata_node = $hotspot_status_root_node->appendChild($hotspots_metadata_node);
89                       
90                        foreach ($node_results as $node_row)
91                        {
92                                $hotspot = $xmldoc->createElement("hotspot");
93                                $hotspot = $hotspots_metadata_node->appendChild($hotspot);
94                               
95                                // Hotspot ID
96                                $id = $xmldoc->createElement("hotspotId", $node_row['node_id']);
97                                $hotspot->appendChild($id);
98                               
99                                // Hotspot name
100                                if (!empty ($node_row['name']))
101                                {
102                                        $name = $xmldoc->createElement("name", htmlspecialchars($node_row['name'], ENT_QUOTES));
103                                        $hotspot->appendChild($name);
104                                }
105                               
106                                // (1..n) A Hotspot has many node
107                                // WARNING For now, we are simply duplicating the hotspot data in node
108                                // Until wifidog implements full abstractiong hotspot vs nodes
109                                $nodes = $xmldoc->createElement("nodes");
110                                $hotspot->appendChild($nodes);
111                                if($nodes)
112                                {
113                                        $node = $xmldoc->createElement("node");
114                                        $nodes->appendChild($node);
115                                       
116                                        // Node ID
117                                        $nodeId = $xmldoc->createElement("nodeId", $node_row['node_id']);
118                                        $node->appendChild($nodeId);
119                                       
120                                        if (!empty ($node_row['creation_date']))
121                                        {
122                                                $creation_date = $xmldoc->createElement("creationDate", $node_row['creation_date']);
123                                                $node->appendChild($creation_date);
124                                        }
125                                       
126                                        if (!empty ($node_row['node_deployment_status']) && $node_row['node_deployment_status'] != 'NON_WIFIDOG_NODE')
127                                        {
128                                                if ($node_row['is_up'] == 't')
129                                                        $status = $xmldoc->createElement("status", "up");
130                                                else
131                                                        $status = $xmldoc->createElement("status", "down");
132                                                $node->appendChild($status);
133                                        }
134                                       
135                                        if (!empty ($node_row['longitude']) && !empty ($node_row['latitude']))
136                                        {
137                                                $gis = $xmldoc->createElement("gisLatLong");
138                                                $gis->setAttribute("lat",  $node_row['latitude']);
139                                                $gis->setAttribute("long",  $node_row['longitude']);
140                                                $node->appendChild($gis);
141                                        }
142                                }
143                               
144                                // Hotspot opening date ( for now it's called creation_date )
145                                if (!empty ($node_row['creation_date']))
146                                {
147                                        $opening_date = $xmldoc->createElement("openingDate", $node_row['creation_date']);
148                                        $hotspot->appendChild($opening_date);
149                                }
150
151                                // Hotspot Website URL
152                                if (!empty ($node_row['home_page_url']))
153                                {
154                                        $url = $xmldoc->createElement("webSiteUrl", htmlspecialchars($node_row['home_page_url'], ENT_QUOTES));
155                                        $hotspot->appendChild($url);
156                                }
157                               
158                                // Hotspot global status
159                                if (!empty ($node_row['node_deployment_status']) && $node_row['node_deployment_status'] != 'NON_WIFIDOG_NODE')
160                                {
161                                        // Until we implement the complete node / hotspot paradigm,
162                                        // we are simply stating that up = 100% and down = 0%
163                                        if ($node_row['is_up'] == 't')
164                                                $status = $xmldoc->createElement("globalStatus", "100");
165                                        else
166                                                $status = $xmldoc->createElement("globalStatus", "0");
167                                        $hotspot->appendChild($status);
168                                }
169                               
170                                // Description
171                                if (!empty ($node_row['description']))
172                                {
173                                        $desc = $xmldoc->createElement("description", htmlspecialchars($node_row['description'], ENT_QUOTES));
174                                        $hotspot->appendChild($desc);
175                                }
176
177                                // Map Url
178                                if (!empty ($node_row['map_url']))
179                                {
180                                        $map_url = $xmldoc->createElement("mapUrl", htmlspecialchars($node_row['map_url'], ENT_QUOTES));
181                                        $hotspot->appendChild($map_url);
182                                }
183                               
184                                // Mass transit info
185                                if (!empty ($node_row['mass_transit_info']))
186                                {
187                                        $transit = $xmldoc->createElement("massTransitInfo", htmlspecialchars($node_row['mass_transit_info'], ENT_QUOTES));
188                                        $hotspot->appendChild($transit);
189                                }
190                               
191                                // Contact e-mail
192                                if (!empty ($node_row['public_email']))
193                                {
194                                        $contact_email = $xmldoc->createElement("contactEmail", $node_row['public_email']);
195                                        $hotspot->appendChild($contact_email);
196                                }
197                               
198                                // Contact phone
199                                if (!empty ($node_row['public_phone_number']))
200                                {
201                                        $contact_phone = $xmldoc->createElement("contactPhoneNumber", $node_row['public_phone_number']);
202                                        $hotspot->appendChild($contact_phone);
203                                }
204                               
205                                // Street address
206                                if (!empty ($node_row['street_address']))
207                                {
208                                        $street_addr = $xmldoc->createElement("streetAddress", $node_row['street_address']);
209                                        $hotspot->appendChild($street_addr);
210                                }
211                               
212                                // Long / Lat
213                                if (!empty ($node_row['longitude']) && !empty ($node_row['latitude']))
214                                {
215                                        $gisCenter = $xmldoc->createElement("gisCenterLatLong");
216                                        $gisCenter->setAttribute("lat",  $node_row['latitude']);
217                                        $gisCenter->setAttribute("long",  $node_row['longitude']);
218                                        $hotspot->appendChild($gisCenter);
219                                }
220                        }
221                }
222               
223                ob_clean();
224               
225                // If a XSL transform stylesheet has been specified, try to us it.
226                if(defined('XSLT_SUPPORT') && XSLT_SUPPORT == true && !empty($_REQUEST['xslt']) && ($xslt_dom = @DomDocument::load($_REQUEST['xslt'])) !== false)
227                {
228                        // Load the XSLT
229                        $xslt_proc = new XsltProcessor();
230                        $xslt_proc->importStyleSheet($xslt_dom);
231                       
232                        // Prepare HTML
233                        header("Content-Type: text/html; charset=UTF-8");
234                        echo $xslt_proc->transformToXML($xmldoc);
235                }
236                else
237                {
238                        header("Content-Type: text/xml; charset=UTF-8");
239                        echo $xmldoc->saveXML();
240                }
241               
242                break;
243        case "RSS" :
244                Header("Cache-control: private, no-cache, must-revalidate");
245                Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); # Past date
246                Header("Pragma: no-cache");
247                Header("Content-Type: text/xml; charset=UTF-8");
248
249                $xmldoc = new DOMDocument();
250                $xmldoc->formatOutput = true;
251                //$xmldoc->encoding="iso-8859-15";
252                $rss = $xmldoc->createElement("rss");
253                $xmldoc->appendChild($rss);
254                $rss->setAttribute('version', '2.0');
255
256                /* channel */
257                $channel = $xmldoc->createElement("channel");
258                $rss->appendChild($channel);
259
260                /**************** Required channel elements ********************/
261                /* title */
262                $title = $xmldoc->createElement("title");
263                $title = $channel->appendChild($title);
264
265                $textnode = $xmldoc->createTextNode(HOTSPOT_NETWORK_NAME._(": Newest HotSpots"));
266                $title->appendChild($textnode);
267
268                /* link */
269                $link = $xmldoc->createElement("link");
270                $channel->appendChild($link);
271                $textnode = $xmldoc->createTextNode(HOTSPOT_NETWORK_URL);
272                $link->appendChild($textnode);
273
274                /* description */
275                $description = $xmldoc->createElement("description");
276                $channel->appendChild($description);
277                $textnode = $xmldoc->createTextNode(_("WiFiDog list of the most recent HotSpots opened by the network: ").HOTSPOT_NETWORK_NAME);
278                $description->appendChild($textnode);
279
280                /****************** Optional channel elements *******************/
281                /* language */
282                /**@todo Make language selectable */
283                $language = $xmldoc->createElement("language");
284                $channel->appendChild($language);
285                $textnode = $xmldoc->createTextNode("en-CA");
286                $language->appendChild($textnode);
287
288                /* copyright */
289                $copyright = $xmldoc->createElement("copyright");
290                $channel->appendChild($copyright);
291                $textnode = $xmldoc->createTextNode(_("Copyright ").HOTSPOT_NETWORK_NAME);
292                $copyright->appendChild($textnode);
293
294                /* managingEditor */
295
296                /* webMaster */
297
298                $webMaster = $xmldoc->createElement("webMaster");
299                $channel->appendChild($webMaster);
300                $textnode = $xmldoc->createTextNode(TECH_SUPPORT_EMAIL);
301                $webMaster->appendChild($textnode);
302
303                /* pubDate */
304                $pubDate = $xmldoc->createElement("pubDate");
305                $channel->appendChild($pubDate);
306                $textnode = $xmldoc->createTextNode(gmdate("D, d M Y H:i:s \G\M\T", time()));
307                $pubDate->appendChild($textnode);
308
309                /* lastBuildDate */
310                //<lastBuildDate> -- The date-time the last time the content of the channel changed.
311                /* Make a request through the database for the latest modification date of an object. 
312                 * Maybe it should be an object property? */
313                $db->ExecSqlUniqueRes("SELECT EXTRACT(epoch FROM MAX(creation_date)) as date_last_hotspot_opened FROM nodes WHERE node_deployment_status = 'DEPLOYED' OR node_deployment_status = 'NON_WIFIDOG_NODE' ", $last_hotspot_row, false);
314
315                $lastBuildDate = $xmldoc->createElement("lastBuildDate");
316                $channel->appendChild($lastBuildDate);
317                $textnode = $xmldoc->createTextNode(gmdate("D, d M Y H:i:s \G\M\T", $last_hotspot_row['date_last_hotspot_opened']));
318                $lastBuildDate->appendChild($textnode);
319
320                /* category */
321                /* Specify one or more categories that the channel belongs to.
322                 *  Follows the same rules as the <item>-level category element.*/
323
324                /* generator */
325                $generator = $xmldoc->createElement("generator");
326                $channel->appendChild($generator);
327                $textnode = $xmldoc->createTextNode(WIFIDOG_NAME." ".WIFIDOG_VERSION);
328                $generator->appendChild($textnode);
329
330                /* docs */
331                $docs = $xmldoc->createElement("docs");
332                $channel->appendChild($docs);
333                $textnode = $xmldoc->createTextNode("http://blogs.law.harvard.edu/tech/rss");
334                $docs->appendChild($textnode);
335
336                /* cloud */
337                /* Allows processes to register with a cloud to be notified of updates to the channel, implementing a lightweight publish-subscribe protocol for RSS feeds.*/
338
339                /* ttl */
340                /* ttl stands for time to live. It's a number of minutes that indicates how long a channel can be cached before refreshing from the source.*/
341
342                /* image */
343                $image = $xmldoc->createElement("image");
344                $channel->appendChild($image);
345
346                /* title */
347                $title = $xmldoc->createElement("title");
348                $image->appendChild($title);
349                $textnode = $xmldoc->createTextNode(HOTSPOT_NETWORK_NAME);
350                $title->appendChild($textnode);
351                /* url */
352                $url = $xmldoc->createElement("url");
353                $image->appendChild($url);
354                $textnode = $xmldoc->createTextNode(COMMON_CONTENT_URL.NETWORK_LOGO_NAME);
355                $url->appendChild($textnode);
356                /* link */
357                $link = $xmldoc->createElement("link");
358                $image->appendChild($link);
359                $textnode = $xmldoc->createTextNode(HOTSPOT_NETWORK_URL);
360                $link->appendChild($textnode);
361                /* width */
362                /*
363                 $width = $xmldoc->createElement("width");
364                 $image->appendChild($width);
365                 $textnode = $xmldoc->createTextNode('135');
366                 $width->appendChild($textnode);
367                */
368                /* height */
369                /*
370                 $height = $xmldoc->createElement("height");
371                 $image->appendChild($height);
372                 $textnode = $xmldoc->createTextNode('109');
373                 $height->appendChild($textnode);
374                */
375                /* description */
376                /*
377                 $description = $xmldoc->createElement("description");
378                 $image->appendChild($description);
379                 $textnode = $xmldoc->createTextNode("Le portail des TIC");
380                 $description->appendChild($textnode);
381                */
382
383                /* rating */
384                /* textInput */
385                /* skipHours */
386                /* skipDays */
387
388                $i = 0;
389
390                if ($node_results)
391                        foreach ($node_results as $node_row)
392                        {
393
394                                $item = $xmldoc->createElement("item");
395                                $item = $channel->appendChild($item);
396
397                                /* title */
398                                /* lom_1_2_title_langstrings_id */
399                                $title = $xmldoc->createElement("title");
400                                $item->appendChild($title);
401                                $title_str = $node_row['name'];
402                                $textnode = $xmldoc->createTextNode($title_str);
403                                $title->appendChild($textnode);
404
405                                /* link */
406                                if (!empty ($node_row['home_page_url']))
407                                {
408                                        $link = $xmldoc->createElement("link");
409                                        $item->appendChild($link);
410                                        $textnode = $xmldoc->createTextNode($node_row['home_page_url']);
411                                        $link->appendChild($textnode);
412                                }
413
414                                /* description */
415                                $description = $xmldoc->createElement("description");
416                                $item->appendChild($description);
417                                $description_text = '<p>';
418
419                                if ($node_row['node_deployment_status'] != 'NON_WIFIDOG_NODE')
420                                {
421                                        if ($node_row['is_up'] == 't')
422                                        {
423                                                $description_text .= "<img src='".BASE_URL_PATH."images/hotspot_status_up.png'> ";
424                                        }
425                                        else
426                                        {
427                                                $description_text .= "<img src='".BASE_URL_PATH."images/hotspot_status_down.png'> ";
428                                        }
429                                }
430
431                                if (!empty ($node_row['description']))
432                                {
433                                        $description_text .= $node_row['description'];
434                                }
435                                $description_text .= "</p>\n";
436                                $description_text .= "<p>\n";
437                                if (!empty ($node_row['street_address']))
438                                {
439                                        $description_text .= ""._("Address:")." ".$node_row['street_address']." ";
440                                }
441                                if (!empty ($node_row['map_url']))
442                                {
443                                        $description_text .= " <a href='".$node_row['map_url']."'>"._("See Map")."</a> ";
444                                }
445                                $description_text .= "<br/>\n";
446                                if (!empty ($node_row['mass_transit_info']))
447                                {
448                                        $description_text .= ""._("Mass transit:")." ".$node_row['mass_transit_info']."<br/>\n";
449                                }
450                                $description_text .= "</p>\n";
451                                if (!empty ($node_row['public_email']) || !empty ($node_row['public_phone_number']))
452                                {
453                                        $description_text .= "<p>"._("Contact:");
454
455                                        if (!empty ($node_row['public_phone_number']))
456                                        {
457                                                $description_text .= " $node_row[public_phone_number] ";
458                                        }
459                                        if (!empty ($node_row['public_email']))
460                                        {
461                                                $description_text .= " <a href='".$node_row['public_email']."'>$node_row[public_email]</a> ";
462                                        }
463                                        $description_text .= "</p>\n";
464                                }
465                                $textnode = $xmldoc->createTextNode($description_text);
466                                $description->appendChild($textnode);
467
468                                /* author */
469                                /*
470                                 $author = $xmldoc->createElement("author");
471                                 $item->appendChild($author);
472                                 $textnode = $xmldoc->createTextNode($author_vcard->GetEmail().' ('.$author_vcard->GetName().')');
473                                 $author->appendChild($textnode);
474                                */
475                                /* category */
476
477                                /* comments */
478                                /** Link to page once page is available **/
479                                /* enclosure */
480                                /* guid */
481
482                                $guid = $xmldoc->createElement("guid");
483                                $guid->setAttribute('isPermaLink', 'false');
484                                $item->appendChild($guid);
485                                $textnode = $xmldoc->createTextNode(HOTSPOT_NETWORK_URL.$node_row['node_id']);
486                                $guid->appendChild($textnode);
487
488                                /* pubDate */
489                                $pubDate = $xmldoc->createElement("pubDate");
490                                $item->appendChild($pubDate);
491                                $textnode = $xmldoc->createTextNode(gmdate("D, d M Y H:i:s \G\M\T", $node_row['creation_date_epoch']));
492                                $pubDate->appendChild($textnode);
493
494                                /* source */
495                        }
496                @ ob_clean();
497                echo $xmldoc->saveXML();
498                break;
499        case "WIFI411_CSV" :
500                /* Header("Cache-control: private, no-cache, must-revalidate");
501                 Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); # Past date
502                 Header("Pragma: no-cache");
503                 Header("Content-Type: text/xml; charset=UTF-8");*/
504
505                $xmldoc = new DOMDocument();
506                $xmldoc->formatOutput = true;
507                //$xmldoc->encoding="iso-8859-15";
508                $rss = $xmldoc->createElement("rss");
509                $xmldoc->appendChild($rss);
510                $rss->setAttribute('version', '2.0');
511
512                /* channel */
513                $channel = $xmldoc->createElement("channel");
514                $rss->appendChild($channel);
515
516                /**************** Required channel elements ********************/
517                /* title */
518                $title = $xmldoc->createElement("title");
519                $title = $channel->appendChild($title);
520
521                $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_NAME._(": Newest HotSpots")));
522                $title->appendChild($textnode);
523
524                /* link */
525                $link = $xmldoc->createElement("link");
526                $channel->appendChild($link);
527                $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_URL));
528                $link->appendChild($textnode);
529
530                /* description */
531                $description = $xmldoc->createElement("description");
532                $channel->appendChild($description);
533                $textnode = $xmldoc->createTextNode(utf8_encode(_("WiFiDog list of the most recent HotSpots opened by the network: ").HOTSPOT_NETWORK_NAME));
534                $description->appendChild($textnode);
535
536                /****************** Optional channel elements *******************/
537                /* language */
538                /**@todo Make language selectable */
539                $language = $xmldoc->createElement("language");
540                $channel->appendChild($language);
541                $textnode = $xmldoc->createTextNode("en-CA");
542                $language->appendChild($textnode);
543
544                /* copyright */
545                $copyright = $xmldoc->createElement("copyright");
546                $channel->appendChild($copyright);
547                $textnode = $xmldoc->createTextNode(utf8_encode(_("Copyright ").HOTSPOT_NETWORK_NAME));
548                $copyright->appendChild($textnode);
549
550                /* managingEditor */
551
552                /* webMaster */
553
554                $webMaster = $xmldoc->createElement("webMaster");
555                $channel->appendChild($webMaster);
556                $textnode = $xmldoc->createTextNode(utf8_encode(TECH_SUPPORT_EMAIL));
557                $webMaster->appendChild($textnode);
558
559                /* pubDate */
560                $pubDate = $xmldoc->createElement("pubDate");
561                $channel->appendChild($pubDate);
562                $textnode = $xmldoc->createTextNode(utf8_encode(gmdate("D, d M Y H:i:s \G\M\T", time())));
563                $pubDate->appendChild($textnode);
564
565                /* lastBuildDate */
566                //<lastBuildDate> -- The date-time the last time the content of the channel changed.
567                /* Make a request through the database for the latest modification date of an object. 
568                 * Maybe it should be an object property? */
569                $db->ExecSqlUniqueRes("SELECT EXTRACT(epoch FROM MAX(creation_date)) as date_last_hotspot_opened FROM nodes WHERE node_deployment_status = 'DEPLOYED' OR node_deployment_status = 'NON_WIFIDOG_NODE' ", $last_hotspot_row, false);
570
571                $lastBuildDate = $xmldoc->createElement("lastBuildDate");
572                $channel->appendChild($lastBuildDate);
573                $textnode = $xmldoc->createTextNode(gmdate("D, d M Y H:i:s \G\M\T", $last_hotspot_row['date_last_hotspot_opened']));
574                $lastBuildDate->appendChild($textnode);
575
576                /* category */
577                /* Specify one or more categories that the channel belongs to.
578                 *  Follows the same rules as the <item>-level category element.*/
579
580                /* generator */
581                $generator = $xmldoc->createElement("generator");
582                $channel->appendChild($generator);
583                $textnode = $xmldoc->createTextNode(utf8_encode(WIFIDOG_NAME." ".WIFIDOG_VERSION));
584                $generator->appendChild($textnode);
585
586                /* docs */
587                $docs = $xmldoc->createElement("docs");
588                $channel->appendChild($docs);
589                $textnode = $xmldoc->createTextNode(utf8_encode("http://blogs.law.harvard.edu/tech/rss"));
590                $docs->appendChild($textnode);
591
592                /* cloud */
593                /* Allows processes to register with a cloud to be notified of updates to the channel, implementing a lightweight publish-subscribe protocol for RSS feeds.*/
594
595                /* ttl */
596                /* ttl stands for time to live. It's a number of minutes that indicates how long a channel can be cached before refreshing from the source.*/
597
598                /* image */
599                $image = $xmldoc->createElement("image");
600                $channel->appendChild($image);
601
602                /* title */
603                $title = $xmldoc->createElement("title");
604                $image->appendChild($title);
605                $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_NAME));
606                $title->appendChild($textnode);
607                /* url */
608                $url = $xmldoc->createElement("url");
609                $image->appendChild($url);
610                $textnode = $xmldoc->createTextNode(utf8_encode(COMMON_CONTENT_URL.NETWORK_LOGO_NAME));
611                $url->appendChild($textnode);
612                /* link */
613                $link = $xmldoc->createElement("link");
614                $image->appendChild($link);
615                $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_URL));
616                $link->appendChild($textnode);
617                /* width */
618                /*
619                 $width = $xmldoc->createElement("width");
620                 $image->appendChild($width);
621                 $textnode = $xmldoc->createTextNode('135');
622                 $width->appendChild($textnode);
623                */
624                /* height */
625                /*
626                 $height = $xmldoc->createElement("height");
627                 $image->appendChild($height);
628                 $textnode = $xmldoc->createTextNode('109');
629                 $height->appendChild($textnode);
630                */
631                /* description */
632                /*
633                 $description = $xmldoc->createElement("description");
634                 $image->appendChild($description);
635                 $textnode = $xmldoc->createTextNode("Le portail des TIC");
636                 $description->appendChild($textnode);
637                */
638
639                /* rating */
640                /* textInput */
641                /* skipHours */
642                /* skipDays */
643
644                $i = 0;
645
646                if ($node_results)
647                        foreach ($node_results as $node_row)
648                        {
649
650                                $item = $xmldoc->createElement("item");
651                                $item = $channel->appendChild($item);
652
653                                /* title */
654                                /* lom_1_2_title_langstrings_id */
655                                $title = $xmldoc->createElement("title");
656                                $item->appendChild($title);
657                                $title_str = $node_row['name'];
658                                $textnode = $xmldoc->createTextNode(utf8_encode($title_str));
659                                $title->appendChild($textnode);
660
661                                /* link */
662                                if (!empty ($node_row['home_page_url']))
663                                {
664                                        $link = $xmldoc->createElement("link");
665                                        $item->appendChild($link);
666                                        $textnode = $xmldoc->createTextNode(utf8_encode($node_row['home_page_url']));
667                                        $link->appendChild($textnode);
668                                }
669
670                                /* description */
671                                $description = $xmldoc->createElement("description");
672                                $item->appendChild($description);
673                                $description_text = '<p>';
674                                if ($node_row['node_deployment_status'] != 'NON_WIFIDOG_NODE')
675                                {
676                                        if ($node_row['is_up'] == 't')
677                                        {
678                                                $description_text .= "<img src='".BASE_URL_PATH."images/hotspot_status_up.png'> ";
679                                        }
680                                        else
681                                        {
682                                                $description_text .= "<img src='".BASE_URL_PATH."images/hotspot_status_down.png'> ";
683                                        }
684                                }
685
686                                if (!empty ($node_row['description']))
687                                {
688                                        $description_text .= $node_row['description'];
689                                }
690                                $description_text .= "</p>\n";
691                                $description_text .= "<p>\n";
692                                if (!empty ($node_row['street_address']))
693                                {
694                                        $description_text .= ""._("Address:")." ".$node_row['street_address']." ";
695                                }
696                                if (!empty ($node_row['map_url']))
697                                {
698                                        $description_text .= " <a href='".$node_row['map_url']."'>"._("See Map")."</a> ";
699                                }
700                                $description_text .= "<br/>\n";
701                                if (!empty ($node_row['mass_transit_info']))
702                                {
703                                        $description_text .= ""._("Mass transit:")." ".$node_row['mass_transit_info']."<br/>\n";
704                                }
705                                $description_text .= "</p>\n";
706                                if (!empty ($node_row['public_email']) || !empty ($node_row['public_phone_number']))
707                                {
708                                        $description_text .= "<p>"._("Contact:");
709
710                                        if (!empty ($node_row['public_phone_number']))
711                                        {
712                                                $description_text .= " $node_row[public_phone_number] ";
713                                        }
714                                        if (!empty ($node_row['public_email']))
715                                        {
716                                                $description_text .= " <a href='".$node_row['public_email']."'>$node_row[public_email]</a> ";
717                                        }
718                                        $description_text .= "</p>\n";
719                                }
720                                $textnode = $xmldoc->createTextNode(utf8_encode($description_text));
721                                $description->appendChild($textnode);
722
723                                /* author */
724                                /*
725                                 $author = $xmldoc->createElement("author");
726                                 $item->appendChild($author);
727                                 $textnode = $xmldoc->createTextNode($author_vcard->GetEmail().' ('.$author_vcard->GetName().')');
728                                 $author->appendChild($textnode);
729                                */
730                                /* category */
731
732                                /* comments */
733                                /** Link to page once page is available **/
734                                /* enclosure */
735                                /* guid */
736
737                                $guid = $xmldoc->createElement("guid");
738                                $guid->setAttribute('isPermaLink', 'false');
739                                $item->appendChild($guid);
740                                $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_URL.$node_row['node_id']));
741                                $guid->appendChild($textnode);
742
743                                /* pubDate */
744                                $pubDate = $xmldoc->createElement("pubDate");
745                                $item->appendChild($pubDate);
746                                $textnode = $xmldoc->createTextNode(utf8_encode(gmdate("D, d M Y H:i:s \G\M\T", $node_row['creation_date_epoch'])));
747                                $pubDate->appendChild($textnode);
748
749                                /* source */
750                        }
751                ob_clean();
752                echo $xmldoc->saveXML();
753                break;
754        default :
755                if ($node_results)
756                        foreach ($node_results as $node_row)
757                        {
758                                $node_row['num_online_users'] = $stats->getNumOnlineUsers($node_row['node_id']);
759                                $smarty->append("nodes", $node_row);
760                        }
761                $smarty->assign("num_deployed_nodes", count($node_results));
762
763                require_once BASEPATH.'classes/MainUI.php';
764               
765                if(defined('GMAPS_HOTSPOTS_MAP_ENABLED') && GMAPS_HOTSPOTS_MAP_ENABLED == true)
766                {
767                        $tool_html = '<p class="indent">'."\n";
768                        $tool_html .= "<ul class='users_list'>\n";
769                        $tool_html .= "<li><a href='".BASE_NON_SSL_PATH."hotspots_map.php'>"._('Deployed HotSpots map')."</a></li>";
770                        $tool_html .= "</ul>\n";
771                        $tool_html .= '</p>'."\n";
772                }
773                else
774                        $tool_html = "";
775               
776                $ui = new MainUI();
777                $ui->setToolContent($tool_html);
778                $ui->setTitle(_("Hotspot list"));
779                $ui->setMainContent($smarty->fetch("templates/hotspot_status.html"));
780                $ui->display();
781}
782?>
Note: See TracBrowser for help on using the browser.