Press This updates from noel. see #6813

git-svn-id: http://svn.automattic.com/wordpress/trunk@8169 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-06-23 16:00:12 +00:00
parent f42b96cd5e
commit 9198dc7dbc
3 changed files with 201 additions and 192 deletions

View File

@ -294,26 +294,38 @@ div#categories h2 {
height: 100px; height: 100px;
} }
#img_container a {
display: block;
width: 79px;
height: 79px;
float: left;
}
#img_container img { #img_container img {
width: 75px; width: 75px;
height: 75px; height: 75px;
border: 0px;
padding: 2px; padding: 2px;
background-color: #f4f4f4; background-color: #f4f4f4;
margin-right: 7px;
margin-bottom: 7px;
cursor: pointer; cursor: pointer;
} }
#img_container a, #img_container a:link, #img_container a:visited {
border: 2px solid #ccc;
margin: 0 4px 4px 0;
}
#img_container a:hover, #img_container a:active {
border: 2px solid #000;
}
.submit { .submit {
-moz-border-radius-bottomleft: 3px; -moz-border-radius-bottomleft: 3px;
-khtml-border-bottom-left-radius: 3px; -khtml-border-bottom-left-radius: 3px;
-webkit-border-bottom-left-radius: 3px; -webkit-border-bottom-left-radius: 3px;
border-bottom-left-radius: 3px; border-bottom-left-radius: 3px;
-moz-border-radius-bottomright: 3px; -moz-border-radius-bottomright: 3px;
-khtml-border-bottom-right-radius: 3px; -khtml-border-bottom-right-radius: 3px;
-webkit-border-bottom-right-radius: 3px; -webkit-border-bottom-right-radius: 3px;
border-bottom-right-radius: 3px; border-bottom-right-radius: 3px;
margin: 0; margin: 0;
padding: 0; padding: 0;
} }
.submitbox { .submitbox {
width: 100%; width: 100%;
@ -466,9 +478,9 @@ margin-bottom: 8px;
} }
#post_status { #post_status {
margin-left: 10px; margin-left: 10px;
margin-bottom: 1em; margin-bottom: 1em;
display: block; display: block;
} }
#footer { #footer {

View File

