Version Description
Download this release
Release Info
Developer | phpaddicted |
Plugin | 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 +0 -0
- app/assets/font/fontawesome-webfont.svg +0 -0
- app/assets/font/fontawesome-webfont.ttf +0 -0
- app/assets/font/fontawesome-webfont.woff +0 -0
- app/class-rss-post-importer.php +256 -128
- app/classes/helpers/class-rss-pi-parser.php +5 -8
- app/classes/import/class-rss-pi-engine.php +816 -408
- app/templates/feed-table-row.php +358 -179
- index.php +2 -2
- readme.txt +16 -1
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 |
-
|
4 |
-
|
5 |
-
*
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
}
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
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 |
-
|
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 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
'
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
return $
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
*
|
164 |
-
|
165 |
-
* @param array $
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
$
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
*
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
*
|
380 |
-
|
381 |
-
* @
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
private function
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
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 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
'
|
12 |
-
|
13 |
-
'
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
$
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
$
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
<
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
</tr>
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
</
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
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.
|
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.
|
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 =
|