1<?php
2/**
3 * Plugin syntaxmantis: Displays link to Mantis-BT
4 *
5 * Syntax: ~~Mantis:123~~ - will be replaced with link to Mantis issue 123 with icon next to it
6 *
7 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
8 * based on: https://www.mantisbt.org/wiki/doku.php/mantisbt:issue:8253?rev=1194413581
9 * and https://www.mantisbt.org/wiki/doku.php/mantisbt:issue:7075:integration_with_dokuwiki#mantis_syntax_plug-in
10 */
11
12if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
13if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
14require_once(DOKU_PLUGIN.'syntax.php');
15
16class syntax_plugin_syntaxmantis extends DokuWiki_Syntax_Plugin {
17
18    function getType(){
19        return 'substition';
20    }
21
22    function getPType(){
23        return 'normal';
24    }
25
26    function getSort(){
27        return 998;
28    }
29
30    function connectTo($mode) {
31    	$this->Lexer->addSpecialPattern('~~Mantis:[0-9]+~~',$mode,'plugin_syntaxmantis');
32    }
33
34    function handle($match, $state, $pos, Doku_Handler $handler){
35	$match = substr( $match, 9, -2 ); // strip "~~Mantis:" from start and "~~" from end
36        return array(strtolower( $match ));
37    }
38
39    function render($mode, Doku_Renderer $renderer, $data) {
40        if($mode == 'xhtml'){
41		$link['target'] = $conf['target']['wiki'];
42		$link['style']  = '';
43		$link['pre']    = '';
44		$link['suf']    = '';
45		$link['more']   = '';
46		$link['class']  = 'mantislink';
47		$link['url']    = $this->getConf('mantis_server') . '/view.php?id=' . $data[0];
48		$link['name']   = $this->getConf('LinkPrefix') . $data[0];
49		$link['title']  = $renderer->_xmlEntities($url);
50
51		//output formatted
52		$renderer->doc .= $renderer->_formatLink($link);
53	}
54        return true;
55    }
56}
57?>
58