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