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