Uploader improvements from mdawaffe. fixes #3191

git-svn-id: http://svn.automattic.com/wordpress/trunk@4274 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2006-10-03 07:15:13 +00:00
parent f1f2928770
commit b5741c1270
12 changed files with 855 additions and 773 deletions

View File

@ -1973,16 +1973,28 @@ function the_attachment_links($id = false) {
$icon = get_attachment_icon($post->ID);
?>
<p><?php _e('Text linked to file') ?><br />
<textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo $post->guid ?>" class="attachmentlink"><?php echo basename($post->guid) ?></a></textarea></p>
<p><?php _e('Text linked to subpost') ?><br />
<textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link($post->ID) ?>" rel="attachment" id="<?php echo $post->ID ?>"><?php echo $post->post_title ?></a></textarea></p>
<form id="the-attachment-links">
<table>
<tr>
<th scope="row"><?php _e('Text linked to file') ?></th>
<td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo $post->guid ?>" class="attachmentlink"><?php echo basename($post->guid) ?></a></textarea></td>
</tr>
<tr>
<th scope="row"><?php _e('Text linked to subpost') ?></th>
<td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link($post->ID) ?>" rel="attachment" id="<?php echo $post->ID ?>"><?php echo $post->post_title ?></a></textarea></td>
</tr>
<?php if ( $icon ) : ?>
<p><?php _e('Thumbnail linked to file') ?><br />
<textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo $post->guid ?>" class="attachmentlink"><?php echo $icon ?></a></textarea></p>
<p><?php _e('Thumbnail linked to subpost') ?><br />
<textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link($post->ID) ?>" rel="attachment" id="<?php echo $post->ID ?>"><?php echo $icon ?></a></textarea></p>
<tr>
<th scope="row"><?php _e('Thumbnail linked to file') ?></th>
<td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo $post->guid ?>" class="attachmentlink"><?php echo $icon ?></a></textarea></td>
</tr>
<tr>
<th scope="row"><?php _e('Thumbnail linked to subpost') ?></th>
<td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link($post->ID) ?>" rel="attachment" id="<?php echo $post->ID ?>"><?php echo $icon ?></a></textarea></td>
</tr>
<?php endif; ?>
</table>
</form>
<?php
}

View File

