Not logged in. · Lost password · Register
Forum: General Help and Support Plugins RSS
Newbie needs help with first plugin
Avatar
locksdownunder #1
Member since Apr 2007 · 11 posts
Group memberships: Members
Show profile · Link to this post
Subject: Newbie needs help with first plugin
Hello,
I am trying to understand how plugin works & have adjusted the sample in the tutorial.

How do I get data from the handle into render?

I want to put the likes of <KEYCONV|red> into a wiki page and have it return "Hello Worldred"

Below is what i tried and failed. Please show me how to do this.

<?php
/**
 * Plugin Skeleton: Displays "Hello World!"
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Christopher Smith <chris@jalakai.co.uk>
 */
 
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_keyconv extends DokuWiki_Syntax_Plugin {
 
    /**
     * return some info
     */
    function getInfo(){
        return array(
            'author' => 'Tony Steward',
            'email'  => 'tony_steward@inbox.com',
            'date'   => '2007-05-29',
            'name'   => 'Key Converter',
            'desc'   => 'Show keys from differant manufacturers',
            'url'    => 'http://www.locks.stewardclan.net/lockswiki/',
        );
    }
 
    /**
     * What kind of syntax are we?
     */
    function getType(){
        return 'substition';
    }
 
    /**
     * What kind of syntax do we allow (optional)
     */
//    function getAllowedTypes() {
//        return array();
//    }
 
    /**
     * What about paragraphs? (optional)
     */
//    function getPType(){
//        return 'normal';
//    }
 
    /**
     * Where to sort in?
     */
    function getSort(){
        return 999;
    }
 
 
    /**
     * Connect pattern to lexer
     */
    function connectTo($mode) {
      $this->Lexer->addSpecialPattern('<KEYCONV|.+?>',$mode,'plugin_keyconv');
//      $this->Lexer->addEntryPattern('<keyconv>',$mode,'plugin_keyconv');
    }
 
//    function postConnect() {
//      $this->Lexer->addExitPattern('</keyconv>','plugin_keyconv');
//    }
 
 
    /**
     * Handle the match
     */
    function handle($match, $state, $pos, &$handler){
        $match = substr($match, 10, -2); // strip {{keyconv> from start and }} from end
        switch ($state) {
          case DOKU_LEXER_ENTER :
            break;
          case DOKU_LEXER_MATCHED :
            //return array($state, $match);
            break;
          case DOKU_LEXER_UNMATCHED :
            break;
          case DOKU_LEXER_EXIT :
            break;
          case DOKU_LEXER_SPECIAL :
            break;
        }
        return array($match);
    }
 
    /**
     * Create output
     */
    function render($mode, &$renderer, $data) {
        if($mode == 'xhtml'){
            $renderer->doc .= "Hello World!";            // ptype = 'normal'
            $renderer->doc .= $data;
//            $renderer->doc .= "<p>Hello World!</p>";     // ptype = 'block'
            return true;
        }
        return false;
    }
}
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
Imprint
This board is powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2015 by Yves Goergen
Current time: 2019-08-21, 17:54:01 (UTC +02:00)