php 7.4 dev branch

This commit is contained in:
2020-04-03 15:56:04 +02:00
parent 2636719583
commit a8fc52b42a
48 changed files with 456 additions and 530 deletions

View File

@@ -2,9 +2,10 @@
namespace Elements;
abstract class Body extends \View {
use View;
abstract class Body extends View {
public function __construct($document) {
parent::__construct($document);
}
};
?>
}

View File

@@ -2,14 +2,16 @@
namespace Elements;
use Objects\User;
abstract class Document {
protected $head;
protected $body;
protected $user;
protected $databaseRequired;
protected Head $head;
protected Body $body;
protected User $user;
protected bool $databaseRequired;
public function __construct($user, $headClass, $bodyClass) {
public function __construct(User $user, $headClass, $bodyClass) {
$this->head = new $headClass($this);
$this->body = new $bodyClass($this);
$this->user = $user;
@@ -29,30 +31,6 @@ abstract class Document {
return new $documentClass($user);
}
public static function createDocument($class) {
// TODO: check instance, configuration, ..
require_once realpath($_SERVER['DOCUMENT_ROOT']) . '/php/sql.php';
// require_once realpath($_SERVER['DOCUMENT_ROOT']) . '/php/conf/config.php';
// require_once realpath($_SERVER['DOCUMENT_ROOT']) . "/php/pages/$file.php";
require_once realpath($_SERVER['DOCUMENT_ROOT']) . '/php/api/objects/User.php';
$connectionData = getSqlData($database);
$sql = connectSQL($connectionData);
if(!$sql->isConnected()) {
http_response_code(500);
die('Internal Database error');
}
$user = new CUser($sql);
$document = new $class($user);
$code = $document->getCode();
$document->sendHeaders();
$user->sendCookies();
die($code);
}
function getCode() {
if ($this->databaseRequired) {
@@ -75,6 +53,4 @@ abstract class Document {
return $html;
}
};
?>
}

View File

@@ -2,15 +2,17 @@
namespace Elements;
abstract class Head extends \View {
use View;
protected $sources;
protected $title;
protected $metas;
protected $rawFields;
protected $keywords;
protected $description;
protected $baseUrl;
abstract class Head extends View {
protected array $sources;
protected string $title;
protected array $metas;
protected array $rawFields;
protected array $keywords;
protected string $description;
protected string $baseUrl;
function __construct($document) {
parent::__construct($document);
@@ -54,19 +56,6 @@ abstract class Head extends \View {
$this->addCSS(Link::FONTAWESOME);
}
public function loadSyntaxHighlighting() {
$this->addJS(Script::HIGHLIGHT);
$this->addJSCode(Script::HIGHLIGHT_JS_LOADER);
$this->addCSS(Link::HIGHLIGHT);
$this->addCSS(Link::HIGHLIGHT_THEME);
}
public function loadJQueryTerminal($unixFormatting = true) {
$this->addJS(Script::JQUERY_TERMINAL);
if($unixFormatting) $this->addJS(Script::JQUERY_TERMINAL_UNIX);
$this->addCSS(Link::JQUERY_TERMINAL);
}
public function loadGoogleRecaptcha($siteKey) {
$this->addJS("https://www.google.com/recaptcha/api.js?render=$siteKey");
}
@@ -80,11 +69,6 @@ abstract class Head extends \View {
$this->addJS(Script::BOOTSTRAP);
}
public function loadChartJS() {
$this->addJS(Script::MOMENT);
$this->addJS(Script::CHART);
}
public function getCode() {
$header = "<head>";
@@ -123,4 +107,3 @@ abstract class Head extends \View {
return $header;
}
}
?>

View File

@@ -2,7 +2,9 @@
namespace Elements;
class Link extends Source {
use View;
class Link extends View {
const STYLESHEET = "stylesheet";
const MIME_TEXT_CSS = "text/css";
@@ -23,20 +25,18 @@ class Link extends Source {
// const REVEALJS_THEME_MOON = "/css/reveal_moon.css";
// const REVEALJS_THEME_BLACK = "/css/reveal_black.css";
private $type;
private $rel;
private string $type;
private string $rel;
private string $href;
function __construct($rel, $href, $type = "") {
parent::__construct('link', $href);
$this->href = $href;
$this->type = $type;
$this->rel = $rel;
}
function getCode() {
$type = (empty($this->type) ? "" : " type=\"$this->type\"");
$link = "<link rel=\"$this->rel\" href=\"$this->url\" $type/>";
return $link;
return "<link rel=\"$this->rel\" href=\"$this->href\"$type/>";
}
}
?>

View File

@@ -2,7 +2,7 @@
namespace Elements;
class Script extends Source {
class Script extends \View {
const MIME_TEXT_JAVASCRIPT = "text/javascript";
@@ -32,11 +32,11 @@ class Script extends Source {
const HIGHLIGHT_JS_LOADER = "\$(document).ready(function(){\$('code').each(function(i, block) { hljs.highlightBlock(block); }); })";
private $type;
private $content;
private string $type;
private string $content;
private string $url;
function __construct($type, $src, $content = "") {
parent::__construct('script', $src);
$this->type = $type;
$this->content = $content;
}
@@ -48,6 +48,4 @@ class Script extends Source {
$script .= '</script>';
return $script;
}
}
?>
}

View File

@@ -1,22 +0,0 @@
<?php
namespace Elements;
class Source extends \View {
protected $sourceType;
protected $url;
public function __construct($sourceType, $url) {
$this->sourceType = $sourceType;
$this->url = $url;
}
public function getCode() {
return "<$sourceType />";
}
public function getUrl() { return $this->url; }
}
?>

View File

@@ -2,12 +2,11 @@
namespace Elements;
class Style extends Source {
class Style extends View {
private $style;
private string $style;
function __construct($style) {
parent::__construct('style', '');
$this->style = $style;
}
@@ -15,5 +14,3 @@ class Style extends Source {
return "<style>$this->style</style>";
}
}
?>