summaryrefslogtreecommitdiffstats
path: root/wp-admin/import
diff options
context:
space:
mode:
authordonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2007-05-21 21:35:12 +0000
committerdonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2007-05-21 21:35:12 +0000
commit1945437f261353791a656f7fd6d450736c941ee1 (patch)
treecf978bc00280185242f3b8e9cb55884185912cda /wp-admin/import
parent577d5d307e7d38e9619a653d16d5bdbd607ee1fb (diff)
downloadwordpress-mu-1945437f261353791a656f7fd6d450736c941ee1.tar.gz
wordpress-mu-1945437f261353791a656f7fd6d450736c941ee1.tar.xz
wordpress-mu-1945437f261353791a656f7fd6d450736c941ee1.zip
Too soon for these
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@974 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-admin/import')
-rw-r--r--wp-admin/import/utw.php270
-rw-r--r--wp-admin/import/wp-cat2tag.php226
2 files changed, 0 insertions, 496 deletions
diff --git a/wp-admin/import/utw.php b/wp-admin/import/utw.php
deleted file mode 100644
index 824ba50..0000000
--- a/wp-admin/import/utw.php
+++ /dev/null
@@ -1,270 +0,0 @@
-<?php
-
-class UTW_Import {
-
- function header() {
- echo '<div class="wrap">';
- echo '<h2>'.__('Import Ultimate Tag Warrior').'</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">';
- echo '<p>'.__('Howdy! This imports tags from an existing Ultimate Tag Warrior 3 installation into this blog using the new WordPress native tagging structure.').'</p>';
- echo '<p>'.__('This has not been tested on any other versions of Ultimate Tag Warrior. Mileage may vary.').'</p>';
- echo '<p>'.__('To accommodate larger databases for those tag-crazy authors out there, we have made this into an easy 5-step program to help you kick that nasty UTW habit. Just keep clicking along and we will let you know when you are in the clear!').'</p>';
- echo '<p><strong>'.__('Don&#8217;t be stupid - backup your database before proceeding!').'</strong></p>';
- echo '<form action="admin.php?import=utw&amp;step=1" method="post">';
- echo '<p class="submit"><input type="submit" name="submit" value="'.__('Step 1 &raquo;').'" /></p>';
- echo '</form>';
- echo '</div>';
- }
-
-
- function dispatch () {
- if ( empty( $_GET['step'] ) ) {
- $step = 0;
- } else {
- $step = (int) $_GET['step'];
- }
-
- // load the header
- $this->header();
-
- switch ( $step ) {
- case 0 :
- $this->greet();
- break;
- case 1 :
- $this->import_tags();
- break;
- case 2 :
- $this->import_posts();
- break;
- case 3:
- $this->import_t2p();
- break;
- case 4:
- $this->cleanup_import();
- break;
- }
-
- // load the footer
- $this->footer();
- }
-
-
- function import_tags ( ) {
- echo '<div class="narrow">';
- echo '<p><h3>'.__('Reading UTW Tags&#8230;').'</h3></p>';
-
- $tags = $this->get_utw_tags();
-
- // if we didn't get any tags back, that's all there is folks!
- if ( !is_array($tags) ) {
- echo '<p>' . __('No Tags Found!') . '</p>';
- return false;
- }
- else {
-
- // if there's an existing entry, delete it
- if ( get_option('utwimp_tags') ) {
- delete_option('utwimp_tags');
- }
-
- add_option('utwimp_tags', $tags);
-
-
- $count = count($tags);
-
- echo '<p>' . sprintf( __('Done! <strong>%s</strong> tags were read.'), $count ) . '<br /></p>';
- echo '<p>' . __('The following tags were found:') . '</p>';
-
- echo '<ul>';
-
- foreach ( $tags as $tag_id => $tag_name ) {
-
- echo '<li>' . $tag_name . '</li>';
-
- }
-
- echo '</ul>';
-
- echo '<br />';
-
- echo '<p>' . __('If you don&#8217;t want to import any of these tags, you should delete them from the UTW tag management page and then re-run this import.') . '</p>';
-
-
- }
-
- echo '<form action="admin.php?import=utw&amp;step=2" method="post">';
- echo '<p class="submit"><input type="submit" name="submit" value="'.__('Step 2 &raquo;').'" /></p>';
- echo '</form>';
- echo '</div>';
- }
-
-
- function import_posts ( ) {
- echo '<div class="narrow">';
- echo '<p><h3>'.__('Reading UTW Post Tags&#8230;').'</h3></p>';
-
- // read in all the UTW tag -> post settings
- $posts = $this->get_utw_posts();
-
- // if we didn't get any tags back, that's all there is folks!
- if ( !is_array($posts) ) {
- echo '<p>' . __('No posts were found to have tags!') . '</p>';
- return false;
- }
- else {
-
- // if there's an existing entry, delete it
- if ( get_option('utwimp_posts') ) {
- delete_option('utwimp_posts');
- }
-
- add_option('utwimp_posts', $posts);
-
-
- $count = count($posts);
-
- echo '<p>' . sprintf( __('Done! <strong>%s</strong> tag to post relationships were read.'), $count ) . '<br /></p>';
-
- }
-
- echo '<form action="admin.php?import=utw&amp;step=3" method="post">';
- echo '<p class="submit"><input type="submit" name="submit" value="'.__('Step 3 &raquo;').'" /></p>';
- echo '</form>';
- echo '</div>';
-
- }
-
-
- function import_t2p ( ) {
-
- echo '<div class="narrow">';
- echo '<p><h3>'.__('Adding Tags to Posts&#8230;').'</h3></p>';
-
- // run that funky magic!
- $tags_added = $this->tag2post();
-
- echo '<p>' . sprintf( __('Done! <strong>%s</strong> tags where added!'), $tags_added ) . '<br /></p>';
-
- echo '<form action="admin.php?import=utw&amp;step=4" method="post">';
- echo '<p class="submit"><input type="submit" name="submit" value="'.__('Step 4 &raquo;').'" /></p>';
- echo '</form>';
- echo '</div>';
-
- }
-
-
- function get_utw_tags ( ) {
-
- global $wpdb;
-
- // read in all the tags from the UTW tags table: should be wp_tags
- $tags_query = "SELECT tag_id, tag FROM " . $wpdb->prefix . "tags";
-
- $tags = $wpdb->get_results($tags_query);
-
- // rearrange these tags into something we can actually use
- foreach ( $tags as $tag ) {
-
- $new_tags[$tag->tag_id] = $tag->tag;
-
- }
-
- return $new_tags;
-
- }
-
- function get_utw_posts ( ) {
-
- global $wpdb;
-
- // read in all the posts from the UTW post->tag table: should be wp_post2tag
- $posts_query = "SELECT tag_id, post_id FROM " . $wpdb->prefix . "post2tag";
-
- $posts = $wpdb->get_results($posts_query);
-
- return $posts;
-
- }
-
-
- function tag2post ( ) {
-
- // get the tags and posts we imported in the last 2 steps
- $tags = get_option('utwimp_tags');
- $posts = get_option('utwimp_posts');
-
- // null out our results
- $tags_added = 0;
-
- // loop through each post and add its tags to the db
- foreach ( $posts as $this_post ) {
-
- $the_post = (int) $this_post->post_id;
- $the_tag = (int) $this_post->tag_id;
-
- // what's the tag name for that id?
- $the_tag = $tags[$the_tag];
-
- // screw it, just try to add the tag
- wp_add_post_tags($the_post, $the_tag);
-
- $tags_added++;
-
- }
-
- // that's it, all posts should be linked to their tags properly, pending any errors we just spit out!
- return $tags_added;
-
-
- }
-
-
- function cleanup_import ( ) {
-
- delete_option('utwimp_tags');
- delete_option('utwimp_posts');
-
- $this->done();
-
- }
-
-
- function done ( ) {
-
- echo '<div class="narrow">';
- echo '<p><h3>'.__('Import Complete!').'</h3></p>';
-
- echo '<p>' . __('OK, so we lied about this being a 5-step program! You&#8217;re done!') . '</p>';
-
- echo '<p>' . __('Now wasn&#8217;t that easy?') . '</p>';
-
- echo '</div>';
-
- }
-
-
- function UTW_Import ( ) {
-
- // Nothing.
-
- }
-
-}
-
-
-// create the import object
-$utw_import = new UTW_Import();
-
-// add it to the import page!
-register_importer('utw', 'Ultimate Tag Warrior', __('Import Ultimate Tag Warrior tags into the new native tagging structure.'), array($utw_import, 'dispatch'));
-
-?> \ No newline at end of file
diff --git a/wp-admin/import/wp-cat2tag.php b/wp-admin/import/wp-cat2tag.php
deleted file mode 100644
index 6df9f1c..0000000
--- a/wp-admin/import/wp-cat2tag.php
+++ /dev/null
@@ -1,226 +0,0 @@
-<?php
-
-class WP_Categories_to_Tags {
- var $categories_to_convert = array();
- var $all_categories = array();
-
- function header() {
- print '<div class="wrap">';
- print '<h2>' . __('Convert Categories to Tags') . '</h2>';
- }
-
- function footer() {
- print '</div>';
- }
-
- function populate_all_categories() {
- global $wpdb;
-
- $this->all_categories = $wpdb->get_results("SELECT * FROM $wpdb->categories WHERE (type & ~ " . TAXONOMY_TAG . ") != 0 AND category_count > 0 ORDER BY cat_name ASC");
- }
-
- function welcome() {
- $this->populate_all_categories();
-
- print '<div class="narrow">';
-
- if (count($this->all_categories) > 0) {
- print '<p>' . __('Howdy! This converter allows you to selectively convert existing categories to tags. To get started, check the checkboxes of the categories you wish to be converted, then click the Convert button.') . '</p>';
- print '<p>' . __('Keep in mind that if you convert a category with child categories, those child categories get their parent setting removed, so they\'re in the root.') . '</p>';
-
- $this->categories_form();
- } else {
- print '<p>'.__('You have no categories to convert!').'</p>';
- }
-
- print '</div>';
- }
-
- function categories_form() {
- print '<form action="admin.php?import=wp-cat2tag&amp;step=2" method="post">';
- print '<ul style="list-style:none">';
-
- $hier = _get_category_hierarchy();
-
- foreach ($this->all_categories as $category) {
- if ((int) $category->category_parent == 0) {
- print '<li><label><input type="checkbox" name="cats_to_convert[]" value="' . intval($category->cat_ID) . '" /> ' . $category->cat_name . ' (' . $category->category_count . ')</label>';
-
- if (isset($hier[$category->cat_ID])) {
- $this->_category_children($category, $hier);
- }
-
- print '</li>';
- }
- }
-
- print '</ul>';
-
- print '<p class="submit"><input type="submit" name="maybe_convert_all_cats" value="' . __('Convert All Categories') . '" /> <input type="submit" name="submit" value="' . __('Convert &raquo;') . '" /></p>';
- print '</form>';
- }
-
- function _category_children($parent, $hier) {
- print '<ul style="list-style:none">';
-
- foreach ($hier[$parent->cat_ID] as $child_id) {
- $child =& get_category($child_id);
-
- print '<li><label><input type="checkbox" name="cats_to_convert[]" value="' . intval($child->cat_ID) . '" /> ' . $child->cat_name . ' (' . $child->category_count . ')</label>';
-
- if (isset($hier[$child->cat_ID])) {
- $this->_category_children($child, $hier);
- }
-
- print '</li>';
- }
-
- print '</ul>';
- }
-
- function _category_exists($cat_id) {
- global $wpdb;
-
- $cat_id = (int) $cat_id;
-
- $maybe_exists = $wpdb->get_results("SELECT cat_ID from $wpdb->categories WHERE cat_ID = '$cat_id'");
-
- if (count($maybe_exists) > 0) {
- return true;
- } else {
- return false;
- }
- }
-
- function convert_them() {
- global $wpdb;
-
- if (!isset($_POST['cats_to_convert']) || !is_array($_POST['cats_to_convert'])) {
- print '<div class="narrow">';
- print '<p>' . sprintf(__('Uh, oh. Something didn\'t work. Please <a href="%s">try again</a>.'), 'admin.php?import=wp-cat2tag') . '</p>';
- print '</div>';
- }
-
- $this->categories_to_convert = $_POST['cats_to_convert'];
- $hier = _get_category_hierarchy();
-
- print '<ul>';
-
- foreach ($this->categories_to_convert as $cat_id) {
- $cat_id = (int) $cat_id;
-
- print '<li>' . __('Converting category') . ' #' . $cat_id . '... ';
-
- if (!$this->_category_exists($cat_id)) {
- _e('Category doesn\'t exist!');
- } else {
- $category =& get_category($cat_id);
-
- if ($category->link_count > 0) {
- $type = $category->type | TAXONOMY_TAG;
- } else {
- $type = TAXONOMY_TAG;
- }
-
- // Set the category itself to $type from above
- $wpdb->query("UPDATE $wpdb->categories SET type = '$type' WHERE cat_ID = '{$category->cat_ID}'");
-
- // Set relationships in post2cat to 'tag', category_count becomes tag_count
- $wpdb->query("UPDATE $wpdb->post2cat SET rel_type = 'tag' WHERE category_ID = '{$category->cat_ID}'");
- $wpdb->query("UPDATE $wpdb->categories SET tag_count = '{$category->category_count}', category_count = '0' WHERE cat_ID = '{$category->cat_ID}'");
-
- // Set all parents to 0 (root-level) if their parent was the converted tag
- $wpdb->query("UPDATE $wpdb->categories SET category_parent = 0 WHERE category_parent = '{$category->cat_ID}'");
-
- // Clean the cache
- clean_category_cache($category->cat_ID);
-
- _e('Converted successfully.');
- }
-
- print '</li>';
- }
-
- print '</ul>';
- }
-
- function convert_all_confirm() {
- print '<div class="narrow">';
-
- print '<h3>' . __('Confirm') . '</h3>';
-
- print '<p>' . __('You are about to convert all categories to tags. Are you sure you want to continue?') . '</p>';
-
- print '<form action="admin.php?import=wp-cat2tag" method="post">';
- print '<p style="text-align:center" class="submit"><input type="submit" value="' . __('Yes') . '" name="yes_convert_all_cats" />&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="' . __('No') . '" name="no_dont_do_it" /></p>';
- print '</form>';
-
- print '</div>';
- }
-
- function convert_all() {
- global $wpdb;
-
- $cats = $wpdb->get_results("SELECT * FROM $wpdb->categories WHERE (type & ~ " . TAXONOMY_TAG . ") != 0 AND category_count > 0");
-
- $_POST['cats_to_convert'] = array();
-
- foreach ($cats as $cat) {
- $_POST['cats_to_convert'][] = $cat->cat_ID;
- }
-
- $this->convert_them();
- }
-
- function init() {
- echo '<!--'; print_r($_POST); print_r($_GET); echo '-->';
-
- if (isset($_POST['maybe_convert_all_cats'])) {
- $step = 3;
- } elseif (isset($_POST['yes_convert_all_cats'])) {
- $step = 4;
- } elseif (isset($_POST['no_dont_do_it'])) {
- die('no_dont_do_it');
- } else {
- $step = (isset($_GET['step'])) ? (int) $_GET['step'] : 1;
- }
-
- $this->header();
-
- if (!current_user_can('manage_categories')) {
- print '<div class="narrow">';
- print '<p>' . __('Cheatin&#8217; uh?') . '</p>';
- print '</div>';
- } else {
- switch ($step) {
- case 1 :
- $this->welcome();
- break;
-
- case 2 :
- $this->convert_them();
- break;
-
- case 3 :
- $this->convert_all_confirm();
- break;
-
- case 4 :
- $this->convert_all();
- break;
- }
- }
-
- $this->footer();
- }
-
- function WP_Categories_to_Tags() {
- // Do nothing.
- }
-}
-
-$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'));
-
-?>