Wordpress 2.5.1
[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         <input type="text" id="post-search-input" name="s" value="<?php echo attribute_escape(stripslashes($_GET['s'])); ?>" />
137         <input type="submit" value="<?php _e( 'Search Tags' ); ?>" class="button" />
138 </p>
139
140 <br class="clear" />
141
142 <div class="tablenav">
143
144 <?php
145 $pagenum = absint( $_GET['pagenum'] );
146 if ( empty($pagenum) )
147         $pagenum = 1;
148 if( !$tagsperpage || $tagsperpage < 0 )
149         $tagsperpage = 20;
150
151 $page_links = paginate_links( array(
152         'base' => add_query_arg( 'pagenum', '%#%' ),
153         'format' => '',
154         'total' => ceil(wp_count_terms('post_tag') / $tagsperpage),
155         'current' => $pagenum
156 ));
157
158 if ( $page_links )
159         echo "<div class='tablenav-pages'>$page_links</div>";
160 ?>
161
162 <div class="alignleft">
163 <input type="submit" value="<?php _e('Delete'); ?>" name="deleteit" class="button-secondary delete" />
164 <?php wp_nonce_field('bulk-tags'); ?>
165 </div>
166
167 <br class="clear" />
168 </div>
169
170 <br class="clear" />
171
172 <table class="widefat">
173         <thead>
174         <tr>
175         <th scope="col" class="check-column"><input type="checkbox" onclick="checkAll(document.getElementById('posts-filter'));" /></th>
176         <th scope="col"><?php _e('Name') ?></th>
177         <th scope="col" class="num" style="width: 90px"><?php _e('Posts') ?></th>
178         </tr>
179         </thead>
180         <tbody id="the-list" class="list:tag">
181 <?php
182
183 $searchterms = trim( $_GET['s'] );
184
185 $count = tag_rows( $pagenum, $tagsperpage, $searchterms );
186 ?>
187         </tbody>
188 </table>
189 </form>
190
191 <div class="tablenav">
192
193 <?php
194 if ( $page_links )
195         echo "<div class='tablenav-pages'>$page_links</div>";
196 ?>
197 <br class="clear" />
198 </div>
199 <br class="clear" />
200
201 </div>
202
203 <?php if ( current_user_can('manage_categories') ) : ?>
204
205 <br />
206 <?php include('edit-tag-form.php'); ?>
207
208 <?php endif; ?>
209
210 <?php
211 break;
212 }
213
214 include('admin-footer.php');
215
216 ?>