/**
 * Checks to see if all of the feed url in $check_urls are cached.
 *
 * If $check_urls is empty, look for the rss feed url found in the dashboard
 * widget optios of $widget_id. If cached, call $callback, a function that
 * echoes out output for this widget. If not cache, echo a "Loading..." stub
 * which is later replaced by AJAX call (see top of /wp-admin/index.php)
 *
 * @since unknown
 *
 * @param int $widget_id
 * @param callback $callback
 * @param array $check_urls RSS feeds
 * @return bool False on failure. True on success.
 */
function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array() ) {
	$loading = '<p class="widget-loading">' . __( 'Loading&#8230;' ) . '</p>';

	if ( empty($check_urls) ) {
		$widgets = get_option( 'dashboard_widget_options' );
		if ( empty($widgets[$widget_id]['url']) ) {
			echo $loading;
			return false;
		}
		$check_urls = array( $widgets[$widget_id]['url'] );
	}


	require_once( ABSPATH . WPINC . '/rss.php' );
	init(); // initialize rss constants

	$cache = new RSSCache( MAGPIE_CACHE_DIR, MAGPIE_CACHE_AGE );

	foreach ( $check_urls as $check_url ) {
		$status = $cache->check_cache( $check_url );
		if ( 'HIT' !== $status ) {
			echo $loading;
			return false;
		}
	}

	if ( $callback && is_callable( $callback ) ) {
		$args = array_slice( func_get_args(), 2 );
		array_unshift( $args, $widget_id );
		call_user_func_array( $callback, $args );
	}

	return true;
}
 /**
  * Build Magpie object based on RSS from URL.
  *
  * @since 1.5.0
  * @package External
  * @subpackage MagpieRSS
  *
  * @param string $url URL to retrieve feed
  * @return bool|MagpieRSS false on failure or MagpieRSS object on success.
  */
 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 {
         // Flow
         // 1. check cache
         // 2. if there is a hit, make sure its 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;
             }
         }
         $resp = _fetch_remote_file($url, $request_headers);
         if (isset($resp) and $resp) {
             if ($resp->status == '304') {
                 // we have the most current copy
                 if (MAGPIE_DEBUG > 1) {
                     debug("Got 304 for {$url}");
                 }
                 // reset cache on 304 (at minutillo insistent prodding)
                 $cache->set($url, $rss);
                 return $rss;
             } elseif (is_success($resp->status)) {
                 $rss = _response_to_rss($resp);
                 if ($rss) {
                     if (MAGPIE_DEBUG > 1) {
                         debug("Fetch successful");
                     }
                     // add object to cache
                     $cache->set($url, $rss);
                     return $rss;
                 }
             } else {
                 $errormsg = "Failed to fetch {$url}. ";
                 if ($resp->error) {
                     # compensate for Snoopy's annoying habbit to tacking
                     # on '\n'
                     $http_error = substr($resp->error, 0, -2);
                     $errormsg .= "(HTTP Error: {$http_error})";
                 } else {
                     $errormsg .= "(HTTP Response: " . $resp->response_code . ')';
                 }
             }
         } else {
             $errormsg = "Unable to retrieve RSS file for unknown reasons.";
         }
         // else fetch failed
         // attempt to return cached object
         if ($rss) {
             if (MAGPIE_DEBUG) {
                 debug("Returning STALE object for {$url}");
             }
             return $rss;
         }
         // else we totally failed
         // error( $errormsg );
         return false;
     }
     // end if ( !MAGPIE_CACHE_ON ) {
 }
 function fetch_request($request)
 {
     global $CFG;
     make_upload_directory('/cache/youtube');
     $cache = new RSSCache($CFG->dataroot . '/cache/youtube', YOUTUBE_CACHE_EXPIRATION);
     $cache_status = $cache->check_cache($request);
     if ($cache_status == 'HIT') {
         $cached_response = $cache->get($request);
         $xmlobj = XML_unserialize($cached_response);
         return $this->render_video_list($xmlobj);
     }
     if ($cache_status == 'STALE') {
         $cached_response = $cache->get($request);
     }
     $response = download_file_content($request);
     if (empty($response)) {
         $response = $cached_response;
     } else {
         $cache->set($request, $response);
     }
     $xmlobj = XML_unserialize($response);
     return $this->render_video_list($xmlobj);
 }
 function fetch_request($request)
 {
     global $CFG;
     make_upload_directory('/cache/flickr');
     $cache = new RSSCache($CFG->dataroot . '/cache/flickr', FLICKR_CACHE_EXPIRATION);
     $cache_status = $cache->check_cache($request);
     if ($cache_status == 'HIT') {
         $cached_response = $cache->get($request);
         return $cached_response;
     }
     if ($cache_status == 'STALE') {
         $cached_response = $cache->get($request);
     }
     $response = download_file_content($request);
     if (empty($response)) {
         $response = $cached_response;
     } else {
         $cache->set($request, $response);
     }
     return $response;
 }
 function fetch_request($request)
 {
     global $CFG;
     make_upload_directory('/cache/youtube');
     $cache = new RSSCache($CFG->dataroot . '/cache/youtube', YOUTUBE_CACHE_EXPIRATION);
     $cache_status = $cache->check_cache($request);
     if ($cache_status == 'HIT') {
         $cached_response = $cache->get($request);
         // TODO: Stop using phpxml, switching to DOM/Simple for this
         // TODO: Drop lib/phpxml if 0 uses in core/contrib
         $xmlobj = XML_unserialize($cached_response);
         return $this->render_video_list($xmlobj);
     }
     if ($cache_status == 'STALE') {
         $cached_response = $cache->get($request);
     }
     $response = download_file_content($request);
     if (empty($response)) {
         $response = $cached_response;
     } else {
         $cache->set($request, $response);
     }
     // TODO: Stop using phpxml, switching to DOM/Simple for this
     // TODO: Drop lib/phpxml if 0 uses in core/contrib
     $xmlobj = XML_unserialize($response);
     return $this->render_video_list($xmlobj);
 }
 /**
  * Check cache hit
  */
 function checkCacheHit()
 {
     ilExternalFeed::_createCacheDirectory();
     $cache = new RSSCache(MAGPIE_CACHE_DIR, MAGPIE_CACHE_AGE);
     $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
     $cache_key = $this->getUrl() . MAGPIE_OUTPUT_ENCODING;
     if (!$cache->ERROR) {
         // return cache HIT, MISS, or STALE
         $cache_status = $cache->check_cache($cache_key);
     }
     // if object cached, and cache is fresh, return cached obj
     if ($cache_status == 'HIT') {
         return true;
     }
     return false;
 }
<div class="rss_header">
\t<span class="rss_date">[+date+]</span>
\t<a href="[+link+]">[+title+]</a> из <a href="[+feed_link+]">[+feed_description+]</a>
</div>
<div class="rss_text">[+text+]</div>
<a href="[+link+]">[+more+]</a>
</div>
EOF;
$output = '';
$basePath = $modx->config['base_path'];
//Work with cache
if ($cacheAge) {
    define(CACHE_DIR, $basePath . $modx->getCachePath());
    define(CACHE_AGE, $cacheAge);
    require_once $basePath . 'manager/media/rss/rss_cache.inc';
    $cache = new RSSCache(CACHE_DIR, CACHE_AGE);
    $cache_status = $cache->check_cache($url);
    if ($cache_status == 'HIT') {
        //have fresh cache
        $output = $cache->get($baseurl);
        //uncomment this if you want to see and control cache work
        //RSS::_log('FROM CACHE');
    }
}
if ($output == '') {
    //cache is off OR have no cache OR it's STALE
    //use system class Snoopy
    //this class is used in manager panel to show news on startpage.
    require_once $basePath . 'manager/media/rss/extlib/Snoopy.class.inc';
    $client = new Snoopy();
    $client->agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 GTB7.1';