1*308cc83fSAndreas Gohr<?php 2*308cc83fSAndreas Gohr 3*308cc83fSAndreas Gohr/** 4*308cc83fSAndreas Gohr * DokuWiki Plugin struct (Syntax Component) 5*308cc83fSAndreas Gohr * 6*308cc83fSAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 7*308cc83fSAndreas Gohr * @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de> 8*308cc83fSAndreas Gohr */ 9*308cc83fSAndreas Gohr 10*308cc83fSAndreas Gohruse dokuwiki\plugin\struct\meta\AggregationEditorTable; 11*308cc83fSAndreas Gohr 12*308cc83fSAndreas Gohr// must be run within Dokuwiki 13*308cc83fSAndreas Gohrif (!defined('DOKU_INC')) die(); 14*308cc83fSAndreas Gohr 15*308cc83fSAndreas Gohrclass syntax_plugin_struct_global extends syntax_plugin_struct_table 16*308cc83fSAndreas Gohr{ 17*308cc83fSAndreas Gohr 18*308cc83fSAndreas Gohr /** @var string which class to use for output */ 19*308cc83fSAndreas Gohr protected $tableclass = AggregationEditorTable::class; 20*308cc83fSAndreas Gohr 21*308cc83fSAndreas Gohr /** 22*308cc83fSAndreas Gohr * Connect lookup pattern to lexer. 23*308cc83fSAndreas Gohr * 24*308cc83fSAndreas Gohr * @param string $mode Parser mode 25*308cc83fSAndreas Gohr */ 26*308cc83fSAndreas Gohr public function connectTo($mode) 27*308cc83fSAndreas Gohr { 28*308cc83fSAndreas Gohr $this->Lexer->addSpecialPattern('----+ *struct global *-+\n.*?\n----+', $mode, 'plugin_struct_global'); 29*308cc83fSAndreas Gohr 30*308cc83fSAndreas Gohr // deprecated: 31*308cc83fSAndreas Gohr $this->Lexer->addSpecialPattern('----+ *struct lookup *-+\n.*?\n----+', $mode, 'plugin_struct_global'); 32*308cc83fSAndreas Gohr } 33*308cc83fSAndreas Gohr 34*308cc83fSAndreas Gohr /** 35*308cc83fSAndreas Gohr * Handle matches of the struct syntax 36*308cc83fSAndreas Gohr * 37*308cc83fSAndreas Gohr * @param string $match The match of the syntax 38*308cc83fSAndreas Gohr * @param int $state The state of the handler 39*308cc83fSAndreas Gohr * @param int $pos The position in the document 40*308cc83fSAndreas Gohr * @param Doku_Handler $handler The handler 41*308cc83fSAndreas Gohr * @return array Data for the renderer 42*308cc83fSAndreas Gohr */ 43*308cc83fSAndreas Gohr public function handle($match, $state, $pos, Doku_Handler $handler) 44*308cc83fSAndreas Gohr { 45*308cc83fSAndreas Gohr // usual parsing 46*308cc83fSAndreas Gohr $config = parent::handle($match, $state, $pos, $handler); 47*308cc83fSAndreas Gohr if (is_null($config)) return null; 48*308cc83fSAndreas Gohr 49*308cc83fSAndreas Gohr $config = $this->addTypeFilter($config); 50*308cc83fSAndreas Gohr 51*308cc83fSAndreas Gohr // adjust some things for the lookup editor 52*308cc83fSAndreas Gohr $config['cols'] = array('*'); // always select all columns 53*308cc83fSAndreas Gohr if (isset($config['rownumbers'])) unset($config['rownumbers']); // this annoying to update dynamically 54*308cc83fSAndreas Gohr return $config; 55*308cc83fSAndreas Gohr } 56*308cc83fSAndreas Gohr 57*308cc83fSAndreas Gohr /** 58*308cc83fSAndreas Gohr * Filter based on primary key columns 59*308cc83fSAndreas Gohr * 60*308cc83fSAndreas Gohr * @param array $config 61*308cc83fSAndreas Gohr * @return array 62*308cc83fSAndreas Gohr */ 63*308cc83fSAndreas Gohr protected function addTypeFilter($config) 64*308cc83fSAndreas Gohr { 65*308cc83fSAndreas Gohr $config['filter'][] = ['%rowid%', '!=', (string)\dokuwiki\plugin\struct\meta\AccessTablePage::DEFAULT_PAGE_RID, 'AND']; 66*308cc83fSAndreas Gohr $config['filter'][] = ['%pageid%', '=*', '^(?![\s\S])', 'AND']; 67*308cc83fSAndreas Gohr $config['withpid'] = 0; // flag for the editor to distinguish data types 68*308cc83fSAndreas Gohr return $config; 69*308cc83fSAndreas Gohr } 70*308cc83fSAndreas Gohr} 71