xref: /plugin/include/syntax/wrap.php (revision 1403dce04142d4874c515f4f0c6b9b4a88d51d29)
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'))
11    define('DOKU_INC', realpath(dirname(__FILE__) . '/../../') . '/');
12if (!defined('DOKU_PLUGIN'))
13    define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
14require_once (DOKU_PLUGIN . 'syntax.php');
15
16class syntax_plugin_include_wrap extends DokuWiki_Syntax_Plugin {
17
18    function getType() {
19        return 'formatting';
20    }
21
22    function getSort() {
23        return 50;
24    }
25
26    function handle($match, $state, $pos, &$handler) {
27        // this is a syntax plugin that doesn't offer any syntax, so there's nothing to handle by the parser
28    }
29
30    /**
31     * Wraps the included page in a div and writes section edits for the action component
32     * so it can detect where an included page starts/ends.
33     *
34     * @author Michael Klier <chi@chimeric.de>
35     * @author Michael Hamann <michael@content-space.de>
36     */
37    function render($mode, &$renderer, $data) {
38        if ($mode == 'xhtml') {
39            switch($data[0]) {
40                case 'open':
41                    if ($data[2]) { // $data[2] = $flags['redirect']
42                        $renderer->startSectionEdit(0, 'plugin_include_start', $data[1]);
43                    } else {
44                        $renderer->startSectionEdit(0, 'plugin_include_start_noredirect', $data[1]);
45                    }
46                    $renderer->finishSectionEdit();
47                    // Start a new section with type != section so headers in the included page
48                    // won't print section edit buttons of the parent page
49                    $renderer->startSectionEdit(0, 'plugin_include_end', $data[1]);
50                    $renderer->doc .= '<div class="plugin_include_content plugin_include__' . $data[1] . '">' . DOKU_LF;
51                    break;
52                case 'close':
53                    $renderer->finishSectionEdit();
54                    $renderer->doc .= '</div>' . DOKU_LF;
55                    break;
56            }
57            return true;
58        }
59        return false;
60    }
61}
62// vim:ts=4:sw=4:et:
63