当前位置: 首页>>代码示例>>PHP>>正文


PHP SimplePie::force_feed方法代码示例

本文整理汇总了PHP中SimplePie::force_feed方法的典型用法代码示例。如果您正苦于以下问题:PHP SimplePie::force_feed方法的具体用法?PHP SimplePie::force_feed怎么用?PHP SimplePie::force_feed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SimplePie的用法示例。


在下文中一共展示了SimplePie::force_feed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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;
	}
开发者ID:GitIPFire,项目名称:Homeworks,代码行数:41,代码来源:factory.php

示例2: 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 />";
    }
}
开发者ID:philhassey,项目名称:ludumdare,代码行数:25,代码来源:news.php

示例3: 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;
 }
开发者ID:Telemedellin,项目名称:feriadelasfloresmedellin,代码行数:30,代码来源:getFeed.php

示例4: 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;
 }
开发者ID:01J,项目名称:bealtine,代码行数:31,代码来源:cpanel.php

示例5: register

 /**
  * Register the service provider.
  *
  * @return  void
  */
 public function register()
 {
     $this->app['feed.parser'] = function ($app) {
         $cache = PATH_APP . DS . 'cache';
         $cache .= DS . (isset($app['client']->alias) ? $app['client']->alias : $app['client']->name);
         include_once PATH_CORE . DS . 'libraries' . DS . 'simplepie' . DS . 'simplepie.php';
         $reader = new \SimplePie(null, $cache, $app['config']->get('cachetime', 15));
         $reader->enable_cache(false);
         $reader->force_feed(true);
         return $reader;
     };
 }
开发者ID:kevinwojo,项目名称:hubzero-cms,代码行数:17,代码来源:FeedServiceProvider.php

示例6: fetchSite

 protected function fetchSite($site)
 {
     $feed = new \SimplePie();
     $feed->force_feed(true);
     $feed->set_item_limit(20);
     $feed->set_feed_url($site);
     $feed->enable_cache(false);
     $feed->set_output_encoding('utf-8');
     $feed->init();
     foreach ($feed->get_items() as $item) {
         $this->outputItem(['site' => $site, 'title' => $item->get_title(), 'link' => $item->get_permalink(), 'date' => new \Carbon\Carbon($item->get_date()), 'content' => $item->get_content()]);
     }
 }
开发者ID:aukw,项目名称:phprssreader,代码行数:13,代码来源:RSSReader.php

示例7: getFeedByUrl

 private function getFeedByUrl($url)
 {
     // Create a new instance of the SimplePie object
     $feed = new \SimplePie();
     // Set feed
     $feed->set_feed_url($url);
     // Allow us to change the input encoding from the URL string if we want to. (optional)
     if (!empty($_GET['input'])) {
         $feed->set_input_encoding($_GET['input']);
     }
     // Allow us to choose to not re-order the items by date. (optional)
     if (!empty($_GET['orderbydate']) && $_GET['orderbydate'] == 'false') {
         $feed->enable_order_by_date(false);
     }
     // Trigger force-feed
     if (!empty($_GET['force']) && $_GET['force'] == 'true') {
         $feed->force_feed(true);
     }
     $feed->set_cache_location(dirname(__FILE__) . '/../cache/');
     $feed->init();
     return $feed->get_items(0, 10);
 }
开发者ID:nsystem1,项目名称:ZeeJong,代码行数:22,代码来源:News.php

示例8: parseFeed

 /**
  * Opens an RSS feed, parses and loads the contents.
  *
  * @param string $url         The URL of the RSS feed
  * @param bool   $nativeOrder If true, disable order by date to preserve native ordering
  * @param bool   $force       Force SimplePie to parse the feed despite errors
  *
  * @return object An object that encapsulates the feed contents and operations on those contents.
  * @throws FeedParserException If opening or parsing feed fails
  **/
 public function parseFeed($url, $nativeOrder = false, $force = false)
 {
     require_once PATH_SYSTEM . '/vendors/SimplePie.php';
     $feed = new SimplePie();
     $feed->set_timeout($this->timeout);
     $feed->set_feed_url($url);
     $feed->enable_order_by_date(!$nativeOrder);
     $feed->force_feed($force);
     if ($this->cacheDuration != null) {
         $feed->set_cache_duration(intval($this->cacheDuration));
     }
     if ($this->cacheDirectory != null) {
         $feed->set_cache_location($this->cacheDirectory);
     }
     if ($this->stripHtmlTags != null) {
         $feed->strip_htmltags($this->stripHtmlTags);
     }
     @$feed->init();
     if ($err = $feed->error()) {
         throw new FeedParserException($err);
     }
     return $feed;
 }
