コード例 #1
0
 protected function renderContent()
 {
     $name = $this->getAttribute('name');
     $tag = $this->getAttribute('tag', 'div');
     $cssClass = trim('ObjectsCollection ' . $this->getAttribute('class', ''));
     $key = $this->getAttribute('key', FALSE);
     $template = $this->getAttribute('template', FALSE);
     $ifEmpty = $this->getAttribute('ifEmpty', FALSE);
     $placeholders = $this->normalizePlaceholders($this->getAttribute('placeholders', array()));
     $renderer = new ElementRenderer($this->view, $name, '${key}', $template);
     $emptyRenderer = new ElementRenderer($this->view, $name, '${key}', $ifEmpty);
     $content = '';
     $values = $this->view[$name];
     if (empty($values)) {
         $content = $emptyRenderer->render();
     } else {
         foreach ($values as $defaultKey => $data) {
             $placeHolderValues = array();
             foreach ($placeholders as $p => $f) {
                 $placeHolderValues[sprintf('${%s}', $p)] = $data[$f];
             }
             $vR = new ElementRenderer($this->view, $name, $key ? $data[$key] : $defaultKey, $template);
             $content .= strtr((string) $vR->copyFrom($data)->render(), $placeHolderValues);
         }
     }
     return $this->openTag($tag, array('class' => $cssClass . ' ' . $this->getClientEventTarget(), 'id' => $this->view->getUniqueId($name), 'data-state' => json_encode(array('rendered' => !empty($values), 'key' => $key, 'template' => $renderer->render(), 'ifEmpty' => $emptyRenderer->render(), 'placeholders' => $placeholders)))) . $content . $this->closeTag($tag);
 }
コード例 #2
0
 /**
  * Displays this and all children as a hierarchical list. Assumes to
  * already be surround in either a <ul> or <ol>.
  * 
  * @param bool $echo Whether or not to echo the output
  * @return string
  */
 function display($echo = true, $args = array())
 {
     $output = '';
     $defaults = array('bare' => false, 'level' => 0, 'depth' => 0);
     $args = wp_parse_args($args, $defaults);
     $this->display_args = $args;
     // Output the header. Don't escape here because we expect the header to contain html.
     $header_text = $this->display_header($this->element->get_header());
     if ($this->element->get_child_summary()) {
         $header_text .= ' ' . $this->stylize_text('(' . $this->display_child_summary($this->element->get_child_summary()) . ')', array('small' => true));
     }
     if (!$args['bare']) {
         $header_classes = array('renderer-group-header');
         if (isset($args['body_classes'])) {
             $header_classes = array_merge($header_classes, $args['body_classes']);
         }
         if ($this->element->is_empty()) {
             $header_classes[] = 'renderer-group-empty';
         }
         $output .= '<h3 class="' . esc_attr(implode(' ', $header_classes)) . '">' . $header_text . '</h3>';
         $body_classes = array('renderer-group-body');
         if (isset($args['body_classes'])) {
             $body_classes = array_merge($body_classes, $args['body_classes']);
         }
         // Output the body container div
         $output .= '<div class="' . esc_attr(implode(' ', $body_classes)) . '">';
         $output .= '<div class="renderer-group-children">';
     } else {
         $output .= str_repeat($this->spacing_char, $args['level']) . $header_text . "\n";
         $args['level'] += 1;
     }
     if (0 === $args['depth'] || $args['level'] < $args['depth']) {
         $colors = array();
         if ($this->element instanceof ElementGroup) {
             $prefix_count = $this->element->analyze_prefixes();
             $colors = $this->randColor($prefix_count);
         }
         foreach ($this->element->get_children() as $child) {
             $r = new ElementRenderer($child, $colors);
             $output .= $r->display(false, $args);
         }
     }
     if (!$args['bare']) {
         $output .= '</div>';
     }
     // Output attributes
     $output .= $this->display_attributes($args);
     // Output stats
     $output .= $this->display_stats($args);
     if (!$args['bare']) {
         $output .= '</div>';
     } else {
         $output .= "\n";
     }
     if ($echo) {
         echo $output;
     } else {
         return $output;
     }
 }
