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