Initial Commit
This commit is contained in:
10
core/Elements/Body.class.php
Normal file
10
core/Elements/Body.class.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Elements;
|
||||
|
||||
abstract class Body extends \View {
|
||||
public function __construct($document) {
|
||||
parent::__construct($document);
|
||||
}
|
||||
};
|
||||
?>
|
||||
80
core/Elements/Document.class.php
Normal file
80
core/Elements/Document.class.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace Elements;
|
||||
|
||||
abstract class Document {
|
||||
|
||||
protected $head;
|
||||
protected $body;
|
||||
protected $user;
|
||||
protected $databseRequired;
|
||||
|
||||
public function __construct($user, $headClass, $bodyClass) {
|
||||
$this->head = new $headClass($this);
|
||||
$this->body = new $bodyClass($this);
|
||||
$this->user = $user;
|
||||
$this->databseRequired = true;
|
||||
}
|
||||
|
||||
public function getHead() { return $this->head; }
|
||||
public function getBody() { return $this->body; }
|
||||
public function getSQL() { return $this->user->getSQL(); }
|
||||
public function getUser() { return $this->user; }
|
||||
|
||||
protected function sendHeaders() {
|
||||
header("X-Frame-Options: DENY");
|
||||
}
|
||||
|
||||
public static function createSearchableDocument($documentClass, $user) {
|
||||
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->databseRequired) {
|
||||
$sql = $this->user->getSQL();
|
||||
if (is_null($sql)) {
|
||||
die("Database is not configured yet.");
|
||||
} else {
|
||||
die("Database is not connected: " . $sql->getLastError());
|
||||
}
|
||||
}
|
||||
|
||||
$body = $this->body->getCode();
|
||||
$head = $this->head->getCode();
|
||||
|
||||
$html = "<!DOCTYPE html>";
|
||||
$html .= "<html>";
|
||||
$html .= $head;
|
||||
$html .= $body;
|
||||
$html .= "</html>";
|
||||
return $html;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
?>
|
||||
126
core/Elements/Head.class.php
Normal file
126
core/Elements/Head.class.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace Elements;
|
||||
|
||||
abstract class Head extends \View {
|
||||
|
||||
protected $sources;
|
||||
protected $title;
|
||||
protected $metas;
|
||||
protected $rawFields;
|
||||
protected $keywords;
|
||||
protected $description;
|
||||
protected $baseUrl;
|
||||
|
||||
function __construct($document) {
|
||||
parent::__construct($document);
|
||||
$this->sources = array();
|
||||
$this->metas = $this->initMetas();
|
||||
$this->rawFields = $this->initRawFields();
|
||||
$this->title = $this->initTitle();
|
||||
$this->initSources();
|
||||
$this->init();
|
||||
}
|
||||
|
||||
protected abstract function initSources();
|
||||
protected abstract function initMetas();
|
||||
protected abstract function initRawFields();
|
||||
protected abstract function initTitle();
|
||||
|
||||
protected function init() {
|
||||
$this->keywords = array();
|
||||
$this->description = "";
|
||||
$this->baseUrl = "";
|
||||
}
|
||||
|
||||
public function setBaseUrl($baseUrl) { $this->baseUrl = $baseUrl; }
|
||||
public function setDescription($description) { $this->description = $description; }
|
||||
public function setKeywords($keywords) { $this->keywords = $keywords; }
|
||||
public function setTitle($title) { $this->title = $title; }
|
||||
public function getSources() { return $this->sources; }
|
||||
public function addScript($type, $url, $js = '') { $this->sources[] = new Script($type, $url, $js); }
|
||||
public function addRawField($rawField) { $this->rawFields[] = $rawField; }
|
||||
public function addMeta($aMeta) { $this->metas[] = $aMeta; }
|
||||
public function addLink($rel, $href, $type = "") { $this->sources[] = new Link($rel, $href, $type); }
|
||||
public function addKeywords($keywords) { array_merge($this->keywords, $keywords); }
|
||||
public function getTitle() { return $this->title; }
|
||||
|
||||
public function addCSS($href, $type = Link::MIME_TEXT_CSS) { $this->sources[] = new Link("stylesheet", $href, $type); }
|
||||
public function addStyle($style) { $this->sources[] = new Style($style); }
|
||||
public function addJS($url) { $this->sources[] = new Script(Script::MIME_TEXT_JAVASCRIPT, $url, ""); }
|
||||
public function addJSCode($code) { $this->sources[] = new Script(Script::MIME_TEXT_JAVASCRIPT, "", $code); }
|
||||
|
||||
public function loadFontawesome() {
|
||||
$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");
|
||||
}
|
||||
|
||||
public function loadJQuery() {
|
||||
$this->addJS(Script::JQUERY);
|
||||
}
|
||||
|
||||
public function loadBootstrap() {
|
||||
$this->addCSS(Link::BOOTSTRAP);
|
||||
$this->addJS(Script::BOOTSTRAP);
|
||||
}
|
||||
|
||||
public function loadChartJS() {
|
||||
$this->addJS(Script::MOMENT);
|
||||
$this->addJS(Script::CHART);
|
||||
}
|
||||
|
||||
public function getCode() {
|
||||
$header = "<head>";
|
||||
|
||||
foreach($this->metas as $aMeta) {
|
||||
$header .= '<meta';
|
||||
foreach($aMeta as $key => $val) {
|
||||
$header .= " $key=\"$val\"";
|
||||
}
|
||||
$header .= ' />';
|
||||
}
|
||||
|
||||
if(!empty($this->description)) {
|
||||
$header .= "<meta name=\"description\" content=\"$this->description\" />";
|
||||
}
|
||||
|
||||
if(!empty($this->keywords)) {
|
||||
$keywords = implode(", ", $this->keywords);
|
||||
$header .= "<meta name=\"keywords\" content=\"$keywords\" />";
|
||||
}
|
||||
|
||||
if(!empty($this->baseUrl)) {
|
||||
$header .= "<base href=\"$this->baseUrl\">";
|
||||
}
|
||||
|
||||
$header .= "<title>$this->title</title>";
|
||||
|
||||
foreach($this->sources as $src) {
|
||||
$header .= $src->getCode();
|
||||
}
|
||||
|
||||
foreach($this->rawFields as $raw) {
|
||||
$header .= $raw;
|
||||
}
|
||||
|
||||
$header .= "</head>";
|
||||
return $header;
|
||||
}
|
||||
}
|
||||
?>
|
||||
42
core/Elements/Link.class.php
Normal file
42
core/Elements/Link.class.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Elements;
|
||||
|
||||
class Link extends Source {
|
||||
|
||||
const STYLESHEET = "stylesheet";
|
||||
const MIME_TEXT_CSS = "text/css";
|
||||
|
||||
const FONTAWESOME = '/css/fontawesome.min.css';
|
||||
// const JQUERY_UI = '/css/jquery-ui.css';
|
||||
// const JQUERY_TERMINAL = '/css/jquery.terminal.min.css';
|
||||
const BOOTSTRAP = '/css/bootstrap.min.css';
|
||||
// const BOOTSTRAP_THEME = '/css/bootstrap-theme.min.css';
|
||||
// const BOOTSTRAP_DATEPICKER_CSS = '/css/bootstrap-datepicker.standalone.min.css';
|
||||
// const BOOTSTRAP_DATEPICKER3_CSS = '/css/bootstrap-datepicker.standalone.min.css';
|
||||
// const HIGHLIGHT = '/css/highlight.css';
|
||||
// const HIGHLIGHT_THEME = '/css/theme.css';
|
||||
const CORE = "/css/style.css";
|
||||
// const ADMIN = "/css/admin.css";
|
||||
// const HOME = "/css/home.css";
|
||||
// const REVEALJS = "/css/reveal.css";
|
||||
// const REVEALJS_THEME_MOON = "/css/reveal_moon.css";
|
||||
// const REVEALJS_THEME_BLACK = "/css/reveal_black.css";
|
||||
|
||||
private $type;
|
||||
private $rel;
|
||||
|
||||
function __construct($rel, $href, $type = "") {
|
||||
parent::__construct('link', $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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
53
core/Elements/Script.class.php
Normal file
53
core/Elements/Script.class.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Elements;
|
||||
|
||||
class Script extends Source {
|
||||
|
||||
const MIME_TEXT_JAVASCRIPT = "text/javascript";
|
||||
|
||||
const CORE = "/js/script.js";
|
||||
// const HOME = "/js/home.js";
|
||||
// const ADMIN = "/js/admin.js";
|
||||
// const SORTTABLE = "/js/sorttable.js";
|
||||
const JQUERY = "/js/jquery.min.js";
|
||||
// const JQUERY_UI = "/js/jquery-ui.js";
|
||||
// const JQUERY_MASKED_INPUT = "/js/jquery.maskedinput.min.js";
|
||||
// const JQUERY_CONTEXT_MENU = "/js/jquery.contextmenu.min.js";
|
||||
// const JQUERY_TERMINAL = "/js/jquery.terminal.min.js";
|
||||
// const JQUERY_TERMINAL_UNIX = "/js/unix_formatting.js";
|
||||
// const JSCOLOR = "/js/jscolor.min.js";
|
||||
// const SYNTAX_HIGHLIGHTER = "/js/syntaxhighlighter.js";
|
||||
// const HIGHLIGHT = "/js/highlight.pack.js";
|
||||
// const GOOGLE_CHARTS = "/js/loader.js";
|
||||
const BOOTSTRAP = "/js/bootstrap.min.js";
|
||||
// const BOOTSTRAP_DATEPICKER_JS = "/js/bootstrap-datepicker.min.js";
|
||||
// const POPPER = "/js/popper.min.js";
|
||||
// const JSMPEG = "/js/jsmpeg.min.js";
|
||||
// const MOMENT = "/js/moment.min.js";
|
||||
// const CHART = "/js/chart.js";
|
||||
// const REVEALJS = "/js/reveal.js";
|
||||
// const REVEALJS_PLUGIN_NOTES = "/js/reveal_notes.js";
|
||||
const INSTALL = "/js/install.js";
|
||||
|
||||
const HIGHLIGHT_JS_LOADER = "\$(document).ready(function(){\$('code').each(function(i, block) { hljs.highlightBlock(block); }); })";
|
||||
|
||||
private $type;
|
||||
private $content;
|
||||
|
||||
function __construct($type, $src, $content = "") {
|
||||
parent::__construct('script', $src);
|
||||
$this->type = $type;
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
function getCode() {
|
||||
$src = (empty($this->url) ? "" : " src=\"$this->url\"");
|
||||
$script = "<script type=\"$this->type\"$src>";
|
||||
$script .= $this->content;
|
||||
$script .= '</script>';
|
||||
return $script;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
22
core/Elements/Source.class.php
Normal file
22
core/Elements/Source.class.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?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; }
|
||||
}
|
||||
|
||||
?>
|
||||
19
core/Elements/Style.class.php
Normal file
19
core/Elements/Style.class.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Elements;
|
||||
|
||||
class Style extends Source {
|
||||
|
||||
private $style;
|
||||
|
||||
function __construct($style) {
|
||||
parent::__construct('style', '');
|
||||
$this->style = $style;
|
||||
}
|
||||
|
||||
function getCode() {
|
||||
return "<style>$this->style</style>";
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user