PressThis:

- Filter and select the content on the PHP side. Then pass only the needed data to JS.
- Add the suggested post title and contend directly to the HTML.
- Standardise the data type names.
- Some cleanup/reduction of the code in the bookmarklet.
See #31373.
Built from https://develop.svn.wordpress.org/trunk@31693


git-svn-id: http://core.svn.wordpress.org/trunk@31674 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2015-03-09 21:49:28 +00:00
parent fe47177a65
commit be24bc3a97
11 changed files with 343 additions and 367 deletions

View File

@ -1388,6 +1388,11 @@ html {
margin: 0 auto;
}
/* Make the text inside the editor textarea white. Prevents a "flash" on loading the page */
#pressthis {
color: #fff;
}
@media (min-width: 901px) {
.editor {
max-width: 760px;

File diff suppressed because one or more lines are too long

View File

@ -1388,6 +1388,11 @@ html {
margin: 0 auto;
}
/* Make the text inside the editor textarea white. Prevents a "flash" on loading the page */
#pressthis {
color: #fff;
}
@media (min-width: 901px) {
.editor {
max-width: 760px;

File diff suppressed because one or more lines are too long

View File

@ -14,6 +14,10 @@
*/
class WP_Press_This {
private $images = array();
private $embeds = array();
/**
* Constructor.
*
@ -31,16 +35,10 @@ class WP_Press_This {
* @return array Site settings.
*/
public function site_settings() {
$default_html = array(
'quote' => '<blockquote>%1$s</blockquote>',
'link' => '<p>' . _x( 'Source:', 'Used in Press This to indicate where the content comes from.' ) .
' <em><a href="%1$s">%2$s</a></em></p>',
);
return array(
// Used to trigger the bookmarklet update notice.
// Needs to be set here and in get_shortcut_link() in wp-includes/link-template.php.
'version' => '6',
'version' => '7',
/**
* Filter whether or not Press This should redirect the user in the parent window upon save.
@ -50,16 +48,6 @@ class WP_Press_This {
* @param bool false Whether to redirect in parent window or not. Default false.
*/
'redirInParent' => apply_filters( 'press_this_redirect_in_parent', false ),
/**
* Filter the default HTML for the Press This editor.
*
* @since 4.2.0
*
* @param array $default_html Associative array with two keys: 'quote' where %1$s is replaced with the site description
* or the selected content, and 'link' there %1$s is link href, %2$s is link text.
*/
'html' => apply_filters( 'press_this_suggested_html', $default_html ),
);
}
@ -435,7 +423,7 @@ class WP_Press_This {
}
private function _process_meta_entry( $meta_name, $meta_value, $data ) {
if ( preg_match( '/:?(title|description|keywords)$/', $meta_name ) ) {
if ( preg_match( '/:?(title|description|keywords|site_name)$/', $meta_name ) ) {
$data['_meta'][ $meta_name ] = $meta_value;
} else {
switch ( $meta_name ) {
@ -444,12 +432,12 @@ class WP_Press_This {
case 'og:video:secure_url':
$meta_value = $this->_limit_embed( $meta_value );
if ( ! isset( $data['_embed'] ) ) {
$data['_embed'] = array();
if ( ! isset( $data['_embeds'] ) ) {
$data['_embeds'] = array();
}
if ( ! empty( $meta_value ) && ! in_array( $meta_value, $data['_embed'] ) ) {
$data['_embed'][] = $meta_value;
if ( ! empty( $meta_value ) && ! in_array( $meta_value, $data['_embeds'] ) ) {
$data['_embeds'][] = $meta_value;
}
break;
@ -461,12 +449,12 @@ class WP_Press_This {
case 'twitter:image':
$meta_value = $this->_limit_img( $meta_value );
if ( ! isset( $data['_img'] ) ) {
$data['_img'] = array();
if ( ! isset( $data['_images'] ) ) {
$data['_images'] = array();
}
if ( ! empty( $meta_value ) && ! in_array( $meta_value, $data['_img'] ) ) {
$data['_img'][] = $meta_value;
if ( ! empty( $meta_value ) && ! in_array( $meta_value, $data['_images'] ) ) {
$data['_images'][] = $meta_value;
}
break;
@ -477,7 +465,7 @@ class WP_Press_This {
}
/**
* Fetches and parses _meta, _img, and _links data from the source.
* Fetches and parses _meta, _images, and _links data from the source.
*
* @since 4.2.0
* @access public
@ -521,8 +509,8 @@ class WP_Press_This {
}
// Fetch and gather <img> data.
if ( empty( $data['_img'] ) ) {
$data['_img'] = array();
if ( empty( $data['_images'] ) ) {
$data['_images'] = array();
}
if ( preg_match_all( '/<img [^>]+>/', $source_content, $matches ) ) {
@ -537,16 +525,16 @@ class WP_Press_This {
if ( preg_match( '/src=(\'|")([^\'"]+)\\1/i', $value, $new_matches ) ) {
$src = $this->_limit_img( $new_matches[2] );
if ( ! empty( $src ) && ! in_array( $src, $data['_img'] ) ) {
$data['_img'][] = $src;
if ( ! empty( $src ) && ! in_array( $src, $data['_images'] ) ) {
$data['_images'][] = $src;
}
}
}
}
// Fetch and gather <iframe> data.
if ( empty( $data['_embed'] ) ) {
$data['_embed'] = array();
if ( empty( $data['_embeds'] ) ) {
$data['_embeds'] = array();
}
if ( preg_match_all( '/<iframe [^>]+>/', $source_content, $matches ) ) {
@ -556,8 +544,8 @@ class WP_Press_This {
if ( preg_match( '/src=(\'|")([^\'"]+)\\1/', $value, $new_matches ) ) {
$src = $this->_limit_embed( $new_matches[2] );
if ( ! empty( $src ) && ! in_array( $src, $data['_embed'] ) ) {
$data['_embed'][] = $src;
if ( ! empty( $src ) && ! in_array( $src, $data['_embeds'] ) ) {
$data['_embeds'][] = $src;
}
}
}
@ -572,13 +560,12 @@ class WP_Press_This {
$items = $this->_limit_array( $matches[0] );
foreach ( $items as $value ) {
if ( preg_match( '/(rel|itemprop)="([^"]+)"[^>]+href="([^"]+)"/', $value, $new_matches ) ) {
if ( 'alternate' === $new_matches[2] || 'thumbnailUrl' === $new_matches[2] || 'url' === $new_matches[2] ) {
$url = $this->_limit_url( $new_matches[3] );
if ( preg_match( '/rel=["\'](canonical|shortlink|icon)["\']/i', $value, $matches_rel ) && preg_match( '/href=[\'"]([^\'" ]+)[\'"]/i', $value, $matches_url ) ) {
$rel = $matches_rel[1];
$url = $this->_limit_url( $matches_url[1] );
if ( ! empty( $url ) && empty( $data['_links'][ $new_matches[2] ] ) ) {
$data['_links'][ $new_matches[2] ] = $url;
}
if ( ! empty( $url ) && empty( $data['_links'][ $rel ] ) ) {
$data['_links'][ $rel ] = $url;
}
}
}
@ -600,7 +587,7 @@ class WP_Press_This {
$data = array();
// Only instantiate the keys we want. Sanity check and sanitize each one.
foreach ( array( 'u', 's', 't', 'v', '_version' ) as $key ) {
foreach ( array( 'u', 's', 't', 'v' ) as $key ) {
if ( ! empty( $_POST[ $key ] ) ) {
$value = wp_unslash( $_POST[ $key ] );
} else if ( ! empty( $_GET[ $key ] ) ) {
@ -629,48 +616,56 @@ class WP_Press_This {
*/
if ( apply_filters( 'enable_press_this_media_discovery', true ) ) {
/*
* If no title, _img, _embed, and _meta was passed via $_POST, fetch data from source as fallback,
* If no title, _images, _embed, and _meta was passed via $_POST, fetch data from source as fallback,
* making PT fully backward compatible with the older bookmarklet.
*/
if ( empty( $_POST ) && ! empty( $data['u'] ) ) {
$data = $this->source_data_fetch_fallback( $data['u'], $data );
} else {
foreach ( array( '_img', '_embed', '_meta' ) as $type ) {
foreach ( array( '_images', '_embeds' ) as $type ) {
if ( empty( $_POST[ $type ] ) ) {
continue;
}
$data[ $type ] = array();
$items = $this->_limit_array( $_POST[ $type ] );
$items = wp_unslash( $items );
foreach ( $items as $key => $value ) {
if ( ! is_numeric( $key ) ) {
$key = $this->_limit_string( wp_unslash( $key ) );
if ( $type === '_images' ) {
$value = $this->_limit_img( wp_unslash( $value ) );
} else {
$value = $this->_limit_embed( wp_unslash( $value ) );
}
// Sanity check. $key is usually things like 'title', 'description', 'keywords', etc.
if ( empty( $key ) || strlen( $key ) > 100 ) {
continue;
}
if ( ! empty( $value ) ) {
$data[ $type ][] = $value;
}
}
}
foreach ( array( '_meta', '_links' ) as $type ) {
if ( empty( $_POST[ $type ] ) ) {
continue;
}
$data[ $type ] = array();
$items = $this->_limit_array( $_POST[ $type ] );
foreach ( $items as $key => $value ) {
// Sanity check. These are associative arrays, $key is usually things like 'title', 'description', 'keywords', etc.
if ( empty( $key ) || strlen( $key ) > 100 ) {
continue;
}
if ( $type === '_meta' ) {
$value = $this->_limit_string( $value );
$value = $this->_limit_string( wp_unslash( $value ) );
if ( ! empty( $value ) ) {
$data = $this->_process_meta_entry( $key, $value, $data );
}
} else if ( $type === '_img' ) {
$value = $this->_limit_img( $value );
if ( ! empty( $value ) ) {
$data[ $type ][] = $value;
}
} else if ( $type === '_embed' ) {
$value = $this->_limit_embed( $value );
if ( ! empty( $value ) ) {
$data[ $type ][] = $value;
} else {
if ( in_array( $key, array( 'canonical', 'shortlink', 'icon' ), true ) ) {
$data[ $type ][ $key ] = $this->_limit_url( wp_unslash( $value ) );
}
}
}
@ -749,6 +744,7 @@ class WP_Press_This {
<label for="post-format-<?php echo $attr_format ?>" class="post-format-icon post-format-<?php echo $attr_format; ?>"><?php echo esc_html( get_post_format_string( $format ) ); ?></label>
<?php
}
?>
</fieldset>
</div>
@ -850,6 +846,194 @@ class WP_Press_This {
}
}
/**
* Get a list of embeds with no duplicates.
*
* @param array $data The site's data.
* @returns array
*/
public function get_embeds( $data ) {
$selected_embeds = array();
if ( ! empty( $data['_embeds'] ) ) {
foreach( $data['_embeds'] as $src ) {
$prot_relative_src = preg_replace( '/^https?:/', '', $src );
if ( in_array( $prot_relative_src, $this->embeds ) ) {
continue;
}
$selected_embeds[] = $src;
$this->embeds[] = $prot_relative_src;
}
}
return $selected_embeds;
}
/**
* Get a list of images with no duplicates.
*
* @param array $data The site's data.
* @returns array
*/
public function get_images( $data ) {
$selected_images = array();
if ( ! empty( $data['_images'] ) ) {
foreach( $data['_images'] as $src ) {
if ( false !== strpos( $src, 'gravatar.com' ) ) {
$src = preg_replace( '%http://[\d]+\.gravatar\.com/%', 'https://secure.gravatar.com/', $src );
}
$prot_relative_src = preg_replace( '/^https?:/', '', $src );
if ( in_array( $prot_relative_src, $this->images ) ||
( false !== strpos( $src, 'avatar' ) && count( $this->images ) > 15 ) ) {
// Skip: already selected or some type of avatar and we've already gathered more than 15 images.
continue;
}
$selected_images[] = $src;
$this->images[] = $prot_relative_src;
}
}
return $selected_images;
}
/**
* Gets the source page's canonical link, based on passed location and meta data.
*
* @param array $data The site's data.
* @returns string Discovered canonical URL, or empty
*/
public function get_canonical_link( $data ) {
$link = '';
if ( ! empty( $data['_links']['canonical'] ) ) {
$link = $data['_links']['canonical'];
} elseif ( ! empty( $data['u'] ) ) {
$link = $data['u'];
} elseif ( ! empty( $data['_meta'] ) ) {
if ( ! empty( $data['_meta']['twitter:url'] ) ) {
$link = $data['_meta']['twitter:url'];
} else if ( ! empty( $data['_meta']['og:url'] ) ) {
$link = $data['_meta']['og:url'];
}
}
if ( empty( $link ) && ! empty( $data['_links']['shortlink'] ) ) {
$link = $data['_links']['shortlink'];
}
return $link;
}
/**
* Gets the source page's site name, based on passed meta data.
*
* @param array $data The site's data.
* @returns string Discovered site name, or empty
*/
public function get_source_site_name( $data ) {
$name = '';
if ( ! empty( $data['_meta'] ) ) {
if ( ! empty( $data['_meta']['og:site_name'] ) ) {
$name = $data['_meta']['og:site_name'];
} else if ( ! empty( $data['_meta']['application-name'] ) ) {
$name = $data['_meta']['application-name'];
}
}
return $name;
}
/**
* Gets the source page's title, based on passed title and meta data.
*
* @param array $data The site's data.
* @returns string Discovered page title, or empty
*/
public function get_suggested_title( $data ) {
$title = '';
if ( ! empty( $data['t'] ) ) {
$title = $data['t'];
} elseif( ! empty( $data['_meta'] ) ) {
if ( ! empty( $data['_meta']['twitter:title'] ) ) {
$title = $data['_meta']['twitter:title'];
} else if ( ! empty( $data['_meta']['og:title'] ) ) {
$title = $data['_meta']['og:title'];
} else if ( ! empty( $data['_meta']['title'] ) ) {
$title = $data['_meta']['title'];
}
}
return $title;
}
/**
* Gets the source page's suggested content, based on passed data (description, selection, etc).
* Features a blockquoted excerpt, as well as content attribution, if any.
*
* @param array $data The site's data.
* @returns string Discovered content, or empty
*/
public function get_suggested_content( $data ) {
$content = $text = '';
if ( ! empty( $data['s'] ) ) {
$text = $data['s'];
} else if ( ! empty( $data['_meta'] ) ) {
if ( ! empty( $data['_meta']['twitter:description'] ) ) {
$text = $data['_meta']['twitter:description'];
} else if ( ! empty( $data['_meta']['og:description'] ) ) {
$text = $data['_meta']['og:description'];
} else if ( ! empty( $data['_meta']['description'] ) ) {
$text = $data['_meta']['description'];
}
}
$default_html = array(
'quote' => '<blockquote>%1$s</blockquote>',
'link' => '<p>' . _x( 'Source:', 'Used in Press This to indicate where the content comes from.' ) .
' <em><a href="%1$s">%2$s</a></em></p>',
);
/**
* Filter the default HTML for the Press This editor.
*
* @since 4.2.0
*
* @param array $default_html Associative array with two keys: 'quote' where %1$s is replaced with the site description
* or the selected content, and 'link' there %1$s is link href, %2$s is link text.
*/
$default_html = apply_filters( 'press_this_suggested_html', $default_html, $data );
// Wrap suggested content in the specified HTML.
if ( ! empty( $default_html['quote'] ) ) {
$content = sprintf( $default_html['quote'], $text );
}
// Add source attribution if there is one available.
if ( ! empty( $default_html['link'] ) ) {
$title = $this->get_suggested_title( $data );
$url = $this->get_canonical_link( $data );
if ( ! $title ) {
$title = $this->get_source_site_name( $data );
}
if ( $url && $title ) {
$content .= sprintf( $default_html['link'], $url, $title );
}
}
return $content;
}
/**
* Serves the app's base HTML, which in turns calls the load script.
*
@ -862,11 +1046,33 @@ class WP_Press_This {
// Get data, new (POST) and old (GET).
$data = $this->merge_or_fetch_data();
$post_title = $this->get_suggested_title( $data );
if ( empty( $title ) ) {
$title = __( 'New Post' );
}
$post_content = $this->get_suggested_content( $data );
// Get site settings array/data.
$site_settings = $this->site_settings();
// Set the passed data.
$data['_version'] = $site_settings['version'];
// Pass the images and embeds
$images = $this->get_images( $data );
$embeds = $this->get_embeds( $data );
$site_data = array(
'v' => ! empty( $data['v'] ) ? $data['v'] : '',
'hasData' => ! empty( $data ),
);
if ( ! empty( $images ) ) {
$site_data['_images'] = $images;
}
if ( ! empty( $embeds ) ) {
$site_data['_embeds'] = $embeds;
}
// Add press-this-editor.css and remove theme's editor-style.css, if any.
remove_editor_styles();
@ -890,8 +1096,8 @@ class WP_Press_This {
<title><?php esc_html_e( 'Press This!' ) ?></title>
<script>
window.wpPressThisData = <?php echo wp_json_encode( $data ) ?>;
window.wpPressThisConfig = <?php echo wp_json_encode( $site_settings ) ?>;
window.wpPressThisData = <?php echo wp_json_encode( $site_data ); ?>;
window.wpPressThisConfig = <?php echo wp_json_encode( $site_settings ); ?>;
</script>
<script type="text/javascript">
@ -959,7 +1165,7 @@ class WP_Press_This {
$admin_body_class .= ' version-' . str_replace( '.', '-', preg_replace( '/^([.0-9]+).*/', '$1', $wp_version ) );
$admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' );
$admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
/** This filter is documented in wp-admin/admin-header.php */
$admin_body_classes = apply_filters( 'admin_body_class', '' );
@ -1007,7 +1213,7 @@ class WP_Press_This {
<div id='app-container' class="editor">
<span id="title-container-label" class="post-title-placeholder" aria-hidden="true"><?php _e( 'Post title' ); ?></span>
<h2 id="title-container" class="post-title" contenteditable="true" spellcheck="true" aria-label="<?php esc_attr_e( 'Post title' ); ?>" tabindex="0"></h2>
<h2 id="title-container" class="post-title" contenteditable="true" spellcheck="true" aria-label="<?php esc_attr_e( 'Post title' ); ?>" tabindex="0"><?php echo esc_html( $post_title ); ?></h2>
<div id='featured-media-container' class="featured-container no-media">
<div id='all-media-widget' class="all-media">
<div id='all-media-container'></div>
@ -1015,7 +1221,7 @@ class WP_Press_This {
</div>
<?php
wp_editor( '', 'pressthis', array(
wp_editor( $post_content, 'pressthis', array(
'drag_drop_upload' => true,
'editor_height' => 600,
'media_buttons' => false,
@ -1039,7 +1245,7 @@ class WP_Press_This {
</div>
</div>
<div class="options-panel-back is-hidden" tabindex="-1"></div>
<div class="options-panel-back is-hidden" tabindex="-1"></div>
<div class="options-panel is-off-screen is-hidden" tabindex="-1">
<div class="post-options">

View File

@ -31,7 +31,7 @@
selection = document.selection.createRange().text || '';
}
pt_url += ( pt_url.indexOf( '?' ) > -1 ? '&' : '?' ) + 'buster=' + ( new Date().getTime() );
pt_url += '&buster=' + ( new Date().getTime() );
if ( ! canPost ) {
if ( document.title ) {
@ -68,18 +68,14 @@
form.appendChild( input );
}
if ( href.match( /\/\/www\.youtube\.com\/watch/ ) ) {
add( '_embed[]', href );
} else if ( href.match( /\/\/vimeo\.com\/(.+\/)?([\d]+)$/ ) ) {
add( '_embed[]', href );
} else if ( href.match( /\/\/(www\.)?dailymotion\.com\/video\/.+$/ ) ) {
add( '_embed[]', href );
} else if ( href.match( /\/\/soundcloud\.com\/.+$/ ) ) {
add( '_embed[]', href );
} else if ( href.match( /\/\/twitter\.com\/[^\/]+\/status\/[\d]+$/ ) ) {
add( '_embed[]', href );
} else if ( href.match( /\/\/vine\.co\/v\/[^\/]+/ ) ) {
add( '_embed[]', href );
if ( href.match( /\/\/www\.youtube\.com\/watch/ ) ||
href.match( /\/\/vimeo\.com\/(.+\/)?([\d]+)$/ ) ||
href.match( /\/\/(www\.)?dailymotion\.com\/video\/.+$/ ) ||
href.match( /\/\/soundcloud\.com\/.+$/ ) ||
href.match( /\/\/twitter\.com\/[^\/]+\/status\/[\d]+$/ ) ||
href.match( /\/\/vine\.co\/v\/[^\/]+/ ) ) {
add( '_embeds[]', href );
}
metas = head.getElementsByTagName( 'meta' ) || [];
@ -111,20 +107,8 @@
var g = links[ y ],
g_rel = g.getAttribute( 'rel' );
if ( g_rel ) {
switch ( g_rel ) {
case 'canonical':
case 'icon':
case 'shortlink':
add( '_links[' + g_rel + ']', g.getAttribute( 'href' ) );
break;
case 'alternate':
if ( 'application/json+oembed' === g.getAttribute( 'type' ) ) {
add( '_links[' + g_rel + ']', g.getAttribute( 'href' ) );
} else if ( 'handheld' === g.getAttribute( 'media' ) ) {
add( '_links[' + g_rel + ']', g.getAttribute( 'href' ) );
}
}
if ( g_rel === 'canonical' || g_rel === 'icon' || g_rel === 'shortlink' ) {
add( '_links[' + g_rel + ']', g.getAttribute( 'href' ) );
}
}
@ -147,7 +131,7 @@
img.src = imgs[ n ].src;
if ( img.width >= 256 && img.height >= 128 ) {
add( '_img[]', img.src );
add( '_images[]', img.src );
}
}
@ -158,7 +142,7 @@
break;
}
add( '_embed[]', ifrs[ p ].src );
add( '_embeds[]', ifrs[ p ].src );
}
if ( document.title ) {

View File

@ -1 +1 @@
!function(a,b,c,d){function e(a,c){if("undefined"!=typeof c){var d=b.createElement("input");d.name=a,d.value=c,d.type="hidden",o.appendChild(d)}}var f,g,h,i,j,k,l,m,n=a.encodeURIComponent,o=b.createElement("form"),p=b.getElementsByTagName("head")[0],q=new Image,r="_press_this_app",s=!0;if(d){if(!c.match(/^https?:/))return void(top.location.href=d);if(d+="&u="+n(c),c.match(/^https:/)&&d.match(/^http:/)&&(s=!1),a.getSelection?m=a.getSelection()+"":b.getSelection?m=b.getSelection()+"":b.selection&&(m=b.selection.createRange().text||""),d+=(d.indexOf("?")>-1?"&":"?")+"buster="+(new Date).getTime(),s||(b.title&&(d+="&t="+n(b.title.substr(0,256))),m&&(d+="&s="+n(m.substr(0,512)))),f=a.outerWidth||b.documentElement.clientWidth||600,g=a.outerHeight||b.documentElement.clientHeight||700,f=800>f||f>5e3?600:.7*f,g=800>g||g>3e3?700:.9*g,!s)return void a.open(d,r,"location,resizable,scrollbars,width="+f+",height="+g);c.match(/\/\/www\.youtube\.com\/watch/)?e("_embed[]",c):c.match(/\/\/vimeo\.com\/(.+\/)?([\d]+)$/)?e("_embed[]",c):c.match(/\/\/(www\.)?dailymotion\.com\/video\/.+$/)?e("_embed[]",c):c.match(/\/\/soundcloud\.com\/.+$/)?e("_embed[]",c):c.match(/\/\/twitter\.com\/[^\/]+\/status\/[\d]+$/)?e("_embed[]",c):c.match(/\/\/vine\.co\/v\/[^\/]+/)&&e("_embed[]",c),h=p.getElementsByTagName("meta")||[];for(var t=0;t<h.length&&!(t>=50);t++){var u=h[t],v=u.getAttribute("name"),w=u.getAttribute("property"),x=u.getAttribute("content");v?e("_meta["+v+"]",x):w&&e("_meta["+w+"]",x)}i=p.getElementsByTagName("link")||[];for(var y=0;y<i.length&&!(y>=50);y++){var z=i[y],A=z.getAttribute("rel");if(A)switch(A){case"canonical":case"icon":case"shortlink":e("_links["+A+"]",z.getAttribute("href"));break;case"alternate":"application/json+oembed"===z.getAttribute("type")?e("_links["+A+"]",z.getAttribute("href")):"handheld"===z.getAttribute("media")&&e("_links["+A+"]",z.getAttribute("href"))}}b.body.getElementsByClassName&&(j=b.body.getElementsByClassName("hfeed")[0]),j=b.getElementById("content")||j||b.body,k=j.getElementsByTagName("img")||[];for(var B=0;B<k.length&&!(B>=50);B++)k[B].src.indexOf("avatar")>-1||k[B].className.indexOf("avatar")>-1||(q.src=k[B].src,q.width>=256&&q.height>=128&&e("_img[]",q.src));l=b.body.getElementsByTagName("iframe")||[];for(var C=0;C<l.length&&!(C>=50);C++)e("_embed[]",l[C].src);b.title&&e("t",b.title),m&&e("s",m),o.setAttribute("method","POST"),o.setAttribute("action",d),o.setAttribute("target",r),o.setAttribute("style","display: none;"),a.open("about:blank",r,"location,resizable,scrollbars,width="+f+",height="+g),b.body.appendChild(o),o.submit()}}(window,document,top.location.href,window.pt_url);
!function(a,b,c,d){function e(a,c){if("undefined"!=typeof c){var d=b.createElement("input");d.name=a,d.value=c,d.type="hidden",o.appendChild(d)}}var f,g,h,i,j,k,l,m,n=a.encodeURIComponent,o=b.createElement("form"),p=b.getElementsByTagName("head")[0],q=new Image,r="_press_this_app",s=!0;if(d){if(!c.match(/^https?:/))return void(top.location.href=d);if(d+="&u="+n(c),c.match(/^https:/)&&d.match(/^http:/)&&(s=!1),a.getSelection?m=a.getSelection()+"":b.getSelection?m=b.getSelection()+"":b.selection&&(m=b.selection.createRange().text||""),d+="&buster="+(new Date).getTime(),s||(b.title&&(d+="&t="+n(b.title.substr(0,256))),m&&(d+="&s="+n(m.substr(0,512)))),f=a.outerWidth||b.documentElement.clientWidth||600,g=a.outerHeight||b.documentElement.clientHeight||700,f=800>f||f>5e3?600:.7*f,g=800>g||g>3e3?700:.9*g,!s)return void a.open(d,r,"location,resizable,scrollbars,width="+f+",height="+g);(c.match(/\/\/www\.youtube\.com\/watch/)||c.match(/\/\/vimeo\.com\/(.+\/)?([\d]+)$/)||c.match(/\/\/(www\.)?dailymotion\.com\/video\/.+$/)||c.match(/\/\/soundcloud\.com\/.+$/)||c.match(/\/\/twitter\.com\/[^\/]+\/status\/[\d]+$/)||c.match(/\/\/vine\.co\/v\/[^\/]+/))&&e("_embeds[]",c),h=p.getElementsByTagName("meta")||[];for(var t=0;t<h.length&&!(t>=50);t++){var u=h[t],v=u.getAttribute("name"),w=u.getAttribute("property"),x=u.getAttribute("content");v?e("_meta["+v+"]",x):w&&e("_meta["+w+"]",x)}i=p.getElementsByTagName("link")||[];for(var y=0;y<i.length&&!(y>=50);y++){var z=i[y],A=z.getAttribute("rel");("canonical"===A||"icon"===A||"shortlink"===A)&&e("_links["+A+"]",z.getAttribute("href"))}b.body.getElementsByClassName&&(j=b.body.getElementsByClassName("hfeed")[0]),j=b.getElementById("content")||j||b.body,k=j.getElementsByTagName("img")||[];for(var B=0;B<k.length&&!(B>=50);B++)k[B].src.indexOf("avatar")>-1||k[B].className.indexOf("avatar")>-1||(q.src=k[B].src,q.width>=256&&q.height>=128&&e("_images[]",q.src));l=b.body.getElementsByTagName("iframe")||[];for(var C=0;C<l.length&&!(C>=50);C++)e("_embeds[]",l[C].src);b.title&&e("t",b.title),m&&e("s",m),o.setAttribute("method","POST"),o.setAttribute("action",d),o.setAttribute("target",r),o.setAttribute("style","display: none;"),a.open("about:blank",r,"location,resizable,scrollbars,width="+f+",height="+g),b.body.appendChild(o),o.submit()}}(window,document,top.location.href,window.pt_url);

View File

@ -8,14 +8,9 @@
saveAlert = false,
textarea = document.createElement( 'textarea' ),
sidebarIsOpen = false,
siteConfig = window.wpPressThisConfig || {},
settings = window.wpPressThisConfig || {},
data = window.wpPressThisData || {},
smallestWidth = 128,
interestingImages = getInterestingImages( data ) || [],
interestingEmbeds = getInterestingEmbeds( data ) || [],
hasEmptyTitleStr = false,
suggestedTitleStr = getSuggestedTitle( data ),
suggestedContentStr = getSuggestedContent( data ),
hasSetFocus = false,
catsCache = [],
isOffScreen = 'is-off-screen',
@ -75,10 +70,14 @@
* @returns string Sanitized text.
*/
function sanitizeText( text ) {
text = stripTags( text );
textarea.innerHTML = text;
var _text = stripTags( text );
return stripTags( textarea.value );
try {
textarea.innerHTML = _text;
_text = stripTags( textarea.value );
} catch ( er ) {}
return _text;
}
/**
@ -98,190 +97,6 @@
return '';
}
/**
* Gets the source page's canonical link, based on passed location and meta data.
*
* @returns string Discovered canonical URL, or empty
*/
function getCanonicalLink() {
var link = '';
if ( data._links && data._links.canonical ) {
link = data._links.canonical;
}
if ( ! link && data.u ) {
link = data.u;
}
if ( ! link && data._meta ) {
if ( data._meta['twitter:url'] ) {
link = data._meta['twitter:url'];
} else if ( data._meta['og:url'] ) {
link = data._meta['og:url'];
}
}
return checkUrl( decodeURI( link ) );
}
/**
* Gets the source page's site name, based on passed meta data.
*
* @returns string Discovered site name, or empty
*/
function getSourceSiteName() {
var name = '';
if ( data._meta ) {
if ( data._meta['og:site_name'] ) {
name = data._meta['og:site_name'];
} else if ( data._meta['application-name'] ) {
name = data._meta['application-name'];
}
}
return sanitizeText( name );
}
/**
* Gets the source page's title, based on passed title and meta data.
*
* @returns string Discovered page title, or empty
*/
function getSuggestedTitle() {
var title = '';
if ( data.t ) {
title = data.t;
}
if ( ! title && data._meta ) {
if ( data._meta['twitter:title'] ) {
title = data._meta['twitter:title'];
} else if ( data._meta['og:title'] ) {
title = data._meta['og:title'];
} else if ( data._meta.title ) {
title = data._meta.title;
}
}
if ( ! title ) {
title = __( 'newPost' );
hasEmptyTitleStr = true;
}
return sanitizeText( title );
}
/**
* Gets the source page's suggested content, based on passed data (description, selection, etc).
* Features a blockquoted excerpt, as well as content attribution, if any.
*
* @returns string Discovered content, or empty
*/
function getSuggestedContent() {
var content = '',
text = '',
title = getSuggestedTitle(),
url = getCanonicalLink(),
siteName = getSourceSiteName();
if ( data.s ) {
text = data.s;
} else if ( data._meta ) {
if ( data._meta['twitter:description'] ) {
text = data._meta['twitter:description'];
} else if ( data._meta['og:description'] ) {
text = data._meta['og:description'];
} else if ( data._meta.description ) {
text = data._meta.description;
}
}
if ( text && siteConfig.html.quote ) {
// Wrap suggested content in specified HTML.
content = siteConfig.html.quote.replace( /%1\$s/g, sanitizeText( text ) );
}
// Add a source attribution if there is one available.
if ( url && siteConfig.html.link && ( ( title && __( 'newPost' ) !== title ) || siteName ) ) {
content += siteConfig.html.link.replace( /%1\$s/g, encodeURI( url ) ).replace( /%2\$s/g, ( title || siteName ) );
}
return content || '';
}
/**
* Get a list of valid embeds from what was passed via WpPressThis_App.data._embed on page load.
*
* @returns array
*/
function getInterestingEmbeds() {
var embeds = data._embed || [],
interestingEmbeds = [],
alreadySelected = [];
if ( embeds.length ) {
$.each( embeds, function ( i, src ) {
if ( ! src ) {
// Skip: no src value
return;
}
var schemelessSrc = src.replace( /^https?:/, '' );
if ( $.inArray( schemelessSrc, alreadySelected ) > -1 ) {
// Skip: already shown
return;
}
interestingEmbeds.push( src );
alreadySelected.push( schemelessSrc );
} );
}
return interestingEmbeds;
}
/**
* Get a list of valid images from what was passed via WpPressThis_App.data._img and WpPressThis_App.data._meta on page load.
*
* @returns array
*/
function getInterestingImages( data ) {
var imgs = data._img || [],
interestingImgs = [],
alreadySelected = [];
if ( imgs.length ) {
$.each( imgs, function ( i, src ) {
src = src.replace( /http:\/\/[\d]+\.gravatar\.com\//, 'https://secure.gravatar.com/' );
src = checkUrl( src );
if ( ! src ) {
// Skip: no src value
return;
}
var schemelessSrc = src.replace( /^https?:/, '' );
if ( Array.prototype.indexOf && alreadySelected.indexOf( schemelessSrc ) > -1 ) {
// Skip: already shown
return;
} else if ( src.indexOf( 'avatar' ) > -1 && interestingImgs.length >= 15 ) {
// Skip: some type of avatar and we've already gathered more than 23 diff images to show
return;
}
interestingImgs.push( src );
alreadySelected.push( schemelessSrc );
} );
}
return interestingImgs;
}
/**
* Show UX spinner
*/
@ -345,7 +160,7 @@
renderError( response.data.errorMessage );
hideSpinner();
} else if ( response.data.redirect ) {
if ( window.opener && siteConfig.redirInParent ) {
if ( window.opener && settings.redirInParent ) {
try {
window.opener.location.href = response.data.redirect;
} catch( er ) {}
@ -456,7 +271,7 @@
* Hide the form letting users enter a URL to be scanned, if a URL was already passed.
*/
function renderToolsVisibility() {
if ( data.u && data.u.match( /^https?:/ ) ) {
if ( data.hasData ) {
$( '#scanbar' ).hide();
}
}
@ -495,56 +310,11 @@
}
// Prompt user to upgrade their bookmarklet if there is a version mismatch.
if ( data.v && data._version && ( data.v + '' ) !== ( data._version + '' ) ) {
if ( data.v && settings.version && ( data.v + '' ) !== ( settings.version + '' ) ) {
$( '.should-upgrade-bookmarklet' ).removeClass( 'is-hidden' );
}
}
/**
* Render the suggested title, if any
*/
function renderSuggestedTitle() {
var suggestedTitle = suggestedTitleStr || '',
$title = $( '#title-container' );
if ( ! hasEmptyTitleStr ) {
$( '#post_title' ).val( suggestedTitle );
$title.text( suggestedTitle );
$( '.post-title-placeholder' ).addClass( 'is-hidden' );
}
$title.on( 'keyup', function() {
saveAlert = true;
}).on( 'paste', function() {
saveAlert = true;
setTimeout( function() {
$title.text( $title.text() );
}, 100 );
} );
}
/**
* Render the suggested content, if any
*/
function renderSuggestedContent() {
if ( ! suggestedContentStr ) {
return;
}
if ( ! editor ) {
editor = window.tinymce.get( 'pressthis' );
}
if ( editor ) {
editor.setContent( suggestedContentStr );
editor.on( 'focus', function() {
hasSetFocus = true;
} );
}
}
/**
* Render the detected images and embed for selection, if any
*/
@ -555,12 +325,12 @@
listContainer.empty();
if ( interestingEmbeds || interestingImages ) {
listContainer.append( '<h2 class="screen-reader-text">' + __( 'allMediaHeading' ) + '</h2><ul class="wppt-all-media-list"/>' );
if ( data._embeds || data._images ) {
listContainer.append( '<h2 class="screen-reader-text">' + __( 'allMediaHeading' ) + '</h2><ul class="wppt-all-media-list" />' );
}
if ( interestingEmbeds ) {
$.each( interestingEmbeds, function ( i, src ) {
if ( data._embeds ) {
$.each( data._embeds, function ( i, src ) {
src = checkUrl( src );
var displaySrc = '',
@ -601,8 +371,8 @@
} );
}
if ( interestingImages ) {
$.each( interestingImages, function ( i, src ) {
if ( data._images ) {
$.each( data._images, function( i, src ) {
src = checkUrl( src );
var displaySrc = src.replace(/^(http[^\?]+)(\?.*)?$/, '$1');
@ -716,25 +486,27 @@
// Reset to options list
$( '.post-options' ).removeClass( offscreenHidden );
$( '.setting-modal').addClass( offscreenHidden );
} );
});
}
/**
* Interactive behavior for the post title's field placeholder
*/
function monitorPlaceholder() {
var $selector = $( '#title-container'),
var $titleField = $( '#title-container'),
$placeholder = $('.post-title-placeholder');
$selector.on( 'focus', function() {
$titleField.on( 'focus', function() {
$placeholder.addClass('is-hidden');
} );
$selector.on( 'blur', function() {
if ( ! $( this ).text() ) {
}).on( 'blur', function() {
if ( ! $titleField.text() ) {
$placeholder.removeClass('is-hidden');
}
} );
});
if ( $titleField.text() ) {
$placeholder.addClass('is-hidden');
}
}
/* ***************************************************************
@ -747,9 +519,7 @@
function render(){
// We're on!
renderToolsVisibility();
renderSuggestedTitle();
renderDetectedMedia();
$( document ).on( 'tinymce-editor-init', renderSuggestedContent );
renderStartupNotices();
if ( window.tagBox ) {
@ -761,12 +531,19 @@
* Set app events and other state monitoring related code.
*/
function monitor(){
$( document ).on( 'tinymce-editor-init', function( event, ed ) {
editor = ed;
ed.on( 'focus', function() {
hasSetFocus = true;
} );
});
$( '#current-site a').click( function( e ) {
e.preventDefault();
} );
// Publish and Draft buttons and submit
// Publish, Draft and Preview buttons
$( '.post-actions' ).on( 'click.press-this', function( event ) {
var $target = $( event.target );
@ -876,8 +653,7 @@
refreshCatsCache();
});
// Expose public methods
// TODO: which are needed?
// Expose public methods?
return {
renderNotice: renderNotice,
renderError: renderError

File diff suppressed because one or more lines are too long

View File

@ -2600,7 +2600,7 @@ function paginate_comments_links($args = array()) {
function get_shortcut_link() {
global $is_IE, $wp_version;
$bookmarklet_version = '6';
$bookmarklet_version = '7';
$link = '';
if ( $is_IE ) {

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.2-alpha-31692';
$wp_version = '4.2-alpha-31693';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.