How To Develop Syntax Plugin Step by Step

Dokuwiki is a powerful and extensible platform due to it plugin architecture. So I started to dig into how to create a plugin. Here is how to create a simple syntax plugin, Hello World!. It displays Hello World! when Dokuwiki finds a tag [hellomsg].

Devel plugin approach

The overall approach consists of the following macro-steps:

  1. Define the keyword syntax
  2. Define the methods behavior when the keyword is encountered on a page

The micro-step methods to develop are:

  1. Extends DokuWiki_Syntax_Plugin: Encapsulates the behavior of the plugin
  2. Define getInfo method: Some description about the plugin and Author
  3. Define getType method: Should return the type of syntax this plugin defines, often return 'substition' (modes where the token is simply replaced)
  4. Define getSort method: Returns a number used to determine in which order modes are added, often return a number
  5. Define connectTo method: This function is inherited from Doku_Parser_Mode. Here is the place to register the regular expressions needed to match your keyword tag, in other words connects your plugin to the Dokuwiki engine to handle the tag
  6. Define handle method: to prepare the matched syntax for use in the renderer
  7. Define render method: Renders the output of the plugin

Devel plugin steps: Hello World Plugin ( Static Plugin )

Hello World Plugin macro-steps are:

  1. Define the keyword syntax: [hellomsg]
  2. Define the methods behavior when the keyword is encountered on a page: substitute tag [hellomsg] with string “Hello World !”

The micro-steps Hello World Plugin methods coding are:

1. Extends DokuWiki_Syntax_Plugin

Encapsulates the behavior of the plugin:

  • In your own DokuWiki installation, create a new sub directory in the lib/plugins/ directory. That directory will have the same name as your plugin. In this case lib/plugins/hello
  • Create a file named syntax.php in the folder lib/plugins/hello
  • Define the class for your plugin with the same name of directory ( syntax_plugin_hello ):
    <?php
    /**
     * Plugin Hello: Hello World Plugin.
     * 
     * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
     * @author     Riccardo Pisanu <rkpisanu@yahoo.it>
     */
 
    // must be run within DokuWiki
    if(!defined('DOKU_INC')) die();
 
    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_hello extends DokuWiki_Syntax_Plugin {
 
    }

2. Define getInfo method

Some description about the plugin and Author

        function getInfo() {
            return array('author' => 'Riccardo Pisanu',
                         'email'  => 'rkpisanu@yahoo.it',
                         'date'   => '2013-01-7',
                         'name'   => 'Hello Plugin',
                         'desc'   => 'Hello Plugin Example.',
                         'url'    => 'http://rkpisanu.altervista.org/doku.php?id=dokuwiki:devel:plugins:howto');
        }

3. Define getType method

Should return the type of syntax this plugin defines, often return 'substition' (modes where the token is simply replaced)

        function getType() { return 'substition'; }

4. Define getSort method

Returns a number used to determine in which order modes are added, often return a number

        function getSort() { return 32; }

5. Define connectTo method

