Lexer->addSpecialPattern(']*/>', $mode,'plugin_redproject'); $this->Lexer->addEntryPattern(']*>(?=.*)', $mode,'plugin_redproject'); } function postConnect() { $this->Lexer->addExitPattern('', 'plugin_redproject'); } 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 getPercent($opIssue, $totalIssue) { $p = $opIssue / $totalIssue; $progress = $p * 100; return round($progress, 1); } // Do the regexp function handle($match, $state, $pos, Doku_Handler $handler) { switch($state){ case DOKU_LEXER_SPECIAL : case DOKU_LEXER_ENTER : $data = array( 'state'=>$state, 'proj'=> '', ); 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('redproject.API'); } if (!isset($data['server_url'])) { $data['server_url'] = $this->getConf('redproject.url'); } // Looking for id preg_match("/proj *= *(['\"])(.*?)\\1/", $match, $proj); if( count($proj) != 0 ) { $data['proj'] = $proj[2]; } else { return array( 'state'=>$state, 'error'=>true, 'text'=>'##ERROR <redproject>: project name required##' ); } return $data; case DOKU_LEXER_UNMATCHED : return array('state'=>$state, 'text'=>$match); default: return array('state'=>$state, 'bytepos_end' => $pos + strlen($match)); } } // Main render_link function _render_project($renderer, $data) { $client = new Redmine\Client($data['server_url'], $data['server_token']); // Get Id user of the Wiki if Impersonate $view = $this->getConf('redproject.view'); if ($view == self::RI_IMPERSONATE) { $redUser = $_SERVER['REMOTE_USER']; // Attempt to collect information with this user $client->setImpersonateUser($redUser); } // Get Project Info $proj = $client->api('project')->show($data['proj']); if($proj){ $projId = $proj['project']['id']; $projIdent = $proj['project']['identifier']; $projName = $proj['project']['name']; $projParent = $proj['project']['parent']; if ( ! empty($projParent)) { $nameParent = $projParent['name']; $parentId = $client->api('project')->getIdByName($nameParent); $parent = $client->api('project')->show($parentId); $parentIdent = $parent['project']['identifier']; } $projHome = $proj['project']['homepage']; $projDesc = $proj['project']['description']; // RENDERER PROJECT INFO // Title $renderer->doc .= '

'.$this->getLang('title').'

'; if($projHome) { $renderer->doc .= '
'; $renderer->doc .= '
HOME
'; $renderer->doc .= '
'; $renderer->doc .= ''.$projName.''; $renderer->doc .= '
'; $renderer->doc .= 'See it in redmine'; $renderer->doc .= '
';// /.see-it $renderer->doc .= '
'; // /.title-droite $renderer->doc .= '
'; // /.title } else { $renderer->doc .= '
'; $renderer->doc .= '
+
'; $renderer->doc .= '
'; $renderer->doc .= ''.$projName.''; $renderer->doc .= '
'; $renderer->doc .= 'See it in redmine'; $renderer->doc .= '
';// /.see-it $renderer->doc .= '
'; // /.title-droite $renderer->doc .= '
'; // /.title } // DESCRIPTION if ($projDesc == ''){ $renderer->doc .= '

'.$this->getLang('desctitle').'

'.$this->getLang('description').'

'; } else { $renderer->doc .= '

'.$this->getLang('desctitle').'

' . $projDesc . '

'; } // VERSIONS $versions = $client->api('version')->all($data['proj']); // Parsing Version if($versions) { $renderer->doc .= '

'.$this->getLang('vertitle').'

'; $renderer->doc .= '
'; for($i = 0; $i < count($versions['versions']); $i++) { // Begin Accordion $renderer->doc .= '
'; $foundVersion = $versions['versions'][$i]; $versionId = $foundVersion['id']; $renderer->doc .= '
'; $renderer->doc .= '

'; $renderer->doc .= ''; $renderer->doc .= 'Version ' . $foundVersion['name'] . ' '; $renderer->doc .= ''; $statusClass = (($foundVersion['status'] == 'open') ? 'statusop' : 'statuscl'); $renderer->doc .= ' ' . $foundVersion['status'] . ' '; $renderer->doc .= '

'; // /.panel-title $renderer->doc .= '
'; // /.panel-heading $renderer->doc .= '
'; // PANEL BODY $renderer->doc .= '
'; // Time Entries $createdOn = DateTime::createFromFormat(DateTime::ISO8601, $foundVersion['created_on']); $updatedOn = DateTime::createFromFormat(DateTime::ISO8601, $foundVersion['updated_on']); $renderer->doc .= '

Description : '.$foundVersion['description'].'

'; $renderer->doc .= '

See this version in redmine

'; $renderer->doc .= '

'.$this->getLang('createdon').''.$createdOn->format(DateTime::RFC850).'

'; $renderer->doc .= '

