xref: /plugin/bez/syntax/qlink.php (revision a0cd8c785f18b483f73582b411767428d04a78f6)
1<?php
2// must be run within DokuWiki
3if(!defined('DOKU_INC')) die();
4
5if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
6require_once DOKU_PLUGIN.'syntax.php';
7/**
8 * All DokuWiki plugins to extend the parser/rendering mechanism
9 * need to inherit from this class
10 */
11class syntax_plugin_bez_qlink extends DokuWiki_Syntax_Plugin {
12
13    function getType() { return 'substition'; }
14    function getSort() { return 34; }
15	function connectTo($mode) {
16		$this->Lexer->addSpecialPattern('#[z]?[0-9]+',$mode,'plugin_bez_qlink');
17	}
18
19
20    function handle($match, $state, $pos, Doku_Handler $handler) {
21		$code = substr($match, 1, 1);
22		if ($code === 'z') {
23			$nr = substr($match, 2, strlen($match));
24			return array('z', $nr);
25		} else {
26			$nr = substr($match, 1, strlen($match));
27			return array('', $nr);
28		}
29    }
30
31    function render($mode, Doku_Renderer $renderer, $link) {
32		if ($mode == 'xhtml') {
33			$id = $_GET['id'];
34			$ex = explode(':', $id);
35
36			$lang_code = '';
37			/*english namespace*/
38			switch($ex[0]) {
39				case 'en':
40					$lang_code = $ex[0].':';
41			}
42			$nr = $link[1];
43			if ($link[0] === 'z') {
44				$renderer->doc .= '<a href="?id='.$lang_code.'bez:task:tid:'.$nr.'">#z'.$nr.'</a>';
45			} else {
46				$renderer->doc .= '<a href="?id='.$lang_code.'bez:issue:id:'.$nr.'">#'.$nr.'</a>';
47			}
48			return true;
49		}
50		return false;
51    }
52}
53