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

Revision 421, 10.9 KB (checked in by benoitg, 8 years ago)

2005-01-31 Benoit Gr�goire <bock@…>

  • wifidog/templates/hotspot_status.html: Restore the number of nodes
  • wifidog/hotspot_status.php: Restore the number of nodes, add formatting and more information to the RSS feed.
  • 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   * This program is free software; you can redistribute it and/or    *
4   * modify it under the terms of the GNU General Public License as   *
5   * published by the Free Software Foundation; either version 2 of   *
6   * the License, or (at your option) any later version.              *
7   *                                                                  *
8   * This program is distributed in the hope that it will be useful,  *
9   * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
10   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
11   * GNU General Public License for more details.                     *
12   *                                                                  *
13   * You should have received a copy of the GNU General Public License*
14   * along with this program; if not, contact:                        *
15   *                                                                  *
16   * Free Software Foundation           Voice:  +1-617-542-5942       *
17   * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
18   * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
19   *                                                                  *
20   \********************************************************************/
21  /**@file hotspot_status.php
22   * Network status page
23   * @author Copyright (C) 2004 Benoit Gr�goire
24   */
25
26define('BASEPATH','./');
27require_once BASEPATH.'include/common.php';
28require_once BASEPATH.'include/common_interface.php';
29
30if(!empty($_REQUEST['format'])) {
31  $format = $_REQUEST['format'];
32 } else {
33  $format = null;
34 }
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);
37
38if ($format == 'RSS') {
39  Header("Cache-control: private, no-cache, must-revalidate");
40  Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); # Past date
41  Header("Pragma: no-cache");
42  Header("Content-Type: text/xml; charset=UTF-8");
43
44  $xmldoc = new DOMDocument();
45  $xmldoc->formatOutput = true;
46  //$xmldoc->encoding="iso-8859-15";
47  $rss = $xmldoc->createElement("rss");
48  $xmldoc->appendChild($rss);
49  $rss->setAttribute('version', '2.0');
50
51  /* channel */
52  $channel = $xmldoc->createElement("channel");
53  $rss->appendChild($channel);
54
55  /**************** Required channel elements ********************/
56  /* title */
57  $title = $xmldoc->createElement("title");
58  $title = $channel->appendChild($title);
59
60  $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_NAME._(": Newest HotSpots")));
61  $title->appendChild($textnode);
62
63  /* link */
64  $link = $xmldoc->createElement("link");
65  $channel->appendChild($link);
66  $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_URL));
67  $link->appendChild($textnode);
68
69  /* description */
70  $description = $xmldoc->createElement("description");
71  $channel->appendChild($description);
72  $textnode = $xmldoc->createTextNode(utf8_encode(_("WiFiDog list of the most recent HotSpots opened by the network: ").HOTSPOT_NETWORK_NAME));
73  $description->appendChild($textnode);
74
75  /****************** Optional channel elements *******************/
76  /* language */
77  /**@todo Make language selectable */
78  $language = $xmldoc->createElement("language");
79  $channel->appendChild($language);
80  $textnode = $xmldoc->createTextNode("en-CA");
81  $language->appendChild($textnode);
82
83  /* copyright */
84  $copyright = $xmldoc->createElement("copyright");
85  $channel->appendChild($copyright);
86  $textnode = $xmldoc->createTextNode(utf8_encode(_("Copyright ").HOTSPOT_NETWORK_NAME));
87  $copyright->appendChild($textnode);
88
89  /* managingEditor */
90               
91  /* webMaster */
92               
93  $webMaster = $xmldoc->createElement("webMaster");
94  $channel->appendChild($webMaster);
95  $textnode = $xmldoc->createTextNode(utf8_encode(TECH_SUPPORT_EMAIL));
96  $webMaster->appendChild($textnode);
97
98  /* pubDate */
99  $pubDate = $xmldoc->createElement("pubDate");
100  $channel->appendChild($pubDate);
101  $textnode = $xmldoc->createTextNode(utf8_encode(gmdate("D, d M Y H:i:s \G\M\T", time())));
102  $pubDate->appendChild($textnode);
103
104  /* lastBuildDate */
105  //<lastBuildDate> -- The date-time the last time the content of the channel changed.
106  /* Make a request through the database for the latest modification date of an object. 
107   * Maybe it should be an object property? */
108  $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);
109
110  $lastBuildDate = $xmldoc->createElement("lastBuildDate");
111  $channel->appendChild($lastBuildDate);
112  $textnode = $xmldoc->createTextNode(gmdate("D, d M Y H:i:s \G\M\T", $last_hotspot_row['date_last_hotspot_opened']));
113  $lastBuildDate->appendChild($textnode);
114               
115  /* category */
116  /* Specify one or more categories that the channel belongs to.
117   *  Follows the same rules as the <item>-level category element.*/
118                 
119  /* generator */
120  $generator = $xmldoc->createElement("generator");
121  $channel->appendChild($generator);
122  $textnode = $xmldoc->createTextNode(utf8_encode(WIFIDOG_NAME . " " . WIFIDOG_VERSION));
123  $generator->appendChild($textnode);
124               
125  /* docs */
126  $docs = $xmldoc->createElement("docs");
127  $channel->appendChild($docs);
128  $textnode = $xmldoc->createTextNode(utf8_encode("http://blogs.law.harvard.edu/tech/rss"));
129  $docs->appendChild($textnode);
130               
131  /* cloud */
132  /* Allows processes to register with a cloud to be notified of updates to the channel, implementing a lightweight publish-subscribe protocol for RSS feeds.*/
133
134  /* ttl */
135  /* 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.*/
136
137  /* image */
138  $image = $xmldoc->createElement("image");
139  $channel->appendChild($image);
140               
141  /* title */
142  $title = $xmldoc->createElement("title");
143  $image->appendChild($title);
144  $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_NAME));
145  $title->appendChild($textnode);
146  /* url */
147  $url = $xmldoc->createElement("url");
148  $image->appendChild($url);
149  $textnode = $xmldoc->createTextNode(utf8_encode(COMMON_CONTENT_URL.NETWORK_LOGO_NAME));
150  $url->appendChild($textnode);
151  /* link */
152  $link = $xmldoc->createElement("link");
153  $image->appendChild($link);
154  $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_URL));
155  $link->appendChild($textnode);
156  /* width */
157  /*
158   $width = $xmldoc->createElement("width");
159   $image->appendChild($width);
160   $textnode = $xmldoc->createTextNode('135');
161   $width->appendChild($textnode);
162  */
163  /* height */
164  /*
165   $height = $xmldoc->createElement("height");
166   $image->appendChild($height);
167   $textnode = $xmldoc->createTextNode('109');
168   $height->appendChild($textnode);
169  */
170  /* description */
171  /*
172   $description = $xmldoc->createElement("description");
173   $image->appendChild($description);
174   $textnode = $xmldoc->createTextNode("Le portail des TIC");
175   $description->appendChild($textnode);
176  */
177
178  /* rating */
179  /* textInput */
180  /* skipHours */
181  /* skipDays */
182               
183  $i=0;
184
185  foreach($node_results as $node_row) {
186
187    $item = $xmldoc->createElement("item");
188    $item = $channel->appendChild($item);
189
190    /* title */
191    /* lom_1_2_title_langstrings_id */
192    $title = $xmldoc->createElement("title");
193    $item->appendChild($title);
194    $title_str = $node_row['name'];
195    $textnode = $xmldoc->createTextNode(utf8_encode($title_str));
196    $title->appendChild($textnode);
197
198    /* link */
199    if(!empty($node_row['home_page_url']))
200      {
201        $link = $xmldoc->createElement("link");
202        $item->appendChild($link);
203        $textnode = $xmldoc->createTextNode(utf8_encode($node_row['home_page_url']));
204        $link->appendChild($textnode);
205      }
206
207    /* description */
208    $description = $xmldoc->createElement("description");
209    $item->appendChild($description);
210    $description_text='<p>';
211    if($node_row['node_deployment_status'] != 'NON_WIFIDOG_NODE')
212      {
213        if($node_row['is_up']=='t')
214          {
215            $description_text .= "<img src='".BASE_URL_PATH."images/hotspot_status_up.png'> ";
216          }
217        else
218          {
219            $description_text .= "<img src='".BASE_URL_PATH."images/hotspot_status_down.png'> ";
220          }
221      }
222
223    if(!empty($node_row['description']))
224      {
225        $description_text.= $node_row['description'];
226      }
227    $description_text.= "</p>\n";
228    $description_text.="<p>\n";
229    if(!empty($node_row['street_address']))
230      {
231        $description_text.= ""._("Address:")." ".$node_row['street_address']." ";
232      }
233    if(!empty($node_row['map_url']))
234      {
235        $description_text.=" <a href='".$node_row['map_url']."'>"._("See Map")."</a> ";
236      }
237    $description_text.= "<br/>\n";
238    if(!empty($node_row['mass_transit_info']))
239      {
240        $description_text.=""._("Mass transit:")." ".$node_row['mass_transit_info']."<br/>\n";
241      }
242    $description_text.= "</p>\n";
243    if(!empty($node_row['public_email']) || !empty($node_row['public_phone_number']))
244      {
245        $description_text.="<p>"._("Contact:");
246
247        if(!empty($node_row['public_phone_number']))
248          {
249            $description_text.=" $node_row[public_phone_number] ";
250          }
251        if(!empty($node_row['public_email']))
252          {
253            $description_text.=" <a href='".$node_row['public_email']."'>$node_row[public_email]</a> ";
254          }
255        $description_text.="</p>\n";
256      }
257    $textnode = $xmldoc->createTextNode(utf8_encode($description_text));
258    $description->appendChild($textnode);
259     
260    /* author */
261    /*
262     $author = $xmldoc->createElement("author");
263     $item->appendChild($author);
264     $textnode = $xmldoc->createTextNode($author_vcard->GetEmail().' ('.$author_vcard->GetName().')');
265     $author->appendChild($textnode);
266    */
267    /* category */
268
269    /* comments */
270    /** Link to page once page is available **/
271    /* enclosure */
272    /* guid */
273
274    $guid = $xmldoc->createElement("guid");
275    $guid->setAttribute('isPermaLink', 'false');
276    $item->appendChild($guid);
277    $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_URL.$node_row['node_id']));
278    $guid->appendChild($textnode);
279
280    /* pubDate */
281    $pubDate = $xmldoc->createElement("pubDate");
282    $item->appendChild($pubDate);
283    $textnode = $xmldoc->createTextNode(utf8_encode(gmdate("D, d M Y H:i:s \G\M\T", $node_row['creation_date_epoch'])));
284    $pubDate->appendChild($textnode);
285
286    /* source */
287  }
288  ob_clean();
289  echo $xmldoc->saveXML();
290 } else {
291  foreach($node_results as $node_row) {
292    $node_row['num_online_users'] = $stats->getNumOnlineUsers($node_row['node_id']);
293    $smarty->append("nodes", $node_row);
294  }
295  $smarty->assign("num_deployed_nodes", count($node_results));
296  $smarty->assign("title", "hotspot_status");
297  $smarty->display("templates/hotspot_status.html");
298 }
299?>
Note: See TracBrowser for help on using the browser.