Make WordPress Core

Changeset 8169


Ignore:
Timestamp:
06/23/2008 04:00:12 PM (17 years ago)
Author:
ryan
Message:

Press This updates from noel. see #6813

Location:
trunk/wp-admin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/css/press-this.css

    r8128 r8169  
    295295}
    296296
     297#img_container a {
     298    display: block;
     299    width: 79px;
     300    height: 79px;
     301    float: left;
     302}
    297303#img_container img {
    298304    width: 75px;
    299305    height: 75px;
     306    border: 0px;
    300307    padding: 2px;
    301308    background-color: #f4f4f4;
    302     margin-right: 7px;
    303     margin-bottom: 7px;
    304309    cursor: pointer;
    305310}
     311#img_container a, #img_container a:link, #img_container a:visited {
     312    border: 2px solid #ccc;
     313    margin: 0 4px 4px 0;
     314}
     315#img_container a:hover, #img_container a:active {
     316    border: 2px solid #000;
     317}
    306318.submit {
    307 -moz-border-radius-bottomleft: 3px;
    308 -khtml-border-bottom-left-radius: 3px;
    309 -webkit-border-bottom-left-radius: 3px;
    310 border-bottom-left-radius: 3px;
    311 -moz-border-radius-bottomright: 3px;
    312 -khtml-border-bottom-right-radius: 3px;
    313 -webkit-border-bottom-right-radius: 3px;
    314 border-bottom-right-radius: 3px;
    315 margin: 0;
    316 padding: 0;
     319    -moz-border-radius-bottomleft: 3px;
     320    -khtml-border-bottom-left-radius: 3px;
     321    -webkit-border-bottom-left-radius: 3px;
     322    border-bottom-left-radius: 3px;
     323    -moz-border-radius-bottomright: 3px;
     324    -khtml-border-bottom-right-radius: 3px;
     325    -webkit-border-bottom-right-radius: 3px;
     326    border-bottom-right-radius: 3px;
     327    margin: 0;
     328    padding: 0;
    317329}
    318330.submitbox {
     
    467479
    468480#post_status {
    469 margin-left: 10px;
    470 margin-bottom: 1em;
    471 display: block;
     481    margin-left: 10px;
     482    margin-bottom: 1em;
     483    display: block;
    472484}
    473485
  • trunk/wp-admin/includes/media.php

    r8067 r8169  
    116116}
    117117
    118 
    119 function media_sideload_image($file, $post_id, $desc = null) {
    120 
    121     if (!empty($file) ) {
    122         // Upload File button was clicked
    123        
    124         $file_array['name'] = basename($file);
    125         $file_array['tmp_name'] = download_url($file);
    126         $desc = @$desc;
    127        
    128         $sideload = media_handle_sideload($file_array, $post_id, $desc);
    129 
    130         $id = $sideload['id'];
    131         $src = $sideload['src'];
    132        
    133         unset($file_array['tmp_name']);
    134         unset($file_array);
    135        
    136         if ( is_wp_error($id) ) {
    137             $errors['upload_error'] = $id;
    138             $id = false;
    139         }
    140     }
    141    
    142     if ( !empty($src) && !strpos($src, '://') )
    143        
    144         $src = "http://$src";
    145         $alt = @$desc;
    146        
    147         if ( !empty($src) )
    148             $html = "<img src='$src' alt='$alt' />";
    149             return $html;
    150    
    151 }
    152 
    153118function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) {
    154119    $overrides = array('test_form'=>false);
     
    187152    if ( !is_wp_error($id) ) {
    188153        wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
    189     }
    190 
    191     return array('id' => $id, 'src' => $url);
     154        return $src;
     155    }
     156   
     157    return $id;
    192158
    193159}
     
    347313
    348314    return wp_iframe( 'media_upload_type_form', 'image', $errors, $id );
     315}
     316
     317function media_sideload_image($file, $post_id, $desc = null) {
     318    if (!empty($file) ) {
     319        $file_array['name'] = basename($file);
     320        $file_array['tmp_name'] = download_url($file);
     321        $desc = @$desc;
     322       
     323        $id = media_handle_sideload($file_array, $post_id, $desc);
     324        unset($file_array);
     325       
     326        if ( is_wp_error($id) ) {
     327            $errors['upload_error'] = $id;
     328            return $id;
     329        } else {
     330            $src = $id;
     331        }
     332    }
     333   
     334    if (!empty($src) && !strpos($src, '://') ) {
     335        $src = "http://$src";
     336        $alt = @$desc;
     337    }
     338    if ( !empty($src) ) {
     339        $html = "<img src='$src' alt='$alt' />";
     340        return $html;
     341    }
    349342}
    350343
  • trunk/wp-admin/press-this.php

    r8128 r8169  
    3131                preg_match('/'.$quoted.'/', $_REQUEST['content'], $matches[0]);
    3232                if($matches[0])
    33                     media_sideload_image($data, $post_ID, $_REQUEST['photo_description'][$key]);   
     33                    $upload = media_sideload_image($data, $post_ID, $_REQUEST['photo_description'][$key]); 
    3434            }
    3535            $content = $_REQUEST['content'];
     
    4646
    4747    #error handling for $post
    48     if ( is_wp_error($post_ID) ) {
     48    if ( is_wp_error($post_ID)) {
    4949        wp_die($id);
    5050        wp_delete_post($post_ID);
    51 
    5251    #error handling for media_sideload
     52    } elseif ( is_wp_error($upload)) {
     53        wp_die($upload);
     54        wp_delete_post($post_ID);
    5355    } else {   
    5456        $quick['ID'] = $post_ID;
     
    7981    </head>
    8082    <body class="press-this">
     83       
    8184        <div id="message" class="updated fade"><p><strong><?php _e('Your post has been saved.'); ?></strong> <a onclick="window.opener.location.replace(this.href); window.close();" href="<?php echo get_permalink( $post_ID); ?>"><?php _e('View post'); ?></a> | <a href="post.php?action=edit&amp;post=<?php echo $post_ID; ?>" onclick="window.opener.location.replace(this.href); window.close();"><?php _e('Edit post'); ?></a> | <a href="#" onclick="window.close();">Close Window</a></p></div>
    8285       
     
    111114
    112115if($_REQUEST['ajax'] == 'thickbox') { ?>
     116    <script type="text/javascript" charset="utf-8">
     117        jQuery('.cancel').click(function() {
     118            tb_remove();
     119        });
     120       
     121        jQuery('.select').click(function() {
     122            image_selector();
     123        });
     124    </script>
    113125    <h3 id="title"><label for="post_title"><?php _e('Description') ?></label></h3>
    114126    <div class="titlewrap">
     
    124136
    125137if($_REQUEST['ajax'] == 'thickbox_url') { ?>
     138    <script type="text/javascript" charset="utf-8">
     139        jQuery('.cancel').click(function() {
     140            tb_remove();
     141        });
     142       
     143        jQuery('.select').click(function() {
     144            image_selector();
     145        });
     146    </script>
    126147    <h3 id="title"><label for="post_title"><?php _e('URL') ?></label></h3>
    127148    <div class="titlewrap">
     
    182203
    183204if($_REQUEST['ajax'] == 'photo_js') { ?>
    184 
    185             tb_init('a.thickbox, area.thickbox, input.thickbox'); //pass where to apply thickbox
     205   
     206   
     207    // gather images and load some default JS
     208   
     209    var last = null
     210    var img, img_tag, aspect, w, h, skip, i, strtoappend = "";
     211    var my_src = eval(
     212        jQuery.ajax({
     213            type: "GET",
     214            url: "<?php echo clean_url($_SERVER['PHP_SELF']); ?>",
     215            cache : false,
     216            async : false,
     217            data: "ajax=photo_images&u=<?php echo urlencode($url); ?>",
     218            dataType : "script"
     219        }).responseText
     220    );
     221   
     222    for (i = 0; i < my_src.length; i++) {
     223        img = new Image();
     224        img.src = my_src[i];
     225        img_attr = 'id="img' + i + '"';
     226        skip = false;
     227        if (img.width && img.height) {
     228            if (img.width * img.height < 2500)
     229                skip = true;
     230            aspect = img.width / img.height;
     231            scale = (aspect > 1) ? (75 / img.width) : (75 / img.height);
    186232           
    187             function image_selector() {
    188                 desc = jQuery('#this_photo_description').val();
    189                 src = jQuery('#this_photo').val();
    190                 pick(src, desc);
    191                 tb_remove();
    192                 return false;
     233            w = img.width;
     234            h = img.height;
     235           
     236            if (scale < 1) {
     237                w = parseInt(img.width * scale);
     238                h = parseInt(img.height * scale);
    193239            }
    194            
    195             jQuery(document).ready(function() {
    196                 jQuery('#this_photo').focus();
    197 
    198                 jQuery('.cancel').click(function() {
    199                     tb_remove();
    200                 });
    201                
    202                 jQuery('.select').click(function() {
    203                     image_selector();
    204                 });
    205                
    206                 jQuery('#photo_add_url').attr('href', '?ajax=thickbox_url&height=200&width=500');
    207                
    208             });
    209            
    210            
    211             function pick(img, desc) {
    212                 if (img) {
    213                     length = jQuery('.photolist input').length;
    214                     if(length == 0) length = 1;
    215                     jQuery('.photolist').append('<input name="photo_src[' + length + ']" value="' + img +'" type="hidden"/>');
    216                     jQuery('.photolist').append('<input name="photo_description[' + length + ']" value="' + desc +'" type="hidden"/>');
    217                     append_editor('<img src="' + img +'" alt="' + desc + '" />'); }
    218                     tinyMCE.activeEditor.resizeToContent();
    219                 return false;
    220             }
    221 
    222             var last = null
    223             var my_src, img, img_tag, aspect, w, h, skip, i, strtoappend = "";
    224             var my_src = eval(
    225             jQuery.ajax({
    226                 type: "GET",
    227                 url: "<?php echo clean_url($_SERVER['PHP_SELF']); ?>",
    228                 cache : false,
    229                 async : false,
    230                 data: "ajax=photo_images&u=<?php echo urlencode($url); ?>",
    231                 dataType : "script"
    232                 }).responseText);
    233 
    234             for (i = 0; i < my_src.length; i++) {
    235                 img = new Image(); img.src = my_src[i]; img_attr = 'id="img' + i; skip = false;
    236 
    237                 if (img.width && img.height) {
    238                     if (img.width * img.height < 2500)
    239                         skip = true;
    240                     aspect = img.width / img.height;
    241                     scale = (aspect > 1) ? (75 / img.width) : (75 / img.height);
    242                    
    243                     if (scale < 1) {
    244                         w = parseInt(img.width * scale);
    245                         h = parseInt(img.height * scale);
    246                     } else {
    247                         w = img.width;
    248                         h = img.height;
    249                     }
    250                     img_attr += ' style="width: ' + w + 'px; height: ' + h + 'px;"';
    251                 }
    252 
    253                 if (!skip) strtoappend += '<a href="?ajax=thickbox&amp;i=' + img.src + '&amp;u=<?php echo $url; ?>&amp;height=400&amp;width=500" title="" class="thickbox"><img src="' + img.src + '" ' + img_attr + '/></a>';
    254 
    255             }
    256             jQuery('#img_container').html(strtoappend);
    257 
     240            img_attr += ' style="width: ' + w + 'px; height: ' + h + 'px;"';
     241        }
     242        if (!skip) strtoappend += '<a href="?ajax=thickbox&amp;i=' + img.src + '&amp;u=<?php echo $url; ?>&amp;height=400&amp;width=500" title="" class="thickbox"><img src="' + img.src + '" ' + img_attr + '/></a>';
     243    }
     244   
     245    function pick(img, desc) {
     246        if (img) {
     247            length = jQuery('.photolist input').length;
     248            if(length == 0) length = 1;
     249            jQuery('.photolist').append('<input name="photo_src[' + length + ']" value="' + img +'" type="hidden"/>');
     250            jQuery('.photolist').append('<input name="photo_description[' + length + ']" value="' + desc +'" type="hidden"/>');
     251            append_editor('<img src="' + img +'" alt="' + desc + '" />');
     252        }
     253        tinyMCE.activeEditor.resizeToContent();
     254        return false;
     255    }
     256   
     257    function image_selector() {
     258        tb_remove();
     259        desc = jQuery('#this_photo_description').val();
     260        src = jQuery('#this_photo').val();
     261        pick(src, desc);
     262        return false;
     263    }
     264   
     265    jQuery(document).ready(function() {
     266        jQuery('#img_container').html(strtoappend);
     267        jQuery('#photo_add_url').attr('href', '?ajax=thickbox_url&height=200&width=500');
     268        tb_init('a.thickbox, area.thickbox, input.thickbox');
     269    });
     270   
    258271<?php die; }
    259272
     
    293306            (function() {
    294307                var base = tinymce.baseURL, sl = tinymce.ScriptLoader, ln = "<?php echo $language; ?>";
    295 
    296308                sl.markDone(base + '/langs/' + ln + '.js');
    297309                sl.markDone(base + '/themes/advanced/langs/' + ln + '.js');
     
    355367        jQuery("#post_type").val(type);
    356368    }
     369   
    357370    function set_editor(text) {
    358371
     
    360373        if(tinyMCE.activeEditor) tinyMCE.execCommand('mceInsertContent' ,false, text);
    361374    }
     375   
    362376    function append_editor(text) {
    363377        if(tinyMCE.activeEditor) tinyMCE.execCommand('mceInsertContent' ,false, text);
    364378    }
     379   
    365380    function set_title(title) { jQuery("#content_type").text(title); }
    366381
     
    372387                set_menu('text');
    373388                set_title('<?php _e('Post') ?>');
    374 
    375389                return false;
    376             break;
     390                break;
    377391            case 'quote' :
    378392                set_menu('quote');
     
    380394                set_editor("<blockquote><p><?php echo $selection; ?> </p><p><cite><a href='<?php echo $url; ?>'><?php echo $title; ?> </a> </cite> </p></blockquote>");
    381395                return false;
    382             break;
     396                break;
    383397            case 'video' :
    384 
    385398                set_menu('video');
    386399                set_title('<?php _e('Caption') ?>');
     
    389402                jQuery('body').addClass('video_split');
    390403                jQuery('#extra_fields').load('<?php echo clean_url($_SERVER['PHP_SELF']); ?>', { ajax: 'video', s: '<?php echo attribute_escape($selection); ?>'}, function() {
    391                    
    392404                    <?php
    393405                    if ( preg_match("/youtube\.com\/watch/i", $url) ) {
     
    408420                    set_editor("<?php echo $title; ?>");
    409421                });
    410                
    411422                return false;
    412             break;
    413            
     423                break;
    414424            case 'photo' :
    415425                set_menu('photo');
     
    431441                    }
    432442                });
    433                
    434443                return false;
    435             break;
    436 
     444                break;
    437445        }
    438    
    439446    }
    440447   
     
    446453        });
    447454       
     455        // Set default tabs
    448456        <?php if ( preg_match("/youtube\.com\/watch/i", $url) ) { ?>
    449457            show('video');
     
    454462        <?php } ?>
    455463    });
     464   
    456465</script>
    457466</head>
    458467<body class="press-this">
    459468<div id="wphead">
    460 <h1><span id="viewsite"><a href="<?php echo get_option('home'); ?>/"><?php _e('Visit:') ?> <?php bloginfo('name'); ?></a></span></h1>
     469    <h1><span id="viewsite"><a href="<?php echo get_option('home'); ?>/"><?php _e('Visit:') ?> <?php bloginfo('name'); ?></a></span></h1>
    461470</div>
    462471
    463         <ul id="menu" class="ui-tabs-nav">
    464             <li id="text_button" class="ui-tabs-selected"><a href="#"><?php _e('Text') ?></a></li>
    465             <li id="photo_button"><a href="#"><?php _e('Photo') ?></a></li>
    466             <li id="quote_button"><a href="#"><?php _e('Quote') ?></a></li>
    467             <li id="video_button"><a href="#"><?php _e('Video') ?></a></li>
    468         </ul>
    469 
    470             <form action="press-this.php?action=post" method="post">
    471 
    472                 <?php wp_nonce_field('press-this') ?>
    473                 <input type="hidden" name="post_type" id="post_type" value="text"/>
    474                 <div id="posting">
    475                    
    476                     <h2 id="title"><label for="post_title"><?php _e('Title') ?></label></h2>
    477                     <div class="titlewrap">
    478                         <input name="post_title" id="post_title" class="text" value="<?php echo attribute_escape($title);?>"/>
    479                     </div>
    480                    
    481                     <div id="extra_fields" style="display: none"></div>
    482                     <div class="editor_area">
    483                     <h2 id="content_type"><label for="content"><?php _e('Post') ?></label></h2>
    484                     <div class="editor-container">
    485                         <textarea name="content" id="content" style="width:100%;" class="mceEditor"><?php if($selection) { ?><a href='<?php echo $url ?>'><?php echo $selection ?></a><?php } else { ?><a href='<?php echo $url ?>'><?php echo $title; ?></a><?php } ?></textarea>
    486                     </div>
    487                     </div>
    488                    
    489                 </div>
    490                 <div id="categories">
    491                     <div class="submitbox" id="submitpost">
    492                     <div id="previewview"></div>
    493                     <div class="inside">
    494                         <h2><?php _e('Categories') ?></h2>
    495                         <div id="categories-all">
    496                             <ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
    497                                 <?php wp_category_checklist() ?>
    498                             </ul>
    499                         </div>
    500                         <h2><?php _e('Tags') ?></h2>
    501                         <p id="jaxtag"><label class="hidden" for="newtag"><?php _e('Tags'); ?></label><input type="text" name="tags_input" class="tags-input" id="tags-input" size="40" tabindex="3" value="<?php echo get_tags_to_edit( $post->ID ); ?>" /></p>
    502                         <div id="tagchecklist"></div>
    503                     </div>
    504                     <label for="post_status" id="post_status"><input type="radio" name="post_status" value="publish" checked="checked" id="published" />Published <input type="radio" name="post_status" value="draft" id="unpubplished" /> Unpublished</label>
    505                    
    506                     <p class="submit">         
    507                         <input type="submit" value="<?php _e('Publish') ?>" onclick="document.getElementById('photo_saving').style.display = '';"/>
    508                         <img src="images/loading-publish.gif" alt="" id="photo_saving" style="display:none;"/>
    509                     </p>
    510                 </div>
    511                
    512                
    513             </form>     
    514                    
     472<ul id="menu" class="ui-tabs-nav">
     473    <li id="text_button" class="ui-tabs-selected"><a href="#"><?php _e('Text') ?></a></li>
     474    <li id="photo_button"><a href="#"><?php _e('Photo') ?></a></li>
     475    <li id="quote_button"><a href="#"><?php _e('Quote') ?></a></li>
     476    <li id="video_button"><a href="#"><?php _e('Video') ?></a></li>
     477</ul>
     478
     479<form action="press-this.php?action=post" method="post">
     480    <?php wp_nonce_field('press-this') ?>
     481    <input type="hidden" name="post_type" id="post_type" value="text"/>
     482    <div id="posting">
     483        <h2 id="title"><label for="post_title"><?php _e('Title') ?></label></h2>
     484        <div class="titlewrap">
     485            <input name="post_title" id="post_title" class="text" value="<?php echo attribute_escape($title);?>"/>
     486        </div>
     487       
     488        <div id="extra_fields" style="display: none"></div>
     489       
     490        <div class="editor_area">
     491            <h2 id="content_type"><label for="content"><?php _e('Post') ?></label></h2>
     492            <div class="editor-container">
     493                <textarea name="content" id="content" style="width:100%;" class="mceEditor"><?php if($selection) { ?><a href='<?php echo $url ?>'><?php echo $selection ?></a><?php } else { ?><a href='<?php echo $url ?>'><?php echo $title; ?></a><?php } ?></textarea>
     494            </div>
     495        </div>
     496    </div>
     497   
     498    <div id="categories">
     499        <div class="submitbox" id="submitpost">
     500        <div id="previewview"></div>
     501        <div class="inside">
     502            <h2><?php _e('Categories') ?></h2>
     503            <div id="categories-all">
     504                <ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
     505                    <?php wp_category_checklist() ?>
     506                </ul>
     507            </div>
     508            <h2><?php _e('Tags') ?></h2>
     509            <p id="jaxtag"><label class="hidden" for="newtag"><?php _e('Tags'); ?></label><input type="text" name="tags_input" class="tags-input" id="tags-input" size="40" tabindex="3" value="<?php echo get_tags_to_edit( $post->ID ); ?>" /></p>
     510            <div id="tagchecklist"></div>
     511        </div>
     512        <label for="post_status" id="post_status"><input type="radio" name="post_status" value="publish" checked="checked" id="published" />Published <input type="radio" name="post_status" value="draft" id="unpubplished" /> Unpublished</label>
     513        <p class="submit">         
     514            <input type="submit" value="<?php _e('Publish') ?>" onclick="document.getElementById('photo_saving').style.display = '';"/>
     515            <img src="images/loading-publish.gif" alt="" id="photo_saving" style="display:none;"/>
     516        </p>
     517    </div>
     518</form>
    515519</body>
    516520</html>
Note: See TracChangeset for help on using the changeset viewer.