1
0

ndex route works again

This commit is contained in:
2020-01-15 02:50:23 +01:00
parent f9a692e635
commit 588e9b089a
30 changed files with 427 additions and 258 deletions

View File

@@ -1,34 +0,0 @@
<?php
require_once 'website.php';
class AlephNoteStatistics
{
/** @var Website */
private $site;
public function __construct(Website $site)
{
$this->site = $site;
}
public function getTotalUserCount()
{
return $this->site->Database()->sql_query_num('SELECT COUNT(*) FROM an_statslog WHERE NoteCount>0');
}
public function getUserCountFromLastVersion()
{
return $this->site->Database()->sql_query_num('SELECT COUNT(*) FROM an_statslog WHERE NoteCount>0 GROUP BY Version ORDER BY INET_ATON(Version) DESC LIMIT 1');
}
public function getActiveUserCount($days)
{
return $this->site->Database()->sql_query_num('SELECT COUNT(*) FROM an_statslog WHERE NoteCount>0 AND LastChanged > NOW() - INTERVAL '.$days.' DAY');
}
public function getAllActiveEntriesOrdered()
{
return $this->site->Database()->sql_query_assoc('SELECT * FROM an_statslog WHERE NoteCount>0 ORDER BY LastChanged DESC');
}
}

View File

@@ -0,0 +1,48 @@
<?php
class Fragments
{
public function PanelEuler()
{
global $FRAGMENT_PARAM;
$FRAGMENT_PARAM = [ ];
include (__DIR__ . '/../fragments/panel_euler.php');
}
public function PanelPrograms()
{
global $FRAGMENT_PARAM;
$FRAGMENT_PARAM = [ ];
include (__DIR__ . '/../fragments/panel_programs.php');
}
public function PanelBlog()
{
global $FRAGMENT_PARAM;
$FRAGMENT_PARAM = [ ];
include (__DIR__ . '/../fragments/panel_blog.php');
}
public function PanelBooks()
{
global $FRAGMENT_PARAM;
$FRAGMENT_PARAM = [ ];
include (__DIR__ . '/../fragments/panel_books.php');
}
public function PanelAdventOfCode()
{
global $FRAGMENT_PARAM;
$FRAGMENT_PARAM = [ ];
include (__DIR__ . '/../fragments/panel_aoc.php');
}
public function PanelAdventOfCodeCalendar(int $year, bool $shownav, bool $linkheader, bool $ajax, bool $frame=true, $frameid=null)
{
if ($frameid == null) $frameid = 'aoc_frame_' . getRandomToken(16);
global $FRAGMENT_PARAM;
$FRAGMENT_PARAM = [ 'year' => $year, 'nav'=>$shownav, 'linkheader'=>$linkheader, 'ajax'=>$ajax, 'frame'=>$frame, 'frameid'=>$frameid ];
include (__DIR__ . '/../fragments/panel_aoc_calendar.php');
}
}

86
www/internals/modules.php Normal file
View File

