Make WordPress Core

Ticket #3191: 3191b.diff

File 3191b.diff, 33.0 KB (added by mdawaffe, 18 years ago)
  • wp-includes/script-loader.php

     
    2929                        $this->add( 'admin-comments', '/wp-admin/edit-comments.js', array('listman'), '3847' );
    3030                        $this->add( 'admin-users', '/wp-admin/users.js', array('listman'), '3684' );
    3131                        $this->add( 'xfn', '/wp-admin/xfn.js', false, '3517' );
     32                        $this->add( 'upload', '/wp-admin/upload-js.php', array('prototype'), mt_rand() );
    3233                }
    3334        }
    3435
  • wp-admin/wp-admin.css

     
    186186        border-style: none;
    187187        padding: 0px;
    188188        margin-bottom: 16px;
    189         height: 15em;
     189        height: 16em;
    190190        width: 100%;
    191191/*      overflow-y: hidden;*/
    192192}
  • wp-admin/admin-functions.php

     
    19731973        $icon = get_attachment_icon($post->ID);
    19741974
    19751975?>
    1976 <p><?php _e('Text linked to file') ?><br />
    1977 <textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo $post->guid ?>" class="attachmentlink"><?php echo basename($post->guid) ?></a></textarea></p>
    1978 <p><?php _e('Text linked to subpost') ?><br />
    1979 <textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link($post->ID) ?>" rel="attachment" id="<?php echo $post->ID ?>"><?php echo $post->post_title ?></a></textarea></p>
     1976<form id="the-attachment-links">
     1977<table>
     1978        <tr>
     1979                <th scope="row"><?php _e('Text linked to file') ?></th>
     1980                <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo $post->guid ?>" class="attachmentlink"><?php echo basename($post->guid) ?></a></textarea></td>
     1981        </tr>
     1982        <tr>
     1983                <th scope="row"><?php _e('Text linked to subpost') ?></th>
     1984                <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link($post->ID) ?>" rel="attachment" id="<?php echo $post->ID ?>"><?php echo $post->post_title ?></a></textarea></td>
     1985        </tr>
    19801986<?php if ( $icon ) : ?>
    1981 <p><?php _e('Thumbnail linked to file') ?><br />
    1982 <textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo $post->guid ?>" class="attachmentlink"><?php echo $icon ?></a></textarea></p>
    1983 <p><?php _e('Thumbnail linked to subpost') ?><br />
    1984 <textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link($post->ID) ?>" rel="attachment" id="<?php echo $post->ID ?>"><?php echo $icon ?></a></textarea></p>
     1987        <tr>
     1988                <th scope="row"><?php _e('Thumbnail linked to file') ?></th>
     1989                <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo $post->guid ?>" class="attachmentlink"><?php echo $icon ?></a></textarea></td>
     1990        </tr>
     1991        <tr>
     1992                <th scope="row"><?php _e('Thumbnail linked to subpost') ?></th>
     1993                <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link($post->ID) ?>" rel="attachment" id="<?php echo $post->ID ?>"><?php echo $icon ?></a></textarea></td>
     1994        </tr>
    19851995<?php endif; ?>
     1996</table>
     1997</form>
    19861998<?php
    19871999}
    19882000
  • wp-admin/upload-js.php

     
     1<?php require_once('admin.php'); cache_javascript_headers(); ?>
     2addLoadEvent( function() {
     3        theFileList = {
     4                currentImage: {ID: 0},
     5                nonce: '',
     6                tab: '',
     7                postID: 0,
     8
     9                initializeVars: function() {
     10                        this.urlData  = document.location.href.split('?');
     11                        this.params = this.urlData[1].toQueryParams();
     12                        this.postID = this.params['post_id'];
     13                        this.tab = this.params['tab'];
     14                        this.style = this.params['style'];
     15                        this.ID = this.params['ID'];
     16                        if ( !this.style )
     17                                this.style = 'default';
     18                        var nonceEl = $('nonce-value');
     19                        if ( nonceEl )
     20                                this.nonce = nonceEl.value;
     21                        if ( this.ID ) {
     22                                this.grabImageData( this.ID );
     23                                this.imageView( this.ID );
     24                        }
     25                },
     26
     27                initializeLinks: function() {
     28                        if ( this.ID )
     29                                return;
     30                        $$('a.file-link').each( function(i) {
     31                                var id = i.id.split('-').pop();
     32                                i.onclick = function(e) { theFileList.imageView(id, e); }
     33                        } );
     34                },
     35
     36                grabImageData: function(id) {
     37                        if ( id == this.currentImage.ID )
     38                                return;
     39                        var thumbEl = $('attachment-thumb-url-' + id);
     40                        if ( thumbEl )
     41                                this.currentImage.thumb = ( 0 == id ? '' : thumbEl.value );
     42                        else
     43                                this.currentImage.thumb = false;
     44                        this.currentImage.src = ( 0 == id ? '' : $('attachment-url-' + id).value );
     45                        this.currentImage.page = ( 0 == id ? '' : $('attachment-page-url-' + id).value );
     46                        this.currentImage.title = ( 0 == id ? '' : $('attachment-title-' + id).value );
     47                        this.currentImage.description = ( 0 == id ? '' : $('attachment-description-' + id).value );
     48                        var widthEl = $('attachment-width-' + id);
     49                        if ( widthEl ) {
     50                                this.currentImage.width = ( 0 == id ? '' : widthEl.value );
     51                                this.currentImage.height = ( 0 == id ? '' : $('attachment-height-' + id).value );
     52                        } else {
     53                                this.currentImage.width = false;
     54                                this.currentImage.height = false;
     55                        }
     56                        this.currentImage.ID = id;
     57                },
     58
     59                imageView: function(id, e) {
     60                        this.prepView(id);
     61                        var h = '';
     62
     63                        h += "<div id='upload-file'>"
     64                        h += "<div id='file-title'>"
     65                        h += "<h2><a href='" + this.currentImage.src + "' title='Direct Link to this file'>" + this.currentImage.title + "</a></h2>";
     66                        h += "<span>[&nbsp";
     67                        h += "<a href='" + this.currentImage.page + "' title='Permalink to the blog page for this file'>page link</a>"
     68                        h += '&nbsp;|&nbsp;';
     69                        h += "<a href='#' onclick='theFileList.editView(" + id + ")'  title='Edit this file'>edit</a>"
     70                        h += '&nbsp;|&nbsp;';
     71                        if ( this.ID ) {
     72                                var params = $H(this.params);
     73                                params.ID = '';
     74                                params.action = '';
     75                                h += "<a href='" + this.urlData[0] + '?' + params.toQueryString() + "'  title='Browse your files'>cancel</a>";
     76                        } else {
     77                                h += "<a href='#' onclick='theFileList.cancelView()'  title='Browse your files'>cancel</a>";
     78                        }
     79                        h += "&nbsp;]</span>";
     80                        h += '</div>'
     81                        h += "<div id='upload-file-view' class='left'>";
     82                        if ( this.currentImage.thumb )
     83                                h += "<img src='" + this.currentImage.thumb + "' alt='" + this.currentImage.title + "' width='" + this.currentImage.width + "' height='" + this.currentImage.height + "' />";
     84                        else
     85                                h += '&nbsp;';
     86                        h += "</div>";
     87
     88                        h += "<form name='uploadoptions' id='uploadoptions' class='left'>";
     89                        if ( this.currentImage.thumb ) {
     90                                h += "<input type='radio' name='display' value='thumb' checked='checked'>Display thumbnail</input><br />";
     91                                h += "<input type='radio' name='display' value='full'>Display full-sized image</input><br /><br />";
     92                        }
     93
     94                        if ( this.currentImage.thumb ) {
     95                                h += "<input type='radio' name='link' value='none' checked='checked'>Do not link to this file</input><br />";
     96                                h += "<input type='radio' name='link' value='file'>Link directly to this file</input><br />";
     97                                h += "<input type='radio' name='link' value='page'>Link to this file's blog page</input><br />";
     98                        } else {
     99                                h += "<input type='radio' name='link' value='file'>Link directly to this file</input><br />";
     100                                h += "<input type='radio' name='link' value='page' checked='checked'>Link to this file's blog page</input><br />";
     101                        }
     102
     103                        h += "<input type='button' name='send' onclick='theFileList.sendToEditor(" + id + ")' value='Send to editor' />";
     104                        h += "</form>";
     105
     106                        h += "</div>";
     107
     108                        new Insertion.Top('upload-content', h);
     109                        if (e) Event.stop(e);
     110                        return false;
     111                },
     112
     113                editView: function(id, e) {
     114                        this.prepView(id);
     115                        var h = '';
     116
     117                        h += "<form id='upload-file' method='post' action='upload.php?style=inline&amp;tab=upload&amp;post_id=" + this.postID + "'>";
     118                        h += "<div id='file-title'>"
     119                        h += "<h2><a href='" + this.currentImage.src + "' title='Direct Link to this file'>" + this.currentImage.title + "</a></h2>";
     120                        h += "<span>[&nbsp";
     121                        h += "<a href='" + this.currentImage.page + "' title='Permalink to the blog page for this file'>page link</a>"
     122                        h += '&nbsp;|&nbsp;';
     123                        h += "<a href='#' onclick='theFileList.imageView(" + id + ")'  title='View options for this file'>options</a>"
     124                        h += '&nbsp;|&nbsp;';
     125                        if ( this.ID ) {
     126                                var params = $H(this.params);
     127                                params.ID = '';
     128                                params.action = '';
     129                                h += "<a href='" + this.urlData[0] + '?' + params.toQueryString() + "'  title='Browse your files'>cancel</a>";
     130                        } else {
     131                                h += "<a href='#' onclick='theFileList.cancelView()'  title='Browse your files'>cancel</a>";
     132                        }
     133                        h += "&nbsp;]</span>";
     134                        h += '</div>'
     135                        h += "<div id='upload-file-view' class='left'>";
     136                        if ( this.currentImage.thumb )
     137                                h += "<img src='" + this.currentImage.thumb + "' alt='" + this.currentImage.title + "' width='" + this.currentImage.width + "' height='" + this.currentImage.height + "' />";
     138                        else
     139                                h += '&nbsp;';
     140                        h += "</div>";
     141
     142
     143                        h += "<table><tr>"
     144                        h += "<th scope='row'><label for='post_title'>Title:</label></th>";
     145                        h += "<td><input type='text' id='post_title' name='post_title' value='" + this.currentImage.title + "' /></td>";
     146                        h += "</tr><tr>";
     147                        h += "<th scope='row'><label for='post_content'>Description:</label></th>";
     148                        h += "<td><textarea name='post_content' id='post_content'>" + this.currentImage.description + "</textarea></td>";
     149                        h += "</tr><tr id='buttons'><th></th><td>";
     150                        h += "<input type='hidden' name='from_tab' value='" + this.tab + "' />";
     151                        h += "<input type='hidden' name='action' id='action-value' value='save' />";
     152                        h += "<input type='hidden' name='ID' value='" + id + "' />";
     153                        h += "<input type='hidden' name='_wpnonce' value='" + this.nonce + "' />";
     154                        h += "<div id='submit'><input type='submit' value='Save' />";
     155                        h += "<input type='button' name='delete' class='delete' value='Delete' onclick='theFileList.deleteFile(" + id + ");' />";
     156                        h += "</div></td></tr></table></form>";
     157
     158                        new Insertion.Top('upload-content', h);
     159                        if (e) Event.stop(e);
     160                        return false;           
     161                },
     162
     163                prepView: function(id) {
     164                        this.cancelView( true );
     165                        var filesEl = $('upload-files');
     166                        if ( filesEl )
     167                                filesEl.hide();
     168                        this.grabImageData(id);
     169                },
     170
     171                cancelView: function( prep ) {
     172                        if ( !prep ) {
     173                                var filesEl = $('upload-files');
     174                                if ( filesEl )
     175                                        filesEl.show();
     176                        }
     177                        if ( !this.ID )
     178                                this.grabImageData(0);
     179                        var div = $('upload-file');
     180                        if ( div )
     181                                div.remove();
     182                        return false;
     183                },
     184
     185                sendToEditor: function(id) {
     186                        this.grabImageData(id);
     187                        var link = '';
     188                        var display = '';
     189                        var h = '';
     190
     191                        link = $A(document.forms.uploadoptions.elements.link).detect( function(i) { return i.checked; } ).value;
     192                        displayEl = $A(document.forms.uploadoptions.elements.display).detect( function(i) { return i.checked; } )
     193                        if ( displayEl )
     194                                display = displayEl.value;
     195
     196                        if ( 'none' != link )
     197                                h += "<a href='" + ( 'file' == link ? this.currentImage.src : this.currentImage.page ) + "' title='" + this.currentImage.title + "'>";
     198                        if ( display )
     199                                h += "<img src='" + ( 'thumb' == display ? this.currentImage.thumb : this.currentImage.src ) + "' alt='" + this.currentImage.title + "' />";
     200                        else
     201                                h += this.currentImage.title;
     202                        if ( 'none' != link )
     203                                h += "</a>";
     204
     205                        var win = window.opener ? window.opener : window.dialogArguments;
     206                        if ( !win )
     207                                win = top;
     208                        tinyMCE = win.tinyMCE;
     209                        if ( typeof tinyMCE != 'undefined' && tinyMCE.getInstanceById('content') )
     210                                win.tinyMCE.execCommand('mceInsertContent', false, h);
     211                        else
     212                                win.edInsertContent(win.edCanvas, h);
     213                        this.cancelView();
     214                        return false;
     215                },
     216
     217                deleteFile: function(id) {
     218                        if ( confirm("Are you sure you want to delete the file '" + this.currentImage.title + "'?\nClick ok to delete or cancel to go back.") ) {
     219                                $('action-value').value = 'delete';
     220                                $('upload-file').submit();
     221                                return true;
     222                        }
     223                        return false;
     224                }
     225                       
     226        };
     227        theFileList.initializeVars();
     228        theFileList.initializeLinks();
     229} );
  • wp-admin/edit-page-form.php

     
    156156<?php
    157157if (current_user_can('upload_files')) {
    158158        $uploading_iframe_ID = (0 == $post_ID ? $temp_ID : $post_ID);
    159         $uploading_iframe_src = wp_nonce_url("inline-uploading.php?action=view&amp;post=$uploading_iframe_ID", 'inlineuploading');
     159        $uploading_iframe_src = wp_nonce_url("upload.php?style=inline&amp;tab=upload&amp;post_id=$uploading_iframe_ID", 'inlineuploading');
    160160        $uploading_iframe_src = apply_filters('uploading_iframe_src', $uploading_iframe_src);
    161161        if ( false != $uploading_iframe_src )
    162162                echo '<iframe id="uploading" frameborder="0" src="' . $uploading_iframe_src . '">' . __('This feature requires iframe support.') . '</iframe>';
  • wp-admin/upload.php

     
     1<?php
     2require_once('admin.php');
     3
     4@header('Content-type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
     5
     6if (!current_user_can('upload_files'))
     7        wp_die(__('You do not have permission to upload files.'));
     8
     9wp_reset_vars(array('action', 'tab', 'from_tab', 'style', 'post_id', 'ID', 'paged', 'post_title', 'post_content', 'delete'));
     10
     11require_once('upload-functions.php');
     12if ( !$tab )
     13        $tab = 'browse-all';
     14
     15do_action( "upload_files_$tab" );
     16
     17add_action( 'admin_head', 'wp_upload_admin_head' );
     18
     19$pid = 0;
     20if ( $post_id < 0 )
     21        $pid = $post_id;
     22elseif ( get_post( $post_id ) )
     23        $pid = $post_id;
     24$wp_upload_tabs = array();
     25$all_atts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'attachment'");
     26$post_atts = 0;
     27if ( $pid ) {
     28        $wp_upload_tabs['upload'] = array(__('Upload'), 'upload_files', 'wp_upload_tab_upload');
     29        if ( $all_atts && $post_atts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = '$post_id'") )
     30                $wp_upload_tabs['browse'] = array(__('Browse'), 'upload_files', "wp_upload_tab_browse");
     31        if ( $post_atts < $all_atts )
     32                $wp_upload_tabs['browse-all'] = array(__('Browse All'), 'upload_files', 'wp_upload_tab_browse');
     33} else
     34        $wp_upload_tabs['browse-all'] = array(__('Browse All'), 'upload_files', 'wp_upload_tab_browse');
     35
     36        $wp_upload_tabs = array_merge($wp_upload_tabs, apply_filters( 'wp_upload_tabs', array() ));
     37
     38if ( !function_exists($wp_upload_tabs[$tab][2]) ) {
     39        $to_tab = isset($wp_upload_tabs['upload']) ? 'upload' : 'browse-all';
     40        wp_redirect( add_query_arg( 'tab', $to_tab ) );
     41        exit;
     42}
     43
     44foreach ( $wp_upload_tabs as $t => $tab_array ) {
     45        if ( !current_user_can( $tab_array[1] ) ) {
     46                unset($wp_upload_tabs[$t]);
     47                if ( $tab == $t )
     48                        wp_die(__("You are not allowed to be here"));
     49        }
     50}
     51
     52include_once('admin-header.php');
     53
     54echo "<ul id='upload-menu'>\n";
     55foreach ( $wp_upload_tabs as $t => $tab_array ) { // We've already done the current_user_can check
     56        $class = 'upload-tab';
     57        $href = add_query_arg( array('tab' => $t, 'ID' => '', 'action' => '') );
     58        if ( isset($tab_array[3]) && is_array($tab_array[3]) )
     59                add_query_arg( $tab_array[3], $href );
     60        $_href = wp_specialchars( $href, 1 );
     61        if ( $tab == $t )
     62                $class .= ' current';
     63        echo "\t<li class='$class left'><a href='$_href' title='{$tab_array[0]}'>{$tab_array[0]}</a></li>\n";
     64}
     65echo "</ul>\n\n";
     66
     67echo "<div id='upload-content'>\n";
     68
     69call_user_func( $wp_upload_tabs[$tab][2] );
     70
     71echo "</div>\n";
     72
     73include_once('admin-footer.php');
     74?>
  • wp-admin/upload-rtl.css

     
     1body { font: 13px Tahoma, "Lucida Grande", "Lucida Sans Unicode", Verdana; }
     2
     3#upload-menu li { margin: 0 .75em 0 0; }
     4
     5#upload-menu .current a {
     6        border-right: 0;
     7        border-left: 2px solid #448abd;
     8}
     9
     10#file-title { margin: 0 15px 0 0; }
     11
     12h2 { margin: 0 0 0 .2em; }
     13
     14#upload-files li { margin: 0 15px 15px 0; }
     15
     16th { text-align: right; }
     17
     18.left, table { float: right; }
     19
     20.right, #the-attachment-links { float: left; }
     21
     22#submit input, #submit input:focus {
     23        border-left: 0;
     24        border-right-color: #ccc;
     25}
     26
     27#submit input:active {
     28        border-left: 0;
     29        border-right-color: #999;
     30}
  • wp-admin/edit-form-advanced.php

     
    183183<?php
    184184if (current_user_can('upload_files')) {
    185185        $uploading_iframe_ID = (0 == $post_ID ? $temp_ID : $post_ID);
    186         $uploading_iframe_src = wp_nonce_url("inline-uploading.php?action=view&amp;post=$uploading_iframe_ID", 'inlineuploading');
     186        $uploading_iframe_src = wp_nonce_url("upload.php?style=inline&amp;tab=upload&amp;post_id=$uploading_iframe_ID", 'inlineuploading');
    187187        $uploading_iframe_src = apply_filters('uploading_iframe_src', $uploading_iframe_src);
    188188        if ( false != $uploading_iframe_src )
    189189                echo '<iframe id="uploading" frameborder="0" src="' . $uploading_iframe_src . '">' . __('This feature requires iframe support.') . '</iframe>';
  • wp-admin/upload-functions.php

     
     1<?php
     2function wp_upload_display( $dims = false, $href = '' ) {
     3        global $post;
     4        $id = get_the_ID();
     5        $attachment_data = get_post_meta( $id, '_wp_attachment_metadata', true );
     6        if ( isset($attachment_data['width']) )
     7                list($width,$height) = wp_shrink_dimensions($attachment_data['width'], $attachment_data['height'], 171, 128);
     8        ob_start();
     9                the_title();
     10                $post_title = wp_specialchars( ob_get_contents(), 1 );
     11        ob_end_clean();
     12        $post_content = apply_filters( 'content_edit_pre', $post->post_content );
     13       
     14        $class = 'text';
     15        $innerHTML = get_attachment_innerHTML( $id, false, $dims );
     16        if ( $image_src = strstr($innerHTML, 'src="') ) {
     17                $image_src = explode('"', $image_src);
     18                $image_src = $image_src[1];
     19                $class = 'image';
     20                $innerHTML = '&nbsp;' . $innerHTML;
     21        }
     22
     23        $r = '';
     24
     25        if ( $href )
     26                $r .= "<a id='file-link-$id' href='$href' title='$post_title' class='file-link $class'>\n";
     27        if ( $href || $image_src )
     28                $r .= "\t\t\t$innerHTML";
     29        if ( $href )
     30                $r .= "</a>\n";
     31        $r .= "\n\t\t<div class='upload-file-data'>\n\t\t\t<p>\n";
     32        $r .= "\t\t\t\t<input type='hidden' name='attachment-url-$id' id='attachment-url-$id' value='" . get_the_guid() . "' />\n";
     33
     34        if ( $image_src )
     35                $r .= "\t\t\t\t<input type='hidden' name='attachment-thumb-url-$id' id='attachment-thumb-url-$id' value='$image_src' />\n";
     36        if ( isset($width) ) {
     37                $r .= "\t\t\t\t<input type='hidden' name='attachment-width-$id' id='attachment-width-$id' value='$width' />\n";
     38                $r .= "\t\t\t\t<input type='hidden' name='attachment-height-$id' id='attachment-height-$id' value='$height' />\n";
     39        }
     40        $r .= "\t\t\t\t<input type='hidden' name='attachment-page-url-$id' id='attachment-page-url-$id' value='" . get_attachment_link( $id ) . "' />\n";
     41        $r .= "\t\t\t\t<input type='hidden' name='attachment-title-$id' id='attachment-title-$id' value='$post_title' />\n";
     42        $r .= "\t\t\t\t<input type='hidden' name='attachment-description-$id' id='attachment-description-$id' value='$post_content' />\n";
     43        $r .= "\t\t\t</p>\n\t\t</div>\n";
     44        return $r;
     45}
     46
     47function wp_upload_view() {
     48        global $style, $post_id;
     49        $id = get_the_ID();
     50?>
     51        <div id="upload-file">
     52                <div id="file-title">
     53                        <h2><a href="<?php the_guid(); ?>" title="Direct link to this file"><?php the_title(); ?></a></h2>
     54                        <span><?php
     55                                echo '[&nbsp;';
     56                                echo '<a href="' . get_permalink() . '" title="' . ('Permalink to the blog page for this file') . '">' . __('page link') . '</a>';
     57                                echo '&nbsp;|&nbsp;';
     58                                        echo '<a href="' . wp_specialchars( add_query_arg( 'action', 'edit' ), 1 ) . '" title="' . __('Edit this file') . '">' . __('edit') . '</a>';
     59                                echo '&nbsp;|&nbsp;';
     60                                echo '<a href="' . wp_specialchars( remove_query_arg( array('action', 'ID') ), 1 ) . '" title="' . __('Browse your files') . '">' . __('cancel') . '</a>';
     61                                echo '&nbsp;]'; ?></span>
     62                </div>
     63
     64                <div id="upload-file-view" class="left">
     65<?php   echo wp_upload_display( array(171, 128)  ); ?>
     66                </div>
     67                <?php the_attachment_links( $id ); ?>
     68        </div>
     69<?php
     70}
     71
     72function wp_upload_form() {
     73        $id = get_the_ID();
     74        global $post_id, $tab, $style;
     75        $enctype = $id ? '' : ' enctype="multipart/form-data"';
     76?>
     77        <form<?php echo $enctype; ?> id="upload-file" method="post" action="<?php echo get_option('siteurl') . "/wp-admin/upload.php?style=$style&amp;tab=upload&amp;post_id=$post_id"; ?>">
     78<?php
     79        if ( $id ) :
     80                $attachment = get_post_to_edit( $id );
     81?>
     82                <div id="file-title">
     83                        <h2><a href="<?php the_guid(); ?>" title="Direct link to this file"><?php the_title(); ?></a></h2>
     84                        <span><?php
     85                                echo '[&nbsp;';
     86                                echo '<a href="' . get_permalink() . '" title="' . ('Permalink to the blog page for this file') . '">' . __('page link') . '</a>';
     87                                echo '&nbsp;|&nbsp;';
     88                                        echo '<a href="' . wp_specialchars( add_query_arg( 'action', 'view' ), 1 ) . '" title="' . __('View options for this file') . '">' . __('options') . '</a>';
     89                                echo '&nbsp;|&nbsp;';
     90                                echo '<a href="' . wp_specialchars( remove_query_arg( array('action','ID') ), 1 ) . '" title="' . __('Browse your files') . '">' . __('cancel') . '</a>';
     91                                echo '&nbsp;]'; ?></span>
     92                </div>
     93
     94        <div id="upload-file-view" class="left">
     95<?php           echo wp_upload_display( array(171, 128) ); ?>
     96        </div>
     97<?php   endif; ?>
     98                <table>
     99<?php   if ( !$id ): ?>
     100                        <tr>
     101                                <th scope="row"><label for="upload"><?php _e('File:'); ?></label></th>
     102                                <td><input type="file" id="upload" name="image" /></td>
     103                        </tr>
     104<?php   endif; ?>
     105                        <tr>
     106                                <th scope="row"><label for="post_title"><?php _e('Title:'); ?></label></th>
     107                                <td><input type="text" id="post_title" name="post_title" value="<?php echo $attachment->post_title; ?>" /></td>
     108                        </tr>
     109                        <tr>
     110                                <th scope="row"><label for="post_content"><?php _e('Description:'); ?></label></th>
     111                                <td><textarea name="post_content" id="post_content"><?php echo $attachment->post_content; ?></textarea></td>
     112                        </tr>
     113                        <tr id="buttons">
     114                                <th></th>
     115                                <td>
     116                                        <input type="hidden" name="from_tab" value="<?php echo $tab; ?>" />
     117                                        <input type="hidden" name="action" value="<?php echo $id ? 'save' : 'upload'; ?>" />
     118<?php   if ( $post_id ) : ?>
     119                                        <input type="hidden" name="post_id" value="<?php echo $post_id; ?>" />
     120<?php   endif; if ( $id ) : ?>
     121                                        <input type="hidden" name="ID" value="<?php echo $id; ?>" />
     122<?php   endif; ?>
     123                                        <?php wp_nonce_field( 'inlineuploading' ); ?>
     124                                        <div id="submit">
     125                                                <input type="submit" value="<?php $id ? _e('Save') : _e('Upload'); ?>" />
     126<?php   if ( $id ) : ?>
     127                                                <input type="submit" name="delete" class="delete" value="<?php _e('Delete'); ?>" />
     128<?php   endif; ?>
     129                                        </div>
     130                                </td>
     131                        </tr>
     132                </table>
     133        </form>
     134<?php
     135}
     136
     137function wp_upload_tab_upload() {
     138        wp_upload_form();
     139}
     140
     141function wp_upload_tab_upload_action() {
     142        global $action;
     143        if ( isset($_POST['delete']) )
     144                $action = 'delete';
     145
     146        switch ( $action ) :
     147        case 'upload' :
     148                global $from_tab, $post_id, $style;
     149                if ( !$from_tab )
     150                        $from_tab = 'upload';
     151
     152                check_admin_referer( 'inlineuploading' );
     153
     154                global $post_id, $post_title, $post_content;
     155
     156                if ( !current_user_can( 'upload_files' ) )
     157                        wp_die( __('You are not allowed to upload files.')
     158                                . " <a href='" . get_option('siteurl') . "/wp-admin/upload.php?style=$style&amp;tab=browse-all&amp;post_id=$post_id'>"
     159                                . __('Browse Files') . '</a>'
     160                        );
     161
     162                $overrides = array('action'=>'upload');
     163
     164                $file = wp_handle_upload($_FILES['image'], $overrides);
     165
     166                if ( isset($file['error']) )
     167                        wp_die($file['error'] . "<br /><a href='" . get_option('siteurl')
     168                        . "/wp-admin/upload.php?style=$style&amp;tab=$from_tab&amp;post_id=$post_id'>'" . __('Back to Image Uploading') . '</a>'
     169                );
     170
     171                $url = $file['url'];
     172                $type = $file['type'];
     173                $file = $file['file'];
     174                $filename = basename($file);
     175
     176                // Construct the attachment array
     177                $attachment = array(
     178                        'post_title' => $post_title ? $post_title : $filename,
     179                        'post_content' => $post_content,
     180                        'post_type' => 'attachment',
     181                        'post_parent' => $post_id,
     182                        'post_mime_type' => $type,
     183                        'guid' => $url
     184                );
     185
     186                // Save the data
     187                $id = wp_insert_attachment($attachment, $file, $post_id);
     188
     189                if ( preg_match('!^image/!', $attachment['post_mime_type']) ) {
     190                        // Generate the attachment's postmeta.
     191                        $imagesize = getimagesize($file);
     192                        $imagedata['width'] = $imagesize['0'];
     193                        $imagedata['height'] = $imagesize['1'];
     194                        list($uwidth, $uheight) = get_udims($imagedata['width'], $imagedata['height']);
     195                        $imagedata['hwstring_small'] = "height='$uheight' width='$uwidth'";
     196                        $imagedata['file'] = $file;
     197
     198                        add_post_meta($id, '_wp_attachment_metadata', $imagedata);
     199
     200                        if ( $imagedata['width'] * $imagedata['height'] < 3 * 1024 * 1024 ) {
     201                                if ( $imagedata['width'] > 128 && $imagedata['width'] >= $imagedata['height'] * 4 / 3 )
     202                                        $thumb = wp_create_thumbnail($file, 128);
     203                                elseif ( $imagedata['height'] > 96 )
     204                                        $thumb = wp_create_thumbnail($file, 96);
     205
     206                                if ( @file_exists($thumb) ) {
     207                                        $newdata = $imagedata;
     208                                        $newdata['thumb'] = basename($thumb);
     209                                        update_post_meta($id, '_wp_attachment_metadata', $newdata, $imagedata);
     210                                } else {
     211                                        $error = $thumb;
     212                                }
     213                        }
     214                } else {
     215                        add_post_meta($id, '_wp_attachment_metadata', array());
     216                }
     217
     218                wp_redirect( get_option('siteurl') . "/wp-admin/upload.php?style=$style&tab=browse&action=view&ID=$id&post_id=$post_id");
     219                die;
     220                break;
     221
     222        case 'save' :
     223                global $from_tab, $post_id, $style;
     224                if ( !$from_tab )
     225                        $from_tab = 'upload';
     226                check_admin_referer( 'inlineuploading' );
     227
     228                wp_update_post($_POST);
     229                wp_redirect( get_option('siteurl') . "/wp-admin/upload.php?style=$style&tab=$from_tab&post_id=$post_id");
     230                die;
     231                break;
     232
     233        case 'delete' :
     234                global $ID, $post_id, $from_tab, $style;
     235                if ( !$from_tab )
     236                        $from_tab = 'upload';
     237
     238                check_admin_referer( 'inlineuploading' );
     239
     240                if ( !current_user_can('edit_post', (int) $ID) )
     241                        wp_die( __('You are not allowed to delete this attachment.')
     242                                . " <a href='" . get_option('siteurl') . "/wp-admin/upload.php?style=$style&amp;tab=$from_tab&amp;post_id=$post_id'>"
     243                                . __('Go back') . '</a>'
     244                        );
     245
     246                wp_delete_attachment($ID);
     247
     248                wp_redirect( get_option('siteurl') . "/wp-admin/upload.php?style=$style&tab=$from_tab&post_id=$post_id" );
     249                die;
     250                break;
     251
     252        endswitch;
     253}
     254
     255add_action( 'upload_files_upload', 'wp_upload_tab_upload_action' );
     256
     257function wp_upload_grab_attachments( $obj ) {
     258        $obj->is_attachment = true;
     259}
     260
     261function wp_upload_posts_where( $where ) {
     262        global $post_id;
     263        return $where . " AND post_parent = '" . (int) $post_id . "'";
     264}
     265
     266function wp_upload_tab_browse() {
     267        global $wpdb, $action, $paged;
     268        $old_vars = compact( 'paged' );
     269       
     270        switch ( $action ) :
     271        case 'edit' :
     272        case 'view' :
     273                global $ID;
     274                $attachments = query_posts("attachment_id=$ID");
     275                if ( have_posts() ) : while ( have_posts() ) : the_post();
     276                        'edit' == $action ? wp_upload_form() : wp_upload_view();
     277                endwhile; endif;
     278                break;
     279        default :
     280                global $tab, $post_id;
     281                add_action( 'pre_get_posts', 'wp_upload_grab_attachments' );
     282                if ( 'browse' == $tab && $post_id )
     283                        add_filter( 'posts_where', 'wp_upload_posts_where' );
     284                $attachments = query_posts("what_to_show=posts&posts_per_page=10&paged=$paged");
     285                $count_query = "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'attachment'";
     286                if ( $post_id )
     287                        $count_query .= " AND post_parent = '$post_id'";
     288                $total =  $wpdb->get_var($count_query);
     289
     290                echo "<ul id='upload-files'>\n";
     291                if ( have_posts() ) : while ( have_posts() ) : the_post();
     292                        $href = wp_specialchars( add_query_arg( array('action' => 'view', 'ID' => get_the_ID()) ), 1 );
     293
     294                        echo "\t<li id='file-";
     295                        the_ID();
     296                        echo "' class='left'>\n";
     297                        echo wp_upload_display( array(128,128), $href );
     298                        echo "\t</li>\n";
     299                endwhile;
     300                else :
     301                        echo "\t<li>" . __('There are no attachments to show.') . "</li>\n";
     302                endif;
     303                echo "</ul>\n\n";
     304
     305                echo "<form action='' id='browse-form'><input type='hidden' id='nonce-value' value='" . wp_create_nonce( 'inlineuploading' )  . "' /></form>\n";
     306
     307//              echo $total;
     308                break;
     309        endswitch;
     310
     311        extract($old_vars);
     312}
     313
     314
     315function wp_upload_tab_browse_action() {
     316        wp_enqueue_script('upload');
     317}
     318
     319add_action( 'upload_files_browse', 'wp_upload_tab_browse_action' );
     320add_action( 'upload_files_browse-all', 'wp_upload_tab_browse_action' );
     321
     322function wp_upload_admin_head() {
     323        global $wp_locale;
     324        echo "<link rel='stylesheet' href='" . get_option('siteurl') . '/wp-admin/upload.css?version=' . get_bloginfo('version') . "' type='text/css' />\n";
     325        if ( 'rtl' == $wp_locale->text_direction )
     326                echo "<link rel='stylesheet' href='" . get_option('siteurl') . '/wp-admin/upload-rtl.css?version=' . get_bloginfo('version') . "' type='text/css' />\n";
     327        if ( 'inline' == @$_GET['style'] ) {
     328                echo "<style type='text/css'>\n";
     329                echo "\t#wphead, #user_info, #adminmenu, #submenu, #footer { display: none; }\n";
     330                echo "\tbody { height: 14em; overflow: hidden; }\n";
     331                echo "\t#upload-content { overflow-y: auto; }\n";
     332                echo "\t#upload-file { position: absolute; }\n";
     333                echo "</style>";
     334        }
     335}
     336
  • wp-admin/menu.php

     
    3030
    3131$submenu['edit.php'][5] = array(__('Posts'), 'edit_posts', 'edit.php');
    3232$submenu['edit.php'][10] = array(__('Pages'), 'edit_pages', 'edit-pages.php');
     33$submenu['edit.php'][12] = array(__('Uploads'), 'upload_files', 'upload.php');
    3334$submenu['edit.php'][15] = array(__('Categories'), 'manage_categories', 'categories.php');
    3435$submenu['edit.php'][20] = array(__('Comments'), 'edit_posts', 'edit-comments.php');
    3536$awaiting_mod = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'");
     
    124125        }
    125126}
    126127
     128unset($id);
     129
    127130ksort($menu); // make it all pretty
    128131
    129132if (! user_can_access_admin_page()) {
  • wp-admin/upload.css

     
     1body { background: #dfe8f1; }
     2
     3.upload-file-data { display: none; }
     4
     5#upload-menu {
     6        background: #fff;
     7        margin: 0px;
     8        padding: 0;
     9        list-style: none;
     10        height: 2em;
     11        border-bottom: 1px solid #448abd;
     12        width: 100%;
     13}
     14
     15#upload-menu li { margin: 0 0 0 .75em; }
     16
     17#upload-menu a {
     18        display: block;
     19        padding: 5px;
     20        color: #000;
     21        border-top: 3px solid #fff;
     22        text-decoration: none;
     23        border-bottom: none;
     24}
     25
     26#upload-menu .current a {
     27        background: #dfe8f1;
     28        border-right: 2px solid #448abd;
     29}
     30
     31#upload-menu a:hover {
     32        background: #dfe8f1;
     33        color: #000;
     34}
     35
     36#upload-content {
     37        position: relative;
     38        clear: both;
     39        margin: 0;
     40        padding: 0;
     41        border: none;
     42        width: 100%;
     43        height: 100%;
     44        background: none;
     45}
     46
     47#upload-file {
     48        position: relative;
     49        margin: 0;
     50        top: 0;
     51        left: 0;
     52        width: 100%;
     53        height: 100%;
     54        background: #dfe8f1;
     55}
     56
     57#upload-file-view { padding: 0 15px; }
     58
     59#file-title {
     60        margin: 0 0 0 15px;
     61        padding: 0;
     62        display: block;
     63}
     64
     65h2 {
     66        margin: 0 .2em 0 0;
     67        padding: 0;
     68        display: inline;
     69        border: none;
     70        font-weight: bold;
     71        font-size: 1.4em;
     72        line-height: 1.4em;
     73}
     74
     75#upload-files {
     76        list-style-type: none;
     77        margin: 0;
     78        padding: 15px 0 0;
     79}
     80
     81#upload-files li { margin: 0 0 15px 15px; }
     82
     83#upload-files a, a.file-link {
     84        border: none;
     85        text-decoration: none;
     86}
     87
     88#upload-files a.file-link {
     89        display: block;
     90        width: 130px;
     91        height: 128px;
     92        background-color: rgb(209, 226, 239);
     93        text-align: center;
     94        overflow-y: hidden;
     95}
     96
     97#upload-files a.file-link.image {
     98        line-height: 128px;
     99        font-size: 2px;
     100        letter-spacing: 0;
     101}
     102
     103#upload-files a.file-link img {
     104        vertical-align: middle;
     105}
     106
     107#the-attachment-links { float: right; }
     108
     109#the-attachment-links textarea {
     110        font-size: 10px;
     111        overflow: hidden;
     112}
     113
     114form table { float: none; }
     115
     116table {
     117        float: left;
     118        margin: 0;
     119        padding: 0 15px;
     120}
     121
     122.left { float: left; }
     123
     124.right { float: right; }
     125
     126.center { text-align: center; }
     127
     128th { text-align: left; }
     129
     130tr, td, th {
     131        margin-top: 0;
     132        padding-top: 0;
     133}
     134
     135#submit {
     136        margin: 1px;
     137        width: 99%;
     138}
     139
     140#submit input, #submit input:focus {
     141        background: url( images/fade-butt.png );
     142        border: 3px double #999;
     143        border-left-color: #ccc;
     144        border-top-color: #ccc;
     145        color: #333;
     146        padding: 0.25em;
     147}
     148
     149#submit input:active {
     150        background: #f4f4f4;
     151        border: 3px double #ccc;
     152        border-left-color: #999;
     153        border-top-color: #999;
     154}
     155
     156#submit input.delete:hover {
     157        background: #ce0000;
     158        color: #fff;
     159}