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


PHP SimplePie::error方法代码示例

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


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

示例1: tweetimport_import_twitter_feed

function tweetimport_import_twitter_feed($twitter_account)
{
  require_once (ABSPATH . WPINC . '/class-feed.php');

  $feed = new SimplePie();

  $account_parts = explode ('/', $twitter_account['twitter_name'], 2);



  if ($twitter_account['account_type'] == 1): //Account is Favorites
    $feed->set_feed_url(str_replace('#=#USER#=#', $account_parts[0], TWEETIMPORT_API_FAVORITES_URL));
  elseif ($twitter_account['account_type'] == 0 && count($account_parts) == 1): //User timeline
      $feed->set_feed_url(str_replace('#=#USER#=#', $account_parts[0], TWEETIMPORT_API_USER_TIMELINE_URL));
  elseif ($twitter_account['account_type'] == 2 && count($account_parts) == 2): //Account is list
      $feed_url = str_replace('#=#USER#=#', $account_parts[0], TWEETIMPORT_API_LIST_URL);
      $feed_url = str_replace('#=#LIST#=#', $account_parts[1], $feed_url);
      $feed->set_feed_url($feed_url);
  else :
      return '<strong>ERROR: Account information not correct. Account type wrong?</strong>';
  endif;

  $feed->set_useragent('Tweet Import http://skinju.com/wordpress/tweetimport');
  $feed->set_cache_class('WP_Feed_Cache');
  $feed->set_file_class('WP_SimplePie_File');
  $feed->enable_cache(true);
  $feed->set_cache_duration (apply_filters('tweetimport_cache_duration', 880));
  $feed->enable_order_by_date(false);
  $feed->init();
  $feed->handle_content_type();

  if ($feed->error()):
   return '<strong>ERROR: Feed Reading Error.</strong>';
  endif;

  $rss_items = $feed->get_items();

  $imported_count = 0;
  foreach ($rss_items as $item)
  {
    $item = apply_filters ('tweetimport_tweet_before_new_post', $item); //return false to stop processing an item.
    if (!$item) continue;

    $processed_description = $item->get_description();

    //Get the twitter author from the beginning of the tweet text
    $twitter_author = trim(preg_replace("~^(\w+):(.*?)$~", "\\1", $processed_description));

    if ($twitter_account['strip_name'] == 1):
      $processed_description = preg_replace("~^(\w+):(.*?)~i", "\\2", $processed_description);
    endif;

    if ($twitter_account['names_clickable'] == 1):
      $processed_description = preg_replace("~@(\w+)~", "<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>", $processed_description);
      $processed_description = preg_replace("~^(\w+):~", "<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>:", $processed_description);
    endif;

    if ($twitter_account['hashtags_clickable'] == 1):
      if ($twitter_account['hashtags_clickable_twitter'] == 1):
          $processed_description = preg_replace("/#(\w+)/", "<a href=\"http://search.twitter.com/search?q=\\1\" target=\"_blank\">#\\1</a>", $processed_description);
      else:
        $processed_description = preg_replace("/#(\w+)/", "<a href=\"" . skinju_get_tag_link("\\1") . "\">#\\1</a>", $processed_description);
      endif;
    endif;

  $processed_description = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $processed_description);
  $processed_description = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $processed_description);

    $new_post = array('post_title' => trim (substr (preg_replace("~{$account_parts[0]}: ~i", "", $item->get_title()), 0, 25) . '...'),
                      'post_content' => trim ($processed_description),
                      'post_date' => $item->get_date('Y-m-d H:i:s'),
                      'post_author' => $twitter_account['author'],
                      'post_category' => array($twitter_account['category']),
                      'post_status' => 'publish');

    $new_post = apply_filters('tweetimport_new_post_before_create', $new_post); // Offer the chance to manipulate new post data. return false to skip
    if (!$new_post) continue;
    $new_post_id = wp_insert_post($new_post);

    $imported_count++;

    add_post_meta ($new_post_id, 'tweetimport_twitter_author', $twitter_author, true); 
    add_post_meta ($new_post_id, 'tweetimport_date_imported', date ('Y-m-d H:i:s'), true);
    add_post_meta ($new_post_id, 'tweetimport_twitter_id', $item->get_id(), true);
    add_post_meta ($new_post_id, 'tweetimport_twitter_id', $item->get_id(), true);
    add_post_meta ($new_post_id, '_tweetimport_twitter_id_hash', $item->get_id(true), true);
    add_post_meta ($new_post_id, 'tweetimport_twitter_post_uri', $item->get_link(0));
    add_post_meta ($new_post_id, 'tweetimport_author_avatar', $item->get_link(0, 'image'));

    preg_match_all ('~#([A-Za-z0-9_]+)(?=\s|\Z)~', $item->get_description(), $out);
    if ($twitter_account['add_tag']) $out[0][] = $twitter_account['add_tag'];
    wp_set_post_tags($new_post_id, implode (',', $out[0]));
  }

  return $imported_count;
}
开发者ID:robotconscience,项目名称:Robotconscience.com,代码行数:96,代码来源:tweet-import.php

