Changeset 900447
- Timestamp:
- 04/22/2014 08:18:36 PM (12 years ago)
- Location:
- vip-scanner/trunk
- Files:
-
- 6 added
- 3 deleted
- 16 edited
-
.gitignore (added)
-
.travis.yml (added)
-
assets (deleted)
-
css/vip-scanner.css (modified) (1 diff)
-
js/vip-scanner-async.js (added)
-
readme.md (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
-
vip-scanner-wpcom (deleted)
-
vip-scanner-wpcom.php (deleted)
-
vip-scanner.php (modified) (7 diffs)
-
vip-scanner/analyzers/CustomResourceAnalyzer.php (modified) (10 diffs)
-
vip-scanner/analyzers/PHPAnalyzer.php (modified) (4 diffs)
-
vip-scanner/checks/VCMergeConflictCheck.php (modified) (1 diff)
-
vip-scanner/checks/VIPRestrictedPatternsCheck.php (modified) (1 diff)
-
vip-scanner/class-analyzed-php-file.php (modified) (2 diffs)
-
vip-scanner/class-analyzer-renderer.php (modified) (4 diffs)
-
vip-scanner/class-async-directory-scanner.php (added)
-
vip-scanner/class-base-check.php (modified) (1 diff)
-
vip-scanner/class-base-scanner.php (modified) (5 diffs)
-
vip-scanner/class-function-renderer.php (modified) (1 diff)
-
vip-scanner/class-theme-scanner.php (modified) (1 diff)
-
vip-scanner/class-token-parser.php (added)
-
vip-scanner/class-wp-cli.php (modified) (2 diffs)
-
vip-scanner/vip-scanner-async.php (added)
-
vip-scanner/vip-scanner.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
vip-scanner/trunk/css/vip-scanner.css
r794835 r900447 125 125 font-weight: 600; 126 126 } 127 128 /* Analyzer */ 129 #analysis ul ul { 130 margin-left: 30px; 131 } -
vip-scanner/trunk/readme.md
r883100 r900447 30 30 Changelog 31 31 --------- 32 33 __0.7__ 34 35 * Modified analyzer to use PHP tokens rather than regular expressions 36 * New checks, including white/blacklist checking for file types and names 37 * Added basic async scanning as an admin bar node 38 * WP CLI scan commands now support paths in addition to theme slugs 39 * WP CLI `scan_type` argument is now optional 32 40 33 41 __0.6__ -
vip-scanner/trunk/readme.txt
r883100 r900447 4 4 Requires at least: 3.4 5 5 Tested up to: 3.9 6 Stable tag: 0. 66 Stable tag: 0.7 7 7 8 8 Scan all sorts of themes and files and things. … … 35 35 36 36 == Changelog == 37 38 = 0.7 = 39 40 * Modified analyzer to use PHP tokens rather than regular expressions 41 * New checks, including white/blacklist checking for file types and names 42 * Added basic async scanning as an admin bar node 43 * WP CLI scan commands now support paths in addition to theme slugs 44 * WP CLI `scan_type` argument is now optional 37 45 38 46 = 0.6 = -
vip-scanner/trunk/vip-scanner.php
r883100 r900447 5 5 Description: Easy to use UI for the VIP Scanner. 6 6 Author: Automattic (Original code by Pross, Otto42, and Thorsten Ott) 7 Version: 0. 67 Version: 0.7 8 8 9 9 License: GPLv2 … … 15 15 16 16 class VIP_Scanner_UI { 17 const key = 'vip-scanner'; 17 const key = 'vip-scanner'; 18 private $version = null; 18 19 19 20 public $default_review; … … 73 74 } 74 75 return self::$instance; 76 } 77 78 function get_version() { 79 if ( is_null( $this->version ) ) { 80 // Load plugin version from plugin data 81 $plugin_data = get_plugin_data( __FILE__ ); 82 $this->version = $plugin_data['Version']; 83 } 84 85 return $this->version; 75 86 } 76 87 … … 135 146 $scanner = VIP_Scanner::get_instance()->run_theme_review( $theme, $review ); 136 147 137 $transient_key = 'vip_scanner_' . md5( $theme . $review );148 $transient_key = 'vip_scanner_' . $this->get_version() . '_' . md5( $theme . $review ); 138 149 if ( $scanner !== get_transient( $transient_key ) ) 139 150 @set_transient( $transient_key, $scanner ); … … 337 348 338 349 $results .= $title = apply_filters( 'vip_scanner_export_title', "$theme - $review", $review ) . PHP_EOL; 339 $results .= str_repeat( '=', strlen( $title ) ) . PHP_EOL . PHP_EOL; 350 $title_len = strlen( $title ); 351 $results .= str_repeat( '=', $title_len ) . PHP_EOL; 352 353 $version_str = ' ' . sprintf( __( 'VIP Scanner %s', 'theme-check' ), $this->get_version() ) . ' '; 354 $side_spacing = ( $title_len - strlen( $version_str ) ) / 2.; 355 $results .= str_repeat( '=', ceil( $side_spacing ) ) . $version_str . str_repeat( '=', floor( $side_spacing ) ) . PHP_EOL; 356 $results .= str_repeat( '=', $title_len ) . PHP_EOL . PHP_EOL; 340 357 341 358 $form_results = apply_filters( 'vip_scanner_form_results', '', $review ); … … 429 446 430 447 function get_cached_theme_review( $theme, $review ) { 431 $transient_key = 'vip_scanner_' . md5( $theme . $review );448 $transient_key = 'vip_scanner_' . $this->get_version() . '_' . md5( $theme . $review ); 432 449 433 450 if ( false === $scanner = get_transient( $transient_key ) ) { … … 496 513 // redirect with error message 497 514 if ( !$zip ) 498 break;515 return; 499 516 500 517 $mail = wp_mail( -
vip-scanner/trunk/vip-scanner/analyzers/CustomResourceAnalyzer.php
r883100 r900447 12 12 protected $resource_types = array( 13 13 array( 14 'func_name' => 'apply_filters',14 'func_name' => array( 'apply_filters' ), 15 15 'plural' => 'filters', 16 16 'singular' => 'filter', … … 18 18 19 19 array( 20 'func_name' => 'do_action',20 'func_name' => array( 'do_action' ), 21 21 'plural' => 'actions', 22 22 'singular' => 'action', … … 24 24 25 25 array( 26 'func_name' => '->add_cap',26 'func_name' => array( '->add_cap' ), 27 27 'plural' => 'capabilities', 28 28 'singular' => 'capability', … … 31 31 32 32 array( 33 'func_name' => 'add_role',33 'func_name' => array( 'add_role' ), 34 34 'plural' => 'roles', 35 35 'singular' => 'role', … … 37 37 38 38 array( 39 'func_name' => 'add_shortcode',39 'func_name' => array( 'add_shortcode' ), 40 40 'plural' => 'shortcodes', 41 41 'singular' => 'shortcode', … … 43 43 44 44 array( 45 'func_name' => 'register_post_type',45 'func_name' => array( 'register_post_type' ), 46 46 'plural' => 'custom post types', 47 47 'singular' => 'custom post type', … … 49 49 50 50 array( 51 'func_name' => 'register_taxonomy',51 'func_name' => array( 'register_taxonomy' ), 52 52 'plural' => 'taxonomies', 53 53 'singular' => 'taxonomy', … … 89 89 if ( !array_key_exists( $filepath, $file_metas ) ) { 90 90 // This is not a file we can handle 91 var_dump( "Not scanning file: {$file->get_filepath()}: " . $file_metas[$filepath]->get_file()->get_filepath());92 91 continue; 93 92 } … … 108 107 */ 109 108 public function scan_file( $file, $file_renderer ) { 110 $f ile_functions = $file->get_code_elements( 'functions' );111 109 $function_calls = $file->get_code_elements( 'function_calls' ); 110 112 111 foreach ( $this->resource_types as $resource ) { 113 $regexes = array(); 114 115 if ( is_array( $resource['func_name'] ) ) { 116 foreach ( $resource['func_name'] as $func_name ) { 117 $regexes[] = "/{$func_name}\s*\(\s*(?<name>([a-zA-Z0-9_'\".$-]|\s*)+)/ix"; 118 } 119 } else { 120 $regexes[] = "/{$resource['func_name']}\s*\(\s*(?<name>([a-zA-Z0-9_'\".$-]|\s*)+)/ix"; 121 } 122 123 if ( isset( $resource['regexes'] ) ) { 124 $regexes = array_merge( $regexes, $resource['regexes'] ); 125 } 126 127 foreach ( $regexes as $regex ) { 128 foreach ( $file_functions as $functions ) { 129 // Scan the functions in the file 130 $phpelements = $file->get_code_elements( 'php' ); 131 $code_blocks_to_scan = array_merge( $functions, $phpelements[''] ); 112 foreach ( $resource['func_name'] as $function_name ) { 113 foreach ( $function_calls as $call_path => $functions ) { 114 // check and see if this function was called 115 if ( array_key_exists( $function_name, $functions ) ) { 116 if ( isset( $functions[$function_name]['args'] ) ) { 117 $calls = array( $functions[$function_name] ); 118 } else { 119 $calls = $functions[$function_name]; 120 } 132 121 133 foreach ( $code_blocks_to_scan as $code_block ) { 134 preg_match_all( $regex, $code_block['contents'], $matches, PREG_OFFSET_CAPTURE ); 135 foreach ( $matches['name'] as $match ) { 136 $match = str_replace( $this->remove_chars, '', $match ); 137 $child_renderer = $this->create_child_renderer_from_match( $match, $code_block['contents'], $resource, $file, $code_block['line'] ); 122 foreach( $calls as $call ) { 123 $child_renderer = new ResourceRenderer( str_replace( $this->remove_chars, '', $call['args'][0] ) ); 124 $child_renderer->set_resource_type( $resource['singular'], $resource['plural'] ); 125 $child_renderer->add_attribute( 'file', $file->get_filename() ); 126 $child_renderer->add_attribute( 'args', $call['args'] ); 127 138 128 $file_renderer->add_child( $child_renderer ); 139 129 $this->renderers[$resource['plural']]->add_child( $child_renderer ); … … 144 134 } 145 135 } 146 147 public function create_child_renderer_from_match( $match, $contents, $resource, $file, $line_offset = 0 ) {148 $child_renderer = new ResourceRenderer( $match[0] );149 $child_renderer->set_resource_type( $resource['singular'], $resource['plural'] );150 $child_renderer->add_attribute( 'line', $file->compute_line_number( $contents, $match[1], $line_offset ) );151 $child_renderer->add_attribute( 'file', $file->get_filename() );152 return $child_renderer;153 }154 136 } -
vip-scanner/trunk/vip-scanner/analyzers/PHPAnalyzer.php
r883100 r900447 8 8 'functions' => 'FunctionRenderer', 9 9 ); 10 10 11 protected $check_hierarchy = array( 12 'php' => array( 13 'namespaces' => array( 14 'classes' => array( 15 'functions' => array(), 16 'members' => array(), 17 ), 18 ), 19 20 'classes' => array( 21 'functions' => array(), 22 'members' => array(), 23 ), 24 25 'functions' => array(), 26 'members' => array(), 27 ), 28 ); 29 11 30 function __construct() { 12 31 $this->renderers = array( … … 31 50 continue; 32 51 } 33 52 34 53 $file_meta = new FileRenderer( $file ); 35 54 $this->add_renderers( $file, $file_meta ); … … 48 67 public function add_renderers( $file, &$renderer, $path = '', $hierarchy = null ) { 49 68 if ( is_null( $hierarchy ) ) { 50 $hierarchy = $ file->get_check_hierarchy();69 $hierarchy = $this->check_hierarchy; 51 70 } 52 71 53 72 foreach ( $hierarchy as $level => $hierarchy_children ) { 54 73 $code_elements = $file->get_code_elements( $level, $path ); 55 56 74 if ( empty( $code_elements ) ) { 57 75 $this->add_renderers( $file, $renderer, $path, $hierarchy_children ); … … 59 77 } else { 60 78 foreach ( $code_elements as $child_path => $child_element ) { 61 62 79 if ( array_key_exists( $level, $this->hierarchy_metas ) ) { 63 80 $child_meta = new $this->hierarchy_metas[$level]( $child_path ); -
vip-scanner/trunk/vip-scanner/checks/VCMergeConflictCheck.php
r883100 r900447 3 3 class VCMergeConflictCheck extends BaseCheck { 4 4 protected $checks = array( 5 // Check for the signs of a merge conflict IE: 6 // <<<<<< YOUR_SIDE 7 // /*some stuff*/ 8 // ====== 9 // /*some other stuff*/ 10 // >>>>>> THEIR_SIDE 5 11 'merge-conflict' => '/(<{4,}\W+(?<your_side>\w+)[\s\S]*>{4,}\W+(?<their_side>\w+))/im', 12 13 // Matches the filename of a conflict file created by SVN. Eg: test.php.mine, test.php.r10, test.php.r100 6 14 'conflict_file' => '/mine|r[0-9]+/im' 7 15 ); -
vip-scanner/trunk/vip-scanner/checks/VIPRestrictedPatternsCheck.php
r883100 r900447 8 8 $checks = array( 9 9 "/(\\\$isIE)+/msiU" => array( "level" => "Warning", "note" => 'Using $isIE conflicts with full page caching' ), 10 "/WordPress VIP/msiU" => array( "level" => "Warning", "note" => 'Please use "WordPress.com VIP" rather than "WordPress VIP"' ), 10 11 "/(kses)+/msiU" => array ( "level" => "Warning", "note" => "Working with kses" ), 11 12 "/(\\\$wpdb->|mysql_)+.+(ALTER)+\s+/msiU" => array( "level" => "Blocker", "note" => "Possible database table alteration" ), -
vip-scanner/trunk/vip-scanner/class-analyzed-php-file.php
r883100 r900447 5 5 protected $filecontents = ''; 6 6 protected $processed_file_contents = ''; 7 8 protected $hierarchy_elements = array(9 'namespaces' => array(),10 'classes' => array(),11 'functions' => array(),12 'php' => array(),13 );14 15 protected $comments_regex = <<<EOT16 (\/\*(?:(?!\*\/)[\s\S])*\*\/) # match a multiline comment17 EOT18 ;19 7 20 protected $single_comment_regex = <<<EOT21 (\/\/.*$) # match a single line comment22 EOT;23 24 protected $heredox_regex = <<<EOT25 <<<(?<herestart>\S+)((?!\1)[\s\S])*\3; # match a heredoc26 EOT27 ;28 29 protected $strip_inline_php_regex = '\?>((?!<\?php)[\s\S])*<\?php';30 31 protected $hierarchy_regexes = array(32 'php' => array( 'regex' => <<<EOT33 ( # start of bracket 134 <\?php # php opening tag35 (?<contents>((?!\?>)[\s\S])*) # match anything except a php closing tag36 (\?>)? # match a closing tag37 ) # end of bracket 138 EOT39 ),40 41 'namespaces' => array( 'regex' => <<<EOT42 namespace\s+(?<name>(\\\\?\w+)+); # Match the name of the namespace43 (?<contents>((?!namespace)[\s\S])*) # match the contents of the namespace44 EOT45 , ),46 47 'classes' => array( 'regex' => <<<EOT48 ((?<abstract>abstract)\s+)? # optionally match an abstract class49 class\s+(?<name>\w+)\s+ # match the classname50 (extends\s+(?<parentclass>\w+)\s*)? # optionally match a parentclass51 (?<contents>52 ( # start of bracket 753 { # match an opening curly bracket54 (?:55 [^{}]++ # one or more non curly brackets56 |57 (?7) # recurse to bracket 758 )*59 } # match a closing curly bracket60 ) # end of bracket 761 )62 EOT63 , ),64 65 'functions' => array( 'regex' => <<<EOT66 \s*( # match function modifiers (visibility, static, abstract)67 \s*(?<visibility>private|protected|public)\s+68 |69 \s*(?<static>static)\s+70 |71 \s*(?<abstract>abstract)\s+72 ){0,3}73 \s*function\s+(?<name>[a-zA-Z0-9_]+\s*) # match the function definition & name74 \((?<args>(\s|\w|[$,_='"])+)?\)\s* # match the function arguments75 (?<contents>76 (?(abstract);| # match either the semicolon of an abstract function or a closure77 ( # start of bracket 178 { # match an opening curly bracket79 (?:80 [^{}]++ # one or more non curly brackets81 |82 (?8) # recurse to bracket 183 )*84 } # match a closing curly bracket85 ) # end of bracket 186 )87 )88 EOT89 , ),90 91 'members' => array( 'regex' => '', ),92 );93 94 protected $check_hierarchy = array(95 'php' => array(96 'namespaces' => array(97 'classes' => array(98 'functions' => array(),99 'members' => array(),100 ),101 ),102 103 'classes' => array(104 'functions' => array(),105 'members' => array(),106 ),107 108 'functions' => array(),109 'members' => array(),110 ),111 );112 113 8 /** 114 9 * Analyzes this file. … … 123 18 return; 124 19 } 125 126 // Strip strings and comments from the file. Preserve line numbers 127 $stripped = $this->strip_strings_and_comments( $this->filecontents ); 128 129 // Do the php check hierarchy 130 $this->processed_file_contents = $this->do_check_hierarchy( '', $this->check_hierarchy, $stripped, 0 ); 20 21 // Parse the tokens 22 require_once( 'class-token-parser.php' ); 23 $parser = new TokenParser(); 24 $items = $parser->parse_contents( $this->filecontents ); 25 26 // Parse the items 27 $this->hierarchy_elements = array(); 28 $this->parse_token_results( $items ); 131 29 } 132 30 133 31 protected function get_strings_and_comments_regexes() { 134 return array( 135 $this->single_comment_regex, 136 $this->comments_regex, 137 $this->heredox_regex, 138 $this->strip_inline_php_regex, 139 ); 32 return array(); 140 33 } 141 34 35 private function parse_token_results( $items ) { 36 foreach ( $items as $item ) { 37 $type = ''; 38 switch ( $item['type'] ) { 39 case 'class': 40 $type = 'classes'; 41 break; 42 43 case 'const': 44 $type = 'constants'; 45 break; 46 47 default: 48 $type = $item['type'] . 's'; 49 } 50 51 if ( !isset( $this->hierarchy_elements[$type] ) ) { 52 $this->hierarchy_elements[$type] = array(); 53 } 54 55 if ( !isset( $this->hierarchy_elements[$type][$item['path']] ) ) { 56 $this->hierarchy_elements[$type][$item['path']] = array(); 57 } 58 59 // There's a chance for duplicate items that are significant. Ie: two calls to one function within a block of code. 60 if ( isset( $this->hierarchy_elements[$type][$item['path']][$item['name']] ) ) { 61 if ( isset( $this->hierarchy_elements[$type][$item['path']][$item['name']][0] ) ) { 62 $this->hierarchy_elements[$type][$item['path']][$item['name']][] = $item; 63 } else { 64 $this->hierarchy_elements[$type][$item['path']][$item['name']] = array( 65 $this->hierarchy_elements[$type][$item['path']][$item['name']], 66 $item, 67 ); 68 } 69 } else { 70 $this->hierarchy_elements[$type][$item['path']][$item['name']] = $item; 71 } 72 73 if ( !empty( $item['children'] ) ) { 74 $this->parse_token_results( $item['children'] ); 75 } 76 } 77 } 142 78 } -
vip-scanner/trunk/vip-scanner/class-analyzer-renderer.php
r883100 r900447 186 186 foreach ( $this->attributes as $slug => $attribute ) { 187 187 if ( ! in_array( $slug, $skip_attributes ) && ! empty( $attribute ) ) { 188 $output .= sprintf( '<li><strong>%s</strong>: %s</li>', esc_html( $slug ), esc_html( $attribute ));188 $output .= $this->display_html_attribute( $slug, $attribute, $args ); 189 189 } 190 190 } … … 193 193 foreach ( $this->attributes as $slug => $attribute ) { 194 194 if ( ! in_array( $slug, $skip_attributes ) && ! empty( $attribute ) ) { 195 $output .= sprintf( "%s> %s: %s\n", str_repeat( $this->spacing_char, $args['level'] ), $slug, $attribute ); 195 if ( is_string( $attribute ) ) { 196 $output .= sprintf( "%s> %s: %s\n", str_repeat( $this->spacing_char, $args['level'] ), $slug, $attribute ); 197 } elseif ( is_numeric( $attribute ) ) { 198 $output .= sprintf( "%s> %s: %s\n", str_repeat( $this->spacing_char, $args['level'] ), $slug, number_format( $attribute ) ); 199 } elseif ( is_array( $attribute ) ) { 200 $output .= sprintf( "%s> %s: %s\n", str_repeat( $this->spacing_char, $args['level'] ), $slug, implode( ', ', $attribute ) ); 201 } 196 202 } 197 203 } … … 199 205 } 200 206 return $output; 207 } 208 209 function display_html_attribute( $slug, $attribute, $args ) { 210 $fstring = '<li><strong>%s</strong>: %s</li>'; 211 if ( is_string( $attribute ) ) { 212 if ( substr_count( $attribute, "\n" ) ) { 213 return sprintf( $fstring, esc_html( $slug ), '<pre>' . esc_html( $attribute ) . '</pre>' ); 214 } else { 215 return sprintf( $fstring, esc_html( $slug ), esc_html( $attribute ) ); 216 } 217 } elseif ( is_numeric( $attribute ) ) { 218 return sprintf( $fstring, esc_html( $slug ), number_format( $attribute ) ); 219 } elseif ( is_bool( $attribute ) ) { 220 return sprintf( $fstring, esc_html( $slug ), $attribute ? __( 'true', 'vip-scanner' ) : __( 'false', 'vip-scanner' ) ); 221 } elseif ( is_array( $attribute ) ) { 222 $output = ''; 223 foreach ( $attribute as $key => $value ) { 224 $output .= $this->display_html_attribute( $key, $value, $args ); 225 } 226 return sprintf( $fstring, esc_html( $slug ), "<ul>$output</ul>" ); 227 } 201 228 } 202 229 … … 421 448 */ 422 449 protected function skip_attributes() { 423 return array( 'contents', 'name' );450 return array( 'contents', 'name', 'children' ); 424 451 } 425 452 -
vip-scanner/trunk/vip-scanner/class-base-check.php
r883100 r900447 214 214 $scanner = $this->get_scanner(); 215 215 216 if ( ! $scanner instanceof ThemeScanner)216 if ( !is_subclass_of( $scanner, 'DirectoryScanner' ) ) 217 217 return null; 218 218 -
vip-scanner/trunk/vip-scanner/class-base-scanner.php
r883100 r900447 13 13 public $renderers = array(); 14 14 public $stats = array(); 15 //recognized extensions 15 16 public $known_extensions = array( 16 17 'php' => array( 'php', 'php5', 'inc' ), 17 18 'css' => 'css', 18 19 'js' => 'js', 20 'gif' => 'gif', 21 'jpg' => array( 'jpg', 'jpeg' ), 22 'png' => 'png', 23 'svg' => 'svg', 24 'txt' => 'txt', 25 ); 26 //these extensions are not allowed and will produce blocking errors 27 public $known_bad_extensions = array( 28 'gz', 29 'zip', 30 'tar', 31 'orig', 32 'rej', 33 'bak', 34 'log', 35 'git', 36 'asp', 37 'py', 38 'cfm', 39 'htaccess', 40 'swf' 41 ); 42 //these patterns are not allowed anywhere in any filename and will produce blocking errors 43 public $known_bad_file_patterns = array( 44 '\.php\..*', 45 '^\.DS_Store$', 46 '^Thumbs.db$', 47 '^WS_FTP.*', 19 48 ); 20 49 … … 64 93 } 65 94 95 public function is_bad_file_type( $filename ) { 96 return in_array( $this->get_file_type( $filename ), $this->known_bad_extensions ); 97 } 98 99 public function has_bad_file_pattern( $filename ) { 100 foreach ( $this->known_bad_file_patterns as $pattern ) { 101 $pattern = '/' . $pattern . '/i'; 102 if ( 1 === preg_match( $pattern, $filename ) ) { 103 return true; 104 } 105 } 106 } 107 108 public function check_filename( $filename, $type ) { 109 if ( $this->has_bad_file_pattern( basename( $filename ) ) ) { 110 $this->add_error( 111 'badfile-error', 112 'bad file in theme', 113 'Blocker', 114 basename( $filename ) 115 ); 116 return false; 117 } 118 119 if ( $this->is_bad_file_type( $filename ) ) { 120 $this->add_error( 121 'filetype-error', 122 'File type ' . $type . ' not permitted', 123 'Blocker', 124 basename( $filename ) 125 ); 126 return false; 127 } 128 129 if ( !$this->is_known_file_type( $filename ) ) { 130 $this->add_error( 131 'filetype-error', 132 'File type ' . $type . ' detected', 133 'Warning', 134 basename( $filename ) 135 ); 136 return false; 137 } 138 139 return true; 140 } 141 66 142 public function get_file_count() { 67 143 $count = 0; … … 81 157 $file_type = $this->get_file_type( $filename ); 82 158 83 // If we only want to scan files of a certain type 84 //if ( ! $this->is_known_file_type( $filename ) ) 85 // continue; 159 $this->check_filename( $filename, $file_type); 86 160 87 161 if( !isset( $grouped_files[$file_type] ) ) … … 112 186 $this->run_scanners( 'analyzers' ); 113 187 } 114 188 115 189 return $pass; 116 190 } … … 137 211 $check_file = ''; 138 212 } 213 214 if ( ! apply_filters( 'vip_scanner_run_check', true, $check ) ) { 215 $this->add_error( 'skipped-check', sprintf( __( 'The "%s" check was skipped.', 'vip-scanner' ), $check ), BaseScanner::LEVEL_WARNING ); 216 continue; 217 } 218 139 219 $check_exists = $this->load_check( $check, $check_file, $type ); 140 220 -
vip-scanner/trunk/vip-scanner/class-function-renderer.php
r883100 r900447 22 22 23 23 $args = $this->get_attribute( 'args' ); 24 $header_items[] = sprintf( 25 'function %s%s', 26 $this->stylize_text( esc_html( $this->name() ), array( 'bold' => true, 'classes' => array( 'renderer-function-name' ) ) ), 27 $args === ';' ? ';' : '(' . esc_html( $args ) . ')' 28 ); 24 if ( is_array( $args ) ) { 25 $header_items[] = sprintf( 26 'function %s%s', 27 $this->stylize_text( esc_html( $this->name() ), array( 'bold' => true, 'classes' => array( 'renderer-function-name' ) ) ), 28 $args === ';' ? ';' : '(' . esc_html( implode( ', ', $args ) ) . ')' 29 ); 30 } else { 31 $header_items[] = sprintf( 32 'function %s%s', 33 $this->stylize_text( esc_html( $this->name() ), array( 'bold' => true, 'classes' => array( 'renderer-function-name' ) ) ), 34 $args === ';' ? ';' : '(' . esc_html( $args ) . ')' 35 ); 36 } 29 37 30 38 return implode( ' ', $header_items ); -
vip-scanner/trunk/vip-scanner/class-theme-scanner.php
r883100 r900447 7 7 return $this->add_error( 'wp-load', sprintf( '%s requires WordPress to be loaded.', get_class( $this ) ), 'blocker' ); 8 8 9 // Get Theme Path 10 $path = sprintf( '%s/%s', get_theme_root(), $theme ); 9 // decide whether to interpret theme as a path by checking if the path exists 10 $potential_file_path = realpath( $theme ); 11 if ( $potential_file_path ) { 12 $path = $potential_file_path; 13 } else { 14 $path = sprintf( '%s/%s', get_theme_root(), $theme ); 15 } 11 16 12 17 // Call Parent Constructor -
vip-scanner/trunk/vip-scanner/class-wp-cli.php
r883100 r900447 15 15 * 16 16 * @subcommand scan-theme 17 * @synopsis --theme=<theme-name> --scan_type=<scan-type>[--format=<format>] [--summary=<summary>]17 * @synopsis --theme=<theme-name> [--scan_type=<scan-type>] [--format=<format>] [--summary=<summary>] 18 18 */ 19 19 public function scan_theme( $args, $assoc_args ) { … … 77 77 $lines = array(); 78 78 79 // Not all errors have lines 80 if ( isset( $error['lines'] ) ) 81 $lines = $error['lines']; 79 // Not all errors have lines -- assign a null line if we lack lines entirely 80 $lines = ( isset( $error['lines'] ) ) ? $error['lines'] : array( '' ); 82 81 83 82 // In JSON output, group the lines together -
vip-scanner/trunk/vip-scanner/vip-scanner.php
r883100 r900447 28 28 require_once( VIP_SCANNER_DIR . '/class-function-renderer.php' ); 29 29 require_once( VIP_SCANNER_DIR . '/class-base-analyzer.php' ); 30 31 if ( is_admin() ) { 32 require_once( VIP_SCANNER_DIR . '/class-async-directory-scanner.php' ); 33 require_once( VIP_SCANNER_DIR . '/vip-scanner-async.php' ); 34 } 30 35 31 36 class VIP_Scanner { … … 63 68 return false; 64 69 70 do_action( 'vip_scanner_pre_theme_review', $theme, $review_type ); 71 65 72 $scanner = new ThemeScanner( $theme, $review ); 66 73 $scanner->scan( $scanners ); 74 75 do_action( 'vip_scanner_post_theme_review', $theme, $review_type, $scanner ); 67 76 return $scanner; 68 77 }
Note: See TracChangeset
for help on using the changeset viewer.