1 | <?php
|
---|
2 | /**
|
---|
3 | * Jeromes Keyword Plugin Importer
|
---|
4 | *
|
---|
5 | * @package WordPress
|
---|
6 | * @subpackage Importer
|
---|
7 | */
|
---|
8 |
|
---|
9 | /**
|
---|
10 | * Jeromes Keyword Plugin Importer class
|
---|
11 | *
|
---|
12 | * Will convert Jeromes Keyword Plugin tags to WordPress taxonomy tags.
|
---|
13 | *
|
---|
14 | * @since 2.3
|
---|
15 | */
|
---|
16 | class JeromesKeyword_Import {
|
---|
17 |
|
---|
18 | function header() {
|
---|
19 | echo '<div class="wrap">';
|
---|
20 | screen_icon();
|
---|
21 | echo '<h2>'.__('Import Jerome’s Keywords').'</h2>';
|
---|
22 | echo '<p>'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'<br /><br /></p>';
|
---|
23 | }
|
---|
24 |
|
---|
25 | function footer() {
|
---|
26 | echo '</div>';
|
---|
27 | }
|
---|
28 |
|
---|
29 | function greet() {
|
---|
30 | echo '<div class="narrow">';
|
---|
31 | echo '<p>'.__('Howdy! This imports tags from Jerome’s Keywords into WordPress tags.').'</p>';
|
---|
32 | echo '<p>'.__('This is suitable for Jerome’s Keywords version 1.x and 2.0a.').'</p>';
|
---|
33 | echo '<p><strong>'.__('All existing Jerome’s Keywords will be removed after import.').'</strong></p>';
|
---|
34 | echo '<p><strong>'.__('Don’t be stupid - backup your database before proceeding!').'</strong></p>';
|
---|
35 | echo '<form action="admin.php?import=jkw&step=1" method="post">';
|
---|
36 | wp_nonce_field('import-jkw');
|
---|
37 | echo '<p class="submit"><input type="submit" name="submit" class="button" value="'.esc_attr__('Import Version 1.x').'" /></p>';
|
---|
38 | echo '</form>';
|
---|
39 | echo '<form action="admin.php?import=jkw&step=3" method="post">';
|
---|
40 | wp_nonce_field('import-jkw');
|
---|
41 | echo '<p class="submit"><input type="submit" name="submit" class="button" value="'.esc_attr__('Import Version 2.0a').'" /></p>';
|
---|
42 | echo '</form>';
|
---|
43 | echo '</div>';
|
---|
44 | }
|
---|
45 |
|
---|
46 | function dispatch() {
|
---|
47 | if ( empty($_GET['step']) )
|
---|
48 | $step = 0;
|
---|
49 | else
|
---|
50 | $step = absint($_GET['step']);
|
---|
51 |
|
---|
52 | // load the header
|
---|
53 | $this->header();
|
---|
54 |
|
---|
55 | switch ( $step ) {
|
---|
56 | case 0 :
|
---|
57 | $this->greet();
|
---|
58 | break;
|
---|
59 | case 1 :
|
---|
60 | check_admin_referer('import-jkw');
|
---|
61 | $this->check_V1_post_keyword( true );
|
---|
62 | break;
|
---|
63 | case 2 :
|
---|
64 | check_admin_referer('import-jkw');
|
---|
65 | $this->check_V1_post_keyword( false );
|
---|
66 | break;
|
---|
67 | case 3 :
|
---|
68 | check_admin_referer('import-jkw');
|
---|
69 | $this->check_V2_post_keyword( true );
|
---|
70 | break;
|
---|
71 | case 4 :
|
---|
72 | check_admin_referer('import-jkw');
|
---|
73 | $this->check_V2_post_keyword( false );
|
---|
74 | break;
|
---|
75 | case 5:
|
---|
76 | check_admin_referer('import-jkw');
|
---|
77 | $this->cleanup_V2_import();
|
---|
78 | break;
|
---|
79 | case 6:
|
---|
80 | $this->done();
|
---|
81 | break;
|
---|
82 | }
|
---|
83 |
|
---|
84 | // load the footer
|
---|
85 | $this->footer();
|
---|
86 | }
|
---|
87 |
|
---|
88 | function check_V1_post_keyword($precheck = true) {
|
---|
89 | global $wpdb;
|
---|
90 |
|
---|
91 | echo '<div class="narrow">';
|
---|
92 | echo '<p><h3>'.__('Reading Jerome’s Keywords Tags…').'</h3></p>';
|
---|
93 |
|
---|
94 | // import Jerome's Keywords tags
|
---|
95 | $metakeys = $wpdb->get_results("SELECT post_id, meta_id, meta_key, meta_value FROM $wpdb->postmeta WHERE $wpdb->postmeta.meta_key = 'keywords'");
|
---|
96 | if ( !is_array($metakeys)) {
|
---|
97 | echo '<p>' . __('No Tags Found!') . '</p>';
|
---|
98 | return false;
|
---|
99 | } else {
|
---|
100 | $count = count($metakeys);
|
---|
101 | echo '<p>' . sprintf( _n('Done! <strong>%s</strong> post with tags were read.', 'Done! <strong>%s</strong> posts with tags were read.', $count), $count ) . '<br /></p>';
|
---|
102 | echo '<ul>';
|
---|
103 | foreach ( $metakeys as $post_meta ) {
|
---|
104 | if ( $post_meta->meta_value != '' ) {
|
---|
105 | $post_keys = explode(',', $post_meta->meta_value);
|
---|
106 | foreach ( $post_keys as $keyword ) {
|
---|
107 | $keyword = addslashes(trim($keyword));
|
---|
108 | if ( '' != $keyword ) {
|
---|
109 | echo '<li>' . $post_meta->post_id . ' - ' . $keyword . '</li>';
|
---|
110 | if ( !$precheck )
|
---|
111 | wp_add_post_tags($post_meta->post_id, $keyword);
|
---|
112 | }
|
---|
113 | }
|
---|
114 | }
|
---|
115 | if ( !$precheck )
|
---|
116 | delete_post_meta($post_meta->post_id, 'keywords');
|
---|
117 | }
|
---|
118 | echo '</ul>';
|
---|
119 | }
|
---|
120 |
|
---|
121 | echo '<form action="admin.php?import=jkw&step='.($precheck? 2:6).'" method="post">';
|
---|
122 | wp_nonce_field('import-jkw');
|
---|
123 | echo '<p class="submit"><input type="submit" name="submit" class="button" value="'.esc_attr__('Next').'" /></p>';
|
---|
124 | echo '</form>';
|
---|
125 | echo '</div>';
|
---|
126 | }
|
---|
127 |
|
---|
128 | function check_V2_post_keyword($precheck = true) {
|
---|
129 | global $wpdb;
|
---|
130 |
|
---|
131 | echo '<div class="narrow">';
|
---|
132 | echo '<p><h3>'.__('Reading Jerome’s Keywords Tags…').'</h3></p>';
|
---|
133 |
|
---|
134 | // import Jerome's Keywords tags
|
---|
135 | $tablename = $wpdb->prefix . substr(get_option('jkeywords_keywords_table'), 1, -1);
|
---|
136 | $metakeys = $wpdb->get_results("SELECT post_id, tag_name FROM $tablename");
|
---|
137 | if ( !is_array($metakeys) ) {
|
---|
138 | echo '<p>' . __('No Tags Found!') . '</p>';
|
---|
139 | return false;
|
---|
140 | } else {
|
---|
141 | $count = count($metakeys);
|
---|
142 | echo '<p>' . sprintf( _n('Done! <strong>%s</strong> tag were read.', 'Done! <strong>%s</strong> tags were read.', $count), $count ) . '<br /></p>';
|
---|
143 | echo '<ul>';
|
---|
144 | foreach ( $metakeys as $post_meta ) {
|
---|
145 | $keyword = addslashes(trim($post_meta->tag_name));
|
---|
146 | if ( $keyword != '' ) {
|
---|
147 | echo '<li>' . $post_meta->post_id . ' - ' . $keyword . '</li>';
|
---|
148 | if ( !$precheck )
|
---|
149 | wp_add_post_tags($post_meta->post_id, $keyword);
|
---|
150 | }
|
---|
151 | }
|
---|
152 | echo '</ul>';
|
---|
153 | }
|
---|
154 | echo '<form action="admin.php?import=jkw&step='.($precheck? 4:5).'" method="post">';
|
---|
155 | wp_nonce_field('import-jkw');
|
---|
156 | echo '<p class="submit"><input type="submit" name="submit" class="button" value="'.esc_attr__('Next').'" /></p>';
|
---|
157 | echo '</form>';
|
---|
158 | echo '</div>';
|
---|
159 | }
|
---|
160 |
|
---|
161 | function cleanup_V2_import() {
|
---|
162 | global $wpdb;
|
---|
163 |
|
---|
164 | /* options from V2.0a (jeromes-keywords.php) */
|
---|
165 | $options = array('version', 'keywords_table', 'query_varname', 'template', 'meta_always_include', 'meta_includecats', 'meta_autoheader', 'search_strict', 'use_feed_cats', 'post_linkformat', 'post_tagseparator', 'post_includecats', 'post_notagstext', 'cloud_linkformat', 'cloud_tagseparator', 'cloud_includecats', 'cloud_sortorder', 'cloud_displaymax', 'cloud_displaymin', 'cloud_scalemax', 'cloud_scalemin');
|
---|
166 |
|
---|
167 | $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . substr(get_option('jkeywords_keywords_table'), 1, -1));
|
---|
168 |
|
---|
169 | foreach ( $options as $o )
|
---|
170 | delete_option('jkeywords_' . $o);
|
---|
171 |
|
---|
172 | $this->done();
|
---|
173 | }
|
---|
174 |
|
---|
175 | function done() {
|
---|
176 | echo '<div class="narrow">';
|
---|
177 | echo '<p><h3>'.__('Import Complete!').'</h3></p>';
|
---|
178 | echo '</div>';
|
---|
179 | }
|
---|
180 |
|
---|
181 | function JeromesKeyword_Import() {
|
---|
182 | }
|
---|
183 |
|
---|
184 | }
|
---|
185 |
|
---|
186 | // create the import object
|
---|
187 | $jkw_import = new JeromesKeyword_Import();
|
---|
188 |
|
---|
189 | // add it to the import page!
|
---|
190 | register_importer('jkw', 'Jerome’s Keywords', __('Import Jerome’s Keywords into WordPress tags.'), array($jkw_import, 'dispatch'));
|
---|
191 |
|
---|
192 | ?>
|
---|