@ -183,7 +183,7 @@ else
<?php
if (current_user_can('upload_files')) {
$uploading_iframe_ID = (0 == $post_ID ? $temp_ID : $post_ID);
$uploading_iframe_src = wp_nonce_url("inline-uploading.php?action=view&amp;post=$uploading_iframe_ID", 'inlineuploading');
$uploading_iframe_src = wp_nonce_url("upload.php?style=inline&amp;tab=upload&amp;post_id=$uploading_iframe_ID", 'inlineuploading');
$uploading_iframe_src = apply_filters('uploading_iframe_src', $uploading_iframe_src);
if ( false != $uploading_iframe_src )
echo '<iframe id="uploading" frameborder="0" src="' . $uploading_iframe_src . '">' . __('This feature requires iframe support.') . '</iframe>';

View File

@ -156,7 +156,7 @@ if ('publish' != $post->post_status || 0 == $post_ID):
<?php
if (current_user_can('upload_files')) {
$uploading_iframe_ID = (0 == $post_ID ? $temp_ID : $post_ID);
$uploading_iframe_src = wp_nonce_url("inline-uploading.php?action=view&amp;post=$uploading_iframe_ID", 'inlineuploading');
$uploading_iframe_src = wp_nonce_url("upload.php?style=inline&amp;tab=upload&amp;post_id=$uploading_iframe_ID", 'inlineuploading');
$uploading_iframe_src = apply_filters('uploading_iframe_src', $uploading_iframe_src);
if ( false != $uploading_iframe_src )
echo '<iframe id="uploading" frameborder="0" src="' . $uploading_iframe_src . '">' . __('This feature requires iframe support.') . '</iframe>';

View File

@ -1,762 +0,0 @@
<?php
require_once('admin.php');
@header('Content-type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
if (!current_user_can('upload_files'))
wp_die(__('You do not have permission to upload files.'));
wp_reset_vars(array('action', 'post', 'all', 'last', 'link', 'sort', 'start', 'imgtitle', 'descr', 'attachment'));
$post = (int) $post;
$images_width = 1;
switch($action) {
case 'links':
// Do not pass GO.
break;
case 'delete':
check_admin_referer('inlineuploading');
if ( !current_user_can('edit_post', (int) $attachment) )
wp_die(__('You are not allowed to delete this attachment.').' <a href="'.basename(__FILE__)."?post=$post&amp;all=$all&amp;action=upload\">".__('Go back').'</a>');
wp_delete_attachment($attachment);
wp_redirect(basename(__FILE__) ."?post=$post&all=$all&action=view&start=$start");
die;
case 'save':
check_admin_referer('inlineuploading');
$overrides = array('action'=>'save');
$file = wp_handle_upload($_FILES['image'], $overrides);
if ( isset($file['error']) )
wp_die($file['error'] . '<br /><a href="' . basename(__FILE__) . '?action=upload&post=' . $post . '">'.__('Back to Image Uploading').'</a>');
$url = $file['url'];
$type = $file['type'];
$file = $file['file'];
$filename = basename($file);
// Construct the attachment array
$attachment = array(
'post_title' => $imgtitle ? $imgtitle : $filename,
'post_content' => $descr,
'post_type' => 'attachment',
'post_parent' => $post,
'post_mime_type' => $type,
'guid' => $url
);
// Save the data
$id = wp_insert_attachment($attachment, $file, $post);
if ( preg_match('!^image/!', $attachment['post_mime_type']) ) {
// Generate the attachment's postmeta.
$imagesize = getimagesize($file);
$imagedata['width'] = $imagesize['0'];
$imagedata['height'] = $imagesize['1'];
list($uwidth, $uheight) = get_udims($imagedata['width'], $imagedata['height']);
$imagedata['hwstring_small'] = "height='$uheight' width='$uwidth'";
$imagedata['file'] = $file;
add_post_meta($id, '_wp_attachment_metadata', $imagedata);
if ( $imagedata['width'] * $imagedata['height'] < 3 * 1024 * 1024 ) {
if ( $imagedata['width'] > 128 && $imagedata['width'] >= $imagedata['height'] * 4 / 3 )
$thumb = wp_create_thumbnail($file, 128);
elseif ( $imagedata['height'] > 96 )
$thumb = wp_create_thumbnail($file, 96);
if ( @file_exists($thumb) ) {
$newdata = $imagedata;
$newdata['thumb'] = basename($thumb);
update_post_meta($id, '_wp_attachment_metadata', $newdata, $imagedata);
} else {
$error = $thumb;
}
}
} else {
add_post_meta($id, '_wp_attachment_metadata', array());
}
wp_redirect(basename(__FILE__) . "?post=$post&all=$all&action=view&start=0");
die();
case 'upload':
$current_1 = ' class="current"';
$back = $next = false;
break;
case 'view':
// How many images do we show? How many do we query?
$num = 5;
$double = $num * 2;
if ( $post && (empty($all) || $all == 'false') ) {
$and_post = "AND post_parent = '$post'";
$current_2 = ' class="current"';
} else {
$current_3 = ' class="current"';
}
if (! current_user_can('edit_others_posts') )
$and_user = "AND post_author = " . $user_ID;
if ( $last )
$start = $wpdb->get_var("SELECT count(ID) FROM $wpdb->posts WHERE post_type = 'attachment' $and_user $and_post") - $num;
else
$start = (int) $start;
if ( $start < 0 )
$start = 0;
if ( '' == $sort )
$sort = "post_date_gmt DESC";
$attachments = $wpdb->get_results("SELECT ID, post_date, post_title, post_mime_type, guid FROM $wpdb->posts WHERE post_type = 'attachment' $and_type $and_post $and_user ORDER BY $sort LIMIT $start, $double", ARRAY_A);
if ( count($attachments) == 0 ) {
wp_redirect( basename(__FILE__) ."?post=$post&action=upload" );
die;
} elseif ( count($attachments) > $num ) {
$next = $start + count($attachments) - $num;
} else {
$next = false;
}
if ( $start > 0 ) {
$back = $start - $num;
if ( $back < 1 )
$back = '0';
} else {
$back = false;
}
$uwidth_sum = 0;
$html = '';
$popups = '';
$style = '';
$script = '';
if ( count($attachments) > 0 ) {
$attachments = array_slice( $attachments, 0, $num );
$__delete = __('Delete');
$__not_linked = __('Not Linked');
$__linked_to_page = __('Linked to Page');
$__linked_to_image = __('Linked to Image');
$__linked_to_file = __('Linked to File');
$__using_thumbnail = __('Using Thumbnail');
$__using_original = __('Using Original');
$__using_title = __('Using Title');
$__using_filename = __('Using Filename');
$__using_icon = __('Using Icon');
$__no_thumbnail = '<del>'.__('No Thumbnail').'</del>';
$__send_to_editor = __('Send to editor');
$__close = __('Close Options');
$__confirmdelete = __('Delete this file from the server?');
$__nothumb = __('There is no thumbnail associated with this photo.');
$script .= "notlinked = '$__not_linked';
linkedtoimage = '$__linked_to_image';
linkedtopage = '$__linked_to_page';
linkedtofile = '$__linked_to_file';
usingthumbnail = '$__using_thumbnail';
usingoriginal = '$__using_original';
usingtitle = '$__using_title';
usingfilename = '$__using_filename';
usingicon = '$__using_icon';
var aa = new Array();
var ab = new Array();
var imga = new Array();
var imgb = new Array();
var srca = new Array();
var srcb = new Array();
var title = new Array();
var filename = new Array();
var icon = new Array();
";
foreach ( $attachments as $key => $attachment ) {
$ID = $attachment['ID'];
$href = get_attachment_link($ID);
$meta = get_post_meta($ID, '_wp_attachment_metadata', true);
if (!is_array($meta)) {
$meta = get_post_meta($ID, 'imagedata', true); // Try 1.6 Alpha meta key
if (!is_array($meta)) {
$meta = array();
}
add_post_meta($ID, '_wp_attachment_metadata', $meta);
}
$attachment = array_merge($attachment, $meta);
$noscript = "<noscript>
<div class='caption'><a href=\"".basename(__FILE__)."?action=links&amp;attachment={$ID}&amp;post={$post}&amp;all={$all}&amp;start={$start}\">Choose Links</a></div>
</noscript>
";
$send_delete_cancel = "<a onclick=\"sendToEditor({$ID});return false;\" href=\"javascript:void()\">$__send_to_editor</a>
<a onclick=\"return confirm('$__confirmdelete')\" href=\"" . wp_nonce_url( basename(__FILE__) . "?action=delete&amp;attachment={$ID}&amp;all=$all&amp;start=$start&amp;post=$post", inlineuploading) . "\">$__delete</a>
<a onclick=\"popup.style.display='none';return false;\" href=\"javascript:void()\">$__close</a>
";
$uwidth_sum += 128;
if ( preg_match('!^image/!', $attachment['post_mime_type'] ) ) {
$image = & $attachment;
if ( ($image['width'] > 128 || $image['height'] > 96) && !empty($image['thumb']) && file_exists(dirname($image['file']).'/'.$image['thumb']) ) {
$src = str_replace(basename($image['guid']), $image['thumb'], $image['guid']);
$script .= "srca[{$ID}] = '$src';
srcb[{$ID}] = '{$image['guid']}';
";
$thumb = 'true';
$thumbtext = $__using_thumbnail;
} else {
$src = $image['guid'];
$thumb = 'false';
$thumbtext = $__no_thumbnail;
}
list($image['uwidth'], $image['uheight']) = get_udims($image['width'], $image['height']);
$height_width = 'height="'.$image['uheight'].'" width="'.$image['uwidth'].'"';
$xpadding = (128 - $image['uwidth']) / 2;
$ypadding = (96 - $image['uheight']) / 2;
$style .= "#target{$ID} img { padding: {$ypadding}px {$xpadding}px; }\n";
$title = wp_specialchars($image['post_title'], ENT_QUOTES);
$script .= "aa[{$ID}] = '<a id=\"p{$ID}\" rel=\"attachment\" class=\"imagelink\" href=\"$href\" onclick=\"doPopup({$ID});return false;\" title=\"{$title}\">';
ab[{$ID}] = '<a class=\"imagelink\" href=\"{$image['guid']}\" onclick=\"doPopup({$ID});return false;\" title=\"{$title}\">';
imga[{$ID}] = '<img id=\"image{$ID}\" src=\"$src\" alt=\"{$title}\" $height_width />';
imgb[{$ID}] = '<img id=\"image{$ID}\" src=\"{$image['guid']}\" alt=\"{$title}\" $height_width />';
";
$html .= "<div id='target{$ID}' class='attwrap left'>
<div id='div{$ID}' class='imagewrap' onclick=\"doPopup({$ID});\">
<img id=\"image{$ID}\" src=\"$src\" alt=\"{$title}\" $height_width />
</div>
{$noscript}
</div>
";
$popups .= "<div id='popup{$ID}' class='popup'>
<a id=\"I{$ID}\" onclick=\"if($thumb)toggleImage({$ID});else alert('$__nothumb');return false;\" href=\"javascript:void()\">$thumbtext</a>
<a id=\"L{$ID}\" onclick=\"toggleLink({$ID});return false;\" href=\"javascript:void()\">$__not_linked</a>
{$send_delete_cancel}
</div>
";
} else {
$title = wp_specialchars($attachment['post_title'], ENT_QUOTES);
$filename = basename($attachment['guid']);
$icon = get_attachment_icon($ID);
$toggle_icon = "<a id=\"I{$ID}\" onclick=\"toggleOtherIcon({$ID});return false;\" href=\"javascript:void()\">$__using_title</a>";
$script .= "aa[{$ID}] = '<a id=\"p{$ID}\" rel=\"attachment\" href=\"$href\" onclick=\"doPopup({$ID});return false;\" title=\"{$title}\">';
ab[{$ID}] = '<a id=\"p{$ID}\" href=\"{$filename}\" onclick=\"doPopup({$ID});return false;\" title=\"{$title}\">';
title[{$ID}] = '{$title}';
filename[{$ID}] = '{$filename}';
icon[{$ID}] = '{$icon}';
";
$html .= "<div id='target{$ID}' class='attwrap left'>
<div id='div{$ID}' class='otherwrap usingtext' onmousedown=\"selectLink({$ID})\" onclick=\"doPopup({$ID});return false;\">
<a id=\"p{$ID}\" href=\"{$attachment['guid']}\" onmousedown=\"selectLink({$ID});\" onclick=\"return false;\">{$title}</a>
</div>
{$noscript}
</div>
";
$popups .= "<div id='popup{$ID}' class='popup'>
<div class='filetype'>".__('File Type:').' '.str_replace('/',"/\n",$attachment['post_mime_type'])."</div>
<a id=\"L{$ID}\" onclick=\"toggleOtherLink({$ID});return false;\" href=\"javascript:void()\">$__linked_to_file</a>
{$toggle_icon}
{$send_delete_cancel}
</div>
";
}
}
}
$images_width = $uwidth_sum + ( count($images) * 6 ) + 35;
break;
default:
wp_die(__('This script was not meant to be called directly.'));
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
<head>
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
<title></title>
<meta http-equiv="imagetoolbar" content="no" />
<script type="text/javascript">
// <![CDATA[
/* Define any variables we'll need, such as alternate URLs. */
<?php echo $script; ?>
function htmldecode(st) {
o = document.getElementById('htmldecode');
if (! o) {
o = document.createElement("A");
o.id = "htmldecode"
}
o.innerHTML = st;
r = o.innerHTML;
return r;
}
function cancelUpload() {
o = document.getElementById('uploadForm');
o.method = 'GET';
o.action.value = 'view';
o.submit();
}
function doPopup(i) {
if ( popup )
popup.style.display = 'none';
target = document.getElementById('target'+i);
popup = document.getElementById('popup'+i);
popup.style.left = (target.offsetLeft) + 'px';
popup.style.top = (target.offsetTop) + 'px';
popup.style.display = 'block';
}
popup = false;
function selectLink(n) {
o=document.getElementById('div'+n);
if ( typeof document.body.createTextRange == 'undefined' || typeof win.tinyMCE == 'undefined' || win.tinyMCE.configs.length < 1 )
return;
r = document.body.createTextRange();
if ( typeof r != 'undefined' ) {
r.moveToElementText(o);
r.select();
}
}
function toggleLink(n) {
ol=document.getElementById('L'+n);
if ( ol.innerHTML == htmldecode(notlinked) ) {
ol.innerHTML = linkedtoimage;
} else if ( ol.innerHTML == htmldecode(linkedtoimage) ) {
ol.innerHTML = linkedtopage;
} else {
ol.innerHTML = notlinked;
}
updateImage(n);
}
function toggleOtherLink(n) {
ol=document.getElementById('L'+n);
if ( ol.innerHTML == htmldecode(linkedtofile) ) {
ol.innerHTML = linkedtopage;
} else {
ol.innerHTML = linkedtofile;
}
updateOtherIcon(n);
}
function toggleImage(n) {
oi = document.getElementById('I'+n);
if ( oi.innerHTML == htmldecode(usingthumbnail) ) {
oi.innerHTML = usingoriginal;
} else {
oi.innerHTML = usingthumbnail;
}
updateImage(n);
}
function toggleOtherIcon(n) {
od = document.getElementById('div'+n);
oi = document.getElementById('I'+n);
if ( oi.innerHTML == htmldecode(usingtitle) ) {
oi.innerHTML = usingfilename;
od.className = 'otherwrap usingtext';
} else if ( oi.innerHTML == htmldecode(usingfilename) && icon[n] != '' ) {
oi.innerHTML = usingicon;
od.className = 'otherwrap usingicon';
} else {
oi.innerHTML = usingtitle;
od.className = 'otherwrap usingtext';
}
updateOtherIcon(n);
}
function updateImage(n) {
od=document.getElementById('div'+n);
ol=document.getElementById('L'+n);
oi=document.getElementById('I'+n);
if ( oi.innerHTML == htmldecode(usingthumbnail) ) {
img = imga[n];
} else {
img = imgb[n];
}
if ( ol.innerHTML == htmldecode(linkedtoimage) ) {
od.innerHTML = ab[n]+img+'</a>';
} else if ( ol.innerHTML == htmldecode(linkedtopage) ) {
od.innerHTML = aa[n]+img+'</a>';
} else {
od.innerHTML = img;
}
}
function updateOtherIcon(n) {
od=document.getElementById('div'+n);
ol=document.getElementById('L'+n);
oi=document.getElementById('I'+n);
if ( oi.innerHTML == htmldecode(usingfilename) ) {
txt = filename[n];
} else if ( oi.innerHTML == htmldecode(usingicon) ) {
txt = icon[n];
} else {
txt = title[n];
}
if ( ol.innerHTML == htmldecode(linkedtofile) ) {
od.innerHTML = ab[n]+txt+'</a>';
} else if ( ol.innerHTML == htmldecode(linkedtopage) ) {
od.innerHTML = aa[n]+txt+'</a>';
} else {
od.innerHTML = txt;
}
}
var win = window.opener ? window.opener : window.dialogArguments;
if (!win) win = top;
tinyMCE = win.tinyMCE;
function sendToEditor(n) {
o = document.getElementById('div'+n);
h = o.innerHTML.replace(new RegExp('^\\s*(.*?)\\s*$', ''), '$1'); // Trim
h = h.replace(new RegExp(' (class|title|width|height|id|onclick|onmousedown)=([^\'"][^ ]*)( |/|>)', 'g'), ' $1="$2"$3'); // Enclose attribs in quotes
h = h.replace(new RegExp(' (width|height)=".*?"', 'g'), ''); // Drop size constraints
h = h.replace(new RegExp(' on(click|mousedown)="[^"]*"', 'g'), ''); // Drop menu events
h = h.replace(new RegExp('<(/?)A', 'g'), '<$1a'); // Lowercase tagnames
h = h.replace(new RegExp('<IMG', 'g'), '<img'); // Lowercase again
h = h.replace(new RegExp('(<img .+?")>', 'g'), '$1 />'); // XHTML
if ( typeof tinyMCE != 'undefined' && tinyMCE.getInstanceById('content') )
win.tinyMCE.execCommand('mceInsertContent', false, h);
else
win.edInsertContent(win.edCanvas, h);
}
// ]]>
</script>
<style type="text/css">
<?php if ( $action == 'links' ) : ?>
* html { overflow-x: hidden; }
<?php else : ?>
* html { overflow-y: hidden; }
<?php endif; ?>
body {
font: 13px "Lucida Grande", "Lucida Sans Unicode", Tahoma, Verdana;
border: none;
margin: 0px;
height: 150px;
background: #dfe8f1;
}
form { margin: 3px 2px 0px 6px; }
#wrap {
clear: both;
padding: 0px;
width: 100%;
}
#images {
position: absolute;
clear: both;
margin: 0px;
padding: 15px 15px;
width: <?php echo $images_width; ?>px;
}
#images img { background-color: rgb(209, 226, 239); }
<?php echo $style; ?>
.attwrap, .attwrap * {
margin: 0px;
padding: 0px;
border: 0px;
}
.imagewrap {
margin-right: 5px;
overflow: hidden;
width: 128px;
}
.otherwrap {
margin-right: 5px;
overflow: hidden;
background-color: #f9fcfe;
}
.otherwrap a { display: block; }
.otherwrap a, .otherwrap a:hover, .otherwrap a:active, .otherwrap a:visited { color: blue; }
.usingicon {
padding: 0px;
height: 96px;
text-align: center;
width: 128px;
}
.usingtext {
padding: 3px;
height: 90px;
text-align: left;
width: 122px;
}
.filetype {
font-size: 80%;
border-bottom: 3px double #89a;
}
.imagewrap, .imagewrap img, .imagewrap a, .imagewrap a img, .imagewrap a:hover img, .imagewrap a:visited img, .imagewrap a:active img { text-decoration: none; }
#upload-menu {
background: #fff;
margin: 0px;
padding: 0;
list-style: none;
height: 2em;
border-bottom: 1px solid #448abd;
width: 100%;
}
#upload-menu li {
float: left;
margin: 0 0 0 .75em;
}
#upload-menu a {
display: block;
padding: 5px;
text-decoration: none;
color: #000;
border-top: 3px solid #fff;
}
#upload-menu .current a {
background: #dfe8f1;
border-right: 2px solid #448abd;
}
#upload-menu a:hover {
background: #dfe8f1;
color: #000;
}
.tip {
color: rgb(68, 138, 189);
padding: 2px 1em;
}
.inactive {
color: #fff;
padding: 1px 3px;
}
.left { float: left; }
.right { float: right; }
.center { text-align: center; }
#upload-menu li.spacer { margin-left: 40px; }
#title, #descr {
width: 99%;
margin-top: 1px;
}
th {
text-align: right;
width: 4.5em;
}
#descr { height: 36px; }
#buttons {
margin-top: 2px;
text-align: right;
}
.popup {
margin: 4px 4px;
padding: 1px;
position: absolute;
width: 114px;
display: none;
background-color: rgb(240, 240, 238);
border-top: 2px solid #fff;
border-right: 2px solid #ddd;
border-bottom: 2px solid #ddd;
border-left: 2px solid #fff;
text-align: center;
}
.imagewrap .popup {
opacity: .90;
filter:alpha(opacity=90);
}
.otherwrap .popup { padding-top: 20px; }
.popup a, .popup a:visited, .popup a:active {
background-color: transparent;
display: block;
width: 100%;
text-decoration: none;
color: #246;
}
.popup a:hover {
background-color: #fff;
color: #000;
}
.caption { text-align: center; }
#submit {
margin: 1px;
width: 99%;
}
#submit input, #submit input:focus {
background: url( images/fade-butt.png );
border: 3px double #999;
border-left-color: #ccc;
border-top-color: #ccc;
color: #333;
padding: 0.25em;
}
#submit input:active {
background: #f4f4f4;
border: 3px double #ccc;
border-left-color: #999;
border-top-color: #999;
}
.zerosize {
width: 0px;
height: 0px;
overflow: hidden;
position: absolute;
}
#links {
margin: 3px 8px;
line-height: 2em;
}
#links textarea {
width: 95%;
height: 4.5em;
}
</style>
<?php if ( ('rtl' == $wp_locale->text_direction) ): ?>
<style type="text/css">
body { font: 13px Tahoma, "Lucida Grande", "Lucida Sans Unicode", Verdana; }
.usingtext { text-align: right; }
th { text-align: left; }
.left, #upload-menu li { float: right; }
.right { float: left; }
.popup {
border-right: 2px solid #fff;
border-left: 2px solid #ddd;
}
#upload-menu .current a {
border-right: 0;
border-left: 2px solid #448abd;
}
#submit input, #submit input:focus {
border-left: 0;
border-right-color: #ccc;
}
#submit input:active {
border-left: 0;
border-right-color: #999;
}
</style>
<?php endif; ?>
</head>
<body>
<ul id="upload-menu">
<li<?php echo $current_1; ?>><a href="<?php echo basename(__FILE__) . "?action=upload&amp;post=$post&amp;all=$all&amp;start=$start"; ?>"><?php _e('Upload'); ?></a></li>
<?php if ( $attachments = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_parent = '$post'") ): ?>
<li<?php echo $current_2; ?>><a href="<?php echo basename(__FILE__) . "?action=view&amp;post=$post&amp;all=false"; ?>"><?php _e('Browse'); ?></a></li>
<?php endif; ?>
<?php if ($wpdb->get_var("SELECT count(ID) FROM $wpdb->posts WHERE post_type = 'attachment'")): ?>
<li<?php echo $current_3; ?>><a href="<?php echo basename(__FILE__) . "?action=view&amp;post=$post&amp;all=true"; ?>"><?php _e('Browse All'); ?></a></li>
<?php endif; ?>
<li> </li>
<?php if ( $action == 'view' ): ?>
<?php if ( false !== $back ): ?>
<li class="spacer"><a href="<?php echo basename(__FILE__) . "?action=$action&amp;post=$post&amp;all=$all&amp;start=0"; ?>" title="<?php _e('First'); ?>">|&laquo;</a></li>
<li><a href="<?php echo basename(__FILE__) . "?action=$action&amp;post=$post&amp;all=$all&amp;start=$back"; ?>">&laquo; <?php _e('Back'); ?></a></li>
<?php else: ?>
<li class="inactive spacer">|&laquo;</li>
<li class="inactive">&laquo; <?php _e('Back'); ?></li>
<?php endif; ?>
<?php if ( false !== $next ): ?>
<li><a href="<?php echo basename(__FILE__) . "?action=$action&amp;post=$post&amp;all=$all&amp;start=$next"; ?>"><?php _e('Next &raquo;'); ?></a></li>
<li><a href="<?php echo basename(__FILE__) . "?action=$action&amp;post=$post&amp;all=$all&amp;last=true"; ?>" title="<?php _e('Last'); ?>">&raquo;|</a></li>
<?php else: ?>
<li class="inactive"><?php _e('Next &raquo;'); ?></li>
<li class="inactive">&raquo;|</li>
<?php endif; ?>
<?php endif; ?>
</ul>
<?php if ( $action == 'view' ): ?>
<div id="wrap">
<!--<div class="tip"><?php _e('You can drag and drop these items into your post. Click on one for more options.'); ?></div>-->
<div id="images">
<?php echo $html; ?>
<?php echo $popups; ?>
</div>
</div>
<?php elseif ( $action == 'upload' ): ?>
<div class="tip"></div>
<form enctype="multipart/form-data" id="uploadForm" method="post" action="<?php echo basename(__FILE__); ?>">
<table style="width: 99%">
<tr>
<th scope="row"><label for="upload"><?php _e('File:'); ?></label></th>
<td><input type="file" id="upload" name="image" /></td>
</tr>
<tr>
<th scope="row"><label for="title"><?php _e('Title:'); ?></label></th>
<td><input type="text" id="title" name="imgtitle" /></td>
</tr>
<tr>
<th scope="row"><label for="descr"><?php _e('Description:'); ?></label></th>
<td><input type="textarea" name="descr" id="descr" value="" /></td>
</tr>
<tr id="buttons">
<th></th>
<td>
<input type="hidden" name="action" value="save" />
<input type="hidden" name="post" value="<?php echo $post; ?>" />
<input type="hidden" name="all" value="<?php echo $all; ?>" />
<input type="hidden" name="start" value="<?php echo $start; ?>" />
<?php wp_nonce_field( 'inlineuploading' ); ?>
<div id="submit">
<input type="submit" value="<?php _e('Upload'); ?>" />
<?php if ( !empty($all) ): ?>
<input type="button" value="<?php _e('Cancel'); ?>" onclick="cancelUpload()" />
<?php endif; ?>
</div>
</td>
</tr>
</table>
</form>
<?php elseif ( $action == 'links' ): ?>
<div id="links">
<?php the_attachment_links($attachment); ?>
</div>
<?php endif; ?>
</body>
</html>

View File

@ -30,6 +30,7 @@ $submenu['post-new.php'][10] = array(__('Write Page'), 'edit_pages', 'page-new.p
$submenu['edit.php'][5] = array(__('Posts'), 'edit_posts', 'edit.php');
$submenu['edit.php'][10] = array(__('Pages'), 'edit_pages', 'edit-pages.php');
$submenu['edit.php'][12] = array(__('Uploads'), 'upload_files', 'upload.php');
$submenu['edit.php'][15] = array(__('Categories'), 'manage_categories', 'categories.php');
$submenu['edit.php'][20] = array(__('Comments'), 'edit_posts', 'edit-comments.php');
$awaiting_mod = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'");
@ -124,6 +125,8 @@ foreach ( $menu as $id => $data ) {
}
}
unset($id);
ksort($menu); // make it all pretty
if (! user_can_access_admin_page()) {

View File

@ -0,0 +1,336 @@
<?php
function wp_upload_display( $dims = false, $href = '' ) {
global $post;
$id = get_the_ID();
$attachment_data = get_post_meta( $id, '_wp_attachment_metadata', true );
if ( isset($attachment_data['width']) )
list($width,$height) = wp_shrink_dimensions($attachment_data['width'], $attachment_data['height'], 171, 128);
ob_start();
the_title();
$post_title = wp_specialchars( ob_get_contents(), 1 );
ob_end_clean();
$post_content = apply_filters( 'content_edit_pre', $post->post_content );
$class = 'text';
$innerHTML = get_attachment_innerHTML( $id, false, $dims );
if ( $image_src = strstr($innerHTML, 'src="') ) {
$image_src = explode('"', $image_src);
$image_src = $image_src[1];
$class = 'image';
$innerHTML = '&nbsp;' . $innerHTML;
}
$r = '';
if ( $href )
$r .= "<a id='file-link-$id' href='$href' title='$post_title' class='file-link $class'>\n";
if ( $href || $image_src )
$r .= "\t\t\t$innerHTML";
if ( $href )
$r .= "</a>\n";
$r .= "\n\t\t<div class='upload-file-data'>\n\t\t\t<p>\n";
$r .= "\t\t\t\t<input type='hidden' name='attachment-url-$id' id='attachment-url-$id' value='" . get_the_guid() . "' />\n";
if ( $image_src )
$r .= "\t\t\t\t<input type='hidden' name='attachment-thumb-url-$id' id='attachment-thumb-url-$id' value='$image_src' />\n";
if ( isset($width) ) {
$r .= "\t\t\t\t<input type='hidden' name='attachment-width-$id' id='attachment-width-$id' value='$width' />\n";
$r .= "\t\t\t\t<input type='hidden' name='attachment-height-$id' id='attachment-height-$id' value='$height' />\n";
}
$r .= "\t\t\t\t<input type='hidden' name='attachment-page-url-$id' id='attachment-page-url-$id' value='" . get_attachment_link( $id ) . "' />\n";
$r .= "\t\t\t\t<input type='hidden' name='attachment-title-$id' id='attachment-title-$id' value='$post_title' />\n";
$r .= "\t\t\t\t<input type='hidden' name='attachment-description-$id' id='attachment-description-$id' value='$post_content' />\n";
$r .= "\t\t\t</p>\n\t\t</div>\n";
return $r;
}
function wp_upload_view() {
global $style, $post_id;
$id = get_the_ID();
?>
<div id="upload-file">
<div id="file-title">
<h2><a href="<?php the_guid(); ?>" title="Direct link to this file"><?php the_title(); ?></a></h2>
<span><?php
echo '[&nbsp;';
echo '<a href="' . get_permalink() . '" title="' . ('Permalink to the blog page for this file') . '">' . __('page link') . '</a>';
echo '&nbsp;|&nbsp;';
echo '<a href="' . wp_specialchars( add_query_arg( 'action', 'edit' ), 1 ) . '" title="' . __('Edit this file') . '">' . __('edit') . '</a>';
echo '&nbsp;|&nbsp;';
echo '<a href="' . wp_specialchars( remove_query_arg( array('action', 'ID') ), 1 ) . '" title="' . __('Browse your files') . '">' . __('cancel') . '</a>';
echo '&nbsp;]'; ?></span>
</div>
<div id="upload-file-view" class="left">
<?php echo wp_upload_display( array(171, 128) ); ?>
</div>
<?php the_attachment_links( $id ); ?>
</div>
<?php
}
function wp_upload_form() {
$id = get_the_ID();
global $post_id, $tab, $style;
$enctype = $id ? '' : ' enctype="multipart/form-data"';
?>
<form<?php echo $enctype; ?> id="upload-file" method="post" action="<?php echo get_option('siteurl') . "/wp-admin/upload.php?style=$style&amp;tab=upload&amp;post_id=$post_id"; ?>">
<?php
if ( $id ) :
$attachment = get_post_to_edit( $id );
?>
<div id="file-title">
<h2><a href="<?php the_guid(); ?>" title="Direct link to this file"><?php the_title(); ?></a></h2>
<span><?php
echo '[&nbsp;';
echo '<a href="' . get_permalink() . '" title="' . ('Permalink to the blog page for this file') . '">' . __('page link') . '</a>';
echo '&nbsp;|&nbsp;';
echo '<a href="' . wp_specialchars( add_query_arg( 'action', 'view' ), 1 ) . '" title="' . __('View options for this file') . '">' . __('options') . '</a>';
echo '&nbsp;|&nbsp;';
echo '<a href="' . wp_specialchars( remove_query_arg( array('action','ID') ), 1 ) . '" title="' . __('Browse your files') . '">' . __('cancel') . '</a>';
echo '&nbsp;]'; ?></span>
</div>
<div id="upload-file-view" class="left">
<?php echo wp_upload_display( array(171, 128) ); ?>
</div>
<?php endif; ?>
<table>
<?php if ( !$id ): ?>
<tr>
<th scope="row"><label for="upload"><?php _e('File:'); ?></label></th>
<td><input type="file" id="upload" name="image" /></td>
</tr>
<?php endif; ?>
<tr>
<th scope="row"><label for="post_title"><?php _e('Title:'); ?></label></th>
<td><input type="text" id="post_title" name="post_title" value="<?php echo $attachment->post_title; ?>" /></td>
</tr>
<tr>
<th scope="row"><label for="post_content"><?php _e('Description:'); ?></label></th>
<td><textarea name="post_content" id="post_content"><?php echo $attachment->post_content; ?></textarea></td>
</tr>
<tr id="buttons">
<th></th>
<td>
<input type="hidden" name="from_tab" value="<?php echo $tab; ?>" />
<input type="hidden" name="action" value="<?php echo $id ? 'save' : 'upload'; ?>" />
<?php if ( $post_id ) : ?>
<input type="hidden" name="post_id" value="<?php echo $post_id; ?>" />
<?php endif; if ( $id ) : ?>
<input type="hidden" name="ID" value="<?php echo $id; ?>" />
<?php endif; ?>
<?php wp_nonce_field( 'inlineuploading' ); ?>
<div id="submit">
<input type="submit" value="<?php $id ? _e('Save') : _e('Upload'); ?>" />
<?php if ( $id ) : ?>
<input type="submit" name="delete" class="delete" value="<?php _e('Delete'); ?>" />
<?php endif; ?>
</div>
</td>
</tr>
</table>
</form>
<?php
}
function wp_upload_tab_upload() {
wp_upload_form();
}
function wp_upload_tab_upload_action() {
global $action;
if ( isset($_POST['delete']) )
$action = 'delete';
switch ( $action ) :
case 'upload' :
global $from_tab, $post_id, $style;
if ( !$from_tab )
$from_tab = 'upload';
check_admin_referer( 'inlineuploading' );
global $post_id, $post_title, $post_content;
if ( !current_user_can( 'upload_files' ) )
wp_die( __('You are not allowed to upload files.')
. " <a href='" . get_option('siteurl') . "/wp-admin/upload.php?style=$style&amp;tab=browse-all&amp;post_id=$post_id'>"
. __('Browse Files') . '</a>'
);
$overrides = array('action'=>'upload');
$file = wp_handle_upload($_FILES['image'], $overrides);
if ( isset($file['error']) )
wp_die($file['error'] . "<br /><a href='" . get_option('siteurl')
. "/wp-admin/upload.php?style=$style&amp;tab=$from_tab&amp;post_id=$post_id'>'" . __('Back to Image Uploading') . '</a>'
);
$url = $file['url'];
$type = $file['type'];
$file = $file['file'];
$filename = basename($file);
// Construct the attachment array
$attachment = array(
'post_title' => $post_title ? $post_title : $filename,
'post_content' => $post_content,
'post_type' => 'attachment',
'post_parent' => $post_id,
'post_mime_type' => $type,
'guid' => $url
);
// Save the data
$id = wp_insert_attachment($attachment, $file, $post_id);
if ( preg_match('!^image/!', $attachment['post_mime_type']) ) {
// Generate the attachment's postmeta.
$imagesize = getimagesize($file);
$imagedata['width'] = $imagesize['0'];
$imagedata['height'] = $imagesize['1'];
list($uwidth, $uheight) = get_udims($imagedata['width'], $imagedata['height']);
$imagedata['hwstring_small'] = "height='$uheight' width='$uwidth'";
$imagedata['file'] = $file;
add_post_meta($id, '_wp_attachment_metadata', $imagedata);
if ( $imagedata['width'] * $imagedata['height'] < 3 * 1024 * 1024 ) {
if ( $imagedata['width'] > 128 && $imagedata['width'] >= $imagedata['height'] * 4 / 3 )
$thumb = wp_create_thumbnail($file, 128);
elseif ( $imagedata['height'] > 96 )
$thumb = wp_create_thumbnail($file, 96);
if ( @file_exists($thumb) ) {
$newdata = $imagedata;
$newdata['thumb'] = basename($thumb);
update_post_meta($id, '_wp_attachment_metadata', $newdata, $imagedata);
} else {
$error = $thumb;
}
}
} else {
add_post_meta($id, '_wp_attachment_metadata', array());
}
wp_redirect( get_option('siteurl') . "/wp-admin/upload.php?style=$style&tab=browse&action=view&ID=$id&post_id=$post_id");
die;
break;
case 'save' :
global $from_tab, $post_id, $style;
if ( !$from_tab )
$from_tab = 'upload';
check_admin_referer( 'inlineuploading' );
wp_update_post($_POST);
wp_redirect( get_option('siteurl') . "/wp-admin/upload.php?style=$style&tab=$from_tab&post_id=$post_id");
die;
break;
case 'delete' :
global $ID, $post_id, $from_tab, $style;
if ( !$from_tab )
$from_tab = 'upload';
check_admin_referer( 'inlineuploading' );
if ( !current_user_can('edit_post', (int) $ID) )
wp_die( __('You are not allowed to delete this attachment.')
. " <a href='" . get_option('siteurl') . "/wp-admin/upload.php?style=$style&amp;tab=$from_tab&amp;post_id=$post_id'>"
. __('Go back') . '</a>'
);
wp_delete_attachment($ID);
wp_redirect( get_option('siteurl') . "/wp-admin/upload.php?style=$style&tab=$from_tab&post_id=$post_id" );
die;
break;
endswitch;
}
add_action( 'upload_files_upload', 'wp_upload_tab_upload_action' );
function wp_upload_grab_attachments( $obj ) {
$obj->is_attachment = true;
}
function wp_upload_posts_where( $where ) {
global $post_id;
return $where . " AND post_parent = '" . (int) $post_id . "'";
}
function wp_upload_tab_browse() {
global $wpdb, $action, $paged;
$old_vars = compact( 'paged' );
switch ( $action ) :
case 'edit' :
case 'view' :
global $ID;
$attachments = query_posts("attachment_id=$ID");
if ( have_posts() ) : while ( have_posts() ) : the_post();
'edit' == $action ? wp_upload_form() : wp_upload_view();
endwhile; endif;
break;
default :
global $tab, $post_id;
add_action( 'pre_get_posts', 'wp_upload_grab_attachments' );
if ( 'browse' == $tab && $post_id )
add_filter( 'posts_where', 'wp_upload_posts_where' );
$attachments = query_posts("what_to_show=posts&posts_per_page=10&paged=$paged");
$count_query = "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'attachment'";
if ( $post_id )
$count_query .= " AND post_parent = '$post_id'";
$total = $wpdb->get_var($count_query);
echo "<ul id='upload-files'>\n";
if ( have_posts() ) : while ( have_posts() ) : the_post();
$href = wp_specialchars( add_query_arg( array('action' => 'view', 'ID' => get_the_ID()) ), 1 );
echo "\t<li id='file-";
the_ID();
echo "' class='left'>\n";
echo wp_upload_display( array(128,128), $href );
echo "\t</li>\n";
endwhile;
else :
echo "\t<li>" . __('There are no attachments to show.') . "</li>\n";
endif;
echo "</ul>\n\n";
echo "<form action='' id='browse-form'><input type='hidden' id='nonce-value' value='" . wp_create_nonce( 'inlineuploading' ) . "' /></form>\n";
// echo $total;
break;
endswitch;
extract($old_vars);
}
function wp_upload_tab_browse_action() {
wp_enqueue_script('upload');
}
add_action( 'upload_files_browse', 'wp_upload_tab_browse_action' );
add_action( 'upload_files_browse-all', 'wp_upload_tab_browse_action' );
function wp_upload_admin_head() {
global $wp_locale;
echo "<link rel='stylesheet' href='" . get_option('siteurl') . '/wp-admin/upload.css?version=' . get_bloginfo('version') . "' type='text/css' />\n";
if ( 'rtl' == $wp_locale->text_direction )
echo "<link rel='stylesheet' href='" . get_option('siteurl') . '/wp-admin/upload-rtl.css?version=' . get_bloginfo('version') . "' type='text/css' />\n";
if ( 'inline' == @$_GET['style'] ) {
echo "<style type='text/css'>\n";
echo "\t#wphead, #user_info, #adminmenu, #submenu, #footer { display: none; }\n";
echo "\tbody { height: 14em; overflow: hidden; }\n";
echo "\t#upload-content { overflow-y: auto; }\n";
echo "\t#upload-file { position: absolute; }\n";
echo "</style>";
}
}

229
wp-admin/upload-js.php Normal file
View File

@ -0,0 +1,229 @@
<?php require_once('admin.php'); cache_javascript_headers(); ?>
addLoadEvent( function() {
theFileList = {
currentImage: {ID: 0},
nonce: '',
tab: '',
postID: 0,
initializeVars: function() {
this.urlData = document.location.href.split('?');
this.params = this.urlData[1].toQueryParams();
this.postID = this.params['post_id'];
this.tab = this.params['tab'];
this.style = this.params['style'];
this.ID = this.params['ID'];
if ( !this.style )
this.style = 'default';
var nonceEl = $('nonce-value');
if ( nonceEl )
this.nonce = nonceEl.value;
if ( this.ID ) {
this.grabImageData( this.ID );
this.imageView( this.ID );
}
},
initializeLinks: function() {
if ( this.ID )
return;
$$('a.file-link').each( function(i) {
var id = i.id.split('-').pop();
i.onclick = function(e) { theFileList.imageView(id, e); }
} );
},
grabImageData: function(id) {
if ( id == this.currentImage.ID )
return;
var thumbEl = $('attachment-thumb-url-' + id);
if ( thumbEl )
this.currentImage.thumb = ( 0 == id ? '' : thumbEl.value );
else
this.currentImage.thumb = false;
this.currentImage.src = ( 0 == id ? '' : $('attachment-url-' + id).value );
this.currentImage.page = ( 0 == id ? '' : $('attachment-page-url-' + id).value );
this.currentImage.title = ( 0 == id ? '' : $('attachment-title-' + id).value );
this.currentImage.description = ( 0 == id ? '' : $('attachment-description-' + id).value );
var widthEl = $('attachment-width-' + id);
if ( widthEl ) {
this.currentImage.width = ( 0 == id ? '' : widthEl.value );
this.currentImage.height = ( 0 == id ? '' : $('attachment-height-' + id).value );
} else {
this.currentImage.width = false;
this.currentImage.height = false;
}
this.currentImage.ID = id;
},
imageView: function(id, e) {
this.prepView(id);
var h = '';
h += "<div id='upload-file'>"
h += "<div id='file-title'>"
h += "<h2><a href='" + this.currentImage.src + "' title='Direct Link to this file'>" + this.currentImage.title + "</a></h2>";
h += "<span>[&nbsp";
h += "<a href='" + this.currentImage.page + "' title='Permalink to the blog page for this file'>page link</a>"
h += '&nbsp;|&nbsp;';
h += "<a href='#' onclick='theFileList.editView(" + id + ")' title='Edit this file'>edit</a>"
h += '&nbsp;|&nbsp;';
if ( this.ID ) {
var params = $H(this.params);
params.ID = '';
params.action = '';
h += "<a href='" + this.urlData[0] + '?' + params.toQueryString() + "' title='Browse your files'>cancel</a>";
} else {
h += "<a href='#' onclick='theFileList.cancelView()' title='Browse your files'>cancel</a>";
}
h += "&nbsp;]</span>";
h += '</div>'
h += "<div id='upload-file-view' class='left'>";
if ( this.currentImage.thumb )
h += "<img src='" + this.currentImage.thumb + "' alt='" + this.currentImage.title + "' width='" + this.currentImage.width + "' height='" + this.currentImage.height + "' />";
else
h += '&nbsp;';
h += "</div>";
h += "<form name='uploadoptions' id='uploadoptions' class='left'>";
if ( this.currentImage.thumb ) {
h += "<input type='radio' name='display' value='thumb' checked='checked'>Display thumbnail</input><br />";
h += "<input type='radio' name='display' value='full'>Display full-sized image</input><br /><br />";
}
if ( this.currentImage.thumb ) {
h += "<input type='radio' name='link' value='none' checked='checked'>Do not link to this file</input><br />";
h += "<input type='radio' name='link' value='file'>Link directly to this file</input><br />";
h += "<input type='radio' name='link' value='page'>Link to this file's blog page</input><br />";
} else {
h += "<input type='radio' name='link' value='file'>Link directly to this file</input><br />";
h += "<input type='radio' name='link' value='page' checked='checked'>Link to this file's blog page</input><br />";
}
h += "<input type='button' name='send' onclick='theFileList.sendToEditor(" + id + ")' value='Send to editor' />";
h += "</form>";
h += "</div>";
new Insertion.Top('upload-content', h);
if (e) Event.stop(e);
return false;
},
editView: function(id, e) {
this.prepView(id);
var h = '';
h += "<form id='upload-file' method='post' action='upload.php?style=inline&amp;tab=upload&amp;post_id=" + this.postID + "'>";
h += "<div id='file-title'>"
h += "<h2><a href='" + this.currentImage.src + "' title='Direct Link to this file'>" + this.currentImage.title + "</a></h2>";
h += "<span>[&nbsp";
h += "<a href='" + this.currentImage.page + "' title='Permalink to the blog page for this file'>page link</a>"
h += '&nbsp;|&nbsp;';
h += "<a href='#' onclick='theFileList.imageView(" + id + ")' title='View options for this file'>options</a>"
h += '&nbsp;|&nbsp;';
if ( this.ID ) {
var params = $H(this.params);
params.ID = '';
params.action = '';
h += "<a href='" + this.urlData[0] + '?' + params.toQueryString() + "' title='Browse your files'>cancel</a>";
} else {
h += "<a href='#' onclick='theFileList.cancelView()' title='Browse your files'>cancel</a>";
}
h += "&nbsp;]</span>";
h += '</div>'
h += "<div id='upload-file-view' class='left'>";
if ( this.currentImage.thumb )
h += "<img src='" + this.currentImage.thumb + "' alt='" + this.currentImage.title + "' width='" + this.currentImage.width + "' height='" + this.currentImage.height + "' />";
else
h += '&nbsp;';
h += "</div>";
h += "<table><tr>"
h += "<th scope='row'><label for='post_title'>Title:</label></th>";
h += "<td><input type='text' id='post_title' name='post_title' value='" + this.currentImage.title + "' /></td>";
h += "</tr><tr>";
h += "<th scope='row'><label for='post_content'>Description:</label></th>";
h += "<td><textarea name='post_content' id='post_content'>" + this.currentImage.description + "</textarea></td>";
h += "</tr><tr id='buttons'><th></th><td>";
h += "<input type='hidden' name='from_tab' value='" + this.tab + "' />";
h += "<input type='hidden' name='action' id='action-value' value='save' />";
h += "<input type='hidden' name='ID' value='" + id + "' />";
h += "<input type='hidden' name='_wpnonce' value='" + this.nonce + "' />";
h += "<div id='submit'><input type='submit' value='Save' />";
h += "<input type='button' name='delete' class='delete' value='Delete' onclick='theFileList.deleteFile(" + id + ");' />";
h += "</div></td></tr></table></form>";
new Insertion.Top('upload-content', h);
if (e) Event.stop(e);
return false;
},
prepView: function(id) {
this.cancelView( true );
var filesEl = $('upload-files');
if ( filesEl )
filesEl.hide();
this.grabImageData(id);
},
cancelView: function( prep ) {
if ( !prep ) {
var filesEl = $('upload-files');
if ( filesEl )
filesEl.show();
}
if ( !this.ID )
this.grabImageData(0);
var div = $('upload-file');
if ( div )
div.remove();
return false;
},
sendToEditor: function(id) {
this.grabImageData(id);
var link = '';
var display = '';
var h = '';
link = $A(document.forms.uploadoptions.elements.link).detect( function(i) { return i.checked; } ).value;
displayEl = $A(document.forms.uploadoptions.elements.display).detect( function(i) { return i.checked; } )
if ( displayEl )
display = displayEl.value;
if ( 'none' != link )
h += "<a href='" + ( 'file' == link ? this.currentImage.src : this.currentImage.page ) + "' title='" + this.currentImage.title + "'>";
if ( display )
h += "<img src='" + ( 'thumb' == display ? this.currentImage.thumb : this.currentImage.src ) + "' alt='" + this.currentImage.title + "' />";
else
h += this.currentImage.title;
if ( 'none' != link )
h += "</a>";
var win = window.opener ? window.opener : window.dialogArguments;
if ( !win )
win = top;
tinyMCE = win.tinyMCE;
if ( typeof tinyMCE != 'undefined' && tinyMCE.getInstanceById('content') )
win.tinyMCE.execCommand('mceInsertContent', false, h);
else
win.edInsertContent(win.edCanvas, h);
this.cancelView();
return false;
},
deleteFile: function(id) {
if ( confirm("Are you sure you want to delete the file '" + this.currentImage.title + "'?\nClick ok to delete or cancel to go back.") ) {
$('action-value').value = 'delete';
$('upload-file').submit();
return true;
}
return false;
}
};
theFileList.initializeVars();
theFileList.initializeLinks();
} );

30
wp-admin/upload-rtl.css Normal file
View File

@ -0,0 +1,30 @@
body { font: 13px Tahoma, "Lucida Grande", "Lucida Sans Unicode", Verdana; }
#upload-menu li { margin: 0 .75em 0 0; }
#upload-menu .current a {
border-right: 0;
border-left: 2px solid #448abd;
}
#file-title { margin: 0 15px 0 0; }
h2 { margin: 0 0 0 .2em; }
#upload-files li { margin: 0 15px 15px 0; }
th { text-align: right; }
.left, table { float: right; }
.right, #the-attachment-links { float: left; }
#submit input, #submit input:focus {
border-left: 0;
border-right-color: #ccc;
}
#submit input:active {
border-left: 0;
border-right-color: #999;
}

