Страница со статистикой
Сделана основа для страницы со статистикой и несколько функций в бэке для неё
This commit is contained in:
parent
751476c4f8
commit
de456dea0a
@ -22,6 +22,19 @@ if ($IS_FRONTEND) {
|
|||||||
|
|
||||||
// Functions
|
// 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
|
* FUNCTION
|
||||||
* Get comments from range of selected comment section
|
* Get comments from range of selected comment section
|
||||||
|
@ -27,14 +27,10 @@ if ($IS_FRONTEND) {
|
|||||||
function Post_GetPostsAmount (): int {
|
function Post_GetPostsAmount (): int {
|
||||||
global $db;
|
global $db;
|
||||||
|
|
||||||
$s = $db->prepare("SELECT id FROM posts"); // NOTICE: very naive and will impact performance when many posts are exist
|
$qr = $db->query("SELECT COUNT(*) FROM posts");
|
||||||
$s->execute();
|
$row = $qr->fetch_row();
|
||||||
$d = $s->get_result()->fetch_assoc();
|
|
||||||
|
|
||||||
if ($d)
|
return $row[0];
|
||||||
return count($d);
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -20,6 +20,19 @@ if (isset($IS_FRONTEND) && $IS_FRONTEND) {
|
|||||||
|
|
||||||
// Functions
|
// 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
|
* FUNCTION
|
||||||
* Get list of all approved tags
|
* Get list of all approved tags
|
||||||
|
@ -20,6 +20,29 @@ if ($IS_FRONTEND) {
|
|||||||
|
|
||||||
// Functions
|
// 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
|
* FUNCTION
|
||||||
* Check if user with supplied login exists
|
* Check if user with supplied login exists
|
||||||
|
@ -7,6 +7,7 @@ $MARKUP_CURRENT_PAGE = "class=\"current\"";
|
|||||||
$MARKUP_CURRENT_PAGE_LOGIN = "";
|
$MARKUP_CURRENT_PAGE_LOGIN = "";
|
||||||
$MARKUP_CURRENT_PAGE_REGISTER = "";
|
$MARKUP_CURRENT_PAGE_REGISTER = "";
|
||||||
$MARKUP_CURRENT_PAGE_VIEWTAGS = "";
|
$MARKUP_CURRENT_PAGE_VIEWTAGS = "";
|
||||||
|
$MARKUP_CURRENT_PAGE_STATS = "";
|
||||||
|
|
||||||
if ($WHAT_PAGE_IS_CURRENT["login"])
|
if ($WHAT_PAGE_IS_CURRENT["login"])
|
||||||
$MARKUP_CURRENT_PAGE_LOGIN = $MARKUP_CURRENT_PAGE;
|
$MARKUP_CURRENT_PAGE_LOGIN = $MARKUP_CURRENT_PAGE;
|
||||||
@ -14,6 +15,8 @@ elseif ($WHAT_PAGE_IS_CURRENT["register"])
|
|||||||
$MARKUP_CURRENT_PAGE_REGISTER = $MARKUP_CURRENT_PAGE;
|
$MARKUP_CURRENT_PAGE_REGISTER = $MARKUP_CURRENT_PAGE;
|
||||||
elseif ($WHAT_PAGE_IS_CURRENT["view_tags"])
|
elseif ($WHAT_PAGE_IS_CURRENT["view_tags"])
|
||||||
$MARKUP_CURRENT_PAGE_VIEWTAGS = $MARKUP_CURRENT_PAGE;
|
$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>
|
<p><a title="A paginated list of every tag" href="./?do=view_tags">Tags</p></a>
|
||||||
</li>
|
</li>
|
||||||
<span>|</span>
|
<span>|</span>
|
||||||
<li>
|
<li <?php echo $MARKUP_CURRENT_PAGE_STATS; ?>>
|
||||||
<p><a title="Statistics of current instance" href="./?do=view_stats">Stats</p></a>
|
<p><a title="Statistics of current instance" href="./?do=view_stats">Stats</p></a>
|
||||||
</li>
|
</li>
|
||||||
<span>|</span>
|
<span>|</span>
|
||||||
|
50
front/pages/stats/page.php
Normal file
50
front/pages/stats/page.php
Normal 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>
|
@ -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 */
|
/* Other */
|
||||||
|
|
||||||
form.login div {
|
form.login div {
|
||||||
|
11
index.php
11
index.php
@ -28,11 +28,20 @@ $WHAT_PAGE_IS_CURRENT = array(
|
|||||||
"main" => false,
|
"main" => false,
|
||||||
"login" => false,
|
"login" => false,
|
||||||
"register" => false,
|
"register" => false,
|
||||||
"view_tags" => false
|
"view_tags" => false,
|
||||||
|
"view_stats" => false
|
||||||
);
|
);
|
||||||
|
|
||||||
// Picking current page
|
// Picking current page
|
||||||
switch ($PICKED_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
|
// Approved tags viewer
|
||||||
case "view_tags":
|
case "view_tags":
|
||||||
$WHAT_PAGE_IS_CURRENT["view_tags"] = true;
|
$WHAT_PAGE_IS_CURRENT["view_tags"] = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user