RSS Post Importer - Version 2.0.5

Version Description

Download this release

Release Info

Developer phpaddicted
Plugin Icon 128x128 RSS Post Importer
Version 2.0.5
Comparing to
See all releases

Code changes from version 2.0.4 to 2.0.5

app/classes/admin/class-rss-pi-admin.php CHANGED
@@ -76,6 +76,9 @@ class rssPIAdmin {
76
 
77
  // disable the feed author dropdown for invalid/absent API keys
78
  add_filter('wp_dropdown_users', array($this, 'disable_user_dropdown'));
 
 
 
79
  }
80
 
81
  /**
@@ -109,7 +112,13 @@ class rssPIAdmin {
109
  );
110
  wp_localize_script('rss-pi', 'rss_pi', $localise_args);
111
  }
112
-
 
 
 
 
 
 
113
  /**
114
  * Display the screen/ui
115
  */
76
 
77
  // disable the feed author dropdown for invalid/absent API keys
78
  add_filter('wp_dropdown_users', array($this, 'disable_user_dropdown'));
79
+
80
+ // Add 10 minutes in frequency.
81
+ add_filter('cron_schedules', array($this, 'rss_pi_cron_add'));
82
  }
83
 
84
  /**
112
  );
113
  wp_localize_script('rss-pi', 'rss_pi', $localise_args);
114
  }
115
+ function rss_pi_cron_add($schedules){
116
+ $schedules['minutes_10'] = array(
117
+ 'interval' => 600,
118
+ 'display'=> '10 minutes'
119
+ );
120
+ return $schedules;
121
+ }
122
  /**
123
  * Display the screen/ui
124
  */
