101f06932SAndreas Gohr<?php 201f06932SAndreas Gohr 37ebc7895Ssplitbrainuse dokuwiki\Extension\SyntaxPlugin; 47ebc7895Ssplitbrain 501f06932SAndreas Gohr/** 601f06932SAndreas Gohr * DokuWiki Plugin aichat (Syntax Component) 701f06932SAndreas Gohr * 801f06932SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 901f06932SAndreas Gohr * @author Andreas Gohr <gohr@cosmocode.de> 1001f06932SAndreas Gohr */ 117ebc7895Ssplitbrainclass syntax_plugin_aichat_chat extends SyntaxPlugin 1201f06932SAndreas Gohr{ 1301f06932SAndreas Gohr /** @inheritDoc */ 1401f06932SAndreas Gohr public function getType() 1501f06932SAndreas Gohr { 1601f06932SAndreas Gohr return 'substition'; 1701f06932SAndreas Gohr } 1801f06932SAndreas Gohr 1901f06932SAndreas Gohr /** @inheritDoc */ 2001f06932SAndreas Gohr public function getPType() 2101f06932SAndreas Gohr { 2201f06932SAndreas Gohr return 'block'; 2301f06932SAndreas Gohr } 2401f06932SAndreas Gohr 2501f06932SAndreas Gohr /** @inheritDoc */ 2601f06932SAndreas Gohr public function getSort() 2701f06932SAndreas Gohr { 2801f06932SAndreas Gohr return 155; 2901f06932SAndreas Gohr } 3001f06932SAndreas Gohr 3101f06932SAndreas Gohr /** @inheritDoc */ 3201f06932SAndreas Gohr public function connectTo($mode) 3301f06932SAndreas Gohr { 3401f06932SAndreas Gohr $this->Lexer->addSpecialPattern('<aichat(?: [^>]+)*>.*?(?:<\/aichat>)', $mode, 'plugin_aichat_chat'); 3501f06932SAndreas Gohr } 3601f06932SAndreas Gohr 3701f06932SAndreas Gohr 3801f06932SAndreas Gohr /** @inheritDoc */ 3901f06932SAndreas Gohr public function handle($match, $state, $pos, Doku_Handler $handler) 4001f06932SAndreas Gohr { 4101f06932SAndreas Gohr $match = substr($match, 7, -9); 4201f06932SAndreas Gohr [$params, $body] = explode('>', $match, 2); 4301f06932SAndreas Gohr $params = explode(' ', $params); 4401f06932SAndreas Gohr 4501f06932SAndreas Gohr return ['params' => $params, 'body' => $body]; 4601f06932SAndreas Gohr } 4701f06932SAndreas Gohr 4801f06932SAndreas Gohr /** @inheritDoc */ 4901f06932SAndreas Gohr public function render($format, Doku_Renderer $renderer, $data) 5001f06932SAndreas Gohr { 5101f06932SAndreas Gohr if ($format !== 'xhtml') { 5201f06932SAndreas Gohr return false; 5301f06932SAndreas Gohr } 5401f06932SAndreas Gohr 5501f06932SAndreas Gohr if ($this->getConf('restricted')) $renderer->nocache(); 5601f06932SAndreas Gohr $helper = plugin_load('helper', 'aichat'); 5701f06932SAndreas Gohr if (!$helper->userMayAccess()) { 5801f06932SAndreas Gohr return true; 5901f06932SAndreas Gohr } 6001f06932SAndreas Gohr 6101f06932SAndreas Gohr $opts = [ 6230b9cbc7Ssplitbrain 'hello' => trim((string) $data['body']), 6301f06932SAndreas Gohr 'placeholder' => $this->getLang('placeholder'), 6401f06932SAndreas Gohr 'url' => DOKU_BASE . 'lib/exe/ajax.php?call=aichat', 65*f43684f4SAndreas Gohr 'title-send' => $this->getLang('send-button'), 66*f43684f4SAndreas Gohr 'title-restart' => $this->getLang('restart-button'), 6701f06932SAndreas Gohr ]; 6801f06932SAndreas Gohr $html = '<aichat-chat ' . buildAttributes($opts) . '></aichat-chat>'; 6901f06932SAndreas Gohr 7001f06932SAndreas Gohr if (in_array('button', $data['params'])) { 7101f06932SAndreas Gohr $opts = [ 7201f06932SAndreas Gohr 'label' => $this->getLang('title'), 73*f43684f4SAndreas Gohr 'title-close' => $this->getLang('close-button'), 74*f43684f4SAndreas Gohr 'title-fullscreen' => $this->getLang('fullscreen-button'), 7501f06932SAndreas Gohr ]; 7601f06932SAndreas Gohr if (in_array('float', $data['params'])) $opts['class'] = 'float'; 7701f06932SAndreas Gohr 7801f06932SAndreas Gohr $html = '<aichat-button ' . buildAttributes($opts) . '>' . $html . '</aichat-button>'; 7901f06932SAndreas Gohr } 8001f06932SAndreas Gohr 8101f06932SAndreas Gohr $renderer->doc .= $html; 8201f06932SAndreas Gohr return true; 8301f06932SAndreas Gohr } 8401f06932SAndreas Gohr} 85