1*01f06932SAndreas Gohr<?php 2*01f06932SAndreas Gohr 3*01f06932SAndreas Gohr/** 4*01f06932SAndreas Gohr * DokuWiki Plugin aichat (Syntax Component) 5*01f06932SAndreas Gohr * 6*01f06932SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 7*01f06932SAndreas Gohr * @author Andreas Gohr <gohr@cosmocode.de> 8*01f06932SAndreas Gohr */ 9*01f06932SAndreas Gohrclass syntax_plugin_aichat_chat extends \dokuwiki\Extension\SyntaxPlugin 10*01f06932SAndreas Gohr{ 11*01f06932SAndreas Gohr /** @inheritDoc */ 12*01f06932SAndreas Gohr public function getType() 13*01f06932SAndreas Gohr { 14*01f06932SAndreas Gohr return 'substition'; 15*01f06932SAndreas Gohr } 16*01f06932SAndreas Gohr 17*01f06932SAndreas Gohr /** @inheritDoc */ 18*01f06932SAndreas Gohr public function getPType() 19*01f06932SAndreas Gohr { 20*01f06932SAndreas Gohr return 'block'; 21*01f06932SAndreas Gohr } 22*01f06932SAndreas Gohr 23*01f06932SAndreas Gohr /** @inheritDoc */ 24*01f06932SAndreas Gohr public function getSort() 25*01f06932SAndreas Gohr { 26*01f06932SAndreas Gohr return 155; 27*01f06932SAndreas Gohr } 28*01f06932SAndreas Gohr 29*01f06932SAndreas Gohr /** @inheritDoc */ 30*01f06932SAndreas Gohr public function connectTo($mode) 31*01f06932SAndreas Gohr { 32*01f06932SAndreas Gohr $this->Lexer->addSpecialPattern('<aichat(?: [^>]+)*>.*?(?:<\/aichat>)', $mode, 'plugin_aichat_chat'); 33*01f06932SAndreas Gohr } 34*01f06932SAndreas Gohr 35*01f06932SAndreas Gohr 36*01f06932SAndreas Gohr /** @inheritDoc */ 37*01f06932SAndreas Gohr public function handle($match, $state, $pos, Doku_Handler $handler) 38*01f06932SAndreas Gohr { 39*01f06932SAndreas Gohr $match = substr($match, 7, -9); 40*01f06932SAndreas Gohr [$params, $body] = explode('>', $match, 2); 41*01f06932SAndreas Gohr $params = explode(' ', $params); 42*01f06932SAndreas Gohr 43*01f06932SAndreas Gohr return ['params' => $params, 'body' => $body]; 44*01f06932SAndreas Gohr } 45*01f06932SAndreas Gohr 46*01f06932SAndreas Gohr /** @inheritDoc */ 47*01f06932SAndreas Gohr public function render($format, Doku_Renderer $renderer, $data) 48*01f06932SAndreas Gohr { 49*01f06932SAndreas Gohr if ($format !== 'xhtml') { 50*01f06932SAndreas Gohr return false; 51*01f06932SAndreas Gohr } 52*01f06932SAndreas Gohr 53*01f06932SAndreas Gohr if($this->getConf('restricted')) $renderer->nocache(); 54*01f06932SAndreas Gohr $helper = plugin_load('helper', 'aichat'); 55*01f06932SAndreas Gohr if(!$helper->userMayAccess()) { 56*01f06932SAndreas Gohr return true; 57*01f06932SAndreas Gohr } 58*01f06932SAndreas Gohr 59*01f06932SAndreas Gohr $opts = [ 60*01f06932SAndreas Gohr 'hello' => trim($data['body']), 61*01f06932SAndreas Gohr 'placeholder' => $this->getLang('placeholder'), 62*01f06932SAndreas Gohr 'url' => DOKU_BASE . 'lib/exe/ajax.php?call=aichat', 63*01f06932SAndreas Gohr ]; 64*01f06932SAndreas Gohr $html = '<aichat-chat ' . buildAttributes($opts) . '></aichat-chat>'; 65*01f06932SAndreas Gohr 66*01f06932SAndreas Gohr if (in_array('button', $data['params'])) { 67*01f06932SAndreas Gohr $opts = [ 68*01f06932SAndreas Gohr 'label' => $this->getLang('title'), 69*01f06932SAndreas Gohr ]; 70*01f06932SAndreas Gohr if(in_array('float', $data['params'])) $opts['class'] = 'float'; 71*01f06932SAndreas Gohr 72*01f06932SAndreas Gohr $html = '<aichat-button ' . buildAttributes($opts) . '>' . $html . '</aichat-button>'; 73*01f06932SAndreas Gohr } 74*01f06932SAndreas Gohr 75*01f06932SAndreas Gohr $renderer->doc .= $html; 76*01f06932SAndreas Gohr return true; 77*01f06932SAndreas Gohr } 78*01f06932SAndreas Gohr} 79*01f06932SAndreas Gohr 80