2 require_once('admin.php');
4 if ( ! current_user_can('publish_posts') ) wp_die( __( 'Cheatin’ uh?' ) );
6 function preg_quote2($string) {
7 return str_replace('/', '\/', preg_quote($string));
9 function aposfix($text) {
10 $translation_table[chr(34)] = '"';
11 $translation_table[chr(38)] = '&';
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));
16 // define some basic variables
17 $quick['post_status'] = isset($_REQUEST['publish']) ? 'publish' : 'draft';
18 $quick['post_category'] = $_REQUEST['post_category'];
19 $quick['tags_input'] = $_REQUEST['tags_input'];
20 $quick['post_title'] = $_REQUEST['post_title'];
21 $quick['post_content'] = '';
23 // insert the post with nothing in it, to get an ID
24 $post_ID = wp_insert_post($quick, true);
27 switch ( $_REQUEST['post_type'] ) {
30 $content .= $_REQUEST['content'];
34 $content = $_REQUEST['content'];
36 foreach( (array) $_REQUEST['photo_src'] as $key => $image) {
38 // see if files exist in content - we don't want to upload non-used selected files.
39 if( strpos($_REQUEST['content'], $image) !== false ) {
40 $upload = media_sideload_image($image, $post_ID, $_REQUEST['photo_description'][$key]);
42 // Replace the POSTED content <img> with correct uploaded ones.
43 // escape quote for matching
44 $quoted = preg_quote2($image);
45 if( !is_wp_error($upload) ) $content = preg_replace('/<img ([^>]*)src=(\"|\')'.$quoted.'(\2)([^>\/]*)\/*>/is', $upload, $content);
52 if($_REQUEST['embed_code'])
53 $content .= $_REQUEST['embed_code']."\n\n";
54 $content .= $_REQUEST['content'];
57 // set the post_content
58 $quick['post_content'] = $content;
60 // error handling for $post
61 if ( is_wp_error($post_ID)) {
63 wp_delete_post($post_ID);
64 // error handling for media_sideload
65 } elseif ( is_wp_error($upload)) {
67 wp_delete_post($post_ID);
69 $quick['ID'] = $post_ID;
70 wp_update_post($quick);
75 // For submitted posts.
76 if ( 'post' == $_REQUEST['action'] ) {
77 check_admin_referer('press-this'); $post_ID = press_it(); ?>
78 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
79 <html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
81 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
82 <title><?php _e('Press This') ?></title>
85 wp_enqueue_style('press-this');
86 wp_enqueue_style('press-this-ie');
87 wp_enqueue_style( 'colors' );
88 wp_enqueue_script('post');
90 do_action('admin_print_styles');
91 do_action('admin_print_scripts');
92 do_action('admin_head');
95 <body class="press-this">
96 <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 do_action('in_admin_footer', '');
100 $upgrade = apply_filters( 'update_footer', '' );
101 echo __('Thank you for creating with <a href="http://wordpress.org/">WordPress</a>');
104 <?php do_action('admin_footer', ''); ?>
111 $title = wp_specialchars(aposfix(stripslashes($_GET['t'])));
113 $selection = trim( aposfix( stripslashes($_GET['s']) ) );
114 if ( ! empty($selection) ) {
115 $selection = preg_replace('/(\r?\n|\r)/', '</p><p>', $selection);
116 $selection = '<p>'.str_replace('<p></p>', '', $selection).'</p>';
119 $url = clean_url($_GET['u']);
122 if($_REQUEST['ajax'] == 'thickbox') { ?>
123 <script type="text/javascript" charset="utf-8">
124 jQuery('.cancel').click(function() {
128 jQuery('.select').click(function() {
132 <h3 id="title"><label for="post_title"><?php _e('Description') ?></label></h3>
133 <div class="titlewrap">
134 <input id="this_photo_description" name="photo_description" class="text" onkeypress="if(event.keyCode==13) image_selector();" value="<?php echo attribute_escape($title);?>"/>
137 <p class="centered"><input type="hidden" name="this_photo" value="<?php echo attribute_escape($image); ?>" id="this_photo" />
138 <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>
140 <p id="options"><a href="#" class="select button"><?php _e('Insert Image'); ?></a> <a href="#" class="cancel button"><?php _e('Cancel'); ?></a></p>
144 if($_REQUEST['ajax'] == 'thickbox_url') { ?>
145 <script type="text/javascript" charset="utf-8">
146 jQuery('.cancel').click(function() {
150 jQuery('.select').click(function() {
154 <h3 id="title"><label for="post_title"><?php _e('URL') ?></label></h3>
155 <div class="titlewrap">
156 <input id="this_photo" name="this_photo" class="text" onkeypress="if(event.keyCode==13) image_selector();" />
160 <h3 id="title"><label for="post_title"><?php _e('Description') ?></label></h3>
161 <div class="titlewrap">
162 <input id="this_photo_description" name="photo_description" class="text" onkeypress="if(event.keyCode==13) image_selector();" value="<?php echo attribute_escape($title);?>"/>
165 <p id="options"><a href="#" class="select"><?php _e('Insert Image'); ?></a> | <a href="#" class="cancel"><?php _e('Cancel'); ?></a></p>
169 if($_REQUEST['ajax'] == 'video') { ?>
170 <h2 id="embededcode"><label for="embed_code"><?php _e('Embed Code') ?></label></h2>
171 <div class="titlewrap" >
172 <textarea name="embed_code" id="embed_code" rows="8" cols="40"><?php echo format_to_edit($selection); ?></textarea>
177 if($_REQUEST['ajax'] == 'photo_images') {
178 function get_images_from_uri($uri) {
179 if( preg_match('/\.(jpg|jpe|jpeg|png|gif)/', $uri) && !strpos($uri,'blogger.com') )
182 $content = wp_remote_fopen($uri);
183 if ( false === $content ) return '';
185 $host = parse_url($uri);
187 $pattern = '/<img ([^>]*)src=(\"|\')([^<>]+?\.(png|jpeg|jpg|jpe|gif))[^<>\'\"]*(\2)([^>\/]*)\/*>/is';
188 preg_match_all($pattern, $content, $matches);
190 if ( empty($matches[1]) ) return '';
193 foreach ($matches[3] as $src) {
195 if(strpos($src, 'http') === false)
196 // if it doesn't have a relative uri
197 if( strpos($src, '../') === false && strpos($src, './') === false && strpos($src, '/') === true)
198 $src = 'http://'.str_replace('//','/', $host['host'].'/'.$src);
200 $src = 'http://'.str_replace('//','/', $host['host'].'/'.dirname($host['path']).'/'.$src);
202 $sources[] = clean_url($src);
204 return "'" . implode("','", $sources) . "'";
207 $url = urldecode($url);
208 $url = str_replace(' ', '%20', $url);
209 echo 'new Array('.get_images_from_uri($url).')';
213 if($_REQUEST['ajax'] == 'photo_js') { ?>
214 // gather images and load some default JS
216 var img, img_tag, aspect, w, h, skip, i, strtoappend = "";
220 url: "<?php echo clean_url($_SERVER['PHP_SELF']); ?>",
223 data: "ajax=photo_images&u=<?php echo urlencode($url); ?>",
228 for (i = 0; i < my_src.length; i++) {
231 img_attr = 'id="img' + i + '"';
233 if (img.width && img.height) {
234 if (img.width * img.height < 2500)
236 aspect = img.width / img.height;
237 scale = (aspect > 1) ? (75 / img.width) : (75 / img.height);
243 w = parseInt(img.width * scale);
244 h = parseInt(img.height * scale);
246 img_attr += ' style="width: ' + w + 'px; height: ' + h + 'px;"';
248 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>';
251 function pick(img, desc) {
253 if('object' == typeof jQuery('.photolist input') && jQuery('.photolist input').length != 0) length = jQuery('.photolist input').length;
254 if(length == 0) length = 1;
255 jQuery('.photolist').append('<input name="photo_src[' + length + ']" value="' + img +'" type="hidden"/>');
256 jQuery('.photolist').append('<input name="photo_description[' + length + ']" value="' + desc +'" type="hidden"/>');
257 append_editor("\n\n" + '<p><img src="' + img +'" alt="' + desc + '" class="aligncenter"/></p>');
259 tinyMCE.activeEditor.resizeToContent();
263 function image_selector() {
265 desc = jQuery('#this_photo_description').val();
266 src = jQuery('#this_photo').val();
271 jQuery(document).ready(function() {
272 jQuery('#extra_fields').html('<div class="photolist"></div><small id="photo_directions"><?php _e("Click images to select:") ?> <span><a href="#" id="photo_add_url" class="thickbox"><?php _e("Add from URL") ?> +</a></span></small><div class="titlewrap"><div id="img_container"></div></div>');
273 jQuery('#img_container').html(strtoappend);
274 jQuery('#photo_add_url').attr('href', '?ajax=thickbox_url&height=200&width=500');
275 tb_init('a.thickbox, area.thickbox, input.thickbox');
281 if($_REQUEST['ajax'] == 'photo') { ?>
286 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
287 <html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
289 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
290 <title><?php _e('Press This') ?></title>
292 <script type="text/javascript" src="../wp-includes/js/tinymce/tiny_mce.js?ver=311"></script>
295 wp_enqueue_style('press-this');
296 wp_enqueue_style('press-this-ie');
297 wp_enqueue_style( 'colors' );
298 wp_enqueue_script('post');
299 wp_enqueue_script('editor_functions');
301 do_action('admin_print_styles');
302 do_action('admin_print_scripts');
303 do_action('admin_head');
305 <script type="text/javascript">
306 <?php if ( user_can_richedit() ) {
307 $language = ( '' == get_locale() ) ? 'en' : strtolower( substr(get_locale(), 0, 2) );
308 // Add TinyMCE languages
309 @include_once( dirname(__FILE__).'/../wp-includes/js/tinymce/langs/wp-langs.php' );
310 if ( isset($strings) ) echo $strings; ?>
312 var base = tinymce.baseURL, sl = tinymce.ScriptLoader, ln = "<?php echo $language; ?>";
313 sl.markDone(base + '/langs/' + ln + '.js');
314 sl.markDone(base + '/themes/advanced/langs/' + ln + '.js');
315 sl.markDone(base + '/themes/advanced/langs/' + ln + '_dlg.js');
320 editor_selector: "mceEditor",
321 language : "<?php echo $language; ?>",
325 theme_advanced_buttons1 : "bold,italic,underline,blockquote,separator,strikethrough,bullist,numlist,undo,redo,link,unlink",
326 theme_advanced_buttons2 : "",
327 theme_advanced_buttons3 : "",
328 theme_advanced_toolbar_location : "top",
329 theme_advanced_toolbar_align : "left",
330 theme_advanced_statusbar_location : "bottom",
331 theme_advanced_resizing : true,
332 theme_advanced_resize_horizontal : false,
334 dialog_type : "modal",
335 relative_urls : false,
336 remove_script_host : false,
337 convert_urls : false,
338 apply_source_formatting : false,
339 remove_linebreaks : true,
340 accessibility_focus : false,
342 plugins : "safari,inlinepopups",
343 entities : "38,amp,60,lt,62,gt",
344 force_p_newlines : true,
345 save_callback : 'switchEditors.saveCallback'
349 jQuery('#tags-input').hide();
351 tag_update_quickclicks();
353 // add the quickadd form
354 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>');
356 jQuery('#tagadd').click( tag_flush_to_text );
357 jQuery('#newtag').focus(function() {
358 if ( this.value == postL10n.addTag )
359 jQuery(this).val( '' ).removeClass( 'form-input-tip' );
361 jQuery('#newtag').blur(function() {
362 if ( this.value == '' )
363 jQuery(this).val( postL10n.addTag ).addClass( 'form-input-tip' );
366 // auto-save tags on post save/publish
367 jQuery('#publish').click( tag_save_on_publish );
368 jQuery('#save-post').click( tag_save_on_publish );
370 function set_menu(type) {
371 jQuery('#text_button').removeClass('ui-tabs-selected');
372 jQuery('#menu li').removeClass('ui-tabs-selected');
373 jQuery('#' + type + '_button').addClass('ui-tabs-selected');
374 jQuery("#post_type").val(type);
377 function set_editor(text) {
378 if ( '' == text || '<p></p>' == text ) text = '<p><br /></p>';
379 if ( tinyMCE.activeEditor ) tinyMCE.execCommand('mceSetContent', false, text);
382 function append_editor(text) {
383 if ( '' != text && tinyMCE.activeEditor ) tinyMCE.execCommand('mceInsertContent', false, text);
386 function set_title(title) { jQuery("#content_type").text(title); }
388 function show(tab_name) {
389 jQuery('body').removeClass('video_split');
390 jQuery('#extra_fields').hide();
394 set_title('<?php _e('Post') ?>');
395 <?php if ($selection) { ?>
396 set_editor('<?php echo $selection; ?><p><a href="<?php echo $url ?>"><?php echo $title; ?></a>.</p>');
398 set_editor('<p><a href="<?php echo $url ?>"><?php echo $title; ?></a></p>');
404 set_title('<?php _e('Quote') ?>');
405 set_editor('<blockquote><?php echo $selection; ?> <p><cite><a href="<?php echo $url; ?>"><?php echo $title; ?> </a> </cite> </p></blockquote>');
410 set_title('<?php _e('Caption') ?>');
411 jQuery('#extra_fields').show();
412 jQuery('body').addClass('video_split');
413 jQuery('#extra_fields').load('<?php echo clean_url($_SERVER['PHP_SELF']); ?>', { ajax: 'video', s: '<?php echo attribute_escape($selection); ?>'}, function() {
416 if ( preg_match("/youtube\.com\/watch/i", $url) ) {
417 list($domain, $video_id) = split("v=", $url);
418 $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>';
420 } elseif ( preg_match("/vimeo\.com\/[0-9]+/i", $url) ) {
421 list($domain, $video_id) = split(".com/", $url);
422 $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>';
424 if ( trim($selection) == '' )
425 $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>';
427 } elseif ( strpos( $selection, '<object' ) !== false ) {
428 $content = $selection;
431 jQuery('#embed_code').prepend('<?php echo htmlentities($content); ?>');
433 set_editor('<a href="<?php echo $url ?>"><?php echo $title; ?></a>.');
439 set_title('<?php _e('Post') ?>');
440 <?php if ($selection) { ?>
441 set_editor('<?php echo $selection; ?><p><a href="<?php echo $url ?>"><?php echo $title; ?></a></p>');
443 set_editor('<p><a href="<?php echo $url ?>"><?php echo $title; ?></a></p>');
445 jQuery('#extra_fields').show();
446 jQuery('#extra_fields').before('<h2 id="waiting"><img src="images/loading.gif" alt="" /><?php echo js_escape( __( 'Loading...' ) ); ?></h2>');
450 url: "<?php echo clean_url($_SERVER['PHP_SELF']); ?>",
451 data: "ajax=photo_js&u=<?php echo urlencode($url)?>",
453 success : function() {
454 jQuery('#waiting').remove();
462 jQuery(document).ready(function() {
463 jQuery('#menu li').click(function (){
464 tab_name = this.id.split('_');
465 tab_name = tab_name[0];
469 <?php if ( preg_match("/youtube\.com\/watch/i", $url) ) { ?>
471 <?php } elseif ( preg_match("/vimeo\.com\/[0-9]+/i", $url) ) { ?>
473 <?php } elseif ( preg_match("/flickr\.com/i", $url) ) { ?>
480 <body class="press-this">
482 <h1><span id="viewsite"><a href="<?php echo get_option('home'); ?>/"><?php _e('Visit:') ?> <?php bloginfo('name'); ?></a></span></h1>
485 <ul id="menu" class="ui-tabs-nav">
486 <li id="text_button" class="ui-tabs-selected"><a href="#"><?php _e('Text') ?></a></li>
487 <li id="photo_button"><a href="#"><?php _e('Photo') ?></a></li>
488 <li id="quote_button"><a href="#"><?php _e('Quote') ?></a></li>
489 <li id="video_button"><a href="#"><?php _e('Video') ?></a></li>
492 <form action="press-this.php?action=post" method="post">
493 <?php wp_nonce_field('press-this') ?>
494 <input type="hidden" name="post_type" id="post_type" value="text"/>
496 <h2 id="title"><label for="post_title"><?php _e('Title') ?></label></h2>
497 <div class="titlewrap">
498 <input name="post_title" id="post_title" class="text" value="<?php echo attribute_escape($title);?>"/>
501 <div id="extra_fields" style="display: none"></div>
503 <div class="editor_area">
504 <h2 id="content_type"><label for="content"><?php _e('Post') ?></label></h2>
505 <div class="editor-container">
506 <textarea name="content" id="content" style="width:100%;" class="mceEditor" rows="15"><?php if ($selection) { echo wp_richedit_pre($selection); } ?><a href="<?php echo $url ?>"><?php echo $title; ?></a>.</textarea>
511 <div id="categories">
512 <div class="submitbox" id="submitpost">
513 <div id="previewview"></div>
515 <h2><?php _e('Categories') ?></h2>
516 <div id="categories-all">
517 <ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
518 <?php wp_category_checklist() ?>
522 <h2><?php _e('Tags') ?></h2>
523 <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>
524 <div id="tagchecklist"></div>
528 <input type="submit" name="draft" value="<?php _e('Save') ?>" onclick="document.getElementById('photo_saving').style.display = '';"/>
529 <input type="submit" name="publish" value="<?php _e('Publish') ?>" onclick="document.getElementById('photo_saving').style.display = '';"/>
530 <img src="images/loading-publish.gif" alt="" id="photo_saving" style="display:none;"/>