Trump suits plugin for DokuWiki

This may not be the most spectacular DokuWiki plugin available, but it suits my own needs just fine. The plugin renders the diamond and heart card suit symbols in red, and the clubs and spade card suit symbols in black. It also adds four buttons to the editor toolbar for quick access to the trump suit symbols.

Due to my very limited knowledge of PHP and javascript I can't guarantee this won't set fire to your DokuWiki server. Mine seems to have survived thus far, so there is hope yet. Suggestions for improvement are very welcome.

Syntax

No special syntax. Just use standard UTF card suit symbols (optionally inserted by using the toolbar buttons).

Versions

2010-09-03
Fixed javascript that was broken in DokuWiki version 2009-12-25, “Lemming”.
2009-11-05
Initial version

Installation

Plugin manager

Manual

Create the folder lib/plugins/trumpsuits in your DokuWiki folder. Create syntax.php and scrips.js as given below. Create the folder lib/plugins/trumpsuits/images and place the images in this table in there.

Suit Unicode, hexadecimal Filename Image
Clubs 2663 2667 clubs.png
Diamonds 2666 2662 diamonds.png
Hearts 2665 2661 hearts.png
Spades 2660 2664 spades.png

syntax.php

Take care not to include whitespace in front of the first php tag or after the last php tag. This leads to strange behaviour by DokuWiki.

<?php
/**
 * Plugin base links: Creates links relative to site root for all links beginning with "/"
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Pieter van der Meulen <pieter@vdmeulen.net>
 */
 
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_trumpsuits extends DokuWiki_Syntax_Plugin {
 
    /**
     * return some info
     */
    function getInfo(){
        return array(
            'author' => 'Pieter van der Meulen',
            'email'  => 'pieter@vdmeulen.net',
            'date'   => '2007-08-09',
            'name'   => 'trumpsuits',
            'desc'   => 'Adds toolbar buttons in editor for trump suits. Displays red suits red, black suits black.',
            'url'    => 'http://www.vdmeulen.net/wiki/bridge/trumpsuits-dokuwiki-plugin',
        );
    }
 
    /**
     * What kind of syntax are we?
     */
    function getType(){
        return 'substition';
    }
 
    //This must be implemented
    function getSort(){ return 123; }
 
 
}
?>

Hieruit eventueel nog stukje gebruiken:

<?php
/**
 * Plugin Trumpsigns: Inserts <font size="+1" color="..."> tags into the document when trumpsigns are encountered
 * 
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Pieter van der Meulen <dev@vdmeulen.net>
 */
 
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_tab extends DokuWiki_Syntax_Plugin {
 
    /**
     * return some info
     */
    function getInfo(){
        return array(
            'author' => 'Pieter van der Meulen',
            'email'  => 'dev@vdmeulen.net',
            'date'   => '2006-11-20',
            'name'   => 'Trumpsigns Plugin',
            'desc'   => 'Inserts <font size="+1" color="..."> tags into the html around trump signs',
            'url'    => 'http://www.vdmeulen.net/wiki/bridge/troeftekens_in_dokuwiki#vergroot_in_rood_en_wart_weergeven',
        );
    }
 
    /**
     * What kind of syntax are we?
     */
    function getType(){
        return 'substition';
    }
 
 
    /**
     * Where to sort in?
     */ 
    function getSort(){
        return 789;
    }
 
 
    /**
     * Connect pattern to lexer
     */
    function connectTo($mode) {
      $this->Lexer->addSpecialPattern('♣',$mode,'plugin_trumpsigns');
      $this->Lexer->addSpecialPattern('♦',$mode,'plugin_trumpsigns');
      $this->Lexer->addSpecialPattern('♥',$mode,'plugin_trumpsigns');
      $this->Lexer->addSpecialPattern('♠',$mode,'plugin_trumpsigns');
    }
 
    /**
     * 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();
    }
 
    /**
     * Create output
     */
    function render($mode, &$renderer, $data) {
        if($mode == 'xhtml'){
            $renderer->doc .= "<FONT SIZE=\"+1\" COLOR=\"RED\">XXX+";
            $renderer->doc .= $data;
            $renderer->doc .= "-XXX</FONT>";
            return true;
        }
        return false;
    }
}
 
//Setup VIM: ex: et ts=4 enc=utf-8 :

script.js

if(window.toolbar!=undefined){
    var icobase = DOKU_BASE + "lib/plugins/trumpsuits/images/";
    toolbar[toolbar.length] = {
        "type": "insert",
        "title": "Spades",
        "icon": "spades.png",
        "insert": "♠",
        "icobase": icobase};
    toolbar[toolbar.length] = {
        "type": "insert",
        "title": "Hearts",
        "icon": "hearts.png",
        "insert":  "♥",
        "icobase": icobase};
    toolbar[toolbar.length] = {
        "type":	"insert",
        "title": "Diamonds",
        "icon":	"diamonds.png",
        "insert": "♦",
        "icobase": icobase};
    toolbar[toolbar.length] = {
        "type":	"insert",
        "title": "Clubs",
        "icon":	"clubs.png",
        "insert": "♣",
        "icobase": icobase};
}

Wishlist

  • Configuration options for trump suit symbol replacement
  • Language options. Can one use language conf in javascript?
/share/Web/dokuwiki/data/pages/bridge/trumpsuits-dokuwiki-plugin.txt · Laatst gewijzigd: 2020/06/16 02:07 door 114.119.164.162
CC Attribution-Share Alike 4.0 International
Powered by PHP Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0 Valid HTML5