DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:pgnviewer

This is an old revision of the document!


PGN Viewer Plugin

Compatible with DokuWiki

2007-06-26b

plugin JavaScript viewer for chess games in PGN format (based on jsPgnViewer library by Toomas Römer)

Last updated on
2007-11-09
Provides
Syntax

The missing download url means that this extension cannot be installed via the Extension Manager. Please see Publishing a Plugin on dokuwiki.org. Recommended are public repository hosts like GitHub, GitLab or Bitbucket.

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Tagged with diagram, game, images, javascript, media

Warning

This plugin is still in development (alpha version)! Use it on your own risk only!

This plugin is based on jsPgnViewer library developed by Toomas Römer. More info at http://tom.jabber.ee/chess/

Installation

coming soon…

Configuration

coming soon…

Usage

Put the PGN 1) code of your free games between <pgn> and </pgn> tags.

Example:

<pgn>
[Event "gameID 5127359"]
[Site "http://www.chessmaniac.com"]
[Date "2007.10.20"]
[Round ""]
[White "CaptainMuleus"]
[Black "d0minik"]
[TimeControl "normal"]
[Result "1-0"]
[ECO "oft "]
1.e4 e5 2.Qh5 Nbc6 3.Bfc4 Bfc5 4.Qxf7+ 1-0
</pgn>

Plugin

<?php
/**
 * Plugin PGN Viewer: JavaScript viewer for chess games in PGN format
 * 
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Dominik Smatana <dominiks[at]users.sourceforge.net>
 *
 * This plugin in based on jsPgnViewer library:
 * 
 * @license    Apache License ver 2.0
 * @author     Toomas Römer <toomasr[at]gmail.com>  
 */
 
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
 
/**
 * All DokuWiki plugins to extend the parser/rendering mechanism
 * need to inherit from this class
 */
class syntax_plugin_pgnviewer extends DokuWiki_Syntax_Plugin {
 
    /**
     * return some info
     */
    function getInfo(){
        return array(
            'author' => 'Dominik Smatana',
            'email'  => 'dominiks@users.sourceforge.net',
            'date'   => '2007-11-09',
            'name'   => 'PGN Viewer',
            'desc'   => 'JavaScript viewer for chess games in PGN format',
            'url'    => 'http://www.dokuwiki.org/plugin:pgnviewer',
        );
    }
 
    /**
     * What kind of syntax are we?
     */
    function getType(){
        return 'protected';
    }
 
    /**
     * Where to sort in?
     */ 
    function getSort(){
        return 999;
    }
 
 
    /**
     * Connect pattern to lexer
     */
    function connectTo($mode) {
		$this->Lexer->addEntryPattern('<pgn>(?=.*</pgn>)',$mode,'plugin_pgnviewer');
    }
 
    function postConnect() {
		$this->Lexer->addExitPattern('</pgn>', 'plugin_pgnviewer');
    }
 
 
    /**
     * Handle the match
     */
    function handle($match, $state, $pos, &$handler){
        switch ($state) {
          case DOKU_LEXER_ENTER : 
            break;
          case DOKU_LEXER_MATCHED :
            break;
          case DOKU_LEXER_UNMATCHED :
            break;
          case DOKU_LEXER_EXIT :
            break;
          case DOKU_LEXER_SPECIAL :
            break;
        }
        return array($match, $state);
    }
 
    /**
     * Create output
     */
	function render($mode, &$renderer, $data) {
		if ($mode == 'xhtml') {
			if ($data[1] == DOKU_LEXER_UNMATCHED) {
				$path = 'lib/plugins/pgnviewer/jspgnviewer/';
				$pgn = $data[0];
				$now = time() + mt_rand();
				$out = '<script type="text/javascript" charset="utf-8" src="'.$path.'jsPgnViewer.js" ></script>';
				// hidden div with the game information
				$out .= '<div id="'.$now.'" style="visibility:hidden;display:none">'.$pgn."</div>\n";
				// the div that will contain the graphical board
				$out .= '<div id="'.$now.'_board"></div>';
				// initialize the board
				$out .= '<script>var brd = new Board('.$now.',{"imagePrefix":"'.$path.'img/default/"});brd.init()</script>';
				$out .= '<noscript>You have JavaScript disabled and you are not seeing a graphical interactive chessboard!</noscript>';
				$renderer->doc .= $out;
			}
			return true;
		}
		return false;
	}
}

Change log

coming soon…

ToDo's

  • don't include external JavaScript in the middle of body element!
  • add configuration parameters (e.g. <pgn theme=“zurich”> etc…)
  • is there need to support <noscript> on DokuWiki pages?
  • update plugin syntax according to DokuWiki coding standards
  • update this documentation (installation, etc…)

Comments

Your comments and ideas…

1)
PGN - Portable Game Notation, Portable game notation
plugin/pgnviewer.1335062835.txt.gz · Last modified: 2012-04-22 04:47 by 58.187.55.8

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki