1 | <?php |
---|
2 | |
---|
3 | class JeromesKeyword_Import { |
---|
4 | |
---|
5 | function header() { |
---|
6 | echo '<div class="wrap">'; |
---|
7 | echo '<h2>'.__('Import Jerome’s Keywords').'</h2>'; |
---|
8 | echo '<p>'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'<br /><br /></p>'; |
---|
9 | } |
---|
10 | |
---|
11 | function footer() { |
---|
12 | echo '</div>'; |
---|
13 | } |
---|
14 | |
---|
15 | function greet() { |
---|
16 | echo '<div class="narrow">'; |
---|
17 | echo '<p>'.__('Howdy! This imports tags from an existing Jerome’s Keywords installation into this blog using the new WordPress native tagging structure.').'</p>'; |
---|
18 | echo '<p>'.__('This is suitable for Jerome’s Keywords version 1.x and 2.0a.').'</p>'; |
---|
19 | echo '<p><strong>'.__('All existing Jerome’s Keywords will be removed after import.').'</strong></p>'; |
---|
20 | echo '<p><strong>'.__('Don’t be stupid - backup your database before proceeding!').'</strong></p>'; |
---|
21 | echo '<p><em>'.__('Source code is modified from Ultimate Tag Warrior importer (utw.php), and Jerome’s importer code of LightPress').'</em></p>'; |
---|
22 | echo '<form action="admin.php?import=jkw&step=1" method="post">'; |
---|
23 | echo '<p class="submit"><input type="submit" name="submit" value="'.__('Import Version 1.x, Next »').'" /></p>'; |
---|
24 | echo '</form>'; |
---|
25 | echo '<form action="admin.php?import=jkw&step=3" method="post">'; |
---|
26 | echo '<p class="submit"><input type="submit" name="submit" value="'.__('Import Version 2.0a, Next »').'" /></p>'; |
---|
27 | echo '</form>'; |
---|
28 | echo '</div>'; |
---|
29 | } |
---|
30 | |
---|
31 | |
---|
32 | function dispatch () { |
---|
33 | if ( empty( $_GET['step'] ) ) { |
---|
34 | $step = 0; |
---|
35 | } else { |
---|
36 | $step = (int) $_GET['step']; |
---|
37 | } |
---|
38 | |
---|
39 | // load the header |
---|
40 | $this->header(); |
---|
41 | |
---|
42 | switch ( $step ) { |
---|
43 | case 0 : |
---|
44 | $this->greet(); |
---|
45 | break; |
---|
46 | case 1 : |
---|
47 | $this->check_V1_post_keyword( true ); |
---|
48 | break; |
---|
49 | case 2 : |
---|
50 | $this->check_V1_post_keyword( false ); |
---|
51 | break; |
---|
52 | case 3 : |
---|
53 | $this->check_V2_post_keyword( true ); |
---|
54 | break; |
---|
55 | case 4 : |
---|
56 | $this->check_V2_post_keyword( false ); |
---|
57 | break; |
---|
58 | case 5: |
---|
59 | $this->cleanup_V2_import(); |
---|
60 | break; |
---|
61 | case 6: |
---|
62 | $this->done(); |
---|
63 | break; |
---|
64 | } |
---|
65 | |
---|
66 | // load the footer |
---|
67 | $this->footer(); |
---|
68 | } |
---|
69 | |
---|
70 | |
---|
71 | function check_V1_post_keyword ( $precheck = true ) { |
---|
72 | global $wpdb; |
---|
73 | |
---|
74 | echo '<div class="narrow">'; |
---|
75 | echo '<p><h3>'.__('Reading Jerome’s Keywords Tags…').'</h3></p>'; |
---|
76 | |
---|
77 | // import Jerome's Keywords tags |
---|
78 | $qry = "SELECT post_id, meta_id, meta_key, meta_value |
---|
79 | FROM $wpdb->postmeta |
---|
80 | WHERE $wpdb->postmeta.meta_key = 'keywords'"; |
---|
81 | $metakeys = $wpdb->get_results($qry); |
---|
82 | if ( !is_array($metakeys)) { |
---|
83 | echo '<p>' . __('No Tags Found!') . '</p>'; |
---|
84 | return false; |
---|
85 | } |
---|
86 | else { |
---|
87 | $count = count($metakeys); |
---|
88 | echo '<p>' . sprintf( __('Done! <strong>%s</strong> posts with tags were read.'), $count ) . '<br /></p>'; |
---|
89 | |
---|
90 | echo '<ul>'; |
---|
91 | |
---|
92 | foreach($metakeys as $post_meta) { |
---|
93 | if ($post_meta->meta_value != '') { |
---|
94 | $post_keys = explode(',', $post_meta->meta_value); |
---|
95 | foreach($post_keys as $keyword) { |
---|
96 | $keyword = addslashes(trim($keyword)); |
---|
97 | if ($keyword != ''){ |
---|
98 | echo '<li>' . $post_meta->post_id . ' - ' . $keyword . '</li>'; |
---|
99 | if( !$precheck ){ |
---|
100 | wp_add_post_tags($post_meta->post_id, $keyword); |
---|
101 | } |
---|
102 | } |
---|
103 | } |
---|
104 | } |
---|
105 | if( !$precheck ){ |
---|
106 | delete_post_meta($post_meta->post_id, 'keywords'); |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | echo '</ul>'; |
---|
111 | |
---|
112 | } |
---|
113 | |
---|
114 | echo '<form action="admin.php?import=jkw&step='.($precheck? 2:6).'" method="post">'; |
---|
115 | echo '<p class="submit"><input type="submit" name="submit" value="'.__('Next »').'" /></p>'; |
---|
116 | echo '</form>'; |
---|
117 | echo '</div>'; |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | function check_V2_post_keyword ( $precheck = true ) { |
---|
122 | global $wpdb; |
---|
123 | global $table_prefix; |
---|
124 | |
---|
125 | echo '<div class="narrow">'; |
---|
126 | echo '<p><h3>'.__('Reading Jerome’s Keywords Tags…').'</h3></p>'; |
---|
127 | |
---|
128 | // import Jerome's Keywords tags |
---|
129 | $tablename = $table_prefix . substr(get_option('jkeywords_keywords_table'), 1, -1); |
---|
130 | $qry = "SELECT post_id, tag_name FROM $tablename"; |
---|
131 | $metakeys = $wpdb->get_results($qry); |
---|
132 | if ( !is_array($metakeys)) { |
---|
133 | echo '<p>' . __('No Tags Found!') . '</p>'; |
---|
134 | return false; |
---|
135 | } |
---|
136 | else { |
---|
137 | $count = count($metakeys); |
---|
138 | echo '<p>' . sprintf( __('Done! <strong>%s</strong> tags were read.'), $count ) . '<br /></p>'; |
---|
139 | |
---|
140 | echo '<ul>'; |
---|
141 | |
---|
142 | foreach($metakeys as $post_meta) { |
---|
143 | $keyword = addslashes(trim($post_meta->tag_name)); |
---|
144 | |
---|
145 | if ($keyword != ''){ |
---|
146 | echo '<li>' . $post_meta->post_id . ' - ' . $keyword . '</li>'; |
---|
147 | if( !$precheck ){ |
---|
148 | wp_add_post_tags($post_meta->post_id, $keyword); |
---|
149 | } |
---|
150 | } |
---|
151 | } |
---|
152 | |
---|
153 | echo '</ul>'; |
---|
154 | |
---|
155 | } |
---|
156 | |
---|
157 | echo '<form action="admin.php?import=jkw&step='.($precheck? 4:5).'" method="post">'; |
---|
158 | echo '<p class="submit"><input type="submit" name="submit" value="'.__('Next »').'" /></p>'; |
---|
159 | echo '</form>'; |
---|
160 | echo '</div>'; |
---|
161 | } |
---|
162 | |
---|
163 | |
---|
164 | function cleanup_V2_import ( ) { |
---|
165 | global $wpdb; |
---|
166 | global $table_prefix; |
---|
167 | |
---|
168 | /* options from V2.0a (jeromes-keywords.php) */ |
---|
169 | $options = array( |
---|
170 | 'version' => '2.0', // keywords options version |
---|
171 | 'keywords_table' => 'jkeywords', // table where keywords/tags are stored |
---|
172 | 'query_varname' => 'tag', // HTTP var name used for tag searches |
---|
173 | 'template' => 'keywords.php', // template file to use for displaying tag queries |
---|
174 | |
---|
175 | 'meta_always_include' => '', // meta keywords to always include |
---|
176 | 'meta_includecats' => 'default', // default' => include cats in meta keywords only for home page |
---|
177 | // all' => includes cats on every page, none' => never included |
---|
178 | |
---|
179 | 'meta_autoheader' => '1', // automatically output meta keywords in header |
---|
180 | 'search_strict' => '1', // returns only exact tag matches if true |
---|
181 | 'use_feed_cats' => '1', // insert tags into feeds as categories |
---|
182 | |
---|
183 | /* post tag options */ |
---|
184 | 'post_linkformat' => '', // post tag format (initialized to $link_localsearch) |
---|
185 | 'post_tagseparator' => ', ', // tag separator character(s) |
---|
186 | 'post_includecats' => '0', // include categories in post's tag list |
---|
187 | 'post_notagstext' => 'none', // text to display if no tags found |
---|
188 | |
---|
189 | /* tag cloud options */ |
---|
190 | 'cloud_linkformat' => '', // post tag format (initialized to $link_tagcloud) |
---|
191 | 'cloud_tagseparator' => ' ', // tag separator character(s) |
---|
192 | 'cloud_includecats' => '0', // include categories in tag cloud |
---|
193 | 'cloud_sortorder' => 'natural', // tag sorting: natural, countup/asc, countdown/desc, alpha |
---|
194 | 'cloud_displaymax' => '0', // maximum # of tags to display (all if set to zero) |
---|
195 | 'cloud_displaymin' => '0', // minimum tag count to include in tag cloud |
---|
196 | 'cloud_scalemax' => '0', // maximum value for count scaling (no scaling if zero) |
---|
197 | 'cloud_scalemin' => '0' // minimum value for count scaling |
---|
198 | ); |
---|
199 | |
---|
200 | $tablename = $table_prefix . substr(get_option('jkeywords_keywords_table'), 1, -1); |
---|
201 | |
---|
202 | $wpdb->query('DROP TABLE IF EXISTS ' . $tablename); |
---|
203 | |
---|
204 | foreach($options as $optname => $optval) { |
---|
205 | delete_option('jkeywords_' . $optname); |
---|
206 | } |
---|
207 | |
---|
208 | $this->done(); |
---|
209 | } |
---|
210 | |
---|
211 | |
---|
212 | function done ( ) { |
---|
213 | echo '<div class="narrow">'; |
---|
214 | echo '<p><h3>'.__('Import Complete!').'</h3></p>'; |
---|
215 | echo '</div>'; |
---|
216 | } |
---|
217 | |
---|
218 | |
---|
219 | function JeromesKeyword_Import ( ) { |
---|
220 | |
---|
221 | // Nothing. |
---|
222 | |
---|
223 | } |
---|
224 | |
---|
225 | } |
---|
226 | |
---|
227 | |
---|
228 | // create the import object |
---|
229 | $jkw_import = new JeromesKeyword_Import(); |
---|
230 | |
---|
231 | // add it to the import page! |
---|
232 | register_importer('jkw', 'Jerome’s keyword', __('Import Jerome’s keyword into the new native tagging structure.'), array($jkw_import, 'dispatch')); |
---|
233 | |
---|
234 | ?> |
---|