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"])

Tags

| -
  • +
  • >

    Stats

  • | diff --git a/front/pages/stats/page.php b/front/pages/stats/page.php new file mode 100644 index 0000000..eed40bf --- /dev/null +++ b/front/pages/stats/page.php @@ -0,0 +1,50 @@ + +
    +

    Instance statistics

    + + + + + + + + + + + + + + + + + + +

    Users amount

    Total:

    Banned:

    Tags amount

    Total:

    Posts amount

    Total:

    Comments amount

    Total:

    +
    diff --git a/front/styles/main.css b/front/styles/main.css index ed41dc3..a33478e 100644 --- a/front/styles/main.css +++ b/front/styles/main.css @@ -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 { diff --git a/index.php b/index.php index 3c23161..9f55a45 100644 --- a/index.php +++ b/index.php @@ -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;