diff options
author | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2008-06-13 17:21:00 +0000 |
---|---|---|
committer | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2008-06-13 17:21:00 +0000 |
commit | 12de05107e4c8b006bde6ee8916f34eb476d08da (patch) | |
tree | 123ee54ecd1f3f777373b7df54a4604012d43640 /wp-admin/import | |
parent | e51c7a9ca4bfdb45fa3ec7334bd33871e78c68b1 (diff) | |
download | wordpress-mu-12de05107e4c8b006bde6ee8916f34eb476d08da.tar.gz wordpress-mu-12de05107e4c8b006bde6ee8916f34eb476d08da.tar.xz wordpress-mu-12de05107e4c8b006bde6ee8916f34eb476d08da.zip |
WP Merge with revision 8075
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@1328 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-admin/import')
-rw-r--r-- | wp-admin/import/blogger.php | 4 | ||||
-rw-r--r-- | wp-admin/import/dotclear.php | 4 | ||||
-rw-r--r-- | wp-admin/import/greymatter.php | 12 | ||||
-rw-r--r-- | wp-admin/import/mt.php | 4 | ||||
-rw-r--r-- | wp-admin/import/textpattern.php | 4 | ||||
-rw-r--r-- | wp-admin/import/wordpress.php | 9 | ||||
-rw-r--r-- | wp-admin/import/wp-cat2tag.php | 301 |
7 files changed, 266 insertions, 72 deletions
diff --git a/wp-admin/import/blogger.php b/wp-admin/import/blogger.php index 27f7c87..1fdbf35 100644 --- a/wp-admin/import/blogger.php +++ b/wp-admin/import/blogger.php @@ -641,7 +641,7 @@ class Blogger_Import { $host = $this->blogs[$importing_blog]['host'];
// Get an array of posts => authors
- $post_ids = (array) $wpdb->get_col("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'blogger_blog' AND meta_value = '$host'");
+ $post_ids = (array) $wpdb->get_col( $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'blogger_blog' AND meta_value = %s", $host) );
$post_ids = join( ',', $post_ids );
$results = (array) $wpdb->get_results("SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = 'blogger_author' AND post_id IN ($post_ids)");
foreach ( $results as $row )
@@ -658,7 +658,7 @@ class Blogger_Import { $post_ids = (array) array_keys( $authors_posts, $this->blogs[$importing_blog]['authors'][$author][0] );
$post_ids = join( ',', $post_ids);
- $wpdb->query("UPDATE $wpdb->posts SET post_author = $user_id WHERE id IN ($post_ids)");
+ $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_author = %d WHERE id IN ($post_ids)", $user_id) );
$this->blogs[$importing_blog]['authors'][$author][1] = $user_id;
}
$this->save_vars();
diff --git a/wp-admin/import/dotclear.php b/wp-admin/import/dotclear.php index 16df934..da1047f 100644 --- a/wp-admin/import/dotclear.php +++ b/wp-admin/import/dotclear.php @@ -13,7 +13,7 @@ if(!function_exists('get_comment_count')) function get_comment_count($post_ID) { global $wpdb; - return $wpdb->get_var('SELECT count(*) FROM '.$wpdb->comments.' WHERE comment_post_ID = '.$post_ID); + return $wpdb->get_var( $wpdb->prepare("SELECT count(*) FROM $wpdb->comments WHERE comment_post_ID = %d", $post_ID) ); } } @@ -22,7 +22,7 @@ if(!function_exists('link_exists')) function link_exists($linkname) { global $wpdb; - return $wpdb->get_var('SELECT link_id FROM '.$wpdb->links.' WHERE link_name = "'.$linkname.'"'); + return $wpdb->get_var( $wpdb->prepare("SELECT link_id FROM $wpdb->links WHERE link_name = %s", $linkname) ); } } diff --git a/wp-admin/import/greymatter.php b/wp-admin/import/greymatter.php index 92abc48..58aa757 100644 --- a/wp-admin/import/greymatter.php +++ b/wp-admin/import/greymatter.php @@ -38,16 +38,16 @@ class GM_Import { <h3><?php _e('Second step: GreyMatter details:') ?></h3> <table class="form-table"> <tr> -<td><?php _e('Path to GM files:') ?></td> -<td><input type="text" style="width:300px" name="gmpath" value="/home/my/site/cgi-bin/greymatter/" /></td> +<td><label for="gmpath"><?php _e('Path to GM files:') ?></label></td> +<td><input type="text" style="width:300px" name="gmpath" id="gmpath" value="/home/my/site/cgi-bin/greymatter/" /></td> </tr> <tr> -<td><?php _e('Path to GM entries:') ?></td> -<td><input type="text" style="width:300px" name="archivespath" value="/home/my/site/cgi-bin/greymatter/archives/" /></td> +<td><label for="archivespath"><?php _e('Path to GM entries:') ?></label></td> +<td><input type="text" style="width:300px" name="archivespath" id="archivespath" value="/home/my/site/cgi-bin/greymatter/archives/" /></td> </tr> <tr> -<td><?php _e("Last entry's number:") ?></td> -<td><input type="text" name="lastentry" value="00000001" /><br /> +<td><label for="lastentry"><?php _e("Last entry's number:") ?></label></td> +<td><input type="text" name="lastentry" id="lastentry" value="00000001" /><br /> <?php _e("This importer will search for files 00000001.cgi to 000-whatever.cgi,<br />so you need to enter the number of the last GM post here.<br />(if you don't know that number, just log into your FTP and look it out<br />in the entries' folder)") ?></td> </tr> </table> diff --git a/wp-admin/import/mt.php b/wp-admin/import/mt.php index dcf5892..53ca091 100644 --- a/wp-admin/import/mt.php +++ b/wp-admin/import/mt.php @@ -149,9 +149,9 @@ class MT_Import { $j = -1; foreach ($authors as $author) { ++ $j; - echo '<li>'.__('Current author:').' <strong>'.$author.'</strong><br />'.'<input type="text" value="'.$author.'" name="'.'user[]'.'" maxlength="30">'; + echo '<li><label>'.__('Current author:').' <strong>'.$author.'</strong><br />'.'<input type="text" value="'.$author.'" name="'.'user[]'.'" maxlength="30">'; $this->users_form($j); - echo '</li>'; + echo '</label></li>'; } echo '<input type="submit" value="'.__('Submit').'">'.'<br />'; diff --git a/wp-admin/import/textpattern.php b/wp-admin/import/textpattern.php index 1c10015..c3fb1d7 100644 --- a/wp-admin/import/textpattern.php +++ b/wp-admin/import/textpattern.php @@ -8,7 +8,7 @@ if(!function_exists('get_comment_count')) function get_comment_count($post_ID) { global $wpdb; - return $wpdb->get_var('SELECT count(*) FROM '.$wpdb->comments.' WHERE comment_post_ID = '.$post_ID); + return $wpdb->get_var( $wpdb->prepare("SELECT count(*) FROM $wpdb->comments WHERE comment_post_ID = %d", $post_ID) ); } } @@ -17,7 +17,7 @@ if(!function_exists('link_exists')) function link_exists($linkname) { global $wpdb; - return $wpdb->get_var('SELECT link_id FROM '.$wpdb->links.' WHERE link_name = "'.$wpdb->escape($linkname).'"'); + return $wpdb->get_var( $wpdb->prepare("SELECT link_id FROM $wpdb->links WHERE link_name = %s", $linkname) ); } } diff --git a/wp-admin/import/wordpress.php b/wp-admin/import/wordpress.php index 03395bd..5271abe 100644 --- a/wp-admin/import/wordpress.php +++ b/wp-admin/import/wordpress.php @@ -218,7 +218,7 @@ class WP_Import { function users_form($n, $author) { if ( $this->allow_create_users() ) { - printf(__('Create user %1$s or map to existing'), ' <input type="text" value="'.$author.'" name="'.'user_create['.intval($n).']'.'" maxlength="30"> <br />'); + printf('<label>'.__('Create user %1$s or map to existing'), ' <input type="text" value="'.$author.'" name="'.'user_create['.intval($n).']'.'" maxlength="30"></label> <br />'); } else { echo __('Map to existing').'<br />'; @@ -357,6 +357,11 @@ class WP_Import { $guid = $this->get_tag( $post, 'guid' ); $post_author = $this->get_tag( $post, 'dc:creator' ); + $post_excerpt = $this->get_tag( $post, 'excerpt:encoded' ); + $post_excerpt = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $post_excerpt); + $post_excerpt = str_replace('<br>', '<br />', $post_excerpt); + $post_excerpt = str_replace('<hr>', '<hr />', $post_excerpt); + $post_content = $this->get_tag( $post, 'content:encoded' ); $post_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $post_content); $post_content = str_replace('<br>', '<br />', $post_content); @@ -404,7 +409,7 @@ class WP_Import { $post_author = $this->checkauthor($post_author); //just so that if a post already exists, new users are not created by checkauthor - $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_status', 'post_name', 'comment_status', 'ping_status', 'guid', 'post_parent', 'menu_order', 'post_type', 'post_password'); + $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_excerpt', 'post_title', 'post_status', 'post_name', 'comment_status', 'ping_status', 'guid', 'post_parent', 'menu_order', 'post_type', 'post_password'); if ($post_type == 'attachment') { $remote_url = $this->get_tag( $post, 'wp:attachment_url' ); if ( !$remote_url ) diff --git a/wp-admin/import/wp-cat2tag.php b/wp-admin/import/wp-cat2tag.php index 246125e..3176fa4 100644 --- a/wp-admin/import/wp-cat2tag.php +++ b/wp-admin/import/wp-cat2tag.php @@ -3,50 +3,75 @@ class WP_Categories_to_Tags { var $categories_to_convert = array(); var $all_categories = array(); + var $tags_to_convert = array(); + var $all_tags = array(); + var $hybrids_ids = array(); function header() { echo '<div class="wrap">'; - echo '<h2>' . __('Convert Categories to Tags') . '</h2>'; + if ( ! current_user_can('manage_categories') ) { + echo '<div class="narrow">'; + echo '<p>' . __('Cheatin’ uh?') . '</p>'; + echo '</div>'; + } else { ?> + <div class="tablenav"><p style="margin:4px"><a style="display:inline;" class="button-secondary" href="admin.php?import=wp-cat2tag">Categories to Tags</a> + <a style="display:inline;" class="button-secondary" href="admin.php?import=wp-cat2tag&step=3">Tags to Categories</a></p></div> +<?php } } function footer() { echo '</div>'; } - function populate_all_categories() { + function populate_cats() { global $wpdb; $categories = get_categories('get=all'); foreach ( $categories as $category ) { - if ( !tag_exists($wpdb->escape($category->name)) ) - $this->all_categories[] = $category; + $this->all_categories[] = $category; + if ( tag_exists( $wpdb->escape($category->name) ) ) + $this->hybrids_ids[] = $category->term_id; + } + } + + function populate_tags() { + global $wpdb; + + $tags = get_terms( array('post_tag'), 'get=all' ); + foreach ( $tags as $tag ) { + $this->all_tags[] = $tag; + if ( $this->_category_exists($tag->term_id) ) + $this->hybrids_ids[] = $tag->term_id; } } - function welcome() { - $this->populate_all_categories(); + function categories_tab() { + $this->populate_cats(); + $cat_num = count($this->all_categories); - echo '<div class="narrow">'; + echo '<br class="clear" />'; - if (count($this->all_categories) > 0) { + if ( $cat_num > 0 ) { + echo '<h2>Convert Categories (' . $cat_num . ') to Tags.</h2>'; + echo '<div class="narrow">'; echo '<p>' . __('Hey there. Here you can selectively converts existing categories to tags. To get started, check the categories you wish to be converted, then click the Convert button.') . '</p>'; - echo '<p>' . __('Keep in mind that if you convert a category with child categories, the children become top-level orphans.') . '</p>'; + echo '<p>' . __('Keep in mind that if you convert a category with child categories, the children become top-level orphans.') . '</p></div>'; $this->categories_form(); + } elseif ( $hyb_num > 0 ) { + echo '<p>' . __('You have no categories that can be converted. However some of your categories are both a tag and a category.') . '</p>'; } else { echo '<p>'.__('You have no categories to convert!').'</p>'; } - - echo '</div>'; } - function categories_form() { -?> + function categories_form() { ?> + <script type="text/javascript"> -<!-- +/* <![CDATA[ */ var checkflag = "false"; function check_all_rows() { - field = document.formlist; + field = document.catlist; if ( 'false' == checkflag ) { for ( i = 0; i < field.length; i++ ) { if ( 'cats_to_convert[]' == field[i].name ) @@ -63,54 +88,153 @@ function check_all_rows() { return '<?php _e('Check All') ?>'; } } - -// --> +/* ]]> */ </script> -<?php - echo '<form name="formlist" id="formlist" action="admin.php?import=wp-cat2tag&step=2" method="post"> - <p><input type="button" class="button-secondary" value="' . __('Check All') . '"' . ' onClick="this.value=check_all_rows()"></p>'; - wp_nonce_field('import-cat2tag'); - echo '<ul style="list-style:none">'; +<form name="catlist" id="catlist" action="admin.php?import=wp-cat2tag&step=2" method="post"> +<p><input type="button" class="button-secondary" value="<?php _e('Check All'); ?>" onclick="this.value=check_all_rows()"> +<?php wp_nonce_field('import-cat2tag'); ?></p> +<ul style="list-style:none"> +<?php $hier = _get_term_hierarchy('category'); foreach ($this->all_categories as $category) { $category = sanitize_term( $category, 'category', 'display' ); - if ((int) $category->parent == 0) { - echo '<li><label><input type="checkbox" name="cats_to_convert[]" value="' . intval($category->term_id) . '" /> ' . $category->name . ' (' . $category->count . ')</label>'; + if ( (int) $category->parent == 0 ) { + if ( in_array( intval($category->term_id), $this->hybrids_ids ) ) { +?> + <li style="color:#777;padding-left:1.3em;"><?php echo $category->name . ' (' . $category->count . ') *'; ?></li> +<?php + } else { +?> + <li><label><input type="checkbox" name="cats_to_convert[]" value="<?php echo intval($category->term_id); ?>" /> <?php echo $category->name . ' (' . $category->count . ')'; ?></label><?php - if (isset($hier[$category->term_id])) { - $this->_category_children($category, $hier); + if ( isset($hier[$category->term_id]) ) + $this->_category_children($category, $hier); +?></li> +<?php } + } + } +?> +</ul> + +<?php + if ( ! empty($this->hybrids_ids) ) { + echo '<p>' . __('* This category is also a tag. It cannot be convert again.') . '</p>'; + } +?> +<p class="submit"><input type="submit" name="submit" class="button" value="<?php _e('Convert Categories to Tags'); ?>" /></p> +</form> + +<?php + } - echo '</li>'; + function tags_tab() { + $this->populate_tags(); + $tags_num = count($this->all_tags); + + echo '<br class="clear" />'; + + if ( $tags_num > 0 ) { + echo '<h2>Convert Tags (' . $tags_num . ') to Categories.</h2>'; + echo '<div class="narrow">'; + echo '<p>' . __('Here you can selectively converts existing tags to categories. To get started, check the tags you wish to be converted, then click the Convert button.') . '</p>'; + echo '<p>' . __('The newly created categories will still be associated with the same posts.') . '</p></div>'; + + + $this->tags_form(); + } elseif ( $hyb_num > 0 ) { + echo '<p>' . __('You have no tags that can be converted. However some of your tags are both a tag and a category.') . '</p>'; + } else { + echo '<p>'.__('You have no tags to convert!').'</p>'; + } + } + + function tags_form() { ?> + +<script type="text/javascript"> +/* <![CDATA[ */ +var checktags = "false"; +function check_all_tagrows() { + field = document.taglist; + if ( 'false' == checktags ) { + for ( i = 0; i < field.length; i++ ) { + if ( 'tags_to_convert[]' == field[i].name ) + field[i].checked = true; + } + checktags = 'true'; + return '<?php _e('Uncheck All') ?>'; + } else { + for ( i = 0; i < field.length; i++ ) { + if ( 'tags_to_convert[]' == field[i].name ) + field[i].checked = false; + } + checktags = 'false'; + return '<?php _e('Check All') ?>'; + } +} +/* ]]> */ +</script> + +<form name="taglist" id="taglist" action="admin.php?import=wp-cat2tag&step=4" method="post"> +<p><input type="button" class="button-secondary" value="<?php _e('Check All'); ?>" onclick="this.value=check_all_tagrows()"> +<?php wp_nonce_field('import-cat2tag'); ?></p> +<ul style="list-style:none"> +<?php + foreach ( $this->all_tags as $tag ) { + if ( in_array( intval($tag->term_id), $this->hybrids_ids ) ) { +?> + <li style="color:#777;padding-left:1.3em;"><?php echo attribute_escape($tag->name) . ' (' . $tag->count . ') *'; ?></li> +<?php + } else { +?> + <li><label><input type="checkbox" name="tags_to_convert[]" value="<?php echo intval($tag->term_id); ?>" /> <?php echo attribute_escape($tag->name) . ' (' . $tag->count . ')'; ?></label></li> + +<?php } } +?> +</ul> - echo '</ul>'; +<?php + if ( ! empty($this->hybrids_ids) ) + echo '<p>' . __('* This tag is also a category. It cannot be converted again.') . '</p>'; +?> - echo '<p class="submit"><input type="submit" name="submit" class="button" value="' . __('Convert Tags') . '" /></p>'; +<p class="submit"><input type="submit" name="submit_tags" class="button" value="<?php _e('Convert Tags to Categories'); ?>" /></p> +</form> - echo '</form>'; +<?php } function _category_children($parent, $hier) { - echo '<ul style="list-style:none">'; +?> + <ul style="list-style:none"> +<?php foreach ($hier[$parent->term_id] as $child_id) { $child =& get_category($child_id); + + if ( in_array( intval($child->term_id), $this->hybrids_ids ) ) { +?> + <li style="color:#777;padding-left:1.3em;"><?php echo $child->name . ' (' . $child->count . ') *'; ?></li> +<?php + } else { +?> + <li><label><input type="checkbox" name="cats_to_convert[]" value="<?php echo intval($child->term_id); ?>" /> <?php echo $child->name . ' (' . $child->count . ')'; ?></label> +<?php - echo '<li><label><input type="checkbox" name="cats_to_convert[]" value="' . intval($child->term_id) . '" /> ' . $child->name . ' (' . $child->count . ')</label>'; - - if (isset($hier[$child->term_id])) { + if ( isset($hier[$child->term_id]) ) $this->_category_children($child, $hier); +?> </li> +<?php } - - echo '</li>'; } - - echo '</ul>'; +?> + </ul> +<?php } function _category_exists($cat_id) { @@ -125,7 +249,7 @@ function check_all_rows() { } } - function convert_them() { + function convert_categories() { global $wpdb; if ( (!isset($_POST['cats_to_convert']) || !is_array($_POST['cats_to_convert'])) && empty($this->categories_to_convert)) { @@ -135,7 +259,6 @@ function check_all_rows() { return; } - if ( empty($this->categories_to_convert) ) $this->categories_to_convert = $_POST['cats_to_convert']; $hier = _get_term_hierarchy('category'); @@ -164,12 +287,12 @@ function check_all_rows() { $id = $id['term_taxonomy_id']; $posts = get_objects_in_term($category->term_id, 'category'); foreach ( $posts as $post ) { - if ( !$wpdb->get_var("SELECT object_id FROM $wpdb->term_relationships WHERE object_id = '$post' AND term_taxonomy_id = '$id'") ) - $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ('$post', '$id')"); + if ( !$wpdb->get_var( $wpdb->prepare("SELECT object_id FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id = %d", $post, $id) ) ) + $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES (%d, %d)", $post, $id) ); clean_post_cache($post); } } else { - $tt_ids = $wpdb->get_col("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id = '{$category->term_id}' AND taxonomy = 'category'"); + $tt_ids = $wpdb->get_col( $wpdb->prepare("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id = %d AND taxonomy = 'category'", $category->term_id) ); if ( $tt_ids ) { $posts = $wpdb->get_col("SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id IN (" . join(',', $tt_ids) . ") GROUP BY object_id"); foreach ( (array) $posts as $post ) @@ -177,14 +300,14 @@ function check_all_rows() { } // Change the category to a tag. - $wpdb->query("UPDATE $wpdb->term_taxonomy SET taxonomy = 'post_tag' WHERE term_id = '{$category->term_id}' AND taxonomy = 'category'"); + $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET taxonomy = 'post_tag' WHERE term_id = %d AND taxonomy = 'category'", $category->term_id) ); - $terms = $wpdb->get_col("SELECT term_id FROM $wpdb->term_taxonomy WHERE parent = '{$category->term_id}' AND taxonomy = 'category'"); + $terms = $wpdb->get_col( $wpdb->prepare("SELECT term_id FROM $wpdb->term_taxonomy WHERE parent = %d AND taxonomy = 'category'", $category->term_id) ); foreach ( (array) $terms as $term ) clean_category_cache($term); // Set all parents to 0 (root-level) if their parent was the converted tag - $wpdb->query("UPDATE $wpdb->term_taxonomy SET parent = 0 WHERE parent = '{$category->term_id}' AND taxonomy = 'category'"); + $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET parent = 0 WHERE parent = %d AND taxonomy = 'category'", $category->term_id) ); } // Clean the cache clean_category_cache($category->term_id); @@ -199,27 +322,93 @@ function check_all_rows() { echo '<p>' . sprintf( __('We’re all done here, but you can always <a href="%s">convert more</a>.'), 'admin.php?import=wp-cat2tag' ) . '</p>'; } + function convert_tags() { + global $wpdb; + + if ( (!isset($_POST['tags_to_convert']) || !is_array($_POST['tags_to_convert'])) && empty($this->tags_to_convert)) { + echo '<div class="narrow">'; + echo '<p>' . sprintf(__('Uh, oh. Something didn’t work. Please <a href="%s">try again</a>.'), 'admin.php?import=wp-cat2tag&step=3') . '</p>'; + echo '</div>'; + return; + } + + if ( empty($this->categories_to_convert) ) + $this->tags_to_convert = $_POST['tags_to_convert']; + + $clean_cache = array(); + echo '<ul>'; + + foreach ( (array) $this->tags_to_convert as $tag_id) { + $tag_id = (int) $tag_id; + + echo '<li>' . sprintf(__('Converting tag #%s ... '), $tag_id); + + if ( ! is_term($tag_id, 'post_tag') ) { + _e('Tag doesn\'t exist!'); + } else { + + if ( is_term($tag_id, 'category') ) { + _e('This Tag is already a Category.'); + echo '</li>'; + continue; + } + + $tt_ids = $wpdb->get_col( $wpdb->prepare("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id = %d AND taxonomy = 'post_tag'", $tag_id) ); + if ( $tt_ids ) { + $posts = $wpdb->get_col("SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id IN (" . join(',', $tt_ids) . ") GROUP BY object_id"); + foreach ( (array) $posts as $post ) + clean_post_cache($post); + } + + // Change the tag to a category. + $parent = $wpdb->get_var( $wpdb->prepare("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = %d AND taxonomy = 'post_tag'", $tag_id) ); + if ( 0 == $parent || (0 < (int) $parent && $this->_category_exists($parent)) ) + $reset_parent = ''; + else $reset_parent = ", parent = '0'"; + + $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET taxonomy = 'category' $reset_parent WHERE term_id = %d AND taxonomy = 'post_tag'", $tag_id) ); + + // Clean the cache + $clean_cache[] = $tag_id; + + _e('Converted successfully.'); + } + + echo '</li>'; + } + + clean_term_cache( $clean_cache, 'post_tag' ); + delete_option('category_children'); + + echo '</ul>'; + echo '<p>' . sprintf( __('We’re all done here, but you can always <a href="%s">convert more</a>.'), 'admin.php?import=wp-cat2tag&step=3' ) . '</p>'; + } + function init() { $step = (isset($_GET['step'])) ? (int) $_GET['step'] : 1; $this->header(); - if (!current_user_can('manage_categories')) { - echo '<div class="narrow">'; - echo '<p>' . __('Cheatin’ uh?') . '</p>'; - echo '</div>'; - } else { - if ( $step > 1 ) - check_admin_referer('import-cat2tag'); + if ( current_user_can('manage_categories') ) { switch ($step) { case 1 : - $this->welcome(); + $this->categories_tab(); break; case 2 : - $this->convert_them(); + check_admin_referer('import-cat2tag'); + $this->convert_categories(); + break; + + case 3 : + $this->tags_tab(); + break; + + case 4 : + check_admin_referer('import-cat2tag'); + $this->convert_tags(); break; } } @@ -234,6 +423,6 @@ function check_all_rows() { $wp_cat2tag_importer = new WP_Categories_to_Tags(); -register_importer('wp-cat2tag', __('Categories to Tags Converter'), __('Convert existing categories to tags, selectively.'), array(&$wp_cat2tag_importer, 'init')); +register_importer('wp-cat2tag', __('Categories and Tags Converter'), __('Convert existing categories to tags or tags to categories, selectively.'), array(&$wp_cat2tag_importer, 'init')); ?> |