xref: /plugin/siteexport/syntax/toctools.php (revision 7462771189df6f2c2af9010eb8746ad2e13be7d1)
1300ce4a2SGerry Weißbach<?php
2300ce4a2SGerry Weißbach/**
3300ce4a2SGerry Weißbach * Siteexport Plugin
4300ce4a2SGerry Weißbach *
5300ce4a2SGerry Weißbach * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6300ce4a2SGerry Weißbach * @author     i-net software <tools@inetsoftware.de>
7300ce4a2SGerry Weißbach * @author     Gerry Weissbach <gweissbach@inetsoftware.de>
8300ce4a2SGerry Weißbach */
9300ce4a2SGerry Weißbach
10a8c17ab5Si-net /// softwareif (!defined('DOKU_INC')) define('DOKU_INC', /** @scrutinizer ignore-type */ realpath(dirname(__FILE__) . '/../../') . '/');
11300ce4a2SGerry Weißbachif (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
12300ce4a2SGerry Weißbachrequire_once(DOKU_PLUGIN . 'syntax.php');
13300ce4a2SGerry Weißbach
14300ce4a2SGerry Weißbach/**
15300ce4a2SGerry Weißbach * All DokuWiki plugins to extend the parser/rendering mechanism
16300ce4a2SGerry Weißbach * need to inherit from this class
17300ce4a2SGerry Weißbach */
18300ce4a2SGerry Weißbachclass syntax_plugin_siteexport_toctools extends DokuWiki_Syntax_Plugin {
19300ce4a2SGerry Weißbach
20*74627711SGerry Weißbach    protected $special_pattern = '<mergehint\b[^>\r\n]*?/>';
21*74627711SGerry Weißbach    protected $entry_pattern   = '<mergehint\b.*?>(?=.*?</mergehint>)';
22*74627711SGerry Weißbach    protected $exit_pattern    = '</mergehint>';
23300ce4a2SGerry Weißbach
24*74627711SGerry Weißbach    function getType(){ return 'substition';}
25*74627711SGerry Weißbach    function getAllowedTypes() { return array('container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs'); }
26*74627711SGerry Weißbach    function getPType(){ return 'stack';}
27*74627711SGerry Weißbach    function getSort(){ return 999; }
28300ce4a2SGerry Weißbach
29300ce4a2SGerry Weißbach    /**
30300ce4a2SGerry Weißbach     * Connect pattern to lexer
31300ce4a2SGerry Weißbach     */
32*74627711SGerry Weißbach    function connectTo($mode) {
33*74627711SGerry Weißbach        $this->Lexer->addSpecialPattern($this->special_pattern,$mode,'plugin_siteexport_toctools');
34*74627711SGerry Weißbach        $this->Lexer->addEntryPattern($this->entry_pattern,$mode,'plugin_siteexport_toctools');
35*74627711SGerry Weißbach    }
36*74627711SGerry Weißbach
37*74627711SGerry Weißbach    function postConnect() {
38*74627711SGerry Weißbach        $this->Lexer->addExitPattern($this->exit_pattern, 'plugin_siteexport_toctools');
39300ce4a2SGerry Weißbach    }
40300ce4a2SGerry Weißbach
41300ce4a2SGerry Weißbach    /**
42300ce4a2SGerry Weißbach     * Handle the match
43300ce4a2SGerry Weißbach     */
44*74627711SGerry Weißbach    function handle($match, $state, $pos, Doku_Handler $handler){
45*74627711SGerry Weißbach        global $conf;
46*74627711SGerry Weißbach        switch ($state) {
47*74627711SGerry Weißbach            case DOKU_LEXER_ENTER:
48*74627711SGerry Weißbach            case DOKU_LEXER_SPECIAL:
49*74627711SGerry Weißbach                $data = trim(substr($match,strpos($match,' '),-1)," \t\n/");
50*74627711SGerry Weißbach
51*74627711SGerry Weißbach                // print "<pre>"; print_r($handler); print "</pre>";
52*74627711SGerry Weißbach
53*74627711SGerry Weißbach                if ($handler->status['section']) {
54*74627711SGerry Weißbach                    $handler->_addCall('section_close',array(),$pos);
55*74627711SGerry Weißbach                }
56*74627711SGerry Weißbach
57*74627711SGerry Weißbach                return array('mergehint', 'start', $data, sectionid( $data ));
58*74627711SGerry Weißbach
59*74627711SGerry Weißbach            case DOKU_LEXER_UNMATCHED:
60*74627711SGerry Weißbach                $handler->_addCall('cdata', array($match), $pos);
61*74627711SGerry Weißbach                break;
62*74627711SGerry Weißbach
63*74627711SGerry Weißbach            case DOKU_LEXER_EXIT:
64*74627711SGerry Weißbach
65*74627711SGerry Weißbach                $level = 1;
66*74627711SGerry Weißbach                foreach( array_reverse( $handler->calls ) as $call ) {
67*74627711SGerry Weißbach                    if ( $calls[0] == 'section_open' ) {
68*74627711SGerry Weißbach                        $level = $calls[1][0];
69*74627711SGerry Weißbach                        break;
70*74627711SGerry Weißbach                    }
71*74627711SGerry Weißbach                }
72*74627711SGerry Weißbach
73*74627711SGerry Weißbach                // We need to add the current plugin first and then open the section again.
74*74627711SGerry Weißbach                $handler->_addCall('plugin',array('siteexport_toctools', array('mergehint', 'end', 'syntax'),DOKU_LEXER_EXIT),$pos);
75*74627711SGerry Weißbach                $handler->_addCall('section_open',array($level),$pos+strlen($match));
76*74627711SGerry Weißbach        }
77*74627711SGerry Weißbach        return false;
78300ce4a2SGerry Weißbach    }
79300ce4a2SGerry Weißbach
80300ce4a2SGerry Weißbach    /**
81300ce4a2SGerry Weißbach     * Create output
82300ce4a2SGerry Weißbach     */
83a8c17ab5Si-net /// software    public function render($mode, Doku_Renderer $renderer, $data) {
84300ce4a2SGerry Weißbach        if ($mode == 'xhtml') {
85300ce4a2SGerry Weißbach            list( $type, $pos, $title, $id ) = $data;
86300ce4a2SGerry Weißbach            if ( $type == 'mergehint' ) {
87300ce4a2SGerry Weißbach                if ( $pos == 'start' ) {
88300ce4a2SGerry Weißbach                    $renderer->doc .= '<!-- MergeHint Start for "' . $title . '" -->';
8906a81c5cSGerry Weißbach                    $renderer->doc .= '<div id="' . $id . '" class="siteexport mergehintwrapper"><aside class="mergehint">' . $title . '</aside><div class="mergehintcontent">';
90300ce4a2SGerry Weißbach                } else {
9106a81c5cSGerry Weißbach                    $renderer->doc .= '</div></div>';
92300ce4a2SGerry Weißbach                    $renderer->doc .= '<!-- MergeHint End for "' . $title . '" -->';
93300ce4a2SGerry Weißbach                }
94300ce4a2SGerry Weißbach            } else {
95300ce4a2SGerry Weißbach                $renderer->doc .= "<br style=\"page-break-after:always;\" />";
96300ce4a2SGerry Weißbach            }
97300ce4a2SGerry Weißbach            return true;
98300ce4a2SGerry Weißbach        }
99300ce4a2SGerry Weißbach        return false;
100300ce4a2SGerry Weißbach    }
101300ce4a2SGerry Weißbach}
102300ce4a2SGerry Weißbach
103300ce4a2SGerry Weißbach//Setup VIM: ex: et ts=4 enc=utf-8 :