Plugin Directory

Changeset 900447


Ignore:
Timestamp:
04/22/2014 08:18:36 PM (12 years ago)
Author:
mobius5150
Message:

Tagging version 0.7 from GitHub and updating stable tag.

Location:
vip-scanner/trunk
Files:
6 added
3 deleted
16 edited

Legend:

Unmodified
Added
Removed
  • vip-scanner/trunk/css/vip-scanner.css

    r794835 r900447  
    125125    font-weight: 600;
    126126}
     127
     128/* Analyzer */
     129#analysis ul ul {
     130    margin-left: 30px;
     131}
  • vip-scanner/trunk/readme.md

    r883100 r900447  
    3030Changelog
    3131---------
     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
    3240
    3341__0.6__
  • vip-scanner/trunk/readme.txt

    r883100 r900447  
    44Requires at least: 3.4
    55Tested up to: 3.9
    6 Stable tag: 0.6
     6Stable tag: 0.7
    77
    88Scan all sorts of themes and files and things.
     
    3535
    3636== 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
    3745
    3846= 0.6 =
  • vip-scanner/trunk/vip-scanner.php

    r883100 r900447  
    55Description: Easy to use UI for the VIP Scanner.
    66Author: Automattic (Original code by Pross, Otto42, and Thorsten Ott)
    7 Version: 0.6
     7Version: 0.7
    88
    99License: GPLv2
     
    1515
    1616class VIP_Scanner_UI {
    17     const key = 'vip-scanner';
     17    const   key      = 'vip-scanner';
     18    private $version = null;
    1819
    1920    public $default_review;
     
    7374        }
    7475        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;
    7586    }
    7687
     
    135146        $scanner = VIP_Scanner::get_instance()->run_theme_review( $theme, $review );
    136147
    137         $transient_key = 'vip_scanner_' . md5( $theme . $review );
     148        $transient_key = 'vip_scanner_' . $this->get_version() . '_' . md5( $theme . $review );
    138149        if ( $scanner !== get_transient( $transient_key ) )
    139150            @set_transient( $transient_key, $scanner );
     
    337348
    338349        $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;
    340357
    341358        $form_results = apply_filters( 'vip_scanner_form_results', '', $review );
     
    429446
    430447    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 );
    432449
    433450        if ( false === $scanner = get_transient( $transient_key ) ) {
     
    496513            // redirect with error message
    497514            if ( !$zip )
    498                 break;
     515                return;
    499516
    500517            $mail = wp_mail(
  • vip-scanner/trunk/vip-scanner/analyzers/CustomResourceAnalyzer.php

    r883100 r900447  
    1212    protected $resource_types = array(
    1313        array(
    14             'func_name' => 'apply_filters',
     14            'func_name' => array( 'apply_filters' ),
    1515            'plural'    => 'filters',
    1616            'singular'  => 'filter',
     
    1818       
    1919        array(
    20             'func_name' => 'do_action',
     20            'func_name' => array( 'do_action' ),
    2121            'plural'    => 'actions',
    2222            'singular'  => 'action',
     
    2424       
    2525        array(
    26             'func_name' => '->add_cap',
     26            'func_name' => array( '->add_cap' ),
    2727            'plural'    => 'capabilities',
    2828            'singular'  => 'capability',
     
    3131       
    3232        array(
    33             'func_name' => 'add_role',
     33            'func_name' => array( 'add_role' ),
    3434            'plural'    => 'roles',
    3535            'singular'  => 'role',
     
    3737       
    3838        array(
    39             'func_name' => 'add_shortcode',
     39            'func_name' => array( 'add_shortcode' ),
    4040            'plural'    => 'shortcodes',
    4141            'singular'  => 'shortcode',
     
    4343       
    4444        array(
    45             'func_name' => 'register_post_type',
     45            'func_name' => array( 'register_post_type' ),
    4646            'plural'    => 'custom post types',
    4747            'singular'  => 'custom post type',
     
    4949       
    5050        array(
    51             'func_name' => 'register_taxonomy',
     51            'func_name' => array( 'register_taxonomy' ),
    5252            'plural'    => 'taxonomies',
    5353            'singular'  => 'taxonomy',
     
    8989            if ( !array_key_exists( $filepath, $file_metas ) ) {
    9090                // This is not a file we can handle
    91                 var_dump( "Not scanning file: {$file->get_filepath()}: " . $file_metas[$filepath]->get_file()->get_filepath());
    9291                continue;
    9392            }
     
    108107     */
    109108    public function scan_file( $file, $file_renderer ) {
    110         $file_functions = $file->get_code_elements( 'functions' );
    111        
     109        $function_calls = $file->get_code_elements( 'function_calls' );
     110
    112111        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                        }
    132121
    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
    138128                            $file_renderer->add_child( $child_renderer );
    139129                            $this->renderers[$resource['plural']]->add_child( $child_renderer );
     
    144134        }
    145135    }
    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     }
    154136}
  • vip-scanner/trunk/vip-scanner/analyzers/PHPAnalyzer.php

    r883100 r900447  
    88        'functions'  => 'FunctionRenderer',
    99    );
    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
    1130    function __construct() {
    1231        $this->renderers = array(
     
    3150                continue;
    3251            }
    33            
     52
    3453            $file_meta = new FileRenderer( $file );
    3554            $this->add_renderers( $file, $file_meta );
     
    4867    public function add_renderers( $file, &$renderer, $path = '', $hierarchy = null ) {
    4968        if ( is_null( $hierarchy ) ) {
    50             $hierarchy = $file->get_check_hierarchy();
     69            $hierarchy = $this->check_hierarchy;
    5170        }
    5271
    5372        foreach ( $hierarchy as $level => $hierarchy_children ) {
    5473            $code_elements = $file->get_code_elements( $level, $path );
    55            
    5674            if ( empty( $code_elements ) ) {
    5775                $this->add_renderers( $file, $renderer, $path, $hierarchy_children );
     
    5977            } else {
    6078                foreach ( $code_elements as $child_path => $child_element ) {
    61                    
    6279                    if ( array_key_exists( $level, $this->hierarchy_metas ) ) {
    6380                        $child_meta = new $this->hierarchy_metas[$level]( $child_path );
  • vip-scanner/trunk/vip-scanner/checks/VCMergeConflictCheck.php

    r883100 r900447  
    33class VCMergeConflictCheck extends BaseCheck {
    44    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
    511        '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
    614        'conflict_file'  => '/mine|r[0-9]+/im'
    715    );
  • vip-scanner/trunk/vip-scanner/checks/VIPRestrictedPatternsCheck.php

    r883100 r900447  
    88        $checks = array(
    99            "/(\\\$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"' ),
    1011            "/(kses)+/msiU" => array ( "level" => "Warning", "note" => "Working with kses" ),
    1112            "/(\\\$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  
    55    protected $filecontents = '';
    66    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 = <<<EOT
    16         (\/\*(?:(?!\*\/)[\s\S])*\*\/)           # match a multiline comment
    17 EOT
    18         ;
    197
    20     protected $single_comment_regex = <<<EOT
    21         (\/\/.*$)           # match a single line comment
    22 EOT;
    23    
    24     protected $heredox_regex = <<<EOT
    25         <<<(?<herestart>\S+)((?!\1)[\s\S])*\3;  # match a heredoc
    26 EOT
    27         ;
    28 
    29     protected $strip_inline_php_regex = '\?>((?!<\?php)[\s\S])*<\?php';
    30    
    31     protected $hierarchy_regexes = array(
    32         'php'        => array( 'regex' => <<<EOT
    33             (                               # start of bracket 1
    34                 <\?php                          # php opening tag
    35                     (?<contents>((?!\?>)[\s\S])*)   # match anything except a php closing tag
    36                 (\?>)?                          # match a closing tag
    37             )                               # end of bracket 1
    38 EOT
    39             ),
    40 
    41         'namespaces' => array( 'regex' => <<<EOT
    42             namespace\s+(?<name>(\\\\?\w+)+);    # Match the name of the namespace
    43             (?<contents>((?!namespace)[\s\S])*)  # match the contents of the namespace
    44 EOT
    45             , ),
    46 
    47         'classes'    => array( 'regex' => <<<EOT
    48             ((?<abstract>abstract)\s+)? # optionally match an abstract class
    49             class\s+(?<name>\w+)\s+ # match the classname
    50             (extends\s+(?<parentclass>\w+)\s*)? # optionally match a parentclass
    51             (?<contents>
    52                 (                       # start of bracket 7
    53                     {                   # match an opening curly bracket
    54                         (?:
    55                             [^{}]++     # one or more non curly brackets
    56                               |
    57                             (?7)        # recurse to bracket 7
    58                         )*
    59                     }                   # match a closing curly bracket
    60                 )                       # end of bracket 7
    61             )
    62 EOT
    63            , ),
    64 
    65         'functions'  => array( 'regex' => <<<EOT
    66             \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 & name
    74             \((?<args>(\s|\w|[$,_='"])+)?\)\s*      # match the function arguments
    75             (?<contents>
    76                 (?(abstract);|                          # match either the semicolon of an abstract function or a closure
    77                     (                                   # start of bracket 1
    78                         {                               # match an opening curly bracket
    79                             (?:
    80                                 [^{}]++                 # one or more non curly brackets
    81                                   |
    82                                 (?8)                    # recurse to bracket 1
    83                             )*
    84                         }                               # match a closing curly bracket
    85                     )                                   # end of bracket 1
    86                 )
    87             )
    88 EOT
    89             , ),
    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    
    1138    /**
    1149     * Analyzes this file.
     
    12318            return;
    12419        }
    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 );
    13129    }
    13230
    13331    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();
    14033    }
    14134
     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    }
    14278}
  • vip-scanner/trunk/vip-scanner/class-analyzer-renderer.php

    r883100 r900447  
    186186                foreach ( $this->attributes as $slug => $attribute ) {
    187187                    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 );
    189189                    }
    190190                }
     
    193193                foreach ( $this->attributes as $slug => $attribute ) {
    194194                    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                        }
    196202                    }
    197203                }
     
    199205        }
    200206        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        }
    201228    }
    202229   
     
    421448     */
    422449    protected function skip_attributes() {
    423         return array( 'contents', 'name' );
     450        return array( 'contents', 'name', 'children' );
    424451    }
    425452   
  • vip-scanner/trunk/vip-scanner/class-base-check.php

    r883100 r900447  
    214214        $scanner = $this->get_scanner();
    215215
    216         if ( ! $scanner instanceof ThemeScanner )
     216        if ( !is_subclass_of( $scanner, 'DirectoryScanner' ) )
    217217            return null;
    218218
  • vip-scanner/trunk/vip-scanner/class-base-scanner.php

    r883100 r900447  
    1313    public $renderers = array();
    1414    public $stats = array();
     15    //recognized extensions
    1516    public $known_extensions = array(
    1617        'php' => array( 'php', 'php5', 'inc' ),
    1718        'css' => 'css',
    1819        '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.*',
    1948    );
    2049
     
    6493    }
    6594
     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
    66142    public function get_file_count() {
    67143        $count = 0;
     
    81157            $file_type = $this->get_file_type( $filename );
    82158
    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);
    86160
    87161            if( !isset( $grouped_files[$file_type] ) )
     
    112186            $this->run_scanners( 'analyzers' );
    113187        }
    114        
     188
    115189        return $pass;
    116190    }
     
    137211                $check_file = '';
    138212            }
     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
    139219            $check_exists = $this->load_check( $check, $check_file, $type );
    140220
  • vip-scanner/trunk/vip-scanner/class-function-renderer.php

    r883100 r900447  
    2222
    2323        $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        }
    2937
    3038        return implode( ' ', $header_items );
  • vip-scanner/trunk/vip-scanner/class-theme-scanner.php

    r883100 r900447  
    77            return $this->add_error( 'wp-load', sprintf( '%s requires WordPress to be loaded.', get_class( $this ) ), 'blocker' );
    88
    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        }
    1116
    1217        // Call Parent Constructor
  • vip-scanner/trunk/vip-scanner/class-wp-cli.php

    r883100 r900447  
    1515     *
    1616     * @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>]
    1818     */
    1919    public function scan_theme( $args, $assoc_args ) {
     
    7777                    $lines = array();
    7878
    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( '' );
    8281
    8382                    // In JSON output, group the lines together
  • vip-scanner/trunk/vip-scanner/vip-scanner.php

    r883100 r900447  
    2828require_once( VIP_SCANNER_DIR . '/class-function-renderer.php' );
    2929require_once( VIP_SCANNER_DIR . '/class-base-analyzer.php' );
     30
     31if ( is_admin() ) {
     32    require_once( VIP_SCANNER_DIR . '/class-async-directory-scanner.php' );
     33    require_once( VIP_SCANNER_DIR . '/vip-scanner-async.php' );
     34}
    3035
    3136class VIP_Scanner {
     
    6368            return false;
    6469
     70        do_action( 'vip_scanner_pre_theme_review', $theme, $review_type );
     71
    6572        $scanner = new ThemeScanner( $theme, $review );
    6673        $scanner->scan( $scanners );
     74
     75        do_action( 'vip_scanner_post_theme_review', $theme, $review_type, $scanner );
    6776        return $scanner;
    6877    }
Note: See TracChangeset for help on using the changeset viewer.