RSS Post Importer - Version 1.0.9

Version Description

Download this release

Release Info

Developer saurabhshukla
Plugin Icon 128x128 RSS Post Importer
Version 1.0.9
Comparing to
See all releases

Code changes from version 1.0.4 to 1.0.9

css/rss_pi.css CHANGED
File without changes
font/FontAwesome.otf CHANGED
File without changes
js/rss_pi.js CHANGED
File without changes
lang/rss_pi-es_ES.mo CHANGED
File without changes
lang/rss_pi-es_ES.po CHANGED
File without changes
lang/rss_pi-sv_SE.mo CHANGED
File without changes
lang/rss_pi-sv_SE.po CHANGED
File without changes
parts/rss_pi-log.php CHANGED
File without changes
parts/table_row.php CHANGED
@@ -63,7 +63,7 @@
63
  <label><input type="radio" id="<?php echo($f['id']); ?>-strip_html" name="<?php echo($f['id']); ?>-strip_html" value="true" <?php echo($f['strip_html'] == 'true' ? 'checked="checked"' : ''); ?> /> <?php _e('Yes'); ?></label>
64
  </li>
65
  <li>
66
- <label><input type="radio" id="<?php echo($f['id']); ?>-strip_html" name="<?php echo($f['id']); ?>-strip_html" value="false" <?php echo($f['strip_html'] == 'false' ? 'checked="checked"' : ''); ?> /> <? _e('No'); ?></label>
67
  </li>
68
  </ul>
69
  </td>
63
  <label><input type="radio" id="<?php echo($f['id']); ?>-strip_html" name="<?php echo($f['id']); ?>-strip_html" value="true" <?php echo($f['strip_html'] == 'true' ? 'checked="checked"' : ''); ?> /> <?php _e('Yes'); ?></label>
64
  </li>
65
  <li>
66
+ <label><input type="radio" id="<?php echo($f['id']); ?>-strip_html" name="<?php echo($f['id']); ?>-strip_html" value="false" <?php echo($f['strip_html'] == 'false' ? 'checked="checked"' : ''); ?> /> <?php _e('No'); ?></label>
67
  </li>
68
  </ul>
69
  </td>
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.0
8
- Stable tag: trunk
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -52,6 +52,12 @@ WP-o-Matic , WP-o-Matic, RSSImport, FeedWordPress, Syndicate Press, FeedWeb, RSS
52
  1. This is the combined settings- and feed-management-screen.
53
 
54
  == Change Log ==
 
 
 
 
 
 
55
 
56
  = Version 1.0.7 =
57
  * Added support for Full Text RSS Feeds Content fetching.
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.0
8
+ Stable tag: 1.0.10
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
52
  1. This is the combined settings- and feed-management-screen.
53
 
54
  == Change Log ==
55
+ = Version 1.0.9 =
56
+ * Added support for excerpts.
57
+ * Fixed some warnings and notices
58
+
59
+ = Version 1.0.8 =
60
+ * Added support for featured image.
61
 
62
  = Version 1.0.7 =
63
  * Added support for Full Text RSS Feeds Content fetching.
rss_pi-ui.php CHANGED
@@ -129,6 +129,7 @@
129
  <code>{$permalink}</code>
130
  <code>{$title}</code>
131
  <code>{$feed_title}</code>
 
132
  </p>
133
  </td>
134
  <td>
129
  <code>{$permalink}</code>
130
  <code>{$title}</code>
131
  <code>{$feed_title}</code>
132
+ <code>{$excerpt:n}</code>
133
  </p>
134
  </td>
135
  <td>
rss_pi.php CHANGED
@@ -1,385 +1,435 @@
1
  <?php
2
  /*
3
- Plugin Name: Rss Post Importer
4
- Plugin URI: https://wordpress.org/plugins/rss-post-importer/
5
- 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.
6
- Author: feedsapi
7
- Version: 1.0.7
8
- Author URI: https://www.feedsapi.org/
9
- License: GPLv2 or later
10
- License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
- */
12
 
13
  add_action('wp_ajax_rss_pi_add_row', 'rss_pi_add_row');
14
  add_action('wp_ajax_rss_pi_load_log', 'rss_pi_load_log');
15
  add_action('wp_ajax_rss_pi_clear_log', 'rss_pi_clear_log');
16
 
