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 9*ea5ad12aSMichael Grosseuse dokuwiki\plugin\struct\meta\AggregationList; 10*ea5ad12aSMichael Grosseuse dokuwiki\plugin\struct\meta\ConfigParser; 11*ea5ad12aSMichael Grosseuse dokuwiki\plugin\struct\meta\SearchConfig; 12*ea5ad12aSMichael Grosseuse dokuwiki\plugin\struct\meta\StructException; 13*ea5ad12aSMichael Grosse 14549a0837SAndreas Gohr// must be run within Dokuwiki 15549a0837SAndreas Gohrif (!defined('DOKU_INC')) die(); 16549a0837SAndreas Gohr 17549a0837SAndreas Gohrclass syntax_plugin_struct_list extends DokuWiki_Syntax_Plugin { 18*ea5ad12aSMichael Grosse 19*ea5ad12aSMichael Grosse /** @var string which class to use for output */ 20*ea5ad12aSMichael Grosse protected $tableclass = AggregationList::class; 21*ea5ad12aSMichael Grosse 22549a0837SAndreas Gohr /** 23549a0837SAndreas Gohr * @return string Syntax mode type 24549a0837SAndreas Gohr */ 25549a0837SAndreas Gohr public function getType() { 26*ea5ad12aSMichael Grosse return 'substition'; 27549a0837SAndreas Gohr } 28549a0837SAndreas Gohr /** 29549a0837SAndreas Gohr * @return string Paragraph type 30549a0837SAndreas Gohr */ 31549a0837SAndreas Gohr public function getPType() { 32*ea5ad12aSMichael Grosse return 'block'; 33549a0837SAndreas Gohr } 34549a0837SAndreas Gohr /** 35549a0837SAndreas Gohr * @return int Sort order - Low numbers go before high numbers 36549a0837SAndreas Gohr */ 37549a0837SAndreas Gohr public function getSort() { 38*ea5ad12aSMichael Grosse return 155; 39549a0837SAndreas Gohr } 40549a0837SAndreas Gohr 41549a0837SAndreas Gohr /** 42549a0837SAndreas Gohr * Connect lookup pattern to lexer. 43549a0837SAndreas Gohr * 44549a0837SAndreas Gohr * @param string $mode Parser mode 45549a0837SAndreas Gohr */ 46549a0837SAndreas Gohr public function connectTo($mode) { 47*ea5ad12aSMichael Grosse $this->Lexer->addSpecialPattern('----+ *struct list *-+\n.*?\n----+',$mode,'plugin_struct_list'); 48549a0837SAndreas Gohr } 49549a0837SAndreas Gohr 50549a0837SAndreas Gohr /** 51549a0837SAndreas Gohr * Handle matches of the struct syntax 52549a0837SAndreas Gohr * 53549a0837SAndreas Gohr * @param string $match The match of the syntax 54549a0837SAndreas Gohr * @param int $state The state of the handler 55549a0837SAndreas Gohr * @param int $pos The position in the document 56549a0837SAndreas Gohr * @param Doku_Handler $handler The handler 57549a0837SAndreas Gohr * @return array Data for the renderer 58549a0837SAndreas Gohr */ 59ab466032SAndreas Gohr public function handle($match, $state, $pos, Doku_Handler $handler){ 60*ea5ad12aSMichael Grosse global $conf; 61549a0837SAndreas Gohr 62*ea5ad12aSMichael Grosse $lines = explode("\n", $match); 63*ea5ad12aSMichael Grosse array_shift($lines); 64*ea5ad12aSMichael Grosse array_pop($lines); 65*ea5ad12aSMichael Grosse 66*ea5ad12aSMichael Grosse try { 67*ea5ad12aSMichael Grosse $parser = new ConfigParser($lines); 68*ea5ad12aSMichael Grosse $config = $parser->getConfig(); 69*ea5ad12aSMichael Grosse return $config; 70*ea5ad12aSMichael Grosse } catch(StructException $e) { 71*ea5ad12aSMichael Grosse msg($e->getMessage(), -1, $e->getLine(), $e->getFile()); 72*ea5ad12aSMichael Grosse if($conf['allowdebug']) msg('<pre>' . hsc($e->getTraceAsString()) . '</pre>', -1); 73*ea5ad12aSMichael Grosse return null; 74*ea5ad12aSMichael Grosse } 75*ea5ad12aSMichael Grosse } 76*ea5ad12aSMichael Grosse 77*ea5ad12aSMichael Grosse /** 78*ea5ad12aSMichael Grosse * Checks for options that do not work in a list aggregation 79*ea5ad12aSMichael Grosse * 80*ea5ad12aSMichael Grosse * @param array $config 81*ea5ad12aSMichael Grosse */ 82*ea5ad12aSMichael Grosse protected function checkForInvalidOptions($config) { 83*ea5ad12aSMichael Grosse $illegal = ['dynfilters', 'summarize', 'rownumbers', 'widths', 'summary']; 84*ea5ad12aSMichael Grosse foreach ($illegal as $illegalOption) 85*ea5ad12aSMichael Grosse if (!empty($config[$illegalOption])) { 86*ea5ad12aSMichael Grosse throw new StructException('illegal option', $illegalOption); 87*ea5ad12aSMichael Grosse } 88549a0837SAndreas Gohr } 89549a0837SAndreas Gohr 90549a0837SAndreas Gohr /** 91549a0837SAndreas Gohr * Render xhtml output or metadata 92549a0837SAndreas Gohr * 93549a0837SAndreas Gohr * @param string $mode Renderer mode (supported modes: xhtml) 94549a0837SAndreas Gohr * @param Doku_Renderer $renderer The renderer 95549a0837SAndreas Gohr * @param array $data The data from the handler() function 96549a0837SAndreas Gohr * @return bool If rendering was successful. 97549a0837SAndreas Gohr */ 98ab466032SAndreas Gohr public function render($mode, Doku_Renderer $renderer, $data) { 99549a0837SAndreas Gohr if($mode != 'xhtml') return false; 100*ea5ad12aSMichael Grosse if(!$data) return false; 101*ea5ad12aSMichael Grosse global $INFO; 102*ea5ad12aSMichael Grosse global $conf; 103*ea5ad12aSMichael Grosse 104*ea5ad12aSMichael Grosse try { 105*ea5ad12aSMichael Grosse $this->checkForInvalidOptions($data); 106*ea5ad12aSMichael Grosse $search = new SearchConfig($data); 107*ea5ad12aSMichael Grosse 108*ea5ad12aSMichael Grosse /** @var AggregationList $list */ 109*ea5ad12aSMichael Grosse $list = new $this->tableclass($INFO['id'], $mode, $renderer, $search); 110*ea5ad12aSMichael Grosse $list->render(); 111*ea5ad12aSMichael Grosse 112*ea5ad12aSMichael Grosse if($mode == 'metadata') { 113*ea5ad12aSMichael Grosse /** @var Doku_Renderer_metadata $renderer */ 114*ea5ad12aSMichael Grosse $renderer->meta['plugin']['struct']['hasaggregation'] = $search->getCacheFlag(); 115*ea5ad12aSMichael Grosse } 116*ea5ad12aSMichael Grosse 117*ea5ad12aSMichael Grosse } catch(StructException $e) { 118*ea5ad12aSMichael Grosse msg($e->getMessage(), -1, $e->getLine(), $e->getFile()); 119*ea5ad12aSMichael Grosse if($conf['allowdebug']) msg('<pre>' . hsc($e->getTraceAsString()) . '</pre>', -1); 120*ea5ad12aSMichael Grosse } 121549a0837SAndreas Gohr 122549a0837SAndreas Gohr return true; 123549a0837SAndreas Gohr } 124549a0837SAndreas Gohr} 125549a0837SAndreas Gohr 126549a0837SAndreas Gohr// vim:ts=4:sw=4:et: 127