1<?php
2/**
3 * DokuWiki Syntax Plugin Medialist
4 *
5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author  Michael Klier <chi@chimeric.de>
7 */
8
9if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
10if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
11require_once(DOKU_PLUGIN.'syntax.php');
12
13/**
14 * All DokuWiki plugins to extend the parser/rendering mechanism
15 * need to inherit from this class
16 */
17class syntax_plugin_bashorg extends DokuWiki_Syntax_Plugin {
18
19    /**
20     * General Info
21     */
22    function getInfo(){
23        return array(
24            'author' => 'Patrick Lerner',
25            'email'  => 'PaddyLerner@gmail.com',
26            'date'   => '2008-08-02',
27            'name'   => 'bashorg',
28            'desc'   => 'Shows funny quotes from bash.org',
29            'url'    => 'https://www.dokuwiki.org/plugin:bashorg'
30        );
31    }
32
33    /**
34     * Syntax Type
35     *
36     * Needs to return one of the mode types defined in $PARSER_MODES in parser.php
37     */
38    function getType()  { return 'substition'; }
39    function getPType() { return 'block'; }
40    function getSort()  { return 299; }
41
42    /**
43     * Connect pattern to lexer
44     */
45    function connectTo($mode) {
46        $this->Lexer->addSpecialPattern('{{bashorg}}',$mode,'plugin_bashorg');
47    }
48
49    /**
50     * Handler to prepare matched data for the rendering process
51     */
52    function handle($match, $state, $pos, &$handler){
53        global $ID;
54
55        // catch the match
56        $match = substr($match,12,-2);
57
58        // process the match
59        if(empty($match) || $match == '@PAGE@') {
60            return array($ID);
61        } elseif(@file_exists(wikiFN($match))) {
62            return array(cleanID($match));
63        } else {
64            return array();
65        }
66
67    }
68
69    /**
70     * Handles the actual output creation.
71     */
72    function render($mode, &$renderer, $data) {
73
74        if($mode == 'xhtml'){
75            // disable caching
76            if(!empty($data[0])) {
77                include("bash.org.php");
78                $renderer->info['cache'] = false;
79                $renderer->doc .= $output;
80            }
81            return true;
82        }
83        return false;
84    }
85}
86//Setup VIM: ex: et ts=4 enc=utf-8 :
87