IP : 3.134.117.239Hostname : server86.web-hosting.comKernel : Linux server86.web-hosting.com 4.18.0-513.18.1.lve.el8.x86_64 #1 SMP Thu Feb 22 12:55:50 UTC 2024 x86_64Disable Function : None :) OS : Linux
PATH:
/
home/
./
servlmvm/
public_html/
wp-includes/
rss.php/
/
class MagpieRSS { var $parser; var $current_item = array(); // item currently being parsed var $items = array(); // collection of parsed items var $channel = array(); // hash of channel fields var $textinput = array(); var $image = array(); var $feed_type; var $feed_version;
// parser variables var $stack = array(); // parser stack var $inchannel = false; var $initem = false; var $incontent = false; // if in Atom <content mode="xml"> field var $intextinput = false; var $inimage = false; var $current_field = ''; var $current_namespace = false;
//var $ERROR = "";
var $_CONTENT_CONSTRUCTS = array('content', 'summary', 'info', 'title', 'tagline', 'copyright');
/** * PHP5 constructor. */ function __construct( $source ) {
# Check if PHP xml isn't compiled # if ( ! function_exists('xml_parser_create') ) { wp_trigger_error( '', "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ); return; }
$parser = xml_parser_create();
$this->parser = $parser;
# pass in parser, and a reference to this object # set up handlers # xml_set_element_handler($this->parser, array( $this, 'feed_start_element' ), array( $this, 'feed_end_element' ) );
// if we're in the default namespace of an RSS feed, // record textinput or image fields elseif ( $this->feed_type == RSS and $this->current_namespace == '' and $el == 'textinput' ) { $this->intextinput = true; }
elseif ( $this->feed_type == RSS and $this->current_namespace == '' and $el == 'image' ) { $this->inimage = true; }
# handle atom content constructs elseif ( $this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) ) { // avoid clashing w/ RSS mod_content if ($el == 'content' ) { $el = 'atom_content'; }
$this->incontent = $el;
}
// if inside an Atom content construct (e.g. content or summary) field treat tags as text elseif ($this->feed_type == ATOM and $this->incontent ) { // if tags are inlined, then flatten $attrs_str = join(' ', array_map(array('MagpieRSS', 'map_attrs'), array_keys($attrs), array_values($attrs) ) );
$this->append_content( "<$element $attrs_str>" );
array_unshift( $this->stack, $el ); }
// Atom support many links per containing element. // Magpie treats link elements of type rel='alternate' // as being equivalent to RSS's simple link element. // elseif ($this->feed_type == ATOM and $el == 'link' ) { if ( isset($attrs['rel']) and $attrs['rel'] == 'alternate' ) { $link_el = 'link'; } else { $link_el = 'link_' . $attrs['rel']; }
$this->append($link_el, $attrs['href']); } // set stack[0] to current element else { array_unshift($this->stack, $el); } }
function feed_cdata ($p, $text) {
if ($this->feed_type == ATOM and $this->incontent) { $this->append_content( $text ); } else { $current_el = join('_', array_reverse($this->stack)); $this->append($current_el, $text); } }
function feed_end_element ($p, $el) { $el = strtolower($el);
if ( $el == 'item' or $el == 'entry' ) { $this->items[] = $this->current_item; $this->current_item = array(); $this->initem = false; } elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'textinput' ) { $this->intextinput = false; } elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'image' ) { $this->inimage = false; } elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) ) { $this->incontent = false; } elseif ($el == 'channel' or $el == 'feed' ) { $this->inchannel = false; } elseif ($this->feed_type == ATOM and $this->incontent ) { // balance tags properly // note: This may not actually be necessary if ( $this->stack[0] == $el ) { $this->append_content("</$el>"); } else { $this->append_content("<$el />"); }
if ( !function_exists('fetch_rss') ) : /** * Build Magpie object based on RSS from URL. * * @since 1.5.0 * @package External * @subpackage MagpieRSS * * @param string $url URL to retrieve feed. * @return MagpieRSS|false MagpieRSS object on success, false on failure. */ function fetch_rss ($url) { // initialize constants init();
if ( !isset($url) ) { // error("fetch_rss called without a url"); return false; }
// if cache is disabled if ( !MAGPIE_CACHE_ON ) { // fetch file, and parse it $resp = _fetch_remote_file( $url ); if ( is_success( $resp->status ) ) { return _response_to_rss( $resp ); } else { // error("Failed to fetch $url and cache is off"); return false; } } // else cache is ON else { // Flow // 1. check cache // 2. if there is a hit, make sure it's fresh // 3. if cached obj fails freshness check, fetch remote // 4. if remote fails, return stale object, or error
$cache = new RSSCache( MAGPIE_CACHE_DIR, MAGPIE_CACHE_AGE );
if (MAGPIE_DEBUG and $cache->ERROR) { debug($cache->ERROR, E_USER_WARNING); }
$cache_status = 0; // response of check_cache $request_headers = array(); // HTTP headers to send with fetch $rss = 0; // parsed RSS object $errormsg = 0; // errors, if any
if (!$cache->ERROR) { // return cache HIT, MISS, or STALE $cache_status = $cache->check_cache( $url ); }
// if object cached, and cache is fresh, return cached obj if ( $cache_status == 'HIT' ) { $rss = $cache->get( $url ); if ( isset($rss) and $rss ) { $rss->from_cache = 1; if ( MAGPIE_DEBUG > 1) { debug("MagpieRSS: Cache HIT", E_USER_NOTICE); } return $rss; } }
// else attempt a conditional get
// set up headers if ( $cache_status == 'STALE' ) { $rss = $cache->get( $url ); if ( isset($rss->etag) and $rss->last_modified ) { $request_headers['If-None-Match'] = $rss->etag; $request_headers['If-Last-Modified'] = $rss->last_modified; } }
class RSSCache { var $BASE_CACHE; // where the cache files are stored var $MAX_AGE = 43200; // when are files stale, default twelve hours var $ERROR = ''; // accumulate error messages
/*=======================================================================*\ Function: set Purpose: add an item to the cache, keyed on url Input: url from which the rss file was fetched Output: true on success \*=======================================================================*/ function set ($url, $rss) { $cache_option = 'rss_' . $this->file_name( $url );
/*=======================================================================*\ Function: get Purpose: fetch an item from the cache Input: url from which the rss file was fetched Output: cached object on HIT, false on MISS \*=======================================================================*/ function get ($url) { $this->ERROR = ""; $cache_option = 'rss_' . $this->file_name( $url );
if ( ! $rss = get_transient( $cache_option ) ) { $this->debug( "Cache does not contain: $url (cache option: $cache_option)" ); return 0; }
return $rss; }
/*=======================================================================*\ Function: check_cache Purpose: check a url for membership in the cache and whether the object is older then MAX_AGE (ie. STALE) Input: url from which the rss file was fetched Output: cached object on HIT, false on MISS \*=======================================================================*/ function check_cache ( $url ) { $this->ERROR = ""; $cache_option = 'rss_' . $this->file_name( $url );
if ( get_transient($cache_option) ) { // object exists and is current return 'HIT'; } else { // object does not exist return 'MISS'; } }
/*=======================================================================*\ Function: file_name Purpose: map url to location in cache Input: url from which the rss file was fetched Output: a file name \*=======================================================================*/ function file_name ($url) { return md5( $url ); }
if ( !function_exists('wp_rss') ) : /** * Display all RSS items in a HTML ordered list. * * @since 1.5.0 * @package External * @subpackage MagpieRSS * * @param string $url URL of feed to display. Will not auto sense feed URL. * @param int $num_items Optional. Number of items to display, default is all. */ function wp_rss( $url, $num_items = -1 ) { if ( $rss = fetch_rss( $url ) ) { echo '<ul>';
echo '</ul>'; } else { _e( 'An error has occurred, which probably means the feed is down. Try again later.' ); } } endif;
if ( !function_exists('get_rss') ) : /** * Display RSS items in HTML list items. * * You have to specify which HTML list you want, either ordered or unordered * before using the function. You also have to specify how many items you wish * to display. You can't display all of them like you can with wp_rss() * function. * * @since 1.5.0 * @package External * @subpackage MagpieRSS * * @param string $url URL of feed to display. Will not auto sense feed URL. * @param int $num_items Optional. Number of items to display, default is all. * @return bool False on failure. */ function get_rss ($url, $num_items = 5) { // Like get posts, but for RSS $rss = fetch_rss($url); if ( $rss ) { $rss->items = array_slice($rss->items, 0, $num_items); foreach ( (array) $rss->items as $item ) { echo "<li>\n"; echo "<a href='$item[link]' title='$item[description]'>"; echo esc_html($item['title']); echo "</a><br />\n"; echo "</li>\n"; } } else { return false; } } endif;