Changeset 315

Show
Ignore:
Timestamp:
01/11/05 23:00:06 (8 years ago)
Author:
benoitg
Message:

2004-01-11 Benoit Gr�goire <bock@…>

  • INSTALL: Mandate PHP5
  • wifidog/hotspot_status.php: Allow export of the list as a RSS feed
  • wifidog/classes/RssPressReview.inc: Make it truly functionnal.
  • wifidog/portal/index.php: Support multiple RSS feeds. The system will automatically pick the best 5 entries from all the feeds. It will compensate for disparate publication intervals. An entry from a feed that does not publish often will live longer than an entry from a feed that publishes very often. If a feed doesn't have any entry that makes the cut, it will not appear at all.
  • wifidog/templates/hotspot_status.html: Add link to the RSS version.
Location:
trunk/wifidog-auth
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog-auth/ChangeLog

    r314 r315  
    11# $Header$ 
    2 2004-01-10 Benoit Gr�goire  <bock@step.polymtl.ca> 
     22004-01-11 Benoit Gr�goire  <bock@step.polymtl.ca> 
     3        * INSTALL: Mandate PHP5 
     4        * wifidog/hotspot_status.php: Allow export of the list as a RSS feed 
     5        * wifidog/classes/RssPressReview.inc:  Make it truly functionnal. 
     6        * wifidog/portal/index.php:  Support multiple RSS feeds.  The system will automatically pick the best 5 entries from all the feeds.  It will compensate for disparate publication intervals.  An entry from a feed that does not publish often will live longer than an entry from a feed that publishes very often.  If a feed doesn't have any entry that makes the cut, it will not appear at all. 
     7        * wifidog/templates/hotspot_status.html:  Add link to the RSS version. 
     8 
     92004-01-11 Benoit Gr�goire  <bock@step.polymtl.ca> 
    310        * wifidog/config.php:  Add list of hotspot to network rss feed list (not yet functionnal) 
    411        * wifidog/hotspot_status.php:  Allow RSS export of the list of deployed HotSpots. 
  • trunk/wifidog-auth/INSTALL

    r273 r315  
    11Prerequisites: 
    2 Smarty template engine http://smarty.php.net/ 
    3 magpierss http://magpierss.sourceforge.net/ (Required for RSS support.  RSS support must be manually disabled if you do not insall it) 
    4 php's php-xml extention installed. (Required if RSS support is on) 
    5 php compiled with gettext support (Will be autodetected if unavailable, but you will loose internationalization) 
    6 PostgreSQL (mysql code also exists, but is looking for a maintainer) 
     2-PHP5 
     3-Smarty template engine http://smarty.php.net/ 
     4-Magpierss http://magpierss.sourceforge.net/ (Required for RSS support.  RSS support must be manually disabled if you do not insall it) 
     5-php's php-xml extention installed. (Required if RSS support is on) 
     6-php's dom extension installed. (Required if you want to export the list of HotSpots as a RSS feed) 
     7-php compiled with gettext support (Will be autodetected if unavailable, but you will loose internationalization) 
     8-PostgreSQL (mysql code also exists, but is looking for a maintainer) 
    79 
    810Install files: 
  • trunk/wifidog-auth/wifidog/classes/RssPressReview.inc

    r314 r315  
    7777   @return the date in timestamp format of -1 if unavailable 
    7878  */ 
    79   private function get_item_date ( $item, $debug = 0 ) 
    80   { 
    81     $retval = -1; 
    82     if(!empty($item['dc']['date'])) 
    83       { 
    84         $datestr = $item['dc']['date']; 
    85       } 
    86     else if (!empty($item['pubdate'])) 
    87       { 
    88         $datestr = $item['pubdate']; 
    89       } 
    90     else if (!empty($item['date'])) 
    91       { 
    92         $datestr = $item['date']; 
    93       } 
    94     else if (!empty($item['created'])) 
    95       { 
    96         $datestr = $item['created']; 
    97       } 
    98     else 
    99       { 
    100         if ($debug) 
    101           { 
    102             echo "<p>get_item_date(): No date present!</p>"; 
    103           } 
    104         $datestr = null; 
    105       } 
     79  static private function get_item_date ( $item, $debug = 0 ) 
     80    { 
     81      $retval = -1; 
     82      if(!empty($item['dc']['date'])) 
     83        { 
     84          $datestr = $item['dc']['date']; 
     85        } 
     86      else if (!empty($item['pubdate'])) 
     87        { 
     88          $datestr = $item['pubdate']; 
     89        } 
     90      else if (!empty($item['date'])) 
     91        { 
     92          $datestr = $item['date']; 
     93        } 
     94      else if (!empty($item['created'])) 
     95        { 
     96          $datestr = $item['created']; 
     97        } 
     98      else 
     99        { 
     100          if ($debug) 
     101            { 
     102              echo "<p>get_item_date(): No date present!</p>"; 
     103            } 
     104          $datestr = null; 
     105        } 
    106106                 
    107     if ($datestr==null) 
    108       { 
    109         $retval = -1; 
    110       } 
    111     else 
    112       { 
    113         if ($debug) 
    114           { 
    115             echo "<p>get_item_date(): String to convert: $datestr</p>";  
    116           } 
     107      if ($datestr==null) 
     108        { 
     109          $retval = -1; 
     110        } 
     111      else 
     112        { 
     113          if ($debug) 
     114            { 
     115              echo "<p>get_item_date(): String to convert: $datestr</p>";        
     116            } 
    117117         
    118         $retval = parse_w3cdtf($datestr); 
    119         if($retval == -1) 
    120           { 
    121             $retval = strtotime($datestr); 
    122           } 
     118          $retval = parse_w3cdtf($datestr); 
     119          if($retval == -1) 
     120            { 
     121              $retval = strtotime($datestr); 
     122            } 
    123123                 
    124         if ($debug) 
    125           { 
    126             if ($retval == -1) 
    127               { 
    128                 echo "<p>get_item_date(): Conversion of $datestr failed!</p>";   
    129               } 
    130             else 
    131               { 
    132                 echo "<p>get_item_date(): Conversion succeded</p>";      
    133                 setlocale(LC_TIME, "fr_CA"); 
    134                 echo strftime("%c", $retval); 
    135               } 
    136           } 
    137  
    138       } 
    139     if ($debug) 
    140       { 
    141         echo "<p>get_item_date(): Retval: $retval</p>"; 
    142       } 
    143     return $retval; 
    144  
    145   } 
     124          if ($debug) 
     125            { 
     126              if ($retval == -1) 
     127                { 
     128                  echo "<p>get_item_date(): Conversion of $datestr failed!</p>";         
     129                } 
     130              else 
     131                { 
     132                  echo "<p>get_item_date(): Conversion succeded</p>";    
     133                  setlocale(LC_TIME, "fr_CA"); 
     134                  echo strftime("%c", $retval); 
     135                } 
     136            } 
     137 
     138        } 
     139      if ($debug) 
     140        { 
     141          echo "<p>get_item_date(): Retval: $retval</p>"; 
     142        } 
     143      return $retval; 
     144 
     145    } 
    146146     
    147147  /** Inverted comparaison function for adjusted dates (so that the most recent are first */ 
     
    169169    return $string; 
    170170  } 
     171 
     172  /** This is the static comparing function to sort rss items in chronological order: */ 
     173  static function cmp_date_item($a, $b) 
     174    { 
     175      $a_date=self::get_item_date($a); 
     176      $b_date=self::get_item_date($b); 
     177      if ($a_date == $b_date) { 
     178        return 0; 
     179      } 
     180      /*echo "cmp_date_item(): a:$a_date, b:$b_date "; 
     181       echo ($a_date < $b_date) ? +1 : -1;*/ 
     182      return ($a_date < $b_date) ? +1 : -1; 
     183    } 
     184 
    171185 
    172186  /* 
     
    201215        $publication_interval_total = null; //running total of the difference between the date of the current item and the previous one 
    202216        $average_publication_interval = null; 
    203         $previous_item_date; 
     217        $previous_item_date=null; 
    204218        $rss = fetch_rss( $rss_source['url'] ); 
    205219        if ( !$rss ) 
     
    212226            //$rss->show_channel(); 
    213227            //$rss->show_list(); 
    214                
     228             
     229            /* Sort the array in chronological order */ 
     230 
     231            /*foreach  ($rss->items as $item) {echo "$item[title] ". self::get_item_date($item) . "<br>\n";}*/ 
     232            if(!uasort($rss->items, array("RssPressReview","cmp_date_item"))) 
     233              { 
     234                echo "Error: uasort() failed<br />\n"; 
     235              } 
     236            /*foreach  ($rss->items as $item) {echo "$item[title] ". self::get_item_date($item) . "<br>\n";}*/ 
     237 
     238            /* Calculate the publication interval for this source */ 
    215239            foreach ($rss->items as $item) 
    216240              { 
    217                 $date = $this->get_item_date($item); 
     241                $date = self::get_item_date($item); 
    218242                       
    219243                if ($date == -1) 
     
    237261                $i++; 
    238262              }// End foreach items 
     263 
     264 
    239265            if($i >= 2  && $publication_interval_total != 0) 
    240266              { 
     
    273299    //print_r($item_date_array); 
    274300 
    275     usort($item_date_array, "$this->cmp"); 
     301    usort($item_date_array, array("RssPressReview","cmp")); 
    276302    //print_r($item_date_array); 
    277303    //echo "</pre>\n"; 
     
    286312    /************** Now we actually display the feeds **************/ 
    287313    $sidx=0; 
     314    $rss_html_all_feeds=''; 
     315    //print_r($rss_sources); 
     316    reset($rss_sources); 
    288317    foreach ($rss_sources as $rss_sources_key => $rss_source) 
    289318      { 
    290         //echo "<h1>$rss_source[url]</h1>"; 
     319        //echo "<h3>$rss_source[url]</h3>"; 
    291320        $rss = fetch_rss( $rss_source['url'] ); 
    292321        if ( !$rss ) 
     
    302331            if ($rss_sources_key!=0) 
    303332              { 
    304                 $rss_header .= "<hr />\n"; 
     333                //$rss_header .= "<hr />\n"; 
    305334              } 
    306335            $rss_header .= "<p class=textegris>"._('Source: ')."<b>"; 
     
    318347            $header_is_displayed = false; 
    319348            $i = 0; 
     349            /* Sort the items by date, so we get the most recent first */ 
     350            if(!uasort($rss->items, array("RssPressReview","cmp_date_item"))) 
     351              { 
     352                echo "Error: uasort() failed<br />\n"; 
     353              } 
     354 
    320355            foreach ($rss->items as $item) 
    321356              { 
    322                 $date = $this->get_item_date($item); 
     357                $date = self::get_item_date($item); 
    323358                $realdate = $date; 
    324359                if ($date == -1) 
     
    329364                       
    330365                $average_publication_interval = $rss_sources[$rss_sources_key]['average_publication_interval']; 
     366 
    331367                $adjust_factor = $all_feed_publication_interval/$average_publication_interval; 
    332368                $adjusted_date = time()- ((time()-$date)*$adjust_factor); 
    333  
    334                 //echo "adjusted_date $adjusted_date, min_adjusted_date_to_display $min_adjusted_date_to_display<br>"; 
     369                //echo "<pre>";print_r($item);echo"</pre>"; 
     370                /*      setlocale(LC_TIME, "fr_CA"); 
     371                 $display_date= strftime("%x", $realdate); 
     372                 echo "$item[title] ($display_date): adjusted_date $adjusted_date, min_adjusted_date_to_display $min_adjusted_date_to_display<br>"; 
     373                 echo "average_publication_interval: $average_publication_interval, adjust_factor: $adjust_factor, date: $date, $adjusted_date: $adjusted_date<br>";*/ 
    335374                if ($adjusted_date >= $min_adjusted_date_to_display) 
    336375                  { 
     
    340379                        $header_is_displayed = true; 
    341380                      } 
    342                     $href = $item['link']; 
     381                    if(!empty($item['link'])) 
     382                      { 
     383                        $href = $item['link']; 
     384                      } 
     385                    else 
     386                      { 
     387                        $href = false; 
     388                      } 
    343389                    $title = $this->convert_string_encoding($item['title']); 
    344390 
    345                     $summary =  $this->convert_string_encoding($item['summary']);        
    346  
     391                    if(!empty($item['summary'])) 
     392                      { 
     393                        $summary =  $this->convert_string_encoding($item['summary']);    
     394                      } 
     395                    else 
     396                      { 
     397                        $summary = ''; 
     398                      } 
    347399                    if($realdate!= -1) 
    348400                      { 
     
    356408               
    357409                    $author=''; 
    358                     if(trim($item['dc']['creator'])!='') 
     410                    if(!empty($item['dc']['creator'])) 
    359411                      { 
    360412                        $author = trim($item['dc']['creator']); 
    361413                      } 
    362                     elseif (trim($item['author'])!='') 
     414                    elseif (!empty($item['author'])) 
    363415                      { 
    364416                        $author = trim($item['author']); 
    365417                      } 
    366                     elseif (trim($item['author_name'])!='') 
     418                    elseif (!empty($item['author_name'])) 
    367419                      { 
    368420                        $author = trim($item['author_name']); 
     
    376428                    $dhtml_id = "summary_".mt_rand(1, 10000). "_".$sidx; 
    377429                    $rss_html .= "<li>\n"; 
    378                     $rss_html .= "<span class='textegrispetit'>$display_date</span><a class='y' onMouseOver=\"changestyle('$dhtml_id','visible');\" onMouseOut=\"changestyle('$dhtml_id','hidden');\"  href='$href'>\n"; 
    379                     $rss_html .= "<b>$title</b><br />\n"; 
    380                     $rss_html .= "</a>\n"; 
     430                    $rss_html .= "<span class='textegrispetit'>$display_date</span><span class='y' onMouseOver=\"changestyle('$dhtml_id','visible');\" onMouseOut=\"changestyle('$dhtml_id','hidden');\">\n"; 
     431                    if($href) 
     432                      { 
     433                        $rss_html .= "<a class='y' href='$href'>\n"; 
     434                      } 
     435                    $rss_html .= "<b>$title</b></span><br />\n"; 
     436                    if($href) 
     437                      { 
     438                        $rss_html .= "</a>\n"; 
     439                      } 
    381440                    $rss_html .= "<div style='z-index: 1000; position: relative'>\n"; 
    382441                    $rss_html .= "<div style='z-index: 1000;' id='$dhtml_id' class='introduction'> 
     
    390449                $sidx++; 
    391450              }// End foreach items 
     451 
    392452            if($header_is_displayed) 
    393453              { 
    394454                $rss_html .= "</ul>\n"; 
    395455              } 
    396             return $rss_html; 
    397                    
     456            $rss_html_all_feeds .= $rss_html; 
    398457          } 
    399458      }// End foreach rss feeds 
     459    return $rss_html_all_feeds; 
    400460    error_reporting($old_error_level); 
    401461  } 
  • trunk/wifidog-auth/wifidog/hotspot_status.php

    r314 r315  
    6767    $title = $channel->appendChild($title); 
    6868 
    69     $textnode = $xmldoc->createTextNode(utf8_encode(_("New ").HOTSPOT_NETWORK_NAME. _("Hotspots"))); 
     69    $textnode = $xmldoc->createTextNode(utf8_encode(_("Newest")." ".HOTSPOT_NETWORK_NAME. " ". _("Hotspots"))); 
    7070    $title->appendChild($textnode); 
    7171 
     
    292292     } 
    293293     $smarty->assign("nodes_count", count($node_results)); 
     294     $smarty->assign("rss_format_url", 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'].'?format=RSS'); 
    294295     echo $style->GetHeader(HOTSPOT_NETWORK_NAME.' hotspot status'); 
    295296     $smarty->display("hotspot_status.html"); 
  • trunk/wifidog-auth/wifidog/portal/index.php

    r314 r315  
    4646    $hotspot_rss_url = UNKNOWN_HOTSPOT_RSS_URL; 
    4747  } 
    48 else 
    49   { 
    50     $smarty->assign('hotspot_name', $node_info['name']); 
    51     $hotspot_rss_url =  $node_info['rss_url']; 
    52   } 
     48 else 
     49   { 
     50     $smarty->assign('hotspot_name', $node_info['name']); 
     51     $hotspot_rss_url =  $node_info['rss_url']; 
     52   } 
    5353 
    5454/* Find out who is online */ 
     
    6060  { 
    6161    foreach ($users as $user_info) 
    62     { 
    63       $smarty->append("online_users", $user_info); 
    64     } 
     62      { 
     63        $smarty->append("online_users", $user_info); 
     64      } 
    6565  } 
    6666 
    6767if(RSS_SUPPORT) 
    6868  { 
    69 //      $old_error_level = error_reporting(E_ERROR); 
     69    //      $old_error_level = error_reporting(E_ERROR); 
    7070    define('MAGPIE_DIR', BASEPATH.MAGPIE_REL_PATH); 
    71 //    require_once(MAGPIE_DIR.'rss_fetch.inc'); 
    72 //    define('MAGPIE_DEBUG', 0); 
    73  require_once BASEPATH.'classes/RssPressReview.inc'; 
    74  $press_review=new RssPressReview; 
    75    $tokens = "/[\s,]+/"; 
    76  $network_rss_sources = NETWORK_RSS_URL; 
    77  $network_rss_html = null; 
    78                      if(!empty($network_rss_sources)) 
    79                      { 
     71    //    require_once(MAGPIE_DIR.'rss_fetch.inc'); 
     72    //    define('MAGPIE_DEBUG', 0); 
     73    require_once BASEPATH.'classes/RssPressReview.inc'; 
     74    $press_review=new RssPressReview; 
     75    $tokens = "/[\s,]+/"; 
     76    $network_rss_sources = NETWORK_RSS_URL; 
     77    $network_rss_html = null; 
     78    if(!empty($network_rss_sources)) 
     79      { 
    8080 
    81   $extract_array=null; 
    82   $extract_array = preg_split($tokens, $network_rss_sources); 
    83   //print_r($extract_array); 
    84   foreach($extract_array as $source) 
    85   { 
    86 $network_rss_sources_array[] = array('url' => $source, 'default_publication_interval' => 7*24*3600); 
    87                      } 
    88                      $network_rss_html=$press_review->get_rss_html($network_rss_sources_array, 5); 
    89                      } 
     81        $extract_array=null; 
     82        $extract_array = preg_split($tokens, $network_rss_sources); 
     83        //print_r($extract_array); 
     84        foreach($extract_array as $source) 
     85          { 
     86            $network_rss_sources_array[] = array('url' => $source, 'default_publication_interval' => 7*24*3600); 
     87          } 
     88        $network_rss_html=$press_review->get_rss_html($network_rss_sources_array, 5); 
     89      } 
    9090                      
    91                      $hotspot_rss_html=null; 
    92                      if(!empty($hotspot_rss_url)) 
    93                      { 
    94                        $extract_array=null; 
    95   $extract_array = preg_split($tokens, $hotspot_rss_url); 
    96   //print_r($extract_array); 
    97   foreach($extract_array as $source) 
    98   { 
    99 $hotspot_rss_sources_array[] = array('url' => $source, 'default_publication_interval' => 7*24*3600); 
    100                      } 
    101                      $hotspot_rss_html=$press_review->get_rss_html($hotspot_rss_sources_array, 5);      
    102 } 
     91    $hotspot_rss_html=null; 
     92    if(!empty($hotspot_rss_url)) 
     93      { 
     94        $extract_array=null; 
     95        $extract_array = preg_split($tokens, $hotspot_rss_url); 
     96        //print_r($extract_array); 
     97        foreach($extract_array as $source) 
     98          { 
     99            $hotspot_rss_sources_array[] = array('url' => $source, 'default_publication_interval' => 7*24*3600); 
     100          } 
     101        $hotspot_rss_html=$press_review->get_rss_html($hotspot_rss_sources_array, 5);      
     102      } 
    103103    /** 
    104104     @return the generated html or the error message or an empty string if called without a URL. 
     
    121121              $rss_html .= "<ul>\n"; 
    122122              foreach ($rss->items as $item) 
    123               { 
    124                 //echo '<pre>'; print_r($item);         echo '</pre>'; 
    125                 $href = $item['link']; 
    126                 $title = $item['title']; 
    127                 $summary =  $item['summary'];    
    128                 $rss_html .= "<li><emp><a href=$href>$title</a></emp> $summary</li>\n"; 
    129               } 
     123                { 
     124                  //echo '<pre>'; print_r($item);       echo '</pre>'; 
     125                  $href = $item['link']; 
     126                  $title = $item['title']; 
     127                  $summary =  $item['summary'];  
     128                  $rss_html .= "<li><emp><a href=$href>$title</a></emp> $summary</li>\n"; 
     129                } 
    130130              $rss_html .= "</ul>\n"; 
    131131            } 
     
    143143    //echo $hotspot_rss_html; 
    144144    $smarty->assign("hotspot_rss_html", $hotspot_rss_html); 
    145      //   error_reporting($old_error_level); 
     145    //   error_reporting($old_error_level); 
    146146  } 
    147147$smarty->assign("user_management_menu", get_user_management_menu()); 
     
    156156    $smarty->display(NODE_CONTENT_SMARTY_PATH.PORTAL_PAGE_NAME); 
    157157  } 
    158 else 
    159   { 
    160     $smarty->display(DEFAULT_CONTENT_SMARTY_PATH.PORTAL_PAGE_NAME); 
    161   } 
     158 else 
     159   { 
     160     $smarty->display(DEFAULT_CONTENT_SMARTY_PATH.PORTAL_PAGE_NAME); 
     161   } 
    162162 
    163163?> 
  • trunk/wifidog-auth/wifidog/templates/hotspot_status.html

    r312 r315  
    77<thead> 
    88<tr class='spreadsheet'> 
    9     <th class='spreadsheet' colspan=6>Status of the {$nodes_count} open {$smarty.const.HOTSPOT_NETWORK_NAME} HotSpots</th> 
     9    <th class='spreadsheet' colspan=6>Status of the {$nodes_count} open {$smarty.const.HOTSPOT_NETWORK_NAME} HotSpots (Get this list as a <a href='{$rss_format_url}'>RSS feed</a>)</th> 
    1010</tr> 
    1111<tr class='spreadsheet'>