コード例 #1
0
 /**
  * Import feeds
  * 
  * @return int
  */
 public function import_feed()
 {
     global $rss_post_importer;
     $this->load_options();
     $post_count = 0;
     // filter cache lifetime
     add_filter('wp_feed_cache_transient_lifetime', array($this, 'frequency'));
     foreach ($this->options['feeds'] as $i => $f) {
         // before the first feed, we check for key validity
         if ($i == 0) {
             $this->is_key_valid = $rss_post_importer->is_valid_key($this->options['settings']['feeds_api_key']);
             $this->options['settings']['is_key_valid'] = $this->is_key_valid;
             // if the key is not fine
             if (!empty($this->options['settings']['feeds_api_key']) && !$this->is_key_valid) {
                 // unset from settings
                 unset($this->options['settings']['feeds_api_key']);
             }
             // update options
             $new_options = array('feeds' => $this->options['feeds'], 'settings' => $this->options['settings'], 'latest_import' => $this->options['latest_import'], 'imports' => $this->options['imports'], 'upgraded' => $this->options['upgraded']);
             // update in db
             update_option('rss_pi_feeds', $new_options);
         }
         // prepare, import feed and count imported posts
         if ($items = $this->do_import($f)) {
             $post_count += count($items);
         }
     }
     // reformulate import count
     $imports = intval($this->options['imports']) + $post_count;
     // update options
     update_option('rss_pi_feeds', array('feeds' => $this->options['feeds'], 'settings' => $this->options['settings'], 'latest_import' => date("Y-m-d H:i:s"), 'imports' => $imports));
     global $rss_post_importer;
     // reload options
     $rss_post_importer->load_options();
     remove_filter('wp_feed_cache_transient_lifetime', array($this, 'frequency'));
     // log this
     rssPILog::log($post_count);
     return $post_count;
 }
コード例 #2
0
 /**
  * Import any feeds
  */
 function ajax_import()
 {
     global $rss_post_importer;
     // if there's nothing for processing or invalid data, bail
     if (!isset($_POST['feed'])) {
         wp_send_json_error(array('message' => 'no feed provided'));
     }
     $_found = false;
     foreach ($this->options['feeds'] as $id => $f) {
         if ($f['id'] == $_POST['feed']) {
             $_found = $id;
             break;
         }
     }
     if ($_found === false) {
         wp_send_json_error(array('message' => 'wrong feed id provided'));
     }
     // TODO: make this better
     if ($_found == 0) {
         // check for valid key only for the first feed
         $this->is_key_valid = $rss_post_importer->is_valid_key($this->options['settings']['feeds_api_key']);
         $this->options['settings']['is_key_valid'] = $this->is_key_valid;
         // if the key is not fine
         if (!empty($this->options['settings']['feeds_api_key']) && !$this->is_key_valid) {
             // unset from settings
             unset($this->options['settings']['feeds_api_key']);
         }
         // update options
         $new_options = array('feeds' => $this->options['feeds'], 'settings' => $this->options['settings'], 'latest_import' => $this->options['latest_import'], 'imports' => $this->options['imports'], 'upgraded' => $this->options['upgraded']);
         // update in db
         update_option('rss_pi_feeds', $new_options);
     }
     $post_count = 0;
     $f = $this->options['feeds'][$_found];
     $engine = new rssPIEngine();
     // filter cache lifetime
     add_filter('wp_feed_cache_transient_lifetime', array($engine, 'frequency'));
     // prepare, import feed and count imported posts
     if ($items = $engine->do_import($f)) {
         $post_count += count($items);
     }
     remove_filter('wp_feed_cache_transient_lifetime', array($engine, 'frequency'));
     // reformulate import count
     $imports = intval($this->options['imports']) + $post_count;
     // update options
     $new_options = array('feeds' => $this->options['feeds'], 'settings' => $this->options['settings'], 'latest_import' => date("Y-m-d H:i:s"), 'imports' => $imports, 'upgraded' => $this->options['upgraded']);
     // update in db
     update_option('rss_pi_feeds', $new_options);
     global $rss_post_importer;
     // reload options
     $rss_post_importer->load_options();
     // log this
     rssPILog::log($post_count);
     wp_send_json_success(array('count' => $post_count, 'url' => $f['url']));
 }