开发者ID:wb-crowdfusion,项目名称:crowdfusion,代码行数:33,代码来源:FeedParser.php

示例9: fetch

 function fetch($url, $force_feed = true)
 {
     $feed = new SimplePie();
     $feed->set_feed_url($url);
     if (version_compare(SIMPLEPIE_VERSION, '1.3-dev', '>')) {
         $feed->set_cache_location('wp-transient');
         $feed->registry->register('Cache', 'WP_Feed_Cache_Transient');
         $feed->registry->register('File', 'FeedWordPress_File');
     } else {
         $feed->set_cache_class('WP_Feed_Cache');
         $feed->set_file_class('FeedWordPress_File');
     }
     $feed->set_content_type_sniffer_class('FeedWordPress_Content_Type_Sniffer');
     $feed->set_file_class('FeedWordPress_File');
     $feed->force_feed($force_feed);
     $feed->set_cache_duration(FeedWordPress::cache_duration());
     $feed->init();
     $feed->handle_content_type();
     if ($feed->error()) {
         $ret = new WP_Error('simplepie-error', $feed->error());
     } else {
         $ret = $feed;
     }
     return $ret;
 }
开发者ID:gopinathshiva,项目名称:wordpress-vip-plugins,代码行数:25,代码来源:feedwordpress.php

示例10: getFeedParser

 /**
  * Get an parsed XML Feed Source
  *
  * @access public
  * @param string 	Url for feed source
  * @param int   	Time to cache feed
  *
  * @return mixed SimplePie parsed object on success, false on failure
  * @since: Nooku Server 0.7
  */
 function getFeedParser($url, $cache_time = null)
 {
     jimport('simplepie.simplepie');
     $simplepie = new SimplePie();
     $simplepie->set_feed_url($url);
     $cache_path = JFactory::getConfig()->getValue('config.cache_path', JPATH_ROOT . DS . 'cache');
     if (is_writable($cache_path) && JFactory::getConfig()->getValue('config.caching')) {
         if (is_null($cache_time)) {
             $cache_time = JFactory::getConfig()->getValue('config.caching') * 60;
         }
         $simplepie->set_cache_duration($cache_time);
         $simplepie->set_cache_location($cache_path);
     } else {
         $simplepie->enable_cache(false);
     }
     $simplepie->force_feed(true);
     $simplepie->handle_content_type();
     if ($simplepie->init()) {
         return $simplepie;
     }
     JError::raiseWarning('SOME_ERROR_CODE', JText::_('ERROR LOADING FEED DATA'));
     return false;
 }
开发者ID:JSWebdesign,项目名称:intranet-platform,代码行数:33,代码来源:factory.php

示例11: 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;
}
开发者ID:kivivuori,项目名称:jotain,代码行数:49,代码来源:feed-importing.php

