RuleEngine + Frame
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<?php if(count(get_included_files()) ==1) exit("Direct access not permitted.");
|
||||
<?php
|
||||
|
||||
require_once (__DIR__ . '/../internals/database.php');
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?php if(count(get_included_files()) ==1) exit("Direct access not permitted.");
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/base.php';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?php if(count(get_included_files()) ==1) exit("Direct access not permitted.");
|
||||
<?php
|
||||
|
||||
class Database
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?php if(count(get_included_files()) ==1) exit("Direct access not permitted.");
|
||||
<?php
|
||||
|
||||
class Euler
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?php if(count(get_included_files()) ==1) exit("Direct access not permitted.");
|
||||
<?php
|
||||
|
||||
require_once (__DIR__ . '/../internals/database.php');
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?php if(count(get_included_files()) ==1) exit("Direct access not permitted.");
|
||||
<?php
|
||||
|
||||
require_once (__DIR__ . '/../internals/base.php');
|
||||
require_once (__DIR__ . '/../extern/egg/ExtendedGitGraph2.php');
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?php if(count(get_included_files()) ==1) exit("Direct access not permitted.");
|
||||
<?php
|
||||
|
||||
|
||||
class PageFrameOptions
|
||||
|
||||
109
www/internals/parsedowncustom.php
Normal file
109
www/internals/parsedowncustom.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
require_once (__DIR__ . '/../internals/base.php');
|
||||
require_once (__DIR__ . '/../extern/Parsedown.php');
|
||||
require_once (__DIR__ . '/../extern/ParsedownExtra.php');
|
||||
|
||||
|
||||
class ParsedownCustom extends ParsedownExtra
|
||||
{
|
||||
protected function element(array $Element)
|
||||
{
|
||||
if (isset($Element['custom']) && $Element['custom'] && isset($Element['handler']))
|
||||
return $this->{$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;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
<?php if(count(get_included_files()) ==1) exit("Direct access not permitted.");
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/base.php';
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?php if(count(get_included_files()) ==1) exit("Direct access not permitted.");
|
||||
<?php
|
||||
|
||||
require_once "website.php";
|
||||
require_once "utils.php";
|
||||
|
||||
class RuleEngine
|
||||
{
|
||||
@@ -28,11 +27,7 @@ class RuleEngine
|
||||
$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);
|
||||
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'];
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?php if(count(get_included_files()) ==1) exit("Direct access not permitted.");
|
||||
<?php
|
||||
|
||||
require_once (__DIR__ . '/../internals/database.php');
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php if(count(get_included_files()) ==1) exit("Direct access not permitted.");
|
||||
<?php
|
||||
|
||||
require_once "URLRoute.php";
|
||||
require_once "website.php";
|
||||
|
||||
class URLRoute
|
||||
{
|
||||
@@ -14,7 +14,7 @@ class URLRoute
|
||||
public $parameter;
|
||||
|
||||
/** @var int */
|
||||
public $minimal_access_rights;
|
||||
public $needsAdminLogin;
|
||||
|
||||
/** @var int */
|
||||
public $isAPI;
|
||||
@@ -24,19 +24,19 @@ class URLRoute
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
<?php if(count(get_included_files()) ==1) exit("Direct access not permitted.");
|
||||
<?php
|
||||
|
||||
global $CONFIG;
|
||||
$CONFIG = require 'config.php';
|
||||
@@ -40,7 +40,6 @@ function httpDie($errorcode, $message)
|
||||
ob_flush();
|
||||
http_response_code($errorcode);
|
||||
die($message);
|
||||
|
||||
}
|
||||
|
||||
function destructiveUrlEncode($str) {
|
||||
@@ -403,4 +402,35 @@ function getRandomToken($length = 32)
|
||||
catch (Exception $e) { throw new InvalidArgumentException($e); }
|
||||
|
||||
throw new InvalidArgumentException("No random");
|
||||
}
|
||||
|
||||
function isHTTPRequest()
|
||||
{
|
||||
return (!isset($_SERVER['HTTPS'])) || empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "off";
|
||||
}
|
||||
|
||||
function formatException($e)
|
||||
{
|
||||
if ($e === null) return "NULL";
|
||||
|
||||
if ($e instanceof Exception)
|
||||
{
|
||||
$r = '';
|
||||
$r .= $e->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('<br />', "\n", $xdbg);
|
||||
$xdbg = str_replace('<br/>', "\n", $xdbg);
|
||||
$xdbg = str_replace('<br>', "\n", $xdbg);
|
||||
$xdbg = strip_tags($xdbg);
|
||||
$xdbg = htmlspecialchars($xdbg);
|
||||
$r .= $xdbg . "\n";
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
|
||||
return 'object';
|
||||
}
|
||||
@@ -1,9 +1,25 @@
|
||||
<?php if(count(get_included_files()) ==1) exit("Direct access not permitted.");
|
||||
<?php
|
||||
|
||||
require_once 'ruleengine.php';
|
||||
require_once 'urlroute.php';
|
||||
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';
|
||||
|
||||
class Website
|
||||
{
|
||||
/** @var Website */
|
||||
|
||||
Reference in New Issue
Block a user