From 7b7dfb6b0db0e0cae955e4e13c29c917fa72ece0 Mon Sep 17 00:00:00 2001 From: Tim Date: Sat, 30 Mar 2019 18:22:13 -0400 Subject: [PATCH] parse html for theme sniffer specific messages fixes #107 --- assets/dev/scripts/theme-sniffer.js | 7 +++++-- src/sniffs/readme/class-license-uri.php | 8 ++++++- src/sniffs/readme/class-parser.php | 28 ------------------------- 3 files changed, 12 insertions(+), 31 deletions(-) diff --git a/assets/dev/scripts/theme-sniffer.js b/assets/dev/scripts/theme-sniffer.js index 59905d2..b79b59a 100644 --- a/assets/dev/scripts/theme-sniffer.js +++ b/assets/dev/scripts/theme-sniffer.js @@ -98,11 +98,14 @@ export default class ThemeSniffer { $singleItem.find( this.reportItemLine ).text( line ); $singleItem.find( this.reportItemType ).text( type ); - if ( message.includes( 'iframe' ) ) { + if ( value.source && ! value.source.includes( 'ThemeSniffer' ) ) { $singleItem.find( this.reportItemMessage ).text( message ); } else { - $singleItem.find( this.reportItemMessage ).html( message ); + let decoded = $( '

' ).html( message ).text(); + let msg = new DOMParser().parseFromString( decoded, 'text/html' ).body.childNodes; + $singleItem.find( this.reportItemMessage ).append( $( msg ) ); } + $singleItem.appendTo( $reportReportTable ); if ( source ) { diff --git a/src/sniffs/readme/class-license-uri.php b/src/sniffs/readme/class-license-uri.php index 8a29acc..28ed2d8 100644 --- a/src/sniffs/readme/class-license-uri.php +++ b/src/sniffs/readme/class-license-uri.php @@ -63,7 +63,7 @@ public function check() { 'message' => wp_kses( sprintf( /* translators: 1: the user provided License URI in readme.txt 2: the license comparing against in readme.txt 3: a list of suitable license URIs that could be used */ - __( 'The License URI provided: %1$s, is not a known URI reference for the license %2$s. All themes must meet this requirement!
These are recognized URIs based on the license provided:
%3$s', 'theme-sniffer' ), + __( 'The License URI provided: %1$s, is not a known URI reference for the license %2$s. These are recognized URIs for the license provided:
%3$s', 'theme-sniffer' ), $this->args->uri, $this->args->primary, implode( '
', $uris ) @@ -74,6 +74,12 @@ public function check() { ), ]; } + } else { + // Unable to determine License URI without valid License. + $this->results[] = [ + 'severity' => 'error', + 'message' => esc_html__( 'Unable to determine License URI with an invalid License supplied in readme.txt!', 'theme-sniffer' ), + ]; } } } diff --git a/src/sniffs/readme/class-parser.php b/src/sniffs/readme/class-parser.php index 1cd08e8..089fecb 100644 --- a/src/sniffs/readme/class-parser.php +++ b/src/sniffs/readme/class-parser.php @@ -360,35 +360,7 @@ protected function parse_readme( $file ) { } if ( ! empty( $section_name ) ) { - $this->sections[ $section_name ] .= trim( $current ); - - // Check for resources - if ( stripos( $section_name, 'resources' ) !== false ) { - - // Split resources into array. - $resources = preg_split( "/\r\n|\n|\r/", $current ); - - // Extract each resource's params. - foreach ( $resources as $resource ) { - if ( ! empty( $resource ) ) { - $res = strstr( $resource, ',', true ); - $resource = str_replace( $res, '', $resource ); - $license = strrchr( $resource, ',' ); - $resource = str_replace( $license, '', $resource ); - $this->resources[ trim( $res, "*, \t\n" ) ] = [ - 'license' => trim( $license, ", \t\n" ), - 'attribute' => trim( $resource, ", \t\n" ), - ]; - } - } - - // Pass in primary license to validate against each resource license. - $this->resources['primary_license'] = $license; - - // Cleanup. - unset( $this->sections['resources'] ); - } } // Filter out any empty sections.