]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/edit.php
Wordpress 2.9.2-scripts
[autoinstalls/wordpress.git] / wp-admin / edit.php
1 <?php
2 /**
3  * Edit Posts Administration Panel.
4  *
5  * @package WordPress
6  * @subpackage Administration
7  */
8
9 /** WordPress Administration Bootstrap */
10 require_once('admin.php');
11
12 if ( !current_user_can('edit_posts') )
13         wp_die(__('Cheatin&#8217; uh?'));
14
15 // Back-compat for viewing comments of an entry
16 if ( $_redirect = intval( max( @$_GET['p'], @$_GET['attachment_id'], @$_GET['page_id'] ) ) ) {
17         wp_redirect( admin_url('edit-comments.php?p=' . $_redirect ) );
18         exit;
19 } else {
20         unset( $_redirect );
21 }
22
23 // Handle bulk actions
24 if ( isset($_GET['doaction']) || isset($_GET['doaction2']) || isset($_GET['delete_all']) || isset($_GET['delete_all2']) || isset($_GET['bulk_edit']) ) {
25         check_admin_referer('bulk-posts');
26         $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), wp_get_referer() );
27
28         if ( strpos($sendback, 'post.php') !== false )
29                 $sendback = admin_url('post-new.php');
30
31         if ( isset($_GET['delete_all']) || isset($_GET['delete_all2']) ) {
32                 $post_status = preg_replace('/[^a-z0-9_-]+/i', '', $_GET['post_status']);
33                 $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='post' AND post_status = %s", $post_status ) );
34                 $doaction = 'delete';
35         } elseif ( ( $_GET['action'] != -1 || $_GET['action2'] != -1 ) && ( isset($_GET['post']) || isset($_GET['ids']) ) ) {
36                 $post_ids = isset($_GET['post']) ? array_map( 'intval', (array) $_GET['post'] ) : explode(',', $_GET['ids']);
37                 $doaction = ($_GET['action'] != -1) ? $_GET['action'] : $_GET['action2'];
38         } else {
39                 wp_redirect( admin_url('edit.php') );
40         }
41
42         switch ( $doaction ) {
43                 case 'trash':
44                         $trashed = 0;
45                         foreach( (array) $post_ids as $post_id ) {
46                                 if ( !current_user_can('delete_post', $post_id) )
47                                         wp_die( __('You are not allowed to move this post to the trash.') );
48
49                                 if ( !wp_trash_post($post_id) )
50                                         wp_die( __('Error in moving to trash...') );
51
52                                 $trashed++;
53                         }
54                         $sendback = add_query_arg( array('trashed' => $trashed, 'ids' => join(',', $post_ids)), $sendback );
55                         break;
56                 case 'untrash':
57                         $untrashed = 0;
58                         foreach( (array) $post_ids as $post_id ) {
59                                 if ( !current_user_can('delete_post', $post_id) )
60                                         wp_die( __('You are not allowed to restore this post from the trash.') );
61
62                                 if ( !wp_untrash_post($post_id) )
63                                         wp_die( __('Error in restoring from trash...') );
64
65                                 $untrashed++;
66                         }
67                         $sendback = add_query_arg('untrashed', $untrashed, $sendback);
68                         break;
69                 case 'delete':
70                         $deleted = 0;
71                         foreach( (array) $post_ids as $post_id ) {
72                                 $post_del = & get_post($post_id);
73
74                                 if ( !current_user_can('delete_post', $post_id) )
75                                         wp_die( __('You are not allowed to delete this post.') );
76
77                                 if ( $post_del->post_type == 'attachment' ) {
78                                         if ( ! wp_delete_attachment($post_id) )
79                                                 wp_die( __('Error in deleting...') );
80                                 } else {
81                                         if ( !wp_delete_post($post_id) )
82                                                 wp_die( __('Error in deleting...') );
83                                 }
84                                 $deleted++;
85                         }
86                         $sendback = add_query_arg('deleted', $deleted, $sendback);
87                         break;
88                 case 'edit':
89                         $done = bulk_edit_posts($_GET);
90
91                         if ( is_array($done) ) {
92                                 $done['updated'] = count( $done['updated'] );
93                                 $done['skipped'] = count( $done['skipped'] );
94                                 $done['locked'] = count( $done['locked'] );
95                                 $sendback = add_query_arg( $done, $sendback );
96                         }
97                         break;
98         }
99
100         if ( isset($_GET['action']) )
101                 $sendback = remove_query_arg( array('action', 'action2', 'cat', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status',  'post', 'bulk_edit', 'post_view', 'post_type'), $sendback );
102
103         wp_redirect($sendback);
104         exit();
105 } elseif ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) {
106          wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
107          exit;
108 }
109
110 if ( empty($title) )
111         $title = __('Edit Posts');
112 $parent_file = 'edit.php';
113 wp_enqueue_script('inline-edit-post');
114
115 $user_posts = false;
116 if ( !current_user_can('edit_others_posts') ) {
117         $user_posts_count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(1) FROM $wpdb->posts WHERE post_type = 'post' AND post_status != 'trash' AND post_author = %d", $current_user->ID) );
118         $user_posts = true;
119         if ( $user_posts_count && empty($_GET['post_status']) && empty($_GET['all_posts']) && empty($_GET['author']) )
120                 $_GET['author'] = $current_user->ID;
121 }
122
123 list($post_stati, $avail_post_stati) = wp_edit_posts_query();
124
125 require_once('admin-header.php');
126
127 if ( !isset( $_GET['paged'] ) )
128         $_GET['paged'] = 1;
129
130 if ( empty($_GET['mode']) )
131         $mode = 'list';
132 else
133         $mode = esc_attr($_GET['mode']); ?>
134
135 <div class="wrap">
136 <?php screen_icon(); ?>
137 <h2><?php echo esc_html( $title ); ?> <a href="post-new.php" class="button add-new-h2"><?php echo esc_html_x('Add New', 'post'); ?></a> <?php
138 if ( isset($_GET['s']) && $_GET['s'] )
139         printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( get_search_query() ) ); ?>
140 </h2>
141
142 <?php
143 if ( isset($_GET['posted']) && $_GET['posted'] ) : $_GET['posted'] = (int) $_GET['posted']; ?>
144 <div id="message" class="updated fade"><p><strong><?php _e('Your post has been saved.'); ?></strong> <a href="<?php echo get_permalink( $_GET['posted'] ); ?>"><?php _e('View post'); ?></a> | <a href="<?php echo get_edit_post_link( $_GET['posted'] ); ?>"><?php _e('Edit post'); ?></a></p></div>
145 <?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('posted'), $_SERVER['REQUEST_URI']);
146 endif; ?>
147
148 <?php if ( isset($_GET['locked']) || isset($_GET['skipped']) || isset($_GET['updated']) || isset($_GET['deleted']) || isset($_GET['trashed']) || isset($_GET['untrashed']) ) { ?>
149 <div id="message" class="updated fade"><p>
150 <?php if ( isset($_GET['updated']) && (int) $_GET['updated'] ) {
151         printf( _n( '%s post updated.', '%s posts updated.', $_GET['updated'] ), number_format_i18n( $_GET['updated'] ) );
152         unset($_GET['updated']);
153 }
154
155 if ( isset($_GET['skipped']) && (int) $_GET['skipped'] )
156         unset($_GET['skipped']);
157
158 if ( isset($_GET['locked']) && (int) $_GET['locked'] ) {
159         printf( _n( '%s post not updated, somebody is editing it.', '%s posts not updated, somebody is editing them.', $_GET['locked'] ), number_format_i18n( $_GET['locked'] ) );
160         unset($_GET['locked']);
161 }
162
163 if ( isset($_GET['deleted']) && (int) $_GET['deleted'] ) {
164         printf( _n( 'Post permanently deleted.', '%s posts permanently deleted.', $_GET['deleted'] ), number_format_i18n( $_GET['deleted'] ) );
165         unset($_GET['deleted']);
166 }
167
168 if ( isset($_GET['trashed']) && (int) $_GET['trashed'] ) {
169         printf( _n( 'Post moved to the trash.', '%s posts moved to the trash.', $_GET['trashed'] ), number_format_i18n( $_GET['trashed'] ) );
170         $ids = isset($_GET['ids']) ? $_GET['ids'] : 0;
171         echo ' <a href="' . esc_url( wp_nonce_url( "edit.php?doaction=undo&action=untrash&ids=$ids", "bulk-posts" ) ) . '">' . __('Undo') . '</a><br />';
172         unset($_GET['trashed']);
173 }
174
175 if ( isset($_GET['untrashed']) && (int) $_GET['untrashed'] ) {
176         printf( _n( 'Post restored from the trash.', '%s posts restored from the trash.', $_GET['untrashed'] ), number_format_i18n( $_GET['untrashed'] ) );
177         unset($_GET['undeleted']);
178 }
179
180 $_SERVER['REQUEST_URI'] = remove_query_arg( array('locked', 'skipped', 'updated', 'deleted', 'trashed', 'untrashed'), $_SERVER['REQUEST_URI'] );
181 ?>
182 </p></div>
183 <?php } ?>
184
185 <form id="posts-filter" action="<?php echo admin_url('edit.php'); ?>" method="get">
186
187 <ul class="subsubsub">
188 <?php
189 if ( empty($locked_post_status) ) :
190 $status_links = array();
191 $num_posts = wp_count_posts( 'post', 'readable' );
192 $class = '';
193 $allposts = '';
194
195 if ( $user_posts ) {
196         if ( isset( $_GET['author'] ) && ( $_GET['author'] == $current_user->ID ) )
197                 $class = ' class="current"';
198         $status_links[] = "<li><a href='edit.php?author=$current_user->ID'$class>" . sprintf( _nx( 'My Posts <span class="count">(%s)</span>', 'My Posts <span class="count">(%s)</span>', $user_posts_count, 'posts' ), number_format_i18n( $user_posts_count ) ) . '</a>';
199         $allposts = '?all_posts=1';
200 }
201
202 $total_posts = array_sum( (array) $num_posts ) - $num_posts->trash;
203 $class = empty($class) && empty($_GET['post_status']) ? ' class="current"' : '';
204 $status_links[] = "<li><a href='edit.php{$allposts}'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_posts, 'posts' ), number_format_i18n( $total_posts ) ) . '</a>';
205
206 foreach ( $post_stati as $status => $label ) {
207         $class = '';
208
209         if ( !in_array( $status, $avail_post_stati ) )
210                 continue;
211
212         if ( empty( $num_posts->$status ) )
213                 continue;
214
215         if ( isset($_GET['post_status']) && $status == $_GET['post_status'] )
216                 $class = ' class="current"';
217
218         $status_links[] = "<li><a href='edit.php?post_status=$status'$class>" . sprintf( _n( $label[2][0], $label[2][1], $num_posts->$status ), number_format_i18n( $num_posts->$status ) ) . '</a>';
219 }
220 echo implode( " |</li>\n", $status_links ) . '</li>';
221 unset( $status_links );
222 endif;
223 ?>
224 </ul>
225
226 <p class="search-box">
227         <label class="screen-reader-text" for="post-search-input"><?php _e( 'Search Posts' ); ?>:</label>
228         <input type="text" id="post-search-input" name="s" value="<?php the_search_query(); ?>" />
229         <input type="submit" value="<?php esc_attr_e( 'Search Posts' ); ?>" class="button" />
230 </p>
231
232 <input type="hidden" name="post_status" class="post_status_page" value="<?php echo !empty($_GET['post_status']) ? esc_attr($_GET['post_status']) : 'all'; ?>" />
233 <input type="hidden" name="mode" value="<?php echo esc_attr($mode); ?>" />
234
235 <?php if ( have_posts() ) { ?>
236
237 <div class="tablenav">
238 <?php
239 $page_links = paginate_links( array(
240         'base' => add_query_arg( 'paged', '%#%' ),
241         'format' => '',
242         'prev_text' => __('&laquo;'),
243         'next_text' => __('&raquo;'),
244         'total' => $wp_query->max_num_pages,
245         'current' => $_GET['paged']
246 ));
247
248 $is_trash = isset($_GET['post_status']) && $_GET['post_status'] == 'trash';
249
250 ?>
251
252 <div class="alignleft actions">
253 <select name="action">
254 <option value="-1" selected="selected"><?php _e('Bulk Actions'); ?></option>
255 <?php if ( $is_trash ) { ?>
256 <option value="untrash"><?php _e('Restore'); ?></option>
257 <?php } else { ?>
258 <option value="edit"><?php _e('Edit'); ?></option>
259 <?php } if ( $is_trash || !EMPTY_TRASH_DAYS ) { ?>
260 <option value="delete"><?php _e('Delete Permanently'); ?></option>
261 <?php } else { ?>
262 <option value="trash"><?php _e('Move to Trash'); ?></option>
263 <?php } ?>
264 </select>
265 <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
266 <?php wp_nonce_field('bulk-posts'); ?>
267
268 <?php // view filters
269 if ( !is_singular() ) {
270 $arc_query = "SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_type = 'post' ORDER BY post_date DESC";
271
272 $arc_result = $wpdb->get_results( $arc_query );
273
274 $month_count = count($arc_result);
275
276 if ( $month_count && !( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) {
277 $m = isset($_GET['m']) ? (int)$_GET['m'] : 0;
278 ?>
279 <select name='m'>
280 <option<?php selected( $m, 0 ); ?> value='0'><?php _e('Show all dates'); ?></option>
281 <?php
282 foreach ($arc_result as $arc_row) {
283         if ( $arc_row->yyear == 0 )
284                 continue;
285         $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 );
286
287         if ( $arc_row->yyear . $arc_row->mmonth == $m )
288                 $default = ' selected="selected"';
289         else
290                 $default = '';
291
292         echo "<option$default value='" . esc_attr("$arc_row->yyear$arc_row->mmonth") . "'>";
293         echo $wp_locale->get_month($arc_row->mmonth) . " $arc_row->yyear";
294         echo "</option>\n";
295 }
296 ?>
297 </select>
298 <?php } ?>
299
300 <?php
301 $dropdown_options = array('show_option_all' => __('View all categories'), 'hide_empty' => 0, 'hierarchical' => 1,
302         'show_count' => 0, 'orderby' => 'name', 'selected' => $cat);
303 wp_dropdown_categories($dropdown_options);
304 do_action('restrict_manage_posts');
305 ?>
306 <input type="submit" id="post-query-submit" value="<?php esc_attr_e('Filter'); ?>" class="button-secondary" />
307 <?php }
308
309 if ( $is_trash && current_user_can('edit_others_posts') ) { ?>
310 <input type="submit" name="delete_all" id="delete_all" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" />
311 <?php } ?>
312 </div>
313
314 <?php if ( $page_links ) { ?>
315 <div class="tablenav-pages"><?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s' ) . '</span>%s',
316         number_format_i18n( ( $_GET['paged'] - 1 ) * $wp_query->query_vars['posts_per_page'] + 1 ),
317         number_format_i18n( min( $_GET['paged'] * $wp_query->query_vars['posts_per_page'], $wp_query->found_posts ) ),
318         number_format_i18n( $wp_query->found_posts ),
319         $page_links
320 ); echo $page_links_text; ?></div>
321 <?php } ?>
322
323 <div class="view-switch">
324         <a href="<?php echo esc_url(add_query_arg('mode', 'list', $_SERVER['REQUEST_URI'])) ?>"><img <?php if ( 'list' == $mode ) echo 'class="current"'; ?> id="view-switch-list" src="../wp-includes/images/blank.gif" width="20" height="20" title="<?php _e('List View') ?>" alt="<?php _e('List View') ?>" /></a>
325         <a href="<?php echo esc_url(add_query_arg('mode', 'excerpt', $_SERVER['REQUEST_URI'])) ?>"><img <?php if ( 'excerpt' == $mode ) echo 'class="current"'; ?> id="view-switch-excerpt" src="../wp-includes/images/blank.gif" width="20" height="20" title="<?php _e('Excerpt View') ?>" alt="<?php _e('Excerpt View') ?>" /></a>
326 </div>
327
328 <div class="clear"></div>
329 </div>
330
331 <div class="clear"></div>
332
333 <?php include( 'edit-post-rows.php' ); ?>
334
335 <div class="tablenav">
336
337 <?php
338 if ( $page_links )
339         echo "<div class='tablenav-pages'>$page_links_text</div>";
340 ?>
341
342 <div class="alignleft actions">
343 <select name="action2">
344 <option value="-1" selected="selected"><?php _e('Bulk Actions'); ?></option>
345 <?php if ( $is_trash ) { ?>
346 <option value="untrash"><?php _e('Restore'); ?></option>
347 <?php } else { ?>
348 <option value="edit"><?php _e('Edit'); ?></option>
349 <?php } if ( $is_trash || !EMPTY_TRASH_DAYS ) { ?>
350 <option value="delete"><?php _e('Delete Permanently'); ?></option>
351 <?php } else { ?>
352 <option value="trash"><?php _e('Move to Trash'); ?></option>
353 <?php } ?>
354 </select>
355 <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
356 <?php if ( $is_trash && current_user_can('edit_others_posts') ) { ?>
357 <input type="submit" name="delete_all2" id="delete_all2" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" />
358 <?php } ?>
359 <br class="clear" />
360 </div>
361 <br class="clear" />
362 </div>
363
364 <?php } else { // have_posts() ?>
365 <div class="clear"></div>
366 <p><?php
367 if ( isset($_GET['post_status']) && 'trash' == $_GET['post_status'] )
368         _e('No posts found in the trash');
369 else
370         _e('No posts found');
371 ?></p>
372 <?php } ?>
373
374 </form>
375
376 <?php inline_edit_row( 'post' ); ?>
377
378 <div id="ajax-response"></div>
379 <br class="clear" />
380 </div>
381
382 <?php
383 include('admin-footer.php');