diff --git a/www/commands/progs_updatecheck.php b/www/commands/progs_updatecheck.php index 93108a8..245f42a 100644 --- a/www/commands/progs_updatecheck.php +++ b/www/commands/progs_updatecheck.php @@ -10,7 +10,7 @@ if (!isset($API_OPTIONS['name'])) httpDie(400, "Wrong parameters."); $name = $API_OPTIONS['name']; -$updatedata = Programs::listUpdateData(); +$updatedata = UpdatesLog::listUpdateData(); if (!array_key_exists($name, $updatedata)) httpError(404, 'Invalid Request - [Name] not found'); diff --git a/www/internals/alephnoteStatistics.php b/www/internals/alephnoteStatistics.php index 6c59386..1f1be2b 100644 --- a/www/internals/alephnoteStatistics.php +++ b/www/internals/alephnoteStatistics.php @@ -10,8 +10,6 @@ class AlephNoteStatistics public function __construct(Website $site) { $this->site = $site; - - $site->Database(); } public function getTotalUserCount() diff --git a/www/internals/updateslog.php b/www/internals/updateslog.php index dc40512..01ee07d 100644 --- a/www/internals/updateslog.php +++ b/www/internals/updateslog.php @@ -4,17 +4,45 @@ require_once (__DIR__ . '/../internals/database.php'); class UpdatesLog { - public static function insert($name, $version) + /** @var Website */ + private $site; + + /** @var array */ + private $staticData; + + public function __construct(Website $site) + { + $this->site = $site; + $this->load(); + } + + private function load() + { + $all = require (__DIR__ . '/../statics/blog/__all.php'); + + $this->staticData = array_map(function($a){return self::readSingle($a);}, $all); + } + + private static function readSingle($d) + { + return $d; + } + + public function listUpdateData() + { + return $this->staticData; + } + + public function insert($name, $version) { $ip = get_client_ip(); - $ippath = __DIR__ . '/../dynamic/self_ip_address.auto.cfg'; + $ippath = (__DIR__ . '/../dynamic/self_ip_address.auto.cfg'); $self_ip = file_exists($ippath) ? file_get_contents($ippath) : 'N/A'; if ($self_ip === $ip) $ip = "self"; - Database::connect(); - Database::sql_exec_prep("INSERT INTO updateslog (programname, ip, version, date) VALUES (:pn, :ip, :vn, NOW())", + $this->site->Database()->sql_exec_prep("INSERT INTO updateslog (programname, ip, version, date) VALUES (:pn, :ip, :vn, NOW())", [ [':pn', $name, PDO::PARAM_STR], [':ip', $ip, PDO::PARAM_STR], @@ -22,16 +50,14 @@ class UpdatesLog ]); } - public static function listProgramsInformation() + public function listProgramsInformation() { - Database::connect(); - return Database::sql_query_assoc('SELECT programname AS name, Count(*) as count_total, MAX(date) AS last_query, (SELECT COUNT(*) FROM updateslog AS u1 WHERE u1.programname=u0.programname AND NOW() - INTERVAL 7 DAY < u1.date) AS count_week FROM updateslog AS u0 GROUP BY programname'); + return $this->site->Database()->sql_query_assoc('SELECT programname AS name, Count(*) as count_total, MAX(date) AS last_query, (SELECT COUNT(*) FROM updateslog AS u1 WHERE u1.programname=u0.programname AND NOW() - INTERVAL 7 DAY < u1.date) AS count_week FROM updateslog AS u0 GROUP BY programname'); } - public static function getEntries($name, $limit) + public function getEntries($name, $limit) { - Database::connect(); - return Database::sql_query_assoc_prep('SELECT * FROM updateslog WHERE programname = :pn ORDER BY date DESC LIMIT :lt', + return $this->site->Database()->sql_query_assoc_prep('SELECT * FROM updateslog WHERE programname = :pn ORDER BY date DESC LIMIT :lt', [ [':pn', $name, PDO::PARAM_STR], [':lt', $limit, PDO::PARAM_INT], diff --git a/www/internals/website.php b/www/internals/website.php index ebaf9c2..e564c62 100644 --- a/www/internals/website.php +++ b/www/internals/website.php @@ -21,6 +21,7 @@ class Website /** @var Euler|null */ private $euler = null; /** @var Programs|null */ private $programs = null; /** @var AlephNoteStatistics|null */ private $anstats = null; + /** @var UpdatesLog|null */ private $updateslog = null; public function init() { @@ -196,10 +197,16 @@ class Website public function AlephNoteStatistics() { - if ($this->anstats === null) { require_once 'alephnoteStatistics.php'; $this->anstats = new AlephNoteStatistics(); } + if ($this->anstats === null) { require_once 'alephnoteStatistics.php'; $this->anstats = new AlephNoteStatistics($this); } return $this->anstats; } + public function UpdatesLog() + { + if ($this->updateslog === null) { require_once 'updateslog.php'; $this->updateslog = new UpdatesLog($this); } + return $this->updateslog; + } + /** * @return bool */