Changeset 8316 for trunk/wp-admin/press-this.php
- Timestamp:
- 07/11/2008 08:27:50 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/press-this.php
r8303 r8316 11 11 $translation_table[chr(38)] = '&'; 12 12 $translation_table[chr(39)] = '''; 13 return preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/","&" , strtr($text, $translation_table)); 13 return preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/","&" , strtr($text, $translation_table)); 14 14 } 15 15 function press_it() { 16 16 // define some basic variables 17 $quick['post_status'] = $_REQUEST['post_status'];17 $quick['post_status'] = isset($_REQUEST['publish']) ? 'publish' : 'draft'; 18 18 $quick['post_category'] = $_REQUEST['post_category']; 19 19 $quick['tags_input'] = $_REQUEST['tags_input']; 20 20 $quick['post_title'] = $_REQUEST['post_title']; 21 21 $quick['post_content'] = ''; 22 22 23 $posted = str_replace('<br />', "\n", str_replace('<p>', '', $_REQUEST['content'])); 24 $posted = str_replace('</p>', "\n\n", $posted); 25 23 26 // insert the post with nothing in it, to get an ID 24 27 $post_ID = wp_insert_post($quick, true); 25 28 26 29 $content = ''; 27 30 switch ( $_REQUEST['post_type'] ) { 28 31 case 'text': 29 32 case 'quote': 30 $content .= $ _REQUEST['content'];33 $content .= $posted; 31 34 break; 32 35 33 36 case 'photo': 34 $content = $ _REQUEST['content'];35 36 foreach( $_REQUEST['photo_src'] as $key => $image) {37 $content = $posted; 38 39 foreach( (array) $_REQUEST['photo_src'] as $key => $image) { 37 40 // escape quote for matching 38 41 $quoted = preg_quote2($image); 39 42 40 43 // see if files exist in content - we don't want to upload non-used selected files. 41 preg_match('/'.$quoted.'/', $_REQUEST['content'], $matches[0]); 42 if($matches[0]) { 44 if( strpos($posted, $quoted) !== false ) { 43 45 $upload = media_sideload_image($image, $post_ID, $_REQUEST['photo_description'][$key]); 44 46 // Replace the POSTED content <img> with correct uploaded ones. … … 46 48 } 47 49 } 48 50 49 51 break; 50 52 51 53 case "video": 52 54 if($_REQUEST['embed_code']) 53 55 $content .= $_REQUEST['embed_code']."\n\n"; 54 $content .= $ _REQUEST['content'];55 break; 56 $content .= $posted; 57 break; 56 58 } 57 59 // set the post_content 58 $quick['post_content'] = str_replace('<br />', "\n", preg_replace('/<\/?p>/','',$content));60 $quick['post_content'] = preg_replace("/\n\n+/", "\n\n", $content); 59 61 60 62 // error handling for $post … … 66 68 wp_die($upload); 67 69 wp_delete_post($post_ID); 68 } else { 70 } else { 69 71 $quick['ID'] = $post_ID; 70 72 wp_update_post($quick); … … 81 83 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" /> 82 84 <title><?php _e('Press This') ?></title> 85 <!--[if gte IE 6]> 86 <link rel="stylesheet" href="./css/press-this-ie.css" type="text/css" media="screen" charset="utf-8" /> 87 <![endif]--> 83 88 <?php 84 89 add_thickbox(); … … 92 97 ?> 93 98 </head> 94 <body class="press-this"> 95 <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> 99 <body class="press-this"> 100 <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> 96 101 <div id="footer"> 97 102 <p><?php … … 101 106 ?></p> 102 107 </div> 103 <?php do_action('admin_footer', ''); ?> 108 <?php do_action('admin_footer', ''); ?> 104 109 </body> 105 110 </html> … … 110 115 $title = wp_specialchars(aposfix(stripslashes($_GET['t']))); 111 116 112 $selection = str_replace("\n", "<br />", aposfix( stripslashes($_GET['s']) ) ); 117 $selection = trim( aposfix( stripslashes($_GET['s']) ) ); 118 if ( ! empty($selection) ) { 119 $selection = preg_replace('/(\r?\n|\r)/', '</p><p>', $selection); 120 $selection = '<p>'.str_replace('<p></p>', '', $selection).'</p>'; 121 } 122 113 123 $url = clean_url($_GET['u']); 114 124 $image = $_GET['i']; … … 119 129 tb_remove(); 120 130 }); 121 131 122 132 jQuery('.select').click(function() { 123 133 image_selector(); … … 128 138 <input id="this_photo_description" name="photo_description" class="text" onkeypress="if(event.keyCode==13) image_selector();" value="<?php echo attribute_escape($title);?>"/> 129 139 </div> 130 140 131 141 <p class="centered"><input type="hidden" name="this_photo" value="<?php echo attribute_escape($image); ?>" id="this_photo" /> 132 142 <a href="#" class="select"><img src="<?php echo clean_url($image); ?>" alt="<?php echo attribute_escape(__('Click to insert.')); ?>" title="<?php echo attribute_escape(__('Click to insert.')); ?>" /></a></p> 133 143 134 144 <p id="options"><a href="#" class="select button"><?php _e('Insert Image'); ?></a> <a href="#" class="cancel button"><?php _e('Cancel'); ?></a></p> 135 145 <?php die; … … 141 151 tb_remove(); 142 152 }); 143 153 144 154 jQuery('.select').click(function() { 145 155 image_selector(); … … 150 160 <input id="this_photo" name="this_photo" class="text" onkeypress="if(event.keyCode==13) image_selector();" /> 151 161 </div> 152 153 162 163 154 164 <h3 id="title"><label for="post_title"><?php _e('Description') ?></label></h3> 155 165 <div class="titlewrap"> 156 166 <input id="this_photo_description" name="photo_description" class="text" onkeypress="if(event.keyCode==13) image_selector();" value="<?php echo attribute_escape($title);?>"/> 157 167 </div> 158 168 159 169 <p id="options"><a href="#" class="select"><?php _e('Insert Image'); ?></a> | <a href="#" class="cancel"><?php _e('Cancel'); ?></a></p> 160 170 <?php die; … … 176 186 $content = wp_remote_fopen($uri); 177 187 if ( false === $content ) return ''; 178 188 179 189 $host = parse_url($uri); 180 190 181 191 $pattern = '/<img ([^>]*)src=(\"|\')([^<>]+?\.(png|jpeg|jpg|jpe|gif))(\2)([^>\/]*)\/*>/is'; 182 192 preg_match_all($pattern, $content, $matches); 183 193 184 194 if ( empty($matches[1]) ) return ''; 185 195 186 196 $sources = array(); 187 197 foreach ($matches[3] as $src) { … … 191 201 else 192 202 $src = 'http://'.str_replace('//','/', $host['host'].'/'.$host['path'].'/'.$src); 193 203 194 204 $sources[] = clean_url($src); 195 205 } 196 206 return "'" . implode("','", $sources) . "'"; 197 207 } 198 208 199 209 $url = urldecode($url); 200 210 $url = str_replace(' ', '%20', $url); 201 211 echo 'new Array('.get_images_from_uri($url).')'; 202 die; 212 die; 203 213 } 204 214 … … 217 227 }).responseText 218 228 ); 219 229 220 230 for (i = 0; i < my_src.length; i++) { 221 231 img = new Image(); … … 228 238 aspect = img.width / img.height; 229 239 scale = (aspect > 1) ? (75 / img.width) : (75 / img.height); 230 240 231 241 w = img.width; 232 242 h = img.height; 233 243 234 244 if (scale < 1) { 235 245 w = parseInt(img.width * scale); … … 240 250 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>'; 241 251 } 242 252 243 253 function pick(img, desc) { 244 254 if (img) { … … 252 262 return false; 253 263 } 254 264 255 265 function image_selector() { 256 266 tb_remove(); … … 260 270 return false; 261 271 } 262 272 263 273 jQuery(document).ready(function() { 264 274 jQuery('#img_container').html(strtoappend); … … 266 276 tb_init('a.thickbox, area.thickbox, input.thickbox'); 267 277 }); 268 278 269 279 <?php die; 270 280 } … … 288 298 289 299 <script type="text/javascript" src="../wp-includes/js/tinymce/tiny_mce.js?ver=311"></script> 300 <!--[if gte IE 6]> 301 <?php wp_enqueue_style('press-this-ie'); ?> 302 <![endif]--> 290 303 <?php 291 304 add_thickbox(); … … 310 323 sl.markDone(base + '/themes/advanced/langs/' + ln + '_dlg.js'); 311 324 })(); 312 325 313 326 tinyMCE.init({ 314 327 mode: "textareas", … … 331 344 convert_urls : false, 332 345 apply_source_formatting : false, 333 remove_linebreaks : false,346 remove_linebreaks : true, 334 347 accessibility_focus : false, 335 348 tab_focus : ":next", … … 346 359 // add the quickadd form 347 360 jQuery('#jaxtag').prepend('<span id="ajaxtag"><input type="text" name="newtag" id="newtag" class="form-input-tip" size="16" autocomplete="off" value="'+postL10n.addTag+'" /><input type="submit" class="button" id="tagadd" value="' + postL10n.add + '" tabindex="3" onclick="return false;" /><input type="hidden"/><input type="hidden"/><span class="howto">'+postL10n.separate+'</span></span>'); 348 361 349 362 jQuery('#tagadd').click( tag_flush_to_text ); 350 363 jQuery('#newtag').focus(function() { … … 360 373 jQuery('#publish').click( tag_save_on_publish ); 361 374 jQuery('#save-post').click( tag_save_on_publish ); 362 375 363 376 function set_menu(type) { 364 377 jQuery('#text_button').removeClass('ui-tabs-selected'); … … 367 380 jQuery("#post_type").val(type); 368 381 } 369 382 370 383 function set_editor(text) { 371 if (tinyMCE.activeEditor) tinyMCE.activeEditor.setContent('');372 if (tinyMCE.activeEditor) tinyMCE.execCommand('mceInsertContent' ,false, text);373 } 374 384 if ( '' == text || '<p></p>' == text ) text = '<p><br /></p>'; 385 if ( tinyMCE.activeEditor ) tinyMCE.execCommand('mceSetContent', false, text); 386 } 387 375 388 function append_editor(text) { 376 if (tinyMCE.activeEditor) tinyMCE.execCommand('mceInsertContent' ,false, text);377 } 378 389 if ( '' != text && tinyMCE.activeEditor ) tinyMCE.execCommand('mceInsertContent', false, text); 390 } 391 379 392 function set_title(title) { jQuery("#content_type").text(title); } 380 393 … … 387 400 set_title('<?php _e('Post') ?>'); 388 401 <?php if ($selection) { ?> 389 set_editor( "<?php echo $selection; ?>");402 set_editor('<?php echo $selection; ?><p><a href="<?php echo $url ?>"><?php echo $title; ?></a> ‏</p>'); 390 403 <?php } else { ?> 391 set_editor( "<a href='<?php echo $url ?>'><?php echo $title; ?></a>");404 set_editor('<p><a href="<?php echo $url ?>"><?php echo $title; ?></a></p>'); 392 405 <?php } ?> 393 406 return false; … … 396 409 set_menu('quote'); 397 410 set_title('<?php _e('Quote') ?>'); 398 set_editor( "<blockquote><p><?php echo $selection; ?> </p><p><cite><a href='<?php echo $url; ?>'><?php echo $title; ?> </a> </cite> </p></blockquote>");411 set_editor('<blockquote><?php echo $selection; ?> <p><cite><a href="<?php echo $url; ?>"><?php echo $title; ?> </a> </cite> </p></blockquote>'); 399 412 return false; 400 413 break; … … 406 419 jQuery('#extra_fields').load('<?php echo clean_url($_SERVER['PHP_SELF']); ?>', { ajax: 'video', s: '<?php echo attribute_escape($selection); ?>'}, function() { 407 420 <?php 421 $content = ''; 408 422 if ( preg_match("/youtube\.com\/watch/i", $url) ) { 409 423 list($domain, $video_id) = split("v=", $url); 410 424 $content = '<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/' . $video_id . '"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/' . $video_id . '" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>'; 411 425 412 426 } elseif ( preg_match("/vimeo\.com\/[0-9]+/i", $url) ) { 413 427 list($domain, $video_id) = split(".com/", $url); 414 428 $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>'; 415 429 416 430 if ( trim($selection) == '' ) 417 $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>';418 419 } else {431 $selection = '<p><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></p>'; 432 433 } elseif ( strpos( $selection, '<object' ) !== false ) { 420 434 $content = $selection; 421 435 } 422 423 436 ?> 424 437 jQuery('#embed_code').prepend('<?php echo htmlentities($content); ?>'); 425 426 set_editor( "<?php echo $title; ?>");438 439 set_editor('<a href="<?php echo $url ?>"><?php echo $title; ?></a> ‏'); 427 440 }); 428 441 return false; … … 432 445 set_title('<?php _e('Post') ?>'); 433 446 <?php if ($selection) { ?> 434 set_editor( "<?php echo $selection; ?>");447 set_editor('<?php echo $selection; ?><p><a href="<?php echo $url ?>"><?php echo $title; ?></a></p>'); 435 448 <?php } else { ?> 436 set_editor( "<a href='<?php echo $url ?>'><?php echo $title; ?></a>");449 set_editor('<p><a href="<?php echo $url ?>"><?php echo $title; ?></a></p>'); 437 450 <?php } ?> 438 451 jQuery('#extra_fields').show(); … … 453 466 } 454 467 } 455 468 456 469 jQuery(document).ready(function() { 457 470 jQuery('#menu li').click(function (){ … … 492 505 <input name="post_title" id="post_title" class="text" value="<?php echo attribute_escape($title);?>"/> 493 506 </div> 494 507 495 508 <div id="extra_fields" style="display: none"></div> 496 509 497 510 <div class="editor_area"> 498 511 <h2 id="content_type"><label for="content"><?php _e('Post') ?></label></h2> 499 512 <div class="editor-container"> 500 <textarea name="content" id="content" style="width:100%;" class="mceEditor"><?php if ($selection) { echo wp_richedit_pre($selection); } else { ?><a href='<?php echo $url ?>'><?php echo $title; ?></a><?php } ?></textarea>513 <textarea name="content" id="content" style="width:100%;" class="mceEditor"><?php if ($selection) { echo wp_richedit_pre($selection); } ?><a href="<?php echo $url ?>"><?php echo $title; ?></a> ‏</textarea> 501 514 </div> 502 515 </div> … … 505 518 <div id="categories"> 506 519 <div class="submitbox" id="submitpost"> 507 <div id="previewview"></div> 508 <div class="inside"> 509 <h2><?php _e('Categories') ?></h2> 510 <div id="categories-all"> 511 <ul id="categorychecklist" class="list:category categorychecklist form-no-clear"> 512 <?php wp_category_checklist() ?> 513 </ul> 520 <div id="previewview"></div> 521 <div class="inside"> 522 <h2><?php _e('Categories') ?></h2> 523 <div id="categories-all"> 524 <ul id="categorychecklist" class="list:category categorychecklist form-no-clear"> 525 <?php wp_category_checklist() ?> 526 </ul> 527 </div> 528 529 <h2><?php _e('Tags') ?></h2> 530 <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> 531 <div id="tagchecklist"></div> 514 532 </div> 515 <h2><?php _e('Tags') ?></h2> 516 <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> 517 <div id="tagchecklist"></div> 533 534 <p class="submit"> 535 <input type="submit" name="draft" value="<?php _e('Save') ?>" onclick="document.getElementById('photo_saving').style.display = '';"/> 536 <input type="submit" name="publish" value="<?php _e('Publish') ?>" onclick="document.getElementById('photo_saving').style.display = '';"/> 537 <img src="images/loading-publish.gif" alt="" id="photo_saving" style="display:none;"/> 538 </p> 518 539 </div> 519 <div id="post_status">520 <input type="radio" name="post_status" value="publish" checked="checked" id="published" /> <label for="published"><?php _e('Published'); ?></label>521 <input type="radio" name="post_status" value="draft" id="unpublished" /> <label for="unpublished"><?php _e('Unpublished'); ?></label>522 </div>523 <p class="submit">524 <input type="submit" value="<?php _e('Publish') ?>" onclick="document.getElementById('photo_saving').style.display = '';"/>525 <img src="images/loading-publish.gif" alt="" id="photo_saving" style="display:none;"/>526 </p>527 540 </div> 528 541 </form>
Note: See TracChangeset
for help on using the changeset viewer.