Ticket #421: gregarius-simplepie.patch

File gregarius-simplepie.patch, 118.1 kB (added by gregarius.net@…, 4 years ago)
  • cls/update.php

     
    2525# 
    2626############################################################################### 
    2727 
     28require_once ('init.php'); 
     29rss_require('cls/config.php'); 
     30 
    2831define('PUSH_BOUNDARY', "-------- =_aaaaaaaaaa0"); 
    2932define('ERROR_NOERROR', ""); 
    3033define('ERROR_WARNING', " warning"); 
     
    111114    } 
    112115 
    113116    function magpieError($error) { 
    114         if ($error & MAGPIE_FEED_ORIGIN_CACHE) { 
     117        if ($error != -1 && ($error & MAGPIE_FEED_ORIGIN_CACHE)) { 
    115118            if ($error & MAGPIE_FEED_ORIGIN_HTTP_304) { 
    116119                $label = LBL_UPDATE_NOT_MODIFIED; 
    117120                $cls = ERROR_NOERROR; 
     
    133136                $cls = ERROR_ERROR; 
    134137            } 
    135138        } 
    136         elseif ($error & MAGPIE_FEED_ORIGIN_HTTP_200) { 
     139        elseif ($error != -1 && ($error & MAGPIE_FEED_ORIGIN_HTTP_200)) { 
    137140            $label = LBL_UPDATE_STATUS_OK; 
    138141            $cls = ERROR_NOERROR; 
    139142        } 
    140143        else { 
     144/* 
    141145            if (is_numeric($error)) { 
    142146                $label = LBL_UPDATE_STATUS_ERROR; 
    143147                $cls = ERROR_ERROR; 
    144148            } else { 
     149*/ 
    145150                // shoud contain MagpieError at this point 
    146151                $label = $error; 
    147152                $cls = ERROR_ERROR; 
     153/* 
    148154            } 
     155*/ 
    149156        } 
    150157 
    151158        return array( $label, $cls); 
     
    406413    echo "Content-Type: text/html\n\n" 
    407414    ."<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n" 
    408415    ."<html>\n"."<head>\n"."<title>Redirecting...</title>\n" 
    409     ."<meta http-equiv=\"refresh\" content=\"0;url=index.php\"/>\n" 
     416    ."<meta http-equiv=\"refresh\" content=\"0;url=.\"/>\n" 
    410417    ."</head>\n"."<body/>\n"."</html>"; 
    411418 
    412419    echo "\n".PUSH_BOUNDARY."\n"; 
     
    559566    function ajaxUpdateCleanup_cb(dummy) {} 
    560567 
    561568    function redirect() { 
    562         document.location = "index.php"; 
     569        document.location = "."; 
    563570    } 
    564571 
    565572    function ajaxUpdate(batch) { 
  • extlib/rss_fetch.inc

     
    170170        // else attempt a conditional get 
    171171 
    172172        // setup headers 
     173        $request_headers['Cache-Control'] = 'no-cache, must-revalidate'; 
     174        $request_headers['Pragma'] = 'no-cache'; 
    173175        if ( $cache_status == 'STALE' ) { 
    174176            $rss = $cache->get 
    175177                   ( $cache_key ); 
    176178            if ( isset($rss->etag) &&  $rss->etag and 
    177179                    isset($rss->last_modified) && $rss->last_modified ) { 
    178180                $request_headers['If-None-Match'] = $rss->etag; 
    179                 $request_headers['If-Last-Modified'] = $rss->last_modified; 
     181                $request_headers['If-Modified-Since'] = $rss->last_modified; 
    180182            } 
    181183        } 
    182184 
  • extlib/rss_utils.inc

     
    2929     
    3030    if ( preg_match( $pat, $date_str, $match ) ) { 
    3131        list( $year, $month, $day, $hours, $minutes, $seconds) =  
    32             array( $match[1], $match[2], $match[3], $match[4], $match[5], $match[6]); 
     32            array( $match[1], $match[2], $match[3], $match[4], $match[5], $match[7]); 
    3333         
    3434        # calc epoch for current date assuming GMT 
    35         $epoch = gmmktime( $hours, $minutes, intval($seconds), $month, $day, $year); 
     35        $epoch = gmmktime( $hours, $minutes, $seconds, $month, $day, $year); 
    3636         
    3737        $offset = 0; 
    38         if ( $match[10] == 'Z' ) { 
     38        if ( $match[11] == 'Z' ) { 
    3939            # zulu time, aka GMT 
    4040        } 
    4141        else { 
     
    6464    } 
    6565} 
    6666 
    67 ?> 
    68  No newline at end of file 
     67?> 
  • extlib/rss_dbcache.inc

     
    140140    \*=======================================================================*/ 
    141141    function translateUrl ($url) { 
    142142        $url = rss_real_escape_string($url); 
    143                                 $sql = "select id from " . getTable("channels") . " where url='$url'"; 
     143        $sql = "select id from " . getTable("channels") . " where url='$url'"; 
    144144        $res = rss_query($sql); 
    145145        if(1 == rss_num_rows($res)) { 
    146146            list ($cid) = rss_fetch_row($res); 
  • .htaccess

     
     1ExpiresActive on 
     2ExpiresDefault "now" 
     3ExpiresByType text/css  "access plus 1 day" 
     4#ExpiresByType text/html "access plus 1 hour" 
     5ExpiresByType text/html "now" 
     6#ExpiresByType application/xhtml+xml "access plus 1 hour" 
    17 
    28# Disable MultiViews: we want the real thing 
    39# http://httpd.apache.org/docs-2.0/mod/mod_negotiation.html#multiviews 
     
    713 
    814<IfModule mod_rewrite.c> 
    915  RewriteEngine on 
     16  RewriteBase /simplepie/ 
    1017   
     18  RewriteRule ^.+/images.php(.*) /simplepie/images.php$1 [QSA,L] 
    1119   
    12    
    1320  # If we have a file or a directory match then lets set the  
    1421  # static variable 
    1522  RewriteCond %{REQUEST_FILENAME} -f [OR] 
  • simplepie/simplepie.inc

     
     1<?php 
     2/**************************************************** 
     3SIMPLEPIE 
     4A PHP-Based RSS and Atom Feed Framework 
     5Takes the hard work out of managing a complete RSS/Atom solution. 
     6 
     7Version: "Razzleberry" 
     8Updated: 9 June 2006 
     9Copyright: 2004-2006 Ryan Parman, Geoffrey Sneddon 
     10http://simplepie.org 
     11 
     12***************************************************** 
     13LICENSE: 
     14 
     15GNU Lesser General Public License 2.1 (LGPL) 
     16http://creativecommons.org/licenses/LGPL/2.1/ 
     17 
     18***************************************************** 
     19Please submit all bug reports and feature requests to the SimplePie forums. 
     20http://simplepie.org/support/ 
     21 
     22****************************************************/ 
     23 
     24class SimplePie { 
     25 
     26        // SimplePie Information 
     27        var $name = 'SimplePie'; 
     28        var $version = 'Razzleberry'; 
     29        var $build = '20060609'; 
     30        var $url = 'http://simplepie.org/'; 
     31        var $useragent; 
     32        var $linkback; 
     33 
     34        // Run-time Variables 
     35        var $rss_url; 
     36        var $encoding; 
     37        var $xml_dump = false; 
     38        var $caching = true; 
     39        var $max_minutes = 60; 
     40        var $cache_location = './cache'; 
     41        var $bypass_image_hotlink = 'i'; 
     42        var $bypass_image_hotlink_page = false; 
     43        var $replace_headers = false; 
     44        var $remove_div = true; 
     45        var $order_by_date = true; 
     46        var $strip_ads = false; 
     47        var $strip_htmltags = 'blink,body,doctype,embed,font,form,frame,frameset,html,iframe,input,marquee,meta,noscript,object,param,script,style'; 
     48        var $strip_attributes = 'class,id,style,onclick,onmouseover,onmouseout,onfocus,onblur'; 
     49        var $encode_instead_of_strip = false; 
     50        var $http_proxy = false; 
     51 
     52        // RSS Auto-Discovery Variables 
     53        var $parsed_url; 
     54        var $local = array(); 
     55        var $elsewhere = array(); 
     56 
     57        // XML Parsing Variables 
     58        var $xml; 
     59        var $tagName; 
     60        var $insideItem; 
     61        var $insideChannel; 
     62        var $insideImage; 
     63        var $insideAuthor; 
     64        var $itemNumber = 0; 
     65        var $authorNumber = 0; 
     66        var $categoryNumber = 0; 
     67        var $enclosureNumber = 0; 
     68        var $linkNumber = 0; 
     69        var $itemLinkNumber = 0; 
     70        var $data = false; 
     71        var $attribs; 
     72        var $xmldata; 
     73        var $feed_xmlbase; 
     74        var $item_xmlbase; 
     75        var $xhtml_prefix; 
     76 
     77 
     78 
     79 
     80        /**************************************************** 
     81        CONSTRUCTOR 
     82        Initiates a couple of variables.  Accepts feed_url, cache_location,  
     83        and cache_max_minutes. 
     84        ****************************************************/ 
     85        function SimplePie($feed_url = null, $cache_location = null, $cache_max_minutes = null) { 
     86                $this->useragent = $this->name . '/' . $this->version . ' (Feed Parser; ' . $this->url . '; Allow like Gecko) Build/' . $this->build; 
     87                $this->linkback = '<a href="' . $this->url . '" title="' . $this->name . ' ' . $this->version . '">' . $this->name . '</a>'; 
     88                 
     89                if (!is_null($feed_url)) { 
     90                        $this->feed_url($feed_url); 
     91                } 
     92 
     93                if (!is_null($cache_location)) { 
     94                        $this->cache_location($cache_location); 
     95                } 
     96 
     97                if (!is_null($cache_max_minutes)) { 
     98                        $this->cache_max_minutes($cache_max_minutes); 
     99                } 
     100 
     101                if (!is_null($feed_url)) { 
     102                        return $this->init(); 
     103                } 
     104 
     105                // If we've passed an xmldump variable in the URL, snap into XMLdump mode 
     106                if (isset($_GET['xmldump'])) { 
     107                        $this->enable_xmldump($_GET['xmldump']); 
     108                } 
     109        } 
     110 
     111 
     112 
     113 
     114        /**************************************************** 
     115        CONFIGURE OPTIONS 
     116        Set various options (feed URL, XML dump, caching, etc.) 
     117        ****************************************************/ 
     118        // Feed URL 
     119        function feed_url($url) { 
     120                $url = $this->fix_protocol($url, 1); 
     121                $this->rss_url = $url; 
     122                return true; 
     123        } 
     124 
     125        // XML Dump 
     126        function enable_xmldump($enable) { 
     127                $this->xml_dump = (bool) $enable; 
     128                return true; 
     129        } 
     130 
     131        // Bypass Image Hotlink 
     132        function bypass_image_hotlink($getvar='i') { 
     133                $this->bypass_image_hotlink = (string) $getvar; 
     134                return true; 
     135        } 
     136 
     137        // Bypass Image Hotlink Page 
     138        function bypass_image_hotlink_page($page = false) { 
     139                $this->bypass_image_hotlink_page = (string) $page; 
     140                return true; 
     141        } 
     142 
     143        // Caching 
     144        function enable_caching($enable) { 
     145                $this->caching = (bool) $enable; 
     146                return true; 
     147        } 
     148 
     149        // Cache Timeout 
     150        function cache_max_minutes($minutes) { 
     151                $this->max_minutes = (int) $minutes; 
     152                return true; 
     153        } 
     154 
     155        // Cache Location 
     156        function cache_location($location) { 
     157                $this->cache_location = (string) $location; 
     158                return true; 
     159        } 
     160 
     161        // Replace H1, H2, and H3 tags with the less important H4 tags. 
     162        function replace_headers($enable) { 
     163                $this->replace_headers = (bool) $enable; 
     164                return true; 
     165        } 
     166         
     167        // Remove outer div in XHTML content within Atom 
     168        function remove_div($enable) { 
     169                $this->remove_div = (bool) $enable; 
     170                return true; 
     171        } 
     172         
     173        // Order the items by date 
     174        function order_by_date($enable) { 
     175                $this->order_by_date = (bool) $enable; 
     176                return true; 
     177        } 
     178         
     179        // Strip out certain well-known ads 
     180        function strip_ads($enable) { 
     181                $this->strip_ads = (bool) $enable; 
     182                return true; 
     183        } 
     184         
     185        // Strip out potentially dangerous tags 
     186        function strip_htmltags($tags, $encode=false) { 
     187                $this->strip_htmltags = (string) $tags; 
     188                $this->encode_instead_of_strip = (bool) $encode; 
     189                return true; 
     190        } 
     191         
     192        // Encode dangerous tags instead of stripping them 
     193        function encode_instead_of_strip($encode=true) { 
     194                $this->encode_instead_of_strip = (bool) $encode; 
     195                return true; 
     196        } 
     197 
     198        // Strip out potentially dangerous attributes 
     199        function strip_attributes($attrib) { 
     200                $this->strip_attributes = (string) $attrib; 
     201                return true; 
     202        } 
     203 
     204        // Set HTTP proxy for curl 
     205        function proxy($host_port) { 
     206                $this->http_proxy = (string) $host_port; 
     207                return true; 
     208        } 
     209 
     210        // Set HTTP User-agent prefix 
     211        function user_agent($prefix) { 
     212                $this->useragent = (string) $prefix . " " . $this->useragent; 
     213                return true; 
     214        } 
     215 
     216        /**************************************************** 
     217        MAIN INITIALIZATION FUNCTION 
     218        Rewrites the feed so that it actually resembles XML, processes the XML, 
     219        and builds an array from the feed. 
     220        ****************************************************/ 
     221        function init() { 
     222                // If Bypass Image Hotlink is enabled, send image to the page and quit. 
     223                if ($this->bypass_image_hotlink) { 
     224                        if (isset($_GET[$this->bypass_image_hotlink]) && !empty($_GET[$this->bypass_image_hotlink])) { 
     225                                $this->display_image($_GET[$this->bypass_image_hotlink]); 
     226                                exit; 
     227                        } 
     228                } 
     229 
     230                // If Bypass Image Hotlink is enabled, send image to the page and quit. 
     231                if (isset($_GET['js'])) { 
     232 
     233                        // JavaScript for the Odeo Player 
     234                        $embed=''; 
     235                        $embed.='function embed_odeo(link) {'; 
     236                        $embed.='document.writeln(\''; 
     237                        $embed.='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" '; 
     238                        $embed.='    codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" '; 
     239                        $embed.='    width="440" '; 
     240                        $embed.='    height="80" '; 
     241                        $embed.='    align="middle">'; 
     242                        $embed.='<param name="movie" value="http://odeo.com/flash/audio_player_fullsize.swf" />'; 
     243                        $embed.='<param name="allowScriptAccess" value="any" />'; 
     244                        $embed.='<param name="quality" value="high">'; 
     245                        $embed.='<param name="wmode" value="transparent">'; 
     246                        $embed.='<param name="flashvars" value="valid_sample_rate=true&external_url=\'+link+\'" />'; 
     247                        $embed.='<embed src="http://odeo.com/flash/audio_player_fullsize.swf" '; 
     248                        $embed.='    pluginspage="http://www.macromedia.com/go/getflashplayer" '; 
     249                        $embed.='    type="application/x-shockwave-flash" '; 
     250                        $embed.='    quality="high" '; 
     251                        $embed.='    width="440" '; 
     252                        $embed.='    height="80" '; 
     253                        $embed.='    wmode="transparent" '; 
     254                        $embed.='    allowScriptAccess="any" '; 
     255                        $embed.='    flashvars="valid_sample_rate=true&external_url=\'+link+\'">'; 
     256                        $embed.='</embed>'; 
     257                        $embed.='</object>'; 
     258                        $embed.='\');'; 
     259                        $embed.='}'; 
     260 
     261                        $embed.="\r\n"; 
     262 
     263                        $embed.='function embed_quicktime(type, bgcolor, width, height, link, placeholder, loop) {'; 
     264                        $embed.='document.writeln(\''; 
     265                        $embed.='<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" '; 
     266                        $embed.='    style="cursor:hand; cursor:pointer;" '; 
     267                        $embed.='    type="\'+type+\'" '; 
     268                        $embed.='    codebase="http://www.apple.com/qtactivex/qtplugin.cab" '; 
     269                        $embed.='    bgcolor="\'+bgcolor+\'" '; 
     270                        $embed.='    width="\'+width+\'" '; 
     271                        $embed.='    height="\'+height+\'">'; 
     272                        $embed.='<param name="href" value="\'+link+\'" />'; 
     273                        $embed.='<param name="src" value="\'+placeholder+\'" />'; 
     274                        $embed.='<param name="autoplay" value="false" />'; 
     275                        $embed.='<param name="target" value="myself" />'; 
     276                        $embed.='<param name="controller" value="false" />'; 
     277                        $embed.='<param name="loop" value="\'+loop+\'" />'; 
     278                        $embed.='<param name="scale" value="aspect" />'; 
     279                        $embed.='<param name="bgcolor" value="\'+bgcolor+\'">'; 
     280                        $embed.='<embed type="\'+type+\'" '; 
     281                        $embed.='    style="cursor:hand; cursor:pointer;" '; 
     282                        $embed.='    href="\'+link+\'" '; 
     283                        $embed.='    src="\'+placeholder+\'"'; 
     284                        $embed.='    width="\'+width+\'" '; 
     285                        $embed.='    height="\'+height+\'" '; 
     286                        $embed.='    autoplay="false" '; 
     287                        $embed.='    target="myself" '; 
     288                        $embed.='    controller="false" '; 
     289                        $embed.='    loop="\'+loop+\'" '; 
     290                        $embed.='    scale="aspect" '; 
     291                        $embed.='    bgcolor="\'+bgcolor+\'" '; 
     292                        $embed.='    pluginspage="http://www.apple.com/quicktime/download/">'; 
     293                        $embed.='</embed>'; 
     294                        $embed.='</object>'; 
     295                        $embed.='\');'; 
     296                        $embed.='}'; 
     297 
     298                        $embed.="\r\n"; 
     299 
     300                        $embed.='function embed_flash(bgcolor, width, height, link, loop, type) {'; 
     301                        $embed.='document.writeln(\''; 
     302                        $embed.='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '; 
     303                        $embed.='    codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" '; 
     304                        $embed.='    bgcolor="\'+bgcolor+\'" '; 
     305                        $embed.='    width="\'+width+\'" '; 
     306                        $embed.='    height="\'+height+\'">'; 
     307                        $embed.='<param name="movie" value="\'+link+\'">'; 
     308                        $embed.='<param name="quality" value="high">'; 
     309                        $embed.='<param name="loop" value="\'+loop+\'">'; 
     310                        $embed.='<param name="bgcolor" value="\'+bgcolor+\'">'; 
     311                        $embed.='<embed src="\'+link+\'" '; 
     312                        $embed.='    pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" '; 
     313                        $embed.='    type="\'+type+\'" '; 
     314                        $embed.='    quality="high" '; 
     315                        $embed.='    width="\'+width+\'" '; 
     316                        $embed.='    height="\'+height+\'" '; 
     317                        $embed.='    bgcolor="\'+bgcolor+\'" '; 
     318                        $embed.='    loop="\'+loop+\'">'; 
     319                        $embed.='</embed>'; 
     320                        $embed.='</object>'; 
     321                        $embed.='\');'; 
     322                        $embed.='}'; 
     323 
     324                        $embed.="\r\n"; 
     325 
     326                        $embed.='function embed_wmedia(width, height, link) {'; 
     327                        $embed.='document.writeln(\''; 
     328                        $embed.='<object classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"'; 
     329                        $embed.='    type="application/x-oleobject"'; 
     330                        $embed.='    width="\'+width+\'"'; 
     331                        $embed.='    height="\'+height+\'"'; 
     332                        $embed.='    standby="Loading Windows Media Player...">'; 
     333                        $embed.='<param name="FileName" value="\'+link+\'">'; 
     334                        $embed.='<param name="autosize" value="true">'; 
     335                        $embed.='<param name="ShowControls" value="true">'; 
     336                        $embed.='<param name="ShowStatusBar" value="false">'; 
     337                        $embed.='<param name="ShowDisplay" value="false">'; 
     338                        $embed.='<param name="autostart" value="false">'; 
     339                        $embed.='<embed type="application/x-mplayer2" '; 
     340                        $embed.='    src="\'+link+\'" '; 
     341                        $embed.='    autosize="1" '; 
     342                        $embed.='    width="\'+width+\'" '; 
     343                        $embed.='    height="\'+height+\'" '; 
     344                        $embed.='    showcontrols="1" '; 
     345                        $embed.='    showstatusbar="0" '; 
     346                        $embed.='    showdisplay="0" '; 
     347                        $embed.='    autostart="0">'; 
     348                        $embed.='</embed>'; 
     349                        $embed.='</object>'; 
     350                        $embed.='\');'; 
     351                        $embed.='}'; 
     352 
     353                        $embed.="\r\n"; 
     354 
     355                        // enable gzip compression 
     356                        ob_start ("ob_gzhandler");  
     357                        header("Content-type: text/javascript; charset: UTF-8");  
     358                        header("Cache-Control: must-revalidate");  
     359                        header("Expires: " .  gmdate("D, d M Y H:i:s", time() + 60*60*24) . " GMT"); 
     360                        echo $embed; 
     361                        exit; 
     362                } 
     363 
     364                // Clear all outdated cache from the server's cache folder 
     365                $this->clear_cache($this->cache_location, $this->max_minutes); 
     366 
     367                if (!empty($this->rss_url)) { 
     368                        // Read the XML file for processing. 
     369                        $cache_filename = $this->cache_location . '/' . urlencode($this->rss_url) . '.spc'; 
     370                        if ($this->caching && !$this->xml_dump && substr($this->rss_url, 0, 7) == 'http://' && file_exists($cache_filename)) { 
     371                                if ($fp = fopen($cache_filename, 'r')) { 
     372                                        $data = ''; 
     373                                        while (!feof($fp)) { 
     374                                                $data .= fread($fp, 2048); 
     375                                        } 
     376                                        fclose($fp); 
     377                                        $mp_rss = unserialize($data); 
     378                                        if (empty($mp_rss)) { 
     379                                                $this->caching = false; 
     380                                                return $this->init(); 
     381                                        } else if (isset($mp_rss['feed_url'])) { 
     382                                                $this->rss_url = $mp_rss['feed_url']; 
     383                                                return $this->init(); 
     384                                        } else { 
     385                                                $this->data = $mp_rss; 
     386                                                return true; 
     387                                        } 
     388                                } else { 
     389                                        $this->caching = false; 
     390                                        return $this->init(); 
     391                                } 
     392                        } else { 
     393                                // Get the file 
     394                                $mp_rss = $this->get_file($this->rss_url); 
     395 
     396                                // Check if file is a feed or a webpage 
     397                                // If it's a webpage, auto-discover the feed and re-pass it to init() 
     398                                $discovery = $this->rss_locator($mp_rss, $this->rss_url); 
     399                                if ($discovery) { 
     400                                        if ($discovery != $this->rss_url) { 
     401                                                $this->rss_url = $discovery; 
     402                                                if ($this->caching && substr($this->rss_url, 0, 7) == 'http://') { 
     403                                                        if ($this->is_writeable_createable($cache_filename)) { 
     404                                                                $fp = fopen($cache_filename, 'w'); 
     405                                                                fwrite($fp, serialize(array('feed_url' => $discovery))); 
     406                                                                fclose($fp); 
     407                                                        } 
     408                                                        else trigger_error("$cache_filename is not writeable", E_USER_WARNING); 
     409                                                } 
     410                                                return $this->init(); 
     411                                        } 
     412                                } else { 
     413                                        $this->sp_error("A feed could not be found at $this->rss_url", E_USER_WARNING, __FILE__, __LINE__); 
     414                                        return false; 
     415                                } 
     416 
     417                                // Trim out any whitespace at the beginning or the end of the file 
     418                                $mp_rss = trim($mp_rss); 
     419 
     420                                // Get encoding 
     421                                // Attempt to support everything from libiconv (http://www.gnu.org/software/libiconv/) 
     422                                // Support everything from mbstring (http://www.php.net/manual/en/ref.mbstring.php#mbstring.supported-encodings) 
     423                                $use_iconv = false; 
     424                                $use_mbstring = false; 
     425                                $utf8_fail = true; 
     426                                if (preg_match('/encoding=["|\'](.*)["|\']/Ui', $mp_rss, $encoding)) { 
     427                                        $match = $encoding; 
     428                                        switch (strtolower($encoding[1])) { 
     429 
     430                                                // 7bit 
     431                                                case '7bit': 
     432                                                case '7-bit': 
     433                                                        $encoding = '7bit'; 
     434                                                        $use_mbstring = true; 
     435                                                        break; 
     436 
     437                                                // 8bit 
     438                                                case '8bit': 
     439                                                case '8-bit': 
     440                                                        $encoding = '8bit'; 
     441                                                        $use_mbstring = true; 
     442                                                        break; 
     443 
     444                                                // ARMSCII-8 
     445                                                case 'armscii-8': 
     446                                                case 'armscii': 
     447                                                        $encoding = 'ARMSCII-8'; 
     448                                                        $use_iconv = true; 
     449                                                        break; 
     450 
     451                                                // ASCII 
     452                                                case 'us-ascii': 
     453                                                case 'ascii': 
     454                                                        $encoding = 'US-ASCII'; 
     455                                                        $use_iconv = true; 
     456                                                        $use_mbstring = true; 
     457                                                        $utf8_fail = false; 
     458                                                        break; 
     459 
     460                                                // BASE64 
     461                                                case 'base64': 
     462                                                case 'base-64': 
     463                                                        $encoding = 'BASE64'; 
     464                                                        $use_mbstring = true; 
     465                                                        break; 
     466 
     467                                                // Big5 - Traditional Chinese, mainly used in Taiwan 
     468                                                case 'big5': 
     469                                                case '950': 
     470                                                        $encoding = 'BIG5'; 
     471                                                        $use_iconv = true; 
     472                                                        $use_mbstring = true; 
     473                                                        break; 
     474 
     475                                                // Big5 with Hong Kong extensions, Traditional Chinese 
     476                                                case 'big5-hkscs': 
     477                                                        $encoding = 'BIG5-HKSCS'; 
     478                                                        $use_iconv = true; 
     479                                                        $use_mbstring = true; 
     480                                                        break; 
     481 
     482                                                // byte2be 
     483                                                case 'byte2be': 
     484                                                        $encoding = 'byte2be'; 
     485                                                        $use_mbstring = true; 
     486                                                        break; 
     487 
     488                                                // byte2le 
     489                                                case 'byte2le': 
     490                                                        $encoding = 'byte2le'; 
     491                                                        $use_mbstring = true; 
     492                                                        break; 
     493 
     494                                                // byte4be 
     495                                                case 'byte4be': 
     496                                                        $encoding = 'byte4be'; 
     497                                                        $use_mbstring = true; 
     498                                                        break; 
     499 
     500                                                // byte4le 
     501                                                case 'byte4le': 
     502                                                        $encoding = 'byte4le'; 
     503                                                        $use_mbstring = true; 
     504                                                        break; 
     505 
     506                                                // EUC-CN 
     507                                                case 'euc-cn': 
     508                                                case 'euccn': 
     509                                                        $encoding = 'EUC-CN'; 
     510                                                        $use_iconv = true; 
     511                                                        $use_mbstring = true; 
     512                                                        break; 
     513 
     514                                                // EUC-JISX0213 
     515                                                case 'euc-jisx0213': 
     516                                                case 'eucjisx0213': 
     517                                                        $encoding = 'EUC-JISX0213'; 
     518                                                        $use_iconv = true; 
     519                                                        break; 
     520 
     521                                                // EUC-JP 
     522                                                case 'euc-jp': 
     523                                                case 'eucjp': 
     524                                                        $encoding = 'EUC-JP'; 
     525                                                        $use_iconv = true; 
     526                                                        $use_mbstring = true; 
     527                                                        break; 
     528 
     529                                                // EUCJP-win 
     530                                                case 'euc-jp-win': 
     531                                                case 'eucjp-win': 
     532                                                case 'eucjpwin': 
     533                                                        $encoding = 'EUCJP-win'; 
     534                                                        $use_iconv = true; 
     535                                                        $use_mbstring = true; 
     536                                                        break; 
     537 
     538                                                // EUC-KR 
     539                                                case 'euc-kr': 
     540                                                case 'euckr': 
     541                                                        $encoding = 'EUC-KR'; 
     542                                                        $use_iconv = true; 
     543                                                        $use_mbstring = true; 
     544                                                        break; 
     545 
     546                                                // EUC-TW 
     547                                                case 'euc-tw': 
     548                                                case 'euctw': 
     549                                                        $encoding = 'EUC-TW'; 
     550                                                        $use_iconv = true; 
     551                                                        $use_mbstring = true; 
     552                                                        break; 
     553 
     554                                                // GB18030 - Simplified Chinese, national standard character set 
     555                                                case 'gb18030-2000': 
     556                                                case 'gb18030': 
     557                                                        $encoding = 'GB18030'; 
     558                                                        $use_iconv = true; 
     559                                                        break; 
     560 
     561                                                // GB2312 - Simplified Chinese, national standard character set 
     562                                                case 'gb2312': 
     563                                                case '936': 
     564                                                        $encoding = 'GB2312'; 
     565                                                        $use_mbstring = true; 
     566                                                        break; 
     567 
     568                                                // GBK 
     569                                                case 'gbk': 
     570                                                        $encoding = 'GBK'; 
     571                                                        $use_iconv = true; 
     572                                                        break; 
     573 
     574                                                // Georgian-Academy 
     575                                                case 'georgian-academy': 
     576                                                        $encoding = 'Georgian-Academy'; 
     577                                                        $use_iconv = true; 
     578                                                        break; 
     579 
     580                                                // Georgian-PS 
     581                                                case 'georgian-ps': 
     582                                                        $encoding = 'Georgian-PS'; 
     583                                                        $use_iconv = true; 
     584                                                        break; 
     585 
     586                                                // HTML-ENTITIES 
     587                                                case 'html-entities': 
     588                                                case 'htmlentities': 
     589                                                        $encoding = 'HTML-ENTITIES'; 
     590                                                        $use_mbstring = true; 
     591                                                        break; 
     592 
     593                                                // HZ 
     594                                                case 'hz': 
     595                                                        $encoding = 'HZ'; 
     596                                                        $use_iconv = true; 
     597                                                        $use_mbstring = true; 
     598                                                        break; 
     599 
     600                                                // ISO-2022-CN 
     601                                                case 'iso-2022-cn': 
     602                                                case 'iso2022-cn': 
     603                                                case 'iso2022cn': 
     604                                                        $encoding = 'ISO-2022-CN'; 
     605                                                        $use_iconv = true; 
     606                                                        break; 
     607 
     608                                                // ISO-2022-CN-EXT 
     609                                                case 'iso-2022-cn-ext': 
     610                                                case 'iso2022-cn-ext': 
     611                                                case 'iso2022cn-ext': 
     612                                                case 'iso2022cnext': 
     613                                                        $encoding = 'ISO-2022-CN'; 
     614                                                        $use_iconv = true; 
     615                                                        break; 
     616 
     617                                                // ISO-2022-JP 
     618                                                case 'iso-2022-jp': 
     619                                                case 'iso2022-jp': 
     620                                                case 'iso2022jp': 
     621                                                        $encoding = 'ISO-2022-JP'; 
     622                                                        $use_iconv = true; 
     623                                                        $use_mbstring = true; 
     624                                                        break; 
     625 
     626                                                // ISO-2022-JP-1 
     627                                                case 'iso-2022-jp-1': 
     628                                                case 'iso2022-jp-1': 
     629                                                case 'iso2022jp-1': 
     630                                                case 'iso2022jp1': 
     631                                                        $encoding = 'ISO-2022-JP-1'; 
     632                                                        $use_iconv = true; 
     633                                                        break; 
     634 
     635                                                // ISO-2022-JP-2 
     636                                                case 'iso-2022-jp-2': 
     637                                                case 'iso2022-jp-2': 
     638                                                case 'iso2022jp-2': 
     639                                                case 'iso2022jp2': 
     640                                                        $encoding = 'ISO-2022-JP-2'; 
     641                                                        $use_iconv = true; 
     642                                                        break; 
     643 
     644                                                // ISO-2022-JP-3 
     645                                                case 'iso-2022-jp-3': 
     646                                                case 'iso2022-jp-3': 
     647                                                case 'iso2022jp-3': 
     648                                                case 'iso2022jp3': 
     649                                                        $encoding = 'ISO-2022-JP-3'; 
     650                                                        $use_iconv = true; 
     651                                                        break; 
     652 
     653                                                // ISO-2022-KR 
     654                                                case 'iso-2022-kr': 
     655                                                case 'iso2022-kr': 
     656                                                case 'iso2022kr': 
     657                                                        $encoding = 'ISO-2022-KR'; 
     658                                                        $use_iconv = true; 
     659                                                        $use_mbstring = true; 
     660                                                        break; 
     661 
     662                                                // ISO-8859-1 
     663                                                case 'iso-8859-1': 
     664                                                case 'iso8859-1': 
     665                                                        $encoding = 'ISO-8859-1'; 
     666                                                        $use_iconv = true; 
     667                                                        $use_mbstring = true; 
     668                                                        $utf8_fail = false; 
     669                                                        break; 
     670 
     671                                                // ISO-8859-2 
     672                                                case 'iso-8859-2': 
     673                                                case 'iso8859-2': 
     674                                                        $encoding = 'ISO-8859-2'; 
     675                                                        $use_iconv = true; 
     676                                                        $use_mbstring = true; 
     677                                                        break; 
     678 
     679                                                // ISO-8859-3 
     680                                                case 'iso-8859-3': 
     681                                                case 'iso8859-3': 
     682                                                        $encoding = 'ISO-8859-3'; 
     683                                                        $use_iconv = true; 
     684                                                        $use_mbstring = true; 
     685                                                        break; 
     686 
     687                                                // ISO-8859-4 
     688                                                case 'iso-8859-4': 
     689                                                case 'iso8859-4': 
     690                                                        $encoding = 'ISO-8859-4'; 
     691                                                        $use_iconv = true; 
     692                                                        $use_mbstring = true; 
     693                                                        break; 
     694 
     695                                                // ISO-8859-5 
     696                                                case 'iso-8859-5': 
     697                                                case 'iso8859-5': 
     698                                                        $encoding = 'ISO-8859-5'; 
     699                                                        $use_iconv = true; 
     700                                                        $use_mbstring = true; 
     701                                                        break; 
     702 
     703                                                // ISO-8859-6 
     704                                                case 'iso-8859-6': 
     705                                                case 'iso8859-6': 
     706                                                        $encoding = 'ISO-8859-6'; 
     707                                                        $use_iconv = true; 
     708                                                        $use_mbstring = true; 
     709                                                        break; 
     710 
     711                                                // ISO-8859-7 
     712                                                case 'iso-8859-7': 
     713                                                case 'iso8859-7': 
     714                                                        $encoding = 'ISO-8859-7'; 
     715                                                        $use_iconv = true; 
     716                                                        $use_mbstring = true; 
     717                                                        break; 
     718 
     719                                                // ISO-8859-8 
     720                                                case 'iso-8859-8': 
     721                                                case 'iso8859-8': 
     722                                                        $encoding = 'ISO-8859-8'; 
     723                                                        $use_iconv = true; 
     724                                                        $use_mbstring = true; 
     725                                                        break; 
     726 
     727                                                // ISO-8859-9 
     728                                                case 'iso-8859-9': 
     729                                                case 'iso8859-9': 
     730                                                        $encoding = 'ISO-8859-9'; 
     731                                                        $use_iconv = true; 
     732                                                        $use_mbstring = true; 
     733                                                        break; 
     734 
     735                                                // ISO-8859-10 
     736                                                case 'iso-8859-10': 
     737                                                case 'iso8859-10': 
     738                                                        $encoding = 'ISO-8859-10'; 
     739                                                        $use_iconv = true; 
     740                                                        $use_mbstring = true; 
     741                                                        break; 
     742 
     743                                                // mbstring/iconv functions don't appear to support 11 & 12 
     744 
     745                                                // ISO-8859-13 
     746                                                case 'iso-8859-13': 
     747                                                case 'iso8859-13': 
     748                                                        $encoding = 'ISO-8859-13'; 
     749                                                        $use_iconv = true; 
     750                                                        $use_mbstring = true; 
     751                                                        break; 
     752 
     753                                                // ISO-8859-14 
     754                                                case 'iso-8859-14': 
     755                                                case 'iso8859-14': 
     756                                                        $encoding = 'ISO-8859-14'; 
     757                                                        $use_iconv = true; 
     758                                                        $use_mbstring = true; 
     759                                                        break; 
     760 
     761                                                // ISO-8859-15 
     762                                                case 'iso-8859-15': 
     763                                                case 'iso8859-15': 
     764                                                        $encoding = 'ISO-8859-15'; 
     765                                                        $use_iconv = true; 
     766                                                        $use_mbstring = true; 
     767                                                        break; 
     768 
     769                                                // ISO-8859-16 
     770                                                case 'iso-8859-16': 
     771                                                case 'iso8859-16': 
     772                                                        $encoding = 'ISO-8859-16'; 
     773                                                        $use_iconv = true; 
     774                                                        break; 
     775 
     776                                                // JIS 
     777                                                case 'jis': 
     778                                                        $encoding = 'JIS'; 
     779                                                        $use_mbstring = true; 
     780                                                        break; 
     781 
     782                                                // JOHAB - Korean 
     783                                                case 'johab': 
     784                                                        $encoding = 'JOHAB'; 
     785                                                        $use_iconv = true; 
     786                                                        break; 
     787 
     788                                                // Russian 
     789                                                case 'koi8-r': 
     790                                                case 'koi8r': 
     791                                                        $encoding = 'KOI8-R'; 
     792                                                        $use_iconv = true; 
     793                                                        $use_mbstring = true; 
     794                                                        break; 
     795 
     796                                                // Turkish 
     797                                                case 'koi8-t': 
     798                                                case 'koi8t': 
     799                                                        $encoding = 'KOI8-T'; 
     800                                                        $use_iconv = true; 
     801                                                        break; 
     802 
     803                                                // Ukrainian 
     804                                                case 'koi8-u': 
     805                                                case 'koi8u': 
     806                                                        $encoding = 'KOI8-U'; 
     807                                                        $use_iconv = true; 
     808                                                        break; 
     809 
     810                                                // Russian+Ukrainian 
     811                                                case 'koi8-ru': 
     812                                                case 'koi8ru': 
     813                                                        $encoding = 'KOI8-RU'; 
     814                                                        $use_iconv = true; 
     815                                                        break; 
     816 
     817                                                // Macintosh (Mac OS Classic) 
     818                                                case 'macintosh': 
     819                                                        $encoding = 'Macintosh'; 
     820                                                        $use_iconv = true; 
     821                                                        break; 
     822 
     823                                                // MacArabic (Mac OS Classic) 
     824                                                case 'macarabic': 
     825                                                        $encoding = 'MacArabic'; 
     826                                                        $use_iconv = true; 
     827                                                        break; 
     828 
     829                                                // MacCentralEurope (Mac OS Classic) 
     830                                                case 'maccentraleurope': 
     831                                                        $encoding = 'MacCentralEurope'; 
     832                                                        $use_iconv = true; 
     833                                                        break; 
     834 
     835                                                // MacCroatian (Mac OS Classic) 
     836                                                case 'maccroatian': 
     837                                                        $encoding = 'MacCroatian'; 
     838                                                        $use_iconv = true; 
     839                                                        break; 
     840 
     841                                                // MacCyrillic (Mac OS Classic) 
     842                                                case 'maccyrillic': 
     843                                                        $encoding = 'MacCyrillic'; 
     844                                                        $use_iconv = true; 
     845                                                        break; 
     846 
     847                                                // MacGreek (Mac OS Classic) 
     848                                                case 'macgreek': 
     849                                                        $encoding = 'MacGreek'; 
     850                                                        $use_iconv = true; 
     851                                                        break; 
     852 
     853                                                // MacHebrew (Mac OS Classic) 
     854                                                case 'machebrew': 
     855                                                        $encoding = 'MacHebrew'; 
     856                                                        $use_iconv = true; 
     857                                                        break; 
     858 
     859                                                // MacIceland (Mac OS Classic) 
     860                                                case 'maciceland': 
     861                                                        $encoding = 'MacIceland'; 
     862                                                        $use_iconv = true; 
     863                                                        break; 
     864 
     865                                                // MacRoman (Mac OS Classic) 
     866                                                case 'macroman': 
     867                                                        $encoding = 'MacRoman'; 
     868                                                        $use_iconv = true; 
     869                                                        break; 
     870 
     871                                                // MacRomania (Mac OS Classic) 
     872                                                case 'macromania': 
     873                                                        $encoding = 'MacRomania'; 
     874                                                        $use_iconv = true; 
     875                                                        break; 
     876 
     877                                                // MacThai (Mac OS Classic) 
     878                                                case 'macthai': 
     879                                                        $encoding = 'MacThai'; 
     880                                                        $use_iconv = true; 
     881                                                        break; 
     882 
     883                                                // MacTurkish (Mac OS Classic) 
     884                                                case 'macturkish': 
     885                                                        $encoding = 'MacTurkish'; 
     886                                                        $use_iconv = true; 
     887                                                        break; 
     888 
     889                                                // MacUkraine (Mac OS Classic) 
     890                                                case 'macukraine': 
     891                                                        $encoding = 'MacUkraine'; 
     892                                                        $use_iconv = true; 
     893                                                        break; 
     894 
     895                                                // MuleLao-1 
     896                                                case 'mulelao-1': 
     897                                                case 'mulelao1': 
     898                                                        $encoding = 'MuleLao-1'; 
     899                                                        $use_iconv = true; 
     900                                                        break; 
     901 
     902                                                // Shift_JIS 
     903                                                case 'shift_jis': 
     904                                                case 'sjis': 
     905                                                case '932': 
     906                                                        $encoding = 'Shift_JIS'; 
     907                                                        $use_iconv = true; 
     908                                                        $use_mbstring = true; 
     909                                                        break; 
     910 
     911                                                // Shift_JISX0213 
     912                                                case 'shift-jisx0213': 
     913                                                case 'shiftjisx0213': 
     914                                                        $encoding = 'Shift_JISX0213'; 
     915                                                        $use_iconv = true; 
     916                                                        break; 
     917 
     918                                                // SJIS-win 
     919                                                case 'sjis-win': 
     920                                                case 'sjiswin': 
     921                                                case 'shift_jis-win': 
     922                                                        $encoding = 'SJIS-win'; 
     923                                                        $use_iconv = true; 
     924                                                        $use_mbstring = true; 
     925                                                        break; 
     926 
     927                                                // TCVN - Vietnamese 
     928                                                case 'tcvn': 
     929                                                        $encoding = 'TCVN'; 
     930                                                        $use_iconv = true; 
     931                                                        break; 
     932 
     933                                                // TDS565 - Turkish 
     934                                                case 'tds565': 
     935                                                        $encoding = 'TDS565'; 
     936                                                        $use_iconv = true; 
     937                                                        break; 
     938 
     939                                                // TIS-620 Thai 
     940                                                case 'tis-620': 
     941                                                case 'tis620': 
     942                                                        $encoding = 'TIS-620'; 
     943                                                        $use_iconv = true; 
     944                                                        $use_mbstring = true; 
     945                                                        break; 
     946 
     947                                                // UCS-2 
     948                                                case 'ucs-2': 
     949                                                case 'ucs2': 
     950                                                case 'utf-16': 
     951                                                case 'utf16': 
     952                                                        $encoding = 'UCS-2'; 
     953                                                        $use_iconv = true; 
     954                                                        $use_mbstring = true; 
     955                                                        break; 
     956 
     957                                                // UCS-2BE 
     958                                                case 'ucs-2be': 
     959                                                case 'ucs2be': 
     960                                                case 'utf-16be': 
     961                                                case 'utf16be': 
     962                                                        $encoding = 'UCS-2BE'; 
     963                                                        $use_iconv = true; 
     964                                                        $use_mbstring = true; 
     965                                                        break; 
     966 
     967                                                // UCS-2LE 
     968                                                case 'ucs-2le': 
     969                                                case 'ucs2le': 
     970                                                case 'utf-16le': 
     971                                                case 'utf16le': 
     972                                                        $encoding = 'UCS-2LE'; 
     973                                                        $use_iconv = true; 
     974                                                        $use_mbstring = true; 
     975                                                        break; 
     976 
     977                                                // UCS-2-INTERNAL 
     978                                                case 'ucs-2-internal': 
     979                                                case 'ucs2internal': 
     980                                                        $encoding = 'UCS-2-INTERNAL'; 
     981                                                        $use_iconv = true; 
     982                                                        break; 
     983 
     984                                                // UCS-4 
     985                                                case 'ucs-4': 
     986                                                case 'ucs4': 
     987                                                case 'utf-32': 
     988                                                case 'utf32': 
     989                                                        $encoding = 'UCS-4'; 
     990                                                        $use_iconv = true; 
     991                                                        $use_mbstring = true; 
     992                                                        break; 
     993 
     994                                                // UCS-4BE 
     995                                                case 'ucs-4be': 
     996                                                case 'ucs4be': 
     997                                                case 'utf-32be': 
     998                                                case 'utf32be': 
     999                                                        $encoding = 'UCS-4BE'; 
     1000                                                        $use_iconv = true; 
     1001                                                        $use_mbstring = true; 
     1002                                                        break; 
     1003 
     1004                                                // UCS-4LE 
     1005                                                case 'ucs-4le': 
     1006                                                case 'ucs4le': 
     1007                                                case 'utf-32le': 
     1008                                                case 'utf32le': 
     1009                                                        $encoding = 'UCS-4LE'; 
     1010                                                        $use_iconv = true; 
     1011                                                        $use_mbstring = true; 
     1012                                                        break; 
     1013 
     1014                                                // UCS-4-INTERNAL 
     1015                                                case 'ucs-4-internal': 
     1016                                                case 'ucs4internal': 
     1017                                                        $encoding = 'UCS-4-INTERNAL'; 
     1018                                                        $use_iconv = true; 
     1019                                                        break; 
     1020 
     1021                                                // UCS-16 
     1022                                                case 'ucs-16': 
     1023                                                case 'ucs16': 
     1024                                                        $encoding = 'UCS-16'; 
     1025                                                        $use_iconv = true; 
     1026                                                        $use_mbstring = true; 
     1027                                                        break; 
     1028 
     1029                                                // UCS-16BE 
     1030                                                case 'ucs-16be': 
     1031                                                case 'ucs16be': 
     1032                                                        $encoding = 'UCS-16BE'; 
     1033                                                        $use_iconv = true; 
     1034                                                        $use_mbstring = true; 
     1035                                                        break; 
     1036 
     1037                                                // UCS-16LE 
     1038                                                case 'ucs-16le': 
     1039                                                case 'ucs16le': 
     1040                                                        $encoding = 'UCS-16LE'; 
     1041                                                        $use_iconv = true; 
     1042                                                        $use_mbstring = true; 
     1043                                                        break; 
     1044 
     1045                                                // UCS-32 
     1046                                                case 'ucs-32': 
     1047                                                case 'ucs32': 
     1048                                                        $encoding = 'UCS-32'; 
     1049                                                        $use_iconv = true; 
     1050                                                        $use_mbstring = true; 
     1051                                                        break; 
     1052 
     1053                                                // UCS-32BE 
     1054                                                case 'ucs-32be': 
     1055                                                case 'ucs32be': 
     1056                                                        $encoding = 'UCS-32BE'; 
     1057                                                        $use_iconv = true; 
     1058                                                        $use_mbstring = true; 
     1059                                                        break; 
     1060 
     1061                                                // UCS-32LE 
     1062                                                case 'ucs-32le': 
     1063                                                case 'ucs32le': 
     1064                                                        $encoding = 'UCS-32LE'; 
     1065                                                        $use_iconv = true; 
     1066                                                        $use_mbstring = true; 
     1067                                                        break; 
     1068 
     1069                                                // UTF-7 
     1070                                                case 'utf-7': 
     1071                                                case 'utf7': 
     1072                                                        $encoding = 'UTF-7'; 
     1073                                                        $use_iconv = true; 
     1074                                                        $use_mbstring = true; 
     1075                                                        break; 
     1076 
     1077                                                // UTF7-IMAP 
     1078                                                case 'utf-7-imap': 
     1079                                                case 'utf7-imap': 
     1080                                                case 'utf7imap': 
     1081                                                        $encoding = 'UTF7-IMAP'; 
     1082                                                        $use_mbstring = true; 
     1083                                                        break; 
     1084 
     1085                                                // VISCII - Vietnamese ASCII 
     1086                                                case 'viscii': 
     1087                                                        $encoding = 'VISCII'; 
     1088                                                        $use_iconv = true; 
     1089                                                        break; 
     1090 
     1091                                                // Windows-specific Central & Eastern Europe 
     1092                                                case 'cp1250': 
     1093                                                case 'windows-1250': 
     1094                                                case 'win-1250': 
     1095                                                case '1250': 
     1096                                                        $encoding = 'Windows-1250'; 
     1097                                                        $use_iconv = true; 
     1098                                                        break; 
     1099 
     1100                                                // Windows-specific Cyrillic 
     1101                                                case 'cp1251': 
     1102                                                case 'windows-1251': 
     1103                                                case 'win-1251': 
     1104                                                case '1251': 
     1105                                                        $encoding = 'Windows-1251'; 
     1106                                                        $use_iconv = true; 
     1107                                                        $use_mbstring = true; 
     1108                                                        break; 
     1109 
     1110                                                // Windows-specific Western Europe 
     1111                                                case 'cp1252': 
     1112                                                case 'windows-1252': 
     1113                                                case '1252': 
     1114                                                        $encoding = 'Windows-1252'; 
     1115                                                        $use_iconv = true; 
     1116                                                        $use_mbstring = true; 
     1117                                                        break; 
     1118 
     1119                                                // Windows-specific Greek 
     1120                                                case 'cp1253': 
     1121                                                case 'windows-1253': 
     1122                                                case '1253': 
     1123                                                        $encoding = 'Windows-1253'; 
     1124                                                        $use_iconv = true; 
     1125                                                        break; 
     1126 
     1127                                                // Windows-specific Turkish 
     1128                                                case 'cp1254': 
     1129                                                case 'windows-1254': 
     1130                                                case '1254': 
     1131                                                        $encoding = 'Windows-1254'; 
     1132                                                        $use_iconv = true; 
     1133                                                        break; 
     1134 
     1135                                                // Windows-specific Hebrew 
     1136                                                case 'cp1255': 
     1137                                                case 'windows-1255': 
     1138                                                case '1255': 
     1139                                                        $encoding = 'Windows-1255'; 
     1140                                                        $use_iconv = true; 
     1141                                                        break; 
     1142 
     1143                                                // Windows-specific Arabic 
     1144                                                case 'cp1256': 
     1145                                                case 'windows-1256': 
     1146                                                case '1256': 
     1147                                                        $encoding = 'Windows-1256'; 
     1148                                                        $use_iconv = true; 
     1149                                                        break; 
     1150 
     1151                                                // Windows-specific Baltic 
     1152                                                case 'cp1257': 
     1153                                                case 'windows-1257': 
     1154                                                case '1257': 
     1155                                                        $encoding = 'Windows-1257'; 
     1156                                                        $use_iconv = true; 
     1157                                                        break; 
     1158 
     1159                                                // Windows-specific Vietnamese 
     1160                                                case 'cp1258': 
     1161                                                case 'windows-1258': 
     1162                                                case '1258': 
     1163                                                        $encoding = 'Windows-1258'; 
     1164                                                        $use_iconv = true; 
     1165                                                        break; 
     1166 
     1167                                                // Default to UTF-8 
     1168                                                default: 
     1169                                                        $encoding = 'UTF-8'; 
     1170                                                        break; 
     1171                                        } 
     1172                                } else { 
     1173                                        $mp_rss = preg_replace ('/<\?xml(.*)( standalone="no")(.*)\?>/msiU', '<?xml\\1\\3?>', $mp_rss, 1); 
     1174                                        $mp_rss = preg_replace ('/<\?xml(.*)\?>/msiU', '<?xml\\1 encoding="UTF-8"?>', $mp_rss, 1); 
     1175                                        preg_match('/encoding=["|\'](.*)["|\']/Ui', $mp_rss, $match); 
     1176                                        $use_iconv = false; 
     1177                                        $use_mbstring = false; 
     1178                                        $utf8_fail = false; 
     1179                                        $encoding = 'UTF-8'; 
     1180                                } 
     1181                                $this->encoding = $encoding; 
     1182 
     1183                                // If function is available and able, convert characters to UTF-8, and overwrite $this->encoding 
     1184                                if (function_exists('iconv') && $use_iconv && iconv($encoding, 'UTF-8', $mp_rss)) { 
     1185                                        $mp_rss = iconv($encoding, 'UTF-8//TRANSLIT', $mp_rss); 
     1186                                        $mp_rss = str_replace ($match[0], 'encoding="UTF-8"', $mp_rss); 
     1187                                        $this->encoding = 'UTF-8'; 
     1188                                } 
     1189                                else if (function_exists('mb_convert_encoding') && $use_mbstring) { 
     1190                                        $mp_rss = mb_convert_encoding($mp_rss, 'UTF-8', $encoding); 
     1191                                        $mp_rss = str_replace ($match[0], 'encoding="UTF-8"', $mp_rss); 
     1192                                        $this->encoding = 'UTF-8'; 
     1193                                } 
     1194                                else if (($use_mbstring || $use_iconv) && $utf8_fail) { 
     1195                                                $this->encoding = 'UTF-8'; 
     1196                                                $mp_rss = str_replace ($match[0], 'encoding="UTF-8"', $mp_rss); 
     1197                                } 
     1198                                $mp_rss = preg_replace('/<(.*)>[\s]*<\!\[CDATA\[/msiU', '<\\1 spencoded="false"><![CDATA[', $mp_rss); // Add an internal attribute to CDATA sections 
     1199                                $mp_rss = str_replace(']] spencoded="false">', ']]>', $mp_rss); // Remove it when we're on the end of a CDATA block (therefore making it ill-formed) 
     1200 
     1201                                // If we're RSS 
     1202                                if (preg_match('/<rdf:rdf/i', $mp_rss) || preg_match('/<rss/i', $mp_rss)) { 
     1203                                        $sp_elements = array( 
     1204                                                'author', 
     1205                                                'link', 
     1206                                        ); 
     1207                                // Or if we're Atom 
     1208                                } else { 
     1209                                        $sp_elements = array( 
     1210                                                'content', 
     1211                                                'copyright', 
     1212                                                'name', 
     1213                                                'subtitle', 
     1214                                                'summary', 
     1215                                                'tagline', 
     1216                                                'title', 
     1217                                        ); 
     1218                                } 
     1219                                foreach ($sp_elements as $full) { 
     1220                                        // The (<\!\[CDATA\[)? never matches any CDATA block, therefore the CDATA gets added, but never replaced 
     1221                                        $mp_rss = preg_replace("/<$full(.*)>[\s]*(<\!\[CDATA\[)?(.*)(]]>)?[\s]*<\/$full>/msiU", "<$full\\1><![CDATA[\\3]]></$full>", $mp_rss); 
     1222                                        // The following line is a work-around for the above bug 
     1223                                        $mp_rss = preg_replace("/<$full(.*)><\!\[CDATA\[[\s]*<\!\[CDATA\[/msiU", "<$full\\1><![CDATA[", $mp_rss); 
     1224                                        // Deal with CDATA within CDATA (this can be caused by us inserting CDATA above) 
     1225                                        $mp_rss = preg_replace_callback("/<($full)(.*)><!\[CDATA\[(.*)\]\]><\/$full>/msiU", array(&$this, 'cdata_in_cdata'), $mp_rss); 
     1226                                } 
     1227 
     1228                                // If XML Dump is enabled, send feed to the page and quit. 
     1229                                if ($this->xml_dump) { 
     1230                                        header("Content-type: text/xml; charset=" . $this->encoding); 
     1231                                        echo $mp_rss; 
     1232                                        exit; 
     1233                                } 
     1234 
     1235                                $this->xml = xml_parser_create_ns($this->encoding); 
     1236                                $this->namespaces = array('xml' => 'HTTP://WWW.W3.ORG/XML/1998/NAMESPACE', 'atom' => 'ATOM', 'rss2' => 'RSS', 'rdf' => 'RDF', 'rss1' => 'RSS', 'dc' => 'DC', 'xhtml' => 'XHTML', 'content' => 'CONTENT'); 
     1237                                xml_parser_set_option($this->xml, XML_OPTION_SKIP_WHITE, 1); 
     1238                                xml_set_object($this->xml, $this); 
     1239                                xml_set_character_data_handler($this->xml, 'dataHandler'); 
     1240                                xml_set_element_handler($this->xml, 'startHandler', 'endHandler'); 
     1241                                xml_set_start_namespace_decl_handler($this->xml, 'startNameSpace'); 
     1242                                xml_set_end_namespace_decl_handler($this->xml, 'endNameSpace'); 
     1243                                if (xml_parse($this->xml, $mp_rss)) 
     1244                                { 
     1245                                        unset($mp_rss); 
     1246                                        xml_parser_free($this->xml); 
     1247                                        $this->parse_xml_data_array(); 
     1248                                        $this->data['feedinfo']['encoding'] = $this->encoding; 
     1249                                        if ($this->order_by_date && !empty($this->data['items'])) { 
     1250                                                $do_sort = true; 
     1251                                                foreach($this->data['items'] as $item) { 
     1252                                                        if (is_null($item->date)) { 
     1253                                                                $do_sort = false; 
     1254                                                                break; 
     1255                                                        } 
     1256                                                } 
     1257                                                if ($do_sort) { 
     1258                                                        usort($this->data['items'], create_function('$a,$b', 'if ($a->date == $b->date) return 0; return ($a->date < $b->date) ? 1 : -1;')); 
     1259                                                } 
     1260                                        } 
     1261                                        if ($this->caching && substr($this->rss_url, 0, 7) == 'http://') { 
     1262                                                if ($this->is_writeable_createable($cache_filename)) { 
     1263                                                        $fp = fopen($cache_filename, 'w'); 
     1264                                                        fwrite($fp, serialize($this->data)); 
     1265                                                        fclose($fp); 
     1266                                                } 
     1267                                                else trigger_error("$cache_filename is not writeable", E_USER_WARNING); 
     1268                                        } 
     1269                                        return true; 
     1270                                } 
     1271                                else 
     1272                                { 
     1273                                        $this->sp_error(sprintf('XML error: %s at line %d, column %d', xml_error_string(xml_get_error_code($this->xml)), xml_get_current_line_number($this->xml), xml_get_current_column_number($this->xml)), E_USER_WARNING, __FILE__, __LINE__); 
     1274                                        xml_parser_free($this->xml); 
     1275                                        $this->data = array(); 
     1276                                        return false; 
     1277                                } 
     1278                        } 
     1279                } 
     1280                else { 
     1281                        return false; 
     1282                } 
     1283        } 
     1284 
     1285 
     1286 
     1287 
     1288        /**************************************************** 
     1289        SIMPLEPIE ERROR (internal function) 
     1290        ****************************************************/ 
     1291        function sp_error($message, $level, $file, $line) { 
     1292                $this->error = $message; 
     1293                switch ($level) { 
     1294                        case E_USER_ERROR: 
     1295                                $note = 'PHP Error'; 
     1296                                break; 
     1297                        case E_USER_WARNING: 
     1298                                $note = 'PHP Warning'; 
     1299                                break; 
     1300                        case E_USER_NOTICE: 
     1301                                $note = 'PHP Notice'; 
     1302                                break; 
     1303                        default: 
     1304                                $note = 'Unknown Error'; 
     1305                                break; 
     1306                } 
     1307                error_log("$note: $message in $file on line $line", 0); 
     1308        } 
     1309 
     1310 
     1311 
     1312 
     1313        /**************************************************** 
     1314        GET FEED ENCODING 
     1315        ****************************************************/ 
     1316        function get_encoding() { 
     1317                if (isset($this->encoding)) { 
     1318                        return $this->encoding; 
     1319                } else if (isset($this->data['feedinfo']['encoding'])) { 
     1320                        return $this->data['feedinfo']['encoding']; 
     1321                } else return false; 
     1322        } 
     1323 
     1324        function handle_content_type($mime='text/html') { 
     1325                if (!headers_sent() && $this->get_encoding()) header('Content-type: ' . $mime . '; charset=' . $this->get_encoding()); 
     1326        } 
     1327 
     1328 
     1329 
     1330 
     1331        /**************************************************** 
     1332        GET FEED VERSION NUMBER 
     1333        ****************************************************/ 
     1334        function get_version() { 
     1335                if (isset($this->data['feedinfo'])) { 
     1336                        return (isset($this->data['feedinfo']['version'])) ? $this->data[feedinfo][type] . ' ' . $this->data[feedinfo][version] : $this->data['feedinfo']['type']; 
     1337                } 
     1338                else return false; 
     1339        } 
     1340 
     1341 
     1342 
     1343 
     1344        /**************************************************** 
     1345        SUBSCRIPTION URLS 
     1346        This allows people to subscribe to the feed in various services. 
     1347        ****************************************************/ 
     1348        function subscribe_url() { 
     1349                return (empty($this->rss_url)) ? false : $this->fix_protocol($this->rss_url, 1); 
     1350        } 
     1351 
     1352        function subscribe_feed() { 
     1353                return (empty($this->rss_url)) ? false : $this->fix_protocol($this->rss_url, 2); 
     1354        } 
     1355 
     1356        function subscribe_podcast() { 
     1357                return (empty($this->rss_url)) ? false : $this->fix_protocol($this->rss_url, 3); 
     1358        } 
     1359 
     1360        function subscribe_aol() { 
     1361                return (empty($this->rss_url)) ? false : 'http://feeds.my.aol.com/add.jsp?url=' . rawurlencode($this->subscribe_url()); 
     1362        } 
     1363 
     1364        function subscribe_bloglines() { 
     1365                return (empty($this->rss_url)) ? false : 'http://www.bloglines.com/sub/' . rawurlencode($this->subscribe_url()); 
     1366        } 
     1367 
     1368        function subscribe_google() { 
     1369                return (empty($this->rss_url)) ? false : 'http://fusion.google.com/add?feedurl=' . rawurlencode($this->subscribe_url()); 
     1370        } 
     1371 
     1372        function subscribe_msn() { 
     1373                return (empty($this->rss_url)) ? false : 'http://my.msn.com/addtomymsn.armx?id=rss&amp;ut=' . rawurlencode($this->subscribe_url()) . '&amp;ru=' . rawurlencode($this->get_feed_link()); 
     1374        } 
     1375 
     1376        function subscribe_netvibes() { 
     1377                return (empty($this->rss_url)) ? false : 'http://www.netvibes.com/subscribe.php?url=' . rawurlencode($this->subscribe_url()); 
     1378        } 
     1379 
     1380        function subscribe_newsburst() { 
     1381                return (empty($this->rss_url)) ? false : 'http://www.newsburst.com/Source/?add=' . rawurlencode($this->subscribe_url()); 
     1382        } 
     1383 
     1384        function subscribe_newsgator() { 
     1385                return (empty($this->rss_url)) ? false : 'http://www.newsgator.com/ngs/subscriber/subext.aspx?url=' . rawurlencode($this->subscribe_url()); 
     1386        } 
     1387 
     1388        function subscribe_odeo() { 
     1389                return (empty($this->rss_url)) ? false : 'http://www.odeo.com/listen/subscribe?feed=' . rawurlencode($this->subscribe_url()); 
     1390        } 
     1391 
     1392        function subscribe_pluck() { 
     1393                return (empty($this->rss_url)) ? false : 'http://client.pluck.com/pluckit/prompt.aspx?GCID=C12286x053&amp;a=' . rawurlencode($this->subscribe_url()); 
     1394        } 
     1395 
     1396        function subscribe_podnova() { 
     1397                return (empty($this->rss_url)) ? false : 'http://www.podnova.com/index_your_podcasts.srf?action=add&url=' . rawurlencode($this->subscribe_url()); 
     1398        } 
     1399 
     1400        function subscribe_rojo() { 
     1401                return (empty($this->rss_url)) ? false : 'http://www.rojo.com/add-subscription?resource=' . rawurlencode($this->subscribe_url()); 
     1402        } 
     1403 
     1404        function subscribe_yahoo() { 
     1405                return (empty($this->rss_url)) ? false : 'http://add.my.yahoo.com/rss?url=' . rawurlencode($this->subscribe_url()); 
     1406        } 
     1407 
     1408 
     1409 
     1410 
     1411        /**************************************************** 
     1412        PARSE OUT GENERAL FEED-RELATED DATA 
     1413        ****************************************************/ 
     1414        // Reads the feed's title 
     1415        function get_feed_title() { 
     1416                return (isset($this->data['info']['title'])) ? $this->data['info']['title'] : false; 
     1417        } 
     1418 
     1419        // Reads the feed's link (URL) 
     1420        function get_feed_link() { 
     1421                return (isset($this->data['info']['link'][0])) ? $this->data['info']['link'][0] : false; 
     1422        } 
     1423 
     1424        // Reads the feed's link (URL) 
     1425        function get_feed_links($key) { 
     1426                return (isset($this->data['info']['link'][$key])) ? $this->data['info']['link'][$key] : false; 
     1427        } 
     1428 
     1429        // Reads the feed's description 
     1430        function get_feed_description() { 
     1431                return (isset($this->data['info']['description'])) ? $this->data['info']['description'] : false; 
     1432        } 
     1433 
     1434        // Reads the feed's copyright information. 
     1435        function get_feed_copyright() { 
     1436                return (isset($this->data['info']['copyright'])) ? $this->data['info']['copyright'] : false; 
     1437        } 
     1438 
     1439        // Reads the feed's language 
     1440        function get_feed_language() { 
     1441                return (isset($this->data['info']['language'])) ? $this->data['info']['language'] : false; 
     1442        } 
     1443 
     1444 
     1445 
     1446 
     1447        /**************************************************** 
     1448        PARSE OUT IMAGE-RELATED DATA 
     1449        Apparently Atom doesn't have feed images. 
     1450        ****************************************************/ 
     1451        // Check if an image element exists (returns true/false) 
     1452        function get_image_exist() { 
     1453                return (isset($this->data['info']['image']['url'])) ? true : false; 
     1454        } 
     1455 
     1456        // Get the image title (to be used in alt and/or title) 
     1457        function get_image_title() { 
     1458                return (isset($this->data['info']['image']['title'])) ? $this->data['info']['image']['title'] : false; 
     1459        } 
     1460 
     1461        // The path to the actual image 
     1462        function get_image_url() { 
     1463                return (isset($this->data['info']['image']['url'])) ? $this->data['info']['image']['url'] : false; 
     1464        } 
     1465 
     1466        // The URL that the image is supposed to link to. 
     1467        function get_image_link() { 
     1468                return (isset($this->data['info']['image']['link'])) ? $this->data['info']['image']['link'] : false; 
     1469        } 
     1470 
     1471        // Get the image width 
     1472        function get_image_width() { 
     1473                return (isset($this->data['info']['image']['width'])) ? $this->data['info']['image']['width'] : false; 
     1474        } 
     1475 
     1476        // Get the image height 
     1477        function get_image_height() { 
     1478                return (isset($this->data['info']['image']['height'])) ? $this->data['info']['image']['height'] : false; 
     1479        } 
     1480 
     1481 
     1482 
     1483 
     1484        /**************************************************** 
     1485        PARSE OUT ITEM-RELATED DATA 
     1486        ****************************************************/ 
     1487        // Get the size of the array of items (for use in a for-loop) 
     1488        function get_item_quantity($max=0) { 
     1489                $qty = (isset($this->data['items'])) ? sizeof($this->data['items']) : 0; 
     1490                if ($max != 0) return ($qty > $max) ? $max : $qty; 
     1491                else return $qty; 
     1492        } 
     1493         
     1494        function get_item($key) { 
     1495                return $this->data['items'][$key]; 
     1496        } 
     1497         
     1498        function get_items($start = 0, $end = 0) { 
     1499                return ($end == 0) ? array_slice($this->data['items'], $start) : array_slice($this->data['items'], $start, $end); 
     1500        } 
     1501 
     1502 
     1503 
     1504 
     1505        /**************************************************** 
     1506        FIX PROTOCOL 
     1507        Convert feed:// and no-protocol URL's to http:// 
     1508        Feed is allowed to have no protocol.  Local files are toggled in init(). 
     1509        This is an internal function and is not intended to be used publically. 
     1510 
     1511        $http=1, http://www.domain.com/feed.xml (absolute) 
     1512        $http=2, feed://www.domain.com/feed.xml (absolute) 
     1513        $http=3, podcast://www.domain.com/feed.xml (absolute) 
     1514        ****************************************************/ 
     1515        function fix_protocol($url, $http = 1) { 
     1516                $url = preg_replace('/^http:\/\/photocast.mac.com/i', 'http://web.mac.com', $url); 
     1517                $url = preg_replace('/^(p(od)?cast|feed)[:]?[\/]*(http(s)?:\/\/)?/i', 'http://', $url); 
     1518                if (!preg_match('/^http(s)?:\/\//i', $url) && !file_exists($url)) $url = "http://$url"; 
     1519 
     1520                if ($http != 1 && strstr($url, 'http://')) { 
     1521                        if ($http == 2) { 
     1522                                $url = substr_replace($url, 'feed', 0, 4); 
     1523                        } 
     1524                        else if ($http == 3) { 
     1525                                $url = substr_replace($url, 'podcast', 0, 4); 
     1526                        } 
     1527                } 
     1528                return $url; 
     1529        } 
     1530 
     1531 
     1532 
     1533 
     1534        /**************************************************** 
     1535        ULTRA-LIBERAL FEED LOCATOR 
     1536        Based upon http://diveintomark.org/archives/2002/08/15/ultraliberal_rss_locator 
     1537        This function enables support for RSS auto-discovery-on-crack. 
     1538        ****************************************************/ 
     1539        function rss_locator($data, $url) { 
     1540 
     1541                $this->url = $url; 
     1542                $this->parsed_url = parse_url($url); 
     1543                if (!isset($this->parsed_url['path'])) { 
     1544                        $this->parsed_url['path'] = '/'; 
     1545                } 
     1546 
     1547                // Check is the URL we're given is a feed 
     1548                if ($this->is_feed($data, false)) { 
     1549                        return $url; 
     1550                } 
     1551 
     1552                // Feeds pointed to by LINK tags in the header of the page (autodiscovery) 
     1553                $stage1 = $this->check_link_elements($data); 
     1554                if ($stage1) { 
     1555                        return $stage1; 
     1556                } 
     1557 
     1558                // Grab all the links in the page, and put them into two arrays (local, and external) 
     1559                if ($this->get_links($data)) { 
     1560 
     1561                        // <A> links to feeds on the same server ending in ".rss", ".rdf", ".xml", or ".atom" 
     1562                        $stage2 = $this->check_link_extension($this->local); 
     1563                        if ($stage2) { 
     1564                                return $stage2; 
     1565                        } 
     1566 
     1567                        // <A> links to feeds on the same server containing "rss", "rdf", "xml", or "atom" 
     1568                        $stage3 = $this->check_link_body($this->local); 
     1569                        if ($stage3) { 
     1570                                return $stage3; 
     1571                        } 
     1572 
     1573                        // <A> links to feeds on external servers ending in ".rss", ".rdf", ".xml", or ".atom" 
     1574                        $stage4 = $this->check_link_extension($this->elsewhere); 
     1575                        if ($stage4) { 
     1576                                return $stage4; 
     1577                        } 
     1578 
     1579                        // <A> links to feeds on external servers containing "rss", "rdf", "xml", or "atom" 
     1580                        $stage5 = $this->check_link_body($this->elsewhere); 
     1581                        if ($stage5) { 
     1582                                return $stage5; 
     1583                        } 
     1584                } 
     1585 
     1586                return false; 
     1587        } 
     1588 
     1589        function check_link_elements($data) { 
     1590                if (preg_match_all('/<link (.*)>/siU', $data, $matches)) { 
     1591                        foreach($matches[1] as $match) { 
     1592                                if (preg_match('/type=[\'|"]?(application\/rss\+xml|application\/atom\+xml|application\/rdf\+xml|application\/xml\+rss|application\/xml\+atom|application\/xml\+rdf|application\/xml|application\/x\.atom\+xml|text\/xml)[\'|"]?/iU', $match, $type)) { 
     1593                                        $href = $this->get_attribute($match, 'href'); 
     1594                                        if (!empty($href[1])) { 
     1595                                                $href = $this->absolutize_url($href[1], $this->parsed_url); 
     1596                                                if ($this->is_feed($href)) { 
     1597                                                        return $href; 
     1598                                                } 
     1599                                        } 
     1600                                } 
     1601                        } 
     1602                } else return false; 
     1603        } 
     1604 
     1605        function check_link_extension($array) { 
     1606                foreach ($array as $value) { 
     1607                        $parsed = @parse_url($value); 
     1608                        if (isset($parsed['path'])) { 
     1609                                $ext = strtolower(pathinfo($parsed['path'], PATHINFO_EXTENSION)); 
     1610                                if (($ext == 'rss' || $ext == 'rdf' || $ext == 'xml' || $ext == 'atom') && $this->is_feed($value)) { 
     1611                                        return $this->absolutize_url($value, $this->parsed_url); 
     1612                                } 
     1613                        } 
     1614                } 
     1615                return false; 
     1616        } 
     1617 
     1618        function check_link_body($array) { 
     1619                foreach ($array as $value) { 
     1620                        $value2 = @parse_url($value); 
     1621                        if (!empty($value2['path'])) { 
     1622                                if (strlen(pathinfo($value2['path'], PATHINFO_EXTENSION)) > 0) { 
     1623                                        $value3 = substr_replace($value, '', strpos($value, $value2['path'])+strpos($value2['path'], pathinfo($value2['path'], PATHINFO_EXTENSION))-1, strlen(pathinfo($value2['path'], PATHINFO_EXTENSION))+1); 
     1624                                } else { 
     1625                                        $value3 = $value; 
     1626                                } 
     1627                                if ((stristr($value3, 'rss') || stristr($value3, 'rdf') || stristr($value3, 'xml') || stristr($value3, 'atom') || stristr($value3, 'feed')) && $this->is_feed($value)) { 
     1628                                        return $this->absolutize_url($value, $this->parsed_url); 
     1629                                } 
     1630                        } 
     1631                } 
     1632                return false; 
     1633        } 
     1634 
     1635        function get_links($data) { 
     1636                if (preg_match_all('/href="(.*)"/iU', $data, $matches)) { 
     1637                        $this->parse_links($matches); 
     1638                } 
     1639                if (preg_match_all('/href=\'(.*)\'/iU', $data, $matches)) { 
     1640                        $this->parse_links($matches); 
     1641                } 
     1642                if (preg_match_all('/href=(.*)[ |\/|>]/iU', $data, $matches)) { 
     1643                        foreach ($matches[1] as $key => $value) { 
     1644                                if (substr($value, 0, 1) == '"' || substr($value, 0, 1) == "'") { 
     1645                                        unset($matches[1][$key]); 
     1646                                } 
     1647                        } 
     1648                        $this->parse_links($matches); 
     1649                } 
     1650                if (!empty($this->local) || !empty($this->elsewhere)) { 
     1651                        $this->local = array_unique($this->local); 
     1652                        $this->elsewhere = array_unique($this->elsewhere); 
     1653                        return true; 
     1654                } else return false; 
     1655        } 
     1656 
     1657        function parse_links($matches) { 
     1658                foreach ($matches[1] as $match) { 
     1659                        if (strtolower(substr($match, 0, 11)) != 'javascript:') { 
     1660                                $parsed = @parse_url($match); 
     1661                                if (!isset($parsed['host']) || $parsed['host'] == $this->parsed_url['host']) { 
     1662                                        $this->local[] = $this->absolutize_url($match, $this->parsed_url); 
     1663                                } else { 
     1664                                        $this->elsewhere[] = $this->absolutize_url($match, $this->parsed_url); 
     1665                                } 
     1666                        } 
     1667                } 
     1668        } 
     1669 
     1670        function is_feed($data, $is_url = true) { 
     1671                if ($is_url) { 
     1672                        $data = $this->get_file($data); 
     1673                } 
     1674                if (((stristr($data, '<rss') || preg_match('/<([a-z0-9]+\:)?RDF/mi', $data)) && (preg_match('/<([a-z0-9]+\:)?channel/mi', $data) || preg_match('/<([a-z0-9]+\:)?item/mi', $data))) || (preg_match('/<([a-z0-9]+\:)?feed/mi', $data) && (preg_match('/<([a-z0-9]+\:)?author/mi', $data) || preg_match('/<([a-z0-9]+\:)?entry/mi', $data)))) { 
     1675                        return true; 
     1676                } else { 
     1677                        return false; 
     1678                } 
     1679        } 
     1680 
     1681        function absolutize_url($href, $location) { 
     1682                @$href_parts = parse_url($href); 
     1683                if (!empty($href_parts['scheme'])) { 
     1684                        return $href; 
     1685                } else { 
     1686                        if (isset($location['host'])) { 
     1687                                $full_url = $location['scheme'] . '://' . $location['host']; 
     1688                        } else { 
     1689                                $full_url = ''; 
     1690                        } 
     1691                        if (isset($location['port'])) { 
     1692                                $full_url .= ':' . $location['port']; 
     1693                        } 
     1694                        if (!empty($href_parts['path'])) { 
     1695                                if (substr($href_parts['path'], 0, 1) == '/') { 
     1696                                        $full_url .= $href_parts['path']; 
     1697                                } else if (!empty($location['path'])) { 
     1698                                        $full_url .= dirname($location['path'] . 'a') . '/' . $href_parts['path']; 
     1699                                } else { 
     1700                                        $full_url .= $href_parts['path']; 
     1701                                } 
     1702                        } else if (!empty($location['path'])) { 
     1703                                $full_url .= $location['path']; 
     1704                        } else { 
     1705                                $full_url .= '/'; 
     1706                        } 
     1707                        if (!empty($href_parts['query'])) { 
     1708                                $full_url .= '?' . $href_parts['query']; 
     1709                        } else if (!empty($location['query'])) { 
     1710                                $full_url .= '?' . $location['query']; 
     1711                        } 
     1712                        if (!empty($href_parts['fragment'])) { 
     1713                                $full_url .= '#' . $href_parts['fragment']; 
     1714                        } else if (!empty($location['fragment'])) { 
     1715                                $full_url .= '#' . $location['fragment']; 
     1716                        } 
     1717                        return $full_url; 
     1718                } 
     1719        } 
     1720 
     1721 
     1722 
     1723 
     1724        /**************************************************** 
     1725        DISPLAY IMAGES 
     1726        Some websites have a setting that blocks images from being loaded  
     1727        into other pages.  This gets around those blocks by spoofing the referrer. 
     1728        ****************************************************/ 
     1729        function display_image($image_url) { 
     1730                $image = $this->get_file($image_url,true); 
     1731                $suffix = pathinfo($image_url, PATHINFO_EXTENSION); 
     1732 
     1733                switch($suffix) { 
     1734                        case 'bmp': 
     1735                                $mime='image/bmp'; 
     1736                                break; 
     1737                        case 'gif': 
     1738                                $mime='image/gif'; 
     1739                                break; 
     1740                        case 'ico': 
     1741                                $mime='image/icon'; 
     1742                                break; 
     1743                        case 'jpe': 
     1744                        case 'jpg': 
     1745                        case 'jpeg': 
     1746                                $mime='image/jpeg'; 
     1747                                break; 
     1748                        case 'jfif': 
     1749                                $mime='image/pipeg'; 
     1750                                break; 
     1751                        case 'png': 
     1752                                $mime='image/png'; 
     1753                                break; 
     1754                        case 'tif': 
     1755                        case 'tiff': 
     1756                                $mime='image/tiff'; 
     1757                                break; 
     1758                        default: 
     1759                                $mime='image'; 
     1760                } 
     1761 
     1762                header('Content-type: ' . $mime); 
     1763                echo $image; 
     1764                //echo $image_url; 
     1765                exit; 
     1766        } 
     1767 
     1768 
     1769 
     1770 
     1771        /**************************************************** 
     1772        DELETE OUTDATED CACHE FILES 
     1773        Copyright 2004 by "adam at roomvoter dot com". This material  
     1774        may be distributed only subject to the terms and conditions set  
     1775        forth in the Open Publication License, v1.0 or later (the latest  
     1776        version is presently available at http://www.opencontent.org/openpub/). 
     1777        This function deletes cache files that have not been used in a hour. 
     1778        ****************************************************/ 
     1779        function clear_cache($path, $max_minutes=60) { 
     1780                if (is_dir($path) ) { 
     1781                        $handle = opendir($path); 
     1782                        while (false !== ($file = readdir($handle))) { 
     1783                                if ($file != '.' && $file != '..' && pathinfo($file, PATHINFO_EXTENSION) == 'spc') { 
     1784                                        $diff = (time() - filemtime("$path/$file"))/60; 
     1785                                        if ($diff > $max_minutes) unlink("$path/$file"); 
     1786                                } 
     1787                        } 
     1788                        closedir($handle); 
     1789                } 
     1790        } 
     1791 
     1792 
     1793 
     1794 
     1795        /**************************************************** 
     1796        OPENS A FILE, WITH EITHER FOPEN OR CURL 
     1797        ****************************************************/ 
     1798        function get_file($url,$spoof_referer) { 
     1799                if ((substr($url, 0, 7) == 'http://' || substr($url, 0, 8) == 'https://') && extension_loaded('curl')) { 
     1800                        $gch = curl_init(); 
     1801                        curl_setopt ($gch, CURLOPT_URL, $url); 
     1802                        curl_setopt ($gch, CURLOPT_HEADER, 0); 
     1803                        curl_setopt ($gch, CURLOPT_FOLLOWLOCATION, 1); 
     1804                        curl_setopt ($gch, CURLOPT_TIMEOUT, 10); 
     1805                        curl_setopt ($gch, CURLOPT_RETURNTRANSFER, 1); 
     1806                        if( $spoof_referer ) { 
     1807                                curl_setopt ($gch, CURLOPT_REFERER, $url); 
     1808                        } 
     1809                        curl_setopt ($gch, CURLOPT_USERAGENT, $this->useragent); 
     1810                        if( $this->http_proxy ) { 
     1811                                curl_setopt ($gch, CURLOPT_PROXY, $this->http_proxy); 
     1812                                $http_headers = array("Cache-Control: must-revalidate"); 
     1813                                curl_setopt ($gch, CURLOPT_HTTPHEADER, $http_headers); 
     1814                        } 
     1815                        $data = curl_exec ($gch); 
     1816                        curl_close ($gch); 
     1817                } else { 
     1818                        $old_ua=''; 
     1819                        if (function_exists('ini_get')) $old_ua = ini_get('user_agent'); 
     1820                        if (function_exists('ini_set')) ini_set('user_agent', $this->useragent); 
     1821                        if ($fp = fopen($url, 'r')) { 
     1822                                stream_set_blocking($fp, false); 
     1823                                stream_set_timeout($fp, 10); 
     1824                                $status = socket_get_status($fp); 
     1825                                $data = ''; 
     1826                                while (!feof($fp) && !$status['timed_out'])     { 
     1827                                        $data .= fread($fp, 2048); 
     1828                                        $status = socket_get_status($fp); 
     1829                                } 
     1830                                if ($status['timed_out']) 
     1831                                        return false; 
     1832                                fclose($fp); 
     1833                        } else return false; 
     1834                        if (function_exists('ini_set')) ini_set('user_agent', $old_ua); 
     1835                } 
     1836                return $data; 
     1837        } 
     1838 
     1839 
     1840 
     1841 
     1842        /**************************************************** 
     1843        CHECKS IF A FILE IS WRITEABLE, OR CREATEABLE 
     1844        ****************************************************/ 
     1845        function is_writeable_createable($file) { 
     1846                if (file_exists($file)) 
     1847                        return is_writeable($file); 
     1848                else 
     1849                        return is_writeable(dirname($file)); 
     1850        } 
     1851 
     1852 
     1853 
     1854 
     1855        /**************************************************** 
     1856        GET ATTRIBUTE 
     1857        ****************************************************/ 
     1858        function get_attribute($data, $attribute_name) { 
     1859                if (preg_match("/$attribute_name='(.*)'/iU", $data, $match)) { 
     1860                        return $match; 
     1861                } else if (preg_match("/$attribute_name=\"(.*)\"/iU", $data, $match)) { 
     1862                        return $match; 
     1863                } else if (preg_match("/$attribute_name=(.*)[ |\/|>]/iU", $data, $match)) { 
     1864                        return $match; 
     1865                } 
     1866        } 
     1867 
     1868 
     1869 
     1870 
     1871        /**************************************************** 
     1872        CALLBACK FUNCTION TO DEAL WITH CDATA WITHIN CDATA 
     1873        ****************************************************/ 
     1874        function cdata_in_cdata($match) { 
     1875                $match[3] = preg_replace_callback('/<!\[CDATA\[(.*)\]\]>/msiU', array(&$this, 'real_cdata_in_cdata'), $match[3]); 
     1876                return "<$match[1]$match[2]><![CDATA[$match[3]]]></$match[1]>"; 
     1877        } 
     1878 
     1879 
     1880 
     1881 
     1882        /**************************************************** 
     1883        CALLBACK FUNCTION TO REALLY DEAL WITH CDATA WITHIN CDATA 
     1884        ****************************************************/ 
     1885        function real_cdata_in_cdata($match) { 
     1886                return htmlentities($match[1], ENT_NOQUOTES, $this->encoding); 
     1887        } 
     1888 
     1889 
     1890 
     1891 
     1892        /**************************************************** 
     1893        ADD DATA TO XMLDATA 
     1894        ****************************************************/ 
     1895        function do_add_content(&$array, $data) { 
     1896                if ($this->is_first) { 
     1897                        $array['data'] = $data; 
     1898                        $array['attribs'] = $this->attribs; 
     1899                } else $array['data'] .= $data; 
     1900        } 
     1901 
     1902 
     1903 
     1904 
     1905        /**************************************************** 
     1906        PARSE XMLDATA 
     1907        ****************************************************/ 
     1908        function parse_xml_data_array() { 
     1909                // Feed level xml:base 
     1910                if (!empty($this->xmldata['feeddata']['attribs']['XML:BASE'])) { 
     1911                        $this->feed_xmlbase = parse_url($this->xmldata['feeddata']['attribs']['XML:BASE']); 
     1912                } 
     1913                else if (!empty($this->xmldata['feeddata']['attribs'][$this->namespaces['xml'] . ':BASE'])) { 
     1914                        $this->feed_xmlbase = parse_url($this->xmldata['feeddata']['attribs'][$this->namespaces['xml'] . ':BASE']); 
     1915                } 
     1916                else if (substr($this->rss_url, 0, 28) == 'http://feeds.feedburner.com/' && !empty($this->xmldata['info']['link'][0]['data'])) { 
     1917                        $this->feed_xmlbase = parse_url($this->xmldata['info']['link'][0]['data']); 
     1918                } else { 
     1919                        $this->feed_xmlbase = $this->parsed_url; 
     1920                } 
     1921                 
     1922                // Feed Info 
     1923                if (isset($this->xmldata['feedinfo']['type'])) { 
     1924                        $this->data['feedinfo'] = $this->xmldata['feedinfo']; 
     1925                } 
     1926                 
     1927                // Feed Title 
     1928                if (!empty($this->xmldata['info']['title']['data'])) { 
     1929                        $this->data['info']['title'] = $this->sanitise($this->xmldata['info']['title']['data'], $this->xmldata['info']['title']['attribs']); 
     1930                } 
     1931                 
     1932                // Feed Link(s) 
     1933                if (!empty($this->xmldata['info']['link'])) { 
     1934                        foreach ($this->xmldata['info']['link'] as $num => $link) { 
     1935                                if (empty($link['attribs']['REL']) || $link['attribs']['REL'] == 'alternate') { 
     1936                                        if (empty($link['data'])) { 
     1937                                                $this->data['info']['link'][$num] = $this->sanitise($link['attribs']['HREF'], $link['attribs'], true); 
     1938                                        } else { 
     1939                                                $this->data['info']['link'][$num] = $this->sanitise($link['data'], $link['attribs'], true); 
     1940                                        } 
     1941                                } 
     1942                        } 
     1943                } 
     1944                 
     1945                // Feed Description 
     1946                if (!empty($this->xmldata['info']['description']['data'])) { 
     1947                        $this->data['info']['description'] = $this->sanitise($this->xmldata['info']['description']['data'], $this->xmldata['info']['description']['attribs']); 
     1948                } 
     1949                else if (!empty($this->xmldata['info']['dc:description']['data'])) { 
     1950                        $this->data['info']['description'] = $this->sanitise($this->xmldata['info']['dc:description']['data'], $this->xmldata['info']['dc:description']['attribs']); 
     1951                } 
     1952                else if (!empty($this->xmldata['info']['tagline']['data'])) { 
     1953                        $this->data['info']['description'] = $this->sanitise($this->xmldata['info']['tagline']['data'], $this->xmldata['info']['tagline']['attribs']); 
     1954                } 
     1955                else if (!empty($this->xmldata['info']['subtitle']['data'])) { 
     1956                        $this->data['info']['description'] = $this->sanitise($this->xmldata['info']['subtitle']['data'], $this->xmldata['info']['subtitle']['attribs']); 
     1957                } 
     1958                 
     1959                // Feed Language 
     1960                if (!empty($this->xmldata['info']['language']['data'])) { 
     1961                        $this->data['info']['language'] = $this->sanitise($this->xmldata['info']['language']['data'], $this->xmldata['info']['language']['attribs']); 
     1962                } 
     1963                 
     1964                // Feed Copyright 
     1965                if (!empty($this->xmldata['info']['copyright']['data'])) { 
     1966                        $this->data['info']['copyright'] = $this->sanitise($this->xmldata['info']['copyright']['data'], $this->xmldata['info']['copyright']['attribs']); 
     1967                } 
     1968                 
     1969                // Feed Image 
     1970                if (!empty($this->xmldata['info']['image']['title']['data'])) { 
     1971                        $this->data['info']['image']['title'] = $this->sanitise($this->xmldata['info']['image']['title']['data'], $this->xmldata['info']['image']['title']['attribs']); 
     1972                } 
     1973                if (!empty($this->xmldata['info']['image']['url']['data'])) { 
     1974                        $this->data['info']['image']['url'] = $this->sanitise($this->xmldata['info']['image']['url']['data'], $this->xmldata['info']['image']['url']['attribs'], true); 
     1975                } 
     1976                else if (!empty($this->xmldata['info']['logo']['data'])) { 
     1977                        $this->data['info']['image']['url'] = $this->sanitise($this->xmldata['info']['logo']['data'], $this->xmldata['info']['logo']['attribs'], true); 
     1978                } 
     1979                if (!empty($this->xmldata['info']['image']['link']['data'])) { 
     1980                        $this->data['info']['image']['link'] = $this->sanitise($this->xmldata['info']['image']['link']['data'], $this->xmldata['info']['image']['link']['attribs'], true); 
     1981                } 
     1982                if (!empty($this->xmldata['info']['image']['width']['data'])) { 
     1983                        $this->data['info']['image']['width'] = $this->sanitise($this->xmldata['info']['image']['width']['data'], $this->xmldata['info']['image']['width']['attribs']); 
     1984                } 
     1985                if (!empty($this->xmldata['info']['image']['height']['data'])) { 
     1986                        $this->data['info']['image']['height'] = $this->sanitise($this->xmldata['info']['image']['height']['data'], $this->xmldata['info']['image']['height']['attribs']); 
     1987                } 
     1988                 
     1989                // Items 
     1990                if (!empty($this->xmldata['items'])) { 
     1991                        foreach ($this->xmldata['items'] as $num => $item) { 
     1992                                // Item level xml:base 
     1993                                if (!empty($item['attribs']['XML:BASE'])) { 
     1994                                        $this->item_xmlbase = parse_url($this->absolutize_url($item['attribs']['XML:BASE'], $this->feed_xmlbase)); 
     1995                                } 
     1996                                else if (!empty($item['attribs'][$this->namespaces['xml'] . ':BASE'])) { 
     1997                                        $this->item_xmlbase = parse_url($this->absolutize_url($item['attribs'][$this->namespaces['xml'] . ':BASE'], $this->feed_xmlbase)); 
     1998                                } 
     1999                                 
     2000                                // Clear vars 
     2001                                $id = null; 
     2002                                $title = null; 
     2003                                $description = null; 
     2004                                $categories = array(); 
     2005                                $author = array(); 
     2006                                $date = null; 
     2007                                $links = array(); 
     2008                                $enclosures = array(); 
     2009         
     2010                                // Title 
     2011                                if (!empty($item['title']['data'])) { 
     2012                                        $title = $this->sanitise($item['title']['data'], $item['title']['attribs']); 
     2013                                } 
     2014                                else if (!empty($item['dc:title']['data'])) { 
     2015                                        $title = $this->sanitise($item['dc:title']['data'], $item['dc:title']['attribs']); 
     2016                                } 
     2017                                 
     2018                                // Description 
     2019                                if (!empty($item['content']['data'])) { 
     2020                                        $description = $this->sanitise($item['content']['data'], $item['content']['attribs']); 
     2021                                } 
     2022                                else if (!empty($item['encoded']['data'])) { 
     2023                                        $description = $this->sanitise($item['encoded']['data'], $item['encoded']['attribs']); 
     2024                                } 
     2025                                else if (!empty($item['summary']['data'])) { 
     2026                                        $description = $this->sanitise($item['summary']['data'], $item['summary']['attribs']); 
     2027                                } 
     2028                                else if (!empty($item['description']['data'])) { 
     2029                                        $description = $this->sanitise($item['description']['data'], $item['description']['attribs']); 
     2030                                } 
     2031                                else if (!empty($item['dc:description']['data'])) { 
     2032                                        $description = $this->sanitise($item['dc:description']['data'], $item['dc:description']['attribs']); 
     2033                                } 
     2034                                else if (!empty($item['longdesc']['data'])) { 
     2035                                        $description = $this->sanitise($item['longdesc']['data'], $item['longdesc']['attribs']); 
     2036                                } 
     2037                                 
     2038                                // Link 
     2039                                if (!empty($item['link'])) { 
     2040                                        foreach ($item['link'] as $link) { 
     2041                                                if (empty($link['attribs']['REL']) || $link['attribs']['REL'] == 'alternate') { 
     2042                                                        if (empty($link['data'])) { 
     2043                                                                $links[sizeof($links)] = $this->sanitise($link['attribs']['HREF'], $link['attribs'], true); 
     2044                                                        } else { 
     2045                                                                $links[sizeof($links)] = $this->sanitise($link['data'], $link['attribs'], true); 
     2046                                                        } 
     2047                                                } else if ($link['attribs']['REL'] == 'enclosure' && !empty($link['attribs']['HREF'])) { 
     2048                                                        $href = null; 
     2049                                                        $type = null; 
     2050                                                        $length = null; 
     2051                                                        $href = $this->sanitise($link['attribs']['HREF'], $link['attribs'], true); 
     2052                                                        if (!empty($link['attribs']['TYPE'])) { 
     2053                                                                $type = $this->sanitise($link['attribs']['TYPE'], $link['attribs']); 
     2054                                                        } 
     2055                                                        if (!empty($link['attribs']['LENGTH'])) { 
     2056                                                                $length = $this->sanitise($link['attribs']['LENGTH'], $link['attribs']); 
     2057                                                        } 
     2058                                                        $enclosures[] = new SimplePie_Enclosure($href, $type, $length); 
     2059                                                } 
     2060                                        } 
     2061                                } 
     2062                                 
     2063                                // Enclosures 
     2064                                if (!empty($item['enclosure'])) { 
     2065                                        foreach ($item['enclosure'] as $enclosure) { 
     2066                                                if (!empty($enclosure['attribs']['URL'])) { 
     2067                                                        $href = null; 
     2068                                                        $type = null; 
     2069                                                        $length = null; 
     2070                                                        $href = $this->sanitise($enclosure['attribs']['URL'], $enclosure['attribs'], true); 
     2071                                                        if (!empty($enclosure['attribs']['TYPE'])) { 
     2072                                                                $type = $this->sanitise($enclosure['attribs']['TYPE'], $enclosure['attribs']); 
     2073                                                        } 
     2074&nbs