1<?php
2/**
3 * Plugin rtlink: Links to Request Tracker tickets
4 *
5 *  Thanks to Stefan Hechenberger for the inspiration through his websvn plugin
6 *
7 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
8 * @author     Gregg Berkholtz <gregg@tocici.com>
9 */
10
11if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
12if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
13require_once(DOKU_PLUGIN.'syntax.php');
14
15
16
17//-----------------------------------CONFIGURE RTLINK ROOT HERE---------
18global $rtlink_root_url;
19$rtlink_root_url = "http://rt.tocici.com/";
20//----------------------------------------------------------------------
21
22
23
24/**
25 * All DokuWiki plugins to extend the parser/rendering mechanism
26 * need to inherit from this class
27 */
28class syntax_plugin_rtlink extends DokuWiki_Syntax_Plugin {
29
30    /**
31     * return some info
32     */
33    function getInfo(){
34        return array(
35            'author' => 'Gregg Berkholtz',
36            'email'  => 'gregg@tocici.com',
37            'date'   => '2012-04-25',
38            'name'   => 'rtlink Plugin',
39            'desc'   => 'Generates links to RT:: Tickets.',
40            'url'    => 'http://wiki.splitbrain.org/plugin:rtlink',
41        );
42    }
43
44    /**
45     * What kind of syntax are we?
46     */
47    function getType(){
48        return 'substition';
49    }
50
51
52    /**
53     * Where to sort in?
54     */
55    function getSort(){
56        return 921;
57    }
58
59
60    /**
61     * Connect pattern to lexer
62     */
63    function connectTo($mode) {
64      $this->Lexer->addSpecialPattern('[rR][tT][0-9]+',$mode, substr(get_class($this),7));
65    }
66
67
68    /**
69     * Handle the match
70     */
71    function handle($match, $state, $pos, &$handler){
72        $match = html_entity_decode(substr($match, 2));
73        return array($match);
74    }
75
76    /**
77     * Create output
78     */
79    function render($mode, &$renderer, $data) {
80        global $rtlink_root_url;
81        list($ticket) = $data;
82        $url = $rtlink_root_url."Ticket/Display.html?id=$ticket";
83        if($mode == 'xhtml'){
84                $renderer->doc .= "<a href=\"".$url."\">RT$ticket</a>";
85           }
86        return true;
87        //return false;
88    }
89}
90