post_content ); $class = 'text'; $innerHTML = get_attachment_innerHTML( $id, false, $dims ); if ( $image_src = strstr($innerHTML, 'src=') ) { preg_match("/src=(\"|')(.+?)\\1/", $image_src, $matches); $image_src = $matches[2]; $image_rel = wp_make_link_relative($image_src); $class = 'image'; $innerHTML = ' ' . str_replace($image_src, $image_rel, $innerHTML); $image_base = str_replace($image_rel, '', $image_src); } $src_base = get_the_guid(); $src = wp_make_link_relative( $src_base ); $src_base = str_replace($src, '', $src_base); $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"; $r .= "\t\t\t\t\n"; if ( isset($attachment_data['thumb']) ) { $r .= "\t\t\t\t\n"; $r .= "\t\t\t\t\n"; } elseif ( $image_rel ) $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 = get_post_meta( $id, '_wp_attachment_metadata', true ); ?>

"; 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"'; ?> 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_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\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 ""; } }