17
- function rss_pi_add_row()
18
- {
19
- include( plugin_dir_path( __FILE__ ) . 'parts/table_row.php');
20
- exit;
21
  }
22
 
23
- function rss_pi_load_log()
24
- {
25
- $log = file_get_contents(plugin_dir_path( __FILE__ ) . 'log.txt');
26
- include( plugin_dir_path( __FILE__ ) . 'parts/rss_pi-log.php');
27
 
28
- exit;
29
  }
30
 
31
- function rss_pi_clear_log()
32
- {
33
- $log_file = plugin_dir_path( __FILE__ ) . 'log.txt';
34
-
35
- file_put_contents($log_file, '');
36
- ?>
37
- <div id="message" class="updated">
38
- <p><strong><?php _e('Log has been cleared.', "rss_pi"); ?></strong></p>
39
- </div>
40
- <?php
41
-
42
- exit;
43
- }
44
 
 
 
 
 
 
 
 
 
45
 
46
  class rss_pi {
47
 
48
- function __construct() {
49
- add_action('admin_menu', array(&$this, 'admin_menu'));
50
-
51
- $this->settings = array(
52
- 'version' => '1.0.7',
53
- 'dir' => plugin_dir_path( __FILE__ )
54
- );
55
-
56
- load_textdomain('rss_pi', $this->settings['dir'] . 'lang/rss_pi-' . get_locale() . '.mo');
57
-
58
- add_action( 'wp', array(&$this, 'rss_pi_setup_schedule') );
59
- add_action( 'rss_pi_cron', array(&$this, 'rss_pi_do_this_hourly') );
60
-
61
- }
62
-
63
-
64
- // On an early action hook, check if the hook is scheduled - if not, schedule it.
65
- function rss_pi_setup_schedule()
66
- {
67
- if ( ! wp_next_scheduled( 'rss_pi_cron' ) ) {
68
- wp_schedule_event( time(), 'hourly', 'rss_pi_cron');
69
- }
70
- }
71
-
72
- // On the scheduled action hook, run a function.
73
- function rss_pi_do_this_hourly()
74
- {
75
- $this->import_all_feeds();
76
- }
77
-
78
- // Add to settings-menu
79
- function admin_menu () {
80
- add_options_page('Rss Post Importer','Rss Post Importer','manage_options','rss_pi', array($this, 'settings_page'));
81
- }
82
-
83
- function settings_page () {
84
- // If logpage is requested
85
- if(isset($_GET['show']))
86
- {
87
- // Display the logpage
88
- $do = $_GET['show'];
89
- if($do == 'log')
90
- {
91
- die($this->log_page());
92
- }
93
- }
94
- // Changes submitted, check for correct nonce
95
- if( isset($_POST['info_update']) && wp_verify_nonce($_POST['rss_pi_nonce'],'settings_page')) :
96
-
97
- // Get ids of feed-rows
98
- $ids = explode(",", $_POST['ids']);
99
-
100
- $feeds = array();
101
-
102
- // Get selected settings for all imported posts
103
- $settings = array(
104
- 'frequency' => $_POST['frequency'],
105
- 'feeds_api_key'=> $_POST['feeds_api_key'],
106
- 'post_template' => stripslashes_deep($_POST['post_template']),
107
- 'post_status' => $_POST['post_status'],
108
- 'author_id' => $_POST['author_id'],
109
- 'allow_comments' => $_POST['allow_comments'],
110
- 'enable_logging' => $_POST['enable_logging']
111
- );
112
-
113
- $this->is_correct_api( $_POST['feeds_api_key'] );
114
-
115
- // If cron settings have changed
116
- if( wp_get_schedule( 'rss_pi_cron' ) != $settings['frequency'] )
117
- {
118
- // Reset cron
119
- wp_clear_scheduled_hook( 'rss_pi_cron' );
120
- wp_schedule_event( time(), $settings['frequency'], 'rss_pi_cron');
121
- }
122
-
123
- // Loop through feed-rows
124
- foreach($ids as $id)
125
- {
126
- if($id)
127
- {
128
- array_push($feeds, array(
129
- 'id' => $id,
130
- 'url' => strtolower($_POST[$id . '-url']),
131
- 'name' => $_POST[$id . '-name'],
132
- 'max_posts' => $_POST[$id . '-max_posts'],
133
- 'category_id' => $_POST[$id . '-category_id'],
134
- 'strip_html' => $_POST[$id . '-strip_html']
135
- ));
136
- }
137
- }
138
-
139
- $options = $this->rss_pi_get_option();
140
-
141
- update_option('rss_pi_feeds', array('feeds' => $feeds, 'settings' => $settings, 'latest_import' => $options['latest_import'], 'imports' => $options['imports']));
142
-
143
- ?>
144
- <div id="message" class="updated">
145
- <p><strong><?php _e('Settings saved.') ?></strong></p>
146
- </div>
147
- <?php
148
-
149
- if($_POST['save_to_db'] == 'true') :
150
- $imported = $this->import_all_feeds();
151
- ?>
152
- <div id="message" class="updated">
153
- <p><strong><?php echo($imported); ?> <?php _e('new posts imported.') ?></strong></p>
154
- </div>
155
- <?php
156
- endif;
157
- endif;
158
-
159
- $options = $this->rss_pi_get_option();
160
-
161
- $ids = array();
162
-
163
- // Load js and css
164
- $this->input_admin_enqueue_scripts();
165
-
166
- include( $this->settings['dir'] . 'rss_pi-ui.php');
167
- }
168
-
169
- function import_feed($url, $feed_title, $max_posts, $category_id, $strip_html, $save_to_db)
170
- {
171
- include_once( ABSPATH . WPINC . '/feed.php' );
172
-
173
- $options = $this->rss_pi_get_option();
174
-
175
- $rss = "";
176
-
177
- //if api key has been saved by user and is not empty
178
- if(isset($options['settings']["feeds_api_key"]) && $options['settings']["feeds_api_key"]) {
179
-
180
- $feeds_api_key = $options['settings']["feeds_api_key"];
181
-
182
- $feedsapi_url = "http://www.feedsapi.org/fetch.php?key=".$feeds_api_key."&url=".$url;
183
-
184
- /* DEBUGGING
185
-
186
- touch("newfile.txt");
187
- $myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
188
- $txt = print_r($options, true)."\n".$feeds_api_key."\n".$feedsapi_url;
189
- fwrite($myfile, $txt);
190
- fclose($myfile);
191
-
192
- */
193
- // Get a SimplePie feed object from the specified feed source.
194
-
195
- $rss = fetch_feed( $feedsapi_url );
196
- }
197
- else {
198
-
199
- $rss = fetch_feed( $url );
200
-
201
- }
202
-
203
- // Remove the surrounding <div> from XHTML content in Atom feeds.
204
-
205
- if ( ! is_wp_error( $rss ) ) : // Checks that the object is created correctly
206
-
207
- // Figure out how many total items there are, but limit it to 5.
208
- $maxitems = $rss->get_item_quantity( $max_posts );
209
-
210
- // Build an array of all the items, starting with element 0 (first element).
211
- $rss_items = $rss->get_items( 0, $max_posts );
212
-
213
- if($save_to_db)
214
- {
215
- $saved_posts = array();
216
-
217
- $log = '';
218
-
219
- foreach ( $rss_items as $item )
220
- {
221
- if (!$this->post_exists($item->get_permalink()))
222
- {
223
- $new_post = array(
224
- 'post_title' => $item->get_title(),
225
- 'post_content' => $this->parse_content($item, $feed_title, $strip_html),
226
- 'post_status' => $options['settings']['post_status'],
227
- 'post_author' => $options['settings']['author_id'],
228
- 'post_category' => array($category_id),
229
- 'comment_status'=> $options['settings']['allow_comments'],
230
- 'post_date' => $item->get_date('Y-m-d H:i:s')
231
- );
232
-
233
- $post_id = wp_insert_post( $new_post );
234
-
235
- add_post_meta( $post_id, 'rss_pi_source_url', esc_url($item->get_permalink()) );
236
-
237
- array_push($saved_posts, $new_post);
238
-
239
- }
240
- }
241
-
242
- return $saved_posts;
243
- exit;
244
- }
245
- return $rss_items;
246
- endif;
247
- }
248
-
249
- function return_frequency($seconds)
250
- {
251
- $options = $this->rss_pi_get_option();
252
- return $options['settings']['frequency'];
253
- }
254
-
255
- function import_all_feeds()
256
- {
257
-
258
- $post_count = 0;
259
-
260
- $options = $this->rss_pi_get_option();
261
-
262
- add_filter( 'wp_feed_cache_transient_lifetime', array(&$this, 'return_frequency' ) );
263
-
264
- foreach($options['feeds'] as $f)
265
- {
266
- $rss_items = $this->import_feed($f['url'], $f['name'], $f['max_posts'], $f['category_id'], $f['strip_html'], true);
267
- $post_count += count($rss_items);
268
- }
269
- $imports = intval($options['imports']) + $post_count;
270
-
271
- update_option('rss_pi_feeds', array(
272
- 'feeds' => $options['feeds'],
273
- 'settings' => $options['settings'],
274
- 'latest_import' => date("Y-m-d H:i:s"),
275
- 'imports' => $imports
276
- ));
277
-
278
- remove_filter( 'wp_feed_cache_transient_lifetime', array(&$this, 'return_frequency' ) );
279
-
280
- if($options['settings']['enable_logging'] == 'true')
281
- {
282
- $log = date("Y-m-d H:i:s") . "\t Imported " . $post_count . " new posts. \n";
283
- $log_file = $this->settings['dir'] . 'log.txt';
284
- file_put_contents($log_file, $log, FILE_APPEND);
285
- }
286
-
287
- return $post_count;
288
- }
289
-
290
- function parse_content($item, $feed_title, $strip_html)
291
- {
292
- $options = $this->rss_pi_get_option();
293
- $post_template = $options['settings']['post_template'];
294
- $c = $item->get_content() != "" ? $item->get_content() : $item->get_description();
295
-
296
- $parsed_content = str_replace('{$content}', $c, $post_template);
297
- $parsed_content = str_replace('{$permalink}', esc_url( $item->get_permalink() ), $parsed_content);
298
- $parsed_content = str_replace('{$feed_title}', $feed_title, $parsed_content);
299
- $parsed_content = str_replace('{$title}', $item->get_title(), $parsed_content);
300
-
301
- if($strip_html == 'true')
302
- {
303
- $parsed_content = strip_tags($parsed_content);
304
- }
305
- return $parsed_content;
306
- }
307
-
308
- function post_exists($permalink)
309
- {
310
-
311
- $args = array(
312
- 'post_status' => 'any',
313
- 'meta_key' => 'rss_pi_source_url',
314
- 'meta_value' => esc_url($permalink)
315
- );
316
-
317
- $posts = get_posts( $args );
318
-
319
- // Not already imported
320
- return(count($posts) > 0);
321
- }
322
-
323
- function input_admin_enqueue_scripts()
324
- {
325
- // register scripts & styles
326
- wp_register_script( 'rss_pi', plugins_url( 'js/rss_pi.js', __FILE__ ), array('jquery'), $this->settings['version'] );
327
- wp_register_style( 'rss_pi', plugins_url( 'css/rss_pi.css', __FILE__ ) , array(), $this->settings['version'] );
328
- wp_localize_script('rss_pi', 'rss_pi_ajax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
329
-
330
- // scripts
331
- wp_enqueue_script(array(
332
- 'rss_pi'
333
- ));
334
-
335
- // styles
336
- wp_enqueue_style(array(
337
- 'rss_pi'
338
- ));
339
-
340
- }
341
-
342
- // Returns the settings for the plugin
343
- function rss_pi_get_option()
344
- {
345
- $options = get_option('rss_pi_feeds');
346
-
347
- // Insert new settings
348
- if( is_array($options) )
349
- {
350
- if(!array_key_exists('enable_logging', $options['settings']))
351
- {
352
- $options['settings']['enable_logging'] = 'false';
353
- }
354
- if(!array_key_exists('imports', $options))
355
- {
356
- $options['imports'] = 0;
357
- }
358
- }
359
-
360
- return $options;
361
- }
362
-
363
- function is_correct_api($new_key) {
364
- $options = $this->rss_pi_get_option();
365
- $old_key = $options["settings"]["feeds_api_key"];
366
-
367
- if($new_key == $old_key) return true;
368
-
369
- $url = "http://www.feedsapi.org/fetch.php?key=$new_key&url=http://dummyurl.com";
370
- $content = file_get_contents($url);
371
- if(trim($content) == "A valid key must be supplied") {
372
- echo '<div class="error">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
373
  <p>Invalid API key!</p>
374
  </div>';
375
- return false;
376
- }
377
- else {
378
- return true;
379
- }
380
- }
381
-
382
 
383
  }
 
384
  new rss_pi;
385
- ?>
1
  <?php
2
  /*
3
+ Plugin Name: Rss Post Importer
4
+ Plugin URI: https://wordpress.org/plugins/rss-post-importer/
5
+ 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.
6
+ Author: feedsapi
7
+ Version: 1.0.9
8
+ Author URI: https://www.feedsapi.org/
9
+ License: GPLv2 or later
10
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
+ */
12
 
13
  add_action('wp_ajax_rss_pi_add_row', 'rss_pi_add_row');
14
  add_action('wp_ajax_rss_pi_load_log', 'rss_pi_load_log');
15
  add_action('wp_ajax_rss_pi_clear_log', 'rss_pi_clear_log');
16
 
17
+ function rss_pi_add_row() {
18
+ include( plugin_dir_path(__FILE__) . 'parts/table_row.php');
19
+ exit;
 
20
  }
21
 
22
+ function rss_pi_load_log() {
23
+ $log = file_get_contents(plugin_dir_path(__FILE__) . 'log.txt');
24
+ include( plugin_dir_path(__FILE__) . 'parts/rss_pi-log.php');
 
25
 
26
+ exit;
27
  }
28
 
29
+ function rss_pi_clear_log() {
30
+ $log_file = plugin_dir_path(__FILE__) . 'log.txt';
 
 
 
 
 
 
 
 
 
 
 
31
 
32
+ file_put_contents($log_file, '');
33
+ ?>
34
+ <div id="message" class="updated">
35
+ <p><strong><?php _e('Log has been cleared.', "rss_pi"); ?></strong></p>
36
+ </div>
37
+ <?php
38
+ exit;
39
+ }
40
 
41
  class rss_pi {
42
 
43
+ function __construct() {
44
+ add_action('admin_menu', array(&$this, 'admin_menu'));
45
+
46
+ $this->settings = array(
47
+ 'version' => '1.0.7',
48
+ 'dir' => plugin_dir_path(__FILE__)
49
+ );
50
+
51
+ load_textdomain('rss_pi', $this->settings['dir'] . 'lang/rss_pi-' . get_locale() . '.mo');
52
+
53
+ add_action('wp', array(&$this, 'rss_pi_setup_schedule'));
54
+ add_action('rss_pi_cron', array(&$this, 'rss_pi_do_this_hourly'));
55
+ }
56
+
57
+ // On an early action hook, check if the hook is scheduled - if not, schedule it.
58
+ function rss_pi_setup_schedule() {
59
+ if (!wp_next_scheduled('rss_pi_cron')) {
60
+ wp_schedule_event(time(), 'hourly', 'rss_pi_cron');
61
+ }
62
+ }
63
+
64
+ // On the scheduled action hook, run a function.
65
+ function rss_pi_do_this_hourly() {
66
+ $this->import_all_feeds();
67
+ }
68
+
69
+ // Add to settings-menu
70
+ function admin_menu() {
71
+ add_options_page('Rss Post Importer', 'Rss Post Importer', 'manage_options', 'rss_pi', array($this, 'settings_page'));
72
+ }
73
+
74
+ function settings_page() {
75
+ // If logpage is requested
76
+ if (isset($_GET['show'])) {
77
+ // Display the logpage
78
+ $do = $_GET['show'];
79
+ if ($do == 'log') {
80
+ die($this->log_page());
81
+ }
82
+ }
83
+ // Changes submitted, check for correct nonce
84
+ if (isset($_POST['info_update']) && wp_verify_nonce($_POST['rss_pi_nonce'], 'settings_page')) :
85
+
86
+ // Get ids of feed-rows
87
+ $ids = explode(",", $_POST['ids']);
88
+
89
+ $feeds = array();
90
+
91
+ // Get selected settings for all imported posts
92
+ $settings = array(
93
+ 'frequency' => $_POST['frequency'],
94
+ 'feeds_api_key' => $_POST['feeds_api_key'],
95
+ 'post_template' => stripslashes_deep($_POST['post_template']),
96
+ 'post_status' => $_POST['post_status'],
97
+ 'author_id' => $_POST['author_id'],
98
+ 'allow_comments' => $_POST['allow_comments'],
99
+ 'enable_logging' => $_POST['enable_logging']
100
+ );
101
+
102
+ $this->is_correct_api($_POST['feeds_api_key']);
103
+
104
+ // If cron settings have changed
105
+ if (wp_get_schedule('rss_pi_cron') != $settings['frequency']) {
106
+ // Reset cron
107
+ wp_clear_scheduled_hook('rss_pi_cron');
108
+ wp_schedule_event(time(), $settings['frequency'], 'rss_pi_cron');
109
+ }
110
+
111
+ // Loop through feed-rows
112
+ foreach ($ids as $id) {
113
+ if ($id) {
114
+ array_push($feeds, array(
115
+ 'id' => $id,
116
+ 'url' => strtolower($_POST[$id . '-url']),
117
+ 'name' => $_POST[$id . '-name'],
118
+ 'max_posts' => $_POST[$id . '-max_posts'],
119
+ 'category_id' => $_POST[$id . '-category_id'],
120
+ 'strip_html' => $_POST[$id . '-strip_html']
121
+ ));
122
+ }
123
+ }
124
+
125
+ $options = $this->rss_pi_get_option();
126
+
127
+ update_option('rss_pi_feeds', array('feeds' => $feeds, 'settings' => $settings, 'latest_import' => $options['latest_import'], 'imports' => $options['imports']));
128
+ ?>
129
+ <div id="message" class="updated">
130
+ <p><strong><?php _e('Settings saved.') ?></strong></p>
131
+ </div>
132
+ <?php
133
+ if ($_POST['save_to_db'] == 'true') :
134
+ $imported = $this->import_all_feeds();
135
+ ?>
136
+ <div id="message" class="updated">
137
+ <p><strong><?php echo($imported); ?> <?php _e('new posts imported.') ?></strong></p>
138
+ </div>
139
+ <?php
140
+ endif;
141
+ endif;
142
+
143
+ $options = $this->rss_pi_get_option();
144
+
145
+ $ids = array();
146
+
147
+ // Load js and css
148
+ $this->input_admin_enqueue_scripts();
149
+
150
+ include( $this->settings['dir'] . 'rss_pi-ui.php');
151
+ }
152
+
153
+ function import_feed($url, $feed_title, $max_posts, $category_id, $strip_html, $save_to_db) {
154
+ include_once( ABSPATH . WPINC . '/feed.php' );
155
+
156
+ $options = $this->rss_pi_get_option();
157
+
158
+ $rss = "";
159
+
160
+ //if api key has been saved by user and is not empty
161
+ if (isset($options['settings']["feeds_api_key"]) && $options['settings']["feeds_api_key"]) {
162
+
163
+ $feeds_api_key = $options['settings']["feeds_api_key"];
164
+
165
+ $feedsapi_url = "http://www.feedsapi.org/fetch.php?key=" . $feeds_api_key . "&url=" . $url;
166
+
167
+ /* DEBUGGING
168
+
169
+ touch("newfile.txt");
170
+ $myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
171
+ $txt = print_r($options, true)."\n".$feeds_api_key."\n".$feedsapi_url;
172
+ fwrite($myfile, $txt);
173
+ fclose($myfile);
174
+
175
+ */
176
+ // Get a SimplePie feed object from the specified feed source.
177
+
178
+ $rss = fetch_feed($feedsapi_url);
179
+ } else {
180
+
181
+ $rss = fetch_feed($url);
182
+ }
183
+
184
+ // Remove the surrounding <div> from XHTML content in Atom feeds.
185
+
186
+ if (!is_wp_error($rss)) : // Checks that the object is created correctly
187
+ // Figure out how many total items there are, but limit it to 5.
188
+ $maxitems = $rss->get_item_quantity($max_posts);
189
+
190
+ // Build an array of all the items, starting with element 0 (first element).
191
+ $rss_items = $rss->get_items(0, $max_posts);
192
+
193
+ if ($save_to_db) {
194
+ $saved_posts = array();
195
+
196
+ $log = '';
197
+
198
+ foreach ($rss_items as $item) {
199
+ if (!$this->post_exists($item->get_permalink())) {
200
+ $new_post = array(
201
+ 'post_title' => $item->get_title(),
202
+ 'post_content' => $this->parse_content($item, $feed_title, $strip_html),
203
+ 'post_status' => $options['settings']['post_status'],
204
+ 'post_author' => $options['settings']['author_id'],
205
+ 'post_category' => array($category_id),
206
+ 'comment_status' => $options['settings']['allow_comments'],
207
+ 'post_date' => $item->get_date('Y-m-d H:i:s')
208
+ );
209
+
210
+ $new_post = apply_filters('pre_rss_pi_insert_post', $new_post);
211
+
212
+ $post_id = wp_insert_post($new_post);
213
+
214
+ add_action('save_rss_pi_post', $post_id);
215
+
216
+ $meta_id = $this->insert_featured_image($new_post['post_content'], $post_id);
217
+
218
+ add_post_meta($post_id, 'rss_pi_source_url', esc_url($item->get_permalink()));
219
+
220
+ array_push($saved_posts, $new_post);
221
+ }
222
+ }
223
+
224
+ return $saved_posts;
225
+ exit;
226
+ }
227
+ return $rss_items;
228
+ endif;
229
+ }
230
+
231
+ function return_frequency($seconds) {
232
+ $options = $this->rss_pi_get_option();
233
+ return $options['settings']['frequency'];
234
+ }
235
+
236
+ function import_all_feeds() {
237
+
238
+ $post_count = 0;
239
+
240
+ $options = $this->rss_pi_get_option();
241
+
242
+ add_filter('wp_feed_cache_transient_lifetime', array(&$this, 'return_frequency'));
243
+
244
+ foreach ($options['feeds'] as $f) {
245
+ $rss_items = $this->import_feed($f['url'], $f['name'], $f['max_posts'], $f['category_id'], $f['strip_html'], true);
246
+ $post_count += count($rss_items);
247
+ }
248
+ $imports = intval($options['imports']) + $post_count;
249
+
250
+ update_option('rss_pi_feeds', array(
251
+ 'feeds' => $options['feeds'],
252
+ 'settings' => $options['settings'],
253
+ 'latest_import' => date("Y-m-d H:i:s"),
254
+ 'imports' => $imports
255
+ ));
256
+
257
+ remove_filter('wp_feed_cache_transient_lifetime', array(&$this, 'return_frequency'));
258
+
259
+ if ($options['settings']['enable_logging'] == 'true') {
260
+ $log = date("Y-m-d H:i:s") . "\t Imported " . $post_count . " new posts. \n";
261
+ $log_file = $this->settings['dir'] . 'log.txt';
262
+ file_put_contents($log_file, $log, FILE_APPEND);
263
+ }
264
+
265
+ return $post_count;
266
+ }
267
+
268
+
269
+ function parse_content($item, $feed_title, $strip_html) {
270
+ $options = $this->rss_pi_get_option();
271
+ $post_template = $options['settings']['post_template'];
272
+ $c = $item->get_content() != "" ? $item->get_content() : $item->get_description();
273
+
274
+ $c = apply_filters('pre_rss_pi_parse_content', $c);
275
+
276
+
277
+ $parsed_content = str_replace('{$content}', $c, $post_template);
278
+ $parsed_content = str_replace('{$permalink}', esc_url($item->get_permalink()), $parsed_content);
279
+ $parsed_content = str_replace('{$feed_title}', $feed_title, $parsed_content);
280
+ $parsed_content = str_replace('{$title}', $item->get_title(), $parsed_content);
281
+
282
+ preg_match('/\{\$excerpt\:(\d+)\}/i', $parsed_content, $matches);
283
+
284
+ $e_size = (is_array($matches) && !empty($matches)) ? $matches[1] : 0;
285
+
286
+ if ($e_size) {
287
+ $trimmed_c = preg_replace('/<!--(.|\s)*?-->/', '', $c);
288
+ $stripped_c = strip_tags($trimmed_c);
289
+ $parsed_content = preg_replace('/\{\$excerpt\:\d+\}/i', wp_trim_words($stripped_c, $e_size), $parsed_content);
290
+ }
291
+
292
+ if ($strip_html == 'true') {
293
+ $parsed_content = strip_tags($parsed_content);
294
+ }
295
+
296
+ $parsed_content = apply_filters('after_rss_pi_parse_content', $parsed_content);
297
+ return $parsed_content;
298
+ }
299
+
300
+ function insert_featured_image($content, $post_id) {
301
+
302
+ preg_match('/<img.+?src="(.+?)"[^}]+>/i', $content, $matches);
303
+
304
+ $img_url = (is_array($matches) && !empty($matches)) ? $matches[1] : '';
305
+
306
+ if (!empty($img_url)) {
307
+ return false;
308
+ }
309
+
310
+ $featured_id = $this->media_sideload_image($img_url, $post_id, '');
311
+
312
+ add_action('set_rss_pi_featured_image', $featured_id, $post_id);
313
+ return $meta_id = set_post_thumbnail($post_id, $featured_id);
314
+ }
315
+
316
+ /**
317
+ * Modification of default media_sideload_image
318
+ *
319
+ * @param type $file
320
+ * @param type $post_id
321
+ * @param type $desc
322
+ * @return type
323
+ */
324
+ function media_sideload_image($file, $post_id, $desc = null) {
325
+ $id = 0;
326
+
327
+ if (!empty($file)) {
328
+ // Set variables for storage, fix file filename for query strings.
329
+ preg_match('/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches);
330
+ $file_array = array();
331
+ $file_array['name'] = basename($matches[0]);
332
+
333
+ // Download file to temp location.
334
+ $file_array['tmp_name'] = download_url($file);
335
+
336
+ // If error storing temporarily, return the error.
337
+ if (is_wp_error($file_array['tmp_name'])) {
338
+ return $file_array['tmp_name'];
339
+ }
340
+
341
+ // Do the validation and storage stuff.
342
+ $id = media_handle_sideload($file_array, $post_id, $desc);
343
+
344
+ // If error storing permanently, unlink.
345
+ if (is_wp_error($id)) {
346
+ @unlink($file_array['tmp_name']);
347
+ return $id;
348
+ }
349
+ }
350
+
351
+ return $id;
352
+ }
353
+
354
+ function post_exists($permalink) {
355
+
356
+ $args = array(
357
+ 'post_status' => 'any',
358
+ 'meta_key' => 'rss_pi_source_url',
359
+ 'meta_value' => esc_url($permalink)
360
+ );
361
+
362
+ $posts = get_posts($args);
363
+
364
+ // Not already imported
365
+ return(count($posts) > 0);
366
+ }
367
+
368
+ function input_admin_enqueue_scripts() {
369
+ // register scripts & styles
370
+ wp_register_script('rss_pi', plugins_url('js/rss_pi.js', __FILE__), array('jquery'), $this->settings['version']);
371
+ wp_register_style('rss_pi', plugins_url('css/rss_pi.css', __FILE__), array(), $this->settings['version']);
372
+ wp_localize_script('rss_pi', 'rss_pi_ajax', array('ajaxurl' => admin_url('admin-ajax.php')));
373
+
374
+ // scripts
375
+ wp_enqueue_script(array(
376
+ 'rss_pi'
377
+ ));
378
+
379
+ // styles
380
+ wp_enqueue_style(array(
381
+ 'rss_pi'
382
+ ));
383
+ }
384
+
385
+ // Returns the settings for the plugin
386
+ function rss_pi_get_option() {
387
+ $default_settings = array(
388
+ 'enable_logging' => false,
389
+ 'feeds_api_key' => false,
390
+ 'frequency' => 0,
391
+ 'post_template' => '{\$content}\nSource: {\$feed_title}',
392
+ 'post_status' => 'publish',
393
+ 'author_id' => 1,
394
+ 'allow_comments' => true,
395
+
396
+ );
397
+ $options = get_option('rss_pi_feeds', array());
398
+
399
+ if(!isset($options['settings'])){
400
+ $options['settings'] = array();
401
+ }
402
+
403
+ $options['settings'] = wp_parse_args($options['settings'],$default_settings);
404
+
405
+
406
+ if (!array_key_exists('imports', $options)) {
407
+ $options['imports'] = 0;
408
+ }
409
+
410
+ return $options;
411
+ }
412
+
413
+ function is_correct_api($new_key) {
414
+ $options = $this->rss_pi_get_option();
415
+
416
+ $old_key = $options['settings']["feeds_api_key"];
417
+
418
+ if ($new_key == $old_key)
419
+ return true;
420
+
421
+ $url = "http://www.feedsapi.org/fetch.php?key=$new_key&url=http://dummyurl.com";
422
+ $content = file_get_contents($url);
423
+ if (trim($content) == "A valid key must be supplied") {
424
+ echo '<div class="error">
425
  <p>Invalid API key!</p>
426
  </div>';
427
+ return false;
428
+ } else {
429
+ return true;
430
+ }
431
+ }
 
 
432
 
433
  }
434
+
435
  new rss_pi;
 
screenshot-1.png DELETED
Binary file
uninstall.php CHANGED
File without changes