xref: /plugin/include/syntax/wrap.php (revision 83d8bead9c154c952bf7cc14f2397211607699ee)
1<?php
2/**
3 * Include plugin (wrapper component)
4 *
5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author  Michael Klier <chi@chimeric.de>
7 * @author  Michael Hamann <michael@content-space.de>
8 */
9
10if (!defined('DOKU_INC')) die('must be used inside DokuWiki');
11
12class syntax_plugin_include_wrap extends DokuWiki_Syntax_Plugin {
13
14    function getType() {
15        return 'formatting';
16    }
17
18    function getSort() {
19        return 50;
20    }
21
22    function handle($match, $state, $pos, Doku_Handler $handler) {
23        // this is a syntax plugin that doesn't offer any syntax, so there's nothing to handle by the parser
24    }
25
26    /**
27     * Wraps the included page in a div and writes section edits for the action component
28     * so it can detect where an included page starts/ends.
29     *
30     * @author Michael Klier <chi@chimeric.de>
31     * @author Michael Hamann <michael@content-space.de>
32     */
33    function render($mode, Doku_Renderer $renderer, $data) {
34        if ($mode == 'xhtml') {
35            list($state, $page, $redirect, $secid) = $data;
36            switch($state) {
37                case 'open':
38                    if ($redirect) {
39                        $renderer->startSectionEdit(0, 'plugin_include_start', $page);
40                    } else {
41                        $renderer->startSectionEdit(0, 'plugin_include_start_noredirect', $page);
42                    }
43                    $renderer->finishSectionEdit();
44                    // Start a new section with type != section so headers in the included page
45                    // won't print section edit buttons of the parent page
46                    $renderer->startSectionEdit(0, 'plugin_include_end', $page);
47                    if ($secid === NULL) {
48                        $id = '';
49                    } else {
50                        $id = ' id="'.$secid.'"';
51                    }
52                    $renderer->doc .= '<div class="plugin_include_content plugin_include__' . $page .'"'.$id.'>' . DOKU_LF;
53                    if (is_a($renderer,'renderer_plugin_dw2pdf')) {
54                        $renderer->doc .= '<a name="'.$secid.'" />';
55                    }
56                    break;
57                case 'close':
58                    $renderer->finishSectionEdit();
59                    $renderer->doc .= '</div>' . DOKU_LF;
60                    break;
61            }
62            return true;
63        }
64        return false;
65    }
66}
67// vim:ts=4:sw=4:et:
68