Changeset 8242 for branches/crazyhorse/wp-admin/press-this.php
- Timestamp:
- 07/02/2008 11:07:56 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/crazyhorse/wp-admin/press-this.php
r8151 r8242 5 5 6 6 <?php 7 8 function preg_quote2($string) { 9 return str_replace('/', '\/', preg_quote($string)); 10 } 7 11 function press_it() { 8 #define some basic variables12 // define some basic variables 9 13 $quick['post_status'] = $_REQUEST['post_status']; 10 14 $quick['post_category'] = $_REQUEST['post_category']; … … 13 17 $quick['post_content'] = ''; 14 18 15 #insert the post with nothing in it, to get an ID19 // insert the post with nothing in it, to get an ID 16 20 $post_ID = wp_insert_post($quick, true); 17 21 … … 24 28 25 29 case 'photo': 26 foreach($_REQUEST['photo_src'] as $key => $data) { 30 $content = $_REQUEST['content']; 31 32 foreach($_REQUEST['photo_src'] as $key => $image) { 27 33 #quote for matching 28 $quoted = str_replace('/', '\/', preg_quote($data));34 $quoted = preg_quote2($image); 29 35 30 #see if files exist in content - we don't want to upload non-used selected files.36 // see if files exist in content - we don't want to upload non-used selected files. 31 37 preg_match('/'.$quoted.'/', $_REQUEST['content'], $matches[0]); 32 if($matches[0]) 33 media_sideload_image($data, $post_ID, $_REQUEST['photo_description'][$key]); 38 if($matches[0]) { 39 $upload = media_sideload_image($image, $post_ID, $_REQUEST['photo_description'][$key]); 40 // Replace the POSTED content <img> with correct uploaded ones. 41 if( !is_wp_error($upload) ) $content = preg_replace('/<img ([^>]*)src=(\"|\')'.$quoted.'(\2)([^>\/]*)\/*>/is', $upload, $content); 42 } 34 43 } 35 $content = $_REQUEST['content'];44 36 45 break; 37 46 … … 46 55 47 56 #error handling for $post 48 if ( is_wp_error($post_ID) 57 if ( is_wp_error($post_ID)) { 49 58 wp_die($id); 50 59 wp_delete_post($post_ID); 51 52 60 #error handling for media_sideload 61 } elseif ( is_wp_error($upload)) { 62 wp_die($upload); 63 wp_delete_post($post_ID); 53 64 } else { 54 65 $quick['ID'] = $post_ID; … … 79 90 </head> 80 91 <body class="press-this"> 81 <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&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> 92 93 <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&post=<?php echo $post_ID; ?>" onclick="window.opener.location.replace(this.href); window.close();"><?php _e('Edit post'); ?></a> | <a href="#" onclick="window.close();"><?php _e('Close Window'); ?></a></p></div> 82 94 83 95 <div id="footer"> … … 104 116 105 117 // Ajax Requests 106 $title = wp_specialchars( stripslashes($_GET['t']));118 $title = wp_specialchars(aposfix(stripslashes($_GET['t']))); 107 119 108 120 $selection = str_replace("\n", "<br />", aposfix( stripslashes($_GET['s']) ) ); … … 111 123 112 124 if($_REQUEST['ajax'] == 'thickbox') { ?> 125 <script type="text/javascript" charset="utf-8"> 126 jQuery('.cancel').click(function() { 127 tb_remove(); 128 }); 129 130 jQuery('.select').click(function() { 131 image_selector(); 132 }); 133 </script> 113 134 <h3 id="title"><label for="post_title"><?php _e('Description') ?></label></h3> 114 135 <div class="titlewrap"> … … 116 137 </div> 117 138 118 <p><input type="hidden" name="this_photo" value="<?php echo $image; ?>" id="this_photo" />119 <a href="#" class="select"><img src="<?php echo $image; ?>" width="475" alt="Click to insert." title="Click to insert." /></a></p>120 121 <p id="options"><a href="#" class="select"> Insert Image</a> | <a href="#" class="cancel">Cancel</a></p>139 <p><input type="hidden" name="this_photo" value="<?php echo attribute_escape($image); ?>" id="this_photo" /> 140 <a href="#" class="select"><img src="<?php echo clean_url($image); ?>" width="475" alt="<?php echo attribute_escape(__('Click to insert.')); ?>" title="<?php echo attribute_escape(__('Click to insert.')); ?>" /></a></p> 141 142 <p id="options"><a href="#" class="select"><?php _e('Insert Image'); ?></a> | <a href="#" class="cancel"><?php _e('Cancel'); ?></a></p> 122 143 <?php die; 123 144 } 124 145 125 146 if($_REQUEST['ajax'] == 'thickbox_url') { ?> 147 <script type="text/javascript" charset="utf-8"> 148 jQuery('.cancel').click(function() { 149 tb_remove(); 150 }); 151 152 jQuery('.select').click(function() { 153 image_selector(); 154 }); 155 </script> 126 156 <h3 id="title"><label for="post_title"><?php _e('URL') ?></label></h3> 127 157 <div class="titlewrap"> … … 135 165 </div> 136 166 137 <p id="options"><a href="#" class="select"> Insert Image</a> | <a href="#" class="cancel">Cancel</a></p>167 <p id="options"><a href="#" class="select"><?php _e('Insert Image'); ?></a> | <a href="#" class="cancel"><?php _e('Cancel'); ?></a></p> 138 168 <?php die; 139 169 } … … 142 172 <h2 id="embededcode"><label for="embed_code"><?php _e('Embed Code') ?></label></h2> 143 173 <div class="titlewrap" > 144 <textarea name="embed_code" id="embed_code" rows="8" cols="40"><?php echo $selection; ?></textarea>174 <textarea name="embed_code" id="embed_code" rows="8" cols="40"><?php echo format_to_edit($selection); ?></textarea> 145 175 </div> 146 176 <?php die; … … 149 179 if($_REQUEST['ajax'] == 'photo_images') { 150 180 function get_images_from_uri($uri) { 151 if(preg_match('/\.(jpg| png|gif)/', $uri) && !strpos($uri,'blogger.com'))181 if(preg_match('/\.(jpg|jpe|jpeg|png|gif)/', $uri) && !strpos($uri,'blogger.com')) 152 182 return "'".$uri."'"; 153 183 … … 157 187 $host = parse_url($uri); 158 188 159 $pattern = '/<img ([^>]*)src=(\"|\')( .+?)(\2)([^>\/]*)\/*>/is';189 $pattern = '/<img ([^>]*)src=(\"|\')([^<>]+?\.(png|jpeg|jpg|jpe|gif))(\2)([^>\/]*)\/*>/is'; 160 190 preg_match_all($pattern, $content, $matches); 161 191 … … 170 200 $src = 'http://'.str_replace('//','/', $host['host'].'/'.$host['path'].'/'.$src); 171 201 172 $sources[] = $src;202 $sources[] = clean_url($src); 173 203 } 174 204 return "'" . implode("','", $sources) . "'"; … … 182 212 183 213 if($_REQUEST['ajax'] == 'photo_js') { ?> 184 185 tb_init('a.thickbox, area.thickbox, input.thickbox'); //pass where to apply thickbox 214 215 216 // gather images and load some default JS 217 218 var last = null 219 var img, img_tag, aspect, w, h, skip, i, strtoappend = ""; 220 var my_src = eval( 221 jQuery.ajax({ 222 type: "GET", 223 url: "<?php echo clean_url($_SERVER['PHP_SELF']); ?>", 224 cache : false, 225 async : false, 226 data: "ajax=photo_images&u=<?php echo urlencode($url); ?>", 227 dataType : "script" 228 }).responseText 229 ); 230 231 for (i = 0; i < my_src.length; i++) { 232 img = new Image(); 233 img.src = my_src[i]; 234 img_attr = 'id="img' + i + '"'; 235 skip = false; 236 if (img.width && img.height) { 237 if (img.width * img.height < 2500) 238 skip = true; 239 aspect = img.width / img.height; 240 scale = (aspect > 1) ? (75 / img.width) : (75 / img.height); 186 241 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;242 w = img.width; 243 h = img.height; 244 245 if (scale < 1) { 246 w = parseInt(img.width * scale); 247 h = parseInt(img.height * scale); 193 248 } 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&i=' + img.src + '&u=<?php echo $url; ?>&height=400&width=500" title="" class="thickbox"><img src="' + img.src + '" ' + img_attr + '/></a>'; 254 255 } 256 jQuery('#img_container').html(strtoappend); 257 249 img_attr += ' style="width: ' + w + 'px; height: ' + h + 'px;"'; 250 } 251 if (!skip) strtoappend += '<a href="?ajax=thickbox&i=' + img.src + '&u=<?php echo $url; ?>&height=400&width=500" title="" class="thickbox"><img src="' + img.src + '" ' + img_attr + '/></a>'; 252 } 253 254 function pick(img, desc) { 255 if (img) { 256 length = jQuery('.photolist input').length; 257 if(length == 0) length = 1; 258 jQuery('.photolist').append('<input name="photo_src[' + length + ']" value="' + img +'" type="hidden"/>'); 259 jQuery('.photolist').append('<input name="photo_description[' + length + ']" value="' + desc +'" type="hidden"/>'); 260 append_editor('<img src="' + img +'" alt="' + desc + '" />'); 261 } 262 tinyMCE.activeEditor.resizeToContent(); 263 return false; 264 } 265 266 function image_selector() { 267 tb_remove(); 268 desc = jQuery('#this_photo_description').val(); 269 src = jQuery('#this_photo').val(); 270 pick(src, desc); 271 return false; 272 } 273 274 jQuery(document).ready(function() { 275 jQuery('#img_container').html(strtoappend); 276 jQuery('#photo_add_url').attr('href', '?ajax=thickbox_url&height=200&width=500'); 277 tb_init('a.thickbox, area.thickbox, input.thickbox'); 278 }); 279 258 280 <?php die; } 259 281 … … 288 310 <script type="text/javascript"> 289 311 jQuery('#tags-input').hide(); 290 291 312 tag_update_quickclicks(); 292 313 … … 314 335 jQuery("#post_type").val(type); 315 336 } 337 316 338 function set_editor(text) { 317 339 … … 319 341 if(tinyMCE.activeEditor) tinyMCE.execCommand('mceInsertContent' ,false, text); 320 342 } 343 321 344 function append_editor(text) { 322 345 if(tinyMCE.activeEditor) tinyMCE.execCommand('mceInsertContent' ,false, text); 323 346 } 347 324 348 function set_title(title) { jQuery("#content_type").text(title); } 325 349 … … 331 355 set_menu('text'); 332 356 set_title('<?php _e('Post') ?>'); 333 334 357 return false; 335 break;358 break; 336 359 case 'quote' : 337 360 set_menu('quote'); 338 361 set_title('<?php _e('Quote') ?>'); 339 set_editor("<blockquote><p><?php echo $selection; ?> </p><p><cite><a href='<?php echo $url; ?>'><?php echo $title; ?> </a> </cite> </p></blockquote>");362 set_editor("<blockquote><p><?php echo format_to_edit($selection); ?> </p><p><cite><a href='<?php echo $url; ?>'><?php echo $title; ?> </a> </cite> </p></blockquote>"); 340 363 return false; 341 break;364 break; 342 365 case 'video' : 343 344 366 set_menu('video'); 345 367 set_title('<?php _e('Caption') ?>'); … … 348 370 jQuery('body').addClass('video_split'); 349 371 jQuery('#extra_fields').load('<?php echo clean_url($_SERVER['PHP_SELF']); ?>', { ajax: 'video', s: '<?php echo attribute_escape($selection); ?>'}, function() { 350 351 372 <?php 352 373 if ( preg_match("/youtube\.com\/watch/i", $url) ) { … … 359 380 $content = '<object width="400" height="225"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://www.vimeo.com/moogaloop.swf?clip_id=' . $video_id . '&server=www.vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" /> <embed src="http://www.vimeo.com/moogaloop.swf?clip_id=' . $video_id . '&server=www.vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="225"></embed></object>'; 360 381 361 if(trim($selection) == '') $selection = '<a href="http://www.vimeo.com/' . $video_id . '?pg=embed&sec=' . $video_id . '">' . $title . '</a> on <a href="http://vimeo.com?pg=embed&sec=' . $video_id . '">Vimeo</a>'; 362 }else { 382 if ( trim($selection) == '' ) 383 $selection = '<a href="http://www.vimeo.com/' . $video_id . '?pg=embed&sec=' . $video_id . '">' . $title . '</a> on <a href="http://vimeo.com?pg=embed&sec=' . $video_id . '">Vimeo</a>'; 384 } else { 363 385 $content = $selection; 364 386 } ?> … … 367 389 set_editor("<?php echo $title; ?>"); 368 390 }); 369 370 391 return false; 371 break; 372 392 break; 373 393 case 'photo' : 374 394 set_menu('photo'); 375 set_title(' Post');376 <?php if ($selection) { ?>377 set_editor("<?php echo $selection; ?>");395 set_title('<?php _e('Post') ?>'); 396 <?php if ($selection) { ?> 397 set_editor("<?php echo format_to_edit($selection); ?>"); 378 398 <?php } ?> 379 399 jQuery('#extra_fields').show(); 380 jQuery('#extra_fields').before('<h2 id="waiting"><img src="images/loading.gif" alt="" /> Loading...</h2>');400 jQuery('#extra_fields').before('<h2 id="waiting"><img src="images/loading.gif" alt="" /><?php echo js_escape( __( 'Loading...' ) ); ?></h2>'); 381 401 jQuery('#extra_fields').load('<?php echo clean_url($_SERVER['PHP_SELF']).'/?ajax=photo&u='.attribute_escape($url); ?>'); 382 402 jQuery.ajax({ … … 390 410 } 391 411 }); 392 393 412 return false; 394 break; 395 413 break; 396 414 } 397 398 415 } 399 416 … … 405 422 }); 406 423 424 // Set default tabs 407 425 <?php if ( preg_match("/youtube\.com\/watch/i", $url) ) { ?> 408 426 show('video'); … … 413 431 <?php } ?> 414 432 }); 433 415 434 </script> 416 435 </head> 417 436 <body class="press-this"> 418 437 <div id="wphead"> 419 <h1><span id="viewsite"><a href="<?php echo get_option('home'); ?>/"><?php _e('Visit:') ?> <?php bloginfo('name'); ?></a></span></h1>438 <h1><span id="viewsite"><a href="<?php echo get_option('home'); ?>/"><?php _e('Visit:') ?> <?php bloginfo('name'); ?></a></span></h1> 420 439 </div> 421 440 422 <ul id="menu" class="ui-tabs-nav"> 423 <li id="text_button" class="ui-tabs-selected"><a href="#"><?php _e('Text') ?></a></li> 424 <li id="photo_button"><a href="#"><?php _e('Photo') ?></a></li> 425 <li id="quote_button"><a href="#"><?php _e('Quote') ?></a></li> 426 <li id="video_button"><a href="#"><?php _e('Video') ?></a></li> 427 </ul> 428 429 <form action="press-this.php?action=post" method="post"> 430 431 <?php wp_nonce_field('press-this') ?> 432 <input type="hidden" name="post_type" id="post_type" value="text"/> 433 <div id="posting"> 434 435 <h2 id="title"><label for="post_title"><?php _e('Title') ?></label></h2> 436 <div class="titlewrap"> 437 <input name="post_title" id="post_title" class="text" value="<?php echo attribute_escape($title);?>"/> 438 </div> 439 440 <div id="extra_fields" style="display: none"></div> 441 <div class="editor_area"> 442 <h2 id="content_type"><label for="content"><?php _e('Post') ?></label></h2> 443 <div class="editor-container"> 444 <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> 445 </div> 446 </div> 447 448 </div> 449 <div id="categories"> 450 <div class="submitbox" id="submitpost"> 451 <div id="previewview"></div> 452 <div class="inside"> 453 <h2><?php _e('Categories') ?></h2> 454 <div id="categories-all"> 455 <ul id="categorychecklist" class="list:category categorychecklist form-no-clear"> 456 <?php wp_category_checklist() ?> 457 </ul> 458 </div> 459 <h2><?php _e('Tags') ?></h2> 460 <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> 461 <div id="tagchecklist"></div> 462 </div> 463 <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> 464 465 <p class="submit"> 466 <input type="submit" value="<?php _e('Publish') ?>" onclick="document.getElementById('photo_saving').style.display = '';"/> 467 <img src="images/loading-publish.gif" alt="" id="photo_saving" style="display:none;"/> 468 </p> 469 </div> 470 471 472 </form> 473 441 <ul id="menu" class="ui-tabs-nav"> 442 <li id="text_button" class="ui-tabs-selected"><a href="#"><?php _e('Text') ?></a></li> 443 <li id="photo_button"><a href="#"><?php _e('Photo') ?></a></li> 444 <li id="quote_button"><a href="#"><?php _e('Quote') ?></a></li> 445 <li id="video_button"><a href="#"><?php _e('Video') ?></a></li> 446 </ul> 447 448 <form action="press-this.php?action=post" method="post"> 449 <?php wp_nonce_field('press-this') ?> 450 <input type="hidden" name="post_type" id="post_type" value="text"/> 451 <div id="posting"> 452 <h2 id="title"><label for="post_title"><?php _e('Title') ?></label></h2> 453 <div class="titlewrap"> 454 <input name="post_title" id="post_title" class="text" value="<?php echo attribute_escape($title);?>"/> 455 </div> 456 457 <div id="extra_fields" style="display: none"></div> 458 459 <div class="editor_area"> 460 <h2 id="content_type"><label for="content"><?php _e('Post') ?></label></h2> 461 <div class="editor-container"> 462 <textarea name="content" id="content" style="width:100%;" class="mceEditor"><?php if ($selection) { ?><a href='<?php echo $url ?>'><?php echo format_to_edit($selection) ?></a><?php } else { ?><a href='<?php echo $url ?>'><?php echo $title; ?></a><?php } ?></textarea> 463 </div> 464 </div> 465 </div> 466 467 <div id="categories"> 468 <div class="submitbox" id="submitpost"> 469 <div id="previewview"></div> 470 <div class="inside"> 471 <h2><?php _e('Categories') ?></h2> 472 <div id="categories-all"> 473 <ul id="categorychecklist" class="list:category categorychecklist form-no-clear"> 474 <?php wp_category_checklist() ?> 475 </ul> 476 </div> 477 <h2><?php _e('Tags') ?></h2> 478 <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> 479 <div id="tagchecklist"></div> 480 </div> 481 <div id="post_status"> 482 <input type="radio" name="post_status" value="publish" checked="checked" id="published" /> <label for="published"><?php _e('Published'); ?></label> 483 <input type="radio" name="post_status" value="draft" id="unpublished" /> <label for="unpublished"><?php _e('Unpublished'); ?></label> 484 </div> 485 <p class="submit"> 486 <input type="submit" value="<?php _e('Publish') ?>" onclick="document.getElementById('photo_saving').style.display = '';"/> 487 <img src="images/loading-publish.gif" alt="" id="photo_saving" style="display:none;"/> 488 </p> 489 </div> 490 </form> 474 491 </body> 475 492 </html>
Note: See TracChangeset
for help on using the changeset viewer.