RSS Importer - Version 0.3

Version Description

  • Removed set_magic_quotes_runtime() for PHP 7 compatibility.
  • Add support for WordPress 6.1
Download this release

Release Info

Developer githubsync
Plugin Icon 128x128 RSS Importer
Version 0.3
Comparing to
See all releases

Version 0.3

Files changed (3) hide show
  1. languages/rss-importer.pot +80 -0
  2. readme.txt +37 -0
  3. rss-importer.php +232 -0
languages/rss-importer.pot ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Translation of the WordPress plugin RSS Importer 0.2 by wordpressdotorg.
2
+ # Copyright (C) 2010 wordpressdotorg
3
+ # This file is distributed under the same license as the RSS Importer package.
4
+ # FIRST AUTHOR <EMAIL@ADDRESS>, 2010.
5
+ #
6
+ #, fuzzy
7
+ msgid ""
8
+ msgstr ""
9
+ "Project-Id-Version: RSS Importer 0.2\n"
10
+ "Report-Msgid-Bugs-To: http://wordpress.org/tag/rss-importer\n"
11
+ "POT-Creation-Date: 2010-06-01 13:26+0300\n"
12
+ "PO-Revision-Date: 2010-MO-DA HO:MI+ZONE\n"
13
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
+ "Language-Team: LANGUAGE <LL@li.org>\n"
15
+ "MIME-Version: 1.0\n"
16
+ "Content-Type: text/plain; charset=utf-8\n"
17
+ "Content-Transfer-Encoding: 8bit\n"
18
+
19
+ #: rss-importer.php:50
20
+ msgid "Import RSS"
21
+ msgstr ""
22
+
23
+ #: rss-importer.php:59
24
+ msgid ""
25
+ "Howdy! This importer allows you to extract posts from an RSS 2.0 file into "
26
+ "your WordPress site. This is useful if you want to import your posts from a "
27
+ "system that is not handled by a custom import tool. Pick an RSS file to "
28
+ "upload and click Import."
29
+ msgstr ""
30
+
31
+ #: rss-importer.php:143
32
+ msgid "Importing post..."
33
+ msgstr ""
34
+
35
+ #: rss-importer.php:148
36
+ msgid "Post already imported"
37
+ msgstr ""
38
+
39
+ #: rss-importer.php:154
40
+ msgid "Couldn&#8217;t get post ID"
41
+ msgstr ""
42
+
43
+ #: rss-importer.php:160
44
+ msgid "Done!"
45
+ msgstr ""
46
+
47
+ #: rss-importer.php:185
48
+ #, php-format
49
+ msgid "All done. <a href=\"%s\">Have fun!</a>"
50
+ msgstr ""
51
+
52
+ #: rss-importer.php:219
53
+ msgid "RSS"
54
+ msgstr ""
55
+
56
+ #: rss-importer.php:219
57
+ msgid "Import posts from an RSS feed."
58
+ msgstr ""
59
+
60
+ #. Plugin Name of the plugin/theme
61
+ msgid "RSS Importer"
62
+ msgstr ""
63
+
64
+ #. Plugin URI of the plugin/theme
65
+ msgid "http://wordpress.org/extend/plugins/rss-importer/"
66
+ msgstr ""
67
+
68
+ #. Description of the plugin/theme
69
+ msgid ""
70
+ "Import posts from an RSS feed. This plugin depends on the WP_Importer base "
71
+ "class."
72
+ msgstr ""
73
+
74
+ #. Author of the plugin/theme
75
+ msgid "wordpressdotorg"
76
+ msgstr ""
77
+
78
+ #. Author URI of the plugin/theme
79
+ msgid "http://wordpress.org/"
80
+ msgstr ""
readme.txt ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === RSS Importer ===
2
+ Contributors: wordpressdotorg
3
+ Tags: importer, rss
4
+ Requires at least: 3.0
5
+ Tested up to: 6.1
6
+ Stable tag: 0.3
7
+ License: GPLv2 or later
8
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
+
10
+ Import posts from an RSS feed.
11
+
12
+ == Description ==
13
+
14
+ Import posts from an RSS feed.
15
+
16
+ == Installation ==
17
+
18
+ 1. Upload the `rss-importer` folder to the `/wp-content/plugins/` directory
19
+ 1. Activate the plugin through the 'Plugins' menu in WordPress
20
+ 1. Go to the Tools -> Import screen, Click on RSS
21
+
22
+ == Frequently Asked Questions ==
23
+
24
+ == Screenshots ==
25
+
26
+ == Changelog ==
27
+
28
+ = 0.3 =
29
+ * Removed `set_magic_quotes_runtime()` for PHP 7 compatibility.
30
+ * Add support for WordPress 6.1
31
+
32
+ = 0.2 =
33
+ * Update compat
34
+ * Add text domain headers
35
+
36
+ = 0.1 =
37
+ * Initial release
rss-importer.php ADDED
@@ -0,0 +1,232 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: RSS Importer
4
+ Plugin URI: http://wordpress.org/extend/plugins/rss-importer/
5
+ Description: Import posts from an RSS feed.
6
+ Author: wordpressdotorg
7
+ Author URI: http://wordpress.org/
8
+ Version: 0.3
9
+ Stable tag: 0.3
10
+ License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11
+ Text Domain: rss-importer
12
+ */
13
+ if ( !defined('WP_LOAD_IMPORTERS') ) {
14
+ return;
15
+ }
16
+
17
+ // Load Importer API
18
+ require_once ABSPATH . 'wp-admin/includes/import.php';
19
+
20
+ if ( !class_exists( 'WP_Importer' ) ) {
21
+ $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
22
+ if ( file_exists( $class_wp_importer ) )
23
+ require_once $class_wp_importer;
24
+ }
25
+
26
+ /**
27
+ * RSS Importer
28
+ *
29
+ * @package WordPress
30
+ * @subpackage Importer
31
+ */
32
+
33
+ /**
34
+ * RSS Importer
35
+ *
36
+ * Will process a RSS feed for importing posts into WordPress. This is a very
37
+ * limited importer and should only be used as the last resort, when no other
38
+ * importer is available.
39
+ *
40
+ * @since unknown
41
+ */
42
+ if ( class_exists( 'WP_Importer' ) ) {
43
+ class RSS_Import extends WP_Importer {
44
+
45
+ var $posts = array ();
46
+ var $file;
47
+
48
+ function header() {
49
+ echo '<div class="wrap">';
50
+
51
+ if ( version_compare( get_bloginfo( 'version' ), '3.8.0', '<' ) ) {
52
+ screen_icon();
53
+ }
54
+
55
+ echo '<h2>'.__('Import RSS', 'rss-importer').'</h2>';
56
+ }
57
+
58
+ function footer() {
59
+ echo '</div>';
60
+ }
61
+
62
+ function greet() {
63
+ echo '<div class="narrow">';
64
+ echo '<p>'.__('Howdy! This importer allows you to extract posts from an RSS 2.0 file into your WordPress site. This is useful if you want to import your posts from a system that is not handled by a custom import tool. Pick an RSS file to upload and click Import.', 'rss-importer').'</p>';
65
+ wp_import_upload_form("admin.php?import=rss&amp;step=1");
66
+ echo '</div>';
67
+ }
68
+
69
+ function _normalize_tag( $matches ) {
70
+ return '<' . strtolower( $matches[1] );
71
+ }
72
+
73
+ function get_posts() {
74
+ global $wpdb;
75
+
76
+ $datalines = file($this->file); // Read the file into an array
77
+ $importdata = implode('', $datalines); // squish it
78
+ $importdata = str_replace(array ("\r\n", "\r"), "\n", $importdata);
79
+
80
+ preg_match_all('|<item>(.*?)</item>|is', $importdata, $this->posts);
81
+ $this->posts = $this->posts[1];
82
+ $index = 0;
83
+ foreach ($this->posts as $post) {
84
+ preg_match('|<title>(.*?)</title>|is', $post, $post_title);
85
+ $post_title = str_replace(array('<![CDATA[', ']]>'), '', esc_sql( trim($post_title[1]) ) );
86
+
87
+ preg_match('|<pubdate>(.*?)</pubdate>|is', $post, $post_date_gmt);
88
+
89
+ if ($post_date_gmt) {
90
+ $post_date_gmt = strtotime($post_date_gmt[1]);
91
+ } else {
92
+ // if we don't already have something from pubDate
93
+ preg_match('|<dc:date>(.*?)</dc:date>|is', $post, $post_date_gmt);
94
+ $post_date_gmt = preg_replace('|([-+])([0-9]+):([0-9]+)$|', '\1\2\3', $post_date_gmt[1]);
95
+ $post_date_gmt = str_replace('T', ' ', $post_date_gmt);
96
+ $post_date_gmt = strtotime($post_date_gmt);
97
+ }
98
+
99
+ $post_date_gmt = gmdate('Y-m-d H:i:s', $post_date_gmt);
100
+ $post_date = get_date_from_gmt( $post_date_gmt );
101
+
102
+ preg_match_all('|<category>(.*?)</category>|is', $post, $categories);
103
+ $categories = $categories[1];
104
+
105
+ if (!$categories) {
106
+ preg_match_all('|<dc:subject>(.*?)</dc:subject>|is', $post, $categories);
107
+ $categories = $categories[1];
108
+ }
109
+
110
+ $cat_index = 0;
111
+ foreach ($categories as $category) {
112
+ $categories[$cat_index] = esc_sql( html_entity_decode( $category ) );
113
+ $cat_index++;
114
+ }
115
+
116
+ preg_match('|<guid.*?>(.*?)</guid>|is', $post, $guid);
117
+ if ( $guid ) {
118
+ $guid = esc_sql( trim( $guid[1] ) );
119
+ } else {
120
+ $guid = '';
121
+ }
122
+
123
+ preg_match('|<content:encoded>(.*?)</content:encoded>|is', $post, $post_content);
124
+
125
+ if ( count( $post_content ) > 1 ) {
126
+ $post_content = str_replace( array( '<![CDATA[', ']]>'), '', esc_sql( trim( $post_content[1] ) ) );
127
+ } else {
128
+ $post_content = null;
129
+ }
130
+
131
+ if (!$post_content) {
132
+ // This is for feeds that put content in description
133
+ preg_match('|<description>(.*?)</description>|is', $post, $post_content);
134
+ $post_content = esc_sql( html_entity_decode( trim( $post_content[1] ) ) );
135
+ }
136
+
137
+ // Clean up content
138
+ $post_content = preg_replace_callback('|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_content);
139
+ $post_content = str_replace('<br>', '<br />', $post_content);
140
+ $post_content = str_replace('<hr>', '<hr />', $post_content);
141
+
142
+ $post_author = 1;
143
+ $post_status = 'publish';
144
+ $this->posts[$index] = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_status', 'guid', 'categories');
145
+ $index++;
146
+ }
147
+ }
148
+
149
+ function import_posts() {
150
+ echo '<ol>';
151
+
152
+ foreach ($this->posts as $post) {
153
+ echo "<li>".__('Importing post...', 'rss-importer');
154
+
155
+ extract($post);
156
+
157
+ if ($post_id = post_exists($post_title, $post_content, $post_date)) {
158
+ _e('Post already imported', 'rss-importer');
159
+ } else {
160
+ $post_id = wp_insert_post($post);
161
+ if ( is_wp_error( $post_id ) )
162
+ return $post_id;
163
+ if (!$post_id) {
164
+ _e('Couldn&#8217;t get post ID', 'rss-importer');
165
+ return;
166
+ }
167
+
168
+ if (0 != count($categories))
169
+ wp_create_categories($categories, $post_id);
170
+ _e('Done!', 'rss-importer');
171
+ }
172
+ echo '</li>';
173
+ }
174
+
175
+ echo '</ol>';
176
+
177
+ }
178
+
179
+ function import() {
180
+ $file = wp_import_handle_upload();
181
+ if ( isset($file['error']) ) {
182
+ echo $file['error'];
183
+ return;
184
+ }
185
+
186
+ $this->file = $file['file'];
187
+ $this->get_posts();
188
+ $result = $this->import_posts();
189
+ if ( is_wp_error( $result ) )
190
+ return $result;
191
+ wp_import_cleanup($file['id']);
192
+ do_action('import_done', 'rss');
193
+
194
+ echo '<h3>';
195
+ printf(__('All done. <a href="%s">Have fun!</a>', 'rss-importer'), get_option('home'));
196
+ echo '</h3>';
197
+ }
198
+
199
+ function dispatch() {
200
+ if (empty ($_GET['step']))
201
+ $step = 0;
202
+ else
203
+ $step = (int) $_GET['step'];
204
+
205
+ $this->header();
206
+
207
+ switch ($step) {
208
+ case 0 :
209
+ $this->greet();
210
+ break;
211
+ case 1 :
212
+ check_admin_referer('import-upload');
213
+ $result = $this->import();
214
+ if ( is_wp_error( $result ) )
215
+ echo $result->get_error_message();
216
+ break;
217
+ }
218
+
219
+ $this->footer();
220
+ }
221
+ }
222
+
223
+ $rss_import = new RSS_Import();
224
+
225
+ register_importer('rss', __('RSS', 'rss-importer'), __('Import posts from an RSS feed.', 'rss-importer'), array ($rss_import, 'dispatch'));
226
+
227
+ } // class_exists( 'WP_Importer' )
228
+
229
+ function rss_importer_init() {
230
+ load_plugin_textdomain( 'rss-importer', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
231
+ }
232
+ add_action( 'init', 'rss_importer_init' );