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_animation extends DokuWiki_Syntax_Plugin { 16 17 function getType(){ return 'container';} 18 function getAllowedTypes() { return array('layer'); } 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('<animation>(?=.*?</animation>)',$mode,'plugin_layeranimation_animation'); 31 $this->Lexer->addEntryPattern('<animation .+?>(?=.*?</animation>)',$mode,'plugin_layeranimation_animation'); 32 } 33 34 function postConnect() { 35 $this->Lexer->addExitPattern('</animation.*?>', 'plugin_layeranimation_animation'); 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 = array( 'height' => '200' ); 47 foreach ( explode(' ', substr($match, 11, -1)) as $item ) { 48 $isNumeric = is_numeric($item); 49 if ( $isNumeric || preg_match("/.*?(vw|vh|em)$/", $item) ) { 50 if ( $isNumeric ) { 51 $item = $item . 'px'; 52 } 53 54 $option['height'] = hsc($item); 55 } else { 56 $option['class'] .= ' ' . hsc($item); 57 } 58 } 59 60 return array('animation__start', $option, $pos); 61 break; 62 63 case DOKU_LEXER_EXIT: 64 65 return array('animation__end', null, $pos + strlen($match)); 66 break; 67 } 68 return false; 69 } 70 71 /** 72 * Create output 73 */ 74 function render($mode, Doku_Renderer $renderer, $input) { 75 global $conf; 76 if($mode == 'xhtml'){ 77 78 $renderer->nocache(); 79 80 list($instr, $data, $pos) = $input; 81 82 switch ( $instr ) { 83 84 case 'animation__start' : 85 86 $conf['layeranimation']['currentanimation']['height'] = $data['height']; 87 $renderer->doc .= '<noscript><div class="layeranimation_disabled"></div></noscript>'; 88 $renderer->doc .= '<div class="layeranimation' . $data['class'] . ' noscripting' . (method_exists($renderer, "finishSectionEdit") ? ' ' . $renderer->startSectionEdit($pos, array( 'target' => 'section', 'name' => 'layeranimation')) : "") . '" style="height: ' . $data['height'] . '">' . "\n"; 89 90 break; 91 case 'animation__end' : 92 93 $renderer->doc .= '</div>' . "\n"; 94 $renderer->doc .= '<div class="clearer"></div>' . "\n"; 95 if ( method_exists($renderer, "finishSectionEdit") ) { $renderer->finishSectionEdit($pos); } 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