Make WordPress Core

Changeset 31595


Ignore:
Timestamp:
03/01/2015 10:43:36 PM (12 years ago)
Author:
azaozz
Message:

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.

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-press-this.php

    r31589 r31595  
    3232         */
    3333        public function site_settings() {
     34                $html = '<p class="press-this-suggested-source">' . _x( 'Source:', 'Used in Press This to indicate where the content comes from.' ) .
     35                        ' <cite><a href="%1$s">%2$s</a></cite></p>';
     36
    3437                return array(
    3538                        // Used to trigger the bookmarklet update notice.
    … …  
    4245                         * @since 4.2.0
    4346                         *
    44                          * @param bool $redir_in_parent Whether to redirect in parent window or not. Default false.
     47                         * @param bool false Whether to redirect in parent window or not. Default false.
    4548                         */
    46                         'redir_in_parent' => apply_filters( 'press_this_redirect_in_parent', false ),
     49                        'redirInParent' => apply_filters( 'press_this_redirect_in_parent', false ),
     50
     51                        /**
     52                         * Filter the HTML for the Press This source attribution.
     53                         *
     54                         * @since 4.2.0
     55                         *
     56                         * @param string $html Default HTML, %1$s is link href, %2$s is link text.
     57                         */
     58                        'suggestedHTML' => apply_filters( 'press_this_suggested_html', $html ),
    4759                );
    4860        }
  • trunk/src/wp-admin/js/press-this.js

    r31589 r31595  
    101101                 * Gets the source page's canonical link, based on passed location and meta data.
    102102                 *
    103                  * @param data object Usually WpPressThis_App.data
    104103                 * @returns string Discovered canonical URL, or empty
    105104                 */
    106                 function getCanonicalLink( data ) {
    107                         if ( ! data || data.length ) {
    108                                 return '';
    109                         }
    110 
     105                function getCanonicalLink() {
    111106                        var link = '';
    112107
    … …  
    129124                        }
    130125
    131                         return decodeURI( link );
     126                        return checkUrl( decodeURI( link ) );
    132127                }
    133128
    … …  
    135130                 * Gets the source page's site name, based on passed meta data.
    136131                 *
    137                  * @param data object Usually WpPressThis_App.data
    138132                 * @returns string Discovered site name, or empty
    139133                 */
    140                 function getSourceSiteName( data ) {
    141                         if ( ! data || data.length ) {
    142                                 return '';
    143                         }
    144 
    145                         var name='';
     134                function getSourceSiteName() {
     135                        var name = '';
    146136
    147137                        if ( data._meta ) {
    … …  
    153143                        }
    154144
    155                         return name.replace( /\\/g, '' );
     145                        return sanitizeText( name );
    156146                }
    157147
    … …  
    159149                 * Gets the source page's title, based on passed title and meta data.
    160150                 *
    161                  * @param data object Usually WpPressThis_App.data
    162151                 * @returns string Discovered page title, or empty
    163152                 */
    164                 function getSuggestedTitle( data ) {
    165                         if ( ! data || data.length ) {
    166                                 return __( 'newPost' );
    167                         }
    168 
     153                function getSuggestedTitle() {
    169154                        var title = '';
    170155
    … …  
    173158                        }
    174159
    175                         if ( ! title.length && data._meta ) {
     160                        if ( ! title && data._meta ) {
    176161                                if ( data._meta['twitter:title'] && data._meta['twitter:title'].length ) {
    177162                                        title = data._meta['twitter:title'];
    … …  
    183168                        }
    184169
    185                         if ( ! title.length ) {
     170                        if ( ! title ) {
    186171                                title = __( 'newPost' );
    187172                                hasEmptyTitleStr = true;
    188173                        }
    189174
    190                         return title.replace( /\\/g, '' );
     175                        return sanitizeText( title );
    191176                }
    192177
    … …  
    195180                 * Features a blockquoted excerpt, as well as content attribution, if any.
    196181                 *
    197                  * @param data object Usually WpPressThis_App.data
    198182                 * @returns string Discovered content, or empty
    199183                 */
    200                 function getSuggestedContent( data ) {
    201                         if ( ! data || data.length ) {
    202                                 return '';
    203                         }
    204 
    205                         var content   = '',
    206                                 title     = getSuggestedTitle( data ),
    207                                 url       = getCanonicalLink( data ),
    208                                 siteName  = getSourceSiteName( data );
     184                function getSuggestedContent() {
     185                        var content  = '',
     186                                text     = '',
     187                                title    = getSuggestedTitle(),
     188                                url      = getCanonicalLink(),
     189                                siteName = getSourceSiteName();
    209190
    210191                        if ( data.s && data.s.length ) {
    211                                 content = data.s;
     192                                text = data.s;
    212193                        } else if ( data._meta ) {
    213194                                if ( data._meta['twitter:description'] && data._meta['twitter:description'].length ) {
    214                                         content = data._meta['twitter:description'];
     195                                        text = data._meta['twitter:description'];
    215196                                } else if ( data._meta['og:description'] && data._meta['og:description'].length ) {
    216                                         content = data._meta['og:description'];
     197                                        text = data._meta['og:description'];
    217198                                } else if ( data._meta.description && data._meta.description.length ) {
    218                                         content = data._meta.description;
    219                                 }
    220                         }
    221 
    222                         // Wrap suggested content in blockquote tag, if we have any.
    223                         content = ( content.length ? '<blockquote class="press-this-suggested-content">' + sanitizeText( content ) + '</blockquote>' : '' );
     199                                        text = data._meta.description;
     200                                }
     201                        }
     202
     203                        if ( text ) {
     204                                text = sanitizeText( text );
     205                                // Wrap suggested content in blockquote tag.
     206                                content = '<blockquote class="press-this-suggested-content">' + text + '</blockquote>';
     207                        }
    224208
    225209                        // Add a source attribution if there is one available.
    226                         if ( ( ( title.length && __( 'newPost' ) !== title ) || siteName.length ) && url.length ) {
    227                                 content += '<p class="press-this-suggested-source">';
    228                                 content += __( 'source' );
    229                                 content += ' <cite>';
    230                                 content += __( 'sourceLink').replace( '%1$s', encodeURI( url ) ).replace( '%2$s', sanitizeText( title || siteName ) );
    231                                 content += '</cite></p>';
    232                         }
    233 
    234                         if ( ! content ) {
    235                                 content = '';
    236                         }
    237 
    238                         return content.replace( /\\/g, '' );
     210                        if ( url && siteConfig.suggestedHTML && ( ( title && __( 'newPost' ) !== title ) || siteName ) ) {
     211                                content += siteConfig.suggestedHTML.replace( '%1$s', encodeURI( url ) ).replace( '%2$s', ( title || siteName ) );
     212                        }
     213
     214                        return content || '';
    239215                }
    240216
    … …  
    473449                                                hideSpinner();
    474450                                        } else if ( response.data.redirect ) {
    475                                                 if ( window.opener && siteConfig.redir_in_parent ) {
     451                                                if ( window.opener && siteConfig.redirInParent ) {
    476452                                                        try {
    477453                                                                window.opener.location.href = response.data.redirect;
    … …  
    515491
    516492                        if ( ! hasSetFocus ) {
    517                                 // Append to top of content on 1st media insert
    518                                 editor.setContent( newContent + editor.getContent() );
    519                         } else {
    520                                 // Or add where the cursor was last positioned in TinyMCE
    521                                 editor.execCommand( 'mceInsertContent', false, newContent );
    522                         }
    523 
     493                                editor.focus();
     494                        }
     495
     496                        editor.execCommand( 'mceInsertContent', false, newContent );
    524497                        hasSetFocus = true;
    525498                }
    … …  
    674647                                } );
    675648                        }
    676 
    677649                }
    678650
  • trunk/src/wp-includes/script-loader.php

    r31594 r31595  
    475475                $scripts->add( 'press-this', "/wp-admin/js/press-this$suffix.js", array( 'jquery', 'tags-box' ), false, 1 );
    476476                did_action( 'init' ) && $scripts->localize( 'press-this', 'pressThisL10n', array(
    477                         /**
    478                          * Filter the string displayed before the source attribution string in Press This.
    479                          *
    480                          * @since 4.2.0
    481                          *
    482                          * @param string $string Internationalized source string.
    483                          */
    484                         'source' => apply_filters( 'press_this_source_string', __( 'Source:' ) ),
    485 
    486                         /**
    487                          * Filter the HTML link format for the Press This source attribution, can control target, class, etc.
    488                          *
    489                          * @since 4.2.0
    490                          *
    491                          * @param string $link_format Link format, %1$s is link href, %2$s is link text.
    492                          */
    493                         'sourceLink' => apply_filters( 'press_this_source_link', '<a href="%1$s">%2$s</a>' ),
    494477                        'newPost' => __( 'Title' ),
    495478                        'unexpectedError' => __( 'Sorry, but an unexpected error occurred.' ),
Note: See TracChangeset for help on using the changeset viewer.