mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 17:18:32 +01:00
Don't pass image list via GET. Fetch images remotely. Load photo tab via AJAX. see #6813
git-svn-id: http://svn.automattic.com/wordpress/trunk@7927 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
7b1e56dc06
commit
967ee06a32
@ -21,7 +21,7 @@ function quick_post() {
|
||||
case 'quote':
|
||||
$content = '<blockquote>' . $_REQUEST['content'];
|
||||
if ($_REQUEST['content2']) {
|
||||
$content = $content . '</blockquote>';
|
||||
$content .= '</blockquote>';
|
||||
$content = $content . '<p>' . $_REQUEST['content2'];
|
||||
}
|
||||
break;
|
||||
@ -43,7 +43,7 @@ function quick_post() {
|
||||
list($garbage,$video_id) = split("v=", $_REQUEST['content']);
|
||||
$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>';
|
||||
if ($_REQUEST['content2'])
|
||||
$content = $content . '</br><p>' . $_REQUEST['content2'] . '</p>';
|
||||
$content .= '</br><p>' . $_REQUEST['content2'] . '</p>';
|
||||
break;
|
||||
}
|
||||
|
||||
@ -67,6 +67,175 @@ function tag_input() {
|
||||
return $s;
|
||||
}
|
||||
|
||||
function get_images_from_uri($uri) {
|
||||
$content = wp_remote_fopen($uri);
|
||||
if ( false === $content )
|
||||
return '';
|
||||
|
||||
$pattern = '/src=[\'"]?([^\'" >]+)[\'" >]/';
|
||||
preg_match_all($pattern, $content, $matches);
|
||||
if ( empty($matches[1]) )
|
||||
return '';
|
||||
|
||||
$from_host = parse_url($uri);
|
||||
$from_host = $from_host['host'];
|
||||
$from_host = explode('.', $from_host);
|
||||
$count = count($from_host);
|
||||
$from_host = $from_host[$count - 2] . '.' . $from_host[$count - 1];
|
||||
|
||||
$sources = array();
|
||||
foreach ($matches[1] as $src) {
|
||||
if ( false !== strpos($src, '&') )
|
||||
continue;
|
||||
|
||||
$img_host = parse_url($src);
|
||||
$img_host = $img_host['host'];
|
||||
if ( false === strpos($img_host, $from_host) )
|
||||
continue;
|
||||
|
||||
$sources[] = $src;
|
||||
}
|
||||
return "'" . implode("','", $sources) . "'";
|
||||
}
|
||||
|
||||
// Clean up the data being passed in
|
||||
$title = stripslashes($_GET['t']);
|
||||
|
||||
if ( !empty($_GET['load']) && 'photo' == $_GET['load'] ) {
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
<?php if ( user_can_richedit() ) {
|
||||
$language = ( '' == get_locale() ) ? 'en' : strtolower( substr(get_locale(), 0, 2) );
|
||||
?>
|
||||
|
||||
tinyMCE.init({
|
||||
mode: "textareas",
|
||||
editor_selector: "mceEditor",
|
||||
language : "<?php echo $language; ?>",
|
||||
width: "100%",
|
||||
theme : "advanced",
|
||||
theme_advanced_buttons1 : "bold,italic,underline,blockquote,separator,strikethrough,bullist,numlist,undo,redo,link,unlink",
|
||||
theme_advanced_buttons2 : "",
|
||||
theme_advanced_buttons3 : "",
|
||||
theme_advanced_toolbar_location : "top",
|
||||
theme_advanced_toolbar_align : "left",
|
||||
theme_advanced_statusbar_location : "bottom",
|
||||
theme_advanced_resizing : true,
|
||||
theme_advanced_resize_horizontal : false,
|
||||
skin : "wp_theme",
|
||||
dialog_type : "modal",
|
||||
relative_urls : false,
|
||||
remove_script_host : false,
|
||||
convert_urls : false,
|
||||
apply_source_formatting : false,
|
||||
remove_linebreaks : true,
|
||||
accessibility_focus : false,
|
||||
tab_focus : ":next",
|
||||
plugins : "safari,inlinepopups"
|
||||
});
|
||||
<?php } ?>
|
||||
var last = null;
|
||||
function pick(img) {
|
||||
if (last) last.style.backgroundColor = '#f4f4f4';
|
||||
if (img) {
|
||||
document.getElementById('photo_src').value = img.src;
|
||||
img.style.backgroundColor = '#44f';
|
||||
}
|
||||
last = img;
|
||||
return false;
|
||||
}
|
||||
|
||||
jQuery(document).ready(function() {
|
||||
var img, img_tag, aspect, w, h, skip, i, strtoappend = "";
|
||||
var my_src = [<?php echo get_images_from_uri(clean_url($_GET['u'])); ?>];
|
||||
|
||||
for (i = 0; i < my_src.length; i++) {
|
||||
img = new Image();
|
||||
img.src = my_src[i];
|
||||
img_attr = 'id="img' + i + '" onclick="pick(this);"';
|
||||
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="' + img.src + '" title="" class="thickbox"><img src="' + img.src + '" ' + img_attr + '/></a>'
|
||||
}
|
||||
}
|
||||
jQuery('#img_container').html(strtoappend);
|
||||
|
||||
tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
|
||||
});
|
||||
</script>
|
||||
|
||||
<form action="quick-post.php?action=post" method="post" id="photo_form">
|
||||
<?php wp_nonce_field('quick-post') ?>
|
||||
<input type="hidden" name="source" value="bookmarklet"/>
|
||||
<input type="hidden" name="post_type" value="photo"/>
|
||||
<div id="posting">
|
||||
<h2><?php _e('Post Title') ?></h2>
|
||||
<input name="post_title" id="post_title" class="text" value="<?php echo attribute_escape($title);?>"/>
|
||||
|
||||
<h2><?php _e('Caption') ?></h2>
|
||||
<div class="editor-container">
|
||||
<textarea name="content" id="photo_post_two" style="height:130px;width:100%;" class="mceEditor"><?php echo stripslashes($_GET['s']);?>
|
||||
<br><a href="<?php echo clean_url($_GET['u']);?>"><?php echo $title;?></a></textarea>
|
||||
</div>
|
||||
|
||||
<h2><?php _e('Photo URL') ?></h2>
|
||||
<input name="photo_src" id="photo_src" class="text" onkeydown="pick(0);"/>
|
||||
|
||||
<style type="text/css">
|
||||
#img_container img {
|
||||
width: 75px;
|
||||
height: 75px;
|
||||
padding: 2px;
|
||||
background-color: #f4f4f4;
|
||||
margin-right: 7px;
|
||||
margin-bottom: 7px;
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
<div id="img_container" style="border:solid 1px #ccc; background-color:#f4f4f4; padding:5px; width:370px; margin-top:10px; overflow:auto; height:100px;">
|
||||
</div>
|
||||
|
||||
<h2><?php _e('Link Photo to following URL') ?></h2><?php _e('(leave blank to leave the photo unlinked)') ?>
|
||||
<input name="photo_link" id="photo_link" class="text" value="<?php echo attribute_escape($_GET['u']);?>"/>
|
||||
|
||||
<?php tag_input(); ?>
|
||||
|
||||
<div>
|
||||
<input type="submit" value="<?php _e('Create Photo') ?>" style="margin-top:15px;" onclick="document.getElementById('photo_saving').style.display = '';"/>
|
||||
|
||||
<a href="#" onclick="if (confirm('<?php _e('Are you sure?') ?>')) { self.close(); } else { return false; }" style="color:#007BFF;"><?php _e('Cancel') ?></a>
|
||||
<img src="/images/bookmarklet_loader.gif" alt="" id="photo_saving" style="width:16px; height:16px; vertical-align:-4px; display:none;"/>
|
||||
</div>
|
||||
</div>
|
||||
<div id="categories">
|
||||
<h2><?php _e('Categories') ?></h2>
|
||||
<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
|
||||
<?php wp_category_checklist($post_ID) ?>
|
||||
</ul>
|
||||
</div>
|
||||
</form>
|
||||
<?php
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
<!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(); ?>>
|
||||
@ -127,14 +296,14 @@ function tag_input() {
|
||||
|
||||
jQuery(document).ready(function() {
|
||||
<?php if ( preg_match("/youtube\.com\/watch/i", $_GET['u']) ) { ?>
|
||||
jQuery('#container > ul').tabs({ selected: 4 })({ fx: { height: 'toggle', opacity: 'toggle', fxSpeed: 'fast' } });
|
||||
jQuery('#container > ul').tabs({ selected: 3, fx: { height: 'toggle', opacity: 'toggle', fxSpeed: 'fast' } });
|
||||
<?php } elseif ( preg_match("/flickr\.com/i", $_GET['u']) ) { ?>
|
||||
jQuery('#container > ul').tabs({ selected: 2 })({ fx: { height: 'toggle', opacity: 'toggle', fxSpeed: 'fast' } });
|
||||
jQuery('#container > ul').tabs({ selected: 1, fx: { height: 'toggle', opacity: 'toggle', fxSpeed: 'fast' } });
|
||||
<?php } else { ?>
|
||||
jQuery('#container > ul').tabs({ fx: { height: 'toggle', opacity: 'toggle', fxSpeed: 'fast' } });
|
||||
jQuery('#container > ul').tabs({ selected: 1, fx: { height: 'toggle', opacity: 'toggle', fxSpeed: 'fast' } });
|
||||
<?php } ?>
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
@ -150,15 +319,12 @@ if ( 'post' == $_REQUEST['action'] ) {
|
||||
die;
|
||||
}
|
||||
|
||||
// Clean up the data being passed in
|
||||
$title = stripslashes($_GET['t']);
|
||||
|
||||
?>
|
||||
<div id="container">
|
||||
|
||||
<ul>
|
||||
<li><a href="#section-1"><span><?php _e('Text/Link') ?></span></a></li>
|
||||
<li><a href="#section-2"><span><?php _e('Photo') ?></span></a></li>
|
||||
<li><a href="<?php echo add_query_arg('load', 'photo') ?>"><span><?php _e('Photo') ?></span></a></li>
|
||||
<li><a href="#section-3"><span><?php _e('Quote') ?></span></a></li>
|
||||
<li><a href="#section-4"><span><?php _e('Video') ?></span></a></li>
|
||||
</ul>
|
||||
@ -195,109 +361,6 @@ $title = stripslashes($_GET['t']);
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Photo -->
|
||||
<div id="section-2">
|
||||
<form action="quick-post.php?action=post" method="post" id="photo_form">
|
||||
<?php wp_nonce_field('quick-post') ?>
|
||||
<input type="hidden" name="source" value="bookmarklet"/>
|
||||
<input type="hidden" name="post_type" value="photo"/>
|
||||
<div id="posting">
|
||||
<h2><?php _e('Post Title') ?></h2>
|
||||
<input name="post_title" id="post_title" class="text" value="<?php echo attribute_escape($title);?>"/>
|
||||
|
||||
<h2><?php _e('Caption') ?></h2>
|
||||
<div class="editor-container">
|
||||
<textarea name="content" id="photo_post_two" style="height:130px;width:100%;" class="mceEditor"><?php echo "" .stripslashes($_GET['s']);?>
|
||||
<br><a href="<?php echo clean_url($_GET['u']);?>"><?php echo $title;?></a></textarea>
|
||||
</div>
|
||||
|
||||
<h2><?php _e('Photo URL') ?></h2>
|
||||
<input name="photo_src" id="photo_src" class="text" onkeydown="pick(0);"/>
|
||||
|
||||
<style type="text/css">
|
||||
#img_container img {
|
||||
width: 75px;
|
||||
height: 75px;
|
||||
padding: 2px;
|
||||
background-color: #f4f4f4;
|
||||
margin-right: 7px;
|
||||
margin-bottom: 7px;
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div id="img_container" style="border:solid 1px #ccc; background-color:#f4f4f4; padding:5px; width:370px; margin-top:10px; overflow:auto; height:100px;">
|
||||
<script type="text/javascript">
|
||||
var img, img_tag, aspect, w, h, skip, i, strtoappend = "";
|
||||
var my_src = ['<?php echo str_replace(",", "','", rtrim($_GET['imagez'], ","));?>'];
|
||||
var last = null;
|
||||
|
||||
function pick(img) {
|
||||
if (last) last.style.backgroundColor = '#f4f4f4';
|
||||
if (img) {
|
||||
document.getElementById('photo_src').value = img.src;
|
||||
img.style.backgroundColor = '#44f';
|
||||
}
|
||||
last = img;
|
||||
return false;
|
||||
}
|
||||
for (i = 0; i < my_src.length; i++) {
|
||||
img = new Image();
|
||||
img.src = my_src[i];
|
||||
img_attr = 'id="img' + i + '" onclick="pick(this);"';
|
||||
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="' + img.src + '" title="" class="thickbox"><img src="' + img.src + '" ' + img_attr + '/></a>'
|
||||
}
|
||||
}
|
||||
if (jQuery.browser.safari) {
|
||||
document.getElementById('img_container').innerHTML = strtoappend;
|
||||
} else {
|
||||
document.write(strtoappend);
|
||||
}
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<h2><?php _e('Link Photo to following URL') ?></h2><?php _e('(leave blank to leave the photo unlinked)') ?>
|
||||
<input name="photo_link" id="photo_link" class="text" value="<?php echo attribute_escape($_GET['u']);?>"/>
|
||||
|
||||
<?php tag_input(); ?>
|
||||
|
||||
<div>
|
||||
<input type="submit" value="<?php _e('Create Photo') ?>" style="margin-top:15px;" onclick="document.getElementById('photo_saving').style.display = '';"/>
|
||||
|
||||
<a href="#" onclick="if (confirm('<?php _e('Are you sure?') ?>')) { self.close(); } else { return false; }" style="color:#007BFF;"><?php _e('Cancel') ?></a>
|
||||
<img src="/images/bookmarklet_loader.gif" alt="" id="photo_saving" style="width:16px; height:16px; vertical-align:-4px; display:none;"/>
|
||||
</div>
|
||||
</div>
|
||||
<div id="categories">
|
||||
<h2><?php _e('Categories') ?></h2>
|
||||
<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
|
||||
<?php wp_category_checklist($post_ID) ?>
|
||||
</ul>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Quote -->
|
||||
<div id="section-3">
|
||||
<form action="quick-post.php?action=post" method="post" id="quote_form">
|
||||
|
@ -744,13 +744,6 @@ function posts_nav_link($sep=' — ', $prelabel='« Previous Page', $nx
|
||||
|
||||
function get_shortcut_link() {
|
||||
$link = "javascript:
|
||||
var imgstr='';
|
||||
var reg=new RegExp('&');
|
||||
for(i=0;i<document.images.length;i++){
|
||||
if(! reg.test(document.images[i].src)){
|
||||
imgstr = imgstr + document.images[i].src + ',';
|
||||
}
|
||||
}
|
||||
var d=document;
|
||||
var w=window;
|
||||
var e=w.getSelection;
|
||||
@ -760,11 +753,11 @@ function get_shortcut_link() {
|
||||
var f='" . get_settings('siteurl') . '/wp-admin/quick-post.php' . "';
|
||||
var l=d.location;
|
||||
var e=encodeURIComponent;
|
||||
var p='?imagez='+imgstr;
|
||||
var u= '&u=' + e(l.href);
|
||||
var u= '?u=' + e(l.href);
|
||||
var t= '&t=' + e(d.title);
|
||||
var s= '&s=' + e(s);
|
||||
var g= f+p+u+t+s;
|
||||
var v='&v=1';
|
||||
var g= f+u+t+s+v;
|
||||
function a(){
|
||||
if(!w.open(g,'t','toolbar=0,resizable=0,scrollbars=1,status=1,width=700,height=500')){
|
||||
l.href=g;
|
||||
|
Loading…
Reference in New Issue
Block a user