X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/d3b1ea255664edd2deef17f900a655613d20820d..53f4633144ed68c8b8fb5861f992b5489894a940:/wp-admin/includes/media.php diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index ab7cc58b..fc8ce0fe 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 unknown + * @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 unknown + * @since 2.5.0 * - * @param unknown_type $tabs - * @return unknown + * @global wpdb $wpdb + * + * @param array $tabs + * @return array $tabs with gallery if post has image attachment */ function update_gallery_tab($tabs) { global $wpdb; @@ -40,8 +49,10 @@ function update_gallery_tab($tabs) { return $tabs; } - if ( intval($_REQUEST['post_id']) ) - $attachments = intval($wpdb->get_var($wpdb->prepare("SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = %d", $_REQUEST['post_id']))); + $post_id = intval($_REQUEST['post_id']); + + if ( $post_id ) + $attachments = intval( $wpdb->get_var( $wpdb->prepare( "SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent = %d", $post_id ) ) ); if ( empty($attachments) ) { unset($tabs['gallery']); @@ -52,31 +63,37 @@ function update_gallery_tab($tabs) { return $tabs; } -add_filter('media_upload_tabs', 'update_gallery_tab'); /** * {@internal Missing Short Description}} * - * @since unknown + * @since 2.5.0 + * + * @global string $redir_tab */ function the_media_upload_tabs() { global $redir_tab; $tabs = media_upload_tabs(); + $default = 'type'; if ( !empty($tabs) ) { echo "
- | $filename | -
$post->post_mime_type | |
" . mysql2date($post->post_date, get_option('time_format')) . " | |
" . apply_filters('media_meta', '', $post) . " |
+
+ $image_edit_button + |
+
+ " . __('File name:') . " $filename +" . __('File type:') . " $post->post_mime_type +" . __('Upload date:') . " " . mysql2date( get_option('date_format'), $post->post_date ). ' '; + if ( !empty( $media_dims ) ) + $item .= "" . __('Dimensions:') . " $media_dims \n"; + + $item .= " | \n";
+
+ $item .= "
- \n";
+
+
$send $delete
- " . sprintf(__("You are about to delete %s."), $filename) . " " . __('Continue') . "
- " . __('Cancel') . " | |
" . $r['send'] . " $thumbnail $delete | |
\n\t\t\t | "; - if ( !empty($field[$field['input']]) ) - $item .= $field[$field['input']]; + $item .= "\t\t |
---|---|
\n\t\t\t | ";
+ if ( !empty( $field[ $field['input'] ] ) )
+ $item .= $field[ $field['input'] ];
elseif ( $field['input'] == 'textarea' ) {
- $item .= "";
+ 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 .= "";
+ $item .= "";
}
- if ( !empty($field['helps']) )
- $item .= " " . join( " \n", array_unique((array) $field['helps']) ) . ' '; + if ( !empty( $field['helps'] ) ) + $item .= "" . join( " \n", array_unique( (array) $field['helps'] ) ) . ' '; $item .= " | \n\t\t
$html | |
{$form_fields['_final']} |
" . join( "
\n", array_unique( (array) $field['helps'] ) ) . '
'; + $item .= "' . 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; + } - $flash = apply_filters('flash_uploader', $flash); + $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; + } ?> - -- +
+ - - @@ -1695,41 +2305,58 @@ jQuery(function($){ /** * {@internal Missing Short Description}} * - * @since unknown + * @since 2.5.0 * - * @param unknown_type $errors + * @global wpdb $wpdb + * @global WP_Query $wp_query + * @global WP_Locale $wp_locale + * @global string $type + * @global string $tab + * @global array $post_mime_types + * + * @param array $errors */ function media_upload_library_form($errors) { global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types; media_upload_header(); - $post_id = intval($_REQUEST['post_id']); + $post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0; - $form_action_url = admin_url("media-upload.php?type={$GLOBALS['type']}&tab=library&post_id=$post_id"); + $form_action_url = admin_url("media-upload.php?type=$type&tab=library&post_id=$post_id"); + /** This filter is documented in wp-admin/includes/media.php */ + $form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type ); + $form_class = 'media-upload-form validate'; - $_GET['paged'] = isset( $_GET['paged'] ) ? intval($_GET['paged']) : 0; - if ( $_GET['paged'] < 1 ) - $_GET['paged'] = 1; - $start = ( $_GET['paged'] - 1 ) * 10; - if ( $start < 1 ) - $start = 0; - add_filter( 'post_limits', $limit_filter = create_function( '$a', "return 'LIMIT $start, 10';" ) ); + if ( get_user_setting('uploader') ) + $form_class .= ' html-uploader'; - list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query(); + $q = $_GET; + $q['posts_per_page'] = 10; + $q['paged'] = isset( $q['paged'] ) ? intval( $q['paged'] ) : 0; + if ( $q['paged'] < 1 ) { + $q['paged'] = 1; + } + $q['offset'] = ( $q['paged'] - 1 ) * 10; + if ( $q['offset'] < 1 ) { + $q['offset'] = 0; + } + + list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query( $q ); ?> - - @@ -1854,54 +2491,70 @@ jQuery(function($){ } /** - * {@internal Missing Short Description}} + * Creates the form for external url * - * @since unknown + * @since 2.7.0 * - * @return unknown + * @param string $default_view + * @return string the form html */ -function type_url_form_image() { - - if ( apply_filters( 'disable_captions', '' ) ) { - $alt = __('Alternate Text'); - $alt_help = __('Alt text for the image, e.g. “The Mona Lisa”'); +function wp_media_insert_url_form( $default_view = 'image' ) { + /** This filter is documented in wp-admin/includes/media.php */ + if ( ! apply_filters( 'disable_captions', '' ) ) { + $caption = ' +- - + | + + * | ||
---|---|---|---|
- + | + * | -+ | |
- + | |||
' . __('Link text, e.g. “Ransom Demands (PDF)”') . ' | |||
+ |
- ' . $alt_help . ' |
+ ||
+ ' . $caption . ' + | |||
@@ -1914,9 +2567,9 @@ function type_url_form_image() { | |||
- + | |||
+ | @@ -1924,201 +2577,534 @@ function type_url_form_image() { ' . __('Enter a link URL or click above for presets.') . ' |
||
+ | + ' . get_submit_button( __( 'Insert into Post' ), 'button', 'insertonlybutton', false ) . ' + | +
- - * - | -- |
---|---|
- - * - | -- |
' . __('Link text, e.g. “Still Alive by Jonathan Coulton”') . ' | |
- | - - | -
+ browser uploader instead.' ), $browser_uploader, '_blank' ); ?> +
+ -+ Switch to the multi-file uploader.'); ?> +
+ -
+
+
+
+
+
+
'; - _e('You are using the Browser uploader.'); - if ( $flash ) { - // the user manually selected the browser uploader, so let them switch back to Flash - echo ' '; - printf( __('Try the Flash uploader instead.'), esc_url(add_query_arg('flash', 1)) ); - } - echo "
\n"; +function wp_read_video_metadata( $file ) { + if ( ! file_exists( $file ) ) + return false; + + $metadata = array(); + + if ( ! class_exists( 'getID3' ) ) + require( ABSPATH . WPINC . '/ID3/getid3.php' ); + $id3 = new getID3(); + $data = $id3->analyze( $file ); + + if ( isset( $data['video']['lossless'] ) ) + $metadata['lossless'] = $data['video']['lossless']; + if ( ! empty( $data['video']['bitrate'] ) ) + $metadata['bitrate'] = (int) $data['video']['bitrate']; + if ( ! empty( $data['video']['bitrate_mode'] ) ) + $metadata['bitrate_mode'] = $data['video']['bitrate_mode']; + if ( ! empty( $data['filesize'] ) ) + $metadata['filesize'] = (int) $data['filesize']; + if ( ! empty( $data['mime_type'] ) ) + $metadata['mime_type'] = $data['mime_type']; + if ( ! empty( $data['playtime_seconds'] ) ) + $metadata['length'] = (int) round( $data['playtime_seconds'] ); + if ( ! empty( $data['playtime_string'] ) ) + $metadata['length_formatted'] = $data['playtime_string']; + if ( ! empty( $data['video']['resolution_x'] ) ) + $metadata['width'] = (int) $data['video']['resolution_x']; + if ( ! empty( $data['video']['resolution_y'] ) ) + $metadata['height'] = (int) $data['video']['resolution_y']; + if ( ! empty( $data['fileformat'] ) ) + $metadata['fileformat'] = $data['fileformat']; + if ( ! empty( $data['video']['dataformat'] ) ) + $metadata['dataformat'] = $data['video']['dataformat']; + if ( ! empty( $data['video']['encoder'] ) ) + $metadata['encoder'] = $data['video']['encoder']; + if ( ! empty( $data['video']['codec'] ) ) + $metadata['codec'] = $data['video']['codec']; + + if ( ! empty( $data['audio'] ) ) { + unset( $data['audio']['streams'] ); + $metadata['audio'] = $data['audio']; + } + + wp_add_id3_tag_data( $metadata, $data ); + + return $metadata; } -add_action('post-flash-upload-ui', 'media_upload_flash_bypass'); -add_action('post-html-upload-ui', 'media_upload_html_bypass'); +/** + * Retrieve metadata from a audio file's ID3 tags + * + * @since 3.6.0 + * + * @param string $file Path to file. + * @return array|bool Returns array of metadata, if found. + */ +function wp_read_audio_metadata( $file ) { + if ( ! file_exists( $file ) ) + return false; + $metadata = array(); + + if ( ! class_exists( 'getID3' ) ) + require( ABSPATH . WPINC . '/ID3/getid3.php' ); + $id3 = new getID3(); + $data = $id3->analyze( $file ); + + if ( ! empty( $data['audio'] ) ) { + unset( $data['audio']['streams'] ); + $metadata = $data['audio']; + } + + if ( ! empty( $data['fileformat'] ) ) + $metadata['fileformat'] = $data['fileformat']; + if ( ! empty( $data['filesize'] ) ) + $metadata['filesize'] = (int) $data['filesize']; + if ( ! empty( $data['mime_type'] ) ) + $metadata['mime_type'] = $data['mime_type']; + if ( ! empty( $data['playtime_seconds'] ) ) + $metadata['length'] = (int) round( $data['playtime_seconds'] ); + if ( ! empty( $data['playtime_string'] ) ) + $metadata['length_formatted'] = $data['playtime_string']; + + wp_add_id3_tag_data( $metadata, $data ); + + return $metadata; +} /** - * {@internal Missing Short Description}} + * Encapsulate logic for Attach/Detach actions * - * Make sure the GET parameter sticks when we submit a form. + * @since 4.2.0 * - * @since unknown + * @global wpdb $wpdb WordPress database abstraction object. * - * @param unknown_type $url - * @return unknown + * @param int $parent_id Attachment parent ID. + * @param string $action Optional. Attach/detach action. Accepts 'attach' or 'detach'. + * Default 'attach'. */ -function media_upload_bypass_url($url) { - if ( array_key_exists('flash', $_REQUEST) ) - $url = add_query_arg('flash', intval($_REQUEST['flash'])); - return $url; -} +function wp_media_attach_action( $parent_id, $action = 'attach' ) { + global $wpdb; -add_filter('media_upload_form_url', 'media_upload_bypass_url'); + if ( ! $parent_id ) { + return; + } -add_filter('async_upload_image', 'get_media_item', 10, 2); -add_filter('async_upload_audio', 'get_media_item', 10, 2); -add_filter('async_upload_video', 'get_media_item', 10, 2); -add_filter('async_upload_file', 'get_media_item', 10, 2); + if ( ! current_user_can( 'edit_post', $parent_id ) ) { + wp_die( __( 'You are not allowed to edit this post.' ) ); + } + $ids = array(); + foreach ( (array) $_REQUEST['media'] as $att_id ) { + $att_id = (int) $att_id; -add_action('media_upload_image', 'media_upload_image'); -add_action('media_upload_audio', 'media_upload_audio'); -add_action('media_upload_video', 'media_upload_video'); -add_action('media_upload_file', 'media_upload_file'); + if ( ! current_user_can( 'edit_post', $att_id ) ) { + continue; + } -add_filter('media_upload_gallery', 'media_upload_gallery'); + $ids[] = $att_id; + } -add_filter('media_upload_library', 'media_upload_library'); + if ( ! empty( $ids ) ) { + $ids_string = implode( ',', $ids ); + if ( 'attach' === $action ) { + $result = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %d WHERE post_type = 'attachment' AND ID IN ( $ids_string )", $parent_id ) ); + } else { + $result = $wpdb->query( "UPDATE $wpdb->posts SET post_parent = 0 WHERE post_type = 'attachment' AND ID IN ( $ids_string )" ); + } -?> + foreach ( $ids as $att_id ) { + clean_attachment_cache( $att_id ); + } + } + + if ( isset( $result ) ) { + $location = 'upload.php'; + if ( $referer = wp_get_referer() ) { + if ( false !== strpos( $referer, 'upload.php' ) ) { + $location = remove_query_arg( array( 'attached', 'detach' ), $referer ); + } + } + + $key = 'attach' === $action ? 'attached' : 'detach'; + $location = add_query_arg( array( $key => $result ), $location ); + wp_redirect( $location ); + exit; + } +}