xref: /plugin/include/syntax/wrap.php (revision e2231513b73a3caeed16d3498984c72353be779b)
1fa08f439SMichael Hamann<?php
2fa08f439SMichael Hamann/**
3fa08f439SMichael Hamann * Include plugin (wrapper component)
4fa08f439SMichael Hamann *
5fa08f439SMichael Hamann * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
6fa08f439SMichael Hamann * @author  Michael Klier <chi@chimeric.de>
7fa08f439SMichael Hamann * @author  Michael Hamann <michael@content-space.de>
8fa08f439SMichael Hamann */
9fa08f439SMichael Hamann
10fa08f439SMichael Hamannclass syntax_plugin_include_wrap extends DokuWiki_Syntax_Plugin {
11fa08f439SMichael Hamann
12fa08f439SMichael Hamann    function getType() {
13fa08f439SMichael Hamann        return 'formatting';
14fa08f439SMichael Hamann    }
15fa08f439SMichael Hamann
16fa08f439SMichael Hamann    function getSort() {
17fa08f439SMichael Hamann        return 50;
18fa08f439SMichael Hamann    }
19fa08f439SMichael Hamann
204aa23dc0SGerrit Uitslag    function handle($match, $state, $pos, Doku_Handler $handler) {
21fa08f439SMichael Hamann        // this is a syntax plugin that doesn't offer any syntax, so there's nothing to handle by the parser
22fa08f439SMichael Hamann    }
23fa08f439SMichael Hamann
24fa08f439SMichael Hamann    /**
25fa08f439SMichael Hamann     * Wraps the included page in a div and writes section edits for the action component
26fa08f439SMichael Hamann     * so it can detect where an included page starts/ends.
27fa08f439SMichael Hamann     *
28fa08f439SMichael Hamann     * @author Michael Klier <chi@chimeric.de>
29fa08f439SMichael Hamann     * @author Michael Hamann <michael@content-space.de>
30fa08f439SMichael Hamann     */
314aa23dc0SGerrit Uitslag    function render($mode, Doku_Renderer $renderer, $data) {
32fa08f439SMichael Hamann        if ($mode == 'xhtml') {
33*e2231513SMichael Hamann            $state = array_shift($data);
34b0c45c90SMichael Hamann            switch($state) {
35fa08f439SMichael Hamann                case 'open':
36*e2231513SMichael Hamann                    list($page, $redirect, $secid) = $data;
37b0c45c90SMichael Hamann                    if ($redirect) {
389986c3adSMichael Hamann                        if (defined('SEC_EDIT_PATTERN')) { // for DokuWiki Greebo and more recent versions
39*e2231513SMichael Hamann                            $renderer->startSectionEdit(0, array('target' => 'plugin_include_start', 'name' => $page, 'hid' => ''));
409986c3adSMichael Hamann                        } else {
41b0c45c90SMichael Hamann                            $renderer->startSectionEdit(0, 'plugin_include_start', $page);
429986c3adSMichael Hamann                        }
439986c3adSMichael Hamann                    } else {
449986c3adSMichael Hamann                        if (defined('SEC_EDIT_PATTERN')) { // for DokuWiki Greebo and more recent versions
45*e2231513SMichael Hamann                            $renderer->startSectionEdit(0, array('target' => 'plugin_include_start_noredirect', 'name' => $page, 'hid' => ''));
46dcec2f1fSMichael Hamann                        } else {
47b0c45c90SMichael Hamann                            $renderer->startSectionEdit(0, 'plugin_include_start_noredirect', $page);
48dcec2f1fSMichael Hamann                        }
499986c3adSMichael Hamann                    }
50fa08f439SMichael Hamann                    $renderer->finishSectionEdit();
51fa08f439SMichael Hamann                    // Start a new section with type != section so headers in the included page
52fa08f439SMichael Hamann                    // won't print section edit buttons of the parent page
539986c3adSMichael Hamann                    if (defined('SEC_EDIT_PATTERN')) { // for DokuWiki Greebo and more recent versions
54*e2231513SMichael Hamann                        $renderer->startSectionEdit(0, array('target' => 'plugin_include_end', 'name' => $page, 'hid' => ''));
559986c3adSMichael Hamann                    } else {
56b0c45c90SMichael Hamann                        $renderer->startSectionEdit(0, 'plugin_include_end', $page);
579986c3adSMichael Hamann                    }
58b0c45c90SMichael Hamann                    if ($secid === NULL) {
59b0c45c90SMichael Hamann                        $id = '';
60b0c45c90SMichael Hamann                    } else {
61b0c45c90SMichael Hamann                        $id = ' id="'.$secid.'"';
62b0c45c90SMichael Hamann                    }
63b0c45c90SMichael Hamann                    $renderer->doc .= '<div class="plugin_include_content plugin_include__' . $page .'"'.$id.'>' . DOKU_LF;
64b0c45c90SMichael Hamann                    if (is_a($renderer,'renderer_plugin_dw2pdf')) {
65b0c45c90SMichael Hamann                        $renderer->doc .= '<a name="'.$secid.'" />';
66b0c45c90SMichael Hamann                    }
67fa08f439SMichael Hamann                    break;
68fa08f439SMichael Hamann                case 'close':
69fa08f439SMichael Hamann                    $renderer->finishSectionEdit();
70fa08f439SMichael Hamann                    $renderer->doc .= '</div>' . DOKU_LF;
71fa08f439SMichael Hamann                    break;
72fa08f439SMichael Hamann            }
73fa08f439SMichael Hamann            return true;
74fa08f439SMichael Hamann        }
75fa08f439SMichael Hamann        return false;
76fa08f439SMichael Hamann    }
77fa08f439SMichael Hamann}
78fa08f439SMichael Hamann// vim:ts=4:sw=4:et:
79