>From 36ee5561035af335bc3c900ded7aa89066421226 Mon Sep 17 00:00:00 2001 From: Loui Chang Date: Tue, 24 Jun 2008 02:53:16 -0400 Subject: [PATCH] Move code out of index.php Move database queries to functions and html to templates. Signed-off-by: Loui Chang --- web/html/index.php | 182 ++-------------------------- web/lib/stats.inc | 72 +++++++++++ web/template/stats/general_stats_table.php | 38 ++++++ web/template/stats/updates_table.php | 40 ++++++ web/template/stats/user_table.php | 38 ++++++ 5 files changed, 198 insertions(+), 172 deletions(-) create mode 100644 web/lib/stats.inc create mode 100644 web/template/stats/general_stats_table.php create mode 100644 web/template/stats/updates_table.php create mode 100644 web/template/stats/user_table.php diff --git a/web/html/index.php b/web/html/index.php index 7a95abf..ce5e009 100644 --- a/web/html/index.php +++ b/web/html/index.php @@ -5,66 +5,13 @@ set_include_path(get_include_path() . PATH_SEPARATOR . '../lib' . PATH_SEPARATOR # Add to handle the i18n of My Packages include("pkgfuncs_po.inc"); include("aur.inc"); +include('stats.inc'); set_lang(); check_sid(); html_header( __("Home") ); - -# Newest packages -$q = "SELECT * FROM Packages WHERE DummyPkg != 1 ORDER BY GREATEST(SubmittedTS,ModifiedTS) DESC LIMIT 0 , 10"; -$newest_packages = db_query($q, $dbh); - -# AUR statistics -$q = "SELECT count(*) FROM Packages,PackageLocations WHERE Packages.LocationID = PackageLocations.ID AND PackageLocations.Location = 'unsupported'"; -$result = db_query($q, $dbh); -$row = mysql_fetch_row($result); -$unsupported_count = $row[0]; - -$q = "SELECT count(*) FROM Packages,PackageLocations WHERE Packages.LocationID = PackageLocations.ID AND PackageLocations.Location = 'community'"; -$result = db_query($q, $dbh); -$row = mysql_fetch_row($result); -$community_count = $row[0]; - -$q = "SELECT count(*) from Users"; -$result = db_query($q, $dbh); -$row = mysql_fetch_row($result); -$user_count = $row[0]; - -$q = "SELECT count(*) from Users,AccountTypes WHERE Users.AccountTypeID = AccountTypes.ID AND AccountTypes.AccountType = 'Trusted User'"; -$result = db_query($q, $dbh); -$row = mysql_fetch_row($result); -$tu_count = $row[0]; - -$targstamp = intval(strtotime("-7 days")); -$q = "SELECT count(*) from Packages WHERE (Packages.SubmittedTS >= $targstamp OR Packages.ModifiedTS >= $targstamp)"; -$result = db_query($q, $dbh); -$row = mysql_fetch_row($result); -$update_count = $row[0]; - -$user = username_from_sid($_COOKIE["AURSID"]); - -if (!empty($user)) { - $q = "SELECT count(*) FROM Packages,PackageLocations,Users WHERE Packages.MaintainerUID = Users.ID AND Packages.LocationID = PackageLocations.ID AND PackageLocations.Location = 'unsupported' AND Users.Username='".mysql_real_escape_string($user)."'"; - $result = db_query($q, $dbh); - $row = mysql_fetch_row($result); - $maintainer_unsupported_count = $row[0]; - - $q = "SELECT count(*) FROM Packages,Users WHERE Packages.OutOfDate = 1 AND Packages.MaintainerUID = Users.ID AND Users.Username='".mysql_real_escape_string($user)."'"; - $result = db_query($q, $dbh); - $row = mysql_fetch_row($result); - $flagged_outdated = $row[0]; - - # If the user is a TU calculate the number of the packages - $atype = account_from_sid($_COOKIE["AURSID"]); - - if ($atype == 'Trusted User') { - $q = "SELECT count(*) FROM Packages,PackageLocations,Users WHERE Packages.MaintainerUID = Users.ID AND Packages.LocationID = PackageLocations.ID AND PackageLocations.Location = 'community' AND Users.Username='".mysql_real_escape_string($user)."'"; - $result = db_query($q, $dbh); - $row = mysql_fetch_row($result); - $maintainer_community_count = $row[0]; - } -} +$dbh = db_connect(); ?> @@ -106,127 +53,19 @@ print __( 'Contributed PKGBUILDs must conform to the %hArch Packaging Sta - - - - - - - - - - - - - - - - -
- -
-"> - - + - + '; +} -if ($mod_int != 0): - $modstring = gmdate("r", $mod_int); -elseif ($sub_int != 0): - $modstring = ' ' . gmdate("r", $sub_int); -else: - $modstring = '(unknown)'; -endif; +general_stats_table($dbh); ?> - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - - -
- - - -
- - - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- -
- -
- -
- -
- -
@@ -236,4 +75,3 @@ endif; diff --git a/web/lib/stats.inc b/web/lib/stats.inc new file mode 100644 index 0000000..e659210 --- /dev/null +++ b/web/lib/stats.inc @@ -0,0 +1,72 @@ += $targstamp OR Packages.ModifiedTS >= $targstamp)"; + $result = db_query($q, $dbh); + $row = mysql_fetch_row($result); + $update_count = $row[0]; + + include('stats/general_stats_table.php'); +} + diff --git a/web/template/stats/general_stats_table.php b/web/template/stats/general_stats_table.php new file mode 100644 index 0000000..254b6b6 --- /dev/null +++ b/web/template/stats/general_stats_table.php @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ +
+ +
+ +
+ +
+ +
+ diff --git a/web/template/stats/updates_table.php b/web/template/stats/updates_table.php new file mode 100644 index 0000000..e1eb888 --- /dev/null +++ b/web/template/stats/updates_table.php @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + +
+ + +
+ +"> + + + + + ' . gmdate("r", $sub_int); +else: + $modstring = '(unknown)'; +endif; +?> + + +
+ diff --git a/web/template/stats/user_table.php b/web/template/stats/user_table.php new file mode 100644 index 0000000..b844662 --- /dev/null +++ b/web/template/stats/user_table.php @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + +
+ + + +
+ -- 1.5.6.2