Browse Source

Visitor count fix

Roman Hergenreder 3 years ago
parent
commit
852d94e736
6 changed files with 31 additions and 3 deletions
  1. 24 0
      core/Api/Stats.class.php
  2. 2 0
      core/Driver/SQL/SQL.class.php
  3. 1 1
      core/core.php
  4. 0 0
      js/admin.min.js
  5. 1 1
      src/src/footer.js
  6. 3 1
      src/src/views/overview.js

+ 24 - 0
core/Api/Stats.class.php

@@ -2,6 +2,8 @@
 
 namespace Api;
 
+use DateTime;
+use Driver\SQL\Condition\Compare;
 use Driver\SQL\Condition\CondBool;
 
 class Stats extends Request {
@@ -47,6 +49,22 @@ class Stats extends Request {
     return $this->success;
   }
 
+  private function getVisitorCount() {
+    $sql = $this->user->getSQL();
+    $date = new DateTime();
+    $monthStart = $date->format("Ym00");
+    $monthEnd = $date->modify("+1 month")->format("Ym00");
+    $res = $sql->select($sql->count($sql->distinct("cookie")))
+      ->from("Visitor")
+      ->where(new Compare("day", $monthStart, ">="))
+      ->where(new Compare("day", $monthEnd, "<"))
+      ->execute();
+
+    $this->success = ($res !== false);
+    $this->lastError = $sql->getLastError();
+    return ($this->success ? $res[0]["count"] : $this->success);
+  }
+
   public function execute($values = array()) {
     if(!parent::execute($values)) {
       return false;
@@ -62,6 +80,11 @@ class Stats extends Request {
     }
 
     $visitorStatistics = $req->getResult()["visitors"];
+    $visitorCount = $this->getVisitorCount();
+    if (!$this->success) {
+      return false;
+    }
+
     $loadAvg = "Unknown";
     if (function_exists("sys_getloadavg")) {
       $loadAvg = sys_getloadavg();
@@ -74,6 +97,7 @@ class Stats extends Request {
     $this->result["userCount"] = $userCount;
     $this->result["pageCount"] = $pageCount;
     $this->result["visitors"] = $visitorStatistics;
+    $this->result["visitorsTotal"] = $visitorCount;
     $this->result["server"] = array(
       "version" => WEBBASE_VERSION,
       "server" => $_SERVER["SERVER_SOFTWARE"] ?? "Unknown",

+ 2 - 0
core/Driver/SQL/SQL.class.php

@@ -303,6 +303,8 @@ abstract class SQL {
   public function count($col = NULL) {
     if (is_null($col)) {
       return new Keyword("COUNT(*) AS count");
+    } else if($col instanceof Keyword) {
+      return new Keyword("COUNT(" . $col->getValue() . ") AS count");
     } else {
       $countCol = strtolower(str_replace(".","_", $col)) .  "_count";
       $col = $this->columnName($col);

+ 1 - 1
core/core.php

@@ -1,6 +1,6 @@
 <?php
 
-define("WEBBASE_VERSION", "1.0.2");
+define("WEBBASE_VERSION", "1.0.3");
 
 function getProtocol() {
   return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https" : "http";

File diff suppressed because it is too large
+ 0 - 0
js/admin.min.js


+ 1 - 1
src/src/footer.js

@@ -5,7 +5,7 @@ export default function Footer() {
     return (
         <footer className={"main-footer"}>
             Theme: <strong>Copyright © 2014-2019 <a href={"http://adminlte.io"}>AdminLTE.io</a>. <b>Version</b> 3.0.3</strong>&nbsp;
-            CMS: <strong><a href={"https://git.romanh.de/Projekte/web-base"}>WebBase</a></strong>. <b>Version</b> 1.0.2
+            CMS: <strong><a href={"https://git.romanh.de/Projekte/web-base"}>WebBase</a></strong>. <b>Version</b> 1.0.3
         </footer>
     )
 }

+ 3 - 1
src/src/views/overview.js

@@ -22,6 +22,7 @@ export default class Overview extends React.Component {
             statusVisible : true,
             userCount: 0,
             notificationCount: 0,
+            visitorsTotal: 0,
             visitors: { },
             server: { load_avg: ["Unknown"] },
             errors: []
@@ -48,6 +49,7 @@ export default class Overview extends React.Component {
                     userCount: res.userCount,
                     pageCount: res.pageCount,
                     visitors: res.visitors,
+                    visitorsTotal: res.visitorsTotal,
                     server: res.server
                 });
             }
@@ -157,7 +159,7 @@ export default class Overview extends React.Component {
                         <div className={"col-lg-3 col-6"}>
                             <div className={"small-box bg-danger"}>
                                 <div className={"inner"}>
-                                    <h3>{visitorCount}</h3>
+                                    <h3>{this.state.visitorsTotal}</h3>
                                     <p>Unique Visitors</p>
                                 </div>
                                 <div className="icon">

Some files were not shown because too many files changed in this diff