From d5783efff7f2339622b22197e5b8e9897cc59796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer=20=28Macbook=29?= Date: Mon, 13 Jan 2020 14:39:35 +0100 Subject: [PATCH 01/33] copy a few files from mvu fork --- www/index.php | 7 +- www/internals/pageframeoptions.php | 26 ++++ www/internals/ruleengine.php | 115 +++++++++++++++++ www/internals/urlroute.php | 122 ++++++++++++++++++ www/internals/{base.php => utils.php} | 16 --- www/internals/website.php | 176 ++++++++++++++++++++++++++ 6 files changed, 445 insertions(+), 17 deletions(-) create mode 100644 www/internals/pageframeoptions.php create mode 100644 www/internals/ruleengine.php create mode 100644 www/internals/urlroute.php rename www/internals/{base.php => utils.php} (97%) create mode 100644 www/internals/website.php diff --git a/www/index.php b/www/index.php index e9c705a..52a72bd 100644 --- a/www/index.php +++ b/www/index.php @@ -1,6 +1,9 @@ init(); $URL_RULES = [ @@ -79,6 +82,8 @@ $URL_RULES = [ 'url' => ['404'], 'target' => 'pages/error_404.php', 'options' => [], ], ]; +$site->serve($URL_RULES); + //############################################################################# try { diff --git a/www/internals/pageframeoptions.php b/www/internals/pageframeoptions.php new file mode 100644 index 0000000..2d35753 --- /dev/null +++ b/www/internals/pageframeoptions.php @@ -0,0 +1,26 @@ +isProd()) + $requri = $_SERVER['REQUEST_URI']; + else + $requri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : 'localhost:80/'; + + $parse = parse_url($requri); + + $path = isset($parse['path']) ? $parse['path'] : ''; + $pathparts = preg_split('@/@', $path, NULL, PREG_SPLIT_NO_EMPTY); + $partcount = count($pathparts); + + foreach ($urlConfig as $rule) + { + $route = self::testRule($app, $rule, $requri, $pathparts, $partcount); + if ($route === null) continue; + + if ($app->getCurrentRights() >= $route->minimal_access_rights) return $route; + + if ($app->isLoggedIn()) return URLRoute::getInsufficentRightsRoute($requri); + + if (!$app->isLoggedIn()) return URLRoute::getLoginRoute($route, $requri); + } + + return URLRoute::getNotFoundRoute($requri); + } + + private static function testRule(Website $app, array $rule, string $requri, array $pathparts, int $partcount) + { + if ($partcount !== count($rule['url'])) return null; + + $urlparams = []; + + $match = true; + for($i = 0; $i < $partcount; $i++) + { + $comp = $rule['url'][$i]; + if (startsWith($comp, '?{') && endsWith($comp, '}')) + { + $ident = substr($comp, 2, strlen($comp)-3); + $urlparams[$ident] = $pathparts[$i]; + } + else if ($comp === '*') + { + if (!isset($urlparams['*'])) $urlparams['*'] = []; + $urlparams['*'] []= $pathparts[$i]; + } + else + { + if (strtolower($comp) !== strtolower($pathparts[$i])) { $match = false; break; } + } + } + if (!$match) return null; + + $route = new URLRoute($rule['target'], $requri); + + foreach($rule['parameter'] as $optname => $optvalue) + { + $value = $optvalue; + + if ($value === '%GET%') + { + if (!isset($_GET[$optname])) { $match = false; break; } + $value = $_GET[$optname]; + } + else if ($value === '%POST%') + { + if (!isset($_POST[$optname])) { $match = false; break; } + $value = $_POST[$optname]; + } + else if ($value === '%URL%') + { + if (!isset($urlparams[$optname])) { $match = false; break; } + $value = urldecode($urlparams[$optname]); + } + + $route->parameter[strtolower($optname)] = $value; + } + if (!$match) return null; + + $ctrlOpt = $rule['options']; + + if (in_array('disabled', $ctrlOpt)) return null; + if (in_array('api', $ctrlOpt)) $route->isAPI = true; + + if (isset($ctrlOpt['method']) && $_SERVER["REQUEST_METHOD"] !== $ctrlOpt['method']) return null; + + $route->minimal_access_rights = (($rule['rights']===null) ? 0 : $rule['rights']); + + if ($app->isProd() && $app->config->app_enforce_https && isHTTPRequest() && !in_array('http', $ctrlOpt)) + { + // enforce https + $redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; + ob_end_clean(); + header('HTTP/1.1 301 Moved Permanently'); + header('Location: ' . $redirect); + exit(); + } + + return $route; + } +} diff --git a/www/internals/urlroute.php b/www/internals/urlroute.php new file mode 100644 index 0000000..671b447 --- /dev/null +++ b/www/internals/urlroute.php @@ -0,0 +1,122 @@ +targetpath = __DIR__ . '/../pages/' . $target; + $this->full_url = $url; + $this->parameter = []; + $this->minimal_access_rights = 0; + $this->isAPI = false; + } + + /** + * @param VApp $app + * @return PageFrameOptions + */ + public function get(Website $app): PageFrameOptions + { + $pfo = new PageFrameOptions(); + + $pfo->title = $app->config->verein_kurzel . " Orga"; // default title + if ($this->isAPI) + { + $pfo->frame = 'no_frame.php'; + $pfo->contentType = 'application/json'; + } + + return $this->getDirect($app, $pfo); + } + + /** + * @param Website $app + * @param PageFrameOptions $pfo + * @return PageFrameOptions + */ + public function getDirect(Website $app, PageFrameOptions $pfo): PageFrameOptions + { + @ob_end_clean(); + ob_start(); + + global $ROUTE; + global $FRAME_OPTIONS; + global $APP; + $ROUTE = $this; + $FRAME_OPTIONS = $pfo; + $APP = $app; + + /** @noinspection PhpIncludeInspection */ + require $this->targetpath; + + $FRAME_OPTIONS->raw = ob_get_clean(); + + return $FRAME_OPTIONS; + } + + /** + * @param string $requri + * @return URLRoute + */ + public static function getInsufficentRightsRoute(string $requri): URLRoute + { + $r = new URLRoute('errors/insufficent_rights.php', $requri); + $r->parameter = []; + $r->minimal_access_rights = 0; + return $r; + } + + /** + * @param URLRoute $route + * @param string $requri + * @return URLRoute + */ + public static function getLoginRoute(URLRoute $route, string $requri): URLRoute + { + $r = new URLRoute('login.php', $requri); + $r->parameter = [ 'redirect' => $route->full_url ]; + $r->minimal_access_rights = 0; + return $r; + } + + /** + * @param string $requri + * @return URLRoute + */ + public static function getNotFoundRoute(string $requri): URLRoute + { + $r = new URLRoute('errors/not_found.php', $requri); + $r->parameter = []; + $r->minimal_access_rights = 0; + return $r; + } + + /** + * @param string $requri + * @return URLRoute + */ + public static function getServerErrorRoute(string $requri): URLRoute + { + $r = new URLRoute('errors/server_error.php', $requri); + $r->parameter = []; + $r->minimal_access_rights = 0; + return $r; + } +} \ No newline at end of file diff --git a/www/internals/base.php b/www/internals/utils.php similarity index 97% rename from www/internals/base.php rename to www/internals/utils.php index 52d2eee..bf8dbd7 100644 --- a/www/internals/base.php +++ b/www/internals/utils.php @@ -11,22 +11,6 @@ global $ADDITIONAL_STYLESHEETS; $ADDITIONAL_SCRIPTS = []; $ADDITIONAL_STYLESHEETS = []; -function InitPHP() { - - set_error_handler("exception_error_handler"); // errors as exceptions for global catch - - ob_start(); // buffer outpt so it can be discarded in httpError - -} - -function exception_error_handler($severity, $message, $file, $line) { - if (!(error_reporting() & $severity)) { - // This error code is not included in error_reporting - return; - } - throw new ErrorException($message, 0, $severity, $file, $line); -} - function startsWith($haystack, $needle) { $length = strlen($needle); diff --git a/www/internals/website.php b/www/internals/website.php new file mode 100644 index 0000000..5955de6 --- /dev/null +++ b/www/internals/website.php @@ -0,0 +1,176 @@ +config = require (__DIR__ . "/config.php"); + } + catch (exception $e) + { + $this->serveServerError("config.php not found", formatException($e), null); + } + + try + { + if (!$this->config['prod']) + { + ini_set('display_errors', 1); + ini_set('display_startup_errors', 1); + error_reporting(E_ALL); + } + + self::$instance = $this; + } + catch (exception $e) + { + $this->serveServerError("Initialization failed", formatException($e), null); + } + } + + public static function getInstance() + { + return self::$instance; + } + + public function serve($rules) + { + try + { + $route = RuleEngine::findRoute($this, $rules); + + $result = $route->get($this); + + if ($result->force_404) + { + $this->serveCustom404($route->full_url, $result); + 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); + } + } + + private function serveCustom404(string $uri, PageFrameOptions $frameOpt) + { + try + { + @ob_end_clean(); + + $frameOpt->statuscode = 404; + $frameOpt->title = 'Page not found'; + + $route = URLRoute::getNotFoundRoute($uri); + + $result = $route->getDirect($this, $frameOpt); + + $this->output($result, $route); + } + catch (Exception $e) + { + $this->serveServerError(null, formatException($e), null); + } + + exit(); + } + + /** + * @param string|null $message + * @param string|null $debugInfo + * @param PageFrameOptions|null $frameOpt + */ + private function serveServerError($message, $debugInfo, $frameOpt) + { + try + { + @ob_end_clean(); + + if ($frameOpt === null) $frameOpt = new PageFrameOptions(); + + $frameOpt->statuscode = 500; + $frameOpt->title = 'Internal Server Error'; + $frameOpt->frame = 'error_frame.php'; + + $route = URLRoute::getServerErrorRoute($_SERVER['REQUEST_URI']); + + $route->parameter['message'] = $message; + $route->parameter['debuginfo'] = $debugInfo; + + $result = $route->getDirect($this, $frameOpt); + + $this->output($result, $route); + } + catch (Exception $e) + { + http_response_code(500); + die('Internal Server Error'); + } + + exit(); + } + + /** + * @param PageFrameOptions $pfo + * @param URLRoute $route + */ + private function output(PageFrameOptions $pfo, URLRoute $route) + { + if ($pfo->contentType !== null) header('Content-Type: ' . $pfo->contentType); + http_response_code($pfo->statuscode); + + global $ROUTE; + global $FRAME_OPTIONS; + global $APP; + $ROUTE = $route; + $FRAME_OPTIONS = $pfo; + $APP = $this; + + /** @noinspection PhpIncludeInspection */ + require __DIR__ . '/../pages/frame/' . $FRAME_OPTIONS->frame; + } + + /** + * @return bool + */ + public function isProd() + { + if ($this->config == null) return true; + return $this->config['prod']; + } +} + +/** + * @param $severity + * @param $message + * @param $file + * @param $line + * @throws ErrorException + */ +function exception_error_handler($severity, $message, $file, $line) { + // This error code is not included in error_reporting + if (!(error_reporting() & $severity)) return; + throw new ErrorException($message, 0, $severity, $file, $line); +} \ No newline at end of file From ea1aae60c38ae00292418bd91e3e13b7342c9e3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Tue, 14 Jan 2020 22:25:43 +0100 Subject: [PATCH 02/33] RuleEngine + Frame --- www/fragments/footer.php | 4 - www/fragments/header.php | 19 -- www/frames/default_frame.php | 52 ++++ www/index.php | 259 +++++------------- www/internals/alephnoteStatistics.php | 2 +- www/internals/books.php | 2 +- www/internals/database.php | 2 +- www/internals/euler.php | 2 +- www/internals/highscores.php | 2 +- www/internals/mikeschergitgraph.php | 2 +- www/internals/pageframeoptions.php | 2 +- www/internals/parsedowncustom.php | 109 ++++++++ www/internals/programs.php | 2 +- www/internals/ruleengine.php | 13 +- www/internals/updateslog.php | 2 +- www/internals/urlroute.php | 27 +- www/internals/utils.php | 34 ++- www/internals/website.php | 18 +- .../{errorview.php => error_notfound.php} | 0 www/pages/error_servererror.php | 34 +++ 20 files changed, 327 insertions(+), 260 deletions(-) delete mode 100644 www/fragments/footer.php delete mode 100644 www/fragments/header.php create mode 100644 www/frames/default_frame.php create mode 100644 www/internals/parsedowncustom.php rename www/pages/{errorview.php => error_notfound.php} (100%) create mode 100644 www/pages/error_servererror.php diff --git a/www/fragments/footer.php b/www/fragments/footer.php deleted file mode 100644 index 060bca4..0000000 --- a/www/fragments/footer.php +++ /dev/null @@ -1,4 +0,0 @@ -
-
- made with vanilla PHP and MySQL, no frameworks, no bootstrap, no unnecessary* javascript -
\ No newline at end of file diff --git a/www/fragments/header.php b/www/fragments/header.php deleted file mode 100644 index 98c7909..0000000 --- a/www/fragments/header.php +++ /dev/null @@ -1,19 +0,0 @@ -
-
- -
- - - -
\ No newline at end of file diff --git a/www/frames/default_frame.php b/www/frames/default_frame.php new file mode 100644 index 0000000..36045c4 --- /dev/null +++ b/www/frames/default_frame.php @@ -0,0 +1,52 @@ + + + + + + + + <?php echo $FRAME_OPTIONS->title; ?> + + + + + +
+ +
+
+ +
+ +
+ Home + Project Euler + Blog + Programs + Tools + isLoggedInByCookie()): ?>Admin + About +
+ isLoggedInByCookie()): ?> + Github +
+ +
+ + raw; ?> + +
+
+ made with vanilla PHP and MySQL, no frameworks, no bootstrap, no unnecessary* javascript +
+ +
+ + \ No newline at end of file diff --git a/www/index.php b/www/index.php index 52a72bd..82677f3 100644 --- a/www/index.php +++ b/www/index.php @@ -7,212 +7,81 @@ $site->init(); $URL_RULES = [ - [ 'url' => [], 'target' => 'pages/main.php', 'options' => [], ], - [ 'url' => ['index'], 'target' => 'pages/main.php', 'options' => [], ], - [ 'url' => ['index.php'], 'target' => 'pages/main.php', 'options' => [], ], - [ 'url' => ['msmain', 'index'], 'target' => 'pages/main.php', 'options' => [], ], - [ 'url' => ['about'], 'target' => 'pages/about.php', 'options' => [], ], - [ 'url' => ['msmain', 'about'], 'target' => 'pages/about.php', 'options' => [], ], - [ 'url' => ['login'], 'target' => 'pages/login.php', 'options' => [ 'login_target' => '/' ], ], - [ 'url' => ['logout'], 'target' => 'pages/logout.php', 'options' => [ 'logout_target' => '/' ], ], + [ 'url' => [], 'target' => 'main.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['index'], 'target' => 'main.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['index.php'], 'target' => 'main.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['msmain', 'index'], 'target' => 'main.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['about'], 'target' => 'about.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['msmain', 'about'], 'target' => 'about.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['login'], 'target' => 'login.php', 'options' => [ 'http' ], 'parameter' => [ 'login_target' => '/' ], ], + [ 'url' => ['logout'], 'target' => 'logout.php', 'options' => [ 'http' ], 'parameter' => [ 'logout_target' => '/' ], ], - [ 'url' => ['programs'], 'target' => 'pages/programs_list.php', 'options' => [ 'categoryfilter' => '' ], ], - [ 'url' => ['programs', 'index'], 'target' => 'pages/programs_list.php', 'options' => [ 'categoryfilter' => '%GET%' ], ], - [ 'url' => ['programs', 'index'], 'target' => 'pages/programs_list.php', 'options' => [ 'categoryfilter' => '' ], ], - [ 'url' => ['programs', 'cat', '?{categoryfilter}'], 'target' => 'pages/programs_list.php', 'options' => [ 'categoryfilter' => '%URL%' ], ], - [ 'url' => ['downloads', 'details.php'], 'target' => 'pages/programs_list.php', 'options' => [ 'categoryfilter' => '' ], ], - [ 'url' => ['downloads', 'downloads.php'], 'target' => 'pages/programs_list.php', 'options' => [ 'categoryfilter' => '' ], ], - [ 'url' => ['programs', 'view', '?{id}'], 'target' => 'pages/programs_view.php', 'options' => [ 'id' => '%URL%' ], ], - [ 'url' => ['programs', 'view'], 'target' => 'pages/programs_view.php', 'options' => [ 'id' => '%GET%' ], ], - [ 'url' => ['downloads', '?{id}'], 'target' => 'pages/programs_download.php', 'options' => [ 'id' => '%URL%' ], ], - [ 'url' => ['programs', 'download', '?{id}'], 'target' => 'pages/programs_download.php', 'options' => [ 'id' => '%URL%' ], ], - [ 'url' => ['programs', 'download'], 'target' => 'pages/programs_download.php', 'options' => [ 'id' => '%GET%' ], ], + [ 'url' => ['programs'], 'target' => 'programs_list.php', 'options' => [ 'http' ], 'parameter' => [ 'categoryfilter' => '' ], ], + [ 'url' => ['programs', 'index'], 'target' => 'programs_list.php', 'options' => [ 'http' ], 'parameter' => [ 'categoryfilter' => '%GET%' ], ], + [ 'url' => ['programs', 'index'], 'target' => 'programs_list.php', 'options' => [ 'http' ], 'parameter' => [ 'categoryfilter' => '' ], ], + [ 'url' => ['programs', 'cat', '?{categoryfilter}'], 'target' => 'programs_list.php', 'options' => [ 'http' ], 'parameter' => [ 'categoryfilter' => '%URL%' ], ], + [ 'url' => ['downloads', 'details.php'], 'target' => 'programs_list.php', 'options' => [ 'http' ], 'parameter' => [ 'categoryfilter' => '' ], ], + [ 'url' => ['downloads', 'downloads.php'], 'target' => 'programs_list.php', 'options' => [ 'http' ], 'parameter' => [ 'categoryfilter' => '' ], ], + [ 'url' => ['programs', 'view', '?{id}'], 'target' => 'programs_view.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%URL%' ], ], + [ 'url' => ['programs', 'view'], 'target' => 'programs_view.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%GET%' ], ], + [ 'url' => ['downloads', '?{id}'], 'target' => 'programs_download.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%URL%' ], ], + [ 'url' => ['programs', 'download', '?{id}'], 'target' => 'programs_download.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%URL%' ], ], + [ 'url' => ['programs', 'download'], 'target' => 'programs_download.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%GET%' ], ], - [ 'url' => ['books'], 'target' => 'pages/books_list.php', 'options' => [], ], - [ 'url' => ['books', 'list'], 'target' => 'pages/books_list.php', 'options' => [], ], - [ 'url' => ['books', 'view', '?{id}'], 'target' => 'pages/books_view.php', 'options' => [ 'id' => '%GET%' ], ], - [ 'url' => ['books', 'view', '?{id}', '*'], 'target' => 'pages/books_view.php', 'options' => [ 'id' => '%URL%' ], ], + [ 'url' => ['books'], 'target' => 'books_list.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['books', 'list'], 'target' => 'books_list.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['books', 'view', '?{id}'], 'target' => 'books_view.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%GET%' ], ], + [ 'url' => ['books', 'view', '?{id}', '*'], 'target' => 'books_view.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%URL%' ], ], - [ 'url' => ['update.php'], 'target' => 'pages/api.php', 'options' => [ '_opt' => 'http', 'cmd' => 'progs::updatecheck' ], ], - [ 'url' => ['update.php', '?{Name}'], 'target' => 'pages/api.php', 'options' => [ '_opt' => 'http', 'cmd' => 'progs::updatecheck' ], ], - [ 'url' => ['update'], 'target' => 'pages/api.php', 'options' => [ '_opt' => 'http', 'cmd' => 'progs::updatecheck' ], ], - [ 'url' => ['update', '?{Name}'], 'target' => 'pages/api.php', 'options' => [ '_opt' => 'http', 'cmd' => 'progs::updatecheck' ], ], - [ 'url' => ['update2'], 'target' => 'pages/api.php', 'options' => [ '_opt' => 'http', 'cmd' => 'progs::updatecheck' ], ], - [ 'url' => ['api', 'update'], 'target' => 'pages/api.php', 'options' => [ '_opt' => 'http', 'cmd' => 'progs::updatecheck' ], ], - [ 'url' => ['api', 'update', '?{Name}'], 'target' => 'pages/api.php', 'options' => [ '_opt' => 'http', 'cmd' => 'progs::updatecheck' ], ], - [ 'url' => ['api', 'test'], 'target' => 'pages/api.php', 'options' => [ '_opt' => 'http', 'cmd' => 'base::test' ], ], - [ 'url' => ['api', 'setselfadress'], 'target' => 'pages/api.php', 'options' => [ '_opt' => 'http', 'cmd' => 'server::setselfaddress' ], ], - [ 'url' => ['api', 'statsping'], 'target' => 'pages/api.php', 'options' => [ '_opt' => 'http', 'cmd' => 'alephnote::statsping' ], ], - [ 'url' => ['api', 'webhook', '?{target}'], 'target' => 'pages/api.php', 'options' => [ '_opt' => 'http', 'cmd' => 'server::gitwebhook' ], ], - [ 'url' => ['api', 'backupupload'], 'target' => 'pages/api.php', 'options' => [ '_opt' => 'http', 'cmd' => 'server::backupupload' ], ], - [ 'url' => ['api', '?{cmd}'], 'target' => 'pages/api.php', 'options' => [ 'cmd' => '%URL%' ], ], + [ 'url' => ['update.php'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], + [ 'url' => ['update.php', '?{Name}'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], + [ 'url' => ['update'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], + [ 'url' => ['update', '?{Name}'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], + [ 'url' => ['update2'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], + [ 'url' => ['api', 'update'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], + [ 'url' => ['api', 'update', '?{Name}'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], + [ 'url' => ['api', 'test'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'base::test' ], ], + [ 'url' => ['api', 'setselfadress'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'server::setselfaddress' ], ], + [ 'url' => ['api', 'statsping'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'alephnote::statsping' ], ], + [ 'url' => ['api', 'webhook', '?{target}'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'server::gitwebhook' ], ], + [ 'url' => ['api', 'backupupload'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'server::backupupload' ], ], + [ 'url' => ['api', '?{cmd}'], 'target' => 'api.php', 'options' => [ ], 'parameter' => [ 'cmd' => '%URL%' ], ], - [ 'url' => ['admin'], 'target' => 'pages/admin.php', 'options' => [ '_opt' => 'password'], ], + [ 'url' => ['admin'], 'target' => 'admin.php', 'options' => [ 'password' ], 'parameter' => [ ] ], - [ 'url' => ['blog'], 'target' => 'pages/blog_list.php', 'options' => [], ], - [ 'url' => ['log'], 'target' => 'pages/blog_list.php', 'options' => [], ], - [ 'url' => ['blogpost', 'index'], 'target' => 'pages/blog_list.php', 'options' => [], ], - [ 'url' => ['blog', '?{id}'], 'target' => 'pages/blog_view.php', 'options' => [ 'id' => '%URL%', 'subview' => '' ], ], - [ 'url' => ['blog', '?{id}'], 'target' => 'pages/blog_view.php', 'options' => [ 'id' => '%URL%', 'subview' => '' ], ], - [ 'url' => ['blog', '?{id}', '?{name}'], 'target' => 'pages/blog_view.php', 'options' => [ 'id' => '%URL%', 'subview' => '' ], ], - [ 'url' => ['blog', '?{id}', '?{name}', '?{subview}'], 'target' => 'pages/blog_view.php', 'options' => [ 'id' => '%URL%', 'subview' => '%URL%' ], ], - [ 'url' => ['log', '?{id}'], 'target' => 'pages/blog_view.php', 'options' => [ 'id' => '%URL%', 'subview' => '' ], ], - [ 'url' => ['log', '?{id}'], 'target' => 'pages/blog_view.php', 'options' => [ 'id' => '%URL%', 'subview' => '' ], ], - [ 'url' => ['log', '?{id}', '?{name}'], 'target' => 'pages/blog_view.php', 'options' => [ 'id' => '%URL%', 'subview' => '' ], ], - [ 'url' => ['log', '?{id}', '?{name}', '?{subview}'], 'target' => 'pages/blog_view.php', 'options' => [ 'id' => '%URL%', 'subview' => '%URL%' ], ], - [ 'url' => ['blogpost', 'view'], 'target' => 'pages/blog_view.php', 'options' => [ 'id' => '%GET%', 'subview' => '' ], ], + [ 'url' => ['blog'], 'target' => 'blog_list.php', 'options' => [ ], 'parameter' => [ ], ], + [ 'url' => ['log'], 'target' => 'blog_list.php', 'options' => [ ], 'parameter' => [ ], ], + [ 'url' => ['blogpost', 'index'], 'target' => 'blog_list.php', 'options' => [ ], 'parameter' => [ ], ], + [ 'url' => ['blog', '?{id}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ], + [ 'url' => ['blog', '?{id}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ], + [ 'url' => ['blog', '?{id}', '?{name}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ], + [ 'url' => ['blog', '?{id}', '?{name}', '?{subview}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '%URL%' ], ], + [ 'url' => ['log', '?{id}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ], + [ 'url' => ['log', '?{id}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ], + [ 'url' => ['log', '?{id}', '?{name}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ], + [ 'url' => ['log', '?{id}', '?{name}', '?{subview}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '%URL%' ], ], + [ 'url' => ['blogpost', 'view'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%GET%', 'subview' => '' ], ], - [ 'url' => ['webapps'], 'target' => 'pages/webapps_list.php', 'options' => [], ], + [ 'url' => ['webapps'], 'target' => 'webapps_list.php', 'options' => [ ], 'parameter' => [ ], ], - [ 'url' => ['highscores', 'list.php'], 'target' => 'pages/highscores_listentries.php', 'options' => [ '_opt' => 'http', 'gameid' => '%GET%' ], ], - [ 'url' => ['highscores', 'list'], 'target' => 'pages/highscores_listentries.php', 'options' => [ '_opt' => 'http', 'gameid' => '%GET%' ], ], - [ 'url' => ['highscores', 'listentries'], 'target' => 'pages/highscores_listentries.php', 'options' => [ '_opt' => 'http', 'gameid' => '%GET%' ], ], - [ 'url' => ['highscores', 'list.php'], 'target' => 'pages/highscores_listgames.php', 'options' => [ '_opt' => 'http' ], ], - [ 'url' => ['highscores', 'list'], 'target' => 'pages/highscores_listgames.php', 'options' => [ '_opt' => 'http' ], ], - [ 'url' => ['highscores', 'listgames'], 'target' => 'pages/highscores_listgames.php', 'options' => [ '_opt' => 'http' ], ], - [ 'url' => ['highscores', 'insert.php'], 'target' => 'pages/highscores_insert.php', 'options' => [ '_opt' => 'http', 'gameid' => '%GET%', 'check' => '%GET%', 'name' => '%GET%', 'rand' => '%GET%', 'points' => '%GET%' ], ], - [ 'url' => ['highscores', 'insert'], 'target' => 'pages/highscores_insert.php', 'options' => [ '_opt' => 'http', 'gameid' => '%GET%', 'check' => '%GET%', 'name' => '%GET%', 'rand' => '%GET%', 'points' => '%GET%' ], ], - [ 'url' => ['highscores', 'update.php'], 'target' => 'pages/highscores_update.php', 'options' => [ '_opt' => 'http', 'gameid' => '%GET%', 'check' => '%GET%', 'name' => '%GET%', 'rand' => '%GET%', 'points' => '%GET%', 'nameid' => '%GET%' ], ], - [ 'url' => ['highscores', 'update'], 'target' => 'pages/highscores_update.php', 'options' => [ '_opt' => 'http', 'gameid' => '%GET%', 'check' => '%GET%', 'name' => '%GET%', 'rand' => '%GET%', 'points' => '%GET%', 'nameid' => '%GET%' ], ], - [ 'url' => ['highscores', 'list_top50.php'], 'target' => 'pages/highscores_top50.php', 'options' => [ '_opt' => 'http', 'gameid' => '%GET%' ], ], - [ 'url' => ['highscores', 'list_top50'], 'target' => 'pages/highscores_top50.php', 'options' => [ '_opt' => 'http', 'gameid' => '%GET%' ], ], - [ 'url' => ['highscores', 'getNewID.php'], 'target' => 'pages/highscores_newid.php', 'options' => [ '_opt' => 'http', 'gameid' => '%GET%' ], ], - [ 'url' => ['highscores', 'newid'], 'target' => 'pages/highscores_newid.php', 'options' => [ '_opt' => 'http', 'gameid' => '%GET%' ], ], - - [ 'url' => ['404'], 'target' => 'pages/error_404.php', 'options' => [], ], + [ 'url' => ['highscores', 'list.php'], 'target' => 'highscores_listentries.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], + [ 'url' => ['highscores', 'list'], 'target' => 'highscores_listentries.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], + [ 'url' => ['highscores', 'listentries'], 'target' => 'highscores_listentries.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], + [ 'url' => ['highscores', 'list.php'], 'target' => 'highscores_listgames.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['highscores', 'list'], 'target' => 'highscores_listgames.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['highscores', 'listgames'], 'target' => 'highscores_listgames.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['highscores', 'insert.php'], 'target' => 'highscores_insert.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%', 'check' => '%GET%', 'name' => '%GET%', 'rand' => '%GET%', 'points' => '%GET%' ], ], + [ 'url' => ['highscores', 'insert'], 'target' => 'highscores_insert.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%', 'check' => '%GET%', 'name' => '%GET%', 'rand' => '%GET%', 'points' => '%GET%' ], ], + [ 'url' => ['highscores', 'update.php'], 'target' => 'highscores_update.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%', 'check' => '%GET%', 'name' => '%GET%', 'rand' => '%GET%', 'points' => '%GET%', 'nameid' => '%GET%' ], ], + [ 'url' => ['highscores', 'update'], 'target' => 'highscores_update.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%', 'check' => '%GET%', 'name' => '%GET%', 'rand' => '%GET%', 'points' => '%GET%', 'nameid' => '%GET%' ], ], + [ 'url' => ['highscores', 'list_top50.php'], 'target' => 'highscores_top50.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], + [ 'url' => ['highscores', 'list_top50'], 'target' => 'highscores_top50.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], + [ 'url' => ['highscores', 'getNewID.php'], 'target' => 'highscores_newid.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], + [ 'url' => ['highscores', 'newid'], 'target' => 'highscores_newid.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], ]; $site->serve($URL_RULES); -//############################################################################# - -try { - InitPHP(); - - if (isProd()) - $requri = $_SERVER['REQUEST_URI']; - else - $requri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : 'localhost:80/'; - - $parse = parse_url($requri); - - $path = isset($parse['path']) ? $parse['path'] : ''; - $pathparts = preg_split('@/@', $path, NULL, PREG_SPLIT_NO_EMPTY); - $partcount = count($pathparts); - - global $OPTIONS; - global $HEADER_ACTIVE; - - $HEADER_ACTIVE = 'none'; - - foreach ($URL_RULES as $rule) - { - if ($partcount !== count($rule['url'])) continue; - - $urlparams = []; - $ctrlOpt = key_exists('_opt', $rule['options']) ? explode('|', $rule['options']['_opt']) : []; - $target = $rule['target']; - - $match = true; - for($i = 0; $i < $partcount; $i++) - { - $comp = $rule['url'][$i]; - if (startsWith($comp, '?{') && endsWith($comp, '}')) - { - $ident = substr($comp, 2, strlen($comp)-3); - $urlparams[$ident] = $pathparts[$i]; - } - else if ($comp === '*') - { - // ok - } - else - { - if (strtolower($comp) !== strtolower($pathparts[$i])) { $match = false; break; } - } - } - if (!$match) continue; - - $opt = [ 'controllerOptions' => $ctrlOpt, 'uri' => $requri ]; - foreach($rule['options'] as $optname => $optvalue) - { - $value = $optvalue; - - if ($value === '%GET%') - { - if (!isset($_GET[$optname])) { $match = false; break; } - $value = $_GET[$optname]; - } - else if ($value === '%POST%') - { - if (!isset($_POST[$optname])) { $match = false; break; } - $value = $_POST[$optname]; - } - else if ($value === '%URL%') - { - if (!isset($urlparams[$optname])) { $match = false; break; } - $value = urldecode($urlparams[$optname]); - } - - $opt[strtolower($optname)] = $value; - } - - $opt['_urlparams'] = []; - foreach ($urlparams as $name => $value) $opt['_urlparams'][strtolower($name)] = urldecode($value); - - if (!$match) continue; - - if (in_array('disabled', $ctrlOpt)) continue; - - if (in_array('password', $ctrlOpt)) - { - if (!isLoggedInByCookie()) - { - $opt['login_target'] = $path; - $target = 'pages/login.php'; - } - } - - $is_http = (!isset($_SERVER['HTTPS'])) || empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "off"; - - if (isProd() && $is_http && !in_array('http', $ctrlOpt)) - { - ob_clean(); - $redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; - header('HTTP/1.1 301 Moved Permanently'); - header('Location: ' . $redirect); - exit(); - } - - $OPTIONS = $opt; - - /** @noinspection PhpIncludeInspection */ - include $target; - return; - - } - - { - // [404] - Page Not Found - $OPTIONS = []; - httpError('404', 'Page not found'); - return; - } - -} catch (Exception $e) { - - if (isProd()) - { - sendExceptionMail($e); - httpError('500 ', 'Internal server error'); - } - else - { - if (isset($e->xdebug_message)) echo ''.$e->xdebug_message.'
'; - else echo nl2br($e); - } - -} //TODO euler insert+show 32bit | 64bit mode //TODO support for different color schemes diff --git a/www/internals/alephnoteStatistics.php b/www/internals/alephnoteStatistics.php index 7fb6749..fcf838c 100644 --- a/www/internals/alephnoteStatistics.php +++ b/www/internals/alephnoteStatistics.php @@ -1,4 +1,4 @@ -{$Element['handler']}($Element['text']); + else + return parent::element($Element); + } + + protected function blockFencedCode($Line) + { + $Block = parent::blockFencedCode($Line); + if ($Block === null) return $Block; + + $Block['custom'] = false; + + if (isset($Block['element']['text']['attributes'])) + { + foreach ($Block['element']['text']['attributes'] as $attr) + { + $spl = explode('__', $attr); + + if ($spl[0] === 'language-befungerunner') + { + $Block['element']['handler'] = 'handleBef93'; + $Block['custom'] = true; + $Block['element']['text']['b93_speed'] = null; + $Block['element']['text']['b93_interactive'] = true; + $Block['element']['text']['b93_editable'] = true; + + foreach ($spl as $param) + { + if (startsWith($param, 'speed-')) $Block['element']['text']['b93_speed'] = intval( substr($param, strlen('speed-'))); + if (startsWith($param, 'interactive-')) $Block['element']['text']['b93_interactive'] = boolval(substr($param, strlen('interactive-'))); + if (startsWith($param, 'editable-')) $Block['element']['text']['b93_editable'] = boolval(substr($param, strlen('editable-'))); + } + + return $Block; + } + else if ($spl[0] === 'language-bfjoustrunner') + { + $Block['element']['handler'] = 'handleBFJoust'; + $Block['custom'] = true; + return $Block; + } + } + } + + return $Block; + } + + protected function blockFencedCodeComplete($Block) + { + if (! $Block['custom']) { return parent::blockFencedCodeComplete($Block); } + + $Block['element']['custom'] = true; + + return $Block; + } + + protected function handleBFJoust(array $Element) + { + global $PARAM_CODE_LEFT; + global $PARAM_CODE_RIGHT; + + $split = preg_split("/\-{16,}/", $Element['text']); + + $PARAM_CODE_LEFT = trim($split[0]); + $PARAM_CODE_RIGHT = trim($split[1]); + + return require (__DIR__ . '/../fragments/widget_bfjoust.php'); + } + + protected function handleBef93(array $Element) + { + global $PARAM_BEFUNGE93RUNNER; + $PARAM_BEFUNGE93RUNNER = + [ + 'code' => $Element['text'], + 'url' => '', + 'interactive' => $Element['b93_interactive'], + 'speed' => $Element['b93_speed'], + 'editable' => $Element['b93_editable'], + ]; + return require (__DIR__ . '/../fragments/widget_befunge93.php'); + } + + protected function blockTable($Line, array $Block = null) + { + // https://stackoverflow.com/a/46346412/1761622 + + $Block = parent::blockTable($Line, $Block); + + if ($Block === null) return $Block; + if (!key_exists('element', $Block)) return $Block; + + $Block['element']['attributes']['class'] = 'stripedtable'; + + return $Block; + } +} \ No newline at end of file diff --git a/www/internals/programs.php b/www/internals/programs.php index e892bed..a8fbe55 100644 --- a/www/internals/programs.php +++ b/www/internals/programs.php @@ -1,4 +1,4 @@ -getCurrentRights() >= $route->minimal_access_rights) return $route; - - if ($app->isLoggedIn()) return URLRoute::getInsufficentRightsRoute($requri); - - if (!$app->isLoggedIn()) return URLRoute::getLoginRoute($route, $requri); + if ($route->needsAdminLogin && !$app->isLoggedIn()) return URLRoute::getLoginRoute($route, $requri); } return URLRoute::getNotFoundRoute($requri); @@ -98,9 +93,9 @@ class RuleEngine if (isset($ctrlOpt['method']) && $_SERVER["REQUEST_METHOD"] !== $ctrlOpt['method']) return null; - $route->minimal_access_rights = (($rule['rights']===null) ? 0 : $rule['rights']); + $route->needsAdminLogin = isset($ctrlOpt['password']); - if ($app->isProd() && $app->config->app_enforce_https && isHTTPRequest() && !in_array('http', $ctrlOpt)) + if ($app->isProd() && isHTTPRequest() && !in_array('http', $ctrlOpt)) { // enforce https $redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; diff --git a/www/internals/updateslog.php b/www/internals/updateslog.php index 184068b..dc40512 100644 --- a/www/internals/updateslog.php +++ b/www/internals/updateslog.php @@ -1,4 +1,4 @@ -targetpath = __DIR__ . '/../pages/' . $target; $this->full_url = $url; $this->parameter = []; - $this->minimal_access_rights = 0; + $this->needsAdminLogin = false; $this->isAPI = false; } /** - * @param VApp $app + * @param Website $app * @return PageFrameOptions */ public function get(Website $app): PageFrameOptions { $pfo = new PageFrameOptions(); - $pfo->title = $app->config->verein_kurzel . " Orga"; // default title + $pfo->title = 'Mikescher.com'; // default title if ($this->isAPI) { $pfo->frame = 'no_frame.php'; @@ -71,18 +71,6 @@ class URLRoute return $FRAME_OPTIONS; } - /** - * @param string $requri - * @return URLRoute - */ - public static function getInsufficentRightsRoute(string $requri): URLRoute - { - $r = new URLRoute('errors/insufficent_rights.php', $requri); - $r->parameter = []; - $r->minimal_access_rights = 0; - return $r; - } - /** * @param URLRoute $route * @param string $requri @@ -92,7 +80,6 @@ class URLRoute { $r = new URLRoute('login.php', $requri); $r->parameter = [ 'redirect' => $route->full_url ]; - $r->minimal_access_rights = 0; return $r; } @@ -104,7 +91,6 @@ class URLRoute { $r = new URLRoute('errors/not_found.php', $requri); $r->parameter = []; - $r->minimal_access_rights = 0; return $r; } @@ -116,7 +102,6 @@ class URLRoute { $r = new URLRoute('errors/server_error.php', $requri); $r->parameter = []; - $r->minimal_access_rights = 0; return $r; } } \ No newline at end of file diff --git a/www/internals/utils.php b/www/internals/utils.php index bf8dbd7..13cf5ae 100644 --- a/www/internals/utils.php +++ b/www/internals/utils.php @@ -1,4 +1,4 @@ -getMessage() . "\n\n"; + $r .= $e->getFile() . "\n\n"; + $r .= $e->getTraceAsString() . "\n\n"; + if (isset($e->xdebug_message)) + { + $xdbg = $e->xdebug_message; + $xdbg = str_replace('
', "\n", $xdbg); + $xdbg = str_replace('
', "\n", $xdbg); + $xdbg = str_replace('
', "\n", $xdbg); + $xdbg = strip_tags($xdbg); + $xdbg = htmlspecialchars($xdbg); + $r .= $xdbg . "\n"; + } + return $r; + } + + return 'object'; } \ No newline at end of file diff --git a/www/internals/website.php b/www/internals/website.php index 5955de6..972bf29 100644 --- a/www/internals/website.php +++ b/www/internals/website.php @@ -1,9 +1,25 @@ - + + + + + Mikescher.com - <?php echo $errormsg; ?> + + + + +
+ + + +
+ +
+
+
+
+ +
+ +
+ + + + \ No newline at end of file From 020515c4af19eafe2d2ccd7ce8f1172eb45ae6c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Wed, 15 Jan 2020 00:01:20 +0100 Subject: [PATCH 03/33] database --- www/internals/database.php | 67 ++++++++++++++------------------------ www/internals/website.php | 26 ++++++++------- 2 files changed, 39 insertions(+), 54 deletions(-) diff --git a/www/internals/database.php b/www/internals/database.php index 159d05d..dc607c7 100644 --- a/www/internals/database.php +++ b/www/internals/database.php @@ -1,46 +1,35 @@ config['host'] . ";dbname=" . $site->config['database'] . ";charset=utf8"; + $opt = + [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false, ]; - self::$PDO = new PDO($dsn, $CONFIG['user'], $CONFIG['password'], $opt); + $this->pdo = new PDO($dsn, $site->config['user'], $site->config['password'], $opt); } - public static function tryconnect() + public function sql_query_num($query) { - try { - self::connect(); - return true; - } catch (exception $e) { - return false; - } - } - - public static function sql_query_num($query) - { - $r = self::$PDO->query($query)->fetch(PDO::FETCH_NUM)[0]; + $r = $this->pdo->query($query)->fetch(PDO::FETCH_NUM)[0]; return $r; } - public static function sql_query_num_prep($query, $params) + public function sql_query_num_prep($query, $params) { - $stmt = self::$PDO->prepare($query); + $stmt = $this->pdo->prepare($query); foreach ($params as $p) { @@ -53,16 +42,16 @@ class Database return $r; } - public static function sql_query_assoc($query) + public function sql_query_assoc($query) { - $r = self::$PDO->query($query)->fetchAll(PDO::FETCH_ASSOC); + $r = $this->pdo->query($query)->fetchAll(PDO::FETCH_ASSOC); return $r; } - public static function sql_query_assoc_prep($query, $params) + public function sql_query_assoc_prep($query, $params) { - $stmt = self::$PDO->prepare($query); + $stmt = $this->pdo->prepare($query); foreach ($params as $p) { @@ -70,21 +59,17 @@ class Database } $stmt->execute(); - $r = $stmt->fetchAll(PDO::FETCH_ASSOC); - - return $r; + return $stmt->fetchAll(PDO::FETCH_ASSOC); } - public static function sql_query_single($query) + public function sql_query_single($query) { - $r = self::$PDO->query($query)->fetch(PDO::FETCH_ASSOC); - - return $r; + return $this->pdo->query($query)->fetch(PDO::FETCH_ASSOC); } - public static function sql_query_single_prep($query, $params) + public function sql_query_single_prep($query, $params) { - $stmt = self::$PDO->prepare($query); + $stmt = $this->pdo->prepare($query); foreach ($params as $p) { @@ -92,14 +77,12 @@ class Database } $stmt->execute(); - $r = $stmt->fetch(PDO::FETCH_ASSOC); - - return $r; + return $stmt->fetch(PDO::FETCH_ASSOC); } - public static function sql_exec_prep($query, $params) + public function sql_exec_prep($query, $params) { - $stmt = self::$PDO->prepare($query); + $stmt = $this->pdo->prepare($query); foreach ($params as $p) { diff --git a/www/internals/website.php b/www/internals/website.php index 972bf29..125821b 100644 --- a/www/internals/website.php +++ b/www/internals/website.php @@ -6,17 +6,6 @@ require_once 'pageframeoptions.php'; require_once 'utils.php'; -require_once 'database.php'; -require_once 'adventofcode.php'; -require_once 'alephnoteStatistics.php'; -require_once 'blog.php'; -require_once 'books.php'; -require_once 'euler.php'; -require_once 'highscores.php'; -require_once 'programs.php'; -require_once 'updateslog.php'; -require_once 'webapp.php'; - require_once 'mikeschergitgraph.php'; require_once 'parsedowncustom.php'; @@ -26,7 +15,10 @@ class Website private static $instance; /** @var array */ - private $config; + public $config; + + /** @var Database|null */ + private $database = null; public function init() { @@ -168,6 +160,16 @@ class Website require __DIR__ . '/../pages/frame/' . $FRAME_OPTIONS->frame; } + public function database() + { + if ($this->database === null) + { + require_once 'database.php'; + $this->database = new Database($this); + } + return $this->database; + } + /** * @return bool */ From 2b450bdef10eba842a1b88b86e1c2faa7c925757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Wed, 15 Jan 2020 00:04:40 +0100 Subject: [PATCH 04/33] AdventOfCode --- www/internals/ParsedownCustom.php | 109 ------------------------------ www/internals/adventofcode.php | 65 ++++++++++-------- 2 files changed, 37 insertions(+), 137 deletions(-) delete mode 100644 www/internals/ParsedownCustom.php diff --git a/www/internals/ParsedownCustom.php b/www/internals/ParsedownCustom.php deleted file mode 100644 index e6304d7..0000000 --- a/www/internals/ParsedownCustom.php +++ /dev/null @@ -1,109 +0,0 @@ -{$Element['handler']}($Element['text']); - else - return parent::element($Element); - } - - protected function blockFencedCode($Line) - { - $Block = parent::blockFencedCode($Line); - if ($Block === null) return $Block; - - $Block['custom'] = false; - - if (isset($Block['element']['text']['attributes'])) - { - foreach ($Block['element']['text']['attributes'] as $attr) - { - $spl = explode('__', $attr); - - if ($spl[0] === 'language-befungerunner') - { - $Block['element']['handler'] = 'handleBef93'; - $Block['custom'] = true; - $Block['element']['text']['b93_speed'] = null; - $Block['element']['text']['b93_interactive'] = true; - $Block['element']['text']['b93_editable'] = true; - - foreach ($spl as $param) - { - if (startsWith($param, 'speed-')) $Block['element']['text']['b93_speed'] = intval( substr($param, strlen('speed-'))); - if (startsWith($param, 'interactive-')) $Block['element']['text']['b93_interactive'] = boolval(substr($param, strlen('interactive-'))); - if (startsWith($param, 'editable-')) $Block['element']['text']['b93_editable'] = boolval(substr($param, strlen('editable-'))); - } - - return $Block; - } - else if ($spl[0] === 'language-bfjoustrunner') - { - $Block['element']['handler'] = 'handleBFJoust'; - $Block['custom'] = true; - return $Block; - } - } - } - - return $Block; - } - - protected function blockFencedCodeComplete($Block) - { - if (! $Block['custom']) { return parent::blockFencedCodeComplete($Block); } - - $Block['element']['custom'] = true; - - return $Block; - } - - protected function handleBFJoust(array $Element) - { - global $PARAM_CODE_LEFT; - global $PARAM_CODE_RIGHT; - - $split = preg_split("/\-{16,}/", $Element['text']); - - $PARAM_CODE_LEFT = trim($split[0]); - $PARAM_CODE_RIGHT = trim($split[1]); - - return require (__DIR__ . '/../fragments/widget_bfjoust.php'); - } - - protected function handleBef93(array $Element) - { - global $PARAM_BEFUNGE93RUNNER; - $PARAM_BEFUNGE93RUNNER = - [ - 'code' => $Element['text'], - 'url' => '', - 'interactive' => $Element['b93_interactive'], - 'speed' => $Element['b93_speed'], - 'editable' => $Element['b93_editable'], - ]; - return require (__DIR__ . '/../fragments/widget_befunge93.php'); - } - - protected function blockTable($Line, array $Block = null) - { - // https://stackoverflow.com/a/46346412/1761622 - - $Block = parent::blockTable($Line, $Block); - - if ($Block === null) return $Block; - if (!key_exists('element', $Block)) return $Block; - - $Block['element']['attributes']['class'] = 'stripedtable'; - - return $Block; - } -} \ No newline at end of file diff --git a/www/internals/adventofcode.php b/www/internals/adventofcode.php index 8fccc9e..1e64e18 100644 --- a/www/internals/adventofcode.php +++ b/www/internals/adventofcode.php @@ -1,5 +1,7 @@ ['ext'=>'ts', 'css'=>'language-typescript', 'name'=>'Typescript'], ]; - public static function listAllFromAllYears() + /** @var array */ + private $staticData; + + public function __construct() + { + $this->load(); + } + + private function load() { $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); }); }); - return $all; + $this->staticData = $all; } - public static function listSingleYear($year) + public function listAllFromAllYears() { - $all = require (__DIR__ . '/../statics/aoc/__all.php'); - - $result = $all[$year]; - - array_walk($result, function(&$value) use ($year) { $value = self::readSingle($year, $value); }); - - return $result; + return $this->staticData; } - public static function listSingleYearAssociative($year) + public function listSingleYear($year) { - $all = self::listSingleYear($year); + return $this->staticData[$year]; + } + + public function listSingleYearAssociative($year) + { + $all = $this->listSingleYear($year); $result = array_fill(0, 25, null); foreach ($all as $d) { - $result[$d['day']-1] = $d; + $result[$d['day'] - 1] = $d; } return $result; } - public static function listYears() + public function listYears() { - $all = require (__DIR__ . '/../statics/aoc/__all.php'); - - return array_keys($all); + return array_keys($this->staticData); } public static function readSingle($year, $a) @@ -93,7 +100,7 @@ class AdventOfCode return $a; } - public static function getDayFromStrIdent($year, $ident) + public function getDayFromStrIdent($year, $ident) { $e = explode('-', $ident, 2); // day-xxx if (count($e)!==2) return null; @@ -104,25 +111,25 @@ class AdventOfCode return self::getSingleDay($year, $i); } - public static function getSingleDay($year, $day) + public function getSingleDay($year, $day) { - foreach (self::listSingleYear($year) as $aocd) { + foreach ($this->listSingleYear($year) as $aocd) { if ($aocd['day'] == $day) return $aocd; } return null; } - public static function getGithubLink($year) + public function getGithubLink($year) { return self::YEARS['' . $year]['github']; } - public static function getURLForYear($year) + public function getURLForYear($year) { return '/blog/' . self::YEARS[''.$year]['blog-id'] . '/Advent_of_Code_' . $year . '/'; } - public static function getPrevYear($year) + public function getPrevYear($year) { $last = null; foreach (self::YEARS as $y => $d) @@ -133,7 +140,7 @@ class AdventOfCode return null; } - public static function getNextYear($year) + public function getNextYear($year) { $found = false; foreach (self::YEARS as $y => $d) @@ -144,12 +151,12 @@ class AdventOfCode return null; } - public static function getLanguageCSS($data) + public function getLanguageCSS($data) { return self::LANGUAGES[$data['language']]['css']; } - public static function getSolutionCode($data, $i) + public function getSolutionCode($data, $i) { $raw = file_get_contents($data['file_solutions'][$i]); @@ -165,11 +172,13 @@ class AdventOfCode return $raw; } - public static function checkConsistency() + public function checkConsistency() { $warn = null; - foreach (self::listAllFromAllYears() as $year => $yd) + $this->load(); + + foreach ($this->listAllFromAllYears() as $year => $yd) { $daylist = []; $titlelist = []; From c9b6223a8775487fcb73831ee4ce9ceb72cc90ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Wed, 15 Jan 2020 00:29:45 +0100 Subject: [PATCH 05/33] Books --- www/internals/books.php | 41 ++++++++++++++++++++++++++------------ www/internals/database.php | 20 +++++++++---------- www/internals/website.php | 40 +++++++++++++++++++++++++------------ 3 files changed, 65 insertions(+), 36 deletions(-) diff --git a/www/internals/books.php b/www/internals/books.php index cf3ece8..b2199ea 100644 --- a/www/internals/books.php +++ b/www/internals/books.php @@ -1,9 +1,24 @@ load(); + } + + private function load() + { + $all = require (__DIR__ . '/../statics/blog/__all.php'); + + $this->staticData = array_map(function($a){return self::readSingle($a);}, $all); + } + public static function readSingle($a) { $a['imgfront_url'] = '/data/images/book_img/' . $a['id'] . '_front.png'; @@ -31,27 +46,27 @@ class Books return $a; } - public static function listAll() + public function listAll() { - $all = require (__DIR__ . '/../statics/books/__all.php'); - - return array_map('self::readSingle', $all); + return $this->staticData; } - public static function listAllNewestFirst() + public function listAllNewestFirst() { - $data = self::listAll(); + $data = $this->staticData; usort($data, function($a, $b) { return strcasecmp($b['date'], $a['date']); }); return $data; } - public static function checkConsistency() + public function checkConsistency() { $warn = null; + $this->load(); + $ids = []; - foreach (self::listAll() as $prog) + foreach ($this->staticData as $prog) { if (in_array($prog['id'], $ids)) return ['result'=>'err', 'message' => 'Duplicate id ' . $prog['id']]; $ids []= $prog['id']; @@ -79,7 +94,7 @@ class Books return ['result'=>'ok', 'message' => '']; } - public static function checkThumbnails() + public function checkThumbnails() { foreach (self::listAll() as $book) { @@ -89,7 +104,7 @@ class Books return ['result'=>'ok', 'message' => '']; } - public static function createPreview($prog) + public function createPreview($prog) { global $CONFIG; @@ -103,7 +118,7 @@ class Books } - public static function getBook($id) + public function getBook($id) { foreach (self::listAll() as $book) { if ($book['id'] == $id) return $book; @@ -111,7 +126,7 @@ class Books return null; } - public static function getRepositoryHost($book) + public function getRepositoryHost($book) { $r = $book['repository']; if (startsWith($r, "http://")) $r = substr($r, strlen("http://")); diff --git a/www/internals/database.php b/www/internals/database.php index dc607c7..70327e9 100644 --- a/www/internals/database.php +++ b/www/internals/database.php @@ -9,7 +9,12 @@ class Database public function __construct(Website $site) { - $dsn = "mysql:host=" . $site->config['host'] . ";dbname=" . $site->config['database'] . ";charset=utf8"; + $this->connect($site->config); + } + + private function connect(array $config) + { + $dsn = "mysql:host=" . $config['host'] . ";dbname=" . $config['database'] . ";charset=utf8"; $opt = [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, @@ -17,14 +22,12 @@ class Database PDO::ATTR_EMULATE_PREPARES => false, ]; - $this->pdo = new PDO($dsn, $site->config['user'], $site->config['password'], $opt); + $this->pdo = new PDO($dsn, $config['user'], $config['password'], $opt); } public function sql_query_num($query) { - $r = $this->pdo->query($query)->fetch(PDO::FETCH_NUM)[0]; - - return $r; + return $this->pdo->query($query)->fetch(PDO::FETCH_NUM)[0]; } public function sql_query_num_prep($query, $params) @@ -37,16 +40,13 @@ class Database } $stmt->execute(); - $r = $stmt->fetch(PDO::FETCH_NUM)[0]; - return $r; + return $stmt->fetch(PDO::FETCH_NUM)[0]; } public function sql_query_assoc($query) { - $r = $this->pdo->query($query)->fetchAll(PDO::FETCH_ASSOC); - - return $r; + return $this->pdo->query($query)->fetchAll(PDO::FETCH_ASSOC); } public function sql_query_assoc_prep($query, $params) diff --git a/www/internals/website.php b/www/internals/website.php index 125821b..ca91737 100644 --- a/www/internals/website.php +++ b/www/internals/website.php @@ -17,8 +17,10 @@ class Website /** @var array */ public $config; - /** @var Database|null */ - private $database = 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; public function init() { @@ -50,7 +52,7 @@ class Website } } - public static function getInstance() + public static function inst() { return self::$instance; } @@ -140,10 +142,6 @@ class Website exit(); } - /** - * @param PageFrameOptions $pfo - * @param URLRoute $route - */ private function output(PageFrameOptions $pfo, URLRoute $route) { if ($pfo->contentType !== null) header('Content-Type: ' . $pfo->contentType); @@ -160,16 +158,32 @@ class Website require __DIR__ . '/../pages/frame/' . $FRAME_OPTIONS->frame; } - public function database() + public function Database() { - if ($this->database === null) - { - require_once 'database.php'; - $this->database = new Database($this); - } + if ($this->database === null) { require_once 'database.php'; $this->database = new Database($this); } return $this->database; } + public function AdventOfCode() + { + if ($this->adventOfCode === null) { require_once 'adventofcode.php'; $this->adventOfCode = new AdventOfCode(); } + return $this->adventOfCode; + } + + public function Blog() + { + if ($this->blog === null) { require_once 'blog.php'; $this->blog = new Blog(); } + return $this->blog; + } + + public function Books() + { + if ($this->books === null) { require_once 'books.php'; $this->books = new Books(); } + return $this->books; + } + + + /** * @return bool */ From f06948851ca67abd46e1daba76847e2b3d524861 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Wed, 15 Jan 2020 00:29:49 +0100 Subject: [PATCH 06/33] Blog --- www/internals/blog.php | 43 +++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/www/internals/blog.php b/www/internals/blog.php index 12310b4..dfc6173 100644 --- a/www/internals/blog.php +++ b/www/internals/blog.php @@ -1,12 +1,22 @@ load(); + } + + private function load() { $all = require (__DIR__ . '/../statics/blog/__all.php'); - return array_map('self::readSingle', $all); + $this->staticData = array_map(function($a){return self::readSingle($a);}, $all); } private static function readSingle($d) @@ -25,24 +35,29 @@ class Blog return $d; } - public static function listAllNewestFirst() + public function listAll() { - $data = self::listAll(); + return $this->staticData; + } + + public function listAllNewestFirst() + { + $data = $this->staticData; usort($data, function($a, $b) { return strcasecmp($b['date'], $a['date']); }); return $data; } - public static function getBlogpost($id) + public function getBlogpost($id) { - foreach (self::listAll() as $post) { + foreach ($this->staticData as $post) { if ($post['id'] == $id) return $post; } return null; } - public static function getFullBlogpost($id, $subview, &$error) + public function getFullBlogpost($id, $subview, &$error) { - $post = self::getBlogpost($id); + $post = $this->getBlogpost($id); if ($post === null) { $error="Blogpost not found"; return null; } $post['issubview'] = false; @@ -52,7 +67,7 @@ class Blog if ($isSubEuler) { require_once(__DIR__ . '/../internals/euler.php'); - $eulerproblem = Euler::getEulerProblemFromStrIdent($subview); + $eulerproblem = Website::inst()->Euler()->getEulerProblemFromStrIdent($subview); if ($eulerproblem === null) { $error="Project Euler entry not found"; return null; } $post['submodel'] = $eulerproblem; $post['issubview'] = true; @@ -63,7 +78,7 @@ class Blog if ($isSubAdventOfCode) { require_once(__DIR__ . '/../internals/adventofcode.php'); - $adventofcodeday = AdventOfCode::getDayFromStrIdent($post['extras']['aoc:year'], $subview); + $adventofcodeday = Website::inst()->AdventOfCode()->getDayFromStrIdent($post['extras']['aoc:year'], $subview); if ($adventofcodeday === null) { $error="AdventOfCode entry not found"; return null; } $post['submodel'] = $adventofcodeday; $post['issubview'] = true; @@ -79,16 +94,18 @@ class Blog } - public static function getPostFragment($post) + public function getPostFragment($post) { return file_get_contents($post['file_fragment']); } - public static function checkConsistency() + public function checkConsistency() { $keys = []; - foreach (self::listAll() as $post) + $this->load(); + + foreach ($this->staticData as $post) { if (in_array($post['id'], $keys)) return ['result'=>'err', 'message' => 'Duplicate key ' . $post['id']]; $keys []= $post['id']; From e5dc57e2b5b4b181e50db56bdf90f91c5bf8f451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Wed, 15 Jan 2020 00:32:24 +0100 Subject: [PATCH 07/33] Euler --- www/internals/adventofcode.php | 2 +- www/internals/books.php | 2 +- www/internals/euler.php | 77 +++++++++++++++++++++------------- www/internals/website.php | 7 ++++ 4 files changed, 56 insertions(+), 32 deletions(-) diff --git a/www/internals/adventofcode.php b/www/internals/adventofcode.php index 1e64e18..6727462 100644 --- a/www/internals/adventofcode.php +++ b/www/internals/adventofcode.php @@ -71,7 +71,7 @@ class AdventOfCode return array_keys($this->staticData); } - public static function readSingle($year, $a) + private static function readSingle($year, $a) { $yeardata = self::YEARS[$year]; diff --git a/www/internals/books.php b/www/internals/books.php index b2199ea..01fcddd 100644 --- a/www/internals/books.php +++ b/www/internals/books.php @@ -19,7 +19,7 @@ class Books $this->staticData = array_map(function($a){return self::readSingle($a);}, $all); } - public static function readSingle($a) + private static function readSingle($a) { $a['imgfront_url'] = '/data/images/book_img/' . $a['id'] . '_front.png'; $a['imgfront_path'] = __DIR__ . '/../data/images/book_img/' . $a['id'] . '_front.png'; diff --git a/www/internals/euler.php b/www/internals/euler.php index a3c0dcc..66b4b13 100644 --- a/www/internals/euler.php +++ b/www/internals/euler.php @@ -1,8 +1,25 @@ 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($a) { $n3p = str_pad($a['number'], 3, '0', STR_PAD_LEFT); $a['number3'] = $n3p; @@ -25,33 +42,7 @@ class Euler return $a; } - public static function listAll() - { - $all = require (__DIR__ . '/../statics/euler/__all.php'); - - return array_map('self::readSingle', $all); - } - - public static function getEulerProblemFromStrIdent($ident) - { - $e = explode('-', $ident, 2); // problem-xxx - if (count($e)!==2) return null; - - $i = intval($e[1], 10); - if ($i == 0) return null; - - return self::getEulerProblem($i); - } - - public static function getEulerProblem($num) - { - foreach (self::listAll() as $ep) { - if ($ep['number'] == $num) return $ep; - } - return null; - } - - public static function rateTime($problem) + private static function rateTime($problem) { if ($problem['time'] < 100) // < 100ms return 0; @@ -68,14 +59,40 @@ class Euler return 4; } - public static function checkConsistency() + public function listAll() + { + return $this->staticData; + } + + public function getEulerProblemFromStrIdent($ident) + { + $e = explode('-', $ident, 2); // problem-xxx + if (count($e)!==2) return null; + + $i = intval($e[1], 10); + if ($i == 0) return null; + + return self::getEulerProblem($i); + } + + public function getEulerProblem($num) + { + foreach (self::listAll() as $ep) { + if ($ep['number'] == $num) return $ep; + } + return null; + } + + public function checkConsistency() { $warn = null; + $this->load(); + $numbers = []; $realname = []; - foreach (self::listAll() as $ep) + foreach ($this->staticData as $ep) { if (in_array($ep['number'], $numbers)) return ['result'=>'err', 'message' => 'Duplicate number ' . $ep['number']]; $numbers []= $ep['number']; diff --git a/www/internals/website.php b/www/internals/website.php index ca91737..ded064f 100644 --- a/www/internals/website.php +++ b/www/internals/website.php @@ -21,6 +21,7 @@ class Website /** @var AdventOfCode|null */ private $adventOfCode = null; /** @var Blog|null */ private $blog = null; /** @var Books|null */ private $books = null; + /** @var Euler|null */ private $euler = null; public function init() { @@ -182,6 +183,12 @@ class Website return $this->books; } + public function Euler() + { + if ($this->euler === null) { require_once 'euler.php'; $this->euler = new Euler(); } + return $this->euler; + } + /** From 099f5b368ed306e1a0f18e539ad5836a960ca84b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Wed, 15 Jan 2020 00:37:08 +0100 Subject: [PATCH 08/33] Programs --- www/internals/programs.php | 69 +++++++++++++++++++++----------------- www/internals/website.php | 7 +++- 2 files changed, 44 insertions(+), 32 deletions(-) diff --git a/www/internals/programs.php b/www/internals/programs.php index a8fbe55..d4e8eab 100644 --- a/www/internals/programs.php +++ b/www/internals/programs.php @@ -1,6 +1,6 @@ 'https://choosealicense.com/licenses/mpl-2.0/', ]; - public static function readSingle($a) + /** @var array */ + private $staticData; + + public function __construct() + { + $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($a) { $a['mainimage_url'] = '/data/images/program_img/' . $a['internal_name'] . '.png'; $a['mainimage_path'] = __DIR__ . '/../data/images/program_img/' . $a['internal_name'] . '.png'; @@ -62,42 +77,34 @@ class Programs return $a; } - public static function listAll() + public function listAll() { - $all = require (__DIR__ . '/../statics/programs/__all.php'); - - return array_map('self::readSingle', $all); + return $this->staticData; } - public static function listAllNewestFirst($filter = '') + public function listAllNewestFirst($filter = '') { - $data = self::listAll(); + $data = $this->staticData; usort($data, function($a, $b) { return strcasecmp($b['add_date'], $a['add_date']); }); if ($filter !== '') $data = array_filter($data, function($a) use($filter) { return strtolower($a['category']) === strtolower($filter); }); return $data; } - public static function listUpdateData() + public function getProgramByInternalName($id) { - $a = require (__DIR__ . '/../statics/updates/_all.php'); - return $a; - } - - public static function getProgramByInternalName($id) - { - foreach (self::listAll() as $prog) { + foreach ($this->staticData as $prog) { if (strcasecmp($prog['internal_name'], $id) === 0) return $prog; if ($prog['internal_name_alt'] !== null && strcasecmp($prog['internal_name_alt'], $id) === 0) return $prog; } return null; } - public static function getProgramDescription($prog) + public function getProgramDescription($prog) { return file_get_contents($prog['file_longdescription']); } - public static function urlComparator($a, $b) + private static function urlComparator($a, $b) { $na = 0; $nb = 0; @@ -118,10 +125,10 @@ class Programs } - public static function getURLs($prog) + public function getURLs($prog) { $urls = $prog['urls']; - uksort($urls, 'self::urlComparator'); + uksort($urls, function($a,$b){return self::urlComparator($a,$b);}); $result = []; foreach ($urls as $fulltype => $urldata) @@ -178,29 +185,31 @@ class Programs return $result; } - public static function getLicenseUrl($license) + public function getLicenseUrl($license) { return self::LICENSES[$license]; } - public static function getDirectDownloadURL($prog) + public function getDirectDownloadURL($prog) { return '/data/binaries/'.$prog['internal_name'].'.zip'; } - public static function getDirectDownloadPath($prog) + public function getDirectDownloadPath($prog) { return (__DIR__ . '/../data/binaries/'.$prog['internal_name'].'.zip'); } - public static function checkConsistency() + public function checkConsistency() { $warn = null; + $this->load(); + $intname = []; $realname = []; - foreach (self::listAll() as $prog) + foreach ($this->staticData as $prog) { if (in_array($prog['internal_name'], $intname)) return ['result'=>'err', 'message' => 'Duplicate internal_name ' . $prog['name']]; $intname []= $prog['internal_name']; @@ -250,9 +259,9 @@ class Programs return ['result'=>'ok', 'message' => '']; } - public static function checkThumbnails() + public function checkThumbnails() { - foreach (self::listAll() as $prog) + foreach ($this->staticData as $prog) { if (!file_exists($prog['preview_path'])) return ['result'=>'err', 'message' => 'Preview not found ' . $prog['name']]; } @@ -260,14 +269,12 @@ class Programs return ['result'=>'ok', 'message' => '']; } - public static function createPreview($prog) + public function createPreview($prog) { - global $CONFIG; - $src = $prog['mainimage_path']; $dst = $prog['preview_path']; - if ($CONFIG['use_magick']) + if (Website::inst()->config['use_magick']) magick_resize_image($src, 250, 0, $dst); else smart_resize_image($src, 250, 0, true, $dst); diff --git a/www/internals/website.php b/www/internals/website.php index ded064f..b2675e7 100644 --- a/www/internals/website.php +++ b/www/internals/website.php @@ -22,6 +22,7 @@ class Website /** @var Blog|null */ private $blog = null; /** @var Books|null */ private $books = null; /** @var Euler|null */ private $euler = null; + /** @var Programs|null */ private $programs = null; public function init() { @@ -189,7 +190,11 @@ class Website return $this->euler; } - + public function Programs() + { + if ($this->programs === null) { require_once 'programs.php'; $this->programs = new Programs(); } + return $this->programs; + } /** * @return bool From a96315a1037dee46289cc26f7396e8a7056826fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Wed, 15 Jan 2020 00:41:25 +0100 Subject: [PATCH 09/33] AlephNoteStatistics --- www/internals/alephnoteStatistics.php | 28 ++++++++++++++++++--------- www/internals/mikeschergitgraph.php | 2 +- www/internals/website.php | 22 ++++++++++++--------- 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/www/internals/alephnoteStatistics.php b/www/internals/alephnoteStatistics.php index fcf838c..6c59386 100644 --- a/www/internals/alephnoteStatistics.php +++ b/www/internals/alephnoteStatistics.php @@ -1,26 +1,36 @@ 0'); + $this->site = $site; + + $site->Database(); } - public static function getUserCountFromLastVersion() + public function getTotalUserCount() { - return Database::sql_query_num('SELECT COUNT(*) FROM an_statslog WHERE NoteCount>0 GROUP BY Version ORDER BY INET_ATON(Version) DESC LIMIT 1'); + return $this->site->Database()->sql_query_num('SELECT COUNT(*) FROM an_statslog WHERE NoteCount>0'); } - public static function getActiveUserCount($days) + public function getUserCountFromLastVersion() { - return Database::sql_query_num('SELECT COUNT(*) FROM an_statslog WHERE NoteCount>0 AND LastChanged > NOW() - INTERVAL '.$days.' DAY'); + 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 static function getAllActiveEntriesOrdered() + public function getActiveUserCount($days) { - return Database::sql_query_assoc('SELECT * FROM an_statslog WHERE NoteCount>0 ORDER BY LastChanged DESC'); + 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'); } } \ No newline at end of file diff --git a/www/internals/mikeschergitgraph.php b/www/internals/mikeschergitgraph.php index baeef52..b34c87a 100644 --- a/www/internals/mikeschergitgraph.php +++ b/www/internals/mikeschergitgraph.php @@ -1,6 +1,6 @@ programs; } + public function AlephNoteStatistics() + { + if ($this->anstats === null) { require_once 'alephnoteStatistics.php'; $this->anstats = new AlephNoteStatistics(); } + return $this->anstats; + } + /** * @return bool */ From f904691006c732183854f79973e10c56beb5083f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Wed, 15 Jan 2020 00:45:30 +0100 Subject: [PATCH 10/33] UpdatesLog --- www/commands/progs_updatecheck.php | 2 +- www/internals/alephnoteStatistics.php | 2 -- www/internals/updateslog.php | 46 +++++++++++++++++++++------ www/internals/website.php | 9 +++++- 4 files changed, 45 insertions(+), 14 deletions(-) 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 */ From af09b49e8a21d668d44e06c4ef8d43f9d7aa7dd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Wed, 15 Jan 2020 00:50:55 +0100 Subject: [PATCH 11/33] WebApps --- www/internals/books.php | 2 +- www/internals/euler.php | 2 +- www/internals/programs.php | 2 +- www/internals/webapp.php | 20 +++++++++++++++----- www/internals/website.php | 21 ++++++++++++++------- 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/www/internals/books.php b/www/internals/books.php index 01fcddd..7265e58 100644 --- a/www/internals/books.php +++ b/www/internals/books.php @@ -14,7 +14,7 @@ class Books private function load() { - $all = require (__DIR__ . '/../statics/blog/__all.php'); + $all = require (__DIR__ . '/../statics/books/__all.php'); $this->staticData = array_map(function($a){return self::readSingle($a);}, $all); } diff --git a/www/internals/euler.php b/www/internals/euler.php index 66b4b13..8c9f7b3 100644 --- a/www/internals/euler.php +++ b/www/internals/euler.php @@ -14,7 +14,7 @@ class Euler private function load() { - $all = require (__DIR__ . '/../statics/blog/__all.php'); + $all = require (__DIR__ . '/../statics/euler/__all.php'); $this->staticData = array_map(function($a){return self::readSingle($a);}, $all); } diff --git a/www/internals/programs.php b/www/internals/programs.php index d4e8eab..83bea9d 100644 --- a/www/internals/programs.php +++ b/www/internals/programs.php @@ -43,7 +43,7 @@ class Programs private function load() { - $all = require (__DIR__ . '/../statics/blog/__all.php'); + $all = require (__DIR__ . '/../statics/programs/__all.php'); $this->staticData = array_map(function($a){return self::readSingle($a);}, $all); } diff --git a/www/internals/webapp.php b/www/internals/webapp.php index e5b8754..b310749 100644 --- a/www/internals/webapp.php +++ b/www/internals/webapp.php @@ -1,22 +1,32 @@ load(); + } + + private function load() { $all = require (__DIR__ . '/../statics/webapps/__all.php'); - return array_map('self::readSingle', $all); + $this->staticData = array_map(function($a){return self::readSingle($a);}, $all); } - public static function readSingle($a) + private static function readSingle($a) { return $a; } - public static function listAllNewestFirst() + public function listAllNewestFirst() { - $data = self::listAll(); + $data = $this->staticData; usort($data, function($a, $b) { return strcasecmp($b['date'], $a['date']); }); return $data; } diff --git a/www/internals/website.php b/www/internals/website.php index e564c62..f608e9d 100644 --- a/www/internals/website.php +++ b/www/internals/website.php @@ -22,6 +22,7 @@ class Website /** @var Programs|null */ private $programs = null; /** @var AlephNoteStatistics|null */ private $anstats = null; /** @var UpdatesLog|null */ private $updateslog = null; + /** @var WebApps|null */ private $webapps = null; public function init() { @@ -165,48 +166,54 @@ class Website return $this->database; } - public function AdventOfCode() + public function AdventOfCode(): AdventOfCode { if ($this->adventOfCode === null) { require_once 'adventofcode.php'; $this->adventOfCode = new AdventOfCode(); } return $this->adventOfCode; } - public function Blog() + public function Blog(): Blog { if ($this->blog === null) { require_once 'blog.php'; $this->blog = new Blog(); } return $this->blog; } - public function Books() + public function Books(): Books { if ($this->books === null) { require_once 'books.php'; $this->books = new Books(); } return $this->books; } - public function Euler() + public function Euler(): Euler { if ($this->euler === null) { require_once 'euler.php'; $this->euler = new Euler(); } return $this->euler; } - public function Programs() + public function Programs(): Programs { if ($this->programs === null) { require_once 'programs.php'; $this->programs = new Programs(); } return $this->programs; } - public function AlephNoteStatistics() + public function AlephNoteStatistics(): AlephNoteStatistics { if ($this->anstats === null) { require_once 'alephnoteStatistics.php'; $this->anstats = new AlephNoteStatistics($this); } return $this->anstats; } - public function UpdatesLog() + 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 'webapp.php'; $this->webapps = new WebApps(); } + return $this->webapps; + } + /** * @return bool */ From 114e93d09e4758c6417b8897fcd6c45688ec27b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Wed, 15 Jan 2020 00:57:11 +0100 Subject: [PATCH 12/33] ExtendedGitGraph --- .gitignore | 4 +++- www/internals/.gitignore | 1 - www/internals/mikeschergitgraph.php | 24 +++++++++++------------ www/internals/{webapp.php => webapps.php} | 0 www/internals/website.php | 18 ++++++++--------- 5 files changed, 23 insertions(+), 24 deletions(-) delete mode 100644 www/internals/.gitignore rename www/internals/{webapp.php => webapps.php} (100%) diff --git a/.gitignore b/.gitignore index 6ed4df6..8b72e38 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,6 @@ runtime/ **/.idea/workspace.xml **/.idea/tasks.xml -**/.idea/dataSources* \ No newline at end of file +**/.idea/dataSources* + +config.php \ No newline at end of file diff --git a/www/internals/.gitignore b/www/internals/.gitignore deleted file mode 100644 index 4e9b47a..0000000 --- a/www/internals/.gitignore +++ /dev/null @@ -1 +0,0 @@ -config.php \ No newline at end of file diff --git a/www/internals/mikeschergitgraph.php b/www/internals/mikeschergitgraph.php index b34c87a..86e55ad 100644 --- a/www/internals/mikeschergitgraph.php +++ b/www/internals/mikeschergitgraph.php @@ -5,18 +5,16 @@ require_once (__DIR__ . '/../extern/egg/ExtendedGitGraph2.php'); class MikescherGitGraph { - /** - * @return ExtendedGitGraph2 - * @throws Exception - */ - public static function create() - { - global $CONFIG; + /** @var ExtendedGitGraph2 */ + private $extgitgraph; - return new ExtendedGitGraph2($CONFIG['extendedgitgraph']); + /** @noinspection PhpUnhandledExceptionInspection */ + public function __construct(Website $site) + { + $this->extgitgraph = new ExtendedGitGraph2($site->config['extendedgitgraph']); } - public static function getPathRenderedData() + public function getPathRenderedData() { return __DIR__ . '/../dynamic/egg/cache_fullrenderer.html'; } @@ -25,16 +23,16 @@ class MikescherGitGraph * @return string|null * @throws Exception */ - public static function get() + public function get() { - $d = self::create()->loadFromCache(); + $d = $this->extgitgraph->loadFromCache(); if ($d === null) return ""; return $d; } - public static function checkConsistency() + public function checkConsistency() { - $p = self::getPathRenderedData(); + $p =$this->getPathRenderedData(); if (!file_exists($p)) return ['result'=>'err', 'message' => 'Rendered data not found']; diff --git a/www/internals/webapp.php b/www/internals/webapps.php similarity index 100% rename from www/internals/webapp.php rename to www/internals/webapps.php diff --git a/www/internals/website.php b/www/internals/website.php index f608e9d..11a1b58 100644 --- a/www/internals/website.php +++ b/www/internals/website.php @@ -23,6 +23,7 @@ class Website /** @var AlephNoteStatistics|null */ private $anstats = null; /** @var UpdatesLog|null */ private $updateslog = null; /** @var WebApps|null */ private $webapps = null; + /** @var MikescherGitGraph|null */ private $extendedgitgraph = null; public function init() { @@ -30,15 +31,8 @@ class Website try { - $this->config = require (__DIR__ . "/config.php"); - } - catch (exception $e) - { - $this->serveServerError("config.php not found", formatException($e), null); - } + $this->config = require (__DIR__ . "/../config.php"); - try - { if (!$this->config['prod']) { ini_set('display_errors', 1); @@ -210,10 +204,16 @@ class Website public function WebApps(): WebApps { - if ($this->webapps === null) { require_once 'webapp.php'; $this->webapps = new 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 */ From f9a692e6353161119b4d3c90196d2ceb526681cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Wed, 15 Jan 2020 01:46:31 +0100 Subject: [PATCH 13/33] index request works almost --- www/frames/default_frame.php | 14 ++++- www/internals/pageframeoptions.php | 37 ++++++++++++- www/internals/ruleengine.php | 16 +++--- www/internals/urlroute.php | 31 ++++------- www/internals/utils.php | 83 ------------------------------ www/internals/website.php | 36 +++++++++++-- www/pages/main.php | 42 ++++----------- 7 files changed, 112 insertions(+), 147 deletions(-) diff --git a/www/frames/default_frame.php b/www/frames/default_frame.php index 36045c4..713a2a0 100644 --- a/www/frames/default_frame.php +++ b/www/frames/default_frame.php @@ -15,7 +15,15 @@ require_once (__DIR__ . '/../internals/website.php'); <?php echo $FRAME_OPTIONS->title; ?> - + canonical_url !== null) echo ''; + foreach ($FRAME_OPTIONS->stylesheets as $cssfile) echo ''; + foreach ($FRAME_OPTIONS->scripts as $scriptfile) + { + if ($scriptfile[1]) echo ''; + } + ?>
@@ -40,7 +48,9 @@ require_once (__DIR__ . '/../internals/website.php');
- raw; ?> +
+ raw; ?> +

diff --git a/www/internals/pageframeoptions.php b/www/internals/pageframeoptions.php index e01ac02..726d00e 100644 --- a/www/internals/pageframeoptions.php +++ b/www/internals/pageframeoptions.php @@ -7,7 +7,7 @@ class PageFrameOptions public $raw; /** @var string */ - public $title = ''; + public $title = 'Mikescher.com'; /** @var int */ public $statuscode = 200; @@ -23,4 +23,39 @@ class PageFrameOptions /** @var string */ public $contentType = null; + + /** @var string */ + public $activeHeader = null; + + /** @var string */ + public $canonical_url = null; + + /** @var string[] */ + public $contentCSSClasses = [ 'content-responsive' ]; + + /** @var array */ + public $stylesheets = []; + + /** @var array */ + public $scripts = []; + + public function addStylesheet(string $url) + { + foreach ($this->stylesheets as $css) if ($css === $url) return; + $this->stylesheets []= $url; + } + + public function addScript(string $url, bool $defer = false) + { + foreach ($this->scripts as &$script) + { + if ($script[0] === $url) + { + if (!$defer && $script[1]) $script[1] = false; // upgrade from defered to immediate script + return; + } + } + + $this->scripts []= [ $url, $defer ]; + } } \ No newline at end of file diff --git a/www/internals/ruleengine.php b/www/internals/ruleengine.php index 3db339d..1f96f5a 100644 --- a/www/internals/ruleengine.php +++ b/www/internals/ruleengine.php @@ -5,13 +5,13 @@ require_once "website.php"; class RuleEngine { /** - * @param Website $app + * @param Website $site * @param array $urlConfig * @return URLRoute */ - public static function findRoute(Website $app, array $urlConfig): URLRoute + public static function findRoute(Website $site, array $urlConfig): URLRoute { - if ($app->isProd()) + if ($site->isProd()) $requri = $_SERVER['REQUEST_URI']; else $requri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : 'localhost:80/'; @@ -24,16 +24,18 @@ class RuleEngine foreach ($urlConfig as $rule) { - $route = self::testRule($app, $rule, $requri, $pathparts, $partcount); + $route = self::testRule($site, $rule, $requri, $pathparts, $partcount); if ($route === null) continue; - if ($route->needsAdminLogin && !$app->isLoggedIn()) return URLRoute::getLoginRoute($route, $requri); + if ($route->needsAdminLogin && !$site->isLoggedInByCookie()) return URLRoute::getLoginRoute($route, $requri); + + return $route; } return URLRoute::getNotFoundRoute($requri); } - private static function testRule(Website $app, array $rule, string $requri, array $pathparts, int $partcount) + private static function testRule(Website $site, array $rule, string $requri, array $pathparts, int $partcount) { if ($partcount !== count($rule['url'])) return null; @@ -95,7 +97,7 @@ class RuleEngine $route->needsAdminLogin = isset($ctrlOpt['password']); - if ($app->isProd() && isHTTPRequest() && !in_array('http', $ctrlOpt)) + if ($site->isProd() && isHTTPRequest() && !in_array('http', $ctrlOpt)) { // enforce https $redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; diff --git a/www/internals/urlroute.php b/www/internals/urlroute.php index 8c65a8a..0ba3f79 100644 --- a/www/internals/urlroute.php +++ b/www/internals/urlroute.php @@ -16,52 +16,43 @@ class URLRoute /** @var int */ public $needsAdminLogin; - /** @var int */ - public $isAPI; - public function __construct(string $target, string $url) { $this->targetpath = __DIR__ . '/../pages/' . $target; $this->full_url = $url; $this->parameter = []; $this->needsAdminLogin = false; - $this->isAPI = false; } /** - * @param Website $app + * @param Website $site * @return PageFrameOptions */ - public function get(Website $app): PageFrameOptions + public function get(Website $site): PageFrameOptions { $pfo = new PageFrameOptions(); - $pfo->title = 'Mikescher.com'; // default title - if ($this->isAPI) - { - $pfo->frame = 'no_frame.php'; - $pfo->contentType = 'application/json'; - } + $pfo->addStylesheet($site->isProd() ? ('/data/css/styles.min.css') : ('/data/css/styles.css')); - return $this->getDirect($app, $pfo); + return $this->getDirect($site, $pfo); } /** - * @param Website $app + * @param Website $site * @param PageFrameOptions $pfo * @return PageFrameOptions */ - public function getDirect(Website $app, PageFrameOptions $pfo): PageFrameOptions + public function getDirect(Website $site, PageFrameOptions $pfo): PageFrameOptions { @ob_end_clean(); ob_start(); global $ROUTE; global $FRAME_OPTIONS; - global $APP; + global $SITE; $ROUTE = $this; $FRAME_OPTIONS = $pfo; - $APP = $app; + $SITE = $site; /** @noinspection PhpIncludeInspection */ require $this->targetpath; @@ -79,7 +70,7 @@ class URLRoute public static function getLoginRoute(URLRoute $route, string $requri): URLRoute { $r = new URLRoute('login.php', $requri); - $r->parameter = [ 'redirect' => $route->full_url ]; + $r->parameter = [ 'login_target' => $route->full_url ]; return $r; } @@ -89,7 +80,7 @@ class URLRoute */ public static function getNotFoundRoute(string $requri): URLRoute { - $r = new URLRoute('errors/not_found.php', $requri); + $r = new URLRoute('error_notfound.php', $requri); $r->parameter = []; return $r; } @@ -100,7 +91,7 @@ class URLRoute */ public static function getServerErrorRoute(string $requri): URLRoute { - $r = new URLRoute('errors/server_error.php', $requri); + $r = new URLRoute('error_servererror.php', $requri); $r->parameter = []; return $r; } diff --git a/www/internals/utils.php b/www/internals/utils.php index 13cf5ae..431262a 100644 --- a/www/internals/utils.php +++ b/www/internals/utils.php @@ -82,61 +82,6 @@ function formatMilliseconds($millis) } } -function includeAdditionalScript($script, $attr='', $printImmediately = false) { - global $ADDITIONAL_SCRIPTS; - - if (in_array($script, $ADDITIONAL_SCRIPTS)) return false; - - if ($printImmediately) { - $ADDITIONAL_SCRIPTS[$script] = ['src' => $script, 'attr' => $attr, 'consumed' => true]; - echo ''; - return true; - } else { - $ADDITIONAL_SCRIPTS[$script] = ['src' => $script, 'attr' => $attr, 'consumed' => false]; - return true; - } -} - -function includeAdditionalStylesheet($sheet, $attr='', $printImmediately = false) { - global $ADDITIONAL_STYLESHEETS; - - if (in_array($sheet, $ADDITIONAL_STYLESHEETS)) return false; - - if ($printImmediately) { - $ADDITIONAL_STYLESHEETS[$sheet] = ['src' => $sheet, 'attr' => $attr, 'consumed' => true]; - echo ''; - return true; - } else { - $ADDITIONAL_STYLESHEETS[$sheet] = ['src' => $sheet, 'attr' => $attr, 'consumed' => false]; - return true; - } -} - -function printHeaderCSS() { - global $CSS_BASE; - includeAdditionalStylesheet($CSS_BASE, '', true); -} - -function printAdditionalScripts() { - global $ADDITIONAL_SCRIPTS; - - foreach ($ADDITIONAL_SCRIPTS as $d) { - if ($d['consumed']) continue; - echo ''; - $d['consumed'] = true; - } -} - -function printAdditionalStylesheets() { - global $ADDITIONAL_STYLESHEETS; - - foreach ($ADDITIONAL_STYLESHEETS as $d) { - if ($d['consumed']) continue; - echo ''; - $d['consumed'] = true; - } -} - function isProd() { global $CONFIG; return $CONFIG['prod']; @@ -180,34 +125,6 @@ function convertLanguageToFlag($lang) { return null; } -function setLoginCookie($user, $pass) -{ - $expires = time() + (24*60*60); // 24h - $hash = hash('sha256', $user . ';' . $pass . ';' . gmdate('Y-m-d')); - setcookie('mikescher_auth', $hash, $expires); -} - -function isLoggedInByCookie() -{ - static $_loginCache = null; - if ($_loginCache !== null) return $_loginCache; - - global $CONFIG; - if (key_exists('mikescher_auth', $_COOKIE)) - { - if (strlen($_COOKIE['mikescher_auth']) !== 64) return $_loginCache = false; - $auth = hash('sha256', $CONFIG['admin_username'] . ';' . $CONFIG['admin_password'] . ';' . gmdate('Y-m-d')); - if ($auth === $_COOKIE['mikescher_auth']) return $_loginCache = true; - } - - return $_loginCache = false; -} - -function clearLoginCookie() -{ - setcookie("mikescher_auth", "", time()+30); -} - /** * easy image resize function * @author http://www.nimrodstech.com/php-image-resize/ diff --git a/www/internals/website.php b/www/internals/website.php index 11a1b58..3c18f5c 100644 --- a/www/internals/website.php +++ b/www/internals/website.php @@ -14,6 +14,9 @@ class Website /** @var array */ public $config; + /** @var bool|null */ + public $isLoggedIn = null; + /** @var Database|null */ private $database = null; /** @var AdventOfCode|null */ private $adventOfCode = null; /** @var Blog|null */ private $blog = null; @@ -145,13 +148,13 @@ class Website global $ROUTE; global $FRAME_OPTIONS; - global $APP; + global $SITE; $ROUTE = $route; $FRAME_OPTIONS = $pfo; - $APP = $this; + $SITE = $this; /** @noinspection PhpIncludeInspection */ - require __DIR__ . '/../pages/frame/' . $FRAME_OPTIONS->frame; + require __DIR__ . '/../frames/' . $FRAME_OPTIONS->frame; } public function Database() @@ -222,6 +225,33 @@ class Website if ($this->config == null) return true; return $this->config['prod']; } + + public function isLoggedInByCookie() + { + if ($this->isLoggedIn !== null) return $this->isLoggedIn; + + if (key_exists('mikescher_auth', $_COOKIE)) + { + if (strlen($_COOKIE['mikescher_auth']) !== 64) return ($this->isLoggedIn = false); + $auth = hash('sha256', $this->config['admin_username'] . ';' . $this->config['admin_password'] . ';' . gmdate('Y-m-d')); + if ($auth === $_COOKIE['mikescher_auth']) return ($this->isLoggedIn = true); + } + + return ($this->isLoggedIn = false); + } + + function setLoginCookie($user, $pass) + { + $expires = time() + (24*60*60); // 24h + $hash = hash('sha256', $user . ';' . $pass . ';' . gmdate('Y-m-d')); + setcookie('mikescher_auth', $hash, $expires); + } + + function clearLoginCookie() + { + setcookie("mikescher_auth", "", time()+30); + } + } /** diff --git a/www/pages/main.php b/www/pages/main.php index 1cd4b33..ea37c14 100644 --- a/www/pages/main.php +++ b/www/pages/main.php @@ -1,37 +1,17 @@ - - - - - - Mikescher.com - - - - - - -
+ +/** @var PageFrameOptions $FRAME_OPTIONS */ global $FRAME_OPTIONS; +/** @var URLRoute $ROUTE */ global $ROUTE; +/** @var Website $SITE */ global $SITE; +?> -
+ - + - + - + - - - - -
- - - -
- - - - \ No newline at end of file + \ No newline at end of file From 588e9b089a41d4fb27d1052360025a583a7d47ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Wed, 15 Jan 2020 02:50:23 +0100 Subject: [PATCH 14/33] ndex route works again --- www/data/css/styles.css | 10 ++ www/data/css/styles.min.css | 3 +- www/data/css/styles_errorview.scss | 13 +++ www/fragments/panel_aoc.php | 24 +++-- www/fragments/panel_aoc_calendar.php | 39 +++++--- www/fragments/panel_blog.php | 18 +++- www/fragments/panel_books.php | 18 +++- www/fragments/panel_euler.php | 20 +++- www/fragments/panel_programs.php | 18 +++- www/frames/default_frame.php | 2 +- www/frames/error_frame.php | 52 ++++++++++ www/internals/alephnoteStatistics.php | 34 ------- www/internals/fragments.php | 48 +++++++++ www/internals/modules.php | 86 ++++++++++++++++ www/internals/{ => modules}/adventofcode.php | 4 +- www/internals/modules/alephnoteStatistics.php | 32 ++++++ www/internals/{ => modules}/blog.php | 10 +- www/internals/{ => modules}/books.php | 4 +- www/internals/{ => modules}/database.php | 2 - www/internals/{ => modules}/euler.php | 4 +- .../{ => modules}/mikeschergitgraph.php | 7 +- www/internals/{ => modules}/programs.php | 6 +- www/internals/{ => modules}/updateslog.php | 12 +-- www/internals/{ => modules}/webapps.php | 8 +- www/internals/ruleengine.php | 1 - www/internals/urlroute.php | 30 +++--- www/internals/utils.php | 20 +--- www/internals/website.php | 98 +++---------------- www/pages/error_servererror.php | 46 ++++----- www/pages/main.php | 16 ++- 30 files changed, 427 insertions(+), 258 deletions(-) create mode 100644 www/frames/error_frame.php delete mode 100644 www/internals/alephnoteStatistics.php create mode 100644 www/internals/fragments.php create mode 100644 www/internals/modules.php rename www/internals/{ => modules}/adventofcode.php (98%) create mode 100644 www/internals/modules/alephnoteStatistics.php rename www/internals/{ => modules}/blog.php (89%) rename www/internals/{ => modules}/books.php (98%) rename www/internals/{ => modules}/database.php (98%) rename www/internals/{ => modules}/euler.php (96%) rename www/internals/{ => modules}/mikeschergitgraph.php (80%) rename www/internals/{ => modules}/programs.php (98%) rename www/internals/{ => modules}/updateslog.php (55%) rename www/internals/{ => modules}/webapps.php (83%) diff --git a/www/data/css/styles.css b/www/data/css/styles.css index 61cd5e7..b36252b 100644 --- a/www/data/css/styles.css +++ b/www/data/css/styles.css @@ -1900,6 +1900,7 @@ html, body { /* 400px */ .ev_master { align-self: center; + width: 100%; } @media (min-width: 851px) { .ev_master { @@ -1918,6 +1919,15 @@ html, body { text-align: center; font-size: 25pt; } +.ev_master .ev_statusmore { + color: #333333; + background-color: #BBBBBB; + text-align: left; + padding: 4px; + overflow-x: auto; + white-space: nowrap; + width: 100%; +} @media (max-width: 767px) { .ev_master .ev_code { font-size: 75pt; diff --git a/www/data/css/styles.min.css b/www/data/css/styles.min.css index e2e9758..1995694 100644 --- a/www/data/css/styles.min.css +++ b/www/data/css/styles.min.css @@ -360,10 +360,11 @@ html,body{margin:0;padding:0;height:100%} .wle_date{border-bottom:1px solid transparent;padding:2px;font-size:.8em;font-style:italic} .wle_title{font-weight:bold;font-size:1.2em;text-align:left;margin:2px 0 2px 10px} @media(max-width:767px){.wle_title{font-size:1.25em}} -.ev_master{align-self:center} +.ev_master{align-self:center;width:100%} @media(min-width:851px){.ev_master{padding-bottom:80px}} .ev_master .ev_code{color:#333;text-align:center;font-size:150pt;font-weight:500;font-family:Consolas,Monaco,"Courier New",Menlo,monospace} .ev_master .ev_msg{color:#888;text-align:center;font-size:25pt} +.ev_master .ev_statusmore{color:#333;background-color:#bbb;text-align:left;padding:4px;overflow-x:auto;white-space:nowrap;width:100%} @media(max-width:767px){ .ev_master .ev_code{font-size:75pt} .ev_master .ev_msg{font-size:15pt} diff --git a/www/data/css/styles_errorview.scss b/www/data/css/styles_errorview.scss index cf45298..4cdd822 100644 --- a/www/data/css/styles_errorview.scss +++ b/www/data/css/styles_errorview.scss @@ -3,6 +3,7 @@ .ev_master { align-self: center; + width: 100%; @include rdmedia_range(2,4) {padding-bottom: 80px;} @@ -20,6 +21,18 @@ font-size: 25pt; } + .ev_statusmore { + color: $LAYER1_FG; + background-color: $LAYER1_BG_DARKER; + text-align: left; + padding: 4px; + + overflow-x: auto; + white-space: nowrap; + + width: 100%; + } + @include rdmedia(0) { .ev_code { font-size: 75pt; } .ev_msg { font-size: 15pt; } diff --git a/www/fragments/panel_aoc.php b/www/fragments/panel_aoc.php index ce70235..ac34542 100644 --- a/www/fragments/panel_aoc.php +++ b/www/fragments/panel_aoc.php @@ -1,22 +1,28 @@ + +modules->AdventOfCode()->listYears(); +$year = intval(end($years)); ?>
- $year, 'nav'=>true, 'linkheader'=>true, 'ajax'=>true]; - require (__DIR__ . '/../fragments/panel_aoc_calendar.php') - ?> + fragments->PanelAdventOfCodeCalendar($year, true, true, true); ?>
diff --git a/www/fragments/panel_aoc_calendar.php b/www/fragments/panel_aoc_calendar.php index da5f72c..431d72b 100644 --- a/www/fragments/panel_aoc_calendar.php +++ b/www/fragments/panel_aoc_calendar.php @@ -1,19 +1,30 @@ -$assocdays = AdventOfCode::listSingleYearAssociative($year); -$prev_year = $shownav ? AdventOfCode::getPrevYear($year) : null; -$next_year = $shownav ? AdventOfCode::getNextYear($year) : null; +modules->AdventOfCode(); + +$assocdays = $AOC->listSingleYearAssociative($year); +$prev_year = $shownav ? $AOC->getPrevYear($year) : null; +$next_year = $shownav ? $AOC->getNextYear($year) : null; + +if ($ajax) $FRAME_OPTIONS->addScript("/data/javascript/aoc_panel_interactive.js", true); ?> @@ -26,14 +37,14 @@ if ($ajax) includeAdditionalScript("/data/javascript/aoc_panel_interactive.js", if ($ajax) echo '<'; else - echo '<'; + echo '<'; } else { echo '<'; } - if ($linkheader) echo ''.$year.''; + if ($linkheader) echo ''.$year.''; else echo ''.$year.''; if ($next_year !== null) @@ -41,7 +52,7 @@ if ($ajax) includeAdditionalScript("/data/javascript/aoc_panel_interactive.js", if ($ajax) echo '>'; else - echo '>'; + echo '>'; } else { diff --git a/www/fragments/panel_blog.php b/www/fragments/panel_blog.php index a3804d6..f5b5284 100644 --- a/www/fragments/panel_blog.php +++ b/www/fragments/panel_blog.php @@ -1,7 +1,19 @@ + +modules->Blog(); + + $allposts = $BLOG->listAllNewestFirst(); ?>
diff --git a/www/fragments/panel_books.php b/www/fragments/panel_books.php index 6f53726..9209902 100644 --- a/www/fragments/panel_books.php +++ b/www/fragments/panel_books.php @@ -1,7 +1,19 @@ + +modules->Books(); + + $allbooks = $BOOKS->listAllNewestFirst(); ?>
diff --git a/www/fragments/panel_euler.php b/www/fragments/panel_euler.php index 294880d..143859a 100644 --- a/www/fragments/panel_euler.php +++ b/www/fragments/panel_euler.php @@ -1,7 +1,19 @@ + +modules->Euler(); + + $data = $EULER->listAll(); $RATING_CLASSES = ['euler_pnl_celltime_perfect', 'euler_pnl_celltime_good', 'euler_pnl_celltime_ok', 'euler_pnl_celltime_bad', 'euler_pnl_celltime_fail']; ?> @@ -18,7 +30,7 @@ $arr = []; $max = 0; - foreach ($euler as $problem) + foreach ($data as $problem) { $max = max($max, $problem['number']); $arr[$problem['number']] = $problem; diff --git a/www/fragments/panel_programs.php b/www/fragments/panel_programs.php index c0b15ce..63ab45b 100644 --- a/www/fragments/panel_programs.php +++ b/www/fragments/panel_programs.php @@ -1,7 +1,19 @@ + +modules->Programs(); + + $allprograms = $PROGRAMS->listAllNewestFirst(); ?>
diff --git a/www/frames/default_frame.php b/www/frames/default_frame.php index 713a2a0..73167ac 100644 --- a/www/frames/default_frame.php +++ b/www/frames/default_frame.php @@ -20,7 +20,7 @@ require_once (__DIR__ . '/../internals/website.php'); foreach ($FRAME_OPTIONS->stylesheets as $cssfile) echo ''; foreach ($FRAME_OPTIONS->scripts as $scriptfile) { - if ($scriptfile[1]) echo ''; else echo ''; } ?> diff --git a/www/frames/error_frame.php b/www/frames/error_frame.php new file mode 100644 index 0000000..fc390a3 --- /dev/null +++ b/www/frames/error_frame.php @@ -0,0 +1,52 @@ + + + + + + + + <?php echo $FRAME_OPTIONS->title; ?> + + + + + +
+ +
+
+ +
+ + + +
+ +
+ raw; ?> +
+ +
+
+ made with vanilla PHP and MySQL, no frameworks, no bootstrap, no unnecessary* javascript +
+ +
+ + \ No newline at end of file diff --git a/www/internals/alephnoteStatistics.php b/www/internals/alephnoteStatistics.php deleted file mode 100644 index 1f1be2b..0000000 --- a/www/internals/alephnoteStatistics.php +++ /dev/null @@ -1,34 +0,0 @@ -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'); - } -} \ No newline at end of file diff --git a/www/internals/fragments.php b/www/internals/fragments.php new file mode 100644 index 0000000..20d7059 --- /dev/null +++ b/www/internals/fragments.php @@ -0,0 +1,48 @@ + $year, 'nav'=>$shownav, 'linkheader'=>$linkheader, 'ajax'=>$ajax, 'frame'=>$frame, 'frameid'=>$frameid ]; + include (__DIR__ . '/../fragments/panel_aoc_calendar.php'); + } +} \ No newline at end of file diff --git a/www/internals/modules.php b/www/internals/modules.php new file mode 100644 index 0000000..ac5288c --- /dev/null +++ b/www/internals/modules.php @@ -0,0 +1,86 @@ +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; + } + +} \ No newline at end of file diff --git a/www/internals/adventofcode.php b/www/internals/modules/adventofcode.php similarity index 98% rename from www/internals/adventofcode.php rename to www/internals/modules/adventofcode.php index 6727462..7348973 100644 --- a/www/internals/adventofcode.php +++ b/www/internals/modules/adventofcode.php @@ -1,7 +1,5 @@ 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'); + } +} \ No newline at end of file diff --git a/www/internals/blog.php b/www/internals/modules/blog.php similarity index 89% rename from www/internals/blog.php rename to www/internals/modules/blog.php index dfc6173..9d589c2 100644 --- a/www/internals/blog.php +++ b/www/internals/modules/blog.php @@ -1,7 +1,5 @@ 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; diff --git a/www/internals/books.php b/www/internals/modules/books.php similarity index 98% rename from www/internals/books.php rename to www/internals/modules/books.php index 7265e58..6206f96 100644 --- a/www/internals/books.php +++ b/www/internals/modules/books.php @@ -1,7 +1,5 @@ staticData = array_map(function($a){return self::readSingle($a);}, $all); } diff --git a/www/internals/database.php b/www/internals/modules/database.php similarity index 98% rename from www/internals/database.php rename to www/internals/modules/database.php index 70327e9..e19ed6c 100644 --- a/www/internals/database.php +++ b/www/internals/modules/database.php @@ -1,7 +1,5 @@ staticData = array_map(function($a){return self::readSingle($a);}, $all); } diff --git a/www/internals/mikeschergitgraph.php b/www/internals/modules/mikeschergitgraph.php similarity index 80% rename from www/internals/mikeschergitgraph.php rename to www/internals/modules/mikeschergitgraph.php index 86e55ad..78259c2 100644 --- a/www/internals/mikeschergitgraph.php +++ b/www/internals/modules/mikeschergitgraph.php @@ -1,7 +1,6 @@ getPathRenderedData(); + $p = $this->getPathRenderedData(); if (!file_exists($p)) return ['result'=>'err', 'message' => 'Rendered data not found']; diff --git a/www/internals/programs.php b/www/internals/modules/programs.php similarity index 98% rename from www/internals/programs.php rename to www/internals/modules/programs.php index 83bea9d..231d4ff 100644 --- a/www/internals/programs.php +++ b/www/internals/modules/programs.php @@ -1,7 +1,5 @@ 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() diff --git a/www/internals/updateslog.php b/www/internals/modules/updateslog.php similarity index 55% rename from www/internals/updateslog.php rename to www/internals/modules/updateslog.php index 01ee07d..9c7f3da 100644 --- a/www/internals/updateslog.php +++ b/www/internals/modules/updateslog.php @@ -1,7 +1,5 @@ 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], diff --git a/www/internals/webapps.php b/www/internals/modules/webapps.php similarity index 83% rename from www/internals/webapps.php rename to www/internals/modules/webapps.php index b310749..0f9c53e 100644 --- a/www/internals/webapps.php +++ b/www/internals/modules/webapps.php @@ -1,7 +1,5 @@ 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; } -} - - +} \ No newline at end of file diff --git a/www/internals/ruleengine.php b/www/internals/ruleengine.php index 1f96f5a..35e27ad 100644 --- a/www/internals/ruleengine.php +++ b/www/internals/ruleengine.php @@ -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(); diff --git a/www/internals/urlroute.php b/www/internals/urlroute.php index 0ba3f79..d8f1583 100644 --- a/www/internals/urlroute.php +++ b/www/internals/urlroute.php @@ -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(); + } } /** diff --git a/www/internals/utils.php b/www/internals/utils.php index 431262a..0c0a993 100644 --- a/www/internals/utils.php +++ b/www/internals/utils.php @@ -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('
', "\n", $xdbg); $xdbg = str_replace('
', "\n", $xdbg); $xdbg = str_replace('
', "\n", $xdbg); + $xdbg = str_replace('><', "> <", $xdbg); $xdbg = strip_tags($xdbg); $xdbg = htmlspecialchars($xdbg); $r .= $xdbg . "\n"; diff --git a/www/internals/website.php b/www/internals/website.php index 3c18f5c..cee7047 100644 --- a/www/internals/website.php +++ b/www/internals/website.php @@ -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 */ diff --git a/www/pages/error_servererror.php b/www/pages/error_servererror.php index 72e4527..0a3d289 100644 --- a/www/pages/error_servererror.php +++ b/www/pages/error_servererror.php @@ -1,34 +1,26 @@ - - - - - Mikescher.com - <?php echo $errormsg; ?> - - - - -
- +title = 'Mikescher.com - Error'; +$FRAME_OPTIONS->canonical_url = null; +$FRAME_OPTIONS->activeHeader = null; +$FRAME_OPTIONS->contentCSSClasses []= 'content-fullheight'; -
+$message = $ROUTE->parameter['message']; +$debuginfo = $ROUTE->parameter['debuginfo']; +?> -
-
-
-
-
- -
- - - - \ No newline at end of file +
+
500
+
asdasd
+ 0 && ($SITE != null && !$SITE->isProd())): ?> +

+ +
\ No newline at end of file diff --git a/www/pages/main.php b/www/pages/main.php index ea37c14..3bda4c9 100644 --- a/www/pages/main.php +++ b/www/pages/main.php @@ -6,12 +6,18 @@ require_once (__DIR__ . '/../internals/website.php'); /** @var Website $SITE */ global $SITE; ?> - +title = 'Mikescher.com'; +$FRAME_OPTIONS->canonical_url = 'https://www.mikescher.com'; +$FRAME_OPTIONS->activeHeader = 'home'; +?> - +fragments->PanelEuler(); ?> - +fragments->PanelPrograms(); ?> - +fragments->PanelBlog(); ?> - \ No newline at end of file +fragments->PanelBooks(); ?> + +fragments->PanelAdventOfCode(); ?> From 76b4709d1ac7b815fc0d70d3b6d6f337d16e05b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer=20=28Macbook=29?= Date: Thu, 16 Jan 2020 10:07:14 +0100 Subject: [PATCH 15/33] cleanup compress.py --- data/css_compress/compress.py | 151 +++++++++++++++++----------------- 1 file changed, 77 insertions(+), 74 deletions(-) diff --git a/data/css_compress/compress.py b/data/css_compress/compress.py index 6072e02..0dd97db 100644 --- a/data/css_compress/compress.py +++ b/data/css_compress/compress.py @@ -2,78 +2,83 @@ import sys import os -from subprocess import call import re import subprocess -def findnext(str, start, chr): - depth = 0 - for i in range(start, len(str)): - if (str[i] == chr): return i; -def findclose(str, start): +def findnext(strdata, start, searchchr): depth = 0 - for i in range(start, len(str)): - if (str[i] == '{'): depth = depth+1; - if (str[i] == '}'): depth = depth-1; - if (depth == 0): return i; + for i in range(start, len(strdata)): + if strdata[i] == searchchr: return i; -def countnl(str, start, end): + +def findclose(strdata, start): + depth = 0 + for i in range(start, len(strdata)): + if strdata[i] == '{': depth = depth + 1; + if strdata[i] == '}': depth = depth - 1; + if depth == 0: return i; + + +def countnl(strdata, start, end): cnt = 0 - for i in range(start, end+1): - if (str[i] == '\n'): cnt = cnt+1; - return cnt; + for i in range(start, end + 1): + if strdata[i] == '\n': cnt = cnt + 1; + return cnt + def comment_remover(text): def replacer(match): s = match.group(0) if s.startswith('/'): - return " " # note: a space and not an empty string + return " " # note: a space and not an empty string else: return s + pattern = re.compile( r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"', re.DOTALL | re.MULTILINE ) return re.sub(pattern, replacer, text) + fsource = str.replace(sys.argv[1], '\\', '/') # scss -finput = str.replace(sys.argv[2], '\\', '/') # css +finput = str.replace(sys.argv[2], '\\', '/') # css foutput = str.replace(sys.argv[3], '\\', '/') # min.css -ftemp1 = '__temp_compresss_py_1.tmp.css'; -ftemp2 = '__temp_compresss_py_2.tmp.css'; +ftemp1 = '__temp_compresss_py_1.tmp.css' +ftemp2 = '__temp_compresss_py_2.tmp.css' -print('======== INPUT ========'); -print(); -print(fsource); -print(finput); -print(foutput); -print(); -print(); +print('======== INPUT ========') +print() +print(fsource) +print(finput) +print(foutput) +print() +print() -print('======== DELETE OLD DATA ========'); +print('======== DELETE OLD DATA ========') if os.path.isfile(finput): - try: - os.remove(finput); - print(finput + ' deleted') - except: - print(sys.exc_info()[0]) + try: + os.remove(finput) + print(finput + ' deleted') + except: + print(sys.exc_info()[0]) else: - print(finput + ' does not exist') + print(finput + ' does not exist') if os.path.isfile(foutput): - try: - os.remove(foutput); - print(foutput + ' deleted') - except: - print(sys.exc_info()[0]) + try: + os.remove(foutput) + print(foutput + ' deleted') + except: + print(sys.exc_info()[0]) else: - print(foutput + ' does not exist') -print(); -print(); + print(foutput + ' does not exist') +print() +print() - -print('======== CALL SCSS ========'); -out = subprocess.run(['ruby', 'scss', '--style=expanded', '--no-cache', '--update', fsource + ':' + finput], stdout=subprocess.PIPE, stderr=subprocess.PIPE) +print('======== CALL SCSS ========') +out = subprocess.run(['ruby', 'scss', '--style=expanded', '--no-cache', '--update', fsource + ':' + finput], + stdout=subprocess.PIPE, stderr=subprocess.PIPE) print('> scss.bat --style=expanded --no-cache --update ' + fsource + ':' + finput) print('STDOUT:') print(out.stdout.decode('utf-8')) @@ -83,13 +88,13 @@ print(out.stderr.decode('utf-8')) print('') print('') -print('======== CLEANUP COMMENTS ========'); +print('======== CLEANUP COMMENTS ========') with open(finput, 'r') as tf: data1 = tf.read() print(str(len(data1)) + ' characters read from ' + os.path.basename(finput)) data1 = comment_remover(data1) -print('Comments in css removed'); +print('Comments in css removed') with open(ftemp1, "w") as tf: tf.write(data1) @@ -98,19 +103,19 @@ with open(ftemp1, "w") as tf: print('') print('') - -print('======== CALL YUI ========'); -out = subprocess.run(['java', '-jar', 'yuicompressor.jar', '--verbose', ftemp1, '-o', ftemp2], stdout=subprocess.PIPE, stderr=subprocess.PIPE) -print('> java -jar yuicompressor.jar --verbose "'+finput+'" -o "'+ftemp2+'"') -print('STDOUT:'); +print('======== CALL YUI ========') +out = subprocess.run(['java', '-jar', 'yuicompressor.jar', '--verbose', ftemp1, '-o', ftemp2], stdout=subprocess.PIPE, + stderr=subprocess.PIPE) +print('> java -jar yuicompressor.jar --verbose "' + finput + '" -o "' + ftemp2 + '"') +print('STDOUT:') print(out.stdout.decode('utf-8')) -print('STDERR:'); +print('STDERR:') print(out.stderr.decode('utf-8')) print('') print('') -print('======== READ ========'); +print('======== READ ========') with open(ftemp2, 'r') as tf: data = tf.read() print(str(len(data)) + ' characters read from ' + ftemp2) @@ -118,11 +123,11 @@ with open(ftemp2, 'r') as tf: print('') print('') -print('======== REM ========'); +print('======== REM ========') try: - os.remove(ftemp1); + os.remove(ftemp1) print(ftemp1 + ' deleted') - os.remove(ftemp2); + os.remove(ftemp2) print(ftemp2 + ' deleted') except: print(sys.exc_info()[0]) @@ -130,30 +135,29 @@ except: print('') print('') -print('======== REGEX ========'); -data = re.sub(r'(\}*\})', '\g<1>\n', data); +print('======== REGEX ========') +data = re.sub(r'(\}*\})', '\g<1>\n', data) print('css data modified (1)') print('') print('') -print('======== MEDIA ========'); +print('======== MEDIA ========') ins = [] for i in range(len(data)): if data[i:].startswith('@media'): - copen = findnext(data, i, '{') cclose = findclose(data, copen) - if (countnl(data, copen, cclose) == 0): continue; + if countnl(data, copen, cclose) == 0: continue; - ins.append( (copen+1, '\n\t') ) - for i in range(copen+1, cclose): - if data[i] == '\n': - tp =(i+1, '\t') - ins.append( tp ) + ins.append((copen + 1, '\n\t')) + for i2 in range(copen + 1, cclose): + if data[i2] == '\n': + tp = (i2 + 1, '\t') + ins.append(tp) ins.append((cclose, '\n')) print('media query at idx:' + str(i) + ' formatted') @@ -163,7 +167,7 @@ for (l, c) in reversed(ins): print('') print('') -print('======== WRITE ========'); +print('======== WRITE ========') with open(foutput, "w") as tf: tf.write(data) print(str(len(data)) + ' characters written to ' + foutput) @@ -171,18 +175,17 @@ with open(foutput, "w") as tf: print('') print('') -print('======== REMOVE MAP ========'); +print('======== REMOVE MAP ========') if os.path.isfile(finput + '.map'): - try: - os.remove(finput + '.map'); - print(finput + '.map' + ' deleted') - except e: - print(e) + try: + os.remove(finput + '.map') + print(finput + '.map' + ' deleted') + except Exception as e: + print(e) else: - print(finput + '.map' + ' does not exist') + print(finput + '.map' + ' does not exist') print('') print('') - print('Finished.') From 987a0a3c1253d59ae0e4790983b4965f135301bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer=20=28Macbook=29?= Date: Thu, 16 Jan 2020 10:50:18 +0100 Subject: [PATCH 16/33] Blogview --- .idea/watcherTasks.xml | 2 +- www/fragments/blogview_markdown.php | 21 ++++--- www/fragments/blogview_plain.php | 17 ++++- www/frames/default_frame.php | 2 +- www/frames/error_frame.php | 2 +- www/internals/fragments.php | 42 +++++++++++++ www/internals/modules/blog.php | 8 ++- www/internals/pageframeoptions.php | 6 ++ www/internals/parsedowncustom.php | 3 +- www/internals/website.php | 13 +++- www/pages/blog_view.php | 97 ++++++++++++----------------- www/pages/error_notfound.php | 44 +++++-------- www/pages/error_servererror.php | 2 +- 13 files changed, 156 insertions(+), 103 deletions(-) diff --git a/.idea/watcherTasks.xml b/.idea/watcherTasks.xml index f8a509b..5ef69a0 100644 --- a/.idea/watcherTasks.xml +++ b/.idea/watcherTasks.xml @@ -34,7 +34,7 @@
\ No newline at end of file diff --git a/www/fragments/blogview_plain.php b/www/fragments/blogview_plain.php index 765ecfe..92d8ecb 100644 --- a/www/fragments/blogview_plain.php +++ b/www/fragments/blogview_plain.php @@ -1,6 +1,17 @@ + +
@@ -10,7 +21,7 @@ require_once (__DIR__ . '/../internals/blog.php');
- + modules->Blog()->getPostFragment($post))); ?>
\ No newline at end of file diff --git a/www/frames/default_frame.php b/www/frames/default_frame.php index 73167ac..46247fc 100644 --- a/www/frames/default_frame.php +++ b/www/frames/default_frame.php @@ -12,7 +12,7 @@ require_once (__DIR__ . '/../internals/website.php'); - <?php echo $FRAME_OPTIONS->title; ?> + <?php echo htmlspecialchars($FRAME_OPTIONS->title); ?> - <?php echo $FRAME_OPTIONS->title; ?> + <?php echo htmlspecialchars($FRAME_OPTIONS->title); ?> diff --git a/www/internals/fragments.php b/www/internals/fragments.php index 20d7059..e73a840 100644 --- a/www/internals/fragments.php +++ b/www/internals/fragments.php @@ -45,4 +45,46 @@ class Fragments $FRAGMENT_PARAM = [ 'year' => $year, 'nav'=>$shownav, 'linkheader'=>$linkheader, 'ajax'=>$ajax, 'frame'=>$frame, 'frameid'=>$frameid ]; include (__DIR__ . '/../fragments/panel_aoc_calendar.php'); } + + public function BlogviewPlain(array $blogpost) + { + global $FRAGMENT_PARAM; + $FRAGMENT_PARAM = [ 'blogpost' => $blogpost ]; + include (__DIR__ . '/../fragments/blogview_plain.php'); + } + + public function BlogviewMarkdown(array $blogpost) + { + global $FRAGMENT_PARAM; + $FRAGMENT_PARAM = [ 'blogpost' => $blogpost ]; + include (__DIR__ . '/../fragments/blogview_markdown.php'); + } + + public function BlogviewEulerList(array $blogpost) + { + global $FRAGMENT_PARAM; + $FRAGMENT_PARAM = [ 'blogpost' => $blogpost ]; + include (__DIR__ . '/../fragments/blogview_euler_list.php'); + } + + public function BlogviewEulerSingle(array $blogpost, string $subview) + { + global $FRAGMENT_PARAM; + $FRAGMENT_PARAM = [ 'blogpost' => $blogpost, 'subview' => $subview ]; + include (__DIR__ . '/../fragments/blogview_euler_single.php'); + } + + public function BlogviewAdventOfCodeList(array $blogpost) + { + global $FRAGMENT_PARAM; + $FRAGMENT_PARAM = [ 'blogpost' => $blogpost ]; + include (__DIR__ . '/../fragments/blogview_aoc_list.php'); + } + + public function BlogviewAdventOfCodeSingle(array $blogpost, string $subview) + { + global $FRAGMENT_PARAM; + $FRAGMENT_PARAM = [ 'blogpost' => $blogpost, 'subview' => $subview ]; + include (__DIR__ . '/../fragments/blogview_aoc_single.php'); + } } \ No newline at end of file diff --git a/www/internals/modules/blog.php b/www/internals/modules/blog.php index 9d589c2..095c2c7 100644 --- a/www/internals/modules/blog.php +++ b/www/internals/modules/blog.php @@ -26,7 +26,7 @@ class Blog $d['canonical'] = "https://www.mikescher.com" . $d['url']; - $d['file_fragment'] = __DIR__ . '/../statics/blog/' . $d['fragment']; + $d['file_fragment'] = __DIR__ . '/../../statics/blog/' . $d['fragment']; if (!array_key_exists('extras', $d)) $d['extras'] = []; @@ -53,6 +53,12 @@ class Blog return null; } + /** + * @param string $id + * @param string $subview + * @param string $error + * @return array|null + */ public function getFullBlogpost($id, $subview, &$error) { $post = $this->getBlogpost($id); diff --git a/www/internals/pageframeoptions.php b/www/internals/pageframeoptions.php index 726d00e..a8534d4 100644 --- a/www/internals/pageframeoptions.php +++ b/www/internals/pageframeoptions.php @@ -58,4 +58,10 @@ class PageFrameOptions $this->scripts []= [ $url, $defer ]; } + + public function setForced404(string $err) + { + $this->force_404 = true; + $this->force_404_message = $err; + } } \ No newline at end of file diff --git a/www/internals/parsedowncustom.php b/www/internals/parsedowncustom.php index e6304d7..6ef1164 100644 --- a/www/internals/parsedowncustom.php +++ b/www/internals/parsedowncustom.php @@ -1,6 +1,5 @@ force_404) { - $this->serveCustom404($route->full_url, $result); + $this->serveCustom404($route->full_url, $result, $result->force_404_message); exit(); } @@ -79,7 +79,7 @@ class Website } } - private function serveCustom404(string $uri, PageFrameOptions $frameOpt) + private function serveCustom404(string $uri, PageFrameOptions $frameOpt, string $message) { try { @@ -88,6 +88,8 @@ class Website $route = URLRoute::getNotFoundRoute($uri); + $route->parameter['message'] = $message; + $result = $route->getDirect($this, $frameOpt); $this->output($result, $route); @@ -184,6 +186,13 @@ class Website setcookie("mikescher_auth", "", time()+30); } + public function renderMarkdown(string $txt) + { + require_once 'parsedowncustom.php'; + $pd = new ParsedownCustom(); + return $pd->text($txt); + } + } /** diff --git a/www/pages/blog_view.php b/www/pages/blog_view.php index 72e9a7b..5d676fa 100644 --- a/www/pages/blog_view.php +++ b/www/pages/blog_view.php @@ -1,72 +1,55 @@ - - - - - Mikescher.com - <?php echo htmlspecialchars($post['title']); ?> - - - '; ?> - - -
- - -
+parameter['id']; +$subview = $ROUTE->parameter['subview']; -
+$post = $SITE->modules->Blog()->getFullBlogpost($id, $subview, $err); +if ($post === null) { $FRAME_OPTIONS->setForced404($err); return; } -


+$FRAME_OPTIONS->title = 'Mikescher.com - ' . $post['title']; +$FRAME_OPTIONS->canonical_url = $post['canonical']; - activeHeader = 'euler'; +else if ($post['type'] == 'euler' && $post['issubview']) + $FRAME_OPTIONS->activeHeader = 'aoc'; +else + $FRAME_OPTIONS->activeHeader = 'blog'; +?> - if ($post['type'] === 'plain') { - include (__DIR__ . '/../fragments/blogview_plain.php'); +
- } elseif ($post['type'] === 'markdown') { +


- include (__DIR__ . '/../fragments/blogview_markdown.php'); + - -
+ if ($post['type'] === 'plain') + { + $SITE->fragments->BlogviewPlain($post); + } + elseif ($post['type'] === 'markdown') + { + $SITE->fragments->BlogviewMarkdown($post); + } + elseif ($post['type'] === 'euler') + { + if ($subview === '') $SITE->fragments->BlogviewEulerList($post); + else $SITE->fragments->BlogviewEulerSingle($post, $subview); + } + elseif ($post['type'] === 'aoc') + { + if ($subview === '') $SITE->fragments->BlogviewAdventOfCodeList($post); + else $SITE->fragments->BlogviewAdventOfCodeSingle($post, $subview); + } + ?>
- - -
- - - - \ No newline at end of file diff --git a/www/pages/error_notfound.php b/www/pages/error_notfound.php index 72e4527..1e7ee02 100644 --- a/www/pages/error_notfound.php +++ b/www/pages/error_notfound.php @@ -1,34 +1,24 @@ - - - - - Mikescher.com - <?php echo $errormsg; ?> - - - - -
- +parameter['message']) ? $ROUTE->parameter['message'] : ''; -
+$FRAME_OPTIONS->title = 'Mikescher.com - ' . $message; +$FRAME_OPTIONS->canonical_url = null; +$FRAME_OPTIONS->activeHeader = null; +$FRAME_OPTIONS->contentCSSClasses []= 'content-fullheight'; +?> -
-
-
-
-
- -
- - - - \ No newline at end of file +
+
404
+ +
+ +
\ No newline at end of file diff --git a/www/pages/error_servererror.php b/www/pages/error_servererror.php index 0a3d289..10097d0 100644 --- a/www/pages/error_servererror.php +++ b/www/pages/error_servererror.php @@ -19,7 +19,7 @@ $debuginfo = $ROUTE->parameter['debuginfo'];
500
-
asdasd
+
0 && ($SITE != null && !$SITE->isProd())): ?>

From dc483ea4fde55cb212319153f16e1443ca30db27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer=20=28Macbook=29?= Date: Thu, 16 Jan 2020 10:56:12 +0100 Subject: [PATCH 17/33] BlogList --- www/frames/default_frame.php | 2 +- www/frames/error_frame.php | 2 +- www/pages/blog_list.php | 67 ++++++++++++--------------------- www/pages/blog_view.php | 2 +- www/pages/error_notfound.php | 2 +- www/pages/error_servererror.php | 2 +- www/pages/main.php | 2 +- 7 files changed, 31 insertions(+), 48 deletions(-) diff --git a/www/frames/default_frame.php b/www/frames/default_frame.php index 46247fc..d0221c6 100644 --- a/www/frames/default_frame.php +++ b/www/frames/default_frame.php @@ -12,7 +12,7 @@ require_once (__DIR__ . '/../internals/website.php'); - <?php echo htmlspecialchars($FRAME_OPTIONS->title); ?> + <?php echo ($FRAME_OPTIONS->title !== '') ? htmlspecialchars('Mikescher.com - ' . $FRAME_OPTIONS->title) : 'Mikescher.com'; ?> - <?php echo htmlspecialchars($FRAME_OPTIONS->title); ?> + <?php echo ($FRAME_OPTIONS->title !== '') ? htmlspecialchars('Mikescher.com - ' . $FRAME_OPTIONS->title) : 'Mikescher.com'; ?> diff --git a/www/pages/blog_list.php b/www/pages/blog_list.php index 0c5a494..e97483a 100644 --- a/www/pages/blog_list.php +++ b/www/pages/blog_list.php @@ -1,55 +1,38 @@ - - - - - Mikescher.com - Blog - - - - - -
- +title = 'Blog'; +$FRAME_OPTIONS->canonical_url = 'https://www.mikescher.com/blog'; +$FRAME_OPTIONS->activeHeader = 'blog'; -
+$allposts = $SITE->modules->Blog()->listAllNewestFirst(); +?> -
+
-

Blogposts and other stuff


+

Blogposts and other stuff


- - -
+ ?> +
- - - -
- - - - \ No newline at end of file diff --git a/www/pages/blog_view.php b/www/pages/blog_view.php index 5d676fa..62fb473 100644 --- a/www/pages/blog_view.php +++ b/www/pages/blog_view.php @@ -13,7 +13,7 @@ $subview = $ROUTE->parameter['subview']; $post = $SITE->modules->Blog()->getFullBlogpost($id, $subview, $err); if ($post === null) { $FRAME_OPTIONS->setForced404($err); return; } -$FRAME_OPTIONS->title = 'Mikescher.com - ' . $post['title']; +$FRAME_OPTIONS->title = $post['title']; $FRAME_OPTIONS->canonical_url = $post['canonical']; if ($post['type'] == 'euler') diff --git a/www/pages/error_notfound.php b/www/pages/error_notfound.php index 1e7ee02..d1cc388 100644 --- a/www/pages/error_notfound.php +++ b/www/pages/error_notfound.php @@ -9,7 +9,7 @@ require_once (__DIR__ . '/../internals/website.php'); parameter['message']) ? $ROUTE->parameter['message'] : ''; -$FRAME_OPTIONS->title = 'Mikescher.com - ' . $message; +$FRAME_OPTIONS->title = $message; $FRAME_OPTIONS->canonical_url = null; $FRAME_OPTIONS->activeHeader = null; $FRAME_OPTIONS->contentCSSClasses []= 'content-fullheight'; diff --git a/www/pages/error_servererror.php b/www/pages/error_servererror.php index 10097d0..5a61038 100644 --- a/www/pages/error_servererror.php +++ b/www/pages/error_servererror.php @@ -7,7 +7,7 @@ require_once (__DIR__ . '/../internals/website.php'); ?> title = 'Mikescher.com - Error'; +$FRAME_OPTIONS->title = 'Error'; $FRAME_OPTIONS->canonical_url = null; $FRAME_OPTIONS->activeHeader = null; $FRAME_OPTIONS->contentCSSClasses []= 'content-fullheight'; diff --git a/www/pages/main.php b/www/pages/main.php index 3bda4c9..917d890 100644 --- a/www/pages/main.php +++ b/www/pages/main.php @@ -7,7 +7,7 @@ require_once (__DIR__ . '/../internals/website.php'); ?> title = 'Mikescher.com'; +$FRAME_OPTIONS->title = ''; $FRAME_OPTIONS->canonical_url = 'https://www.mikescher.com'; $FRAME_OPTIONS->activeHeader = 'home'; ?> From cdec6903f607ee786c2450072490e3b479d6c1f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer=20=28Macbook=29?= Date: Thu, 16 Jan 2020 11:05:38 +0100 Subject: [PATCH 18/33] BooksList+BooksView --- www/frames/default_frame.php | 8 +- www/pages/books_list.php | 85 +++++++--------- www/pages/books_view.php | 181 ++++++++++++++++------------------- 3 files changed, 121 insertions(+), 153 deletions(-) diff --git a/www/frames/default_frame.php b/www/frames/default_frame.php index d0221c6..9f4a928 100644 --- a/www/frames/default_frame.php +++ b/www/frames/default_frame.php @@ -16,12 +16,12 @@ require_once (__DIR__ . '/../internals/website.php'); canonical_url !== null) echo ''; - foreach ($FRAME_OPTIONS->stylesheets as $cssfile) echo ''; + if ($FRAME_OPTIONS->canonical_url !== null) echo '' . "\n"; + foreach ($FRAME_OPTIONS->stylesheets as $cssfile) echo '' . "\n"; foreach ($FRAME_OPTIONS->scripts as $scriptfile) { - if ($scriptfile[1]) echo ''; - else echo ''; + if ($scriptfile[1]) echo '' . "\n"; + else echo '' . "\n"; } ?> diff --git a/www/pages/books_list.php b/www/pages/books_list.php index fe98383..32688cc 100644 --- a/www/pages/books_list.php +++ b/www/pages/books_list.php @@ -1,64 +1,47 @@ - - - - - Mikescher.com - Converted Books - - - - - -
- +title = 'Converted Books'; +$FRAME_OPTIONS->canonical_url = 'https://www.mikescher.com/books'; +$FRAME_OPTIONS->activeHeader = 'books'; -
+$allbooks = $SITE->modules->Books()->listAllNewestFirst(); +?> -
+
-

Books/Webserials I self-printed


+

Books/Webserials I self-printed


-

- These are some books I read but that do not have an official print version.
- So I type-setted them myself (mostly in LyX) and printed them online.
- I do not own the rights of any of these books.
- The LyX files and generated PDF's are public and everyone who wants can print them on his own. -

+

+ These are some books I read but that do not have an official print version.
+ So I type-setted them myself (mostly in LyX) and printed them online.
+ I do not own the rights of any of these books.
+ The LyX files and generated PDF's are public and everyone who wants can print them on his own. +

- ' . "\n"; - foreach ($allbooks as $book) - { - echo ''; - echo '
'; - echo ' Thumbnail '  . $book['title'] . ''; - echo '
'; - echo '
'; - echo '
' . $book['date'] . '
'; - echo '
' . htmlspecialchars($book['title']) . '
'; - echo '
'; - echo '
' . "\n"; - } - echo '
' . "\n"; + echo '' . "\n"; - ?> - -
- -
- - + ?>
- - - - \ No newline at end of file diff --git a/www/pages/books_view.php b/www/pages/books_view.php index 4df3087..59de11a 100644 --- a/www/pages/books_view.php +++ b/www/pages/books_view.php @@ -1,127 +1,112 @@ - - - - - Mikescher.com - <?php echo $book['title']; ?> - - - '; ?> - - - -
- +parameter['id']; -
+$book = $SITE->modules->Books()->getBook($id); +if ($book === null) { $FRAME_OPTIONS->setForced404("Books not found"); return; } -
+$FRAME_OPTIONS->title = $book['title']; +$FRAME_OPTIONS->canonical_url = $book['url']; +$FRAME_OPTIONS->activeHeader = 'book'; -
+$FRAME_OPTIONS->addScript('/data/javascript/ms_basic.js', true); +?> -


-
-
<?php echo $book['title'] ?>
-
-
Name:
-
+
-
Pages:
-
'; - $pagi++; - } - } - ?>
+ -
- + +
- - - - \ No newline at end of file From e1851fce69fab06428dc4c394f1578af9889d030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer=20=28Macbook=29?= Date: Thu, 16 Jan 2020 11:34:01 +0100 Subject: [PATCH 19/33] ProgramsList+ProgramsView+ProgramsDownload --- www/frames/default_frame.php | 9 +- www/frames/nocontent_frame.php | 9 ++ www/internals/modules/programs.php | 18 ++- www/internals/pageframeoptions.php | 12 ++ www/internals/utils.php | 38 ------- www/internals/website.php | 6 + www/pages/programs_download.php | 38 ++++--- www/pages/programs_list.php | 92 +++++++-------- www/pages/programs_view.php | 172 +++++++++++++---------------- 9 files changed, 186 insertions(+), 208 deletions(-) create mode 100644 www/frames/nocontent_frame.php diff --git a/www/frames/default_frame.php b/www/frames/default_frame.php index 9f4a928..9b16bbe 100644 --- a/www/frames/default_frame.php +++ b/www/frames/default_frame.php @@ -12,7 +12,14 @@ require_once (__DIR__ . '/../internals/website.php'); - <?php echo ($FRAME_OPTIONS->title !== '') ? htmlspecialchars('Mikescher.com - ' . $FRAME_OPTIONS->title) : 'Mikescher.com'; ?> + title !== '' && $FRAME_OPTIONS->title !== null) + echo '' . htmlspecialchars('Mikescher.com - ' . $FRAME_OPTIONS->title) . ''; + else if ($FRAME_OPTIONS->title === '') + echo 'Mikescher.com'; + else + echo ''; + ?> force_404 = true; $this->force_404_message = $err; } + + public function setForcedRedirect(string $url) + { + $this->force_redirect = true; + $this->force_redirect_url = $url; + } } \ No newline at end of file diff --git a/www/internals/utils.php b/www/internals/utils.php index 0c0a993..ef90b1d 100644 --- a/www/internals/utils.php +++ b/www/internals/utils.php @@ -68,44 +68,6 @@ function isProd() { return $CONFIG['prod']; } -function convertCountryToFlag($country) { - $country = trim(strtolower($country)); - - if ($country === 'italy') return '/data/images/flags/013-italy.svg'; - if ($country === 'china') return '/data/images/flags/034-china.svg'; - if ($country === 'japan') return '/data/images/flags/063-japan.svg'; - if ($country === 'un') return '/data/images/flags/082-united-nations.svg'; - if ($country === 'south korea') return '/data/images/flags/094-south-korea.svg'; - if ($country === 'spain') return '/data/images/flags/128-spain.svg'; - if ($country === 'norway') return '/data/images/flags/143-norway.svg'; - if ($country === 'Czech') return '/data/images/flags/149-czech-republic.svg'; - if ($country === 'germany') return '/data/images/flags/162-germany.svg'; - if ($country === 'sweden') return '/data/images/flags/184-sweden.svg'; - if ($country === 'france') return '/data/images/flags/195-france.svg'; - if ($country === 'switzerland') return '/data/images/flags/205-switzerland.svg'; - if ($country === 'england') return '/data/images/flags/216-england.svg'; - if ($country === 'usa') return '/data/images/flags/226-united-states.svg'; - if ($country === 'america') return '/data/images/flags/226-united-states.svg'; - if ($country === 'canada') return '/data/images/flags/243-canada.svg'; - if ($country === 'russia') return '/data/images/flags/248-russia.svg'; - if ($country === 'eu') return '/data/images/flags/259-european-union.svg'; - if ($country === 'uk') return '/data/images/flags/260-united-kingdom.svg'; - - return null; -} - -function convertLanguageToFlag($lang) { - $lang = trim(strtolower($lang)); - - if ($lang === 'italian') return '/data/images/flags/013-italy.svg'; - if ($lang === 'english') return '/data/images/flags/226-united-states.svg'; - if ($lang === 'french') return '/data/images/flags/195-france.svg'; - if ($lang === 'german') return '/data/images/flags/162-germany.svg'; - if ($lang === 'spanish') return '/data/images/flags/128-spain.svg'; - - return null; -} - /** * easy image resize function * @author http://www.nimrodstech.com/php-image-resize/ diff --git a/www/internals/website.php b/www/internals/website.php index 5751c78..c8900a4 100644 --- a/www/internals/website.php +++ b/www/internals/website.php @@ -65,6 +65,12 @@ class Website $result = $route->get($this); + if ($result->force_redirect) + { + header('Location: ' . $result->force_redirect_url); + exit(); + } + if ($result->force_404) { $this->serveCustom404($route->full_url, $result, $result->force_404_message); diff --git a/www/pages/programs_download.php b/www/pages/programs_download.php index 9a41f91..aaf93c9 100644 --- a/www/pages/programs_download.php +++ b/www/pages/programs_download.php @@ -1,21 +1,29 @@ -$prog = Programs::getProgramByInternalName($internalname); -if ($prog === NULL) httpError(404, 'Program not found'); +parameter['id']; -// This page is only for old links. -// Current version does use direct links +$prog = $SITE->modules->Programs()->getProgramByInternalName($progid); +if ($prog === null) { $FRAME_OPTIONS->setForced404("Program not found"); return; } -foreach (Programs::getURLs($prog) as $xurl) +$FRAME_OPTIONS->title = null; +$FRAME_OPTIONS->canonical_url = null; +$FRAME_OPTIONS->activeHeader = null; + +$FRAME_OPTIONS->frame = 'nocontent_frame.php'; + +foreach ($SITE->modules->Programs()->getURLs($prog) as $xurl) { - if ($xurl['type'] === 'download') { header('Location: ' . $xurl['href']); exit; } - if ($xurl['type'] === 'playstore') { header('Location: ' . $xurl['href']); exit; } - if ($xurl['type'] === 'amazonappstore') { header('Location: ' . $xurl['href']); exit; } - if ($xurl['type'] === 'windowsstore') { header('Location: ' . $xurl['href']); exit; } - if ($xurl['type'] === 'itunesstore') { header('Location: ' . $xurl['href']); exit; } -} \ No newline at end of file + if ($xurl['type'] === 'download') { $FRAME_OPTIONS->setForcedRedirect($xurl['href']); return; } + if ($xurl['type'] === 'playstore') { $FRAME_OPTIONS->setForcedRedirect($xurl['href']); return; } + if ($xurl['type'] === 'amazonappstore') { $FRAME_OPTIONS->setForcedRedirect($xurl['href']); return; } + if ($xurl['type'] === 'windowsstore') { $FRAME_OPTIONS->setForcedRedirect($xurl['href']); return; } + if ($xurl['type'] === 'itunesstore') { $FRAME_OPTIONS->setForcedRedirect($xurl['href']); return; } +} +?> diff --git a/www/pages/programs_list.php b/www/pages/programs_list.php index e836906..e337c78 100644 --- a/www/pages/programs_list.php +++ b/www/pages/programs_list.php @@ -1,69 +1,53 @@ - - - - - Mikescher.com - Programs - - - - - -
- +parameter['categoryfilter']; -
- -
- -

My programs


+$FRAME_OPTIONS->title = 'Programs'; +$FRAME_OPTIONS->canonical_url = ($filter === '') ? ('https://www.mikescher.com/programs') : ('https://www.mikescher.com/programs/cat/' . $filter); +$FRAME_OPTIONS->activeHeader = 'programs'; - modules->Programs()->listAllNewestFirst($filter); +?> - echo '' . "\n"; + + ?>
- - - - \ No newline at end of file diff --git a/www/pages/programs_view.php b/www/pages/programs_view.php index a5e1a44..91b98bc 100644 --- a/www/pages/programs_view.php +++ b/www/pages/programs_view.php @@ -1,123 +1,101 @@ - - - - - Mikescher.com - <?php echo $prog['name']; ?> - - - - - - -
- +parameter['id']; -
+$prog = $SITE->modules->Programs()->getProgramByInternalName($id); +if ($prog === null) { $FRAME_OPTIONS->setForced404("Program not found"); return; } -
+$FRAME_OPTIONS->title = $prog['name']; +$FRAME_OPTIONS->canonical_url =$prog['url']; +$FRAME_OPTIONS->activeHeader = 'programs'; -
+if ($prog['has_extra_images']) $FRAME_OPTIONS->addScript('/data/javascript/ms_basic.js', true); +?> -


+
-
+
-
Thumbnail (<?php echo $prog['name'] ?>)
+


-
-
Name:
-
+
-
Language:
-
+
Thumbnail (<?php echo $prog['name'] ?>)
- -
License:
-
'.$prog['license'].'' ?>
- +
+
Name:
+
-
Category:
-
- -
Date:
-
- -
- '; - echo ''; - echo ''; - echo ''; - echo ''.$xurl['caption'].''; - echo ''; - } - ?> -
- -
- ' . "\n"; - } - ?> -
-
-
- - - - +
Language:
+
+ +
License:
+
modules->Programs()->getLicenseUrl($prog['license']).'">'.$prog['license'].'' ?>
-
+
Category:
+
-
+
Date:
+
+ +
text(Programs::getProgramDescription($prog)); + foreach ($SITE->modules->Programs()->getURLs($prog) as $xurl) + { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''.$xurl['caption'].''; + echo ''; + } ?> -
+
-
+
+ modules->Programs()->convertLanguageToFlag($lang).'" title="'.$lang.'" alt="'.$lang[0].'" />' . "\n"; + } + ?> +
+
+
-
+ -
+ - + + +
+ +
+ renderMarkdown($SITE->modules->Programs()->getProgramDescription($prog)); ?> +
+ +
- - - - \ No newline at end of file From 530286832746425e3ed9299c9015a055dbca8653 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer=20=28Macbook=29?= Date: Thu, 16 Jan 2020 11:48:27 +0100 Subject: [PATCH 20/33] WebApps+About --- www/fragments/panel_aoc_calendar.php | 14 +- www/fragments/panel_blog.php | 4 +- www/fragments/panel_books.php | 4 +- www/fragments/panel_euler.php | 4 +- www/fragments/panel_programs.php | 4 +- www/internals/modules/mikeschergitgraph.php | 1 - www/pages/about.php | 162 +++++++++----------- www/pages/programs_view.php | 4 +- www/pages/webapps_list.php | 63 +++----- 9 files changed, 108 insertions(+), 152 deletions(-) diff --git a/www/fragments/panel_aoc_calendar.php b/www/fragments/panel_aoc_calendar.php index 431d72b..4c1629e 100644 --- a/www/fragments/panel_aoc_calendar.php +++ b/www/fragments/panel_aoc_calendar.php @@ -18,11 +18,9 @@ $ajax = $parameter['ajax']; $frame = $parameter['frame']; $frameid = $parameter['frameid']; -$AOC = $SITE->modules->AdventOfCode(); - -$assocdays = $AOC->listSingleYearAssociative($year); -$prev_year = $shownav ? $AOC->getPrevYear($year) : null; -$next_year = $shownav ? $AOC->getNextYear($year) : null; +$assocdays = $SITE->modules->AdventOfCode()->listSingleYearAssociative($year); +$prev_year = $shownav ? $SITE->modules->AdventOfCode()->getPrevYear($year) : null; +$next_year = $shownav ? $SITE->modules->AdventOfCode()->getNextYear($year) : null; if ($ajax) $FRAME_OPTIONS->addScript("/data/javascript/aoc_panel_interactive.js", true); @@ -37,14 +35,14 @@ if ($ajax) $FRAME_OPTIONS->addScript("/data/javascript/aoc_panel_interactive.js" if ($ajax) echo '<'; else - echo '<'; + echo '<'; } else { echo '<'; } - if ($linkheader) echo ''.$year.''; + if ($linkheader) echo ''.$year.''; else echo ''.$year.''; if ($next_year !== null) @@ -52,7 +50,7 @@ if ($ajax) $FRAME_OPTIONS->addScript("/data/javascript/aoc_panel_interactive.js" if ($ajax) echo '>'; else - echo '>'; + echo '>'; } else { diff --git a/www/fragments/panel_blog.php b/www/fragments/panel_blog.php index f5b5284..2f4d605 100644 --- a/www/fragments/panel_blog.php +++ b/www/fragments/panel_blog.php @@ -11,9 +11,7 @@ $parameter = $FRAGMENT_PARAM; ?> modules->Blog(); - - $allposts = $BLOG->listAllNewestFirst(); +$allposts = $SITE->modules->Blog()->listAllNewestFirst(); ?>
diff --git a/www/fragments/panel_books.php b/www/fragments/panel_books.php index 9209902..ed3ea9c 100644 --- a/www/fragments/panel_books.php +++ b/www/fragments/panel_books.php @@ -11,9 +11,7 @@ $parameter = $FRAGMENT_PARAM; ?> modules->Books(); - - $allbooks = $BOOKS->listAllNewestFirst(); +$allbooks = $SITE->modules->Books()->listAllNewestFirst(); ?>
diff --git a/www/fragments/panel_euler.php b/www/fragments/panel_euler.php index 143859a..843be72 100644 --- a/www/fragments/panel_euler.php +++ b/www/fragments/panel_euler.php @@ -11,9 +11,7 @@ $parameter = $FRAGMENT_PARAM; ?> modules->Euler(); - - $data = $EULER->listAll(); + $data = $SITE->modules->Euler()->listAll(); $RATING_CLASSES = ['euler_pnl_celltime_perfect', 'euler_pnl_celltime_good', 'euler_pnl_celltime_ok', 'euler_pnl_celltime_bad', 'euler_pnl_celltime_fail']; ?> diff --git a/www/fragments/panel_programs.php b/www/fragments/panel_programs.php index 63ab45b..ad82e36 100644 --- a/www/fragments/panel_programs.php +++ b/www/fragments/panel_programs.php @@ -11,9 +11,7 @@ $parameter = $FRAGMENT_PARAM; ?> modules->Programs(); - - $allprograms = $PROGRAMS->listAllNewestFirst(); +$allprograms = $SITE->modules->Programs()->listAllNewestFirst(); ?>
diff --git a/www/internals/modules/mikeschergitgraph.php b/www/internals/modules/mikeschergitgraph.php index 78259c2..059eab8 100644 --- a/www/internals/modules/mikeschergitgraph.php +++ b/www/internals/modules/mikeschergitgraph.php @@ -20,7 +20,6 @@ class MikescherGitGraph /** * @return string|null - * @throws Exception */ public function get() { diff --git a/www/pages/about.php b/www/pages/about.php index 3eea2d9..19cffb6 100644 --- a/www/pages/about.php +++ b/www/pages/about.php @@ -1,114 +1,98 @@ - - - - - Mikescher.com - About - - - - - - -
- +title = 'About'; +$FRAME_OPTIONS->canonical_url = 'https://www.mikescher.com/about'; +$FRAME_OPTIONS->activeHeader = 'about'; +?> -
+
-
+

About mikescher.com


-

About mikescher.com


+ - +
+
About me
-
-
About me
+
-
+

Welcome to my Mikescher.com

+

This is my personal homepage, I use it to upload programs I have written, web serials I have style-setted and sometimes for a little bit of blogging.

+

Its mostly just a collection of stuff I wanted to put only, but I guess thats the core of most personal homepages

-

Welcome to my Mikescher.com

-

This is my personal homepage, I use it to upload programs I have written, web serials I have style-setted and sometimes for a little bit of blogging.

-

Its mostly just a collection of stuff I wanted to put only, but I guess thats the core of most personal homepages

+
+
-
+ -
+
+
My git timeline
- +
-
-
My git timeline
+ addScript('/data/javascript/extendedgitgraph.js', true); + echo $SITE->modules->ExtendedGitGraph()->get(); + ?> -
+
- +
-
+ -
+ - -
- - +
- - - - \ No newline at end of file diff --git a/www/pages/programs_view.php b/www/pages/programs_view.php index 91b98bc..20f3820 100644 --- a/www/pages/programs_view.php +++ b/www/pages/programs_view.php @@ -15,8 +15,6 @@ if ($prog === null) { $FRAME_OPTIONS->setForced404("Program not found"); return; $FRAME_OPTIONS->title = $prog['name']; $FRAME_OPTIONS->canonical_url =$prog['url']; $FRAME_OPTIONS->activeHeader = 'programs'; - -if ($prog['has_extra_images']) $FRAME_OPTIONS->addScript('/data/javascript/ms_basic.js', true); ?>
@@ -74,6 +72,8 @@ if ($prog['has_extra_images']) $FRAME_OPTIONS->addScript('/data/javascript/ms_ba + addScript('/data/javascript/ms_basic.js', true); ?> +
diff --git a/www/pages/webapps_list.php b/www/pages/webapps_list.php index 52183c7..c0cf0bf 100644 --- a/www/pages/webapps_list.php +++ b/www/pages/webapps_list.php @@ -1,52 +1,35 @@ - - - - - Mikescher.com - Tools - - - - - - - - - - \ No newline at end of file From f5a9552dbd91cf94c1475123fa6a91d580b7a98e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer=20=28Macbook=29?= Date: Thu, 16 Jan 2020 13:21:14 +0100 Subject: [PATCH 21/33] API --- www/commands/alephnote_show.php | 10 +- www/commands/alephnote_statsping.php | 23 ++-- www/commands/base_test.php | 8 +- www/commands/extendedgitgraph_redraw.php | 12 +- www/commands/extendedgitgraph_refresh.php | 12 +- www/commands/extendedgitgraph_status.php | 14 +- www/commands/html_panel-aoc-calendar.php | 31 +++-- www/commands/progs_updatecheck.php | 16 +-- www/commands/server_backupupload.php | 14 +- www/commands/server_gitwebhook.php | 24 ++-- www/commands/server_setselfaddress.php | 5 + www/commands/site_createBookThumbnails.php | 12 +- www/commands/site_createProgramThumbnails.php | 12 +- www/commands/updates_show.php | 11 +- www/frames/api_frame.php | 9 ++ www/index.php | 128 +++++++++--------- www/internals/modules/mikeschergitgraph.php | 10 ++ www/internals/pageframeoptions.php | 7 + www/internals/ruleengine.php | 2 + www/internals/urlroute.php | 10 +- www/internals/website.php | 2 +- www/pages/api.php | 34 +++-- 22 files changed, 237 insertions(+), 169 deletions(-) create mode 100644 www/frames/api_frame.php diff --git a/www/commands/alephnote_show.php b/www/commands/alephnote_show.php index ee98d25..aa2c36d 100644 --- a/www/commands/alephnote_show.php +++ b/www/commands/alephnote_show.php @@ -1,9 +1,9 @@
@@ -20,7 +20,7 @@ Database::connect(); - + modules->AlephNoteStatistics()->getAllActiveEntriesOrdered() as $entry): ?> diff --git a/www/commands/alephnote_statsping.php b/www/commands/alephnote_statsping.php index dcbf878..98e3f99 100644 --- a/www/commands/alephnote_statsping.php +++ b/www/commands/alephnote_statsping.php @@ -1,16 +1,17 @@ forceResult(400, "Wrong parameters."); return; } +if (!isset($API_OPTIONS['clientid'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; } +if (!isset($API_OPTIONS['version'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; } +if (!isset($API_OPTIONS['providerstr'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; } +if (!isset($API_OPTIONS['providerid'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; } +if (!isset($API_OPTIONS['notecount'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; } $nam = $API_OPTIONS['name']; $cid = $API_OPTIONS['clientid']; @@ -22,9 +23,7 @@ $tnc = $API_OPTIONS['notecount']; if ($nam !== 'AlephNote') print('{"success":false, "message":"Unknown AppName"}'); -Database::connect(); - -Database::sql_exec_prep('INSERT INTO an_statslog (ClientID, Version, ProviderStr, ProviderID, NoteCount) VALUES (:cid1, :ver1, :prv1, :pid1, :tnc1) ON DUPLICATE KEY UPDATE Version=:ver2,ProviderStr=:prv2,ProviderID=:pid2,NoteCount=:tnc2', +$SITE->modules->Database()->sql_exec_prep('INSERT INTO an_statslog (ClientID, Version, ProviderStr, ProviderID, NoteCount) VALUES (:cid1, :ver1, :prv1, :pid1, :tnc1) ON DUPLICATE KEY UPDATE Version=:ver2,ProviderStr=:prv2,ProviderID=:pid2,NoteCount=:tnc2', [ [':cid1', $cid, PDO::PARAM_STR], [':ver1', $ver, PDO::PARAM_STR], diff --git a/www/commands/base_test.php b/www/commands/base_test.php index 1c467f6..4a1b139 100644 --- a/www/commands/base_test.php +++ b/www/commands/base_test.php @@ -1,3 +1,9 @@ updateCache(); - +$v = $SITE->modules->ExtendedGitGraph()->updateCache(); diff --git a/www/commands/extendedgitgraph_refresh.php b/www/commands/extendedgitgraph_refresh.php index f2f3bf1..a65c9fe 100644 --- a/www/commands/extendedgitgraph_refresh.php +++ b/www/commands/extendedgitgraph_refresh.php @@ -1,12 +1,12 @@ update(); -$v->updateCache(); +$SITE->modules->ExtendedGitGraph()->update(); +$SITE->modules->ExtendedGitGraph()->updateCache(); diff --git a/www/commands/extendedgitgraph_status.php b/www/commands/extendedgitgraph_status.php index e39ee5e..9a56ba6 100644 --- a/www/commands/extendedgitgraph_status.php +++ b/www/commands/extendedgitgraph_status.php @@ -1,10 +1,14 @@ config['extendedgitgraph']['output_file']) { - $lfile = $CONFIG['extendedgitgraph']['output_filepath']; + $lfile = $SITE->config['extendedgitgraph']['output_filepath']; if (file_exists($lfile)) { @@ -18,11 +22,11 @@ if ($CONFIG['extendedgitgraph']['output_file']) echo '[[ FILE NOT FOUND ]]'; } } -else if ($CONFIG['extendedgitgraph']['output_file']) +else if ($SITE->config['extendedgitgraph']['output_file']) { if (session_status() !== PHP_SESSION_ACTIVE) session_start(); - $svar = $CONFIG['extendedgitgraph']['session_var']; + $svar = $SITE->config['extendedgitgraph']['session_var']; if (isset($_GET['clear'])) if (key_exists($svar, $_SESSION)) $_SESSION[$svar] = ''; diff --git a/www/commands/html_panel-aoc-calendar.php b/www/commands/html_panel-aoc-calendar.php index fd42fcc..6db0baa 100644 --- a/www/commands/html_panel-aoc-calendar.php +++ b/www/commands/html_panel-aoc-calendar.php @@ -1,16 +1,21 @@ intval($_GET['year']), - 'nav' => boolval($_GET['nav']), - 'linkheader' => boolval($_GET['linkheader']), - 'ajax' => boolval($_GET['ajax']), - 'frame' => false, - 'frameid' => strval($_GET['frameid']), -]; -require (__DIR__ . '/../fragments/panel_aoc_calendar.php'); + + +if (!isset($API_OPTIONS['year'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; } +if (!isset($API_OPTIONS['nav'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; } +if (!isset($API_OPTIONS['linkheader'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; } +if (!isset($API_OPTIONS['ajax'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; } + +$year = intval($API_OPTIONS['year']); +$shownav = boolval($API_OPTIONS['nav']); +$linkheader = boolval($API_OPTIONS['linkheader']); +$ajax = boolval($API_OPTIONS['ajax']); +$frameid = strval($API_OPTIONS['frameid']); + +$SITE->fragments->PanelAdventOfCodeCalendar($year, $shownav, $linkheader, $ajax, false, $frameid); diff --git a/www/commands/progs_updatecheck.php b/www/commands/progs_updatecheck.php index 245f42a..602549e 100644 --- a/www/commands/progs_updatecheck.php +++ b/www/commands/progs_updatecheck.php @@ -1,21 +1,21 @@ forceResult(400, "Wrong parameters."); return; } $name = $API_OPTIONS['name']; -$updatedata = UpdatesLog::listUpdateData(); +$updatedata = $SITE->modules->UpdatesLog()->listUpdateData(); -if (!array_key_exists($name, $updatedata)) httpError(404, 'Invalid Request - [Name] not found'); +if (!array_key_exists($name, $updatedata)) { $FRAME_OPTIONS->forceResult(404, 'Invalid Request - [Name] not found'); return; } $data = $updatedata[$name]; -UpdatesLog::insert($name, $data['version']); +$SITE->modules->UpdatesLog()->insert($name, $data['version']); print($name."
".$data['version']."
".$data['url']); diff --git a/www/commands/server_backupupload.php b/www/commands/server_backupupload.php index 02740ef..cf26e3e 100644 --- a/www/commands/server_backupupload.php +++ b/www/commands/server_backupupload.php @@ -1,17 +1,17 @@ forceResult(400, "Wrong parameters."); return; } +if (!isset($API_OPTIONS['filename'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; } $folder = $API_OPTIONS['folder']; $filename = $API_OPTIONS['filename']; -$uri = $OPTIONS['uri']; +$uri = $ROUTE->full_url; $reltarget = "Backup/$folder/$filename"; diff --git a/www/commands/server_gitwebhook.php b/www/commands/server_gitwebhook.php index 1876fd8..c7f7b6e 100644 --- a/www/commands/server_gitwebhook.php +++ b/www/commands/server_gitwebhook.php @@ -1,21 +1,27 @@ forceResult(400, "Wrong parameters."); return; } $hook = $API_OPTIONS['target']; -$uri = $OPTIONS['uri']; +$uri = $ROUTE->full_url; $cmd = ""; -if ($hook == 'website_mikescher') $cmd = 'git pull'; -else if ($hook == 'griddominance') $cmd = 'update-gdapi'; -else httpDie(400, "Unknown webhook: $hook"); +if ($hook == 'website_mikescher') + $cmd = 'git pull'; +else if ($hook == 'griddominance') + $cmd = 'update-gdapi'; +else +{ + $FRAME_OPTIONS->forceResult(400, "Unknown webhook: $hook"); + return; +} $std = shell_exec($cmd); diff --git a/www/commands/server_setselfaddress.php b/www/commands/server_setselfaddress.php index 0b2db70..f9e0f3e 100644 --- a/www/commands/server_setselfaddress.php +++ b/www/commands/server_setselfaddress.php @@ -1,4 +1,9 @@ '; echo ''; @@ -17,10 +17,10 @@ echo ''; echo ''; echo ''; -foreach (Books::listAll() as $book) +foreach ($SITE->modules->Books()->listAll() as $book) { echo 'Create preview for ' . $book['title'] . '
' . "\n"; - Books::createPreview($book); + $SITE->modules->Books()->createPreview($book); } echo 'Finished.' . '
' . "\n"; diff --git a/www/commands/site_createProgramThumbnails.php b/www/commands/site_createProgramThumbnails.php index 8b5cd6a..7c5b00d 100644 --- a/www/commands/site_createProgramThumbnails.php +++ b/www/commands/site_createProgramThumbnails.php @@ -1,10 +1,10 @@ '; echo ''; @@ -17,10 +17,10 @@ echo ''; echo ''; echo ''; -foreach (Programs::listAll() as $prog) +foreach ($SITE->modules->Programs()->listAll() as $prog) { echo 'Create preview for ' . $prog['name'] . '
' . "\n"; - Programs::createPreview($prog); + $SITE->modules->Programs()->createPreview($prog); } echo 'Finished.' . '
' . "\n"; diff --git a/www/commands/updates_show.php b/www/commands/updates_show.php index 7f35a4b..021f7b3 100644 --- a/www/commands/updates_show.php +++ b/www/commands/updates_show.php @@ -1,10 +1,9 @@
@@ -16,7 +15,7 @@ Database::connect(); - + modules->UpdatesLog()->getEntries($_GET['ulname'], 512) as $entry): ?> diff --git a/www/frames/api_frame.php b/www/frames/api_frame.php new file mode 100644 index 0000000..cff59c6 --- /dev/null +++ b/www/frames/api_frame.php @@ -0,0 +1,9 @@ +raw); \ No newline at end of file diff --git a/www/index.php b/www/index.php index 82677f3..ecf2691 100644 --- a/www/index.php +++ b/www/index.php @@ -7,77 +7,77 @@ $site->init(); $URL_RULES = [ - [ 'url' => [], 'target' => 'main.php', 'options' => [ 'http' ], 'parameter' => [ ], ], - [ 'url' => ['index'], 'target' => 'main.php', 'options' => [ 'http' ], 'parameter' => [ ], ], - [ 'url' => ['index.php'], 'target' => 'main.php', 'options' => [ 'http' ], 'parameter' => [ ], ], - [ 'url' => ['msmain', 'index'], 'target' => 'main.php', 'options' => [ 'http' ], 'parameter' => [ ], ], - [ 'url' => ['about'], 'target' => 'about.php', 'options' => [ 'http' ], 'parameter' => [ ], ], - [ 'url' => ['msmain', 'about'], 'target' => 'about.php', 'options' => [ 'http' ], 'parameter' => [ ], ], - [ 'url' => ['login'], 'target' => 'login.php', 'options' => [ 'http' ], 'parameter' => [ 'login_target' => '/' ], ], - [ 'url' => ['logout'], 'target' => 'logout.php', 'options' => [ 'http' ], 'parameter' => [ 'logout_target' => '/' ], ], + [ 'url' => [], 'target' => 'main.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['index'], 'target' => 'main.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['index.php'], 'target' => 'main.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['msmain', 'index'], 'target' => 'main.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['about'], 'target' => 'about.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['msmain', 'about'], 'target' => 'about.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['login'], 'target' => 'login.php', 'options' => [ 'http' ], 'parameter' => [ 'login_target' => '/' ], ], + [ 'url' => ['logout'], 'target' => 'logout.php', 'options' => [ 'http' ], 'parameter' => [ 'logout_target' => '/' ], ], - [ 'url' => ['programs'], 'target' => 'programs_list.php', 'options' => [ 'http' ], 'parameter' => [ 'categoryfilter' => '' ], ], - [ 'url' => ['programs', 'index'], 'target' => 'programs_list.php', 'options' => [ 'http' ], 'parameter' => [ 'categoryfilter' => '%GET%' ], ], - [ 'url' => ['programs', 'index'], 'target' => 'programs_list.php', 'options' => [ 'http' ], 'parameter' => [ 'categoryfilter' => '' ], ], - [ 'url' => ['programs', 'cat', '?{categoryfilter}'], 'target' => 'programs_list.php', 'options' => [ 'http' ], 'parameter' => [ 'categoryfilter' => '%URL%' ], ], - [ 'url' => ['downloads', 'details.php'], 'target' => 'programs_list.php', 'options' => [ 'http' ], 'parameter' => [ 'categoryfilter' => '' ], ], - [ 'url' => ['downloads', 'downloads.php'], 'target' => 'programs_list.php', 'options' => [ 'http' ], 'parameter' => [ 'categoryfilter' => '' ], ], - [ 'url' => ['programs', 'view', '?{id}'], 'target' => 'programs_view.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%URL%' ], ], - [ 'url' => ['programs', 'view'], 'target' => 'programs_view.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%GET%' ], ], - [ 'url' => ['downloads', '?{id}'], 'target' => 'programs_download.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%URL%' ], ], - [ 'url' => ['programs', 'download', '?{id}'], 'target' => 'programs_download.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%URL%' ], ], - [ 'url' => ['programs', 'download'], 'target' => 'programs_download.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%GET%' ], ], + [ 'url' => ['programs'], 'target' => 'programs_list.php', 'options' => [ 'http' ], 'parameter' => [ 'categoryfilter' => '' ], ], + [ 'url' => ['programs', 'index'], 'target' => 'programs_list.php', 'options' => [ 'http' ], 'parameter' => [ 'categoryfilter' => '%GET%' ], ], + [ 'url' => ['programs', 'index'], 'target' => 'programs_list.php', 'options' => [ 'http' ], 'parameter' => [ 'categoryfilter' => '' ], ], + [ 'url' => ['programs', 'cat', '?{categoryfilter}'], 'target' => 'programs_list.php', 'options' => [ 'http' ], 'parameter' => [ 'categoryfilter' => '%URL%' ], ], + [ 'url' => ['downloads', 'details.php'], 'target' => 'programs_list.php', 'options' => [ 'http' ], 'parameter' => [ 'categoryfilter' => '' ], ], + [ 'url' => ['downloads', 'downloads.php'], 'target' => 'programs_list.php', 'options' => [ 'http' ], 'parameter' => [ 'categoryfilter' => '' ], ], + [ 'url' => ['programs', 'view', '?{id}'], 'target' => 'programs_view.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%URL%' ], ], + [ 'url' => ['programs', 'view'], 'target' => 'programs_view.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%GET%' ], ], + [ 'url' => ['downloads', '?{id}'], 'target' => 'programs_download.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%URL%' ], ], + [ 'url' => ['programs', 'download', '?{id}'], 'target' => 'programs_download.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%URL%' ], ], + [ 'url' => ['programs', 'download'], 'target' => 'programs_download.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%GET%' ], ], - [ 'url' => ['books'], 'target' => 'books_list.php', 'options' => [ 'http' ], 'parameter' => [ ], ], - [ 'url' => ['books', 'list'], 'target' => 'books_list.php', 'options' => [ 'http' ], 'parameter' => [ ], ], - [ 'url' => ['books', 'view', '?{id}'], 'target' => 'books_view.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%GET%' ], ], - [ 'url' => ['books', 'view', '?{id}', '*'], 'target' => 'books_view.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%URL%' ], ], + [ 'url' => ['books'], 'target' => 'books_list.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['books', 'list'], 'target' => 'books_list.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['books', 'view', '?{id}'], 'target' => 'books_view.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%GET%' ], ], + [ 'url' => ['books', 'view', '?{id}', '*'], 'target' => 'books_view.php', 'options' => [ 'http' ], 'parameter' => [ 'id' => '%URL%' ], ], - [ 'url' => ['update.php'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], - [ 'url' => ['update.php', '?{Name}'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], - [ 'url' => ['update'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], - [ 'url' => ['update', '?{Name}'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], - [ 'url' => ['update2'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], - [ 'url' => ['api', 'update'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], - [ 'url' => ['api', 'update', '?{Name}'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], - [ 'url' => ['api', 'test'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'base::test' ], ], - [ 'url' => ['api', 'setselfadress'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'server::setselfaddress' ], ], - [ 'url' => ['api', 'statsping'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'alephnote::statsping' ], ], - [ 'url' => ['api', 'webhook', '?{target}'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'server::gitwebhook' ], ], - [ 'url' => ['api', 'backupupload'], 'target' => 'api.php', 'options' => [ 'http' ], 'parameter' => [ 'cmd' => 'server::backupupload' ], ], - [ 'url' => ['api', '?{cmd}'], 'target' => 'api.php', 'options' => [ ], 'parameter' => [ 'cmd' => '%URL%' ], ], + [ 'url' => ['update.php'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], + [ 'url' => ['update.php', '?{Name}'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], + [ 'url' => ['update'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], + [ 'url' => ['update', '?{Name}'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], + [ 'url' => ['update2'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], + [ 'url' => ['api', 'update'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], + [ 'url' => ['api', 'update', '?{Name}'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], 'parameter' => [ 'cmd' => 'progs::updatecheck' ], ], + [ 'url' => ['api', 'test'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], 'parameter' => [ 'cmd' => 'base::test' ], ], + [ 'url' => ['api', 'setselfadress'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], 'parameter' => [ 'cmd' => 'server::setselfaddress' ], ], + [ 'url' => ['api', 'statsping'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], 'parameter' => [ 'cmd' => 'alephnote::statsping' ], ], + [ 'url' => ['api', 'webhook', '?{target}'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], 'parameter' => [ 'cmd' => 'server::gitwebhook' ], ], + [ 'url' => ['api', 'backupupload'], 'target' => 'api.php', 'options' => [ 'http', 'api' ], 'parameter' => [ 'cmd' => 'server::backupupload' ], ], + [ 'url' => ['api', '?{cmd}'], 'target' => 'api.php', 'options' => [ 'api' ], 'parameter' => [ 'cmd' => '%URL%' ], ], - [ 'url' => ['admin'], 'target' => 'admin.php', 'options' => [ 'password' ], 'parameter' => [ ] ], + [ 'url' => ['admin'], 'target' => 'admin.php', 'options' => [ 'password' ], 'parameter' => [ ] ], - [ 'url' => ['blog'], 'target' => 'blog_list.php', 'options' => [ ], 'parameter' => [ ], ], - [ 'url' => ['log'], 'target' => 'blog_list.php', 'options' => [ ], 'parameter' => [ ], ], - [ 'url' => ['blogpost', 'index'], 'target' => 'blog_list.php', 'options' => [ ], 'parameter' => [ ], ], - [ 'url' => ['blog', '?{id}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ], - [ 'url' => ['blog', '?{id}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ], - [ 'url' => ['blog', '?{id}', '?{name}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ], - [ 'url' => ['blog', '?{id}', '?{name}', '?{subview}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '%URL%' ], ], - [ 'url' => ['log', '?{id}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ], - [ 'url' => ['log', '?{id}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ], - [ 'url' => ['log', '?{id}', '?{name}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ], - [ 'url' => ['log', '?{id}', '?{name}', '?{subview}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '%URL%' ], ], - [ 'url' => ['blogpost', 'view'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%GET%', 'subview' => '' ], ], + [ 'url' => ['blog'], 'target' => 'blog_list.php', 'options' => [ ], 'parameter' => [ ], ], + [ 'url' => ['log'], 'target' => 'blog_list.php', 'options' => [ ], 'parameter' => [ ], ], + [ 'url' => ['blogpost', 'index'], 'target' => 'blog_list.php', 'options' => [ ], 'parameter' => [ ], ], + [ 'url' => ['blog', '?{id}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ], + [ 'url' => ['blog', '?{id}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ], + [ 'url' => ['blog', '?{id}', '?{name}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ], + [ 'url' => ['blog', '?{id}', '?{name}', '?{subview}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '%URL%' ], ], + [ 'url' => ['log', '?{id}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ], + [ 'url' => ['log', '?{id}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ], + [ 'url' => ['log', '?{id}', '?{name}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '' ], ], + [ 'url' => ['log', '?{id}', '?{name}', '?{subview}'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%URL%', 'subview' => '%URL%' ], ], + [ 'url' => ['blogpost', 'view'], 'target' => 'blog_view.php', 'options' => [ ], 'parameter' => [ 'id' => '%GET%', 'subview' => '' ], ], - [ 'url' => ['webapps'], 'target' => 'webapps_list.php', 'options' => [ ], 'parameter' => [ ], ], + [ 'url' => ['webapps'], 'target' => 'webapps_list.php', 'options' => [ ], 'parameter' => [ ], ], - [ 'url' => ['highscores', 'list.php'], 'target' => 'highscores_listentries.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], - [ 'url' => ['highscores', 'list'], 'target' => 'highscores_listentries.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], - [ 'url' => ['highscores', 'listentries'], 'target' => 'highscores_listentries.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], - [ 'url' => ['highscores', 'list.php'], 'target' => 'highscores_listgames.php', 'options' => [ 'http' ], 'parameter' => [ ], ], - [ 'url' => ['highscores', 'list'], 'target' => 'highscores_listgames.php', 'options' => [ 'http' ], 'parameter' => [ ], ], - [ 'url' => ['highscores', 'listgames'], 'target' => 'highscores_listgames.php', 'options' => [ 'http' ], 'parameter' => [ ], ], - [ 'url' => ['highscores', 'insert.php'], 'target' => 'highscores_insert.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%', 'check' => '%GET%', 'name' => '%GET%', 'rand' => '%GET%', 'points' => '%GET%' ], ], - [ 'url' => ['highscores', 'insert'], 'target' => 'highscores_insert.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%', 'check' => '%GET%', 'name' => '%GET%', 'rand' => '%GET%', 'points' => '%GET%' ], ], - [ 'url' => ['highscores', 'update.php'], 'target' => 'highscores_update.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%', 'check' => '%GET%', 'name' => '%GET%', 'rand' => '%GET%', 'points' => '%GET%', 'nameid' => '%GET%' ], ], - [ 'url' => ['highscores', 'update'], 'target' => 'highscores_update.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%', 'check' => '%GET%', 'name' => '%GET%', 'rand' => '%GET%', 'points' => '%GET%', 'nameid' => '%GET%' ], ], - [ 'url' => ['highscores', 'list_top50.php'], 'target' => 'highscores_top50.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], - [ 'url' => ['highscores', 'list_top50'], 'target' => 'highscores_top50.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], - [ 'url' => ['highscores', 'getNewID.php'], 'target' => 'highscores_newid.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], - [ 'url' => ['highscores', 'newid'], 'target' => 'highscores_newid.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], + [ 'url' => ['highscores', 'list.php'], 'target' => 'highscores_listentries.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], + [ 'url' => ['highscores', 'list'], 'target' => 'highscores_listentries.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], + [ 'url' => ['highscores', 'listentries'], 'target' => 'highscores_listentries.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], + [ 'url' => ['highscores', 'list.php'], 'target' => 'highscores_listgames.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['highscores', 'list'], 'target' => 'highscores_listgames.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['highscores', 'listgames'], 'target' => 'highscores_listgames.php', 'options' => [ 'http' ], 'parameter' => [ ], ], + [ 'url' => ['highscores', 'insert.php'], 'target' => 'highscores_insert.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%', 'check' => '%GET%', 'name' => '%GET%', 'rand' => '%GET%', 'points' => '%GET%' ], ], + [ 'url' => ['highscores', 'insert'], 'target' => 'highscores_insert.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%', 'check' => '%GET%', 'name' => '%GET%', 'rand' => '%GET%', 'points' => '%GET%' ], ], + [ 'url' => ['highscores', 'update.php'], 'target' => 'highscores_update.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%', 'check' => '%GET%', 'name' => '%GET%', 'rand' => '%GET%', 'points' => '%GET%', 'nameid' => '%GET%' ], ], + [ 'url' => ['highscores', 'update'], 'target' => 'highscores_update.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%', 'check' => '%GET%', 'name' => '%GET%', 'rand' => '%GET%', 'points' => '%GET%', 'nameid' => '%GET%' ], ], + [ 'url' => ['highscores', 'list_top50.php'], 'target' => 'highscores_top50.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], + [ 'url' => ['highscores', 'list_top50'], 'target' => 'highscores_top50.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], + [ 'url' => ['highscores', 'getNewID.php'], 'target' => 'highscores_newid.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], + [ 'url' => ['highscores', 'newid'], 'target' => 'highscores_newid.php', 'options' => [ 'http' ], 'parameter' => [ 'gameid' => '%GET%' ], ], ]; $site->serve($URL_RULES); diff --git a/www/internals/modules/mikeschergitgraph.php b/www/internals/modules/mikeschergitgraph.php index 059eab8..b3fac93 100644 --- a/www/internals/modules/mikeschergitgraph.php +++ b/www/internals/modules/mikeschergitgraph.php @@ -18,6 +18,16 @@ class MikescherGitGraph return __DIR__ . '/../../dynamic/egg/cache_fullrenderer.html'; } + public function update() + { + return $this->extgitgraph->update(); + } + + public function updateCache() + { + return $this->extgitgraph->updateCache(); + } + /** * @return string|null */ diff --git a/www/internals/pageframeoptions.php b/www/internals/pageframeoptions.php index 478b9e2..c9cc72b 100644 --- a/www/internals/pageframeoptions.php +++ b/www/internals/pageframeoptions.php @@ -76,4 +76,11 @@ class PageFrameOptions $this->force_redirect = true; $this->force_redirect_url = $url; } + + public function forceResult(int $statuscode, string $content) + { + $this->statuscode = $statuscode; + ob_clean(); + echo $content; + } } \ No newline at end of file diff --git a/www/internals/ruleengine.php b/www/internals/ruleengine.php index 35e27ad..a7fa119 100644 --- a/www/internals/ruleengine.php +++ b/www/internals/ruleengine.php @@ -88,6 +88,8 @@ class RuleEngine } if (!$match) return null; + $route->urlParameter = $urlparams; + $ctrlOpt = $rule['options']; if (in_array('disabled', $ctrlOpt)) return null; diff --git a/www/internals/urlroute.php b/www/internals/urlroute.php index d8f1583..96bbaa9 100644 --- a/www/internals/urlroute.php +++ b/www/internals/urlroute.php @@ -16,12 +16,20 @@ class URLRoute /** @var int */ public $needsAdminLogin; + /** @var array */ + public $urlParameter; + + /** @var bool */ + public $isAPI; + public function __construct(string $target, string $url) { - $this->targetpath = __DIR__ . '/../pages/' . $target; + $this->targetpath = (__DIR__ . '/../pages/' . $target); $this->full_url = $url; $this->parameter = []; $this->needsAdminLogin = false; + $this->urlParameter = []; + $this->isAPI = false; } /** diff --git a/www/internals/website.php b/www/internals/website.php index c8900a4..bd3175d 100644 --- a/www/internals/website.php +++ b/www/internals/website.php @@ -17,7 +17,7 @@ class Website public $config; /** @var bool|null */ - public $isLoggedIn = null; + private $isLoggedIn = null; /** @var Modules */ public $modules; diff --git a/www/pages/api.php b/www/pages/api.php index 883245b..f953822 100644 --- a/www/pages/api.php +++ b/www/pages/api.php @@ -1,8 +1,15 @@ title = null; +$FRAME_OPTIONS->canonical_url = null; +$FRAME_OPTIONS->activeHeader = null; +$FRAME_OPTIONS->frame = 'api_frame.php'; -require_once (__DIR__ . '/../internals/base.php'); $API_COMMANDS = [ @@ -29,7 +36,7 @@ $API_COMMANDS = 'html::panel_aoc_calendar' => [ 'src' => __DIR__.'/../commands/html_panel-aoc-calendar.php', 'auth' => 'none' ], ]; -$cmd = strtolower($OPTIONS['cmd']); +$cmd = strtolower($ROUTE->parameter['cmd']); if (!array_key_exists($cmd, $API_COMMANDS)) { @@ -66,17 +73,17 @@ $config = $API_COMMANDS[$cmd]; $secret = isset($_GET['secret']) ? $_GET['secret'] : ''; -if ($config['auth'] === 'webhook_secret' && $secret !== $CONFIG['webhook_secret']) httpDie(401, 'Unauthorized.'); -if ($config['auth'] === 'ajax_secret' && $secret !== $CONFIG['ajax_secret']) httpDie(401, 'Unauthorized.'); -if ($config['auth'] === 'upload_secret' && $secret !== $CONFIG['upload_secret']) httpDie(401, 'Unauthorized.'); -if ($config['auth'] === 'admin' && !isLoggedInByCookie()) httpDie(401, 'Unauthorized.'); +if ($config['auth'] === 'webhook_secret' && $secret !== $CONFIG['webhook_secret']) { $FRAME_OPTIONS->forceResult(401, "Unauthorized."); return; } +if ($config['auth'] === 'ajax_secret' && $secret !== $CONFIG['ajax_secret']) { $FRAME_OPTIONS->forceResult(401, "Unauthorized."); return; } +if ($config['auth'] === 'upload_secret' && $secret !== $CONFIG['upload_secret']) { $FRAME_OPTIONS->forceResult(401, "Unauthorized."); return; } +if ($config['auth'] === 'admin' && !$SITE->isLoggedInByCookie()) { $FRAME_OPTIONS->forceResult(401, "Unauthorized."); return; } global $API_OPTIONS; $API_OPTIONS = []; foreach ($_GET as $k => $v) $API_OPTIONS[strtolower($k)] = $v; -foreach ($OPTIONS['_urlparams'] as $k => $v) $API_OPTIONS[strtolower($k)] = $v; +foreach ($ROUTE->urlParameter as $k => $v) $API_OPTIONS[strtolower($k)] = $v; try { @@ -85,15 +92,16 @@ try } catch (exception $e) { - print("API Command failed with exception"); - print($e); - $content = "REQUEST: " . var_export($_REQUEST) . "\r\n\r\n" . "IP: " . get_client_ip() . "\r\n\r\n" . "ERROR: " . $e . "\r\n\r\n"; - if (isProd()) sendMail("Website API call failed", $content, 'virtualadmin@mikescher.de', 'webserver-info@mikescher.com'); + if ($SITE->isProd()) sendMail("Website API call failed", $content, 'virtualadmin@mikescher.de', 'webserver-info@mikescher.com'); - httpDie(500, 'Error.'); + $msg = "Error."; + if (!$SITE->isProd()) $msg = "Error.\n" . "API Command failed with exception.\n" . $e; + + $FRAME_OPTIONS->forceResult(500, $msg); + return; } From c5bc008db1a0bbabf1bdd926ed36bd993980743f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Fri, 17 Jan 2020 00:21:41 +0100 Subject: [PATCH 22/33] update Parsedown + ParsedownExtra --- www/extern/Parsedown.php | 208 ++++++++++++++++++++++++++++++---- www/extern/ParsedownExtra.php | 18 ++- 2 files changed, 201 insertions(+), 25 deletions(-) diff --git a/www/extern/Parsedown.php b/www/extern/Parsedown.php index 757666e..1b9d6d5 100644 --- a/www/extern/Parsedown.php +++ b/www/extern/Parsedown.php @@ -17,7 +17,7 @@ class Parsedown { # ~ - const version = '1.6.0'; + const version = '1.7.4'; # ~ @@ -75,6 +75,32 @@ class Parsedown protected $urlsLinked = true; + function setSafeMode($safeMode) + { + $this->safeMode = (bool) $safeMode; + + return $this; + } + + protected $safeMode; + + protected $safeLinksWhitelist = array( + 'http://', + 'https://', + 'ftp://', + 'ftps://', + 'mailto:', + 'data:image/png;base64,', + 'data:image/gif;base64,', + 'data:image/jpeg;base64,', + 'irc:', + 'ircs:', + 'git:', + 'ssh:', + 'news:', + 'steam:', + ); + # # Lines # @@ -342,8 +368,6 @@ class Parsedown { $text = $Block['element']['text']['text']; - $text = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8'); - $Block['element']['text']['text'] = $text; return $Block; @@ -354,7 +378,7 @@ class Parsedown protected function blockComment($Line) { - if ($this->markupEscaped) + if ($this->markupEscaped or $this->safeMode) { return; } @@ -396,7 +420,7 @@ class Parsedown protected function blockFencedCode($Line) { - if (preg_match('/^['.$Line['text'][0].']{3,}[ ]*([\w-]+)?[ ]*$/', $Line['text'], $matches)) + if (preg_match('/^['.$Line['text'][0].']{3,}[ ]*([^`]+)?[ ]*$/', $Line['text'], $matches)) { $Element = array( 'name' => 'code', @@ -405,7 +429,21 @@ class Parsedown if (isset($matches[1])) { - $class = 'language-'.$matches[1]; + /** + * https://www.w3.org/TR/2011/WD-html5-20110525/elements.html#classes + * Every HTML element may have a class attribute specified. + * The attribute, if specified, must have a value that is a set + * of space-separated tokens representing the various classes + * that the element belongs to. + * [...] + * The space characters, for the purposes of this specification, + * are U+0020 SPACE, U+0009 CHARACTER TABULATION (tab), + * U+000A LINE FEED (LF), U+000C FORM FEED (FF), and + * U+000D CARRIAGE RETURN (CR). + */ + $language = substr($matches[1], 0, strcspn($matches[1], " \t\n\f\r")); + + $class = 'language-'.$language; $Element['attributes'] = array( 'class' => $class, @@ -457,8 +495,6 @@ class Parsedown { $text = $Block['element']['text']['text']; - $text = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8'); - $Block['element']['text']['text'] = $text; return $Block; @@ -515,10 +551,10 @@ class Parsedown ), ); - if($name === 'ol') + if($name === 'ol') { $listStart = stristr($matches[0], '.', true); - + if($listStart !== '1') { $Block['element']['attributes'] = array('start' => $listStart); @@ -547,6 +583,8 @@ class Parsedown { $Block['li']['text'] []= ''; + $Block['loose'] = true; + unset($Block['interrupted']); } @@ -595,6 +633,22 @@ class Parsedown } } + protected function blockListComplete(array $Block) + { + if (isset($Block['loose'])) + { + foreach ($Block['element']['text'] as &$li) + { + if (end($li['text']) !== '') + { + $li['text'] []= ''; + } + } + } + + return $Block; + } + # # Quote @@ -678,7 +732,7 @@ class Parsedown protected function blockMarkup($Line) { - if ($this->markupEscaped) + if ($this->markupEscaped or $this->safeMode) { return; } @@ -997,7 +1051,7 @@ class Parsedown # ~ # - public function line($text) + public function line($text, $nonNestables=array()) { $markup = ''; @@ -1013,6 +1067,13 @@ class Parsedown foreach ($this->InlineTypes[$marker] as $inlineType) { + # check to see if the current inline type is nestable in the current context + + if ( ! empty($nonNestables) and in_array($inlineType, $nonNestables)) + { + continue; + } + $Inline = $this->{'inline'.$inlineType}($Excerpt); if ( ! isset($Inline)) @@ -1034,6 +1095,13 @@ class Parsedown $Inline['position'] = $markerPosition; } + # cause the new element to 'inherit' our non nestables + + foreach ($nonNestables as $non_nestable) + { + $Inline['element']['nonNestables'][] = $non_nestable; + } + # the text that comes before the inline $unmarkedText = substr($text, 0, $Inline['position']); @@ -1074,7 +1142,6 @@ class Parsedown if (preg_match('/^('.$marker.'+)[ ]*(.+?)[ ]*(? 'a', 'handler' => 'line', + 'nonNestables' => array('Url', 'Link'), 'text' => null, 'attributes' => array( 'href' => null, @@ -1253,8 +1321,6 @@ class Parsedown $Element['attributes']['title'] = $Definition['title']; } - $Element['attributes']['href'] = str_replace(array('&', '<'), array('&', '<'), $Element['attributes']['href']); - return array( 'extent' => $extent, 'element' => $Element, @@ -1263,7 +1329,7 @@ class Parsedown protected function inlineMarkup($Excerpt) { - if ($this->markupEscaped or strpos($Excerpt['text'], '>') === false) + if ($this->markupEscaped or $this->safeMode or strpos($Excerpt['text'], '>') === false) { return; } @@ -1343,14 +1409,16 @@ class Parsedown if (preg_match('/\bhttps?:[\/]{2}[^\s<]+\b\/*/ui', $Excerpt['context'], $matches, PREG_OFFSET_CAPTURE)) { + $url = $matches[0][0]; + $Inline = array( 'extent' => strlen($matches[0][0]), 'position' => $matches[0][1], 'element' => array( 'name' => 'a', - 'text' => $matches[0][0], + 'text' => $url, 'attributes' => array( - 'href' => $matches[0][0], + 'href' => $url, ), ), ); @@ -1363,7 +1431,7 @@ class Parsedown { if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<(\w+:\/{2}[^ >]+)>/i', $Excerpt['text'], $matches)) { - $url = str_replace(array('&', '<'), array('&', '<'), $matches[1]); + $url = $matches[1]; return array( 'extent' => strlen($matches[0]), @@ -1401,6 +1469,11 @@ class Parsedown protected function element(array $Element) { + if ($this->safeMode) + { + $Element = $this->sanitiseElement($Element); + } + $markup = '<'.$Element['name']; if (isset($Element['attributes'])) @@ -1412,21 +1485,45 @@ class Parsedown continue; } - $markup .= ' '.$name.'="'.$value.'"'; + $markup .= ' '.$name.'="'.self::escape($value).'"'; } } + $permitRawHtml = false; + if (isset($Element['text'])) + { + $text = $Element['text']; + } + // very strongly consider an alternative if you're writing an + // extension + elseif (isset($Element['rawHtml'])) + { + $text = $Element['rawHtml']; + $allowRawHtmlInSafeMode = isset($Element['allowRawHtmlInSafeMode']) && $Element['allowRawHtmlInSafeMode']; + $permitRawHtml = !$this->safeMode || $allowRawHtmlInSafeMode; + } + + if (isset($text)) { $markup .= '>'; + if (!isset($Element['nonNestables'])) + { + $Element['nonNestables'] = array(); + } + if (isset($Element['handler'])) { - $markup .= $this->{$Element['handler']}($Element['text']); + $markup .= $this->{$Element['handler']}($text, $Element['nonNestables']); + } + elseif (!$permitRawHtml) + { + $markup .= self::escape($text, true); } else { - $markup .= $Element['text']; + $markup .= $text; } $markup .= ''; @@ -1485,10 +1582,77 @@ class Parsedown return $markup; } + protected function sanitiseElement(array $Element) + { + static $goodAttribute = '/^[a-zA-Z0-9][a-zA-Z0-9-_]*+$/'; + static $safeUrlNameToAtt = array( + 'a' => 'href', + 'img' => 'src', + ); + + if (isset($safeUrlNameToAtt[$Element['name']])) + { + $Element = $this->filterUnsafeUrlInAttribute($Element, $safeUrlNameToAtt[$Element['name']]); + } + + if ( ! empty($Element['attributes'])) + { + foreach ($Element['attributes'] as $att => $val) + { + # filter out badly parsed attribute + if ( ! preg_match($goodAttribute, $att)) + { + unset($Element['attributes'][$att]); + } + # dump onevent attribute + elseif (self::striAtStart($att, 'on')) + { + unset($Element['attributes'][$att]); + } + } + } + + return $Element; + } + + protected function filterUnsafeUrlInAttribute(array $Element, $attribute) + { + foreach ($this->safeLinksWhitelist as $scheme) + { + if (self::striAtStart($Element['attributes'][$attribute], $scheme)) + { + return $Element; + } + } + + $Element['attributes'][$attribute] = str_replace(':', '%3A', $Element['attributes'][$attribute]); + + return $Element; + } + # # Static Methods # + protected static function escape($text, $allowQuotes = false) + { + return htmlspecialchars($text, $allowQuotes ? ENT_NOQUOTES : ENT_QUOTES, 'UTF-8'); + } + + protected static function striAtStart($string, $needle) + { + $len = strlen($needle); + + if ($len > strlen($string)) + { + return false; + } + else + { + return strtolower(substr($string, 0, $len)) === strtolower($needle); + } + } + static function instance($name = 'default') { if (isset(self::$instances[$name])) diff --git a/www/extern/ParsedownExtra.php b/www/extern/ParsedownExtra.php index be6966d..632ba84 100644 --- a/www/extern/ParsedownExtra.php +++ b/www/extern/ParsedownExtra.php @@ -17,13 +17,13 @@ class ParsedownExtra extends Parsedown { # ~ - const version = '0.7.0'; + const version = '0.8.1'; # ~ function __construct() { - if (parent::version < '1.5.0') + if (version_compare(parent::version, '1.7.4') < 0) { throw new Exception('ParsedownExtra requires a later version of Parsedown'); } @@ -206,6 +206,10 @@ class ParsedownExtra extends Parsedown { $Block = parent::blockHeader($Line); + if (! isset($Block)) { + return null; + } + if (preg_match('/[ #]*{('.$this->regexAttribute.'+)}[ ]*$/', $Block['element']['text'], $matches, PREG_OFFSET_CAPTURE)) { $attributeString = $matches[1][0]; @@ -238,6 +242,10 @@ class ParsedownExtra extends Parsedown { $Block = parent::blockSetextHeader($Line, $Block); + if (! isset($Block)) { + return null; + } + if (preg_match('/[ ]*{('.$this->regexAttribute.'+)}[ ]*$/', $Block['element']['text'], $matches, PREG_OFFSET_CAPTURE)) { $attributeString = $matches[1][0]; @@ -302,6 +310,10 @@ class ParsedownExtra extends Parsedown { $Link = parent::inlineLink($Excerpt); + if (! isset($Link)) { + return null; + } + $remainder = substr($Excerpt['text'], $Link['extent']); if (preg_match('/^[ ]*{('.$this->regexAttribute.'+)}/', $remainder, $matches)) @@ -420,7 +432,7 @@ class ParsedownExtra extends Parsedown $Element['text'][1]['text'] []= array( 'name' => 'li', 'attributes' => array('id' => 'fn:'.$definitionId), - 'text' => "\n".$text."\n", + 'rawHtml' => "\n".$text."\n", ); } From b5f8543da2a1809a8093ad57aa38bc7404f14b62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Fri, 17 Jan 2020 00:25:29 +0100 Subject: [PATCH 23/33] ProjectEuler --- www/commands/html_panel-aoc-calendar.php | 2 +- www/data/css/styles.css | 2 + www/data/css/styles.min.css | 2 +- www/data/css/styles_errorview.scss | 2 + www/fragments/blogview_euler_list.php | 17 +++- www/fragments/blogview_euler_single.php | 38 ++++---- www/fragments/panel_aoc.php | 2 +- www/fragments/widget_befunge93.php | 31 +++--- www/fragments/widget_bfjoust.php | 24 +++-- www/internals/fragments.php | 118 +++++++++++++++-------- www/internals/modules/euler.php | 6 +- www/internals/parsedowncustom.php | 19 +--- www/pages/blog_view.php | 12 +-- www/pages/main.php | 10 +- 14 files changed, 169 insertions(+), 116 deletions(-) diff --git a/www/commands/html_panel-aoc-calendar.php b/www/commands/html_panel-aoc-calendar.php index 6db0baa..185a81b 100644 --- a/www/commands/html_panel-aoc-calendar.php +++ b/www/commands/html_panel-aoc-calendar.php @@ -18,4 +18,4 @@ $linkheader = boolval($API_OPTIONS['linkheader']); $ajax = boolval($API_OPTIONS['ajax']); $frameid = strval($API_OPTIONS['frameid']); -$SITE->fragments->PanelAdventOfCodeCalendar($year, $shownav, $linkheader, $ajax, false, $frameid); +echo $SITE->fragments->PanelAdventOfCodeCalendar($year, $shownav, $linkheader, $ajax, false, $frameid); diff --git a/www/data/css/styles.css b/www/data/css/styles.css index b36252b..562b2e8 100644 --- a/www/data/css/styles.css +++ b/www/data/css/styles.css @@ -1924,6 +1924,8 @@ html, body { background-color: #BBBBBB; text-align: left; padding: 4px; + font-family: Consolas, Monaco, "Courier New", Menlo, monospace; + font-size: small; overflow-x: auto; white-space: nowrap; width: 100%; diff --git a/www/data/css/styles.min.css b/www/data/css/styles.min.css index 1995694..3245623 100644 --- a/www/data/css/styles.min.css +++ b/www/data/css/styles.min.css @@ -364,7 +364,7 @@ html,body{margin:0;padding:0;height:100%} @media(min-width:851px){.ev_master{padding-bottom:80px}} .ev_master .ev_code{color:#333;text-align:center;font-size:150pt;font-weight:500;font-family:Consolas,Monaco,"Courier New",Menlo,monospace} .ev_master .ev_msg{color:#888;text-align:center;font-size:25pt} -.ev_master .ev_statusmore{color:#333;background-color:#bbb;text-align:left;padding:4px;overflow-x:auto;white-space:nowrap;width:100%} +.ev_master .ev_statusmore{color:#333;background-color:#bbb;text-align:left;padding:4px;font-family:Consolas,Monaco,"Courier New",Menlo,monospace;font-size:small;overflow-x:auto;white-space:nowrap;width:100%} @media(max-width:767px){ .ev_master .ev_code{font-size:75pt} .ev_master .ev_msg{font-size:15pt} diff --git a/www/data/css/styles_errorview.scss b/www/data/css/styles_errorview.scss index 4cdd822..38cb153 100644 --- a/www/data/css/styles_errorview.scss +++ b/www/data/css/styles_errorview.scss @@ -26,6 +26,8 @@ background-color: $LAYER1_BG_DARKER; text-align: left; padding: 4px; + font-family: $FONT_CODE; + font-size: small; overflow-x: auto; white-space: nowrap; diff --git a/www/fragments/blogview_euler_list.php b/www/fragments/blogview_euler_list.php index 6b76e3e..c31978d 100644 --- a/www/fragments/blogview_euler_list.php +++ b/www/fragments/blogview_euler_list.php @@ -1,11 +1,18 @@ + +modules->Euler()->listAll(); ?>
diff --git a/www/fragments/blogview_euler_single.php b/www/fragments/blogview_euler_single.php index a638664..7f06e96 100644 --- a/www/fragments/blogview_euler_single.php +++ b/www/fragments/blogview_euler_single.php @@ -1,18 +1,23 @@ -if ($problem === NULL) httpError(404, 'Project Euler entry not found'); +modules->Euler()->listAll(); +$problem = $SITE->modules->Euler()->getEulerProblemFromStrIdent($subview); +if ($problem === NULL) { $FRAME_OPTIONS->forceResult(404, 'Project Euler entry not found'); return; } $arr = []; $max = 0; @@ -42,28 +47,19 @@ $max = ceil($max / 20) * 20; Description: -
text(file_get_contents($problem['file_description'])); ?>
+
renderMarkdown(file_get_contents($problem['file_description'])); ?>

Solution: file_get_contents($problem['file_code']), - 'url' => $problem['url_raw'], - 'interactive' => !$problem['abbreviated'], - 'speed' => $problem['steps'] < 15000 ? 1 : ($problem['steps'] < 500000 ? 2 : 3), - 'editable' => false, - ]; - echo require (__DIR__ . '/../fragments/widget_befunge93.php'); + echo $SITE->fragments->WidgetBefunge93(file_get_contents($problem['file_code']), $problem['url_raw'], !$problem['abbreviated'], $problem['steps'] < 15000 ? 1 : ($problem['steps'] < 500000 ? 2 : 3), false); if ($problem['abbreviated']) echo 'This program is too big to display/execute here, click [download] to get the full program.
'; ?>
Explanation: -
text(file_get_contents($problem['file_explanation'])); ?>
+
renderMarkdown(file_get_contents($problem['file_explanation'])); ?>

diff --git a/www/fragments/panel_aoc.php b/www/fragments/panel_aoc.php index ac34542..16050e8 100644 --- a/www/fragments/panel_aoc.php +++ b/www/fragments/panel_aoc.php @@ -22,7 +22,7 @@ $year = intval(end($years));
- fragments->PanelAdventOfCodeCalendar($year, true, true, true); ?> + fragments->PanelAdventOfCodeCalendar($year, true, true, true); ?>
diff --git a/www/fragments/widget_befunge93.php b/www/fragments/widget_befunge93.php index 30e30da..ac7b188 100644 --- a/www/fragments/widget_befunge93.php +++ b/www/fragments/widget_befunge93.php @@ -1,15 +1,23 @@ 0) $speed_attr = ' data-b93rnr_initialspeed="'.$initspeed.'" '; $code_attr = ''; @@ -58,7 +67,7 @@ if ($interactive) { $result .= ' ' . "\n"; $result .= '' . "\n"; - includeAdditionalScript("/data/javascript/blogpost_bef93runner.js"); + $FRAME_OPTIONS->addScript("/data/javascript/blogpost_bef93runner.js", false); } else { @@ -72,4 +81,4 @@ else $result .= '' . "\n"; } -return $result; \ No newline at end of file +echo $result; \ No newline at end of file diff --git a/www/fragments/widget_bfjoust.php b/www/fragments/widget_bfjoust.php index e50e1f3..a77a2b2 100644 --- a/www/fragments/widget_bfjoust.php +++ b/www/fragments/widget_bfjoust.php @@ -1,15 +1,25 @@ ' . "\n"; $result .= '
' . "\n"; -$result .= ' ' . "\n"; -$result .= ' ' . "\n"; +$result .= ' ' . "\n"; +$result .= ' ' . "\n"; $result .= '
' . "\n"; $result .= '
' . "\n"; @@ -35,6 +45,6 @@ $result .= '
' . "\n"; $result .= '' . "\n"; -includeAdditionalScript("/data/javascript/blogpost_BFJoustBot_script.js"); +$FRAME_OPTIONS->addScript('/data/javascript/blogpost_BFJoustBot_script.js', false); -return $result; \ No newline at end of file +echo $result; \ No newline at end of file diff --git a/www/internals/fragments.php b/www/internals/fragments.php index e73a840..3a1e7ea 100644 --- a/www/internals/fragments.php +++ b/www/internals/fragments.php @@ -2,89 +2,131 @@ class Fragments { + private function evalFragment($name, $url, $params) + { + try + { + ob_start(); + { + global $FRAGMENT_PARAM; + $FRAGMENT_PARAM = $params; + /** @noinspection PhpIncludeInspection */ + include (__DIR__ . '/../fragments/' . $url); + } + return ob_get_contents(); + } + finally + { + ob_end_clean(); + } + } + public function PanelEuler() { - global $FRAGMENT_PARAM; - $FRAGMENT_PARAM = [ ]; - include (__DIR__ . '/../fragments/panel_euler.php'); + return $this->evalFragment('PanelEuler', 'panel_euler.php', [ ]); } public function PanelPrograms() { - global $FRAGMENT_PARAM; - $FRAGMENT_PARAM = [ ]; - include (__DIR__ . '/../fragments/panel_programs.php'); + return $this->evalFragment('PanelPrograms', 'panel_programs.php', [ ]); } public function PanelBlog() { - global $FRAGMENT_PARAM; - $FRAGMENT_PARAM = [ ]; - include (__DIR__ . '/../fragments/panel_blog.php'); + return $this->evalFragment('PanelBlog', 'panel_blog.php', [ ]); } public function PanelBooks() { - global $FRAGMENT_PARAM; - $FRAGMENT_PARAM = [ ]; - include (__DIR__ . '/../fragments/panel_books.php'); + return $this->evalFragment('PanelBooks', 'panel_books.php', [ ]); } public function PanelAdventOfCode() { - global $FRAGMENT_PARAM; - $FRAGMENT_PARAM = [ ]; - include (__DIR__ . '/../fragments/panel_aoc.php'); + return $this->evalFragment('PanelAdventOfCode', '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'); + return $this->evalFragment('PanelAdventOfCodeCalendar', 'panel_aoc_calendar.php', + [ + 'year' => $year, + 'nav' => $shownav, + 'linkheader' => $linkheader, + 'ajax' => $ajax, + 'frame' => $frame, + 'frameid' => ($frameid == null) ? ('aoc_frame_' . getRandomToken(16)) : $frameid, + ]); } public function BlogviewPlain(array $blogpost) { - global $FRAGMENT_PARAM; - $FRAGMENT_PARAM = [ 'blogpost' => $blogpost ]; - include (__DIR__ . '/../fragments/blogview_plain.php'); + return $this->evalFragment('BlogviewPlain', 'blogview_plain.php', + [ + 'blogpost' => $blogpost, + ]); } public function BlogviewMarkdown(array $blogpost) { - global $FRAGMENT_PARAM; - $FRAGMENT_PARAM = [ 'blogpost' => $blogpost ]; - include (__DIR__ . '/../fragments/blogview_markdown.php'); + return $this->evalFragment('BlogviewMarkdown', 'blogview_markdown.php', + [ + 'blogpost' => $blogpost, + ]); } public function BlogviewEulerList(array $blogpost) { - global $FRAGMENT_PARAM; - $FRAGMENT_PARAM = [ 'blogpost' => $blogpost ]; - include (__DIR__ . '/../fragments/blogview_euler_list.php'); + return $this->evalFragment('BlogviewEulerList', 'blogview_euler_list.php', + [ + 'blogpost' => $blogpost, + ]); } public function BlogviewEulerSingle(array $blogpost, string $subview) { - global $FRAGMENT_PARAM; - $FRAGMENT_PARAM = [ 'blogpost' => $blogpost, 'subview' => $subview ]; - include (__DIR__ . '/../fragments/blogview_euler_single.php'); + return $this->evalFragment('BlogviewEulerSingle', 'blogview_euler_single.php', + [ + 'blogpost' => $blogpost, + 'subview' => $subview, + ]); } public function BlogviewAdventOfCodeList(array $blogpost) { - global $FRAGMENT_PARAM; - $FRAGMENT_PARAM = [ 'blogpost' => $blogpost ]; - include (__DIR__ . '/../fragments/blogview_aoc_list.php'); + return $this->evalFragment('BlogviewAdventOfCodeList', 'blogview_aoc_list.php', + [ + 'blogpost' => $blogpost, + ]); } public function BlogviewAdventOfCodeSingle(array $blogpost, string $subview) { - global $FRAGMENT_PARAM; - $FRAGMENT_PARAM = [ 'blogpost' => $blogpost, 'subview' => $subview ]; - include (__DIR__ . '/../fragments/blogview_aoc_single.php'); + return $this->evalFragment('BlogviewAdventOfCodeSingle', 'blogview_aoc_single.php', + [ + 'blogpost' => $blogpost, + 'subview' => $subview, + ]); + } + + public function WidgetBefunge93(string $code, string $url, bool $interactive, int $speed, bool $editable) + { + return $this->evalFragment('WidgetBefunge93', 'widget_befunge93.php', + [ + 'code' => $code, + 'url' => $url, + 'interactive' => $interactive, + 'speed' => $speed, + 'editable' => $editable, + ]); + } + + public function WidgetBFJoust(string $codeLeft, string $codeRight) + { + return $this->evalFragment('WidgetBFJoust', 'widget_bfjoust.php', + [ + 'code_left' => $codeLeft, + 'code_right' => $codeRight, + ]); } } \ No newline at end of file diff --git a/www/internals/modules/euler.php b/www/internals/modules/euler.php index b226cbf..d3b91eb 100644 --- a/www/internals/modules/euler.php +++ b/www/internals/modules/euler.php @@ -33,9 +33,9 @@ class Euler $a['url_raw'] = 'https://raw.githubusercontent.com/Mikescher/Project-Euler_Befunge/master/processed/Euler_Problem-' . $n3p . '.b93'; $a['url_github'] = 'https://github.com/Mikescher/Project-Euler_Befunge'; - $a['file_description'] = (__DIR__ . '/../statics/euler/Euler_Problem-'.$n3p.'_description.md'); - $a['file_code'] = (__DIR__ . '/../statics/euler/Euler_Problem-'.$n3p.'.b93'); - $a['file_explanation'] = (__DIR__ . '/../statics/euler/Euler_Problem-'.$n3p.'_explanation.md'); + $a['file_description'] = (__DIR__ . '/../../statics/euler/Euler_Problem-'.$n3p.'_description.md'); + $a['file_code'] = (__DIR__ . '/../../statics/euler/Euler_Problem-'.$n3p.'.b93'); + $a['file_explanation'] = (__DIR__ . '/../../statics/euler/Euler_Problem-'.$n3p.'_explanation.md'); return $a; } diff --git a/www/internals/parsedowncustom.php b/www/internals/parsedowncustom.php index 6ef1164..a665f98 100644 --- a/www/internals/parsedowncustom.php +++ b/www/internals/parsedowncustom.php @@ -67,29 +67,14 @@ class ParsedownCustom extends ParsedownExtra protected function handleBFJoust(array $Element) { - global $PARAM_CODE_LEFT; - global $PARAM_CODE_RIGHT; - $split = preg_split("/-{16,}/", $Element['text']); - $PARAM_CODE_LEFT = trim($split[0]); - $PARAM_CODE_RIGHT = trim($split[1]); - - return require (__DIR__ . '/../fragments/widget_bfjoust.php'); + return Website::inst()->fragments->WidgetBFJoust(trim($split[0]), trim($split[1])); } protected function handleBef93(array $Element) { - global $PARAM_BEFUNGE93RUNNER; - $PARAM_BEFUNGE93RUNNER = - [ - 'code' => $Element['text'], - 'url' => '', - 'interactive' => $Element['b93_interactive'], - 'speed' => $Element['b93_speed'], - 'editable' => $Element['b93_editable'], - ]; - return require (__DIR__ . '/../fragments/widget_befunge93.php'); + return Website::inst()->fragments->WidgetBefunge93($Element['text'], '', $Element['b93_interactive'], $Element['b93_speed'], $Element['b93_editable']); } protected function blockTable($Line, array $Block = null) diff --git a/www/pages/blog_view.php b/www/pages/blog_view.php index 62fb473..595c105 100644 --- a/www/pages/blog_view.php +++ b/www/pages/blog_view.php @@ -33,21 +33,21 @@ else if ($post['type'] === 'plain') { - $SITE->fragments->BlogviewPlain($post); + echo $SITE->fragments->BlogviewPlain($post); } elseif ($post['type'] === 'markdown') { - $SITE->fragments->BlogviewMarkdown($post); + echo $SITE->fragments->BlogviewMarkdown($post); } elseif ($post['type'] === 'euler') { - if ($subview === '') $SITE->fragments->BlogviewEulerList($post); - else $SITE->fragments->BlogviewEulerSingle($post, $subview); + if ($subview === '') echo $SITE->fragments->BlogviewEulerList($post); + else echo $SITE->fragments->BlogviewEulerSingle($post, $subview); } elseif ($post['type'] === 'aoc') { - if ($subview === '') $SITE->fragments->BlogviewAdventOfCodeList($post); - else $SITE->fragments->BlogviewAdventOfCodeSingle($post, $subview); + if ($subview === '') echo $SITE->fragments->BlogviewAdventOfCodeList($post); + else echo $SITE->fragments->BlogviewAdventOfCodeSingle($post, $subview); } ?> diff --git a/www/pages/main.php b/www/pages/main.php index 917d890..7a8942b 100644 --- a/www/pages/main.php +++ b/www/pages/main.php @@ -12,12 +12,12 @@ $FRAME_OPTIONS->canonical_url = 'https://www.mikescher.com'; $FRAME_OPTIONS->activeHeader = 'home'; ?> -fragments->PanelEuler(); ?> +fragments->PanelEuler(); ?> -fragments->PanelPrograms(); ?> +fragments->PanelPrograms(); ?> -fragments->PanelBlog(); ?> +fragments->PanelBlog(); ?> -fragments->PanelBooks(); ?> +fragments->PanelBooks(); ?> -fragments->PanelAdventOfCode(); ?> +fragments->PanelAdventOfCode(); ?> From 81e129effa77ae0580e830c0e6ac08c1bdf71334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Fri, 17 Jan 2020 00:36:37 +0100 Subject: [PATCH 24/33] AdventOfCode --- www/fragments/blogview_aoc_list.php | 31 ++++++++++++----------- www/fragments/blogview_aoc_single.php | 35 +++++++++++++++----------- www/internals/modules/adventofcode.php | 6 ++--- 3 files changed, 39 insertions(+), 33 deletions(-) diff --git a/www/fragments/blogview_aoc_list.php b/www/fragments/blogview_aoc_list.php index ad487af..b5a0eb9 100644 --- a/www/fragments/blogview_aoc_list.php +++ b/www/fragments/blogview_aoc_list.php @@ -1,8 +1,17 @@ + + @@ -21,16 +30,8 @@ $year = $post['extras']['aoc:year'];
- text(Blog::getPostFragment($post)); - ?> + renderMarkdown($SITE->modules->Blog()->getPostFragment($post)); ?>
- $year, 'nav'=>true, 'linkheader'=>false, 'ajax'=>false]; - require (__DIR__ . '/../fragments/panel_aoc_calendar.php') - ?> - + fragments->PanelAdventOfCodeCalendar($year, true, false, false); ?>
\ No newline at end of file diff --git a/www/fragments/blogview_aoc_single.php b/www/fragments/blogview_aoc_single.php index 179d668..12a37be 100644 --- a/www/fragments/blogview_aoc_single.php +++ b/www/fragments/blogview_aoc_single.php @@ -1,23 +1,28 @@ + +modules->AdventOfCode()->getDayFromStrIdent($year, $subview); +if ($day === NULL) { $FRAME_OPTIONS->forceResult(404, 'AdventOfCode entry not found'); return; } ?>
@@ -43,7 +48,7 @@ $pd = new ParsedownCustom(); Part :
-
+
modules->AdventOfCode()->getSolutionCode($day, $i-1)); ?>
Result:
@@ -51,12 +56,12 @@ $pd = new ParsedownCustom(); - - + addScript("/data/javascript/prism.js", true); ?> + addStylesheet("/data/rawcss/prism.css"); ?>