@@ -0,0 +1,86 @@
<?php
require_once 'website.php';
class Modules
{
/** @var Database|null */ private $database = null;
/** @var AdventOfCode|null */ private $adventOfCode = null;
/** @var Blog|null */ private $blog = null;
/** @var Books|null */ private $books = null;
/** @var Euler|null */ private $euler = null;
/** @var Programs|null */ private $programs = null;
/** @var AlephNoteStatistics|null */ private $anstats = null;
/** @var UpdatesLog|null */ private $updateslog = null;
/** @var WebApps|null */ private $webapps = null;
/** @var MikescherGitGraph|null */ private $extendedgitgraph = null;
/** @var Website */
private $site;
public function __construct(Website $site)
{
$this->site = $site;
}
public function Database()
{
if ($this->database === null) { require_once 'modules/database.php'; $this->database = new Database($this->site); }
return $this->database;
}
public function AdventOfCode(): AdventOfCode
{
if ($this->adventOfCode === null) { require_once 'modules/adventofcode.php'; $this->adventOfCode = new AdventOfCode(); }
return $this->adventOfCode;
}
public function Blog(): Blog
{
if ($this->blog === null) { require_once 'modules/blog.php'; $this->blog = new Blog(); }
return $this->blog;
}
public function Books(): Books
{
if ($this->books === null) { require_once 'modules/books.php'; $this->books = new Books(); }
return $this->books;
}
public function Euler(): Euler
{
if ($this->euler === null) { require_once 'modules/euler.php'; $this->euler = new Euler(); }
return $this->euler;
}
public function Programs(): Programs
{
if ($this->programs === null) { require_once 'modules/programs.php'; $this->programs = new Programs(); }
return $this->programs;
}
public function AlephNoteStatistics(): AlephNoteStatistics
{
if ($this->anstats === null) { require_once 'modules/alephnoteStatistics.php'; $this->anstats = new AlephNoteStatistics($this->site); }
return $this->anstats;
}
public function UpdatesLog(): UpdatesLog
{
if ($this->updateslog === null) { require_once 'modules/updateslog.php'; $this->updateslog = new UpdatesLog($this->site); }
return $this->updateslog;
}
public function WebApps(): WebApps
{
if ($this->webapps === null) { require_once 'modules/webapps.php'; $this->webapps = new WebApps(); }
return $this->webapps;
}
public function ExtendedGitGraph(): MikescherGitGraph
{
if ($this->extendedgitgraph === null) { require_once 'modules/mikeschergitgraph.php'; $this->extendedgitgraph = new MikescherGitGraph($this->site); }
return $this->extendedgitgraph;
}
}

View File

