raw
mp-wp_genesis           1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * Simple Tags Plugin Importer
mp-wp_genesis 4 *
mp-wp_genesis 5 * @package WordPress
mp-wp_genesis 6 * @subpackage Importer
mp-wp_genesis 7 */
mp-wp_genesis 8
mp-wp_genesis 9 /**
mp-wp_genesis 10 * Simple Tags Plugin Tags converter class.
mp-wp_genesis 11 *
mp-wp_genesis 12 * Will convert Simple Tags Plugin tags over to the WordPress 2.3 taxonomy.
mp-wp_genesis 13 *
mp-wp_genesis 14 * @since unknown
mp-wp_genesis 15 */
mp-wp_genesis 16 class STP_Import {
mp-wp_genesis 17 function header() {
mp-wp_genesis 18 echo '<div class="wrap">';
mp-wp_genesis 19 screen_icon();
mp-wp_genesis 20 echo '<h2>'.__('Import Simple Tagging').'</h2>';
mp-wp_genesis 21 echo '<p>'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'<br /><br /></p>';
mp-wp_genesis 22 }
mp-wp_genesis 23
mp-wp_genesis 24 function footer() {
mp-wp_genesis 25 echo '</div>';
mp-wp_genesis 26 }
mp-wp_genesis 27
mp-wp_genesis 28 function greet() {
mp-wp_genesis 29 echo '<div class="narrow">';
mp-wp_genesis 30 echo '<p>'.__('Howdy! This imports tags from Simple Tagging 1.6.2 into WordPress tags.').'</p>';
mp-wp_genesis 31 echo '<p>'.__('This has not been tested on any other versions of Simple Tagging. Mileage may vary.').'</p>';
mp-wp_genesis 32 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>';
mp-wp_genesis 33 echo '<p><strong>'.__('Don&#8217;t be stupid - backup your database before proceeding!').'</strong></p>';
mp-wp_genesis 34 echo '<form action="admin.php?import=stp&amp;step=1" method="post">';
mp-wp_genesis 35 wp_nonce_field('import-stp');
mp-wp_genesis 36 echo '<p class="submit"><input type="submit" name="submit" class="button" value="'.__('Step 1').'" /></p>';
mp-wp_genesis 37 echo '</form>';
mp-wp_genesis 38 echo '</div>';
mp-wp_genesis 39 }
mp-wp_genesis 40
mp-wp_genesis 41 function dispatch () {
mp-wp_genesis 42 if ( empty( $_GET['step'] ) ) {
mp-wp_genesis 43 $step = 0;
mp-wp_genesis 44 } else {
mp-wp_genesis 45 $step = (int) $_GET['step'];
mp-wp_genesis 46 }
mp-wp_genesis 47 // load the header
mp-wp_genesis 48 $this->header();
mp-wp_genesis 49 switch ( $step ) {
mp-wp_genesis 50 case 0 :
mp-wp_genesis 51 $this->greet();
mp-wp_genesis 52 break;
mp-wp_genesis 53 case 1 :
mp-wp_genesis 54 check_admin_referer('import-stp');
mp-wp_genesis 55 $this->import_posts();
mp-wp_genesis 56 break;
mp-wp_genesis 57 case 2:
mp-wp_genesis 58 check_admin_referer('import-stp');
mp-wp_genesis 59 $this->import_t2p();
mp-wp_genesis 60 break;
mp-wp_genesis 61 case 3:
mp-wp_genesis 62 check_admin_referer('import-stp');
mp-wp_genesis 63 $this->cleanup_import();
mp-wp_genesis 64 break;
mp-wp_genesis 65 }
mp-wp_genesis 66 // load the footer
mp-wp_genesis 67 $this->footer();
mp-wp_genesis 68 }
mp-wp_genesis 69
mp-wp_genesis 70
mp-wp_genesis 71 function import_posts ( ) {
mp-wp_genesis 72 echo '<div class="narrow">';
mp-wp_genesis 73 echo '<p><h3>'.__('Reading STP Post Tags&#8230;').'</h3></p>';
mp-wp_genesis 74
mp-wp_genesis 75 // read in all the STP tag -> post settings
mp-wp_genesis 76 $posts = $this->get_stp_posts();
mp-wp_genesis 77
mp-wp_genesis 78 // if we didn't get any tags back, that's all there is folks!
mp-wp_genesis 79 if ( !is_array($posts) ) {
mp-wp_genesis 80 echo '<p>' . __('No posts were found to have tags!') . '</p>';
mp-wp_genesis 81 return false;
mp-wp_genesis 82 }
mp-wp_genesis 83 else {
mp-wp_genesis 84 // if there's an existing entry, delete it
mp-wp_genesis 85 if ( get_option('stpimp_posts') ) {
mp-wp_genesis 86 delete_option('stpimp_posts');
mp-wp_genesis 87 }
mp-wp_genesis 88
mp-wp_genesis 89 add_option('stpimp_posts', $posts);
mp-wp_genesis 90 $count = count($posts);
mp-wp_genesis 91 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>';
mp-wp_genesis 92 }
mp-wp_genesis 93
mp-wp_genesis 94 echo '<form action="admin.php?import=stp&amp;step=2" method="post">';
mp-wp_genesis 95 wp_nonce_field('import-stp');
mp-wp_genesis 96 echo '<p class="submit"><input type="submit" name="submit" class="button" value="'.__('Step 2').'" /></p>';
mp-wp_genesis 97 echo '</form>';
mp-wp_genesis 98 echo '</div>';
mp-wp_genesis 99 }
mp-wp_genesis 100
mp-wp_genesis 101
mp-wp_genesis 102 function import_t2p ( ) {
mp-wp_genesis 103 echo '<div class="narrow">';
mp-wp_genesis 104 echo '<p><h3>'.__('Adding Tags to Posts&#8230;').'</h3></p>';
mp-wp_genesis 105
mp-wp_genesis 106 // run that funky magic!
mp-wp_genesis 107 $tags_added = $this->tag2post();
mp-wp_genesis 108
mp-wp_genesis 109 echo '<p>' . sprintf( __ngettext('Done! <strong>%s</strong> tag was added!', 'Done! <strong>%s</strong> tags were added!', $tags_added), $tags_added ) . '<br /></p>';
mp-wp_genesis 110 echo '<form action="admin.php?import=stp&amp;step=3" method="post">';
mp-wp_genesis 111 wp_nonce_field('import-stp');
mp-wp_genesis 112 echo '<p class="submit"><input type="submit" name="submit" class="button" value="'.__('Step 3').'" /></p>';
mp-wp_genesis 113 echo '</form>';
mp-wp_genesis 114 echo '</div>';
mp-wp_genesis 115 }
mp-wp_genesis 116
mp-wp_genesis 117 function get_stp_posts ( ) {
mp-wp_genesis 118 global $wpdb;
mp-wp_genesis 119 // read in all the posts from the STP post->tag table: should be wp_post2tag
mp-wp_genesis 120 $posts_query = "SELECT post_id, tag_name FROM " . $wpdb->prefix . "stp_tags";
mp-wp_genesis 121 $posts = $wpdb->get_results($posts_query);
mp-wp_genesis 122 return $posts;
mp-wp_genesis 123 }
mp-wp_genesis 124
mp-wp_genesis 125 function tag2post ( ) {
mp-wp_genesis 126 global $wpdb;
mp-wp_genesis 127
mp-wp_genesis 128 // get the tags and posts we imported in the last 2 steps
mp-wp_genesis 129 $posts = get_option('stpimp_posts');
mp-wp_genesis 130
mp-wp_genesis 131 // null out our results
mp-wp_genesis 132 $tags_added = 0;
mp-wp_genesis 133
mp-wp_genesis 134 // loop through each post and add its tags to the db
mp-wp_genesis 135 foreach ( $posts as $this_post ) {
mp-wp_genesis 136 $the_post = (int) $this_post->post_id;
mp-wp_genesis 137 $the_tag = $wpdb->escape($this_post->tag_name);
mp-wp_genesis 138 // try to add the tag
mp-wp_genesis 139 wp_add_post_tags($the_post, $the_tag);
mp-wp_genesis 140 $tags_added++;
mp-wp_genesis 141 }
mp-wp_genesis 142
mp-wp_genesis 143 // that's it, all posts should be linked to their tags properly, pending any errors we just spit out!
mp-wp_genesis 144 return $tags_added;
mp-wp_genesis 145 }
mp-wp_genesis 146
mp-wp_genesis 147 function cleanup_import ( ) {
mp-wp_genesis 148 delete_option('stpimp_posts');
mp-wp_genesis 149 $this->done();
mp-wp_genesis 150 }
mp-wp_genesis 151
mp-wp_genesis 152 function done ( ) {
mp-wp_genesis 153 echo '<div class="narrow">';
mp-wp_genesis 154 echo '<p><h3>'.__('Import Complete!').'</h3></p>';
mp-wp_genesis 155 echo '<p>' . __('OK, so we lied about this being a 4-step program! You&#8217;re done!') . '</p>';
mp-wp_genesis 156 echo '<p>' . __('Now wasn&#8217;t that easy?') . '</p>';
mp-wp_genesis 157 echo '</div>';
mp-wp_genesis 158 }
mp-wp_genesis 159
mp-wp_genesis 160 function STP_Import ( ) {
mp-wp_genesis 161 // Nothing.
mp-wp_genesis 162 }
mp-wp_genesis 163 }
mp-wp_genesis 164
mp-wp_genesis 165 // create the import object
mp-wp_genesis 166 $stp_import = new STP_Import();
mp-wp_genesis 167
mp-wp_genesis 168 // add it to the import page!
mp-wp_genesis 169 register_importer('stp', 'Simple Tagging', __('Import Simple Tagging tags into WordPress tags.'), array($stp_import, 'dispatch'));
mp-wp_genesis 170 ?>