Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
parse html for theme sniffer specific messages fixes #107
Browse files Browse the repository at this point in the history
  • Loading branch information
timelsass committed Mar 30, 2019
1 parent f8662e8 commit 7b7dfb6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 31 deletions.
7 changes: 5 additions & 2 deletions assets/dev/scripts/theme-sniffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $( '<p />' ).html( message ).text();
let msg = new DOMParser().parseFromString( decoded, 'text/html' ).body.childNodes;
$singleItem.find( this.reportItemMessage ).append( $( msg ) );
}

$singleItem.appendTo( $reportReportTable );

if ( source ) {
Expand Down
8 changes: 7 additions & 1 deletion src/sniffs/readme/class-license-uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -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!<br/>These are recognized URIs based on the license provided:<br/>%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:<br/>%3$s', 'theme-sniffer' ),
$this->args->uri,
$this->args->primary,
implode( '<br/>', $uris )
Expand All @@ -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' ),
];
}
}
}
28 changes: 0 additions & 28 deletions src/sniffs/readme/class-parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 7b7dfb6

Please sign in to comment.