Changeset 421

Show
Ignore:
Timestamp:
01/31/05 22:52:57 (8 years ago)
Author:
benoitg
Message:

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.
Location:
trunk/wifidog-auth
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog-auth/ChangeLog

    r403 r421  
    11# $Header$ 
     22005-01-31 Benoit Gr�goire  <bock@step.polymtl.ca> 
     3        * wifidog/templates/hotspot_status.html:  Restore the number of nodes 
     4        * wifidog/hotspot_status.php: Restore the number of nodes, add formatting and more information to the RSS feed. 
     5 
    262005-01-26 Philippe April <isf_lists@philippeapril.com> 
    37        * Some kind of virtual login (we need to talk about this). 
  • trunk/wifidog-auth/wifidog/hotspot_status.php

    r402 r421  
    2929 
    3030if(!empty($_REQUEST['format'])) { 
    31     $format = $_REQUEST['format']; 
    32 } else { 
    33     $format = null; 
    34 } 
     31  $format = $_REQUEST['format']; 
     32 } else { 
     33  $format = null; 
     34 } 
    3535 
    3636$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); 
    3737 
    3838if ($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 ********************/ 
     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 
    56190    /* title */ 
     191    /* lom_1_2_title_langstrings_id */ 
    57192    $title = $xmldoc->createElement("title"); 
    58     $title = $channel->appendChild($title); 
    59  
    60     $textnode = $xmldoc->createTextNode(utf8_encode(_("Newest")." ".HOTSPOT_NETWORK_NAME. " ". _("Hotspots"))); 
     193    $item->appendChild($title); 
     194    $title_str = $node_row['name']; 
     195    $textnode = $xmldoc->createTextNode(utf8_encode($title_str)); 
    61196    $title->appendChild($textnode); 
    62197 
    63198    /* link */ 
    64     $link = $xmldoc->createElement("link"); 
    65     $channel->appendChild($link); 
    66     $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_URL)); 
    67     $link->appendChild($textnode); 
     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      } 
    68206 
    69207    /* description */ 
    70208    $description = $xmldoc->createElement("description"); 
    71     $channel->appendChild($description); 
    72     $textnode = $xmldoc->createTextNode(utf8_encode(_("WiFiDog list of the most recent HotSpots opened by ").HOTSPOT_NETWORK_NAME)); 
     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)); 
    73258    $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                  
     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    */ 
    115267    /* 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  
    196       if($node_row['is_up']=='t') 
    197       { 
    198       $title_str .= " (Currently Up)"; 
    199       } 
    200       else 
    201       { 
    202             $title_str .= " (Currently Down)"; 
    203       } 
    204       $textnode = $xmldoc->createTextNode(utf8_encode($title_str)); 
    205       $title->appendChild($textnode); 
    206  
    207       /* link */ 
    208       if(!empty($node_row['home_page_url'])) 
    209       { 
    210       $link = $xmldoc->createElement("link"); 
    211       $item->appendChild($link); 
    212       $textnode = $xmldoc->createTextNode(utf8_encode($node_row['home_page_url'])); 
    213       $link->appendChild($textnode); 
    214       } 
    215  
    216       /* description */ 
    217       /* lom_1_4_descriptions_has_langstrings */ 
    218       $description = $xmldoc->createElement("description"); 
    219       $item->appendChild($description); 
    220       $description_text=''; 
    221       if(!empty($node_row['description'])) 
    222       { 
    223           $description_text.=$node_row['description']; 
    224       } 
    225       if(!empty($node_row['street_address'])) 
    226       { 
    227           $description_text.= " "._("Address:")." ".$node_row['street_address']; 
    228       } 
    229       if(!empty($node_row['mass_transit_info'])) 
    230       { 
    231           $description_text.=" "._("Mass transit:")." ".$node_row['mass_transit_info']; 
    232       } 
    233       $textnode = $xmldoc->createTextNode(utf8_encode($description_text)); 
    234       $description->appendChild($textnode); 
    235        
    236       /* author */ 
    237 /* 
    238           $author = $xmldoc->createElement("author"); 
    239           $item->appendChild($author); 
    240           $textnode = $xmldoc->createTextNode($author_vcard->GetEmail().' ('.$author_vcard->GetName().')'); 
    241           $author->appendChild($textnode); 
    242 */ 
    243       /* category */ 
    244  
    245       /* comments */ 
    246       /** Link to page once page is available **/ 
    247       /* enclosure */ 
    248       /* guid */ 
    249  
    250           $guid = $xmldoc->createElement("guid"); 
    251           $guid->setAttribute('isPermaLink', 'false'); 
    252           $item->appendChild($guid); 
    253           $textnode = $xmldoc->createTextNode(utf8_encode(HOTSPOT_NETWORK_URL.$node_row['node_id'])); 
    254           $guid->appendChild($textnode); 
     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); 
    255279 
    256280    /* pubDate */ 
     
    260284    $pubDate->appendChild($textnode); 
    261285 
    262       /* source */ 
    263     } 
    264  
    265     echo $xmldoc->saveXML(); 
    266 } else { 
    267     foreach($node_results as $node_row) { 
    268         $node_row['num_online_users'] = $stats->getNumOnlineUsers($node_row['node_id']); 
    269         $smarty->append("nodes", $node_row); 
    270     } 
    271  
    272     $smarty->assign("title", "hotspot_status"); 
    273     $smarty->display("templates/hotspot_status.html"); 
    274 } 
     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 } 
    275299?> 
  • trunk/wifidog-auth/wifidog/templates/hotspot_status.html

    r384 r421  
    44<thead> 
    55<tr> 
    6     <th colspan=6>Status of the open {$smarty.const.HOTSPOT_NETWORK_NAME} HotSpots (Get this list as a <a href='?format=RSS'>RSS feed</a>)</th> 
     6    <th colspan=6>Status of the {$num_deployed_nodes} open {$smarty.const.HOTSPOT_NETWORK_NAME} HotSpots (Get this list as a <a href='?format=RSS'>RSS feed</a>)</th> 
    77</tr> 
    88<tr>