xref: /dokuwiki/inc/parser/xhtmlsummary.php (revision faf3f01b9af152b16aca96437c109c41b8250689)
16b7b33dcShfuecks<?php
2*faf3f01bSAndreas 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 */
18*faf3f01bSAndreas Gohrclass Doku_Renderer_xhtmlsummary extends Doku_Renderer_xhtml
19*faf3f01bSAndreas Gohr{
206b7b33dcShfuecks
216b7b33dcShfuecks    // Namespace these variables to
226b7b33dcShfuecks    // avoid clashes with parent classes
23de369923SAndreas Gohr    protected $sum_paragraphs = 0;
24de369923SAndreas Gohr    protected $sum_capture = true;
25de369923SAndreas Gohr    protected $sum_inSection = false;
26de369923SAndreas Gohr    protected $sum_summary = '';
27de369923SAndreas Gohr    protected $sum_pageTitle = false;
286b7b33dcShfuecks
29de369923SAndreas Gohr    /** @inheritdoc */
30*faf3f01bSAndreas Gohr    public function document_start()
31*faf3f01bSAndreas Gohr    {
326b7b33dcShfuecks        $this->doc .= DOKU_LF . '<div>' . DOKU_LF;
336b7b33dcShfuecks    }
346b7b33dcShfuecks
35de369923SAndreas Gohr    /** @inheritdoc */
36*faf3f01bSAndreas Gohr    public function document_end()
37*faf3f01bSAndreas Gohr    {
386b7b33dcShfuecks        $this->doc = $this->sum_summary;
396b7b33dcShfuecks        $this->doc .= DOKU_LF . '</div>' . DOKU_LF;
406b7b33dcShfuecks    }
416b7b33dcShfuecks
42de369923SAndreas Gohr    /** @inheritdoc */
43*faf3f01bSAndreas Gohr    public function header($text, $level, $pos)
44*faf3f01bSAndreas Gohr    {
456b7b33dcShfuecks        if (!$this->sum_pageTitle) {
466b7b33dcShfuecks            $this->info['sum_pagetitle'] = $text;
4744881bd0Shenning.noren            $this->sum_pageTitle = true;
486b7b33dcShfuecks        }
496b7b33dcShfuecks        $this->doc .= DOKU_LF . '<h' . $level . '>';
506b7b33dcShfuecks        $this->doc .= $this->_xmlEntities($text);
516b7b33dcShfuecks        $this->doc .= "</h$level>" . DOKU_LF;
526b7b33dcShfuecks    }
536b7b33dcShfuecks
54de369923SAndreas Gohr    /** @inheritdoc */
55*faf3f01bSAndreas Gohr    public function section_open($level)
56*faf3f01bSAndreas Gohr    {
576b7b33dcShfuecks        if ($this->sum_capture) {
5844881bd0Shenning.noren            $this->sum_inSection = true;
596b7b33dcShfuecks        }
606b7b33dcShfuecks    }
616b7b33dcShfuecks
62de369923SAndreas Gohr    /** @inheritdoc */
63*faf3f01bSAndreas Gohr    public function section_close()
64*faf3f01bSAndreas Gohr    {
656b7b33dcShfuecks        if ($this->sum_capture && $this->sum_inSection) {
666b7b33dcShfuecks            $this->sum_summary .= $this->doc;
6744881bd0Shenning.noren            $this->sum_capture = false;
686b7b33dcShfuecks        }
696b7b33dcShfuecks    }
706b7b33dcShfuecks
71de369923SAndreas Gohr    /** @inheritdoc */
72*faf3f01bSAndreas Gohr    public function p_open()
73*faf3f01bSAndreas Gohr    {
746b7b33dcShfuecks        if ($this->sum_capture && $this->sum_paragraphs < 2) {
756b7b33dcShfuecks            $this->sum_paragraphs++;
766b7b33dcShfuecks        }
776b7b33dcShfuecks        parent:: p_open();
786b7b33dcShfuecks    }
796b7b33dcShfuecks
80de369923SAndreas Gohr    /** @inheritdoc */
81*faf3f01bSAndreas Gohr    public function p_close()
82*faf3f01bSAndreas Gohr    {
836b7b33dcShfuecks        parent:: p_close();
846b7b33dcShfuecks        if ($this->sum_capture && $this->sum_paragraphs >= 2) {
856b7b33dcShfuecks            $this->sum_summary .= $this->doc;
8644881bd0Shenning.noren            $this->sum_capture = false;
876b7b33dcShfuecks        }
886b7b33dcShfuecks    }
896b7b33dcShfuecks
906b7b33dcShfuecks}
916b7b33dcShfuecks
926b7b33dcShfuecks
93e3776c06SMichael Hamann//Setup VIM: ex: et ts=2 :
94