RSS Post Importer - Version 2.4.0

Version Description

Download this release

Release Info

Developer feedsapi
Plugin Icon 128x128 RSS Post Importer
Version 2.4.0
Comparing to
See all releases

Code changes from version 2.3.0 to 2.4.0

app/assets/js/main.js CHANGED
@@ -1,49 +1,119 @@
1
- (function($){
2
 
3
  $('document').ready(function(){
4
  // Edit-buttons
5
  $('body').on('click', 'a.toggle-edit', function () {
6
- $('#edit_' + $(this).attr('data-target')).toggleClass('show');
7
- $('#display_' + $(this).attr('data-target')).toggleClass('show');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  return false;
9
  });
10
 
11
  // Delete-buttons
12
  $('body').on('click', 'a.delete-row', function () {
13
- $('#edit_' + $(this).attr('data-target')).remove();
14
- $('#display_' + $(this).attr('data-target')).remove();
15
- update_ids();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  return false;
17
-
18
-
19
  });
20
-
21
-
22
  // status-buttons
23
  $('body').on('click', 'a.status-row', function () {
24
  var action = $(this).attr('data-action');
25
  var target = $(this).attr('data-target');
26
- if(action=="pause")
27
- {
28
- $(this).attr('data-action','Enable_Feed');
29
- $(this).html('Enable Feed');
30
- }else
31
- {
32
- $(this).attr('data-action','pause');
33
- $(this).html('Pause');
34
  }
35
-
36
- var sts_ids = [];
37
- $('a.status-row').each(function(){
38
- if($(this).attr('data-action') =="Enable_Feed"){
39
- sts_ids.push($(this).attr('data-target'));
40
- }
41
- })
42
-
43
- var sts_value = sts_ids.join();
44
- $("#sts_id").val(sts_value);
45
-
46
-
47
  return false;
48
  });
49
 
@@ -80,29 +150,34 @@ $('document').ready(function(){
80
 
81
  $('a.add-row').on('click', function (e) {
82
  e.preventDefault();
83
- var id = uniqid();
84
- $("#rss_pi-feed-table > tbody .empty_table").parent("tr").remove();
85
- $tr_data = $("#rss_pi-feed-table > tfoot > tr.data-row").clone().attr("id","display_"+id).appendTo("#rss_pi-feed-table > tbody");
86
- $tr_edit = $("#rss_pi-feed-table > tfoot > tr.edit-row").clone().attr("id","edit_"+id).appendTo("#rss_pi-feed-table > tbody");
87
- $tr_data.find(".toggle-edit,.delete-row").attr("data-target",id);
88
- $tr_edit.find(".toggle-edit").attr("data-target",id);
89
- $tr_edit.find("[name='id']").val(id);
90
- $tr_edit.find("[for^=0-]").each(function(){
91
- $(this).attr("for",$(this).attr("for").replace("0-",id+"-"));
92
- });
93
- $tr_edit.find("[id^=0-]").each(function(){
94
- $(this).attr("id",$(this).attr("id").replace("0-",id+"-"));
95
- });
96
- $tr_edit.find("[name^=0-]").each(function(){
97
- $(this).attr("name",$(this).attr("name").replace("0-",id+"-"));
98
  });
99
- update_ids();
100
- $("#"+id+"-name").focus().select();
 
 
 
 
 
 
 
 
 
101
  });
102
 
103
  $('#save_and_import').on('click', function () {
104
-
105
-
106
  $('#save_to_db').val('true');
107
  });
108
 
@@ -197,7 +272,7 @@ $('document').ready(function(){
197
 
198
  if ( $("#rss_pi_progressbar").length && feeds !== undefined && feeds.count ) {
199
  var import_feed = function(id) {
200
-
201
  $.ajax({
202
  type: 'POST',
203
  url: rss_pi.ajaxurl,
@@ -228,28 +303,28 @@ $('document').ready(function(){
228
  $("#rss_pi_progressbar_label").html("Import in progres. Processed feeds: <span class='processed'>0</span> of <span class='max'>"+feeds.total()+"</span>. Imported posts so far: <span class='count'>0</span>");
229
  import_feed(feeds.get());
230
  }
231
-
232
-
233
  /*This is for custom frequency*/
234
  $("#frequency").change(function(){
235
-
236
  if($(this).val()=="custom_frequency")
237
  {
238
  $("#rss_custom_frequency").show();
239
  $("#rss_custom_frequency").focus();
240
  }else{
241
- $("#rss_custom_frequency").val('');
242
- $("#rss_custom_frequency").hide();
243
  }
244
-
245
-
246
  })
247
 
248
  var url = location.href;
249
-
250
  var myParam1 = location.search.split('version=')[1];
251
-
252
-
253
  if (typeof(myParam1) == 'undefined')
254
  {
255
  if(new_js_url=='')
@@ -258,29 +333,28 @@ $('document').ready(function(){
258
  }
259
  else
260
  {
261
- var api_add = "premium";
262
  }
263
  window.location.assign(window.location.href+='&version='+new_js_version+'&type='+api_add);
264
  }
265
-
266
  else{}
267
-
268
  //alert(myParam);
269
-
270
 
271
  });
272
 
273
  })(jQuery);
274
 
275
  function update_ids() {
276
-
277
- ids = jQuery("#rss_pi-feed-table > tbody input[name='id']").map(function () {
278
  return jQuery(this).val();
279
  }).get().join();
280
 
281
- jQuery('#ids').val(ids);
282
-
283
  }
 
284
  var feeds = {
285
  ids: feeds || [],
286
  count: feeds && feeds.length ? feeds.length : 0,
1
+ (function($) {
2
 
3
  $('document').ready(function(){
4
  // Edit-buttons
5
  $('body').on('click', 'a.toggle-edit', function () {
6
+ var target = $(this).attr('data-target');
7
+
8
+ var modified = $('#modified_feeds').val();
9
+
10
+ if (modified) {
11
+ modified = modified.split(',');
12
+ } else {
13
+ modified = [target];
14
+ }
15
+
16
+ var index = modified.indexOf(target);
17
+ if ($('#display_' + target).hasClass('show')) {
18
+ $('#edit_' + target).remove();
19
+ $('#display_' + target).toggleClass('show');
20
+
21
+ if (index > -1) {
22
+ modified.splice(index, 1);
23
+ }
24
+
25
+ return false;
26
+ } else {
27
+ if (index == -1) {
28
+ modified.push(target);
29
+ }
30
+ }
31
+
32
+ $('#modified_feeds').val(modified.join(','));
33
+
34
+ $.ajax({
35
+ type: 'POST',
36
+ url: rss_pi.ajaxurl,
37
+ data: ({
38
+ action: 'rss_pi_edit_row',
39
+ feed_id: $(this).attr('data-target')
40
+ }),
41
+ success: function (data) {
42
+ $(data).insertAfter($('#display_' + target));
43
+ $('#edit_' + target).toggleClass('show');
44
+ $('#display_' + target).toggleClass('show');
45
+ }
46
+ });
47
+
48
  return false;
49
  });
50
 
51
  // Delete-buttons
52
  $('body').on('click', 'a.delete-row', function () {
53
+ var target = $(this).attr('data-target');
54
+
55
+ var deleted = $('#deleted_feeds').val();
56
+ var modified = $('#modified_feeds').val();
57
+ var new_feeds = $('#new_feeds').val();
58
+
59
+ if (deleted) {
60
+ deleted = deleted.split(',');
61
+ deleted.push(target);
62
+ } else {
63
+ deleted = [target];
64
+ }
65
+
66
+ if (modified) {
67
+ modified = modified.split(',');
68
+ var index = modified.indexOf(target);
69
+ if (index > -1) {
70
+ modified.splice(index, 1);
71
+ }
72
+ $('#modified_feeds').val(modified.join(','));
73
+ }
74
+
75
+ if (new_feeds) {
76
+ new_feeds = new_feeds.split(',');
77
+ var index = new_feeds.indexOf(target);
78
+ if (index > -1) {
79
+ new_feeds.splice(index, 1);
80
+ }
81
+ $('#new_feeds').val(new_feeds.join(','));
82
+ }
83
+
84
+
85
+ $('#deleted_feeds').val(deleted.join(','));
86
+
87
+ $('#edit_' + target).remove();
88
+ $('#display_' + target).remove();
89
+
90
  return false;
 
 
91
  });
92
+
93
+
94
  // status-buttons
95
  $('body').on('click', 'a.status-row', function () {
96
  var action = $(this).attr('data-action');
97
  var target = $(this).attr('data-target');
98
+
99
+ if (action == 'pause') {
100
+ $(this).attr('data-action', 'enable');
101
+ $(this).html('Enable Feed');
102
+ } else {
103
+ $(this).attr('data-action', 'pause');
104
+ $(this).html('Pause');
 
105
  }
106
+
107
+ var paused_feeds = $('#paused_feeds').val();
108
+ if (paused_feeds) {
109
+ paused_feeds = paused_feeds.split(',');
110
+ paused_feeds.push(target);
111
+ } else {
112
+ paused_feeds = [target];
113
+ }
114
+
115
+ $('#paused_feeds').val(paused_feeds.join(','));
116
+
 
117
  return false;
118
  });
119
 
150
 
151
  $('a.add-row').on('click', function (e) {
152
  e.preventDefault();
153
+ var target = uniqid();
154
+
155
+ $.ajax({
156
+ type: 'POST',
157
+ url: rss_pi.ajaxurl,
158
+ data: ({
159
+ action: 'rss_pi_add_row',
160
+ feed_id: target
161
+ }),
162
+ success: function (data) {
163
+ $('.rss-rows').append(data);
164
+ $("#" + target + "-name").focus().select();
165
+ }
 
 
166
  });
167
+
168
+ var new_feeds = $('#new_feeds').val();
169
+
170
+ if (new_feeds) {
171
+ new_feeds = new_feeds.split(',');
172
+ new_feeds.push(target);
173
+ } else {
174
+ new_feeds = [target];
175
+ }
176
+
177
+ $('#new_feeds').val(new_feeds.join(','));
178
  });
179
 
180
  $('#save_and_import').on('click', function () {
 
 
181
  $('#save_to_db').val('true');
182
  });
183
 
272
 
273
  if ( $("#rss_pi_progressbar").length && feeds !== undefined && feeds.count ) {
274
  var import_feed = function(id) {
275
+
276
  $.ajax({
277
  type: 'POST',
278
  url: rss_pi.ajaxurl,
303
  $("#rss_pi_progressbar_label").html("Import in progres. Processed feeds: <span class='processed'>0</span> of <span class='max'>"+feeds.total()+"</span>. Imported posts so far: <span class='count'>0</span>");
304
  import_feed(feeds.get());
305
  }
306
+
307
+
308
  /*This is for custom frequency*/
309
  $("#frequency").change(function(){
310
+
311
  if($(this).val()=="custom_frequency")
312
  {
313
  $("#rss_custom_frequency").show();
314
  $("#rss_custom_frequency").focus();
315
  }else{
316
+ $("#rss_custom_frequency").val('');
317
+ $("#rss_custom_frequency").hide();
318
  }
319
+
320
+
321
  })
322
 
323
  var url = location.href;
324
+
325
  var myParam1 = location.search.split('version=')[1];
326
+
327
+
328
  if (typeof(myParam1) == 'undefined')
329
  {
330
  if(new_js_url=='')
333
  }
334
  else
335
  {
336
+ var api_add = "premium";
337
  }
338
  window.location.assign(window.location.href+='&version='+new_js_version+'&type='+api_add);
339
  }
340
+
341
  else{}
342
+
343
  //alert(myParam);
344
+
345
 
346
  });
347
 
348
  })(jQuery);
349
 
350
  function update_ids() {
351
+ var feed_ids = jQuery("#rss_pi-feed-table > tbody input[name='id']").map(function () {
 
352
  return jQuery(this).val();
353
  }).get().join();
354
 
355
+ jQuery('#feed_ids').val(feed_ids);
 
356
  }
357
+
358
  var feeds = {
359
  ids: feeds || [],
360
  count: feeds && feeds.length ? feeds.length : 0,
app/class-rss-post-importer.php CHANGED
@@ -2,258 +2,259 @@
2
 
3
  /**
4
  * One class to rule them all
5
- *
6
  * @author mobilova UG (haftungsbeschränkt) <rsspostimporter@feedsapi.com>
7
  */
8
-
9
  class rssPostImporter {
10
 
11
- /**
12
- * A var to store the options in
13
- * @var array
14
- */
15
- public $options = array();
16
-
17
- /**
18
- * A var to store the link to the plugin page
19
- * @var array
20
- */
21
- public $page_link = '';
22
-
23
- /**
24
- * To initialise the admin and cron classes
25
- *
26
- * @var object
27
- */
28
- private $admin, $cron;
29
-
30
- /**
31
- * Start
32
- */
33
-
34
- function __construct() {
35
-
36
- // populate the options first
37
- $this->load_options();
38
-
39
- // do any upgrade if needed
40
- $this->upgrade();
41
-
42
- $settings = array(
43
- 'feeds_api_key' => sanitize_key($_POST['feeds_api_key'])
44
- );
45
- //$obj = new rssPIAdminProcessor();
46
- global $rss_post_importer;
47
-
48
- // check if submitted api key is valid
49
- $var_link = $this->is_valid_key($settings['feeds_api_key']);
50
-
51
- if($var_link=='')
52
- {
53
- $api_url = "normal";
54
- }
55
- else
56
- {
57
- $api_url = "premium";
58
- }
59
-
60
- // setup this plugin options page link
61
- $new_api_url = $this->page_link = admin_url('options-general.php?page=rss_pi&version='.RSS_PI_VERSION.'&type='.$api_url);
62
-
63
- // hook translations
64
- add_action('plugins_loaded', array($this, 'localize'));
65
-
66
- add_filter('plugin_action_links_' . RSS_PI_BASENAME, array($this, 'settings_link'));
67
- }
68
-
69
- /**
70
- * Load options from the db
71
- */
72
- public function load_options() {
73
-
74
- $default_settings = array(
75
- 'enable_logging' => false,
76
- 'feeds_api_key' => false,
77
- 'frequency' => 0,
78
- 'post_template' => "{\$content}\nSource: {\$feed_title}",
79
- 'post_status' => 'publish',
80
- 'author_id' => 1,
81
- 'allow_comments' => 'open',
82
- 'block_indexing' => false,
83
- 'nofollow_outbound' => true,
84
- 'keywords' => array(),
85
- 'import_images_locally' => false,
86
- 'disable_thumbnail' => false,
87
- 'cache_deleted' => true,
88
- );
89
-
90
- $options = get_option('rss_pi_feeds', array());
91
-
92
- // prepare default options when there is no record in the database
93
- if (!isset($options['feeds'])) {
94
- $options['feeds'] = array();
95
- }
96
- if (!isset($options['settings'])) {
97
- $options['settings'] = array();
98
- }
99
- if (!isset($options['latest_import'])) {
100
- $options['latest_import'] = '';
101
- }
102
- if (!isset($options['imports'])) {
103
- $options['imports'] = 0;
104
- }
105
- if (!isset($options['upgraded'])) {
106
- $options['upgraded'] = array();
107
- }
108
-
109
- $options['settings'] = wp_parse_args($options['settings'], $default_settings);
110
-
111
- if (!array_key_exists('imports', $options)) {
112
- $options['imports'] = 0;
113
- }
114
-
115
- $this->options = $options;
116
- }
117
-
118
- /**
119
- * Upgrade plugin settings
120
- */
121
- public function upgrade() {
122
-
123
- global $wpdb;
124
- $upgraded = FALSE;
125
- $bail = FALSE;
126
-
127
- // migrate to rss_pi_deleted_posts only items from rss_pi_imported_posts that are actually deleted, discard the others
128
- // do this in iterations so not to degrade the UX
129
- if ( ! isset($this->options['upgraded']['deleted_posts']) ) {
130
- // get meta data for "deleted" and "imported" posts
131
- $rss_pi_deleted_posts = get_option( 'rss_pi_deleted_posts', array() );
132
- $rss_pi_imported_posts = get_option( 'rss_pi_imported_posts', array() );
133
- $rss_pi_imported_posts_migrated = get_option( 'rss_pi_imported_posts_migrated', array() );
134
- // limit execution time (in seconds)
135
- $_limit = ( ( defined('DOING_CRON') && DOING_CRON ) ? 20 : ( ( defined('DOING_AJAX') && DOING_AJAX ) ? 10 : 3 ) );
136
- $_start = microtime(TRUE);
137
- // iterate through all imported posts' source URLs
138
- foreach ( $rss_pi_imported_posts as $k => $source_url ) {
139
- // strip any params from the URL
140
- $_source_url = explode('?',$source_url);
141
- $_source_url = $_source_url[0];
142
- // hash the URL for storage
143
- $source_md5 = md5($_source_url);
144
- // properly format the URL for comparison
145
- $source_url = esc_url($source_url);
146
- // skip if we already have "migrated" this item
147
- if ( in_array( $k, $rss_pi_imported_posts_migrated ) ) {
148
- continue;
149
- }
150
- // skip if we already have "deleted" metadata for this item
151
- if ( in_array( $source_md5, $rss_pi_deleted_posts ) ) {
152
- continue;
153
- }
154
- $rss_pi_imported_posts_migrated[] = $k;
155
- // check if there is a post with this source URL
156
- $post_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = 'rss_pi_source_url' and meta_value = %s", $source_url ) );
157
- // when there is no such post (it was deleted?)
158
- if ( ! $post_id ) {
159
- // add this source URL to "deleted" metadata
160
- $rss_pi_deleted_posts[] = $source_md5;
161
- } else {
162
- // otherwise update the post metadata to include hashed URL
163
- update_post_meta( $post_id, 'rss_pi_source_md5', $source_md5 );
164
- }
165
- // remove it from "imported" metadata
166
- $_curr = microtime(TRUE);
167
- if ( $_curr - $_start > $_limit ) {
168
- // bail out when the "max execution time" limit is exhausted
169
- $bail = TRUE;
170
- break;
171
- }
172
- }
173
- // shed any duplicates
174
- $rss_pi_deleted_posts = array_unique($rss_pi_deleted_posts);
175
- update_option('rss_pi_deleted_posts', $rss_pi_deleted_posts);
176
- // keep record of migrated items
177
- update_option('rss_pi_imported_posts_migrated', $rss_pi_imported_posts_migrated);
178
- // are there still source URLs in the "imported" metadata?
179
- if ( count($rss_pi_imported_posts_migrated) < count($rss_pi_imported_posts) ) {
180
- } else {
181
- // remove the "imported" metadata from database
182
- delete_option('rss_pi_imported_posts_migrated');
183
- delete_option('rss_pi_imported_posts');
184
- // mark this upgrade as completed
185
- $this->options['upgraded']['deleted_posts'] = TRUE;
186
- $upgraded = TRUE;
187
- }
188
- }
189
- // check after each upgrade routine
190
- if ( $bail ) {
191
- return;
192
- }
193
-
194
- // if there is something to record as an upgrade
195
- if ( $upgraded ) {
196
- update_option('rss_pi_feeds', $this->options);
197
- }
198
- }
199
-
200
- /**
201
- * Load translations
202
- */
203
- public function localize() {
204
-
205
- load_plugin_textdomain('rss-post-importer', false, RSS_PI_PATH . 'app/lang/');
206
- }
207
-
208
- /**
209
- * Initialise
210
- */
211
- public function init() {
212
-
213
- // initialise admin and cron
214
- $this->cron = new rssPICron();
215
- $this->cron->init();
216
-
217
- $this->admin = new rssPIAdmin();
218
- $this->admin->init();
219
-
220
- $this->front = new rssPIFront();
221
- $this->front->init();
222
- }
223
-
224
- /**
225
- * Check if a given API key is valid
226
- *
227
- * @param string $key
228
- * @return boolean
229
- */
230
- public function is_valid_key($key) {
231
-
232
- if (empty($key)) {
233
- return false;
234
- }
235
-
236
- $url = esc_url("http://www.rsspostimporter.com/fetch.php?key=$key&url=http://dummyurl.com");
237
- $content = file_get_contents($url);
238
-
239
- if (trim($content) == "A valid key must be supplied") {
240
- return false;
241
- }
242
-
243
- return true;
244
- }
245
-
246
- /**
247
- * Adds a settings link
248
- *
249
- * @param array $links EXisting links
250
- * @return type
251
- */
252
- public function settings_link($links) {
253
- $settings_link = array(
254
- '<a href="' . $this->page_link . '">Settings</a>',
255
- );
256
- return array_merge($settings_link, $links);
257
- }
 
258
 
259
  }
2
 
3
  /**
4
  * One class to rule them all
5
+ *
6
  * @author mobilova UG (haftungsbeschränkt) <rsspostimporter@feedsapi.com>
7
  */
8
+
9
  class rssPostImporter {
10
 
11
+ /**
12
+ * A var to store the options in
13
+ * @var array
14
+ */
15
+ public $options = array();
16
+
17
+ /**
18
+ * A var to store the link to the plugin page
19
+ * @var array
20
+ */
21
+ public $page_link = '';
22
+
23
+ /**
24
+ * To initialise the admin and cron classes
25
+ *
26
+ * @var object
27
+ */
28
+ private $admin, $cron;
29
+
30
+ /**
31
+ * Start
32
+ */
33
+
34
+ function __construct() {
35
+ // populate the options first
36
+ $this->load_options();
37
+
38
+ // do any upgrade if needed
39
+ $this->upgrade();
40
+
41
+ $settings = array();
42
+ $valid_api_key = '';
43
+ if (isset($_POST['feeds_api_key'])) {
44
+ $settings = array(
45
+ 'feeds_api_key' => sanitize_key($_POST['feeds_api_key'])
46
+ );
47
+
48
+ // check if submitted api key is valid
49
+ $valid_api_key = $this->is_valid_key($settings['feeds_api_key']);
50
+ }
51
+
52
+ // determine the API type
53
+ $api_type = $valid_api_key == '' ? 'normal' : 'premium';
54
+
55
+ // setup this plugin options page link
56
+ $this->page_link = admin_url(
57
+ 'options-general.php?page=rss_pi&version=' . RSS_PI_VERSION .
58
+ '&type=' . $api_type
59
+ );
60
+
61
+ // hook translations
62
+ add_action('plugins_loaded', array($this, 'localize'));
63
+
64
+ add_filter(
65
+ 'plugin_action_links_' . RSS_PI_BASENAME,
66
+ array($this, 'settings_link')
67
+ );
68
+ }
69
+
70
+ /**
71
+ * Load options from the db
72
+ */
73
+ public function load_options() {
74
+
75
+ $default_settings = array(
76
+ 'enable_logging' => false,
77
+ 'feeds_api_key' => false,
78
+ 'frequency' => 0,
79
+ 'post_template' => "{\$content}\nSource: {\$feed_title}",
80
+ 'post_status' => 'publish',
81
+ 'author_id' => 1,
82
+ 'allow_comments' => 'open',
83
+ 'block_indexing' => false,
84
+ 'nofollow_outbound' => true,
85
+ 'keywords' => array(),
86
+ 'import_images_locally' => false,
87
+ 'disable_thumbnail' => false,
88
+ 'cache_deleted' => true,
89
+ );
90
+
91
+ $options = get_option('rss_pi_feeds', array());
92
+
93
+ // prepare default options when there is no record in the database
94
+ if (!isset($options['feeds'])) {
95
+ $options['feeds'] = array();
96
+ }
97
+ if (!isset($options['settings'])) {
98
+ $options['settings'] = array();
99
+ }
100
+ if (!isset($options['latest_import'])) {
101
+ $options['latest_import'] = '';
102
+ }
103
+ if (!isset($options['imports'])) {
104
+ $options['imports'] = 0;
105
+ }
106
+ if (!isset($options['upgraded'])) {
107
+ $options['upgraded'] = array();
108
+ }
109
+
110
+ $options['settings'] = wp_parse_args($options['settings'], $default_settings);
111
+
112
+ if (!array_key_exists('imports', $options)) {
113
+ $options['imports'] = 0;
114
+ }
115
+
116
+ $this->options = $options;
117
+ }
118
+
119
+ /**
120
+ * Upgrade plugin settings
121
+ */
122
+ public function upgrade() {
123
+
124
+ global $wpdb;
125
+ $upgraded = FALSE;
126
+ $bail = FALSE;
127
+
128
+ // migrate to rss_pi_deleted_posts only items from rss_pi_imported_posts that are actually deleted, discard the others
129
+ // do this in iterations so not to degrade the UX
130
+ if ( ! isset($this->options['upgraded']['deleted_posts']) ) {
131
+ // get meta data for "deleted" and "imported" posts
132
+ $rss_pi_deleted_posts = get_option( 'rss_pi_deleted_posts', array() );
133
+ $rss_pi_imported_posts = get_option( 'rss_pi_imported_posts', array() );
134
+ $rss_pi_imported_posts_migrated = get_option( 'rss_pi_imported_posts_migrated', array() );
135
+ // limit execution time (in seconds)
136
+ $_limit = ( ( defined('DOING_CRON') && DOING_CRON ) ? 20 : ( ( defined('DOING_AJAX') && DOING_AJAX ) ? 10 : 3 ) );
137
+ $_start = microtime(TRUE);
138
+ // iterate through all imported posts' source URLs
139
+ foreach ( $rss_pi_imported_posts as $k => $source_url ) {
140
+ // strip any params from the URL
141
+ //$_source_url = explode('?', $source_url);
142
+ //$_source_url = $_source_url[0];
143
+ // hash the URL for storage
144
+ $source_md5 = md5($source_url);
145
+ // properly format the URL for comparison
146
+ $source_url = esc_url($source_url);
147
+ // skip if we already have "migrated" this item
148
+ if ( in_array( $k, $rss_pi_imported_posts_migrated ) ) {
149
+ continue;
150
+ }
151
+ // skip if we already have "deleted" metadata for this item
152
+ if ( in_array( $source_md5, $rss_pi_deleted_posts ) ) {
153
+ continue;
154
+ }
155
+ $rss_pi_imported_posts_migrated[] = $k;
156
+ // check if there is a post with this source URL
157
+ $post_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = 'rss_pi_source_url' and meta_value = %s", $source_url ) );
158
+ // when there is no such post (it was deleted?)
159
+ if ( ! $post_id ) {
160
+ // add this source URL to "deleted" metadata
161
+ $rss_pi_deleted_posts[] = $source_md5;
162
+ } else {
163
+ // otherwise update the post metadata to include hashed URL
164
+ update_post_meta( $post_id, 'rss_pi_source_md5', $source_md5 );
165
+ }
166
+ // remove it from "imported" metadata
167
+ $_curr = microtime(TRUE);
168
+ if ( $_curr - $_start > $_limit ) {
169
+ // bail out when the "max execution time" limit is exhausted
170
+ $bail = TRUE;
171
+ break;
172
+ }
173
+ }
174
+ // shed any duplicates
175
+ $rss_pi_deleted_posts = array_unique($rss_pi_deleted_posts);
176
+ update_option('rss_pi_deleted_posts', $rss_pi_deleted_posts);
177
+ // keep record of migrated items
178
+ update_option('rss_pi_imported_posts_migrated', $rss_pi_imported_posts_migrated);
179
+ // are there still source URLs in the "imported" metadata?
180
+ if ( count($rss_pi_imported_posts_migrated) < count($rss_pi_imported_posts) ) {
181
+ } else {
182
+ // remove the "imported" metadata from database
183
+ delete_option('rss_pi_imported_posts_migrated');
184
+ delete_option('rss_pi_imported_posts');
185
+ // mark this upgrade as completed
186
+ $this->options['upgraded']['deleted_posts'] = TRUE;
187
+ $upgraded = TRUE;
188
+ }
189
+ }
190
+ // check after each upgrade routine
191
+ if ( $bail ) {
192
+ return;
193
+ }
194
+
195
+ // if there is something to record as an upgrade
196
+ if ( $upgraded ) {
197
+ update_option('rss_pi_feeds', $this->options);
198
+ }
199
+ }
200
+
201
+ /**
202
+ * Load translations
203
+ */
204
+ public function localize() {
205
+
206
+ load_plugin_textdomain('rss-post-importer', false, RSS_PI_PATH . 'app/lang/');
207
+ }
208
+
209
+ /**
210
+ * Initialise
211
+ */
212
+ public function init() {
213
+
214
+ // initialise admin and cron
215
+ $this->cron = new rssPICron();
216
+ $this->cron->init();
217
+
218
+ $this->admin = new rssPIAdmin();
219
+ $this->admin->init();
220
+
221
+ $this->front = new rssPIFront();
222
+ $this->front->init();
223
+ }
224
+
225
+ /**
226
+ * Check if a given API key is valid
227
+ *
228
+ * @param string $key
229
+ * @return boolean
230
+ */
231
+ public function is_valid_key($key) {
232
+
233
+ if (empty($key)) {
234
+ return false;
235
+ }
236
+
237
+ $url = esc_url("http://www.rsspostimporter.com/fetch.php?key=$key&url=http://dummyurl.com");
238
+ $content = file_get_contents($url);
239
+
240
+ if (trim($content) == "A valid key must be supplied") {
241
+ return false;
242
+ }
243
+
244
+ return true;
245
+ }
246
+
247
+ /**
248
+ * Adds a settings link
249
+ *
250
+ * @param array $links EXisting links
251
+ * @return type
252
+ */
253
+ public function settings_link($links) {
254
+ $settings_link = array(
255
+ '<a href="' . $this->page_link . '">Settings</a>',
256
+ );
257
+ return array_merge($settings_link, $links);
258
+ }
259
 
260
  }
app/classes/admin/class-rss-pi-admin-processor.php CHANGED
@@ -7,405 +7,426 @@
7
  */
8
  class rssPIAdminProcessor {
9
 
10
- /**
11
- * If we have a valid api key
12
- *
13
- * @var boolean
14
- */
15
- var $is_key_valid;
16
-
17
- /**
18
- * Process the form result
19
- *
20
- * @global object $rss_post_importer
21
- * @return null
22
- */
23
- function process() {
24
-
25
- // if there's nothing for processing or invalid data, bail
26
- if (!isset($_POST['info_update']) || !wp_verify_nonce($_POST['rss_pi_nonce'], 'settings_page')) {
27
- return;
28
- }
29
-
30
-
31
- // Get ids of feed-rows
32
- $ids = explode(",", $_POST['ids']);
33
- // formulate the settings array
34
- $settings = $this->process_settings();
35
-
36
- // check result for "invalid_key" flag
37
- $invalid_api_key = isset($settings['invalid_api_key']);
38
- unset($settings['invalid_api_key']);
39
-
40
- // update cron settings
41
- $this->update_cron($settings['frequency']);
42
-
43
- // formulate the feeds array
44
- $feeds = array();
45
- if(is_array($ids)){
46
- $feeds = $this->process_feeds($ids);
47
- }
48
-
49
-
50
- // import CSV file
51
- if ( isset($_FILES['import_csv']) && $settings['is_key_valid'] ) {
52
- $feeds = $this->import_csv($feeds);
53
- }
54
-
55
- // import OPML file
56
- // @since v2.1.3
57
- if ( isset($_FILES['import_opml']) && is_uploaded_file($_FILES['import_opml']['tmp_name']) ) {
58
- $opml = new Rss_pi_opml();
59
- $feeds = $opml->import($feeds);
60
- $opml_errors = $opml->errors;
61
- } else {
62
- $opml_errors = array();
63
- }
64
-
65
- // save and reload the options
66
- $this->save_reload_options($settings, $feeds);
67
-
68
- global $rss_post_importer;
69
-
70
- wp_redirect(add_query_arg(
71
- array(
72
- 'settings-updated' => 'true',
73
- // yield the routine for import feeds via AJAX when needed
74
- 'import' => ( $_POST['save_to_db'] == 'true' ),
75
- 'message' => $invalid_api_key ? 2 : 1,
76
- // 'opml_errors' => $opml_errors ? urlencode(implode('<br/>',$opml_errors)) : '',
77
- ),
78
- $rss_post_importer->page_link
79
- ));
80
- exit;
81
- }
82
-
83
- /**
84
- * Purge "deleted_posts" cache from wp_options
85
- * @return void
86
- */
87
- function purge_deleted_posts_cache() {
88
-
89
- if (isset($_POST['purge_deleted_cache'])) {
90
-
91
- delete_option('rss_pi_deleted_posts');
92
- delete_option('rss_pi_imported_posts');
93
-
94
- global $rss_post_importer;
95
-
96
- wp_redirect(add_query_arg(
97
- array(
98
- 'deleted_cache_purged' => 'true',
99
- ),
100
- $rss_post_importer->page_link
101
- ));
102
- exit;
103
-
104
- }
105
-
106
- }
107
-
108
- /**
109
- * Import CSV function to import CSV file data into database
110
-
111
- * @return array
112
- */
113
- private function import_csv($feeds) {
114
-
115
- if (is_uploaded_file($_FILES['import_csv']['tmp_name'])) {
116
- $file = $_FILES['import_csv']['tmp_name'];
117
- $fcount = file($file);
118
- $linescount = count($fcount) - 1;
119
- $file_handle = fopen($file, "r");
120
- $t = 0;
121
- $titlearray = array();
122
- while ($csv_line = fgetcsv($file_handle, 1024)) {
123
-
124
- if ($t <> 0) {
125
-
126
- for ($i = 0, $j = count($csv_line); $i < $j; $i++) {
127
- if ($i == 0)
128
- $importdata['feeds'][$t - 1]['id'] = uniqid("54d4c" . $t);
129
-
130
- $importdata['feeds'][$t - 1][$titlearray[$i]] = $csv_line[$i];
131
- }
132
- }
133
- else {
134
- for ($i = 0, $j = count($csv_line); $i < $j; $i++) {
135
- $titlearray[] = $csv_line[$i];
136
- }
137
- }
138
- $t++;
139
- }
140
- fclose($file_handle) or die("can't close file");
141
-
142
- if (!empty($importdata['feeds'])) {
143
- for ($r = 0; $r < count($importdata['feeds']); $r++) {
144
- if ( isset($importdata['feeds'][$r]['category_id']) ) {
145
- $importdata['feeds'][$r]['category_id'] = explode(',',$importdata['feeds'][$r]['category_id']);
146
- $importdata['feeds'][$r]['tags_id'] = explode(',',$importdata['feeds'][$r]['tags_id']);
147
- $importdata['feeds'][$r]['keywords'] = explode(',',$importdata['feeds'][$r]['keywords']);
148
- $importdata['feeds'][$r]['strip_html'] = $importdata['feeds'][$r]['strip_html']; // this is a STRING, not a BOOLEAN
149
- } else {
150
- $importdata['feeds'][$r]['category_id'] = array(1);
151
- $importdata['feeds'][$r]['tags_id'] = "";
152
- $importdata['feeds'][$r]['keywords'] = "";
153
- $importdata['feeds'][$r]['strip_html'] = "false";
154
- }
155
-
156
- $check_result = $this->check_feed_exist($feeds, $importdata['feeds'][$r]);
157
-
158
- if ($check_result) {
159
- unset($importdata['feeds'][$r]);
160
- } else {
161
- array_push($feeds, $importdata['feeds'][$r]);
162
- }
163
- }
164
- }
165
- }
166
-
167
- return $feeds;
168
- }
169
-
170
- function check_feed_exist($feeds, $csvlink) {
171
-
172
- if (!empty($feeds) && !empty($csvlink)) {
173
-
174
- for ($g = 0; $g < count($feeds); $g++) {
175
-
176
- if ($feeds[$g]['url'] == $csvlink['url']) {
177
-
178
- return true;
179
- }
180
- }
181
- return false;
182
- }
183
- }
184
-
185
- /**
186
- * Process submitted data to formulate settings array
187
- *
188
- * @global object $rss_post_importer
189
- * @return array
190
- */
191
- private function process_settings() {
192
-
193
- // Get selected settings for all imported posts
194
-
195
- // Code added for custom frequency
196
-
197
- $frequency_check = sanitize_text_field($_POST['frequency']);
198
-
199
- if($frequency_check=="custom_frequency")
200
- {
201
- $rss_custom_frequency = intval($_POST['rss_custom_frequency']);
202
- $frequency = "minutes_".$rss_custom_frequency;
203
- $custom_frequency = 'true';
204
- // Adding option for custom cron
205
- $rss_custom_cron_frequency = serialize(
206
- array('time'=>$rss_custom_frequency,
207
- 'frequency'=>$frequency
208
- )
209
- );
210
-
211
- delete_option( 'rss_custom_cron_frequency' );
212
- add_option( 'rss_custom_cron_frequency',$rss_custom_cron_frequency);
213
- }else
214
- {
215
- $frequency = sanitize_text_field($_POST['frequency']);
216
- $custom_frequency = 'false';
217
-
218
- // Delete custom cron if not exixts
219
- delete_option( 'rss_custom_cron_frequency' );
220
- }
221
-
222
-
223
- $settings = array(
224
- 'frequency' => $frequency,
225
- 'feeds_api_key' => htmlentities($_POST['feeds_api_key']),
226
- 'post_template' => stripslashes_deep($_POST['post_template']),
227
- 'post_status' => sanitize_text_field($_POST['post_status']),
228
- 'author_id' => intval($_POST['author_id']),
229
- 'allow_comments' => sanitize_text_field($_POST['allow_comments']),
230
- 'block_indexing' => sanitize_text_field($_POST['block_indexing']),
231
- 'nofollow_outbound' =>sanitize_text_field($_POST['nofollow_outbound']),
232
- 'enable_logging' => sanitize_text_field($_POST['enable_logging']),
233
- 'tw_show' => sanitize_text_field($_POST['tw_show']),
234
- 'gg_show' => sanitize_text_field($_POST['gg_show']),
235
- 'og_show' => sanitize_text_field($_POST['og_show']),
236
- 'import_images_locally' => sanitize_text_field($_POST['import_images_locally']),
237
- 'disable_thumbnail' => sanitize_text_field($_POST['disable_thumbnail']),
238
- // these values are setup after key_validity check via filter()
239
- 'keywords' => array(),
240
- 'cache_deleted' => 'true',
241
- 'custom_frequency' => $custom_frequency
242
- );
243
-
244
- global $rss_post_importer;
245
-
246
- // check if submitted api key is valid
247
- $this->is_key_valid = $rss_post_importer->is_valid_key($settings['feeds_api_key']);
248
- // save key validity state
249
- $settings['is_key_valid'] = $this->is_key_valid;
250
-
251
- // filter the settings and then send them back for saving
252
- return $this->filter($settings);
253
- }
254
-
255
- /**
256
- * Update the frequency of the import cron job
257
- *
258
- * @param string $frequency
259
- */
260
- private function update_cron($frequency) {
261
-
262
- // If cron settings have changed
263
- if (wp_get_schedule('rss_pi_cron') != $frequency) {
264
-
265
- // Reset cron
266
- wp_clear_scheduled_hook('rss_pi_cron');
267
- wp_schedule_event(time(), $frequency, 'rss_pi_cron');
268
- }
269
- }
270
-
271
- /**
272
- * Forms the feeds array from submitted data
273
- *
274
- * @param array $ids feeds ids
275
- * @return array
276
- */
277
- private function process_feeds($ids) {
278
-
279
-
280
- $sts_id = $_POST['sts_id'];
281
-
282
- $status_id = array();
283
- if(!empty($sts_id))
284
- {
285
- $status_id = explode(',',$sts_id);
286
- }
287
- $feeds = array();
288
-
289
- foreach ($ids as $id) {
290
- if ($id) {
291
- $keywords = array();
292
- // if the key is valid
293
- if ($this->is_key_valid) {
294
- // set up keywords (otherwise don't)
295
- if (isset($_POST[$id . '-keywords'])) {
296
- $keyword_str = $_POST[$id . '-keywords'];
297
- }
298
- if (!empty($keyword_str)) {
299
- $keywords = explode(',', $keyword_str);
300
- }
301
-
302
- }
303
- if(in_array($id,$status_id))
304
- $feed_status="pause";
305
- else
306
- $feed_status="active";
307
-
308
-
309
- array_push($feeds, array(
310
- 'id' => $id,
311
- 'url' => $_POST[$id . '-url'],
312
- 'name' => $_POST[$id . '-name'],
313
- 'max_posts' => intval($_POST[$id . '-max_posts']),
314
- // different author ids depending on valid API keys
315
- 'author_id' => ($this->is_key_valid && isset($_POST[$id . '-author_id'])) ? intval($_POST[$id . '-author_id']) : intval($_POST['author_id']),
316
- 'category_id' => (isset($_POST[$id . '-category_id'])) ? $_POST[$id . '-category_id'] : '',
317
- 'tags_id' => (isset($_POST[$id . '-tags_id'])) ? $_POST[$id . '-tags_id'] : '',
318
- 'keywords' => array_map('trim',$keywords),
319
- 'strip_html' => (isset($_POST[$id . '-strip_html'])) ? $_POST[$id . '-strip_html'] : '',
320
- 'nofollow_outbound' => (isset($_POST[$id . '-nofollow_outbound'])) ? $_POST[$id . '-nofollow_outbound'] : '',
321
- 'automatic_import_categories' => (isset($_POST[$id . '-automatic_import_categories'])) ? $_POST[$id . '-automatic_import_categories'] : '',
322
- 'automatic_import_author' => (isset($_POST[$id . '-automatic_import_author'])) ? $_POST[$id . '-automatic_import_author'] : '',
323
- 'canonical_urls' => (isset($_POST[$id . '-canonical_urls'])) ? $_POST[$id . '-canonical_urls'] : '',
324
- 'feed_status' => $feed_status
325
- ));
326
- }
327
- }
328
- return $feeds;
329
- }
330
-
331
- /**
332
- * Update options and reload global options
333
- *
334
- * @global type $rss_post_importer
335
- * @param array $settings
336
- * @param array $feeds
337
- */
338
- private function save_reload_options($settings, $feeds) {
339
-
340
-
341
-
342
- global $rss_post_importer;
343
-
344
- // existing options
345
- $options = $rss_post_importer->options;
346
-
347
- // new data
348
- $new_options = array(
349
- 'feeds' => $feeds,
350
- 'settings' => $settings,
351
- 'latest_import' => $options['latest_import'],
352
- 'imports' => $options['imports'],
353
- 'upgraded' => $options['upgraded']
354
- );
355
-
356
- // update in db
357
- update_option('rss_pi_feeds', $new_options);
358
-
359
-
360
-
361
- // reload so that the new options are used henceforth
362
- $rss_post_importer->load_options();
363
-
364
-
365
- }
366
-
367
- /**
368
- * Filter settings for API key vs non-API key installs
369
- *
370
- * @param array $settings
371
- * @return array
372
- */
373
- private function filter($settings) {
374
-
375
- // if the key is not fine
376
- if (!empty($settings['feeds_api_key']) && !$this->is_key_valid) {
377
-
378
- // unset from settings
379
- unset($settings['feeds_api_key']);
380
- $settings['invalid_api_key'] = true;
381
- }
382
-
383
- // if the key is valid
384
- if ($this->is_key_valid) {
385
-
386
- // set up keywords (otherwise don't)
387
- if (isset($_POST['keyword_filter']))
388
-
389
- // Strip Slases for RegEx
390
- $keyword_str = stripslashes($_POST['keyword_filter']);
391
-
392
- $keywords = array();
393
-
394
- if (!empty($keyword_str)) {
395
- $keywords = explode(',', $keyword_str);
396
- }
397
- $keywords;
398
-
399
-
400
-
401
- $settings['keywords'] = array_map('trim',$keywords);
402
-
403
- // set up "import deleted posts" (otherwise don't)
404
- $settings['cache_deleted'] = isset($_POST['cache_deleted']) ? $_POST['cache_deleted'] : 'true';
405
-
406
- }
407
-
408
- return $settings;
409
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
410
 
411
  }
7
  */
8
  class rssPIAdminProcessor {
9
 
10
+ /**
11
+ * If we have a valid api key
12
+ *
13
+ * @var boolean
14
+ */
15
+ var $is_key_valid;
16
+
17
+ /**
18
+ * Process the form result
19
+ *
20
+ * @global object $rss_post_importer
21
+ * @return null
22
+ */
23
+ function process() {
24
+ global $rss_post_importer;
25
+
26
+ // bail if there's nothing to process or the data is invalid
27
+ if (! isset($_POST['info_update']) ||
28
+ ! wp_verify_nonce($_POST['rss_pi_nonce'], 'settings_page')) {
29
+ return;
30
+ }
31
+
32
+ // formulate the settings array
33
+ $settings = $this->process_settings();
34
+
35
+ // check result for "invalid_key" flag
36
+ $invalid_api_key = isset($settings['invalid_api_key']);
37
+ unset($settings['invalid_api_key']);
38
+
39
+ // update cron settings
40
+ $this->update_cron($settings['frequency']);
41
+
42
+ $feeds = $this->process_feeds($rss_post_importer->options['feeds']);
43
+
44
+ // import CSV file
45
+ if (isset($_FILES['import_csv']) && $settings['is_key_valid']) {
46
+ $feeds = $this->import_csv($feeds);
47
+ }
48
+
49
+ // import OPML file
50
+ // @since v2.1.3
51
+ if (isset($_FILES['import_opml']) && is_uploaded_file($_FILES['import_opml']['tmp_name'])) {
52
+ $opml = new Rss_pi_opml();
53
+ $feeds = $opml->import($feeds);
54
+ $opml_errors = $opml->errors;
55
+ } else {
56
+ $opml_errors = array();
57
+ }
58
+
59
+ // save and reload the options
60
+ $this->save_reload_options($settings, $feeds);
61
+
62
+ wp_redirect(add_query_arg(
63
+ array(
64
+ 'settings-updated' => 'true',
65
+ // yield the routine for import feeds via AJAX when needed
66
+ 'import' => ( $_POST['save_to_db'] == 'true' ),
67
+ 'message' => $invalid_api_key ? 2 : 1,
68
+ //'opml_errors' => $opml_errors ? urlencode(implode('<br/>', $opml_errors)) : '',
69
+ ),
70
+ $rss_post_importer->page_link
71
+ ));
72
+
73
+ exit;
74
+ }
75
+
76
+ /**
77
+ * Purge "deleted_posts" cache from wp_options
78
+ * @return void
79
+ */
80
+ function purge_deleted_posts_cache() {
81
+ if (! isset($_POST['purge_deleted_cache'])) return;
82
+
83
+ delete_option('rss_pi_deleted_posts');
84
+ delete_option('rss_pi_imported_posts');
85
+
86
+ global $rss_post_importer;
87
+
88
+ wp_redirect(add_query_arg(
89
+ array(
90
+ 'deleted_cache_purged' => 'true',
91
+ ),
92
+ $rss_post_importer->page_link
93
+ ));
94
+
95
+ exit;
96
+
97
+ }
98
+
99
+ /**
100
+ * Import CSV function to import CSV file data into database
101
+
102
+ * @return array
103
+ */
104
+ private function import_csv($feeds) {
105
+
106
+ if (is_uploaded_file($_FILES['import_csv']['tmp_name'])) {
107
+ $file = $_FILES['import_csv']['tmp_name'];
108
+ $fcount = file($file);
109
+ $linescount = count($fcount) - 1;
110
+ $file_handle = fopen($file, "r");
111
+ $t = 0;
112
+ $titlearray = array();
113
+ while ($csv_line = fgetcsv($file_handle, 1024)) {
114
+
115
+ if ($t <> 0) {
116
+
117
+ for ($i = 0, $j = count($csv_line); $i < $j; $i++) {
118
+ if ($i == 0)
119
+ $importdata['feeds'][$t - 1]['id'] = uniqid("54d4c" . $t);
120
+
121
+ $importdata['feeds'][$t - 1][$titlearray[$i]] = $csv_line[$i];
122
+ }
123
+ }
124
+ else {
125
+ for ($i = 0, $j = count($csv_line); $i < $j; $i++) {
126
+ $titlearray[] = $csv_line[$i];
127
+ }
128
+ }
129
+ $t++;
130
+ }
131
+ fclose($file_handle) or die("can't close file");
132
+
133
+ if (!empty($importdata['feeds'])) {
134
+ for ($r = 0; $r < count($importdata['feeds']); $r++) {
135
+ if ( isset($importdata['feeds'][$r]['category_id']) ) {
136
+ $importdata['feeds'][$r]['category_id'] = explode(',',$importdata['feeds'][$r]['category_id']);
137
+ $importdata['feeds'][$r]['tags_id'] = explode(',',$importdata['feeds'][$r]['tags_id']);
138
+ $importdata['feeds'][$r]['keywords'] = explode(',',$importdata['feeds'][$r]['keywords']);
139
+ $importdata['feeds'][$r]['strip_html'] = $importdata['feeds'][$r]['strip_html']; // this is a STRING, not a BOOLEAN
140
+ } else {
141
+ $importdata['feeds'][$r]['category_id'] = array(1);
142
+ $importdata['feeds'][$r]['tags_id'] = "";
143
+ $importdata['feeds'][$r]['keywords'] = "";
144
+ $importdata['feeds'][$r]['strip_html'] = "false";
145
+ }
146
+
147
+ $check_result = $this->check_feed_exist($feeds, $importdata['feeds'][$r]);
148
+
149
+ if ($check_result) {
150
+ unset($importdata['feeds'][$r]);
151
+ } else {
152
+ array_push($feeds, $importdata['feeds'][$r]);
153
+ }
154
+ }
155
+ }
156
+ }
157
+
158
+ return $feeds;
159
+ }
160
+
161
+ function check_feed_exist($feeds, $csvlink) {
162
+ if (!empty($feeds) && !empty($csvlink)) {
163
+
164
+ for ($i = 0; $i < count($feeds); $i++) {
165
+ if ($feeds[$i]['url'] == $csvlink['url']) {
166
+ return true;
167
+ }
168
+ }
169
+
170
+ return false;
171
+ }
172
+ }
173
+
174
+ /**
175
+ * Process submitted data to formulate settings array
176
+ *
177
+ * @global object $rss_post_importer
178
+ * @return array
179
+ */
180
+ private function process_settings() {
181
+
182
+ // Get selected settings for all imported posts
183
+
184
+ // Code added for custom frequency
185
+ $frequency_check = isset($_POST['frequency']) ? sanitize_text_field($_POST['frequency']) : '';
186
+
187
+ if ($frequency_check == "custom_frequency") {
188
+ $rss_custom_frequency = intval($_POST['rss_custom_frequency']);
189
+ $frequency = "minutes_" . $rss_custom_frequency;
190
+ $custom_frequency = 'true';
191
+ // Adding option for custom cron
192
+ $rss_custom_cron_frequency = serialize(
193
+ array(
194
+ 'time' => $rss_custom_frequency,
195
+ 'frequency' => $frequency
196
+ )
197
+ );
198
+
199
+ delete_option( 'rss_custom_cron_frequency' );
200
+ add_option( 'rss_custom_cron_frequency',$rss_custom_cron_frequency);
201
+ } else {
202
+ $frequency = isset($_POST['frequency']) ? sanitize_text_field($_POST['frequency']) : '';
203
+ $custom_frequency = 'false';
204
+
205
+ // Delete custom cron if not exixts
206
+ delete_option( 'rss_custom_cron_frequency' );
207
+ }
208
+
209
+
210
+ $settings = array(
211
+ 'frequency' => $frequency,
212
+ 'feeds_api_key' => htmlentities($_POST['feeds_api_key']),
213
+ 'post_template' => stripslashes_deep($_POST['post_template']),
214
+ 'post_status' => sanitize_text_field($_POST['post_status']),
215
+ 'author_id' => intval($_POST['author_id']),
216
+ 'allow_comments' => isset($_POST['allow_comments']) ? sanitize_text_field($_POST['allow_comments']) : '',
217
+ 'block_indexing' => sanitize_text_field($_POST['block_indexing']),
218
+ 'nofollow_outbound' =>sanitize_text_field($_POST['nofollow_outbound']),
219
+ 'enable_logging' => sanitize_text_field($_POST['enable_logging']),
220
+ 'tw_show' => isset($_POST['tw_show']) ? sanitize_text_field($_POST['tw_show']) : '',
221
+ 'gg_show' => isset($_POST['gg_show']) ? sanitize_text_field($_POST['gg_show']) : '',
222
+ 'og_show' => isset($_POST['og_show']) ? sanitize_text_field($_POST['og_show']) : '',
223
+ 'import_images_locally' => sanitize_text_field($_POST['import_images_locally']),
224
+ 'disable_thumbnail' => sanitize_text_field($_POST['disable_thumbnail']),
225
+ // these values are setup after key_validity check via filter()
226
+ 'keywords' => array(),
227
+ 'cache_deleted' => 'true',
228
+ 'custom_frequency' => $custom_frequency
229
+ );
230
+
231
+ global $rss_post_importer;
232
+
233
+ // check if submitted api key is valid
234
+ $this->is_key_valid = $rss_post_importer->is_valid_key($settings['feeds_api_key']);
235
+ // save key validity state
236
+ $settings['is_key_valid'] = $this->is_key_valid;
237
+
238
+ // filter the settings and then send them back for saving
239
+ return $this->filter($settings);
240
+ }
241
+
242
+ /**
243
+ * Update the frequency of the import cron job
244
+ *
245
+ * @param string $frequency
246
+ */
247
+ private function update_cron($frequency) {
248
+
249
+ // If cron settings have changed
250
+ if (wp_get_schedule('rss_pi_cron') != $frequency) {
251
+
252
+ // Reset cron
253
+ wp_clear_scheduled_hook('rss_pi_cron');
254
+ wp_schedule_event(time(), $frequency, 'rss_pi_cron');
255
+ }
256
+ }
257
+
258
+ /**
259
+ * Creates the feeds array from the submitted data
260
+ *
261
+ * @return array
262
+ */
263
+ private function process_feeds($feeds) {
264
+ $paused_feeds = array();
265
+ if (isset($_POST['paused_feeds'])) {
266
+ $paused_feeds = explode(',', $_POST['paused_feeds']);
267
+ }
268
+
269
+ $deleted_feeds = array();
270
+ if (isset($_POST['deleted_feeds'])) {
271
+ $deleted_feeds = explode(',', $_POST['deleted_feeds']);
272
+ }
273
+
274
+ $modified_feeds = array();
275
+ if (isset($_POST['modified_feeds'])) {
276
+ $modified_feeds = explode(',', $_POST['modified_feeds']);
277
+ }
278
+
279
+ $new_feeds = array();
280
+ if (isset($_POST['new_feeds'])) {
281
+ $new_feeds = explode(',', $_POST['new_feeds']);
282
+ }
283
+
284
+ foreach ($feeds as $key => $feed) {
285
+ if (in_array($feed['id'], $paused_feeds)) {
286
+ $feeds[$key]['feed_status'] = 'pause';
287
+ } else {
288
+ $feeds[$key]['feed_status'] = 'active';
289
+ }
290
+
291
+ if (in_array($feed['id'], $deleted_feeds)) {
292
+ unset($feeds[$key]);
293
+ }
294
+
295
+ if (in_array($feed['id'], $modified_feeds)) {
296
+ $keywords = array();
297
+ if ($this->is_key_valid) {
298
+ // if the key is valid set up keywords (otherwise don't)
299
+ if (isset($_POST[$feed['id'] . '-keywords'])) {
300
+ $keyword_str = $_POST[$feed['id'] . '-keywords'];
301
+ }
302
+ if (! empty($keyword_str)) {
303
+ $keywords = explode(',', $keyword_str);
304
+ }
305
+ }
306
+
307
+ $feed['url'] = $_POST[$feed['id'] . '-url'];
308
+ $feed['name'] = $_POST[$feed['id'] . '-name'];
309
+ $feed['max_posts'] = intval($_POST[$feed['id'] . '-max_posts']);
310
+ $feed['author_id'] = ($this->is_key_valid && isset($_POST[$feed['id'] . '-author_id'])) ? intval($_POST[$feed['id'] . '-author_id']) : intval($_POST['author_id']);
311
+ $feed['category_id'] = (isset($_POST[$feed['id'] . '-category_id'])) ? $_POST[$feed['id'] . '-category_id'] : '';
312
+ $feed['tags_id'] = (isset($_POST[$feed['id'] . '-tags_id'])) ? $_POST[$feed['id'] . '-tags_id'] : '';
313
+ $feed['keywords'] = array_map('trim', $keywords);
314
+ $feed['strip_html'] = (isset($_POST[$feed['id'] . '-strip_html'])) ? $_POST[$feed['id'] . '-strip_html'] : '';
315
+ $feed['nofollow_outbound'] = (isset($_POST[$feed['id'] . '-nofollow_outbound'])) ? $_POST[$feed['id'] . '-nofollow_outbound'] : '';
316
+ $feed['automatic_import_categories'] = (isset($_POST[$feed['id'] . '-automatic_import_categories'])) ? $_POST[$feed['id'] . '-automatic_import_categories'] : '';
317
+ $feed['automatic_import_author'] = (isset($_POST[$feed['id'] . '-automatic_import_author'])) ? $_POST[$feed['id'] . '-automatic_import_author'] : '';
318
+ $feed['canonical_urls'] = (isset($_POST[$feed['id'] . '-canonical_urls'])) ? $_POST[$feed['id'] . '-canonical_urls'] : '';
319
+
320
+ $feeds[$key] = $feed;
321
+ }
322
+ }
323
+
324
+ foreach ($new_feeds as $id) {
325
+ if (! $id) continue;
326
+
327
+ $keywords = array();
328
+ if ($this->is_key_valid) {
329
+ // if the key is valid set up keywords (otherwise don't)
330
+ if (isset($_POST[$id . '-keywords'])) {
331
+ $keyword_str = $_POST[$id . '-keywords'];
332
+ }
333
+ if (! empty($keyword_str)) {
334
+ $keywords = explode(',', $keyword_str);
335
+ }
336
+ }
337
+
338
+ $feed_status = in_array($id, $paused_feeds) ? 'pause' : 'active';
339
+
340
+ array_push($feeds, array(
341
+ 'id' => $id,
342
+ 'url' => $_POST[$id . '-url'],
343
+ 'name' => $_POST[$id . '-name'],
344
+ 'max_posts' => intval($_POST[$id . '-max_posts']),
345
+ // different author ids depending on valid API keys
346
+ 'author_id' => ($this->is_key_valid && isset($_POST[$id . '-author_id'])) ? intval($_POST[$id . '-author_id']) : intval($_POST['author_id']),
347
+ 'category_id' => (isset($_POST[$id . '-category_id'])) ? $_POST[$id . '-category_id'] : '',
348
+ 'tags_id' => (isset($_POST[$id . '-tags_id'])) ? $_POST[$id . '-tags_id'] : '',
349
+ 'keywords' => array_map('trim',$keywords),
350
+ 'strip_html' => (isset($_POST[$id . '-strip_html'])) ? $_POST[$id . '-strip_html'] : '',
351
+ 'nofollow_outbound' => (isset($_POST[$id . '-nofollow_outbound'])) ? $_POST[$id . '-nofollow_outbound'] : '',
352
+ 'automatic_import_categories' => (isset($_POST[$id . '-automatic_import_categories'])) ? $_POST[$id . '-automatic_import_categories'] : '',
353
+ 'automatic_import_author' => (isset($_POST[$id . '-automatic_import_author'])) ? $_POST[$id . '-automatic_import_author'] : '',
354
+ 'canonical_urls' => (isset($_POST[$id . '-canonical_urls'])) ? $_POST[$id . '-canonical_urls'] : '',
355
+ 'feed_status' => $feed_status
356
+ ));
357
+ }
358
+
359
+ return $feeds;
360
+ }
361
+
362
+ /**
363
+ * Update options and reload global options
364
+ *
365
+ * @global type $rss_post_importer
366
+ * @param array $settings
367
+ * @param array $feeds
368
+ */
369
+ private function save_reload_options($settings, $feeds) {
370
+ global $rss_post_importer;
371
+
372
+ // existing options
373
+ $options = $rss_post_importer->options;
374
+
375
+ // new data
376
+ $new_options = array(
377
+ 'feeds' => $feeds,
378
+ 'settings' => $settings,
379
+ 'latest_import' => $options['latest_import'],
380
+ 'imports' => $options['imports'],
381
+ 'upgraded' => $options['upgraded']
382
+ );
383
+
384
+ // update in db
385
+ update_option('rss_pi_feeds', $new_options);
386
+
387
+ // reload so that the new options are used henceforth
388
+ $rss_post_importer->load_options();
389
+ }
390
+
391
+ /**
392
+ * Filter settings for API key vs non-API key installs
393
+ *
394
+ * @param array $settings
395
+ * @return array
396
+ */
397
+ private function filter($settings) {
398
+
399
+ // if the key is not fine
400
+ if (!empty($settings['feeds_api_key']) && !$this->is_key_valid) {
401
+
402
+ // unset from settings
403
+ unset($settings['feeds_api_key']);
404
+ $settings['invalid_api_key'] = true;
405
+ }
406
+
407
+ // if the key is valid
408
+ if ($this->is_key_valid) {
409
+
410
+ // set up keywords (otherwise don't)
411
+ if (isset($_POST['keyword_filter']))
412
+
413
+ // Strip Slases for RegEx
414
+ $keyword_str = stripslashes($_POST['keyword_filter']);
415
+
416
+ $keywords = array();
417
+
418
+ if (!empty($keyword_str)) {
419
+ $keywords = explode(',', $keyword_str);
420
+ }
421
+
422
+ $settings['keywords'] = array_map('trim',$keywords);
423
+
424
+ // set up "import deleted posts" (otherwise don't)
425
+ $settings['cache_deleted'] = isset($_POST['cache_deleted']) ? $_POST['cache_deleted'] : 'true';
426
+
427
+ }
428
+
429
+ return $settings;
430
+ }
431
 
432
  }
app/classes/admin/class-rss-pi-admin.php CHANGED
@@ -9,15 +9,15 @@ class rssPIAdmin {
9
 
10
  /**
11
  * Whether the API key is valid
12
- *
13
  * @var boolean
14
  */
15
  var $is_key_valid;
16
 
17
  /**
18
  * The options
19
- *
20
- * @var array
21
  */
22
  var $options;
23
 
@@ -29,7 +29,7 @@ class rssPIAdmin {
29
 
30
  /**
31
  * Start
32
- *
33
  * @global object $rss_post_importer
34
  */
35
  public function __construct() {
@@ -101,6 +101,9 @@ class rssPIAdmin {
101
  // the ajax for adding new feeds (table rows)
102
  add_action('wp_ajax_rss_pi_add_row', array($this, 'add_row'));
103
 
 
 
 
104
  // the ajax for stats chart
105
  add_action('wp_ajax_rss_pi_stats', array($this, 'ajax_stats'));
106
 
@@ -112,7 +115,7 @@ class rssPIAdmin {
112
 
113
  // Add 10 minutes in frequency.
114
  add_filter('cron_schedules', array($this, 'rss_pi_cron_add'));
115
-
116
  add_filter('cron_schedules', array($this, 'rss_pi_cron_add_custom'));
117
 
118
  // trigger on Export
@@ -127,16 +130,12 @@ class rssPIAdmin {
127
  * Add to admin menu
128
  */
129
  function admin_menu() {
130
-
131
-
132
- add_options_page('Rss Post Importer', 'Rss Post Importer', 'manage_options','rss_pi', array($this, 'screen'));
133
-
134
-
135
- }
136
 
137
  /**
138
  * Enqueue our admin css and js
139
- *
140
  * @param string $hook The current screens hook
141
  * @return null
142
  */
@@ -159,7 +158,7 @@ class rssPIAdmin {
159
  wp_enqueue_script('modernizr', RSS_PI_URL . 'app/assets/js/modernizr.custom.32882.js', array(), RSS_PI_VERSION, true);
160
  wp_enqueue_script('phpjs-uniqid', RSS_PI_URL . 'app/assets/js/uniqid.js', array(), RSS_PI_VERSION, true);
161
  wp_enqueue_script('rss-pi', RSS_PI_URL . 'app/assets/js/main.js', array('jquery'), RSS_PI_VERSION, true);
162
-
163
 
164
  // localise ajaxuel for use
165
  $localise_args = array(
@@ -200,13 +199,13 @@ class rssPIAdmin {
200
  'interval' => 600,
201
  'display' => '10 minutes'
202
  );
203
-
204
  return $schedules;
205
  }
206
-
207
  // this will fetch custom frequency
208
  function rss_pi_cron_add_custom($schedules) {
209
-
210
  // min in sec
211
  $rss_min = 60;
212
  $custom_cron_options = get_option( 'rss_custom_cron_frequency',array());
@@ -214,13 +213,13 @@ class rssPIAdmin {
214
  $rss_custom_cron = unserialize($custom_cron_options);
215
  $rss_frequency_cron = $rss_custom_cron['frequency'];
216
  $rss_frequency_time = $rss_custom_cron['time'];
217
- // Adding custom cron
218
  $schedules[$rss_frequency_cron] = array(
219
  'interval' => $rss_min*$rss_frequency_time,
220
  'display' => $rss_frequency_time.' minutes'
221
  );
222
  }
223
- return $schedules;
224
  }
225
 
226
  /**
@@ -241,7 +240,7 @@ class rssPIAdmin {
241
  * Display the screen/ui
242
  */
243
  function screen() {
244
-
245
  // it'll process any submitted form data
246
  // reload the options just in case
247
  $this->load_options();
@@ -275,20 +274,22 @@ class rssPIAdmin {
275
  if( isset($_GET['import']) && isset($_GET['settings-updated']) && $_GET['settings-updated'] ) {
276
  ?>
277
  <script type="text/javascript">
 
278
  <?php
279
-
280
- $ids = array();
281
- if ( is_array($this->options['feeds']) ) :
282
- foreach ($this->options['feeds'] as $f) :
283
- $ids[] = $f['id'];
284
- endforeach;
285
- endif;
286
  ?>
287
- if ( feeds !== undefined ) {
288
- feeds.set( <?php echo json_encode($ids); ?> );
289
- } else {
290
- var feeds = <?php echo json_encode($ids); ?>;
291
- }
 
 
292
  </script>
293
  <?php
294
  }
@@ -321,7 +322,7 @@ if ( feeds !== undefined ) {
321
 
322
  /**
323
  * Display errors
324
- *
325
  * @param string $error The error message
326
  * @param boolean $inline Whether the error is inline or shown like regular wp errors
327
  */
@@ -336,16 +337,34 @@ if ( feeds !== undefined ) {
336
  * Add a new row for a new feed
337
  */
338
  function add_row() {
 
 
 
339
 
 
 
340
  include( RSS_PI_PATH . 'app/templates/feed-table-row.php');
341
  die();
342
  }
343
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
344
  /**
345
  * Generate stats data and return
346
  */
347
  function ajax_stats() {
348
-
349
  include( RSS_PI_PATH . 'app/templates/stats.php');
350
  die();
351
  }
@@ -444,7 +463,7 @@ if ( feeds !== undefined ) {
444
 
445
  /**
446
  * Disable the user dropdwon for each feed
447
- *
448
  * @param string $output The html of the select dropdown
449
  * @return string
450
  */
@@ -469,9 +488,9 @@ if ( feeds !== undefined ) {
469
 
470
  /**
471
  * Walker class function for category multiple checkbox
472
- *
473
- *
474
- *
475
  */
476
  function wp_category_checklist_rss_pi($post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $walker = null, $checked_ontop = true) {
477
 
9
 
10
  /**
11
  * Whether the API key is valid
12
+ *
13
  * @var boolean
14
  */
15
  var $is_key_valid;
16
 
17
  /**
18
  * The options
19
+ *
20
+ * @var array
21
  */
22
  var $options;
23
 
29
 
30
  /**
31
  * Start
32
+ *
33
  * @global object $rss_post_importer
34
  */
35
  public function __construct() {
101
  // the ajax for adding new feeds (table rows)
102
  add_action('wp_ajax_rss_pi_add_row', array($this, 'add_row'));
103
 
104
+ // the ajax for editing a feed row
105
+ add_action('wp_ajax_rss_pi_edit_row', array($this, 'edit_row'));
106
+
107
  // the ajax for stats chart
108
  add_action('wp_ajax_rss_pi_stats', array($this, 'ajax_stats'));
109
 
115
 
116
  // Add 10 minutes in frequency.
117
  add_filter('cron_schedules', array($this, 'rss_pi_cron_add'));
118
+
119
  add_filter('cron_schedules', array($this, 'rss_pi_cron_add_custom'));
120
 
121
  // trigger on Export
130
  * Add to admin menu
131
  */
132
  function admin_menu() {
133
+ add_options_page('Rss Post Importer', 'Rss Post Importer', 'manage_options','rss_pi', array($this, 'screen'));
134
+ }
 
 
 
 
135
 
136
  /**
137
  * Enqueue our admin css and js
138
+ *
139
  * @param string $hook The current screens hook
140
  * @return null
141
  */
158
  wp_enqueue_script('modernizr', RSS_PI_URL . 'app/assets/js/modernizr.custom.32882.js', array(), RSS_PI_VERSION, true);
159
  wp_enqueue_script('phpjs-uniqid', RSS_PI_URL . 'app/assets/js/uniqid.js', array(), RSS_PI_VERSION, true);
160
  wp_enqueue_script('rss-pi', RSS_PI_URL . 'app/assets/js/main.js', array('jquery'), RSS_PI_VERSION, true);
161
+
162
 
163
  // localise ajaxuel for use
164
  $localise_args = array(
199
  'interval' => 600,
200
  'display' => '10 minutes'
201
  );
202
+
203
  return $schedules;
204
  }
205
+
206
  // this will fetch custom frequency
207
  function rss_pi_cron_add_custom($schedules) {
208
+
209
  // min in sec
210
  $rss_min = 60;
211
  $custom_cron_options = get_option( 'rss_custom_cron_frequency',array());
213
  $rss_custom_cron = unserialize($custom_cron_options);
214
  $rss_frequency_cron = $rss_custom_cron['frequency'];
215
  $rss_frequency_time = $rss_custom_cron['time'];
216
+ // Adding custom cron
217
  $schedules[$rss_frequency_cron] = array(
218
  'interval' => $rss_min*$rss_frequency_time,
219
  'display' => $rss_frequency_time.' minutes'
220
  );
221
  }
222
+ return $schedules;
223
  }
224
 
225
  /**
240
  * Display the screen/ui
241
  */
242
  function screen() {
243
+
244
  // it'll process any submitted form data
245
  // reload the options just in case
246
  $this->load_options();
274
  if( isset($_GET['import']) && isset($_GET['settings-updated']) && $_GET['settings-updated'] ) {
275
  ?>
276
  <script type="text/javascript">
277
+ // determine the feed ids within wordpress
278
  <?php
279
+ $feed_ids = array();
280
+ if (is_array($this->options['feeds']) ) {
281
+ foreach ($this->options['feeds'] as $f) {
282
+ $feed_ids[] = $f['id'];
283
+ }
284
+ }
 
285
  ?>
286
+ // and set them as a global JS variable
287
+ if ( feeds !== undefined ) {
288
+ feeds.set(<?php echo json_encode($feed_ids); ?>);
289
+ } else {
290
+ var feeds = <?php echo json_encode($feed_ids); ?>;
291
+ }
292
+ console.log('what is this');
293
  </script>
294
  <?php
295
  }
322
 
323
  /**
324
  * Display errors
325
+ *
326
  * @param string $error The error message
327
  * @param boolean $inline Whether the error is inline or shown like regular wp errors
328
  */
337
  * Add a new row for a new feed
338
  */
339
  function add_row() {
340
+ if (! isset($_POST['feed_id'])) {
341
+ die();
342
+ }
343
 
344
+ $ajax_add = true;
345
+ $ajax_feed_id = $_POST['feed_id'];
346
  include( RSS_PI_PATH . 'app/templates/feed-table-row.php');
347
  die();
348
  }
349
 
350
+ function edit_row() {
351
+ if (! isset($_POST['feed_id'])) {
352
+ die();
353
+ }
354
+
355
+ foreach ($this->options['feeds'] as $f) {
356
+ if ($f['id'] == $_POST['feed_id']) {
357
+ $ajax_edit = true;
358
+ include( RSS_PI_PATH . 'app/templates/feed-table-row.php');
359
+ die();
360
+ }
361
+ }
362
+ }
363
+
364
  /**
365
  * Generate stats data and return
366
  */
367
  function ajax_stats() {
 
368
  include( RSS_PI_PATH . 'app/templates/stats.php');
369
  die();
370
  }
463
 
464
  /**
465
  * Disable the user dropdwon for each feed
466
+ *
467
  * @param string $output The html of the select dropdown
468
  * @return string
469
  */
488
 
489
  /**
490
  * Walker class function for category multiple checkbox
491
+ *
492
+ *
493
+ *
494
  */
495
  function wp_category_checklist_rss_pi($post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $walker = null, $checked_ontop = true) {
496
 
app/classes/front/class-rss-pi-front.php CHANGED
@@ -7,268 +7,274 @@
7
  */
8
  class rssPIFront {
9
 
10
- /**
11
- * Whether the API key is valid
12
- *
13
- * @var boolean
14
- */
15
- var $is_key_valid;
16
-
17
- /**
18
- * The options
19
- *
20
- * @var array
21
- */
22
- var $options;
23
-
24
- /**
25
- * Aprompt for invalid/absent API keys
26
- * @var string
27
- */
28
- var $key_prompt;
29
-
30
- /**
31
- * Initialise and hook all actions
32
- */
33
- public function init() {
34
- global $post, $rss_post_importer;
35
-
36
- // add noidex to front
37
- add_action('wp_head', array($this, 'rss_pi_noindex_meta_tag'));
38
- // add canonical urls
39
-
40
- remove_action( 'wp_head', 'rel_canonical' );
41
- add_action('wp_head', array($this, 'rss_pi_canonical_urls_meta_tag'));
42
-
43
- // add options
44
- $this->options = $rss_post_importer->options;
45
-
46
- // Check for block indexing
47
- if ($this->options['settings']['nofollow_outbound'] == 'true') {
48
- add_filter('the_content', array($this, 'rss_pi_url_parse'));
49
- }
50
- if($this->options['settings']['og_show']==1){
51
- add_action('wp_head', array($this, 'fb_opengraph'));
52
- }
53
- if($this->options['settings']['tw_show']==1){
54
- add_action('wp_head', array($this, 'add_twitter_cards'));
55
- }
56
- if($this->options['settings']['gg_show']==1){
57
- add_action('wp_head', array($this, 'add_google_item'));
58
- }
59
-
60
- }
61
-
62
- function rss_pi_noindex_meta_tag() {
63
- global $post, $rss_post_importer;
64
-
65
- //Add meta tag for UTF-8 character encoding.
66
- echo '<meta http-equiv="Content-type" content="text/html; charset=utf-8" />';
67
-
68
- // Check if single post
69
- if (is_single()) {
70
-
71
- // Get current post id
72
- $current_post_id = $post->ID;
73
-
74
- // add options
75
- $this->options = $rss_post_importer->options;
76
-
77
- // get value of block indexing
78
- $block_indexing = $this->options['settings']['block_indexing'];
79
-
80
- // Check for block indexing
81
- if ($this->options['settings']['block_indexing'] == 'true') {
82
- $meta_values = get_post_meta($current_post_id, 'rss_pi_source_url', false);
83
- // if meta value array is empty it means post is not imported by this plugin.
84
- if (!empty($meta_values)) {
85
- echo '<meta name="robots" content="noindex">';
86
- }
87
- }
88
- }
89
- }
90
-
91
-
92
- function rss_pi_canonical_urls_meta_tag() {
93
- global $post, $rss_post_importer;
94
-
95
- // Check if single post
96
- if (is_single()) {
97
-
98
- // Get current post id
99
- $current_post_id = $post->ID;
100
- // add options
101
- $this->options = $rss_post_importer->options;
102
-
103
- // Check for block indexing
104
-
105
- $meta_rss_pi_canonical_url = get_post_meta($current_post_id, 'rss_pi_canonical_url', false);
106
- if(!empty($meta_rss_pi_canonical_url) && $meta_rss_pi_canonical_url[0]=="source_blog"){
107
- $meta_values_source = get_post_meta($current_post_id, 'rss_pi_source_url', false);
108
- if (!empty($meta_values_source)) {
109
- $pieces = parse_url($meta_values_source[0]);
110
- $domain = isset($pieces['host']) ? $pieces['host'] : '';
111
- if (preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) {
112
- $domain= $regs['domain'];
113
- }
114
- $domain= $regs['domain'];
115
- $check_domain = explode('.',$domain);
116
- //Check URL for Google Only
117
- if(isset($check_domain[0]) && $check_domain[0]=="google"){
118
- $google_url = $pieces['fragment'];
119
- $google_explode = explode("url=",$google_url);
120
- if(isset($google_explode[1]) && $google_explode[1]!='')
121
- {
122
- $canonical_urls = $google_explode[1];
123
- }
124
- }else{
125
- $canonical_urls = $meta_values_source[0];
126
- }
127
-
128
- // if meta value array is empty it means post is not imported by this plugin.
129
- if (!empty($meta_values_source)) {
130
-
131
- echo "<link rel='canonical' href='".$canonical_urls."' />";
132
- }
133
-
134
- }
135
- }else
136
- {
137
- // original code
138
- $link = get_permalink( $current_post_id );
139
- echo "<link rel='canonical' href='$link' />\n";
140
-
141
- }
142
-
143
-
144
- }
145
- }
146
-
147
-
148
- function rss_pi_url_parse($content) {
149
-
150
- $regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>";
151
- if (preg_match_all("/$regexp/siU", $content, $matches, PREG_SET_ORDER)) {
152
- if (!empty($matches)) {
153
-
154
- $srcUrl = get_option('home');
155
- for ($i = 0; $i < count($matches); $i++) {
156
-
157
- $tag = $matches[$i][0];
158
- $tag2 = $matches[$i][0];
159
- $url = $matches[$i][0];
160
-
161
- $noFollow = '';
162
-
163
- $pattern = '/target\s*=\s*"\s*_blank\s*"/';
164
- preg_match($pattern, $tag2, $match, PREG_OFFSET_CAPTURE);
165
- if (count($match) < 1)
166
- $noFollow .= ' target="_blank" ';
167
-
168
- $pattern = '/rel\s*=\s*"\s*[n|d]ofollow\s*"/';
169
- preg_match($pattern, $tag2, $match, PREG_OFFSET_CAPTURE);
170
- if (count($match) < 1)
171
- $noFollow .= ' rel="nofollow" ';
172
-
173
- $pos = strpos($url, $srcUrl);
174
- if ($pos === false) {
175
- $tag = rtrim($tag, '>');
176
- $tag .= $noFollow . '>';
177
- $content = str_replace($tag2, $tag, $content);
178
- }
179
- }
180
- }
181
- }
182
-
183
- $content = str_replace(']]>', ']]&gt;', $content);
184
- return $content;
185
- }
186
-
187
- function add_twitter_cards() {
188
- global $post;
189
- if($this->options['settings']['tw_show']==1){
190
- if(is_single()) {
191
- $tc_url = get_permalink();
192
- $tc_title = get_the_title();
193
- if($excerpt = $post->post_content) {
194
- $excerpt = strip_tags($post->post_content);
195
- $excerpt = str_replace("", "'", $excerpt);
196
- }
197
- $tc_description = trim(substr($excerpt, 0,150));
198
- if(has_post_thumbnail($post->ID)) {
199
- $img_src = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), full );
200
- $tc_image_thumb = $img_src[0];
201
- } else {
202
- //$tc_image_thumb = site_url() . '/wp-content/plugins/rss-post-importer/app/assets/img/03-04-feedsapi-api.jpg';
203
- //plugins_url( 'images/wordpress.png', __FILE__ )
204
- $tc_image_thumb = plugins_url( 'app/assets/img/03-04-feedsapi-api.jpg', __FILE__ );
205
- }
206
- echo '<meta name="twitter:card" value="summary" />';
207
- echo '<meta name="twitter:site" value="@feedsapi" />';
208
- echo '<meta name="twitter:title" value="'.$tc_title.'" />';
209
- echo '<meta name="twitter:description" value="'.$tc_description.'" />';
210
- echo '<meta name="twitter:url" value="'.$tc_url.'" />';
211
- echo '<meta name="twitter:image" value="'.$tc_image_thumb.'" />';
212
- echo '<meta name="twitter:creator" value="@feedsapi" />';
213
- }
214
- }
215
- }
216
-
217
- function fb_opengraph() {
218
- global $post;
219
- if($this->options['settings']['og_show']==1){
220
- if(is_single()) {
221
- if(has_post_thumbnail($post->ID)) {
222
- $img_src = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), 'medium');
223
- $tc_image_thumb = $img_src[0];
224
- } else {
225
- //$tc_image_thumb = site_url() . '/wp-content/plugins/rss-post-importer/app/assets/img/03-04-feedsapi-api.jpg';
226
- $tc_image_thumb = plugins_url( 'app/assets/img/03-04-feedsapi-api.jpg', __FILE__ );
227
- }
228
-
229
- if($excerpt = $post->post_content) {
230
- $excerpt = strip_tags($post->post_content);
231
- $excerpt = str_replace("", "'", $excerpt);
232
- }
233
- $rest = trim(substr($excerpt, 0,150));
234
- $post_date = $post->post_date;
235
- $og_title = get_the_title();
236
- $og_url = get_permalink();
237
- echo '<meta property="og:title" content="'.$og_title.'"/>';
 
 
 
 
 
 
238
  echo '<meta property="og:image" content="'.$tc_image_thumb.'"/>';
239
- echo '<meta property="og:image:width" content="681" />';
240
- echo '<meta property="og:image:height" content="358" />';
241
  echo '<meta property="og:site_name" content="'.get_bloginfo().'"/>';
242
  echo '<meta property="og:description" content="'.$rest.'"/>';
243
- }
244
- }
245
- }
246
-
247
- function add_google_item() {
248
- global $post;
249
- if($this->options['settings']['gg_show']==1){
250
- if(is_single()) {
251
- if(has_post_thumbnail($post->ID)) {
252
- $img_src = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), full );
253
- $tc_image_thumb = $img_src[0];
254
- } else {
255
- //$tc_image_thumb = site_url() . '/wp-content/plugins/rss-post-importer/app/assets/img/03-04-feedsapi-api.jpg';
256
- $tc_image_thumb = plugins_url( 'app/assets/img/03-04-feedsapi-api.jpg', __FILE__ );
257
- }
258
-
259
- if($excerpt = $post->post_content) {
260
- $excerpt = strip_tags($post->post_content);
261
- $excerpt = str_replace("", "'", $excerpt);
262
- }
263
- $rest = trim(substr($excerpt, 0,150));
264
- $gg_url = get_permalink();
265
- $gg_title = get_the_title();
266
- echo '<meta itemprop="name" content="'.$gg_title.'">';
267
- echo '<meta itemprop="description" content="'.$rest.'">';
268
- echo '<meta itemprop="image" content="'.$tc_image_thumb.'">';
269
- }
270
- }
271
- }
272
 
273
 
274
  }
7
  */
8
  class rssPIFront {
9
 
10
+ /**
11
+ * Whether the API key is valid
12
+ *
13
+ * @var boolean
14
+ */
15
+ var $is_key_valid;
16
+
17
+ /**
18
+ * The options
19
+ *
20
+ * @var array
21
+ */
22
+ var $options;
23
+
24
+ /**
25
+ * Aprompt for invalid/absent API keys
26
+ * @var string
27
+ */
28
+ var $key_prompt;
29
+
30
+ /**
31
+ * Initialise and hook all actions
32
+ */
33
+ public function init() {
34
+ global $post, $rss_post_importer;
35
+
36
+ // add noidex to front
37
+ add_action('wp_head', array($this, 'rss_pi_noindex_meta_tag'));
38
+ // add canonical urls
39
+
40
+ remove_action( 'wp_head', 'rel_canonical' );
41
+ add_action('wp_head', array($this, 'rss_pi_canonical_urls_meta_tag'));
42
+
43
+ // add options
44
+ $this->options = $rss_post_importer->options;
45
+
46
+ // Check for block indexing
47
+ if ($this->options['settings']['nofollow_outbound'] == 'true') {
48
+ add_filter('the_content', array($this, 'rss_pi_url_parse'));
49
+ }
50
+
51
+ $social = array(
52
+ 'tw_show' => 'add_twitter_cards',
53
+ 'gg_show' => 'add_google_item',
54
+ 'og_show' => 'fb_opengraph',
55
+ );
56
+
57
+ foreach($social as $key => $value) {
58
+ if (isset($this->options['settings'][$key]) &&
59
+ $this->options['settings'][$key] == 1) {
60
+
61
+ add_action('wp_head', array($this, $value));
62
+
63
+ }
64
+ }
65
+
66
+ }
67
+
68
+ function rss_pi_noindex_meta_tag() {
69
+ global $post, $rss_post_importer;
70
+
71
+ //Add meta tag for UTF-8 character encoding.
72
+ echo '<meta http-equiv="Content-type" content="text/html; charset=utf-8" />';
73
+
74
+ // Check if single post
75
+ if (is_single()) {
76
+
77
+ // Get current post id
78
+ $current_post_id = $post->ID;
79
+
80
+ // add options
81
+ $this->options = $rss_post_importer->options;
82
+
83
+ // get value of block indexing
84
+ $block_indexing = $this->options['settings']['block_indexing'];
85
+
86
+ // Check for block indexing
87
+ if ($this->options['settings']['block_indexing'] == 'true') {
88
+ $meta_values = get_post_meta($current_post_id, 'rss_pi_source_url', false);
89
+ // if meta value array is empty it means post is not imported by this plugin.
90
+ if (!empty($meta_values)) {
91
+ echo '<meta name="robots" content="noindex">';
92
+ }
93
+ }
94
+ }
95
+ }
96
+
97
+
98
+ function rss_pi_canonical_urls_meta_tag() {
99
+ global $post, $rss_post_importer;
100
+
101
+ // Check if single post
102
+ if (is_single()) {
103
+
104
+ // Get current post id
105
+ $current_post_id = $post->ID;
106
+ // add options
107
+ $this->options = $rss_post_importer->options;
108
+
109
+ // Check for block indexing
110
+
111
+ $meta_rss_pi_canonical_url = get_post_meta($current_post_id, 'rss_pi_canonical_url', false);
112
+ if(!empty($meta_rss_pi_canonical_url) && $meta_rss_pi_canonical_url[0]=="source_blog"){
113
+ $meta_values_source = get_post_meta($current_post_id, 'rss_pi_source_url', false);
114
+ if (!empty($meta_values_source)) {
115
+ $pieces = parse_url($meta_values_source[0]);
116
+ $domain = isset($pieces['host']) ? $pieces['host'] : '';
117
+ if (preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) {
118
+ $domain= $regs['domain'];
119
+ }
120
+ $domain= $regs['domain'];
121
+ $check_domain = explode('.',$domain);
122
+ //Check URL for Google Only
123
+ if(isset($check_domain[0]) && $check_domain[0]=="google"){
124
+ $google_url = $pieces['fragment'];
125
+ $google_explode = explode("url=",$google_url);
126
+ if(isset($google_explode[1]) && $google_explode[1]!='')
127
+ {
128
+ $canonical_urls = $google_explode[1];
129
+ }
130
+ }else{
131
+ $canonical_urls = $meta_values_source[0];
132
+ }
133
+
134
+ // if meta value array is empty it means post is not imported by this plugin.
135
+ if (!empty($meta_values_source)) {
136
+
137
+ echo "<link rel='canonical' href='".$canonical_urls."' />";
138
+ }
139
+
140
+ }
141
+ }else
142
+ {
143
+ // original code
144
+ $link = get_permalink( $current_post_id );
145
+ echo "<link rel='canonical' href='$link' />\n";
146
+
147
+ }
148
+
149
+
150
+ }
151
+ }
152
+
153
+
154
+ function rss_pi_url_parse($content) {
155
+
156
+ $regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>";
157
+ if (preg_match_all("/$regexp/siU", $content, $matches, PREG_SET_ORDER)) {
158
+ if (!empty($matches)) {
159
+
160
+ $srcUrl = get_option('home');
161
+ for ($i = 0; $i < count($matches); $i++) {
162
+
163
+ $tag = $matches[$i][0];
164
+ $tag2 = $matches[$i][0];
165
+ $url = $matches[$i][0];
166
+
167
+ $noFollow = '';
168
+
169
+ $pattern = '/target\s*=\s*"\s*_blank\s*"/';
170
+ preg_match($pattern, $tag2, $match, PREG_OFFSET_CAPTURE);
171
+ if (count($match) < 1)
172
+ $noFollow .= ' target="_blank" ';
173
+
174
+ $pattern = '/rel\s*=\s*"\s*[n|d]ofollow\s*"/';
175
+ preg_match($pattern, $tag2, $match, PREG_OFFSET_CAPTURE);
176
+ if (count($match) < 1)
177
+ $noFollow .= ' rel="nofollow" ';
178
+
179
+ $pos = strpos($url, $srcUrl);
180
+ if ($pos === false) {
181
+ $tag = rtrim($tag, '>');
182
+ $tag .= $noFollow . '>';
183
+ $content = str_replace($tag2, $tag, $content);
184
+ }
185
+ }
186
+ }
187
+ }
188
+
189
+ $content = str_replace(']]>', ']]&gt;', $content);
190
+ return $content;
191
+ }
192
+
193
+ function add_twitter_cards() {
194
+ global $post;
195
+ if($this->options['settings']['tw_show']==1){
196
+ if(is_single()) {
197
+ $tc_url = get_permalink();
198
+ $tc_title = get_the_title();
199
+ if($excerpt = $post->post_content) {
200
+ $excerpt = strip_tags($post->post_content);
201
+ $excerpt = str_replace("", "'", $excerpt);
202
+ }
203
+ $tc_description = trim(substr($excerpt, 0,150));
204
+ if(has_post_thumbnail($post->ID)) {
205
+ $img_src = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), full );
206
+ $tc_image_thumb = $img_src[0];
207
+ } else {
208
+ //$tc_image_thumb = site_url() . '/wp-content/plugins/rss-post-importer/app/assets/img/03-04-feedsapi-api.jpg';
209
+ //plugins_url( 'images/wordpress.png', __FILE__ )
210
+ $tc_image_thumb = plugins_url( 'app/assets/img/03-04-feedsapi-api.jpg', __FILE__ );
211
+ }
212
+ echo '<meta name="twitter:card" value="summary" />';
213
+ echo '<meta name="twitter:site" value="@feedsapi" />';
214
+ echo '<meta name="twitter:title" value="'.$tc_title.'" />';
215
+ echo '<meta name="twitter:description" value="'.$tc_description.'" />';
216
+ echo '<meta name="twitter:url" value="'.$tc_url.'" />';
217
+ echo '<meta name="twitter:image" value="'.$tc_image_thumb.'" />';
218
+ echo '<meta name="twitter:creator" value="@feedsapi" />';
219
+ }
220
+ }
221
+ }
222
+
223
+ function fb_opengraph() {
224
+ global $post;
225
+ if($this->options['settings']['og_show']==1){
226
+ if(is_single()) {
227
+ if(has_post_thumbnail($post->ID)) {
228
+ $img_src = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), 'medium');
229
+ $tc_image_thumb = $img_src[0];
230
+ } else {
231
+ //$tc_image_thumb = site_url() . '/wp-content/plugins/rss-post-importer/app/assets/img/03-04-feedsapi-api.jpg';
232
+ $tc_image_thumb = plugins_url( 'app/assets/img/03-04-feedsapi-api.jpg', __FILE__ );
233
+ }
234
+
235
+ if($excerpt = $post->post_content) {
236
+ $excerpt = strip_tags($post->post_content);
237
+ $excerpt = str_replace("", "'", $excerpt);
238
+ }
239
+ $rest = trim(substr($excerpt, 0,150));
240
+ $post_date = $post->post_date;
241
+ $og_title = get_the_title();
242
+ $og_url = get_permalink();
243
+ echo '<meta property="og:title" content="'.$og_title.'"/>';
244
  echo '<meta property="og:image" content="'.$tc_image_thumb.'"/>';
245
+ echo '<meta property="og:image:width" content="681" />';
246
+ echo '<meta property="og:image:height" content="358" />';
247
  echo '<meta property="og:site_name" content="'.get_bloginfo().'"/>';
248
  echo '<meta property="og:description" content="'.$rest.'"/>';
249
+ }
250
+ }
251
+ }
252
+
253
+ function add_google_item() {
254
+ global $post;
255
+ if($this->options['settings']['gg_show']==1){
256
+ if(is_single()) {
257
+ if(has_post_thumbnail($post->ID)) {
258
+ $img_src = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), full );
259
+ $tc_image_thumb = $img_src[0];
260
+ } else {
261
+ //$tc_image_thumb = site_url() . '/wp-content/plugins/rss-post-importer/app/assets/img/03-04-feedsapi-api.jpg';
262
+ $tc_image_thumb = plugins_url( 'app/assets/img/03-04-feedsapi-api.jpg', __FILE__ );
263
+ }
264
+
265
+ if($excerpt = $post->post_content) {
266
+ $excerpt = strip_tags($post->post_content);
267
+ $excerpt = str_replace("", "'", $excerpt);
268
+ }
269
+ $rest = trim(substr($excerpt, 0,150));
270
+ $gg_url = get_permalink();
271
+ $gg_title = get_the_title();
272
+ echo '<meta itemprop="name" content="'.$gg_title.'">';
273
+ echo '<meta itemprop="description" content="'.$rest.'">';
274
+ echo '<meta itemprop="image" content="'.$tc_image_thumb.'">';
275
+ }
276
+ }
277
+ }
278
 
279
 
280
  }
app/classes/import/class-rss-pi-engine.php CHANGED
@@ -7,747 +7,713 @@
7
  */
8
  class rssPIEngine {
9
 
10
- /**
11
- * Whether the API key is valid
12
- *
13
- * @var boolean
14
- */
15
- var $is_key_valid;
16
-
17
- /**
18
- * The options
19
- *
20
- * @var array
21
- */
22
- var $options = array();
23
-
24
- /**
25
- * Start the engine
26
- *
27
- * @global type $rss_post_importer
28
- */
29
- public function __construct() {
30
-
31
- global $rss_post_importer;
32
-
33
- $this->load_options();
34
- }
35
-
36
- /**
37
- * Start the engine
38
- *
39
- * @global type $rss_post_importer
40
- */
41
- public function load_options() {
42
-
43
- global $rss_post_importer;
44
- $this->options = $rss_post_importer->options;
45
- }
46
-
47
- /**
48
- * Import feeds
49
- *
50
- * @return int
51
- */
52
- public function import_feed() {
53
- global $rss_post_importer;
54
- $this->load_options();
55
- $post_count = 0;
56
- // filter cache lifetime
57
- add_filter('wp_feed_cache_transient_lifetime', array($this, 'frequency'));
58
-
59
- foreach ($this->options['feeds'] as $i => $f) {
60
-
61
- // before the first feed, we check for key validity
62
- if ( $i == 0 ) {
63
- $this->is_key_valid = $rss_post_importer->is_valid_key($this->options['settings']['feeds_api_key']);
64
- $this->options['settings']['is_key_valid'] = $this->is_key_valid;
65
- // if the key is not fine
66
- if (!empty($this->options['settings']['feeds_api_key']) && !$this->is_key_valid) {
67
- // unset from settings
68
- unset($this->options['settings']['feeds_api_key']);
69
- }
70
- // update options
71
- $new_options = array(
72
- 'feeds' => $this->options['feeds'],
73
- 'settings' => $this->options['settings'],
74
- 'latest_import' => $this->options['latest_import'],
75
- 'imports' => $this->options['imports'],
76
- 'upgraded' => $this->options['upgraded']
77
- );
78
- // update in db
79
- update_option('rss_pi_feeds', $new_options);
80
- }
81
-
82
- // prepare, import feed and count imported posts
83
- if ( $items = $this->do_import($f) ) {
84
- $post_count += count($items);
85
- }
86
- }
87
-
88
- // reformulate import count
89
- $imports = intval($this->options['imports']) + $post_count;
90
-
91
- // update options
92
- update_option('rss_pi_feeds', array(
93
- 'feeds' => $this->options['feeds'],
94
- 'settings' => $this->options['settings'],
95
- 'latest_import' => date("Y-m-d H:i:s"),
96
- 'imports' => $imports
97
- ));
98
-
99
- global $rss_post_importer;
100
- // reload options
101
- $rss_post_importer->load_options();
102
-
103
- remove_filter('wp_feed_cache_transient_lifetime', array($this, 'frequency'));
104
-
105
- // log this
106
- rssPILog::log($post_count);
107
-
108
- return $post_count;
109
- }
110
-
111
- /**
112
- * Dummy function for filtering because we can't use anon ones yet
113
- * @return string
114
- */
115
- public function frequency() {
116
-
117
- return $this->options['settings']['frequency'];
118
- }
119
-
120
- /**
121
- * Prepares arguments and imports
122
- *
123
- * @param array $f feed array
124
- * @return array
125
- */
126
- public function do_import($f) {
127
-
128
-
129
-
130
- $args = array(
131
- 'feed_title' => $f['name'],
132
- 'max_posts' => $f['max_posts'],
133
- 'author_id' => $f['author_id'],
134
- 'category_id' => $f['category_id'],
135
- 'tags_id' => $f['tags_id'],
136
- 'keywords' => isset($f['keywords']) && is_array($f['keywords']) ? $f['keywords'] : array(),
137
- 'strip_html' => $f['strip_html'],
138
- 'nofollow_outbound' => $f['nofollow_outbound'],
139
- 'automatic_import_categories' => $f['automatic_import_categories'],
140
- 'automatic_import_author' => $f['automatic_import_author'],
141
- 'feed_status' => $f['feed_status'],
142
- 'canonical_urls' => $f['canonical_urls'],
143
- 'save_to_db' => true
144
- );
145
- return $this->_import($f['url'], $args);
146
- }
147
-
148
- /**
149
- * Import feeds from url
150
- *
151
- * @param string $url The remote feed url
152
- * @param array $args Arguments for the import
153
- * @return null|array
154
- */
155
- private function _import($url = '', $args = array()) {
156
-
157
- if (empty($url)) {
158
- return;
159
- }
160
-
161
- $defaults = array(
162
- 'feed_title' => '',
163
- 'max_posts' => 5,
164
- 'author_id' => 1,
165
- 'category_id' => 0,
166
- 'tags_id' => array(),
167
- 'keywords' => array(),
168
- 'strip_html' => true,
169
- 'save_to_db' => true,
170
- 'nofollow_outbound' => true,
171
- 'automatic_import_categories' => true,
172
- 'automatic_import_author' => true,
173
- 'feed_status' => 'active',
174
- 'canonical_urls' => 'my_blog'
175
- );
176
-
177
- if($args['feed_status']=='pause'){
178
- return;
179
- }
180
-
181
- $args = wp_parse_args($args, $defaults);
182
-
183
- // include the default WP feed processing functions
184
- include_once( ABSPATH . WPINC . '/feed.php' );
185
-
186
- // get the right url for fetching (premium vs free)
187
- $url = $this->url($url);
188
-
189
- // fetch the feed
190
- $feed = fetch_feed($url);
191
-
192
-
193
- if (is_wp_error($feed)) {
194
- return false;
195
- }
196
-
197
- // save as posts
198
- $posts = $this->save($feed, $args);
199
-
200
- return $posts;
201
- }
202
-
203
- /**
204
- * Formulate the right url
205
- *
206
- * @param string $url
207
- * @return string
208
- */
209
- private function url($url) {
210
-
211
- $key = $this->options['settings']['feeds_api_key'];
212
-
213
- //if api key has been saved by user and is not empty
214
- if (isset($key) && !empty($key)) {
215
-
216
- // $api_url = 'http://176.58.108.28/fetch.php?key=' . $key . '&url=' . $url;
217
- $api_url = 'http://176.58.108.28/fetch.php?key=' . $key . '&url=' . urlencode($url);
218
-
219
- return $api_url;
220
- }
221
-
222
- return $url;
223
- }
224
-
225
- /**
226
- * Save the feed
227
- *
228
- * @param object $feed The feed object
229
- * @param array $args The arguments
230
- * @return boolean
231
- */
232
- private function save($feed, $args = array()) {
233
-
234
- // filter the feed and get feed items
235
- $feed_items = $this->filter($feed, $args);
236
-
237
- // if we are saving
238
- if ($args['save_to_db']) {
239
- // insert and return
240
-
241
- $saved_posts = $this->insert($feed_items, $args);
242
-
243
-
244
- return $saved_posts;
245
- }
246
-
247
- // otherwsie return the feed items
248
- return $feed_items;
249
- }
250
-
251
- /**
252
- * Filter the feed based on keywords
253
- *
254
- * @param object $feed The feed object
255
- * @param array $args Arguments
256
- * @return array
257
- */
258
- private function filter($feed, $args) {
259
-
260
- // the count of keyword matched items
261
-
262
- $got = 0;
263
-
264
- // the current index of the items aray
265
- $index = 0;
266
-
267
- $filtered = array();
268
-
269
- // till we have as many as the posts needed
270
- while ($got < $args['max_posts']) {
271
-
272
- // get only one item at the current index
273
- $feed_item = $feed->get_items($index, 1);
274
-
275
- // if this is empty, get out of the while
276
- if (empty($feed_item)) {
277
- break;
278
- }
279
- // else be in a forever loop
280
- // get the content
281
- $content = $feed_item[0]->get_content();
282
-
283
-
284
-
285
-
286
- // test it against the keywords
287
- $tested = $this->test($content,$args['keywords']);
288
-
289
- // if this is good for us
290
- if ($tested) {
291
- $got++;
292
-
293
- array_push($filtered, $feed_item[0]);
294
- }
295
- // shift the index
296
- $index++;
297
- }
298
-
299
- return $filtered;
300
- }
301
-
302
- /**
303
- * Test a piece of content against keywords
304
- *
305
- * @param string $content
306
- * @return boolean
307
- */
308
- function test($content,$keywords=null) {
309
-
310
- if ( ! $keywords ) {
311
- $keywords = $this->options['settings']['keywords'];
312
- }
313
-
314
- if ( empty($keywords) || ! is_array($keywords) ) {
315
- return true;
316
- }
317
-
318
- $match = false;
319
-
320
- // loop through keywords
321
- foreach ( $keywords as $keyword ) {
322
-
323
- // if the keyword is not a regex, make it one
324
- if ( ! $this->is_regex($keyword) ) {
325
- $keyword = '/' . $keyword . '/i';
326
- }
327
-
328
- // look for keyword in content
329
- preg_match($keyword, $content, $tested);
330
-
331
- // if it's there, we are good
332
- if ( ! empty($tested) ) {
333
- $match = true;
334
- // no need to test anymore
335
- break;
336
- }
337
- }
338
-
339
-
340
- return $match;
341
- }
342
-
343
- /**
344
- * Check if a string is regex
345
- *
346
- * @param string $str The string to check
347
- * @return boolean
348
- */
349
- private function is_regex($str) {
350
-
351
- // check regex with a regex!
352
- $regex = '/^\/[\s\S]+\/$/';
353
- preg_match($regex, $str, $matched);
354
- return !empty($matched);
355
- }
356
-
357
- /**
358
- * Insert feed items as posts
359
- *
360
- * @param array $items Fetched feed items
361
- * @param array $args arguments
362
- * @return array
363
- */
364
- private function insert($items, $args = array()) {
365
-
366
- $saved_posts = array();
367
-
368
- // Initialise the content parser
369
- $parser = new rssPIParser($this->options);
370
-
371
- // Featured Image setter
372
- $thumbnail = new rssPIFeaturedImage();
373
- // If Item is active then Import
374
-
375
- if($args['feed_status']=="active"){
376
-
377
- foreach ( $items as $item ) {
378
-
379
-
380
- if ( ! $this->post_exists($item) ) {
381
-
382
- /* Code to convert tags id array to tag name array * */
383
- if ( ! empty($args['tags_id']) ) {
384
- foreach ( $args['tags_id'] as $tagid ) {
385
- $tag_name = get_tag($tagid); // <-- your tag ID
386
- $tags_name[] = $tag_name->name;
387
- }
388
- } else {
389
- $tags_name = array();
390
- }
391
-
392
- // parse the content
393
- $content = $parser->_parse($item, $args['feed_title'], $args['strip_html']);
394
-
395
- //Filter content for /* Add rel="nofollow" to all outbounded links. */
396
- if($args['nofollow_outbound']=='true')
397
- {
398
- $content=$this->rss_pi_url_parse_content($content);
399
- }
400
-
401
- // Get auto categories from Feeds
402
- $post_category = array();
403
- if($args['automatic_import_categories']=='true') {
404
-
405
- $category_array = array();
406
- foreach ($item->get_categories() as $category){
407
- $cat_id = wp_create_category($category->get_label());
408
- if($cat_id > 0){
409
- $category_array[] = $cat_id;
410
- }else{
411
- $category = get_term_by('name', $category->get_label(), 'category');
412
- if($category){
413
- $category_array[] = $category->term_id;
414
- }
415
- }
416
- }
417
- $post_category = $category_array;
418
- }else
419
- {
420
- $post_category = array($args['category_id']);
421
- }
422
-
423
- // Get Author From Feed URl
424
- if($args['automatic_import_author']=='true') {
425
-
426
- if ($author = $item->get_author())
427
- {
428
- $array_author = explode(",",$author->get_name());
429
- $user_name = preg_replace('/[^A-Za-z0-9\-]/', ' ', $array_author[0]);
430
- $user_id = username_exists( $user_name );
431
- if ( !$user_id) :
432
- $random_password = wp_generate_password( $length=12, $include_standard_special_chars=false );
433
- $user_id = wp_create_user( $user_name, $random_password,'');
434
-
435
- endif;
436
-
437
- $post_author = $user_id;
438
-
439
- }else
440
- {
441
- $post_author = $args['author_id'];
442
- }
443
- }else
444
- {
445
- $post_author = $args['author_id'];
446
- }
447
-
448
- $post = array(
449
- 'post_title' => $item->get_title(),
450
- 'post_content' => $content,
451
- 'post_status' => $this->options['settings']['post_status'],
452
- 'post_author' => $post_author,
453
- 'post_category' => $post_category,
454
- 'tags_input' => $tags_name,
455
- 'comment_status' => $this->options['settings']['allow_comments'],
456
- 'post_date' => get_date_from_gmt($item->get_date('Y-m-d H:i:s'))
457
- );
458
-
459
-
460
-
461
- // catch base url and replace any img src with it
462
- if (preg_match('/src="\//ui', $content)) {
463
- preg_match('/href="(.+?)"/ui', $content, $matches);
464
- $baseref = (is_array($matches) && !empty($matches)) ? $matches[1] : '';
465
- if (!empty($baseref)) {
466
- $bc = parse_url($baseref);
467
- $scheme = (!isset($bc['scheme']) || empty($bc['scheme'])) ? 'http' : $bc['scheme'];
468
- $port = isset($bc['port']) ? $bc['port'] : '';
469
- $host = isset($bc['host']) ? $bc['host'] : '';
470
- if (!empty($host)) {
471
- $preurl = $scheme . ( $port ? ':' . $port : '' ) . '//' . $host;
472
- $post['post_content'] = preg_replace('/(src="\/)/i', 'src="' . $preurl . '/', $content);
473
- }
474
- }
475
- }
476
-
477
- //download images and save them locally if setting suggests so
478
- if ($this->options['settings']['import_images_locally'] == 'true') {
479
- $post = $this->download_images_locally($post);
480
- }
481
-
482
- // insert as post
483
-
484
-
485
-
486
- $post_id = $this->_insert($post, $item->get_permalink());
487
-
488
- // set thumbnail
489
- if ( $this->options['settings']['disable_thumbnail'] == 'false' ) {
490
- // assign a thumbnail (featured image) to the post
491
- $thumbnail->_set($item, $post_id);
492
- $attachment_id = get_post_thumbnail_id($post_id);
493
- } else {
494
- // just download the image to the media library
495
- $attachment_id = $thumbnail->_prepare($item, $post_id);
496
- }
497
-
498
- /* Parse {$inline_image} template tag
499
- * @since 2.1.3
500
- */
501
- if ( preg_match('/\{\$inline_image\}/i', $post['post_content']) ) {
502
- $_post_content = $post['post_content'];
503
- if ( $attachment_id ) {
504
- // $featured_image = wp_get_attachment_image($attachment_id);
505
- $featured_image = wp_get_attachment_image_src($attachment_id,'full');
506
- $featured_image = '<img src="'.$featured_image[0].'" width="'.$featured_image[1].'" height="'.$featured_image[2].'">';
507
- } else {
508
- $featured_image = '';
509
- }
510
- $_post_content = preg_replace('/\{\$inline_image\}/i', $featured_image, $_post_content);
511
- $_post = array(
512
- 'ID' => $post_id,
513
- 'post_content' => $_post_content
514
- );
515
- wp_update_post($_post);
516
- $post['post_content'] = $_post_content;
517
- }
518
- // canonical_urls
519
- update_post_meta($post_id, 'rss_pi_canonical_url',$args['canonical_urls']);
520
- array_push($saved_posts, $post);
521
- }
522
- }
523
- }
524
-
525
- return $saved_posts;
526
- }
527
-
528
- /**
529
- * Check if a feed ite is alreday imported
530
- *
531
- * @param string $permalink
532
- * @return boolean
533
- */
534
- private function post_exists($item) {
535
- global $wpdb;
536
-
537
- $permalink = $item->get_permalink();
538
- // calculate md5 hash
539
- $permalink_md5 = md5($permalink);
540
- // strip any params from the URL
541
- $permalink_new = $permalink;
542
- $permalink_new = explode('?',$permalink_new);
543
-
544
- $permalink_new = $permalink_new[0];
545
- // calculate new md5 hash
546
- $permalink_md5_new = md5($permalink_new);
547
- $post_exists = FALSE;
548
-
549
- if ( isset($this->options['upgraded']['deleted_posts']) ) { // database migrated
550
- // check if there is post with this source URL that is not trashed
551
- // $posts = $wpdb->get_results( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->postmeta} WHERE meta_key = 'rss_pi_source_md5' and meta_value = %s", $permalink_md5 ), 'ARRAY_A');
552
- $posts = $wpdb->get_results( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->postmeta} pm, {$wpdb->posts} p WHERE pm.meta_key = 'rss_pi_source_md5' AND ( pm.meta_value = %s) AND pm.post_id = p.ID AND p.post_status <> 'trash'", $permalink_md5), 'ARRAY_A');
553
- //echo $wpdb->last_query;
554
- if ( count($posts) ) {
555
- $post_exists = TRUE;
556
- }
557
- }
558
- // } else {
559
- if ( ! $post_exists ) {
560
- // do it the old fashion way -> check for post title and source domain
561
- $title = $item->get_title();
562
- $domain_old = $this->get_domain($permalink);
563
-
564
- //checking if post title already exists
565
- if ($posts = $wpdb->get_results("SELECT ID FROM " . $wpdb->prefix . "posts WHERE post_title = '" . $title . "' and post_status = 'publish' ", 'ARRAY_A')) {
566
- //checking if post source is also same
567
- foreach ($posts as $post) {
568
- $post_id = $post['ID'];
569
- $source_url = get_post_meta($post_id, 'rss_pi_source_url', true);
570
- $domain_new = $this->get_domain($source_url);
571
-
572
- if ($domain_new == $domain_old) {
573
- $post_exists = TRUE;
574
- }
575
- }
576
- }
577
- }
578
-
579
- if ( ! $post_exists && $this->options['settings']['cache_deleted'] == 'true' ) {
580
-
581
- // check if the post has been imported and then deleted
582
- if ( $this->options['upgraded']['deleted_posts'] ) { // database migrated
583
- $rss_pi_deleted_posts = get_option( 'rss_pi_deleted_posts', array() );
584
- if ( in_array( $permalink_md5, $rss_pi_deleted_posts )) {
585
- $post_exists = TRUE;
586
- }
587
- } else {
588
- //do it the old fashion way
589
- $rss_pi_imported_posts = get_option( 'rss_pi_imported_posts', array() );
590
- if ( in_array( $permalink, $rss_pi_imported_posts ) ) {
591
- $post_exists = TRUE;
592
- }
593
- }
594
- }
595
  /* if($post_exists==true){
596
-
597
- echo "1";
598
- }else{
599
- echo "0";
600
- }*/
601
- return $post_exists;
602
- }
603
-
604
- // deprecated as of 2.1.2
605
- private function get_domain($url) {
606
-
607
- $pieces = parse_url($url);
608
- $domain = isset($pieces['host']) ? $pieces['host'] : '';
609
- if (preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) {
610
- return $regs['domain'];
611
- }
612
- return false;
613
- }
614
-
615
- /**
616
- * Insert feed item as post
617
- *
618
- * @param array $post Post array
619
- * @param string $url source url meta
620
- * @return int
621
- */
622
- private function _insert($post, $url) {
623
-
624
- if ($post['post_category'][0] == "") {
625
- $post['post_category'] = array(1);
626
- } else {
627
- if (is_array($post['post_category'][0]))
628
- $post['post_category'] = array_values($post['post_category'][0]);
629
- else
630
- $post['post_category'] = array_values($post['post_category']);
631
- }
632
-
633
- $_post = apply_filters('pre_rss_pi_insert_post', $post);
634
-
635
- $post_id = wp_insert_post($_post);
636
-
637
- add_action('save_rss_pi_post', $post_id);
638
-
639
- // $url_md5 = md5($url);
640
- // strip any params from the URL
641
- $url_new = $url;
642
- $url_new = explode('?',$url_new);
643
- $url_new = $url_new[0];
644
- // calculate new md5 hash
645
- $url_md5 = md5($url_new);
646
- update_post_meta($post_id, 'rss_pi_source_url', esc_url($url));
647
- update_post_meta($post_id, 'rss_pi_source_md5', $url_md5);
648
-
649
- return $post_id;
650
- }
651
-
652
- public function pre($arr) {
653
-
654
- echo '<pre>';
655
- print_r($arr);
656
- echo '</pre>';
657
- }
658
-
659
- function download_images_locally($post) {
660
-
661
- $post_content = $post['post_content'];
662
- // initializing DOMDocument to modify the img source
663
- $dom = new DOMDocument;
664
- libxml_use_internal_errors(true);
665
- $dom->loadHTML('<?xml encoding="utf-8" ?>' . $post_content);
666
- $xpath = new DOMXPath($dom);
667
- libxml_clear_errors();
668
- //get all the src attribs and their values
669
- $doc = $dom->getElementsByTagName('html')->item(0);
670
- $src = $xpath->query('.//@src');
671
- $count = 1;
672
- foreach ($src as $s) {
673
- $url = trim($s->nodeValue);
674
- $attachment_id = $this->add_to_media($url, 0, $post['post_title'] . '-media-' . $count);
675
- $src = wp_get_attachment_url($attachment_id);
676
- $s->nodeValue = $src;
677
- $count++;
678
- }
679
- $post['post_content'] = $dom->saveXML($doc);
680
- return $post;
681
- }
682
-
683
- function add_to_media($url, $associated_with_post, $desc) {
684
- $tmp = @download_url($url);
685
- if (is_wp_error($tmp)) {
686
- return false;
687
- }
688
- $post_id = $associated_with_post;
689
- $desc = $desc;
690
- $file_array = array();
691
- // Set variables for storage
692
- // fix file filename for query strings
693
- if ( ! preg_match('/[^\?]+\.(jpg|jpe|jpeg|gif|png)/i', $url, $matches) ) {
694
- return false;
695
- }
696
- $file_array['name'] = basename($matches[0]);
697
- $file_array['tmp_name'] = $tmp;
698
- // If error storing temporarily, unlink
699
- if (is_wp_error($tmp)) {
700
- @unlink($file_array['tmp_name']);
701
- return false;
702
- }
703
- // do the validation and storage stuff
704
- $id = media_handle_sideload($file_array, $post_id, $desc);
705
- // If error storing permanently, unlink
706
- if (is_wp_error($id)) {
707
- @unlink($file_array['tmp_name']);
708
- return false;
709
- }
710
-
711
- return $id;
712
- }
713
-
714
- function rss_pi_url_parse_content($content) {
715
-
716
- $regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>";
717
- if (preg_match_all("/$regexp/siU", $content, $matches, PREG_SET_ORDER)) {
718
- if (!empty($matches)) {
719
-
720
- $srcUrl = get_option('home');
721
- for ($i = 0; $i < count($matches); $i++) {
722
-
723
- $tag = $matches[$i][0];
724
- $tag2 = $matches[$i][0];
725
- $url = $matches[$i][0];
726
-
727
- $noFollow = '';
728
-
729
- $pattern = '/target\s*=\s*"\s*_blank\s*"/';
730
- preg_match($pattern, $tag2, $match, PREG_OFFSET_CAPTURE);
731
- if (count($match) < 1)
732
- $noFollow .= ' target="_blank" ';
733
-
734
- $pattern = '/rel\s*=\s*"\s*[n|d]ofollow\s*"/';
735
- preg_match($pattern, $tag2, $match, PREG_OFFSET_CAPTURE);
736
- if (count($match) < 1)
737
- $noFollow .= ' rel="nofollow" ';
738
-
739
- $pos = strpos($url, $srcUrl);
740
- if ($pos === false) {
741
- $tag = rtrim($tag, '>');
742
- $tag .= $noFollow . '>';
743
- $content = str_replace($tag2, $tag, $content);
744
- }
745
- }
746
- }
747
- }
748
-
749
- $content = str_replace(']]>', ']]&gt;', $content);
750
- return $content;
751
- }
752
 
753
  }
7
  */
8
  class rssPIEngine {
9
 
10
+ /**
11
+ * Whether the API key is valid
12
+ *
13
+ * @var boolean
14
+ */
15
+ var $is_key_valid;
16
+
17
+ /**
18
+ * The options
19
+ *
20
+ * @var array
21
+ */
22
+ var $options = array();
23
+
24
+ /**
25
+ * Start the engine
26
+ *
27
+ * @global type $rss_post_importer
28
+ */
29
+ public function __construct() {
30
+
31
+ global $rss_post_importer;
32
+
33
+ $this->load_options();
34
+ }
35
+
36
+ /**
37
+ * Start the engine
38
+ *
39
+ * @global type $rss_post_importer
40
+ */
41
+ public function load_options() {
42
+
43
+ global $rss_post_importer;
44
+ $this->options = $rss_post_importer->options;
45
+ }
46
+
47
+ /**
48
+ * Import feeds
49
+ *
50
+ * @return int
51
+ */
52
+ public function import_feed() {
53
+ global $rss_post_importer;
54
+ $this->load_options();
55
+ $post_count = 0;
56
+ // filter cache lifetime
57
+ add_filter('wp_feed_cache_transient_lifetime', array($this, 'frequency'));
58
+
59
+ foreach ($this->options['feeds'] as $i => $f) {
60
+
61
+ // before the first feed, we check for key validity
62
+ if ( $i == 0 ) {
63
+ $this->is_key_valid = $rss_post_importer->is_valid_key($this->options['settings']['feeds_api_key']);
64
+ $this->options['settings']['is_key_valid'] = $this->is_key_valid;
65
+ // if the key is not fine
66
+ if (!empty($this->options['settings']['feeds_api_key']) && !$this->is_key_valid) {
67
+ // unset from settings
68
+ unset($this->options['settings']['feeds_api_key']);
69
+ }
70
+ // update options
71
+ $new_options = array(
72
+ 'feeds' => $this->options['feeds'],
73
+ 'settings' => $this->options['settings'],
74
+ 'latest_import' => $this->options['latest_import'],
75
+ 'imports' => $this->options['imports'],
76
+ 'upgraded' => $this->options['upgraded']
77
+ );
78
+ // update in db
79
+ update_option('rss_pi_feeds', $new_options);
80
+ }
81
+
82
+ // prepare, import feed and count imported posts
83
+ if ( $items = $this->do_import($f) ) {
84
+ $post_count += count($items);
85
+ }
86
+ }
87
+
88
+ // reformulate import count
89
+ $imports = intval($this->options['imports']) + $post_count;
90
+
91
+ // update options
92
+ update_option('rss_pi_feeds', array(
93
+ 'feeds' => $this->options['feeds'],
94
+ 'settings' => $this->options['settings'],
95
+ 'latest_import' => date("Y-m-d H:i:s"),
96
+ 'imports' => $imports
97
+ ));
98
+
99
+ global $rss_post_importer;
100
+ // reload options
101
+ $rss_post_importer->load_options();
102
+
103
+ remove_filter('wp_feed_cache_transient_lifetime', array($this, 'frequency'));
104
+
105
+ // log this
106
+ rssPILog::log($post_count);
107
+
108
+ return $post_count;
109
+ }
110
+
111
+ /**
112
+ * Dummy function for filtering because we can't use anon ones yet
113
+ * @return string
114
+ */
115
+ public function frequency() {
116
+
117
+ return $this->options['settings']['frequency'];
118
+ }
119
+
120
+ /**
121
+ * Prepares arguments and imports
122
+ *
123
+ * @param array $f feed array
124
+ * @return array
125
+ */
126
+ public function do_import($f) {
127
+ $args = array(
128
+ 'feed_title' => $f['name'],
129
+ 'max_posts' => $f['max_posts'],
130
+ 'author_id' => $f['author_id'],
131
+ 'category_id' => $f['category_id'],
132
+ 'tags_id' => $f['tags_id'],
133
+ 'keywords' => isset($f['keywords']) && is_array($f['keywords']) ? $f['keywords'] : array(),
134
+ 'strip_html' => $f['strip_html'],
135
+ 'nofollow_outbound' => $f['nofollow_outbound'],
136
+ 'automatic_import_categories' => $f['automatic_import_categories'],
137
+ 'automatic_import_author' => $f['automatic_import_author'],
138
+ 'feed_status' => $f['feed_status'],
139
+ 'canonical_urls' => $f['canonical_urls'],
140
+ 'save_to_db' => true
141
+ );
142
+
143
+ return $this->_import($f['url'], $args);
144
+ }
145
+
146
+ /**
147
+ * Import feeds from url
148
+ *
149
+ * @param string $url The remote feed url
150
+ * @param array $args Arguments for the import
151
+ * @return null|array
152
+ */
153
+ private function _import($url='', $args=array()) {
154
+
155
+ if (empty($url)) return;
156
+
157
+ if($args['feed_status'] == 'pause') return;
158
+
159
+ $defaults = array(
160
+ 'feed_title' => '',
161
+ 'max_posts' => 5,
162
+ 'author_id' => 1,
163
+ 'category_id' => 0,
164
+ 'tags_id' => array(),
165
+ 'keywords' => array(),
166
+ 'strip_html' => true,
167
+ 'save_to_db' => true,
168
+ 'nofollow_outbound' => true,
169
+ 'automatic_import_categories' => true,
170
+ 'automatic_import_author' => true,
171
+ 'feed_status' => 'active',
172
+ 'canonical_urls' => 'my_blog'
173
+ );
174
+
175
+ $args = wp_parse_args($args, $defaults);
176
+
177
+ // include the default WP feed processing functions
178
+ include_once( ABSPATH . WPINC . '/feed.php' );
179
+
180
+ // get the right url for fetching (premium vs free)
181
+ $url = $this->url($url);
182
+
183
+ // fetch the feed
184
+ $feed = fetch_feed($url);
185
+
186
+
187
+ if (is_wp_error($feed)) {
188
+ return false;
189
+ }
190
+
191
+ // save as posts
192
+ $posts = $this->save($feed, $args);
193
+
194
+ return $posts;
195
+ }
196
+
197
+ /**
198
+ * Formulate the right url
199
+ *
200
+ * @param string $url
201
+ * @return string
202
+ */
203
+ private function url($url) {
204
+
205
+ $key = $this->options['settings']['feeds_api_key'];
206
+
207
+ //if api key has been saved by user and is not empty
208
+ if (isset($key) && !empty($key)) {
209
+ //$api_url = 'http://176.58.108.28/fetch.php?key=' . $key . '&url=' . $url;
210
+ $api_url = 'http://176.58.108.28/fetch.php?key=' . $key . '&url=' . urlencode($url);
211
+
212
+ return $api_url;
213
+ }
214
+
215
+ return $url;
216
+ }
217
+
218
+ /**
219
+ * Save the feed
220
+ *
221
+ * @param object $feed The feed object
222
+ * @param array $args The arguments
223
+ * @return boolean
224
+ */
225
+ private function save($feed, $args=array()) {
226
+
227
+ // filter the feed and get feed items
228
+ $feed_items = $this->filter($feed, $args);
229
+
230
+ // if we are saving
231
+ if ($args['save_to_db']) {
232
+ // insert and return
233
+ $saved_posts = $this->insert($feed_items, $args);
234
+
235
+ return $saved_posts;
236
+ }
237
+
238
+ // otherwsie return the feed items
239
+ return $feed_items;
240
+ }
241
+
242
+ /**
243
+ * Filter the feed based on keywords
244
+ *
245
+ * @param object $feed The feed object
246
+ * @param array $args Arguments
247
+ * @return array
248
+ */
249
+ private function filter($feed, $args) {
250
+ // the count of keyword matched items
251
+ $got = 0;
252
+
253
+ // the current index of the items aray
254
+ $index = 0;
255
+
256
+ $filtered = array();
257
+
258
+ // till we have as many as the posts needed
259
+ while ($got < $args['max_posts']) {
260
+ // get only one item at the current index
261
+ $feed_item = $feed->get_items($index, 1);
262
+
263
+ // if this is empty, get out of the while
264
+ if (empty($feed_item)) {
265
+ break;
266
+ }
267
+ // else be in a forever loop
268
+ // get the content
269
+ $content = $feed_item[0]->get_content();
270
+
271
+ // test it against the keywords
272
+ $tested = $this->test($content,$args['keywords']);
273
+
274
+ // if this is good for us
275
+ if ($tested) {
276
+ $got++;
277
+
278
+ array_push($filtered, $feed_item[0]);
279
+ }
280
+ // shift the index
281
+ $index++;
282
+ }
283
+
284
+ return $filtered;
285
+ }
286
+
287
+ /**
288
+ * Test a piece of content against keywords
289
+ *
290
+ * @param string $content
291
+ * @return boolean
292
+ */
293
+ function test($content,$keywords=null) {
294
+ if ( ! $keywords ) {
295
+ $keywords = $this->options['settings']['keywords'];
296
+ }
297
+
298
+ if ( empty($keywords) || ! is_array($keywords) ) {
299
+ return true;
300
+ }
301
+
302
+ $match = false;
303
+
304
+ // loop through keywords
305
+ foreach ( $keywords as $keyword ) {
306
+ // if the keyword is not a regex, make it one
307
+ if ( ! $this->is_regex($keyword) ) {
308
+ $keyword = '/' . $keyword . '/i';
309
+ }
310
+
311
+ // look for keyword in content
312
+ preg_match($keyword, $content, $tested);
313
+
314
+ // if it's there, we are good
315
+ if ( ! empty($tested) ) {
316
+ $match = true;
317
+ // no need to test anymore
318
+ break;
319
+ }
320
+ }
321
+
322
+ return $match;
323
+ }
324
+
325
+ /**
326
+ * Check if a string is regex
327
+ *
328
+ * @param string $str The string to check
329
+ * @return boolean
330
+ */
331
+ private function is_regex($str) {
332
+
333
+ // check regex with a regex!
334
+ $regex = '/^\/[\s\S]+\/$/';
335
+ preg_match($regex, $str, $matched);
336
+ return !empty($matched);
337
+ }
338
+
339
+ /**
340
+ * Insert feed items as posts
341
+ *
342
+ * @param array $items Fetched feed items
343
+ * @param array $args arguments
344
+ * @return array
345
+ */
346
+ private function insert($items, $args = array()) {
347
+ $saved_posts = array();
348
+
349
+ // Initialise the content parser
350
+ $parser = new rssPIParser($this->options);
351
+
352
+ // Featured Image setter
353
+ $thumbnail = new rssPIFeaturedImage();
354
+
355
+ // If Item is active then Import
356
+ if($args['feed_status'] == "active") {
357
+
358
+ foreach ( $items as $item ) {
359
+
360
+ if ( ! $this->post_exists($item) ) {
361
+
362
+ /* Code to convert tags id array to tag name array * */
363
+ if ( ! empty($args['tags_id']) ) {
364
+ foreach ( $args['tags_id'] as $tagid ) {
365
+ $tag_name = get_tag($tagid); // <-- your tag ID
366
+ $tags_name[] = $tag_name->name;
367
+ }
368
+ } else {
369
+ $tags_name = array();
370
+ }
371
+
372
+ // parse the content
373
+ $content = $parser->_parse($item, $args['feed_title'], $args['strip_html']);
374
+
375
+ //Filter content for /* Add rel="nofollow" to all outbounded links. */
376
+ if($args['nofollow_outbound']=='true') {
377
+ $content=$this->rss_pi_url_parse_content($content);
378
+ }
379
+
380
+ // Get auto categories from Feeds
381
+ $post_category = array();
382
+ if($args['automatic_import_categories']=='true') {
383
+ $category_array = array();
384
+ foreach ($item->get_categories() as $category) {
385
+ $cat_id = wp_create_category($category->get_label());
386
+ if ($cat_id > 0) {
387
+ $category_array[] = $cat_id;
388
+ } else {
389
+ $category = get_term_by('name', $category->get_label(), 'category');
390
+ if ($category) {
391
+ $category_array[] = $category->term_id;
392
+ }
393
+ }
394
+ }
395
+ $post_category = $category_array;
396
+ } else {
397
+ $post_category = array($args['category_id']);
398
+ }
399
+
400
+ // Get Author From Feed URl
401
+ if($args['automatic_import_author']=='true') {
402
+ if ($author = $item->get_author()) {
403
+ $array_author = explode(",",$author->get_name());
404
+ $user_name = preg_replace('/[^A-Za-z0-9\-]/', ' ', $array_author[0]);
405
+ $user_id = username_exists( $user_name );
406
+ if (! $user_id) {
407
+ $random_password = wp_generate_password( $length=12, $include_standard_special_chars=false );
408
+ $user_id = wp_create_user( $user_name, $random_password,'');
409
+ }
410
+ $post_author = $user_id;
411
+
412
+ } else {
413
+ $post_author = $args['author_id'];
414
+ }
415
+ } else {
416
+ $post_author = $args['author_id'];
417
+ }
418
+
419
+ $post = array(
420
+ 'post_title' => $item->get_title(),
421
+ 'post_content' => $content,
422
+ 'post_status' => $this->options['settings']['post_status'],
423
+ 'post_author' => $post_author,
424
+ 'post_category' => $post_category,
425
+ 'tags_input' => $tags_name,
426
+ 'comment_status' => $this->options['settings']['allow_comments'],
427
+ 'post_date' => get_date_from_gmt($item->get_date('Y-m-d H:i:s'))
428
+ );
429
+
430
+ // catch base url and replace any img src with it
431
+ if (preg_match('/src="\//ui', $content)) {
432
+ preg_match('/href="(.+?)"/ui', $content, $matches);
433
+ $baseref = (is_array($matches) && !empty($matches)) ? $matches[1] : '';
434
+ if (!empty($baseref)) {
435
+ $bc = parse_url($baseref);
436
+ $scheme = (!isset($bc['scheme']) || empty($bc['scheme'])) ? 'http' : $bc['scheme'];
437
+ $port = isset($bc['port']) ? $bc['port'] : '';
438
+ $host = isset($bc['host']) ? $bc['host'] : '';
439
+ if (!empty($host)) {
440
+ $preurl = $scheme . ( $port ? ':' . $port : '' ) . '//' . $host;
441
+ $post['post_content'] = preg_replace('/(src="\/)/i', 'src="' . $preurl . '/', $content);
442
+ }
443
+ }
444
+ }
445
+
446
+ //download images and save them locally if setting suggests so
447
+ if ($this->options['settings']['import_images_locally'] == 'true') {
448
+ $post = $this->download_images_locally($post);
449
+ }
450
+
451
+ // insert as post
452
+ $post_id = $this->_insert($post, $item->get_permalink());
453
+
454
+ // set thumbnail
455
+ if ( $this->options['settings']['disable_thumbnail'] == 'false' ) {
456
+ // assign a thumbnail (featured image) to the post
457
+ $thumbnail->_set($item, $post_id);
458
+ $attachment_id = get_post_thumbnail_id($post_id);
459
+ } else {
460
+ // just download the image to the media library
461
+ $attachment_id = $thumbnail->_prepare($item, $post_id);
462
+ }
463
+
464
+ /* Parse {$inline_image} template tag
465
+ * @since 2.1.3
466
+ */
467
+ if ( preg_match('/\{\$inline_image\}/i', $post['post_content']) ) {
468
+ $_post_content = $post['post_content'];
469
+ if ( $attachment_id ) {
470
+ //$featured_image = wp_get_attachment_image($attachment_id);
471
+ $featured_image = wp_get_attachment_image_src($attachment_id, 'full');
472
+ $featured_image = '<img src="' . $featured_image[0] . '" width="' . $featured_image[1] . '" height="' . $featured_image[2] . '">';
473
+ } else {
474
+ $featured_image = '';
475
+ }
476
+ $_post_content = preg_replace('/\{\$inline_image\}/i', $featured_image, $_post_content);
477
+ $_post = array(
478
+ 'ID' => $post_id,
479
+ 'post_content' => $_post_content
480
+ );
481
+
482
+ wp_update_post($_post);
483
+
484
+ $post['post_content'] = $_post_content;
485
+ }
486
+ // canonical_urls
487
+ update_post_meta($post_id, 'rss_pi_canonical_url',$args['canonical_urls']);
488
+ array_push($saved_posts, $post);
489
+ }
490
+ }
491
+ }
492
+
493
+ return $saved_posts;
494
+ }
495
+
496
+ /**
497
+ * Check if a feed item is alreday imported
498
+ *
499
+ * @param string $permalink
500
+ * @return boolean
501
+ */
502
+ private function post_exists($item) {
503
+ global $wpdb;
504
+
505
+ $permalink = $item->get_permalink();
506
+ // calculate md5 hash
507
+ $permalink_md5 = md5($permalink);
508
+ // strip any params from the URL
509
+ $permalink_new = $permalink;
510
+ $permalink_new = explode('?', $permalink_new);
511
+
512
+ $permalink_new = $permalink_new[0];
513
+ // calculate new md5 hash
514
+ $permalink_md5_new = md5($permalink_new);
515
+ $post_exists = FALSE;
516
+
517
+ if ( isset($this->options['upgraded']['deleted_posts']) ) { // database migrated
518
+ // check if there is post with this source URL that is not trashed
519
+ //$posts = $wpdb->get_results( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->postmeta} WHERE meta_key = 'rss_pi_source_md5' and meta_value = %s", $permalink_md5 ), 'ARRAY_A');
520
+ $posts = $wpdb->get_results( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->postmeta} pm, {$wpdb->posts} p WHERE pm.meta_key = 'rss_pi_source_md5' AND ( pm.meta_value = %s) AND pm.post_id = p.ID AND p.post_status <> 'trash'", $permalink_md5), 'ARRAY_A');
521
+ //echo $wpdb->last_query;
522
+ if ( count($posts) ) {
523
+ $post_exists = TRUE;
524
+ }
525
+ }
526
+ // } else {
527
+ if ( ! $post_exists ) {
528
+ // do it the old fashion way -> check for post title and source domain
529
+ $title = $item->get_title();
530
+ $domain_old = $this->get_domain($permalink);
531
+
532
+ //checking if post title already exists
533
+ if ($posts = $wpdb->get_results("SELECT ID FROM " . $wpdb->prefix . "posts WHERE post_title = '" . $title . "' and post_status = 'publish' ", 'ARRAY_A')) {
534
+ //checking if post source is also same
535
+ foreach ($posts as $post) {
536
+ $post_id = $post['ID'];
537
+ $source_url = get_post_meta($post_id, 'rss_pi_source_url', true);
538
+ $domain_new = $this->get_domain($source_url);
539
+
540
+ if ($domain_new == $domain_old) {
541
+ $post_exists = TRUE;
542
+ }
543
+ }
544
+ }
545
+ }
546
+
547
+ if ( ! $post_exists && $this->options['settings']['cache_deleted'] == 'true' ) {
548
+ // check if the post has been imported and then deleted
549
+ if ( $this->options['upgraded']['deleted_posts'] ) { // database migrated
550
+ $rss_pi_deleted_posts = get_option( 'rss_pi_deleted_posts', array() );
551
+ if ( in_array( $permalink_md5, $rss_pi_deleted_posts )) {
552
+ $post_exists = TRUE;
553
+ }
554
+ } else {
555
+ //do it the old fashion way
556
+ $rss_pi_imported_posts = get_option( 'rss_pi_imported_posts', array() );
557
+ if ( in_array( $permalink, $rss_pi_imported_posts ) ) {
558
+ $post_exists = TRUE;
559
+ }
560
+ }
561
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
562
  /* if($post_exists==true){
563
+
564
+ echo "1";
565
+ }else{
566
+ echo "0";
567
+ }*/
568
+ return $post_exists;
569
+ }
570
+
571
+ // deprecated as of 2.1.2
572
+ // TODO: Remove
573
+ private function get_domain($url) {
574
+ $pieces = parse_url($url);
575
+ $domain = isset($pieces['host']) ? $pieces['host'] : '';
576
+ if (preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) {
577
+ return $regs['domain'];
578
+ }
579
+ return false;
580
+ }
581
+
582
+ /**
583
+ * Insert feed item as post
584
+ *
585
+ * @param array $post Post array
586
+ * @param string $url source url meta
587
+ * @return int
588
+ */
589
+ private function _insert($post, $url) {
590
+
591
+ if ($post['post_category'][0] == "") {
592
+ $post['post_category'] = array(1);
593
+ } else {
594
+ if (is_array($post['post_category'][0])) {
595
+ $post['post_category'] = array_values($post['post_category'][0]);
596
+ } else {
597
+ $post['post_category'] = array_values($post['post_category']);
598
+ }
599
+ }
600
+
601
+ $_post = apply_filters('pre_rss_pi_insert_post', $post);
602
+
603
+ $post_id = wp_insert_post($_post);
604
+
605
+ add_action('save_rss_pi_post', $post_id);
606
+
607
+ //$url_md5 = md5($url);
608
+ // strip any params from the URL
609
+ //$url_new = $url;
610
+ //$url_new = explode('?', $url_new);
611
+ //$url_new = $post_id . $url_new[0] . $post_id;
612
+ // calculate new md5 hash
613
+ $url_md5 = md5($url);
614
+ update_post_meta($post_id, 'rss_pi_source_url', esc_url($url));
615
+ update_post_meta($post_id, 'rss_pi_source_md5', $url_md5);
616
+
617
+ return $post_id;
618
+ }
619
+
620
+ public function pre($arr) {
621
+
622
+ echo '<pre>';
623
+ print_r($arr);
624
+ echo '</pre>';
625
+ }
626
+
627
+ function download_images_locally($post) {
628
+ $post_content = $post['post_content'];
629
+ // initializing DOMDocument to modify the img source
630
+ $dom = new DOMDocument;
631
+ libxml_use_internal_errors(true);
632
+ $dom->loadHTML('<?xml encoding="utf-8" ?>' . $post_content);
633
+ $xpath = new DOMXPath($dom);
634
+ libxml_clear_errors();
635
+ //get all the src attribs and their values
636
+ $doc = $dom->getElementsByTagName('html')->item(0);
637
+ $src = $xpath->query('.//@src');
638
+ $count = 1;
639
+ foreach ($src as $s) {
640
+ $url = trim($s->nodeValue);
641
+ $attachment_id = $this->add_to_media($url, 0, $post['post_title'] . '-media-' . $count);
642
+ $src = wp_get_attachment_url($attachment_id);
643
+ $s->nodeValue = $src;
644
+ $count++;
645
+ }
646
+ $post['post_content'] = $dom->saveXML($doc);
647
+ return $post;
648
+ }
649
+
650
+ function add_to_media($url, $associated_with_post, $desc) {
651
+ $tmp = @download_url($url);
652
+ if (is_wp_error($tmp)) {
653
+ return false;
654
+ }
655
+ $post_id = $associated_with_post;
656
+ $desc = $desc;
657
+ $file_array = array();
658
+ // Set variables for storage
659
+ // fix file filename for query strings
660
+ if ( ! preg_match('/[^\?]+\.(jpg|jpe|jpeg|gif|png)/i', $url, $matches) ) {
661
+ return false;
662
+ }
663
+ $file_array['name'] = basename($matches[0]);
664
+ $file_array['tmp_name'] = $tmp;
665
+ // If error storing temporarily, unlink
666
+ if (is_wp_error($tmp)) {
667
+ @unlink($file_array['tmp_name']);
668
+ return false;
669
+ }
670
+ // do the validation and storage stuff
671
+ $id = media_handle_sideload($file_array, $post_id, $desc);
672
+ // If error storing permanently, unlink
673
+ if (is_wp_error($id)) {
674
+ @unlink($file_array['tmp_name']);
675
+ return false;
676
+ }
677
+
678
+ return $id;
679
+ }
680
+
681
+ function rss_pi_url_parse_content($content) {
682
+ $regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>";
683
+ if (preg_match_all("/$regexp/siU", $content, $matches, PREG_SET_ORDER)) {
684
+ if (!empty($matches)) {
685
+
686
+ $srcUrl = get_option('home');
687
+ for ($i = 0; $i < count($matches); $i++) {
688
+
689
+ $tag = $matches[$i][0];
690
+ $tag2 = $matches[$i][0];
691
+ $url = $matches[$i][0];
692
+
693
+ $noFollow = '';
694
+
695
+ $pattern = '/target\s*=\s*"\s*_blank\s*"/';
696
+ preg_match($pattern, $tag2, $match, PREG_OFFSET_CAPTURE);
697
+ if (count($match) < 1)
698
+ $noFollow .= ' target="_blank" ';
699
+
700
+ $pattern = '/rel\s*=\s*"\s*[n|d]ofollow\s*"/';
701
+ preg_match($pattern, $tag2, $match, PREG_OFFSET_CAPTURE);
702
+ if (count($match) < 1)
703
+ $noFollow .= ' rel="nofollow" ';
704
+
705
+ $pos = strpos($url, $srcUrl);
706
+ if ($pos === false) {
707
+ $tag = rtrim($tag, '>');
708
+ $tag .= $noFollow . '>';
709
+ $content = str_replace($tag2, $tag, $content);
710
+ }
711
+ }
712
+ }
713
+ }
714
+
715
+ $content = str_replace(']]>', ']]&gt;', $content);
716
+ return $content;
717
+ }
 
718
 
719
  }
app/templates/feed-table-row.php CHANGED
@@ -1,9 +1,16 @@
1
  <?php
2
- $show = '';
3
 
 
 
 
 
 
 
 
 
4
  if (!isset($f)) {
5
  $f = array(
6
- 'id' => 0,
7
  'name' => 'New feed',
8
  'url' => '',
9
  'max_posts' => 5,
@@ -57,25 +64,40 @@ if (is_array($f['category_id'])) {
57
 
58
  ?>
59
 
 
 
 
60
  <tr id="display_<?php echo ($f['id']); ?>" class="data-row<?php echo $show; ?>" data-fields="name,url,max_posts">
61
  <td class="rss_pi-feed_name">
62
  <strong><a href="#" class="toggle-edit" data-target="<?php echo ($f['id']); ?>"><span class="field-name"><?php echo esc_html(stripslashes($f['name'])); ?></span></a></strong>
63
  <div class="row-options">
64
- <a href="#" class="toggle-edit" data-target="<?php echo ($f['id']); ?>"><?php _e('Edit', 'rss-post-importer'); ?></a> |
 
 
 
 
 
65
  <a href="#" class="delete-row" data-target="<?php echo ($f['id']); ?>"><?php _e('Delete', 'rss-post-importer'); ?></a>
66
- <?php
67
- if($f['feed_status']=="active"){ ?>
68
  | <a href="#" class="status-row" data-action="pause" data-target="<?php echo ($f['id']); ?>"><?php _e('Pause', 'rss-post-importer'); ?></a>
69
- <?php }elseif($f['feed_status']=="pause"){ ?>
70
- | <a href="#" class="status-row" data-action="Enable_Feed" data-target="<?php echo ($f['id']); ?>"><?php _e('Enable Feed', 'rss-post-importer'); ?></a>
71
  <?php } ?>
72
-
73
  </div>
74
  </td>
75
  <td class="rss_pi-feed_url"><span class="field-url"><?php echo esc_url(stripslashes($f['url'])); ?></span></td>
76
  <td class="rss_pi_feed_max_posts"><span class="field-max_posts"><?php echo $f['max_posts']; ?></span></td>
77
  <!-- <td width="20%"><?php //echo $category; ?></td>-->
78
  </tr>
 
 
 
 
 
 
 
79
  <tr id="edit_<?php echo ($f['id']); ?>" class="edit-row<?php echo $show; ?>">
80
  <td colspan="4">
81
  <table class="widefat edit-table">
@@ -111,8 +133,8 @@ if (is_array($f['category_id'])) {
111
  </li>
112
  </ul>
113
  </td>
114
- </tr>
115
-
116
  <tr>
117
  <td>
118
  <label for="<?php echo ($f['id']); ?>-canonical_urls"><?php _e('SEO canonical URLs ?', "rss-post-importer"); ?></label>
@@ -128,12 +150,12 @@ if (is_array($f['category_id'])) {
128
  </li>
129
  </ul>
130
  </td>
131
- </tr>
132
-
133
  <tr>
134
  <td>
135
  <label for="<?php echo ($f['id']); ?>-automatic_import_author"><?php _e('Automatic import of Authors ?', "rss-post-importer"); ?></label>
136
-
137
  </td>
138
  <td>
139
  <ul class="radiolist">
@@ -145,8 +167,8 @@ if (is_array($f['category_id'])) {
145
  </li>
146
  </ul>
147
  </td>
148
- </tr>
149
-
150
  <tr>
151
  <td><label for="<?php echo ($f['id']); ?>-author_id"><?php _e("Feed Author", 'rss-post-importer'); ?></label></td>
152
  <td>
@@ -164,11 +186,11 @@ wp_dropdown_users($args);
164
  ?>
165
  </td>
166
  </tr>
167
-
168
  <tr>
169
  <td>
170
  <label for="<?php echo ($f['id']); ?>-automatic_import_categories"><?php _e('Automatic import of Categories ?', "rss-post-importer"); ?></label>
171
-
172
  </td>
173
  <td>
174
  <ul class="radiolist">
@@ -181,8 +203,8 @@ wp_dropdown_users($args);
181
  </ul>
182
  </td>
183
  </tr>
184
-
185
-
186
  <tr>
187
  <td><label for=""><?php _e("Category", 'rss-post-importer'); ?></label></td>
188
  <td>
@@ -208,7 +230,7 @@ wp_dropdown_users($args);
208
  ?>
209
  </td>
210
  </tr>
211
-
212
  <tr>
213
  <td><label for=""><?php _e("Tags", 'rss-post-importer'); ?></label></td>
214
  <td>
@@ -249,7 +271,7 @@ wp_dropdown_users($args);
249
  ?></textarea>
250
  </td>
251
  </tr>
252
-
253
  <tr>
254
  <td><label for=""><?php _e("Strip html tags", 'rss-post-importer'); ?></label></td>
255
  <td>
@@ -271,3 +293,6 @@ wp_dropdown_users($args);
271
 
272
  </td>
273
  </tr>
 
 
 
1
  <?php
 
2
 
3
+ if (! isset($ajax_add)) {
4
+ $ajax_add = false;
5
+ }
6
+ if (! isset($ajax_edit)) {
7
+ $ajax_edit = false;
8
+ }
9
+
10
+ $show = '';
11
  if (!isset($f)) {
12
  $f = array(
13
+ 'id' => isset($ajax_feed_id) ? $ajax_feed_id : 0,
14
  'name' => 'New feed',
15
  'url' => '',
16
  'max_posts' => 5,
64
 
65
  ?>
66
 
67
+ <?php
68
+ if ($ajax_add || ! $ajax_edit):
69
+ ?>
70
  <tr id="display_<?php echo ($f['id']); ?>" class="data-row<?php echo $show; ?>" data-fields="name,url,max_posts">
71
  <td class="rss_pi-feed_name">
72
  <strong><a href="#" class="toggle-edit" data-target="<?php echo ($f['id']); ?>"><span class="field-name"><?php echo esc_html(stripslashes($f['name'])); ?></span></a></strong>
73
  <div class="row-options">
74
+ <?php
75
+ if (isset($f['feed_status'])): ?>
76
+ <a href="#" class="toggle-edit" data-target="<?php echo ($f['id']); ?>"><?php _e('Edit', 'rss-post-importer'); ?></a> |
77
+ <?php
78
+ endif;
79
+ ?>
80
  <a href="#" class="delete-row" data-target="<?php echo ($f['id']); ?>"><?php _e('Delete', 'rss-post-importer'); ?></a>
81
+ <?php
82
+ if(isset($f['feed_status']) && $f['feed_status'] == "active") { ?>
83
  | <a href="#" class="status-row" data-action="pause" data-target="<?php echo ($f['id']); ?>"><?php _e('Pause', 'rss-post-importer'); ?></a>
84
+ <?php } elseif (isset($f['feed_status']) && $f['feed_status'] == "pause"){ ?>
85
+ | <a href="#" class="status-row" data-action="enable" data-target="<?php echo ($f['id']); ?>"><?php _e('Enable Feed', 'rss-post-importer'); ?></a>
86
  <?php } ?>
87
+
88
  </div>
89
  </td>
90
  <td class="rss_pi-feed_url"><span class="field-url"><?php echo esc_url(stripslashes($f['url'])); ?></span></td>
91
  <td class="rss_pi_feed_max_posts"><span class="field-max_posts"><?php echo $f['max_posts']; ?></span></td>
92
  <!-- <td width="20%"><?php //echo $category; ?></td>-->
93
  </tr>
94
+ <?php
95
+ endif;
96
+ ?>
97
+
98
+ <?php
99
+ if ($ajax_add || $ajax_edit):
100
+ ?>
101
  <tr id="edit_<?php echo ($f['id']); ?>" class="edit-row<?php echo $show; ?>">
102
  <td colspan="4">
103
  <table class="widefat edit-table">
133
  </li>
134
  </ul>
135
  </td>
136
+ </tr>
137
+
138
  <tr>
139
  <td>
140
  <label for="<?php echo ($f['id']); ?>-canonical_urls"><?php _e('SEO canonical URLs ?', "rss-post-importer"); ?></label>
150
  </li>
151
  </ul>
152
  </td>
153
+ </tr>
154
+
155
  <tr>
156
  <td>
157
  <label for="<?php echo ($f['id']); ?>-automatic_import_author"><?php _e('Automatic import of Authors ?', "rss-post-importer"); ?></label>
158
+
159
  </td>
160
  <td>
161
  <ul class="radiolist">
167
  </li>
168
  </ul>
169
  </td>
170
+ </tr>
171
+
172
  <tr>
173
  <td><label for="<?php echo ($f['id']); ?>-author_id"><?php _e("Feed Author", 'rss-post-importer'); ?></label></td>
174
  <td>
186
  ?>
187
  </td>
188
  </tr>
189
+
190
  <tr>
191
  <td>
192
  <label for="<?php echo ($f['id']); ?>-automatic_import_categories"><?php _e('Automatic import of Categories ?', "rss-post-importer"); ?></label>
193
+
194
  </td>
195
  <td>
196
  <ul class="radiolist">
203
  </ul>
204
  </td>
205
  </tr>
206
+
207
+
208
  <tr>
209
  <td><label for=""><?php _e("Category", 'rss-post-importer'); ?></label></td>
210
  <td>
230
  ?>
231
  </td>
232
  </tr>
233
+
234
  <tr>
235
  <td><label for=""><?php _e("Tags", 'rss-post-importer'); ?></label></td>
236
  <td>
271
  ?></textarea>
272
  </td>
273
  </tr>
274
+
275
  <tr>
276
  <td><label for=""><?php _e("Strip html tags", 'rss-post-importer'); ?></label></td>
277
  <td>
293
 
294
  </td>
295
  </tr>
296
+ <?php
297
+ endif;
298
+ ?>
app/templates/feed-table.php CHANGED
@@ -9,13 +9,16 @@
9
  </thead>
10
  <tbody class="rss-rows">
11
  <?php
12
- $saved_ids = array();
 
13
 
14
  if (is_array($this->options['feeds']) && count($this->options['feeds']) > 0) :
15
  foreach ($this->options['feeds'] as $f) :
 
 
16
  $category = get_the_category($f['category_id']);
17
- array_push($saved_ids, $f['id']);
18
- include( RSS_PI_PATH . 'app/templates/feed-table-row.php');
19
  endforeach;
20
  else :
21
  ?>
@@ -34,17 +37,20 @@
34
  <a href="#" class="button button-large button-primary add-row">
35
  <?php _e('Add new feed', "rss-post-importer"); ?>
36
  </a>
37
- <input type="hidden" name="ids" id="ids" value="<?php echo(join($saved_ids, ',')); ?>" />
38
- <input type="hidden" id="sts_id" name="sts_id" value="" />
 
 
 
39
  </td>
40
  </tr>
41
  <?php
42
  // preload an empty (and hidden by css) "new feed" row
43
  unset($f);
44
- include( RSS_PI_PATH . 'app/templates/feed-table-row.php');
45
  ?>
46
  </tfoot>
47
  </table>
48
  <style>
49
  .rss_pi-table tfoot tr.data-row,.rss_pi-table tfoot tr.edit-row{display:none;}
50
- </style>
9
  </thead>
10
  <tbody class="rss-rows">
11
  <?php
12
+ $feed_ids = array();
13
+ $paused_feeds = array();
14
 
15
  if (is_array($this->options['feeds']) && count($this->options['feeds']) > 0) :
16
  foreach ($this->options['feeds'] as $f) :
17
+ if ($f['feed_status'] == 'pause') array_push($paused_feeds, $f['id']);
18
+
19
  $category = get_the_category($f['category_id']);
20
+ //array_push($feed_ids, $f['id']);
21
+ include(RSS_PI_PATH . 'app/templates/feed-table-row.php');
22
  endforeach;
23
  else :
24
  ?>
37
  <a href="#" class="button button-large button-primary add-row">
38
  <?php _e('Add new feed', "rss-post-importer"); ?>
39
  </a>
40
+ <!--<input type="hidden" name="feed_ids" id="feed_ids" value="<?php echo(join($feed_ids, ',')); ?>" />-->
41
+ <input type="hidden" name="deleted_feeds" id="deleted_feeds" value="" />
42
+ <input type="hidden" name="modified_feeds" id="modified_feeds" value="" />
43
+ <input type="hidden" name="new_feeds" id="new_feeds" value="" />
44
+ <input type="hidden" id="paused_feeds" name="paused_feeds" value="<?php echo(join($paused_feeds, ',')); ?>" />
45
  </td>
46
  </tr>
47
  <?php
48
  // preload an empty (and hidden by css) "new feed" row
49
  unset($f);
50
+ include(RSS_PI_PATH . 'app/templates/feed-table-row.php');
51
  ?>
52
  </tfoot>
53
  </table>
54
  <style>
55
  .rss_pi-table tfoot tr.data-row,.rss_pi-table tfoot tr.edit-row{display:none;}
56
+ </style>
app/templates/settings-table.php CHANGED
@@ -15,32 +15,45 @@
15
  <p class="description"><?php _e('Custom Frequency in minutes only.', "rss-post-importer"); ?></p>
16
  </td>
17
  <td>
18
- <?php
19
- $x = wp_get_schedules();
20
- $custom_cron_options = get_option( 'rss_custom_cron_frequency',array());
21
- if(!empty($custom_cron_options)):
22
- $rss_custom_cron = unserialize($custom_cron_options);
23
- endif;
 
 
24
  ?>
25
  <select name="frequency" id="frequency">
26
- <?php foreach (array_keys($x) as $interval) :
27
- if($rss_custom_cron['frequency'] != $interval) :
28
-
29
- ?>
30
- <option value="<?php echo $interval; ?>" <?php
31
- if ($this->options['settings']['frequency'] == $interval) : echo('selected="selected"');
32
- endif;
33
- ?>><?php echo $x[$interval]['display']; ?></option>
34
- <?php endif;
35
- endforeach; ?>
36
-
37
- <option value="custom_frequency" <?php if ($this->options['settings']['custom_frequency'] == "true"){ echo('selected="selected"');} ?>><?php _e('Custom frequency', "rss-post-importer"); ?></option>
 
 
 
38
  </select>
39
  &nbsp;
40
-
41
- <input type="text" id="rss_custom_frequency" name="rss_custom_frequency" value="<?php echo $rss_custom_cron['time']; ?>" placeholder="Minutes" <?php if ($this->options['settings']['custom_frequency'] == 'true'){ echo('style="display:inline"');}else{ echo('style="display:none"');} ?>/>
42
-
43
-
 
 
 
 
 
 
 
 
44
  </td>
45
  </tr>
46
  <tr>
@@ -48,8 +61,8 @@
48
  <label for="feeds_api_key"><?php _e('Full Text RSS Feed API Key', "rss-post-importer"); ?></label>
49
  <?php if ( ! $this->is_key_valid ) : ?>
50
  <p class="description">
51
- <?php _e('Boost Your traffic with Full RSS Content - ', "rss-post-importer"); ?>
52
- Request a Free 14 Days <a href="http://www.feedsapi.com/?utm_source=rsspi-full-rss-key-here" target="_blank"> Full RSS Key Here !</a>
53
  </p>
54
  <?php endif; ?>
55
  </td>
@@ -138,7 +151,7 @@
138
  'selected' => $this->options['settings']['author_id']
139
  );
140
  wp_dropdown_users($args);
141
- ?>
142
  </td>
143
  </tr>
144
  <tr>
@@ -200,7 +213,7 @@
200
  <label><input type="radio" id="enable_logging_false" name="enable_logging" value="false" <?php echo($this->options['settings']['enable_logging'] == 'false' || $this->options['settings']['enable_logging'] == '' ? 'checked="checked"' : ''); ?> /> <?php _e('No', 'rss-post-importer'); ?></label>
201
  </li>
202
  </ul>
203
- </td>
204
  </tr>
205
  <tr>
206
  <td>
@@ -216,7 +229,7 @@
216
  <label><input type="radio" id="import_images_locally_false" name="import_images_locally" value="false" <?php echo($this->options['settings']['import_images_locally'] == 'false' || $this->options['settings']['enable_logging'] == '' ? 'checked="checked"' : ''); ?> /> <?php _e('No', 'rss-post-importer'); ?></label>
217
  </li>
218
  </ul>
219
- </td>
220
  </tr>
221
  <tr>
222
  <td>
@@ -232,7 +245,7 @@
232
  <label><input type="radio" id="disable_thumbnail_false" name="disable_thumbnail" value="false" <?php echo($this->options['settings']['disable_thumbnail'] == 'false' || $this->options['settings']['disable_thumbnail'] == '' ? 'checked="checked"' : ''); ?> /> <?php _e('No', 'rss-post-importer'); ?></label>
233
  </li>
234
  </ul>
235
- </td>
236
  </tr>
237
  <tr>
238
  <td>
@@ -255,7 +268,7 @@
255
  <label><input type="radio" id="cache_deleted_false" name="cache_deleted" value="true" <?php echo($this->options['settings']['cache_deleted'] == 'true' || $this->options['settings']['cache_deleted'] == '' ? 'checked="checked"' : ''); ?><?php echo $disabled; ?> /> <?php _e('No', 'rss-post-importer'); ?></label>
256
  </li>
257
  </ul>
258
- </td>
259
  </tr>
260
  <?php if ( isset($this->options['upgraded']['deleted_posts']) ) { ?>
261
  <tr>
@@ -273,8 +286,8 @@
273
  ?>
274
  <?php $rss_pi_deleted_posts = count( get_option( 'rss_pi_deleted_posts', array() ) ); ?>
275
  <p><?php printf( _n('Cached: <strong>%d</strong> deleted post', 'Cached: <strong>%d</strong> deleted posts', $rss_pi_deleted_posts, 'rss-post-importer'), $rss_pi_deleted_posts ); ?></p>
276
- <input type="submit" value="Purge Cache" name="purge_deleted_cache" class="button button-primary button-large"<?php echo $disabled; ?> />
277
- </td>
278
  </tr>
279
  <?php } ?>
280
  <tr>
@@ -290,8 +303,8 @@
290
  $this->key_error( sprintf( $this->key_prompt, '', 'http://www.feedsapi.com/?utm_source=rsspostimporter&utm_medium=upgrade&utm_term=export-feeds&utm_content=rsspi-full-rss-key-here&utm_campaign=wordpress' ), true );
291
  }
292
  ?>
293
- <input type="submit" value="Export your Feeds and Setting as CSV File" name="csv_download" class="button button-primary button-large"<?php echo $disabled; ?> />
294
- </td>
295
  </tr>
296
  <tr>
297
  <td>
@@ -318,7 +331,7 @@ strip_html = strip html tags - "true" or "false"', "rss-post-importer"); ?></p>
318
  }
319
  ?>
320
  <input type="file" name="import_csv"<?php echo $disabled; ?> />
321
- </td>
322
  </tr>
323
  <tr>
324
  <td>
@@ -333,8 +346,8 @@ strip_html = strip html tags - "true" or "false"', "rss-post-importer"); ?></p>
333
  $this->key_error( sprintf( $this->key_prompt, '', 'http://www.feedsapi.com/?utm_source=rsspostimporter&utm_medium=upgrade&utm_term=export-opml&utm_content=rsspi-full-rss-key-here&utm_campaign=wordpress' ), true );
334
  }
335
  ?>
336
- <input type="submit" value="Export your Feeds as OPML File" name="export_opml" class="button button-primary button-large"<?php echo $disabled; ?> />
337
- </td>
338
  </tr>
339
  <tr>
340
  <td>
@@ -350,9 +363,9 @@ strip_html = strip html tags - "true" or "false"', "rss-post-importer"); ?></p>
350
  }
351
  ?>
352
  <input type="file" name="import_opml"<?php echo $disabled; ?> />
353
- </td>
354
  </tr>
355
-
356
  <tr>
357
  <td>
358
  <?php _e('Social Media Optimization and Open Graph', "rss-post-importer"); ?>
@@ -361,19 +374,34 @@ strip_html = strip html tags - "true" or "false"', "rss-post-importer"); ?></p>
361
  <td>
362
  <ul class="radiolist">
363
  <li>
364
- <label><label><input type="checkbox" name="tw_show" id="tw_show" value="1" <?php echo($this->options['settings']['tw_show'] == '1' ? 'checked="checked"' : ''); ?> /> <?php _e('Twitter', 'rss-post-importer'); ?></label>
 
 
 
 
 
365
  </li>
366
  <li>
367
- <label><label><input type="checkbox" name="gg_show" id="gg_show" value="1" <?php echo($this->options['settings']['gg_show'] == '1' ? 'checked="checked"' : ''); ?> /> <?php _e('Google+', 'rss-post-importer'); ?></label>
 
 
 
 
 
368
  </li>
369
  <li>
370
- <label><label><input type="checkbox" name="og_show" id="og_show" value="1" <?php echo($this->options['settings']['og_show'] == '1' ? 'checked="checked"' : ''); ?> /> <?php _e('Facebook Opengraph', 'rss-post-importer'); ?></label>
 
 
 
 
 
371
  </li>
372
  </ul>
373
- </td>
374
  </tr>
375
-
376
-
377
  </table>
378
  </td>
379
  </tr>
15
  <p class="description"><?php _e('Custom Frequency in minutes only.', "rss-post-importer"); ?></p>
16
  </td>
17
  <td>
18
+ <?php
19
+ $schedules = wp_get_schedules();
20
+ $custom_cron_options = get_option( 'rss_custom_cron_frequency', array());
21
+ if (! empty($custom_cron_options)) {
22
+ $rss_custom_cron = unserialize($custom_cron_options);
23
+ } else {
24
+ $rss_custom_cron = array();
25
+ }
26
  ?>
27
  <select name="frequency" id="frequency">
28
+ <?php
29
+ foreach (array_keys($schedules) as $interval) :
30
+ if (empty($rss_custom_cron) || $rss_custom_cron['frequency'] != $interval) :
31
+ ?>
32
+ <option value="<?php echo $interval; ?>"
33
+ <?php if ($this->options['settings']['frequency'] == $interval) echo('selected="selected"'); ?>
34
+ ><?php echo $schedules[$interval]['display']; ?></option>
35
+ <?php
36
+ endif;
37
+ endforeach;
38
+ ?>
39
+
40
+ <option value="custom_frequency"
41
+ <?php if (isset($this->options['settings']['custom_frequency']) && $this->options['settings']['custom_frequency'] == "true") echo('selected="selected"'); ?>
42
+ ><?php _e('Custom frequency', "rss-post-importer"); ?></option>
43
  </select>
44
  &nbsp;
45
+
46
+ <input type="text" id="rss_custom_frequency" name="rss_custom_frequency" value="<?php echo(isset($rss_custom_cron['time']) ? $rss_custom_cron['time'] : ''); ?>" placeholder="Minutes"
47
+ <?php
48
+ if (isset($this->options['settings']['custom_frequency']) && $this->options['settings']['custom_frequency'] == 'true') {
49
+ echo('style="display:inline"');
50
+ } else {
51
+ echo('style="display:none"');
52
+ }
53
+ ?>
54
+ />
55
+
56
+
57
  </td>
58
  </tr>
59
  <tr>
61
  <label for="feeds_api_key"><?php _e('Full Text RSS Feed API Key', "rss-post-importer"); ?></label>
62
  <?php if ( ! $this->is_key_valid ) : ?>
63
  <p class="description">
64
+ <?php _e('Boost Your traffic with Full RSS Content - ', "rss-post-importer"); ?>
65
+ Request a Free 14 Days <a href="http://www.feedsapi.com/?utm_source=rsspi-full-rss-key-here" target="_blank"> Full RSS Key Here !</a>
66
  </p>
67
  <?php endif; ?>
68
  </td>
151
  'selected' => $this->options['settings']['author_id']
152
  );
153
  wp_dropdown_users($args);
154
+ ?>
155
  </td>
156
  </tr>
157
  <tr>
213
  <label><input type="radio" id="enable_logging_false" name="enable_logging" value="false" <?php echo($this->options['settings']['enable_logging'] == 'false' || $this->options['settings']['enable_logging'] == '' ? 'checked="checked"' : ''); ?> /> <?php _e('No', 'rss-post-importer'); ?></label>
214
  </li>
215
  </ul>
216
+ </td>
217
  </tr>
218
  <tr>
219
  <td>
229
  <label><input type="radio" id="import_images_locally_false" name="import_images_locally" value="false" <?php echo($this->options['settings']['import_images_locally'] == 'false' || $this->options['settings']['enable_logging'] == '' ? 'checked="checked"' : ''); ?> /> <?php _e('No', 'rss-post-importer'); ?></label>
230
  </li>
231
  </ul>
232
+ </td>
233
  </tr>
234
  <tr>
235
  <td>
245
  <label><input type="radio" id="disable_thumbnail_false" name="disable_thumbnail" value="false" <?php echo($this->options['settings']['disable_thumbnail'] == 'false' || $this->options['settings']['disable_thumbnail'] == '' ? 'checked="checked"' : ''); ?> /> <?php _e('No', 'rss-post-importer'); ?></label>
246
  </li>
247
  </ul>
248
+ </td>
249
  </tr>
250
  <tr>
251
  <td>
268
  <label><input type="radio" id="cache_deleted_false" name="cache_deleted" value="true" <?php echo($this->options['settings']['cache_deleted'] == 'true' || $this->options['settings']['cache_deleted'] == '' ? 'checked="checked"' : ''); ?><?php echo $disabled; ?> /> <?php _e('No', 'rss-post-importer'); ?></label>
269
  </li>
270
  </ul>
271
+ </td>
272
  </tr>
273
  <?php if ( isset($this->options['upgraded']['deleted_posts']) ) { ?>
274
  <tr>
286
  ?>
287
  <?php $rss_pi_deleted_posts = count( get_option( 'rss_pi_deleted_posts', array() ) ); ?>
288
  <p><?php printf( _n('Cached: <strong>%d</strong> deleted post', 'Cached: <strong>%d</strong> deleted posts', $rss_pi_deleted_posts, 'rss-post-importer'), $rss_pi_deleted_posts ); ?></p>
289
+ <input type="submit" value="Purge Cache" name="purge_deleted_cache" class="button button-primary button-large"<?php echo $disabled; ?> />
290
+ </td>
291
  </tr>
292
  <?php } ?>
293
  <tr>
303
  $this->key_error( sprintf( $this->key_prompt, '', 'http://www.feedsapi.com/?utm_source=rsspostimporter&utm_medium=upgrade&utm_term=export-feeds&utm_content=rsspi-full-rss-key-here&utm_campaign=wordpress' ), true );
304
  }
305
  ?>
306
+ <input type="submit" value="Export your Feeds and Setting as CSV File" name="csv_download" class="button button-primary button-large"<?php echo $disabled; ?> />
307
+ </td>
308
  </tr>
309
  <tr>
310
  <td>
331
  }
332
  ?>
333
  <input type="file" name="import_csv"<?php echo $disabled; ?> />
334
+ </td>
335
  </tr>
336
  <tr>
337
  <td>
346
  $this->key_error( sprintf( $this->key_prompt, '', 'http://www.feedsapi.com/?utm_source=rsspostimporter&utm_medium=upgrade&utm_term=export-opml&utm_content=rsspi-full-rss-key-here&utm_campaign=wordpress' ), true );
347
  }
348
  ?>
349
+ <input type="submit" value="Export your Feeds as OPML File" name="export_opml" class="button button-primary button-large"<?php echo $disabled; ?> />
350
+ </td>
351
  </tr>
352
  <tr>
353
  <td>
363
  }
364
  ?>
365
  <input type="file" name="import_opml"<?php echo $disabled; ?> />
366
+ </td>
367
  </tr>
368
+
369
  <tr>
370
  <td>
371
  <?php _e('Social Media Optimization and Open Graph', "rss-post-importer"); ?>
374
  <td>
375
  <ul class="radiolist">
376
  <li>
377
+ <label>
378
+ <input type="checkbox" name="tw_show" id="tw_show" value="1"
379
+ <?php echo(isset($this->options['settings']['tw_show']) && $this->options['settings']['tw_show'] == '1' ? 'checked="checked"' : ''); ?>
380
+ />
381
+ <?php _e('Twitter', 'rss-post-importer'); ?>
382
+ </label>
383
  </li>
384
  <li>
385
+ <label>
386
+ <input type="checkbox" name="gg_show" id="gg_show" value="1"
387
+ <?php echo(isset($this->options['settings']['gg_show']) && $this->options['settings']['gg_show'] == '1' ? 'checked="checked"' : ''); ?>
388
+ />
389
+ <?php _e('Google+', 'rss-post-importer'); ?>
390
+ </label>
391
  </li>
392
  <li>
393
+ <label>
394
+ <input type="checkbox" name="og_show" id="og_show" value="1"
395
+ <?php echo(isset($this->options['settings']['og_show']) && $this->options['settings']['og_show'] == '1' ? 'checked="checked"' : ''); ?>
396
+ />
397
+ <?php _e('Facebook Opengraph', 'rss-post-importer'); ?>
398
+ </label>
399
  </li>
400
  </ul>
401
+ </td>
402
  </tr>
403
+
404
+
405
  </table>
406
  </td>
407
  </tr>
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.3.0
9
  Author URI: https://www.feedsapi.org/
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -32,7 +32,7 @@ if (!defined('RSS_PI_BASENAME')) {
32
  }
33
 
34
  if (!defined('RSS_PI_VERSION')) {
35
- define('RSS_PI_VERSION', '2.3.0');
36
  }
37
 
38
  if (!defined('RSS_PI_LOG_PATH')) {
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.4.0
9
  Author URI: https://www.feedsapi.org/
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
32
  }
33
 
34
  if (!defined('RSS_PI_VERSION')) {
35
+ define('RSS_PI_VERSION', '2.4.0');
36
  }
37
 
38
  if (!defined('RSS_PI_LOG_PATH')) {
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: feedsapi
3
  Donate link: https://www.feedsapi.org/
4
  Tags: rss aggregation, wordpress autoblog aggregator, Autoblogger, rss autopost and syndicator, blog content curation, feedsyndicate, feedwordpress, multiple rss feed importer, rss feeds to post, content syndication, blog migration, yahoo pipes
5
  Requires at least: 3.5
6
- Tested up to: 4.2.4
7
- Stable tag: 2.3.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -128,6 +128,9 @@ Learn more (and get detailed instructions) in our [contribute guide](http://jetp
128
 
129
  == Change Log ==
130
 
 
 
 
131
  = Version 2.3.0 =
132
  * Featured Image Fix
133
  * Logs Fix
@@ -297,4 +300,4 @@ Learn more (and get detailed instructions) in our [contribute guide](http://jetp
297
  * Added possibility to log each time imports are made in a textfile (for debugging purposes).
298
 
299
  = Version 1.0.1 =
300
- * Fixed some localization issues.
3
  Donate link: https://www.feedsapi.org/
4
  Tags: rss aggregation, wordpress autoblog aggregator, Autoblogger, rss autopost and syndicator, blog content curation, feedsyndicate, feedwordpress, multiple rss feed importer, rss feeds to post, content syndication, blog migration, yahoo pipes
5
  Requires at least: 3.5
6
+ Tested up to: 4.7.4
7
+ Stable tag: 2.4.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
128
 
129
  == Change Log ==
130
 
131
+ = Version 2.4.0 =
132
+ * Several bugs fixing and stability improvement
133
+
134
  = Version 2.3.0 =
135
  * Featured Image Fix
136
  * Logs Fix
300
  * Added possibility to log each time imports are made in a textfile (for debugging purposes).
301
 
302
  = Version 1.0.1 =
303
+ * Fixed some localization issues.