Make WordPress Core


Ignore:
Timestamp:
06/14/2007 02:25:30 AM (19 years ago)
Author:
ryan
Message:

Trim empty lines. Nothing but newline.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/import/wp-cat2tag.php

    r5554 r5700  
    44        var $categories_to_convert = array();
    55        var $all_categories = array();
    6        
     6
    77        function header() {
    88                print '<div class="wrap">';
    99                print '<h2>' . __('Convert Categories to Tags') . '</h2>';
    1010        }
    11        
     11
    1212        function footer() {
    1313                print '</div>';
    1414        }
    15        
     15
    1616        function populate_all_categories() {
    1717                global $wpdb;
    18                
     18
    1919                $this->all_categories = get_categories('get=all');
    2020        }
    21        
     21
    2222        function welcome() {
    2323                $this->populate_all_categories();
    24                
     24
    2525                print '<div class="narrow">';
    26                
     26
    2727                if (count($this->all_categories) > 0) {
    2828                        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>';
    2929                        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
    3131                        $this->categories_form();
    3232                } else {
    3333                        print '<p>'.__('You have no categories to convert!').'</p>';
    3434                }
    35                
     35
    3636                print '</div>';
    3737        }
    38        
     38
    3939        function categories_form() {
    4040                print '<form action="admin.php?import=wp-cat2tag&amp;step=2" method="post">';
    4141                print '<ul style="list-style:none">';
    42                
     42
    4343                $hier = _get_term_hierarchy('category');
    44                
     44
    4545                foreach ($this->all_categories as $category) {
    4646                        if ((int) $category->parent == 0) {
    4747                                print '<li><label><input type="checkbox" name="cats_to_convert[]" value="' . intval($category->term_id) . '" /> ' . $category->name . ' (' . $category->count . ')</label>';
    48                                
     48
    4949                                if (isset($hier[$category->term_id])) {
    5050                                        $this->_category_children($category, $hier);
    5151                                }
    52                                
     52
    5353                                print '</li>';
    5454                        }
    5555                }
    56                
     56
    5757                print '</ul>';
    58                
     58
    5959                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>';
    6060                print '</form>';
    6161        }
    62        
     62
    6363        function _category_children($parent, $hier) {
    6464                print '<ul style="list-style:none">';
    65                
     65
    6666                foreach ($hier[$parent->term_id] as $child_id) {
    6767                        $child =& get_category($child_id);
    68                        
     68
    6969                        print '<li><label><input type="checkbox" name="cats_to_convert[]" value="' . intval($child->term_id) . '" /> ' . $child->name . ' (' . $child->count . ')</label>';
    70                        
     70
    7171                        if (isset($hier[$child->term_id])) {
    7272                                $this->_category_children($child, $hier);
    7373                        }
    74                        
     74
    7575                        print '</li>';
    7676                }
    77                
     77
    7878                print '</ul>';
    7979        }
    80        
     80
    8181        function _category_exists($cat_id) {
    8282                global $wpdb;
    83                
     83
    8484                $cat_id = (int) $cat_id;
    85                
     85
    8686                $maybe_exists = category_exists($cat_id);
    87                
     87
    8888                if ( $maybe_exists ) {
    8989                        return true;
     
    9292                }
    9393        }
    94        
     94
    9595        function convert_them() {
    9696                global $wpdb;
    97                
     97
    9898                if (!isset($_POST['cats_to_convert']) || !is_array($_POST['cats_to_convert'])) {
    9999                        print '<div class="narrow">';
     
    101101                        print '</div>';
    102102                }
    103                
    104                
     103
     104
    105105                if ( empty($this->categories_to_convert) )
    106106                        $this->categories_to_convert = $_POST['cats_to_convert'];
    107107                $hier = _get_term_hierarchy('category');
    108                
     108
    109109                print '<ul>';
    110                
     110
    111111                foreach ($this->categories_to_convert as $cat_id) {
    112112                        $cat_id = (int) $cat_id;
    113                        
     113
    114114                        print '<li>' . __('Converting category') . ' #' . $cat_id . '... ';
    115                        
     115
    116116                        if (!$this->_category_exists($cat_id)) {
    117117                                _e('Category doesn\'t exist!');
    118118                        } else {
    119119                                $category =& get_category($cat_id);
    120                                
     120
    121121                                // Set the category itself to $type from above
    122122                                $wpdb->query("UPDATE $wpdb->term_taxonomy SET taxonomy = 'post_tag' WHERE term_id = '{$category->term_id}' AND taxonomy = 'category'");
    123                                
     123
    124124                                // Set all parents to 0 (root-level) if their parent was the converted tag
    125125                                $wpdb->query("UPDATE $wpdb->term_taxonomy SET parent = 0 WHERE parent = '{$category->term_id}' AND taxonomy = 'category'");
    126                                
     126
    127127                                // Clean the cache
    128128                                clean_category_cache($category->term_id);
    129                                
     129
    130130                                _e('Converted successfully.');
    131131                        }
    132                        
     132
    133133                        print '</li>';
    134134                }
    135                
     135
    136136                print '</ul>';
    137137        }
    138        
     138
    139139        function convert_all_confirm() {
    140140                print '<div class="narrow">';
    141                
     141
    142142                print '<h3>' . __('Confirm') . '</h3>';
    143                
     143
    144144                print '<p>' . __('You are about to convert all categories to tags. Are you sure you want to continue?') . '</p>';
    145                
     145
    146146                print '<form action="admin.php?import=wp-cat2tag" method="post">';
    147147                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>';
    148148                print '</form>';
    149                
     149
    150150                print '</div>';
    151151        }
    152        
     152
    153153        function convert_all() {
    154154                global $wpdb;
     
    157157                clean_category_cache($category->term_id);
    158158        }
    159        
     159
    160160        function init() {
    161161                echo '<!--'; print_r($_POST); print_r($_GET); echo '-->';
    162                
     162
    163163                if (isset($_POST['maybe_convert_all_cats'])) {
    164164                        $step = 3;
     
    170170                        $step = (isset($_GET['step'])) ? (int) $_GET['step'] : 1;
    171171                }
    172                
     172
    173173                $this->header();
    174                
     174
    175175                if (!current_user_can('manage_categories')) {
    176176                        print '<div class="narrow">';
     
    182182                                        $this->welcome();
    183183                                break;
    184                                
     184
    185185                                case 2 :
    186186                                        $this->convert_them();
    187187                                break;
    188                                
     188
    189189                                case 3 :
    190190                                        $this->convert_all_confirm();
    191191                                break;
    192                                
     192
    193193                                case 4 :
    194194                                        $this->convert_all();
     
    196196                        }
    197197                }
    198                
     198
    199199                $this->footer();
    200200        }
    201        
     201
    202202        function WP_Categories_to_Tags() {
    203203                // Do nothing.
Note: See TracChangeset for help on using the changeset viewer.