1<?php
2/**
3 * Return a value from $_GET
4 * write {{arg>message}} to get "hello" when .../page?message=hello
5 * note that the only permanent argument is "id"
6 * !! You probably want ~~NOCACHE~~ with this plugin !!
7 *
8 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
9 * @author     Olivier Fraysse <olivier at picapo dot com>
10 * @version    1.0
11 */
12
13if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
14if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
15require_once(DOKU_PLUGIN.'syntax.php');
16
17class syntax_plugin_arguments extends DokuWiki_Syntax_Plugin {
18    /**
19     * return some info
20     */
21    function getInfo(){
22        return array(
23            'author' => 'Olivier Fraysse',
24            'email'  => 'olivier at picapo dot com',
25            'date'   => '2006-01-05',
26            'name'   => 'GET arguments Plugin',
27            'desc'   => 'Return an element from $_GET array',
28            'url'    => 'http://wiki.splitbrain.org/plugin:arguments',
29        );
30    }
31
32    /**
33     * What kind of syntax are we?
34     */
35    function getType(){
36        return 'substition';
37    }
38
39    /**
40     * What about paragraphs?
41     */
42    function getPType(){
43        return 'normal';
44    }
45
46    /**
47     * Where to sort in?
48     */
49    function getSort(){
50        return 300;
51    }
52
53
54    /**
55     * Connect pattern to lexer
56     * match for {{arg>something}}
57     */
58    function connectTo($mode) {
59        $this->Lexer->addSpecialPattern('\{\{arg>[^\}]+\}\}',$mode,'plugin_arguments');
60    }
61
62
63    /**
64     * Handle the match
65     */
66    function handle($match, $state, $pos, &$handler){
67        return substr($match,6,-2); //strip markup from start and end
68    }
69
70    /**
71     * Create output
72     */
73    function render($mode, &$renderer, $data) {
74        if(isset( $_GET[$data])){
75            $renderer->doc .= $_GET[$data];
76            return true;
77        }
78        return false;
79    }
80
81}
82
83//Setup VIM: ex: et ts=4 enc=utf-8 :
84