159
wp-admin/upload.css Normal file
View File

@ -0,0 +1,159 @@
body { background: #dfe8f1; }
.upload-file-data { display: none; }
#upload-menu {
background: #fff;
margin: 0px;
padding: 0;
list-style: none;
height: 2em;
border-bottom: 1px solid #448abd;
width: 100%;
}
#upload-menu li { margin: 0 0 0 .75em; }
#upload-menu a {
display: block;
padding: 5px;
color: #000;
border-top: 3px solid #fff;
text-decoration: none;
border-bottom: none;
}
#upload-menu .current a {
background: #dfe8f1;
border-right: 2px solid #448abd;
}
#upload-menu a:hover {
background: #dfe8f1;
color: #000;
}
#upload-content {
position: relative;
clear: both;
margin: 0;
padding: 0;
border: none;
width: 100%;
height: 100%;
background: none;
}
#upload-file {
position: relative;
margin: 0;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #dfe8f1;
}
#upload-file-view { padding: 0 15px; }
#file-title {
margin: 0 0 0 15px;
padding: 0;
display: block;
}
h2 {
margin: 0 .2em 0 0;
padding: 0;
display: inline;
border: none;
font-weight: bold;
font-size: 1.4em;
line-height: 1.4em;
}
#upload-files {
list-style-type: none;
margin: 0;
padding: 15px 0 0;
}
#upload-files li { margin: 0 0 15px 15px; }
#upload-files a, a.file-link {
border: none;
text-decoration: none;
}
#upload-files a.file-link {
display: block;
width: 130px;
height: 128px;
background-color: rgb(209, 226, 239);
text-align: center;
overflow-y: hidden;
}
#upload-files a.file-link.image {
line-height: 128px;
font-size: 2px;
letter-spacing: 0;
}
#upload-files a.file-link img {
vertical-align: middle;
}
#the-attachment-links { float: right; }
#the-attachment-links textarea {
font-size: 10px;
overflow: hidden;
}
form table { float: none; }
table {
float: left;
margin: 0;
padding: 0 15px;
}
.left { float: left; }
.right { float: right; }
.center { text-align: center; }
th { text-align: left; }
tr, td, th {
margin-top: 0;
padding-top: 0;
}
#submit {
margin: 1px;
width: 99%;
}
#submit input, #submit input:focus {
background: url( images/fade-butt.png );
border: 3px double #999;
border-left-color: #ccc;
border-top-color: #ccc;
color: #333;
padding: 0.25em;
}
#submit input:active {
background: #f4f4f4;
border: 3px double #ccc;
border-left-color: #999;
border-top-color: #999;
}
#submit input.delete:hover {
background: #ce0000;
color: #fff;
}

