1<?php 2class syntax_plugin_custommeta extends DokuWiki_Syntax_Plugin 3{ 4 function getType() 5 { 6 return 'substition'; 7 } 8 9 function getSort() 10 { 11 return 35; 12 } 13 14 function connectTo($mode) 15 { 16 $this->Lexer->addSpecialPattern('\+\+CMV:.*?\+\+',$mode,'plugin_custommeta'); 17 $this->Lexer->addSpecialPattern('\+\+CMI:.*?\+\+',$mode,'plugin_custommeta'); 18 } 19 20 public function handle($match, $state, $pos, Doku_Handler $handler) 21 { 22 23 $match = substr($match,4,-2); 24 $pairs = explode(':', $match); 25 $mode = trim($pairs[0]); 26 $key = trim($pairs[1]); 27 $value = trim($pairs[2]); 28 if (strlen($key) >= 1 && strlen($value) >1 && ( $mode == 'I' || $mode == 'V' )) { 29 $data['mode'] = $mode; 30 $data['key'] = $key; 31 $data['value'] = $value; 32 $data['dataType'] = isset($pairs[3]) ? trim($pairs[3]) : 's'; 33 } 34 return $data; 35 } 36 37 public function render($mode, Doku_Renderer $renderer, $data) 38 { 39 if ($mode == 'xhtml') { 40 if ($data['mode'] == 'V') { 41 $renderer->doc .= $data['value']; 42 } 43 } elseif ($mode == 'metadata') { 44 if ($data['dataType'] == 'i') { 45 $renderer->meta['custommeta'][$data['key']] = intval($data['value']); 46 } elseif ($data['dataType'] == 'd') { 47 $auxDateTime = new DateTime($data['value']); 48 $renderer->meta['custommeta'][$data['key']] = $auxDateTime->getTimestamp(); 49 } else { 50 $renderer->meta['custommeta'][$data['key']] = $data['value']; 51 } 52 } 53 54 } 55} 56 57