1*7bf9165dSAndreas Gohr<?php 2*7bf9165dSAndreas Gohr 3*7bf9165dSAndreas Gohruse dokuwiki\Extension\SyntaxPlugin; 4*7bf9165dSAndreas Gohr 5*7bf9165dSAndreas Gohr/** 6*7bf9165dSAndreas Gohr * DokuWiki Plugin aichat (Syntax Component) 7*7bf9165dSAndreas Gohr * 8*7bf9165dSAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 9*7bf9165dSAndreas Gohr * @author Andreas Gohr <gohr@cosmocode.de> 10*7bf9165dSAndreas Gohr */ 11*7bf9165dSAndreas Gohrclass syntax_plugin_aichat_ignore extends SyntaxPlugin 12*7bf9165dSAndreas Gohr{ 13*7bf9165dSAndreas Gohr /** @var string temporary store for the current document */ 14*7bf9165dSAndreas Gohr protected $temporaryDoc; 15*7bf9165dSAndreas Gohr 16*7bf9165dSAndreas Gohr /** @inheritDoc */ 17*7bf9165dSAndreas Gohr public function getType() 18*7bf9165dSAndreas Gohr { 19*7bf9165dSAndreas Gohr return 'formatting'; 20*7bf9165dSAndreas Gohr } 21*7bf9165dSAndreas Gohr 22*7bf9165dSAndreas Gohr /** @inheritdoc */ 23*7bf9165dSAndreas Gohr public function getAllowedTypes() 24*7bf9165dSAndreas Gohr { 25*7bf9165dSAndreas Gohr return [ 26*7bf9165dSAndreas Gohr 'container', 27*7bf9165dSAndreas Gohr 'formatting', 28*7bf9165dSAndreas Gohr 'substition', 29*7bf9165dSAndreas Gohr 'protected', 30*7bf9165dSAndreas Gohr 'disabled', 31*7bf9165dSAndreas Gohr 'paragraphs', 32*7bf9165dSAndreas Gohr 'baseonly', 33*7bf9165dSAndreas Gohr ]; 34*7bf9165dSAndreas Gohr } 35*7bf9165dSAndreas Gohr 36*7bf9165dSAndreas Gohr /** @inheritDoc */ 37*7bf9165dSAndreas Gohr public function getPType() 38*7bf9165dSAndreas Gohr { 39*7bf9165dSAndreas Gohr return 'normal'; 40*7bf9165dSAndreas Gohr } 41*7bf9165dSAndreas Gohr 42*7bf9165dSAndreas Gohr /** @inheritDoc */ 43*7bf9165dSAndreas Gohr public function getSort() 44*7bf9165dSAndreas Gohr { 45*7bf9165dSAndreas Gohr return 32; 46*7bf9165dSAndreas Gohr } 47*7bf9165dSAndreas Gohr 48*7bf9165dSAndreas Gohr /** @inheritDoc */ 49*7bf9165dSAndreas Gohr public function connectTo($mode) 50*7bf9165dSAndreas Gohr { 51*7bf9165dSAndreas Gohr $this->Lexer->addEntryPattern('<ai-ignore>', $mode, 'plugin_aichat_ignore'); 52*7bf9165dSAndreas Gohr } 53*7bf9165dSAndreas Gohr 54*7bf9165dSAndreas Gohr /** @inheritDoc */ 55*7bf9165dSAndreas Gohr public function postConnect() 56*7bf9165dSAndreas Gohr { 57*7bf9165dSAndreas Gohr $this->Lexer->addExitPattern('</ai-ignore>', 'plugin_aichat_ignore'); 58*7bf9165dSAndreas Gohr } 59*7bf9165dSAndreas Gohr 60*7bf9165dSAndreas Gohr /** @inheritDoc */ 61*7bf9165dSAndreas Gohr public function handle($match, $state, $pos, Doku_Handler $handler) 62*7bf9165dSAndreas Gohr { 63*7bf9165dSAndreas Gohr $data = [ 64*7bf9165dSAndreas Gohr 'state' => $state, 65*7bf9165dSAndreas Gohr 'match' => $match, 66*7bf9165dSAndreas Gohr 'pos' => $pos, 67*7bf9165dSAndreas Gohr ]; 68*7bf9165dSAndreas Gohr 69*7bf9165dSAndreas Gohr return $data; 70*7bf9165dSAndreas Gohr } 71*7bf9165dSAndreas Gohr 72*7bf9165dSAndreas Gohr /** @inheritDoc */ 73*7bf9165dSAndreas Gohr public function render($mode, Doku_Renderer $renderer, $data) 74*7bf9165dSAndreas Gohr { 75*7bf9165dSAndreas Gohr // in all non-aichat modes we just output the raw content and are done 76*7bf9165dSAndreas Gohr if ($mode !== 'aichat') { 77*7bf9165dSAndreas Gohr if ($data['state'] === DOKU_LEXER_UNMATCHED) { 78*7bf9165dSAndreas Gohr $renderer->cdata($data['match']); 79*7bf9165dSAndreas Gohr } 80*7bf9165dSAndreas Gohr return true; 81*7bf9165dSAndreas Gohr } 82*7bf9165dSAndreas Gohr 83*7bf9165dSAndreas Gohr // we're now in aichat mode, ignore everything inside the tags 84*7bf9165dSAndreas Gohr switch ($data['state']) { 85*7bf9165dSAndreas Gohr case DOKU_LEXER_ENTER: 86*7bf9165dSAndreas Gohr $this->temporaryDoc = $renderer->doc; 87*7bf9165dSAndreas Gohr $renderer->doc = ''; 88*7bf9165dSAndreas Gohr break; 89*7bf9165dSAndreas Gohr case DOKU_LEXER_EXIT: 90*7bf9165dSAndreas Gohr $renderer->doc = $this->temporaryDoc; 91*7bf9165dSAndreas Gohr $this->temporaryDoc = ''; 92*7bf9165dSAndreas Gohr break; 93*7bf9165dSAndreas Gohr } 94*7bf9165dSAndreas Gohr 95*7bf9165dSAndreas Gohr return true; 96*7bf9165dSAndreas Gohr } 97*7bf9165dSAndreas Gohr} 98