Wordpress 2.8.5-scripts
[autoinstalls/wordpress.git] / wp-admin / categories.php
1 <?php
2 /**
3  * Categories Management Panel
4  *
5  * @package WordPress
6  * @subpackage Administration
7  */
8
9 /** Load WordPress Bootstrap */
10 require_once('admin.php');
11
12 $title = __('Categories');
13
14 wp_reset_vars( array('action', 'cat') );
15
16 if ( isset( $_GET['action'] ) && isset($_GET['delete']) && ( 'delete' == $_GET['action'] || 'delete' == $_GET['action2'] ) )
17         $action = 'bulk-delete';
18
19 switch($action) {
20
21 case 'addcat':
22
23         check_admin_referer('add-category');
24
25         if ( !current_user_can('manage_categories') )
26                 wp_die(__('Cheatin&#8217; uh?'));
27
28         if ( wp_insert_category($_POST ) )
29                 wp_safe_redirect( add_query_arg( 'message', 1, wp_get_referer() ) . '#addcat' );
30         else
31                 wp_safe_redirect( add_query_arg( 'message', 4, wp_get_referer() ) . '#addcat' );
32
33         exit;
34 break;
35
36 case 'delete':
37         $cat_ID = (int) $_GET['cat_ID'];
38         check_admin_referer('delete-category_' .  $cat_ID);
39
40         if ( !current_user_can('manage_categories') )
41                 wp_die(__('Cheatin&#8217; uh?'));
42
43         $cat_name = get_cat_name($cat_ID);
44
45         // Don't delete the default cats.
46         if ( $cat_ID == get_option('default_category') )
47                 wp_die(sprintf(__("Can&#8217;t delete the <strong>%s</strong> category: this is the default one"), $cat_name));
48
49         wp_delete_category($cat_ID);
50
51         wp_safe_redirect( add_query_arg( 'message', 2, wp_get_referer() ) );
52         exit;
53
54 break;
55
56 case 'bulk-delete':
57         check_admin_referer('bulk-categories');
58
59         if ( !current_user_can('manage_categories') )
60                 wp_die( __('You are not allowed to delete categories.') );
61
62         foreach ( (array) $_GET['delete'] as $cat_ID ) {
63                 $cat_name = get_cat_name($cat_ID);
64
65                 // Don't delete the default cats.
66                 if ( $cat_ID == get_option('default_category') )
67                         wp_die(sprintf(__("Can&#8217;t delete the <strong>%s</strong> category: this is the default one"), $cat_name));
68
69                 wp_delete_category($cat_ID);
70         }
71
72         wp_safe_redirect( wp_get_referer() );
73         exit();
74
75 break;
76 case 'edit':
77
78         $title = __('Edit Category');
79
80         require_once ('admin-header.php');
81         $cat_ID = (int) $_GET['cat_ID'];
82         $category = get_category_to_edit($cat_ID);
83         include('edit-category-form.php');
84
85 break;
86
87 case 'editedcat':
88         $cat_ID = (int) $_POST['cat_ID'];
89         check_admin_referer('update-category_' . $cat_ID);
90
91         if ( !current_user_can('manage_categories') )
92                 wp_die(__('Cheatin&#8217; uh?'));
93
94         $location = 'categories.php';
95         if ( $referer = wp_get_original_referer() ) {
96                 if ( false !== strpos($referer, 'categories.php') )
97                         $location = $referer;
98         }
99
100         if ( wp_update_category($_POST) )
101                 $location = add_query_arg('message', 3, $location);
102         else
103                 $location = add_query_arg('message', 5, $location);
104
105         wp_redirect($location);
106
107         exit;
108 break;
109
110 default:
111
112 if ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) {
113          wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
114          exit;
115 }
116
117 wp_enqueue_script('admin-categories');
118 if ( current_user_can('manage_categories') )
119         wp_enqueue_script('inline-edit-tax');
120
121 require_once ('admin-header.php');
122
123 $messages[1] = __('Category added.');
124 $messages[2] = __('Category deleted.');
125 $messages[3] = __('Category updated.');
126 $messages[4] = __('Category not added.');
127 $messages[5] = __('Category not updated.');
128 ?>
129
130 <div class="wrap nosubsub">
131 <?php screen_icon(); ?>
132 <h2><?php echo esc_html( $title );
133 if ( isset($_GET['s']) && $_GET['s'] )
134         printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( stripslashes($_GET['s']) ) ); ?>
135 </h2>
136
137 <?php
138 if ( isset($_GET['message']) && ( $msg = (int) $_GET['message'] ) ) : ?>
139 <div id="message" class="updated fade"><p><?php echo $messages[$msg]; ?></p></div>
140 <?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
141 endif; ?>
142
143 <form class="search-form topmargin" action="" method="get">
144 <p class="search-box">
145         <label class="screen-reader-text" for="category-search-input"><?php _e('Search Categories'); ?>:</label>
146         <input type="text" id="category-search-input" name="s" value="<?php _admin_search_query(); ?>" />
147         <input type="submit" value="<?php esc_attr_e( 'Search Categories' ); ?>" class="button" />
148 </p>
149 </form>
150 <br class="clear" />
151
152 <div id="col-container">
153
154 <div id="col-right">
155 <div class="col-wrap">
156 <form id="posts-filter" action="" method="get">
157 <div class="tablenav">
158
159 <?php
160 $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 0;
161 if ( empty($pagenum) )
162         $pagenum = 1;
163
164 $cats_per_page = get_user_option('categories_per_page');
165 if ( empty($cats_per_page) )
166         $cats_per_page = 20;
167 $cats_per_page = apply_filters('edit_categories_per_page', $cats_per_page);
168
169 if ( !empty($_GET['s']) )
170         $num_cats = count(get_categories(array('hide_empty' => 0, 'search' => $_GET['s'])));
171 else
172         $num_cats = wp_count_terms('category');
173
174 $page_links = paginate_links( array(
175         'base' => add_query_arg( 'pagenum', '%#%' ),
176         'format' => '',
177         'prev_text' => __('&laquo;'),
178         'next_text' => __('&raquo;'),
179         'total' => ceil($num_cats / $cats_per_page),
180         'current' => $pagenum
181 ));
182
183 if ( $page_links )
184         echo "<div class='tablenav-pages'>$page_links</div>";
185 ?>
186
187 <div class="alignleft actions">
188 <select name="action">
189 <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
190 <option value="delete"><?php _e('Delete'); ?></option>
191 </select>
192 <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
193 <?php wp_nonce_field('bulk-categories'); ?>
194 </div>
195
196 <br class="clear" />
197 </div>
198
199 <div class="clear"></div>
200
201 <table class="widefat fixed" cellspacing="0">
202         <thead>
203         <tr>
204 <?php print_column_headers('categories'); ?>
205         </tr>
206         </thead>
207
208         <tfoot>
209         <tr>
210 <?php print_column_headers('categories', false); ?>
211         </tr>
212         </tfoot>
213
214         <tbody id="the-list" class="list:cat">
215 <?php
216 cat_rows(0, 0, 0, $pagenum, $cats_per_page);
217 ?>
218         </tbody>
219 </table>
220
221 <div class="tablenav">
222 <?php
223 if ( $page_links )
224         echo "<div class='tablenav-pages'>$page_links</div>";
225 ?>
226
227 <div class="alignleft actions">
228 <select name="action2">
229 <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
230 <option value="delete"><?php _e('Delete'); ?></option>
231 </select>
232 <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
233 <?php wp_nonce_field('bulk-categories'); ?>
234 </div>
235
236 <br class="clear" />
237 </div>
238
239 </form>
240
241 <div class="form-wrap">
242 <p><?php printf(__('<strong>Note:</strong><br />Deleting a category does not delete the posts in that category. Instead, posts that were only assigned to the deleted category are set to the category <strong>%s</strong>.'), apply_filters('the_category', get_cat_name(get_option('default_category')))) ?></p>
243 <p><?php printf(__('Categories can be selectively converted to tags using the <a href="%s">category to tag converter</a>.'), 'admin.php?import=wp-cat2tag') ?></p>
244 </div>
245
246 </div>
247 </div><!-- /col-right -->
248
249 <div id="col-left">
250 <div class="col-wrap">
251
252 <?php if ( current_user_can('manage_categories') ) { ?>
253 <?php $category = (object) array(); $category->parent = 0; do_action('add_category_form_pre', $category); ?>
254
255 <div class="form-wrap">
256 <h3><?php _e('Add Category'); ?></h3>
257 <div id="ajax-response"></div>
258 <form name="addcat" id="addcat" method="post" action="categories.php" class="add:the-list: validate">
259 <input type="hidden" name="action" value="addcat" />
260 <?php wp_original_referer_field(true, 'previous'); wp_nonce_field('add-category'); ?>
261
262 <div class="form-field form-required">
263         <label for="cat_name"><?php _e('Category Name') ?></label>
264         <input name="cat_name" id="cat_name" type="text" value="" size="40" aria-required="true" />
265     <p><?php _e('The name is used to identify the category almost everywhere, for example under the post or in the category widget.'); ?></p>
266 </div>
267
268 <div class="form-field">
269         <label for="category_nicename"><?php _e('Category Slug') ?></label>
270         <input name="category_nicename" id="category_nicename" type="text" value="" size="40" />
271     <p><?php _e('The &#8220;slug&#8221; is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.'); ?></p>
272 </div>
273
274 <div class="form-field">
275         <label for="category_parent"><?php _e('Category Parent') ?></label>
276         <?php wp_dropdown_categories(array('hide_empty' => 0, 'name' => 'category_parent', 'orderby' => 'name', 'selected' => $category->parent, 'hierarchical' => true, 'show_option_none' => __('None'))); ?>
277     <p><?php _e('Categories, unlike tags, can have a hierarchy. You might have a Jazz category, and under that have children categories for Bebop and Big Band. Totally optional.'); ?></p>
278 </div>
279
280 <div class="form-field">
281         <label for="category_description"><?php _e('Description') ?></label>
282         <textarea name="category_description" id="category_description" rows="5" cols="40"></textarea>
283     <p><?php _e('The description is not prominent by default, however some themes may show it.'); ?></p>
284 </div>
285
286 <p class="submit"><input type="submit" class="button" name="submit" value="<?php esc_attr_e('Add Category'); ?>" /></p>
287 <?php do_action('edit_category_form', $category); ?>
288 </form></div>
289
290 <?php } ?>
291
292 </div>
293 </div><!-- /col-left -->
294
295 </div><!-- /col-container -->
296 </div><!-- /wrap -->
297
298 <?php
299 inline_edit_term_row('categories');
300
301 break;
302 }
303
304 include('admin-footer.php');
305
306 ?>