1<?php
2
3
4/**
5 */
6
7
8if (!defined('DOKU_INC')) die();
9if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
10
11
12require_once DOKU_PLUGIN.'syntax.php';
13
14/**
15 */
16class syntax_plugin_bugzillaint_link extends DokuWiki_Syntax_Plugin {
17
18
19	/**
20	 * Gets plugin type
21	 *
22	 * @return string
23	 */
24	public function getType() {
25		return 'substition';
26	}
27
28
29	/**
30	 * Gets plugin sort order
31	 *
32	 * @return number
33	 */
34	public function getSort() {
35		return 10;
36	}
37
38
39	/**
40	 * Plugin mode connection
41	 *
42	 * @param string $mode
43	 */
44	public function connectTo($mode) {
45		$this->Lexer->addSpecialPattern('[Bb]ug\s[0-9]+(?:\s<[a-z_,^>]+>)?', $mode, 'plugin_bugzillaint_link');
46	}
47
48
49	/**
50	 * Handle matches
51	 */
52	public function handle($match, $state, $pos, Doku_Handler $handler){
53		$matches = array();
54
55		// found link
56		if ( preg_match('/^[Bb]ug\s([0-9]+)(?:\s<([a-z_,^>]+)>)?$/', $match, $submatch) ) {
57			$matches['link'] = array(
58				'id' => $submatch[1],
59				'extras' => isset($submatch[2]) ? trim($submatch[2]) : $this->getConf('link_default_extras')
60			);
61		}
62
63		return $matches;
64	}
65
66
67
68	/**
69	 * Render the output
70	 *
71	 * @param string $mode
72	 * @param Doku_Renderer $renderer
73	 * @param array $data
74	 * @return boolean
75	 */
76	public function render($mode, Doku_Renderer $renderer, $data) {
77		if ($mode != 'xhtml') return false;
78
79		// render link
80		if ( isset( $data['link'] ) ) {
81
82			$render = $this->loadHelper('bugzillaint_render', false);
83			$attrs = $render->renderAttributes( $data['link'] );
84
85			$label = $data['link']['id'];
86			$url = $this->getConf('show_baseurl') . (int) $data['link']['id'];
87
88			$renderer->doc .= '<span class="bugzillalink loading" '.$attrs.'>'
89							.   '<a class="bzref" href="' . htmlspecialchars($url) . '">'
90							.     htmlspecialchars($label)
91							.   '</a>'
92							. '</span>';
93		}
94
95		return true;
96	}
97
98
99}
100