X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/5aa86a9053fb0fa15846bb60aac2fb8fdfff524a..3194d1bb103c2d8db4f44feeced5e58ee2756658:/wp-admin/includes/media.php diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index ff77e6c0..9990b9fd 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -7,11 +7,11 @@ */ /** - * {@internal Missing Short Description}} + * Defines the default media upload tabs * * @since 2.5.0 * - * @return unknown + * @return array default tabs */ function media_upload_tabs() { $_default_tabs = array( @@ -21,16 +21,25 @@ function media_upload_tabs() { 'library' => __('Media Library') ); - return apply_filters('media_upload_tabs', $_default_tabs); + /** + * Filter the available tabs in the legacy (pre-3.5.0) media popup. + * + * @since 2.5.0 + * + * @param array $_default_tabs An array of media tabs. + */ + return apply_filters( 'media_upload_tabs', $_default_tabs ); } /** - * {@internal Missing Short Description}} + * Adds the gallery tab back to the tabs array if post has image attachments * * @since 2.5.0 * - * @param unknown_type $tabs - * @return unknown + * @global wpdb $wpdb WordPress database abstraction object. + * + * @param array $tabs + * @return array $tabs with gallery if post has image attachment */ function update_gallery_tab($tabs) { global $wpdb; @@ -54,32 +63,29 @@ function update_gallery_tab($tabs) { return $tabs; } -add_filter('media_upload_tabs', 'update_gallery_tab'); /** - * {@internal Missing Short Description}} + * Outputs the legacy media upload tabs UI. * * @since 2.5.0 + * + * @global string $redir_tab */ function the_media_upload_tabs() { - global $redir_tab, $is_iphone; + global $redir_tab; $tabs = media_upload_tabs(); - - if ( $is_iphone ) { - unset($tabs['type']); - $default = 'type_url'; - } else { - $default = 'type'; - } + $default = 'type'; if ( !empty($tabs) ) { echo "
$image_edit_button @@ -1129,8 +1461,6 @@ function get_media_item( $attachment_id, $args = null ) { $item .= " | |||||||
$send $thumbnail $delete | |||||||
" . $r['send'] . " $thumbnail $delete | |||||||
\n\t\t\t | "; + $item .= "\t\t | ||||||
---|---|---|---|---|---|---|---|
\n\t\t\t | ";
if ( !empty( $field[ $field['input'] ] ) )
$item .= $field[ $field['input'] ];
elseif ( $field['input'] == 'textarea' ) {
- if ( user_can_richedit() ) { // textarea_escaped when user_can_richedit() = false
- $field['value'] = esc_textarea( $field['value'] );
+ if ( 'post_content' == $id && user_can_richedit() ) {
+ // Sanitize_post() skips the post_content when user_can_richedit.
+ $field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES );
}
+ // Post_excerpt is already escaped by sanitize_post() in get_attachment_fields_to_edit().
$item .= "';
} else {
$item .= "";
@@ -1251,179 +1593,402 @@ function get_media_item( $attachment_id, $args = null ) {
}
/**
- * {@internal Missing Short Description}}
+ * @since 3.5.0
*
- * @since 2.5.0
+ * @param int $attachment_id
+ * @param array $args
+ * @return array
*/
-function media_upload_header() {
- ?>
-
-
-
-
- null,
+ 'in_modal' => false,
+ );
- if ( $is_iphone )
- return;
+ $user_can_edit = current_user_can( 'edit_post', $attachment_id );
- $upload_action_url = admin_url('async-upload.php');
- $post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0;
- $_type = isset($type) ? $type : '';
- $_tab = isset($tab) ? $tab : '';
+ $args = wp_parse_args( $args, $default_args );
- $upload_size_unit = $max_upload_size = wp_max_upload_size();
- $sizes = array( 'KB', 'MB', 'GB' );
+ /** This filter is documented in wp-admin/includes/media.php */
+ $args = apply_filters( 'get_media_item_args', $args );
- for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) {
- $upload_size_unit /= 1024;
- }
+ $form_fields = array();
- if ( $u < 0 ) {
- $upload_size_unit = 0;
- $u = 0;
- } else {
- $upload_size_unit = (int) $upload_size_unit;
- }
-?>
+ if ( $args['in_modal'] ) {
+ foreach ( get_attachment_taxonomies($post) as $taxonomy ) {
+ $t = (array) get_taxonomy($taxonomy);
+ if ( ! $t['public'] || ! $t['show_ui'] )
+ continue;
+ if ( empty($t['label']) )
+ $t['label'] = $taxonomy;
+ if ( empty($t['args']) )
+ $t['args'] = array();
-ID, $taxonomy);
+ if ( false === $terms )
+ $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
- if (isset($errors['upload_notice']) )
- echo $errors['upload_notice'];
+ $values = array();
-?>
-slug;
+ $t['value'] = join(', ', $values);
+ $t['taxonomy'] = true;
- if (isset($errors['upload_error']) && is_wp_error($errors['upload_error']))
- echo $errors['upload_error']->get_error_message();
+ $form_fields[$taxonomy] = $t;
+ }
+ }
-?>
-' . sprintf( __( 'Sorry, you have filled your storage quota (%s MB).' ), get_space_allowed() ) . '';
- return;
-}
+ // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default
+ // The recursive merge is easily traversed with array casting: foreach ( (array) $things as $thing )
+ $form_fields = array_merge_recursive($form_fields, (array) $args['errors'] );
-do_action('pre-upload-ui');
+ /** This filter is documented in wp-admin/includes/media.php */
+ $form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post );
-$post_params = array(
- "post_id" => $post_id,
- "_wpnonce" => wp_create_nonce('media-form'),
- "type" => $_type,
- "tab" => $_tab,
- "short" => "1",
-);
+ unset( $form_fields['image-size'], $form_fields['align'], $form_fields['image_alt'],
+ $form_fields['post_title'], $form_fields['post_excerpt'], $form_fields['post_content'],
+ $form_fields['url'], $form_fields['menu_order'], $form_fields['image_url'] );
-$post_params = apply_filters( 'upload_post_params', $post_params ); // hook change! old name: 'swfupload_post_params'
+ /** This filter is documented in wp-admin/includes/media.php */
+ $media_meta = apply_filters( 'media_meta', '', $post );
-$plupload_init = array(
- 'runtimes' => 'html5,silverlight,flash,html4',
- 'browse_button' => 'plupload-browse-button',
- 'container' => 'plupload-upload-ui',
- 'drop_element' => 'drag-drop-area',
- 'file_data_name' => 'async-upload',
- 'multiple_queues' => true,
- 'max_file_size' => $max_upload_size . 'b',
- 'url' => $upload_action_url,
- 'flash_swf_url' => includes_url('js/plupload/plupload.flash.swf'),
- 'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'),
- 'filters' => array( array('title' => __( 'Allowed Files' ), 'extensions' => '*') ),
- 'multipart' => true,
- 'urlstream_upload' => true,
- 'multipart_params' => $post_params
-);
+ $defaults = array(
+ 'input' => 'text',
+ 'required' => false,
+ 'value' => '',
+ 'extra_rows' => array(),
+ 'show_in_edit' => true,
+ 'show_in_modal' => true,
+ );
-$plupload_init = apply_filters( 'plupload_init', $plupload_init );
+ $hidden_fields = array();
-?>
+ $item = '';
+ foreach ( $form_fields as $id => $field ) {
+ if ( $id[0] == '_' )
+ continue;
-
+ $name = "attachments[$attachment_id][$id]";
+ $id_attr = "attachments-$attachment_id-$id";
-
-
-
+ if ( !empty( $field['tr'] ) ) {
+ $item .= $field['tr'];
+ continue;
+ }
-
-
-
-
-
-
-
-
-
-
+ $field = array_merge( $defaults, $field );
+
+ if ( ( ! $field['show_in_edit'] && ! $args['in_modal'] ) || ( ! $field['show_in_modal'] && $args['in_modal'] ) )
+ continue;
+
+ if ( $field['input'] == 'hidden' ) {
+ $hidden_fields[$name] = $field['value'];
+ continue;
+ }
+
+ $readonly = ! $user_can_edit && ! empty( $field['taxonomy'] ) ? " readonly='readonly' " : '';
+ $required = $field['required'] ? '*' : '';
+ $aria_required = $field['required'] ? " aria-required='true' " : '';
+ $class = 'compat-field-' . $id;
+ $class .= $field['required'] ? ' form-required' : '';
+
+ $item .= "\t\t ";
+ $item .= " | \n\t\t\t";
+
+ if ( !empty( $field[ $field['input'] ] ) )
+ $item .= $field[ $field['input'] ];
+ elseif ( $field['input'] == 'textarea' ) {
+ if ( 'post_content' == $id && user_can_richedit() ) {
+ // sanitize_post() skips the post_content when user_can_richedit.
+ $field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES );
+ }
+ $item .= "';
+ } else {
+ $item .= "";
+ }
+ if ( !empty( $field['helps'] ) )
+ $item .= " | \n\t\t" . join( " \n", array_unique( (array) $field['helps'] ) ) . ' '; + $item .= "$html | {$form_fields['_final']} | ';
+ the_media_upload_tabs();
+ echo ' ';
+ }
+}
+
+/**
+ * Outputs the legacy media upload form.
+ *
+ * @since 2.5.0
+ *
+ * @global string $type
+ * @global string $tab
+ * @global bool $is_IE
+ * @global bool $is_opera
+ *
+ * @param array $errors
+ */
+function media_upload_form( $errors = null ) {
+ global $type, $tab, $is_IE, $is_opera;
+
+ if ( ! _device_can_upload() ) {
+ echo '' . sprintf( __('The web browser on your device cannot be used to upload files. You may be able to use the native app for your device instead.'), 'https://apps.wordpress.org/' ) . ' '; + return; + } + + $upload_action_url = admin_url('async-upload.php'); + $post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0; + $_type = isset($type) ? $type : ''; + $_tab = isset($tab) ? $tab : ''; + + $max_upload_size = wp_max_upload_size(); + if ( ! $max_upload_size ) { + $max_upload_size = 0; + } +?> + + +get_error_message();
+
+?>
+ $post_id,
+ "_wpnonce" => wp_create_nonce('media-form'),
+ "type" => $_type,
+ "tab" => $_tab,
+ "short" => "1",
+);
+
+/**
+ * Filter the media upload post parameters.
+ *
+ * @since 3.1.0 As 'swfupload_post_params'
+ * @since 3.3.0
+ *
+ * @param array $post_params An array of media upload parameters used by Plupload.
+ */
+$post_params = apply_filters( 'upload_post_params', $post_params );
+
+$plupload_init = array(
+ 'runtimes' => 'html5,flash,silverlight,html4',
+ 'browse_button' => 'plupload-browse-button',
+ 'container' => 'plupload-upload-ui',
+ 'drop_element' => 'drag-drop-area',
+ 'file_data_name' => 'async-upload',
+ 'url' => $upload_action_url,
+ 'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ),
+ 'silverlight_xap_url' => includes_url( 'js/plupload/plupload.silverlight.xap' ),
+ 'filters' => array(
+ 'max_file_size' => $max_upload_size . 'b',
+ ),
+ 'multipart_params' => $post_params,
+);
+
+// Currently only iOS Safari supports multiple files uploading but iOS 7.x has a bug that prevents uploading of videos
+// when enabled. See #29602.
+if ( wp_is_mobile() && strpos( $_SERVER['HTTP_USER_AGENT'], 'OS 7_' ) !== false &&
+ strpos( $_SERVER['HTTP_USER_AGENT'], 'like Mac OS X' ) !== false ) {
+
+ $plupload_init['multi_selection'] = false;
+}
+
+/**
+ * Filter the default Plupload settings.
+ *
+ * @since 3.3.0
+ *
+ * @param array $plupload_init An array of default settings used by Plupload.
+ */
+$plupload_init = apply_filters( 'plupload_init', $plupload_init );
+
+?>
+
+
+
+
+
+
+
+
-
+
100 * 1024 * 1024 ) { ?>
-
-
-
+
+
+
+
+
+
+
+ |