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_tree 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]ugtree\s+[0-9]+[^>]*>', $mode, 'plugin_bugzillaint_tree');
46	}
47
48
49	/**
50	 * Handle matches
51	 */
52	public function handle($match, $state, $pos, Doku_Handler $handler){
53		$matches = array();
54
55		// found tree
56		if ( preg_match('/<[Bb]ugtree\s+([0-9]+)[^>]*>/', $match, $submatch) ) {
57			$matches['tree'] = array(
58				'id' => $submatch[1],
59				'depth' => preg_match('/depth:([0-9])/i', $match, $found) ? $found[1] : $this->getConf('tree_depth'),
60				'hideResolved' => !!preg_match('/hideResolved/i', $match, $found),
61				'extras' => preg_match('/extras:([a-z_,]+)/i', $match, $found) ? trim($found[1]) : $this->getConf('list_default_extras')
62			);
63		}
64
65		return $matches;
66	}
67
68
69
70	/**
71	 * Render the output
72	 *
73	 * @param string $mode
74	 * @param Doku_Renderer $renderer
75	 * @param array $data
76	 * @return boolean
77	 */
78	public function render($mode, Doku_Renderer $renderer, $data) {
79		if ($mode != 'xhtml') return false;
80
81		// render tree
82		if ( isset( $data['tree'] ) ) {
83
84			$render = $this->loadHelper('bugzillaint_render', false);
85			$attrs = $render->renderAttributes( $data['tree'] );
86
87			$label = $data['tree']['id'];
88			$url = $this->getConf('show_baseurl') . $data['tree']['id'];
89
90			$renderer->doc .= '<div class="bugzillatree loading" '. $attrs .'>'
91							. '  <p class="heading">'
92						    . '    <a class="bzref" href="'.htmlspecialchars($url).'">'.htmlspecialchars($label).'</a>'
93						    . '    <span class="blocked-by-msg">' .htmlspecialchars($this->getLang('msg_blocked_by')). '</span>'
94						    . '  </p>'
95							. '  <ul>'
96							. '    <li class="placeholder"></li>'
97							. '    <li class="empty-msg">'
98							. '      <div class="li">' .htmlspecialchars($this->getLang('msg_empty')). '</div>'
99							. '    </li>'
100							. '  </ul>'
101							. '</div>';
102		}
103
104		return true;
105	}
106
107
108}
109