1<?php
2/**
3 * Bugzilla-links syntax plugin for DokuWiki
4 *
5 * @author Antonin Kral <a.kral@bobek.cz>
6 * @author christian studer <christian.studer@meteotest.ch>
7 * @license GPL2 http://www.gnu.org/licenses/gpl-2.0.html
8 */
9
10// Must be run within DokuWiki
11if (!defined('DOKU_INC')) die();
12if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
13
14require_once DOKU_PLUGIN.'syntax.php';
15
16/**
17 * The Bugzilla-links syntay plugin itself
18 *
19 * @author christian studer <christian.studer@meteotest.ch>
20 */
21class syntax_plugin_bugzillalinks extends DokuWiki_Syntax_Plugin {
22	/**
23	 * Gets plugin type
24	 *
25	 * @return string
26	 */
27	public function getType() {
28		return 'substition';
29	}
30
31	/**
32	 * Gets plugin sort order
33	 *
34	 * @return number
35	 */
36	public function getSort() {
37		return 331; // Belongs to externallink somehow
38	}
39
40
41	/**
42	 * Plugin mode connection
43	 *
44	 * @param string $mode
45	 */
46	public function connectTo($mode) {
47		$this->Lexer->addSpecialPattern('[Bb]ug\s*\d+', $mode, 'plugin_bugzillalinks');
48	}
49
50	/**
51	 * Match handling
52	 *
53	 * @param string $match
54	 * @param string $state
55	 * @param int $pos
56	 * @param Doku_Handler $handler
57	 * @return array
58	 */
59	public function handle($match, $state, $pos, &$handler){
60        if ( preg_match('/^[Bb]ug\s*(\d+)$/', $match, $bugMatch) ) {
61	      return array($match, $bugMatch[1]);
62        }
63        return array($match);
64	}
65
66	/**
67	 * Render the output
68	 *
69	 * @param string $mode
70	 * @param Doku_Renderer $renderer
71	 * @param array $data
72	 * @return boolean
73	 */
74	public function render($mode, &$renderer, $data) {
75		// Only render to xhtml
76		if($mode != 'xhtml') return false;
77
78		// Append the link to the issue
79		$renderer->doc .= '<a class="bugzillalink" href="' . $this->getConf('bugzillaserver') . $data[1] . '">' . $data[0] . '</a>';
80
81		return true;
82	}
83}
84