Changeset 5700 for trunk/wp-admin/import/wp-cat2tag.php
- Timestamp:
- 06/14/2007 02:25:30 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/import/wp-cat2tag.php
r5554 r5700 4 4 var $categories_to_convert = array(); 5 5 var $all_categories = array(); 6 6 7 7 function header() { 8 8 print '<div class="wrap">'; 9 9 print '<h2>' . __('Convert Categories to Tags') . '</h2>'; 10 10 } 11 11 12 12 function footer() { 13 13 print '</div>'; 14 14 } 15 15 16 16 function populate_all_categories() { 17 17 global $wpdb; 18 18 19 19 $this->all_categories = get_categories('get=all'); 20 20 } 21 21 22 22 function welcome() { 23 23 $this->populate_all_categories(); 24 24 25 25 print '<div class="narrow">'; 26 26 27 27 if (count($this->all_categories) > 0) { 28 28 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>'; 29 29 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>'; 30 30 31 31 $this->categories_form(); 32 32 } else { 33 33 print '<p>'.__('You have no categories to convert!').'</p>'; 34 34 } 35 35 36 36 print '</div>'; 37 37 } 38 38 39 39 function categories_form() { 40 40 print '<form action="admin.php?import=wp-cat2tag&step=2" method="post">'; 41 41 print '<ul style="list-style:none">'; 42 42 43 43 $hier = _get_term_hierarchy('category'); 44 44 45 45 foreach ($this->all_categories as $category) { 46 46 if ((int) $category->parent == 0) { 47 47 print '<li><label><input type="checkbox" name="cats_to_convert[]" value="' . intval($category->term_id) . '" /> ' . $category->name . ' (' . $category->count . ')</label>'; 48 48 49 49 if (isset($hier[$category->term_id])) { 50 50 $this->_category_children($category, $hier); 51 51 } 52 52 53 53 print '</li>'; 54 54 } 55 55 } 56 56 57 57 print '</ul>'; 58 58 59 59 print '<p class="submit"><input type="submit" name="maybe_convert_all_cats" value="' . __('Convert All Categories') . '" /> <input type="submit" name="submit" value="' . __('Convert »') . '" /></p>'; 60 60 print '</form>'; 61 61 } 62 62 63 63 function _category_children($parent, $hier) { 64 64 print '<ul style="list-style:none">'; 65 65 66 66 foreach ($hier[$parent->term_id] as $child_id) { 67 67 $child =& get_category($child_id); 68 68 69 69 print '<li><label><input type="checkbox" name="cats_to_convert[]" value="' . intval($child->term_id) . '" /> ' . $child->name . ' (' . $child->count . ')</label>'; 70 70 71 71 if (isset($hier[$child->term_id])) { 72 72 $this->_category_children($child, $hier); 73 73 } 74 74 75 75 print '</li>'; 76 76 } 77 77 78 78 print '</ul>'; 79 79 } 80 80 81 81 function _category_exists($cat_id) { 82 82 global $wpdb; 83 83 84 84 $cat_id = (int) $cat_id; 85 85 86 86 $maybe_exists = category_exists($cat_id); 87 87 88 88 if ( $maybe_exists ) { 89 89 return true; … … 92 92 } 93 93 } 94 94 95 95 function convert_them() { 96 96 global $wpdb; 97 97 98 98 if (!isset($_POST['cats_to_convert']) || !is_array($_POST['cats_to_convert'])) { 99 99 print '<div class="narrow">'; … … 101 101 print '</div>'; 102 102 } 103 104 103 104 105 105 if ( empty($this->categories_to_convert) ) 106 106 $this->categories_to_convert = $_POST['cats_to_convert']; 107 107 $hier = _get_term_hierarchy('category'); 108 108 109 109 print '<ul>'; 110 110 111 111 foreach ($this->categories_to_convert as $cat_id) { 112 112 $cat_id = (int) $cat_id; 113 113 114 114 print '<li>' . __('Converting category') . ' #' . $cat_id . '... '; 115 115 116 116 if (!$this->_category_exists($cat_id)) { 117 117 _e('Category doesn\'t exist!'); 118 118 } else { 119 119 $category =& get_category($cat_id); 120 120 121 121 // Set the category itself to $type from above 122 122 $wpdb->query("UPDATE $wpdb->term_taxonomy SET taxonomy = 'post_tag' WHERE term_id = '{$category->term_id}' AND taxonomy = 'category'"); 123 123 124 124 // Set all parents to 0 (root-level) if their parent was the converted tag 125 125 $wpdb->query("UPDATE $wpdb->term_taxonomy SET parent = 0 WHERE parent = '{$category->term_id}' AND taxonomy = 'category'"); 126 126 127 127 // Clean the cache 128 128 clean_category_cache($category->term_id); 129 129 130 130 _e('Converted successfully.'); 131 131 } 132 132 133 133 print '</li>'; 134 134 } 135 135 136 136 print '</ul>'; 137 137 } 138 138 139 139 function convert_all_confirm() { 140 140 print '<div class="narrow">'; 141 141 142 142 print '<h3>' . __('Confirm') . '</h3>'; 143 143 144 144 print '<p>' . __('You are about to convert all categories to tags. Are you sure you want to continue?') . '</p>'; 145 145 146 146 print '<form action="admin.php?import=wp-cat2tag" method="post">'; 147 147 print '<p style="text-align:center" class="submit"><input type="submit" value="' . __('Yes') . '" name="yes_convert_all_cats" /> <input type="submit" value="' . __('No') . '" name="no_dont_do_it" /></p>'; 148 148 print '</form>'; 149 149 150 150 print '</div>'; 151 151 } 152 152 153 153 function convert_all() { 154 154 global $wpdb; … … 157 157 clean_category_cache($category->term_id); 158 158 } 159 159 160 160 function init() { 161 161 echo '<!--'; print_r($_POST); print_r($_GET); echo '-->'; 162 162 163 163 if (isset($_POST['maybe_convert_all_cats'])) { 164 164 $step = 3; … … 170 170 $step = (isset($_GET['step'])) ? (int) $_GET['step'] : 1; 171 171 } 172 172 173 173 $this->header(); 174 174 175 175 if (!current_user_can('manage_categories')) { 176 176 print '<div class="narrow">'; … … 182 182 $this->welcome(); 183 183 break; 184 184 185 185 case 2 : 186 186 $this->convert_them(); 187 187 break; 188 188 189 189 case 3 : 190 190 $this->convert_all_confirm(); 191 191 break; 192 192 193 193 case 4 : 194 194 $this->convert_all(); … … 196 196 } 197 197 } 198 198 199 199 $this->footer(); 200 200 } 201 201 202 202 function WP_Categories_to_Tags() { 203 203 // Do nothing.
Note: See TracChangeset
for help on using the changeset viewer.