This function is inherited from Doku_Parser_Mode. Here is the place to register the regular expressions needed to match your keyword tag, in other words connects your plugin to the Dokuwiki engine to handle the tag. In this case, the regular expression is: \[hellomsg\] ( backslash is needed because [ is a special regex character )

        function connectTo($mode) {
            $this->Lexer->addSpecialPattern('\[hellomsg\]',$mode,'plugin_hello');
        }

6. Define handle method

to prepare the matched syntax for use in the renderer

        function handle($match, $state, $pos, &$handler) {
            return array($match, $state, $pos);
        }

7. Define render method

Renders the output of the plugin. It prints Hello World ! in the page

        function render($mode, &$renderer, $data) {
            if($mode == 'xhtml'){
                $renderer->doc .= "Hello World !";
                return true;
            }
            return false;
        }

Create a test page and insert [hellomsg] and save it. You can see the text: Hello World !

Devel plugin steps: Date Plugin ( Dinamic Plugin )

Now modify previous hello plugin to render date/time in wiki page dinamically. The Date Plugin macro-steps are:

  1. Define the keyword syntax: [date]
  2. Define the methods behavior when the keyword is encountered on a page: substitute tag [date] with current date/time.

The connectTo method is:

  function connectTo($mode) 
    {
    $this->Lexer->addSpecialPattern('\[date\]',$mode,'plugin_date');
    }

The render method is:

  function render($mode, &$renderer, $data) 
    {
    if($mode == 'xhtml')
      {
      $renderer->doc .= date('r');
      return true;
      }
      return false;
    }

The Date Plugin code is:

File syntax.php:

<?php
/**
* Plugin Date: Insert current date/time.
* 
* @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author     Riccardo Pisanu <rkpisanu@yahoo.it>
*/
 
// must be run within DokuWiki
if(!defined('DOKU_INC')) die();
 
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_date extends DokuWiki_Syntax_Plugin 
 
  {
 
  function getInfo() 
    {
    return array('author' => 'Riccardo Pisanu',
                 'email'  => 'rkpisanu@yahoo.it',
                 'date'   => '2013-01-11',
                 'name'   => 'Date Plugin',
                 'desc'   => 'Date Plugin Example.',
                 'url'    => 'http://rkpisanu.altervista.org/doku.php?id=dokuwiki:devel:plugins:howto');
    }
 
  function getType() { return 'substition'; }
 
  function getSort() { return 32; }
 
  function connectTo($mode) 
    {
    $this->Lexer->addSpecialPattern('\[date\]',$mode,'plugin_date');
    }
 
  function handle($match, $state, $pos, &$handler) 
    {
    return array($match, $state, $pos);
    }
 
  function render($mode, &$renderer, $data) 
    {
    if($mode == 'xhtml')
      {
      $renderer->doc .= date('r');
      return true;
      }
      return false;
    }
 
  }

Tag: [date]

Output: Fri, 11 Jan 2013 12:06:41 +0100

CmdExec Plugin

    <?php
    /**
     * Plugin CmdExec: Execute a sys command.
     * 
     * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
     * @author     Riccardo Pisanu <rkpisanu@yahoo.it>
     */
 
    // must be run within DokuWiki
    if(!defined('DOKU_INC')) die();
 
    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_cmdexec extends DokuWiki_Syntax_Plugin {
 
        function getInfo() {
            return array('author' => 'Riccardo Pisanu',
                         'email'  => 'rkpisanu@yahoo.it',
                         'date'   => '2010-01-10',
                         'name'   => 'CmdExec Plugin',
                         'desc'   => 'Execute a sys command.',
                         'url'    => 'http://www.dokuwiki.org/plugin:cmdexec');
        }
 
        function getType() { return 'substition'; }
        function getSort() { return 32; }
 
        function connectTo($mode) {
            $this->Lexer->addSpecialPattern('\[cmdexec\]',$mode,'plugin_cmdexec');
        }
 
        function handle($match, $state, $pos, &$handler) {
            return array($match, $state, $pos);
        }
 
        function render($mode, &$renderer, $data) {
            if($mode == 'xhtml'){
                $output = shell_exec('pwd');
                $renderer->doc .= "<pre>$output</pre>";
                return true;
            }
            return false;
        }
    }

Tag: [cmdexec]

Output: /var/www/crmas

Modify function connectTo add function postConnect :

Modify function connectTo to accept many parameters and add function postConnect to close parsing parameters :

  function connectTo($mode) {$this->Lexer->addEntryPattern('<cmdexec(?=.*?>.*?</cmdexec>)',$mode,'plugin_cmdexec');}
  function postConnect(){$this->Lexer->addExitPattern('</cmdexec>','plugin_cmdexec');}

Tag:

<cmdexec>

</cmdexec>

Output:

/var/www/crmas

/var/www/crmas

/var/www/crmas

Note: Why have we 3 rows instead 1 row ? To find out it, we need a debug version.

This is the complete source code:

    <?php
    /**
     * Plugin CmdExec: Execute a sys command.
     * 
     * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
     * @author     Riccardo Pisanu <rkpisanu@yahoo.it>
     */
 
    // must be run within DokuWiki
    if(!defined('DOKU_INC')) die();
 
    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_cmdexec extends DokuWiki_Syntax_Plugin {
 
        function getInfo() {
            return array('author' => 'Riccardo Pisanu',
                         'email'  => 'rkpisanu@yahoo.it',
                         'date'   => '2010-01-10',
                         'name'   => 'CmdExec Plugin',
                         'desc'   => 'Execute a sys command.',
                         'url'    => 'http://www.dokuwiki.org/plugin:cmdexec');
        }
 
        function getType() { return 'substition'; }
        function getSort() { return 32; }
 
        function connectTo($mode) {
            $this->Lexer->addEntryPattern('<cmdexec(?=.*?>.*?</cmdexec>)',$mode,'plugin_cmdexec');
        }
 
        function postConnect(){
            $this->Lexer->addExitPattern('</cmdexec>','plugin_cmdexec');
        }
 
        function handle($match, $state, $pos, &$handler) {
            return array($match, $state, $pos);
        }
 
        function render($mode, &$renderer, $data) {
            if($mode == 'xhtml'){
                $output = shell_exec('pwd');
                $renderer->doc .= "<pre>$output</pre>";
                return true;
            }
            return false;
        }
    }

Debug Version:

We use a dbg() function to print function string and variable value. The problem is the call of function render(), called 3 times with mode = xhtml with the following match type:

DOKU_LEXER_ENTER : matched our tag

DOKU_LEXER_UNMATCHED : after matched our tag

DOKU_LEXER_EXIT : exit matched our tag

    <?php
    /**
     * Plugin CmdExec: Execute a sys command.
     * 
     * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
     * @author     Riccardo Pisanu <rkpisanu@yahoo.it>
     */
 
    // must be run within DokuWiki
    if(!defined('DOKU_INC')) die();
 
    if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
    require_once DOKU_PLUGIN.'syntax.php';
 
#dbg($GLOBALS);
 
 
 
    /**
     * All DokuWiki plugins to extend the parser/rendering mechanism
     * need to inherit from this class
     */
    class syntax_plugin_cmdexec extends DokuWiki_Syntax_Plugin {
 
        function getInfo() {
            return array('author' => 'Riccardo Pisanu',
                         'email'  => 'rkpisanu@yahoo.it',
                         'date'   => '2010-01-10',
                         'name'   => 'CmdExec Plugin',
                         'desc'   => 'Execute a sys command.',
                         'url'    => 'http://www.dokuwiki.org/plugin:cmdexec');
        }
 
        function getType() { return 'substition'; }
        function getSort() { return 32; }
 
        function connectTo($mode) {
            dbg('function connectTo($mode)-->'.$mode);
            $this->Lexer->addEntryPattern('<cmdexec(?=.*?>.*?</cmdexec>)',$mode,'plugin_cmdexec');
        }
 
        function postConnect(){
            dbg('function postConnect()');
            $this->Lexer->addExitPattern('</cmdexec>','plugin_cmdexec');
        }
 
        function handle($match, $state, $pos, &$handler) {
            dbg('function handle($match, $state, $pos, &$handler)-->'.' match = '.$match.' state = '.$state.' pos = '.$pos);
            return array($match, $state, $pos);
        }
 
        function render($mode, &$renderer, $data) {
            dbg('function render($mode, &$renderer, $data)-->'.' mode = '.$mode.' data = '.$data);
            if($mode == 'xhtml'){
                $output = shell_exec('pwd');
                $renderer->doc .= "<pre>$output</pre>";
                return true;
            }
            return false;
        }
    }

Tag:

<cmdexec>

</cmdexec>

Output:

function render($mode, &$renderer, $data)–> mode = metadata data = Array

function render($mode, &$renderer, $data)–> mode = metadata data = Array

function render($mode, &$renderer, $data)–> mode = metadata data = Array

function render($mode, &$renderer, $data)–> mode = xhtml data = Array

function render($mode, &$renderer, $data)–> mode = xhtml data = Array

function render($mode, &$renderer, $data)–> mode = xhtml data = Array

function render($mode, &$renderer, $data)–> mode = metadata data = Array

function render($mode, &$renderer, $data)–> mode = metadata data = Array

function render($mode, &$renderer, $data)–> mode = metadata data = Array

/var/www/crmas

/var/www/crmas

/var/www/crmas

Refactory indent and manage match:

To verify howto manage dokuwiki parsing, now debug parameter received by render function. Please attention: the debug output is interpreted by the browser, so some tag are hide. To avoid this, view the html source between <!– wikipage start –> and <!– wikipage stop –> tag.

<?php
/**
* Plugin CmdExec: Execute a sys command.
* 
* @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author     Riccardo Pisanu <rkpisanu@yahoo.it>
*/
 
// must be run within DokuWiki
if(!defined('DOKU_INC')) die();
 
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once DOKU_PLUGIN.'syntax.php';
 
#dbg($GLOBALS);
 
 
 
/**
* All DokuWiki plugins to extend the parser/rendering mechanism
* need to inherit from this class
*/
class syntax_plugin_cmdexec extends DokuWiki_Syntax_Plugin 
  {
 
  function getInfo() 
    {
    return array('author' => 'Riccardo Pisanu',
                 'email'  => 'rkpisanu@yahoo.it',
                 'date'   => '2010-01-10',
                 'name'   => 'CmdExec Plugin',
                 'desc'   => 'Execute a sys command.',
                 'url'    => 'http://www.dokuwiki.org/plugin:cmdexec');
    }
 
  function getType() 
    { 
    return 'substition'; 
    }
 
  function getSort() 
    { 
    return 32; 
    }
 
  function connectTo($mode) 
    {
    dbg('function connectTo($mode)-->'.$mode);
    $this->Lexer->addEntryPattern('<cmdexec(?=.*?>.*?</cmdexec>)',$mode,'plugin_cmdexec');
    }
 
  function postConnect()
    {
    dbg('function postConnect()');
    $this->Lexer->addExitPattern('</cmdexec>','plugin_cmdexec');
    }
 
  function handle($match, $state, $pos, &$handler) 
    {
    dbg('function handle($match, $state, $pos, &$handler)-->'.' match = '.$match.' state = '.$state.' pos = '.$pos);
    return array($match, $state, $pos);
    }
 
/*  function render($mode, &$renderer, $data) 
    {
    dbg('function render($mode, &$renderer, $data)-->'.' mode = '.$mode.' data = '.$data);
    print_r($data);
    if($mode == 'xhtml')
      {
      $output = shell_exec('pwd');
      $renderer->doc .= "<pre>$output</pre>";
      }
    return true;
    } */
 
  function render($mode, &$renderer, $data) 
    {
    //dbg('function render($mode, &$renderer, $data)-->'.' mode = '.$mode.' data = '.$data);
    //print_r($data);
    if ($mode!='xhtml') return;
 
    @list($match, $state, $pos) = $data;
    dbg('function render-->list'.' MATCH = '.$match.' STATE = '.$state.' POS = '.$pos);
 
    switch ($state) 
      {
 
      case DOKU_LEXER_ENTER:
        break;
 
      case DOKU_LEXER_UNMATCHED:
        $output = shell_exec('pwd');
        $renderer->doc .= "<pre>$output</pre>";
        break;
 
      case DOKU_LEXER_EXIT:
        break;
 
      }
 
    return true;
 
    }
 
 
  }
 
?>

Tag:

<cmdexec>

</cmdexec>

Output:

function render–>list MATCH = <cmdexec STATE = 1 POS = 1

function render–>list MATCH = >[\n] STATE = 3 POS = 9

function render–>list MATCH = </cmdexec> STATE = 4 POS = 11

/var/www/crmas

Following the link:

http://dev.splitbrain.org/reference/dokuwiki/nav.html?inc/parser/handler.php.source.html

we noted:

18  /**#@+
19   * lexer mode constant
20   */
21  define("DOKU_LEXER_ENTER", 1);
22  define("DOKU_LEXER_MATCHED", 2);
23  define("DOKU_LEXER_UNMATCHED", 3);
24  define("DOKU_LEXER_EXIT", 4);
25  define("DOKU_LEXER_SPECIAL", 5);
26  /**#@-*/

so :

STATE = 1 means DOKU_LEXER_ENTER

STATE = 3 means DOKU_LEXER_UNMATCHED

STATE = 4 means DOKU_LEXER_EXIT

and the pos is the position of first character matching.

Focus on render function and its parsing:

We use the following function:

preg_split('/>/u',$match,2);

to split text into two string: the first is the parameters command and the second is the text between the tag. This 2 items are split by the > character. The /u flag is for unicode string.

<?php
/**
* Plugin CmdExec: Execute a sys command.
* 
* @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author     Riccardo Pisanu <rkpisanu@yahoo.it>
*/
 
// must be run within DokuWiki
if(!defined('DOKU_INC')) die();
 
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once DOKU_PLUGIN.'syntax.php';
 
//dbg($GLOBALS);
 
 
 
/**
* All DokuWiki plugins to extend the parser/rendering mechanism
* need to inherit from this class
*/
class syntax_plugin_cmdexec extends DokuWiki_Syntax_Plugin 
  {
 
  function getInfo() 
    {
    return array('author' => 'Riccardo Pisanu',
                 'email'  => 'rkpisanu@yahoo.it',
                 'date'   => '2010-01-10',
                 'name'   => 'CmdExec Plugin',
                 'desc'   => 'Execute a sys command.',
                 'url'    => 'http://www.dokuwiki.org/plugin:cmdexec');
    }
 
  function getType() 
    { 
    return 'substition'; 
    }
 
  function getSort() 
    { 
    return 32; 
    }
 
  function connectTo($mode) 
    {
    //dbg('function connectTo($mode)-->'.$mode);
    $this->Lexer->addEntryPattern('<cmdexec(?=.*?>.*?</cmdexec>)',$mode,'plugin_cmdexec');
    }
 
  function postConnect()
    {
    //dbg('function postConnect()');
    $this->Lexer->addExitPattern('</cmdexec>','plugin_cmdexec');
    }
 
  function handle($match, $state, $pos, &$handler) 
    {
    //dbg('function handle($match, $state, $pos, &$handler)-->'.' match = '.$match.' state = '.$state.' pos = '.$pos);
    return array($match, $state, $pos);
    }
 
  function render($mode, &$renderer, $data) 
    {
    //dbg('function render($mode, &$renderer, $data)-->'.' mode = '.$mode.' data = '.$data);
    //print_r($data);
    if ($mode!='xhtml') return;
 
    @list($match, $state, $pos) = $data;
    //dbg('function render-->list'.' MATCH = '.$match.' STATE = '.$state.' POS = '.$pos);
 
    switch ($state) 
      {
 
      case DOKU_LEXER_ENTER:
        break;
 
      case DOKU_LEXER_UNMATCHED:
        // $matches[0] is the parameters <cmdexec [parameters]>
        // $matches[1] is the text inside the block <cmdexec [parameters]> </cmdexec>
        $matches = preg_split('/>/u',$match,2);
        $matches[0] = trim($matches[0]);
        if ( trim($matches[0]) == '' ) 
          {
	  $matches[0] = NULL;
          }
        $output = shell_exec($matches[1]);
        $renderer->doc .= "The input is: $matches[1] <BR> The output is: <BR> <pre>$output</pre>";
        break;
 
      case DOKU_LEXER_EXIT:
        break;
 
      }
 
    return true;
 
    }
 
 
  }
 
?>

Tag:

<cmdexec>

pwd;ls -ltr *.php

</cmdexec>

Output:

The input is: pwd;ls -ltr *.php

The output is:

/var/www/crmas

-rw-r–r– 1 www-data www-data 10676 Feb 14 2009 feed.php

-rw-r–r– 1 www-data www-data 2206 Feb 14 2009 doku.php

-rw-r–r– 1 www-data www-data 185 Feb 14 2009 index.php

Parsing parameters:

We use the following function:

preg_match('/width=([0-9]+)/i', $matches[0], $match_width);
preg_match('/height=([0-9]+)/i', $matches[0], $match_height);
preg_match('/name=([a-zA-Z_0-9]+)/i', $matches[0], $match_name);

It split the string and the parameters in a array if it's matching.

<?php
/**
* Plugin CmdExec: Execute a sys command.
* 
* @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author     Riccardo Pisanu <rkpisanu@yahoo.it>
*/
 
// must be run within DokuWiki
if(!defined('DOKU_INC')) die();
 
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once DOKU_PLUGIN.'syntax.php';
 
//dbg($GLOBALS);
 
 
 
/**
* All DokuWiki plugins to extend the parser/rendering mechanism
* need to inherit from this class
*/
class syntax_plugin_cmdexec extends DokuWiki_Syntax_Plugin 
  {
 
  function getInfo() 
    {
    return array('author' => 'Riccardo Pisanu',
                 'email'  => 'rkpisanu@yahoo.it',
                 'date'   => '2010-01-10',
                 'name'   => 'CmdExec Plugin',
                 'desc'   => 'Execute a sys command.',
                 'url'    => 'http://www.dokuwiki.org/plugin:cmdexec');
    }
 
  function getType() 
    { 
    return 'substition'; 
    }
 
  function getSort() 
    { 
    return 32; 
    }
 
  function connectTo($mode) 
    {
    //dbg('function connectTo($mode)-->'.$mode);
    $this->Lexer->addEntryPattern('<cmdexec(?=.*?>.*?</cmdexec>)',$mode,'plugin_cmdexec');
    }
 
  function postConnect()
    {
    //dbg('function postConnect()');
    $this->Lexer->addExitPattern('</cmdexec>','plugin_cmdexec');
    }
 
  function handle($match, $state, $pos, &$handler) 
    {
    //dbg('function handle($match, $state, $pos, &$handler)-->'.' match = '.$match.' state = '.$state.' pos = '.$pos);
    return array($match, $state, $pos);
    }
 
  function render($mode, &$renderer, $data) 
    {
    //dbg('function render($mode, &$renderer, $data)-->'.' mode = '.$mode.' data = '.$data);
    //print_r($data);
    if ($mode!='xhtml') return;
 
    @list($match, $state, $pos) = $data;
    //dbg('function render-->list'.' MATCH = '.$match.' STATE = '.$state.' POS = '.$pos);
 
    switch ($state) 
      {
 
      case DOKU_LEXER_ENTER:
        break;
 
      case DOKU_LEXER_UNMATCHED:
        //** Split Parameters and Text Inside the block ** 
        // $matches[0] is the parameters <cmdexec [parameters]>
        // $matches[1] is the text inside the block <cmdexec [parameters]> </cmdexec>
        $matches = preg_split('/>/u',$match,2);
        $matches[0] = trim($matches[0]);
        if ( trim($matches[0]) == '' ) 
          {
	  $matches[0] = NULL;
          }
        //** Parsing Parameters **
        preg_match('/width=([0-9]+)/i', $matches[0], $match_width);
        preg_match('/height=([0-9]+)/i', $matches[0], $match_height);
        preg_match('/name=([a-zA-Z_0-9]+)/i', $matches[0], $match_name);
        //** Rendering **
        $output = shell_exec($matches[1]);
        $renderer->doc .= "The input is: $matches[1] <BR>\n";
        $renderer->doc .= "Parameters: = $matches[0] <BR>\n";
        $renderer->doc .= "width = $match_width[1] <BR>\n";
        $renderer->doc .= "height = $match_height[1] <BR>\n"; 
        $renderer->doc .= "name = $match_name[1] <BR>\n"; 
        $renderer->doc .= "The output is: <BR>\n";
        $renderer->doc .= "<pre>$output</pre>";
        break;
 
      case DOKU_LEXER_EXIT:
        break;
 
      }
 
    return true;
 
    }
 
 
  }
 
?>

Tag:

<cmdexec width=12345 height=6789 name=asdf123 >

pwd;ls -ltr *.php

</cmdexec>

Output:

The input is: pwd;ls -ltr *.php

Parameters: = width=12345 height=6789 name=asdf123

width = 12345

height = 6789

name = asdf123

The output is:

/var/www/crmas

-rw-r–r– 1 www-data www-data 10676 Feb 14 2009 feed.php

-rw-r–r– 1 www-data www-data 2206 Feb 14 2009 doku.php

-rw-r–r– 1 www-data www-data 185 Feb 14 2009 index.php

dokuwiki/devel/plugins/howto.txt · Last modified: 2013/01/11 11:05 by rkpisanu
www.chimeric.de Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0





Mail