From 79399700556f58148e4226522271993fd2de3b7c Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 10 Jun 2008 16:13:06 +0000 Subject: [PATCH] Press This improvements from noel. fixes #7117 git-svn-id: http://svn.automattic.com/wordpress/trunk@8067 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/css/press-this.css | 50 +++++++++ wp-admin/includes/media.php | 18 +-- wp-admin/press-this.php | 212 +++++++++++++++++++++--------------- 3 files changed, 183 insertions(+), 97 deletions(-) diff --git a/wp-admin/css/press-this.css b/wp-admin/css/press-this.css index 07d158e934..8dad13b1c3 100644 --- a/wp-admin/css/press-this.css +++ b/wp-admin/css/press-this.css @@ -356,6 +356,7 @@ padding: 0; height: 300px; float: left; } + #embed_code { border: 0; width: 99%; @@ -394,3 +395,52 @@ padding: 0; .ac_match { text-decoration: underline; } + + +.photolist { +display: none; +} + +#extra_fields small { +display: block; +margin-top: .5em; +padding-bottom: .25em; +} + +#TB_ajaxContent #options { +position: absolute; +top: 20px; +right: 25px; +background: white; +padding: 5px; +} +#TB_ajaxContent h3 { +margin-bottom: .25em; +} + +.updated { + margin: 0; + margin-left: 15px; + margin-right: 15px; + padding: 0; + max-width: 980px; + border-width: 1px; + border-style: solid; + padding: 0 0.6em; + max-width: 950px; + margin-top: 1em; + margin-bottom: 1em; +} + +.updated p, .error p { + margin: 0.6em 0; +} + +.updated a, .error a { + text-decoration: underline; +} + +.updated a { + text-decoration: none; + padding-bottom: 2px; +} \ No newline at end of file diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index 4f7b344542..4d42def8d7 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -116,15 +116,16 @@ function media_handle_upload($file_id, $post_id, $post_data = array()) { } -function media_sideload_image($file, $post_id) { +function media_sideload_image($file, $post_id, $desc = null) { if (!empty($file) ) { // Upload File button was clicked $file_array['name'] = basename($file); $file_array['tmp_name'] = download_url($file); + $desc = @$desc; - $sideload = media_handle_sideload($file_array, $post_id); + $sideload = media_handle_sideload($file_array, $post_id, $desc); $id = $sideload['id']; $src = $sideload['src']; @@ -141,18 +142,15 @@ function media_sideload_image($file, $post_id) { if ( !empty($src) && !strpos($src, '://') ) $src = "http://$src"; - /*$alt = attribute_escape($_POST['insertonly']['alt']); - if ( isset($_POST['insertonly']['align']) ) { - $align = attribute_escape($_POST['insertonly']['align']); - $class = " class='align$align'"; - } */ + $alt = @$desc; + if ( !empty($src) ) - $html = "$alt"; + $html = "$alt"; return $html; } -function media_handle_sideload($file_array, $post_id, $post_data = array()) { +function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) { $overrides = array('test_form'=>false); $file = wp_handle_sideload($file_array, $overrides); @@ -172,6 +170,8 @@ function media_handle_sideload($file_array, $post_id, $post_data = array()) { if ( trim($image_meta['caption']) ) $content = $image_meta['caption']; } + + $title = @$desc; // Construct the attachment array $attachment = array_merge( array( diff --git a/wp-admin/press-this.php b/wp-admin/press-this.php index 74e03f4f58..4be9329d62 100644 --- a/wp-admin/press-this.php +++ b/wp-admin/press-this.php @@ -5,64 +5,64 @@ if ( ! current_user_can('publish_posts') ) wp_die( __( 'Cheatin’ uh?' )); '; - - $content .= media_sideload_image($_REQUEST['photo_src'], $post_ID); - - if ($_REQUEST['photo_link']) - $content .= ''; - - if ($_REQUEST['content']) - $content .= $content . "\n\n".$_REQUEST['content']; - - break; - case "video": - if($_REQUEST['embed_code']) - $content .= $_REQUEST['embed_code']."\n\n"; - $content .= $_REQUEST['content']; - break; + $content = ''; + switch ( $_REQUEST['post_type'] ) { + case 'text': + case 'quote': + $content .= $_REQUEST['content']; + break; + + case 'photo': + foreach($_REQUEST['photo_src'] as $key => $data) { + #quote for matching + $quoted = str_replace('/', '\/', preg_quote($data)); + + # 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]); + } + $content = $_REQUEST['content']; + break; + + case "video": + if($_REQUEST['embed_code']) + $content .= $_REQUEST['embed_code']."\n\n"; + $content .= $_REQUEST['content']; + break; } - + # set the post_content $quick['post_content'] = $content; + #error handling for $post if ( is_wp_error($post_ID) ) { wp_die($id); wp_delete_post($post_ID); - } else { + + #error handling for media_sideload + } else { $quick['ID'] = $post_ID; wp_update_post($quick); } return $post_ID; } - function tag_div() { ?> +function tag_div() { ?>