'.$this->getLang('updatedon').''.$updatedOn->format(DateTime::RFC850).'

'; // Issues of Versions $issueTotal = $client->api('issue')->all(array( 'project_id' => $projId, 'status_id' => '*', 'fixed_version_id' => $foundVersion['id'], 'limit' => 1 )); // Total issues & open $issueOpen = $client->api('issue')->all(array( 'project_id' => $projId, 'status_id' => 'open', 'fixed_version_id' => $foundVersion['id'], 'limit' => 1 )); // Get percent version $diffIssue = $issueTotal['total_count'] - $issueOpen['total_count']; $progress = $this->getPercent($diffIssue,$issueTotal['total_count']); // renderer Progressbar $renderer->doc .= ''; $renderer->doc .= ''.$issueTotal['total_count'].' issues ('.$diffIssue.' closed - '.$issueOpen['total_count'].' open)'; $renderer->doc .= ''; // /.col-md-3 $renderer->doc .= ''; $renderer->doc .= '
'; $renderer->doc .= ''; $renderer->doc .= ''.$progress.'% Complete'; $renderer->doc .= '
'; // ./progress $renderer->doc .= '
'; // ./col-md-6 $renderer->doc .= '
'; // /.panel-body $renderer->doc .= '
'; // /#collapse-version-nb-'.$versionId.' .panel-collapse $renderer->doc .= '
'; // /.panel .panel-default $renderer->doc .= '
'; } $renderer->doc .= '
'; // /.panel-group } else { $renderer->doc .= '

'.$this->getLang('vertitle').'

'; $renderer->doc .= $nbVersion . ' versions'; $renderer->doc .= 'div class="descver">

' . $this->getLang('noversion') . '

'; } $renderer->doc .= '
'; // DETAILS // Get Number of Version for($v = 0; $v < count($versions['versions']); $v++) { $nbVersion = $v + 1; } // Get number of Issues $issueTotal = $client->api('issue')->all(array( 'project_id' => $projId, 'status_id' => '*', 'limit' => 1 )); $issueOpen = $client->api('issue')->all(array( 'project_id' => $projId, 'status_id' => 'open', 'limit' => 1 )); // Initialize Array $usersByRole = array(); $members = $client->api('membership')->all($projId); // Found each Members for($m = 0; $m < count($members['memberships']); $m++) { // $z++; $memberFound = $members['memberships'][$m]; $currentUser = $memberFound['user']; for($r = 0; $r doc .= '
'; $renderer->doc .= '

'.$this->getlang('hdetail').'

'; // Stats $renderer->doc .= '
'; if($projParent == ''){ $renderer->doc .= '

'.$this->getLang('mainproj').'

'; } else { $renderer->doc .= '

'.$this->getLang('subproject').' '.$nameParent.'

'; } $renderer->doc .= '

'.$this->getLang('tversion').''.$nbVersion.''.$this->getLang('vversion').'

'; $renderer->doc .= '

'. $issueTotal['total_count'].''.$this->getLang('issues').''.$issueOpen['total_count'].''.$this->getLang('open').'

'; $renderer->doc .= '

'.$m.''.$this->getLang('membdetail').'

'; $renderer->doc .= '
'; // /.stats $renderer->doc .= '
'; // /.details // MEMBERSHIPS & ROLES $langMembers = $this->getLang('membres'); $renderer->doc .= '

'. $langMembers . '

'; // Display new array usersByRole $renderer->doc .= '
'; foreach($usersByRole as $role => $currentRole) { $renderer->doc .= '

'.$currentRole['name'].' : '; // Define a total to render commas $total = count($currentRole['members']); foreach($currentRole['members'] as $who => $currentUser) { $userId = $currentUser['id']; $mailCurrentUser = $client->api('user')->show($userId); $mailUser = $mailCurrentUser['user']['mail']; $renderer->doc .= ' '. $currentUser['name'] . '' ; if ($who < $total - 1) { $renderer->doc .= ','; } } $renderer->doc .= '

'; } $renderer->doc .= '
'; } else { $renderer->doc .= '

'.$this->getLang('private').'

'; $renderer->doc .= '

'.$this->getLang('info').'

'.$this->getLang('norights').'

'; } } // Dokuwiki Renderer function render($mode, Doku_Renderer $renderer, $data) { $renderer->info['cache'] = false; if($mode != 'xhtml') return false; if($data['error']) { $renderer->doc .= $data['text']; return true; } switch($data['state']) { case DOKU_LEXER_SPECIAL : $this->_render_project($renderer, $data); break; case DOKU_LEXER_ENTER : $this->_render_project($renderer, $data); break; case DOKU_LEXER_EXIT: case DOKU_LEXER_UNMATCHED : $renderer->doc .= $renderer->_xmlEntities($data['text']); break; } return true; } }