1<?php
2/**
3 * Imageflow Plugin
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     i-net software <tools@inetsoftware.de>
7 * @author     Gerry Weissbach <gweissbach@inetsoftware.de>
8 */
9
10if(!defined('DOKU_INC')) die();
11if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
12
13require_once(DOKU_PLUGIN.'syntax.php');
14
15class syntax_plugin_layeranimation_layer extends DokuWiki_Syntax_Plugin {
16
17    function getType(){ return 'layer';}
18    function getAllowedTypes() { return array('item'); }
19    function getPType(){ return 'block';}
20
21    /**
22     * Where to sort in?
23     */
24    function getSort(){ return 301; }
25
26    /**
27     * Connect pattern to lexer
28     */
29    function connectTo($mode) {
30      $this->Lexer->addEntryPattern('<layer>(?=.*?</layer>)',$mode,'plugin_layeranimation_layer');
31      $this->Lexer->addEntryPattern('<layer .+?>(?=.*?</layer>)',$mode,'plugin_layeranimation_layer');
32    }
33
34    function postConnect() {
35      $this->Lexer->addExitPattern('</layer.*?>', 'plugin_layeranimation_layer');
36    }
37
38    /**
39     * Handle the match
40     */
41    function handle($match, $state, $pos, Doku_Handler $handler){
42
43        switch ($state) {
44            case DOKU_LEXER_ENTER:
45
46                $option = explode(' ', substr($match, 6, -1));
47                return array('layer__start', $option);
48                break;
49
50            case DOKU_LEXER_EXIT:
51
52                return array('layer__end', null);
53                break;
54        }
55        return false;
56    }
57
58    /**
59    * Create output
60    */
61    function render($mode, Doku_Renderer $renderer, $input) {
62        global $conf;
63        if($mode == 'xhtml'){
64
65            $renderer->nocache();
66
67            list($instr, $data) = $input;
68
69            switch ( $instr ) {
70
71                case 'layer__start' :
72
73                    $CSSoption = '';
74                    $TIMING = 'timing="7"';
75                    foreach ( $data as $item ) {
76
77                        if ( substr($item, -1) == 's' && is_int(intval(substr($item, 0, -1))) )
78                        {
79                            $TIMING = 'timing="' . intval(substr($item, 0, -1)) . '"';
80                        }
81
82                        $CSSoption .= ' ' . hsc(trim($item));
83                    }
84
85                    if ( intval($conf['layeranimation']['currentanimation']['height']) > 0 )
86                    {
87                        $renderer->doc .= '<div type="layer" class="layer' . $CSSoption . '" style="height: ' . $conf['layeranimation']['currentanimation']['height'] . 'px" ' . $TIMING . '>' . "\n";
88                    } else {
89                        $renderer->doc .= '<div type="layer" class="layer' . $CSSoption . '" ' . $TIMING . '>' . "\n";
90                    }
91
92                    break;
93                case 'layer__end' :
94
95                    $renderer->doc .= '</div>' . "\n\n";
96
97                    break;
98                default :
99                    return false;
100            }
101            return true;
102        }
103        return false;
104    }
105}
106
107//Setup VIM: ex: et ts=4 enc=utf-8 :
108