diff --git a/api/comments/index.php b/api/comments/index.php index d385515..0e37b86 100644 --- a/api/comments/index.php +++ b/api/comments/index.php @@ -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 diff --git a/api/post/index.php b/api/post/index.php index 4e88f27..25b18ad 100644 --- a/api/post/index.php +++ b/api/post/index.php @@ -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]; } /* diff --git a/api/tags/index.php b/api/tags/index.php index cb08e14..63ec3b5 100644 --- a/api/tags/index.php +++ b/api/tags/index.php @@ -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 diff --git a/api/user/index.php b/api/user/index.php index 8aea5ef..5aec564 100644 --- a/api/user/index.php +++ b/api/user/index.php @@ -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 diff --git a/front/pages/main_nav.php b/front/pages/main_nav.php index 06f23ce..f2e0106 100644 --- a/front/pages/main_nav.php +++ b/front/pages/main_nav.php @@ -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"])
| -Users amount |
+ Total: |
+ Banned: |
+
---|---|---|
Tags amount |
+ Total: |
+ |
Posts amount |
+ Total: |
+ |
Comments amount |
+ Total: |
+