74
wp-admin/upload.php Normal file
View File

@ -0,0 +1,74 @@
<?php
require_once('admin.php');
@header('Content-type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
if (!current_user_can('upload_files'))
wp_die(__('You do not have permission to upload files.'));
wp_reset_vars(array('action', 'tab', 'from_tab', 'style', 'post_id', 'ID', 'paged', 'post_title', 'post_content', 'delete'));
require_once('upload-functions.php');
if ( !$tab )
$tab = 'browse-all';
do_action( "upload_files_$tab" );
add_action( 'admin_head', 'wp_upload_admin_head' );
$pid = 0;
if ( $post_id < 0 )
$pid = $post_id;
elseif ( get_post( $post_id ) )
$pid = $post_id;
$wp_upload_tabs = array();
$all_atts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'attachment'");
$post_atts = 0;
if ( $pid ) {
$wp_upload_tabs['upload'] = array(__('Upload'), 'upload_files', 'wp_upload_tab_upload');
if ( $all_atts && $post_atts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = '$post_id'") )
$wp_upload_tabs['browse'] = array(__('Browse'), 'upload_files', "wp_upload_tab_browse");
if ( $post_atts < $all_atts )
$wp_upload_tabs['browse-all'] = array(__('Browse All'), 'upload_files', 'wp_upload_tab_browse');
} else
$wp_upload_tabs['browse-all'] = array(__('Browse All'), 'upload_files', 'wp_upload_tab_browse');
$wp_upload_tabs = array_merge($wp_upload_tabs, apply_filters( 'wp_upload_tabs', array() ));
if ( !function_exists($wp_upload_tabs[$tab][2]) ) {
$to_tab = isset($wp_upload_tabs['upload']) ? 'upload' : 'browse-all';
wp_redirect( add_query_arg( 'tab', $to_tab ) );
exit;
}
foreach ( $wp_upload_tabs as $t => $tab_array ) {
if ( !current_user_can( $tab_array[1] ) ) {
unset($wp_upload_tabs[$t]);
if ( $tab == $t )
wp_die(__("You are not allowed to be here"));
}
}
include_once('admin-header.php');
echo "<ul id='upload-menu'>\n";
foreach ( $wp_upload_tabs as $t => $tab_array ) { // We've already done the current_user_can check
$class = 'upload-tab';
$href = add_query_arg( array('tab' => $t, 'ID' => '', 'action' => '') );
if ( isset($tab_array[3]) && is_array($tab_array[3]) )
add_query_arg( $tab_array[3], $href );
$_href = wp_specialchars( $href, 1 );
if ( $tab == $t )
$class .= ' current';
echo "\t<li class='$class left'><a href='$_href' title='{$tab_array[0]}'>{$tab_array[0]}</a></li>\n";
}
echo "</ul>\n\n";
echo "<div id='upload-content'>\n";
call_user_func( $wp_upload_tabs[$tab][2] );
echo "</div>\n";
include_once('admin-footer.php');
?>

View File

@ -186,7 +186,7 @@ textarea, input, select {
border-style: none;
padding: 0px;
margin-bottom: 16px;
height: 15em;
height: 16em;
width: 100%;
/* overflow-y: hidden;*/
}

View File

@ -29,6 +29,7 @@ class WP_Scripts {
$this->add( 'admin-comments', '/wp-admin/edit-comments.js', array('listman'), '3847' );
$this->add( 'admin-users', '/wp-admin/users.js', array('listman'), '3684' );
$this->add( 'xfn', '/wp-admin/xfn.js', false, '3517' );
$this->add( 'upload', '/wp-admin/upload-js.php', array('prototype'), mt_rand() );
}
}