Страница со статистикой

Сделана основа для страницы со статистикой и несколько функций в бэке для неё
This commit is contained in:
Shr3dd3r 2024-02-01 13:20:39 +03:00
parent 751476c4f8
commit de456dea0a
8 changed files with 142 additions and 9 deletions

View File

@ -22,6 +22,19 @@ if ($IS_FRONTEND) {
// Functions
/*
* FUNCTION
* Get comments amount
*/
function Comments_GetTotalAmount (): int {
global $db;
$qr = $db->query("SELECT COUNT(*) FROM comments");
$row = $qr->fetch_row();
return $row[0];
}
/*
* FUNCTION
* Get comments from range of selected comment section

View File

@ -27,14 +27,10 @@ if ($IS_FRONTEND) {
function Post_GetPostsAmount (): int {
global $db;
$s = $db->prepare("SELECT id FROM posts"); // NOTICE: very naive and will impact performance when many posts are exist
$s->execute();
$d = $s->get_result()->fetch_assoc();
$qr = $db->query("SELECT COUNT(*) FROM posts");
$row = $qr->fetch_row();
if ($d)
return count($d);
else
return 0;
return $row[0];
}
/*

View File

@ -20,6 +20,19 @@ if (isset($IS_FRONTEND) && $IS_FRONTEND) {
// Functions
/*
* FUNCTION
* Get amount of approved tags
*/
function Tags_GetTagsAmount (): int {
global $db;
$qr = $db->query("SELECT COUNT(*) FROM approved_tags");
$row = $qr->fetch_row();
return $row[0];
}
/*
* FUNCTION
* Get list of all approved tags

View File

@ -20,6 +20,29 @@ if ($IS_FRONTEND) {
// Functions
/*
* FUNCTION
* Get amount of users
*/
function User_GetUsersAmount (): array {
global $db;
$result = array(
"users" => 0,
"banned" => 0
);
$qr = $db->query("SELECT COUNT(*) FROM users");
$row = $qr->fetch_row();
$result["users"] = $row[0];
$qr = $db->query("SELECT COUNT(*) FROM users WHERE banned = TRUE");
$row = $qr->fetch_row();
$result["banned"] = $row[0];
return $result;
}
/*
* FUNCTION
* Check if user with supplied login exists

View File

@ -7,6 +7,7 @@ $MARKUP_CURRENT_PAGE = "class=\"current\"";
$MARKUP_CURRENT_PAGE_LOGIN = "";
$MARKUP_CURRENT_PAGE_REGISTER = "";
$MARKUP_CURRENT_PAGE_VIEWTAGS = "";
$MARKUP_CURRENT_PAGE_STATS = "";
if ($WHAT_PAGE_IS_CURRENT["login"])
$MARKUP_CURRENT_PAGE_LOGIN = $MARKUP_CURRENT_PAGE;
@ -14,6 +15,8 @@ elseif ($WHAT_PAGE_IS_CURRENT["register"])
$MARKUP_CURRENT_PAGE_REGISTER = $MARKUP_CURRENT_PAGE;
elseif ($WHAT_PAGE_IS_CURRENT["view_tags"])
$MARKUP_CURRENT_PAGE_VIEWTAGS = $MARKUP_CURRENT_PAGE;
elseif ($WHAT_PAGE_IS_CURRENT["view_stats"])
$MARKUP_CURRENT_PAGE_STATS = $MARKUP_CURRENT_PAGE;
@ -40,7 +43,7 @@ elseif ($WHAT_PAGE_IS_CURRENT["view_tags"])
<p><a title="A paginated list of every tag" href="./?do=view_tags">Tags</p></a>
</li>
<span>|</span>
<li>
<li <?php echo $MARKUP_CURRENT_PAGE_STATS; ?>>
<p><a title="Statistics of current instance" href="./?do=view_stats">Stats</p></a>
</li>
<span>|</span>

View File

@ -0,0 +1,50 @@
<?php
// Approved tags list
// Includes
require_once("api/_config.php");
require_once("api/user/index.php");
require_once("api/tags/index.php");
require_once("api/post/index.php");
require_once("api/comments/index.php");
require_once("front/pages/main_nav.php");
require_once("front/notifications.php");
// Getting stats
$statUsers = User_GetUsersAmount(); // array
$statTags = Tags_GetTagsAmount(); // int
$statPosts = Post_GetPostsAmount(); // int
$statComms = Comments_GetTotalAmount(); // int
NTFY_EchoAllNotices();
?>
<div class="visualbox">
<h1>Instance statistics</h1>
<table>
<tr>
<th><p>Users amount</p></th>
<td><p>Total: <?php echo $statUsers["users"]; ?></p></td>
<td><p>Banned: <?php echo $statUsers["banned"]; ?></p></td>
</tr>
<tr>
<th><p>Tags amount</p></th>
<td><p>Total: <?php echo $statTags; ?></p></td>
</tr>
<tr>
<th><p>Posts amount</p></th>
<td><p>Total: <?php echo $statPosts; ?></p></td>
</tr>
<tr>
<th><p>Comments amount</p></th>
<td><p>Total: <?php echo $statComms; ?></p></td>
</tr>
</table>
</div>

View File

@ -62,6 +62,32 @@ nav.main ul span {
/* Table */
table, tr, th, td {
border: 2px solid #009049;
}
table {
border-collapse: collapse;
}
th, td {
padding: 4px;
}
th {
padding-left: 8px;
padding-right: 8px;
}
td {
padding-left: 16px;
padding-right: 16px;
}
/* Other */
form.login div {

View File

@ -28,11 +28,20 @@ $WHAT_PAGE_IS_CURRENT = array(
"main" => false,
"login" => false,
"register" => false,
"view_tags" => false
"view_tags" => false,
"view_stats" => false
);
// Picking current page
switch ($PICKED_PAGE) {
// Navigable pages
// Common instance statistics
case "view_stats":
$WHAT_PAGE_IS_CURRENT["view_stats"] = true;
$PAGE_TITLE = "Instance statistics";
$PAGE_STYLE = "front/styles/main.css";
$PAGE_FILE = "front/pages/stats/page.php";
break;
// Approved tags viewer
case "view_tags":
$WHAT_PAGE_IS_CURRENT["view_tags"] = true;