Exemplo n.º 1
0
 /**
  * Runs the analyzers for the given review on the theme.
  * 
  * You can change the <depth> parameter to indicate how many levels of hierarchy
  * you would like outputted. 0 outputs everything.
  * 
  * @subcommand analyze-theme
  * @synopsis --theme=<theme-name> --scan_type=<scan-type> [--depth=<depth>]
  */
 public function analyze_theme($args, $assoc_args)
 {
     $defaults = array('theme' => null, 'scan_type' => 'WP.org Theme Review', 'depth' => 1);
     $args = wp_parse_args($assoc_args, $defaults);
     $scanner = VIP_Scanner::get_instance()->run_theme_review($args['theme'], $args['scan_type'], array('analyzers'));
     if (!$scanner) {
         WP_CLI::error(sprintf('Scanning of %s failed', $args['theme']));
     }
     $empty = array();
     $display_args = array('bare' => true, 'depth' => $args['depth']);
     foreach ($scanner->renderers as $renderer) {
         // Display empty renderers after the others
         if ($renderer->is_empty()) {
             $empty[] = $renderer;
             continue;
         }
         if ($renderer->name() !== 'Files') {
             $renderer->analyze_prefixes();
         }
         WP_CLI::line($renderer->display(false, $display_args));
     }
     foreach ($empty as $renderer) {
         $renderer->display(true, $display_args);
     }
 }
Exemplo n.º 2
0
 public function testScanner()
 {
     $vipsccanner = VIP_Scanner::get_instance();
     $vipsccanner->register_review('VIPInitCheck', array('VIPInitCheck'), array('ThemeAnalyzer'));
     $review = $vipsccanner->get_review('VIPInitCheck');
     $scanner = new ThemeScanner(dirname($this->_functions_file), $review);
     $scanner->scan(array('checks'));
     $this->assertFalse($scanner->has_error('vip-init'));
 }
Exemplo n.º 3
0
 private function __construct()
 {
     $this->vip_scanner_instance = VIP_Scanner::get_instance();
     add_action('init', array($this, 'init'));
     add_action('admin_init', array($this, 'admin_init'));
     add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
     add_action('wp_before_admin_bar_render', array($this, 'add_admin_bar_node'));
     add_action('vip_scanner_post_theme_review', array($this, 'post_external_theme_review'), 10, 3);
     add_action('wp_ajax_vip-scanner-do_async_scan', array($this, 'ajax_do_scan'));
     add_action('wp_ajax_vip-scanner-get_errors_summary', array($this, 'ajax_get_errors_summary'));
 }
Exemplo n.º 4
0
 function get_cached_theme_review($theme, $review)
 {
     $transient_key = 'vip_scanner_' . $this->get_version() . '_' . md5($theme . $review);
     if (false === ($scanner = get_transient($transient_key))) {
         $scanner = VIP_Scanner::get_instance()->run_theme_review($theme, $review);
         @set_transient($transient_key, $scanner);
     }
     return $scanner;
 }
Exemplo n.º 5
0
<?php

// Include the form config
include_once VIP_SCANNER_DIR . '/config-vip-scanner-wpcom-form.php';
// TODO: Not sure if this is the best place or way to handle this...
VIP_Scanner::get_instance()->register_review('Undefined Function Check', array('UndefinedFunctionCheck'));
VIP_Scanner::get_instance()->register_review('WP.com Theme Review', array('AtPackageCheck', 'BodyClassCheck', 'CDNCheck', 'CommentsCheck', 'CustomizerCheck', 'DeprecatedConstantsCheck', 'DeprecatedFunctionsCheck', 'DeprecatedParametersCheck', 'EscapingCheck', 'FirstPostPromptCheck', 'ForbiddenConstantsCheck', 'ForbiddenFunctionsCheck', 'ForbiddenGoogleCheck', 'ForbiddenLibrariesCheck', 'ForbiddenPHPFunctionsCheck', 'HeaderCheck', 'HooksCheck', 'InternationalizedStringCheck', 'jQueryCheck', 'JetpackCheck', 'LanguagePacksCheck', 'MasonryCheck', 'PostThumbnailsCheck', 'ScreenshotCheck', 'ThemecolorsCheck', 'ThemeNameCheck', 'TitleCheck', 'VCMergeConflictCheck', 'WidgetsCheck', 'JavaScriptLintCheck'), array('PHPAnalyzer', 'CustomResourceAnalyzer', 'ThemeAnalyzer'));
VIP_Scanner::get_instance()->register_review('VIP Theme Review', array('VIPWhitelistCheck', 'VIPRestrictedPatternsCheck', 'VIPRestrictedCommandsCheck', 'VIPInitCheck', 'PHPShortTagsCheck', 'PHPClosingTagsCheck', 'VCMergeConflictCheck', 'WordPressCodingStandardsCheck', 'ClamAVCheck'), array('PHPAnalyzer', 'CustomResourceAnalyzer', 'ThemeAnalyzer'));
Exemplo n.º 6
0
<?php