示例2: 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));
     }
 }
开发者ID:sandeepone,项目名称:reclaim-social-media,代码行数:35,代码来源:goodreads.class.php

示例3: getFeedItems

 /**
  * Fetches and parses an RSS or Atom feed, and returns its items.
  *
  * Each element in the returned array will have the following keys:
  *
  * - **authors** – An array of the item’s authors, where each sub-element has the following keys:
  *     - **name** – The author’s name
  *     - **url** – The author’s URL
  *     - **email** – The author’s email
  * - **categories** – An array of the item’s categories, where each sub-element has the following keys:
  *     - **term** – The category’s term
  *     - **scheme** – The category’s scheme
  *     - **label** – The category’s label
  * - **content** – The item’s main content.
  * - **contributors** – An array of the item’s contributors, where each sub-element has the following keys:
  *     - **name** – The contributor’s name
  *     - **url** – The contributor’s URL
  *     - **email** – The contributor’s email
  * - **date** – A {@link DateTime} object representing the item’s date.
  * - **dateUpdated** – A {@link DateTime} object representing the item’s last updated date.
  * - **permalink** – The item’s URL.
  * - **summary** – The item’s summary content.
  * - **title** – The item’s title.
  *
  * @param string $url           The feed’s URL.
  * @param int    $limit         The maximum number of items to return. Default is 0 (no limit).
  * @param int    $offset        The number of items to skip. Defaults to 0.
  * @param string $cacheDuration Any valid [PHP time format](http://www.php.net/manual/en/datetime.formats.time.php).
  *
  * @return array|string The list of feed items.
  */
 public function getFeedItems($url, $limit = 0, $offset = 0, $cacheDuration = null)
 {
     $items = array();
     if (!extension_loaded('dom')) {
         Craft::log('Craft needs the PHP DOM extension (http://www.php.net/manual/en/book.dom.php) enabled to parse feeds.', LogLevel::Warning);
         return $items;
     }
     if (!$cacheDuration) {
         $cacheDuration = craft()->config->getCacheDuration();
     } else {
         $cacheDuration = DateTimeHelper::timeFormatToSeconds($cacheDuration);
     }
     $feed = new \SimplePie();
     $feed->set_feed_url($url);
     $feed->set_cache_location(craft()->path->getCachePath());
     $feed->set_cache_duration($cacheDuration);
     $feed->init();
     // Something went wrong.
     if ($feed->error()) {
         Craft:
         log('There was a problem parsing the feed: ' . $feed->error(), LogLevel::Warning);
         return array();
     }
     foreach ($feed->get_items($offset, $limit) as $item) {
         $date = $item->get_date('U');
         $dateUpdated = $item->get_updated_date('U');
         $items[] = array('authors' => $this->_getItemAuthors($item->get_authors()), 'categories' => $this->_getItemCategories($item->get_categories()), 'content' => $item->get_content(true), 'contributors' => $this->_getItemAuthors($item->get_contributors()), 'date' => $date ? new DateTime('@' . $date) : null, 'dateUpdated' => $dateUpdated ? new DateTime('@' . $dateUpdated) : null, 'permalink' => $item->get_permalink(), 'summary' => $item->get_description(true), 'title' => $item->get_title(), 'enclosures' => $this->_getEnclosures($item->get_enclosures()));
     }
     return $items;
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:61,代码来源:FeedsService.php

示例4: 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

示例5: addAction

 public function addAction()
 {
     require_once PLUGIN_DIR . "/FeedImporter/libraries/SimplePie/simplepie.inc";
     $feed = new SimplePie();
     $varName = strtolower($this->_modelClass);
     $class = $this->_modelClass;
     $record = new FeedImporter_Feed();
     //Need an id to work with the tags, so save it now, even though it might be sloppy/confusing
     $record->save();
     if ($_GET['feed_url']) {
         $feed_url = $_GET['feed_url'];
         $debug = new stdClass();
         $feed->set_feed_url($feed_url);
         // Run SimplePie.
         $feed->init();
         $feed->handle_content_type();
         if ($feed->error()) {
             $this->flash($feed->error());
             //return here?
         }
         $debug->title = $feed->get_title();
         $debug->description = $feed->get_description();
         //Set up the tag configurations for the first import
         $import = new FeedImporter_Import();
         $import->processFeedTags($feed, $record->id);
         $record->feed_url = $feed_url;
         $record->feed_title = $feed->get_title();
         $record->feed_description = $feed->get_description();
     }
     $record->save();
     // Create a new FakeCron_Task for the feed
     $fc_task = new FakeCron_Task();
     $fc_task->interval = 0;
     $fc_task->name = "Cron for feed " . $record->feed_title;
     $fc_task->plugin_class = "FeedImporter_FakeCronTask";
     $fc_task->plugin_name = 'FeedImporter';
     $fc_task->params = serialize(array($record->id));
     $fc_task->save();
     $record->task_id = $fc_task->id;
     $_POST['task_id'] = $fc_task->id;
     $this->view->assign(array($varName => $record));
     try {
         if ($record->saveForm($_POST)) {
             $this->redirect->goto('browse');
         }
     } catch (Omeka_Validator_Exception $e) {
         $this->flashValidationErrors($e);
     } catch (Exception $e) {
         $this->flash($e->getMessage());
     }
 }
开发者ID:patrickmj,项目名称:FeedImporter,代码行数:51,代码来源:FeedsController.php

示例6: doImport

 public function doImport()
 {
     _log("Feed Import Started at " . date('c'));
     $db = get_db();
     $hasError = false;
     require_once PLUGIN_DIR . "/FeedImporter/libraries/SimplePie/simplepie.inc";
     $this->fi_feed = $db->getTable('FeedImporter_Feed')->find($this->feed_id);
     $this->fi_tags = $db->getTable('FeedImporter_TagConfig')->findByFeedId($this->feed_id, true);
     if ($this->fi_feed->map_authors) {
         $this->authorsMap = unserialize($this->fi_feed->authors_map);
     }
     $sp_feed = new SimplePie();
     $sp_feed->enable_cache(false);
     $sp_feed->set_feed_url($this->fi_feed->feed_url);
     $sp_feed->handle_content_type();
     // Run SimplePie.
     $sp_feed->init();
     if ($sp_feed->error()) {
         $hasError = true;
         $this->status = self::STATUS_FEED_ERRORS;
         $this->sp_error = $sp_feed->error();
         $this->save();
         return false;
     }
     if (!$hasError) {
         foreach ($sp_feed->get_items() as $sp_item) {
             if ($this->_needsImport($sp_item)) {
                 $this->processItemTags($sp_item);
                 $metadataArray = $this->buildFeedItemMetadata($sp_item);
                 $elementTextsArray = $this->buildFeedItemElementTexts($sp_item);
                 $newOmekaItem = insert_item($metadataArray, $elementTextsArray);
                 $newImportedItem = new FeedImporter_ImportedItem();
                 $newImportedItem->item_id = $newOmekaItem->id;
                 $newImportedItem->feed_id = $this->fi_feed->id;
                 $newImportedItem->import_id = $this->id;
                 $newImportedItem->sp_id = $sp_item->get_id();
                 $newImportedItem->save();
                 $this->_buildFeedItemItemTypeData($sp_item, $newOmekaItem);
                 $license = $sp_item->get_link(0, 'license');
                 if ($this->fi_feed->import_media && !empty($license)) {
                     $this->_doFileImportForItem($sp_item, $newOmekaItem);
                 }
             }
         }
     }
     $this->status = self::STATUS_COMPLETED_IMPORT;
     $this->save();
     return true;
 }
开发者ID:patrickmj,项目名称:FeedImporter,代码行数:49,代码来源:Import.php

示例7: add

 /**
  * Add a new feed to the database
  *
  * Adds the specified feed name and URL to the database. If no name is set
  * by the user, it fetches one from the feed. If the URL specified is a HTML
  * page and not a feed, it lets SimplePie do autodiscovery and uses the XML
  * url returned.
  *
  * @since 1.0
  *
  * @param string $url URL to feed or website (if autodiscovering)
  * @param string $name Title/Name of feed
  * @param string $cat Category to add feed to
  * @return bool True if succeeded, false if failed
  */
 public function add($url, $name = '', $cat = 'default')
 {
     if (empty($url)) {
         throw new Exception(_r("Couldn't add feed: No feed URL supplied"), Errors::get_code('admin.feeds.no_url'));
     }
     if (!preg_match('#https|http|feed#', $url)) {
         if (strpos($url, '://')) {
             throw new Exception(_r('Unsupported URL protocol'), Errors::get_code('admin.feeds.protocol_error'));
         }
         $url = 'http://' . $url;
     }
     require_once LILINA_INCPATH . '/contrib/simplepie/simplepie.inc';
     $feed_info = new SimplePie();
     $feed_info->set_useragent(LILINA_USERAGENT . ' SimplePie/' . SIMPLEPIE_BUILD);
     $feed_info->set_stupidly_fast(true);
     $feed_info->set_cache_location(get_option('cachedir'));
     $feed_info->set_favicon_handler(get_option('baseurl') . '/lilina-favicon.php');
     $feed_info->set_feed_url($url);
     $feed_info->init();
     $feed_error = $feed_info->error();
     $feed_url = $feed_info->subscribe_url();
     if (!empty($feed_error)) {
         throw new Exception(sprintf(_r("Couldn't add feed: %s is not a valid URL or the server could not be accessed. Additionally, no feeds could be found by autodiscovery."), $url), Errors::get_code('admin.feeds.invalid_url'));
     }
     if (empty($name)) {
         //Get it from the feed
         $name = $feed_info->get_title();
     }
     $id = sha1($feed_url);
     $this->feeds[$id] = array('feed' => $feed_url, 'url' => $feed_info->get_link(), 'id' => $id, 'name' => $name, 'cat' => $cat, 'icon' => $feed_info->get_favicon());
     $this->feeds[$id] = apply_filters('feed-create', $this->feeds[$id], $url);
     $this->save();
     return array('msg' => sprintf(_r('Added feed "%1$s"'), $name), 'id' => $id);
 }
开发者ID:BackupTheBerlios,项目名称:oos-svn,代码行数:49,代码来源:class-feeds.php

示例8: 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;
 }
