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_phosphor_phitem extends DokuWiki_Syntax_Plugin { 16 17 /** 18 * return some info 19 */ 20 function getInfo(){ 21 return array_merge(confToHash(dirname(__FILE__).'/info.txt'), array( 22 'name' => 'PhosPhor - Block Item', 23 )); 24 } 25 26 function getType(){ return 'phitem';} 27 function getAllowedTypes() { return array('container','substition','protected','disabled','formatting','paragraphs'); } 28 function getPType(){ return 'block';} 29 30 /** 31 * Where to sort in? 32 */ 33 function getSort(){ return 301; } 34 35 /** 36 * Connect pattern to lexer 37 */ 38 function connectTo($mode) { 39 $this->Lexer->addEntryPattern('<item>(?=.*?</item>)',$mode,'plugin_phosphor_phitem'); 40 $this->Lexer->addEntryPattern('<item .+?>(?=.*?</item>)',$mode,'plugin_phosphor_phitem'); 41 } 42 43 function postConnect() { 44 $this->Lexer->addExitPattern('</item.*?>', 'plugin_phosphor_phitem'); 45 } 46 47 /** 48 * Handle the match 49 */ 50 function handle($match, $state, $pos, Doku_Handler $handler){ 51 52 switch ($state) { 53 case DOKU_LEXER_ENTER: 54 55 list($id, $title) = explode('|', substr($match, 6, -1), 2); // find ID/Params + Name Extension 56 list($id, $paramlist) = explode('?', $id, 2); // find ID + Params 57 58 $params = array(); 59 foreach(explode('&', $paramlist) as $param) 60 { 61 list($n, $v) = explode('=', $param); 62 $params[$n] = trim($v); 63 } 64 65 return array('item__start', array($id, $title, $params)); 66 break; 67 68 case DOKU_LEXER_UNMATCHED: 69 70 $handler->_addCall('cdata',array($match), $pos); 71 return false; 72 break; 73 case DOKU_LEXER_EXIT: 74 75 return array('item__end', null); 76 break; 77 } 78 return false; 79 } 80 81 /** 82 * Create output 83 */ 84 function render($mode, Doku_Renderer $renderer, $input) { 85 global $conf; 86 if($mode == 'xhtml'){ 87 88 $renderer->nocache(); 89 90 list($instr, $data) = $input; 91 92 switch ( $instr ) { 93 94 case 'item__start' : 95 96 list($id, $title, $params) = $data; 97 $renderer->doc .= '<div class="phitem">' . "\n"; 98 if ( $title ) { 99 $renderer->doc .= '<p class="phhead">' . hsc($title) . '</p>'; 100 } 101 102 $functions =& plugin_load('syntax', 'phosphor_phosphor' ); 103 $renderer->doc .= $functions->phosphorContent($renderer, $data, true, 'phosphor'); 104 105 break; 106 case 'item__end' : 107 108 $renderer->doc .= '</div>' . "\n"; 109 110 break; 111 default : 112 return false; 113 } 114 return true; 115 } 116 return false; 117 } 118} 119 120//Setup VIM: ex: et ts=4 enc=utf-8 : 121