本文整理汇总了PHP中SimplePie类的典型用法代码示例。如果您正苦于以下问题:PHP SimplePie类的具体用法?PHP SimplePie怎么用?PHP SimplePie使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SimplePie类的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)
{
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);
}
示例2: add
function add($render)
{
$url = $_REQUEST['url'];
require_once 'lib/simplepie/simplepie.inc';
$pie = new SimplePie();
$pie->enable_cache(false);
$pie->set_autodiscovery_level(SIMPLEPIE_LOCATOR_ALL);
$pie->set_feed_url($url);
$pie->init();
$feed_url = $pie->feed_url;
$feed_title = $pie->get_title();
// Save feed to insert into session variables for later insertion into db
// only do this if we found items at the given url. This way we won't
// insert broken urls in doadd(). Also prevents inserting a new feed
// that never gets subscribed to in the following page.
if (count($pie->get_items()) > 0) {
$_SESSION['new_feed_url'] = $feed_url;
$_SESSION['new_feed_name'] = $feed_title;
} else {
$_SESSION['new_feed_url'] = NULL;
$_SESSION['new_feed_name'] = NULL;
}
$render->assign('url', $url);
$render->assign('feed_url', $feed_url);
$render->assign('items', array_slice($pie->get_items(), 0, 5));
$render->assign('feed', $pie);
$render->assign('title', 'Adding Feed');
$render->display('feed_search.tpl');
}
示例3: __construct
/**
* MagpieFromSimplePie constructor
*
* @param SimplePie $pie The feed to convert to MagpieRSS format.
* @param mixed $item
*
* @uses SimplePie::get_items
* @uses MagpieFromSimplePie::processFeedData
* @uses MagpieFromSimplePie::processItemData
* @uses MagpieFromSimplePie::normalize
* @uses MagpieFromSimplePie::is_atom
*/
function __construct($pie, $item = true)
{
$this->pie = $pie;
// item in {NULL, true} = process channel data
if (!is_a($item, 'SimplePie_Item')) {
$this->originals = $this->pie->get_items();
$this->channel = $this->processFeedData($this->pie->data);
} else {
$this->originals = array($item);
$this->channel = NULL;
}
// item in {true, SimplePie_Item} = process item data
if (!is_null($item)) {
foreach ($this->originals as $key => $item) {
$this->items[$key] = $this->processItemData($item->data);
}
} else {
$this->items = NULL;
}
$this->normalize();
// In case anyone goes poking around our private members (uh...)
$this->feed_type = $this->is_atom() ? 'Atom' : 'RSS';
$this->feed_version = $this->feed_version();
$this->encoding = $pie->get_encoding();
}
示例4: fetchfeed
/**
* Fetches the latest entry from the source's feed
**/
function fetchfeed()
{
require_once SIMPLEPIEPATH;
$feed = $this->select();
if (preg_match('/twitter\\.com/', $feed[0]->feed_url) == true) {
$istwitter = 1;
}
$feed_path = $feed[0]->feed_url;
$feed = new SimplePie((string) $feed_path, TEMPLATEPATH . (string) '/app/cache/activity');
SourceAdmin::clean_dir();
$feed->handle_content_type();
if ($feed->data) {
foreach ($feed->get_items() as $entry) {
$name = $stream->title;
$update[]['name'] = (string) $name;
$update[]['title'] = $entry->get_title();
$update[]['link'] = $entry->get_permalink();
$update[]['date'] = strtotime(substr($entry->get_date(), 0, 25));
}
$return = array_slice($update, 0, 5);
// This auto-hyperlinks URLs
$return[1]['title'] = preg_replace('((?:\\S)+://\\S+[[:alnum:]]/?)', '<a href="\\0">\\0</a>', $return[1]['title']);
/**
* If Twitter is the source, then we hyperlink any '@username's
* to that user's Twitter address.
**/
if ($istwitter == 1) {
$return[1]['title'] = preg_replace('/(@)([A-Za-z0-9_-]+)/', '<a href="http://twitter.com/\\2">\\0</a>', $return[1]['title']);
}
return substr($return[1]['title'], 0, 1000) . ' — <a href="' . $return[2]['link'] . '" title="">' . date('g:ia', $return[3]['date']) . '</a>';
} else {
return "Thanks for exploring my world! Can you believe this avatar is talking to you?";
}
}
示例5: load
/**
* Loads a newsfeed object.
* @param string $feed
* @return SimplePie $feed
*/
public function load($feedurl)
{
$feed = new SimplePie();
$feed->set_feed_url($feedurl);
$feed->set_cache_location(DIR_FILES_CACHE);
return $feed;
}
示例6: _createSimplePie
/**
* _createSimplePie
*
* @param string &$feed Params
*
* @return object
*/
private function _createSimplePie(&$feed)
{
include_once JPATH_AUTOTWEET . '/libs/SimplePie_autoloader.php';
// Process the feed with SimplePie
$simplePie = new SimplePie();
$simplePie->set_feed_url($feed->xtform->get('url'));
$simplePie->set_stupidly_fast(true);
$simplePie->enable_order_by_date(true);
if ($feed->xtform->get('encoding', 'utf-8')) {
$simplePie->set_input_encoding($feed->xtform->get('encoding'));
}
if ($feed->xtform->get('force_fsockopen')) {
$simplePie->force_fsockopen(true);
}
$use_sp_cache = EParameter::getComponentParam(CAUTOTWEETNG, 'use_sp_cache', true);
if ($use_sp_cache && is_writable(JPATH_CACHE)) {
$simplePie->set_cache_location(JPATH_CACHE);
$simplePie->enable_cache(true);
} else {
$simplePie->enable_cache(false);
}
$set_sp_timeout = EParameter::getComponentParam(CAUTOTWEETNG, 'set_sp_timeout', 10);
if ($set_sp_timeout) {
$simplePie->set_timeout((int) $set_sp_timeout);
}
$simplePie->init();
return $simplePie;
}
示例7: __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);
}
示例8: import
public function import($forceResync)
{
if (get_option('goodreads_user_id')) {
if (!class_exists('SimplePie')) {
require_once ABSPATH . WPINC . '/class-feed.php';
}
$rss_source = sprintf(self::$apiurl, get_option('goodreads_user_id'));
/* Create the SimplePie object */
$feed = new SimplePie();
/* Set the URL of the feed you're retrieving */
$feed->set_feed_url($rss_source);
/* Tell SimplePie to cache the feed using WordPress' cache class */
$feed->set_cache_class('WP_Feed_Cache');
/* Tell SimplePie to use the WordPress class for retrieving feed files */
$feed->set_file_class('WP_SimplePie_File');
/* Tell SimplePie how long to cache the feed data in the WordPress database */
$feed->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', get_option('reclaim_update_interval'), $rss_source));
/* Run any other functions or filters that WordPress normally runs on feeds */
do_action_ref_array('wp_feed_options', array(&$feed, $rss_source));
/* Initiate the SimplePie instance */
$feed->init();
/* Tell SimplePie to send the feed MIME headers */
$feed->handle_content_type();
if ($feed->error()) {
parent::log(sprintf(__('no %s data', 'reclaim'), $this->shortname));
parent::log($feed->error());
} else {
$data = self::map_data($feed);
parent::insert_posts($data);
update_option('reclaim_' . $this->shortname . '_last_update', current_time('timestamp'));
}
} else {
parent::log(sprintf(__('%s user data missing. No import was done', 'reclaim'), $this->shortname));
}
}
示例9: getFeedParser
/**
* Get a parsed XML Feed Source
*
* @param string $url Url for feed source.
* @param integer $cache_time Time to cache feed for (using internal cache mechanism).
*
* @return mixed SimplePie parsed object on success, false on failure.
*
* @since 12.2
* @deprecated 4.0 Use JFeedFactory($url) instead.
*
* @note In 3.2 will be proxied to JFeedFactory()
*/
public static function getFeedParser($url, $cache_time = 0)
{
JLog::add(__METHOD__ . ' is deprecated. Use JFeedFactory() or supply Simple Pie instead.', JLog::WARNING, 'deprecated');
$cache = JFactory::getCache('feed_parser', 'callback');
if ($cache_time > 0)
{
$cache->setLifeTime($cache_time);
}
$simplepie = new SimplePie(null, null, 0);
$simplepie->enable_cache(false);
$simplepie->set_feed_url($url);
$simplepie->force_feed(true);
$contents = $cache->get(array($simplepie, 'init'), null, false, false);
if ($contents)
{
return $simplepie;
}
JLog::add(JText::_('JLIB_UTIL_ERROR_LOADING_FEED_DATA'), JLog::WARNING, 'jerror');
return false;
}
示例10: compile
/**
* Generate the module
*/
protected function compile()
{
/** @var PageModel $objPage */
global $objPage;
if ($this->rss_template != 'rss_default') {
$this->strTemplate = $this->rss_template;
/** @var FrontendTemplate|object $objTemplate */
$objTemplate = new \FrontendTemplate($this->strTemplate);
$this->Template = $objTemplate;
$this->Template->setData($this->arrData);
}
$this->Template->link = $this->objFeed->get_link();
$this->Template->title = $this->objFeed->get_title();
$this->Template->language = $this->objFeed->get_language();
$this->Template->description = $this->objFeed->get_description();
$this->Template->copyright = $this->objFeed->get_copyright();
// Add image
if ($this->objFeed->get_image_url()) {
$this->Template->image = true;
$this->Template->src = $this->objFeed->get_image_url();
$this->Template->alt = $this->objFeed->get_image_title();
$this->Template->href = $this->objFeed->get_image_link();
$this->Template->height = $this->objFeed->get_image_height();
$this->Template->width = $this->objFeed->get_image_width();
}
// Get the items (see #6107)
$arrItems = array_slice($this->objFeed->get_items(0, intval($this->numberOfItems) + intval($this->skipFirst)), intval($this->skipFirst), intval($this->numberOfItems) ?: null);
$limit = count($arrItems);
$offset = 0;
// Split pages
if ($this->perPage > 0) {
// Get the current page
$id = 'page_r' . $this->id;
$page = \Input::get($id) !== null ? \Input::get($id) : 1;
// Do not index or cache the page if the page number is outside the range
if ($page < 1 || $page > max(ceil(count($arrItems) / $this->perPage), 1)) {
throw new PageNotFoundException('Page not found: ' . \Environment::get('uri'));
}
// Set limit and offset
$offset = ($page - 1) * $this->perPage;
$limit = $this->perPage + $offset;
$objPagination = new \Pagination(count($arrItems), $this->perPage, \Config::get('maxPaginationLinks'), $id);
$this->Template->pagination = $objPagination->generate("\n ");
}
$items = array();
$last = min($limit, count($arrItems)) - 1;
/** @var \SimplePie_Item[] $arrItems */
for ($i = $offset, $c = count($arrItems); $i < $limit && $i < $c; $i++) {
$items[$i] = array('link' => $arrItems[$i]->get_link(), 'title' => $arrItems[$i]->get_title(), 'permalink' => $arrItems[$i]->get_permalink(), 'description' => str_replace(array('<?', '?>'), array('<?', '?>'), $arrItems[$i]->get_description()), 'class' => ($i == 0 ? ' first' : '') . ($i == $last ? ' last' : '') . ($i % 2 == 0 ? ' even' : ' odd'), 'pubdate' => \Date::parse($objPage->datimFormat, $arrItems[$i]->get_date('U')), 'category' => $arrItems[$i]->get_category(0), 'object' => $arrItems[$i]);
// Add author
if (($objAuthor = $arrItems[$i]->get_author(0)) != false) {
$items[$i]['author'] = trim($objAuthor->name . ' ' . $objAuthor->email);
}
// Add enclosure
if (($objEnclosure = $arrItems[$i]->get_enclosure(0)) != false) {
$items[$i]['enclosure'] = $objEnclosure->get_link();
}
}
$this->Template->items = array_values($items);
}
示例11: feed
function feed()
{
$feed = new SimplePie();
$feed->set_raw_data($this->data);
$feed->enable_cache(false);
$feed->init();
return $feed;
}
示例12: getFeed
/**
* see http://simplepie.org/wiki/reference/start#simplepie_item
*
* @return array SimplePie_Item
*/
static function getFeed($url)
{
$feed = new SimplePie();
$feed->set_feed_url($url);
$feed->enable_cache(false);
$feed->init();
return $feed;
}
示例13: newsRss
/**
* RSS news page
*
* @param Request $request
* @param Application $app
*/
public function newsRss(Request $request, Application $app)
{
$simplePie = new \SimplePie();
$simplePie->set_feed_url($app['resources']['news_rss']);
$simplePie->init();
$items = $simplePie->get_items();
return $app['twig']->render('main/news-rss.twig', ['items' => $items]);
}
示例14: lire_feed
function lire_feed($url, $nb = 3)
{
$feed = new SimplePie($url, '../client/cache/flux');
$feed->init();
$feed->handle_content_type();
$tab = $feed->get_items();
return count($tab) > 0 ? array_slice($tab, 0, 3) : false;
}
示例15: __construct
public function __construct($url)
{
$simplePie = new \SimplePie();
$simplePie->set_cache_location($_SERVER['DOCUMENT_ROOT'] . '/zowcast/rest/cache');
$simplePie->set_feed_url($url);
$simplePie->init();
$simplePie->handle_content_type();
$this->rawData = $simplePie;
}