xref: /plugin/include/syntax/wrap.php (revision 12772492a784cfa5ad91a8b947fde38a10c0b118)
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, &$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, &$renderer, $data) {
34        if ($mode == 'xhtml') {
35            switch($data[0]) {
36                case 'open':
37                    if ($data[2]) { // $data[2] = $flags['redirect']
38                        $renderer->startSectionEdit(0, 'plugin_include_start', $data[1]);
39                    } else {
40                        $renderer->startSectionEdit(0, 'plugin_include_start_noredirect', $data[1]);
41                    }
42                    $renderer->finishSectionEdit();
43                    // Start a new section with type != section so headers in the included page
44                    // won't print section edit buttons of the parent page
45                    $renderer->startSectionEdit(0, 'plugin_include_end', $data[1]);
46                    $renderer->doc .= '<div class="plugin_include_content plugin_include__' . $data[1] . '">' . DOKU_LF;
47                    break;
48                case 'close':
49                    $renderer->finishSectionEdit();
50                    $renderer->doc .= '</div>' . DOKU_LF;
51                    break;
52            }
53            return true;
54        }
55        return false;
56    }
57}
58// vim:ts=4:sw=4:et:
59