コード例 #3
0
    function display_theme_review_result($scanner, $theme)
    {
        global $SyntaxHighlighter;
        if (isset($SyntaxHighlighter)) {
            add_action('admin_footer', array(&$SyntaxHighlighter, 'maybe_output_scripts'));
        }
        $report = $scanner->get_results();
        $error_levels = $scanner->get_error_levels();
        $note_types = array_diff($error_levels, array_keys($this->blocker_types));
        $blockers = $scanner->get_errors(array_keys($this->blocker_types));
        $notes = count($note_types) ? $scanner->get_errors($note_types) : array();
        $errors = count($blockers);
        $notes = count($notes);
        $pass = !$errors;
        ?>
		<div class="scan-info">
			<span>Scanned Theme: <span class="theme-name"><?php 
        echo $theme;
        ?>
</span></span>
			<?php 
        $this->display_vip_scanner_form();
        ?>
		</div>

		<div class="scan-report">
			<div class="scan-results result-<?php 
        echo $pass ? 'pass' : 'fail';
        ?>
"><?php 
        echo $pass ? __('Passed the Scan with no errors!', 'theme-check') : __('Failed to pass Scan', 'theme-check');
        ?>
</div>

			<table class="scan-results-table">
				<tr>
					<th><?php 
        _e('Total Files', 'theme-check');
        ?>
</th>
					<td><?php 
        echo intval($report['total_files']);
        ?>
</td>
				</tr>
				<tr>
					<th><?php 
        _e('Total Checks', 'theme-check');
        ?>
</th>
					<td><?php 
        echo intval($report['total_checks']);
        ?>
</td>
				</tr>
			</table>
		</div>

		<h2 class="nav-tab-wrapper">
			<a href="#errors" class="nav-tab"><?php 
        echo absint($errors);
        ?>
 <?php 
        _e('Errors', 'theme-check');
        ?>
</a>
			<a href="#notes" class="nav-tab"><?php 
        echo absint($notes);
        ?>
 <?php 
        _e('Notes', 'theme-check');
        ?>
</a>
			<a href="#analysis" class="nav-tab"><?php 
        _e('Analysis', 'theme-check');
        ?>
</a>
		</h2>

		<div id="errors">
			<?php 
        foreach ($this->blocker_types as $type => $title) {
            $errors = $scanner->get_errors(array($type));
            if (!count($errors)) {
                continue;
            }
            ?>
				<h3><?php 
            echo esc_html($title);
            ?>
</h3>
				<ol class="scan-results-list">
					<?php 
            foreach ($errors as $result) {
                $this->display_theme_review_result_row($result, $scanner, $theme);
            }
            ?>
				</ol>
			<?php 
        }
        ?>
		</div>

		<div id="notes">
			<?php 
        foreach ($note_types as $type) {
            $errors = $scanner->get_errors(array($type));
            $title = ucfirst($type . 's');
            if (!count($errors)) {
                continue;
            }
            ?>
				<h3><?php 
            echo esc_html($title);
            ?>
</h3>
				<ul class="analysis-results-list">
					<?php 
            foreach ($errors as $result) {
                $this->display_theme_review_result_row($result, $scanner, $theme);
            }
            ?>
				</ul>
			<?php 
        }
        ?>
		</div>
			
		<div id="analysis">
			<div id="analysis-accordion">
				<?php 
        $empty = array();
        foreach ($scanner->elements as $element) {
            if ($element->name() !== 'Files') {
                $element->analyze_prefixes();
            }
            // Display empty elements after the others
            if ($element->is_empty()) {
                $empty[] = $element;
                continue;
            }
            $r = new ElementRenderer($element);
            $r->display();
        }
        foreach ($empty as $element) {
            $r = new ElementRenderer($element);
            $r->display();
        }
        ?>
			</div>
		</div>
		<?php 
    }
コード例 #4
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);
     }
 }