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 return ['users' => $users, 'groups' => $groups]; 47 } 48 49 /** 50 * Render xhtml output or metadata 51 * 52 * @param string $mode Renderer mode (supported modes: xhtml) 53 * @param Doku_Renderer $renderer The renderer 54 * @param array $data The data from the handler() function 55 * 56 * @return bool If rendering was successful. 57 */ 58 59 public function render($mode, Doku_Renderer $renderer, $data) 60 { 61 if (!$data) { 62 return false; 63 } 64 65 $method = "render_$mode"; 66 if (method_exists($this, $method)) { 67 call_user_func([$this, $method], $renderer, $data); 68 return true; 69 } 70 return false; 71 } 72 73 /** 74 * Render metadata 75 * 76 * @param Doku_Renderer $renderer The renderer 77 * @param array $data The data from the handler() function 78 */ 79 public function render_metadata(Doku_Renderer $renderer, $data) 80 { 81 // add version number to avoid conflict with historical metadata 82 $renderer->meta['plugin_ireadit=0.2'] = $data; 83 } 84} 85