php-test1
<html>
 <head>
  <title>PHP-Test</title>
 </head>
 <body>
<?php
/**
 * Plugin Chessdiagram: Creates a chessdiagram from FEN or 8x8 characters
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Michael Arlt <michael.arlt@sk-schwanstetten.de>
 * @version    2008-02.24
 */

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'   => '2008-02-24',
            '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, &$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,')');
      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, &$renderer,$data)
    {
      if($mode == 'xhtml')
      {
        // for debug: $renderer->doc .= '<pre>'.$data.'</pre>';
        $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' => '<img src="'
                           . chessboard_piece_filename('-', 0)
                           . '" alt="-" />',
                         '-1' => '<img src="'
                           . chessboard_piece_filename('-', 1)
                           . '" alt="-" />',
                         'x0' => '<img src="'
                           . chessboard_piece_filename('x', 0)
                           . '" alt="x" />',
                         'x1' => '<img src="'
                           . chessboard_piece_filename('x', 1)
                           . '" alt="x" />',
                        );

    // Pieces
    $pieces = 'kqbnrp';
    for ($i=0; $i<6; $i++) {
      $piece = $pieces[$i];
      $table_xhtml += array(strtoupper($piece) . '0' => '<img src="'
                              . chessboard_piece_filename(strtoupper($piece), 0)
                              . '" alt="' . strtoupper($piece) . '" />',
                            strtoupper($piece) . '1' => '<img src="'
                              . chessboard_piece_filename(strtoupper($piece), 1)
                              . '" alt="' . strtoupper($piece) . '" />',
                            $piece . '0' => '<img src="'
                              . chessboard_piece_filename($piece, 0)
                              . '" alt="' . $piece . '" />',
                            $piece . '1' => '<img src="'
                              . chessboard_piece_filename($piece, 1)
                              . '" alt="' . $piece . '" />',
                           );
    }

    // Borders
    $table_xhtml += array('T' => '<img src="'
                            . chessboard_border_filename('T')
                            . '" alt="" />',
                          'B' => '<img src="'
                            . chessboard_border_filename('B')
                            . '" alt="" />',
                          'L' => '<img src="'
                            . chessboard_border_filename('L')
                            . '" alt="" />',
                          'R' => '<img src="'
                            . chessboard_border_filename('R')
                            . '" alt="" />',
                          'TL' => '<img src="'
                            . chessboard_border_filename('TL')
                            . '" alt="" />',
                          'TR' => '<img src="'
                            . chessboard_border_filename('TR')
                            . '" alt="" />',
                          'BL' =>
                            '<img src="'
                            . chessboard_border_filename('BL')
                            . '" alt="" />',
                          'BR' =>
                            '<img src="'
                            . chessboard_border_filename('BR')
                            . '" alt="" />',
                         );

    $table_constructed = true;
  }

  preg_match('@^\s*(?:\((.*?)\))?(.*)$@s', $content, $matches);

  // Parameter Parsing
  //--------------------------------
  $params =& $matches[1];

  // Number of files: any integer (default: 8)
  $file_max = preg_match('@[0-9]+@', $params, $m) ? $m[0] : 8;

  // Color of the upper left square: [l]ight (default), or [d]ark
  $square_color_first = (strpos($params, 'd') !== false) ? 1 : 0;

  // Borders
  $border = array('T' => (strpos($params, 'T') !== false),
                  'B' => (strpos($params, 'B') !== false),
                  'L' => (strpos($params, 'L') !== false),
                  'R' => (strpos($params, 'R') !== false));

  // Render the board in XHTML syntax
  //----------------------------------
  $board =& $matches[2];
  $xhtml = '';

  // Top border
  if ($border['T']) {
    if ($border['L'])
      $xhtml .= $table_xhtml['TL'];
    $xhtml .= str_repeat($table_xhtml['T'], $file_max);
    if ($border['R'])
      $xhtml .= $table_xhtml['TR'];
    $file = $file_max;
  }
  else {
    $file = 0;
    $square_color = $square_color_first;
    $square_color_first = 1 - $square_color_first;
  }

  // Left border, board, right border
  for ($i=0; isset($board[$i]); $i++) {

    // Ignore unknown characters
    if (strpos('12345678KQBNRPkqbnrp-x', $board[$i]) === false) {
      continue;
    }

    if ($file >= $file_max) {
      $xhtml .= '<br />';
      $file = 0;
      $square_color = $square_color_first;
      $square_color_first = 1 - $square_color_first;
      if ($border['L'])
        $xhtml .= $table_xhtml['L'];
    }

    $key = $board[$i].$square_color;
    if (strpos('12345678', $board[$i]) !== false) {
      // Multiple empty squares
      for ($j=0; $j<$board[$i]; $j++) {
        $xhtml .= $table_xhtml['-'.$square_color];
        $square_color = 1 - $square_color;
      }
      $file += (int) $board[$i];
    }
    else {
      // $table_xhtml[$key] is defined as we have filtered unknown characters
      $xhtml .= $table_xhtml[$key];
      $square_color = 1 - $square_color;
      $file++;
    }

    if ($file >= $file_max) {
      if ($border['R'])
        $xhtml .= $table_xhtml['R'];
    }
  }

  // Bottom border
  if ($border['B']) {
    $xhtml .= '<br />';
    if ($border['L'])
      $xhtml .= $table_xhtml['BL'];
    $xhtml .= str_repeat($table_xhtml['B'], $file_max);
    if ($border['R'])
      $xhtml .= $table_xhtml['BR'];
  }

  return $xhtml;
}

//Setup VIM: ex: et ts=4 enc=utf-8 :
 </body>
</html>



standard - live "_template" used without any tricks and layout changes…