X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/11be8dc178e77d0b46189bbd8e33a216a9b90942..b137f4ce021b4022c56f452c2eafa7abfcef0a7c:/wp-admin/includes/media.php
diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php
index 57e032ea..99deac5a 100644
--- a/wp-admin/includes/media.php
+++ b/wp-admin/includes/media.php
@@ -9,7 +9,7 @@
/**
* {@internal Missing Short Description}}
*
- * @since unknown
+ * @since 2.5.0
*
* @return unknown
*/
@@ -27,7 +27,7 @@ function media_upload_tabs() {
/**
* {@internal Missing Short Description}}
*
- * @since unknown
+ * @since 2.5.0
*
* @param unknown_type $tabs
* @return unknown
@@ -40,8 +40,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']);
@@ -57,7 +59,7 @@ add_filter('media_upload_tabs', 'update_gallery_tab');
/**
* {@internal Missing Short Description}}
*
- * @since unknown
+ * @since 2.5.0
*/
function the_media_upload_tabs() {
global $redir_tab;
@@ -69,17 +71,16 @@ function the_media_upload_tabs() {
$current = $redir_tab;
elseif ( isset($_GET['tab']) && array_key_exists($_GET['tab'], $tabs) )
$current = $_GET['tab'];
- else {
- $keys = array_keys($tabs);
- $current = array_shift($keys);
- }
+ else
+ $current = apply_filters('media_upload_default_tab', 'type');
+
foreach ( $tabs as $callback => $text ) {
$class = '';
if ( $current == $callback )
$class = " class='current'";
$href = add_query_arg(array('tab'=>$callback, 's'=>false, 'paged'=>false, 'post_mime_type'=>false, 'm'=>false));
- $link = "$text";
- echo "\t
$link\n";
+ $link = "$text";
+ echo "\t$link\n";
}
echo "\n";
}
@@ -88,7 +89,7 @@ function the_media_upload_tabs() {
/**
* {@internal Missing Short Description}}
*
- * @since unknown
+ * @since 2.5.0
*
* @param unknown_type $id
* @param unknown_type $alt
@@ -99,18 +100,16 @@ function the_media_upload_tabs() {
* @param unknown_type $size
* @return unknown
*/
-function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = false, $size='medium') {
-
- $htmlalt = ( empty($alt) ) ? $title : $alt;
+function get_image_send_to_editor($id, $caption, $title, $align, $url='', $rel = false, $size='medium', $alt = '') {
- $html = get_image_tag($id, $htmlalt, $title, $align, $size);
+ $html = get_image_tag($id, $alt, $title, $align, $size);
- $rel = $rel ? ' rel="attachment wp-att-'.attribute_escape($id).'"' : '';
+ $rel = $rel ? ' rel="attachment wp-att-' . esc_attr($id).'"' : '';
if ( $url )
- $html = '$html";
+ $html = '$html";
- $html = apply_filters( 'image_send_to_editor', $html, $id, $alt, $title, $align, $url, $size );
+ $html = apply_filters( 'image_send_to_editor', $html, $id, $caption, $title, $align, $url, $size, $alt );
return $html;
}
@@ -118,7 +117,7 @@ function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = fal
/**
* {@internal Missing Short Description}}
*
- * @since unknown
+ * @since 2.6.0
*
* @param unknown_type $html
* @param unknown_type $id
@@ -129,31 +128,38 @@ function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = fal
* @param unknown_type $size
* @return unknown
*/
-function image_add_caption( $html, $id, $alt, $title, $align, $url, $size ) {
+function image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $alt = '' ) {
+
+ if ( empty($caption) || apply_filters( 'disable_captions', '' ) )
+ return $html;
- if ( empty($alt) || apply_filters( 'disable_captions', '' ) ) return $html;
$id = ( 0 < (int) $id ) ? 'attachment_' . $id : '';
- preg_match( '/width="([0-9]+)/', $html, $matches );
- if ( ! isset($matches[1]) ) return $html;
+ if ( ! preg_match( '/width="([0-9]+)/', $html, $matches ) )
+ return $html;
+
$width = $matches[1];
- $html = preg_replace( '/align[^\s\'"]+\s?/', '', $html );
- if ( empty($align) ) $align = 'none';
+ $caption = str_replace( array( '>', '<', '"', "'" ),
+ array( '>', '<', '"', ''' ),
+ $caption
+ );
- $alt = ! empty($alt) ? addslashes($alt) : '';
+ $html = preg_replace( '/(class=["\'][^\'"]*)align(none|left|right|center)\s?/', '$1', $html );
+ if ( empty($align) )
+ $align = 'none';
$shcode = '[caption id="' . $id . '" align="align' . $align
- . '" width="' . $width . '" caption="' . $alt . '"]' . $html . '[/caption]';
+ . '" width="' . $width . '" caption="' . addslashes($caption) . '"]' . $html . '[/caption]';
return apply_filters( 'image_add_caption_shortcode', $shcode, $html );
}
-add_filter( 'image_send_to_editor', 'image_add_caption', 20, 7 );
+add_filter( 'image_send_to_editor', 'image_add_caption', 20, 8 );
/**
* {@internal Missing Short Description}}
*
- * @since unknown
+ * @since 2.5.0
*
* @param unknown_type $html
*/
@@ -165,7 +171,7 @@ var win = window.dialogArguments || opener || parent || top;
win.send_to_editor('');
/* ]]> */
- ');
*
* This handles the file upload POST itself, creating the attachment post.
*
- * @since unknown
+ * @since 2.5.0
*
- * @param unknown_type $file_id
- * @param unknown_type $post_id
- * @param unknown_type $post_data
- * @return unknown
+ * @param string $file_id Index into the {@link $_FILES} array of the upload
+ * @param int $post_id The post ID the media is associated with
+ * @param array $post_data allows you to overwrite some of the attachment
+ * @param array $overrides allows you to override the {@link wp_handle_upload()} behavior
+ * @return int the ID of the attachment
*/
-function media_handle_upload($file_id, $post_id, $post_data = array()) {
- $overrides = array('test_form'=>false);
+function media_handle_upload($file_id, $post_id, $post_data = array(), $overrides = array( 'test_form' => false )) {
$time = current_time('mysql');
if ( $post = get_post($post_id) ) {
@@ -190,22 +196,26 @@ function media_handle_upload($file_id, $post_id, $post_data = array()) {
$time = $post->post_date;
}
+ $name = $_FILES[$file_id]['name'];
$file = wp_handle_upload($_FILES[$file_id], $overrides, $time);
if ( isset($file['error']) )
return new WP_Error( 'upload_error', $file['error'] );
+ $name_parts = pathinfo($name);
+ $name = trim( substr( $name, 0, -(1 + strlen($name_parts['extension'])) ) );
+
$url = $file['url'];
$type = $file['type'];
$file = $file['file'];
- $title = preg_replace('/\.[^.]+$/', '', basename($file));
+ $title = $name;
$content = '';
// use image exif/iptc data for title and caption defaults if possible
if ( $image_meta = @wp_read_image_metadata($file) ) {
- if ( trim($image_meta['title']) )
+ if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) )
$title = $image_meta['title'];
- if ( trim($image_meta['caption']) )
+ if ( trim( $image_meta['caption'] ) )
$content = $image_meta['caption'];
}
@@ -218,6 +228,10 @@ function media_handle_upload($file_id, $post_id, $post_data = array()) {
'post_content' => $content,
), $post_data );
+ // This should never be set as it would then overwrite an existing attachment.
+ if ( isset( $attachment['ID'] ) )
+ unset( $attachment['ID'] );
+
// Save the data
$id = wp_insert_attachment($attachment, $file, $post_id);
if ( !is_wp_error($id) ) {
@@ -229,20 +243,20 @@ function media_handle_upload($file_id, $post_id, $post_data = array()) {
}
/**
- * {@internal Missing Short Description}}
+ * This handles a sideloaded file in the same way as an uploaded file is handled by {@link media_handle_upload()}
*
- * @since unknown
+ * @since 2.6.0
*
- * @param unknown_type $file_array
- * @param unknown_type $post_id
- * @param unknown_type $desc
- * @param unknown_type $post_data
- * @return unknown
+ * @param array $file_array Array similar to a {@link $_FILES} upload array
+ * @param int $post_id The post ID the media is associated with
+ * @param string $desc Description of the sideloaded file
+ * @param array $post_data allows you to overwrite some of the attachment
+ * @return int|object The ID of the attachment or a WP_Error on failure
*/
function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) {
$overrides = array('test_form'=>false);
- $file = wp_handle_sideload($file_array, $overrides);
+ $file = wp_handle_sideload($file_array, $overrides);
if ( isset($file['error']) )
return new WP_Error( 'upload_error', $file['error'] );
@@ -254,13 +268,13 @@ function media_handle_sideload($file_array, $post_id, $desc = null, $post_data =
// use image exif/iptc data for title and caption defaults if possible
if ( $image_meta = @wp_read_image_metadata($file) ) {
- if ( trim($image_meta['title']) )
+ if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) )
$title = $image_meta['title'];
- if ( trim($image_meta['caption']) )
+ if ( trim( $image_meta['caption'] ) )
$content = $image_meta['caption'];
}
- $title = @$desc;
+ $title = isset($desc) ? $desc : '';
// Construct the attachment array
$attachment = array_merge( array(
@@ -271,12 +285,15 @@ function media_handle_sideload($file_array, $post_id, $desc = null, $post_data =
'post_content' => $content,
), $post_data );
- // Save the data
+ // This should never be set as it would then overwrite an existing attachment.
+ if ( isset( $attachment['ID'] ) )
+ unset( $attachment['ID'] );
+
+ // Save the attachment metadata
$id = wp_insert_attachment($attachment, $file, $post_id);
- if ( !is_wp_error($id) ) {
+ if ( !is_wp_error($id) )
wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
- return $url;
- }
+
return $id;
}
@@ -286,7 +303,7 @@ function media_handle_sideload($file_array, $post_id, $desc = null, $post_data =
* Wrap iframe content (produced by $content_func) in a doctype, html head/body
* etc any additional function args will be passed to content_func.
*
- * @since unknown
+ * @since 2.5.0
*
* @param unknown_type $content_func
*/
@@ -301,19 +318,29 @@ function wp_iframe($content_func /* ... */) {
wp_enqueue_style( 'global' );
wp_enqueue_style( 'wp-admin' );
wp_enqueue_style( 'colors' );
-if ( 0 === strpos( $content_func, 'media' ) )
+// Check callback name for 'media'
+if ( ( is_array( $content_func ) && ! empty( $content_func[1] ) && 0 === strpos( (string) $content_func[1], 'media' ) )
+ || ( ! is_array( $content_func ) && 0 === strpos( $content_func, 'media' ) ) )
wp_enqueue_style( 'media' );
-
+wp_enqueue_style( 'ie' );
?>
@@ -323,7 +350,10 @@ if ( is_string($content_func) )
$args = func_get_args();
$args = array_slice($args, 1);
call_user_func_array($content_func, $args);
+
+ do_action('admin_print_footer_scripts');
?>
+