开发者ID:wilxsv,项目名称:prevensionPublicLibrary,代码行数:19,代码来源:rss-via-shortcode.php

示例9: getFeedItems

 /**
  * Fetches and parses an RSS or Atom feed, and returns its items.
  *
  * Each element in the returned array will have the following keys:
  *
  * - **authors** – An array of the item’s authors, where each sub-element has the following keys:
  *     - **name** – The author’s name
  *     - **url** – The author’s URL
  *     - **email** – The author’s email
  * - **categories** – An array of the item’s categories, where each sub-element has the following keys:
  *     - **term** – The category’s term
  *     - **scheme** – The category’s scheme
  *     - **label** – The category’s label
  * - **content** – The item’s main content.
  * - **contributors** – An array of the item’s contributors, where each sub-element has the following keys:
  *     - **name** – The contributor’s name
  *     - **url** – The contributor’s URL
  *     - **email** – The contributor’s email
  * - **date** – A {@link DateTime} object representing the item’s date.
  * - **dateUpdated** – A {@link DateTime} object representing the item’s last updated date.
  * - **permalink** – The item’s URL.
  * - **summary** – The item’s summary content.
  * - **title** – The item’s title.
  *
  * @param string $url           The feed’s URL.
  * @param int    $limit         The maximum number of items to return. Default is 0 (no limit).
  * @param int    $offset        The number of items to skip. Defaults to 0.
  * @param string $cacheDuration Any valid [PHP time format](http://www.php.net/manual/en/datetime.formats.time.php).
  *
  * @return array|string The list of feed items.
  */
 public function getFeedItems($url, $limit = 0, $offset = 0, $cacheDuration = null)
 {
     $items = array();
     if (!extension_loaded('dom')) {
         Craft::log('Craft needs the PHP DOM extension (http://www.php.net/manual/en/book.dom.php) enabled to parse feeds.', LogLevel::Warning);
         return $items;
     }
     if (!$cacheDuration) {
         $cacheDuration = craft()->config->getCacheDuration();
     } else {
         $cacheDuration = DateTimeHelper::timeFormatToSeconds($cacheDuration);
     }
     // Potentially long-running request, so close session to prevent session blocking on subsequent requests.
     craft()->session->close();
     $feed = new \SimplePie();
     $feed->set_feed_url($url);
     $feed->set_cache_location(craft()->path->getCachePath());
     $feed->set_cache_duration($cacheDuration);
     $feed->init();
     // Something went wrong.
     if ($feed->error()) {
         Craft::log('There was a problem parsing the feed: ' . $feed->error(), LogLevel::Warning);
         return array();
     }
     foreach ($feed->get_items($offset, $limit) as $item) {
         // Validate the permalink
         $permalink = $item->get_permalink();
         if ($permalink) {
             $urlModel = new UrlModel();
             $urlModel->url = $item->get_permalink();
             if (!$urlModel->validate()) {
                 Craft::log('An item was omitted from the feed (' . $url . ') because its permalink was an invalid URL: ' . $permalink);
                 continue;
             }
         }
         $date = $item->get_date('U');
         $dateUpdated = $item->get_updated_date('U');
         $items[] = array('authors' => $this->_getItemAuthors($item->get_authors()), 'categories' => $this->_getItemCategories($item->get_categories()), 'content' => $item->get_content(true), 'contributors' => $this->_getItemAuthors($item->get_contributors()), 'date' => $date ? new DateTime('@' . $date) : null, 'dateUpdated' => $dateUpdated ? new DateTime('@' . $dateUpdated) : null, 'permalink' => $item->get_permalink(), 'summary' => $item->get_description(true), 'title' => $item->get_title(), 'enclosures' => $this->_getEnclosures($item->get_enclosures()));
     }
     return $items;
 }
