本文整理汇总了PHP中SimplePie::handle_content_type方法的典型用法代码示例。如果您正苦于以下问题:PHP SimplePie::handle_content_type方法的具体用法?PHP SimplePie::handle_content_type怎么用?PHP SimplePie::handle_content_type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimplePie
的用法示例。
在下文中一共展示了SimplePie::handle_content_type方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate
/**
* Display a wildcard in the back end
*
* @return string
*/
public function generate()
{
if (TL_MODE == 'BE') {
/** @var \BackendTemplate|object $objTemplate */
$objTemplate = new \BackendTemplate('be_wildcard');
$objTemplate->wildcard = '### ' . utf8_strtoupper($GLOBALS['TL_LANG']['FMD']['rss_reader'][0]) . ' ###';
$objTemplate->title = $this->headline;
$objTemplate->id = $this->id;
$objTemplate->link = $this->name;
$objTemplate->href = '' . $GLOBALS['TL_CONFIG']['backendPath'] . '/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id;
return $objTemplate->parse();
}
$this->objFeed = new \SimplePie();
$arrUrls = trimsplit('[\\n\\t ]', trim($this->rss_feed));
if (count($arrUrls) > 1) {
$this->objFeed->set_feed_url($arrUrls);
} else {
$this->objFeed->set_feed_url($arrUrls[0]);
}
$this->objFeed->set_output_encoding(\Config::get('characterSet'));
$this->objFeed->set_cache_location(TL_ROOT . '/system/tmp');
$this->objFeed->enable_cache(false);
if ($this->rss_cache > 0) {
$this->objFeed->enable_cache(true);
$this->objFeed->set_cache_duration($this->rss_cache);
}
if (!$this->objFeed->init()) {
$this->log('Error importing RSS feed "' . $this->rss_feed . '"', __METHOD__, TL_ERROR);
return '';
}
$this->objFeed->handle_content_type();
return parent::generate();
}
示例2: __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);
}
示例3: showBlogLastArticles
function showBlogLastArticles()
{
$content = '';
$feed = new SimplePie();
$feed->set_feed_url(array('http://bilboplanet.com/feed/'));
$feed->set_cache_duration(600);
# $feed->enable_xml_dump(isset($_GET['xmldump']) ? true : false);
$success = $feed->init();
$feed->handle_content_type();
if ($success) {
$content .= '<div class="box-dashboard"><div class="top-box-dashboard">' . T_('BilboPlanet news - Official Website :') . '</div>';
$content .= '<ul>';
$itemlimit = 0;
foreach ($feed->get_items() as $item) {
if ($itemlimit == 4) {
break;
}
$content .= '<li>' . $item->get_date('j/m/y') . ' : ';
$content .= '<a class="tips" rel="' . $item->get_title() . '" href="' . $item->get_permalink() . '" target="_blank">' . $item->get_title() . '</a>';
$content .= '</li>';
$itemlimit = $itemlimit + 1;
}
$content .= '</ul></div>';
}
return $content;
}
示例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)
{
$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);
}
示例5: 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));
}
}
示例6: SimplePie
function fetch_feed2($url)
{
require_once ABSPATH . WPINC . '/class-feed.php';
$feed = new SimplePie();
$feed->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
$feed->sanitize = new WP_SimplePie_Sanitize_KSES();
$feed->set_cache_class('WP_Feed_Cache');
$feed->set_file_class('WP_SimplePie_File');
$feed->set_feed_url($url);
$feed->force_feed(true);
/** This filter is documented in wp-includes/class-feed.php */
$feed->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url));
/**
* Fires just before processing the SimplePie feed object.
*
* @since 3.0.0
*
* @param object &$feed SimplePie feed object, passed by reference.
* @param mixed $url URL of feed to retrieve. If an array of URLs, the feeds are merged.
*/
do_action_ref_array('wp_feed_options', array(&$feed, $url));
$feed->init();
$feed->handle_content_type();
if ($feed->error()) {
return new WP_Error('simplepie-error', $feed->error());
}
return $feed;
}
示例7: respond
public function respond()
{
$url = trim($this->matches[1]);
$index = 0;
if (isset($this->matches[2])) {
$index = intval(trim($this->matches[2]));
$index = $index - 1;
$index = max(0, $index);
}
$error_level = error_reporting();
error_reporting($error_level ^ E_USER_NOTICE);
$feed = new \SimplePie();
if ($this->cacheEnabled()) {
$feed->set_cache_location($this->config['cache_directory']);
$feed->set_cache_duration(600);
}
$feed->set_feed_url($url);
$feed->init();
$feed->handle_content_type();
if ($index > $feed->get_item_quantity() - 1) {
$index = $feed->get_item_quantity() - 1;
}
$item = $feed->get_item($index);
$result = null;
if ($item) {
$title = html_entity_decode($item->get_title());
$link = $item->get_permalink();
$date = $item->get_date();
$i = $index + 1;
$result = "[{$i}] {$date} - {$title} - {$link}";
}
error_reporting($error_level);
return $result;
}
示例8: 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;
}
示例9: show_news
function show_news($newsfeed, $newsitems, $newsprefiximage, $newssuffiximage)
{
$rss = new SimplePie($newsfeed, dirname(__FILE__) . '/cache');
$rss->force_feed(true);
// MAKE IT WORK
$rss->set_cache_duration(60 * 5);
$rss->init();
$rss->handle_content_type();
// if ($rss->error()) {
// echo htmlentities($rss->error());
// return;
// }
foreach ($rss->get_items(0, $newsitems) as $item) {
$title = $item->get_title();
$url = $item->get_permalink();
if ($newsprefiximage != '') {
echo "<img src='{$newsprefiximage}'>";
}
echo "<a href={$url}>{$title}</a>";
if ($newssuffiximage != '') {
echo "<img src='{$newssuffiximage}'>";
}
echo "<br />";
}
}
示例10: 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;
}
示例11: getFeeds
function getFeeds()
{
$app = JFactory::getApplication();
$params = JComponentHelper::getParams('com_jce');
$limit = $params->get('feed_limit', 2);
$feeds = array();
$options = array('rssUrl' => 'http://www.joomlacontenteditor.net/news/feed/rss/latest-news?format=feed', 'cache_time' => $params->get('feed_cachetime', 86400));
// use this directly instead of JFactory::getXMLParserto avoid the feed data error
jimport('simplepie.simplepie');
if (!is_writable(JPATH_BASE . '/cache')) {
$options['cache_time'] = 0;
}
$rss = new SimplePie($options['rssUrl'], JPATH_BASE . '/cache', isset($options['cache_time']) ? $options['cache_time'] : 0);
$rss->force_feed(true);
$rss->handle_content_type();
if ($rss->init()) {
$count = $rss->get_item_quantity();
if ($count) {
$count = $count > $limit ? $limit : $count;
for ($i = 0; $i < $count; $i++) {
$feed = new StdClass();
$item = $rss->get_item($i);
$feed->link = $item->get_link();
$feed->title = $item->get_title();
$feed->description = $item->get_description();
$feeds[] = $feed;
}
}
}
return $feeds;
}
示例12: 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?";
}
}
示例13: 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;
}
示例14: __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;
}
示例15: __construct
public function __construct($url)
{
$simplePie = new \SimplePie();
$simplePie->set_cache_location(getcwd() . '/cache');
$simplePie->set_feed_url($url);
$simplePie->init();
$simplePie->handle_content_type();
$this->rawData = $simplePie;
}