@ -115,41 +115,6 @@ function media_handle_upload($file_id, $post_id, $post_data = array()) {
} }
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, $desc);
$id = $sideload['id'];
$src = $sideload['src'];
unset($file_array['tmp_name']);
unset($file_array);
if ( is_wp_error($id) ) {
$errors['upload_error'] = $id;
$id = false;
}
}
if ( !empty($src) && !strpos($src, '://') )
$src = "http://$src";
$alt = @$desc;
if ( !empty($src) )
$html = "<img src='$src' alt='$alt' />";
return $html;
}
function media_handle_sideload($file_array, $post_id, $desc = null, $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);
@ -186,9 +151,10 @@ function media_handle_sideload($file_array, $post_id, $desc = null, $post_data =
$id = wp_insert_attachment($attachment, $file, $post_parent); $id = wp_insert_attachment($attachment, $file, $post_parent);
if ( !is_wp_error($id) ) { if ( !is_wp_error($id) ) {
wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
return $src;
} }
return array('id' => $id, 'src' => $url); return $id;
} }
@ -348,6 +314,33 @@ function media_upload_image() {
return wp_iframe( 'media_upload_type_form', 'image', $errors, $id ); return wp_iframe( 'media_upload_type_form', 'image', $errors, $id );
} }
function media_sideload_image($file, $post_id, $desc = null) {
if (!empty($file) ) {
$file_array['name'] = basename($file);
$file_array['tmp_name'] = download_url($file);
$desc = @$desc;
$id = media_handle_sideload($file_array, $post_id, $desc);
unset($file_array);
if ( is_wp_error($id) ) {
$errors['upload_error'] = $id;
return $id;
} else {
$src = $id;
}
}
if (!empty($src) && !strpos($src, '://') ) {
$src = "http://$src";
$alt = @$desc;
}
if ( !empty($src) ) {
$html = "<img src='$src' alt='$alt' />";
return $html;
}
}
function media_upload_audio() { function media_upload_audio() {
if ( isset($_POST['html-upload']) && !empty($_FILES) ) { if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
// Upload File button was clicked // Upload File button was clicked

View File

@ -30,7 +30,7 @@ function press_it() {
# 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]); preg_match('/'.$quoted.'/', $_REQUEST['content'], $matches[0]);
if($matches[0]) if($matches[0])
media_sideload_image($data, $post_ID, $_REQUEST['photo_description'][$key]); $upload = media_sideload_image($data, $post_ID, $_REQUEST['photo_description'][$key]);
} }
$content = $_REQUEST['content']; $content = $_REQUEST['content'];
break; break;
@ -45,11 +45,13 @@ function press_it() {
$quick['post_content'] = str_replace('<br />', "\n", preg_replace('/<\/?p>/','',$content)); $quick['post_content'] = str_replace('<br />', "\n", preg_replace('/<\/?p>/','',$content));
#error handling for $post #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);
#error handling for media_sideload #error handling for media_sideload
} elseif ( is_wp_error($upload)) {
wp_die($upload);
wp_delete_post($post_ID);
} else { } else {
$quick['ID'] = $post_ID; $quick['ID'] = $post_ID;
wp_update_post($quick); wp_update_post($quick);
@ -78,6 +80,7 @@ if ( 'post' == $_REQUEST['action'] ) {
?> ?>
</head> </head>
<body class="press-this"> <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> <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>
<div id="footer"> <div id="footer">
@ -110,6 +113,15 @@ $url = clean_url($_GET['u']);
$image = $_GET['i']; $image = $_GET['i'];
if($_REQUEST['ajax'] == 'thickbox') { ?> if($_REQUEST['ajax'] == 'thickbox') { ?>
<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('Description') ?></label></h3> <h3 id="title"><label for="post_title"><?php _e('Description') ?></label></h3>
<div class="titlewrap"> <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);?>"/> <input id="this_photo_description" name="photo_description" class="text" onkeypress="if(event.keyCode==13) image_selector();" value="<?php echo attribute_escape($title);?>"/>
@ -123,6 +135,15 @@ if($_REQUEST['ajax'] == 'thickbox') { ?>
} }
if($_REQUEST['ajax'] == 'thickbox_url') { ?> 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> <h3 id="title"><label for="post_title"><?php _e('URL') ?></label></h3>
<div class="titlewrap"> <div class="titlewrap">
<input id="this_photo" name="this_photo" class="text" onkeypress="if(event.keyCode==13) image_selector();" /> <input id="this_photo" name="this_photo" class="text" onkeypress="if(event.keyCode==13) image_selector();" />
@ -182,45 +203,11 @@ die;
if($_REQUEST['ajax'] == 'photo_js') { ?> if($_REQUEST['ajax'] == 'photo_js') { ?>
tb_init('a.thickbox, area.thickbox, input.thickbox'); //pass where to apply thickbox
function image_selector() { // gather images and load some default JS
desc = jQuery('#this_photo_description').val();
src = jQuery('#this_photo').val();
pick(src, desc);
tb_remove();
return false;
}
jQuery(document).ready(function() {
jQuery('#this_photo').focus();
jQuery('.cancel').click(function() {
tb_remove();
});
jQuery('.select').click(function() {
image_selector();
});
jQuery('#photo_add_url').attr('href', '?ajax=thickbox_url&height=200&width=500');
});
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;
}
var last = null var last = null
var my_src, img, img_tag, aspect, w, h, skip, i, strtoappend = ""; var 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",
@ -229,31 +216,57 @@ if($_REQUEST['ajax'] == 'photo_js') { ?>
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.src = my_src[i]; img_attr = 'id="img' + i; skip = false; 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) {
if (img.width * img.height < 2500) if (img.width * img.height < 2500)
skip = true; skip = true;
aspect = img.width / img.height; aspect = img.width / img.height;
scale = (aspect > 1) ? (75 / img.width) : (75 / img.height); scale = (aspect > 1) ? (75 / img.width) : (75 / img.height);
w = img.width;
h = img.height;
if (scale < 1) { if (scale < 1) {
w = parseInt(img.width * scale); w = parseInt(img.width * scale);
h = parseInt(img.height * scale); h = parseInt(img.height * scale);
} else {
w = img.width;
h = img.height;
} }
img_attr += ' style="width: ' + w + 'px; height: ' + h + 'px;"'; img_attr += ' style="width: ' + w + 'px; height: ' + h + 'px;"';
} }
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>'; 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>';
} }
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('#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; } <?php die; }
@ -292,7 +305,6 @@ if($_REQUEST['ajax'] == 'photo') { ?>
if ( isset($strings) ) echo $strings; ?> if ( isset($strings) ) echo $strings; ?>
(function() { (function() {
var base = tinymce.baseURL, sl = tinymce.ScriptLoader, ln = "<?php echo $language; ?>"; var base = tinymce.baseURL, sl = tinymce.ScriptLoader, ln = "<?php echo $language; ?>";
sl.markDone(base + '/langs/' + ln + '.js'); sl.markDone(base + '/langs/' + ln + '.js');
sl.markDone(base + '/themes/advanced/langs/' + ln + '.js'); sl.markDone(base + '/themes/advanced/langs/' + ln + '.js');
sl.markDone(base + '/themes/advanced/langs/' + ln + '_dlg.js'); sl.markDone(base + '/themes/advanced/langs/' + ln + '_dlg.js');
@ -354,14 +366,17 @@ if($_REQUEST['ajax'] == 'photo') { ?>
jQuery('#' + type + '_button').addClass('ui-tabs-selected'); jQuery('#' + type + '_button').addClass('ui-tabs-selected');
jQuery("#post_type").val(type); jQuery("#post_type").val(type);
} }
function set_editor(text) { function set_editor(text) {
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) { function append_editor(text) {
if(tinyMCE.activeEditor) tinyMCE.execCommand('mceInsertContent' ,false, 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 show(tab_name) { function show(tab_name) {
@ -371,7 +386,6 @@ if($_REQUEST['ajax'] == 'photo') { ?>
case 'text' : case 'text' :
set_menu('text'); set_menu('text');
set_title('<?php _e('Post') ?>'); set_title('<?php _e('Post') ?>');
return false; return false;
break; break;
case 'quote' : case 'quote' :
@ -381,14 +395,12 @@ if($_REQUEST['ajax'] == 'photo') { ?>
return false; return false;
break; break;
case 'video' : case 'video' :
set_menu('video'); set_menu('video');
set_title('<?php _e('Caption') ?>'); set_title('<?php _e('Caption') ?>');
jQuery('#extra_fields').show(); jQuery('#extra_fields').show();
jQuery('body').addClass('video_split'); 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() { jQuery('#extra_fields').load('<?php echo clean_url($_SERVER['PHP_SELF']); ?>', { ajax: 'video', s: '<?php echo attribute_escape($selection); ?>'}, function() {
<?php <?php
if ( preg_match("/youtube\.com\/watch/i", $url) ) { if ( preg_match("/youtube\.com\/watch/i", $url) ) {
list($domain, $video_id) = split("v=", $url); list($domain, $video_id) = split("v=", $url);
@ -407,10 +419,8 @@ if($_REQUEST['ajax'] == 'photo') { ?>
set_editor("<?php echo $title; ?>"); set_editor("<?php echo $title; ?>");
}); });
return false; return false;
break; break;
case 'photo' : case 'photo' :
set_menu('photo'); set_menu('photo');
set_title('Post'); set_title('Post');
@ -430,12 +440,9 @@ if($_REQUEST['ajax'] == 'photo') { ?>
jQuery('#waiting').remove(); jQuery('#waiting').remove();
} }
}); });
return false; return false;
break; break;
} }
} }
jQuery(document).ready(function() { jQuery(document).ready(function() {
@ -445,6 +452,7 @@ if($_REQUEST['ajax'] == 'photo') { ?>
show(tab_name); show(tab_name);
}); });
// Set default tabs
<?php if ( preg_match("/youtube\.com\/watch/i", $url) ) { ?> <?php if ( preg_match("/youtube\.com\/watch/i", $url) ) { ?>
show('video'); show('video');
<?php } elseif ( preg_match("/vimeo\.com\/[0-9]+/i", $url) ) { ?> <?php } elseif ( preg_match("/vimeo\.com\/[0-9]+/i", $url) ) { ?>
@ -453,40 +461,40 @@ if($_REQUEST['ajax'] == 'photo') { ?>
show('photo'); show('photo');
<?php } ?> <?php } ?>
}); });
</script> </script>
</head> </head>
<body class="press-this"> <body class="press-this">
<div id="wphead"> <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> </div>
<ul id="menu" class="ui-tabs-nav"> <ul id="menu" class="ui-tabs-nav">
<li id="text_button" class="ui-tabs-selected"><a href="#"><?php _e('Text') ?></a></li> <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="photo_button"><a href="#"><?php _e('Photo') ?></a></li>
<li id="quote_button"><a href="#"><?php _e('Quote') ?></a></li> <li id="quote_button"><a href="#"><?php _e('Quote') ?></a></li>
<li id="video_button"><a href="#"><?php _e('Video') ?></a></li> <li id="video_button"><a href="#"><?php _e('Video') ?></a></li>
</ul> </ul>
<form action="press-this.php?action=post" method="post">
<form action="press-this.php?action=post" method="post">
<?php wp_nonce_field('press-this') ?> <?php wp_nonce_field('press-this') ?>
<input type="hidden" name="post_type" id="post_type" value="text"/> <input type="hidden" name="post_type" id="post_type" value="text"/>
<div id="posting"> <div id="posting">
<h2 id="title"><label for="post_title"><?php _e('Title') ?></label></h2> <h2 id="title"><label for="post_title"><?php _e('Title') ?></label></h2>
<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>
<div class="editor-container"> <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> <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>
</div> </div>
<div id="categories"> <div id="categories">
<div class="submitbox" id="submitpost"> <div class="submitbox" id="submitpost">
<div id="previewview"></div> <div id="previewview"></div>
@ -502,15 +510,11 @@ if($_REQUEST['ajax'] == 'photo') { ?>
<div id="tagchecklist"></div> <div id="tagchecklist"></div>
</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> <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"> <p class="submit">
<input type="submit" value="<?php _e('Publish') ?>" onclick="document.getElementById('photo_saving').style.display = '';"/> <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;"/> <img src="images/loading-publish.gif" alt="" id="photo_saving" style="display:none;"/>
</p> </p>
</div> </div>
</form>
</form>
</body> </body>
</html> </html>