* @version 2016-11-08 */ if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../../').'/'); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); if(!defined('IMAGE_PATH')) define('IMAGE_PATH',DOKU_BASE.'lib/plugins/chessdiagram/images/'); require_once(DOKU_PLUGIN.'syntax.php'); /** * All DokuWiki plugins to extend the parser/rendering mechanism * need to inherit from this class */ class syntax_plugin_chessdiagram extends DokuWiki_Syntax_Plugin { /** * function constructor */ function syntax_plugin_chessdiagram(){ // enable direct access to language strings $this->setupLocale(); } /** * return some info */ function getInfo(){ return array( 'author' => 'Michael Arlt', 'email' => 'michael.arlt@sk-schwanstetten.de', 'date' => '2016-11-08', 'name' => 'Chessdiagram Plugin', 'desc' => $lang['desc'], 'url' => 'http://wiki.splitbrain.org/plugin:chessdiagram' ); } /** * What kind of syntax are we? */ function getType(){ return 'substition'; } /** * Where to sort in? */ function getSort(){ return 999; } /** * Connect pattern to lexer */ function connectTo($mode) { $this->Lexer->addSpecialPattern('<'.$this->lang['kwpattern'].'>.+?'.$this->lang['kwpattern'].'>',$mode,'plugin_chessdiagram'); } /** * Handle the match */ function handle($match, $state, $pos, Doku_Handler $handler) { $match=substr($match,strlen($this->lang['kwpattern'])+2,-(strlen($this->lang['kwpattern'])+3)); foreach (preg_split('/\r\n|\r|\n/',$match) as $line) { $line=preg_replace("/#.*/","",trim($line)); if(substr($line,0,1) != "") { $lines.=$line; }; } $pos = strpos($lines,')'); if (preg_match('/[0-9]/',$lines)) { return strip_tags(strtr(substr($lines,0,$pos),$this->lang['kwoptions'],'TBLRdl').substr($lines,$pos)); } else { return strip_tags(strtr(substr($lines,0,$pos),$this->lang['kwoptions'],'TBLRdl').strtr(substr($lines,$pos),$this->lang['kwpieces'],'kqrbnpKQRBNP')); } } /** * Create output */ function render($mode, Doku_Renderer $renderer,$data) { if($mode == 'xhtml') { // for debug: $renderer->doc .= '
'.$data.''; $renderer->doc .= '
'.chessboard_render($data).'
'; return true; } return false; } } /* Copyright (C) 2006 http://www.vyvy.org/ This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA Changes: 15-Jun-06: [v1.0] Initial Release Usage: To convert a board to XHTML code, simply get the return value from: chessboard_render($board) */ /*================================*/ /* Routines */ /*================================*/ function chessboard_border_filename($border) { // $border: T, B, L, R, TL, TR, BL, BR switch ($border) { case 'T': case 'B': return IMAGE_PATH.'h.png'; case 'L': case 'R': return IMAGE_PATH.'v.png'; default: return IMAGE_PATH.'c.png'; } } function chessboard_piece_filename($piece, $square_color) { // $piece : KQBNRPkqbnrp- // $square_color : 0 1 switch ($piece) { case 'x': $name = 'xx'; break; case '-': $name = ''; break; default: $name = strtolower($piece).(ctype_lower($piece)?'d':'l'); break; } return IMAGE_PATH.$name.($square_color?'d':'l').'.png'; } function chessboard_render($content) { static $table_constructed = false; static $table_xhtml; if (!$table_constructed) { // Construct the translation table // Empty and marked squares $table_xhtml = array('-0' => '