2007-09-10 16:30:55 -04:00
< ? php
2008-08-14 02:30:38 -04:00
/**
* BunnyTags Plugin Tag Importer
*
* @ package WordPress
* @ subpackage Importer
*/
2007-09-10 16:30:55 -04:00
2008-08-14 02:30:38 -04:00
/**
* BunnyTags Plugin tag converter
*
* This will process the BunnyTags plugin tags and convert them to the WordPress
* 2.3 taxonomy .
*
* @ since unknown
*/
2007-09-10 16:30:55 -04:00
class BunnyTags_Import {
function header () {
echo '<div class="wrap">' ;
2008-11-26 08:51:25 -05:00
screen_icon ();
2007-09-10 16:30:55 -04:00
echo '<h2>' . __ ( 'Import Bunny’s Technorati Tags' ) . '</h2>' ;
echo '<p>' . __ ( 'Steps may take a few minutes depending on the size of your database. Please be patient.' ) . '<br /><br /></p>' ;
}
function footer () {
echo '</div>' ;
}
function greet () {
echo '<div class="narrow">' ;
2008-02-27 16:47:52 -05:00
echo '<p>' . __ ( 'Howdy! This imports tags from Bunny’s Technorati Tags into WordPress tags.' ) . '</p>' ;
2007-09-10 16:30:55 -04:00
echo '<p>' . __ ( 'This is suitable for Bunny’s Technorati Tags version 0.6.' ) . '</p>' ;
echo '<p><strong>' . __ ( 'All existing Bunny’s Technorati Tags will be removed after import.' ) . '</strong></p>' ;
echo '<p><strong>' . __ ( 'Don’t be stupid - backup your database before proceeding!' ) . '</strong></p>' ;
echo '<form action="admin.php?import=btt&step=1" method="post">' ;
wp_nonce_field ( 'import-btt' );
2009-05-04 13:54:08 -04:00
echo '<p class="submit"><input type="submit" name="submit" class="button" value="' . _a ( 'Import Tags' ) . '" /></p>' ;
2007-09-10 16:30:55 -04:00
echo '</form>' ;
echo '</div>' ;
}
function dispatch () {
if ( empty ( $_GET [ 'step' ]) )
$step = 0 ;
else
2008-01-29 13:48:38 -05:00
$step = absint ( $_GET [ 'step' ]);
2007-09-10 16:30:55 -04:00
// load the header
$this -> header ();
switch ( $step ) {
case 0 :
$this -> greet ();
break ;
case 1 :
check_admin_referer ( 'import-btt' );
$this -> check_post_keyword ( true );
break ;
case 2 :
check_admin_referer ( 'import-btt' );
$this -> check_post_keyword ( false );
break ;
case 3 :
$this -> done ();
break ;
}
// load the footer
$this -> footer ();
}
function check_post_keyword ( $precheck = true ) {
global $wpdb ;
echo '<div class="narrow">' ;
echo '<p><h3>' . __ ( 'Reading Bunny’s Technorati Tags…' ) . '</h3></p>' ;
2008-02-05 01:47:27 -05:00
// import Bunny's Keywords tags
2007-09-10 16:30:55 -04:00
$metakeys = $wpdb -> get_results ( " SELECT post_id, meta_id, meta_key, meta_value FROM $wpdb->postmeta WHERE $wpdb->postmeta .meta_key = 'tags' " );
if ( ! is_array ( $metakeys )) {
echo '<p>' . __ ( 'No Tags Found!' ) . '</p>' ;
return false ;
} else {
$count = count ( $metakeys );
2009-02-20 14:35:16 -05:00
echo '<p>' . sprintf ( _n ( 'Done! <strong>%s</strong> post with tags were read.' , 'Done! <strong>%s</strong> posts with tags were read.' , $count ), $count ) . '<br /></p>' ;
2007-09-10 16:30:55 -04:00
echo '<ul>' ;
foreach ( $metakeys as $post_meta ) {
if ( $post_meta -> meta_value != '' ) {
$post_keys = explode ( ' ' , $post_meta -> meta_value );
foreach ( $post_keys as $keyword ) {
$keyword = addslashes ( trim ( str_replace ( '+' , ' ' , $keyword )));
if ( '' != $keyword ) {
echo '<li>' . $post_meta -> post_id . ' - ' . $keyword . '</li>' ;
if ( ! $precheck )
wp_add_post_tags ( $post_meta -> post_id , $keyword );
}
}
}
if ( ! $precheck )
delete_post_meta ( $post_meta -> post_id , 'tags' );
}
echo '</ul>' ;
}
echo '<form action="admin.php?import=btt&step=' . ( $precheck ? 2 : 3 ) . '" method="post">' ;
wp_nonce_field ( 'import-btt' );
2009-05-04 13:54:08 -04:00
echo '<p class="submit"><input type="submit" name="submit" class="button" value="' . _a ( 'Next' ) . '" /></p>' ;
2007-09-10 16:30:55 -04:00
echo '</form>' ;
echo '</div>' ;
}
function done () {
echo '<div class="narrow">' ;
echo '<p><h3>' . __ ( 'Import Complete!' ) . '</h3></p>' ;
echo '</div>' ;
}
function BunnyTags_Import () {
}
}
// create the import object
$btt_import = new BunnyTags_Import ();
// add it to the import page!
2008-02-27 16:47:52 -05:00
register_importer ( 'btt' , 'Bunny’s Technorati Tags' , __ ( 'Import Bunny’s Technorati Tags into WordPress tags.' ), array ( $btt_import , 'dispatch' ));
2007-09-10 16:30:55 -04:00
?>