diff --git a/wp-admin/includes/class-wp-press-this.php b/wp-admin/includes/class-wp-press-this.php index b3acb52b5c..1ca2ce2ff9 100644 --- a/wp-admin/includes/class-wp-press-this.php +++ b/wp-admin/includes/class-wp-press-this.php @@ -31,6 +31,9 @@ class WP_Press_This { * @return array Site settings. */ public function site_settings() { + $html = '

' . _x( 'Source:', 'Used in Press This to indicate where the content comes from.' ) . + ' %2$s

'; + 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 ), ); } diff --git a/wp-admin/js/press-this.js b/wp-admin/js/press-this.js index 9836a2602e..d718abcf2d 100644 --- a/wp-admin/js/press-this.js +++ b/wp-admin/js/press-this.js @@ -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,21 +123,16 @@ } } - 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 ''; - } - - var name=''; + function getSourceSiteName() { + var name = ''; if ( data._meta ) { if ( data._meta['og:site_name'] && data._meta['og:site_name'].length ) { @@ -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 ''; - } - - var content = '', - title = getSuggestedTitle( data ), - url = getCanonicalLink( data ), - siteName = getSourceSiteName( data ); + function getSuggestedContent() { + var content = '', + 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 ? '
' + sanitizeText( content ) + '
' : '' ); + if ( text ) { + text = sanitizeText( text ); + // Wrap suggested content in blockquote tag. + content = '
' + text + '
'; + } // Add a source attribution if there is one available. - if ( ( ( title.length && __( 'newPost' ) !== title ) || siteName.length ) && url.length ) { - content += '

'; - content += __( 'source' ); - content += ' '; - content += __( 'sourceLink').replace( '%1$s', encodeURI( url ) ).replace( '%2$s', sanitizeText( title || siteName ) ); - content += '

'; + 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; } ); } - } /** diff --git a/wp-admin/js/press-this.min.js b/wp-admin/js/press-this.min.js index d6517f6ff5..9a16421d5d 100644 --- a/wp-admin/js/press-this.min.js +++ b/wp-admin/js/press-this.min.js @@ -1 +1 @@ -!function(a,b){var c=function(){function c(a){return a&&b.pressThisL10n?b.pressThisL10n[a]||a:a||""}function d(a){return a=a||"",a.replace(/|$)/g,"").replace(/<(script|style)[^>]*>[\s\S]*?(<\/\1>|$)/gi,"").replace(/<\/?[a-z][^>]*>/gi,"")}function e(a){return a=d(a),a.replace(/\\/,"").replace(//g,">").replace(/"/g,""").replace(/'/g,"'")}function f(b){return b=a.trim(b||""),/^(?:https?:)?\/\//.test(b)?(b=d(b),b.replace(/["\\]+/g,"")):""}function g(a){if(!a||a.length)return"";var b="";return a._links&&a._links.canonical&&a._links.canonical.length&&(b=a._links.canonical),!b.length&&a.u&&(b=a.u),!b.length&&a._meta&&(a._meta["twitter:url"]&&a._meta["twitter:url"].length?b=a._meta["twitter:url"]:a._meta["og:url"]&&a._meta["og:url"].length&&(b=a._meta["og:url"])),decodeURI(b)}function h(a){if(!a||a.length)return"";var b="";return a._meta&&(a._meta["og:site_name"]&&a._meta["og:site_name"].length?b=a._meta["og:site_name"]:a._meta["application-name"]&&a._meta["application-name"].length&&(b=a._meta["application-name"])),b.replace(/\\/g,"")}function i(a){if(!a||a.length)return c("newPost");var b="";return a.t&&(b=a.t),!b.length&&a._meta&&(a._meta["twitter:title"]&&a._meta["twitter:title"].length?b=a._meta["twitter:title"]:a._meta["og:title"]&&a._meta["og:title"].length?b=a._meta["og:title"]:a._meta.title&&a._meta.title.length&&(b=a._meta.title)),b.length||(b=c("newPost"),O=!0),b.replace(/\\/g,"")}function j(a){if(!a||a.length)return"";var b="",d=i(a),f=g(a),j=h(a);return a.s&&a.s.length?b=a.s:a._meta&&(a._meta["twitter:description"]&&a._meta["twitter:description"].length?b=a._meta["twitter:description"]:a._meta["og:description"]&&a._meta["og:description"].length?b=a._meta["og:description"]:a._meta.description&&a._meta.description.length&&(b=a._meta.description)),b=b.length?'
'+e(b)+"
":"",(d.length&&c("newPost")!==d||j.length)&&f.length&&(b+='

',b+=c("source"),b+=" ",b+=c("sourceLink").replace("%1$s",encodeURI(f)).replace("%2$s",e(d||j)),b+="

"),b||(b=""),b.replace(/\\/g,"")}function k(a){return a?a.match(/\/\/(m\.|www\.)?youtube\.com\/watch\?/)||a.match(/\/youtu\.be\/.+$/)?!0:a.match(/\/\/vimeo\.com\/(.+\/)?[\d]+$/)?!0:a.match(/\/\/(www\.)?dailymotion\.com\/video\/.+$/)?!0:a.match(/\/\/soundcloud\.com\/.+$/)?!0:a.match(/\/\/twitter\.com\/[^\/]+\/status\/[\d]+$/)?!0:a.match(/\/\/vine\.co\/v\/[^\/]+/)?!0:!1:!1}function l(a){return a.match(/\/ad[sx]{1}?\//)?!0:a.match(/(\/share-?this[^\.]+?\.[a-z0-9]{3,4})(\?.*)?$/)?!0:a.match(/\/(spinner|loading|spacer|blank|rss)\.(gif|jpg|png)/)?!0:a.match(/\/([^\.\/]+[-_]{1})?(spinner|loading|spacer|blank)s?([-_]{1}[^\.\/]+)?\.[a-z0-9]{3,4}/)?!0:a.match(/([^\.\/]+[-_]{1})?thumb[^.]*\.(gif|jpg|png)$/)?!0:a.match(/\/wp-includes\//)?!0:a.match(/[^\d]{1}\d{1,2}x\d+\.(gif|jpg|png)$/)?!0:a.indexOf("/g.gif")>-1?!0:a.indexOf("/pixel.mathtag.com")>-1?!0:!1}function m(){var b=K._embed||[],c=[],d=[];return b.length&&a.each(b,function(b,e){if(e&&e.length&&k(e)){var f=e.replace(/^https?:/,"");a.inArray(f,d)>-1||(c.push(e),d.push(f))}}),c}function n(a){var b="";return a&&a._meta?(a._meta["twitter:image0:src"]&&a._meta["twitter:image0:src"].length?b=a._meta["twitter:image0:src"]:a._meta["twitter:image0"]&&a._meta["twitter:image0"].length?b=a._meta["twitter:image0"]:a._meta["twitter:image:src"]&&a._meta["twitter:image:src"].length?b=a._meta["twitter:image:src"]:a._meta["twitter:image"]&&a._meta["twitter:image"].length?b=a._meta["twitter:image"]:a._meta["og:image"]&&a._meta["og:image"].length?b=a._meta["og:image"]:a._meta["og:image:secure_url"]&&a._meta["og:image:secure_url"].length&&(b=a._meta["og:image:secure_url"]),b=f(b),l(b)?"":b):""}function o(b){var c=b._img||[],d=n(b)||"",e=[],g=[];return d.length&&(e.push(d),g.push(d.replace(/^https?:/,""))),c.length&&a.each(c,function(a,b){if(b=b.replace(/http:\/\/[\d]+\.gravatar\.com\//,"https://secure.gravatar.com/"),b=f(b),b&&b.length){var c=b.replace(/^https?:/,"");Array.prototype.indexOf&&g.indexOf(c)>-1||l(b)||b.indexOf("avatar")>-1&&e.length>=15||(e.push(b),g.push(c))}}),e}function p(){a("#spinner").addClass("show"),a(".post-actions button").each(function(){a(this).attr("disabled","disabled")})}function q(){a("#spinner").removeClass("show"),a(".post-actions button").each(function(){a(this).removeAttr("disabled")})}function r(c){I=!1,p();var d=a("#pressthis-form");"publish"===c&&a("#post_status").val("publish"),H&&H.save(),a("#title-field").val(e(a("#title-container").text())),b.tagBox&&a("div.tagsdiv").each(function(){b.tagBox.flushTags(this,!1,1)});var f=d.serialize();a.ajax({type:"post",url:b.ajaxurl,data:f,success:function(a){if(a.success){if(a.data.redirect)if(b.opener&&J.redir_in_parent){try{b.opener.location.href=a.data.redirect}catch(c){}b.self.close()}else b.location.href=a.data.redirect}else w(a.data.errorMessage),q()}})}function s(a,b,c){var d="";H&&(b=f(b),c=f(c),"img"===a?(c&&c.length||(c=b),d='\n'):d="[embed]"+b+"[/embed]\n",R?H.execCommand("mceInsertContent",!1,d):H.setContent(d+H.getContent()),R=!0)}function t(){var c,d=a("#new-category").val();d&&(c={action:"press-this-add-category",post_id:a("#post_ID").val()||0,name:d,new_cat_nonce:a("#_ajax_nonce-add-category").val()||"",parent:a("#new-category-parent").val()||0},a.post(b.ajaxurl,c,function(b){if(b.success){var c,d,e=a("ul.categories-select");a.each(b.data,function(b,f){var g=a("
  • ").attr("id","category-"+f.term_id).append(a('