-
+ 51989C23B4307626271434576CC48791FBE75F002BF3CA0F1FC0A4B6C7DB4752BA7D01B971F148E6B307B3D66A90113F3C0EF10AD6219D10CDA58D87CEECBDCC
mp-wp/wp-admin/import/stp.php
(0 . 0)(1 . 170)
20180 <?php
20181 /**
20182 * Simple Tags Plugin Importer
20183 *
20184 * @package WordPress
20185 * @subpackage Importer
20186 */
20187
20188 /**
20189 * Simple Tags Plugin Tags converter class.
20190 *
20191 * Will convert Simple Tags Plugin tags over to the WordPress 2.3 taxonomy.
20192 *
20193 * @since unknown
20194 */
20195 class STP_Import {
20196 function header() {
20197 echo '<div class="wrap">';
20198 screen_icon();
20199 echo '<h2>'.__('Import Simple Tagging').'</h2>';
20200 echo '<p>'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'<br /><br /></p>';
20201 }
20202
20203 function footer() {
20204 echo '</div>';
20205 }
20206
20207 function greet() {
20208 echo '<div class="narrow">';
20209 echo '<p>'.__('Howdy! This imports tags from Simple Tagging 1.6.2 into WordPress tags.').'</p>';
20210 echo '<p>'.__('This has not been tested on any other versions of Simple Tagging. Mileage may vary.').'</p>';
20211 echo '<p>'.__('To accommodate larger databases for those tag-crazy authors out there, we have made this into an easy 4-step program to help you kick that nasty Simple Tagging habit. Just keep clicking along and we will let you know when you are in the clear!').'</p>';
20212 echo '<p><strong>'.__('Don’t be stupid - backup your database before proceeding!').'</strong></p>';
20213 echo '<form action="admin.php?import=stp&step=1" method="post">';
20214 wp_nonce_field('import-stp');
20215 echo '<p class="submit"><input type="submit" name="submit" class="button" value="'.__('Step 1').'" /></p>';
20216 echo '</form>';
20217 echo '</div>';
20218 }
20219
20220 function dispatch () {
20221 if ( empty( $_GET['step'] ) ) {
20222 $step = 0;
20223 } else {
20224 $step = (int) $_GET['step'];
20225 }
20226 // load the header
20227 $this->header();
20228 switch ( $step ) {
20229 case 0 :
20230 $this->greet();
20231 break;
20232 case 1 :
20233 check_admin_referer('import-stp');
20234 $this->import_posts();
20235 break;
20236 case 2:
20237 check_admin_referer('import-stp');
20238 $this->import_t2p();
20239 break;
20240 case 3:
20241 check_admin_referer('import-stp');
20242 $this->cleanup_import();
20243 break;
20244 }
20245 // load the footer
20246 $this->footer();
20247 }
20248
20249
20250 function import_posts ( ) {
20251 echo '<div class="narrow">';
20252 echo '<p><h3>'.__('Reading STP Post Tags…').'</h3></p>';
20253
20254 // read in all the STP tag -> post settings
20255 $posts = $this->get_stp_posts();
20256
20257 // if we didn't get any tags back, that's all there is folks!
20258 if ( !is_array($posts) ) {
20259 echo '<p>' . __('No posts were found to have tags!') . '</p>';
20260 return false;
20261 }
20262 else {
20263 // if there's an existing entry, delete it
20264 if ( get_option('stpimp_posts') ) {
20265 delete_option('stpimp_posts');
20266 }
20267
20268 add_option('stpimp_posts', $posts);
20269 $count = count($posts);
20270 echo '<p>' . sprintf( __ngettext('Done! <strong>%s</strong> tag to post relationships were read.', 'Done! <strong>%s</strong> tags to post relationships were read.', $count), $count ) . '<br /></p>';
20271 }
20272
20273 echo '<form action="admin.php?import=stp&step=2" method="post">';
20274 wp_nonce_field('import-stp');
20275 echo '<p class="submit"><input type="submit" name="submit" class="button" value="'.__('Step 2').'" /></p>';
20276 echo '</form>';
20277 echo '</div>';
20278 }
20279
20280
20281 function import_t2p ( ) {
20282 echo '<div class="narrow">';
20283 echo '<p><h3>'.__('Adding Tags to Posts…').'</h3></p>';
20284
20285 // run that funky magic!
20286 $tags_added = $this->tag2post();
20287
20288 echo '<p>' . sprintf( __ngettext('Done! <strong>%s</strong> tag was added!', 'Done! <strong>%s</strong> tags were added!', $tags_added), $tags_added ) . '<br /></p>';
20289 echo '<form action="admin.php?import=stp&step=3" method="post">';
20290 wp_nonce_field('import-stp');
20291 echo '<p class="submit"><input type="submit" name="submit" class="button" value="'.__('Step 3').'" /></p>';
20292 echo '</form>';
20293 echo '</div>';
20294 }
20295
20296 function get_stp_posts ( ) {
20297 global $wpdb;
20298 // read in all the posts from the STP post->tag table: should be wp_post2tag
20299 $posts_query = "SELECT post_id, tag_name FROM " . $wpdb->prefix . "stp_tags";
20300 $posts = $wpdb->get_results($posts_query);
20301 return $posts;
20302 }
20303
20304 function tag2post ( ) {
20305 global $wpdb;
20306
20307 // get the tags and posts we imported in the last 2 steps
20308 $posts = get_option('stpimp_posts');
20309
20310 // null out our results
20311 $tags_added = 0;
20312
20313 // loop through each post and add its tags to the db
20314 foreach ( $posts as $this_post ) {
20315 $the_post = (int) $this_post->post_id;
20316 $the_tag = $wpdb->escape($this_post->tag_name);
20317 // try to add the tag
20318 wp_add_post_tags($the_post, $the_tag);
20319 $tags_added++;
20320 }
20321
20322 // that's it, all posts should be linked to their tags properly, pending any errors we just spit out!
20323 return $tags_added;
20324 }
20325
20326 function cleanup_import ( ) {
20327 delete_option('stpimp_posts');
20328 $this->done();
20329 }
20330
20331 function done ( ) {
20332 echo '<div class="narrow">';
20333 echo '<p><h3>'.__('Import Complete!').'</h3></p>';
20334 echo '<p>' . __('OK, so we lied about this being a 4-step program! You’re done!') . '</p>';
20335 echo '<p>' . __('Now wasn’t that easy?') . '</p>';
20336 echo '</div>';
20337 }
20338
20339 function STP_Import ( ) {
20340 // Nothing.
20341 }
20342 }
20343
20344 // create the import object
20345 $stp_import = new STP_Import();
20346
20347 // add it to the import page!
20348 register_importer('stp', 'Simple Tagging', __('Import Simple Tagging tags into WordPress tags.'), array($stp_import, 'dispatch'));
20349 ?>