PressThis:

- Simplify `getSuggestedContent()` and helpers. No need to override the global `data`.
- Replace the `press_this_source_string` and `press_this_source_link` filters with `press_this_suggested_html` that allows filtering of the link and the wrapper HTML tags.
See #31373.
Built from https://develop.svn.wordpress.org/trunk@31595


git-svn-id: http://core.svn.wordpress.org/trunk@31576 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2015-03-01 22:44:25 +00:00
parent 5e07bfdfd1
commit 4e8138cea5
5 changed files with 46 additions and 79 deletions

View File

@ -31,6 +31,9 @@ class WP_Press_This {
* @return array Site settings.
*/
public function site_settings() {
$html = '<p class="press-this-suggested-source">' . _x( 'Source:', 'Used in Press This to indicate where the content comes from.' ) .
' <cite><a href="%1$s">%2$s</a></cite></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.
@ -41,9 +44,18 @@ class WP_Press_This {
*
* @since 4.2.0
*
* @param bool $redir_in_parent Whether to redirect in parent window or not. Default false.
* @param bool false Whether to redirect in parent window or not. Default false.
*/
'redir_in_parent' => apply_filters( 'press_this_redirect_in_parent', false ),
'redirInParent' => apply_filters( 'press_this_redirect_in_parent', false ),
/**
* Filter the HTML for the Press This source attribution.
*
* @since 4.2.0
*
* @param string $html Default HTML, %1$s is link href, %2$s is link text.
*/
'suggestedHTML' => apply_filters( 'press_this_suggested_html', $html ),
);
}

View File

@ -100,14 +100,9 @@
/**
* Gets the source page's canonical link, based on passed location and meta data.
*
* @param data object Usually WpPressThis_App.data
* @returns string Discovered canonical URL, or empty
*/
function getCanonicalLink( data ) {
if ( ! data || data.length ) {
return '';
}
function getCanonicalLink() {
var link = '';
if ( data._links ) {
@ -128,20 +123,15 @@
}
}
return decodeURI( link );
return checkUrl( decodeURI( link ) );
}
/**
* Gets the source page's site name, based on passed meta data.
*
* @param data object Usually WpPressThis_App.data
* @returns string Discovered site name, or empty
*/
function getSourceSiteName( data ) {
if ( ! data || data.length ) {
return '';
}
function getSourceSiteName() {
var name = '';
if ( data._meta ) {
@ -152,27 +142,22 @@
}
}
return name.replace( /\\/g, '' );
return sanitizeText( name );
}
/**
* Gets the source page's title, based on passed title and meta data.
*
* @param data object Usually WpPressThis_App.data
* @returns string Discovered page title, or empty
*/
function getSuggestedTitle( data ) {
if ( ! data || data.length ) {
return __( 'newPost' );
}
function getSuggestedTitle() {
var title = '';
if ( data.t ) {
title = data.t;
}
if ( ! title.length && data._meta ) {
if ( ! title && data._meta ) {
if ( data._meta['twitter:title'] && data._meta['twitter:title'].length ) {
title = data._meta['twitter:title'];
} else if ( data._meta['og:title'] && data._meta['og:title'].length ) {
@ -182,60 +167,51 @@
}
}
if ( ! title.length ) {
if ( ! title ) {
title = __( 'newPost' );
hasEmptyTitleStr = true;
}
return title.replace( /\\/g, '' );
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.
*
* @param data object Usually WpPressThis_App.data
* @returns string Discovered content, or empty
*/
function getSuggestedContent( data ) {
if ( ! data || data.length ) {
return '';
}
function getSuggestedContent() {
var content = '',
title = getSuggestedTitle( data ),
url = getCanonicalLink( data ),
siteName = getSourceSiteName( data );
text = '',
title = getSuggestedTitle(),
url = getCanonicalLink(),
siteName = getSourceSiteName();
if ( data.s && data.s.length ) {
content = data.s;
text = data.s;
} else if ( data._meta ) {
if ( data._meta['twitter:description'] && data._meta['twitter:description'].length ) {
content = data._meta['twitter:description'];
text = data._meta['twitter:description'];
} else if ( data._meta['og:description'] && data._meta['og:description'].length ) {
content = data._meta['og:description'];
text = data._meta['og:description'];
} else if ( data._meta.description && data._meta.description.length ) {
content = data._meta.description;
text = data._meta.description;
}
}
// Wrap suggested content in blockquote tag, if we have any.
content = ( content.length ? '<blockquote class="press-this-suggested-content">' + sanitizeText( content ) + '</blockquote>' : '' );
if ( text ) {
text = sanitizeText( text );
// Wrap suggested content in blockquote tag.
content = '<blockquote class="press-this-suggested-content">' + text + '</blockquote>';
}
// Add a source attribution if there is one available.
if ( ( ( title.length && __( 'newPost' ) !== title ) || siteName.length ) && url.length ) {
content += '<p class="press-this-suggested-source">';
content += __( 'source' );
content += ' <cite>';
content += __( 'sourceLink').replace( '%1$s', encodeURI( url ) ).replace( '%2$s', sanitizeText( title || siteName ) );
content += '</cite></p>';
if ( url && siteConfig.suggestedHTML && ( ( title && __( 'newPost' ) !== title ) || siteName ) ) {
content += siteConfig.suggestedHTML.replace( '%1$s', encodeURI( url ) ).replace( '%2$s', ( title || siteName ) );
}
if ( ! content ) {
content = '';
}
return content.replace( /\\/g, '' );
return content || '';
}
/**
@ -472,7 +448,7 @@
renderError( response.data.errorMessage );
hideSpinner();
} else if ( response.data.redirect ) {
if ( window.opener && siteConfig.redir_in_parent ) {
if ( window.opener && siteConfig.redirInParent ) {
try {
window.opener.location.href = response.data.redirect;
} catch( er ) {}
@ -514,13 +490,10 @@
}
if ( ! hasSetFocus ) {
// Append to top of content on 1st media insert
editor.setContent( newContent + editor.getContent() );
} else {
// Or add where the cursor was last positioned in TinyMCE
editor.execCommand( 'mceInsertContent', false, newContent );
editor.focus();
}
editor.execCommand( 'mceInsertContent', false, newContent );
hasSetFocus = true;
}
@ -673,7 +646,6 @@
hasSetFocus = true;
} );
}
}
/**

File diff suppressed because one or more lines are too long

View File

@ -474,23 +474,6 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'press-this', "/wp-admin/js/press-this$suffix.js", array( 'jquery', 'tags-box' ), false, 1 );
did_action( 'init' ) && $scripts->localize( 'press-this', 'pressThisL10n', array(
/**
* Filter the string displayed before the source attribution string in Press This.
*
* @since 4.2.0
*
* @param string $string Internationalized source string.
*/
'source' => apply_filters( 'press_this_source_string', __( 'Source:' ) ),
/**
* Filter the HTML link format for the Press This source attribution, can control target, class, etc.
*
* @since 4.2.0
*
* @param string $link_format Link format, %1$s is link href, %2$s is link text.
*/
'sourceLink' => apply_filters( 'press_this_source_link', '<a href="%1$s">%2$s</a>' ),
'newPost' => __( 'Title' ),
'unexpectedError' => __( 'Sorry, but an unexpected error occurred.' ),
'saveAlert' => __( 'The changes you made will be lost if you navigate away from this page.' ),

View File

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