Changeset 440

Show
Ignore:
Timestamp:
02/10/05 17:08:50 (4 years ago)
Author:
aprilp
Message:

Added abstraction layer

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wifidog-auth/wifidog/classes/RssPressReview.inc

    r315 r440  
    2929define('OUTPUT_ENCODING','ISO-8859-1'); 
    3030//mb_detect_order("UTF-8, ISO-8859-1, ASCII"); 
    31 ?> 
    32 <style> 
    33 div.introduction { 
    34   font-size: 12px; 
    35  padding: 5px; 
    36  border: 1px solid #324C48; 
    37      background-color: #E0EBE9; 
    38  visibility: hidden; 
    39  position: absolute; 
    40  left: 25px; 
    41  top: 0px; 
    42  width: 350px; 
    43    -moz-opacity: 0.95; filter: alpha(opacity=95); 
    44 } 
    45  
    46 </style> 
    47  
    48 <script language="JavaScript" type="text/javascript"> 
    49   function MM_findObj(n, d) { //v4.0 
    50   var p,i,x; 
    51   if(!d) d=document;  
    52   if((p=n.indexOf("?"))>0&&parent.frames.length) { 
    53     d=parent.frames[n.substring(p+1)].document;  
    54     n=n.substring(0,p); 
    55   } 
    56   if(!(x=d[n])&&d.all) x=d.all[n];  
    57   for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; 
    58   for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); 
    59   if(!x && document.getElementById) x=document.getElementById(n); return x; 
    60 } 
    61                  
    62 function changestyle(couche, style) { 
    63   if (!(layer = MM_findObj(couche))) return; 
    64   layer.style.visibility = style; 
    65 } 
    66                  
    67 function changeclass(objet, myClass) 
    68 {  
    69   objet.className = myClass; 
    70 } 
    71 </script> 
    72 <?php 
    7331 
    7432class RssPressReview 
    7533{ 
    76   /** 
    77    @return the date in timestamp format of -1 if unavailable 
    78   */ 
    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         } 
     34    /** 
     35      * @return the date in timestamp format of -1 if unavailable 
     36      */ 
     37    static private function get_item_date($item, $debug = 0) { 
     38        $retval = -1; 
     39        if(!empty($item['dc']['date'])) { 
     40            $datestr = $item['dc']['date']; 
     41        } else if (!empty($item['pubdate'])) { 
     42            $datestr = $item['pubdate']; 
     43        } else if (!empty($item['date'])) { 
     44            $datestr = $item['date']; 
     45        } else if (!empty($item['created'])) { 
     46            $datestr = $item['created']; 
     47        } else { 
     48            if ($debug) { 
     49                echo "<p>get_item_date(): No date present!</p>"; 
     50            } 
     51            $datestr = null; 
     52        } 
     53         
     54        if ($datestr == null) { 
     55            $retval = -1; 
     56        } else { 
     57            if ($debug) { 
     58                echo "<p>get_item_date(): String to convert: $datestr</p>";      
     59            } 
     60         
     61            $retval = parse_w3cdtf($datestr); 
     62            if($retval == -1) { 
     63                $retval = strtotime($datestr); 
     64            } 
    10665                 
    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             } 
    117          
    118           $retval = parse_w3cdtf($datestr); 
    119           if($retval == -1) 
    120             { 
    121               $retval = strtotime($datestr); 
    122             } 
    123                  
    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  
     66            if ($debug) { 
     67                if ($retval == -1) { 
     68                    echo "<p>get_item_date(): Conversion of $datestr failed!</p>";       
     69                } else { 
     70                    echo "<p>get_item_date(): Conversion succeded</p>";  
     71                    setlocale(LC_TIME, "fr_CA"); 
     72                    echo strftime("%c", $retval); 
     73                } 
     74            } 
     75        } 
     76 
     77        if ($debug) { 
     78            echo "<p>get_item_date(): Retval: $retval</p>"; 
     79        } 
     80        return $retval; 
    14581    } 
    14682     
    147   /** Inverted comparaison function for adjusted dates (so that the most recent are first */ 
    148   private function cmp($a, $b) 
    149   { 
    150     if ($a['adjusted_date'] == $b['adjusted_date']) { 
    151       return 0; 
    152     } 
    153     return ($a['adjusted_date'] > $b['adjusted_date']) ? -1 : 1; 
    154   } 
    155  
    156   /** 
    157    * @return The converted string 
    158    */ 
    159   private function convert_string_encoding($string) 
    160   { 
     83    /** Inverted comparaison function for adjusted dates (so that the most recent are first */ 
     84    private function cmp($a, $b) { 
     85        if ($a['adjusted_date'] == $b['adjusted_date']) { 
     86            return 0; 
     87        } 
     88        return ($a['adjusted_date'] > $b['adjusted_date']) ? -1 : 1; 
     89    } 
     90 
     91    /** 
     92      * @return The converted string 
     93      */ 
     94    private function convert_string_encoding($string) { 
    16195    /* 
    16296     $input_encoding = mb_detect_encoding($string); 
     
    167101     } 
    168102    */ 
    169     return $string; 
    170   } 
    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  
     103        return $string; 
     104    } 
     105 
     106    /** This is the static comparing function to sort rss items in chronological order: */ 
     107    static function cmp_date_item($a, $b) { 
     108        $a_date=self::get_item_date($a); 
     109        $b_date=self::get_item_date($b); 
     110        if ($a_date == $b_date) { 
     111            return 0; 
     112        } 
     113        /*echo "cmp_date_item(): a:$a_date, b:$b_date "; 
     114        echo ($a_date < $b_date) ? +1 : -1;*/ 
     115        return ($a_date < $b_date) ? +1 : -1; 
     116    } 
    185117 
    186118  /* 
     
    203135   @return The formatted html of the press review 
    204136  */                  
    205   public function get_rss_html($rss_sources, $number_of_items_to_display=20) 
    206   { 
    207     $old_error_level = error_reporting(E_ERROR); 
    208     $item_date_array = array(); 
    209     $item_date_array_index = 0; 
     137    public function get_rss($rss_sources, $number_of_items_to_display = 20) { 
     138        $old_error_level = error_reporting(E_ERROR); 
     139        $item_date_array = array(); 
     140        $item_date_array_index = 0; 
     141 
     142        foreach ($rss_sources as $rss_sources_key => $rss_source) { 
     143            $i = 0; 
     144            $publication_interval_total = null; 
     145            /* running total of the difference between the date of the current item and the previous one */ 
     146            $average_publication_interval = null; 
     147            $previous_item_date = null; 
     148            $rss = fetch_rss( $rss_source['url'] ); 
     149            if (!$rss) { 
     150                throw new Exception(_(magpie_error())); 
     151            } else { 
     152                //$rss_sources[$rss_sources_key]['rss'] = $rss; 
     153                //$rss->show_channel(); 
     154                //$rss->show_list(); 
     155  
     156                /* Sort the array in chronological order */ 
     157 
     158                /* foreach  ($rss->items as $item) {echo "$item[title] ". self::get_item_date($item) . "<br>\n";}*/ 
     159                if (!uasort($rss->items, array("RssPressReview", "cmp_date_item"))) { 
     160                    throw new Exception(_('uasort() failed')); 
     161                } 
     162                /* foreach  ($rss->items as $item) {echo "$item[title] ". self::get_item_date($item) . "<br>\n";}*/ 
     163 
     164                /* Calculate the publication interval for this source */ 
     165                foreach ($rss->items as $item) { 
     166                    $date = self::get_item_date($item); 
     167  
     168                    if ($date == -1) { 
     169                        /* 
     170                         *  If we do not know the date, for statistics purposes, 
     171                         *  we will set the date as if a news item as published 
     172                         *  every default_publication_interval, starting now. 
     173                         */ 
     174                        $date = time() - ($i * $rss_sources[$rss_sources_key]['default_publication_interval']); 
     175                    } 
     176  
     177                    if ($i > 0) { 
     178                        $publication_interval_total += $previous_item_date - $date; 
     179                    } 
     180                       
     181                    $previous_item_date = $date; 
     182  
     183                    /* Memorize each date, and publication intervals so we can determine the "oldest" item to publish */ 
     184 
     185                    $item_date_array[$item_date_array_index]['date']=$date; 
     186                    $item_date_array[$item_date_array_index]['rss_sources_key']=$rss_sources_key; 
     187                    $item_date_array_index++; 
     188                    $i++; 
     189                }// End foreach items 
     190 
     191 
     192                if ($i >= 2 && $publication_interval_total != 0) { 
     193                    $average_publication_interval = $publication_interval_total/($i-1); 
     194                    $rss_sources[$rss_sources_key]['average_publication_interval'] = $average_publication_interval; 
     195                } else { 
     196                    $rss_sources[$rss_sources_key]['average_publication_interval'] = $rss_sources[$rss_sources_key]['default_publication_interval']; 
     197                } 
     198                //echo "<p>$i items, average_publication_interval (days) = ". $rss_sources[$rss_sources_key]['average_publication_interval']/(3600 * 24) . "</p>\n"; 
     199  
     200                $rss_sources[$rss_sources_key]['number_of_items'] = $i; 
     201            } 
     202        }// End foreach rss feeds 
     203 
    210204     
    211     foreach ($rss_sources as $rss_sources_key => $rss_source) 
    212       { 
    213         //echo "<h1>$rss_source[url]</h1>"; 
    214         $i = 0; 
    215         $publication_interval_total = null; //running total of the difference between the date of the current item and the previous one 
    216         $average_publication_interval = null; 
    217         $previous_item_date=null; 
    218         $rss = fetch_rss( $rss_source['url'] ); 
    219         if ( !$rss ) 
    220           { 
    221             echo _("Error: ") . magpie_error() ; 
    222           } 
    223         else  
    224           { 
    225             //$rss_sources[$rss_sources_key]['rss']=$rss; 
    226             //$rss->show_channel(); 
    227             //$rss->show_list(); 
    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 */ 
    239             foreach ($rss->items as $item) 
    240               { 
    241                 $date = self::get_item_date($item); 
    242                        
    243                 if ($date == -1) 
    244                   { 
    245                     //If we do not know the date, for statistics purposes, we will set the date as if a news item as published every default_publication_interval, starting now. 
    246                     $date = time() - ($i * $rss_sources[$rss_sources_key]['default_publication_interval']); 
    247                   } 
    248                        
    249                 if($i >0) 
    250                   { 
    251                     $publication_interval_total += $previous_item_date - $date; 
    252                   } 
    253                        
    254                 $previous_item_date = $date; 
    255                        
    256                 /* Memorize each date, and publication intervals so we can determine the "oldest" item to publish */ 
    257  
    258                 $item_date_array[$item_date_array_index]['date']=$date; 
    259                 $item_date_array[$item_date_array_index]['rss_sources_key']=$rss_sources_key; 
    260                 $item_date_array_index++; 
    261                 $i++; 
    262               }// End foreach items 
    263  
    264  
    265             if($i >= 2  && $publication_interval_total != 0) 
    266               { 
    267                 $average_publication_interval = $publication_interval_total/($i-1); 
    268                 $rss_sources[$rss_sources_key]['average_publication_interval']=$average_publication_interval; 
    269               } 
    270             else 
    271               { 
    272                 $rss_sources[$rss_sources_key]['average_publication_interval']=$rss_sources[$rss_sources_key]['default_publication_interval']; 
    273               } 
    274             //echo "<p>$i items, average_publication_interval (days) = ". $rss_sources[$rss_sources_key]['average_publication_interval']/(3600 * 24) . "</p>\n"; 
    275                
    276             $rss_sources[$rss_sources_key]['number_of_items']=$i;          
    277           } 
    278       }// End foreach rss feeds 
     205        $all_feed_publication_interval_total = null; 
     206        reset($rss_sources); 
     207        foreach ($rss_sources as $rss_source) { 
     208            $all_feed_publication_interval_total += $rss_source['average_publication_interval']; 
     209        } 
     210        $all_feed_publication_interval = $all_feed_publication_interval_total / count($rss_sources); 
     211  
     212        for ($i = 0; isset($item_date_array[$i]); $i++) { 
     213            $average_publication_interval = $rss_sources[$item_date_array[$i]['rss_sources_key']]['average_publication_interval']; 
     214            $adjust_factor = $all_feed_publication_interval / $average_publication_interval; 
     215            $item_date_array[$i]['adjusted_date'] = time() - ((time() - $item_date_array[$i]['date']) * $adjust_factor); 
     216        } 
    279217     
    280  
    281     $all_feed_publication_interval_total = null; 
    282     reset($rss_sources); 
    283     foreach ($rss_sources as $rss_source) 
    284       { 
    285         $all_feed_publication_interval_total+= $rss_source['average_publication_interval']; 
    286       } 
    287     $all_feed_publication_interval = $all_feed_publication_interval_total / count($rss_sources); 
    288     //echo "<p>all_feed_publication_interval (days) = ". $all_feed_publication_interval/(3600 * 24) . "</p>\n"; 
    289                
    290     for($i=0; isset($item_date_array[$i]); $i++) 
    291       { 
    292         $average_publication_interval = $rss_sources[$item_date_array[$i]['rss_sources_key']]['average_publication_interval']; 
    293         $adjust_factor = $all_feed_publication_interval/$average_publication_interval; 
    294         $item_date_array[$i]['adjusted_date']= time()- ((time()-$item_date_array[$i]['date'])*$adjust_factor); 
    295       } 
    296      
    297     //echo "<pre>\n"; 
    298     //print_r($rss_sources); 
    299     //print_r($item_date_array); 
    300  
    301     usort($item_date_array, array("RssPressReview","cmp")); 
    302     //print_r($item_date_array); 
    303     //echo "</pre>\n"; 
    304  
    305     if(count($item_date_array)<$number_of_items_to_display) 
    306       { 
    307         $number_of_items_to_display = count($item_date_array); 
    308       } 
    309  
    310     $min_adjusted_date_to_display = $item_date_array[$number_of_items_to_display-1]['adjusted_date']; 
    311  
    312     /************** Now we actually display the feeds **************/ 
    313     $sidx=0; 
    314     $rss_html_all_feeds=''; 
    315     //print_r($rss_sources); 
    316     reset($rss_sources); 
    317     foreach ($rss_sources as $rss_sources_key => $rss_source) 
    318       { 
    319         //echo "<h3>$rss_source[url]</h3>"; 
    320         $rss = fetch_rss( $rss_source['url'] ); 
    321         if ( !$rss ) 
    322           { 
    323             echo _("Error: ") . magpie_error() ; 
    324           } 
    325         else  
    326           { 
    327             //$rss->show_channel(); 
    328             //$rss->show_list(); 
    329             $rss_html = ''; 
    330             $rss_header=''; 
    331             if ($rss_sources_key!=0) 
    332               { 
    333                 //$rss_header .= "<hr />\n"; 
    334               } 
    335             $rss_header .= "<p class=textegris>"._('Source: ')."<b>"; 
    336             $channel_title = $this->convert_string_encoding($rss->channel['title']); 
    337             if(!empty($rss->channel['link'])) 
    338               { 
    339                 $rss_header .= "<a class='y' href='".$rss->channel['link']."'>$channel_title</a>"; 
    340               } 
    341             else 
    342               { 
    343                 $rss_header .= $channel_title; 
    344               } 
    345             $rss_header .= "</b></p>\n"; 
    346             $rss_header .= "<ul>\n"; 
    347             $header_is_displayed = false; 
    348             $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  
    355             foreach ($rss->items as $item) 
    356               { 
    357                 $date = self::get_item_date($item); 
    358                 $realdate = $date; 
    359                 if ($date == -1) 
    360                   { 
    361                     //If we do not know the date, for statistics purposes, we will set the date as if a news item as published every default_publication_interval, starting now. 
    362                     $date = time() - ($i * $rss_sources[$rss_sources_key]['default_publication_interval']); 
    363                   } 
    364                        
    365                 $average_publication_interval = $rss_sources[$rss_sources_key]['average_publication_interval']; 
    366  
    367                 $adjust_factor = $all_feed_publication_interval/$average_publication_interval; 
    368                 $adjusted_date = time()- ((time()-$date)*$adjust_factor); 
    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>";*/ 
    374                 if ($adjusted_date >= $min_adjusted_date_to_display) 
    375                   { 
    376                     if(!$header_is_displayed) 
    377                       { 
    378                         $rss_html .= $rss_header; 
    379                         $header_is_displayed = true; 
    380                       } 
    381                     if(!empty($item['link'])) 
    382                       { 
    383                         $href = $item['link']; 
    384                       } 
    385                     else 
    386                       { 
    387                         $href = false; 
    388                       } 
    389                     $title = $this->convert_string_encoding($item['title']); 
    390  
    391                     if(!empty($item['summary'])) 
    392                       { 
    393                         $summary =  $this->convert_string_encoding($item['summary']);    
    394                       } 
    395                     else 
    396                       { 
    397                         $summary = ''; 
    398                       } 
    399                     if($realdate!= -1) 
    400                       { 
    401                         setlocale(LC_TIME, "fr_CA"); 
    402                         $display_date= strftime("%x", $realdate); 
    403                       } 
    404                     else 
    405                       { 
    406                         $display_date=''; 
    407                       } 
    408                
    409                     $author=''; 
    410                     if(!empty($item['dc']['creator'])) 
    411                       { 
    412                         $author = trim($item['dc']['creator']); 
    413                       } 
    414                     elseif (!empty($item['author'])) 
    415                       { 
    416                         $author = trim($item['author']); 
    417                       } 
    418                     elseif (!empty($item['author_name'])) 
    419                       { 
    420                         $author = trim($item['author_name']); 
    421                       } 
    422                         
    423                     if(!empty($author)) 
    424                       { 
    425                         $author = $this->convert_string_encoding($author); 
    426                         $author = "par $author"; 
    427                       } 
    428                     $dhtml_id = "summary_".mt_rand(1, 10000). "_".$sidx; 
    429                     $rss_html .= "<li>\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                       } 
    440                     $rss_html .= "<div style='z-index: 1000; position: relative'>\n"; 
    441                     $rss_html .= "<div style='z-index: 1000;' id='$dhtml_id' class='introduction'> 
    442         <p>$author ($channel_title) $display_date</p>\n"; 
    443                     $rss_html .= "<p>$summary</p></div>\n";  
    444                     $rss_html .= "</div>\n"; 
    445                     $rss_html .= "</li>\n"; 
    446  
    447                   } 
    448                 $i++; 
    449                 $sidx++; 
    450               }// End foreach items 
    451  
    452             if($header_is_displayed) 
    453               { 
    454                 $rss_html .= "</ul>\n"; 
    455               } 
    456             $rss_html_all_feeds .= $rss_html; 
    457           } 
    458       }// End foreach rss feeds 
    459     return $rss_html_all_feeds; 
    460     error_reporting($old_error_level); 
     218        usort($item_date_array, array("RssPressReview", "cmp")); 
     219 
     220        if (count($item_date_array) < $number_of_items_to_display) { 
     221            $number_of_items_to_display = count($item_date_array); 
     222        } 
     223 
     224        $min_adjusted_date_to_display = $item_date_array[$number_of_items_to_display - 1]['adjusted_date']; 
     225 
     226        /************** Now we actually display the feeds **************/ 
     227        $sidx = 0; 
     228        reset($rss_sources); 
     229        foreach ($rss_sources as $rss_sources_key => $rss_source) { 
     230            $rss = fetch_rss($rss_source['url']); 
     231            if (!$rss) { 
     232                throw new Exception(_(magpie_error())); 
     233            } else { 
     234                unset($rss_info_tmp); 
     235                $rss_info_tmp['title'] = $rss->channel['title']; 
     236                $rss_info_tmp['link'] = $rss->channel['link']; 
     237 
     238                $i = 0; 
     239                /* Sort the items by date, so we get the most recent first */ 
     240                if (!uasort($rss->items, array("RssPressReview","cmp_date_item"))) { 
     241                    throw new Exception(_('uasort() failed')); 
     242                } 
     243 
     244                $rss_info_tmp['items'] = array(); 
     245                foreach ($rss->items as $item){ 
     246                    $date = self::get_item_date($item); 
     247                    $realdate = $date; 
     248                    if ($date == -1) { 
     249                        /* 
     250                         * If we do not know the date, for statistics purposes, 
     251                         * we will set the date as if a news item as published 
     252                         * every default_publication_interval, starting now. 
     253                         */ 
     254                        $date = time() - ($i * $rss_sources[$rss_sources_key]['default_publication_interval']); 
     255                    } 
     256  
     257                    $average_publication_interval = $rss_sources[$rss_sources_key]['average_publication_interval']; 
     258 
     259                    $adjust_factor = $all_feed_publication_interval / $average_publication_interval; 
     260                    $adjusted_date = time() - ((time() - $date) * $adjust_factor); 
     261                    if ($adjusted_date >= $min_adjusted_date_to_display) { 
     262 
     263                        $author = ''; 
     264                        if(!empty($item['dc']['creator'])) { 
     265                            $author = trim($item['dc']['creator']); 
     266                        } elseif (!empty($item['author'])) { 
     267                            $author = trim($item['author']); 
     268                        } elseif (!empty($item['author_name'])) { 
     269                            $author = trim($item['author_name']); 
     270                        } 
     271  
     272                        array_push($rss_info_tmp['items'], array( 
     273                                "title"     => $item['title'], 
     274                                "summary"   => $item['summary'], 
     275                                "author"    => $author, 
     276                                "date"      => $realdate, 
     277                                "link"      => $item['link'], 
     278                                "id"        => "summary_" . mt_rand(1, 10000). "_" . $sidx 
     279                            )); 
     280                    } 
     281                    $i++; 
     282                    $sidx++; 
     283                }// End foreach items 
     284                $rss_info[] = $rss_info_tmp; 
     285            } 
     286        }// End foreach rss feeds 
     287        return $rss_info; 
     288        error_reporting($old_error_level); 
     289    } 
     290 
     291    function get_rss_header() { 
     292        static $done_header = false; 
     293 
     294        if (!$done_header) { 
     295            $done_header = true; 
     296            return ' 
     297<style> 
     298div.introduction { 
     299  font-size: 12px; 
     300 padding: 5px; 
     301 border: 1px solid #324C48; 
     302     background-color: #E0EBE9; 
     303 visibility: hidden; 
     304 position: absolute; 
     305 left: 25px; 
     306 top: 0px; 
     307 width: 350px; 
     308   -moz-opacity: 0.95; filter: alpha(opacity=95); 
     309
     310 
     311</style> 
     312 
     313<script language="JavaScript" type="text/javascript"> 
     314  function MM_findObj(n, d) { //v4.0 
     315  var p,i,x; 
     316  if(!d) d=document;  
     317  if((p=n.indexOf("?"))>0&&parent.frames.length) { 
     318    d=parent.frames[n.substring(p+1)].document;  
     319    n=n.substring(0,p); 
    461320  } 
    462  
    463 
    464  
     321  if(!(x=d[n])&&d.all) x=d.all[n];  
     322  for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; 
     323  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); 
     324  if(!x && document.getElementById) x=document.getElementById(n); return x; 
     325
     326                 
     327function changestyle(couche, style) { 
     328  if (!(layer = MM_findObj(couche))) return; 
     329  layer.style.visibility = style; 
     330
     331                 
     332function changeclass(objet, myClass) 
     333{  
     334  objet.className = myClass; 
     335
     336</script>'; 
     337        } 
     338    } 
     339 
     340    public function get_rss_html($rss_sources, $number_of_items_to_display = 20) { 
     341        $rss_result = $this->get_rss($rss_sources, $number_of_items_to_display); 
     342 
     343        $html = ''; 
     344        foreach ($rss_result as $feed) { 
     345            $html .= "<p class=textegris>"._('Source: ')."<b>"; 
     346            if(!empty($feed['link'])) { 
     347                $html .= "<a class='y' href='".$feed['link']."'>" . $feed['title'] . "</a>"; 
     348            } else { 
     349                $html .= $channel_title; 
     350            } 
     351            $html .= "</b></p>\n"; 
     352            $html .= "<ul>\n"; 
     353 
     354            foreach ($feed['items'] as $item) { 
     355                if ($item['date'] != -1) { 
     356                    setlocale("LC_TIME", "fr_CA"); 
     357                    $display_date = strftime("%x", $item['date']); 
     358                } else { 
     359                    $display_date = ''; 
     360                } 
     361 
     362                $dhtml_id = "summary_".mt_rand(1, 10000). "_".$sidx; 
     363                $html .= "<li>\n"; 
     364                $html .= "<span class='textegrispetit'>$display_date</span>"; 
     365                $html .= "<span class='y' onMouseOver=\"changestyle('$dhtml_id','visible');\" onMouseOut=\"changestyle('$dhtml_id','hidden');\">\n"; 
     366                if ($item['link']) { 
     367                    $html .= "<a class='y' href='{$item['link']}'><b>{$item['title']}</b></span></a><br />"; 
     368                } else { 
     369                    $html .= "<b>{$item['title']}</b></span><br />"; 
     370                } 
     371                $html .= "<div style='z-index: 1000; position: relative'>\n"; 
     372                $html .= "<div style='z-index: 1000;' id='$dhtml_id' class='introduction'><p>{$item['author']} ({$feed['title']}) $display_date</p>\n"; 
     373                $html .= "<p>{$item['summary']}</p></div>\n";  
     374                $html .= "</div>\n"; 
     375                $html .= "</li>\n"; 
     376            } 
     377            $html .= "</ul>\n"; 
     378        } 
     379        return $this->get_rss_header() . $html; 
     380    } 
     381
    465382?>