Make WordPress Core

Changeset 11944


Ignore:
Timestamp:
09/17/2009 08:36:59 PM (16 years ago)
Author:
ryan
Message:

Press This fixes. Props noel. fixes #10784

Location:
trunk/wp-admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/media.php

    r11911 r11944  
    250250function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) {
    251251    $overrides = array('test_form'=>false);
     252   
    252253    $file = wp_handle_sideload($file_array, $overrides);
    253 
    254254    if ( isset($file['error']) )
    255255        return new WP_Error( 'upload_error', $file['error'] );
     
    280280    ), $post_data );
    281281
    282     // Save the data
     282    // Save the attachment metadata
    283283    $id = wp_insert_attachment($attachment, $file, $post_id);
    284284    if ( !is_wp_error($id) ) {
     
    521521function media_sideload_image($file, $post_id, $desc = null) {
    522522    if (!empty($file) ) {
    523         $file_array['name'] = basename($file);
     523        // Download file to temp location
    524524        $tmp = download_url($file);
     525       
     526        // Set variables for storage
     527        // fix file filename for query strings
     528        preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $file, $matches);
     529        $file_array['name'] = basename($matches[0]);
    525530        $file_array['tmp_name'] = $tmp;
    526         $desc = @$desc;
    527 
     531
     532        // If error storing temporarily, unlink
    528533        if ( is_wp_error($tmp) ) {
    529534            @unlink($file_array['tmp_name']);
    530535            $file_array['tmp_name'] = '';
    531536        }
    532 
    533         $id = media_handle_sideload($file_array, $post_id, $desc);
     537       
     538        // do the validation and storage stuff
     539        $id = media_handle_sideload($file_array, $post_id, @$desc);
    534540        $src = $id;
    535 
     541       
     542        // If error storing permanently, unlink
    536543        if ( is_wp_error($id) ) {
    537544            @unlink($file_array['tmp_name']);
     
    539546        }
    540547    }
    541 
     548   
     549    // Finally check to make sure the file has been saved, then return the html
    542550    if ( !empty($src) ) {
    543551        $alt = @$desc;
  • trunk/wp-admin/press-this.php

    r11383 r11944  
    4343    // define some basic variables
    4444    $quick['post_status'] = 'draft'; // set as draft first
    45     $quick['post_category'] = isset($_REQUEST['post_category']) ? $_REQUEST['post_category'] : null;
    46     $quick['tax_input'] = isset($_REQUEST['tax_input']) ? $_REQUEST['tax_input'] : '';
    47     $quick['post_title'] = isset($_REQUEST['title']) ? $_REQUEST['title'] : '';
     45    $quick['post_category'] = isset($_POST['post_category']) ? $_POST['post_category'] : null;
     46    $quick['tax_input'] = isset($_POST['tax_input']) ? $_POST['tax_input'] : '';
     47    $quick['post_title'] = isset($_POST['title']) ? $_POST['title'] : '';
    4848    $quick['post_content'] = '';
    4949
    5050    // insert the post with nothing in it, to get an ID
    5151    $post_ID = wp_insert_post($quick, true);
    52     $content = isset($_REQUEST['content']) ? $_REQUEST['content'] : '';
     52    $content = isset($_POST['content']) ? $_POST['content'] : '';
    5353
    5454    $upload = false;
    55     if( !empty($_REQUEST['photo_src']) && current_user_can('upload_files') )
    56         foreach( (array) $_REQUEST['photo_src'] as $key => $image)
     55    if( !empty($_POST['photo_src']) && current_user_can('upload_files') )
     56        foreach( (array) $_POST['photo_src'] as $key => $image)
    5757            // see if files exist in content - we don't want to upload non-used selected files.
    58             if( strpos($_REQUEST['content'], $image) !== false ) {
    59                 $desc = isset($_REQUEST['photo_description'][$key]) ? $_REQUEST['photo_description'][$key] : '';
     58            if( strpos($_POST['content'], htmlspecialchars($image)) !== false ) {
     59                $desc = isset($_POST['photo_description'][$key]) ? $_POST['photo_description'][$key] : '';
    6060                $upload = media_sideload_image($image, $post_ID, $desc);
    6161
    6262                // Replace the POSTED content <img> with correct uploaded ones. Regex contains fix for Magic Quotes
    63                 if( !is_wp_error($upload) ) $content = preg_replace('/<img ([^>]*)src=\\\?(\"|\')'.preg_quote($image, '/').'\\\?(\2)([^>\/]*)\/*>/is', $upload, $content);
     63                if( !is_wp_error($upload) ) $content = preg_replace('/<img ([^>]*)src=\\\?(\"|\')'.preg_quote(htmlspecialchars($image), '/').'\\\?(\2)([^>\/]*)\/*>/is', $upload, $content);
    6464            }
    65 
     65   
    6666    // set the post_content and status
    67     $quick['post_status'] = isset($_REQUEST['publish']) ? 'publish' : 'draft';
     67    $quick['post_status'] = isset($_POST['publish']) ? 'publish' : 'draft';
    6868    $quick['post_content'] = $content;
    6969    // error handling for $post
     
    101101$image = isset($_GET['i']) ? $_GET['i'] : '';
    102102
    103 if ( !empty($_REQUEST['ajax']) ) {
    104 switch ($_REQUEST['ajax']) {
    105     case 'video': ?>
    106         <script type="text/javascript" charset="utf-8">
    107             jQuery('.select').click(function() {
    108                 append_editor(jQuery('#embed-code').val());
    109                 jQuery('#extra_fields').hide();
    110                 jQuery('#extra_fields').html('');
    111             });
    112             jQuery('.close').click(function() {
    113                 jQuery('#extra_fields').hide();
    114                 jQuery('#extra_fields').html('');
    115             });
    116         </script>
    117         <div class="postbox">
    118         <h2><label for="embed-code"><?php _e('Embed Code') ?></label></h2>
    119         <div class="inside">
    120             <textarea name="embed-code" id="embed-code" rows="8" cols="40"><?php echo format_to_edit($selection, true); ?></textarea>
    121             <p id="options"><a href="#" class="select button"><?php _e('Insert Video'); ?></a> <a href="#" class="close button"><?php _e('Cancel'); ?></a></p>
    122         </div>
    123         </div>
    124         <?php break;
    125 
    126     case 'photo_thickbox': ?>
    127         <script type="text/javascript" charset="utf-8">
    128             jQuery('.cancel').click(function() {
    129                 tb_remove();
    130             });
    131             jQuery('.select').click(function() {
    132                 image_selector();
    133             });
    134         </script>
    135         <h3 class="tb"><label for="this_photo_description"><?php _e('Description') ?></label></h3>
    136         <div class="titlediv">
    137         <div class="titlewrap">
    138             <input id="this_photo_description" name="photo_description" class="tbtitle text" onkeypress="if(event.keyCode==13) image_selector();" value="<?php echo esc_attr($title);?>"/>
    139         </div>
    140         </div>
    141 
    142         <p class="centered"><input type="hidden" name="this_photo" value="<?php echo esc_attr($image); ?>" id="this_photo" />
    143             <a href="#" class="select"><img src="<?php echo esc_url($image); ?>" alt="<?php echo esc_attr(__('Click to insert.')); ?>" title="<?php echo esc_attr(__('Click to insert.')); ?>" /></a></p>
    144 
    145         <p id="options"><a href="#" class="select button"><?php _e('Insert Image'); ?></a> <a href="#" class="cancel button"><?php _e('Cancel'); ?></a></p>
    146 
    147 
    148         <?php break;
    149 
    150     case 'photo_thickbox_url': ?>
    151         <script type="text/javascript" charset="utf-8">
    152             jQuery('.cancel').click(function() {
    153                 tb_remove();
    154             });
    155 
    156             jQuery('.select').click(function() {
    157                 image_selector();
    158             });
    159         </script>
    160         <h3 class="tb"><label for="this_photo"><?php _e('URL') ?></label></h3>
    161         <div class="titlediv">
    162             <div class="titlewrap">
    163             <input id="this_photo" name="this_photo" class="tbtitle text" onkeypress="if(event.keyCode==13) image_selector();" />
    164             </div>
    165         </div>
    166 
    167 
    168         <h3 class="tb"><label for="photo_description"><?php _e('Description') ?></label></h3>
    169         <div id="titlediv">
    170             <div class="titlewrap">
    171             <input id="this_photo_description" name="photo_description" class="tbtitle text" onkeypress="if(event.keyCode==13) image_selector();" value="<?php echo esc_attr($title);?>"/>
    172             </div>
    173         </div>
    174 
    175         <p id="options"><a href="#" class="select"><?php _e('Insert Image'); ?></a> | <a href="#" class="cancel"><?php _e('Cancel'); ?></a></p>
    176         <?php break;
     103if ( !empty($_GET['ajax']) ) {
     104    switch ($_GET['ajax']) {
     105        case 'video': ?>
     106            <script type="text/javascript" charset="utf-8">
     107            /* <![CDATA[ */
     108                jQuery('.select').click(function() {
     109                    append_editor(jQuery('#embed-code').val());
     110                    jQuery('#extra_fields').hide();
     111                    jQuery('#extra_fields').html('');
     112                });
     113                jQuery('.close').click(function() {
     114                    jQuery('#extra_fields').hide();
     115                    jQuery('#extra_fields').html('');
     116                });
     117            /* ]]> */
     118            </script>
     119            <div class="postbox">
     120                <h2><label for="embed-code"><?php _e('Embed Code') ?></label></h2>
     121                <div class="inside">
     122                    <textarea name="embed-code" id="embed-code" rows="8" cols="40"><?php echo format_to_edit($selection, true); ?></textarea>
     123                    <p id="options"><a href="#" class="select button"><?php _e('Insert Video'); ?></a> <a href="#" class="close button"><?php _e('Cancel'); ?></a></p>
     124                </div>
     125            </div>
     126            <?php break;
     127
     128        case 'photo_thickbox': ?>
     129            <script type="text/javascript" charset="utf-8">
     130                /* <![CDATA[ */
     131                jQuery('.cancel').click(function() {
     132                    tb_remove();
     133                });
     134                jQuery('.select').click(function() {
     135                    image_selector();
     136                });
     137                /* ]]> */
     138            </script>
     139            <h3 class="tb"><label for="this_photo_description"><?php _e('Description') ?></label></h3>
     140            <div class="titlediv">
     141                <div class="titlewrap">
     142                    <input id="this_photo_description" name="photo_description" class="tbtitle text" onkeypress="if(event.keyCode==13) image_selector();" value="<?php echo esc_attr($title);?>"/>
     143                </div>
     144            </div>
     145
     146            <p class="centered">
     147                <input type="hidden" name="this_photo" value="<?php echo esc_attr($image); ?>" id="this_photo" />
     148                <a href="#" class="select">
     149                    <img src="<?php echo esc_url($image); ?>" alt="<?php echo esc_attr(__('Click to insert.')); ?>" title="<?php echo esc_attr(__('Click to insert.')); ?>" />
     150                </a>
     151            </p>
     152
     153            <p id="options"><a href="#" class="select button"><?php _e('Insert Image'); ?></a> <a href="#" class="cancel button"><?php _e('Cancel'); ?></a></p>
     154            <?php break;
     155
     156        case 'photo_thickbox_url': ?>
     157            <script type="text/javascript" charset="utf-8">
     158                /* <![CDATA[ */
     159                jQuery('.cancel').click(function() {
     160                    tb_remove();
     161                });
     162
     163                jQuery('.select').click(function() {
     164                    image_selector();
     165                });
     166                /* ]]> */
     167            </script>
     168            <h3 class="tb"><label for="this_photo"><?php _e('URL') ?></label></h3>
     169            <div class="titlediv">
     170                <div class="titlewrap">
     171                    <input id="this_photo" name="this_photo" class="tbtitle text" onkeypress="if(event.keyCode==13) image_selector();" />
     172                </div>
     173            </div>
     174            <h3 class="tb"><label for="photo_description"><?php _e('Description') ?></label></h3>
     175            <div id="titlediv">
     176                <div class="titlewrap">
     177                    <input id="this_photo_description" name="photo_description" class="tbtitle text" onkeypress="if(event.keyCode==13) image_selector();" value="<?php echo esc_attr($title);?>"/>
     178                </div>
     179            </div>
     180
     181            <p id="options"><a href="#" class="select"><?php _e('Insert Image'); ?></a> | <a href="#" class="cancel"><?php _e('Cancel'); ?></a></p>
     182            <?php break;
    177183    case 'photo_images':
    178184        /**
     
    187193         */
    188194        function get_images_from_uri($uri) {
    189             if( preg_match('/\.(jpg|jpe|jpeg|png|gif)$/', $uri) && !strpos($uri,'blogger.com') )
    190                 return "'".$uri."'";
     195            if( preg_match('/\.(jpg|jpe|jpeg|png|gif)/', $uri) && !strpos($uri,'blogger.com') )
     196                return "'".html_entity_decode($uri)."'";
    191197            $content = wp_remote_fopen($uri);
    192198            if ( false === $content )
    193199                return '';
    194200            $host = parse_url($uri);
    195             $pattern = '/<img ([^>]*)src=(\"|\')([^<>]+?\.(png|jpeg|jpg|jpe|gif))[^<>\'\"]*(\2)([^>\/]*)\/*>/is';
     201            $pattern = '/<img ([^>]*)src=(\"|\')([^<>]+?\.(png|jpeg|jpg|jpe|gif)[^<>\'\"]*)(\2)([^>\/]*)\/*>/is';
    196202            preg_match_all($pattern, $content, $matches);
    197203            if ( empty($matches[0]) )
     
    211217        }
    212218        $url = urldecode($url);
    213         $url = str_replace(' ', '%20', $url);
    214219        echo 'new Array('.get_images_from_uri($url).')';
    215220
     
    220225        var last = null
    221226        var img, img_tag, aspect, w, h, skip, i, strtoappend = "";
     227        var my_src = eval(
     228            jQuery.ajax({
     229                type: "GET",
     230                url: "<?php echo esc_url($_SERVER['PHP_SELF']); ?>",
     231                cache : false,
     232                async : false,
     233                data: "ajax=photo_images&u=<?php echo urlencode($url); ?>",
     234                dataType : "script"
     235            }).responseText
     236        );
     237        if(my_src.length == 0) {
    222238            var my_src = eval(
    223239                jQuery.ajax({
    224                     type: "GET",
    225                     url: "<?php echo esc_url($_SERVER['PHP_SELF']); ?>",
     240                    type: "GET",
     241                    url: "<?php echo esc_url($_SERVER['PHP_SELF']); ?>",
    226242                    cache : false,
    227243                    async : false,
    228                     data: "ajax=photo_images&u=<?php echo urlencode($url); ?>",
     244                    data: "ajax=photo_images&u=<?php echo urlencode($url); ?>",
    229245                    dataType : "script"
    230246                }).responseText
    231247            );
    232248            if(my_src.length == 0) {
    233                 var my_src = eval(
    234                 jQuery.ajax({
    235                     type: "GET",
    236                     url: "<?php echo esc_url($_SERVER['PHP_SELF']); ?>",
    237                     cache : false,
    238                     async : false,
    239                     data: "ajax=photo_images&u=<?php echo urlencode($url); ?>",
    240                     dataType : "script"
    241                 }).responseText
    242                 );
    243                 if(my_src.length == 0) {
    244                     strtoappend = '<?php _e('Unable to retrieve images or no images on page.'); ?>';
    245                 }
     249                strtoappend = '<?php _e('Unable to retrieve images or no images on page.'); ?>';
    246250            }
     251        }
    247252
    248253        for (i = 0; i < my_src.length; i++) {
Note: See TracChangeset for help on using the changeset viewer.