本文整理汇总了PHP中SimplePie::set_raw_data方法的典型用法代码示例。如果您正苦于以下问题:PHP SimplePie::set_raw_data方法的具体用法?PHP SimplePie::set_raw_data怎么用?PHP SimplePie::set_raw_data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimplePie
的用法示例。
在下文中一共展示了SimplePie::set_raw_data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __new_feed
/**
* 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);
}
示例2: simplepie
public static function simplepie($feed_url = NULL)
{
if (!$feed_url) {
return false;
}
$data = new SimplePie();
//*******************************
// Convert To GeoRSS feed
// To Disable Uncomment these 3 lines
//*******************************
$geocoder = new Geocoder();
$georss_feed = $geocoder->geocode_feed($feed_url);
if ($georss_feed == false or empty($georss_feed)) {
// Our RSS feed pull failed, so let's grab the original RSS feed
$data->set_feed_url($feed_url);
} else {
// Converting our feed to GeoRSS was successful, use that data
$data->set_raw_data($georss_feed);
}
// Uncomment Below to disable geocoding
//$data->set_feed_url( $feed_url );
//*******************************
$data->enable_cache(false);
$data->enable_order_by_date(true);
$data->init();
$data->handle_content_type();
return $data;
}
示例3: SimplePie
function rss_to_activity_streams($data)
{
//
$feed = new SimplePie();
$feed->set_raw_data($data);
//
unset($data);
//
$feed->set_stupidly_fast(true);
$feed->init();
$feed->handle_content_type();
//
$id = md5($url);
$title = 'submit';
$link = 'http://' . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
$activityStream = new ActivityStreamsDoc($id, $title, $link);
//
foreach ($feed->get_items() as $item) {
$author = $item->get_author();
if (!$author) {
$author = $feed->get_author();
}
//
$activityStream->entry($item->get_id(), date("r", $item->get_date()), $author ? $author->get_name() : null, $author ? $author->get_link() : null, $item->get_title(), $item->get_permalink(), $item->get_description());
}
return $activityStream;
}
示例4: __new_feed
/**
* 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)
{
require_once ABSPATH . '/wp-includes/class-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;
}
return array('content' => $content, 'url' => $url, 'simplepie' => $simplepie, 'failed' => $failed);
}
示例5: feed
function feed()
{
$feed = new SimplePie();
$feed->set_raw_data($this->data);
$feed->enable_cache(false);
$feed->init();
return $feed;
}
示例6: setUp
public function setUp()
{
parent::setUp();
$rss_sample = file_get_contents(dirname(__FILE__) . '/test-assets/rss');
$sampleFeed = new SimplePie();
$sampleFeed->set_raw_data($rss_sample);
$sampleFeed->init();
self::$sampleFeed = $sampleFeed;
$this->testFeedUrl = 'http://www.theguardian.com/world/rss';
}
示例7: parseFeed
static function parseFeed($url, $omitDB = false)
{
global $wgOut;
//reset array
self::$data = array('feedTitle' => '', 'images' => array());
if (!$omitDB) {
//check DB for this URL - we might have it already (background task will refresh it)
$data = self::getDataByUrl($url);
}
if ($omitDB || is_null($data)) {
//no data in DB - fetch from feed
$itemCount = 0;
$rssContent = Http::get($url);
$feed = new SimplePie();
$feed->set_raw_data($rssContent);
$feed->init();
self::$data['feedTitle'] = $feed->get_title();
foreach ($feed->get_items() as $item) {
$enclosures = $item->get_enclosures();
$enclosuresFound = false;
//we have enclosures - use them instead of content of feed (usually there are bigger image while content uses thumbnails)
if (!is_null($enclosures)) {
foreach ($enclosures as $enclosure) {
$type = $enclosure->get_type();
if (!empty($type) && substr($type, 0, 6) === 'image/') {
self::$data['images'][] = array('src' => $enclosure->get_link(), 'caption' => $item->get_title(), 'link' => $item->get_link());
$enclosuresFound = true;
break;
//one image per feed
}
}
}
//if enclosures has not been found or doesn't contain any images - use regular method
if (!$enclosuresFound) {
//look for <img /> tags
$description = $item->get_description();
preg_match('/<img .*?src=([\'"])(.*?\\.(?:jpg|jpeg|gif|png))\\1/', $description, $matches);
if (!empty($matches[2])) {
self::$data['images'][] = array('src' => $matches[2], 'caption' => $item->get_title(), 'link' => $item->get_link());
}
}
if (count(self::$data['images']) >= 20 || ++$itemCount > 50) {
break;
//take up to 20 images, from up to 50 articles.
}
}
//store data in DB only if valid rss (images found)
if (count(self::$data['images'])) {
self::setData($url, self::$data);
}
} else {
self::$data = $data;
}
return self::$data;
}
示例8: loadStringIntoSimplePieObject
public function loadStringIntoSimplePieObject($xmldata)
{
// Create a new instance of the SimplePie object
$feed = new SimplePie();
$feed->enable_cache(false);
// $feed->set_feed_url('http://simplepie.org/blog/feed/');
$feed->set_raw_data($xmldata);
$feed->init();
$feed->handle_content_type();
return $feed;
}
示例9: checkFromTemplate
/**
* Run a test using a sprintf template and data
*
* @param string $template
*/
protected function checkFromTemplate($template, $data, $expected)
{
if (!is_array($data)) {
$data = array($data);
}
$xml = vsprintf($template, $data);
$feed = new SimplePie();
$feed->set_raw_data($xml);
$feed->enable_cache(false);
$feed->init();
return $feed;
}
示例10: powerpress_get_news
function powerpress_get_news($feed_url, $limit = 10)
{
include_once ABSPATH . WPINC . '/feed.php';
$rss = fetch_feed($feed_url);
// If feed doesn't work...
if (is_wp_error($rss)) {
require_once ABSPATH . WPINC . '/class-feed.php';
// Try fetching the feed using CURL directly...
$content = powerpress_remote_fopen($feed_url, false, array(), 3, false, true);
if (!$content) {
return false;
}
// Load the content in a fetch_feed object...
$rss = new SimplePie();
$rss->set_sanitize_class('WP_SimplePie_Sanitize_KSES');
// We must manually overwrite $feed->sanitize because SimplePie's
// constructor sets it before we have a chance to set the sanitization class
$rss->sanitize = new WP_SimplePie_Sanitize_KSES();
$rss->set_cache_class('WP_Feed_Cache');
$rss->set_file_class('WP_SimplePie_File');
$rss->set_raw_data($content);
$rss->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $feed_url));
do_action_ref_array('wp_feed_options', array(&$rss, $feed_url));
$rss->init();
$rss->set_output_encoding(get_option('blog_charset'));
$rss->handle_content_type();
if ($rss->error()) {
return false;
}
}
$rss_items = $rss->get_items(0, $rss->get_item_quantity($limit));
// If the feed was erroneously
if (!$rss_items) {
$md5 = md5($this->feed);
delete_transient('feed_' . $md5);
delete_transient('feed_mod_' . $md5);
$rss->__destruct();
unset($rss);
$rss = fetch_feed($this->feed);
$rss_items = $rss->get_items(0, $rss->get_item_quantity($num));
$rss->__destruct();
unset($rss);
}
return $rss_items;
}
示例11: fetch_feed
/**
* Fetch feed w/o caching.
*
* @param int $limit Number of entries to fetch.
* @param string $feed URI of RSS feed to import.
*
* @return array List of feed entries.
*/
public function fetch_feed($limit, $feed)
{
if (!class_exists('SimplePie_File')) {
include_once ABSPATH . WPINC . DIRECTORY_SEPARATOR . 'SimplePie' . DIRECTORY_SEPARATOR . 'File.php';
}
$result = array();
try {
$file = new SimplePie_File($feed);
$feed = new SimplePie();
$feed->set_raw_data($file->body);
$feed->init();
if (!is_wp_error($feed)) {
$result = $feed->get_items(0, $limit);
}
} catch (Exception $exception) {
}
// discard
return $result;
}
示例12: parseFeed
/**
* Given the content of a page and its URL, returns an array of FeedItem objects (or false on failure)
* @param $content
* @param $url
* @return array|bool
*/
function parseFeed($content, $url)
{
// Check for microformats
if ($html = @\DOMDocument::loadHTML($content)) {
try {
$parser = new \Mf2\Parser($html, $url);
$parsed_content = $parser->parse();
return $this->mf2FeedToFeedItems($parsed_content, $url);
} catch (\Exception $e) {
return false;
}
}
// Try XML (RSS or Atom)
$xml_parser = new \SimplePie();
$xml_parser->set_raw_data($content);
$xml_parser->init();
if (!$xml_parser->error()) {
return $this->xmlFeedToFeedItems($xml_parser->get_items(), $url);
}
return false;
}
示例13: simplepie
public static function simplepie($feed_url = NULL)
{
if (!$feed_url) {
return false;
}
$data = new SimplePie();
//*******************************
// Convert To GeoRSS feed
// To Disable Uncomment these 3 lines
//*******************************
$geocoder = new Geocoder();
$georss_feed = $geocoder->geocode_feed($feed_url);
$data->set_raw_data($georss_feed);
// Uncomment Below to disable geocoding
//$data->set_feed_url( $feed_url );
//*******************************
$data->enable_cache(false);
$data->enable_order_by_date(true);
$data->init();
$data->handle_content_type();
return $data;
}
示例14: urlencode
/**
* Geonames Feeds GeoCoding (RSS to GEORSS)
* Due to limitations, this returns only 20 items
*
* @param string location / address
* @return string raw georss data
*/
function geocode_feed($feed_url = NULL)
{
$base_url = "http://" . GEOCODER_GEONAMES . "/rssToGeoRSS?";
// Only requests service if we have an user
$geocode_username = Settings_Model::get_setting('feed_geolocation_user');
if ($feed_url && !empty($geocode_username)) {
// First check to make sure geonames webservice is running
$geonames_status = @remote::status($base_url);
if ($geonames_status == "200") {
// Successful
$request_url = $base_url . "&feedUrl=" . urlencode($feed_url) . "&username=" . $geocode_username;
} else {
// Down perhaps?? Use direct feed
$request_url = $feed_url;
}
$request = new HttpClient($request_url);
if (!($georss = $request->execute($request_url))) {
// If the request failed, something may be wrong with the GEOCODER_GEONAMES service
return false;
}
//$georss = utf8_encode($georss);
// Lez verify this we got a good reply from the geocoder before proceeding
$data = new SimplePie();
$data->set_raw_data($georss);
$data->init();
$data->handle_content_type();
// Feed no good - get outta here!
if ($data->error()) {
Kohana::log('error', $data->error() . $request_url);
return false;
}
return trim($georss);
} else {
return false;
}
}
示例15: UpdateFeeds
/**
* Update the feeds
*
*/
function UpdateFeeds()
{
if (!is_dir('./tmp')) {
mkdir('./tmp', 0777);
}
$feedData = array();
$lock = Lock("Update Feeds", false);
if (isset($lock)) {
// load the list of feeds
require_once './settings/feeds.inc';
require_once './lib/simplepie.inc';
// loop through and update each one
foreach ($feeds as $category => &$feedList) {
$feedData[$category] = array();
foreach ($feedList as $feedSource => $feedUrl) {
$feedUrl = trim($feedUrl);
if (strlen($feedUrl)) {
$feed = new SimplePie();
if ($feed) {
$rawFeed = trim(http_fetch($feedUrl));
$feed->set_raw_data($rawFeed);
$feed->enable_cache(false);
$feed->init();
// try sanitizing the data if we have a problem parsing the feed
if (strlen($feed->error())) {
FixFeed($rawFeed);
$feed->set_raw_data($rawFeed);
$feed->enable_cache(false);
$feed->init();
}
foreach ($feed->get_items() as $item) {
$dateStr = $item->get_date(DATE_RSS);
if ($dateStr && strlen($dateStr)) {
$date = strtotime($dateStr);
if ($date) {
// only include articles from the last 30 days
$now = time();
$elapsed = 0;
if ($now > $date) {
$elapsed = $now - $date;
}
$days = (int) ($elapsed / 86400);
if ($days <= 30) {
// make sure we don't have another article from the exact same time
while (isset($feedData[$category][$date])) {
$date++;
}
$feedData[$category][$date] = array('source' => $feedSource, 'title' => $item->get_title(), 'link' => urldecode($item->get_permalink()), 'date' => $dateStr);
}
}
}
$item->__destruct();
}
$feed->__destruct();
unset($feed);
}
}
}
if (count($feedData[$category])) {
krsort($feedData[$category]);
}
}
// save out the feed data
file_put_contents('./tmp/feeds.dat', json_encode($feedData));
Unlock($lock);
}
}