Changeset 11944
- Timestamp:
- 09/17/2009 08:36:59 PM (16 years ago)
- Location:
- trunk/wp-admin
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/media.php
r11911 r11944 250 250 function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) { 251 251 $overrides = array('test_form'=>false); 252 252 253 $file = wp_handle_sideload($file_array, $overrides); 253 254 254 if ( isset($file['error']) ) 255 255 return new WP_Error( 'upload_error', $file['error'] ); … … 280 280 ), $post_data ); 281 281 282 // Save the data282 // Save the attachment metadata 283 283 $id = wp_insert_attachment($attachment, $file, $post_id); 284 284 if ( !is_wp_error($id) ) { … … 521 521 function media_sideload_image($file, $post_id, $desc = null) { 522 522 if (!empty($file) ) { 523 $file_array['name'] = basename($file);523 // Download file to temp location 524 524 $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]); 525 530 $file_array['tmp_name'] = $tmp; 526 $desc = @$desc; 527 531 532 // If error storing temporarily, unlink 528 533 if ( is_wp_error($tmp) ) { 529 534 @unlink($file_array['tmp_name']); 530 535 $file_array['tmp_name'] = ''; 531 536 } 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); 534 540 $src = $id; 535 541 542 // If error storing permanently, unlink 536 543 if ( is_wp_error($id) ) { 537 544 @unlink($file_array['tmp_name']); … … 539 546 } 540 547 } 541 548 549 // Finally check to make sure the file has been saved, then return the html 542 550 if ( !empty($src) ) { 543 551 $alt = @$desc; -
trunk/wp-admin/press-this.php
r11383 r11944 43 43 // define some basic variables 44 44 $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'] : ''; 48 48 $quick['post_content'] = ''; 49 49 50 50 // insert the post with nothing in it, to get an ID 51 51 $post_ID = wp_insert_post($quick, true); 52 $content = isset($_ REQUEST['content']) ? $_REQUEST['content'] : '';52 $content = isset($_POST['content']) ? $_POST['content'] : ''; 53 53 54 54 $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) 57 57 // 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] : ''; 60 60 $upload = media_sideload_image($image, $post_ID, $desc); 61 61 62 62 // 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); 64 64 } 65 65 66 66 // set the post_content and status 67 $quick['post_status'] = isset($_ REQUEST['publish']) ? 'publish' : 'draft';67 $quick['post_status'] = isset($_POST['publish']) ? 'publish' : 'draft'; 68 68 $quick['post_content'] = $content; 69 69 // error handling for $post … … 101 101 $image = isset($_GET['i']) ? $_GET['i'] : ''; 102 102 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; 103 if ( !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; 177 183 case 'photo_images': 178 184 /** … … 187 193 */ 188 194 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)."'"; 191 197 $content = wp_remote_fopen($uri); 192 198 if ( false === $content ) 193 199 return ''; 194 200 $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'; 196 202 preg_match_all($pattern, $content, $matches); 197 203 if ( empty($matches[0]) ) … … 211 217 } 212 218 $url = urldecode($url); 213 $url = str_replace(' ', '%20', $url);214 219 echo 'new Array('.get_images_from_uri($url).')'; 215 220 … … 220 225 var last = null 221 226 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) { 222 238 var my_src = eval( 223 239 jQuery.ajax({ 224 225 240 type: "GET", 241 url: "<?php echo esc_url($_SERVER['PHP_SELF']); ?>", 226 242 cache : false, 227 243 async : false, 228 244 data: "ajax=photo_images&u=<?php echo urlencode($url); ?>", 229 245 dataType : "script" 230 246 }).responseText 231 247 ); 232 248 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.'); ?>'; 246 250 } 251 } 247 252 248 253 for (i = 0; i < my_src.length; i++) {
Note: See TracChangeset
for help on using the changeset viewer.