<?php
/**
 * Return a value from $_GET
 * write {{arg>message}} to get "hello" when .../page?message=hello
 * note that the only permanent argument is "id"
 * !! You probably want ~~NOCACHE~~ with this plugin !!
 * 
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Olivier Fraysse <olivier at picapo dot com>
 * @version    1.0
 */

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');

class syntax_plugin_arguments extends DokuWiki_Syntax_Plugin {
    /**
     * return some info
     */
    function getInfo(){
        return array(
            'author' => 'Olivier Fraysse',
            'email'  => 'olivier at picapo dot com',
            'date'   => '2006-01-05',
            'name'   => 'GET arguments Plugin',
            'desc'   => 'Return an element from $_GET array',
            'url'    => 'http://wiki.splitbrain.org/plugin:arguments',
        );
    }

    /**
     * What kind of syntax are we?
     */
    function getType(){
        return 'substition';
    }
   
    /**
     * What about paragraphs?
     */
    function getPType(){
        return 'normal';
    }

    /**
     * Where to sort in?
     */ 
    function getSort(){
        return 300;
    }


    /**
     * Connect pattern to lexer
     * match for {{arg>something}}
     */
    function connectTo($mode) {
        $this->Lexer->addSpecialPattern('\{\{arg>[^\}]+\}\}',$mode,'plugin_arguments');
    }


    /**
     * Handle the match
     */
    function handle($match, $state, $pos, &$handler){
        return substr($match,6,-2); //strip markup from start and end
    }

    /**
     * Create output
     */
    function render($mode, &$renderer, $data) {
        if(isset( $_GET[$data])){
            $renderer->doc .= $_GET[$data];
            return true;
        }
        return false;
    }

}

//Setup VIM: ex: et ts=4 enc=utf-8 :