diff --git a/wp-admin/admin-functions.php b/wp-admin/admin-functions.php index d04709265..771c2fdea 100644 --- a/wp-admin/admin-functions.php +++ b/wp-admin/admin-functions.php @@ -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); + +?> +
+ +
+ + +
+ +
+ + + 4 / 3 ) + return array(128, (int) ($height / $width * 128)); + else + return array((int) ($width / $height * 96), 96); +} + ?> diff --git a/wp-admin/edit-pages.php b/wp-admin/edit-pages.php index 2d1cd5acd..96083ec77 100644 --- a/wp-admin/edit-pages.php +++ b/wp-admin/edit-pages.php @@ -9,8 +9,22 @@ require_once('admin-header.php');

»

+
+
+ + + +
+
+ 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) { - + + + ID; ?> + + + + + post_modified); ?> + + " . __('Edit') . ""; } ?> + " . __('Delete') . ""; } ?> + +
diff --git a/wp-admin/edit.php b/wp-admin/edit.php index d1a98c0ce..1496a568c 100644 --- a/wp-admin/edit.php +++ b/wp-admin/edit.php @@ -65,7 +65,9 @@ if ( is_month() ) { } elseif ( is_search() ) { printf(__('Search for “%s”'), 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'); diff --git a/wp-admin/inline-uploading.php b/wp-admin/inline-uploading.php index 9d7e5c5a4..18cc7f19c 100644 --- a/wp-admin/inline-uploading.php +++ b/wp-admin/inline-uploading.php @@ -25,15 +25,6 @@ for ($i=0; $i 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'] . ''.__('Back to Image Uploading').''); $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 = ''.__('No Thumbnail').''; $__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 = "$__send_to_editor -$__delete + $__close "; $uwidth_sum += 128; @@ -234,11 +242,18 @@ imgb[{$ID}] = '\"{$image['po "; } else { - $script .= "aa[{$ID}] = '{$attachment['post_title']}'; -ab[{$ID}] = '{$attachment['post_title']}'; + $title = $attachment['post_title']; + $filename = basename($attachment['guid']); + if ( $icon = get_attachment_icon($ID) ) + $toggle_icon = "$__using_title"; + $script .= "aa[{$ID}] = '{$attachment['post_title']}'; +ab[{$ID}] = '{$attachment['post_title']}'; +title[{$ID}] = '{$attachment['post_title']}'; +filename[{$ID}] = '{$filename}'; +icon[{$ID}] = '{$icon}'; "; $html .= "
- @@ -246,6 +261,7 @@ ab[{$ID}] = ' $__linked_to_file + {$toggle_icon} {$send_delete_cancel}
"; @@ -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 diff --git a/wp-admin/post.php b/wp-admin/post.php index b61aa16c4..ea53a0740 100644 --- a/wp-admin/post.php +++ b/wp-admin/post.php @@ -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': 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; diff --git a/wp-admin/wp-admin.css b/wp-admin/wp-admin.css index 88619565c..357d19f1d 100644 --- a/wp-admin/wp-admin.css +++ b/wp-admin/wp-admin.css @@ -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%; } diff --git a/wp-content/themes/default/attachment.php b/wp-content/themes/default/attachment.php index 6a31a61f2..559a8e4bd 100644 --- a/wp-content/themes/default/attachment.php +++ b/wp-content/themes/default/attachment.php @@ -11,22 +11,8 @@

post_parent); ?> »

-post_mime_type); - switch ( $type[0] ) { - case 'image' : - $meta = get_post_meta($post->ID, '_wp_attachment_metadata', true); - if ($meta['width'] > 450) : ?> -

<?php the_title(); ?>

- -

<?php the_title(); ?>

- -

guid); ?>

- + + Read the rest of this entry »

'); ?> Pages: ', '

', 'number'); ?> diff --git a/wp-content/themes/default/images/audio.jpg b/wp-content/themes/default/images/audio.jpg new file mode 100644 index 000000000..b02e1c86e Binary files /dev/null and b/wp-content/themes/default/images/audio.jpg differ diff --git a/wp-content/themes/default/style.css b/wp-content/themes/default/style.css index 820c99308..8d5a73044 100644 --- a/wp-content/themes/default/style.css +++ b/wp-content/themes/default/style.css @@ -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; diff --git a/wp-includes/classes.php b/wp-includes/classes.php index 3fc191d13..428cee6d2 100644 --- a/wp-includes/classes.php +++ b/wp-includes/classes.php @@ -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; diff --git a/wp-includes/functions-post.php b/wp-includes/functions-post.php index 91e1ac18c..38c754093 100644 --- a/wp-includes/functions-post.php +++ b/wp-includes/functions-post.php @@ -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) { diff --git a/wp-includes/functions.php b/wp-includes/functions.php index ff7d65900..4fb97351a 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -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'") ) { diff --git a/wp-includes/template-functions-links.php b/wp-includes/template-functions-links.php index b18a80172..4b7f86608 100644 --- a/wp-includes/template-functions-links.php +++ b/wp-includes/template-functions-links.php @@ -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&post=$post->ID"; + if ( is_attachment() ) + $file = 'attachments'; + else + $file = 'post'; + + $location = get_settings('siteurl') . "/wp-admin/{$file}.php?action=edit&post=$post->ID"; echo $before . "$link" . $after; } diff --git a/wp-includes/template-functions-post.php b/wp-includes/template-functions-post.php index be4d97776..c85194738 100644 --- a/wp-includes/template-functions-post.php +++ b/wp-includes/template-functions-post.php @@ -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 = '

'; +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 "guid}\" title=\"{$_post->post_title}\" >{$innerHTML}"; - if ( '' != $post->guid ) { - if ( substr($post->post_mime_type, 0, 6) == 'image/' ) - $p .= '' . $post->post_title . ''; - 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 = "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 .= get_the_attachment_link(false, true, array(400, 300)); $p .= '

'; + $p = apply_filters('prepend_attachment', $p); return "$p\n$content"; } + ?>