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