]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/categories.php
d2e8fb3720f45eef84691d3928a941c124463556
[autoinstalls/wordpress.git] / wp-admin / categories.php
1 <?php
2 require_once('admin.php');
3
4 $title = __('Categories');
5 $parent_file = 'edit.php';
6
7 wp_reset_vars(array('action', 'cat'));
8
9 if ( isset($_GET['deleteit']) && isset($_GET['delete']) )
10         $action = 'bulk-delete';
11
12 switch($action) {
13
14 case 'addcat':
15
16         check_admin_referer('add-category');
17
18         if ( !current_user_can('manage_categories') )
19                 wp_die(__('Cheatin&#8217; uh?'));
20
21         if( wp_insert_category($_POST ) ) {
22                 wp_redirect('categories.php?message=1#addcat');
23         } else {
24                 wp_redirect('categories.php?message=4#addcat');
25         }
26         exit;
27 break;
28
29 case 'delete':
30         $cat_ID = (int) $_GET['cat_ID'];
31         check_admin_referer('delete-category_' .  $cat_ID);
32
33         if ( !current_user_can('manage_categories') )
34                 wp_die(__('Cheatin&#8217; uh?'));
35
36         $cat_name = get_catname($cat_ID);
37
38         // Don't delete the default cats.
39     if ( $cat_ID == get_option('default_category') )
40                 wp_die(sprintf(__("Can&#8217;t delete the <strong>%s</strong> category: this is the default one"), $cat_name));
41
42         wp_delete_category($cat_ID);
43
44         wp_redirect('categories.php?message=2');
45         exit;
46
47 break;
48
49 case 'bulk-delete':
50         check_admin_referer('bulk-categories');
51
52         if ( !current_user_can('manage_categories') )
53                 wp_die( __('You are not allowed to delete categories.') );
54
55         foreach ( (array) $_GET['delete'] as $cat_ID ) {
56                 $cat_name = get_catname($cat_ID);
57
58                 // Don't delete the default cats.
59                 if ( $cat_ID == get_option('default_category') )
60                         wp_die(sprintf(__("Can&#8217;t delete the <strong>%s</strong> category: this is the default one"), $cat_name));
61
62                 wp_delete_category($cat_ID);
63         }
64
65         $sendback = wp_get_referer();
66         $sendback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $sendback);
67
68         wp_redirect($sendback);
69         exit();
70
71 break;
72 case 'edit':
73
74         require_once ('admin-header.php');
75         $cat_ID = (int) $_GET['cat_ID'];
76         $category = get_category_to_edit($cat_ID);
77         include('edit-category-form.php');
78
79 break;
80
81 case 'editedcat':
82         $cat_ID = (int) $_POST['cat_ID'];
83         check_admin_referer('update-category_' . $cat_ID);
84
85         if ( !current_user_can('manage_categories') )
86                 wp_die(__('Cheatin&#8217; uh?'));
87
88         if ( wp_update_category($_POST) )
89                 wp_redirect('categories.php?message=3');
90         else
91                 wp_redirect('categories.php?message=5');
92
93         exit;
94 break;
95
96 default:
97
98 if ( !empty($_GET['_wp_http_referer']) ) {
99          wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI'])));
100          exit;
101 }
102
103 wp_enqueue_script( 'admin-categories' );
104 wp_enqueue_script('admin-forms');
105
106 require_once ('admin-header.php');
107
108 $messages[1] = __('Category added.');
109 $messages[2] = __('Category deleted.');
110 $messages[3] = __('Category updated.');
111 $messages[4] = __('Category not added.');
112 $messages[5] = __('Category not updated.');
113 ?>
114
115 <?php if (isset($_GET['message'])) : ?>
116 <div id="message" class="updated fade"><p><?php echo $messages[$_GET['message']]; ?></p></div>
117 <?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
118 endif; ?>
119
120 <div class="wrap">
121 <form id="posts-filter" action="" method="get">
122 <?php if ( current_user_can('manage_categories') ) : ?>
123         <h2><?php printf(__('Manage Categories (<a href="%s">add new</a>)'), '#addcat') ?> </h2>
124 <?php else : ?>
125         <h2><?php _e('Manage Categories') ?> </h2>
126 <?php endif; ?>
127
128 <p id="post-search">
129         <label class="hidden" for="post-search-input"><?php _e('Search Categories'); ?>:</label>
130         <input type="text" id="post-search-input" name="s" value="<?php echo attribute_escape(stripslashes($_GET['s'])); ?>" />
131         <input type="submit" value="<?php _e( 'Search Categories' ); ?>" class="button" />
132 </p>
133
134 <br class="clear" />
135
136 <div class="tablenav">
137
138 <?php
139 $pagenum = absint( $_GET['pagenum'] );
140 if ( empty($pagenum) )
141         $pagenum = 1;
142 if( !$catsperpage || $catsperpage < 0 )
143         $catsperpage = 20;
144
145 $page_links = paginate_links( array(
146         'base' => add_query_arg( 'pagenum', '%#%' ),
147         'format' => '',
148         'total' => ceil(wp_count_terms('category') / $catsperpage),
149         'current' => $pagenum
150 ));
151
152 if ( $page_links )
153         echo "<div class='tablenav-pages'>$page_links</div>";
154 ?>
155
156 <div class="alignleft">
157 <input type="submit" value="<?php _e('Delete'); ?>" name="deleteit" class="button-secondary delete" />
158 <?php wp_nonce_field('bulk-categories'); ?>
159 </div>
160
161 <br class="clear" />
162 </div>
163
164 <br class="clear" />
165
166 <table class="widefat">
167         <thead>
168         <tr>
169                 <th scope="col" class="check-column"><input type="checkbox" /></th>
170         <th scope="col"><?php _e('Name') ?></th>
171         <th scope="col"><?php _e('Description') ?></th>
172         <th scope="col" class="num"><?php _e('Posts') ?></th>
173         </tr>
174         </thead>
175         <tbody id="the-list" class="list:cat">
176 <?php
177 cat_rows(0, 0, 0, $pagenum, $catsperpage);
178 ?>
179         </tbody>
180 </table>
181 </form>
182
183 <div class="tablenav">
184
185 <?php
186 if ( $page_links )
187         echo "<div class='tablenav-pages'>$page_links</div>";
188 ?>
189 <br class="clear" />
190 </div>
191 <br class="clear" />
192
193 </div>
194
195 <?php if ( current_user_can('manage_categories') ) : ?>
196 <div class="wrap">
197 <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_catname(get_option('default_category')))) ?></p>
198 <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>
199 </div>
200
201 <?php include('edit-category-form.php'); ?>
202
203 <?php endif; ?>
204
205 <?php
206 break;
207 }
208
209 include('admin-footer.php');
210
211 ?>