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