11c845774SAndreas Gohr<?php 21c845774SAndreas Gohr 31c845774SAndreas Gohrnamespace dokuwiki\plugin\qc; 41c845774SAndreas Gohr 51c845774SAndreas Gohr/** 61c845774SAndreas Gohr * Class Output 71c845774SAndreas Gohr * 81c845774SAndreas Gohr * Create the HTML formatted output of the scoring analysis 91c845774SAndreas Gohr * 101c845774SAndreas Gohr * @package dokuwiki\plugin\qc 111c845774SAndreas Gohr */ 12*76bbc49cSAnna Dabrowskaclass Output 13*76bbc49cSAnna Dabrowska{ 141c845774SAndreas Gohr 151c845774SAndreas Gohr const MAXERR = 10; //what score to use as total failure 161c845774SAndreas Gohr 171c845774SAndreas Gohr /** @var array the scoring data */ 181c845774SAndreas Gohr protected $data; 191c845774SAndreas Gohr 201c845774SAndreas Gohr /** @var \helper_plugin_qc */ 211c845774SAndreas Gohr protected $helper; 221c845774SAndreas Gohr 231c845774SAndreas Gohr /** 241c845774SAndreas Gohr * Output constructor. 251c845774SAndreas Gohr * @param string $page the page to analyze 261c845774SAndreas Gohr */ 27*76bbc49cSAnna Dabrowska public function __construct($page) 28*76bbc49cSAnna Dabrowska { 291c845774SAndreas Gohr $this->helper = plugin_load('helper', 'qc'); 301c845774SAndreas Gohr $this->data = $this->helper->getQCData($page); 311c845774SAndreas Gohr } 321c845774SAndreas Gohr 331c845774SAndreas Gohr /** 341c845774SAndreas Gohr * Get the score as icon 351c845774SAndreas Gohr * 361c845774SAndreas Gohr * @param $score 371c845774SAndreas Gohr * @return string 381c845774SAndreas Gohr */ 39*76bbc49cSAnna Dabrowska public static function scoreIcon($score) 40*76bbc49cSAnna Dabrowska { 411c845774SAndreas Gohr $html = ''; 421c845774SAndreas Gohr 431c845774SAndreas Gohr // rate the score 441c845774SAndreas Gohr if ($score > self::MAXERR) { 451c845774SAndreas Gohr $rating = 'bad'; 461c845774SAndreas Gohr } elseif ($score) { 471c845774SAndreas Gohr $rating = 'meh'; 481c845774SAndreas Gohr } else { 491c845774SAndreas Gohr $rating = 'good'; 501c845774SAndreas Gohr } 511c845774SAndreas Gohr 521c845774SAndreas Gohr // output icon and score 531c845774SAndreas Gohr $html .= '<span class="qc_icon qc_' . $rating . '">'; 541c845774SAndreas Gohr $html .= inlineSVG(__DIR__ . '/svg/' . $rating . '.svg'); 55578c8d9aSAndreas Gohr if ($score) $html .= '<span>' . $score . '</span>'; 561c845774SAndreas Gohr $html .= '</span>'; 571c845774SAndreas Gohr 581c845774SAndreas Gohr return $html; 591c845774SAndreas Gohr } 601c845774SAndreas Gohr 611c845774SAndreas Gohr /** 621c845774SAndreas Gohr * Print the short summary 631c845774SAndreas Gohr * 641c845774SAndreas Gohr * @return string 651c845774SAndreas Gohr */ 66*76bbc49cSAnna Dabrowska public function short() 67*76bbc49cSAnna Dabrowska { 68d9e33559SAndreas Gohr return self::scoreIcon($this->data['score']); 691c845774SAndreas Gohr } 701c845774SAndreas Gohr 711c845774SAndreas Gohr /** 721c845774SAndreas Gohr * Print full analysis 731c845774SAndreas Gohr * 741c845774SAndreas Gohr * @return string 751c845774SAndreas Gohr */ 76*76bbc49cSAnna Dabrowska public function long() 77*76bbc49cSAnna Dabrowska { 781c845774SAndreas Gohr $html = ''; 791c845774SAndreas Gohr 801c845774SAndreas Gohr $html .= '<h1>' . $this->helper->getLang('intro_h') . '</h1>'; 811c845774SAndreas Gohr 821c845774SAndreas Gohr $html .= '<div>'; 831c845774SAndreas Gohr $html .= '<dl>'; 841c845774SAndreas Gohr $html .= '<dt>' . $this->helper->getLang('g_created') . '</dt>'; 851c845774SAndreas Gohr $html .= '<dd>' . dformat($this->data['created']) . '</dd>'; 861c845774SAndreas Gohr 871c845774SAndreas Gohr $html .= '<dt>' . $this->helper->getLang('g_modified') . '</dt>'; 881c845774SAndreas Gohr $html .= '<dd>' . dformat($this->data['modified']) . '</dd>'; 891c845774SAndreas Gohr 901c845774SAndreas Gohr // print top 5 authors 911c845774SAndreas Gohr if (!is_array($this->data['authors'])) $this->data['authors'] = array(); 921c845774SAndreas Gohr arsort($this->data['authors']); 931c845774SAndreas Gohr $top5 = array_slice($this->data['authors'], 0, 5); 941c845774SAndreas Gohr $cnt = count($top5); 951c845774SAndreas Gohr $i = 1; 961c845774SAndreas Gohr $html .= '<dt>' . $this->helper->getLang('g_authors') . '</dt>'; 971c845774SAndreas Gohr $html .= '<dd>'; 981c845774SAndreas Gohr foreach ($top5 as $a => $e) { 991c845774SAndreas Gohr if ($a == '*') { 1001c845774SAndreas Gohr $html .= $this->helper->getLang('anonymous'); 1011c845774SAndreas Gohr } else { 1021c845774SAndreas Gohr $html .= editorinfo($a); 1031c845774SAndreas Gohr } 1041c845774SAndreas Gohr $html .= ' (' . $e . ')'; 1051c845774SAndreas Gohr if ($i++ < $cnt) $html .= ', '; 1061c845774SAndreas Gohr } 1071c845774SAndreas Gohr $html .= '</dd>'; 1081c845774SAndreas Gohr 1091c845774SAndreas Gohr $html .= '<dt>' . $this->helper->getLang('g_changes') . '</dt>'; 1101c845774SAndreas Gohr $html .= '<dd>' . $this->data['changes'] . '</dd>'; 1111c845774SAndreas Gohr 1121c845774SAndreas Gohr $html .= '<dt>' . $this->helper->getLang('g_chars') . '</dt>'; 1131c845774SAndreas Gohr $html .= '<dd>' . $this->data['chars'] . '</dd>'; 1141c845774SAndreas Gohr 1151c845774SAndreas Gohr $html .= '<dt>' . $this->helper->getLang('g_words') . '</dt>'; 1161c845774SAndreas Gohr $html .= '<dd>' . $this->data['words'] . '</dd>'; 1171c845774SAndreas Gohr 1181c845774SAndreas Gohr $html .= '</dl>'; 1191c845774SAndreas Gohr $html .= '</div>'; 1201c845774SAndreas Gohr 1211c845774SAndreas Gohr // output all the problems 1221c845774SAndreas Gohr if ($this->data['score']) { 1231c845774SAndreas Gohr $html .= '<h2>' . $this->helper->getLang('errorsfound_h') . '</h2>'; 1241c845774SAndreas Gohr $html .= '<p>' . $this->helper->getLang('errorsfound') . '</p>'; 1251c845774SAndreas Gohr $html .= '<div>'; 1261c845774SAndreas Gohr arsort($this->data['err']); #sort by score 1271c845774SAndreas Gohr foreach ($this->data['err'] as $err => $val) { 1281c845774SAndreas Gohr if ($val) { 1291c845774SAndreas Gohr $html .= '<h3>'; 1301c845774SAndreas Gohr $html .= sprintf($this->helper->getLang($err . '_h'), $val); 1311c845774SAndreas Gohr $html .= '<span class="qc_icon qc_bad">'; 1321c845774SAndreas Gohr $html .= inlineSVG(__DIR__ . '/svg/bad.svg'); 1331c845774SAndreas Gohr $html .= '<span>' . $val . '</span>'; 1341c845774SAndreas Gohr $html .= '</span>'; 1351c845774SAndreas Gohr $html .= '</h3>'; 1361c845774SAndreas Gohr $html .= '<p>' . sprintf($this->helper->getLang($err), $val) . '</p>'; 1371c845774SAndreas Gohr } 1381c845774SAndreas Gohr } 1391c845774SAndreas Gohr $html .= '</div>'; 1401c845774SAndreas Gohr } 1411c845774SAndreas Gohr 1421c845774SAndreas Gohr return $html; 1431c845774SAndreas Gohr } 1441c845774SAndreas Gohr} 145