4 echo '<div class="wrap">';
5 echo '<h2>'.__('Import Simple Tagging').'</h2>';
6 echo '<p>'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'<br /><br /></p>';
14 echo '<div class="narrow">';
15 echo '<p>'.__('Howdy! This imports tags from Simple Tagging 1.6.2 into WordPress tags.').'</p>';
16 echo '<p>'.__('This has not been tested on any other versions of Simple Tagging. Mileage may vary.').'</p>';
17 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>';
18 echo '<p><strong>'.__('Don’t be stupid - backup your database before proceeding!').'</strong></p>';
19 echo '<form action="admin.php?import=stp&step=1" method="post">';
20 wp_nonce_field('import-stp');
21 echo '<p class="submit"><input type="submit" name="submit" value="'.__('Step 1').'" /></p>';
26 function dispatch () {
27 if ( empty( $_GET['step'] ) ) {
30 $step = (int) $_GET['step'];
39 check_admin_referer('import-stp');
40 $this->import_posts();
43 check_admin_referer('import-stp');
47 check_admin_referer('import-stp');
48 $this->cleanup_import();
56 function import_posts ( ) {
57 echo '<div class="narrow">';
58 echo '<p><h3>'.__('Reading STP Post Tags…').'</h3></p>';
60 // read in all the STP tag -> post settings
61 $posts = $this->get_stp_posts();
63 // if we didn't get any tags back, that's all there is folks!
64 if ( !is_array($posts) ) {
65 echo '<p>' . __('No posts were found to have tags!') . '</p>';
69 // if there's an existing entry, delete it
70 if ( get_option('stpimp_posts') ) {
71 delete_option('stpimp_posts');
74 add_option('stpimp_posts', $posts);
75 $count = count($posts);
76 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>';
79 echo '<form action="admin.php?import=stp&step=2" method="post">';
80 wp_nonce_field('import-stp');
81 echo '<p class="submit"><input type="submit" name="submit" value="'.__('Step 2').'" /></p>';
87 function import_t2p ( ) {
88 echo '<div class="narrow">';
89 echo '<p><h3>'.__('Adding Tags to Posts…').'</h3></p>';
91 // run that funky magic!
92 $tags_added = $this->tag2post();
94 echo '<p>' . sprintf( __ngettext('Done! <strong>%s</strong> tag was added!', 'Done! <strong>%s</strong> tags were added!', $tags_added), $tags_added ) . '<br /></p>';
95 echo '<form action="admin.php?import=stp&step=3" method="post">';
96 wp_nonce_field('import-stp');
97 echo '<p class="submit"><input type="submit" name="submit" value="'.__('Step 3').'" /></p>';
102 function get_stp_posts ( ) {
104 // read in all the posts from the STP post->tag table: should be wp_post2tag
105 $posts_query = "SELECT post_id, tag_name FROM " . $wpdb->prefix . "stp_tags";
106 $posts = $wpdb->get_results($posts_query);
110 function tag2post ( ) {
113 // get the tags and posts we imported in the last 2 steps
114 $posts = get_option('stpimp_posts');
116 // null out our results
119 // loop through each post and add its tags to the db
120 foreach ( $posts as $this_post ) {
121 $the_post = (int) $this_post->post_id;
122 $the_tag = $wpdb->escape($this_post->tag_name);
123 // try to add the tag
124 wp_add_post_tags($the_post, $the_tag);
128 // that's it, all posts should be linked to their tags properly, pending any errors we just spit out!
132 function cleanup_import ( ) {
133 delete_option('stpimp_posts');
138 echo '<div class="narrow">';
139 echo '<p><h3>'.__('Import Complete!').'</h3></p>';
140 echo '<p>' . __('OK, so we lied about this being a 4-step program! You’re done!') . '</p>';
141 echo '<p>' . __('Now wasn’t that easy?') . '</p>';
145 function STP_Import ( ) {
150 // create the import object
151 $stp_import = new STP_Import();
153 // add it to the import page!
154 register_importer('stp', 'Simple Tagging', __('Import Simple Tagging tags into WordPress tags.'), array($stp_import, 'dispatch'));