post_content )); $class = 'text'; $innerHTML = get_attachment_innerHTML( $id, false, $dims ); if ( $image_src = get_attachment_icon_src() ) { $image_rel = wp_make_link_relative($image_src); $innerHTML = ' ' . str_replace($image_src, $image_rel, $innerHTML); $class = 'image'; } $src_base = wp_get_attachment_url(); $src = wp_make_link_relative( $src_base ); $src_base = str_replace($src, '', $src_base); if ( !trim($post_title) ) $post_title = basename($src); $r = ''; if ( $href ) $r .= "\n"; if ( $href || $image_src ) $r .= "\t\t\t$innerHTML"; if ( $href ) $r .= "\n"; $size = @filesize($filesystem_path); if ( !empty($size) ) $r .= "\t\t\t\t".size_format($size)."\n"; $r .= "\n\t\t
\n\t\t\t

\n"; $r .= "\t\t\t\t\n"; $r .= "\t\t\t\t\n"; if ( !$thumb_base = wp_get_attachment_thumb_url() ) $thumb_base = wp_mime_type_icon(); if ( $thumb_base ) { $thumb_rel = wp_make_link_relative( $thumb_base ); $thumb_base = str_replace( $thumb_rel, '', $thumb_base ); $r .= "\t\t\t\t\n"; $r .= "\t\t\t\t\n"; } $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, $style; $id = get_the_ID(); $attachment_data = wp_get_attachment_metadata( $id ); ?>

"; the_title(); if ( !isset($attachment_data['width']) && 'inline' != $style ) echo ''; ?>

' . __('view') . ''; echo ' | '; echo '' . __('edit') . ''; echo ' | '; echo '' . __('cancel') . ''; echo ' ]'; ?>
"; echo wp_upload_display( array(171, 128) ); if ( isset($attachment_data['width']) && 'inline' != $style ) echo ''; ?>
\n"; } function wp_upload_form() { $id = get_the_ID(); global $post_id, $tab, $style; $enctype = $id ? '' : ' enctype="multipart/form-data"'; $post_id = (int) $post_id; ?> id="upload-file" method="post" action="">

"; the_title(); if ( !isset($attachment_data['width']) && 'inline' != $style ) echo ''; ?>

' . __('view') . ''; echo ' | '; echo '' . __('links') . ''; echo ' | '; echo '' . __('cancel') . ''; echo ' ]'; ?>
"; echo wp_upload_display( array(171, 128) ); if ( isset($attachment_data['width']) && 'inline' != $style ) 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_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); wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); 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 $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&post_status=any&posts_per_page=10&paged=$paged"); 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() { wp_admin_css( 'css/upload' ); if ( 'inline' == @$_GET['style'] ) { echo ""; } } ?>