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_item extends DokuWiki_Syntax_Plugin {
16
17    function getType(){ return 'item';}
18    function getAllowedTypes() { return array('container','substition','protected','disabled','formatting','paragraphs'); }
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('<item>(?=.*?</item>)',$mode,'plugin_layeranimation_item');
31      $this->Lexer->addEntryPattern('<item .+?>(?=.*?</item>)',$mode,'plugin_layeranimation_item');
32    }
33
34    function postConnect() {
35      $this->Lexer->addExitPattern('</item.*?>', 'plugin_layeranimation_item');
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                list ($option, $clip) = explode('?', substr($match, 6, -1), 2);
47
48                return array('item__start', array('option' => explode(' ', $option), 'clip' => explode(':', $clip)));
49                break;
50
51            case DOKU_LEXER_UNMATCHED:
52
53                $handler->_addCall('cdata',array($match), $pos);
54                return false;
55                break;
56            case DOKU_LEXER_EXIT:
57
58                return array('item__end', null);
59            break;
60        }
61        return false;
62    }
63
64    /**
65    * Create output
66    */
67    function render($mode, Doku_Renderer $renderer, $input) {
68        global $conf;
69        if($mode == 'xhtml'){
70
71            $renderer->nocache();
72
73            list($instr, $data) = $input;
74
75            switch ( $instr ) {
76
77                case 'item__start' :
78
79                    $CSSOption = '';
80                    $ClassOption = '';
81                    $ClipOption = array();
82                    foreach ( $data['option'] as $item ) {
83
84                       $subItem = explode(':', $item, 2);
85                       if ( count($subItem) == 1 )
86                       {
87                           $ClassOption .= ' ' . hsc(trim($item));
88                       } else {
89                           $CSSOption .= ' ' . hsc(trim($item));
90                       }
91
92                    }
93
94                    foreach ( $data['clip'] as $item ) {
95                        $item = hsc(trim($item));
96                        if ( $item == 'auto' )
97                            $ClipOption[] = $item;
98                        else if ( is_numeric($item) )
99                            $ClipOption[] = intval($item) . 'px';
100                    }
101
102                    if ( !empty($ClipOption) && count($ClipOption) == 4 ) {
103                        $ClipOption = 'clip:rect(' . implode(',', $ClipOption) . ');';
104                    } else $ClipOption = '';
105
106                    $renderer->doc .= '<div class="item' . $ClassOption . '" style="' . $ClipOption . $CSSOption . '">' . "\n";
107
108                    break;
109                case 'item__end' :
110
111                    $renderer->doc .= '</div>' . "\n";
112
113                    break;
114                default :
115                    return false;
116            }
117            return true;
118        }
119        return false;
120    }
121}
122
123//Setup VIM: ex: et ts=4 enc=utf-8 :
124