1 <?php
2 // Copyright 2012 Andreas Parschalk
3 
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13 
14 // You should have received a copy of the GNU General Public License
15 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 
17 if(!defined('DOKU_INC')) die();
18 if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
19 require_once(DOKU_PLUGIN.'syntax.php');
20 require_once('cUrlHelper.php');
21 require_once('BzBug.php');
22 
23 class syntax_plugin_bugzillaHTTP extends DokuWiki_Syntax_Plugin {
24 
25 
26 	private $starttime;
27 	private $endtime;
28 
29 	function getInfo(){
30 		return array(
31 				'author' => 'andreas parschalk',
32 				'email'  => 'dprskavec@gmail.com',
33 				'date'   => '2012-08-17',
34 				'name'   => 'bugzilla http plugin',
35 				'desc'   => 'Gets information about bugs via HTTP (xml-view).',
36 				'url'    => 'http://www.dokuwiki.org/plugin:bugzillaHTTP',
37 		);
38 	}
39 
40 	function getType()  {
41 		return 'substition';
42 	}
43 	function getPType() {
44 		return 'normal';
45 	}
46 	function getSort()  {
47 		return 777;
48 	}
49 
50 	function connectTo($mode) {
51 		$this->Lexer->addSpecialPattern('^\[buglist\s*\|\s*\d+\s*(?:\s*,\s*\d+)*\s*\]', $mode, 'plugin_bugzillaHTTP');
52 	}
53 
54 
55 	function fetchBugs($idString) {
56 	//	$this->starttime = microtime(true);
57 		$url = $this->getConf('bug_xml_url');
58 		$url .= $idString;
59 		$curl = new cUrlHelper();
60 		$content = $curl->fetchContent($url);
61 		$bug = new BzBug();
62 		$buglist = $bug->unmarshall($content);
63 	//	$this->endtime = microtime(true);
64 		return $buglist;
65 	}
66 
67 	function handle($match, $state, $pos, &$handler) {
68 		preg_match('/^\[buglist\s*\|([\s(\d),]+)\]/', $match, $submatch);
69 		$idString = preg_replace('/\s/', '', $submatch[1]);
70 		return $idString;
71 	}
72 
73 
74 	function uncachedHandle($idString) {
75 		return $this->fetchBugs($idString);
76 	}
77 
78 
79 	function render($mode, &$renderer, $idString) {
80 		$bugData = $this->uncachedHandle($idString);
81 		//var_dump($bugData);
82 		$url = $this->getConf('bug_url');
83 		if($mode == 'xhtml'){
84 			// render tableheader
85 			$bugtable = '<table class="bugtable"><tr><th>ID</th><th>PRI</th><th>SEV</th><th>ASSIGNEE</th><th>STATUS</th><th>SHORT DESCRIPTION</th></tr>';
86 			//print_r($data_bugs);
87 			foreach($bugData as $bug) {
88 				$rowclass = "bugtable_".$bug->getPriority();
89 				if ($bug->getStatus() === 'CLOSED') {
90 					$rowclass = "bugtable_closed";
91 				}
92 				if ($bug->getStatus() === 'VERIFIED') {
93 					$rowclass = "bugtable_verified";
94 				}
95 				if ($bug->getStatus() === 'RESOLVED') {
96 					$rowclass = "bugtable_resolved";
97 				}
98 				$bugtable .= '<tr class="'.$rowclass.'">';
99 				$bugtable .= '<td><a href="'.$url . $bug->getId().'" target="_blank">'.$bug->getId().'</a></td><td>'.$bug->getPriority().'</td><td>'.$bug->getSeverity().'</td><td>'.
100 						$bug->getAssignedTo().'</td><td>'.$bug->getStatus().'</td><td>'.$bug->getShortDesc().'</td>';
101 				$bugtable .= '</tr>';
102 			}
103 			$bugtable .= '</table>';
104 
105 			$renderer->doc .= $bugtable;
106 		//	$renderer->doc .= 'fetchted buglist in '.($this->endtime - $this->starttime) .'s';
107 			return true;
108 
109 		}
110 		return false;
111 	}
112 
113 }
114 ?>
115