From a02dc6a24086895ee1aee154779b3b2d08971ac0 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Fri, 29 Feb 2008 06:54:15 +0000 Subject: [PATCH] Media Library updates from andy. see #5911 git-svn-id: https://develop.svn.wordpress.org/trunk@7100 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/css/media.css | 6 ++++++ wp-includes/functions.php | 15 ++++++++++++++ wp-includes/js/swfupload/handlers.js | 6 +++++- wp-includes/post.php | 24 +++++++++++++--------- wp-includes/script-loader.php | 30 ++++++++++++++-------------- 5 files changed, 56 insertions(+), 25 deletions(-) diff --git a/wp-admin/css/media.css b/wp-admin/css/media.css index df62cc3b2b..e1fabb00ea 100644 --- a/wp-admin/css/media.css +++ b/wp-admin/css/media.css @@ -21,6 +21,12 @@ div#media-upload-error { color: #f00; } +.file-error { + font-weight: bold; + color: #f00; + margin: 0 15px; +} + form { margin: 1em; } diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 33e2e88088..7fbd8134b9 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -1175,6 +1175,21 @@ function wp_upload_bits( $name, $deprecated, $bits, $time = NULL ) { return array( 'file' => $new_file, 'url' => $url, 'error' => false ); } +function wp_ext2type( $ext ) { + $ext2type = apply_filters('ext2type', array( + 'audio' => array('aac','ac3','aif','aiff','mp1','mp2','mp3','m3a','m4a','m4b','ogg','ram','wav','wma'), + 'video' => array('asf','avi','divx','dv','mov','mpg','mpeg','mp4','mpv','ogm','qt','rm','vob','wmv'), + 'document' => array('doc','pages','odt','rtf','pdf'), + 'spreadsheet' => array('xls','numbers','ods'), + 'interactive' => array('ppt','key','odp','swf'), + 'text' => array('txt'), + 'archive' => array('tar','bz2','gz','cab','dmg','rar','sea','sit','sqx','zip'), + 'code' => array('css','html','php','js'), + )); + foreach ( $ext2type as $type => $exts ) + if ( in_array($ext, $exts) ) + return $type; +} function wp_check_filetype( $filename, $mimes = null ) { // Accepted MIME types are set here as PCRE unless provided. diff --git a/wp-includes/js/swfupload/handlers.js b/wp-includes/js/swfupload/handlers.js index 70f0307e51..795a669796 100644 --- a/wp-includes/js/swfupload/handlers.js +++ b/wp-includes/js/swfupload/handlers.js @@ -117,7 +117,8 @@ function wpQueueError(message) { // file-specific message function wpFileError(fileObj, message) { - jQuery('#media-upload-error-' + fileObj.id).show().text(message); + jQuery('#media-item-' + fileObj.id + ' .filename').append(''+message+' '); + jQuery('.dismiss').click(function(){jQuery(this).parents('.media-item').slideUp(200, function(){jQuery(this).remove();})}); } function fileQueueError(fileObj, error_code, message) { @@ -126,12 +127,15 @@ function fileQueueError(fileObj, error_code, message) { wpQueueError(swfuploadL10n.queue_limit_exceeded); } else if ( error_code == SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT ) { + fileQueued(fileObj); wpFileError(fileObj, swfuploadL10n.file_exceeds_size_limit); } else if ( error_code == SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE ) { + fileQueued(fileObj); wpFileError(fileObj, swfuploadL10n.zero_byte_file); } else if ( error_code == SWFUpload.QUEUE_ERROR.INVALID_FILETYPE ) { + fileQueued(fileObj); wpFileError(fileObj, swfuploadL10n.invalid_filetype); } else { diff --git a/wp-includes/post.php b/wp-includes/post.php index f3d0ca0869..21cf0abaa3 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -884,10 +884,10 @@ function wp_match_mime_types($wildcard_mime_types, $real_mime_types) { $wild = '[-._a-z0-9]*'; foreach ( (array) $wildcard_mime_types as $type ) { $type = str_replace('*', $wild, $type); - $patternses[1][$type] = $type; + $patternses[1][$type] = "^$type$"; if ( false === strpos($type, '/') ) { - $patternses[2][$type] = "^$type/$wild$"; - $patternses[3][$type] = "$wild$type$wild"; + $patternses[2][$type] = "^$type/"; + $patternses[3][$type] = $type; } } asort($patternses); @@ -2361,7 +2361,6 @@ function wp_attachment_is_image( $post_id = 0 ) { function wp_mime_type_icon( $mime = 0 ) { if ( !is_numeric($mime) ) $icon = wp_cache_get("mime_type_icon_$mime"); - if ( empty($icon) ) { $post_id = 0; $post_mimes = array(); @@ -2370,8 +2369,11 @@ function wp_mime_type_icon( $mime = 0 ) { if ( $post =& get_post( $mime ) ) { $post_id = (int) $post->ID; $ext = preg_replace('/^.+?\.([^.]+)$/', '$1', $post->guid); - if ( !empty($ext) ) + if ( !empty($ext) ) { $post_mimes[] = $ext; + if ( $ext_type = wp_ext2type( $ext ) ) + $post_mimes[] = $ext_type; + } $mime = $post->post_mime_type; } else { $mime = 0; @@ -2383,16 +2385,20 @@ function wp_mime_type_icon( $mime = 0 ) { $icon_files = wp_cache_get('icon_files'); if ( !is_array($icon_files) ) { - $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images' ); - $icon_dir_uri = apply_filters( 'icon_dir_uri', trailingslashit(get_option('siteurl')) . WPINC . '/images' ); + $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/crystal' ); + $icon_dir_uri = apply_filters( 'icon_dir_uri', trailingslashit(get_option('siteurl')) . WPINC . '/images/crystal' ); $dirs = apply_filters( 'icon_dirs', array($icon_dir => $icon_dir_uri) ); $icon_files = array(); - foreach ( $dirs as $dir => $uri) { + while ( $dirs ) { + $dir = array_shift(array_keys($dirs)); + $uri = array_shift($dirs); if ( $dh = opendir($dir) ) { while ( false !== $file = readdir($dh) ) { $file = basename($file); + if ( substr($file, 0, 1) == '.' ) + continue; if ( !in_array(strtolower(substr($file, -4)), array('.png', '.gif', '.jpg') ) ) { - if ( is_dir($file) ) + if ( is_dir("$dir/$file") ) $dirs["$dir/$file"] = "$uri/$file"; continue; } diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 66e58e65a1..3f435e8f19 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -88,23 +88,23 @@ class WP_Scripts { $this->add( 'swfupload', '/wp-includes/js/swfupload/swfupload.js', false, '2.0.2'); $this->add( 'swfupload-degrade', '/wp-includes/js/swfupload/plugins/swfupload.graceful_degradation.js', array('swfupload'), '2.0.2'); $this->add( 'swfupload-queue', '/wp-includes/js/swfupload/plugins/swfupload.queue.js', array('swfupload'), '2.0.2'); - $this->add( 'swfupload-handlers', '/wp-includes/js/swfupload/handlers.js', array('swfupload'), '2.0.2-20080227'); + $this->add( 'swfupload-handlers', '/wp-includes/js/swfupload/handlers.js', array('swfupload'), '2.0.2-20080228'); // these error messages came from the sample swfupload js, they might need changing. $this->localize( 'swfupload-handlers', 'swfuploadL10n', array( - 'queue_limit_exceeded' => 'You have attempted to queue too many files.', - 'file_exceeds_size_limit' => 'The file you have selected is too big.', - 'zero_byte_file' => 'The file you selected is empty. Please select another file.', - 'invalid_filetype' => 'The file you choose is not an allowed file type.', - 'default_error' => 'An error occurred in the upload. Please try again later.', - 'missing_upload_url' => 'There was a configuration error. Please contact the server administrator.', - 'upload_limit_exceeded' => 'You may only upload 1 file.', - 'http_error' => 'HTTP error.', - 'upload_failed' => 'Upload failed.', - 'io_error' => 'IO error.', - 'security_error' => 'Security error.', - 'file_cancelled' => 'File cancelled.', - 'upload_stopped' => 'Upload stopped.', - + 'queue_limit_exceeded' => __('You have attempted to queue too many files.'), + 'file_exceeds_size_limit' => __('This file is too big. See php.ini.'), + 'zero_byte_file' => __('The file you selected is empty. Please select another file.'), + 'invalid_filetype' => __('The file you choose is not an allowed file type.'), + 'default_error' => __('An error occurred in the upload. Please try again later.'), + 'missing_upload_url' => __('There was a configuration error. Please contact the server administrator.'), + 'upload_limit_exceeded' => __('You may only upload 1 file.'), + 'http_error' => __('HTTP error.'), + 'upload_failed' => __('Upload failed.'), + 'io_error' => __('IO error.'), + 'security_error' => __('Security error.'), + 'file_cancelled' => __('File cancelled.'), + 'upload_stopped' => __('Upload stopped.'), + 'dismiss' => __('Dismiss'), ) ); $this->add( 'jquery-ui-tabs', '/wp-includes/js/jquery/ui.tabs.js', array('jquery'), '3' );