diff options
author | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2008-06-24 17:00:10 +0000 |
---|---|---|
committer | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2008-06-24 17:00:10 +0000 |
commit | 631c9bb4d60d242432052f56c00768392f42a392 (patch) | |
tree | 50d41b0248d5c5fb156c6d52020675208b77a3e6 /wp-admin/press-this.php | |
parent | a1fbe4e0694a66d7351e2f6280ab84568681e8e0 (diff) | |
download | wordpress-mu-631c9bb4d60d242432052f56c00768392f42a392.tar.gz wordpress-mu-631c9bb4d60d242432052f56c00768392f42a392.tar.xz wordpress-mu-631c9bb4d60d242432052f56c00768392f42a392.zip |
WP Merge to revision 8180
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@1336 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-admin/press-this.php')
-rw-r--r-- | wp-admin/press-this.php | 420 |
1 files changed, 223 insertions, 197 deletions
diff --git a/wp-admin/press-this.php b/wp-admin/press-this.php index a0bfd1c..ded9e01 100644 --- a/wp-admin/press-this.php +++ b/wp-admin/press-this.php @@ -4,15 +4,19 @@ require_once('admin.php'); if ( ! current_user_can('publish_posts') ) wp_die( __( 'Cheatin’ uh?' )); ?> <?php + +function preg_quote2($string) { + return str_replace('/', '\/', preg_quote($string)); +} function press_it() { - #define some basic variables - $quick['post_status'] = 'publish'; + // define some basic variables + $quick['post_status'] = $_REQUEST['post_status']; $quick['post_category'] = $_REQUEST['post_category']; $quick['tags_input'] = $_REQUEST['tags_input']; $quick['post_title'] = $_REQUEST['post_title']; $quick['post_content'] = ''; - # insert the post with nothing in it, to get an ID + // insert the post with nothing in it, to get an ID $post_ID = wp_insert_post($quick, true); $content = ''; @@ -23,16 +27,21 @@ function press_it() { break; case 'photo': - foreach($_REQUEST['photo_src'] as $key => $data) { + $content = $_REQUEST['content']; + + foreach($_REQUEST['photo_src'] as $key => $image) { #quote for matching - $quoted = str_replace('/', '\/', preg_quote($data)); + $quoted = preg_quote2($image); - # see if files exist in content - we don't want to upload non-used selected files. + // see if files exist in content - we don't want to upload non-used selected files. preg_match('/'.$quoted.'/', $_REQUEST['content'], $matches[0]); - if($matches[0]) - media_sideload_image($data, $post_ID, $_REQUEST['photo_description'][$key]); + if($matches[0]) { + $upload = media_sideload_image($image, $post_ID, $_REQUEST['photo_description'][$key]); + // Replace the POSTED content <img> with correct uploaded ones. + if( !is_wp_error($upload) ) $content = preg_replace('/<img ([^>]*)src=(\"|\')'.$quoted.'(\2)([^>\/]*)\/*>/is', $upload, $content); + } } - $content = $_REQUEST['content']; + break; case "video": @@ -42,14 +51,16 @@ function press_it() { break; } # set the post_content - $quick['post_content'] = $content; + $quick['post_content'] = str_replace('<br />', "\n", preg_replace('/<\/?p>/','',$content)); #error handling for $post - if ( is_wp_error($post_ID) ) { + if ( is_wp_error($post_ID)) { wp_die($id); wp_delete_post($post_ID); - #error handling for media_sideload + } elseif ( is_wp_error($upload)) { + wp_die($upload); + wp_delete_post($post_ID); } else { $quick['ID'] = $post_ID; wp_update_post($quick); @@ -57,30 +68,6 @@ function press_it() { return $post_ID; } - -function category_div() { ?> - <div id="categories"> - <div class="submitbox" id="submitpost"> - <div id="previewview"></div> - <div class="inside"> - <h2><?php _e('Categories') ?></h2> - <div id="categories-all"> - <ul id="categorychecklist" class="list:category categorychecklist form-no-clear"> - <?php wp_category_checklist() ?> - </ul> - </div> - <h2><?php _e('Tags') ?></h2> - <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> - <div id="tagchecklist"></div> - - </div> - <p class="submit"> - <input type="submit" value="<?php _e('Publish') ?>" onclick="document.getElementById('photo_saving').style.display = '';"/> - <img src="images/loading.gif" alt="" id="photo_saving" style="width:16px; height:16px; vertical-align:-4px; display:none;"/> - </p> - </div> -<?php } - # For submitted posts. if ( 'post' == $_REQUEST['action'] ) { check_admin_referer('press-this'); $post_ID = press_it(); ?> @@ -102,35 +89,47 @@ if ( 'post' == $_REQUEST['action'] ) { ?> </head> <body class="press-this"> + <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> + + <div id="footer"> + <p><?php + do_action('in_admin_footer', ''); + $upgrade = apply_filters( 'update_footer', '' ); + echo __('Thank you for creating with <a href="http://wordpress.org/">WordPress</a>'); + ?></p> + </div> + <?php do_action('admin_footer', ''); ?> + </body> </html> <?php die; } + +function aposfix($text) { + $translation_table[chr(34)] = '"'; + $translation_table[chr(38)] = '&'; + $translation_table[chr(39)] = '''; + return preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/","&" , strtr($text, $translation_table)); +} + // Ajax Requests $title = wp_specialchars(stripslashes($_GET['t'])); -$selection = trim(wp_specialchars(str_replace("\n", ' ',stripslashes($_GET['s'])))); -$url = $_GET['u']; + +$selection = str_replace("\n", "<br />", aposfix( stripslashes($_GET['s']) ) ); +$url = clean_url($_GET['u']); $image = $_GET['i']; + if($_REQUEST['ajax'] == 'thickbox') { ?> - <script type="text/javascript" charset="utf-8"> + <script type="text/javascript" charset="utf-8"> jQuery('.cancel').click(function() { tb_remove(); }); - function image_selector() { - desc = jQuery('#this_photo_description').val(); - src = jQuery('#this_photo').val(); - pick(src, desc); - tb_remove(); - return false; - } - jQuery('.select').click(function() { image_selector(); }); - </script> <h3 id="title"><label for="post_title"><?php _e('Description') ?></label></h3> <div class="titlewrap"> @@ -138,12 +137,36 @@ if($_REQUEST['ajax'] == 'thickbox') { ?> </div> <p><input type="hidden" name="this_photo" value="<?php echo $image; ?>" id="this_photo" /> - <a href="#" class="select" rel="<?php echo $image; ?>"><img src="<?php echo $image; ?>" width="475" alt="Click to insert." title="Click to insert." /></a></p> + <a href="#" class="select"><img src="<?php echo $image; ?>" width="475" alt="Click to insert." title="Click to insert." /></a></p> - <p id="options"><a href="#" class="select" rel="<?php echo $image; ?>">Insert Image</a> | <a href="#" class="cancel">Cancel</a></p> + <p id="options"><a href="#" class="select">Insert Image</a> | <a href="#" class="cancel">Cancel</a></p> <?php die; } +if($_REQUEST['ajax'] == 'thickbox_url') { ?> + <script type="text/javascript" charset="utf-8"> + jQuery('.cancel').click(function() { + tb_remove(); + }); + + jQuery('.select').click(function() { + image_selector(); + }); + </script> + <h3 id="title"><label for="post_title"><?php _e('URL') ?></label></h3> + <div class="titlewrap"> + <input id="this_photo" name="this_photo" class="text" onkeypress="if(event.keyCode==13) image_selector();" /> + </div> + + + <h3 id="title"><label for="post_title"><?php _e('Description') ?></label></h3> + <div class="titlewrap"> + <input id="this_photo_description" name="photo_description" class="text" onkeypress="if(event.keyCode==13) image_selector();" value="<?php echo attribute_escape($title);?>"/> + </div> + + <p id="options"><a href="#" class="select">Insert Image</a> | <a href="#" class="cancel">Cancel</a></p> +<?php die; +} if($_REQUEST['ajax'] == 'video') { ?> <h2 id="embededcode"><label for="embed_code"><?php _e('Embed Code') ?></label></h2> @@ -154,110 +177,117 @@ if($_REQUEST['ajax'] == 'video') { ?> } if($_REQUEST['ajax'] == 'photo_images') { -$url = urldecode($url); -$url = str_replace(' ', '%20', $url); - function get_images_from_uri($uri) { - if(preg_match('/\.(jpg|png|gif)/', $uri)) return "'".$uri."'"; + if(preg_match('/\.(jpg|png|gif)/', $uri) && !strpos($uri,'blogger.com')) + return "'".$uri."'"; + $content = wp_remote_fopen($uri); - $host = parse_url($uri); if ( false === $content ) return ''; - - $pattern = '/<img[^>]+src=[\'"]([^\'" >]+?)[\'" >]/is'; + + $host = parse_url($uri); + + $pattern = '/<img ([^>]*)src=(\"|\')(.+?)(\2)([^>\/]*)\/*>/is'; preg_match_all($pattern, $content, $matches); + if ( empty($matches[1]) ) return ''; - + $sources = array(); - - foreach ($matches[1] as $src) { - if ( false !== strpos($src, '&') ) continue; - if(strpos($src, 'http') === false) { - if(strpos($src, '../') === false && strpos($src, './') === false) { - $src = 'http://'.str_replace('//','/', $host['host'].'/'.$src); - } else { - $src = 'http://'.str_replace('//','/', $host['host'].'/'.$host['path'].'/'.$src); - } - } - $sources[] = $src; + foreach ($matches[3] as $src) { + if(strpos($src, 'http') === false) + if(strpos($src, '../') === false && strpos($src, './') === false) + $src = 'http://'.str_replace('//','/', $host['host'].'/'.$src); + else + $src = 'http://'.str_replace('//','/', $host['host'].'/'.$host['path'].'/'.$src); + + $sources[] = $src; } return "'" . implode("','", $sources) . "'"; } - + $url = urldecode($url); + $url = str_replace(' ', '%20', $url); echo 'new Array('.get_images_from_uri($url).')'; die; } if($_REQUEST['ajax'] == 'photo_js') { ?> - var last = null + + // gather images and load some default JS + + var last = null + var img, img_tag, aspect, w, h, skip, i, strtoappend = ""; + var my_src = eval( + jQuery.ajax({ + type: "GET", + url: "<?php echo clean_url($_SERVER['PHP_SELF']); ?>", + cache : false, + async : false, + data: "ajax=photo_images&u=<?php echo urlencode($url); ?>", + dataType : "script" + }).responseText + ); + + for (i = 0; i < my_src.length; i++) { + img = new Image(); + img.src = my_src[i]; + img_attr = 'id="img' + i + '"'; + skip = false; + if (img.width && img.height) { + if (img.width * img.height < 2500) + skip = true; + aspect = img.width / img.height; + scale = (aspect > 1) ? (75 / img.width) : (75 / img.height); - function pick(img, desc) { - if (img) { - length = jQuery('.photolist input').length; - if(length == 0) length = 1; - jQuery('.photolist').append('<input name="photo_src[' + length + ']" value="' + img +'" type="hidden"/>'); - jQuery('.photolist').append('<input name="photo_description[' + length + ']" value="' + desc +'" type="hidden"/>'); - append_editor('<img src="' + img +'" alt="' + desc + '" />'); } - return false; - } - - var my_src, img, img_tag, aspect, w, h, skip, i, strtoappend = ""; + w = img.width; + h = img.height; - var my_src = eval( - jQuery.ajax({ - type: "GET", - url: "<?php echo clean_url($_SERVER['PHP_SELF']); ?>", - cache : false, - async : false, - data: "ajax=photo_images&u=<?php echo urlencode($url); ?>", - dataType : "script" - }).responseText); - - for (i = 0; i < my_src.length; i++) { - img = new Image(); - img.src = my_src[i]; - img_attr = 'id="img' + i; - skip = false; - - if (img.width && img.height) { - if (img.width * img.height < 2500) skip = true; - aspect = img.width / img.height; - if (aspect > 1) { // Image is wide - scale = 75 / img.width; - } else { // Image is tall or square - scale = 75 / img.height; - } - if (scale < 1) { - w = parseInt(img.width * scale); - h = parseInt(img.height * scale); - } else { - w = img.width; - h = img.height; - } - img_attr += ' style="width: ' + w + 'px; height: ' + h + 'px;"'; - } - - 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>'; - + if (scale < 1) { + w = parseInt(img.width * scale); + h = parseInt(img.height * scale); } - - jQuery('#img_container').html(strtoappend); - - tb_init('a.thickbox, area.thickbox, input.thickbox'); //pass where to apply thickbox - + img_attr += ' style="width: ' + w + 'px; height: ' + h + 'px;"'; + } + 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>'; + } + + function pick(img, desc) { + if (img) { + length = jQuery('.photolist input').length; + if(length == 0) length = 1; + jQuery('.photolist').append('<input name="photo_src[' + length + ']" value="' + img +'" type="hidden"/>'); + jQuery('.photolist').append('<input name="photo_description[' + length + ']" value="' + desc +'" type="hidden"/>'); + append_editor('<img src="' + img +'" alt="' + desc + '" />'); + } + tinyMCE.activeEditor.resizeToContent(); + return false; + } + + function image_selector() { + tb_remove(); + desc = jQuery('#this_photo_description').val(); + src = jQuery('#this_photo').val(); + pick(src, desc); + return false; + } + + jQuery(document).ready(function() { + jQuery('#img_container').html(strtoappend); + jQuery('#photo_add_url').attr('href', '?ajax=thickbox_url&height=200&width=500'); + tb_init('a.thickbox, area.thickbox, input.thickbox'); + }); + <?php die; } if($_REQUEST['ajax'] == 'photo') { ?> - <div class="photolist"></div> - - <small><?php _e('Click images to select:') ?></small> + + <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> <?php die; } - ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>> @@ -284,7 +314,6 @@ if($_REQUEST['ajax'] == 'photo') { ?> if ( isset($strings) ) echo $strings; ?> (function() { var base = tinymce.baseURL, sl = tinymce.ScriptLoader, ln = "<?php echo $language; ?>"; - sl.markDone(base + '/langs/' + ln + '.js'); sl.markDone(base + '/themes/advanced/langs/' + ln + '.js'); sl.markDone(base + '/themes/advanced/langs/' + ln + '_dlg.js'); @@ -314,7 +343,8 @@ if($_REQUEST['ajax'] == 'photo') { ?> accessibility_focus : false, tab_focus : ":next", plugins : "safari,inlinepopups", - entities : "38,amp,60,lt,62,gt" + entities : "38,amp,60,lt,62,gt", + force_p_newlines : true }); <?php } ?> @@ -345,53 +375,41 @@ if($_REQUEST['ajax'] == 'photo') { ?> jQuery('#' + type + '_button').addClass('ui-tabs-selected'); jQuery("#post_type").val(type); } + function set_editor(text) { + if(tinyMCE.activeEditor) tinyMCE.activeEditor.setContent(''); if(tinyMCE.activeEditor) tinyMCE.execCommand('mceInsertContent' ,false, text); } + function append_editor(text) { if(tinyMCE.activeEditor) tinyMCE.execCommand('mceInsertContent' ,false, text); } + function set_title(title) { jQuery("#content_type").text(title); } - function reset_height() { - tinyMCE.height = '170px'; - } + function show(tab_name) { jQuery('body').removeClass('video_split'); jQuery('#extra_fields').hide(); switch(tab_name) { case 'text' : - reset_height(); - jQuery('.editor-container').show(); - jQuery('#content_type').show(); set_menu('text'); - set_title('<?php _e('Text') ?>'); - set_editor("<?php echo $selection; ?>"); + set_title('<?php _e('Post') ?>'); return false; - break; + break; case 'quote' : - reset_height(); - jQuery('.editor-container').show(); - jQuery('#content_type').show(); set_menu('quote'); set_title('<?php _e('Quote') ?>'); - set_editor("<blockquote><p><?php echo $selection; ?> </p><p><cite><a href='<?php echo ''; ?>'><?php echo ''; ?></a></cite> </p></blockquote>"); - + set_editor("<blockquote><p><?php echo $selection; ?> </p><p><cite><a href='<?php echo $url; ?>'><?php echo $title; ?> </a> </cite> </p></blockquote>"); return false; - break; + break; case 'video' : - reset_height(); - jQuery('.editor-container').show(); - jQuery('#content_type').show(); set_menu('video'); set_title('<?php _e('Caption') ?>'); jQuery('#extra_fields').show(); jQuery('body').addClass('video_split'); - - jQuery('#extra_fields').load('<?php echo clean_url($_SERVER['PHP_SELF']); ?>', { ajax: 'video', s: '<?php echo attribute_escape($selection); ?>'}, function() { - <?php if ( preg_match("/youtube\.com\/watch/i", $url) ) { list($domain, $video_id) = split("v=", $url); @@ -407,25 +425,19 @@ if($_REQUEST['ajax'] == 'photo') { ?> $content = $selection; } ?> jQuery('#embed_code').prepend('<?php echo htmlentities($content); ?>'); - set_editor("<?php echo $title; ?>"); + set_editor("<?php echo $title; ?>"); }); - - return false; - break; - + break; case 'photo' : - reset_height(); set_menu('photo'); set_title('Post'); <?php if($selection) { ?> set_editor("<?php echo $selection; ?>"); - <?php } else { ?> - set_editor('') <?php } ?> jQuery('#extra_fields').show(); - jQuery('#extra_fields').prepend('<h2 id="waiting"><img src="images/loading.gif" alt="" /> Loading...</h2>'); + jQuery('#extra_fields').before('<h2 id="waiting"><img src="images/loading.gif" alt="" /> Loading...</h2>'); jQuery('#extra_fields').load('<?php echo clean_url($_SERVER['PHP_SELF']).'/?ajax=photo&u='.attribute_escape($url); ?>'); jQuery.ajax({ type: "GET", @@ -434,15 +446,12 @@ if($_REQUEST['ajax'] == 'photo') { ?> data: "ajax=photo_js&u=<?php echo urlencode($url)?>", dataType : "script", success : function() { - jQuery('#waiting').innerHTML(''); + jQuery('#waiting').remove(); } }); - return false; - break; - + break; } - } jQuery(document).ready(function() { @@ -452,6 +461,7 @@ if($_REQUEST['ajax'] == 'photo') { ?> show(tab_name); }); + // Set default tabs <?php if ( preg_match("/youtube\.com\/watch/i", $url) ) { ?> show('video'); <?php } elseif ( preg_match("/vimeo\.com\/[0-9]+/i", $url) ) { ?> @@ -460,44 +470,60 @@ if($_REQUEST['ajax'] == 'photo') { ?> show('photo'); <?php } ?> }); + </script> </head> <body class="press-this"> <div id="wphead"> -<h1><span id="viewsite"><a href="<?php echo get_option('home'); ?>/"><?php _e('Visit:') ?> <?php bloginfo('name'); ?></a></span></h1> + <h1><span id="viewsite"><a href="<?php echo get_option('home'); ?>/"><?php _e('Visit:') ?> <?php bloginfo('name'); ?></a></span></h1> </div> - <ul id="menu" class="ui-tabs-nav"> - <li id="text_button" class="ui-tabs-selected"><a href="#"><?php _e('Text') ?></a></li> - <li id="photo_button"><a href="#"><?php _e('Photo') ?></a></li> - <li id="quote_button"><a href="#"><?php _e('Quote') ?></a></li> - <li id="video_button"><a href="#"><?php _e('Video') ?></a></li> - </ul> - - <form action="press-this.php?action=post" method="post"> - - <?php wp_nonce_field('press-this') ?> - <input type="hidden" name="post_type" id="post_type" value="text"/> - <div id="posting"> - - <h2 id="title"><label for="post_title"><?php _e('Title') ?></label></h2> - <div class="titlewrap"> - <input name="post_title" id="post_title" class="text" value="<?php echo attribute_escape($title);?>"/> - </div> - - <div id="extra_fields" style="display: none"></div> - <div class="editor_area"> - <h2 id="content_type"><label for="content"><?php _e('Post') ?></label></h2> - <div class="editor-container"> - <textarea name="content" id="content" style="width:100%;" class="mceEditor"> - <?php echo $selection; ?> - </textarea> - </div> - </div> - - </div> - <?php category_div(); ?> - </form> - +<ul id="menu" class="ui-tabs-nav"> + <li id="text_button" class="ui-tabs-selected"><a href="#"><?php _e('Text') ?></a></li> + <li id="photo_button"><a href="#"><?php _e('Photo') ?></a></li> + <li id="quote_button"><a href="#"><?php _e('Quote') ?></a></li> + <li id="video_button"><a href="#"><?php _e('Video') ?></a></li> +</ul> + +<form action="press-this.php?action=post" method="post"> + <?php wp_nonce_field('press-this') ?> + <input type="hidden" name="post_type" id="post_type" value="text"/> + <div id="posting"> + <h2 id="title"><label for="post_title"><?php _e('Title') ?></label></h2> + <div class="titlewrap"> + <input name="post_title" id="post_title" class="text" value="<?php echo attribute_escape($title);?>"/> + </div> + + <div id="extra_fields" style="display: none"></div> + + <div class="editor_area"> + <h2 id="content_type"><label for="content"><?php _e('Post') ?></label></h2> + <div class="editor-container"> + <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> + </div> + </div> + </div> + + <div id="categories"> + <div class="submitbox" id="submitpost"> + <div id="previewview"></div> + <div class="inside"> + <h2><?php _e('Categories') ?></h2> + <div id="categories-all"> + <ul id="categorychecklist" class="list:category categorychecklist form-no-clear"> + <?php wp_category_checklist() ?> + </ul> + </div> + <h2><?php _e('Tags') ?></h2> + <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> + <div id="tagchecklist"></div> + </div> + <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> + <p class="submit"> + <input type="submit" value="<?php _e('Publish') ?>" onclick="document.getElementById('photo_saving').style.display = '';"/> + <img src="images/loading-publish.gif" alt="" id="photo_saving" style="display:none;"/> + </p> + </div> +</form> </body> </html> |