示例12: do_rss

 /**
  *
  * @param object $bookmark
  * @param object $owner
  */
 protected function do_rss($bookmark, $owner)
 {
     // no bookmark, no fun
     if (empty($bookmark) || !is_object($bookmark)) {
         return false;
     }
     // no owner means no email, so no reason to parse
     if (empty($owner) || !is_object($owner)) {
         return false;
     }
     // instead of the way too simple fetch_feed, we'll use SimplePie itself
     if (!class_exists('SimplePie')) {
         require_once ABSPATH . WPINC . '/class-simplepie.php';
     }
     $url = htmlspecialchars_decode($bookmark->link_rss);
     $last_updated = strtotime($bookmark->link_updated);
     static::debug('Fetching: ' . $url, 6);
     $feed = new SimplePie();
     $feed->set_feed_url($url);
     $feed->set_cache_duration(static::revisit_time - 10);
     $feed->set_cache_location($this->cachedir);
     $feed->force_feed(true);
     // optimization
     $feed->enable_order_by_date(true);
     $feed->remove_div(true);
     $feed->strip_comments(true);
     $feed->strip_htmltags(false);
     $feed->strip_attributes(true);
     $feed->set_image_handler(false);
     $feed->init();
     $feed->handle_content_type();
     if ($feed->error()) {
         $err = new WP_Error('simplepie-error', $feed->error());
         static::debug('Error: ' . $err->get_error_message(), 4);
         $this->failed($owner->user_email, $url, $err->get_error_message());
         return $err;
     }
     // set max items to 12
     // especially useful with first runs
     $maxitems = $feed->get_item_quantity(12);
     $feed_items = $feed->get_items(0, $maxitems);
     $feed_title = $feed->get_title();
     // set the link name from the RSS title
     if (!empty($feed_title) && $bookmark->link_name != $feed_title) {
         global $wpdb;
         $wpdb->update($wpdb->prefix . 'links', array('link_name' => $feed_title), array('link_id' => $bookmark->link_id));
     }
     // if there's a feed author, get it, we may need it if there's no entry
     // author
     $feed_author = $feed->get_author();
     $last_updated_ = 0;
     if ($maxitems > 0) {
         foreach ($feed_items as $item) {
             // U stands for Unix Time
             $date = $item->get_date('U');
             if ($date > $last_updated) {
                 $fromname = $feed_title;
                 $author = $item->get_author();
                 if ($author) {
                     $fromname = $fromname . ': ' . $author->get_name();
                 } elseif ($feed_author) {
                     $fromname = $fromname . ': ' . $feed_author->get_name();
                 }
                 // this is to set the sender mail from our own domain
                 $frommail = get_user_meta($owner->ID, 'blogroll2email_email', true);
                 if (!$frommail) {
                     $sitedomain = parse_url(get_bloginfo('url'), PHP_URL_HOST);
                     $frommail = static::schedule . '@' . $sitedomain;
                 }
                 $from = $fromname . '<' . $frommail . '>';
                 $content = $item->get_content();
                 $matches = array();
                 preg_match_all('/farm[0-9]\\.staticflickr\\.com\\/[0-9]+\\/([0-9]+_[0-9a-zA-Z]+_m\\.jpg)/s', $content, $matches);
                 if (!empty($matches[0])) {
                     foreach ($matches[0] as $to_replace) {
                         $clean = str_replace('_m.jpg', '_c.jpg', $to_replace);
                         $content = str_replace($to_replace, $clean, $content);
                     }
                     $content = preg_replace("/(width|height)=\"(.*?)\" ?/is", '', $content);
                 }
                 $content = apply_filters('blogroll2email_message', $content);
                 if ($this->send($owner->user_email, $item->get_link(), $item->get_title(), $from, $url, $item->get_content(), $date)) {
                     if ($date > $last_updated_) {
                         $last_updated_ = $date;
                     }
                 }
             }
         }
     }
     // poke the link's last update field, so we know what was the last sent
     // entry's date
     $this->update_link_date($bookmark, $last_updated_);
 }
开发者ID:petermolnar,项目名称:blogroll2email,代码行数:98,代码来源:blogroll2email.php

