SimplePie::set_raw_data PHP Method

set_raw_data() public method

Allows you to use a string of RSS/Atom data instead of a remote feed. If you have a feed available as a string in PHP, you can tell SimplePie to parse that data string instead of a remote feed. Any set feed URL takes precedence.
See also: set_feed_url()
Since: 1.0 Beta 3
public set_raw_data ( string $data )
$data string RSS or Atom data as a string.
    public function set_raw_data($data)
    {
        $this->raw_data = $data;
    }

Usage Example

Example #1
0
 /**
  * Provided a URL, will return an array representing the feed item for that
  * URL.  A feed item contains the content, url, simplepie object, and failure
  * status for the URL passed.  Handles caching of content requests.
  *
  * @return array
  * @author Jared Lang
  **/
 protected static function __new_feed($url)
 {
     $timer = Timer::start();
     require_once THEME_DIR . '/third-party/simplepie.php';
     $simplepie = null;
     $failed = False;
     $cache_key = 'feedmanager-' . md5($url);
     $content = get_site_transient($cache_key);
     if ($content === False) {
         $content = @file_get_contents($url);
         if ($content === False) {
             $failed = True;
             $content = null;
             error_log('FeedManager failed to fetch data using url of ' . $url);
         } else {
             set_site_transient($cache_key, $content, self::$cache_length);
         }
     }
     if ($content) {
         $simplepie = new SimplePie();
         $simplepie->set_raw_data($content);
         $simplepie->init();
         $simplepie->handle_content_type();
         if ($simplepie->error) {
             error_log($simplepie->error);
             $simplepie = null;
             $failed = True;
         }
     } else {
         $failed = True;
     }
     $elapsed = round($timer->elapsed() * 1000);
     debug("__new_feed: {$elapsed} milliseconds");
     return array('content' => $content, 'url' => $url, 'simplepie' => $simplepie, 'failed' => $failed);
 }
All Usage Examples Of SimplePie::set_raw_data