STP importer fixes from momo360modena. fixes #5059
git-svn-id: https://develop.svn.wordpress.org/trunk@6162 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
85a3aab65c
commit
6404a6cc79
@ -1,7 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class STP_Import {
|
class STP_Import {
|
||||||
|
|
||||||
function header() {
|
function header() {
|
||||||
echo '<div class="wrap">';
|
echo '<div class="wrap">';
|
||||||
echo '<h2>'.__('Import Simple Tagging').'</h2>';
|
echo '<h2>'.__('Import Simple Tagging').'</h2>';
|
||||||
@ -19,41 +17,37 @@ class STP_Import {
|
|||||||
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>';
|
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>';
|
||||||
echo '<p><strong>'.__('Don’t be stupid - backup your database before proceeding!').'</strong></p>';
|
echo '<p><strong>'.__('Don’t be stupid - backup your database before proceeding!').'</strong></p>';
|
||||||
echo '<form action="admin.php?import=stp&step=1" method="post">';
|
echo '<form action="admin.php?import=stp&step=1" method="post">';
|
||||||
wp_nonce_field('import-utw');
|
wp_nonce_field('import-stp');
|
||||||
echo '<p class="submit"><input type="submit" name="submit" value="'.__('Step 1 »').'" /></p>';
|
echo '<p class="submit"><input type="submit" name="submit" value="'.__('Step 1 »').'" /></p>';
|
||||||
echo '</form>';
|
echo '</form>';
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function dispatch () {
|
function dispatch () {
|
||||||
if ( empty( $_GET['step'] ) ) {
|
if ( empty( $_GET['step'] ) ) {
|
||||||
$step = 0;
|
$step = 0;
|
||||||
} else {
|
} else {
|
||||||
$step = (int) $_GET['step'];
|
$step = (int) $_GET['step'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// load the header
|
// load the header
|
||||||
$this->header();
|
$this->header();
|
||||||
|
|
||||||
switch ( $step ) {
|
switch ( $step ) {
|
||||||
case 0 :
|
case 0 :
|
||||||
$this->greet();
|
$this->greet();
|
||||||
break;
|
break;
|
||||||
case 1 :
|
case 1 :
|
||||||
check_admin_referer('import-utw');
|
check_admin_referer('import-stp');
|
||||||
$this->import_posts();
|
$this->import_posts();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
check_admin_referer('import-utw');
|
check_admin_referer('import-stp');
|
||||||
$this->import_t2p();
|
$this->import_t2p();
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
check_admin_referer('import-utw');
|
check_admin_referer('import-stp');
|
||||||
$this->cleanup_import();
|
$this->cleanup_import();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// load the footer
|
// load the footer
|
||||||
$this->footer();
|
$this->footer();
|
||||||
}
|
}
|
||||||
@ -72,63 +66,47 @@ class STP_Import {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
// if there's an existing entry, delete it
|
// if there's an existing entry, delete it
|
||||||
if ( get_option('stpimp_posts') ) {
|
if ( get_option('stpimp_posts') ) {
|
||||||
delete_option('stpimp_posts');
|
delete_option('stpimp_posts');
|
||||||
}
|
}
|
||||||
|
|
||||||
add_option('stpimp_posts', $posts);
|
add_option('stpimp_posts', $posts);
|
||||||
|
|
||||||
|
|
||||||
$count = count($posts);
|
$count = count($posts);
|
||||||
|
|
||||||
echo '<p>' . sprintf( __('Done! <strong>%s</strong> tag to post relationships were read.'), $count ) . '<br /></p>';
|
echo '<p>' . sprintf( __('Done! <strong>%s</strong> tag to post relationships were read.'), $count ) . '<br /></p>';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
echo '<form action="admin.php?import=stp&step=2" method="post">';
|
echo '<form action="admin.php?import=stp&step=2" method="post">';
|
||||||
wp_nonce_field('import-utw');
|
wp_nonce_field('import-stp');
|
||||||
echo '<p class="submit"><input type="submit" name="submit" value="'.__('Step 2 »').'" /></p>';
|
echo '<p class="submit"><input type="submit" name="submit" value="'.__('Step 2 »').'" /></p>';
|
||||||
echo '</form>';
|
echo '</form>';
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function import_t2p ( ) {
|
function import_t2p ( ) {
|
||||||
|
|
||||||
echo '<div class="narrow">';
|
echo '<div class="narrow">';
|
||||||
echo '<p><h3>'.__('Adding Tags to Posts…').'</h3></p>';
|
echo '<p><h3>'.__('Adding Tags to Posts…').'</h3></p>';
|
||||||
|
|
||||||
// run that funky magic!
|
// run that funky magic!
|
||||||
$tags_added = $this->tag2post();
|
$tags_added = $this->tag2post();
|
||||||
|
|
||||||
echo '<p>' . sprintf( __('Done! <strong>%s</strong> tags where added!'), $tags_added ) . '<br /></p>';
|
echo '<p>' . sprintf( __('Done! <strong>%s</strong> tags where added!'), $tags_added ) . '<br /></p>';
|
||||||
|
|
||||||
echo '<form action="admin.php?import=stp&step=3" method="post">';
|
echo '<form action="admin.php?import=stp&step=3" method="post">';
|
||||||
wp_nonce_field('import-utw');
|
wp_nonce_field('import-stp');
|
||||||
echo '<p class="submit"><input type="submit" name="submit" value="'.__('Step 3 »').'" /></p>';
|
echo '<p class="submit"><input type="submit" name="submit" value="'.__('Step 3 »').'" /></p>';
|
||||||
echo '</form>';
|
echo '</form>';
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function get_stp_posts ( ) {
|
function get_stp_posts ( ) {
|
||||||
|
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
// read in all the posts from the STP post->tag table: should be wp_post2tag
|
// read in all the posts from the STP post->tag table: should be wp_post2tag
|
||||||
$posts_query = "SELECT post_id, tag_name FROM " . $wpdb->prefix . "stp_tags";
|
$posts_query = "SELECT post_id, tag_name FROM " . $wpdb->prefix . "stp_tags";
|
||||||
|
|
||||||
$posts = $wpdb->get_results($posts_query);
|
$posts = $wpdb->get_results($posts_query);
|
||||||
|
|
||||||
return $posts;
|
return $posts;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function tag2post ( ) {
|
function tag2post ( ) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
@ -142,57 +120,36 @@ class STP_Import {
|
|||||||
foreach ( $posts as $this_post ) {
|
foreach ( $posts as $this_post ) {
|
||||||
$the_post = (int) $this_post->post_id;
|
$the_post = (int) $this_post->post_id;
|
||||||
$the_tag = $wpdb->escape($this_post->tag_name);
|
$the_tag = $wpdb->escape($this_post->tag_name);
|
||||||
|
|
||||||
// try to add the tag
|
// try to add the tag
|
||||||
wp_add_post_tags($the_post, $the_tag);
|
wp_add_post_tags($the_post, $the_tag);
|
||||||
|
|
||||||
$tags_added++;
|
$tags_added++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// that's it, all posts should be linked to their tags properly, pending any errors we just spit out!
|
// that's it, all posts should be linked to their tags properly, pending any errors we just spit out!
|
||||||
return $tags_added;
|
return $tags_added;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function cleanup_import ( ) {
|
function cleanup_import ( ) {
|
||||||
|
|
||||||
delete_option('stpimp_posts');
|
delete_option('stpimp_posts');
|
||||||
|
|
||||||
$this->done();
|
$this->done();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function done ( ) {
|
function done ( ) {
|
||||||
|
|
||||||
echo '<div class="narrow">';
|
echo '<div class="narrow">';
|
||||||
echo '<p><h3>'.__('Import Complete!').'</h3></p>';
|
echo '<p><h3>'.__('Import Complete!').'</h3></p>';
|
||||||
|
|
||||||
echo '<p>' . __('OK, so we lied about this being a 4-step program! You’re done!') . '</p>';
|
echo '<p>' . __('OK, so we lied about this being a 4-step program! You’re done!') . '</p>';
|
||||||
|
|
||||||
echo '<p>' . __('Now wasn’t that easy?') . '</p>';
|
echo '<p>' . __('Now wasn’t that easy?') . '</p>';
|
||||||
|
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function STP_Import ( ) {
|
function STP_Import ( ) {
|
||||||
|
|
||||||
// Nothing.
|
// Nothing.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// create the import object
|
// create the import object
|
||||||
$stp_import = new STP_Import();
|
$stp_import = new STP_Import();
|
||||||
|
|
||||||
// add it to the import page!
|
// add it to the import page!
|
||||||
register_importer('stp', 'Simple Tagging', __('Import Simple Tagging tags into the new native tagging structure.'), array($stp_import, 'dispatch'));
|
register_importer('stp', 'Simple Tagging', __('Import Simple Tagging tags into the new native tagging structure.'), array($stp_import, 'dispatch'));
|
||||||
|
?>
|
||||||
?>
|
|
Loading…
Reference in New Issue
Block a user