示例13: renderVersionStatusReport

 function renderVersionStatusReport(&$needsupdate)
 {
     jimport("joomla.filesystem.folder");
     if (JEVHelper::isAdminUser()) {
         //  get RSS parsed object
         $options = array();
         $rssUrl = 'https://www.jevents.net/versions30.xml';
         $cache_time = 86400;
         error_reporting(0);
         ini_set('display_errors', 0);
         jimport('simplepie.simplepie');
         // this caching doesn't work!!!
         //$cache = JFactory::getCache('feed_parser', 'callback');
         //$cache->setLifeTime($cache_time);
         //$cache->setCaching(true);
         $rssDoc = new SimplePie(null, null, 0);
         $rssDoc->enable_cache(false);
         $rssDoc->set_feed_url($rssUrl);
         $rssDoc->force_feed(true);
         $rssDoc->set_item_limit(999);
         //$results = $cache->get(array($rssDoc, 'init'), null, false, false);
         $results = $rssDoc->init();
         if ($results == false) {
             return false;
         } else {
             $this->generateVersionsFile($rssDoc);
             $rows = array();
             $items = $rssDoc->get_items();
             foreach ($items as $item) {
                 $apps = array();
                 if (strpos($item->get_title(), "layout_") === 0) {
                     $layout = str_replace("layout_", "", $item->get_title());
                     if (JFolder::exists(JEV_PATH . "views/{$layout}")) {
                         // club layouts
                         $xmlfiles1 = JFolder::files(JEV_PATH . "views/{$layout}", "manifest\\.xml", true, true);
                         if ($xmlfiles1 && count($xmlfiles1) > 0) {
                             foreach ($xmlfiles1 as $manifest) {
                                 if (realpath($manifest) != $manifest) {
                                     continue;
                                 }
                                 if (!($manifestdata = $this->getValidManifestFile($manifest))) {
                                     continue;
                                 }
                                 $app = new stdClass();
                                 $app->name = $manifestdata["name"];
                                 $app->version = $manifestdata["version"];
                                 $apps["layout_" . basename(dirname($manifest))] = $app;
                             }
                         }
                     }
                     // package version
                     if (JFolder::exists(JPATH_ADMINISTRATOR . "/manifests/files")) {
                         // club layouts
                         $xmlfiles1 = JFolder::files(JPATH_ADMINISTRATOR . "/manifests/files", "{$layout}\\.xml", true, true);
                         if (!$xmlfiles1) {
                             continue;
                         }
                         foreach ($xmlfiles1 as $manifest) {
                             if (realpath($manifest) != $manifest) {
                                 continue;
                             }
                             if (!($manifestdata = $this->getValidManifestFile($manifest))) {
                                 continue;
                             }
                             $app = new stdClass();
                             $app->name = $manifestdata["name"];
                             $app->version = $manifestdata["version"];
                             $apps["layout_" . basename(dirname($manifest))] = $app;
                         }
                     }
                 } else {
                     if (strpos($item->get_title(), "module_") === 0) {
                         $module = str_replace("module_", "", $item->get_title());
                         // modules
                         if (JFolder::exists(JPATH_SITE . "/modules/{$module}")) {
                             $xmlfiles1 = JFolder::files(JPATH_SITE . "/modules/{$module}", "\\.xml", true, true);
                             if (!$xmlfiles1) {
                                 continue;
                             }
                             foreach ($xmlfiles1 as $manifest) {
                                 if (realpath($manifest) != $manifest) {
                                     continue;
                                 }
                                 if (!($manifestdata = $this->getValidManifestFile($manifest))) {
                                     continue;
                                 }
                                 $app = new stdClass();
                                 $app->name = $manifestdata["name"];
                                 $app->version = $manifestdata["version"];
                                 $name = "module_" . str_replace(".xml", "", basename($manifest));
                                 $apps[$name] = $app;
                             }
                         }
                     } else {
                         if (strpos($item->get_title(), "plugin_") === 0) {
                             $plugin = explode("_", str_replace("plugin_", "", $item->get_title()), 2);
                             if (count($plugin) < 2) {
                                 continue;
                             }
                             // plugins
//.........这里部分代码省略.........
开发者ID:poorgeek,项目名称:JEvents,代码行数:101,代码来源:view.html.php

示例14: getRSSFeed

 /**
  * Get a specific RSS feed
  *
  * @param $url             string/array   URL of the feed or array of URL
  * @param $cache_duration  timestamp      cache duration (default DAY_TIMESTAMP)
  *
  * @return feed object
  **/
 static function getRSSFeed($url, $cache_duration = DAY_TIMESTAMP)
 {
     global $CFG_GLPI;
     $feed = new SimplePie();
     $feed->set_cache_location(GLPI_RSS_DIR);
     $feed->set_cache_duration($cache_duration);
     // proxy support
     if (!empty($CFG_GLPI["proxy_name"])) {
         $prx_opt = array();
         $prx_opt[CURLOPT_PROXY] = $CFG_GLPI["proxy_name"];
         $prx_opt[CURLOPT_PROXYPORT] = $CFG_GLPI["proxy_port"];
         if (!empty($CFG_GLPI["proxy_user"])) {
             $prx_opt[CURLOPT_HTTPAUTH] = CURLAUTH_ANYSAFE;
             $prx_opt[CURLOPT_PROXYUSERPWD] = $CFG_GLPI["proxy_user"] . ":" . Toolbox::decrypt($CFG_GLPI["proxy_passwd"], GLPIKEY);
         }
         $feed->set_curl_options($prx_opt);
     }
     $feed->enable_cache(true);
     $feed->set_feed_url($url);
     $feed->force_feed(true);
     // Initialize the whole SimplePie object.  Read the feed, process it, parse it, cache it, and
     // all that other good stuff.  The feed's information will not be available to SimplePie before
     // this is called.
     $feed->init();
     // We'll make sure that the right content type and character encoding gets set automatically.
     // This function will grab the proper character encoding, as well as set the content type to text/html.
     $feed->handle_content_type();
     if ($feed->error()) {
         return false;
     }
     return $feed;
 }
开发者ID:stweil,项目名称:glpi,代码行数:40,代码来源:rssfeed.class.php

示例15: items

 public function items()
 {
     if ($this->input->is_ajax_request()) {
         $this->readerself_library->set_template('_json');
         $this->readerself_library->set_content_type('application/json');
         $content = array();
     } else {
         $this->readerself_library->set_template('_plain');
         $this->readerself_library->set_content_type('text/plain');
         $content = '';
     }
     if ($this->input->is_cli_request() && !$this->config->item('refresh_by_cron')) {
         $content .= 'Refresh by cron disabled' . "\n";
     } else {
         include_once 'thirdparty/simplepie/autoloader.php';
         include_once 'thirdparty/simplepie/idn/idna_convert.class.php';
         if ($this->config->item('facebook/enabled')) {
             include_once 'thirdparty/facebook/autoload.php';
             $fb = new Facebook\Facebook(array('app_id' => $this->config->item('facebook/id'), 'app_secret' => $this->config->item('facebook/secret')));
             $fbApp = $fb->getApp();
             $accessToken = $fbApp->getAccessToken();
         }
         $query = $this->db->query('SELECT fed.* FROM ' . $this->db->dbprefix('feeds') . ' AS fed WHERE fed.fed_nextcrawl IS NULL OR fed.fed_nextcrawl <= ? GROUP BY fed.fed_id HAVING (SELECT COUNT(DISTINCT(sub.mbr_id)) FROM ' . $this->db->dbprefix('subscriptions') . ' AS sub WHERE sub.fed_id = fed.fed_id) > 0', array(date('Y-m-d H:i:s')));
         if ($query->num_rows() > 0) {
             $microtime_start = microtime(1);
             $errors = 0;
             foreach ($query->result() as $fed) {
                 $parse_url = parse_url($fed->fed_link);
                 if (isset($parse_url['host']) == 1 && $parse_url['host'] == 'www.facebook.com' && $this->config->item('facebook/enabled')) {
                     try {
                         $parts = explode('/', $parse_url['path']);
                         $total_parts = count($parts);
                         $last_part = $parts[$total_parts - 1];
                         $request = new Facebook\FacebookRequest($fbApp, $accessToken, 'GET', $last_part . '?fields=link,name,about');
                         $response = $fb->getClient()->sendRequest($request);
                         $result = $response->getDecodedBody();
                         $request = new Facebook\FacebookRequest($fbApp, $accessToken, 'GET', $last_part . '?fields=feed{created_time,id,message,story,full_picture,place,type,status_type,link}');
                         $response = $fb->getClient()->sendRequest($request);
                         $posts = $response->getDecodedBody();
                         $this->readerself_library->crawl_items_facebook($fed->fed_id, $posts['feed']['data']);
                         $lastitem = $this->db->query('SELECT itm.itm_datecreated FROM ' . $this->db->dbprefix('items') . ' AS itm WHERE itm.fed_id = ? GROUP BY itm.itm_id ORDER BY itm.itm_id DESC LIMIT 0,1', array($fed->fed_id))->row();
                         $this->db->set('fed_title', $result['name']);
                         $this->db->set('fed_url', $result['link']);
                         $this->db->set('fed_link', $result['link']);
                         if (isset($parse_url['host']) == 1) {
                             $this->db->set('fed_host', $parse_url['host']);
                         }
                         $this->db->set('fed_description', $result['about']);
                         $this->db->set('fed_lasterror', '');
                         $this->db->set('fed_lastcrawl', date('Y-m-d H:i:s'));
                         if ($lastitem) {
                             $nextcrawl = '';
                             //older than 96 hours, next crawl in 12 hours
                             if ($lastitem->itm_datecreated < date('Y-m-d H:i:s', time() - 3600 * 24 * 96)) {
                                 $nextcrawl = date('Y-m-d H:i:s', time() + 3600 * 12);
                                 //older than 48 hours, next crawl in 6 hours
                             } else {
                                 if ($lastitem->itm_datecreated < date('Y-m-d H:i:s', time() - 3600 * 48)) {
                                     $nextcrawl = date('Y-m-d H:i:s', time() + 3600 * 6);
                                     //older than 24 hours, next crawl in 3 hours
                                 } else {
                                     if ($lastitem->itm_datecreated < date('Y-m-d H:i:s', time() - 3600 * 24)) {
                                         $nextcrawl = date('Y-m-d H:i:s', time() + 3600 * 3);
                                     }
                                 }
                             }
                             $this->db->set('fed_nextcrawl', $nextcrawl);
                         }
                         $this->db->where('fed_id', $fed->fed_id);
                         $this->db->update('feeds');
                     } catch (Facebook\Exceptions\FacebookResponseException $e) {
                         $errors++;
                         $this->db->set('fed_lasterror', 'Graph returned an error: ' . $e->getMessage());
                         $this->db->set('fed_lastcrawl', date('Y-m-d H:i:s'));
                         $this->db->where('fed_id', $fed->fed_id);
                         $this->db->update('feeds');
                     } catch (Facebook\Exceptions\FacebookSDKException $e) {
                         $errors++;
                         $this->db->set('fed_lasterror', 'Facebook SDK returned an error: ' . $e->getMessage());
                         $this->db->set('fed_lastcrawl', date('Y-m-d H:i:s'));
                         $this->db->where('fed_id', $fed->fed_id);
                         $this->db->update('feeds');
                     }
                 } else {
                     $sp_feed = new SimplePie();
                     $sp_feed->set_feed_url(convert_to_ascii($fed->fed_link));
                     $sp_feed->enable_cache(false);
                     $sp_feed->set_timeout(5);
                     $sp_feed->force_feed(true);
                     $sp_feed->init();
                     $sp_feed->handle_content_type();
                     if ($sp_feed->error()) {
                         $errors++;
                         $this->db->set('fed_lasterror', $sp_feed->error());
                         $this->db->set('fed_lastcrawl', date('Y-m-d H:i:s'));
                         $this->db->where('fed_id', $fed->fed_id);
                         $this->db->update('feeds');
                     } else {
                         $this->readerself_library->crawl_items($fed->fed_id, $sp_feed->get_items());
                         $lastitem = $this->db->query('SELECT itm.itm_datecreated FROM ' . $this->db->dbprefix('items') . ' AS itm WHERE itm.fed_id = ? GROUP BY itm.itm_id ORDER BY itm.itm_id DESC LIMIT 0,1', array($fed->fed_id))->row();
//.........这里部分代码省略.........
开发者ID:esironal,项目名称:readerself,代码行数:101,代码来源:refresh.php


注:本文中的SimplePie::force_feed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。