<?php

function slides_media_upload_tabs ($tabs) {
	unset($tabs['gallery']);
	return $tabs;
}

function slides_media_form_url($form_action_url, $type){
	$form_action_url = $form_action_url.'&slides_media_select=1';
	return $form_action_url;
}

function disable_gallery_flash_uploader($flash){
	return false;
}

function slides_media_attachment_fields_to_edit($form_fields, $post){

	unset($form_fields['url'], $form_fields['align'], $form_fields['image-size']);
	$filename = basename( $post->guid );
	$attachment_id = $post->ID;
	if ( current_user_can( 'delete_post', $attachment_id ) ) {
		if ( !EMPTY_TRASH_DAYS ) {
			$delete = "<a href='" . wp_nonce_url( "post.php?action=delete&amp;post=$attachment_id", 'delete-attachment_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete'>" . __( 'Delete Permanently' ,THEME_ADMIN_DOMAIN) . '</a>';
		} elseif ( !MEDIA_TRASH ) {
			$delete = "<a href='#' class='del-link' onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __( 'Delete',THEME_ADMIN_DOMAIN ) . "</a>
			 <div id='del_attachment_$attachment_id' class='del-attachment' style='display:none;'>" . sprintf( __( 'You are about to delete <strong>%s</strong>.' ,THEME_ADMIN_DOMAIN), $filename ) . "
			 <a href='" . wp_nonce_url( "post.php?action=delete&amp;post=$attachment_id", 'delete-attachment_' . $attachment_id ) . "' id='del[$attachment_id]' class='button'>" . __( 'Continue' ,THEME_ADMIN_DOMAIN) . "</a>
			 <a href='#' class='button' onclick=\"this.parentNode.style.display='none';return false;\">" . __( 'Cancel',THEME_ADMIN_DOMAIN ) . "</a>
			 </div>";
		} else {
			$delete = "<a href='" . wp_nonce_url( "post.php?action=trash&amp;post=$attachment_id", 'trash-attachment_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete'>" . __( 'Move to Trash',THEME_ADMIN_DOMAIN ) . "</a>
			<a href='" . wp_nonce_url( "post.php?action=untrash&amp;post=$attachment_id", 'untrash-attachment_' . $attachment_id ) . "' id='undo[$attachment_id]' class='undo hidden'>" . __( 'Undo',THEME_ADMIN_DOMAIN ) . "</a>";
		}
	} else {
		$delete = '';
	}
	$mime  =  explode('/',$post->post_mime_type);
	$type  =  '';
	if($mime[0]=="image")
		$type="image";
	if($mime[1]=="x-shockwave-flash")
		$type="video";
	$form_fields['buttons'] = array( 
		'tr' => '<tr><td></td><td><input type="button" class="button" onclick="themeSendMediaData(\''.$post->ID.'\',\''.$post->post_title.'\',\''.$type.'\');" value="' . esc_attr__('Insert into Gallery',THEME_ADMIN_DOMAIN) . '" />'.$delete.'</td></tr>'
	);
	return $form_fields;
}
function type_url_form_slides(){
   
	return '
		<table class="describe"><tbody>
		<tr>
			<th valign="top" scope="row" class="label">
				<span class="alignleft"><label for="href">' . __('URL',THEME_ADMIN_DOMAIN) . '</label></span>
				<span class="alignright"><abbr id="status_img" title="required" class="required">*</abbr></span>
			</th>
			<td class="field"><input id="href" name="href" value="" type="text" aria-required="true" onblur="addExtMedia.themeGetMediaData(\''.esc_url( admin_url( 'images/no.png' )).'\',\''.esc_url( admin_url( 'images/yes.png' )).'\',\''.esc_url( admin_url( 'images/wpspin_light.gif' ) ).'\');"></td>
		</tr>
		<tr>
			<th valign="top" scope="row" class="label">
				<span class="alignleft"><label for="title">' . __('Title',THEME_ADMIN_DOMAIN) . '</label></span>
				<span class="alignright"><abbr title="required" class="required">*</abbr></span>
			</th>
			<td class="field"><input id="title" name="title" value="" type="text" aria-required="true"></td>
		</tr>
		<tr><td></td><td class="help">' . __('Only supported is image or swf',THEME_ADMIN_DOMAIN) . '</td></tr>
		<tr>
			<td></td>
			<td>
			<input type="button" class="button" id="go_button" style="color:#bbb;" onclick="addExtMedia.themeSelectMediaFromUrl();" value="' . esc_attr__('Insert into Gallery',THEME_ADMIN_DOMAIN) . '" />
			</td>
		</tr>
	</tbody></table>';
}
function gallery_image_upload_init(){
	add_filter('flash_uploader', 'disable_gallery_flash_uploader');
	add_filter('media_upload_tabs', 'slides_media_upload_tabs');
	add_filter('attachment_fields_to_edit', 'slides_media_attachment_fields_to_edit', 10, 2);
	add_filter('media_upload_form_url', 'slides_media_form_url', 10, 2);
	add_filter('type_url_form_file', 'type_url_form_slides', 10, 2);
	wp_register_script('theme-slides-media-upload', THEME_ADMIN_ASSETS_URI . '/js/slides-media-upload.js');
	wp_enqueue_script('theme-slides-media-upload');
}

add_action('admin_init', 'gallery_image_upload_init');
?>
