media_upload_form

Definition:
function media_upload_form( $errors = null ) {}

Parameters

  • unknown_type $errors

Defined filters

  • flash_uploader
    apply_filters('flash_uploader', $flash)
  • swfupload_post_params
    apply_filters( 'swfupload_post_params', $post_params )
  • upload_file_glob
    apply_filters('upload_file_glob', '*.*')
  • swfupload_success_handler
    apply_filters( 'swfupload_success_handler', 'uploadSuccess' )

Defined actions

  • pre-upload-ui
    do_action('pre-upload-ui');
  • pre-flash-upload-ui
    do_action('pre-flash-upload-ui');
  • post-flash-upload-ui
    do_action('post-flash-upload-ui');
  • pre-html-upload-ui
    do_action('pre-html-upload-ui');
  • post-html-upload-ui
    do_action('post-html-upload-ui', $flash);
  • post-upload-ui
    do_action('post-upload-ui');

Source code

function media_upload_form( $errors = null ) {

	global $type, $tab, $pagenow;



	$flash_action_url = admin_url('async-upload.php');



	// If Mac and mod_security, no Flash. 😦

	$flash = true;

	if ( false !== stripos($_SERVER['HTTP_USER_AGENT'], 'mac') && apache_mod_loaded('mod_security') )

		$flash = false;



	$flash = apply_filters('flash_uploader', $flash);

	$post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0;



	$upload_size_unit = $max_upload_size =  wp_max_upload_size();

	$sizes = array( 'KB', 'MB', 'GB' );

	for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ )

		$upload_size_unit /= 1024;

	if ( $u < 0 ) {

		$upload_size_unit = 0;

		$u = 0;

	} else {

		$upload_size_unit = (int) $upload_size_unit;

	}

?>

<script type="text/javascript">

//<![CDATA[

var uploaderMode = 0;

jQuery(document).ready(function($){

	uploaderMode = getUserSetting('uploader');

	$('.upload-html-bypass a').click(function(){deleteUserSetting('uploader');uploaderMode=0;swfuploadPreLoad();return false;});

	$('.upload-flash-bypass a').click(function(){setUserSetting('uploader', '1');uploaderMode=1;swfuploadPreLoad();return false;});

});

//]]>

</script>

<div id="media-upload-notice">

<?php if (isset($errors['upload_notice']) ) { ?>

	<?php echo $errors['upload_notice']; ?>

<?php } ?>

</div>

<div id="media-upload-error">

<?php if (isset($errors['upload_error']) && is_wp_error($errors['upload_error'])) { ?>

	<?php echo $errors['upload_error']->get_error_message(); ?>

<?php } ?>

</div>

<?php

// Check quota for this blog if multisite

if ( is_multisite() && !is_upload_space_available() ) {

	echo '<p>' . sprintf( __( 'Sorry, you have filled your storage quota (%s MB).' ), get_space_allowed() ) . '</p>';

	return;

}



do_action('pre-upload-ui');



if ( $flash ) :



// Set the post params, which SWFUpload will post back with the file, and pass

// them through a filter.

$post_params = array(

		"post_id" => $post_id,

		"auth_cookie" => (is_ssl() ? $_COOKIE[SECURE_AUTH_COOKIE] : $_COOKIE[AUTH_COOKIE]),

		"logged_in_cookie" => $_COOKIE[LOGGED_IN_COOKIE],

		"_wpnonce" => wp_create_nonce('media-form'),

		"type" => $type,

		"tab" => $tab,

		"short" => "1",

);

$post_params = apply_filters( 'swfupload_post_params', $post_params );

$p = array();

foreach ( $post_params as $param => $val )

	$p[] = "\t\t'$param' : '$val'";

$post_params_str = implode( ", \n", $p );



// #8545. wmode=transparent cannot be used with SWFUpload

if ( 'media-new.php' == $pagenow ) {

	$upload_image_path = get_user_option( 'admin_color' );

	if ( 'classic' != $upload_image_path )

		$upload_image_path = 'fresh';

	$upload_image_path = admin_url( 'images/upload-' . $upload_image_path . '.png?ver=20101205' );

} else {

	$upload_image_path = includes_url( 'images/upload.png?ver=20100531' );

}