app/classes/helpers/class-rss-pi-featured-image.php CHANGED
@@ -1,76 +1,117 @@
1
- <?php
2
- /**
3
- * Sets a featured image
4
- *
5
- * @author Saurabh Shukla <saurabh@yapapaya.com>
6
- */
7
- class rssPIFeaturedImage {
8
-
9
- /**
10
- * Sets featured image
11
- *
12
- * @param object $item Feed item
13
- * @param int $post_id Post id
14
- * @return boolean
15
- */
16
- function _set($item, $post_id) {
17
-
18
- $content = $item->get_content() != "" ? $item->get_content() : $item->get_description();
19
-
20
- // get the first image from content
21
- preg_match('/<img.+?src="(.+?)"[^}]+>/i', $content, $matches);
22
- $img_url = (is_array($matches) && !empty($matches)) ? $matches[1] : '';
23
-
24
- if (empty($img_url)) {
25
- return false;
26
- }
27
-
28
- // sideload it
29
- $featured_id = $this->_sideload($img_url, $post_id, '');
30
-
31
- add_action('set_rss_pi_featured_image', $featured_id, $post_id);
32
-
33
- // set as featured image
34
- return $meta_id = set_post_thumbnail($post_id, $featured_id);
35
- }
36
-
37
- /**
38
- * Modification of default media_sideload_image
39
- *
40
- * @param type $file
41
- * @param type $post_id
42
- * @param type $desc
43
- * @return type
44
- */
45
- private function _sideload($file, $post_id, $desc = null) {
46
- $id = 0;
47
-
48
- if (!empty($file)) {
49
- // Set variables for storage, fix file filename for query strings.
50
- preg_match('/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches);
51
- $file_array = array();
52
- $file_array['name'] = basename($file);
53
-
54
- // Download file to temp location.
55
- $file_array['tmp_name'] = download_url($file);
56
-
57
- // If error storing temporarily, return the error.
58
- if (is_wp_error($file_array['tmp_name'])) {
59
- return $file_array['tmp_name'];
60
- }
61
-
62
- // Do the validation and storage stuff.
63
- $id = media_handle_sideload($file_array, $post_id, $desc);
64
-
65
- // If error storing permanently, unlink.
66
- if (is_wp_error($id)) {
67
- @unlink($file_array['tmp_name']);
68
- return $id;
69
- }
70
- }
71
-
72
- return $id;
73
- }
74
-
75
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  }
1
+ <?php
2
+ /**
3
+ * Sets a featured image
4
+ *
5
+ * @author Saurabh Shukla <saurabh@yapapaya.com>
6
+ */
7
+ if ( !function_exists('download_url') ) {
8
+ require_once(ABSPATH.'/wp-admin/includes/file.php');
9
+ };
10
+
11
+ if ( !function_exists('media_handle_sideload') ) {
12
+ require_once(ABSPATH . "wp-admin" . '/includes/image.php');
13
+ require_once(ABSPATH . "wp-admin" . '/includes/file.php');
14
+ require_once(ABSPATH . "wp-admin" . '/includes/media.php');
15
+ };
16
+ class rssPIFeaturedImage {
17
+
18
+ /**
19
+ * Sets featured image
20
+ *
21
+ * @param object $item Feed item
22
+ * @param int $post_id Post id
23
+ * @return boolean
24
+ */
25
+ function _set($item, $post_id) {
26
+
27
+ $content = $item->get_content() != "" ? $item->get_content() : $item->get_description();
28
+
29
+
30
+ // catch base url
31
+ preg_match('/href="(.+?)"/i', $content, $matches);
32
+ $baseref = (is_array($matches) && !empty($matches)) ? $matches[1] : '';
33
+
34
+ // get the first image from content
35
+ preg_match('/<img.+?src="(.+?)"[^}]+>/i', $content, $matches);
36
+ $img_url = (is_array($matches) && !empty($matches)) ? $matches[1] : '';
37
+
38
+ if (empty($img_url)) {
39
+ return false;
40
+ }
41
+
42
+ $img_host = parse_url($img_url, PHP_URL_HOST);
43
+
44
+ if (empty($img_host)) {
45
+
46
+ if (empty($baseref)) {
47
+ return false;
48
+ };
49
+
50
+ $bc = parse_url($baseref);
51
+ $scheme = (empty($bc["scheme"])) ? "http" : $bc["scheme"];
52
+ $port = $bc["port"];
53
+ $host = $bc["host"];
54
+ if (empty($host)) {
55
+ return false;
56
+ };
57
+
58
+ $img_url = $scheme . ":" . $port . "//" . $host . $img_url;
59
+ }
60
+
61
+ // get the first image from content
62
+ /*preg_match('/<img.+?src="(.+?)"[^}]+>/i', $content, $matches);
63
+ $img_url = (is_array($matches) && !empty($matches)) ? $matches[1] : '';
64
+
65
+ if (empty($img_url)) {
66
+ return false;
67
+ }
68
+ */
69
+ // sideload it
70
+ $featured_id = $this->_sideload($img_url, $post_id, '');
71
+
72
+ add_action('set_rss_pi_featured_image', $featured_id, $post_id);
73
+
74
+ // set as featured image
75
+ return $meta_id = set_post_thumbnail($post_id, $featured_id);
76
+ }
77
+
78
+ /**
79
+ * Modification of default media_sideload_image
80
+ *
81
+ * @param type $file
82
+ * @param type $post_id
83
+ * @param type $desc
84
+ * @return type
85
+ */
86
+ private function _sideload($file, $post_id, $desc = null) {
87
+ $id = 0;
88
+
89
+ if (!empty($file)) {
90
+ // Set variables for storage, fix file filename for query strings.
91
+ preg_match('/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches);
92
+ $file_array = array();
93
+ $file_array['name'] = basename($file);
94
+
95
+ // Download file to temp location.
96
+ $file_array['tmp_name'] = download_url($file);
97
+
98
+ // If error storing temporarily, return the error.
99
+ if (is_wp_error($file_array['tmp_name'])) {
100
+ return $file_array['tmp_name'];
101
+ }
102
+
103
+ // Do the validation and storage stuff.
104
+ $id = media_handle_sideload($file_array, $post_id, $desc);
105
+
106
+ // If error storing permanently, unlink.
107
+ if (is_wp_error($id)) {
108
+ @unlink($file_array['tmp_name']);
109
+ return $id;
110
+ }
111
+ }
112
+
113
+ return $id;
114
+ }
115
+
116
+
117
  }
app/classes/import/class-rss-pi-cron.php CHANGED
@@ -1,41 +1,47 @@
1
- <?php
2
-
3
- /**
4
- * Handles cron jobs
5
- *
6
- * @author Saurabh Shukla <saurabh@yapapaya.com>
7
- */
8
- class rssPICron {
9
-
10
- /**
11
- * Initialise
12
- */
13
- public function init() {
14
-
15
- // hook up scheduled events
16
- add_action('wp', array(&$this, 'schedule'));
17
-
18
- add_action('rss_pi_cron', array(&$this, 'do_hourly'));
19
- }
20
-
21
- /**
22
- * Check and confirm scheduling
23
- */
24
- function schedule() {
25
-
26
- if (!wp_next_scheduled('rss_pi_cron')) {
27
-
28
- wp_schedule_event(time(), 'hourly', 'rss_pi_cron');
29
- }
30
- }
31
-
32
- /**
33
- * Import the feeds on schedule
34
- */
35
- function do_hourly() {
36
-
37
- $engine = new rssPIEngine();
38
- $engine->import_feed();
39
- }
40
-
41
- }
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Handles cron jobs
5
+ *
6
+ * @author Saurabh Shukla <saurabh@yapapaya.com>
7
+ */
8
+ class rssPICron {
9
+
10
+ /**
11
+ * Initialise
12
+ */
13
+ public function init() {
14
+
15
+ // hook up scheduled events
16
+ add_action('wp', array(&$this, 'schedule'));
17
+
18
+ add_action('rss_pi_cron', array(&$this, 'do_hourly'));
19
+
20
+
21
+ }
22
+
23
+ /**
24
+ * Check and confirm scheduling
25
+ */
26
+ function schedule() {
27
+
28
+ if (!wp_next_scheduled('rss_pi_cron')) {
29
+
30
+ wp_schedule_event(time(), 'hourly', 'rss_pi_cron');
31
+ }
32
+ }
33
+
34
+ /**
35
+ * Import the feeds on schedule
36
+ */
37
+ function do_hourly() {
38
+
39
+ $engine = new rssPIEngine();
40
+ $engine->import_feed();
41
+ }
42
+
43
+
44
+
45
+
46
+
47
+ }
app/classes/import/class-rss-pi-engine.php CHANGED
@@ -321,6 +321,25 @@ class rssPIEngine {
321
  'post_date' => $item->get_date('Y-m-d H:i:s')
322
  );
323
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
324
  // insert as post
325
  $post_id = $this->_insert($post, $item->get_permalink());
326
 
321
  'post_date' => $item->get_date('Y-m-d H:i:s')
322
  );
323
 
324
+ $content = $post["post_content"];
325
+
326
+ // catch base url
327
+ if (preg_match('/src="\//i', $content)) {
328
+ preg_match('/href="(.+?)"/i', $content, $matches);
329
+ $baseref = (is_array($matches) && !empty($matches)) ? $matches[1] : '';
330
+ if (!empty($baseref)) {
331
+ $bc = parse_url($baseref);
332
+ $scheme = (empty($bc["scheme"])) ? "http" : $bc["scheme"];
333
+ $port = $bc["port"];
334
+ $host = $bc["host"];
335
+ if (!empty($host)) {
336
+ $preurl = $scheme . ":" . $port . "//" . $host;
337
+ $post["post_content"] = preg_replace('/(src="\/)/i', 'src="' . $preurl . "/", $content);
338
+ }
339
+ }
340
+ }
341
+
342
+
343
  // insert as post
344
  $post_id = $this->_insert($post, $item->get_permalink());
345
 
index.php CHANGED
@@ -5,7 +5,7 @@
5
  Plugin URI: https://wordpress.org/plugins/rss-post-importer/
6
  Description: This plugin lets you set up an import posts from one or several rss-feeds and save them as posts on your site, simple and flexible.
7
  Author: feedsapi
8
- Version: 2.0.4
9
  Author URI: https://www.feedsapi.org/
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -28,7 +28,7 @@ if (!defined('RSS_PI_BASENAME')) {
28
  }
29
 
30
  if (!defined('RSS_PI_VERSION')) {
31
- define('RSS_PI_VERSION', '2.0.4');
32
  }
33
 
34
  if (!defined('RSS_PI_LOG_PATH')) {
@@ -64,4 +64,8 @@ global $rss_post_importer;
64
 
65
  $rss_post_importer = new rssPostImporter();
66
 
67
- $rss_post_importer->init();
 
 
 
 
5
  Plugin URI: https://wordpress.org/plugins/rss-post-importer/
6
  Description: This plugin lets you set up an import posts from one or several rss-feeds and save them as posts on your site, simple and flexible.
7
  Author: feedsapi
8
+ Version: 2.0.5
9
  Author URI: https://www.feedsapi.org/
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
28
  }
29
 
30
  if (!defined('RSS_PI_VERSION')) {
31
+ define('RSS_PI_VERSION', '2.0.5');
32
  }
33
 
34
  if (!defined('RSS_PI_LOG_PATH')) {
64
 
65
  $rss_post_importer = new rssPostImporter();
66
 
67
+ $rss_post_importer->init();
68
+
69
+
70
+
71
+
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: rss, feeds, import, feed, autoblog, feed aggregation, rss-feed, aggregatio
5
  RSSImport, yahoo pipes, WP Pipes, Import XML feed , FeedSyndicate, RSSpost, RSS in Page
6
  Requires at least: 3.5
7
  Tested up to: 4.1
8
- Stable tag: 2.0.4
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -77,6 +77,11 @@ WP-o-Matic , WP-o-Matic, RSSImport, FeedWordPress, Syndicate Press, FeedWeb, RSS
77
 
78
  == Change Log ==
79
 
 
 
 
 
 
80
  = Version 2.0.4 =
81
  * Added Single tag(Without API key) and Multiple tags(With API key) assigned to imported posts
82
 
5
  RSSImport, yahoo pipes, WP Pipes, Import XML feed , FeedSyndicate, RSSpost, RSS in Page
6
  Requires at least: 3.5
7
  Tested up to: 4.1
8
+ Stable tag: 2.0.5
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
77
 
78
  == Change Log ==
79
 
80
+ = Version 2.0.5 =
81
+ * Broken links to images solved.
82
+ * Added cron option for 10 minutes.
83
+ * Bug fixed and Improvements in code.
84
+
85
  = Version 2.0.4 =
86
  * Added Single tag(Without API key) and Multiple tags(With API key) assigned to imported posts
87