1<?php 2/** 3 * DokuWiki Plugin advrack (Syntax Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Ashraf Hasson <ashraf.hasson@gmail.com> 7 */ 8 9// must be run within Dokuwiki 10if(!defined('DOKU_INC')) die(); 11//if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 12if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 13//require_once(DOKU_PLUGIN.'syntax.php'); 14 15class syntax_plugin_advrack extends DokuWiki_Syntax_Plugin { 16 /** 17 * @return string Syntax mode type 18 */ 19 public function getType() { return "protected"; } 20 /** 21 * @return string Paragraph type 22 */ 23 //public function getPType() { 24 // return 'normal'; 25 //} 26 /** 27 * @return int Sort order - Low numbers go before high numbers 28 */ 29 public function getSort() { return 999; } 30 /** 31 * Connect lookup pattern to lexer. 32 * 33 * @param string $mode Parser mode 34 */ 35 public function connectTo($mode) { $this->Lexer->addEntryPattern('<advrack>(?=.*?</advrack>)',$mode,'plugin_advrack'); } 36 37 public function postConnect() { $this->Lexer->addExitPattern('</advrack>','plugin_advrack'); } 38 39 /** 40 * Handle matches of the advrack syntax 41 * 42 * @param string $match The match of the syntax 43 * @param int $state The state of the handler 44 * @param int $pos The position in the document 45 * @param Doku_Handler $handler The handler 46 * @return array Data for the renderer 47 */ 48 public function handle($match, $state, $pos, Doku_Handler &$handler){ 49 switch ($state) { 50 case DOKU_LEXER_ENTER : return array($state, array($state, $match)); 51 case DOKU_LEXER_UNMATCHED : return array($state, $match); 52 case DOKU_LEXER_EXIT : return array($state, ''); 53 } 54 return array(); 55 } 56 57 /** 58 * Render xhtml output or metadata 59 * 60 * @param string $mode Renderer mode (supported modes: xhtml) 61 * @param Doku_Renderer $renderer The renderer 62 * @param array $data The data from the handler() function 63 * @return bool If rendering was successful. 64 */ 65 public function render($mode, Doku_Renderer &$renderer, $data) { 66 if($mode == 'xhtml') { 67 list($state,$match) = $data; 68 switch ($state) { 69 //case DOKU_LEXER_ENTER:$renderer->doc .= "<pre advrack='true' style='border: none; box-shadow: none;background-color: #fff;'>"; break; 70 case DOKU_LEXER_ENTER:$renderer->doc .= "<div class=\"advrack mediacenter\">"; break; 71 //case DOKU_LEXER_UNMATCHED: $renderer->doc .= $match; error_log("UNMATCHED: $match"); break; 72 case DOKU_LEXER_UNMATCHED: $renderer->doc .= $renderer->_xmlEntities($match); break; 73 case DOKU_LEXER_EXIT:$renderer->doc .= "</div>"; break; 74 } 75 return true; 76 } 77 return false; 78 } 79} 80 81// vim:ts=4:sw=4:et: 82