xref: /dokuwiki/inc/parser/xhtmlsummary.php (revision 749bc7f13d5fc213945d96ad93feaab8f74a1e03)
16b7b33dcShfuecks<?php
2faf3f01bSAndreas Gohr
36b7b33dcShfuecks/**
46b7b33dcShfuecks * The summary XHTML form selects either up to the first two paragraphs
56b7b33dcShfuecks * it find in a page or the first section (whichever comes first)
66b7b33dcShfuecks * It strips out the table of contents if one exists
76b7b33dcShfuecks * Section divs are not used - everything should be nested in a single
86b7b33dcShfuecks * div with CSS class "page"
96b7b33dcShfuecks * Headings have their a name link removed and section editing links
106b7b33dcShfuecks * removed
116b7b33dcShfuecks * It also attempts to capture the first heading in a page for
126b7b33dcShfuecks * use as the title of the page.
13b8c943a4SAndreas Gohr *
14b8c943a4SAndreas Gohr *
15b8c943a4SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
16b8c943a4SAndreas Gohr * @todo   Is this currently used anywhere? Should it?
176b7b33dcShfuecks */
18faf3f01bSAndreas Gohrclass Doku_Renderer_xhtmlsummary extends Doku_Renderer_xhtml
19faf3f01bSAndreas Gohr{
206b7b33dcShfuecks    // Namespace these variables to
216b7b33dcShfuecks    // avoid clashes with parent classes
22de369923SAndreas Gohr    protected $sum_paragraphs = 0;
23de369923SAndreas Gohr    protected $sum_capture = true;
24de369923SAndreas Gohr    protected $sum_inSection = false;
25de369923SAndreas Gohr    protected $sum_summary = '';
26de369923SAndreas Gohr    protected $sum_pageTitle = false;
276b7b33dcShfuecks
28de369923SAndreas Gohr    /** @inheritdoc */
29faf3f01bSAndreas Gohr    public function document_start()
30faf3f01bSAndreas Gohr    {
316b7b33dcShfuecks        $this->doc .= DOKU_LF . '<div>' . DOKU_LF;
326b7b33dcShfuecks    }
336b7b33dcShfuecks
34de369923SAndreas Gohr    /** @inheritdoc */
35faf3f01bSAndreas Gohr    public function document_end()
36faf3f01bSAndreas Gohr    {
376b7b33dcShfuecks        $this->doc = $this->sum_summary;
386b7b33dcShfuecks        $this->doc .= DOKU_LF . '</div>' . DOKU_LF;
396b7b33dcShfuecks    }
406b7b33dcShfuecks
41*749bc7f1SAndreas Gohr    /** @inheritdoc
42*749bc7f1SAndreas Gohr     * @param string $text
43*749bc7f1SAndreas Gohr     * @param int $level
44*749bc7f1SAndreas Gohr     * @param int $pos
45*749bc7f1SAndreas Gohr     * @param false $returnonly
46*749bc7f1SAndreas Gohr     */
47*749bc7f1SAndreas Gohr    public function header($text, $level, $pos, $returnonly = false)
48faf3f01bSAndreas Gohr    {
496b7b33dcShfuecks        if (!$this->sum_pageTitle) {
506b7b33dcShfuecks            $this->info['sum_pagetitle'] = $text;
5144881bd0Shenning.noren            $this->sum_pageTitle = true;
526b7b33dcShfuecks        }
536b7b33dcShfuecks        $this->doc .= DOKU_LF . '<h' . $level . '>';
546b7b33dcShfuecks        $this->doc .= $this->_xmlEntities($text);
556b7b33dcShfuecks        $this->doc .= "</h$level>" . DOKU_LF;
566b7b33dcShfuecks    }
576b7b33dcShfuecks
58de369923SAndreas Gohr    /** @inheritdoc */
59faf3f01bSAndreas Gohr    public function section_open($level)
60faf3f01bSAndreas Gohr    {
616b7b33dcShfuecks        if ($this->sum_capture) {
6244881bd0Shenning.noren            $this->sum_inSection = true;
636b7b33dcShfuecks        }
646b7b33dcShfuecks    }
656b7b33dcShfuecks
66de369923SAndreas Gohr    /** @inheritdoc */
67faf3f01bSAndreas Gohr    public function section_close()
68faf3f01bSAndreas Gohr    {
696b7b33dcShfuecks        if ($this->sum_capture && $this->sum_inSection) {
706b7b33dcShfuecks            $this->sum_summary .= $this->doc;
7144881bd0Shenning.noren            $this->sum_capture = false;
726b7b33dcShfuecks        }
736b7b33dcShfuecks    }
746b7b33dcShfuecks
75de369923SAndreas Gohr    /** @inheritdoc */
76faf3f01bSAndreas Gohr    public function p_open()
77faf3f01bSAndreas Gohr    {
786b7b33dcShfuecks        if ($this->sum_capture && $this->sum_paragraphs < 2) {
796b7b33dcShfuecks            $this->sum_paragraphs++;
806b7b33dcShfuecks        }
816b7b33dcShfuecks        parent::p_open();
826b7b33dcShfuecks    }
836b7b33dcShfuecks
84de369923SAndreas Gohr    /** @inheritdoc */
85faf3f01bSAndreas Gohr    public function p_close()
86faf3f01bSAndreas Gohr    {
876b7b33dcShfuecks        parent::p_close();
886b7b33dcShfuecks        if ($this->sum_capture && $this->sum_paragraphs >= 2) {
896b7b33dcShfuecks            $this->sum_summary .= $this->doc;
9044881bd0Shenning.noren            $this->sum_capture = false;
916b7b33dcShfuecks        }
926b7b33dcShfuecks    }
936b7b33dcShfuecks}
946b7b33dcShfuecks
956b7b33dcShfuecks
96e3776c06SMichael Hamann//Setup VIM: ex: et ts=2 :
97