<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre, #msg p { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[11944] trunk/wp-admin: Press This fixes.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/11944">11944</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2009-09-17 20:36:59 +0000 (Thu, 17 Sep 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>Press This fixes. Props noel. fixes <a href="http://trac.wordpress.org/ticket/10784">#10784</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesmediaphp">trunk/wp-admin/includes/media.php</a></li>
<li><a href="#trunkwpadminpressthisphp">trunk/wp-admin/press-this.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/media.php (11943 => 11944)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/media.php        2009-09-17 20:17:33 UTC (rev 11943)
+++ trunk/wp-admin/includes/media.php        2009-09-17 20:36:59 UTC (rev 11944)
</span><span class="lines">@@ -249,8 +249,8 @@
</span><span class="cx"> */
</span><span class="cx"> function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) {
</span><span class="cx">         $overrides = array('test_form'=>false);
</span><ins>+        
</ins><span class="cx">         $file = wp_handle_sideload($file_array, $overrides);
</span><del>-
</del><span class="cx">         if ( isset($file['error']) )
</span><span class="cx">                 return new WP_Error( 'upload_error', $file['error'] );
</span><span class="cx">
</span><span class="lines">@@ -279,7 +279,7 @@
</span><span class="cx">                 'post_content' => $content,
</span><span class="cx">         ), $post_data );
</span><span class="cx">
</span><del>-        // Save the data
</del><ins>+        // Save the attachment metadata
</ins><span class="cx">         $id = wp_insert_attachment($attachment, $file, $post_id);
</span><span class="cx">         if ( !is_wp_error($id) ) {
</span><span class="cx">                 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
</span><span class="lines">@@ -520,25 +520,33 @@
</span><span class="cx"> */
</span><span class="cx"> function media_sideload_image($file, $post_id, $desc = null) {
</span><span class="cx">         if (!empty($file) ) {
</span><del>-                $file_array['name'] = basename($file);
</del><ins>+                // Download file to temp location
</ins><span class="cx">                 $tmp = download_url($file);
</span><ins>+                
+                // Set variables for storage
+                // fix file filename for query strings
+                preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $file, $matches);
+                $file_array['name'] = basename($matches[0]);
</ins><span class="cx">                 $file_array['tmp_name'] = $tmp;
</span><del>-                $desc = @$desc;
</del><span class="cx">
</span><ins>+                // If error storing temporarily, unlink
</ins><span class="cx">                 if ( is_wp_error($tmp) ) {
</span><span class="cx">                         @unlink($file_array['tmp_name']);
</span><span class="cx">                         $file_array['tmp_name'] = '';
</span><span class="cx">                 }
</span><del>-
-                $id = media_handle_sideload($file_array, $post_id, $desc);
</del><ins>+                
+                // do the validation and storage stuff
+                $id = media_handle_sideload($file_array, $post_id, @$desc);
</ins><span class="cx">                 $src = $id;
</span><del>-
</del><ins>+                
+                // If error storing permanently, unlink
</ins><span class="cx">                 if ( is_wp_error($id) ) {
</span><span class="cx">                         @unlink($file_array['tmp_name']);
</span><span class="cx">                         return $id;
</span><span class="cx">                 }
</span><span class="cx">         }
</span><del>-
</del><ins>+        
+        // Finally check to make sure the file has been saved, then return the html
</ins><span class="cx">         if ( !empty($src) ) {
</span><span class="cx">                 $alt = @$desc;
</span><span class="cx">                 $html = "<img src='$src' alt='$alt' />";
</span></span></pre></div>
<a id="trunkwpadminpressthisphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/press-this.php (11943 => 11944)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/press-this.php        2009-09-17 20:17:33 UTC (rev 11943)
+++ trunk/wp-admin/press-this.php        2009-09-17 20:36:59 UTC (rev 11944)
</span><span class="lines">@@ -42,29 +42,29 @@
</span><span class="cx"> function press_it() {
</span><span class="cx">         // define some basic variables
</span><span class="cx">         $quick['post_status'] = 'draft'; // set as draft first
</span><del>-        $quick['post_category'] = isset($_REQUEST['post_category']) ? $_REQUEST['post_category'] : null;
-        $quick['tax_input'] = isset($_REQUEST['tax_input']) ? $_REQUEST['tax_input'] : '';
-        $quick['post_title'] = isset($_REQUEST['title']) ? $_REQUEST['title'] : '';
</del><ins>+        $quick['post_category'] = isset($_POST['post_category']) ? $_POST['post_category'] : null;
+        $quick['tax_input'] = isset($_POST['tax_input']) ? $_POST['tax_input'] : '';
+        $quick['post_title'] = isset($_POST['title']) ? $_POST['title'] : '';
</ins><span class="cx">         $quick['post_content'] = '';
</span><span class="cx">
</span><span class="cx">         // insert the post with nothing in it, to get an ID
</span><span class="cx">         $post_ID = wp_insert_post($quick, true);
</span><del>-        $content = isset($_REQUEST['content']) ? $_REQUEST['content'] : '';
</del><ins>+        $content = isset($_POST['content']) ? $_POST['content'] : '';
</ins><span class="cx">
</span><span class="cx">         $upload = false;
</span><del>-        if( !empty($_REQUEST['photo_src']) && current_user_can('upload_files') )
-                foreach( (array) $_REQUEST['photo_src'] as $key => $image)
</del><ins>+        if( !empty($_POST['photo_src']) && current_user_can('upload_files') )
+                foreach( (array) $_POST['photo_src'] as $key => $image)
</ins><span class="cx">                         // see if files exist in content - we don't want to upload non-used selected files.
</span><del>-                        if( strpos($_REQUEST['content'], $image) !== false ) {
-                                $desc = isset($_REQUEST['photo_description'][$key]) ? $_REQUEST['photo_description'][$key] : '';
</del><ins>+                        if( strpos($_POST['content'], htmlspecialchars($image)) !== false ) {
+                                $desc = isset($_POST['photo_description'][$key]) ? $_POST['photo_description'][$key] : '';
</ins><span class="cx">                                 $upload = media_sideload_image($image, $post_ID, $desc);
</span><span class="cx">
</span><span class="cx">                                 // Replace the POSTED content <img> with correct uploaded ones. Regex contains fix for Magic Quotes
</span><del>-                                if( !is_wp_error($upload) ) $content = preg_replace('/<img ([^>]*)src=\\\?(\"|\')'.preg_quote($image, '/').'\\\?(\2)([^>\/]*)\/*>/is', $upload, $content);
</del><ins>+                                if( !is_wp_error($upload) ) $content = preg_replace('/<img ([^>]*)src=\\\?(\"|\')'.preg_quote(htmlspecialchars($image), '/').'\\\?(\2)([^>\/]*)\/*>/is', $upload, $content);
</ins><span class="cx">                         }
</span><del>-
</del><ins>+        
</ins><span class="cx">         // set the post_content and status
</span><del>-        $quick['post_status'] = isset($_REQUEST['publish']) ? 'publish' : 'draft';
</del><ins>+        $quick['post_status'] = isset($_POST['publish']) ? 'publish' : 'draft';
</ins><span class="cx">         $quick['post_content'] = $content;
</span><span class="cx">         // error handling for $post
</span><span class="cx">         if ( is_wp_error($post_ID)) {
</span><span class="lines">@@ -100,80 +100,86 @@
</span><span class="cx"> $url = isset($_GET['u']) ? esc_url($_GET['u']) : '';
</span><span class="cx"> $image = isset($_GET['i']) ? $_GET['i'] : '';
</span><span class="cx">
</span><del>-if ( !empty($_REQUEST['ajax']) ) {
-switch ($_REQUEST['ajax']) {
-        case 'video': ?>
-                <script type="text/javascript" charset="utf-8">
-                        jQuery('.select').click(function() {
-                                append_editor(jQuery('#embed-code').val());
-                                jQuery('#extra_fields').hide();
-                                jQuery('#extra_fields').html('');
-                        });
-                        jQuery('.close').click(function() {
-                                jQuery('#extra_fields').hide();
-                                jQuery('#extra_fields').html('');
-                        });
-                </script>
-                <div class="postbox">
-                <h2><label for="embed-code"><?php _e('Embed Code') ?></label></h2>
-                <div class="inside">
-                        <textarea name="embed-code" id="embed-code" rows="8" cols="40"><?php echo format_to_edit($selection, true); ?></textarea>
-                        <p id="options"><a href="#" class="select button"><?php _e('Insert Video'); ?></a> <a href="#" class="close button"><?php _e('Cancel'); ?></a></p>
-                </div>
-                </div>
-                <?php break;
</del><ins>+if ( !empty($_GET['ajax']) ) {
+        switch ($_GET['ajax']) {
+                case 'video': ?>
+                        <script type="text/javascript" charset="utf-8">
+                        /* <![CDATA[ */
+                                jQuery('.select').click(function() {
+                                        append_editor(jQuery('#embed-code').val());
+                                        jQuery('#extra_fields').hide();
+                                        jQuery('#extra_fields').html('');
+                                });
+                                jQuery('.close').click(function() {
+                                        jQuery('#extra_fields').hide();
+                                        jQuery('#extra_fields').html('');
+                                });
+                        /* ]]> */
+                        </script>
+                        <div class="postbox">
+                                <h2><label for="embed-code"><?php _e('Embed Code') ?></label></h2>
+                                <div class="inside">
+                                        <textarea name="embed-code" id="embed-code" rows="8" cols="40"><?php echo format_to_edit($selection, true); ?></textarea>
+                                        <p id="options"><a href="#" class="select button"><?php _e('Insert Video'); ?></a> <a href="#" class="close button"><?php _e('Cancel'); ?></a></p>
+                                </div>
+                        </div>
+                        <?php break;
</ins><span class="cx">
</span><del>-        case 'photo_thickbox': ?>
-                <script type="text/javascript" charset="utf-8">
-                        jQuery('.cancel').click(function() {
-                                tb_remove();
-                        });
-                        jQuery('.select').click(function() {
-                                image_selector();
-                        });
-                </script>
-                <h3 class="tb"><label for="this_photo_description"><?php _e('Description') ?></label></h3>
-                <div class="titlediv">
-                <div class="titlewrap">
-                        <input id="this_photo_description" name="photo_description" class="tbtitle text" onkeypress="if(event.keyCode==13) image_selector();" value="<?php echo esc_attr($title);?>"/>
-                </div>
-                </div>
</del><ins>+                case 'photo_thickbox': ?>
+                        <script type="text/javascript" charset="utf-8">
+                                /* <![CDATA[ */
+                                jQuery('.cancel').click(function() {
+                                        tb_remove();
+                                });
+                                jQuery('.select').click(function() {
+                                        image_selector();
+                                });
+                                /* ]]> */
+                        </script>
+                        <h3 class="tb"><label for="this_photo_description"><?php _e('Description') ?></label></h3>
+                        <div class="titlediv">
+                                <div class="titlewrap">
+                                        <input id="this_photo_description" name="photo_description" class="tbtitle text" onkeypress="if(event.keyCode==13) image_selector();" value="<?php echo esc_attr($title);?>"/>
+                                </div>
+                        </div>
</ins><span class="cx">
</span><del>-                <p class="centered"><input type="hidden" name="this_photo" value="<?php echo esc_attr($image); ?>" id="this_photo" />
-                        <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>
</del><ins>+                        <p class="centered">
+                                <input type="hidden" name="this_photo" value="<?php echo esc_attr($image); ?>" id="this_photo" />
+                                <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>
</ins><span class="cx">
</span><del>-                <p id="options"><a href="#" class="select button"><?php _e('Insert Image'); ?></a> <a href="#" class="cancel button"><?php _e('Cancel'); ?></a></p>
</del><ins>+                        <p id="options"><a href="#" class="select button"><?php _e('Insert Image'); ?></a> <a href="#" class="cancel button"><?php _e('Cancel'); ?></a></p>
+                        <?php break;
</ins><span class="cx">
</span><ins>+                case 'photo_thickbox_url': ?>
+                        <script type="text/javascript" charset="utf-8">
+                                /* <![CDATA[ */
+                                jQuery('.cancel').click(function() {
+                                        tb_remove();
+                                });
</ins><span class="cx">
</span><del>-                <?php break;
-
-        case 'photo_thickbox_url': ?>
-                <script type="text/javascript" charset="utf-8">
-                        jQuery('.cancel').click(function() {
-                                tb_remove();
-                        });
-
-                        jQuery('.select').click(function() {
-                                image_selector();
-                        });
-                </script>
-                <h3 class="tb"><label for="this_photo"><?php _e('URL') ?></label></h3>
-                <div class="titlediv">
-                        <div class="titlewrap">
-                        <input id="this_photo" name="this_photo" class="tbtitle text" onkeypress="if(event.keyCode==13) image_selector();" />
</del><ins>+                                jQuery('.select').click(function() {
+                                        image_selector();
+                                });
+                                /* ]]> */
+                        </script>
+                        <h3 class="tb"><label for="this_photo"><?php _e('URL') ?></label></h3>
+                        <div class="titlediv">
+                                <div class="titlewrap">
+                                        <input id="this_photo" name="this_photo" class="tbtitle text" onkeypress="if(event.keyCode==13) image_selector();" />
+                                </div>
</ins><span class="cx">                         </div>
</span><del>-                </div>
-
-
-                <h3 class="tb"><label for="photo_description"><?php _e('Description') ?></label></h3>
-                <div id="titlediv">
-                        <div class="titlewrap">
-                        <input id="this_photo_description" name="photo_description" class="tbtitle text" onkeypress="if(event.keyCode==13) image_selector();" value="<?php echo esc_attr($title);?>"/>
</del><ins>+                        <h3 class="tb"><label for="photo_description"><?php _e('Description') ?></label></h3>
+                        <div id="titlediv">
+                                <div class="titlewrap">
+                                        <input id="this_photo_description" name="photo_description" class="tbtitle text" onkeypress="if(event.keyCode==13) image_selector();" value="<?php echo esc_attr($title);?>"/>
+                                </div>
</ins><span class="cx">                         </div>
</span><del>-                </div>
</del><span class="cx">
</span><del>-                <p id="options"><a href="#" class="select"><?php _e('Insert Image'); ?></a> | <a href="#" class="cancel"><?php _e('Cancel'); ?></a></p>
-                <?php break;
</del><ins>+                        <p id="options"><a href="#" class="select"><?php _e('Insert Image'); ?></a> | <a href="#" class="cancel"><?php _e('Cancel'); ?></a></p>
+                        <?php break;
</ins><span class="cx">         case 'photo_images':
</span><span class="cx">                 /**
</span><span class="cx">                  * Retrieve all image URLs from given URI.
</span><span class="lines">@@ -186,13 +192,13 @@
</span><span class="cx">                  * @return string
</span><span class="cx">                  */
</span><span class="cx">                 function get_images_from_uri($uri) {
</span><del>-                        if( preg_match('/\.(jpg|jpe|jpeg|png|gif)$/', $uri) && !strpos($uri,'blogger.com') )
-                                return "'".$uri."'";
</del><ins>+                        if( preg_match('/\.(jpg|jpe|jpeg|png|gif)/', $uri) && !strpos($uri,'blogger.com') )
+                                return "'".html_entity_decode($uri)."'";
</ins><span class="cx">                         $content = wp_remote_fopen($uri);
</span><span class="cx">                         if ( false === $content )
</span><span class="cx">                                 return '';
</span><span class="cx">                         $host = parse_url($uri);
</span><del>-                        $pattern = '/<img ([^>]*)src=(\"|\')([^<>]+?\.(png|jpeg|jpg|jpe|gif))[^<>\'\"]*(\2)([^>\/]*)\/*>/is';
</del><ins>+                        $pattern = '/<img ([^>]*)src=(\"|\')([^<>]+?\.(png|jpeg|jpg|jpe|gif)[^<>\'\"]*)(\2)([^>\/]*)\/*>/is';
</ins><span class="cx">                         preg_match_all($pattern, $content, $matches);
</span><span class="cx">                         if ( empty($matches[0]) )
</span><span class="cx">                                 return '';
</span><span class="lines">@@ -210,7 +216,6 @@
</span><span class="cx">                         return "'" . implode("','", $sources) . "'";
</span><span class="cx">                 }
</span><span class="cx">                 $url = urldecode($url);
</span><del>-                $url = str_replace(' ', '%20', $url);
</del><span class="cx">                 echo 'new Array('.get_images_from_uri($url).')';
</span><span class="cx">
</span><span class="cx">                 break;
</span><span class="lines">@@ -219,31 +224,31 @@
</span><span class="cx">                 // gather images and load some default JS
</span><span class="cx">                 var last = null
</span><span class="cx">                 var img, img_tag, aspect, w, h, skip, i, strtoappend = "";
</span><ins>+                var my_src = eval(
+                        jQuery.ajax({
+                                 type: "GET",
+                                 url: "<?php echo esc_url($_SERVER['PHP_SELF']); ?>",
+                                cache : false,
+                                async : false,
+                                 data: "ajax=photo_images&u=<?php echo urlencode($url); ?>",
+                                dataType : "script"
+                        }).responseText
+                );
+                if(my_src.length == 0) {
</ins><span class="cx">                         var my_src = eval(
</span><span class="cx">                                 jQuery.ajax({
</span><del>-                                         type: "GET",
-                                         url: "<?php echo esc_url($_SERVER['PHP_SELF']); ?>",
</del><ins>+                                         type: "GET",
+                                         url: "<?php echo esc_url($_SERVER['PHP_SELF']); ?>",
</ins><span class="cx">                                         cache : false,
</span><span class="cx">                                         async : false,
</span><del>-                                         data: "ajax=photo_images&u=<?php echo urlencode($url); ?>",
</del><ins>+                                         data: "ajax=photo_images&u=<?php echo urlencode($url); ?>",
</ins><span class="cx">                                         dataType : "script"
</span><span class="cx">                                 }).responseText
</span><span class="cx">                         );
</span><span class="cx">                         if(my_src.length == 0) {
</span><del>-                                var my_src = eval(
-                                jQuery.ajax({
-                                         type: "GET",
-                                         url: "<?php echo esc_url($_SERVER['PHP_SELF']); ?>",
-                                        cache : false,
-                                        async : false,
-                                         data: "ajax=photo_images&u=<?php echo urlencode($url); ?>",
-                                        dataType : "script"
-                                }).responseText
-                                );
-                                if(my_src.length == 0) {
-                                        strtoappend = '<?php _e('Unable to retrieve images or no images on page.'); ?>';
-                                }
</del><ins>+                                strtoappend = '<?php _e('Unable to retrieve images or no images on page.'); ?>';
</ins><span class="cx">                         }
</span><ins>+                }
</ins><span class="cx">
</span><span class="cx">                 for (i = 0; i < my_src.length; i++) {
</span><span class="cx">                         img = new Image();
</span></span></pre>
</div>
</div>
</body>
</html>