Press This improvements from noel. fixes #7117

git-svn-id: http://svn.automattic.com/wordpress/trunk@8067 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-06-10 16:13:06 +00:00
parent 2cc03f7d06
commit 7939970055
3 changed files with 183 additions and 97 deletions

View File

@ -356,6 +356,7 @@ padding: 0;
height: 300px; height: 300px;
float: left; float: left;
} }
#embed_code { #embed_code {
border: 0; border: 0;
width: 99%; width: 99%;
@ -394,3 +395,52 @@ padding: 0;
.ac_match { .ac_match {
text-decoration: underline; 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;
}

View File

@ -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) ) { if (!empty($file) ) {
// Upload File button was clicked // Upload File button was clicked
$file_array['name'] = basename($file); $file_array['name'] = basename($file);
$file_array['tmp_name'] = download_url($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']; $id = $sideload['id'];
$src = $sideload['src']; $src = $sideload['src'];
@ -141,18 +142,15 @@ function media_sideload_image($file, $post_id) {
if ( !empty($src) && !strpos($src, '://') ) if ( !empty($src) && !strpos($src, '://') )
$src = "http://$src"; $src = "http://$src";
/*$alt = attribute_escape($_POST['insertonly']['alt']); $alt = @$desc;
if ( isset($_POST['insertonly']['align']) ) {
$align = attribute_escape($_POST['insertonly']['align']);
$class = " class='align$align'";
} */
if ( !empty($src) ) if ( !empty($src) )
$html = "<img src='$src' alt='$alt'$class />"; $html = "<img src='$src' alt='$alt' />";
return $html; 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); $overrides = array('test_form'=>false);
$file = wp_handle_sideload($file_array, $overrides); $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']) ) if ( trim($image_meta['caption']) )
$content = $image_meta['caption']; $content = $image_meta['caption'];
} }
$title = @$desc;
// Construct the attachment array // Construct the attachment array
$attachment = array_merge( array( $attachment = array_merge( array(

View File

@ -5,64 +5,64 @@ if ( ! current_user_can('publish_posts') ) wp_die( __( 'Cheatin&#8217; uh?' ));
<?php <?php
function press_it() { function press_it() {
$quick['post_status'] = 'publish'; #define some basic variables
$quick['post_category'] = $_REQUEST['post_category']; $quick['post_status'] = 'publish';
$quick['tags_input'] = $_REQUEST['tags_input']; $quick['post_category'] = $_REQUEST['post_category'];
$quick['post_title'] = $_REQUEST['post_title']; $quick['tags_input'] = $_REQUEST['tags_input'];
$quick['post_content'] = ''; $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); $post_ID = wp_insert_post($quick, true);
$content = ''; $content = '';
switch ( $_REQUEST['post_type'] ) { switch ( $_REQUEST['post_type'] ) {
case 'text': case 'text':
$content .= $_REQUEST['content']; case 'quote':
$content .= $_REQUEST['content'];
case 'quote': break;
$content .= $_REQUEST['content'];
break; case 'photo':
foreach($_REQUEST['photo_src'] as $key => $data) {
case 'photo': #quote for matching
if ($_REQUEST['photo_link']) $quoted = str_replace('/', '\/', preg_quote($data));
$content .= '<a href="' . $_REQUEST['photo_link'] . '">';
# see if files exist in content - we don't want to upload non-used selected files.
$content .= media_sideload_image($_REQUEST['photo_src'], $post_ID); preg_match('/'.$quoted.'/', $_REQUEST['content'], $matches[0]);
if($matches[0])
if ($_REQUEST['photo_link']) media_sideload_image($data, $post_ID, $_REQUEST['photo_description'][$key]);
$content .= '</a>'; }
$content = $_REQUEST['content'];
if ($_REQUEST['content']) break;
$content .= $content . "\n\n".$_REQUEST['content'];
case "video":
break; if($_REQUEST['embed_code'])
case "video": $content .= $_REQUEST['embed_code']."\n\n";
if($_REQUEST['embed_code']) $content .= $_REQUEST['content'];
$content .= $_REQUEST['embed_code']."\n\n"; break;
$content .= $_REQUEST['content'];
break;
} }
# set the post_content
$quick['post_content'] = $content; $quick['post_content'] = $content;
#error handling for $post
if ( is_wp_error($post_ID) ) { if ( is_wp_error($post_ID) ) {
wp_die($id); wp_die($id);
wp_delete_post($post_ID); wp_delete_post($post_ID);
} else {
#error handling for media_sideload
} else {
$quick['ID'] = $post_ID; $quick['ID'] = $post_ID;
wp_update_post($quick); wp_update_post($quick);
} }
return $post_ID; return $post_ID;
} }
function tag_div() { ?> function tag_div() { ?>
<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> <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 id="tagchecklist"></div>
<?php <?php }
}
function category_div() { function category_div() { ?>
?>
<div id="categories"> <div id="categories">
<div class="submitbox" id="submitpost"> <div class="submitbox" id="submitpost">
<div id="previewview"> <h2><?php _e('Categories') ?></h2></div> <div id="previewview"> <h2><?php _e('Categories') ?></h2></div>
@ -78,13 +78,32 @@ function press_it() {
<img src="images/loading.gif" alt="" id="photo_saving" style="width:16px; height:16px; vertical-align:-4px; display:none;"/> <img src="images/loading.gif" alt="" id="photo_saving" style="width:16px; height:16px; vertical-align:-4px; display:none;"/>
</p> </p>
</div> </div>
<?php <?php }
}
// For posts submitted # For submitted posts.
if ( 'post' == $_REQUEST['action'] ) { if ( 'post' == $_REQUEST['action'] ) {
check_admin_referer('press-this'); $post_ID = press_it(); ?> check_admin_referer('press-this'); $post_ID = press_it(); ?>
<script>if(confirm("<?php _e('Your post is saved. Do you want to view the post?') ?>")){window.opener.location.replace("<?php echo get_permalink($post_ID);?>");}window.close();</script>
<!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(); ?>>
<head>
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
<title><?php _e('Press This') ?></title>
<?php
add_thickbox();
wp_enqueue_style('press-this');
wp_enqueue_style( 'colors' );
wp_enqueue_script('post');
do_action('admin_print_styles');
do_action('admin_print_scripts');
do_action('admin_head');
?>
</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&amp;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>
</body>
</html>
<?php die; <?php die;
} }
@ -92,6 +111,38 @@ if ( 'post' == $_REQUEST['action'] ) {
$title = wp_specialchars(stripslashes($_GET['t'])); $title = wp_specialchars(stripslashes($_GET['t']));
$selection = trim(wp_specialchars(str_replace("\n", ' ',stripslashes($_GET['s'])))); $selection = trim(wp_specialchars(str_replace("\n", ' ',stripslashes($_GET['s']))));
$url = $_GET['u']; $url = $_GET['u'];
$image = $_GET['i'];
if($_REQUEST['ajax'] == 'thickbox') { ?>
<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">
<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><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>
<p id="options"><a href="#" class="select" rel="<?php echo $image; ?>">Insert Image</a> | <a href="#" class="cancel">Cancel</a></p>
<?php die;
}
if($_REQUEST['ajax'] == 'video') { ?> if($_REQUEST['ajax'] == 'video') { ?>
<h2 id="embededcode"><label for="embed_code"><?php _e('Embed Code') ?></label></h2> <h2 id="embededcode"><label for="embed_code"><?php _e('Embed Code') ?></label></h2>
@ -137,45 +188,33 @@ die;
if($_REQUEST['ajax'] == 'photo_js') { ?> if($_REQUEST['ajax'] == 'photo_js') { ?>
var last = null var last = null
function pick(img) {
function pick(img, desc) {
if (last) last.style.backgroundColor = '#f4f4f4'; if (img) {
if (img) { length = jQuery('.photolist input').length;
jQuery('#photo_src').val(img.src); if(length == 0) length = 1;
img.style.backgroundColor = '#44f'; jQuery('.photolist').append('<input name="photo_src[' + length + ']" value="' + img +'" type="hidden"/>');
} jQuery('.photolist').append('<input name="photo_description[' + length + ']" value="' + desc +'" type="hidden"/>');
last = img; append_editor('<img src="' + img +'" alt="' + desc + '" />'); }
/*noel's code to select more than one image....
jQuery('.photolist').append('<h2><?php _e("Photo URL") ?></h2>' +
'<div class="titlewrap">' +
'<a href="#" class="remove">remove <input name="photo_src" id="photo_src[]" value ="'+ img.src +'" class="text" onkeydown="pick(0);"/></a>' +
'</div>');*/
return false; return false;
} }
jQuery('.remove').click(function() {
jQuery(this).remove;
});
var my_src, img, img_tag, aspect, w, h, skip, i, strtoappend = ""; var my_src, img, img_tag, aspect, w, h, skip, i, strtoappend = "";
var my_src =eval( var my_src = eval(
jQuery.ajax({ jQuery.ajax({
type: "GET", type: "GET",
url: "<?php echo clean_url($_SERVER['PHP_SELF']); ?>", url: "<?php echo clean_url($_SERVER['PHP_SELF']); ?>",
cache : false, cache : false,
async : false, async : false,
data: "ajax=photo_images&u=<?php echo urlencode($url); ?>", data: "ajax=photo_images&u=<?php echo urlencode($url); ?>",
dataType : "script" dataType : "script"
}).responseText); }).responseText);
for (i = 0; i < my_src.length; i++) { for (i = 0; i < my_src.length; i++) {
img = new Image(); img = new Image();
img.src = my_src[i]; img.src = my_src[i];
img_attr = 'id="img' + i + '" onclick="pick(this);"'; img_attr = 'id="img' + i;
skip = false; skip = false;
if (img.width && img.height) { if (img.width && img.height) {
@ -196,7 +235,7 @@ if($_REQUEST['ajax'] == 'photo_js') { ?>
img_attr += ' style="width: ' + w + 'px; height: ' + h + 'px;"'; img_attr += ' style="width: ' + w + 'px; height: ' + h + 'px;"';
} }
if (!skip) strtoappend += '<a href="' + img.src + '" title="" class="thickbox"><img src="' + img.src + '" ' + img_attr + '/></a>'; if (!skip) strtoappend += '<a href="?ajax=thickbox&amp;i=' + img.src + '&amp;u=<?php echo $url; ?>&amp;height=400&amp;width=500" title="" class="thickbox"><img src="' + img.src + '" ' + img_attr + '/></a>';
} }
@ -207,18 +246,9 @@ if($_REQUEST['ajax'] == 'photo_js') { ?>
<?php die; } <?php die; }
if($_REQUEST['ajax'] == 'photo') { ?> if($_REQUEST['ajax'] == 'photo') { ?>
<h2><?php _e('Photo URL') ?></h2>
<div class="titlewrap">
<input name="photo_src" id="photo_src" class="text" onkeydown="pick(0);"/>
</div>
<div class="photolist"></div> <div class="photolist"></div>
<h2><?php _e('Link Photo to following URL') ?></h2><?php _e('(leave blank to leave the photo unlinked)') ?>
<div class="titlewrap">
<input name="photo_link" id="photo_link" class="text" value="<?php echo attribute_escape($url);?>"/>
</div>
<small><?php _e('Click images to select:') ?></small> <small><?php _e('Click images to select:') ?></small>
<div class="titlewrap"> <div class="titlewrap">
<div id="img_container">Loading Images...</div> <div id="img_container">Loading Images...</div>
@ -264,7 +294,6 @@ if($_REQUEST['ajax'] == 'photo') { ?>
width: "100%", width: "100%",
theme : "advanced", theme : "advanced",
theme_advanced_buttons1 : "bold,italic,underline,blockquote,separator,strikethrough,bullist,numlist,undo,redo,link,unlink", 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_buttons2 : "",
theme_advanced_buttons3 : "", theme_advanced_buttons3 : "",
theme_advanced_toolbar_location : "top", theme_advanced_toolbar_location : "top",
@ -278,7 +307,7 @@ if($_REQUEST['ajax'] == 'photo') { ?>
remove_script_host : false, remove_script_host : false,
convert_urls : false, convert_urls : false,
apply_source_formatting : false, apply_source_formatting : false,
remove_linebreaks : true, remove_linebreaks : false,
accessibility_focus : false, accessibility_focus : false,
tab_focus : ":next", tab_focus : ":next",
plugins : "safari,inlinepopups", plugins : "safari,inlinepopups",
@ -317,6 +346,9 @@ if($_REQUEST['ajax'] == 'photo') { ?>
if(tinyMCE.activeEditor) tinyMCE.activeEditor.setContent(''); if(tinyMCE.activeEditor) tinyMCE.activeEditor.setContent('');
if(tinyMCE.activeEditor) tinyMCE.execCommand('mceInsertContent' ,false, text); 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 set_title(title) { jQuery("#content_type").text(title); }
function reset_height() { function reset_height() {
tinyMCE.height = '170px'; tinyMCE.height = '170px';
@ -331,7 +363,7 @@ if($_REQUEST['ajax'] == 'photo') { ?>
jQuery('#content_type').show(); jQuery('#content_type').show();
set_menu('text'); set_menu('text');
set_title('<?php _e('Text') ?>'); set_title('<?php _e('Text') ?>');
set_editor('<?php echo $selection; ?>'); set_editor("<?php echo $selection; ?>");
return false; return false;
break; break;
case 'quote' : case 'quote' :
@ -340,7 +372,7 @@ if($_REQUEST['ajax'] == 'photo') { ?>
jQuery('#content_type').show(); jQuery('#content_type').show();
set_menu('quote'); set_menu('quote');
set_title('<?php _e('Quote') ?>'); set_title('<?php _e('Quote') ?>');
set_editor('<blockquote><p><?php echo $selection; ?> </p><p><cite><a href="<?php echo $url; ?>"><?php echo $title; ?></a></cite> </p></blockquote>'); set_editor("<blockquote><p><?php echo $selection; ?> </p><p><cite><a href='<?php echo ''; ?>'><?php echo ''; ?></a></cite> </p></blockquote>");
return false; return false;
break; break;
@ -372,7 +404,7 @@ if($_REQUEST['ajax'] == 'photo') { ?>
$content = $selection; $content = $selection;
} ?> } ?>
jQuery('#embed_code').prepend('<?php echo htmlentities($content); ?>'); jQuery('#embed_code').prepend('<?php echo htmlentities($content); ?>');
set_editor('<?php echo $title; ?>'); set_editor("<?php echo $title; ?>");
}); });
@ -383,9 +415,12 @@ if($_REQUEST['ajax'] == 'photo') { ?>
case 'photo' : case 'photo' :
reset_height(); reset_height();
set_menu('photo'); set_menu('photo');
set_title('Caption'); set_title('Post');
set_editor('<a href="<?php echo $url; ?>"><?php echo $title; ?></a>'); <?php if($selection) { ?>
set_editor("<?php echo $selection; ?>");
<?php } else { ?>
set_editor('')
<?php } ?>
jQuery('#extra_fields').show(); jQuery('#extra_fields').show();
jQuery('#extra_fields').load('<?php echo clean_url($_SERVER['PHP_SELF']).'/?ajax=photo&u='.attribute_escape($url); ?>'); jQuery('#extra_fields').load('<?php echo clean_url($_SERVER['PHP_SELF']).'/?ajax=photo&u='.attribute_escape($url); ?>');
jQuery('#extra_fields').prepend('<h2><img src="images/loading.gif" alt="" /> Loading...</h2>'); jQuery('#extra_fields').prepend('<h2><img src="images/loading.gif" alt="" /> Loading...</h2>');
@ -398,6 +433,7 @@ if($_REQUEST['ajax'] == 'photo') { ?>
success : function() { success : function() {
} }
}); });
return false; return false;
break; break;
@ -444,7 +480,7 @@ if($_REQUEST['ajax'] == 'photo') { ?>
<div class="titlewrap"> <div class="titlewrap">
<input name="post_title" id="post_title" class="text" value="<?php echo attribute_escape($title);?>"/> <input name="post_title" id="post_title" class="text" value="<?php echo attribute_escape($title);?>"/>
</div> </div>
<div id="extra_fields" style="display: none"></div> <div id="extra_fields" style="display: none"></div>
<div class="editor_area"> <div class="editor_area">
<h2 id="content_type"><label for="content"><?php _e('Post') ?></label></h2> <h2 id="content_type"><label for="content"><?php _e('Post') ?></label></h2>