1<?php
2/**
3 *
4 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
5 * @author     Dan Kreiser <dan.kreiser@gmail.com>
6 */
7if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
8if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
9require_once(DOKU_PLUGIN.'syntax.php');
10
11class syntax_plugin_cssmenu extends DokuWiki_Syntax_Plugin {
12
13    function getInfo(){
14        return array(
15            'author' => 'Dan Kreiser',
16            'email'  => 'dan-kreiser@gmail.com',
17            'date'   => '2010-04-19',
18            'name'   => 'cssmenu',
19            'desc'   => 'creates a nice hover menu using css',
20            'url'    => 'http://www.tux-tips.de/tux-wiki/doku.php?id=start:dokuwiki:plugins',
21        );
22		}
23
24    function getType(){ return 'formatting';}
25    function getAllowedTypes() { return array('container', 'baseonly', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs'); }
26    function getPType(){ return 'block';}
27    function getSort(){ return 196; }
28
29    /**
30     * Connect pattern to lexer
31     */
32    function connectTo($mode) {
33        $this->Lexer->addEntryPattern('<cssmenu.*?>(?=.*?</cssmenu>)',$mode,'plugin_cssmenu');
34    }
35
36    function postConnect() {
37        $this->Lexer->addExitPattern('</cssmenu>', 'plugin_cssmenu');
38    }
39
40    /**
41     * Handle the match
42     */
43    function handle($match, $state, $pos, &$handler){
44        switch ($state) {
45            case DOKU_LEXER_ENTER:
46                $data = strtolower(trim(substr($match,5,-1)));
47                return array($state, $data);
48
49            case DOKU_LEXER_UNMATCHED :
50                return array($state, $match);
51
52            case DOKU_LEXER_EXIT :
53                return array($state, '');
54        }
55        return false;
56    }
57
58    /**
59     * Create output
60     */
61    function render($mode, &$renderer, $indata) {
62
63        if (empty($indata)) return false;
64        list($state, $data) = $indata;
65
66        if($mode == 'xhtml'){
67            switch ($state) {
68                case DOKU_LEXER_ENTER:
69					$renderer->doc .= '<div class="cssmenu">';
70                    break;
71
72                case DOKU_LEXER_UNMATCHED:
73                    $renderer->doc .= $renderer->_xmlEntities($data);
74                    break;
75
76                case DOKU_LEXER_EXIT:
77                    $renderer->doc .= "</div>";
78                    break;
79            }
80            return true;
81        }
82        return false;
83    }
84
85
86}
87
88