Failed Conditions
Push — psr2 ( d2778c...de3699 )
by Andreas
06:25 queued 03:28
created

Doku_Renderer_xhtmlsummary::toc_close()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * The summary XHTML form selects either up to the first two paragraphs
4
 * it find in a page or the first section (whichever comes first)
5
 * It strips out the table of contents if one exists
6
 * Section divs are not used - everything should be nested in a single
7
 * div with CSS class "page"
8
 * Headings have their a name link removed and section editing links
9
 * removed
10
 * It also attempts to capture the first heading in a page for
11
 * use as the title of the page.
12
 *
13
 *
14
 * @author Harry Fuecks <[email protected]>
15
 * @todo   Is this currently used anywhere? Should it?
16
 */
17
class Doku_Renderer_xhtmlsummary extends Doku_Renderer_xhtml {
18
19
    // Namespace these variables to
20
    // avoid clashes with parent classes
21
    protected $sum_paragraphs = 0;
22
    protected $sum_capture = true;
23
    protected $sum_inSection = false;
24
    protected $sum_summary = '';
25
    protected $sum_pageTitle = false;
26
27
    /** @inheritdoc */
28
    public function document_start() {
29
        $this->doc .= DOKU_LF.'<div>'.DOKU_LF;
30
    }
31
32
    /** @inheritdoc */
33
    public function document_end() {
34
        $this->doc = $this->sum_summary;
35
        $this->doc .= DOKU_LF.'</div>'.DOKU_LF;
36
    }
37
38
    /** @inheritdoc */
39
    public function header($text, $level, $pos) {
40
        if ( !$this->sum_pageTitle ) {
41
            $this->info['sum_pagetitle'] = $text;
42
            $this->sum_pageTitle = true;
43
        }
44
        $this->doc .= DOKU_LF.'<h'.$level.'>';
45
        $this->doc .= $this->_xmlEntities($text);
46
        $this->doc .= "</h$level>".DOKU_LF;
47
    }
48
49
    /** @inheritdoc */
50
    public function section_open($level) {
51
        if ( $this->sum_capture ) {
52
            $this->sum_inSection = true;
53
        }
54
    }
55
56
    /** @inheritdoc */
57
    public function section_close() {
58
        if ( $this->sum_capture && $this->sum_inSection ) {
59
            $this->sum_summary .= $this->doc;
60
            $this->sum_capture = false;
61
        }
62
    }
63
64
    /** @inheritdoc */
65
    public function p_open() {
66
        if ( $this->sum_capture && $this->sum_paragraphs < 2 ) {
67
            $this->sum_paragraphs++;
68
        }
69
        parent :: p_open();
70
    }
71
72
    /** @inheritdoc */
73
    public function p_close() {
74
        parent :: p_close();
75
        if ( $this->sum_capture && $this->sum_paragraphs >= 2 ) {
76
            $this->sum_summary .= $this->doc;
77
            $this->sum_capture = false;
78
        }
79
    }
80
81
}
82
83
84
//Setup VIM: ex: et ts=2 :
85