]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/upload.php
WordPress 4.1
[autoinstalls/wordpress.git] / wp-admin / upload.php
1 <?php
2 /**
3  * Media Library administration panel.
4  *
5  * @package WordPress
6  * @subpackage Administration
7  */
8
9 /** WordPress Administration Bootstrap */
10 require_once( dirname( __FILE__ ) . '/admin.php' );
11
12 if ( !current_user_can('upload_files') )
13         wp_die( __( 'You do not have permission to upload files.' ) );
14
15 $mode = get_user_option( 'media_library_mode', get_current_user_id() ) ? get_user_option( 'media_library_mode', get_current_user_id() ) : 'grid';
16 $modes = array( 'grid', 'list' );
17
18 if ( isset( $_GET['mode'] ) && in_array( $_GET['mode'], $modes ) ) {
19         $mode = $_GET['mode'];
20         update_user_option( get_current_user_id(), 'media_library_mode', $mode );
21 }
22
23 if ( 'grid' === $mode ) {
24         wp_enqueue_media();
25         wp_enqueue_script( 'media-grid' );
26         wp_enqueue_script( 'media' );
27         wp_localize_script( 'media-grid', '_wpMediaGridSettings', array(
28                 'adminUrl' => parse_url( self_admin_url(), PHP_URL_PATH ),
29         ) );
30
31         get_current_screen()->add_help_tab( array(
32                 'id'            => 'overview',
33                 'title'         => __( 'Overview' ),
34                 'content'       =>
35                         '<p>' . __( 'All the files you&#8217;ve uploaded are listed in the Media Library, with the most recent uploads listed first.' ) . '</p>' .
36                         '<p>' . __( 'You can view your media in a simple visual grid or a list with columns. Switch between these views using the icons to the left above the media.' ) . '</p>' .
37                         '<p>' . __( 'To delete media items, click the Bulk Select button at the top of the screen. Select any items you wish to delete, then click the Delete Selected button. Clicking the Cancel Selection button takes you back to viewing your media.' ) . '</p>'
38         ) );
39
40         get_current_screen()->add_help_tab( array(
41                 'id'            => 'attachment-details',
42                 'title'         => __( 'Attachment Details' ),
43                 'content'       =>
44                         '<p>' . __( 'Clicking an item will display an Attachment Details dialog, which allows you to preview media and make quick edits. Any changes you make to the attachment details will be automatically saved.' ) . '</p>' .
45                         '<p>' . __( 'Use the arrow buttons at the top of the dialog, or the left and right arrow keys on your keyboard, to navigate between media items quickly.' ) . '</p>' .
46                         '<p>' . __( 'You can also delete individual items and access the extended edit screen from the details dialog.' ) . '</p>'
47         ) );
48
49         get_current_screen()->set_help_sidebar(
50                 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
51                 '<p>' . __( '<a href="http://codex.wordpress.org/Media_Library_Screen" target="_blank">Documentation on Media Library</a>' ) . '</p>' .
52                 '<p>' . __( '<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
53         );
54
55         $title = __('Media Library');
56         $parent_file = 'upload.php';
57
58         require_once( ABSPATH . 'wp-admin/admin-header.php' );
59         ?>
60         <div class="wrap" id="wp-media-grid">
61                 <h2>
62                 <?php
63                 echo esc_html( $title );
64                 if ( current_user_can( 'upload_files' ) ) { ?>
65                         <a href="media-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add New', 'file' ); ?></a><?php
66                 }
67                 ?>
68                 </h2>
69                 <div class="error hide-if-js">
70                         <p><?php _e( 'The grid view for the Media Library requires JavaScript. <a href="upload.php?mode=list">Switch to the list view</a>.' ); ?></p>
71                 </div>
72         </div>
73         <?php
74         include( ABSPATH . 'wp-admin/admin-footer.php' );
75         exit;
76 }
77
78 $wp_list_table = _get_list_table('WP_Media_List_Table');
79 $pagenum = $wp_list_table->get_pagenum();
80
81 // Handle bulk actions
82 $doaction = $wp_list_table->current_action();
83
84 if ( $doaction ) {
85         check_admin_referer('bulk-media');
86
87         if ( 'delete_all' == $doaction ) {
88                 $post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type='attachment' AND post_status = 'trash'" );
89                 $doaction = 'delete';
90         } elseif ( isset( $_REQUEST['media'] ) ) {
91                 $post_ids = $_REQUEST['media'];
92         } elseif ( isset( $_REQUEST['ids'] ) ) {
93                 $post_ids = explode( ',', $_REQUEST['ids'] );
94         }
95
96         $location = 'upload.php';
97         if ( $referer = wp_get_referer() ) {
98                 if ( false !== strpos( $referer, 'upload.php' ) )
99                         $location = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'message', 'ids', 'posted' ), $referer );
100         }
101
102         switch ( $doaction ) {
103                 case 'attach':
104                         $parent_id = (int) $_REQUEST['found_post_id'];
105                         if ( !$parent_id )
106                                 return;
107
108                         $parent = get_post( $parent_id );
109                         if ( !current_user_can( 'edit_post', $parent_id ) )
110                                 wp_die( __( 'You are not allowed to edit this post.' ) );
111
112                         $attach = array();
113                         foreach ( (array) $_REQUEST['media'] as $att_id ) {
114                                 $att_id = (int) $att_id;
115
116                                 if ( !current_user_can( 'edit_post', $att_id ) )
117                                         continue;
118
119                                 $attach[] = $att_id;
120                         }
121
122                         if ( ! empty( $attach ) ) {
123                                 $attach_string = implode( ',', $attach );
124                                 $attached = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %d WHERE post_type = 'attachment' AND ID IN ( $attach_string )", $parent_id ) );
125                                 foreach ( $attach as $att_id ) {
126                                         clean_attachment_cache( $att_id );
127                                 }
128                         }
129
130                         if ( isset( $attached ) ) {
131                                 $location = 'upload.php';
132                                 if ( $referer = wp_get_referer() ) {
133                                         if ( false !== strpos( $referer, 'upload.php' ) )
134                                                 $location = $referer;
135                                 }
136
137                                 $location = add_query_arg( array( 'attached' => $attached ) , $location );
138                                 wp_redirect( $location );
139                                 exit;
140                         }
141                         break;
142                 case 'trash':
143                         if ( !isset( $post_ids ) )
144                                 break;
145                         foreach ( (array) $post_ids as $post_id ) {
146                                 if ( !current_user_can( 'delete_post', $post_id ) )
147                                         wp_die( __( 'You are not allowed to move this post to the trash.' ) );
148
149                                 if ( !wp_trash_post( $post_id ) )
150                                         wp_die( __( 'Error in moving to trash.' ) );
151                         }
152                         $location = add_query_arg( array( 'trashed' => count( $post_ids ), 'ids' => join( ',', $post_ids ) ), $location );
153                         break;
154                 case 'untrash':
155                         if ( !isset( $post_ids ) )
156                                 break;
157                         foreach ( (array) $post_ids as $post_id ) {
158                                 if ( !current_user_can( 'delete_post', $post_id ) )
159                                         wp_die( __( 'You are not allowed to move this post out of the trash.' ) );
160
161                                 if ( !wp_untrash_post( $post_id ) )
162                                         wp_die( __( 'Error in restoring from trash.' ) );
163                         }
164                         $location = add_query_arg( 'untrashed', count( $post_ids ), $location );
165                         break;
166                 case 'delete':
167                         if ( !isset( $post_ids ) )
168                                 break;
169                         foreach ( (array) $post_ids as $post_id_del ) {
170                                 if ( !current_user_can( 'delete_post', $post_id_del ) )
171                                         wp_die( __( 'You are not allowed to delete this post.' ) );
172
173                                 if ( !wp_delete_attachment( $post_id_del ) )
174                                         wp_die( __( 'Error in deleting.' ) );
175                         }
176                         $location = add_query_arg( 'deleted', count( $post_ids ), $location );
177                         break;
178         }
179
180         wp_redirect( $location );
181         exit;
182 } elseif ( ! empty( $_GET['_wp_http_referer'] ) ) {
183          wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
184          exit;
185 }
186
187 $wp_list_table->prepare_items();
188
189 $title = __('Media Library');
190 $parent_file = 'upload.php';
191
192 wp_enqueue_script( 'media' );
193
194 add_screen_option( 'per_page', array('label' => _x( 'Media items', 'items per page (screen options)' )) );
195
196 get_current_screen()->add_help_tab( array(
197 'id'            => 'overview',
198 'title'         => __('Overview'),
199 'content'       =>
200         '<p>' . __( 'All the files you&#8217;ve uploaded are listed in the Media Library, with the most recent uploads listed first. You can use the Screen Options tab to customize the display of this screen.' ) . '</p>' .
201         '<p>' . __( 'You can narrow the list by file type/status using the text link filters at the top of the screen. You also can refine the list by date using the dropdown menu above the media table.' ) . '</p>' .
202         '<p>' . __( 'You can view your media in a simple visual grid or a list with columns. Switch between these views using the icons to the left above the media.' ) . '</p>'
203 ) );
204 get_current_screen()->add_help_tab( array(
205 'id'            => 'actions-links',
206 'title'         => __('Available Actions'),
207 'content'       =>
208         '<p>' . __( 'Hovering over a row reveals action links: Edit, Delete Permanently, and View. Clicking Edit or on the media file&#8217;s name displays a simple screen to edit that individual file&#8217;s metadata. Clicking Delete Permanently will delete the file from the media library (as well as from any posts to which it is currently attached). View will take you to the display page for that file.' ) . '</p>'
209 ) );
210 get_current_screen()->add_help_tab( array(
211 'id'            => 'attaching-files',
212 'title'         => __('Attaching Files'),
213 'content'       =>
214         '<p>' . __( 'If a media file has not been attached to any post, you will see that in the Attached To column, and can click on Attach File to launch a small popup that will allow you to search for a post and attach the file.' ) . '</p>'
215 ) );
216
217 get_current_screen()->set_help_sidebar(
218         '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
219         '<p>' . __( '<a href="http://codex.wordpress.org/Media_Library_Screen" target="_blank">Documentation on Media Library</a>' ) . '</p>' .
220         '<p>' . __( '<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
221 );
222
223 require_once( ABSPATH . 'wp-admin/admin-header.php' );
224 ?>
225
226 <div class="wrap">
227 <h2>
228 <?php
229 echo esc_html( $title );
230 if ( current_user_can( 'upload_files' ) ) { ?>
231         <a href="media-new.php" class="add-new-h2"><?php echo esc_html_x('Add New', 'file'); ?></a><?php
232 }
233 if ( ! empty( $_REQUEST['s'] ) )
234         printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', get_search_query() ); ?>
235 </h2>
236
237 <?php
238 $message = '';
239 if ( ! empty( $_GET['posted'] ) ) {
240         $message = __('Media attachment updated.');
241         $_SERVER['REQUEST_URI'] = remove_query_arg(array('posted'), $_SERVER['REQUEST_URI']);
242 }
243
244 if ( ! empty( $_GET['attached'] ) && $attached = absint( $_GET['attached'] ) ) {
245         $message = sprintf( _n('Reattached %d attachment.', 'Reattached %d attachments.', $attached), $attached );
246         $_SERVER['REQUEST_URI'] = remove_query_arg(array('attached'), $_SERVER['REQUEST_URI']);
247 }
248
249 if ( ! empty( $_GET['deleted'] ) && $deleted = absint( $_GET['deleted'] ) ) {
250         $message = sprintf( _n( 'Media attachment permanently deleted.', '%d media attachments permanently deleted.', $deleted ), number_format_i18n( $_GET['deleted'] ) );
251         $_SERVER['REQUEST_URI'] = remove_query_arg(array('deleted'), $_SERVER['REQUEST_URI']);
252 }
253
254 if ( ! empty( $_GET['trashed'] ) && $trashed = absint( $_GET['trashed'] ) ) {
255         $message = sprintf( _n( 'Media attachment moved to the trash.', '%d media attachments moved to the trash.', $trashed ), number_format_i18n( $_GET['trashed'] ) );
256         $message .= ' <a href="' . esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids='.(isset($_GET['ids']) ? $_GET['ids'] : ''), "bulk-media" ) ) . '">' . __('Undo') . '</a>';
257         $_SERVER['REQUEST_URI'] = remove_query_arg(array('trashed'), $_SERVER['REQUEST_URI']);
258 }
259
260 if ( ! empty( $_GET['untrashed'] ) && $untrashed = absint( $_GET['untrashed'] ) ) {
261         $message = sprintf( _n( 'Media attachment restored from the trash.', '%d media attachments restored from the trash.', $untrashed ), number_format_i18n( $_GET['untrashed'] ) );
262         $_SERVER['REQUEST_URI'] = remove_query_arg(array('untrashed'), $_SERVER['REQUEST_URI']);
263 }
264
265 $messages[1] = __('Media attachment updated.');
266 $messages[2] = __('Media permanently deleted.');
267 $messages[3] = __('Error saving media attachment.');
268 $messages[4] = __('Media moved to the trash.') . ' <a href="' . esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids='.(isset($_GET['ids']) ? $_GET['ids'] : ''), "bulk-media" ) ) . '">' . __('Undo') . '</a>';
269 $messages[5] = __('Media restored from the trash.');
270
271 if ( ! empty( $_GET['message'] ) && isset( $messages[ $_GET['message'] ] ) ) {
272         $message = $messages[ $_GET['message'] ];
273         $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
274 }
275
276 if ( !empty($message) ) { ?>
277 <div id="message" class="updated"><p><?php echo $message; ?></p></div>
278 <?php } ?>
279
280 <form id="posts-filter" action="" method="get">
281
282 <?php $wp_list_table->views(); ?>
283
284 <?php $wp_list_table->display(); ?>
285
286 <div id="ajax-response"></div>
287 <?php find_posts_div(); ?>
288 </form>
289 </div>
290
291 <?php
292 include( ABSPATH . 'wp-admin/admin-footer.php' );