Renaming. object and subpost are now attachment. post_type is post_mime_type.

git-svn-id: https://develop.svn.wordpress.org/trunk@3092 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren
2005-11-15 22:55:24 +00:00
parent 06d61e1f7a
commit 1a012b8b49
11 changed files with 125 additions and 89 deletions

View File

@@ -59,7 +59,7 @@ function write_post() {
$post_ID = wp_insert_post($_POST);
add_meta($post_ID);
// Reunite any orphaned subposts with their parent
// Reunite any orphaned attachments with their parent
if ( $_POST['temp_ID'] )
relocate_children($_POST['temp_ID'], $post_ID);

View File

@@ -5,7 +5,7 @@ require_once('admin.php');
if (!current_user_can('edit_posts'))
die(__('You do not have permission to edit posts.'));
$wpvarstoreset = array('action', 'post', 'all', 'last', 'link', 'sort', 'start', 'imgtitle', 'descr', 'object', 'flickrtag');
$wpvarstoreset = array('action', 'post', 'all', 'last', 'link', 'sort', 'start', 'imgtitle', 'descr', 'attachment', 'flickrtag');
for ($i=0; $i<count($wpvarstoreset); $i += 1) {
$wpvar = $wpvarstoreset[$i];
@@ -37,7 +37,7 @@ function get_udims($width, $height) {
switch($action) {
case 'delete':
wp_delete_object($object);
wp_delete_attachment($attachment);
header("Location: ".basename(__FILE__)."?post=$post&all=$all&action=view&start=$start");
die;
@@ -55,20 +55,20 @@ $url = $file['url'];
$file = $file['file'];
$filename = basename($file);
// Construct the object array
$object = array(
// Construct the attachment array
$attachment = array(
'post_title' => $imgtitle ? $imgtitle : $filename,
'post_content' => $descr,
'post_status' => 'object',
'post_status' => 'attachment',
'post_parent' => $post,
'post_type' => $_FILES['image']['type'],
'post_mime_type' => $_FILES['image']['type'],
'guid' => $url
);
// Save the data
$id = wp_attach_object($object, $post);
$id = wp_insert_attachment($attachment, $file, $post);
// Generate the object's postmeta.
// Generate the attachment's postmeta.
$imagesize = getimagesize($file);
$imagedata['width'] = $imagesize['0'];
$imagedata['height'] = $imagesize['1'];
@@ -81,7 +81,7 @@ add_post_meta($id, 'imagedata', $imagedata);
if ( $imagedata['width'] * $imagedata['height'] < 3 * 1024 * 1024 ) {
if ( $imagedata['width'] > 128 && $imagedata['width'] >= $imagedata['height'] * 4 / 3 )
$error = wp_create_thumbnail($file['file'], 128);
$error = wp_create_thumbnail($file, 128);
elseif ( $imagedata['height'] > 96 )
$error = wp_create_thumbnail($file, 96);
}
@@ -109,7 +109,7 @@ if ( $post && empty($all) ) {
}
if ( $last )
$start = $wpdb->get_var("SELECT count(ID) FROM $wpdb->posts WHERE post_status = 'object' AND left(post_type, 5) = 'image' $and_post") - $num;
$start = $wpdb->get_var("SELECT count(ID) FROM $wpdb->posts WHERE post_status = 'attachment' AND left(post_mime_type, 5) = 'image' $and_post") - $num;
else
$start = (int) $start;
@@ -119,7 +119,7 @@ if ( $start < 0 )
if ( '' == $sort )
$sort = "ID";
$images = $wpdb->get_results("SELECT ID, post_date, post_title, guid FROM $wpdb->posts WHERE post_status = 'object' AND left(post_type, 5) = 'image' $and_post ORDER BY $sort LIMIT $start, $double", ARRAY_A);
$images = $wpdb->get_results("SELECT ID, post_date, post_title, guid FROM $wpdb->posts WHERE post_status = 'attachment' AND left(post_mime_type, 5) = 'image' $and_post ORDER BY $sort LIMIT $start, $double", ARRAY_A);
if ( count($images) > $num ) {
$next = $start + count($images) - $num;
@@ -143,20 +143,19 @@ $images_script = '';
if ( count($images) > 0 ) {
$images = array_slice( $images, 0, $num );
$__delete = __('DELETE');
$__subpost_on = __('SUBPOST <strong>ON</strong>');
$__subpost_off = __('SUBPOST <strong>OFF</strong>');
$__attachment_on = __('ATTACHMENT <strong>ON</strong>');
$__thumbnail_on = __('THUMBNAIL <strong>ON</strong>');
$__thumbnail_off = __('THUMBNAIL <strong>OFF</strong>');
$__no_thumbnail = __('<del>THUMBNAIL</del>');
$__close = __('CLOSE');
$__confirmdelete = __('Delete this photo from the server?');
$__nothumb = __('There is no thumbnail associated with this photo.');
$images_script .= "subposton = '$__subpost_on';\nsubpostoff = '$__subpost_off';\n";
$images_script .= "attachmenton = '$__attachment_on';\nattachmentoff = '$__attachment_off';\n";
$images_script .= "thumbnailon = '$__thumbnail_on';\nthumbnailoff = '$__thumbnail_off';\n";
foreach ( $images as $key => $image ) {
$meta = get_post_meta($image['ID'], 'imagedata', true);
if (!is_array($meta)) {
wp_delete_object($image['ID']);
wp_delete_attachment($image['ID']);
continue;
}
$image = array_merge($image, $meta);
@@ -175,16 +174,16 @@ if ( count($images) > 0 ) {
$uwidth_sum += 128;
$xpadding = (128 - $image['uwidth']) / 2;
$ypadding = (96 - $image['uheight']) / 2;
$object = $image['ID'];
$attachment = $image['ID'];
$images_style .= "#target$i img { padding: {$ypadding}px {$xpadding}px; }\n";
$href = get_subpost_link($object);
$href = get_attachment_link($attachment);
$images_script .= "href".$i."a = '$href';\nhref".$i."b = '{$image['guid']}';\n";
$images_html .= "
<div id='target$i' class='imagewrap left'>
<div id='popup$i' class='popup'>
<a id=\"L$i\" onclick=\"toggleLink($i);return false;\" href=\"javascript:void();\">$__subpost_on</a>
<a id=\"L$i\" onclick=\"toggleLink($i);return false;\" href=\"javascript:void();\">$__attachment_on</a>
<a id=\"I$i\" onclick=\"if($thumb)toggleImage($i);else alert('$__nothumb');return false;\" href=\"javascript:void();\">$thumbtext</a>
<a onclick=\"return confirm('$__confirmdelete')\" href=\"".basename(__FILE__)."?action=delete&amp;object=$object&amp;all=$all&amp;start=$start&amp;post=$post\">$__delete</a>
<a onclick=\"return confirm('$__confirmdelete')\" href=\"".basename(__FILE__)."?action=delete&amp;attachment=$attachment&amp;all=$all&amp;start=$start&amp;post=$post\">$__delete</a>
<a onclick=\"popup.style.display='none';return false;\" href=\"javascript:void()\">$__close</a>
</div>
<a id=\"link$i\" class=\"imagelink\" href=\"$href\" onclick=\"imagePopup($i);return false;\" title=\"{$image['post_title']}\">
@@ -244,12 +243,12 @@ popup = false;
function toggleLink(n) {
o=document.getElementById('link'+n);
oi=document.getElementById('L'+n);
if ( oi.innerHTML == subposton ) {
if ( oi.innerHTML == attachmenton ) {
o.href = eval('href'+n+'b');
oi.innerHTML = subpostoff;
oi.innerHTML = attachmentoff;
} else {
o.href = eval('href'+n+'a');
oi.innerHTML = subposton;
oi.innerHTML = attachmenton;
}
}
function toggleImage(n) {

View File

@@ -30,7 +30,7 @@ function upgrade_all() {
upgrade_130();
}
if ( $wp_current_db_version < 3091 )
if ( $wp_current_db_version < 3092 )
upgrade_160();
save_mod_rewrite_rules();
@@ -240,8 +240,8 @@ function upgrade_130() {
}
function upgrade_160() {
global $wpdb, $table_prefix;
global $wpdb, $table_prefix, $wp_current_db_version;
populate_roles_160();
$users = $wpdb->get_results("SELECT * FROM $wpdb->users");
@@ -300,6 +300,23 @@ function upgrade_160() {
$wpdb->query("UPDATE $wpdb->categories SET category_count = '$count' WHERE cat_ID = '$cat_id'");
}
}
// Some alpha versions used a post status of object instead of attachment and put
// the mime type in post_type instead of post_mime_type.
if ( $wp_current_db_version > 2541 && $wp_current_db_version <= 3091 ) {
$objects = $wpdb->get_results("SELECT ID, post_type FROM $wpdb->posts WHERE post_status = 'object'");
foreach ($objects as $object) {
$wpdb->query("UPDATE $wpdb->posts SET post_status = 'attachment',
post_mime_type = '$object->post_type',
post_type = '',
guid = '$guid'
WHERE ID = $object->ID");
$meta = get_post_meta($postid, 'imagedata', true);
if ( ! empty($meta['file']) )
add_post_meta($object->ID, '_wp_attached_file', $meta['file']);
}
}
}
// The functions we use to actually do stuff

View File

@@ -106,7 +106,7 @@ CREATE TABLE $wpdb->posts (
post_title text NOT NULL,
post_category int(4) NOT NULL default '0',
post_excerpt text NOT NULL,
post_status enum('publish','draft','private','static','object') NOT NULL default 'publish',
post_status enum('publish','draft','private','static','object','attachment') NOT NULL default 'publish',
comment_status enum('open','closed','registered_only') NOT NULL default 'open',
ping_status enum('open','closed') NOT NULL default 'open',
post_password varchar(20) NOT NULL default '',
@@ -120,6 +120,7 @@ CREATE TABLE $wpdb->posts (
guid varchar(255) NOT NULL default '',
menu_order int(11) NOT NULL default '0',
post_type varchar(100) NOT NULL,
post_mime_type varchar(100) NOT NULL,
PRIMARY KEY (ID),
KEY post_name (post_name)
);