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