?>

<script type="text/javascript">

//<![CDATA[

var swfu;

SWFUpload.onload = function() {

	var settings = {

			button_text: '<span class="button"><?php _e('Select Files'); ?><\/span>',

			button_text_style: '.button { text-align: center; font-weight: bold; font-family:"Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif; font-size: 11px; text-shadow: 0 1px 0 #FFFFFF; color:#464646; }',

			button_height: "23",

			button_width: "132",

			button_text_top_padding: 3,

			button_image_url: '<?php echo $upload_image_path; ?>',

			button_placeholder_id: "flash-browse-button",

			upload_url : "<?php echo esc_attr( $flash_action_url ); ?>",

			flash_url : "<?php echo includes_url('js/swfupload/swfupload.swf'); ?>",

			file_post_name: "async-upload",

			file_types: "<?php echo apply_filters('upload_file_glob', '*.*'); ?>",

			post_params : {

				<?php echo $post_params_str; ?>

			},

			file_size_limit : "<?php echo $max_upload_size; ?>b",

			file_dialog_start_handler : fileDialogStart,

			file_queued_handler : fileQueued,

			upload_start_handler : uploadStart,

			upload_progress_handler : uploadProgress,

			upload_error_handler : uploadError,

			upload_success_handler : <?php echo apply_filters( 'swfupload_success_handler', 'uploadSuccess' ); ?>,

			upload_complete_handler : uploadComplete,

			file_queue_error_handler : fileQueueError,

			file_dialog_complete_handler : fileDialogComplete,

			swfupload_pre_load_handler: swfuploadPreLoad,

			swfupload_load_failed_handler: swfuploadLoadFailed,

			custom_settings : {

				degraded_element_id : "html-upload-ui", // id of the element displayed when swfupload is unavailable

				swfupload_element_id : "flash-upload-ui" // id of the element displayed when swfupload is available

			},

			debug: false

		};

		swfu = new SWFUpload(settings);

};

//]]>

</script>



<div id="flash-upload-ui" class="hide-if-no-js">

<?php do_action('pre-flash-upload-ui'); ?>



	<div>

	<?php _e( 'Choose files to upload' ); ?>

	<div id="flash-browse-button"></div>

	<span><input id="cancel-upload" disabled="disabled" onclick="cancelUpload()" type="button" value="<?php esc_attr_e('Cancel Upload'); ?>" class="button" /></span>

	</div>

	<p class="media-upload-size"><?php printf( __( 'Maximum upload file size: %d%s' ), $upload_size_unit, $sizes[$u] ); ?></p>

<?php do_action('post-flash-upload-ui'); ?>

	<p class="howto"><?php _e('After a file has been uploaded, you can add titles and descriptions.'); ?></p>

</div>

<?php endif; // $flash ?>



<div id="html-upload-ui" <?php if ( $flash ) echo 'class="hide-if-js"'; ?>>

<?php do_action('pre-html-upload-ui'); ?>

	<p id="async-upload-wrap">

		<label class="screen-reader-text" for="async-upload"><?php _e('Upload'); ?></label>

		<input type="file" name="async-upload" id="async-upload" />

		<?php submit_button( __( 'Upload' ), 'button', 'html-upload', false ); ?>

		<a href="#" onclick="try{top.tb_remove();}catch(e){}; return false;"><?php _e('Cancel'); ?></a>

	</p>

	<div class="clear"></div>

	<p class="media-upload-size"><?php printf( __( 'Maximum upload file size: %d%s' ), $upload_size_unit, $sizes[$u] ); ?></p>

	<?php if ( is_lighttpd_before_150() ): ?>

	<p><?php _e('If you want to use all capabilities of the uploader, like uploading multiple files at once, please update to lighttpd 1.5.'); ?></p>

	<?php endif;?>

<?php do_action('post-html-upload-ui', $flash); ?>

</div>

<?php do_action('post-upload-ui'); ?>

<?php

}

2369

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: