本文整理汇总了PHP中SimplePie::set_sanitize_class方法的典型用法代码示例。如果您正苦于以下问题:PHP SimplePie::set_sanitize_class方法的具体用法?PHP SimplePie::set_sanitize_class怎么用?PHP SimplePie::set_sanitize_class使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimplePie
的用法示例。
在下文中一共展示了SimplePie::set_sanitize_class方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: SimplePie
function get_rss_feed($url)
{
require_once ABSPATH . WPINC . '/class-feed.php';
$feed = new SimplePie();
$feed->set_sanitize_class('WP_SimplePie_Sanitize_KSES');
$feed->sanitize = new WP_SimplePie_Sanitize_KSES();
$feed->set_useragent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36');
$feed->set_cache_class('WP_Feed_Cache');
$feed->set_file_class('WP_SimplePie_File');
$feed->set_feed_url($url);
$feed->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url));
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;
}
示例4: fetch_feed
/**
* Build SimplePie object based on RSS or Atom feed from URL.
*
* @since 2.8
*
* @param mixed $url URL of feed to retrieve. If an array of URLs, the feeds are merged
* using SimplePie's multifeed feature.
* See also {@link http://simplepie.org/wiki/faq/typical_multifeed_gotchas}
*
* @return WP_Error|SimplePie WP_Error object on failure or SimplePie object on success
*/
function fetch_feed($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->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url));
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;
}
示例5: debug
}
////////////////////////////////
// Get RSS/Atom feed
////////////////////////////////
if ($accept !== 'html') {
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_sanitize_class('DisableSimplePieSanitize');
// need to assign this manually it seems
$feed->sanitize = new DisableSimplePieSanitize();
//$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();
示例6: array
function import_blog($blogID)
{
global $importing_blog;
$importing_blog = $blogID;
if (isset($_GET['authors'])) {
return print $this->get_author_form();
}
if (isset($_GET['status'])) {
self::ajax_die($this->get_js_status());
}
if (isset($_GET['saveauthors'])) {
self::ajax_die($this->save_authors());
}
//Simpler counting for posts as we load them forwards
if (isset($this->blogs[$importing_blog]['posts_start_index'])) {
$start_index = (int) $this->blogs[$importing_blog]['posts_start_index'];
} else {
$start_index = 1;
}
// This will be positive until we have finished importing posts
if ($start_index > 0) {
// Grab all the posts
$this->blogs[$importing_blog]['mode'] = 'posts';
do {
$index = $struct = $entries = array();
$url = $this->blogs[$importing_blog]['posts_url'];
$response = $this->oauth_get($url, array('max-results' => MAX_RESULTS, 'start-index' => $start_index));
if ($response == false) {
break;
}
// parse the feed
$feed = new SimplePie();
$feed->set_item_class('WP_SimplePie_Blog_Item');
$feed->set_sanitize_class('Blogger_Importer_Sanitize');
$feed->set_raw_data($response);
$feed->init();
foreach ($feed->get_items() as $item) {
$blogentry = new BloggerEntry();
$blogentry->id = $item->get_id();
$blogentry->published = $item->get_published();
$blogentry->updated = $item->get_updated();
$blogentry->isDraft = $item->get_draft_status($item);
$blogentry->title = $item->get_title();
$blogentry->content = $item->get_content();
$blogentry->author = $item->get_author()->get_name();
$blogentry->geotags = $item->get_geotags();
$linktypes = array('replies', 'edit', 'self', 'alternate');
foreach ($linktypes as $type) {
$links = $item->get_links($type);
if (!is_null($links)) {
foreach ($links as $link) {
$blogentry->links[] = array('rel' => $type, 'href' => $link);
}
}
}
$cats = $item->get_categories();
if (!is_null($cats)) {
foreach ($cats as $cat) {
$blogentry->categories[] = $cat->term;
}
}
$result = $this->import_post($blogentry);
//Ref: Not importing properly http://core.trac.wordpress.org/ticket/19096
//Simplified this section to count what is loaded rather than parsing the results again
$start_index++;
}
$this->blogs[$importing_blog]['posts_start_index'] = $start_index;
$this->save_vars();
} while ($this->blogs[$importing_blog]['total_posts'] > $start_index && $this->have_time());
//have time function will "die" if it's out of time
}
if (isset($this->blogs[$importing_blog]['comments_start_index'])) {
$start_index = (int) $this->blogs[$importing_blog]['comments_start_index'];
} else {
$start_index = 1;
}
if ($start_index > 0 && $this->blogs[$importing_blog]['total_comments'] > 0) {
$this->blogs[$importing_blog]['mode'] = 'comments';
do {
$index = $struct = $entries = array();
//So we can link up the comments as we go we need to load them in reverse order
//Reverse the start index as the GData Blogger feed can't be sorted
$batch = floor(($this->blogs[$importing_blog]['total_comments'] - $start_index) / MAX_RESULTS) * MAX_RESULTS + 1;
$response = $this->oauth_get($this->blogs[$importing_blog]['comments_url'], array('max-results' => MAX_RESULTS, 'start-index' => $batch));
// parse the feed
$feed = new SimplePie();
$feed->set_item_class('WP_SimplePie_Blog_Item');
// Use the standard "stricter" sanitize class for comments
$feed->set_raw_data($response);
$feed->init();
//Reverse the batch so we load the oldest comments first and hence can link up nested comments
$comments = array_reverse($feed->get_items());
if (!is_null($comments)) {
foreach ($comments as $item) {
$blogentry = new BloggerEntry();
$blogentry->id = $item->get_id();
$blogentry->updated = $item->get_updated();
$blogentry->content = $item->get_content();
$blogentry->author = $item->get_author()->get_name();
$blogentry->authoruri = $item->get_author()->get_link();
//.........这里部分代码省略.........
示例7: update_rss_feed
function update_rss_feed($link, $feed, $ignore_daemon = false, $no_cache = false, $override_url = false)
{
require_once "lib/simplepie/simplepie.inc";
$debug_enabled = defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug'];
if ($debug_enabled) {
_debug("update_rss_feed: start");
}
$result = db_query($link, "SELECT id,update_interval,auth_login,\n\t\t\tfeed_url,auth_pass,cache_images,last_updated,\n\t\t\tmark_unread_on_update, owner_uid,\n\t\t\tpubsub_state\n\t\t\tFROM ttrss_feeds WHERE id = '{$feed}'");
if (db_num_rows($result) == 0) {
if ($debug_enabled) {
_debug("update_rss_feed: feed {$feed} NOT FOUND/SKIPPED");
}
return false;
}
$last_updated = db_fetch_result($result, 0, "last_updated");
$owner_uid = db_fetch_result($result, 0, "owner_uid");
$mark_unread_on_update = sql_bool_to_bool(db_fetch_result($result, 0, "mark_unread_on_update"));
$pubsub_state = db_fetch_result($result, 0, "pubsub_state");
db_query($link, "UPDATE ttrss_feeds SET last_update_started = NOW()\n\t\t\tWHERE id = '{$feed}'");
$auth_login = db_fetch_result($result, 0, "auth_login");
$auth_pass = db_fetch_result($result, 0, "auth_pass");
$cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
$fetch_url = db_fetch_result($result, 0, "feed_url");
$feed = db_escape_string($feed);
/* if ($auth_login && $auth_pass ){
$url_parts = array();
preg_match("/(^[^:]*):\/\/(.*)/", $fetch_url, $url_parts);
if ($url_parts[1] && $url_parts[2]) {
$fetch_url = $url_parts[1] . "://$auth_login:$auth_pass@" . $url_parts[2];
}
} */
if ($override_url) {
$fetch_url = $override_url;
}
if ($debug_enabled) {
_debug("update_rss_feed: fetching [{$fetch_url}]...");
}
// Ignore cache if new feed or manual update.
$cache_age = is_null($last_updated) || $last_updated == '1970-01-01 00:00:00' ? -1 : get_feed_update_interval($link, $feed) * 60;
$simplepie_cache_dir = CACHE_DIR . "/simplepie";
if (!is_dir($simplepie_cache_dir)) {
mkdir($simplepie_cache_dir);
}
$feed_data = fetch_file_contents($fetch_url, false, $auth_login, $auth_pass, false, $no_cache ? 15 : 45);
if (!$feed_data) {
global $fetch_last_error;
if ($debug_enabled) {
_debug("update_rss_feed: unable to fetch: {$fetch_last_error}");
}
$error_escaped = db_escape_string($fetch_last_error);
db_query($link, "UPDATE ttrss_feeds SET last_error = '{$error_escaped}',\n\t\t\t\t\tlast_updated = NOW() WHERE id = '{$feed}'");
return;
}
$pluginhost = new PluginHost($link);
$pluginhost->set_debug($debug_enabled);
$user_plugins = get_pref($link, "_ENABLED_PLUGINS", $owner_uid);
$pluginhost->load(PLUGINS, $pluginhost::KIND_ALL);
$pluginhost->load($user_plugins, $pluginhost::KIND_USER, $owner_uid);
$pluginhost->load_data();
foreach ($pluginhost->get_hooks($pluginhost::HOOK_FEED_FETCHED) as $plugin) {
$feed_data = $plugin->hook_feed_fetched($feed_data);
}
if ($debug_enabled) {
_debug("update_rss_feed: fetch done, parsing...");
}
$rss = new SimplePie();
$rss->set_sanitize_class("SanitizeDummy");
// simplepie ignores the above and creates default sanitizer anyway,
// so let's override it...
$rss->sanitize = new SanitizeDummy();
$rss->set_output_encoding('UTF-8');
$rss->set_raw_data($feed_data);
if ($debug_enabled) {
_debug("feed update interval (sec): " . get_feed_update_interval($link, $feed) * 60);
}
$rss->enable_cache(!$no_cache);
if (!$no_cache) {
$rss->set_cache_location($simplepie_cache_dir);
$rss->set_cache_duration($cache_age);
}
@$rss->init();
// print_r($rss);
$feed = db_escape_string($feed);
if (!$rss->error()) {
// We use local pluginhost here because we need to load different per-user feed plugins
$pluginhost->run_hooks($pluginhost::HOOK_FEED_PARSED, "hook_feed_parsed", $rss);
if ($debug_enabled) {
_debug("update_rss_feed: processing feed data...");
}
// db_query($link, "BEGIN");
if (DB_TYPE == "pgsql") {
$favicon_interval_qpart = "favicon_last_checked < NOW() - INTERVAL '12 hour'";
} else {
$favicon_interval_qpart = "favicon_last_checked < DATE_SUB(NOW(), INTERVAL 12 HOUR)";
}
$result = db_query($link, "SELECT title,site_url,owner_uid,\n\t\t\t\t(favicon_last_checked IS NULL OR {$favicon_interval_qpart}) AS\n\t\t\t\t\t\tfavicon_needs_check\n\t\t\t\tFROM ttrss_feeds WHERE id = '{$feed}'");
$registered_title = db_fetch_result($result, 0, "title");
$orig_site_url = db_fetch_result($result, 0, "site_url");
$favicon_needs_check = sql_bool_to_bool(db_fetch_result($result, 0, "favicon_needs_check"));
//.........这里部分代码省略.........
示例8: runSQL
$sql = 'SELECT * FROM lylina_feeds';
$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);
示例9: 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
}
}
}