-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats.php
113 lines (106 loc) · 4.3 KB
/
stats.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
require("core/functions.php");
require("core/dbConnect.php");
$getStats = $connect->prepare("SELECT * FROM stats");
$getStats->execute();
$getBrowsersAndDevices = $connect->prepare("SELECT * FROM browsers");
$getBrowsersAndDevices->execute(); ?>
<!DOCTYPE html>
<html lang="tr">
<head>
<title><?php echo($settings["title"]); ?> - Statistics</title>
<?php require("pages/header.php"); ?>
<link rel="stylesheet" href="assets/css/stats.css">
</head>
<body class="bg-primary-gradient">
<?php require("pages/navbar.php"); ?>
<a id="topButton" href="#">
<svg class="bi bi-chevron-up" xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" fill="white" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M7.646 4.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1-.708.708L8 5.707l-5.646 5.647a.5.5 0 0 1-.708-.708l6-6z"></path>
</svg>
</a>
<section class="pt-5 mt-5 mb-4">
<div class="container mb-0 pt-5 p-lg-5">
<?php if(($getStats->rowCount()) > 0 and ($getBrowsersAndDevices->rowCount() > 0)){ ?>
<div class="row mb-5">
<div>
<h3 class="fw-bold">Most Frequently Used Tools</h3>
</div>
</div>
<?php $stats = $getStats->fetchAll(PDO::FETCH_ASSOC);
uasort($stats[0], function($a, $b){
return $b - $a;
});
$popularTools = array_slice($stats[0], 0, 10); ?>
<div class="chart">
<div class="chart-container">
<canvas id="popularTools"></canvas>
</div>
</div>
<div class="row mb-5">
<div>
<h3 class="fw-bold">Most Frequently Used Browsers</h3>
</div>
</div>
<div class="chart">
<div class="chart-container">
<canvas id="popularBrowsers"></canvas>
</div>
</div>
<div class="row mb-5">
<div>
<h3 class="fw-bold">Most Frequently Used Devices</h3>
</div>
</div>
<div class="chart">
<div class="chart-container" style="margin-bottom: 0;">
<canvas id="popularDevices"></canvas>
</div>
</div>
</div>
<?php }else{ ?>
<div class="alert alert-danger" role="alert">
There are currently no statistics available.
</div>
<?php } ?>
</section>
<?php require("pages/footer.php"); ?>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/Chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script src="assets/js/bold-and-bright.js"></script>
<script>
<?php
if(($getStats->rowCount()) > 0 and ($getBrowsersAndDevices->rowCount() > 0)){
$popularToolsKeys = array_keys($popularTools);
$popularToolsKeys = array_map(function($el) use ($pageNames){
return @$pageNames[$el] ?? "Unknown Tool";
}, $popularToolsKeys);
$popularToolsData = array_values($popularTools);
echo "let getPopularTools = " . json_encode($popularToolsKeys) . ";\n";
echo "let getPopularToolsData = " . json_encode($popularToolsData) . ";\n";
$browsersAndDevices = $getBrowsersAndDevices->fetchAll(PDO::FETCH_ASSOC)[0];
$getBrowsers = json_decode($browsersAndDevices["browsers"], true);
uasort($getBrowsers, function($a, $b){
return $b - $a;
});
$getBrowsers = array_slice($getBrowsers, 0, 10);
$getBrowsers = array_filter($getBrowsers, function($key, $val){
return !strpos(strtolower($val), "bot") and !strpos(strtolower($val), "unknown");
}, ARRAY_FILTER_USE_BOTH);
$getDevices = json_decode($browsersAndDevices["devices"], true);
uasort($getDevices, function($a, $b){
return $b - $a;
});
$getDevices = array_slice($getDevices, 0, 10);
echo "let getPopularBrowsers = " . json_encode(array_keys($getBrowsers)) . ";\n";
echo "let getPopularBrowsersData = " . json_encode(array_values($getBrowsers)) . ";\n";
echo "let getPopularDevices = " . json_encode(array_keys($getDevices)) . ";\n";
echo "let getPopularDevicesData = " . json_encode(array_values($getDevices)) . ";\n"; ?>
</script>
<script src="assets/js/stats.js"></script>
<script src="assets/js/all.js"></script>
<?php
} ?>
</body>
</html>