1<?php 2// must be run within DokuWiki 3if (!defined('DOKU_INC')) die(); 4 5/** 6 * All DokuWiki plugins to extend the parser/rendering mechanism 7 * need to inherit from this class 8 */ 9class syntax_plugin_ireadit_ireadit extends DokuWiki_Syntax_Plugin 10{ 11 function getPType() 12 { 13 return 'block'; 14 } 15 16 function getType() 17 { 18 return 'substition'; 19 } 20 21 function getSort() 22 { 23 return 99; 24 } 25 26 function connectTo($mode) 27 { 28 $this->Lexer->addSpecialPattern('~~IREADIT.*?~~', $mode, 'plugin_ireadit_ireadit'); 29 } 30 31 function handle($match, $state, $pos, Doku_Handler $handler) 32 { 33 $match = trim(substr($match, strlen('~~IREADIT'), -2)); 34 $splits = preg_split('/[\s:]+/', $match, -1, PREG_SPLIT_NO_EMPTY); 35 36 $users = []; 37 $groups = []; 38 foreach ($splits as $split) { 39 if ($split[0] == '@') { 40 $group = substr($split, 1); 41 $groups[] = $group; 42 } else { 43 $users[] = $split; 44 } 45 } 46 47 return ['users' => $users, 'groups' => $groups]; 48 } 49 50 /** 51 * Render xhtml output or metadata 52 * 53 * @param string $mode Renderer mode (supported modes: xhtml) 54 * @param Doku_Renderer $renderer The renderer 55 * @param array $data The data from the handler() function 56 * 57 * @return bool If rendering was successful. 58 */ 59 60 public function render($mode, Doku_Renderer $renderer, $data) 61 { 62 if (!$data) { 63 return false; 64 } 65 66 $method = "render_$mode"; 67 if (method_exists($this, $method)) { 68 call_user_func([$this, $method], $renderer, $data); 69 return true; 70 } 71 return false; 72 } 73 74 /** 75 * Render metadata 76 * 77 * @param Doku_Renderer $renderer The renderer 78 * @param array $data The data from the handler() function 79 */ 80 public function render_metadata(Doku_Renderer $renderer, $data) 81 { 82 $plugin_name = $this->getPluginName(); 83 $renderer->meta['plugin'][$plugin_name] = $data; 84 } 85} 86