Make WordPress Core

Changeset 6394


Ignore:
Timestamp:
12/16/2007 10:07:32 PM (18 years ago)
Author:
matt
Message:

Change prints to echoes. Add check all button to avoid carpal clicking syndrome. Cleaned up some English. Fixes #5437. Hat tip: hailin. Changes from diff: moved JS inside of function so it didn't show up on every import page; moved button above form instead of next to submit button.

File:
1 edited

Legend:

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

    r6225 r6394  
    1 <?php
     1<?php 
    22
    33class WP_Categories_to_Tags {
     
    66
    77    function header() {
    8         print '<div class="wrap">';
    9         print '<h2>' . __('Convert Categories to Tags') . '</h2>';
     8        echo '<div class="wrap">';
     9        echo '<h2>' . __('Convert Categories to Tags') . '</h2>';
    1010    }
    1111
    1212    function footer() {
    13         print '</div>';
     13        echo '</div>';
    1414    }
    1515
     
    2727        $this->populate_all_categories();
    2828
    29         print '<div class="narrow">';
     29        echo '<div class="narrow">';
    3030
    3131        if (count($this->all_categories) > 0) {
    32             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>';
    33             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>';
     32            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>';
     33            echo '<p>' . __('Keep in mind that if you convert a category with child categories, the children become top-level orphans.') . '</p>';
    3434
    3535            $this->categories_form();
    3636        } else {
    37             print '<p>'.__('You have no categories to convert!').'</p>';
    38         }
    39 
    40         print '</div>';
     37            echo '<p>'.__('You have no categories to convert!').'</p>';
     38        }
     39
     40        echo '</div>';
    4141    }
    4242
    4343    function categories_form() {
    44         print '<form action="admin.php?import=wp-cat2tag&amp;step=2" method="post">';
     44?>
     45<script type="text/javascript">
     46<!--
     47var checkflag = "false";
     48function check_all_rows() {
     49    field = document.formlist;
     50    if ( 'false' == checkflag ) {
     51        for ( i = 0; i < field.length; i++ ) {
     52            if ( 'cats_to_convert[]' == field[i].name )
     53                field[i].checked = true;
     54        }
     55        checkflag = 'true';
     56        return '<?php _e('Uncheck All') ?>';
     57    } else {
     58        for ( i = 0; i < field.length; i++ ) {
     59            if ( 'cats_to_convert[]' == field[i].name )
     60                field[i].checked = false;
     61        }
     62        checkflag = 'false';
     63        return '<?php _e('Check All') ?>';
     64    }
     65}
     66
     67//  -->
     68</script>
     69<?php
     70        echo '<form name="formlist" id="formlist" action="admin.php?import=wp-cat2tag&amp;step=2" method="post">
     71        <p><input type="button" value="' . __('Check All') . '"' . ' onClick="this.value=check_all_rows()"></p>';
    4572        wp_nonce_field('import-cat2tag');
    46         print '<ul style="list-style:none">';
     73        echo '<ul style="list-style:none">';
    4774
    4875        $hier = _get_term_hierarchy('category');
     
    5279       
    5380            if ((int) $category->parent == 0) {
    54                 print '<li><label><input type="checkbox" name="cats_to_convert[]" value="' . intval($category->term_id) . '" /> ' . $category->name . ' (' . $category->count . ')</label>';
     81                echo '<li><label><input type="checkbox" name="cats_to_convert[]" value="' . intval($category->term_id) . '" /> ' . $category->name . ' (' . $category->count . ')</label>';
    5582
    5683                if (isset($hier[$category->term_id])) {
     
    5885                }
    5986
    60                 print '</li>';
    61             }
    62         }
    63 
    64         print '</ul>';
    65 
    66         print '<p class="submit"><input type="submit" name="submit" value="' . __('Convert &raquo;') . '" /></p>';
    67         print '</form>';
     87                echo '</li>';
     88            }
     89        }
     90
     91        echo '</ul>';
     92
     93        echo '<p class="submit"><input type="submit" name="submit" value="' . __('Convert Tags &raquo;') . '" /></p>';
     94
     95        echo '</form>';
    6896    }
    6997
    7098    function _category_children($parent, $hier) {
    71         print '<ul style="list-style:none">';
     99        echo '<ul style="list-style:none">';
    72100
    73101        foreach ($hier[$parent->term_id] as $child_id) {
    74102            $child =& get_category($child_id);
    75103
    76             print '<li><label><input type="checkbox" name="cats_to_convert[]" value="' . intval($child->term_id) . '" /> ' . $child->name . ' (' . $child->count . ')</label>';
     104            echo '<li><label><input type="checkbox" name="cats_to_convert[]" value="' . intval($child->term_id) . '" /> ' . $child->name . ' (' . $child->count . ')</label>';
    77105
    78106            if (isset($hier[$child->term_id])) {
     
    80108            }
    81109
    82             print '</li>';
    83         }
    84 
    85         print '</ul>';
     110            echo '</li>';
     111        }
     112
     113        echo '</ul>';
    86114    }
    87115
     
    104132
    105133        if ( (!isset($_POST['cats_to_convert']) || !is_array($_POST['cats_to_convert'])) && empty($this->categories_to_convert)) {
    106             print '<div class="narrow">';
    107             print '<p>' . sprintf(__('Uh, oh. Something didn\'t work. Please <a href="%s">try again</a>.'), 'admin.php?import=wp-cat2tag') . '</p>';
    108             print '</div>';
     134            echo '<div class="narrow">';
     135            echo '<p>' . sprintf(__('Uh, oh. Something didn&#8217;t work. Please <a href="%s">try again</a>.'), 'admin.php?import=wp-cat2tag') . '</p>';
     136            echo '</div>';
    109137            return;
    110138        }
     
    115143        $hier = _get_term_hierarchy('category');
    116144
    117         print '<ul>';
     145        echo '<ul>';
    118146
    119147        foreach ( (array) $this->categories_to_convert as $cat_id) {
    120148            $cat_id = (int) $cat_id;
    121149
    122             print '<li>' . sprintf(__('Converting category #%s ... '),  $cat_id);
     150            echo '<li>' . sprintf(__('Converting category #%s ... '),  $cat_id);
    123151
    124152            if (!$this->_category_exists($cat_id)) {
     
    129157                if ( tag_exists($wpdb->escape($category->name)) ) {
    130158                    _e('Category is already a tag.');
    131                     print '</li>';
     159                    echo '</li>';
    132160                    continue;
    133161                }
     
    167195            }
    168196
    169             print '</li>';
    170         }
    171 
    172         print '</ul>';
     197            echo '</li>';
     198        }
     199
     200        echo '</ul>';
     201        echo '<p>' . sprintf( __('We&#8217;re all done here, but you can always <a href="%s">convert more</a>.'), 'admin.php?import=wp-cat2tag' ) . '</p>';
    173202    }
    174203
     
    180209
    181210        if (!current_user_can('manage_categories')) {
    182             print '<div class="narrow">';
    183             print '<p>' . __('Cheatin&#8217; uh?') . '</p>';
    184             print '</div>';
     211            echo '<div class="narrow">';
     212            echo '<p>' . __('Cheatin&#8217; uh?') . '</p>';
     213            echo '</div>';
    185214        } else {
    186215            if ( $step > 1 )
Note: See TracChangeset for help on using the changeset viewer.