removed visitors feature
This commit is contained in:
@@ -36,40 +36,11 @@ class Stats extends Request {
|
||||
return $this->success;
|
||||
}
|
||||
|
||||
private function getVisitorCount() {
|
||||
$sql = $this->context->getSQL();
|
||||
$date = new DateTime();
|
||||
$monthStart = $date->format("Ym00");
|
||||
$monthEnd = $date->modify("+1 month")->format("Ym00");
|
||||
$res = $sql->select(new Count(new Distinct("cookie")))
|
||||
->from("Visitor")
|
||||
->where(new Compare("day", $monthStart, ">="))
|
||||
->where(new Compare("day", $monthEnd, "<"))
|
||||
->where(new Compare("count", 2, ">="))
|
||||
->execute();
|
||||
|
||||
$this->success = ($res !== false);
|
||||
$this->lastError = $sql->getLastError();
|
||||
return ($this->success ? $res[0]["count"] : $this->success);
|
||||
}
|
||||
|
||||
public function _execute(): bool {
|
||||
$sql = $this->context->getSQL();
|
||||
$userCount = User::count($sql);
|
||||
$pageCount = Route::count($sql, new CondBool("active"));
|
||||
$groupCount = Group::count($sql);
|
||||
$req = new \Core\API\Visitors\Stats($this->context);
|
||||
$this->success = $req->execute(array("type"=>"monthly"));
|
||||
$this->lastError = $req->getLastError();
|
||||
if (!$this->success) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$visitorStatistics = $req->getResult()["visitors"];
|
||||
$visitorCount = $this->getVisitorCount();
|
||||
if (!$this->success) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$req = new \Core\API\Logs\Get($this->context, false);
|
||||
$success = $req->execute([
|
||||
@@ -96,8 +67,6 @@ class Stats extends Request {
|
||||
"userCount" => $userCount,
|
||||
"pageCount" => $pageCount,
|
||||
"groupCount" => $groupCount,
|
||||
"visitors" => $visitorStatistics,
|
||||
"visitorsTotal" => $visitorCount,
|
||||
"errorCount" => $errorCount,
|
||||
"server" => [
|
||||
"version" => WEBBASE_VERSION,
|
||||
|
||||
@@ -1,122 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Core\API {
|
||||
|
||||
use Core\Objects\Context;
|
||||
|
||||
abstract class VisitorsAPI extends Request {
|
||||
public function __construct(Context $context, bool $externalCall = false, array $params = []) {
|
||||
parent::__construct($context, $externalCall, $params);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace Core\API\Visitors {
|
||||
|
||||
use Core\API\Parameter\Parameter;
|
||||
use Core\API\Parameter\StringType;
|
||||
use Core\API\VisitorsAPI;
|
||||
use Core\Driver\SQL\Expression\Count;
|
||||
use Core\Driver\SQL\Query\Insert;
|
||||
use Core\Objects\DatabaseEntity\Group;
|
||||
use DateTime;
|
||||
use Core\Driver\SQL\Condition\Compare;
|
||||
use Core\Driver\SQL\Expression\Add;
|
||||
use Core\Driver\SQL\Query\Select;
|
||||
use Core\Driver\SQL\Strategy\UpdateStrategy;
|
||||
use Core\Objects\Context;
|
||||
|
||||
class ProcessVisit extends VisitorsAPI {
|
||||
public function __construct(Context $context, bool $externalCall = false) {
|
||||
parent::__construct($context, $externalCall, array(
|
||||
"cookie" => new StringType("cookie", 26)
|
||||
));
|
||||
$this->isPublic = false;
|
||||
}
|
||||
|
||||
public function _execute(): bool {
|
||||
$sql = $this->context->getSQL();
|
||||
$cookie = $this->getParam("cookie");
|
||||
$day = (new DateTime())->format("Ymd");
|
||||
$sql->insert("Visitor", array("cookie", "day"))
|
||||
->addRow($cookie, $day)
|
||||
->onDuplicateKeyStrategy(new UpdateStrategy(
|
||||
array("day", "cookie"),
|
||||
array("count" => new Add("Visitor.count", 1))))
|
||||
->execute();
|
||||
|
||||
return $this->success;
|
||||
}
|
||||
}
|
||||
|
||||
class Stats extends VisitorsAPI {
|
||||
public function __construct(Context $context, bool $externalCall = false) {
|
||||
parent::__construct($context, $externalCall, array(
|
||||
'type' => new StringType('type', 32),
|
||||
'date' => new Parameter('date', Parameter::TYPE_DATE, true, new DateTime())
|
||||
));
|
||||
}
|
||||
|
||||
private function setConditions(string $type, DateTime $date, Select $query): bool {
|
||||
if ($type === "yearly") {
|
||||
$yearStart = $date->format("Y0000");
|
||||
$yearEnd = $date->modify("+1 year")->format("Y0000");
|
||||
$query->where(new Compare("day", $yearStart, ">="));
|
||||
$query->where(new Compare("day", $yearEnd, "<"));
|
||||
} else if($type === "monthly") {
|
||||
$monthStart = $date->format("Ym00");
|
||||
$monthEnd = $date->modify("+1 month")->format("Ym00");
|
||||
$query->where(new Compare("day", $monthStart, ">="));
|
||||
$query->where(new Compare("day", $monthEnd, "<"));
|
||||
} else if($type === "weekly") {
|
||||
$weekStart = ($date->modify("monday this week"))->format("Ymd");
|
||||
$weekEnd = ($date->modify("sunday this week"))->format("Ymd");
|
||||
$query->where(new Compare("day", $weekStart, ">="));
|
||||
$query->where(new Compare("day", $weekEnd, "<="));
|
||||
} else {
|
||||
return $this->createError("Invalid scope: $type");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function _execute(): bool {
|
||||
$date = $this->getParam("date");
|
||||
$type = $this->getParam("type");
|
||||
|
||||
$sql = $this->context->getSQL();
|
||||
$query = $sql->select(new Count(), "day")
|
||||
->from("Visitor")
|
||||
->whereGt("count", 1)
|
||||
->groupBy("day")
|
||||
->orderBy("day")
|
||||
->ascending();
|
||||
|
||||
$this->success = $this->setConditions($type, $date, $query);
|
||||
if (!$this->success) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$res = $query->execute();
|
||||
$this->success = ($res !== FALSE);
|
||||
$this->lastError = $sql->getLastError();
|
||||
|
||||
if ($this->success) {
|
||||
$this->result["type"] = $type;
|
||||
$this->result["visitors"] = array();
|
||||
|
||||
foreach($res as $row) {
|
||||
$day = DateTime::createFromFormat("Ymd", $row["day"])->format("Y/m/d");
|
||||
$count = $row["count"];
|
||||
$this->result["visitors"][$day] = $count;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->success;
|
||||
}
|
||||
|
||||
public static function getDefaultACL(Insert $insert): void {
|
||||
$insert->addRow(self::getEndpoint(), [Group::ADMIN, Group::SUPPORT], "Allows users to view visitor statistics", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,12 +18,6 @@ class CreateDatabase extends DatabaseScript {
|
||||
|
||||
self::loadEntities($queries, $sql);
|
||||
|
||||
$queries[] = $sql->createTable("Visitor")
|
||||
->addInt("day")
|
||||
->addInt("count", false, 1)
|
||||
->addString("cookie", 26)
|
||||
->unique("day", "cookie");
|
||||
|
||||
$queries[] = $sql->createTable("Settings")
|
||||
->addString("name", 32)
|
||||
->addString("value", 1024, true)
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
return [
|
||||
"title" => "Administration",
|
||||
"dashboard" => "Dashboard",
|
||||
"visitor_statistics" => "Besucherstatistiken",
|
||||
"user_groups" => "Benutzer & Gruppen",
|
||||
"users" => "Benutzer",
|
||||
"groups" => "Gruppen",
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
return [
|
||||
"title" => "Administration",
|
||||
"dashboard" => "Dashboard",
|
||||
"visitor_statistics" => "Visitor Statistics",
|
||||
"user_groups" => "Users & Groups",
|
||||
"users" => "Users",
|
||||
"groups" => "Groups",
|
||||
|
||||
@@ -139,18 +139,6 @@ class Context {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function processVisit(): void {
|
||||
if (isset($_COOKIE["PHPSESSID"]) && !empty($_COOKIE["PHPSESSID"])) {
|
||||
if ($this->isBot()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$cookie = $_COOKIE["PHPSESSID"];
|
||||
$req = new \Core\API\Visitors\ProcessVisit($this);
|
||||
$req->execute(["cookie" => $cookie]);
|
||||
}
|
||||
}
|
||||
|
||||
private function isBot(): bool {
|
||||
if (empty($_SERVER["HTTP_USER_AGENT"])) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user