开发者ID:scisahaha,项目名称:generator-craft,代码行数:72,代码来源:FeedsService.php

示例10: read

 static function read($feed)
 {
     $parser = new SimplePie();
     $parser->set_feed_url($feed);
     $parser->set_cache_location(storage_path() . '/cache');
     $parser->set_cache_duration(100);
     $success = $parser->init();
     $parser->handle_content_type();
     if ($parser->error() || !$success) {
         return null;
     } else {
         return $parser->get_items();
     }
 }
开发者ID:basdog22,项目名称:laracms,代码行数:14,代码来源:Feedreader.php

示例11: urlencode

 /**
  * Geonames Feeds GeoCoding (RSS to GEORSS)
  * Due to limitations, this returns only 20 items
  *
  * @param   string location / address
  * @return  string raw georss data
  */
 function geocode_feed($feed_url = NULL)
 {
     $base_url = "http://" . GEOCODER_GEONAMES . "/rssToGeoRSS?";
     // Only requests service if we have an user
     $geocode_username = Settings_Model::get_setting('feed_geolocation_user');
     if ($feed_url && !empty($geocode_username)) {
         // First check to make sure geonames webservice is running
         $geonames_status = @remote::status($base_url);
         if ($geonames_status == "200") {
             // Successful
             $request_url = $base_url . "&feedUrl=" . urlencode($feed_url) . "&username=" . $geocode_username;
         } else {
             // Down perhaps?? Use direct feed
             $request_url = $feed_url;
         }
         $request = new HttpClient($request_url);
         if (!($georss = $request->execute($request_url))) {
             // If the request failed, something may be wrong with the GEOCODER_GEONAMES service
             return false;
         }
         //$georss = utf8_encode($georss);
         // Lez verify this we got a good reply from the geocoder before proceeding
         $data = new SimplePie();
         $data->set_raw_data($georss);
         $data->init();
         $data->handle_content_type();
         // Feed no good - get outta here!
         if ($data->error()) {
             Kohana::log('error', $data->error() . $request_url);
             return false;
         }
         return trim($georss);
     } else {
         return false;
     }
 }
