本文整理汇总了PHP中SimplePie::set_autodiscovery_level方法的典型用法代码示例。如果您正苦于以下问题:PHP SimplePie::set_autodiscovery_level方法的具体用法?PHP SimplePie::set_autodiscovery_level怎么用?PHP SimplePie::set_autodiscovery_level使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimplePie
的用法示例。
在下文中一共展示了SimplePie::set_autodiscovery_level方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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');
}
示例2: debug
// Get RSS/Atom feed
////////////////////////////////
if (!$html_only) {
debug('--------');
debug("Attempting to process URL as feed");
// Send user agent header showing PHP (prevents a HTML response from feedburner)
$http->userAgentDefault = HumbleHttpAgent::UA_PHP;
// configure SimplePie HTTP extension class to use our HumbleHttpAgent instance
SimplePie_HumbleHttpAgent::set_agent($http);
$feed = new SimplePie();
// some feeds use the text/html content type - force_feed tells SimplePie to process anyway
$feed->force_feed(true);
$feed->set_file_class('SimplePie_HumbleHttpAgent');
//$feed->set_feed_url($url); // colons appearing in the URL's path get encoded
$feed->feed_url = $url;
$feed->set_autodiscovery_level(SIMPLEPIE_LOCATOR_NONE);
$feed->set_timeout(20);
$feed->enable_cache(false);
$feed->set_stupidly_fast(true);
$feed->enable_order_by_date(false);
// we don't want to do anything to the feed
$feed->set_url_replacements(array());
// initialise the feed
// the @ suppresses notices which on some servers causes a 500 internal server error
$result = @$feed->init();
//$feed->handle_content_type();
//$feed->get_title();
if ($result && (!is_array($feed->data) || count($feed->data) == 0)) {
die('Sorry, no feed items found');
}
// from now on, we'll identify ourselves as a browser
示例3: wprss_fetch_feed
/**
* A clone of the function 'fetch_feed' in wp-includes/feed.php [line #529]
*
* Called from 'wprss_get_feed_items'
*
* @since 3.5
*/
function wprss_fetch_feed($url, $source = NULL)
{
// Import SimplePie
require_once ABSPATH . WPINC . '/class-feed.php';
// Trim the URL
$url = trim($url);
// Initialize the Feed
$feed = new SimplePie();
// Obselete method calls ?
//$feed->set_cache_class( 'WP_Feed_Cache' );
//$feed->set_file_class( 'WP_SimplePie_File' );
$feed->set_feed_url($url);
$feed->set_autodiscovery_level(SIMPLEPIE_LOCATOR_ALL);
// If a feed source was passed
if ($source !== NULL) {
// Get the force feed option for the feed source
$force_feed = get_post_meta($source, 'wprss_force_feed', TRUE);
// If turned on, force the feed
if ($force_feed == 'true') {
$feed->force_feed(TRUE);
}
}
// Set timeout to 30s. Default: 15s
$feed->set_timeout(30);
//$feed->set_cache_duration( apply_filters( 'wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url ) );
$feed->enable_cache(FALSE);
// Reference array action hook, for the feed object and the URL
do_action_ref_array('wp_feed_options', array(&$feed, $url));
// Prepare the tags to strip from the feed
$tags_to_strip = apply_filters('wprss_feed_tags_to_strip', $feed->strip_htmltags, $source);
// Strip them
$feed->strip_htmltags($tags_to_strip);
// Fetch the feed
$feed->init();
$feed->handle_content_type();
// Convert the feed error into a WP_Error, if applicable
if ($feed->error()) {
return new WP_Error('simplepie-error', $feed->error());
}
// If no error, return the feed
return $feed;
}
示例4: RssFeed
function RssFeed($link)
{
//process rss
$feed_url = $link;
$items_per_feed = 10;
$items_max_age = '-60 days';
$max_age = $items_max_age ? date('Y-m-d H:i:s', strtotime($items_max_age)) : null;
$items = array();
App::import('vendor', 'simplepie/simplepie');
$feed = new SimplePie();
$feed->set_cache_location(CACHE . 'simplepie');
$feed->set_feed_url($feed_url);
$feed->set_autodiscovery_level(SIMPLEPIE_LOCATOR_NONE);
$feed->init();
if ($feed->error() || $feed->feed_url != $feed_url) {
return false;
}
for ($i = 0; $i < $feed->get_item_quantity($items_per_feed); $i++) {
$feeditem = $feed->get_item($i);
# create a NoseRub item out of the feed item
$item = array();
$item['datetime'] = $feeditem->get_date('Y-m-d H:i:s');
if ($max_age && $item['datetime'] < $max_age) {
# we can stop here, as we do not expect any newer items
break;
}
$item['title'] = $feeditem->get_title();
$item['url'] = $feeditem->get_link();
//$item['intro'] = @$intro;
//$item['type'] = @$token;
//$item['username'] = $username;
$items[] = $item;
}
unset($feed);
$items;
foreach ($items as $_item) {
echo '<a href="' . $_item['url'] . '">' . $_item['title'] . '</a><br/>';
}
//end process rss
}
示例5: getInfoFromFeed
/**
* get title, url and preview for rss-feed
*
* @param string $feed_url
* @param int $max_items maximum number of items to fetch
* @return array
* @access
*/
function getInfoFromFeed($username, $service_type_id, $feed_url, $max_items = 5)
{
# needed for autodiscovery of feed
//require 'simplepie/simplepie.php';
$feed = new SimplePie();
$feed->set_cache_location(CACHE . 'simplepie');
$feed->set_feed_url($feed_url);
$feed->set_autodiscovery_level(SIMPLEPIE_LOCATOR_ALL);
@$feed->init();
if ($feed->error()) {
return false;
}
$data = array();
$data['title'] = $feed->get_title();
$data['account_url'] = $feed->get_link();
$data['feed_url'] = $feed->feed_url;
unset($feed);
if (!$data['account_url']) {
$data['account_url'] = $data['feed_url'];
}
$data['service_id'] = 8;
# any RSS-Feed
$data['username'] = 'RSS-Feed';
$data['service_type_id'] = $service_type_id;
$items = $this->feed2array($username, 8, $data['service_type_id'], $data['feed_url'], 5, null);
if (!$items) {
return false;
}
$data['items'] = $items;
return $data;
}
示例6: wprss_fetch_feed
/**
* A clone of the function 'fetch_feed' in wp-includes/feed.php [line #529]
*
* Called from 'wprss_get_feed_items'
*
* @since 3.5
*/
function wprss_fetch_feed($url, $source = NULL, $param_force_feed = FALSE)
{
// Trim the URL
$url = trim($url);
// Initialize the Feed
$feed = new SimplePie();
// Obselete method calls ?
//$feed->set_cache_class( 'WP_Feed_Cache' );
//$feed->set_file_class( 'WP_SimplePie_File' );
$feed->set_feed_url($url);
$feed->set_autodiscovery_level(SIMPLEPIE_LOCATOR_ALL);
// If a feed source was passed
if ($source !== NULL || $param_force_feed) {
// Get the force feed option for the feed source
$force_feed = get_post_meta($source, 'wprss_force_feed', TRUE);
// If turned on, force the feed
if ($force_feed == 'true' || $param_force_feed) {
$feed->force_feed(TRUE);
}
}
// Set timeout limit
$fetch_time_limit = wprss_get_feed_fetch_time_limit();
$feed->set_timeout($fetch_time_limit);
//$feed->set_cache_duration( apply_filters( 'wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url ) );
$feed->enable_cache(FALSE);
// Reference array action hook, for the feed object and the URL
do_action_ref_array('wp_feed_options', array(&$feed, $url));
// Prepare the tags to strip from the feed
$tags_to_strip = apply_filters('wprss_feed_tags_to_strip', $feed->strip_htmltags, $source);
// Strip them
$feed->strip_htmltags($tags_to_strip);
do_action('wprss_fetch_feed_before', $feed);
// Fetch the feed
$feed->init();
$feed->handle_content_type();
do_action('wprss_fetch_feed_after', $feed);
// Convert the feed error into a WP_Error, if applicable
if ($feed->error()) {
if ($source !== NULL) {
$msg = sprintf(__('Failed to fetch the RSS feed. Error: %s', WPRSS_TEXT_DOMAIN), $feed->error());
update_post_meta($source, 'wprss_error_last_import', $msg);
}
return new WP_Error('simplepie-error', $feed->error());
}
// If no error, return the feed and remove any error meta
delete_post_meta($source, "wprss_error_last_import");
return $feed;
}
示例7: get_default_item
public static function get_default_item()
{
$id = filter_input(INPUT_POST, 'id');
$value_default = filter_input(INPUT_POST, 'val_default');
if ($value_default == '') {
return 'Do nothing!';
}
$feed = new SimplePie();
$path = OGRAB_EDATA . 'item-' . $id . DS . 'row-default.dat';
$feed->set_feed_url($value_default);
$feed->set_autodiscovery_level(SIMPLEPIE_LOCATOR_NONE);
$feed->set_timeout(20);
$feed->enable_cache(false);
$feed->set_stupidly_fast(true);
$feed->enable_order_by_date(false);
// we don't want to do anything to the feed
$feed->set_url_replacements(array());
$result = $feed->init();
if (isset($_GET['x'])) {
echo "\n\n<br /><i><b>File:</b>" . __FILE__ . ' <b>Line:</b>' . __LINE__ . "</i><br />\n\n";
echo "<p>URL: [{$value_default}]</p>";
echo "<p>Error: [{$feed->error}]</p>";
}
$items = $feed->get_items();
$c_items = count($items);
if ($c_items == 0) {
echo "<p>Error: [{$feed->error}]</p>";
return array();
}
$row = new stdclass();
$row->title = html_entity_decode($items[0]->get_title(), ENT_QUOTES, 'UTF-8');
# the title for the post
$row->link = $items[0]->get_link();
# a single link for the post
$row->description = $items[0]->get_description();
# the content of the post (prefers summaries)
$row->author = $items[0]->get_author();
# a single author for the post
$row->date = $items[0]->get_date('Y-m-d H:i:s');
$row->enclosures = $items[0]->get_enclosures();
if (!is_file($path)) {
$source = new stdClass();
} else {
$source = ogb_common::get_default_data('', $id);
}
$source->so = $row;
$cache = serialize($source);
if (isset($_GET['x2'])) {
//echo "\n\n<br /><i><b>File:</b>".__FILE__.' <b>Line:</b>'.__LINE__."</i><br />\n\n";
echo '<br>Path: ' . $path;
}
ogbFile::write($path, $cache);
exit;
}
示例8: get_items_feed
public static function get_items_feed($url, $params = null)
{
$feed = new SimplePie();
$mode = isset($params->mode) ? $params->mode : 0;
if ($mode == 0) {
$feed->set_feed_url($url);
} else {
$html = ogbFile::get_curl($url);
$feed->set_raw_data($html);
}
$feed->set_autodiscovery_level(SIMPLEPIE_LOCATOR_NONE);
$feed->set_timeout(20);
$feed->enable_cache(false);
$feed->set_stupidly_fast(true);
$feed->enable_order_by_date(false);
// we don't want to do anything to the feed
$feed->set_url_replacements(array());
$feed->force_feed(true);
$result = $feed->init();
if (isset($_GET['x'])) {
echo "\n\n<br /><i><b>File:</b>" . __FILE__ . ' <b>Line:</b>' . __LINE__ . "</i><br />\n\n";
echo "<p>URL: [{$url}]</p>";
echo "<p>Error: [{$feed->error}]</p>";
}
$items = $feed->get_items();
$c_items = count($items);
if ($c_items == 0) {
echo "<p>Error: [{$feed->error}]</p>";
return array();
}
for ($i = 0; $i < count($items); $i++) {
$row = new stdclass();
$row->title = $items[$i]->get_title();
# the title for the post
$row->link = $items[$i]->get_link();
# a single link for the post
$row->description = $items[$i]->get_description();
# the content of the post (prefers summaries)
$row->author = $items[$i]->get_author();
# a single author for the post
$row->date = $items[$i]->get_date('Y-m-d H:i:s');
$row->enclosures = $items[$i]->get_enclosures();
$rows[] = $row;
}
return $rows;
}
示例9: runSQL
$feeds = runSQL($sql);
$feeds_parse = array();
$feed_count = 0;
//$feeds_parse['url'] = array();
//$feeds_parse['curl'] = array();
//$feeds_parse['data'] = array();
//$feeds_parse['id'] = array();
//$feeds_parse['mirror_url'] = array();
$master_curl = curl_multi_init();
//$data = new SimplePie_Cache_Extras();
$data = new SimplePie();
$data->set_cache_duration(300);
$data->set_cache_location(MAGPIE_CACHE_DIR);
$data->enable_cache(true);
$data->set_sanitize_class('SimplePie_Sanitize_Null');
$data->set_autodiscovery_level(SIMPLEPIE_LOCATOR_ALL);
//$data->set_stupidly_fast(true);
// Don't need this
$data->enable_order_by_date(false);
foreach ($feeds as $feed) {
if ($conf['debug'] == 'true') {
print 'Fetching ' . $feed['url'] . " ";
}
// if($conf['debug'] == 'true') flush();
$enc = '';
// $data = fetch_rss($feed['url']);
/* if(file_exists("mirror/" . md5($feed['url']) . ".xml")) {
// $data = new SimplePie_Cache_Extras("mirror/" . md5($feed['url']) . ".xml");
$data->set_feed_url("mirror/" . md5($feed['url']) . ".xml");
// $data->set_cache_duration(300);
$cache_time = $data->get_cache_time_remaining();
示例10: get
function get()
{
$purifier_config = HTMLPurifier_Config::createDefault();
$purifier_config->set('Cache.SerializerPath', 'cache');
// TODO: This feature is very nice, but breaks titles now that we purify them. Titles only need their entities fixed, so we shouldn't really purify them allowing us to turn this back on
# $purifier_config->set('AutoFormat.Linkify', true);
// Allow flash embeds in newer versions of purifier
$purifier_config->set('HTML.SafeObject', true);
$purifier_config->set('Output.FlashCompat', true);
$purifier_config->set('HTML.FlashAllowFullScreen', true);
$purifier = new HTMLPurifier($purifier_config);
$query = 'SELECT * FROM lylina_feeds';
$feeds = $this->db->GetAll($query);
$pie = new SimplePie();
$pie->enable_cache(false);
$pie->set_sanitize_class('SimplePie_Sanitize_Null');
$pie->set_autodiscovery_level(SIMPLEPIE_LOCATOR_ALL);
$pie->enable_order_by_date(false);
// Array storing feeds which need to be parsed
$feeds_parse = array();
// Keep track of how many we need to parse
$feeds_count = 0;
// Build array of feeds to fetch and their metadata
foreach ($feeds as $feed) {
// Track our cache
$mod_time = -1;
$cache_path = 'cache/' . md5($feed['url']) . '.xml';
if (file_exists($cache_path)) {
$mod_time = @filemtime($cache_path);
$filemd5 = @md5_file($cache_path);
} else {
$mod_time = -1;
$filemd5 = 0;
}
// If our cache is older than 5 minutes, or doesn't exist, fetch new feeds
if (time() - $mod_time > 300 || $mod_time == -1) {
#if(true) {
$feeds_parse[$feeds_count] = array();
$feeds_parse[$feeds_count]['url'] = $feed['url'];
$feeds_parse[$feeds_count]['id'] = $feed['id'];
$feeds_parse[$feeds_count]['name'] = $feed['name'];
$feeds_parse[$feeds_count]['icon'] = $feed['favicon_url'];
$feeds_parse[$feeds_count]['cache_path'] = $cache_path;
$feeds_parse[$feeds_count]['filemd5'] = $filemd5;
$feeds_parse[$feeds_count]['mod'] = $mod_time;
$feeds_count++;
}
}
// Get the data for feeds we need to parse
$curl = new Curl_Get();
$feeds_data = $curl->multi_get($feeds_parse);
// Handle the data and parse the feeds
for ($n = 0; $n < count($feeds_parse); $n++) {
$data = $feeds_data[$n];
$info = $feeds_parse[$n];
// If we got an error back from Curl
if (isset($data['error']) && $data['error'] > 0) {
// Should be logged
error_log("Curl error: " . $data['error']);
// If the feed has been retrieved with content, we should save it
} elseif ($data['data'] != NULL) {
file_put_contents($info['cache_path'], $data['data']);
// Otherwise we've gotten an error on the feed, or there is nothing new, let's freshen the cache
} else {
touch($info['cache_path']);
}
}
// Clear the file stat cache so we get good data on feed mirror size changes
clearstatcache();
for ($n = 0; $n < count($feeds_parse); $n++) {
$data = $feeds_data[$n];
$info = $feeds_parse[$n];
if ($data['data'] != NULL && md5_file($info['cache_path']) !== $info['filemd5']) {
$pie->set_feed_url($info['cache_path']);
$pie->init();
// If SimplePie finds a new RSS URL, let's update our cache
if ($pie->feed_url != $info['url']) {
$this->db->Execute('UPDATE lylina_items SET url=?, fallback_url=? WHERE id=?', array($pie->feed_url, $info['url'], $info['id']));
}
// Update the real feed title - users who already have the feed added won't see the change
// This is to prevent garbage names from OPML imports, which eventually won't be a problem,
// but it's probably a good idea to keep the global title current anyway
if ($pie->get_title() != $info['name']) {
$this->db->Execute('UPDATE lylina_feeds SET name=? WHERE id=?', array($pie->get_title(), $info['id']));
}
// TODO: Favicon handling isn't real pretty
// If we have a new favicon URL, no cache, or stale cache, update cache
if (!file_exists('cache/' . md5($info['url']) . '.ico') || time() - filemtime('cache/' . md5($info['url']) . '.ico') > 7 * 24 * 60 * 60 || $pie->get_favicon() != $info['icon']) {
$this->update_favicon($info, $pie);
}
// If we can successfully parse the file, format them
if ($pie->get_items()) {
$this->insert_items($info, $pie, $purifier);
}
} else {
// TODO: Provide debugging
}
}
}
示例11: date
function feed2array($feed_url, $items_per_feed = 5, $items_max_age = '-21 days')
{
if (!$feed_url) {
return false;
}
# get info about service type
$max_age = $items_max_age ? date('Y-m-d H:i:s', strtotime($items_max_age)) : null;
$items = array();
$feed = new SimplePie();
$feed->set_cache_location(CACHE . 'simplepie');
$feed->set_feed_url($feed_url);
$feed->set_autodiscovery_level(SIMPLEPIE_LOCATOR_NONE);
$feed->init();
if ($feed->error() || $feed->feed_url != $feed_url) {
return false;
}
for ($i = 0; $i < $feed->get_item_quantity($items_per_feed); $i++) {
$feeditem = $feed->get_item($i);
# create a NoseRub item out of the feed item
$item = array();
$item['datetime'] = $feeditem->get_date('Y-m-d H:i:s');
if ($max_age && $item['datetime'] < $max_age) {
# we can stop here, as we do not expect any newer items
break;
}
$item['title'] = $feeditem->get_title();
$item['url'] = $feeditem->get_link();
$item['intro'] = @$intro;
$item['type'] = @$token;
$item['username'] = $username;
$items[] = $item;
}
unset($feed);
return $items;
}