1<?php 2// must be run within Dokuwiki 3if(!defined('DOKU_INC')) die(); 4 5// we inherit from the XHTML renderer instead directly of the base renderer 6require_once DOKU_INC.'inc/parser/renderer.php'; 7 8/** 9 * The Renderer 10 */ 11class renderer_plugin_qc extends Doku_Renderer { 12 /** 13 * We store all our data in an array 14 */ 15 var $doc = array( 16 // raw statistics 17 'header_count' => array(0,0,0,0,0,0), 18 'header_struct' => array(), 19 'linebreak' => 0, 20 'quote_nest' => 0, 21 'quote_count' => 0, 22 'fixme' => 0, 23 'hr' => 0, 24 25 // calculated error scores 26 'err' => array( 27 'fixme' => 0, 28 'noh1' => 0, 29 'manyh1' => 0, 30 'headernest' => 0, 31 'manyhr' => 0, 32 'manybr' => 0, 33 ), 34 ); 35 36 var $quotelevel = 0; 37 38 /** 39 * Here the score is calculated 40 */ 41 function document_end() { 42 43 // 1 point for each FIXME 44 $this->doc['err']['fixme'] += $this->doc['fixme']; 45 46 // 5 points for missing H1 47 if($this->doc['header_count'][1] == 0){ 48 $this->doc['err']['noh1'] += 5; 49 } 50 // 1 point for each H1 too much 51 if($this->doc['header_count'][1] > 1){ 52 $this->doc['err']['manyh1'] += $this->doc['header'][1]; 53 } 54 55 // 1 point for each incorrectly nested headline 56 $cnt = count($this->doc['header_struct']); 57 for($i = 1; $i < $cnt; $i++){ 58 if($this->doc['header_struct'][$i] - $this->doc['header_struct'][$i-1] > 1){ 59 $this->doc['err']['headernest'] += 1; 60 } 61 } 62 63 // 1/2 points for deeply nested quotations 64 if($this->doc['quote_nest'] > 2){ 65 $this->doc['err']['deepquote'] += $this->doc['quote_nest']/2; 66 } 67 68 // FIXME points for many quotes? 69 70 // 1/2 points for too many hr 71 if($this->doc['hr'] > 2){ 72 $this->doc['err']['manyhr'] = ($this->doc['hr'] - 2)/2; 73 } 74 75 // 1 point for too many line breaks 76 if($this->doc['linebreak'] > 2){ 77 $this->doc['err']['manybr'] = $this->doc['linebreak'] - 2; 78 } 79 80 //we're done here 81 $this->doc = serialize($this->doc); 82 } 83 84 /** 85 * return some info 86 */ 87 function getInfo(){ 88 return confToHash(dirname(__FILE__).'/info.txt'); 89 } 90 91 /** 92 * the format we produce 93 */ 94 function getFormat(){ 95 return 'qc'; 96 } 97 98 99 function header($text, $level, $pos){ 100 $this->doc['header_count'][$level]++; 101 $this->doc['header_struct'][] = $level; 102 } 103 104 function smiley($smiley) { 105 if($smiley == 'FIXME') $this->doc['fixme']++; 106 } 107 108 function linebreak() { 109 $this->doc['linebreak']++; 110 } 111 112 function hr() { 113 $this->doc['hr']++; 114 } 115 116 function quote_open() { 117 $this->doc['quote_count']++; 118 $this->quotelevel++; 119 $this->doc['quote_nest'] = max($this->quotelevel,$this->doc['quote_nest']); 120 } 121 122 function quote_close() { 123 $this->quotelevel--; 124 } 125 126 127} 128 129//Setup VIM: ex: et ts=4 enc=utf-8 : 130