Making WordPress.org

Changeset 3360


Ignore:
Timestamp:
06/14/2016 12:30:54 PM (9 years ago)
Author:
dd32
Message:

Plugin Directory: Better parsing for the short_description. We don't want to allow extra HTML/markdown in the short_description.

See #1724

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-readme-parser.php

    r3358 r3360  
    210210        }
    211211
    212         // Sanitize and trim the short_description to match requirements
    213         $this->short_description = $this->sanitize_text( $this->short_description );
    214         $this->short_description = $this->trim_length( $this->short_description, 150 );
    215 
    216212        // Parse out the Upgrade Notice section into it's own data
    217213        if ( isset( $this->sections['upgrade_notice'] ) ) {
     
    243239
    244240        // Markdownify!
    245         $this->short_description = $this->parse_markdown( $this->short_description );
    246241        $this->sections          = array_map( array( $this, 'parse_markdown' ), $this->sections );
    247242        $this->upgrade_notice    = array_map( array( $this, 'parse_markdown' ), $this->upgrade_notice );
     243
     244        // Sanitize and trim the short_description to match requirements
     245        $this->short_description = $this->sanitize_text( $this->short_description );
     246        $this->short_description = $this->trim_length( $this->short_description, 150 );
     247        $this->short_description = $this->parse_markdown( $this->short_description );
     248        $this->short_description = wp_strip_all_tags( $this->short_description );
    248249
    249250        if ( isset( $this->sections['screenshots'] ) ) {
     
    280281
    281282    protected function trim_length( $desc, $length = 150 ) {
    282         if ( function_exists( 'mb_strlen' ) && function_exists( 'mb_substr' ) ) {
    283             if ( mb_strlen( $desc ) > $length ) {
    284                 $desc = mb_substr( $desc, 0, $length );
    285             }
    286         } else {
    287             if ( strlen( $desc ) > $length ) {
    288                 $desc = substr( $desc, 0, $length );
     283        if ( mb_strlen( $desc ) > $length ) {
     284            $desc = mb_substr( $desc, 0, $length ) . ' …';
     285
     286            // If not a full sentence, and one ends within 20% of the end, trim it to that.
     287            if ( '.' !== mb_substr( $desc, -1 ) && ( $pos = mb_strrpos( $desc, '.' ) ) > ( 0.8 * $length ) ) {
     288                $desc = mb_substr( $desc, 0, $pos + 1 );
    289289            }
    290290        }
Note: See TracChangeset for help on using the changeset viewer.