Attachment enhancements from skeltoac. fixes #2074

git-svn-id: http://svn.automattic.com/wordpress/trunk@3303 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2005-12-13 19:19:56 +00:00
parent 9a11319958
commit ab9b8f8b6a
14 changed files with 425 additions and 127 deletions

View File

@ -742,11 +742,13 @@ function wp_create_thumbnail($file, $max_side, $effect = '') {
$thumbnail = imagecreatetruecolor($image_new_width, $image_new_height);
@ imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1]);
// If no filters change the filename, we'll do a default transformation.
if ( basename($file) == $thumb = apply_filters('thumbnail_filename', basename($file)) )
$thumb = preg_replace('!(\.[^.]+)?$!', __('.thumbnail').'$1', basename($file), 1);
$thumbpath = str_replace(basename($file), $thumb, $file);
// move the thumbnail to it's final destination
$path = explode('/', $file);
$thumbpath = substr($file, 0, strrpos($file, '/')).'/thumb-'.$path[count($path) - 1];
if ($type[2] == 1) {
if (!imagegif($thumbnail, $thumbpath)) {
$error = __("Thumbnail path invalid");
@ -771,7 +773,7 @@ function wp_create_thumbnail($file, $max_side, $effect = '') {
if (!empty ($error)) {
return $error;
} else {
return 1;
return $thumbpath;
}
}
@ -1633,8 +1635,10 @@ function current_theme_info() {
// On failure, returns $overrides['upload_error_handler'](&$file, $message) or array('error'=>$message).
function wp_handle_upload(&$file, $overrides = false) {
// The default error handler.
function wp_handle_upload_error(&$file, $message) {
return array('error'=>$message);
if (! function_exists('wp_handle_upload_error') ) {
function wp_handle_upload_error(&$file, $message) {
return array('error'=>$message);
}
}
// You may define your own function and pass the name in $overrides['upload_error_handler']
@ -1653,47 +1657,49 @@ function wp_handle_upload(&$file, $overrides = false) {
__("Failed to write file to disk."));
// Accepted MIME types are set here as PCRE. Override with $override['mimes'].
$mimes = apply_filters('upload_mimes', array(
'image/jpeg' => 'jpg|jpeg|jpe',
'image/gif' => 'gif',
'image/(png|x-png)' => 'png',
'image/(bmp|x-bmp|x-ms-bmp)' => 'bmp',
'image/(tiff|x-tiff)' => 'tif|tiff',
'image/(ico|x-ico)' => 'ico',
'video/(asf|x-asf|x-ms-asf)' => 'asf|asx|wma|wax|wmv|wmx',
'video/(wmv|x-wmv|x-ms-wmv)' => 'wmv',
'video/(msvideo|x-msvideo)' => 'avi',
'video/(quicktime|x-quicktime)' => 'mov|qt',
'video/(mpeg|x-mpeg)' => 'mpeg|mpg|mpe',
'text/plain' => 'txt|c|cc|h|php',
'text/richtext' => 'rtx',
'text/css' => 'css',
'text/html' => 'htm|html',
'text/javascript' => 'js',
'audio/(mpeg|x-mpeg|mpeg3|x-mpeg3)' => 'mp3',
'audio/x-realaudio' => 'ra|ram',
'audio/(wav|x-wav)' => 'wav',
'audio/(ogg|x-ogg)' => 'ogg',
'audio/(midi|x-midi)' => 'mid|midi',
'application/pdf' => 'pdf',
'application/msword' => 'doc',
'application/mspowerpoint' => 'pot|pps|ppt',
'application/mswrite' => 'wri',
'application/(msexcel|vnd.ms-excel)' => 'xla|xls|xlt|xlw',
'application/msaccess' => 'mdb',
'application/msproject' => 'mpp',
'application/x-shockwave-flash' => 'swf',
'application/java' => 'class',
'application/x-tar' => 'tar',
'application/(zip|x-zip-compressed)' => 'zip',
'application/(x-gzip|x-gzip-compressed)' => 'gz|gzip'));
// For security, we never trust HTTP Content-Type headers unless the user overrides this.
$trust_content_type = false;
$mimes = apply_filters('upload_mimes', array (
'jpg|jpeg|jpe' => 'image/jpeg',
'gif' => 'image/gif',
'png' => 'image/png',
'bmp' => 'image/bmp',
'tif|tiff' => 'image/tiff',
'ico' => 'image/x-icon',
'asf|asx|wax|wmv|wmx' => 'video/asf',
'avi' => 'video/avi',
'mov|qt' => 'video/quicktime',
'mpeg|mpg|mpe' => 'video/mpeg',
'txt|c|cc|h|php' => 'text/plain',
'rtx' => 'text/richtext',
'css' => 'text/css',
'htm|html' => 'text/html',
'mp3|mp4' => 'audio/mpeg',
'ra|ram' => 'audio/x-realaudio',
'wav' => 'audio/wav',
'ogg' => 'audio/ogg',
'mid|midi' => 'audio/midi',
'wma' => 'audio/wma',
'rtf' => 'application/rtf',
'js' => 'application/javascript',
'pdf' => 'application/pdf',
'doc' => 'application/msword',
'pot|pps|ppt' => 'application/vnd.ms-powerpoint',
'wri' => 'application/vnd.ms-write',
'xla|xls|xlt|xlw' => 'application/vnd.ms-excel',
'mdb' => 'application/vnd.ms-access',
'mpp' => 'application/vnd.ms-project',
'swf' => 'application/x-shockwave-flash',
'class' => 'application/java',
'tar' => 'application/x-tar',
'zip' => 'application/zip',
'gz|gzip' => 'application/x-gzip',
'exe' => 'application/x-msdownload'
));
// All tests are on by default. Most can be turned off by $override[{test_name}] = false;
$test_form = true;
$test_size = true;
// If you override this, you must provide $ext and $type!!!!
$test_type = true;
// Install user overrides. Did we mention that this voids your warranty?
@ -1716,25 +1722,20 @@ function wp_handle_upload(&$file, $overrides = false) {
if (! is_uploaded_file($file['tmp_name']) )
return $upload_error_handler($file, __('Specified file failed upload test.'));
// A correct MIME type will pass this test. We can't always determine it programatically, so we'll trust the HTTP headers.
// A correct MIME type will pass this test.
if ( $test_type ) {
$type = false;
$ext = false;
foreach ($mimes as $mime_preg => $ext_preg) {
$mime_preg = '!^' . $mime_preg . '$!i';
foreach ($mimes as $ext_preg => $mime_match) {
$ext_preg = '![^.]\.(' . $ext_preg . ')$!i';
if ( preg_match($mime_preg, $file['type'], $type) ) {
if ( preg_match($ext_preg, $file['name'], $ext) ) {
break;
} else {
return $upload_error_handler($file, __('File extension does not match file type. Try another.'));
}
if ( preg_match($ext_preg, $file['name'], $ext_matches) ) {
$type = $mime_match;
$ext = $ext_matches[1];
}
}
if (! $type && $ext )
if ( !$type || !$ext )
return $upload_error_handler($file, __('File type does not meet security guidelines. Try another.'));
$type = $type[0];
$ext = $ext[1];
}
// A writable uploads dir will pass this test. Again, there's no point overriding this one.
@ -1754,7 +1755,7 @@ function wp_handle_upload(&$file, $overrides = false) {
// Move the file to the uploads dir
$new_file = $uploads['path'] . "/$filename";
if ( false === move_uploaded_file($file['tmp_name'], $new_file) )
die(__('The uploaded file could not be moved to $file.'));
die(printf(__('The uploaded file could not be moved to %s.'), $file['path']));
// Set correct file permissions
$stat = stat(dirname($new_file));
@ -1764,7 +1765,7 @@ function wp_handle_upload(&$file, $overrides = false) {
// Compute the URL
$url = $uploads['url'] . "/$filename";
return array('file' => $new_file, 'url' => $url);
return array('file' => $new_file, 'url' => $url, 'type' => $type);
}
function wp_shrink_dimensions($width, $height, $wmax = 128, $hmax = 96) {
@ -1836,4 +1837,36 @@ function user_can_richedit() {
return true; // Best guess
}
function the_attachment_links($id = false) {
$id = (int) $id;
$post = & get_post($id);
if ( $post->post_status != 'attachment' )
return false;
$icon = get_attachment_icon($post->ID);
?>
<?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>
<?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>
<?php if ( $icon ) : ?>
<?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"><img src="<?php echo $thumb ?>" class="attachmentthumb" alt="<?php echo $post->post_title ?>" /></a></textarea>
<?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) ?>" class="attachmentlink"><img src="<?php echo $icon ?>" class="attachmentthumb" alt="<?php echo $post->post_title ?>" /></a></textarea>
<?php endif; ?>
<?php
}
function get_udims($width, $height) {
if ( $height <= 96 && $width <= 128 )
return array($width, $height);
elseif ( $width / $height > 4 / 3 )
return array(128, (int) ($height / $width * 128));
else
return array((int) ($width / $height * 96), 96);
}
?>

View File

@ -9,8 +9,22 @@ require_once('admin-header.php');
<h2><?php _e('Page Management'); ?></h2>
<p><?php _e('Pages are like posts except they live outside of the normal blog chronology and can be hierarchical. You can use pages to organize and manage any amount of content.'); ?> <a href="page-new.php"><?php _e('Create a new page'); ?> &raquo;</a></p>
<form name="searchform" action="" method="get">
<fieldset>
<legend><?php _e('Search Pages&hellip;') ?></legend>
<input type="text" name="s" value="<?php if (isset($_GET['s'])) echo wp_specialchars($_GET['s'], 1); ?>" size="17" />
<input type="submit" name="submit" value="<?php _e('Search') ?>" />
</fieldset>
</form>
<?php
$posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_status = 'static'");
$show_post_type = 'page';
if ( isset($_GET['s']) )
wp();
else
$posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_status = 'static'");
if ($posts) {
?>
@ -24,7 +38,27 @@ if ($posts) {
<th scope="col"></th>
<th scope="col"></th>
</tr>
<?php page_rows(); ?>
<?php
if ( isset($_GET['s']) ) {
foreach ( $posts as $post ) :
$class = ('alternate' != $class) ? 'alternate' : ''; ?>
<tr id='page-<?php echo $id; ?>' class='<?php echo $class; ?>'>
<th scope="row"><?php echo $post->ID; ?></th>
<td>
<?php echo $pad; ?><?php the_title() ?>
</td>
<td><?php the_author() ?></td>
<td><?php echo mysql2date('Y-m-d g:i a', $post->post_modified); ?></td>
<td><a href="<?php the_permalink(); ?>" rel="permalink" class="edit"><?php _e('View'); ?></a></td>
<td><?php if ( current_user_can('edit_pages') ) { echo "<a href='post.php?action=edit&amp;post=$id' class='edit'>" . __('Edit') . "</a>"; } ?></td>
<td><?php if ( current_user_can('edit_pages') ) { echo "<a href='post.php?action=delete&amp;post=$id' class='delete' onclick=\"return deleteSomething( 'page', " . $id . ", '" . sprintf(__("You are about to delete the &quot;%s&quot; page.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop."), wp_specialchars(get_the_title('','',0), 1)) . "' );\">" . __('Delete') . "</a>"; } ?></td>
</tr>
<?php
endforeach;
} else {
page_rows();
}
?>
</table>
<div id="ajax-response"></div>

View File

@ -65,7 +65,9 @@ if ( is_month() ) {
} elseif ( is_search() ) {
printf(__('Search for &#8220;%s&#8221;'), wp_specialchars($_GET['s']) );
} else {
if ( ! is_paged() || get_query_var('paged') == 1 )
if ( is_single() )
printf(__('Comments on %s'), $post->post_title);
elseif ( ! is_paged() || get_query_var('paged') == 1 )
_e('Last 15 Posts');
else
_e('Previous Posts');

View File

@ -25,15 +25,6 @@ for ($i=0; $i<count($wpvarstoreset); $i += 1) {
$post = (int) $post;
$images_width = 1;
function get_udims($width, $height) {
if ( $height <= 96 && $width <= 128 )
return array($width, $height);
elseif ( $width / $height > 4 / 3 )
return array(128, (int) ($height / $width * 128));
else
return array((int) ($width / $height * 96), 96);
}
switch($action) {
case 'delete':
@ -55,6 +46,7 @@ if ( isset($file['error']) )
die($file['error'] . '<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);
@ -64,7 +56,7 @@ $attachment = array(
'post_content' => $descr,
'post_status' => 'attachment',
'post_parent' => $post,
'post_mime_type' => $_FILES['image']['type'],
'post_mime_type' => $type,
'guid' => $url
);
@ -79,15 +71,22 @@ if ( preg_match('!^image/!', $attachment['post_mime_type']) ) {
list($uwidth, $uheight) = get_udims($imagedata['width'], $imagedata['height']);
$imagedata['hwstring_small'] = "height='$uheight' width='$uwidth'";
$imagedata['file'] = $file;
$imagedata['thumb'] = "thumb-$filename";
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 )
$error = wp_create_thumbnail($file, 128);
$thumb = wp_create_thumbnail($file, 128);
elseif ( $imagedata['height'] > 96 )
$error = wp_create_thumbnail($file, 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());
@ -162,6 +161,9 @@ if ( count($attachments) > 0 ) {
$__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');
@ -173,12 +175,18 @@ 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'];
@ -193,7 +201,7 @@ var srcb = new Array();
}
$attachment = array_merge($attachment, $meta);
$send_delete_cancel = "<a onclick=\"sendToEditor({$ID});return false;\" href=\"javascript:void()\">$__send_to_editor</a>
<a onclick=\"return confirm('$__confirmdelete')\" href=\"".basename(__FILE__)."?action=delete&amp;attachment={$ID}&amp;all=$all&amp;start=$start&amp;post=$post\">$__delete</a>
<!--<a onclick=\"return confirm('$__confirmdelete')\" href=\"".basename(__FILE__)."?action=delete&amp;attachment={$ID}&amp;all=$all&amp;start=$start&amp;post=$post\">$__delete</a>-->
<a onclick=\"popup.style.display='none';return false;\" href=\"javascript:void()\">$__close</a>
";
$uwidth_sum += 128;
@ -234,11 +242,18 @@ imgb[{$ID}] = '<img id=\"image{$ID}\" src=\"{$image['guid']}\" alt=\"{$image['po
</div>
";
} else {
$script .= "aa[{$ID}] = '<a id=\"{$ID}\" rel=\"attachment\" href=\"$href\" onclick=\"doPopup({$ID});return false;\" title=\"{$attachment['post_title']}\">{$attachment['post_title']}</a>';
ab[{$ID}] = '<a id=\"{$ID}\" href=\"{$attachment['guid']}\" onclick=\"doPopup({$ID});return false;\" title=\"{$attachment['post_title']}\">{$attachment['post_title']}</a>';
$title = $attachment['post_title'];
$filename = basename($attachment['guid']);
if ( $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=\"{$ID}\" rel=\"attachment\" href=\"$href\" onclick=\"doPopup({$ID});return false;\" title=\"{$title}\">{$attachment['post_title']}</a>';
ab[{$ID}] = '<a id=\"{$ID}\" href=\"{$filename}\" onclick=\"doPopup({$ID});return false;\" title=\"{$title}\">{$attachment['post_title']}</a>';
title[{$ID}] = '{$attachment['post_title']}';
filename[{$ID}] = '{$filename}';
icon[{$ID}] = '{$icon}';
";
$html .= "<div id='target{$ID}' class='attwrap left'>
<div id='div{$ID}' class='otherwrap' onmousedown=\"selectLink({$ID})\" onclick=\"doPopup({$ID});return false;\">
<div id='div{$ID}' class='otherwrap usingtext' onmousedown=\"selectLink({$ID})\" onclick=\"doPopup({$ID});return false;\">
<a id=\"{$ID}\" href=\"{$attachment['guid']}\" onmousedown=\"selectLink({$ID});\" onclick=\"return false;\">{$attachment['post_title']}</a>
</div>
</div>
@ -246,6 +261,7 @@ ab[{$ID}] = '<a id=\"{$ID}\" href=\"{$attachment['guid']}\" onclick=\"doPopup({$
$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>
";
@ -320,6 +336,8 @@ function toggleLink(n) {
function toggleOtherLink(n) {
od=document.getElementById('div'+n);
ol=document.getElementById('L'+n);
oi=document.getElementById(n);
ih=oi.innerHTML;
if ( ol.innerHTML == linkedtofile ) {
od.innerHTML = aa[n];
ol.innerHTML = linkedtopage;
@ -327,6 +345,8 @@ function toggleOtherLink(n) {
od.innerHTML = ab[n];
ol.innerHTML = linkedtofile;
}
oi=document.getElementById(n);
oi.innerHTML = ih;
}
function toggleImage(n) {
o = document.getElementById('image'+n);
@ -339,6 +359,25 @@ function toggleImage(n) {
oi.innerHTML = usingthumbnail;
}
}
function toggleOtherIcon(n) {
od = document.getElementById('div'+n);
o = document.getElementById(n);
oi = document.getElementById('I'+n);
if ( oi.innerHTML == usingtitle ) {
o.innerHTML = filename[n];
oi.innerHTML = usingfilename;
} else if ( oi.innerHTML == usingfilename ) {
o.innerHTML = icon[n];
oi.innerHTML = usingicon;
} else {
o.innerHTML = title[n];
oi.innerHTML = usingtitle;
}
if ( oi.innerHTML == usingicon )
od.className = 'otherwrap usingicon';
else
od.classname = 'otherwrap usingtext';
}
var win = window.opener ? window.opener : window.dialogArguments;
if (!win) win = top;
@ -401,19 +440,32 @@ form {
}
.otherwrap {
margin-right: 5px;
height: 90px;
overflow: hidden;
background-color: #f9fcfe;
float: left;
padding: 3px;
}
.otherwrap a {
display: block;
width: 122px;
}
.otherwrap a, .otherwrap a:hover, .otherwrap a:active, .otherwrap a:visited {
color: blue;
}
.usingicon {
padding: 0px;
height: 96px;
text-align: center;
}
.usingicon a {
width: 128px;
}
.usingtext {
padding: 3px;
height: 90px;
text-align: left;
}
.usingtext a {
width: 122px;
}
.filetype {
font-size: 80%;
border-bottom: 3px double #89a

View File

@ -74,6 +74,8 @@ case 'edit':
if ($post->post_status == 'static')
include('edit-page-form.php');
elseif ($post->post_status == 'attachment')
include('edit-attachment-form.php');
else
include('edit-form-advanced.php');
@ -85,6 +87,22 @@ case 'edit':
<?php
break;
case 'editattachment':
$post_id = (int) $_POST['post_ID'];
// Don't let these be changed
unset($_POST['guid']);
$_POST['post_status'] = 'attachment';
// Update the thumbnail filename
$oldmeta = $newmeta = get_post_meta($post_id, '_wp_attachment_metadata', true);
$newmeta['thumb'] = $_POST['thumb'];
if ( '' !== $oldmeta )
update_post_meta($post_id, '_wp_attachment_metadata', $newmeta, $oldmeta);
else
add_post_meta($post_id, '_wp_attachment_metadata', $newmeta);
case 'editpost':
$post_ID = edit_post();
@ -98,6 +116,8 @@ case 'editpost':
$location = $_POST['referredby'];
if ( $_POST['referredby'] == 'redo' )
$location = get_permalink( $post_ID );
} elseif ($action == 'editattachment') {
$location = 'attachments.php';
} else {
$location = 'post.php';
}
@ -110,15 +130,18 @@ case 'delete':
check_admin_referer();
$post_id = (isset($_GET['post'])) ? intval($_GET['post']) : intval($_POST['post_ID']);
$post = & get_post($post_id);
if ( !current_user_can('edit_post', $post_id) )
die( __('You are not allowed to delete this post.') );
if (! wp_delete_post($post_id))
if ( (($post->post_status != 'attachment') && !wp_delete_post($post_id)) || !wp_delete_attachment($post_id))
die( __('Error in deleting...') );
$sendback = $_SERVER['HTTP_REFERER'];
if (strstr($sendback, 'post.php')) $sendback = get_settings('siteurl') .'/wp-admin/post.php';
elseif (strstr($sendback, 'attachments.php')) $sendback = get_settings('siteurl') .'/wp-admin/attachments.php';
$sendback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $sendback);
header ('Location: ' . $sendback);
break;

View File

@ -163,6 +163,23 @@ textarea, input, select {
overflow-y: hidden;
}
form#upload th {
text-align: right;
}
form#upload #post_content, form#upload #post_title {
width: 250px;
}
form#upload #post_content {
height: 50px;
}
.attpreview {
width: 1px; /* hug */
text-align: center;
}
.alignleft {
float: left
}
@ -389,7 +406,7 @@ table .vers, table .name {
border: none;
}
#titlediv {
#titlediv, #guiddiv {
margin: 0 8px 0 0;
padding: 0px;
}
@ -409,7 +426,7 @@ table .vers, table .name {
width: 100%;
}
#titlediv input {
#titlediv input, #guiddiv input {
margin: 0px;
width: 100%;
}
@ -456,15 +473,21 @@ table .vers, table .name {
font-size: 1.5em;
}
#postexcerpt div {
#postexcerpt div, #attachmentlinks div {
margin-right: 8px;
}
* html #postexcerpt .dbx-toggle-open {
#attachmentlinks textarea {
width: 100%;
height: 2.5em;
margin-bottom: 6px;
}
* html #postexcerpt .dbx-toggle-open, * html #postexcerpt .dbx-toggle-open {
padding-right: 8px;
}
#excerpt {
#excerpt, .attachmentlinks {
margin: 0px;
height: 4em;
width: 100%;
@ -733,7 +756,7 @@ table .vers, table .name {
width: 14.5em;
}
#slugdiv input, #passworddiv input, #authordiv select {
#slugdiv input, #passworddiv input, #authordiv select, #thumbdiv input, #parentdiv input {
margin-top: .5em;
width: 90%;
}

View File

@ -11,22 +11,8 @@
<div class="post" id="post-<?php the_ID(); ?>">
<h2><a href="<?php echo get_permalink($post->post_parent); ?>" rev="attachment"><?php echo get_the_title($post->post_parent); ?></a> &raquo; <a href="<?php echo get_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a></h2>
<div class="entrytext">
<?php $type = explode('/', $post->post_mime_type);
switch ( $type[0] ) {
case 'image' :
$meta = get_post_meta($post->ID, '_wp_attachment_metadata', true);
if ($meta['width'] > 450) : ?>
<p><a href="<?php echo $post->guid; ?>" title="<?php echo $post->post_title.': '.$meta['width'].'x'.$meta['height'] ?>"><img class="centered" src="<?php echo $post->guid; ?>" alt="<?php the_title(); ?>" style="width:450px;" /></a></p>
<?php else : ?>
<p><img class="centered" src="<?php echo $post->guid; ?>" alt="<?php the_title(); ?>" /></p>
<?php endif;
break;
default :
?>
<p><a href="<?php echo $post->guid; ?>"><?php echo basename($post->guid); ?></a></p>
<?php
}
?>
<p class="<?php $link = get_the_attachment_link($post->ID, true, array(450, 800)); /* Doing this now populates the imagesize stuff */ echo $post->iconsize[0] <= 128 ? 'small' : ''; ?>attachment"><?php echo get_the_attachment_link($post->ID, true, array(450, 800)); ?><br /><?php echo basename($post->guid); ?></p>
<?php the_content('<p class="serif">Read the rest of this entry &raquo;</p>'); ?>
<?php link_pages('<p><strong>Pages:</strong> ', '</p>', 'number'); ?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

View File

@ -263,7 +263,23 @@ body {
.widecolumn .postmetadata {
margin: 30px 0;
}
.widecolumn .smallattachment {
text-align: center;
float: left;
width: 128px;
margin: 5px 5px 5px 0px;
}
.widecolumn .attachment {
text-align: center;
margin: 5px 0px;
}
.postmetadata {
clear: left;
}
#footer {
padding: 0 0 0 1px;
margin: 0 auto;

View File

@ -97,12 +97,10 @@ class WP_Query {
if ( '' != $qv['subpost_id'] )
$qv['attachment_id'] = $qv['subpost_id'];
if ( ('' != $qv['attachment']) || $qv['attachment_id'] ) {
if ( ('' != $qv['attachment']) || (int) $qv['attachment_id'] ) {
$this->is_single = true;
$this->is_attachment = true;
}
if ('' != $qv['name']) {
} elseif ('' != $qv['name']) {
$this->is_single = true;
} elseif ( $qv['p'] ) {
$this->is_single = true;
@ -115,6 +113,14 @@ class WP_Query {
$this->is_single = false;
} elseif (!empty($qv['s'])) {
$this->is_search = true;
switch ($qv['show_post_type']) {
case 'page' :
$this->is_page = true;
break;
case 'attachment' :
$this->is_attachment = true;
break;
}
} else {
// Look for archive queries. Dates, categories, authors.
@ -198,6 +204,10 @@ class WP_Query {
if ( ($this->is_date || $this->is_author || $this->is_category)) {
$this->is_archive = true;
}
if ( 'attachment' == $qv['show_post_type'] ) {
$this->is_attachment = true;
}
}
if ('' != $qv['feed']) {
@ -1413,7 +1423,7 @@ class WP_Rewrite {
class WP {
var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 's', 'search', 'exact', 'sentence', 'debug', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id');
var $private_query_vars = array('posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging');
var $private_query_vars = array('posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging', 'show_post_type');
var $query_vars;
var $query_string;

View File

@ -208,12 +208,12 @@ function wp_insert_post($postarr = array()) {
return $post_ID;
}
function wp_insert_attachment($object, $file, $post_parent = 0) {
function wp_insert_attachment($object, $file = false, $post_parent = 0) {
global $wpdb, $user_ID;
if ( is_object($object) )
$object = get_object_vars($object);
// Export array as variables
extract($object);
@ -320,7 +320,8 @@ function wp_insert_attachment($object, $file, $post_parent = 0) {
wp_set_post_cats('', $post_ID, $post_category);
add_post_meta($post_ID, '_wp_attached_file', $file);
if ( $file )
add_post_meta($post_ID, '_wp_attached_file', $file);
clean_post_cache($post_ID);
@ -343,7 +344,7 @@ function wp_delete_attachment($postid) {
if ( 'attachment' != $post->post_status )
return false;
$meta = get_post_meta($postid, 'imagedata', true);
$meta = get_post_meta($postid, '_wp_attachment_metadata', true);
$file = get_post_meta($postid, '_wp_attached_file', true);
$wpdb->query("DELETE FROM $wpdb->posts WHERE ID = $postid");
@ -354,8 +355,11 @@ function wp_delete_attachment($postid) {
$wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = $postid");
if ( ! empty($meta['file']) )
@ unlink($meta['file']);
if ( ! empty($meta['thumb']) ) {
// Don't delete the thumb if another attachment uses it
if (! $foo = $wpdb->get_row("SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE '%".$wpdb->escape($meta['thumb'])."%' AND post_id <> $postid"))
@ unlink(str_replace(basename($file), $meta['thumb'], $file));
}
if ( ! empty($file) )
@ unlink($file);
@ -429,6 +433,9 @@ function wp_update_post($postarr = array()) {
$postarr['post_date_gmt'] = '';
}
if ($postarr['post_status'] == 'attachment')
return wp_insert_attachment($postarr);
return wp_insert_post($postarr);
}
@ -511,6 +518,9 @@ function wp_delete_post($postid = 0) {
if ( !$post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID = $postid") )
return $post;
if ( 'attachment' == $post->post_status )
return wp_delete_attachment($postid);
do_action('delete_post', $postid);
if ( 'publish' == $post->post_status) {

View File

@ -503,7 +503,7 @@ function update_post_meta($post_id, $key, $value, $prev_value = '') {
$original_prev = $prev_value;
if ( is_array($prev_value) || is_object($prev_value) )
$prev_value = serialize($value);
$prev_value = $wpdb->escape(serialize($prev_value));
if (! $wpdb->get_var("SELECT meta_key FROM $wpdb->postmeta WHERE meta_key
= '$key' AND post_id = '$post_id'") ) {

View File

@ -209,11 +209,16 @@ function edit_post_link($link = 'Edit This', $before = '', $after = '') {
get_currentuserinfo();
if ( !user_can_edit_post($user_ID, $post->ID) || is_attachment() ) {
if ( !user_can_edit_post($user_ID, $post->ID) ) {
return;
}
$location = get_settings('siteurl') . "/wp-admin/post.php?action=edit&amp;post=$post->ID";
if ( is_attachment() )
$file = 'attachments';
else
$file = 'post';
$location = get_settings('siteurl') . "/wp-admin/{$file}.php?action=edit&amp;post=$post->ID";
echo $before . "<a href=\"$location\">$link</a>" . $after;
}

View File

@ -439,22 +439,126 @@ function _page_level_out($parent, $page_tree, $args, $depth = 0, $echo = true) {
return $output;
}
function prepend_attachment($content) {
global $post;
function the_attachment_link($id = 0, $fullsize = false, $max_dims = false) {
echo get_the_attachment_link($id, $fullsize, $max_dims);
}
$p = '<p class="attachment">';
function get_the_attachment_link($id = 0, $fullsize = false, $max_dims = false) {
$id = (int) $id;
$_post = & get_post($id);
if ( ('attachment' != $_post->post_status) || ('' == $_post->guid) )
return __('Missing Attachment');
if (! empty($_post->guid) ) {
$innerHTML = get_attachment_innerHTML($_post->ID, $fullsize, $max_dims);
return "<a href=\"{$_post->guid}\" title=\"{$_post->post_title}\" >{$innerHTML}</a>";
if ( '' != $post->guid ) {
if ( substr($post->post_mime_type, 0, 6) == 'image/' )
$p .= '<a href="' . $post->guid . '" title="Click for full-size image" ><img class="attachmentimage" src="' . $post->guid . '" alt="' . $post->post_title . '" /></a>';
else
$p .= __('Attachment') . ' (' . $post->post_mime_type . ')';
} else {
$p .= __('Missing attachment');
}
return $p;
}
function get_attachment_icon($id = 0, $fullsize = false, $max_dims = false) {
$id = (int) $id;
$post = & get_post($id);
$mime = $post->post_mime_type;
$imagedata = get_post_meta($post->ID, '_wp_attachment_metadata', true);
$file = get_post_meta($post->ID, '_wp_attached_file', true);
if ( !$fullsize && !empty($imagedata['thumb'])
&& ($thumbfile = str_replace(basename($file), $imagedata['thumb'], $file))
&& file_exists($thumbfile) ) {
// We have a thumbnail desired, specified and existing
$src = str_replace(basename($post->guid), $imagedata['thumb'], $post->guid);
$src_file = $thumbfile;
$class = 'attachmentthumb';
} elseif ( substr($mime, 0, 6) == 'image/'
&& file_exists($file) ) {
// We have an image without a thumbnail
$src = $post->guid;
$src_file = & $file;
$class = 'attachmentimage';
} elseif (! empty($mime) ) {
// No thumb, no image. We'll look for a mime-related icon instead.
$icon_dir = apply_filters('icon_dir', get_template_directory().'/images');
$icon_dir_uri = apply_filters('icon_dir_uri', get_template_directory_uri().'/images');
$types = array(substr($mime, 0, strpos($mime, '/')), substr($mime, strpos($mime, '/') + 1), str_replace('/', '_', $mime));
$exts = array('jpg', 'gif', 'png');
foreach ($types as $type) {
foreach ($exts as $ext) {
$src_file = "$icon_dir/$type.$ext";
if ( file_exists($src_file) ) {
$src = "$icon_dir_uri/$type.$ext";
break 2;
}
}
}
}
if (! isset($src) )
return false;
// Do we need to constrain the image?
if ( ($max_dims = apply_filters('attachment_max_dims', $max_dims)) && file_exists($src_file) ) {
$imagesize = getimagesize($src_file);
if (($imagesize[0] > $max_dims[0]) || $imagesize[1] > $max_dims[1] ) {
$actual_aspect = $imagesize[0] / $imagesize[1];
$desired_aspect = $max_dims[0] / $max_dims[1];
if ( $actual_aspect >= $desired_aspect ) {
$height = $actual_aspect * $max_dims[0];
$constraint = "width=\"{$max_dims[0]}\" ";
$post->iconsize = array($max_dims[0], $height);
} else {
$width = $max_dims[1] / $actual_aspect;
$constraint = "height=\"{$max_dims[1]}\" ";
$post->iconsize = array($width, $max_dims[1]);
}
} else {
$post->iconsize = array($imagesize[0], $imagesize[1]);
}
}
$icon = "<img src=\"{$src}\" title=\"{$post->post_title}\" {$constraint}/>";
return apply_filters('attachment_icon', $icon, $post->ID);
}
function get_attachment_innerHTML($id = 0, $fullsize = false, $max_dims = false) {
$id = (int) $id;
if ( $innerHTML = get_attachment_icon($id, $fullsize, $max_dims))
return $innerHTML;
$post = & get_post($id);
$innerHTML = $post->post_title;
return apply_filters('attachment_innerHTML', $innerHTML, $post->ID);
}
function prepend_attachment($content) {
$p = '<p class="attachment">';
$p .= get_the_attachment_link(false, true, array(400, 300));
$p .= '</p>';
$p = apply_filters('prepend_attachment', $p);
return "$p\n$content";
}
?>