- +function category_div() { ?>

@@ -78,13 +78,32 @@ function press_it() {

- - + + + > + + + <?php _e('Press This') ?> + + + + + + + +

+
+ +
+ +

+ Click to insert.

+ +

Insert Image | Cancel

+

@@ -137,45 +188,33 @@ die; if($_REQUEST['ajax'] == 'photo_js') { ?> var last = null - function pick(img) { - - if (last) last.style.backgroundColor = '#f4f4f4'; - if (img) { - jQuery('#photo_src').val(img.src); - img.style.backgroundColor = '#44f'; - } - last = img; - - /*noel's code to select more than one image.... - jQuery('.photolist').append('

' + - '
' + - 'remove ' + - '
');*/ - + + function pick(img, desc) { + if (img) { + length = jQuery('.photolist input').length; + if(length == 0) length = 1; + jQuery('.photolist').append(''); + jQuery('.photolist').append(''); + append_editor('' + desc + ''); } return false; } - jQuery('.remove').click(function() { - jQuery(this).remove; - }); - - var my_src, img, img_tag, aspect, w, h, skip, i, strtoappend = ""; - var my_src =eval( + var my_src = eval( jQuery.ajax({ type: "GET", url: "", cache : false, async : false, data: "ajax=photo_images&u=", - dataType : "script" - }).responseText); + dataType : "script" + }).responseText); for (i = 0; i < my_src.length; i++) { img = new Image(); img.src = my_src[i]; - img_attr = 'id="img' + i + '" onclick="pick(this);"'; + img_attr = 'id="img' + i; skip = false; if (img.width && img.height) { @@ -196,7 +235,7 @@ if($_REQUEST['ajax'] == 'photo_js') { ?> img_attr += ' style="width: ' + w + 'px; height: ' + h + 'px;"'; } - if (!skip) strtoappend += ''; + if (!skip) strtoappend += ''; } @@ -207,18 +246,9 @@ if($_REQUEST['ajax'] == 'photo_js') { ?> -

-
- -
-

-
- -
-
Loading Images...
@@ -264,7 +294,6 @@ if($_REQUEST['ajax'] == 'photo') { ?> width: "100%", theme : "advanced", theme_advanced_buttons1 : "bold,italic,underline,blockquote,separator,strikethrough,bullist,numlist,undo,redo,link,unlink", - extended_valid_elements : "object[width|height],param[name|value],embed[src|type|wmode|width|height], a[name|href|target|title|onclick], img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name], hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]", theme_advanced_buttons2 : "", theme_advanced_buttons3 : "", theme_advanced_toolbar_location : "top", @@ -278,7 +307,7 @@ if($_REQUEST['ajax'] == 'photo') { ?> remove_script_host : false, convert_urls : false, apply_source_formatting : false, - remove_linebreaks : true, + remove_linebreaks : false, accessibility_focus : false, tab_focus : ":next", plugins : "safari,inlinepopups", @@ -317,6 +346,9 @@ if($_REQUEST['ajax'] == 'photo') { ?> 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'; @@ -331,7 +363,7 @@ if($_REQUEST['ajax'] == 'photo') { ?> jQuery('#content_type').show(); set_menu('text'); set_title(''); - set_editor(''); + set_editor(""); return false; break; case 'quote' : @@ -340,7 +372,7 @@ if($_REQUEST['ajax'] == 'photo') { ?> jQuery('#content_type').show(); set_menu('quote'); set_title(''); - set_editor('

'); + set_editor("

'>

"); return false; break; @@ -372,7 +404,7 @@ if($_REQUEST['ajax'] == 'photo') { ?> $content = $selection; } ?> jQuery('#embed_code').prepend(''); - set_editor(''); + set_editor(""); }); @@ -383,9 +415,12 @@ if($_REQUEST['ajax'] == 'photo') { ?> case 'photo' : reset_height(); set_menu('photo'); - set_title('Caption'); - set_editor(''); - + set_title('Post'); + + set_editor(""); + + set_editor('') + jQuery('#extra_fields').show(); jQuery('#extra_fields').load(''); jQuery('#extra_fields').prepend('

Loading...

'); @@ -398,6 +433,7 @@ if($_REQUEST['ajax'] == 'photo') { ?> success : function() { } }); + return false; break; @@ -444,7 +480,7 @@ if($_REQUEST['ajax'] == 'photo') { ?>
- +