1549a0837SAndreas Gohr<?php 2549a0837SAndreas Gohr/** 3549a0837SAndreas Gohr * DokuWiki Plugin struct (Syntax Component) 4549a0837SAndreas Gohr * 5549a0837SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6549a0837SAndreas Gohr * @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de> 7549a0837SAndreas Gohr */ 8549a0837SAndreas Gohr 907993756SAndreas Gohr 1007993756SAndreas Gohruse plugin\struct\meta\AggregationTable; 115511bd5bSAndreas Gohruse plugin\struct\meta\ConfigParser; 125511bd5bSAndreas Gohruse plugin\struct\meta\SearchConfig; 135511bd5bSAndreas Gohruse plugin\struct\meta\StructException; 1415929be2SAndreas Gohr 1507993756SAndreas Gohr// must be run within Dokuwiki 16549a0837SAndreas Gohrif (!defined('DOKU_INC')) die(); 17549a0837SAndreas Gohr 18549a0837SAndreas Gohrclass syntax_plugin_struct_table extends DokuWiki_Syntax_Plugin { 19549a0837SAndreas Gohr /** 20549a0837SAndreas Gohr * @return string Syntax mode type 21549a0837SAndreas Gohr */ 22549a0837SAndreas Gohr public function getType() { 2315929be2SAndreas Gohr return 'substition'; 24549a0837SAndreas Gohr } 25549a0837SAndreas Gohr /** 26549a0837SAndreas Gohr * @return string Paragraph type 27549a0837SAndreas Gohr */ 28549a0837SAndreas Gohr public function getPType() { 2915929be2SAndreas Gohr return 'block'; 30549a0837SAndreas Gohr } 31549a0837SAndreas Gohr /** 32549a0837SAndreas Gohr * @return int Sort order - Low numbers go before high numbers 33549a0837SAndreas Gohr */ 34549a0837SAndreas Gohr public function getSort() { 355511bd5bSAndreas Gohr return 155; 36549a0837SAndreas Gohr } 37549a0837SAndreas Gohr 38549a0837SAndreas Gohr /** 39549a0837SAndreas Gohr * Connect lookup pattern to lexer. 40549a0837SAndreas Gohr * 41549a0837SAndreas Gohr * @param string $mode Parser mode 42549a0837SAndreas Gohr */ 43549a0837SAndreas Gohr public function connectTo($mode) { 445511bd5bSAndreas Gohr $this->Lexer->addSpecialPattern('----+ *struct table *-+\n.*?\n----+', $mode, 'plugin_struct_table'); 45549a0837SAndreas Gohr } 46549a0837SAndreas Gohr 47549a0837SAndreas Gohr 48549a0837SAndreas Gohr /** 49549a0837SAndreas Gohr * Handle matches of the struct syntax 50549a0837SAndreas Gohr * 51549a0837SAndreas Gohr * @param string $match The match of the syntax 52549a0837SAndreas Gohr * @param int $state The state of the handler 53549a0837SAndreas Gohr * @param int $pos The position in the document 54549a0837SAndreas Gohr * @param Doku_Handler $handler The handler 55549a0837SAndreas Gohr * @return array Data for the renderer 56549a0837SAndreas Gohr */ 57ab466032SAndreas Gohr public function handle($match, $state, $pos, Doku_Handler $handler){ 58*bd363da9SAndreas Gohr global $conf; 59549a0837SAndreas Gohr 605511bd5bSAndreas Gohr $lines = explode("\n", $match); 615511bd5bSAndreas Gohr array_shift($lines); 625511bd5bSAndreas Gohr array_pop($lines); 635511bd5bSAndreas Gohr 645511bd5bSAndreas Gohr try { 655511bd5bSAndreas Gohr $parser = new ConfigParser($lines); 665511bd5bSAndreas Gohr return $parser->getConfig(); 675511bd5bSAndreas Gohr } catch (StructException $e) { 685511bd5bSAndreas Gohr msg($e->getMessage(), -1, $e->getLine(), $e->getFile()); 69*bd363da9SAndreas Gohr if($conf['allowdebug']) msg('<pre>'.hsc($e->getTraceAsString()).'</pre>', -1); 705511bd5bSAndreas Gohr return null; 715511bd5bSAndreas Gohr } 72549a0837SAndreas Gohr } 73549a0837SAndreas Gohr 74549a0837SAndreas Gohr /** 75549a0837SAndreas Gohr * Render xhtml output or metadata 76549a0837SAndreas Gohr * 77549a0837SAndreas Gohr * @param string $mode Renderer mode (supported modes: xhtml) 78549a0837SAndreas Gohr * @param Doku_Renderer $renderer The renderer 79549a0837SAndreas Gohr * @param array $data The data from the handler() function 80549a0837SAndreas Gohr * @return bool If rendering was successful. 81549a0837SAndreas Gohr */ 82ab466032SAndreas Gohr public function render($mode, Doku_Renderer $renderer, $data) { 835511bd5bSAndreas Gohr if(!$data) return false; 8407993756SAndreas Gohr global $ID; 85*bd363da9SAndreas Gohr global $conf; 8629877279SMichael Große 8715929be2SAndreas Gohr try { 885511bd5bSAndreas Gohr $search = new SearchConfig($data); 8907993756SAndreas Gohr $table = new AggregationTable($ID, $mode, $renderer, $search); 9007993756SAndreas Gohr $table->render(); 9116b7d914SAndreas Gohr 9216b7d914SAndreas Gohr if($mode == 'metadata') { 9316b7d914SAndreas Gohr /** @var Doku_Renderer_metadata $renderer */ 9416b7d914SAndreas Gohr $renderer->meta['plugin']['struct']['hasaggregation'] = $search->getCacheFlag(); 9516b7d914SAndreas Gohr } 9616b7d914SAndreas Gohr 975511bd5bSAndreas Gohr } catch (StructException $e) { 9815929be2SAndreas Gohr msg($e->getMessage(), -1, $e->getLine(), $e->getFile()); 99*bd363da9SAndreas Gohr if($conf['allowdebug']) msg('<pre>'.hsc($e->getTraceAsString()).'</pre>', -1); 10015929be2SAndreas Gohr } 10115929be2SAndreas Gohr 102549a0837SAndreas Gohr return true; 103549a0837SAndreas Gohr } 104549a0837SAndreas Gohr} 105549a0837SAndreas Gohr 106549a0837SAndreas Gohr// vim:ts=4:sw=4:et: 107