deleting unused code

This commit is contained in:
hyung-hwan 2021-09-11 11:06:01 +00:00
parent 1c291410f6
commit 20e4fa5e2e
4 changed files with 3 additions and 309 deletions

View File

@ -1559,310 +1559,4 @@ class Code extends CI_Controller
if ($path == '/') $path = '';
return $path;
}
function graph ($type = '', $projectid = '', $path = '', $rev = SVN_REVISION_HEAD)
{
$this->load->model ('ProjectModel', 'projects');
$login = $this->login->getUser ();
if (CODEPOT_SIGNIN_COMPULSORY && $login['id'] == '')
{
header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found');
return;
}
$project = $this->projects->get ($projectid);
//if ($project === FALSE || ($project->public !== 'Y' && $login['id'] == ''))
if ($project === FALSE || !$this->_can_read ($this->projects, $projectid, $login))
{
header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found');
return;
}
$this->load->model ('SubversionModel', 'subversion');
$path = $this->converter->HexToAscii ($path);
if ($path == '.') $path = ''; /* treat a period specially */
$path = $this->_normalize_path ($path);
if ($type == 'cloc-file')
{
// number of lines in a single file
$file = $this->subversion->getFile ($projectid, $path, $rev);
if ($file === FALSE)
{
header($_SERVER['SERVER_PROTOCOL'].' 500 Internal Server Error');
return;
}
if ($file['type'] != 'file')
{
header($_SERVER['SERVER_PROTOCOL'].' 500 Internal Server Error');
return;
}
// pass __FILE__ as the first argument so that tempnam creates a name
// in the system directory. __FILE__ can never be a valid directory.
$tfname = @tempnam(__FILE__, 'codepot-cloc-');
if ($tfname === FALSE)
{
header($_SERVER['SERVER_PROTOCOL'].' 500 Internal Server Error');
return;
}
$actual_tfname = $tfname . '.' . pathinfo ($file['name'], PATHINFO_EXTENSION);
@file_put_contents ($actual_tfname, $file['content']);
$cloc_cmd = sprintf ('%s --quiet --csv --csv-delimiter=":" %s', CODEPOT_CLOC_COMMAND_PATH, $actual_tfname);
$cloc = @popen ($cloc_cmd, 'r');
if ($cloc === FALSE)
{
@unlink ($tfname);
@unlink ($actual_tfname);
header($_SERVER['SERVER_PROTOCOL'].' 500 Internal Server Error');
return;
}
$line_count = 0;
$counter = FALSE;
while (!feof($cloc))
{
$line = @fgets ($cloc);
if ($line === FALSE) break;
if ($line_count == 2)
{
$counter = explode (':', $line);
}
$line_count++;
}
@pclose ($cloc);
@unlink ($tfname);
@unlink ($actual_tfname);
if ($counter === FALSE)
{
$stats = array (
'no-data' => 0
);
$title = $file['name'];
}
else
{
$stats = array (
'blank' => (integer)$counter[2],
'comment' => (integer)$counter[3],
'code' => (integer)$counter[4],
'total' => (integer)$counter[2] + (integer)$counter[3] + (integer)$counter[4]
);
$title = $file['name'] . ' (' . $counter[1] . ')';
}
$this->load->library ('PHPGraphLib', array ('width' => 280, 'height' => 200), 'graph');
$this->graph->addData($stats);
$this->graph->setTitle($title);
$this->graph->setDataPoints(TRUE);
$this->graph->setDataValues(TRUE);
$this->graph->setBars(TRUE);
$this->graph->setXValuesHorizontal(TRUE);
$this->graph->setYValues (FALSE);
$this->graph->createGraph();
}
else if ($type == 'commits-per-month')
{
$total_commits = 0;
$average_commits = 0;
$total_months = 0;
$file = $this->subversion->getHistory ($projectid, $path, $rev);
if ($file === FALSE)
{
//header($_SERVER['SERVER_PROTOCOL'].' 500 Internal Server Error');
//return;
$stats = array ('no-data' => 0);
}
else
{
$history = $file['history'];
$history_count = count($history);
$stats = array();
for ($i = 0; $i < $history_count; $i++)
{
$h = $history[$i];
if (array_key_exists ('date', $h))
{
$date = substr($h['date'], 0, 7);
if (array_key_exists ($date, $stats))
$stats[$date]++;
else
$stats[$date] = 1;
}
}
ksort ($stats);
$stats_count = count($stats);
$idx = 1;
foreach ($stats as $k => $v)
{
if ($idx == 1)
{
$min_year = substr($k, 0, 4);
$min_month = substr($k, 5, 2);
}
if ($idx == $stats_count)
{
$max_year = substr($k, 0, 4);
$max_month = substr($k, 5, 2);
}
$idx++;
$total_commits += $v;
}
$total_months = 0;
for ($year = $min_year; $year <= $max_year; $year++)
{
$month = ($year == $min_year)? $min_month: 1;
$month_end = ($year == $max_year)? $max_month: 12;
while ($month <= $month_end)
{
$date = sprintf ("%04d-%02d", $year, $month);
if (!array_key_exists ($date, $stats))
{
// fill the holes
$stats[$date] = 0;
}
$month++;
$total_months++;
}
}
if ($total_months > 0) $average_commits = $total_commits / $total_months;
}
ksort ($stats);
$stats_count = count($stats);
$graph_width = $stats_count * 8;
if ($graph_width < 400) $graph_width = 400;
$this->load->library ('PHPGraphLib', array ('width' => $graph_width, 'height' => 180), 'graph');
$this->graph->addData($stats);
$this->graph->setTitle("Commits per month ({$total_commits}/{$total_months})");
$this->graph->setDataPoints(FALSE);
$this->graph->setDataValues(FALSE);
$this->graph->setLine(FALSE);
$this->graph->setLineColor("red");
$this->graph->setBars(TRUE);
$this->graph->setBarOutline (TRUE);
$this->graph->setBarColor ("#EEEEEE");
$this->graph->setBarOutlineColor ("#AAAAAA");
$this->graph->setXValues(TRUE);
$this->graph->setXValuesHorizontal(TRUE);
if ($stats_count <= 1)
{
$this->graph->setBarSpace(TRUE);
//$this->graph->setDataPoints(TRUE);
//$this->graph->setDataPointColor("red");
}
else
{
$this->graph->setBarSpace(FALSE);
if ($stats_count <= 8)
{
$this->graph->setXValuesInterval(1);
}
else if ($stats_count <= 16)
{
$this->graph->setXValuesInterval(2);
}
else
{
$this->graph->setXValuesInterval(11);
}
}
//$this->graph->setGrid(FALSE);
$this->graph->setGridVertical(FALSE);
$this->graph->setGridHorizontal(TRUE);
if ($total_months > 0) $this->graph->setGoalLine ($average_commits, "red", "solid");
$this->graph->createGraph();
}
else if ($type == 'commit-share-by-users')
{
// revision is ignored
$file = $this->subversion->getHistory ($projectid, $path, $rev);
if ($file === FALSE)
{
header($_SERVER['SERVER_PROTOCOL'].' 500 Internal Server Error');
return;
}
$history = $file['history'];
$history_count = count($history);
$stats = array();
for ($i = 0; $i < $history_count; $i++)
{
$h = $history[$i];
$author = (array_key_exists ('author', $h))? $h['author']: '?';
if (array_key_exists ($author, $stats))
$stats[$author]++;
else
$stats[$author] = 1;
}
$this->load->library ('PHPGraphLibPie', array ('width' => 400, 'height' => 300), 'graph');
$this->graph->addData($stats);
$this->graph->setTitle('Commit share by users');
$this->graph->setLabelTextColor('50,50,50');
$this->graph->setLegendTextColor('50,50,50');
$this->graph->createGraph();
}
else /* if ($type == 'commits-by-users') */
{
// revision is ignored
$file = $this->subversion->getHistory ($projectid, $path, $rev);
if ($file === FALSE)
{
header($_SERVER['SERVER_PROTOCOL'].' 500 Internal Server Error');
return;
}
$history = $file['history'];
$history_count = count($history);
$stats = array();
for ($i = 0; $i < $history_count; $i++)
{
$h = $history[$i];
$author = (array_key_exists ('author', $h))? $h['author']: '?';
if (array_key_exists ($author, $stats))
$stats[$author]++;
else
$stats[$author] = 1;
}
$this->load->library ('PHPGraphLib', array ('width' => 400, 'height' => 300), 'graph');
$this->graph->addData($stats);
$this->graph->setTitle('Commits by users');
$this->graph->setDataPoints(TRUE);
$this->graph->setDataValues(TRUE);
//$this->graph->setLine(TRUE);
$this->graph->setBars(TRUE);
//$this->graph->setXValuesHorizontal(TRUE);
$this->graph->createGraph();
}
}
}

View File

@ -331,7 +331,7 @@ class User extends CI_Controller
}
}
$img = imagecreate (50, 50);
$img = imagecreate(50, 50);
$bgcolor = imagecolorallocate($img, 250, 255, 250);
imagefill ($img, 0, 0, $bgcolor);

View File

@ -341,7 +341,7 @@ $this->load->view (
if ($is_octet_stream ||
in_array (strtolower($fileext), array ('png', 'jpg', 'gif', 'tif', 'bmp', 'ico')))
{
$img = @imagecreatefromstring ($file['content']);
$img = @imagecreatefromstring($file['content']);
if ($img !== FALSE)
{
@imagedestroy ($img);

View File

@ -24,7 +24,7 @@
if (in_array ($fileext, array ('png', 'jpg', 'jpeg', 'gif', 'tif', 'bmp', 'ico')))
{
$img = @imagecreatefromstring ($file['content']);
$img = @imagecreatefromstring($file['content']);
if ($img !== FALSE)
{
@imagedestroy ($img);