From 64b38f6165600375a8d357713ba50e470c6ad115 Mon Sep 17 00:00:00 2001 From: Pieter Hordijk Date: Thu, 23 May 2019 21:22:50 +0300 Subject: [PATCH 1/4] Prevent errors when authentication variable is not available (yet) --- templates/layout.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/layout.php b/templates/layout.php index a0eb35f5..bf24d66b 100644 --- a/templates/layout.php +++ b/templates/layout.php @@ -22,7 +22,7 @@ search howto |  statistics |  random bug |  - + my bugs |  admin |  From befb55c804744a879c65ccee89fa0341e05d7005 Mon Sep 17 00:00:00 2001 From: Pieter Hordijk Date: Thu, 23 May 2019 21:24:07 +0300 Subject: [PATCH 2/4] Convert login page to template --- templates/pages/login.php | 27 +++++++++++++++++++ www/login.php | 55 ++++++++++++--------------------------- 2 files changed, 44 insertions(+), 38 deletions(-) create mode 100644 templates/pages/login.php diff --git a/templates/pages/login.php b/templates/pages/login.php new file mode 100644 index 00000000..159817d4 --- /dev/null +++ b/templates/pages/login.php @@ -0,0 +1,27 @@ +extends('layout.php', ['title' => 'Login']) ?> + +start('content') ?> + + +
+ Wrong username or password! +
+ +
+ + + + + + + + + + + +
Username:@php.net +
Password: +
+
+ +end('content') ?> diff --git a/www/login.php b/www/login.php index b5f6b523..7047a86f 100644 --- a/www/login.php +++ b/www/login.php @@ -8,48 +8,27 @@ redirect('index.php'); } -response_header('Login'); +$referer = $_SERVER['HTTP_REFERER'] ?? ''; if (isset($_POST['user'])) { - $referer = $_POST['referer']; + $referer = $_POST['referer']; - bugs_authenticate($user, $pwd, $logged_in, $user_flags); + bugs_authenticate($user, $pwd, $logged_in, $user_flags); - if ($logged_in === 'developer') { - if (!empty($_POST['referer']) && - preg_match("/^{$site_method}:\/\/". preg_quote($site_url) .'/i', $referer) && - parse_url($referer, PHP_URL_PATH) != '/logout.php') { - redirect($referer); + if ($logged_in === 'developer') { + if (!empty($_POST['referer']) && + preg_match("/^{$site_method}:\/\/". preg_quote($site_url) .'/i', $referer) && + parse_url($referer, PHP_URL_PATH) !== '/logout.php') { + redirect($referer); + } + + redirect('index.php'); } - redirect('index.php'); - } else { -?> -
Wrong username or password!
- - -
- - - - - - - - - - - -
Username:@php.net -
Password: -
-
- - +echo $template->render('pages/login.php', [ + 'referer' => $referer, + 'username' => $user ?? '', + // if we have a posted username and we got here it means the login was invalid + 'invalidLogin' => isset($_POST['user']), +]); From 25ca20bb0393805e74d16c1b937a75c59a269911 Mon Sep 17 00:00:00 2001 From: Pieter Hordijk Date: Thu, 23 May 2019 21:38:45 +0300 Subject: [PATCH 3/4] Converted logout page to template --- templates/pages/logged_out.php | 7 +++++++ www/logout.php | 8 +------- 2 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 templates/pages/logged_out.php diff --git a/templates/pages/logged_out.php b/templates/pages/logged_out.php new file mode 100644 index 00000000..afd033b6 --- /dev/null +++ b/templates/pages/logged_out.php @@ -0,0 +1,7 @@ +extends('layout.php', ['title' => 'Logout']) ?> + +start('content') ?> + +

You've been logged out.

+ +end('content') ?> diff --git a/www/logout.php b/www/logout.php index ce542a17..1a45efc5 100644 --- a/www/logout.php +++ b/www/logout.php @@ -11,10 +11,4 @@ unset($_SESSION['user']); session_destroy(); -response_header('Logout'); - -?> - -

You've been logged out.

- -render('pages/logged_out.php'); From 386746d7c598f57b4730fff8d608ca52f07999b2 Mon Sep 17 00:00:00 2001 From: Pieter Hordijk Date: Fri, 31 May 2019 15:25:49 +0300 Subject: [PATCH 4/4] Converted statistics page to use template rendering --- templates/bug_type_options.php | 17 +++ templates/pages/statistics.php | 78 ++++++++++ templates/statistics_header.php | 5 + templates/statistics_headers.php | 16 ++ templates/statistics_value.php | 13 ++ www/stats.php | 242 +++++++------------------------ 6 files changed, 180 insertions(+), 191 deletions(-) create mode 100644 templates/bug_type_options.php create mode 100644 templates/pages/statistics.php create mode 100644 templates/statistics_header.php create mode 100644 templates/statistics_headers.php create mode 100644 templates/statistics_value.php diff --git a/templates/bug_type_options.php b/templates/bug_type_options.php new file mode 100644 index 00000000..d803bb06 --- /dev/null +++ b/templates/bug_type_options.php @@ -0,0 +1,17 @@ + + + + + + + diff --git a/templates/pages/statistics.php b/templates/pages/statistics.php new file mode 100644 index 00000000..8ff61d4d --- /dev/null +++ b/templates/pages/statistics.php @@ -0,0 +1,78 @@ +extends('layout.php', ['title' => 'Bugs Stats']) ?> + +start('content') ?> + +
+ + + + +
+ Bug Type: + + +
+
+ + + + + + + + include('statistics_headers.php', ['sortBy' => $sortBy, 'reverseSort' => $reverseSort]); ?> + + $packageStatistics): ?> + + + include('statistics_headers.php', ['isSubHeader' => true, 'sortBy' => $sortBy, 'reverseSort' => $reverseSort]); ?> + + + + + include('statistics_value.php', ['class' => 1, 'packageName' => $packageName, 'statistics' => $packageStatistics, 'bugType' => $selectedType, 'status' => 'Closed']); ?> + include('statistics_value.php', ['class' => 0, 'packageName' => $packageName, 'statistics' => $packageStatistics, 'bugType' => $selectedType, 'status' => 'Open']); ?> + include('statistics_value.php', ['class' => 1, 'packageName' => $packageName, 'statistics' => $packageStatistics, 'bugType' => $selectedType, 'status' => 'Critical']); ?> + include('statistics_value.php', ['class' => 0, 'packageName' => $packageName, 'statistics' => $packageStatistics, 'bugType' => $selectedType, 'status' => 'Verified']); ?> + include('statistics_value.php', ['class' => 1, 'packageName' => $packageName, 'statistics' => $packageStatistics, 'bugType' => $selectedType, 'status' => 'Analyzed']); ?> + include('statistics_value.php', ['class' => 0, 'packageName' => $packageName, 'statistics' => $packageStatistics, 'bugType' => $selectedType, 'status' => 'Assigned']); ?> + include('statistics_value.php', ['class' => 1, 'packageName' => $packageName, 'statistics' => $packageStatistics, 'bugType' => $selectedType, 'status' => 'Feedback']); ?> + include('statistics_value.php', ['class' => 0, 'packageName' => $packageName, 'statistics' => $packageStatistics, 'bugType' => $selectedType, 'status' => 'No Feedback']); ?> + include('statistics_value.php', ['class' => 1, 'packageName' => $packageName, 'statistics' => $packageStatistics, 'bugType' => $selectedType, 'status' => 'Suspended']); ?> + include('statistics_value.php', ['class' => 0, 'packageName' => $packageName, 'statistics' => $packageStatistics, 'bugType' => $selectedType, 'status' => 'Not a bug']); ?> + include('statistics_value.php', ['class' => 1, 'packageName' => $packageName, 'statistics' => $packageStatistics, 'bugType' => $selectedType, 'status' => 'Duplicate']); ?> + include('statistics_value.php', ['class' => 0, 'packageName' => $packageName, 'statistics' => $packageStatistics, 'bugType' => $selectedType, 'status' => 'Wont fix']); ?> + + + +
No bugs found
e($packageName); ?>
+ + +
+ +

PHP Versions for recent bug reports:

+ + $recentReportsOfDate): ?> + + + + + + + + + + +
+ e($date); ?> +
+ e($versionInformation['version']); ?> + + +
+ + + +end('content') ?> diff --git a/templates/statistics_header.php b/templates/statistics_header.php new file mode 100644 index 00000000..0897898c --- /dev/null +++ b/templates/statistics_header.php @@ -0,0 +1,5 @@ + + + e($type); ?> + + diff --git a/templates/statistics_headers.php b/templates/statistics_headers.php new file mode 100644 index 00000000..f481ee31 --- /dev/null +++ b/templates/statistics_headers.php @@ -0,0 +1,16 @@ + + +   + include('statistics_header.php', ['sortBy' => $sortBy, 'reverseSort' => $reverseSort, 'type' => 'Closed']); ?> + include('statistics_header.php', ['sortBy' => $sortBy, 'reverseSort' => $reverseSort, 'type' => 'Open']); ?> + include('statistics_header.php', ['sortBy' => $sortBy, 'reverseSort' => $reverseSort, 'type' => 'Critical']); ?> + include('statistics_header.php', ['sortBy' => $sortBy, 'reverseSort' => $reverseSort, 'type' => 'Verified']); ?> + include('statistics_header.php', ['sortBy' => $sortBy, 'reverseSort' => $reverseSort, 'type' => 'Analyzed']); ?> + include('statistics_header.php', ['sortBy' => $sortBy, 'reverseSort' => $reverseSort, 'type' => 'Assigned']); ?> + include('statistics_header.php', ['sortBy' => $sortBy, 'reverseSort' => $reverseSort, 'type' => 'Feedback']); ?> + include('statistics_header.php', ['sortBy' => $sortBy, 'reverseSort' => $reverseSort, 'type' => 'No Feedback']); ?> + include('statistics_header.php', ['sortBy' => $sortBy, 'reverseSort' => $reverseSort, 'type' => 'Suspended']); ?> + include('statistics_header.php', ['sortBy' => $sortBy, 'reverseSort' => $reverseSort, 'type' => 'Not a bug']); ?> + include('statistics_header.php', ['sortBy' => $sortBy, 'reverseSort' => $reverseSort, 'type' => 'Duplicate']); ?> + include('statistics_header.php', ['sortBy' => $sortBy, 'reverseSort' => $reverseSort, 'type' => 'Wont fix']); ?> + diff --git a/templates/statistics_value.php b/templates/statistics_value.php new file mode 100644 index 00000000..5cb150f3 --- /dev/null +++ b/templates/statistics_value.php @@ -0,0 +1,13 @@ + + +   + + + + + + + + + + diff --git a/www/stats.php b/www/stats.php index aaac6886..a12024a6 100644 --- a/www/stats.php +++ b/www/stats.php @@ -2,221 +2,81 @@ use App\Repository\BugRepository; -session_start(); - // Obtain common includes require_once '../include/prepend.php'; // Authenticate -bugs_authenticate($user, $pw, $logged_in, $user_flags); - -response_header('Bugs Stats'); - -$titles = [ - 'Closed' => 'Closed', - 'Open' => 'Open', - 'Critical' => 'Crit', - 'Verified' => 'Verified', - 'Analyzed' => 'Analyzed', - 'Assigned' => 'Assigned', - 'Feedback' => 'Fdbk', - 'No Feedback' => 'No Fdbk', - 'Suspended' => 'Susp', - 'Not a bug' => 'Not a bug', - 'Duplicate' => 'Dupe', - 'Wont fix' => 'Wont Fix', -]; +require_once __DIR__ . '/../include/auth.php'; -$rev = isset($_GET['rev']) ? $_GET['rev'] : 1; -$sort_by = isset($_GET['sort_by']) ? $_GET['sort_by'] : 'Open'; -$total = 0; -$row = []; -$pkg = []; -$pkg_tmp = []; -$pkg_total = []; -$pkg_names = []; -$all = []; -$pseudo = true; - -if (!array_key_exists($sort_by, $titles)) { - $sort_by = 'Open'; -} +$selectedBugType = $_GET['bug_type'] ?? 'All'; +$sortBy = $_GET['sort_by'] ?? 'Open'; +$reverseSort = (bool) ($_GET['rev'] ?? 1); -$bug_type = $_GET['bug_type'] ?? 'All'; -$bugRepository = $container->get(BugRepository::class); +//$totalBugs = 0; +$statisticsTally = [ + 'All' => [ + 'Total' => 0, + ], +]; -foreach ($bugRepository->findAllByBugType($bug_type) as $row) { - $pkg_tmp[$row['status']][$row['package_name']] = $row['quant']; - @$pkg_total[$row['package_name']] += $row['quant']; - @$all[$row['status']] += $row['quant']; - @$total += $row['quant']; - $pkg_names[$row['package_name']] = 0; -} +$statistics = []; -if (count($pkg_tmp)) { - foreach ($titles as $key => $val) { - if (isset($pkg_tmp[$key]) && is_array($pkg_tmp[$key])) { - $pkg[$key] = array_merge($pkg_names, $pkg_tmp[$key]); - } else { - $pkg[$key] = $pkg_names; - } +// massage the stats per package into a workable data structure for presentation on the page +foreach ($container->get(BugRepository::class)->findAllByBugType($selectedBugType) as $packageAndStatus) { + if (!isset($statistics[$packageAndStatus['package_name']])) { + $statistics[$packageAndStatus['package_name']] = [ + 'Total' => 0, + ]; } -} -if ($total > 0) { - if ($rev == 1) { - arsort($pkg[$sort_by]); - } else { - asort($pkg[$sort_by]); - } -} -?> - -
- - - - -
- Bug Type: - - -
-
- - - -
No bugs found
' . "\n"; - response_footer(); - exit; -} + $statistics[$packageAndStatus['package_name']][$packageAndStatus['status']] = $packageAndStatus['quant']; -echo display_stat_header($total, true); + $statistics[$packageAndStatus['package_name']]['Total'] += $packageAndStatus['quant']; -echo <<< OUTPUT - - All - {$total} -OUTPUT; + $statisticsTally['All']['Total'] += $packageAndStatus['quant']; -$i = 1; -foreach ($titles as $key => $val) { - echo ' '; - echo bugstats($key, 'all') , "\n"; -} -echo " \n"; - -$stat_row = 1; -foreach ($pkg[$sort_by] as $name => $value) { - if ($name != 'all') { - // Output a new header row every 40 lines - if (($stat_row++ % 40) == 0) { - echo display_stat_header($total, false); - } - echo <<< OUTPUT - - {$name} - {$pkg_total[$name]} -OUTPUT; - - $i = 1; - foreach ($titles as $key => $val) { - echo ' '; - echo bugstats($key, $name), "\n"; - } - echo " \n"; + if (!isset($statisticsTally['All'][$packageAndStatus['status']])) { + $statisticsTally['All'][$packageAndStatus['status']] = 0; } + + $statisticsTally['All'][$packageAndStatus['status']] += $packageAndStatus['quant']; } -echo "\n
\n

PHP Versions for recent bug reports:

"; - -$last_date = null; -foreach ($bugRepository->findPhpVersions($bug_type) as $row) { - if ($row['d'] != $last_date) { - if ($last_date !== null) { - echo "\n\n"; - } - echo "\n". - "\n"; - $last_date = $row['d']; +uasort($statistics, function (array $a, array $b) use ($sortBy) { + if (!isset($a[$sortBy])) { + return -1; } - $version = htmlentities($row["formatted_version"], ENT_QUOTES, 'UTF-8'); - echo "\n"; -} -if ($last_date) { - echo "
{$row["d"]}
{$version}{$row["quant"]}
\n"; -} -echo "
\n"; - -response_footer(); - -// Helper functions - -function bugstats($status, $name) -{ - global $pkg, $all, $bug_type; - - if ($name == 'all') { - if (isset($all[$status])) { - return '' . - $all[$status] . "\n"; - } - } else { - if (empty($pkg[$status][$name])) { - return ' '; - } else { - return '' . - $pkg[$status][$name] . "\n"; - } + + if (!isset($b[$sortBy])) { + return 1; } -} -function sort_url($name) -{ - global $sort_by, $rev, $titles; + return $a[$sortBy] <=> $b[$sortBy]; +}); - if ($name == $sort_by) { - $reve = (int) !$rev; - } else { - $reve = 1; - } - if ($sort_by != $name) { - $attr = 'class="bug_stats"'; - } else { - $attr = 'class="bug_stats_choosen"'; - } - return '' . - $titles[$name] . ''; +if ($reverseSort) { + arsort($statistics); } -function display_stat_header($total, $grandtotal = true) -{ - global $titles; +$statistics = array_merge($statisticsTally, $statistics); - $stat_head = " \n"; - if ($grandtotal) { - $stat_head .= " Name\n"; - } else { - $stat_head .= "  \n"; - } - $stat_head .= "  \n"; +$recentReports = []; - foreach ($titles as $key => $val) { - $stat_head .= ' ' . sort_url($key) . "\n"; +foreach ($container->get(BugRepository::class)->findPhpVersions($selectedBugType) as $recentBugs) { + if (!isset($recentReports[$recentBugs['d']])) { + $recentReports[$recentBugs['d']] = []; } - $stat_head .= '' . "\n"; - return $stat_head; + $recentReports[$recentBugs['d']][] = [ + 'version' => $recentBugs['formatted_version'], + 'quantity' => $recentBugs['quant'], + ]; } + +echo $template->render('pages/statistics.php', [ + 'selectedType' => $selectedBugType, + 'sortBy' => $sortBy, + 'reverseSort' => $reverseSort, + 'statistics' => $statistics, + 'recentReports' => $recentReports, +]);