@@ -1,7 +1,5 @@
<?php
require_once 'website.php';
class AdventOfCode
{
const YEARS =
@@ -35,7 +33,7 @@ class AdventOfCode
private function load()
{
$all = require (__DIR__ . '/../statics/aoc/__all.php');
$all = require (__DIR__ . '/../../statics/aoc/__all.php');
array_walk($all, function(&$value, $year) { array_walk($value, function (&$innervalue) use ($year) { $innervalue = self::readSingle($year, $innervalue); }); });

View File

@@ -0,0 +1,32 @@
<?php
class AlephNoteStatistics
{
/** @var Website */
private $site;
public function __construct(Website $site)
{
$this->site = $site;
}
public function getTotalUserCount()
{
return $this->site->modules->Database()->sql_query_num('SELECT COUNT(*) FROM an_statslog WHERE NoteCount>0');
}
public function getUserCountFromLastVersion()
{
return $this->site->modules->Database()->sql_query_num('SELECT COUNT(*) FROM an_statslog WHERE NoteCount>0 GROUP BY Version ORDER BY INET_ATON(Version) DESC LIMIT 1');
}
public function getActiveUserCount($days)
{
return $this->site->modules->Database()->sql_query_num('SELECT COUNT(*) FROM an_statslog WHERE NoteCount>0 AND LastChanged > NOW() - INTERVAL '.$days.' DAY');
}
public function getAllActiveEntriesOrdered()
{
return $this->site->modules->Database()->sql_query_assoc('SELECT * FROM an_statslog WHERE NoteCount>0 ORDER BY LastChanged DESC');
}
}

View File

@@ -1,7 +1,5 @@
<?php
require_once 'website.php';
class Blog
{
/** @var array */
@@ -14,7 +12,7 @@ class Blog
private function load()
{
$all = require (__DIR__ . '/../statics/blog/__all.php');
$all = require (__DIR__ . '/../../statics/blog/__all.php');
$this->staticData = array_map(function($a){return self::readSingle($a);}, $all);
}
@@ -66,8 +64,7 @@ class Blog
$eulerproblem = null;
if ($isSubEuler)
{
require_once(__DIR__ . '/../internals/euler.php');
$eulerproblem = Website::inst()->Euler()->getEulerProblemFromStrIdent($subview);
$eulerproblem = Website::inst()->modules->Euler()->getEulerProblemFromStrIdent($subview);
if ($eulerproblem === null) { $error="Project Euler entry not found"; return null; }
$post['submodel'] = $eulerproblem;
$post['issubview'] = true;
@@ -77,8 +74,7 @@ class Blog
$adventofcodeday = null;
if ($isSubAdventOfCode)
{
require_once(__DIR__ . '/../internals/adventofcode.php');
$adventofcodeday = Website::inst()->AdventOfCode()->getDayFromStrIdent($post['extras']['aoc:year'], $subview);
$adventofcodeday = Website::inst()->modules->AdventOfCode()->getDayFromStrIdent($post['extras']['aoc:year'], $subview);
if ($adventofcodeday === null) { $error="AdventOfCode entry not found"; return null; }
$post['submodel'] = $adventofcodeday;
$post['issubview'] = true;

View File

@@ -1,7 +1,5 @@
<?php
require_once 'website.php';
class Books
{
/** @var array */
@@ -14,7 +12,7 @@ class Books
private function load()
{
$all = require (__DIR__ . '/../statics/books/__all.php');
$all = require (__DIR__ . '/../../statics/books/__all.php');
$this->staticData = array_map(function($a){return self::readSingle($a);}, $all);
}

View File

@@ -1,7 +1,5 @@
<?php
require_once 'website.php';
class Database
{
/* @var PDO $pdo */

View File

@@ -1,7 +1,5 @@
<?php
require_once 'website.php';
class Euler
{
/** @var array */
@@ -14,7 +12,7 @@ class Euler
private function load()
{
$all = require (__DIR__ . '/../statics/euler/__all.php');
$all = require (__DIR__ . '/../../statics/euler/__all.php');
$this->staticData = array_map(function($a){return self::readSingle($a);}, $all);
}

View File

@@ -1,7 +1,6 @@
<?php
require_once 'website.php';
require_once (__DIR__ . '/../extern/egg/ExtendedGitGraph2.php');
require_once (__DIR__ . '/../../extern/egg/ExtendedGitGraph2.php');
class MikescherGitGraph
{
@@ -16,7 +15,7 @@ class MikescherGitGraph
public function getPathRenderedData()
{
return __DIR__ . '/../dynamic/egg/cache_fullrenderer.html';
return __DIR__ . '/../../dynamic/egg/cache_fullrenderer.html';
}
/**
@@ -32,7 +31,7 @@ class MikescherGitGraph
public function checkConsistency()
{
$p =$this->getPathRenderedData();
$p = $this->getPathRenderedData();
if (!file_exists($p)) return ['result'=>'err', 'message' => 'Rendered data not found'];

View File

@@ -1,7 +1,5 @@
<?php
require_once 'website.php';
class Programs
{
const PROG_LANGS = [ 'Java', 'C#', 'Delphi', 'PHP', 'C++' ];
@@ -43,7 +41,7 @@ class Programs
private function load()
{
$all = require (__DIR__ . '/../statics/programs/__all.php');
$all = require (__DIR__ . '/../../statics/programs/__all.php');
$this->staticData = array_map(function($a){return self::readSingle($a);}, $all);
}
@@ -197,7 +195,7 @@ class Programs
public function getDirectDownloadPath($prog)
{
return (__DIR__ . '/../data/binaries/'.$prog['internal_name'].'.zip');
return (__DIR__ . '/../../data/binaries/'.$prog['internal_name'].'.zip');
}
public function checkConsistency()

View File

@@ -1,7 +1,5 @@
<?php
require_once (__DIR__ . '/../internals/database.php');
class UpdatesLog
{
/** @var Website */
@@ -18,7 +16,7 @@ class UpdatesLog
private function load()
{
$all = require (__DIR__ . '/../statics/blog/__all.php');
$all = require (__DIR__ . '/../../statics/blog/__all.php');
$this->staticData = array_map(function($a){return self::readSingle($a);}, $all);
}
@@ -37,12 +35,12 @@ class UpdatesLog
{
$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";
$this->site->Database()->sql_exec_prep("INSERT INTO updateslog (programname, ip, version, date) VALUES (:pn, :ip, :vn, NOW())",
$this->site->modules->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],
@@ -52,12 +50,12 @@ class UpdatesLog
public function listProgramsInformation()
{
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');
return $this->site->modules->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 function getEntries($name, $limit)
{
return $this->site->Database()->sql_query_assoc_prep('SELECT * FROM updateslog WHERE programname = :pn ORDER BY date DESC LIMIT :lt',
return $this->site->modules->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],

View File

@@ -1,7 +1,5 @@
<?php
require_once 'website.php';
class WebApps
{
/** @var array */
@@ -14,7 +12,7 @@ class WebApps
private function load()
{
$all = require (__DIR__ . '/../statics/webapps/__all.php');
$all = require (__DIR__ . '/../../statics/webapps/__all.php');
$this->staticData = array_map(function($a){return self::readSingle($a);}, $all);
}
@@ -30,6 +28,4 @@ class WebApps
usort($data, function($a, $b) { return strcasecmp($b['date'], $a['date']); });
return $data;
}
}
}

View File

@@ -101,7 +101,6 @@ class RuleEngine
{
// enforce https
$redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
ob_end_clean();
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $redirect);
exit();

View File

@@ -44,22 +44,28 @@ class URLRoute
*/
public function getDirect(Website $site, PageFrameOptions $pfo): PageFrameOptions
{
@ob_end_clean();
ob_start();
try
{
ob_start();
global $ROUTE;
global $FRAME_OPTIONS;
global $SITE;
$ROUTE = $this;
$FRAME_OPTIONS = $pfo;
$SITE = $site;
global $ROUTE;
global $FRAME_OPTIONS;
global $SITE;
$ROUTE = $this;
$FRAME_OPTIONS = $pfo;
$SITE = $site;
/** @noinspection PhpIncludeInspection */
require $this->targetpath;
/** @noinspection PhpIncludeInspection */
require $this->targetpath;
$FRAME_OPTIONS->raw = ob_get_clean();
$FRAME_OPTIONS->raw = ob_get_contents();
return $FRAME_OPTIONS;
return $FRAME_OPTIONS;
}
finally
{
ob_end_clean();
}
}
/**

View File

@@ -23,25 +23,6 @@ function endsWith($haystack, $needle)
return $length === 0 || (substr($haystack, -$length) === $needle);
}
function httpError($errorcode, $message)
{
ob_clean();
http_response_code($errorcode);
global $OPTIONS;
$OPTIONS = [ 'code' => $errorcode, 'message' => $message ];
require (__DIR__ . '/../pages/errorview.php');
die();
}
function httpDie($errorcode, $message)
{
ob_flush();
http_response_code($errorcode);
die($message);
}
function destructiveUrlEncode($str) {
$str = str_replace(' ', '_', $str);
$str = str_replace('+', '_', $str);
@@ -342,6 +323,7 @@ function formatException($e)
$xdbg = str_replace('<br />', "\n", $xdbg);
$xdbg = str_replace('<br/>', "\n", $xdbg);
$xdbg = str_replace('<br>', "\n", $xdbg);
$xdbg = str_replace('><', "> <", $xdbg);
$xdbg = strip_tags($xdbg);
$xdbg = htmlspecialchars($xdbg);
$r .= $xdbg . "\n";

View File

@@ -3,6 +3,8 @@
require_once 'ruleengine.php';
require_once 'urlroute.php';
require_once 'pageframeoptions.php';
require_once 'modules.php';
require_once 'fragments.php';
require_once 'utils.php';
@@ -17,16 +19,11 @@ class Website
/** @var bool|null */
public $isLoggedIn = null;
/** @var Database|null */ private $database = null;
/** @var AdventOfCode|null */ private $adventOfCode = null;
/** @var Blog|null */ private $blog = null;
/** @var Books|null */ private $books = null;
/** @var Euler|null */ private $euler = null;
/** @var Programs|null */ private $programs = null;
/** @var AlephNoteStatistics|null */ private $anstats = null;
/** @var UpdatesLog|null */ private $updateslog = null;
/** @var WebApps|null */ private $webapps = null;
/** @var MikescherGitGraph|null */ private $extendedgitgraph = null;
/** @var Modules */
public $modules;
/** @var Fragments */
public $fragments;
public function init()
{
@@ -43,6 +40,10 @@ class Website
error_reporting(E_ALL);
}
$this->modules = new Modules($this);
$this->fragments = new Fragments();
self::$instance = $this;
}
catch (exception $e)
@@ -70,16 +71,11 @@ class Website
exit();
}
if ($result->contentType !== null) header('Content-Type: ' . $result->contentType);
http_response_code($result->statuscode);
$this->output($result, $route);
exit();
}
catch (Exception $e)
{
$this->serveServerError(null, formatException($e), null);
$this->serveServerError("Internal Server Error", formatException($e), null);
}
}
@@ -87,8 +83,6 @@ class Website
{
try
{
@ob_end_clean();
$frameOpt->statuscode = 404;
$frameOpt->title = 'Page not found';
@@ -100,23 +94,21 @@ class Website
}
catch (Exception $e)
{
$this->serveServerError(null, formatException($e), null);
$this->serveServerError("Internal Server Error", formatException($e), null);
}
exit();
}
/**
* @param string|null $message
* @param string $message
* @param string|null $debugInfo
* @param PageFrameOptions|null $frameOpt
*/
private function serveServerError($message, $debugInfo, $frameOpt)
private function serveServerError(string $message, $debugInfo, $frameOpt)
{
try
{
@ob_end_clean();
if ($frameOpt === null) $frameOpt = new PageFrameOptions();
$frameOpt->statuscode = 500;
@@ -157,66 +149,6 @@ class Website
require __DIR__ . '/../frames/' . $FRAME_OPTIONS->frame;
}
public function Database()
{
if ($this->database === null) { require_once 'database.php'; $this->database = new Database($this); }
return $this->database;
}
public function AdventOfCode(): AdventOfCode
{
if ($this->adventOfCode === null) { require_once 'adventofcode.php'; $this->adventOfCode = new AdventOfCode(); }
return $this->adventOfCode;
}
public function Blog(): Blog
{
if ($this->blog === null) { require_once 'blog.php'; $this->blog = new Blog(); }
return $this->blog;
}
public function Books(): Books
{
if ($this->books === null) { require_once 'books.php'; $this->books = new Books(); }
return $this->books;
}
public function Euler(): Euler
{
if ($this->euler === null) { require_once 'euler.php'; $this->euler = new Euler(); }
return $this->euler;
}
public function Programs(): Programs
{
if ($this->programs === null) { require_once 'programs.php'; $this->programs = new Programs(); }
return $this->programs;
}
public function AlephNoteStatistics(): AlephNoteStatistics
{
if ($this->anstats === null) { require_once 'alephnoteStatistics.php'; $this->anstats = new AlephNoteStatistics($this); }
return $this->anstats;
}
public function UpdatesLog(): UpdatesLog
{
if ($this->updateslog === null) { require_once 'updateslog.php'; $this->updateslog = new UpdatesLog($this); }
return $this->updateslog;
}
public function WebApps(): WebApps
{
if ($this->webapps === null) { require_once 'webapps.php'; $this->webapps = new WebApps(); }
return $this->webapps;
}
public function ExtendedGitGraph(): MikescherGitGraph
{
if ($this->extendedgitgraph === null) { require_once 'mikeschergitgraph.php'; $this->extendedgitgraph = new MikescherGitGraph($this); }
return $this->extendedgitgraph;
}
/**
* @return bool
*/