Lexer->addSpecialPattern(']*/>', $mode,'plugin_redissue'); $this->Lexer->addEntryPattern('/]*>(?=.*)', $mode,'plugin_redissue'); } function postConnect() { $this->Lexer->addExitPattern('', 'plugin_redissue'); } function getServerFromJson($server) { $json_file = file_get_contents(__DIR__.'/server.json'); $json_data = json_decode($json_file, true); if(isset($json_data[$server])) { return $json_data[$server]; } else { return null; } } function handle($match, $state, $pos, Doku_Handler $handler) { switch($state){ case DOKU_LEXER_SPECIAL : $data = array( 'state'=>$state, 'id'=> 0, 'text'=>$this->getLang('redissue.text.default') ); // Redmine Server preg_match("/server *= *(['\"])(.*?)\\1/", $match, $server); if (count($server) != 0) { $server_data = $this->getServerFromJson($server[2]); if( ! is_null($server_data)){ $data['server_url'] = $server_data['url']; $data['server_token'] = $server_data['api_token']; } } if (!isset($data['server_token'])) { $data['server_token'] = $this->getConf('redissue.API'); } if (!isset($data['server_url'])) { $data['server_url'] = $this->getConf('redissue.url'); } // Issue Id preg_match("/id *= *(['\"])#(\\d+)\\1/", $match, $id); if ((count($id) != 0) && ($id[2] != 0)) { $data['id'] = $id[2]; } else { $data['id'] = 0; } // Title preg_match("/title *= *(['\"])(.*?)\\1/", $match, $title); if( count($title) != 0 ) { $data['title'] = $title[2]; } // Short $data['short'] = $this->getConf('redissue.short'); preg_match("/short *= *(['\"])([0-1])\\1/", $match, $over_short); if( $over_short ){ $data['short'] = $over_short[2]; } // Text Access preg_match("/text *= *(['\"])(.*?)\\1/", $match, $text); if( count($text) != 0 ) { $data['text'] = $text[2]; } // Project Id preg_match("/project *= *(['\"])(.*?)\\1/", $match, $project); if( count($project) != 0 ) { $data['project_id'] = $project[2]; } // Tracker Id preg_match("/tracker *= *(['\"])(.*?)\\1/", $match, $tracker); if( count($tracker) != 0 ) { $data['tracker_id'] = $tracker[2]; } // Limit preg_match("/limit *= *(['\"])(\\d+)\\1/", $match, $limit); if( count($limit) != 0 ) { $data['limit'] = $limit[2]; } else { $data['limit'] = 25; } // Sort preg_match("/sort *= *(['\"])(.*?)\\1/", $match, $sort); if( count($sort) != 0 ) { $data['sort'] = $sort[2]; } else { $data['sort'] = ''; } return $data; case DOKU_LEXER_UNMATCHED : return array('state'=>$state, 'text'=>$match); default: return array('state'=>$state, 'bytepos_end' => $pos + strlen($match)); } } // Dokuwiki Renderer function render($mode, Doku_Renderer $renderer, $data) { if($mode != 'xhtml') return false; if($data['error']) { $renderer->doc .= $data['text']; return true; } $renderer->info['cache'] = false; switch($data['state']) { case DOKU_LEXER_SPECIAL: $this->renderRedissue($renderer, $data); break; case DOKU_LEXER_EXIT: $renderer->doc .= ''; case DOKU_LEXER_ENTER: case DOKU_LEXER_UNMATCHED: $renderer->doc .= $renderer->_xmlEntities($data['text']); break; } return true; } function renderRedissue($renderer, $data) { $this->detectBootstrap(); $redmine = new DokuwikiRedmine(); if(empty($data['server_token'])){ $this->renderIssueLink($renderer, $data); } else { $url = $data['server_url']; $view = $this->getConf('redissue.view'); $wiki_user = $_SERVER['REMOTE_USER']; $redmine->connect($url, $data['server_token'], $view, $wiki_user); if(array_key_exists('project_id', $data) && array_key_exists('tracker_id', $data)) { $issues = $redmine->client->issue->all([ 'project_id' => $data['project_id'], 'tracker_id' => $data['tracker_id'], 'limit' => $data['limit'], 'sort' => $data['sort'] ]); if(isset($issues['issues'])) { for ($i = 0; $i < count($issues['issues']); $i++) { $data['id'] = $issues['issues'][$i]['id']; $this->displayIssue($renderer, $data, $redmine); } } else { $renderer->doc .= '

REDISSUE plugin: "project" ID or "tracker" ID is invalid ! Redissue try to display single issue instead !

'; $this->displayIssue($renderer, $data, $redmine); } } else { $this->displayIssue($renderer, $data, $redmine); } } } function detectBootstrap(){ global $conf; $bootstrap_themes = $this->getConf('redissue.bootstrap-themes'); $bootstrap_exploded = explode(',', $bootstrap_themes); foreach ($bootstrap_exploded as $key => $value) { if (strcmp($conf['template'], $value) == 0){ $this->isBootstrap = True; } } } function renderIssueLink($renderer, $data) { // Check if issue or not if ($data['id'] == 0): $cur_title = $data['text']; $collapse = ''; else: if (isset($data['title'])) { $cur_title = '[#'.$data['id'].'] ' . $data['title']; } else { $cur_title = '[#'.$data['id'].'] ' . $data['text']; } $collapse = 'collapse'; endif; // Render Link if ($this->isBootstrap){ $renderer->doc .= ''; $renderer->doc .= ' '; $renderer->doc .= '
'; } else { $renderer->doc .= ''; $renderer->doc .= $cur_title; $renderer->doc .= ' '; } } function getIssueUrl($id, $data) { return $data['server_url'].'/issues/'.$id; } function getImg() { // If empty (False) get the second part return $this->getConf('redissue.img') ?: 'lib/plugins/redissue/images/redmine.png' ; } function displayIssue($renderer, $data, $redmine) { $issue = $redmine->getIssue($data['id']); $url = $data['server_url']; if($issue == 'Syntax error') { $renderer->doc .= '

REDISSUE plugin: Server exist in JSON config but seems not valid ! Please check your url or your API Key !

'; // If rights } elseif (isset($issue['issue'])) { // ISSUE INFOS $project = $issue['issue']['project']; $project_identifier = $redmine->getProjectIdentifier($project['name']); $tracker = $issue['issue']['tracker']; $status = $issue['issue']['status']['name']; $author = $issue['issue']['author']; $author_id = $redmine->getIdByUsername($author['name']); $assigned = $issue['issue']['assigned_to']; $assigned_id = $redmine->getIdByUsername($assigned['name']); $subject = $issue['issue']['subject']; $description = $issue['issue']['description']; $done_ratio = $issue['issue']['done_ratio']; // RENDER ISSUE LINK $isClosed = $redmine->getIsClosedValue($issue['issue']['status']['id']); $renderer->doc .= '

'; $data['text'] = $issue['issue']['subject']; $this->renderIssueLink($renderer, $data); // GENERAL RENDERER $priority = $issue['issue']['priority']; $color_prio = $redmine->getPriorityColor($priority['id']); $dates_times = $redmine->getDatesTimesIssue($issue); if(!$isClosed){ if($this->isBootstrap){ $renderer->doc .= ' ' . $status . ''; }else{ $renderer->doc .= ' '.$priority['name'].''; $renderer->doc .= ' '. $tracker['name'].''; $renderer->doc .= ' ' . $status . ''; } } else { if($this->isBootstrap){ $renderer->doc .= ' ' . $status . ''; }else{ $renderer->doc .= ' ' . $status . ''; } } if($this->isBootstrap) { $renderer->doc .= ' '.$priority['name'].''; $renderer->doc .= ' '. $tracker['name'].''; $renderer->doc .= '

'; $renderer->doc .= '
'; $renderer->doc .= '
 Projet :
'; $renderer->doc .= '
'.$project['name'].'
'; $renderer->doc .= '
'.$this->getLang('redissue.author').' :
'; $renderer->doc .= '
'.$author['name'].'
'; $renderer->doc .= '
'.$this->getLang('redissue.assigned').' :
'; $renderer->doc .= '
'.$assigned['name'].'
'; $renderer->doc .= '
'.$this->getLang('redissue.created').' :
'; $renderer->doc .= '
'.$dates_times['created']['date'].' ('.$dates_times['created']['time'].')
'; $renderer->doc .= '
'.$this->getLang('redissue.updated').' :
'; $renderer->doc .= '
'.$dates_times['updated']['date'].' ('.$dates_times['updated']['time'].')
'; if ($dates_times['closed']){ $renderer->doc .= '
'.$this->getLang('redissue.closed').' :
'; $renderer->doc .= '
'.$dates_times['closed']['date'].' ('.$dates_times['closed']['time'].')
'; } $renderer->doc .= '
'; // ./ Issue-info $renderer->doc .= '

'.$this->getLang('redissue.desc').'

'.$description.'

'; $renderer->doc .= '
'; $renderer->doc .= ''; $renderer->doc .= ''.$done_ratio.'% Complete'; $renderer->doc .= '
'; // ./progress $renderer->doc .= '
'; // ./ well $renderer->doc .= '
'; } else { $renderer->doc .= '
0) { $renderer->doc .= 'style="display:none;"'; } $renderer->doc .= 'class="issue-doku border-'.$color_prio.'">'; $renderer->doc .= '
'; $renderer->doc .= ''.$this->getLang('redissue.project').' : '; $renderer->doc .= ' '.$project['name'].''; $renderer->doc .= ' '.$this->getLang('redissue.author').' : '; $renderer->doc .= ''.$author['name'].''; $renderer->doc .= '
'; $renderer->doc .= ' '.$this->getLang('redissue.assigned').' :'; $renderer->doc .= ' '.$assigned['name'].'
'; $renderer->doc .= ' '.$this->getLang('redissue.created').' : '; $renderer->doc .= ''.$dates_times['created']['date'].' ('.$dates_times['created']['time'].')'; $renderer->doc .= ' '.$this->getLang('redissue.updated').' : '; $renderer->doc .= ''.$dates_times['updated']['date'].' ('.$dates_times['updated']['time'].')'; if ($dates_times['closed']){ $renderer->doc .= ' '.$this->getLang('redissue.closed').' : '; $renderer->doc .= ''.$dates_times['closed']['date'].' ('.$dates_times['closed']['time'].')'; } $renderer->doc .= '
'; // ./ Issue-info $renderer->doc .= '
'; $renderer->doc .= ''.$this->getLang('redissue.desc').' :'; $renderer->doc .= '

'.$description.'

'; $renderer->doc .= '
'; //$renderer->doc .= '
'; $renderer->doc .= $done_ratio.'% Complete '; $renderer->doc .= ''; //$renderer->doc .= '
'; // ./progress $renderer->doc .= '
'; } $renderer->doc .= '

'; } else { // If the user has no Rights $this->renderIssueLink($renderer, $data); } } }