. // Copyright © 2007-2014 Erwan Briand // // This program is free software: you can redistribute it and/or modify it // under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, version 3 only. // // This program is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public // License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . /** * @file * This file contains a class that calls DrawSVGChart */ /** * SVG class */ class SVG { private $database, $page, $xmloutput; function __construct ($database, $page) { // Initialization $this->database = $database; $this->page = $page; $drawsvgchart = getClass('drawsvgchart'); if ($page[2] == 'project') { // Security test if (!mb_ereg("^[0-9a-z_-]+$", $this->page[3])) exit('Error.'); // Load project informations $this->project = getClass('projects.projects', $this->database); $projects = $this->project->load($this->page[3], 'dbname'); if (!$projects) exit('Error.'); else $this->id = $this->project->getId(); $this->dbname = $this->project->getDbname(); // Bugs if ($page[4] == 'bugs') { $project_versions = getClass('project.versions', $this->database); $project_bugs = getClass('project.bugs', $this->database); $versions = $project_versions->getVersions($this->id); $bugs_array = array(); $bugs_total = 0; foreach ($versions as $version) { $version = $version['version']; $bugs = $project_bugs->countReports($this->id, $version); $buga = $project_bugs->countReportsByStatus( $this->id, 'unconfirmed', $version); $bugb = $project_bugs->countReportsByStatus( $this->id, 'confirmed', $version); $bugc = $project_bugs->countReportsByStatus( $this->id, 'working', $version); $bugd = $project_bugs->countReportsByStatus( $this->id, 'needinformations', $version); $buge = $project_bugs->countReportsByStatus( $this->id, 'needcontributors', $version); $bugf = $project_bugs->countReportsByStatus( $this->id, 'needtests', $version); $bugs_open = $buga + $bugb + $bugc + $bugd + $buge + $bugf; $bugs_array[0][$version] = $bugs; $bugs_array[1][$version] = $bugs_open; } $legend = array(array('#5276A9', 'reported bugs'), array('#CD3333', 'open bugs')); $link = CT_BASEURL.'project/'.htmlspecialchars($this->dbname). '/bugs/?nbbugs=30&withversion=1&version={data}'; $svgchart = $drawsvgchart->createChart($bugs_array, $legend, $link); if (!$drawsvgchart->has_errors()) { Header('Content-Type: image/svg+xml; charset=utf-8'); echo $drawsvgchart->getXMLOutput(); } else exit(i18n('Not enough values to proceed!')); } elseif ($page[4] == 'contributors') { $commits = getClass('projects.commits', $this->database); $datas = $commits->getProjectContributors($this->id); asort($datas); $datas = array_reverse($datas, TRUE); $legend = array('#5276A9', 'commits'); $link = CT_BASEURL.'users/show/{data}'; $svgchart = $drawsvgchart->createChart($datas, array($legend), $link); if (!$drawsvgchart->has_errors()) { Header('Content-Type: image/svg+xml; charset=utf-8'); echo $drawsvgchart->getXMLOutput(); } else exit(i18n('Not enough values to proceed!')); } elseif ($page[4] == 'commits') { $commits = getClass('projects.commits', $this->database); $datas = $commits->getProjectHistory($this->id); ksort($datas); $legend = array('#5276A9', 'commits'); $link = FALSE; $svgchart = $drawsvgchart->createChart($datas, array($legend), $link, TRUE); if (!$drawsvgchart->has_errors()) { Header('Content-Type: image/svg+xml; charset=utf-8'); echo $drawsvgchart->getXMLOutput(); } else exit(i18n('Not enough values to proceed!')); } elseif ($page[4] == 'history') { $commits = getClass('projects.commits', $this->database); $c_datas = $commits->getProjectHistory($this->id); ksort($c_datas); $bugs = getClass('project.bugs', $this->database); $b_datas = $bugs->getProjectHistory($this->id); ksort($b_datas); $forums = getClass('project.forum', $this->database); $f_datas = $forums->getProjectHistory($this->id); ksort($f_datas); $doc = getClass('project.doc', $this->database); $d_datas = $doc->getProjectHistory($this->id); ksort($d_datas); $_firsts = array(key($c_datas), key($b_datas), key($f_datas), key($d_datas)); $vfirsts = array(); foreach ($_firsts as $item) if (!is_null($item)) array_push($vfirsts, $item); else array_push($vfirsts, date('Y-m')); $firsts = array_values($vfirsts); sort($firsts); $first_date = reset($firsts); $exp = explode('-', $first_date); $c_years = date('Y') - $exp[0]; $c_months_s = $exp[1]; $c_months_e = date('m'); $dates = array(); for ($i=0; $i<=$c_years; $i++) { $year = $exp[0] + $i; for ($month=1; $month<=12; $month++) { if ($i == 0 && $month < $c_months_s) continue; $data = $year.'-'.(($month < 10) ? '0' : '').$month; $dates[$data] = array(); if (date('Y-m') == $data) break; } } $datas_c = array(); $datas_bunif = array(); foreach ($dates as $key => $value) { if (array_key_exists($key, $c_datas)) $datas_c[$key] = $c_datas[$key]; else $datas_c[$key] = 0; if (array_key_exists($key, $b_datas)) $datas_bunif[$key] = $b_datas[$key]; else $datas_bunif[$key] = 0; if (array_key_exists($key, $f_datas)) $datas_bunif[$key] += $f_datas[$key]; if (array_key_exists($key, $d_datas)) $datas_bunif[$key] += $d_datas[$key]; } $alldb = array(); $firstdb = array(); $secondb = array(); foreach ($datas_c as $k => $v) if ($v > 0) { $firstdb[$k] = $v; if (!in_array($k, $alldb)) array_push($alldb, $k); } foreach ($datas_bunif as $k => $v) if ($v > 0) { $secondb[$k] = $v; if (!in_array($k, $alldb)) array_push($alldb, $k); } sort($alldb); foreach ($alldb as $k => $v) { if (!array_key_exists($v, $firstdb)) $firstdb[$v] = 0; if (!array_key_exists($v, $secondb)) $secondb[$v] = 0; } ksort($firstdb); ksort($secondb); $legend = array(array('#5276A9', 'commits'), array('#CD3333', 'contributions')); $link = FALSE; $svgchart = $drawsvgchart->createChart(array($firstdb, $secondb), $legend, $link, NULL); if (!$drawsvgchart->has_errors()) { Header('Content-Type: image/svg+xml; charset=utf-8'); echo $drawsvgchart->getXMLOutput(); } else exit(i18n('Not enough values to proceed!')); } elseif ($page[4] == 'codestats') { $statsfile = CT_BASEDIR.'/public/codestats/reports/'.$this->dbname; if (!file_exists($statsfile)) exit(i18n('Not enough values to proceed!')); $colors = array('CD2626', 'FFA500', 'FFD700', '0000CD', '4169E1', '00BFFF', 'AFEEEE', 'E0FFFF', 'FAEBD7', 'EEE9BF', 'FFFACD', 'C1FFC1', 'EEE8AA'); require_once(CT_BASEDIR.'/inc/data/language.php'); $data = file_get_contents($statsfile); $codestats = unserialize($data); $_colors = array(); $_legends = array(); $_counts = array(); $others_sum = 0; $i = 1; foreach ($codestats['languages'] as $lang) { if ($i > 4 && count($codestats['languages']) > 5) $others_sum += $lang['lines_code']; else { $count = $lang['lines_code']; $name = $language[$lang['name']]; shuffle($colors); $color = $colors[1]; unset($colors[1]); array_push($_colors, $color); array_push($_legends, $name); array_push($_counts, $count); } $i ++; } if ($others_sum > 0) { shuffle($colors); $color = $colors[1]; unset($colors[1]); array_push($_colors, $color); array_push($_legends, i18n('Others')); array_push($_counts, $others_sum); } require_once(CT_BASEDIR.'/inc/libs/piegraph.class.php'); $pie = new PieGraph(200, 150, $_counts); $pie->setColors($_colors); $pie->setLegends($_legends); $pie->set3dHeight(10); $pie->display(); } elseif ($page[4] == 'pie') { if (isset($page[5]) && is_numeric($page[5])) $total = (int)$page[5]; else exit('Error.'); if (isset($page[6])) { $size = explode('x', $page[6]); if (count($size) == 1) exit('Error.'); $width = (int)$size[0]; $height = (int)$size[1]; } else exit('Error.'); $colors = array('CD2626', 'FFA500', 'FFD700', '0000CD', '4169E1', '00BFFF', 'AFEEEE', 'E0FFFF', 'FAEBD7', 'EEE9BF', 'FFFACD', 'C1FFC1', 'EEE8AA'); $_colors = array(); $_legends = array(); $_counts = array(); for ($i=7; $isetColors($_colors); $pie->setLegends($_legends); $pie->set3dHeight(10); $pie->display(); } } } } ?>