1<?php
2/**
3 * Plugin jira: Creates links into JIRA from JIRA ids.
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Robert Lopuszanski <rlop@gmx.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_jira extends DokuWiki_Syntax_Plugin {
18
19    /**
20     * return some info
21     */
22    function getInfo(){
23        return array(
24            'author' => 'Robert Lopuszanski',
25            'email'  => 'rlop@gmx.de',
26            'date'   => '2009-09-02',
27            'name'   => 'JIRA plugin',
28            'desc'   => 'Creates links into JIRA from JIRA ids',
29            'url'    => 'http://www.dokuwiki.org/plugins',
30        );
31    }
32
33    /**
34     * What kind of syntax are we?
35     */
36    function getType(){
37        return 'substition';
38    }
39
40    function getSort(){ return 359; }
41
42    function connectTo($mode) {
43		$projectKeys = array('KEY1', 'KEY2');
44		foreach($projectKeys as $key) {
45			$this->Lexer->addSpecialPattern('\(' . $key . '-\d+\)',$mode,'plugin_jira');
46		}
47    }
48
49
50    /**
51     * Handle the match
52     */
53    function handle($match, $state, $pos, &$handler){
54        return array( substr( $match, 1, strlen($match) - 2 ));
55    }
56
57    /**
58     * Create output
59     */
60    function render($format, &$renderer, $data) {
61        if($format == 'xhtml'){
62            $renderer->doc .= '(<a href="http://host/browse/' . $data[0] . '" >' . $data[0] . '</a>)';
63		}
64        return true;
65    }
66}
67?>
68