RSS Post Importer - Version 2.0.9

Version Description

Download this release

Release Info

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

Code changes from version 2.0.7 to 2.0.9

app/assets/font/fontawesome-webfont.eot CHANGED
File without changes
app/assets/font/fontawesome-webfont.svg CHANGED
File without changes
app/assets/font/fontawesome-webfont.ttf CHANGED
File without changes
app/assets/font/fontawesome-webfont.woff CHANGED
File without changes
app/class-rss-post-importer.php CHANGED
@@ -1,128 +1,256 @@
1
- <?php
2
- /**
3
- * One class to rule them all
4
- *
5
- * @author Saurabh Shukla <saurabh@yapapaya.com>
6
- */
7
- class rssPostImporter {
8
-
9
- /**
10
- * A var to store the options in
11
- * @var array
12
- */
13
- public $options = array();
14
-
15
- /**
16
- * To initialise the admin and cron classes
17
- *
18
- * @var object
19
- */
20
- private $admin, $cron;
21
-
22
- /**
23
- * Start
24
- */
25
- function __construct() {
26
-
27
- // populate the options first
28
- $this->load_options();
29
-
30
- // hook translations
31
- add_action('plugins_loaded', array($this, 'localize'));
32
-
33
- add_filter( 'plugin_action_links_' . RSS_PI_BASENAME, array($this, 'settings_link') );
34
- }
35
-
36
- /**
37
- * Load options from the db
38
- */
39
- public function load_options() {
40
-
41
- $default_settings = array(
42
- 'enable_logging' => false,
43
- 'feeds_api_key' => false,
44
- 'frequency' => 0,
45
- 'post_template' => "{\$content}\nSource: {\$feed_title}",
46
- 'post_status' => 'publish',
47
- 'author_id' => 1,
48
- 'allow_comments' => 'open',
49
- 'block_indexing' => false,
50
- 'nofollow_outbound' => true,
51
- 'keywords' => array()
52
- );
53
-
54
- $options = get_option('rss_pi_feeds', array());
55
-
56
- if (!isset($options['settings'])) {
57
- $options['settings'] = array();
58
- }
59
-
60
- $options['settings'] = wp_parse_args($options['settings'], $default_settings);
61
-
62
- if (!array_key_exists('imports', $options)) {
63
- $options['imports'] = 0;
64
- }
65
-
66
- $this->options = $options;
67
- }
68
-
69
- /**
70
- * Load translations
71
- */
72
- public function localize() {
73
-
74
- load_plugin_textdomain('rss_pi', false, RSS_PI_PATH . 'app/lang/');
75
- }
76
-
77
- /**
78
- * Initialise
79
- */
80
- public function init() {
81
-
82
- // initialise admin and cron
83
- $this->cron = new rssPICron();
84
- $this->cron->init();
85
-
86
- $this->admin = new rssPIAdmin();
87
- $this->admin->init();
88
-
89
- $this->front = new rssPIFront();
90
- $this->front->init();
91
- }
92
-
93
- /**
94
- * Check if a given API key is valid
95
- *
96
- * @param string $key
97
- * @return boolean
98
- */
99
- public function is_valid_key($key) {
100
-
101
- if (empty($key)) {
102
- return false;
103
- }
104
-
105
- $url = "http://176.58.108.28/makefulltextfeed.php?key=$key&url=http://dummyurl.com";
106
- $content = file_get_contents($url);
107
-
108
- if (trim($content) == "A valid key must be supplied") {
109
- return false;
110
- }
111
-
112
- return true;
113
- }
114
-
115
- /**
116
- * Adds a settings link
117
- *
118
- * @param array $links EXisting links
119
- * @return type
120
- */
121
- public function settings_link($links) {
122
- $settings_link = array(
123
- '<a href="' . admin_url('options-general.php?page=rss_pi') . '">Settings</a>',
124
- );
125
- return array_merge($settings_link, $links);
126
- }
127
-
128
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+
5
+ * One class to rule them all
6
+
7
+ *
8
+
9
+ * @author Saurabh Shukla <saurabh@yapapaya.com>
10
+
11
+ */
12
+
13
+ class rssPostImporter {
14
+
15
+
16
+
17
+ /**
18
+
19
+ * A var to store the options in
20
+
21
+ * @var array
22
+
23
+ */
24
+
25
+ public $options = array();
26
+
27
+
28
+
29
+ /**
30
+
31
+ * To initialise the admin and cron classes
32
+
33
+ *
34
+
35
+ * @var object
36
+
37
+ */
38
+
39
+ private $admin, $cron;
40
+
41
+
42
+
43
+ /**
44
+
45
+ * Start
46
+
47
+ */
48
+
49
+ function __construct() {
50
+
51
+
52
+
53
+ // populate the options first
54
+
55
+ $this->load_options();
56
+
57
+
58
+
59
+ // hook translations
60
+
61
+ add_action('plugins_loaded', array($this, 'localize'));
62
+
63
+
64
+
65
+ add_filter( 'plugin_action_links_' . RSS_PI_BASENAME, array($this, 'settings_link') );
66
+
67
+ }
68
+
69
+
70
+
71
+ /**
72
+
73
+ * Load options from the db
74
+
75
+ */
76
+
77
+ public function load_options() {
78
+
79
+
80
+
81
+ $default_settings = array(
82
+
83
+ 'enable_logging' => false,
84
+
85
+ 'feeds_api_key' => false,
86
+
87
+ 'frequency' => 0,
88
+
89
+ 'post_template' => "{\$content}\nSource: {\$feed_title}",
90
+
91
+ 'post_status' => 'publish',
92
+
93
+ 'author_id' => 1,
94
+
95
+ 'allow_comments' => 'open',
96
+
97
+ 'block_indexing' => false,
98
+
99
+ 'nofollow_outbound' => true,
100
+
101
+ 'keywords' => array()
102
+
103
+ );
104
+
105
+
106
+
107
+ $options = get_option('rss_pi_feeds', array());
108
+
109
+
110
+
111
+ if (!isset($options['settings'])) {
112
+
113
+ $options['settings'] = array();
114
+
115
+ }
116
+
117
+
118
+
119
+ $options['settings'] = wp_parse_args($options['settings'], $default_settings);
120
+
121
+
122
+
123
+ if (!array_key_exists('imports', $options)) {
124
+
125
+ $options['imports'] = 0;
126
+
127
+ }
128
+
129
+
130
+
131
+ $this->options = $options;
132
+
133
+ }
134
+
135
+
136
+
137
+ /**
138
+
139
+ * Load translations
140
+
141
+ */
142
+
143
+ public function localize() {
144
+
145
+
146
+
147
+ load_plugin_textdomain('rss_pi', false, RSS_PI_PATH . 'app/lang/');
148
+
149
+ }
150
+
151
+
152
+
153
+ /**
154
+
155
+ * Initialise
156
+
157
+ */
158
+
159
+ public function init() {
160
+
161
+
162
+
163
+ // initialise admin and cron
164
+
165
+ $this->cron = new rssPICron();
166
+
167
+ $this->cron->init();
168
+
169
+
170
+
171
+ $this->admin = new rssPIAdmin();
172
+
173
+ $this->admin->init();
174
+
175
+
176
+
177
+ $this->front = new rssPIFront();
178
+
179
+ $this->front->init();
180
+
181
+ }
182
+
183
+
184
+
185
+ /**
186
+
187
+ * Check if a given API key is valid
188
+
189
+ *
190
+
191
+ * @param string $key
192
+
193
+ * @return boolean
194
+
195
+ */
196
+
197
+ public function is_valid_key($key) {
198
+
199
+
200
+
201
+ if (empty($key)) {
202
+
203
+ return false;
204
+
205
+ }
206
+
207
+
208
+
209
+ $url = "http://www.feedsapi.org/fetch.php?key=$key&url=http://dummyurl.com";
210
+
211
+ $content = file_get_contents($url);
212
+
213
+
214
+
215
+ if (trim($content) == "A valid key must be supplied") {
216
+
217
+ return false;
218
+
219
+ }
220
+
221
+
222
+
223
+ return true;
224
+
225
+ }
226
+
227
+
228
+
229
+ /**
230
+
231
+ * Adds a settings link
232
+
233
+ *
234
+
235
+ * @param array $links EXisting links
236
+
237
+ * @return type
238
+
239
+ */
240
+
241
+ public function settings_link($links) {
242
+
243
+ $settings_link = array(
244
+
245
+ '<a href="' . admin_url('options-general.php?page=rss_pi') . '">Settings</a>',
246
+
247
+ );
248
+
249
+ return array_merge($settings_link, $links);
250
+
251
+ }
252
+
253
+
254
+
255
+ }
256
+
app/classes/helpers/class-rss-pi-parser.php CHANGED
@@ -38,7 +38,6 @@ class rssPIParser {
38
 
39
  global $rss_post_importer;
40
 
41
-
42
 
43
  // get the saved template
44
 
@@ -56,8 +55,8 @@ class rssPIParser {
56
 
57
 
58
 
59
- //$c = $this->escape_backreference($c);
60
-
61
  // do all the replacements
62
 
63
  $parsed_content = preg_replace('/\{\$content\}/i', $c, $post_template);
@@ -66,13 +65,11 @@ class rssPIParser {
66
 
67
  $parsed_content = preg_replace('/\{\$title\}/i', $item->get_title(), $parsed_content);
68
 
69
-
70
 
71
  // check if we need an excerpt
72
 
73
- $parsed_content = $this->_excerpt($parsed_content);
74
-
75
-
76
 
77
  // strip html, if needed
78
 
@@ -132,7 +129,7 @@ class rssPIParser {
132
 
133
  */
134
 
135
- private function _excerpt($content){
136
 
137
 
138
 
38
 
39
  global $rss_post_importer;
40
 
 
41
 
42
  // get the saved template
43
 
55
 
56
 
57
 
58
+ $c = $this->escape_backreference($c);
59
+
60
  // do all the replacements
61
 
62
  $parsed_content = preg_replace('/\{\$content\}/i', $c, $post_template);
65
 
66
  $parsed_content = preg_replace('/\{\$title\}/i', $item->get_title(), $parsed_content);
67
 
 
68
 
69
  // check if we need an excerpt
70
 
71
+ $parsed_content = $this->_excerpt($parsed_content,$c);
72
+
 
73
 
74
  // strip html, if needed
75
 
129
 
130
  */
131
 
132
+ private function _excerpt($content,$c){
133
 
134
 
135
 
app/classes/import/class-rss-pi-engine.php CHANGED
@@ -1,408 +1,816 @@
1
- <?php
2
-
3
- /**
4
- * Main import engine
5
- *
6
- * @author Saurabh Shukla <saurabh@yapapaya.com>
7
- */
8
- class rssPIEngine {
9
-
10
- /**
11
- * The options
12
- *
13
- * @var array
14
- */
15
- var $options = array();
16
-
17
- /**
18
- * Start the engine
19
- *
20
- * @global type $rss_post_importer
21
- */
22
- public function __construct() {
23
-
24
- global $rss_post_importer;
25
-
26
- // load options
27
- $this->options = $rss_post_importer->options;
28
- }
29
-
30
- /**
31
- * Import feeds
32
- *
33
- * @return int
34
- */
35
- public function import_feed() {
36
-
37
- $post_count = 0;
38
-
39
- // filter cache lifetime
40
- add_filter('wp_feed_cache_transient_lifetime', array($this, 'frequency'));
41
-
42
- foreach ($this->options['feeds'] as $f) {
43
-
44
- // prepare and import each feed
45
- $items = $this->prepare_import($f);
46
- $post_count += count($items);
47
- }
48
-
49
- // reformulate import count
50
- $imports = intval($this->options['imports']) + $post_count;
51
-
52
- // update options
53
- update_option('rss_pi_feeds', array(
54
- 'feeds' => $this->options['feeds'],
55
- 'settings' => $this->options['settings'],
56
- 'latest_import' => date("Y-m-d H:i:s"),
57
- 'imports' => $imports
58
- ));
59
-
60
- global $rss_post_importer;
61
- // reload options
62
- $rss_post_importer->load_options();
63
-
64
- remove_filter('wp_feed_cache_transient_lifetime', array($this, 'frequency'));
65
-
66
- // log this
67
- rssPILog::log($post_count);
68
-
69
- return $post_count;
70
- }
71
-
72
- /**
73
- * Dummy function for filtering because we can't use anon ones yet
74
- * @return string
75
- */
76
- public function frequency() {
77
- return $this->options['settings']['frequency'];
78
- }
79
-
80
- /**
81
- * Prepares arguments and imports
82
- *
83
- * @param array $f feed array
84
- * @return array
85
- */
86
- private function prepare_import($f) {
87
- $args = array(
88
- 'feed_title' => $f['name'],
89
- 'max_posts' => $f['max_posts'],
90
- 'author_id' => $f['author_id'],
91
- 'category_id' => $f['category_id'],
92
- 'tags_id' => $f['tags_id'],
93
- 'strip_html' => $f['strip_html'],
94
- 'save_to_db' => true
95
- );
96
- return $this->_import($f['url'], $args);
97
- }
98
-
99
- /**
100
- * Import feeds from url
101
- *
102
- * @param string $url The remote feed url
103
- * @param array $args Arguments for the import
104
- * @return null|array
105
- */
106
- private function _import($url = '', $args = array()) {
107
-
108
- if (empty($url)) {
109
- return;
110
- }
111
-
112
- $defaults = array(
113
- 'feed_title' => '',
114
- 'max_posts' => 5,
115
- 'author_id' => 1,
116
- 'category_id' => 0,
117
- 'tags_id' => array(),
118
- 'strip_html' => true,
119
- 'save_to_db' => true
120
- );
121
-
122
- $args = wp_parse_args($args, $defaults);
123
-
124
- // include the default WP feed processing functions
125
- include_once( ABSPATH . WPINC . '/feed.php' );
126
-
127
- // get the right url for fetching (premium vs free)
128
- $url = $this->url($url);
129
-
130
- // fetch the feed
131
- $feed = fetch_feed($url);
132
-
133
-
134
- // save as posts
135
- $posts = $this->save($feed, $args);
136
-
137
- return $posts;
138
- }
139
-
140
- /**
141
- * Formulate the right url
142
- *
143
- * @param string $url
144
- * @return string
145
- */
146
- private function url($url) {
147
-
148
- $key = $this->options['settings']["feeds_api_key"];
149
-
150
- //if api key has been saved by user and is not empty
151
- if (isset($key) && !empty($key)) {
152
-
153
- $api_url = "http://176.58.108.28/makefulltextfeed.php?key=" . $key . "&url=" . $url;
154
-
155
- return $api_url;
156
- }
157
-
158
- return $url;
159
- }
160
-
161
- /**
162
- * Save the feed
163
- *
164
- * @param object $feed The feed object
165
- * @param array $args The arguments
166
- * @return boolean
167
- */
168
- private function save($feed, $args = array()) {
169
- if (is_wp_error($feed)) {
170
- return false;
171
- }
172
- // filter the feed and get feed items
173
- $feed_items = $this->filter($feed, $args);
174
-
175
- // if we are saving
176
- if ($args['save_to_db']) {
177
- // insert and return
178
- $saved_posts = $this->insert($feed_items, $args);
179
- return $saved_posts;
180
- }
181
-
182
- // otherwsie return the feed items
183
- return $feed_items;
184
- }
185
-
186
- /**
187
- * Filter the feed based on keywords
188
- *
189
- * @param object $feed The feed object
190
- * @param array $args Arguments
191
- * @return array
192
- */
193
- private function filter($feed, $args) {
194
-
195
- // the count of keyword matched items
196
- $got = 0;
197
-
198
- // the current index of the items aray
199
- $index = 0;
200
-
201
- $filtered = array();
202
-
203
- // till we have as many as the posts needed
204
- while ($got < $args['max_posts']) {
205
-
206
- // get only one item at the current index
207
- $feed_item = $feed->get_items($index, 1);
208
-
209
- // if this is empty, get out of the while
210
- if (empty($feed_item)) {
211
- break;
212
- }
213
- // else be in a forever loop
214
- // get the content
215
- $content = $feed_item[0]->get_content();
216
-
217
- // test it against the keywords
218
- $tested = $this->test($content);
219
-
220
- // if this is good for us
221
- if ($tested) {
222
- $got++;
223
-
224
- array_push($filtered, $feed_item[0]);
225
- }
226
- // shift the index
227
- $index++;
228
- }
229
-
230
- return $filtered;
231
- }
232
-
233
- /**
234
- * Test a piece of content against keywords
235
- *
236
- * @param string $content
237
- * @return boolean
238
- */
239
- function test($content) {
240
- $keywords = $this->options['settings']['keywords'];
241
-
242
- if (empty($keywords)) {
243
- return true;
244
- }
245
-
246
- $match = false;
247
-
248
- // loop through keywords
249
- foreach ($keywords as $keyword) {
250
-
251
- // if the keyword is not a regex, make it one
252
- if (!$this->is_regex($keyword)) {
253
- $keyword = '/' . $keyword . '/i';
254
- }
255
-
256
- // look for keyword in content
257
- preg_match($keyword, $content, $tested);
258
-
259
- // if it's there, we are good
260
- if (!empty($tested)) {
261
- $match = true;
262
- // no need to test anymore
263
- break;
264
- }
265
- }
266
-
267
-
268
- return $match;
269
- }
270
-
271
- /**
272
- * Check if a string is regex
273
- *
274
- * @param string $str The string to check
275
- * @return boolean
276
- */
277
- private function is_regex($str) {
278
-
279
- // check regex with a regex!
280
- $regex = "/^\/[\s\S]+\/$/";
281
- preg_match($regex, $str, $matched);
282
- return !empty($matched);
283
- }
284
-
285
- /**
286
- * Insert feed items as posts
287
- *
288
- * @param array $items Fetched feed items
289
- * @param array $args arguments
290
- * @return array
291
- */
292
- private function insert($items, $args = array()) {
293
- $saved_posts = array();
294
-
295
- // Initialise the content parser
296
- $parser = new rssPIParser($this->options);
297
-
298
- // Featured Image setter
299
- $thumbnail = new rssPIFeaturedImage();
300
-
301
- foreach ($items as $item) {
302
- if (!$this->post_exists($item->get_permalink())) {
303
- /* Code to convert tags id array to tag name array **/
304
- if(!empty($args['tags_id'])){
305
- foreach($args['tags_id'] as $tagid){
306
- $tag_name = get_tag($tagid); // <-- your tag ID
307
- $tags_name[] = $tag_name->name;
308
- }
309
- }else{
310
- $tags_name = array();
311
- }
312
- $parser->_parse($item, $args['feed_title'], $args['strip_html']);
313
- $post = array(
314
- 'post_title' => $item->get_title(),
315
- // parse the content
316
- 'post_content' => $parser->_parse($item, $args['feed_title'], $args['strip_html']),
317
- 'post_status' => $this->options['settings']['post_status'],
318
- 'post_author' => $args['author_id'],
319
- 'post_category' => array($args['category_id']),
320
- 'tags_input' => $tags_name,
321
- 'comment_status' => $this->options['settings']['allow_comments'],
322
- 'post_date' => $item->get_date('Y-m-d H:i:s')
323
- );
324
-
325
- $content = $post["post_content"];
326
-
327
- // catch base url
328
- if (preg_match('/src="\//i', $content)) {
329
- preg_match('/href="(.+?)"/i', $content, $matches);
330
- $baseref = (is_array($matches) && !empty($matches)) ? $matches[1] : '';
331
- if (!empty($baseref)) {
332
- $bc = parse_url($baseref);
333
- $scheme = (empty($bc["scheme"])) ? "http" : $bc["scheme"];
334
- $port = $bc["port"];
335
- $host = $bc["host"];
336
- if (!empty($host)) {
337
- $preurl = $scheme . ":" . $port . "//" . $host;
338
- $post["post_content"] = preg_replace('/(src="\/)/i', 'src="' . $preurl . "/", $content);
339
- }
340
- }
341
- }
342
-
343
-
344
- // insert as post
345
- $post_id = $this->_insert($post, $item->get_permalink());
346
-
347
- // set thumbnail
348
- $thumbnail->_set($item, $post_id);
349
-
350
- array_push($saved_posts, $post);
351
- }
352
- }
353
-
354
- return $saved_posts;
355
- }
356
-
357
- /**
358
- * Check if a feed ite is alreday imported
359
- *
360
- * @param string $permalink
361
- * @return boolean
362
- */
363
- private function post_exists($permalink) {
364
-
365
- // get all posts where the meta is stored
366
- $args = array(
367
- 'post_status' => 'any',
368
- 'meta_key' => 'rss_pi_source_url',
369
- 'meta_value' => esc_url($permalink)
370
- );
371
-
372
- $posts = get_posts($args);
373
-
374
- // Not already imported
375
- return(count($posts) > 0);
376
- }
377
-
378
- /**
379
- * Insert feed item as post
380
- *
381
- * @param array $post Post array
382
- * @param string $url source url meta
383
- * @return int
384
- */
385
- private function _insert($post, $url) {
386
-
387
- if($post['post_category'][0] == ""){
388
- $post['post_category'] = array(1);
389
- }else{
390
- if(is_array($post['post_category'][0]))
391
- $post['post_category']= array_values($post['post_category'][0]);
392
- else
393
- $post['post_category']= array_values($post['post_category']);
394
- }
395
-
396
- $_post = apply_filters('pre_rss_pi_insert_post', $post);
397
-
398
-
399
- $post_id = wp_insert_post($_post);
400
-
401
- add_action('save_rss_pi_post', $post_id);
402
-
403
- add_post_meta($post_id, 'rss_pi_source_url', esc_url($url));
404
-
405
- return $post_id;
406
- }
407
-
408
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+
5
+ /**
6
+
7
+ * Main import engine
8
+
9
+ *
10
+
11
+ * @author Saurabh Shukla <saurabh@yapapaya.com>
12
+
13
+ */
14
+
15
+ class rssPIEngine {
16
+
17
+
18
+
19
+ /**
20
+
21
+ * The options
22
+
23
+ *
24
+
25
+ * @var array
26
+
27
+ */
28
+
29
+ var $options = array();
30
+
31
+
32
+
33
+ /**
34
+
35
+ * Start the engine
36
+
37
+ *
38
+
39
+ * @global type $rss_post_importer
40
+
41
+ */
42
+
43
+ public function __construct() {
44
+
45
+
46
+
47
+ global $rss_post_importer;
48
+
49
+
50
+
51
+ // load options
52
+
53
+ $this->options = $rss_post_importer->options;
54
+
55
+ }
56
+
57
+
58
+
59
+ /**
60
+
61
+ * Import feeds
62
+
63
+ *
64
+
65
+ * @return int
66
+
67
+ */
68
+
69
+ public function import_feed() {
70
+
71
+
72
+
73
+ $post_count = 0;
74
+
75
+
76
+
77
+ // filter cache lifetime
78
+
79
+ add_filter('wp_feed_cache_transient_lifetime', array($this, 'frequency'));
80
+
81
+
82
+
83
+ foreach ($this->options['feeds'] as $f) {
84
+
85
+
86
+
87
+ // prepare and import each feed
88
+
89
+ $items = $this->prepare_import($f);
90
+
91
+ $post_count += count($items);
92
+
93
+ }
94
+
95
+
96
+
97
+ // reformulate import count
98
+
99
+ $imports = intval($this->options['imports']) + $post_count;
100
+
101
+
102
+
103
+ // update options
104
+
105
+ update_option('rss_pi_feeds', array(
106
+
107
+ 'feeds' => $this->options['feeds'],
108
+
109
+ 'settings' => $this->options['settings'],
110
+
111
+ 'latest_import' => date("Y-m-d H:i:s"),
112
+
113
+ 'imports' => $imports
114
+
115
+ ));
116
+
117
+
118
+
119
+ global $rss_post_importer;
120
+
121
+ // reload options
122
+
123
+ $rss_post_importer->load_options();
124
+
125
+
126
+
127
+ remove_filter('wp_feed_cache_transient_lifetime', array($this, 'frequency'));
128
+
129
+
130
+
131
+ // log this
132
+
133
+ rssPILog::log($post_count);
134
+
135
+
136
+
137
+ return $post_count;
138
+
139
+ }
140
+
141
+
142
+
143
+ /**
144
+
145
+ * Dummy function for filtering because we can't use anon ones yet
146
+
147
+ * @return string
148
+
149
+ */
150
+
151
+ public function frequency() {
152
+
153
+ return $this->options['settings']['frequency'];
154
+
155
+ }
156
+
157
+
158
+
159
+ /**
160
+
161
+ * Prepares arguments and imports
162
+
163
+ *
164
+
165
+ * @param array $f feed array
166
+
167
+ * @return array
168
+
169
+ */
170
+
171
+ private function prepare_import($f) {
172
+
173
+ $args = array(
174
+
175
+ 'feed_title' => $f['name'],
176
+
177
+ 'max_posts' => $f['max_posts'],
178
+
179
+ 'author_id' => $f['author_id'],
180
+
181
+ 'category_id' => $f['category_id'],
182
+
183
+ 'tags_id' => $f['tags_id'],
184
+
185
+ 'strip_html' => $f['strip_html'],
186
+
187
+ 'save_to_db' => true
188
+
189
+ );
190
+
191
+ return $this->_import($f['url'], $args);
192
+
193
+ }
194
+
195
+
196
+
197
+ /**
198
+
199
+ * Import feeds from url
200
+
201
+ *
202
+
203
+ * @param string $url The remote feed url
204
+
205
+ * @param array $args Arguments for the import
206
+
207
+ * @return null|array
208
+
209
+ */
210
+
211
+ private function _import($url = '', $args = array()) {
212
+
213
+
214
+
215
+ if (empty($url)) {
216
+
217
+ return;
218
+
219
+ }
220
+
221
+
222
+
223
+ $defaults = array(
224
+
225
+ 'feed_title' => '',
226
+
227
+ 'max_posts' => 5,
228
+
229
+ 'author_id' => 1,
230
+
231
+ 'category_id' => 0,
232
+
233
+ 'tags_id' => array(),
234
+
235
+ 'strip_html' => true,
236
+
237
+ 'save_to_db' => true
238
+
239
+ );
240
+
241
+
242
+
243
+ $args = wp_parse_args($args, $defaults);
244
+
245
+
246
+
247
+ // include the default WP feed processing functions
248
+
249
+ include_once( ABSPATH . WPINC . '/feed.php' );
250
+
251
+
252
+
253
+ // get the right url for fetching (premium vs free)
254
+
255
+ $url = $this->url($url);
256
+
257
+
258
+
259
+ // fetch the feed
260
+
261
+ $feed = fetch_feed($url);
262
+
263
+
264
+
265
+
266
+
267
+ // save as posts
268
+
269
+ $posts = $this->save($feed, $args);
270
+
271
+
272
+
273
+ return $posts;
274
+
275
+ }
276
+
277
+
278
+
279
+ /**
280
+
281
+ * Formulate the right url
282
+
283
+ *
284
+
285
+ * @param string $url
286
+
287
+ * @return string
288
+
289
+ */
290
+
291
+ private function url($url) {
292
+
293
+
294
+
295
+ $key = $this->options['settings']["feeds_api_key"];
296
+
297
+
298
+
299
+ //if api key has been saved by user and is not empty
300
+
301
+ if (isset($key) && !empty($key)) {
302
+
303
+
304
+
305
+ $api_url = "http://www.feedsapi.org/fetch.php?key=" . $key . "&url=" . $url;
306
+
307
+
308
+
309
+ return $api_url;
310
+
311
+ }
312
+
313
+
314
+
315
+ return $url;
316
+
317
+ }
318
+
319
+
320
+
321
+ /**
322
+
323
+ * Save the feed
324
+
325
+ *
326
+
327
+ * @param object $feed The feed object
328
+
329
+ * @param array $args The arguments
330
+
331
+ * @return boolean
332
+
333
+ */
334
+
335
+ private function save($feed, $args = array()) {
336
+
337
+ if (is_wp_error($feed)) {
338
+
339
+ return false;
340
+
341
+ }
342
+
343
+ // filter the feed and get feed items
344
+
345
+ $feed_items = $this->filter($feed, $args);
346
+
347
+
348
+
349
+ // if we are saving
350
+
351
+ if ($args['save_to_db']) {
352
+
353
+ // insert and return
354
+
355
+ $saved_posts = $this->insert($feed_items, $args);
356
+
357
+ return $saved_posts;
358
+
359
+ }
360
+
361
+
362
+
363
+ // otherwsie return the feed items
364
+
365
+ return $feed_items;
366
+
367
+ }
368
+
369
+
370
+
371
+ /**
372
+
373
+ * Filter the feed based on keywords
374
+
375
+ *
376
+
377
+ * @param object $feed The feed object
378
+
379
+ * @param array $args Arguments
380
+
381
+ * @return array
382
+
383
+ */
384
+
385
+ private function filter($feed, $args) {
386
+
387
+
388
+
389
+ // the count of keyword matched items
390
+
391
+ $got = 0;
392
+
393
+
394
+
395
+ // the current index of the items aray
396
+
397
+ $index = 0;
398
+
399
+
400
+
401
+ $filtered = array();
402
+
403
+
404
+
405
+ // till we have as many as the posts needed
406
+
407
+ while ($got < $args['max_posts']) {
408
+
409
+
410
+
411
+ // get only one item at the current index
412
+
413
+ $feed_item = $feed->get_items($index, 1);
414
+
415
+
416
+
417
+ // if this is empty, get out of the while
418
+
419
+ if (empty($feed_item)) {
420
+
421
+ break;
422
+
423
+ }
424
+
425
+ // else be in a forever loop
426
+
427
+ // get the content
428
+
429
+ $content = $feed_item[0]->get_content();
430
+
431
+
432
+
433
+ // test it against the keywords
434
+
435
+ $tested = $this->test($content);
436
+
437
+
438
+
439
+ // if this is good for us
440
+
441
+ if ($tested) {
442
+
443
+ $got++;
444
+
445
+
446
+
447
+ array_push($filtered, $feed_item[0]);
448
+
449
+ }
450
+
451
+ // shift the index
452
+
453
+ $index++;
454
+
455
+ }
456
+
457
+
458
+
459
+ return $filtered;
460
+
461
+ }
462
+
463
+
464
+
465
+ /**
466
+
467
+ * Test a piece of content against keywords
468
+
469
+ *
470
+
471
+ * @param string $content
472
+
473
+ * @return boolean
474
+
475
+ */
476
+
477
+ function test($content) {
478
+
479
+ $keywords = $this->options['settings']['keywords'];
480
+
481
+
482
+
483
+ if (empty($keywords)) {
484
+
485
+ return true;
486
+
487
+ }
488
+
489
+
490
+
491
+ $match = false;
492
+
493
+
494
+
495
+ // loop through keywords
496
+
497
+ foreach ($keywords as $keyword) {
498
+
499
+
500
+
501
+ // if the keyword is not a regex, make it one
502
+
503
+ if (!$this->is_regex($keyword)) {
504
+
505
+ $keyword = '/' . $keyword . '/i';
506
+
507
+ }
508
+
509
+
510
+
511
+ // look for keyword in content
512
+
513
+ preg_match($keyword, $content, $tested);
514
+
515
+
516
+
517
+ // if it's there, we are good
518
+
519
+ if (!empty($tested)) {
520
+
521
+ $match = true;
522
+
523
+ // no need to test anymore
524
+
525
+ break;
526
+
527
+ }
528
+
529
+ }
530
+
531
+
532
+
533
+
534
+
535
+ return $match;
536
+
537
+ }
538
+
539
+
540
+
541
+ /**
542
+
543
+ * Check if a string is regex
544
+
545
+ *
546
+
547
+ * @param string $str The string to check
548
+
549
+ * @return boolean
550
+
551
+ */
552
+
553
+ private function is_regex($str) {
554
+
555
+
556
+
557
+ // check regex with a regex!
558
+
559
+ $regex = "/^\/[\s\S]+\/$/";
560
+
561
+ preg_match($regex, $str, $matched);
562
+
563
+ return !empty($matched);
564
+
565
+ }
566
+
567
+
568
+
569
+ /**
570
+
571
+ * Insert feed items as posts
572
+
573
+ *
574
+
575
+ * @param array $items Fetched feed items
576
+
577
+ * @param array $args arguments
578
+
579
+ * @return array
580
+
581
+ */
582
+
583
+ private function insert($items, $args = array()) {
584
+
585
+ $saved_posts = array();
586
+
587
+
588
+
589
+ // Initialise the content parser
590
+
591
+ $parser = new rssPIParser($this->options);
592
+
593
+
594
+
595
+ // Featured Image setter
596
+
597
+ $thumbnail = new rssPIFeaturedImage();
598
+
599
+
600
+
601
+ foreach ($items as $item) {
602
+
603
+ if (!$this->post_exists($item->get_permalink())) {
604
+
605
+ /* Code to convert tags id array to tag name array **/
606
+
607
+ if(!empty($args['tags_id'])){
608
+
609
+ foreach($args['tags_id'] as $tagid){
610
+
611
+ $tag_name = get_tag($tagid); // <-- your tag ID
612
+
613
+ $tags_name[] = $tag_name->name;
614
+
615
+ }
616
+
617
+ }else{
618
+
619
+ $tags_name = array();
620
+
621
+ }
622
+
623
+ $parser->_parse($item, $args['feed_title'], $args['strip_html']);
624
+
625
+ $post = array(
626
+
627
+ 'post_title' => $item->get_title(),
628
+
629
+ // parse the content
630
+
631
+ 'post_content' => $parser->_parse($item, $args['feed_title'], $args['strip_html']),
632
+
633
+ 'post_status' => $this->options['settings']['post_status'],
634
+
635
+ 'post_author' => $args['author_id'],
636
+
637
+ 'post_category' => array($args['category_id']),
638
+
639
+ 'tags_input' => $tags_name,
640
+
641
+ 'comment_status' => $this->options['settings']['allow_comments'],
642
+
643
+ 'post_date' => $item->get_date('Y-m-d H:i:s')
644
+
645
+ );
646
+
647
+
648
+
649
+ $content = $post["post_content"];
650
+
651
+
652
+
653
+ // catch base url
654
+
655
+ if (preg_match('/src="\//i', $content)) {
656
+
657
+ preg_match('/href="(.+?)"/i', $content, $matches);
658
+
659
+ $baseref = (is_array($matches) && !empty($matches)) ? $matches[1] : '';
660
+
661
+ if (!empty($baseref)) {
662
+
663
+ $bc = parse_url($baseref);
664
+
665
+ $scheme = (empty($bc["scheme"])) ? "http" : $bc["scheme"];
666
+
667
+ $port = $bc["port"];
668
+
669
+ $host = $bc["host"];
670
+
671
+ if (!empty($host)) {
672
+
673
+ $preurl = $scheme . ":" . $port . "//" . $host;
674
+
675
+ $post["post_content"] = preg_replace('/(src="\/)/i', 'src="' . $preurl . "/", $content);
676
+
677
+ }
678
+
679
+ }
680
+
681
+ }
682
+
683
+
684
+
685
+
686
+
687
+ // insert as post
688
+
689
+ $post_id = $this->_insert($post, $item->get_permalink());
690
+
691
+
692
+
693
+ // set thumbnail
694
+
695
+ $thumbnail->_set($item, $post_id);
696
+
697
+
698
+
699
+ array_push($saved_posts, $post);
700
+
701
+ }
702
+
703
+ }
704
+
705
+
706
+
707
+ return $saved_posts;
708
+
709
+ }
710
+
711
+
712
+
713
+ /**
714
+
715
+ * Check if a feed ite is alreday imported
716
+
717
+ *
718
+
719
+ * @param string $permalink
720
+
721
+ * @return boolean
722
+
723
+ */
724
+
725
+ private function post_exists($permalink) {
726
+
727
+
728
+
729
+ // get all posts where the meta is stored
730
+
731
+ $args = array(
732
+
733
+ 'post_status' => 'any',
734
+
735
+ 'meta_key' => 'rss_pi_source_url',
736
+
737
+ 'meta_value' => esc_url($permalink)
738
+
739
+ );
740
+
741
+
742
+
743
+ $posts = get_posts($args);
744
+
745
+
746
+
747
+ // Not already imported
748
+
749
+ return(count($posts) > 0);
750
+
751
+ }
752
+
753
+
754
+
755
+ /**
756
+
757
+ * Insert feed item as post
758
+
759
+ *
760
+
761
+ * @param array $post Post array
762
+
763
+ * @param string $url source url meta
764
+
765
+ * @return int
766
+
767
+ */
768
+
769
+ private function _insert($post, $url) {
770
+
771
+
772
+
773
+ if($post['post_category'][0] == ""){
774
+
775
+ $post['post_category'] = array(1);
776
+
777
+ }else{
778
+
779
+ if(is_array($post['post_category'][0]))
780
+
781
+ $post['post_category']= array_values($post['post_category'][0]);
782
+
783
+ else
784
+
785
+ $post['post_category']= array_values($post['post_category']);
786
+
787
+ }
788
+
789
+
790
+
791
+ $_post = apply_filters('pre_rss_pi_insert_post', $post);
792
+
793
+
794
+
795
+
796
+
797
+ $post_id = wp_insert_post($_post);
798
+
799
+
800
+
801
+ add_action('save_rss_pi_post', $post_id);
802
+
803
+
804
+
805
+ add_post_meta($post_id, 'rss_pi_source_url', esc_url($url));
806
+
807
+
808
+
809
+ return $post_id;
810
+
811
+ }
812
+
813
+
814
+
815
+ }
816
+
app/templates/feed-table-row.php CHANGED
@@ -1,179 +1,358 @@
1
- <?php
2
- $show = '';
3
-
4
- if (!isset($f)) {
5
- $f = array(
6
- 'id' => uniqid(),
7
- 'name' => 'New feed',
8
- 'url' => '',
9
- 'max_posts' => 5,
10
- 'author_id' => 1,
11
- 'category_id' => 1,
12
- 'tags_id' => array(),
13
- 'strip_html' => 'false'
14
- );
15
-
16
- $show = 'show';
17
- }
18
-
19
- if(is_array($f['tags_id'])){
20
- if(!empty($f['tags_id'])){
21
- foreach ( $f['tags_id'] as $tag ) {
22
- $tagname = get_tag($tag);
23
- $tagarray[] = $tagname->name;
24
- }
25
- $tag = join(',', $tagarray);
26
- }
27
- else{
28
- $tag = array();
29
- }
30
-
31
- }else{
32
- if(empty($f['tags_id'])){
33
- $f['tags_id'] = array();
34
- $tag = '';
35
- }
36
- else{
37
- $f['tags_id'] = array($f['tags_id']);
38
- $tagname = get_tag(intval($f['tags_id']));
39
- $tag = $tagname->name;
40
- }
41
-
42
- }
43
-
44
- /*echo "<pre>";
45
- print_r($f);
46
- exit;*/
47
- if(is_array($f['category_id'])){
48
- foreach ( $f['category_id'] as $cat ) {
49
- $catarray[] = get_cat_name($cat);
50
- }
51
- $category = join(',', $catarray);
52
- }else{
53
- if(empty($f['category_id'])){
54
- $f['category_id'] = array(1);
55
- $category = get_the_category_by_ID(1);
56
- }
57
- else{
58
- $f['category_id'] = array($f['category_id']);
59
- $category = get_the_category_by_ID(intval($f['category_id']));
60
- }
61
-
62
- }
63
-
64
- ?>
65
-
66
- <tr id="display_<?php echo ($f['id']); ?>" class="data-row <?php echo $show; ?>">
67
- <td>
68
- <strong><a href="#" class="toggle-edit" data-target="<?php echo ($f['id']); ?>"><?php echo $f['name']; ?></a></strong>
69
- <div class="row-options">
70
- <a href="#" class="toggle-edit" data-target="<?php echo ($f['id']); ?>"><?php _e('Edit', 'rss_pi'); ?></a> |
71
- <a href="#" class="delete-row" data-target="<?php echo ($f['id']); ?>"><?php _e('Delete', 'rss_pi'); ?></a>
72
- </div>
73
- </td>
74
- <td><?php echo $f['url']; ?></td>
75
- <td><?php echo $f['max_posts']; ?></td>
76
- <!-- <td width="20%"><?php //echo $category; ?></td>-->
77
- </tr>
78
- <tr id="edit_<?php echo ($f['id']); ?>" class="edit-row <?php echo $show; ?>">
79
- <td colspan="4">
80
- <table class="widefat edit-table">
81
- <tr>
82
- <td><label for="<?php echo ($f['id']); ?>-name"><?php _e("Feed name", 'rss_pi'); ?></label></td>
83
- <td>
84
- <input type="text" name="<?php echo ($f['id']); ?>-name" id="<?php echo ($f['id']); ?>-name" value="<?php echo ($f['name']); ?>" />
85
- </td>
86
- </tr>
87
- <tr>
88
- <td>
89
- <label for="<?php echo ($f['id']); ?>"><?php _e("Feed url", 'rss_pi'); ?></label>
90
- <p class="description">ie "http://news.google.com/?output=rss"</p>
91
- </td>
92
- <td><input type="text" name="<?php echo ($f['id']); ?>-url" id="<?php echo ($f['id']); ?>-url" value="<?php echo ($f['url']); ?>" /></td>
93
- </tr>
94
- <tr>
95
- <td><label for=""><?php _e("Max posts / import", 'rss_pi'); ?></label></td>
96
- <td><input type="number" name="<?php echo ($f['id']); ?>-max_posts" id="<?php echo ($f['id']); ?>-max_posts" value="<?php echo ($f['max_posts']); ?>" min="1" max="100" /></td>
97
- </tr>
98
- <tr>
99
- <td><label for=""><?php _e("Feed Author", 'rss_pi'); ?></label></td>
100
- <td>
101
- <?php
102
- if(!$this->is_key_valid){
103
- $this->key_error($this->key_prompt, true);
104
- }
105
- $args = array(
106
- 'id' => $f['id'] . '-author_id',
107
- 'name' => $f['id'] . '-author_id',
108
- 'selected' => $f['author_id'],
109
- 'class' => 'rss-pi-specific-feed-author'
110
- );
111
- wp_dropdown_users($args);
112
- ?>
113
- </td>
114
- </tr>
115
- <tr>
116
- <td><label for=""><?php _e("Category", 'rss_pi'); ?></label></td>
117
- <td>
118
- <?php
119
- $rss_post_pi_admin = new rssPIAdmin();
120
- $disabled = '';
121
- if (!$this->is_key_valid) {
122
- $this->key_error($this->key_prompt_multiple_category, true);
123
- wp_dropdown_categories(array('hide_empty' => 0, 'hierarchical' => true, 'id' => $f['id'] . '-category_id', 'name' => $f['id'] . '-category_id', 'selected' => $f['category_id']));
124
- }
125
- else{
126
- ?>
127
- <div class="category_container">
128
- <?php
129
-
130
- $allcats = $rss_post_pi_admin->wp_category_checklist_rss_pi(0, false,$f['category_id']);
131
- $allcats = str_replace( 'name="post_category[]"', 'name="'.$f['id'].'-category_id[]"', $allcats );
132
- echo $allcats;
133
- ?></div>
134
- <?php
135
- }
136
- ?>
137
- </td>
138
- </tr>
139
- <tr>
140
- <td><label for=""><?php _e("Tags", 'rss_pi'); ?></label></td>
141
- <td>
142
- <?php
143
- $disabled = '';
144
- if (!$this->is_key_valid) {
145
- $this->key_error($this->key_prompt_multiple_tags, true);
146
- echo $rss_post_pi_admin->rss_pi_tags_dropdown($f['id'],$f['tags_id']);
147
- }
148
- else{
149
- ?>
150
- <div class="tags_container">
151
- <?php
152
- echo $rss_post_pi_admin->rss_pi_tags_checkboxes($f['id'],$f['tags_id']);
153
- ?></div>
154
- <?php
155
- }
156
- ?>
157
- </td>
158
- </tr>
159
- <tr>
160
- <td><label for=""><?php _e("Strip html tags", 'rss_pi'); ?></label></td>
161
- <td>
162
- <ul class="radiolist">
163
- <li>
164
- <label><input type="radio" id="<?php echo($f['id']); ?>-strip_html" name="<?php echo($f['id']); ?>-strip_html" value="true" <?php echo($f['strip_html'] == 'true' ? 'checked="checked"' : ''); ?> /> <?php _e('Yes', 'rss_pi'); ?></label>
165
- </li>
166
- <li>
167
- <label><input type="radio" id="<?php echo($f['id']); ?>-strip_html" name="<?php echo($f['id']); ?>-strip_html" value="false" <?php echo($f['strip_html'] == 'false' ? 'checked="checked"' : ''); ?> /> <?php _e('No', 'rss_pi'); ?></label>
168
- </li>
169
- </ul>
170
- </td>
171
- </tr>
172
- <tr>
173
- <td><input type="hidden" name="id" value="<?php echo($f['id']); ?>" /></td>
174
- <td><a id="close-edit-table" class="button button-large toggle-edit" data-target="<?php echo ($f['id']); ?>"><?php _e('Close', 'rss_pi'); ?></a></td>
175
- </tr>
176
- </table>
177
-
178
- </td>
179
- </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $show = '';
4
+
5
+
6
+
7
+ if (!isset($f)) {
8
+
9
+ $f = array(
10
+
11
+ 'id' => uniqid(),
12
+
13
+ 'name' => 'New feed',
14
+
15
+ 'url' => '',
16
+
17
+ 'max_posts' => 5,
18
+
19
+ 'author_id' => 1,
20
+
21
+ 'category_id' => 1,
22
+
23
+ 'tags_id' => array(),
24
+
25
+ 'strip_html' => 'false'
26
+
27
+ );
28
+
29
+
30
+
31
+ $show = 'show';
32
+
33
+ }
34
+
35
+
36
+
37
+ if(is_array($f['tags_id'])){
38
+
39
+ if(!empty($f['tags_id'])){
40
+
41
+ foreach ( $f['tags_id'] as $tag ) {
42
+
43
+ $tagname = get_tag($tag);
44
+
45
+ $tagarray[] = $tagname->name;
46
+
47
+ }
48
+
49
+ $tag = join(',', $tagarray);
50
+
51
+ }
52
+
53
+ else{
54
+
55
+ $tag = array();
56
+
57
+ }
58
+
59
+
60
+
61
+ }else{
62
+
63
+ if(empty($f['tags_id'])){
64
+
65
+ $f['tags_id'] = array();
66
+
67
+ $tag = '';
68
+
69
+ }
70
+
71
+ else{
72
+
73
+ $f['tags_id'] = array($f['tags_id']);
74
+
75
+ $tagname = get_tag(intval($f['tags_id']));
76
+
77
+ $tag = $tagname->name;
78
+
79
+ }
80
+
81
+
82
+
83
+ }
84
+
85
+
86
+
87
+ /*echo "<pre>";
88
+
89
+ print_r($f);
90
+
91
+ exit;*/
92
+
93
+ if(is_array($f['category_id'])){
94
+
95
+ foreach ( $f['category_id'] as $cat ) {
96
+
97
+ $catarray[] = get_cat_name($cat);
98
+
99
+ }
100
+
101
+ $category = join(',', $catarray);
102
+
103
+ }else{
104
+
105
+ if(empty($f['category_id'])){
106
+
107
+ $f['category_id'] = array(1);
108
+
109
+ $category = get_the_category_by_ID(1);
110
+
111
+ }
112
+
113
+ else{
114
+
115
+ $f['category_id'] = array($f['category_id']);
116
+
117
+ $category = get_the_category_by_ID(intval($f['category_id']));
118
+
119
+ }
120
+
121
+
122
+
123
+ }
124
+
125
+
126
+
127
+ ?>
128
+
129
+
130
+
131
+ <tr id="display_<?php echo ($f['id']); ?>" class="data-row <?php echo $show; ?>">
132
+
133
+ <td>
134
+
135
+ <strong><a href="#" class="toggle-edit" data-target="<?php echo ($f['id']); ?>"><?php echo $f['name']; ?></a></strong>
136
+
137
+ <div class="row-options">
138
+
139
+ <a href="#" class="toggle-edit" data-target="<?php echo ($f['id']); ?>"><?php _e('Edit', 'rss_pi'); ?></a> |
140
+
141
+ <a href="#" class="delete-row" data-target="<?php echo ($f['id']); ?>"><?php _e('Delete', 'rss_pi'); ?></a>
142
+
143
+ </div>
144
+
145
+ </td>
146
+
147
+ <td><?php echo $f['url']; ?></td>
148
+
149
+ <td><?php echo $f['max_posts']; ?></td>
150
+
151
+ <!-- <td width="20%"><?php //echo $category; ?></td>-->
152
+
153
+ </tr>
154
+
155
+ <tr id="edit_<?php echo ($f['id']); ?>" class="edit-row <?php echo $show; ?>">
156
+
157
+ <td colspan="4">
158
+
159
+ <table class="widefat edit-table">
160
+
161
+ <tr>
162
+
163
+ <td><label for="<?php echo ($f['id']); ?>-name"><?php _e("Feed name", 'rss_pi'); ?></label></td>
164
+
165
+ <td>
166
+
167
+ <input type="text" name="<?php echo ($f['id']); ?>-name" id="<?php echo ($f['id']); ?>-name" value="<?php echo ($f['name']); ?>" />
168
+
169
+ </td>
170
+
171
+ </tr>
172
+
173
+ <tr>
174
+
175
+ <td>
176
+
177
+ <label for="<?php echo ($f['id']); ?>"><?php _e("Feed url", 'rss_pi'); ?></label>
178
+
179
+ <p class="description">ie "http://news.google.com/?output=rss"</p>
180
+
181
+ </td>
182
+
183
+ <td><input type="text" name="<?php echo ($f['id']); ?>-url" id="<?php echo ($f['id']); ?>-url" value="<?php echo ($f['url']); ?>" /></td>
184
+
185
+ </tr>
186
+
187
+ <tr>
188
+
189
+ <td><label for=""><?php _e("Max posts / import", 'rss_pi'); ?></label></td>
190
+
191
+ <td><input type="number" name="<?php echo ($f['id']); ?>-max_posts" id="<?php echo ($f['id']); ?>-max_posts" value="<?php echo ($f['max_posts']); ?>" min="1" max="100" /></td>
192
+
193
+ </tr>
194
+
195
+ <tr>
196
+
197
+ <td><label for=""><?php _e("Feed Author", 'rss_pi'); ?></label></td>
198
+
199
+ <td>
200
+
201
+ <?php
202
+
203
+ if(!$this->is_key_valid){
204
+
205
+ $this->key_error($this->key_prompt, true);
206
+
207
+ }
208
+
209
+ $args = array(
210
+
211
+ 'id' => $f['id'] . '-author_id',
212
+
213
+ 'name' => $f['id'] . '-author_id',
214
+
215
+ 'selected' => $f['author_id'],
216
+
217
+ 'class' => 'rss-pi-specific-feed-author'
218
+
219
+ );
220
+
221
+ wp_dropdown_users($args);
222
+
223
+ ?>
224
+
225
+ </td>
226
+
227
+ </tr>
228
+
229
+ <tr>
230
+
231
+ <td><label for=""><?php _e("Category", 'rss_pi'); ?></label></td>
232
+
233
+ <td>
234
+
235
+ <?php
236
+
237
+ $rss_post_pi_admin = new rssPIAdmin();
238
+
239
+ $disabled = '';
240
+
241
+ if (!$this->is_key_valid) {
242
+
243
+ $this->key_error($this->key_prompt_multiple_category, true);
244
+
245
+ wp_dropdown_categories(array('hide_empty' => 0, 'hierarchical' => true, 'id' => $f['id'] . '-category_id', 'name' => $f['id'] . '-category_id', 'selected' => $f['category_id'][0]));
246
+
247
+ }
248
+
249
+ else{
250
+
251
+ ?>
252
+
253
+ <div class="category_container">
254
+
255
+ <?php
256
+
257
+
258
+
259
+ $allcats = $rss_post_pi_admin->wp_category_checklist_rss_pi(0, false,$f['category_id']);
260
+
261
+ $allcats = str_replace( 'name="post_category[]"', 'name="'.$f['id'].'-category_id[]"', $allcats );
262
+
263
+ echo $allcats;
264
+
265
+ ?></div>
266
+
267
+ <?php
268
+
269
+ }
270
+
271
+ ?>
272
+
273
+ </td>
274
+
275
+ </tr>
276
+
277
+ <tr>
278
+
279
+ <td><label for=""><?php _e("Tags", 'rss_pi'); ?></label></td>
280
+
281
+ <td>
282
+
283
+ <?php
284
+
285
+ $disabled = '';
286
+
287
+ if (!$this->is_key_valid) {
288
+
289
+ $this->key_error($this->key_prompt_multiple_tags, true);
290
+
291
+ echo $rss_post_pi_admin->rss_pi_tags_dropdown($f['id'],$f['tags_id']);
292
+
293
+ }
294
+
295
+ else{
296
+
297
+ ?>
298
+
299
+ <div class="tags_container">
300
+
301
+ <?php
302
+
303
+ echo $rss_post_pi_admin->rss_pi_tags_checkboxes($f['id'],$f['tags_id']);
304
+
305
+ ?></div>
306
+
307
+ <?php
308
+
309
+ }
310
+
311
+ ?>
312
+
313
+ </td>
314
+
315
+ </tr>
316
+
317
+ <tr>
318
+
319
+ <td><label for=""><?php _e("Strip html tags", 'rss_pi'); ?></label></td>
320
+
321
+ <td>
322
+
323
+ <ul class="radiolist">
324
+
325
+ <li>
326
+
327
+ <label><input type="radio" id="<?php echo($f['id']); ?>-strip_html" name="<?php echo($f['id']); ?>-strip_html" value="true" <?php echo($f['strip_html'] == 'true' ? 'checked="checked"' : ''); ?> /> <?php _e('Yes', 'rss_pi'); ?></label>
328
+
329
+ </li>
330
+
331
+ <li>
332
+
333
+ <label><input type="radio" id="<?php echo($f['id']); ?>-strip_html" name="<?php echo($f['id']); ?>-strip_html" value="false" <?php echo($f['strip_html'] == 'false' ? 'checked="checked"' : ''); ?> /> <?php _e('No', 'rss_pi'); ?></label>
334
+
335
+ </li>
336
+
337
+ </ul>
338
+
339
+ </td>
340
+
341
+ </tr>
342
+
343
+ <tr>
344
+
345
+ <td><input type="hidden" name="id" value="<?php echo($f['id']); ?>" /></td>
346
+
347
+ <td><a id="close-edit-table" class="button button-large toggle-edit" data-target="<?php echo ($f['id']); ?>"><?php _e('Close', 'rss_pi'); ?></a></td>
348
+
349
+ </tr>
350
+
351
+ </table>
352
+
353
+
354
+
355
+ </td>
356
+
357
+ </tr>
358
+
index.php CHANGED
@@ -12,7 +12,7 @@
12
 
13
  Author: feedsapi
14
 
15
- Version: 2.0.7
16
 
17
  Author URI: https://www.feedsapi.org/
18
 
@@ -58,7 +58,7 @@ if (!defined('RSS_PI_BASENAME')) {
58
 
59
  if (!defined('RSS_PI_VERSION')) {
60
 
61
- define('RSS_PI_VERSION', '2.0.7');
62
 
63
  }
64
 
12
 
13
  Author: feedsapi
14
 
15
+ Version: 2.0.9
16
 
17
  Author URI: https://www.feedsapi.org/
18
 
58
 
59
  if (!defined('RSS_PI_VERSION')) {
60
 
61
+ define('RSS_PI_VERSION', '2.0.9');
62
 
63
  }
64
 
readme.txt CHANGED
@@ -12,7 +12,7 @@ Requires at least: 3.5
12
 
13
  Tested up to: 4.1
14
 
15
- Stable tag: 2.0.7
16
 
17
  License: GPLv2 or later
18
 
@@ -162,6 +162,21 @@ WP-o-Matic , WP-o-Matic, RSSImport, FeedWordPress, Syndicate Press, FeedWeb, RSS
162
 
163
  == Change Log ==
164
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
 
166
 
167
  = Version 2.0.6 =
12
 
13
  Tested up to: 4.1
14
 
15
+ Stable tag: 2.0.9
16
 
17
  License: GPLv2 or later
18
 
162
 
163
  == Change Log ==
164
 
165
+ = Version 2.0.9 =
166
+
167
+ * Bug fixed and Improvements in code.
168
+
169
+
170
+ = Version 2.0.8 =
171
+
172
+ * default category always selected issue resolved.
173
+
174
+ * {excerpt:n} not working - Fixed.
175
+
176
+
177
+ = Version 2.0.7 =
178
+
179
+ * Bug fixed and Improvements in code.
180
 
181
 
182
  = Version 2.0.6 =