开发者ID:Dirichi,项目名称:Ushahidi_Web,代码行数:43,代码来源:Geocoder.php

示例12: 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;
}
开发者ID:mattsims,项目名称:powerpress,代码行数:45,代码来源:powerpressadmin-dashboard.php

示例13: setCron

 public function setCron()
 {
     $getUnique = $this->getAllFeedUrls();
     if (!empty($getUnique)) {
         foreach ($getUnique as $feedTableData) {
             $feed_user_title = $feedTableData->feed_user_title;
             $feed_url = $feedTableData->feed_admin_url;
             $usercat = $feedTableData->feed_user_category;
             $feed_filter_type = $feedTableData->feed_filter_type;
             $favicon_icon = $feedTableData->feed_favicon;
             $feed = new SimplePie();
             $feed->set_feed_url($feed_url);
             $feed->set_cache_location(APPPATH . '/cache');
             $feed->set_output_encoding('ISO-8859-1');
             $feed->init();
             $feed->handle_content_type();
             // Language
             $lang = $feed->get_language();
             $language = isset($lang) ? $lang : 'en-us';
             if ($feed->get_type() & SIMPLEPIE_TYPE_NONE) {
                 $feed_type = 'Unknown';
             } elseif ($feed->get_type() & SIMPLEPIE_TYPE_RSS_ALL) {
                 $feed_type = 'RSS';
             } elseif ($feed->get_type() & SIMPLEPIE_TYPE_ATOM_ALL) {
                 $feed_type = 'Atom';
             } elseif ($feed->get_type() & SIMPLEPIE_TYPE_ALL) {
                 $feed_type = 'Supported';
             }
             // Author
             if ($author = $feed->get_author()) {
                 $feedAuthor = $author->get_name();
             } else {
                 $feedAuthor = '';
             }
             if ($feed->error()) {
                 die;
             } else {
                 $feed_image_link = $feed->get_image_link();
                 $feed_image_url = $feed->get_image_url();
                 $feed_image_title = $feed->get_image_title();
                 $this->addFeeds($feed->get_items(0, 500), $feed_image_link, $feed_image_url, $feed_image_title, $usercat, $feed_url, $language, $feed_type, $feedAuthor, $feed_filter_type, $feed_user_title, $favicon_icon);
             }
         }
     }
 }
