1<?php 2/** 3 * DokuWiki Plugin struct (Syntax Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de> 7 */ 8 9// must be run within Dokuwiki 10if (!defined('DOKU_INC')) die(); 11 12use dokuwiki\plugin\struct\meta\ConfigParser; 13use dokuwiki\plugin\struct\meta\SearchCloud; 14use dokuwiki\plugin\struct\meta\StructException; 15use dokuwiki\plugin\struct\meta\AggregationCloud; 16 17class syntax_plugin_struct_cloud extends DokuWiki_Syntax_Plugin { 18 19 /** 20 * @return string Syntax mode type 21 */ 22 public function getType() { 23 return 'substition'; 24 } 25 /** 26 * @return string Paragraph type 27 */ 28 public function getPType() { 29 return 'block'; 30 } 31 /** 32 * @return int Sort order - Low numbers go before high numbers 33 */ 34 public function getSort() { 35 return 151; 36 } 37 38 /** 39 * Connect lookup pattern to lexer. 40 * 41 * @param string $mode Parser mode 42 */ 43 public function connectTo($mode) { 44 $this->Lexer->addSpecialPattern('----+ *struct cloud *-+\n.*?\n----+',$mode,'plugin_struct_cloud'); 45 } 46 47 /** 48 * Handle matches of the struct syntax 49 * 50 * @param string $match The match of the syntax 51 * @param int $state The state of the handler 52 * @param int $pos The position in the document 53 * @param Doku_Handler $handler The handler 54 * @return array Data for the renderer 55 */ 56 public function handle($match, $state, $pos, Doku_Handler $handler){ 57 global $conf; 58 $lines = explode("\n", $match); 59 array_shift($lines); 60 array_pop($lines); 61 // todo: disallow dynfilters, rownumbers, limit, offset, ... 62 try { 63 $parser = new ConfigParser($lines); 64 $config = $parser->getConfig(); 65 return $config; 66 } catch(StructException $e) { 67 msg($e->getMessage(), -1, $e->getLine(), $e->getFile()); 68 if($conf['allowdebug']) msg('<pre>' . hsc($e->getTraceAsString()) . '</pre>', -1); 69 return null; 70 } 71 72 } 73 74 /** 75 * Render xhtml output or metadata 76 * 77 * @param string $mode Renderer mode (supported modes: xhtml) 78 * @param Doku_Renderer $renderer The renderer 79 * @param array $data The data from the handler() function 80 * @return bool If rendering was successful. 81 */ 82 public function render($mode, Doku_Renderer $renderer, $data) { 83 if($mode != 'xhtml') return false; 84 if(!$data) return false; 85 global $INFO, $conf; 86 try { 87 $search = new SearchCloud($data); 88 $cloud = new AggregationCloud($INFO['id'], $mode, $renderer, $search); 89 $cloud->render(); 90 if($mode == 'metadata') { 91 /** @var Doku_Renderer_metadata $renderer */ 92 $renderer->meta['plugin']['struct']['hasaggregation'] = $search->getCacheFlag(); 93 } 94 } catch(StructException $e) { 95 msg($e->getMessage(), -1, $e->getLine(), $e->getFile()); 96 if($conf['allowdebug']) msg('<pre>' . hsc($e->getTraceAsString()) . '</pre>', -1); 97 } 98 99 return true; 100 } 101} 102 103// vim:ts=4:sw=4:et: 104