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 = ' ' . $innerHTML;
}
$r = '';
if ( $href )
$r .= "\n";
if ( $href || $image_src )
$r .= "\t\t\t$innerHTML";
if ( $href )
$r .= "\n";
$r .= "\n\t\t
\n\t\t\t
\n";
$r .= "\t\t\t\t\n";
if ( $image_src )
$r .= "\t\t\t\t\n";
if ( isset($width) ) {
$r .= "\t\t\t\t\n";
$r .= "\t\t\t\t\n";
}
$r .= "\t\t\t\t\n";
$r .= "\t\t\t\t\n";
$r .= "\t\t\t\t\n";
$r .= "\t\t\t
\n\t\t
\n";
return $r;
}
function wp_upload_view() {
global $style, $post_id;
$id = get_the_ID();
$attachment_data = get_post_meta( $id, '_wp_attachment_metadata', true );
?>
";
echo wp_upload_display( array(171, 128) );
if ( isset($attachment_data['width']) )
echo ''; ?>
"
. __('Browse Files') . ''
);
$overrides = array('action'=>'upload');
$file = wp_handle_upload($_FILES['image'], $overrides);
if ( isset($file['error']) )
wp_die($file['error'] . "
'" . __('Back to Image Uploading') . ''
);
$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.')
. " "
. __('Go back') . ''
);
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, $style;
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 "\n";
if ( have_posts() ) : while ( have_posts() ) : the_post();
$href = wp_specialchars( add_query_arg( array(
'action' => 'inline' == $style ? 'view' : 'edit',
'ID' => get_the_ID())
), 1 );
echo "\t- \n";
echo wp_upload_display( array(128,128), $href );
echo "\t
\n";
endwhile;
else :
echo "\t- " . __('There are no attachments to show.') . "
\n";
endif;
echo "
\n\n";
echo "\n";
break;
endswitch;
extract($old_vars);
}
function wp_upload_tab_browse_action() {
global $style;
if ( 'inline' == $style )
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 "\n";
if ( 'rtl' == $wp_locale->text_direction )
echo "\n";
if ( 'inline' == @$_GET['style'] ) {
echo "";
}
}