开发者ID:robdmat,项目名称:sport.net,代码行数:45,代码来源:cron_model.php

示例14: create

 /**
  * Create a SimplePie object
  * @param  string  $url        URL of the RSS feed to parse
  * @param  integer $duration   Length of the cache in minutes
  * @param  string  $cache_name Name of the cache directory within /cache
  * @return Object              SimplePie object
  */
 public function create($url, $duration = 180, $cache_name = '')
 {
     $feed = new SimplePie();
     $feed->set_feed_url($url);
     // Load our own caching driver for SimplePie
     $feed->registry->call('Cache', 'register', array('ee', 'EE_SimplePie_Cache_driver'));
     // Establish the cache
     $feed->set_cache_location('ee:' . $cache_name);
     $feed->set_cache_duration($duration * 60);
     // Get parameter to seconds
     // Check to see if the feed was initialized, if so, deal with the type
     $success = $feed->init();
     $feed->handle_content_type();
     if ($success) {
         return $feed;
     }
     throw new Exception("RSS Parser Error: " . $feed->error());
 }
开发者ID:realfluid,项目名称:umbaugh,代码行数:25,代码来源:rss_parser.php

示例15: add

 /**
  * Add a new feed to the database
  *
  * Adds the specified feed name and URL to the database. If no name is set
  * by the user, it fetches one from the feed. If the URL specified is a HTML
  * page and not a feed, it lets SimplePie do autodiscovery and uses the XML
  * url returned.
  *
  * @since 1.0
  *
  * @param string $url URL to feed or website (if autodiscovering)
  * @param string $name Title/Name of feed
  * @param string $cat Category to add feed to
  * @return bool True if succeeded, false if failed
  */
 public function add($url, $name = '', $cat = 'default')
 {
     if (empty($url)) {
         throw new Exception(_r("Couldn't add feed: No feed URL supplied"), Errors::get_code('admin.feeds.no_url'));
     }
     if (!preg_match('#https|http|feed#', $url)) {
         if (strpos($url, '://')) {
             throw new Exception(_r('Unsupported URL protocol'), Errors::get_code('admin.feeds.protocol_error'));
         }
         $url = 'http://' . $url;
     }
     $reporting = error_reporting();
     error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR);
     require_once LILINA_INCPATH . '/contrib/simplepie.class.php';
     // Need this for LILINA_USERAGENT
     class_exists('HTTPRequest');
     require_once LILINA_INCPATH . '/core/class-httprequest.php';
     $feed_info = new SimplePie();
     $feed_info->set_useragent(LILINA_USERAGENT . ' SimplePie/' . SIMPLEPIE_BUILD);
     $feed_info->set_stupidly_fast(true);
     $feed_info->set_cache_location(get_option('cachedir'));
     $feed_info->set_feed_url($url);
     $feed_info->init();
     $feed_error = $feed_info->error();
     $feed_url = $feed_info->subscribe_url();
     if (!empty($feed_error)) {
         throw new Exception(sprintf(_r("Couldn't add feed: %s is not a valid URL or the server could not be accessed. Additionally, no feeds could be found by autodiscovery."), $url), Errors::get_code('admin.feeds.invalid_url'));
     }
     if (empty($name)) {
         //Get it from the feed
         $name = $feed_info->get_title();
     }
     $id = sha1($feed_url);
     // Do a naive check to see if the feed already exists
     if ($this->get($id) !== false) {
         throw new Exception(_r("Couldn't add feed: you have already added that feed"), Errors::get_code('admin.feeds.feed_already_exists'));
     }
     $this->feeds[$id] = array('feed' => $feed_url, 'url' => $feed_info->get_link(), 'id' => $id, 'name' => $name, 'cat' => $cat, 'icon' => self::discover_favicon($feed_info, $id));
     $this->feeds[$id] = apply_filters('feed-create', $this->feeds[$id], $url, $feed_info);
     $this->save();
     error_reporting($reporting);
     return array('msg' => sprintf(_r('Added feed "%1$s"'), $name), 'id' => $id);
 }
开发者ID:JocelynDelalande,项目名称:Lilina,代码行数:58,代码来源:class-feeds.php


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