// Include the form config
include_once VIP_SCANNER_DIR . '/config-vip-scanner-wpcom-form.php';
// TODO: Not sure if this is the best place or way to handle this...
VIP_Scanner::get_instance()->register_review('Undefined Function Check', array('UndefinedFunctionCheck'));
VIP_Scanner::get_instance()->register_review('WP.com Theme Review', array('AtPackageCheck', 'BodyClassCheck', 'CDNCheck', 'CheckedSelectedDisabledCheck', 'CommentsCheck', 'CustomizerCheck', 'DeprecatedConstantsCheck', 'DeprecatedFunctionsCheck', 'DeprecatedParametersCheck', 'EscapingCheck', 'FirstPostPromptCheck', 'ForbiddenConstantsCheck', 'ForbiddenFunctionsCheck', 'ForbiddenGoogleCheck', 'ForbiddenLibrariesCheck', 'ForbiddenPHPFunctionsCheck', 'HeaderCheck', 'HooksCheck', 'InternationalizedStringCheck', 'jQueryCheck', 'JetpackCheck', 'LanguagePacksCheck', 'MasonryCheck', 'PostThumbnailsCheck', 'ScreenshotCheck', 'StyleHeadersCheck', 'ThemecolorsCheck', 'ThemeContentWidthCheck', 'ThemeNameCheck', 'ThemePostPaginationCheck', 'ThemeStyleRequiredCheck', 'ThemeTagCheck', 'TimeDateCheck', 'TitleCheck', 'VCMergeConflictCheck', 'WidgetsCheck', 'JavaScriptLintCheck'), array('CodeAnalyzer', 'ResourceAnalyzer', 'ThemeAnalyzer'));
VIP_Scanner::get_instance()->register_review('VIP Theme Review', array('CheckedSelectedDisabledCheck', 'DeprecatedConstantsCheck', 'DeprecatedFunctionsCheck', 'DeprecatedParametersCheck', 'jQueryCheck', 'VIPWhitelistCheck', 'VIPRestrictedClassesCheck', 'VIPRestrictedPatternsCheck', 'VIPRestrictedCommandsCheck', 'VIPInitCheck', 'VIPParametersCheck', 'PHPShortTagsCheck', 'PHPClosingTagsCheck', 'StyleHeadersCheck', 'VCMergeConflictCheck', 'WordPressCodingStandardsCheck', 'ClamAVCheck', 'AdBustersCheck'), array('CodeAnalyzer', 'ResourceAnalyzer', 'ThemeAnalyzer'));
Exemplo n.º 7
0
    function get_review_types()
    {
        return array_keys($this->reviews);
    }
    function get_review($name)
    {
        if (isset($this->reviews[$name])) {
            return $this->reviews[$name];
        }
        return false;
    }
    function register_review($name, $checks, $analyzers = array())
    {
        $this->reviews[$name] = array('checks' => (array) $checks, 'analyzers' => (array) $analyzers);
    }
    function run_theme_review($theme, $review_type, $scanners = array('checks', 'analyzers'))
    {
        $review = $this->get_review($review_type);
        if (!$review) {
            return false;
        }
        do_action('vip_scanner_pre_theme_review', $theme, $review_type);
        $scanner = new ThemeScanner($theme, $review);
        $scanner->scan($scanners);
        do_action('vip_scanner_post_theme_review', $theme, $review_type, $scanner);
        return $scanner;
    }
}
// Initialize!
VIP_Scanner::get_instance();
Exemplo n.º 8
0
 private static function is_review_type($type)
 {
     global $vip_scanner;
     $review_types = VIP_Scanner::get_instance()->get_review_types();
     $cur = isset($_REQUEST['vip-scanner-review-type']) ? $_REQUEST['vip-scanner-review-type'] : $review_types[$vip_scanner->default_review];
     return $cur == $type;
 }
Exemplo n.º 9
0
 /**
  * Runs the analyzers for the given review on the theme.
  *
  * [--theme=<theme>]
  * : Theme to scan. Defaults to current.
  *
  * [--scan_type=<scan_type>]
  * : Type of scan to perform. Defaults to "VIP Theme Review"
  *
  * [--depth=<depth>]
  * : Number of levels of hierarchy to output. 0 outputs everything.
  * Defaults to 1.
  * 
  * @subcommand analyze-theme
  */
 public function analyze_theme($args, $assoc_args)
 {
     $defaults = array('theme' => get_option('stylesheet'), 'scan_type' => 'VIP Theme Review', 'depth' => 1);
     $args = wp_parse_args($assoc_args, $defaults);
     $scanner = VIP_Scanner::get_instance()->run_theme_review($args['theme'], $args['scan_type'], array('analyzers'));
     if (!$scanner) {
         WP_CLI::error(sprintf('Scanning of %s failed', $args['theme']));
     }
     $errors = $scanner->get_errors();
     if (!empty($errors)) {
         self::display_errors($scanner, 'table');
     }
     $empty = array();
     $display_args = array('bare' => true, 'depth' => intval($args['depth']));
     foreach ($scanner->elements as $element) {
         // Display empty elements after the others
         if ($element->is_empty()) {
             $empty[] = $element;
             continue;
         }
         if ($element->name() !== 'Files') {
             $element->analyze_prefixes();
         }
         $r = new ElementRenderer($element);
         WP_CLI::line($r->display(false, $display_args));
     }
     foreach ($empty as $element) {
         $r = new ElementRenderer($element);
         $r->display(true, $display_args);
     }
 }