Add some analytics data on the Home page

master
Skylar Ittner 6 years ago
parent 8d8982cfce
commit 3c84b1c02f

@ -65,5 +65,11 @@ define("STRINGS", [
"title" => "Title",
"page id" => "Page ID (slug)",
"add page" => "Add page",
"page settings" => "Page Settings"
"page settings" => "Page Settings",
"today" => "Today",
"this week" => "This Week",
"visit" => "visit",
"visits" => "visits",
"page view" => "page view",
"page views" => "page views",
]);

@ -8,7 +8,7 @@
use GeoIp2\Database\Reader;
$_SERVER['REMOTE_ADDR'] = "206.127.96.82";
//$_SERVER['REMOTE_ADDR'] = "206.127.96.82";
try {

@ -2,5 +2,70 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
require_once __DIR__ . '/../required.php';
redirectifnotloggedin();
?>
<h1>Hello World</h1>
<div class="card-deck">
<?php
$visitors = $database->select('analytics', "uuid", ["time[>]" => date("Y-m-d H:i:s", strtotime("-1 day"))]);
$uuids = [];
foreach ($visitors as $v) {
if (!in_array($v, $uuids)) {
$uuids[] = $v;
}
}
$visits_today = count($uuids);
$views_today = count($visitors);
?>
<div class="card bg-blue text-light">
<div class="card-body">
<h4 class="card-title"><?php lang("today") ?></h4>
<h1><i class="fas fa-fw fa-users"></i> <?php echo $visits_today; ?> <?php
if ($visits_today == 1) {
lang("visit");
} else {
lang("visits");
}
?></h1>
<h1><i class="fas fa-fw fa-eye"></i> <?php echo $views_today; ?> <?php
if ($views_today == 1) {
lang("page view");
} else {
lang("page views");
}
?></h1>
</div>
</div>
<?php
$visitors = $database->select('analytics', "uuid", ["time[>]" => date("Y-m-d H:i:s", strtotime("-1 week"))]);
$uuids = [];
foreach ($visitors as $v) {
if (!in_array($v, $uuids)) {
$uuids[] = $v;
}
}
$visits_week = count($uuids);
$views_week = count($visitors);
?>
<div class="card bg-<?php echo ($lowcnt > 0 ? "deep-orange" : "green"); ?> text-light">
<div class="card-body">
<h4 class="card-title"><?php lang("this week") ?></h4>
<h1><i class="fas fa-fw fa-users"></i> <?php echo $visits_week; ?> <?php
if ($visits_week == 1) {
lang("visit");
} else {
lang("visits");
}
?></h1>
<h1><i class="fas fa-fw fa-eye"></i> <?php echo $views_week; ?> <?php
if ($views_week == 1) {
lang("page view");
} else {
lang("page views");
}
?></h1>
</div>
</div>
</div>

Loading…
Cancel
Save