This commit is contained in:
Roman Hergenreder 2020-02-10 12:32:53 +01:00
parent db4f2db28a
commit cdd159869b
5 changed files with 80 additions and 4 deletions

@ -1,6 +1,8 @@
php_flag display_errors on
Options -Indexes
# ErrorDocument 404
RewriteEngine On
RewriteRule ^api/(.*)?$ index.php?api=$1&$2 [L,QSA]
RewriteRule ^(?!((js|css|img|fonts|api)($|\/)))(.*)?$ index.php?site=$1&$2 [L,QSA]
RewriteRule ^((?!((js|css|img|fonts|api)($|\/)))(.*)?)$ index.php?site=$1&$2 [L,QSA]

@ -4,7 +4,6 @@ namespace Documents {
class Admin extends \Elements\Document {
public function __construct($user) {
parent::__construct($user, Admin\Head::class, Admin\Body::class);
$this->databseRequired = false;
}
}
}

@ -0,0 +1,60 @@
<?php
namespace Documents {
class Document404 extends \Elements\Document {
public function __construct($user) {
parent::__construct($user, Document404\Head404::class, Document404\Body404::class);
}
}
}
namespace Documents\Document404 {
class Head404 extends \Elements\Head {
public function __construct($document) {
parent::__construct($document);
}
protected function initSources() {
// $this->loadJQuery();
// $this->loadBootstrap();
// $this->loadFontawesome();
// $this->addJS(\Elements\Script::CORE);
// $this->addCSS(\Elements\Link::CORE);
}
protected function initMetas() {
return array(
array('name' => 'viewport', 'content' => 'width=device-width, initial-scale=1.0'),
array('name' => 'format-detection', 'content' => 'telephone=yes'),
array('charset' => 'utf-8'),
array("http-equiv" => 'expires', 'content' => '0'),
array("name" => 'robots', 'content' => 'noarchive'),
);
}
protected function initRawFields() {
return array();
}
protected function initTitle() {
return "WebBase - Not Found";
}
}
class Body404 extends \Elements\Body {
public function __construct($document) {
parent::__construct($document);
}
public function getCode() {
$html = parent::getCode();
$html .= "<b>404 Not Found</b>";
return $html;
}
}
}
?>

@ -59,7 +59,7 @@ abstract class Document {
$sql = $this->user->getSQL();
if (is_null($sql)) {
die("Database is not configured yet.");
} else {
} else if(!$sql->isConnected()) {
die("Database is not connected: " . $sql->getLastError());
}
}

@ -66,7 +66,22 @@ if(isset($_GET["api"]) && is_string($_GET["api"])) {
if ($installation) {
$document = new Documents\Install($user);
} else {
$document = new Documents\Admin($user);
$documentName = $_GET["site"];
if(empty($documentName) || strcasecmp($documentName, "install") === 0) {
$documentName = "home";
} else if(!preg_match("/[a-zA-Z]+(\/[a-zA-Z]+)*/", $documentName)) {
$documentName = "Document404";
}
$documentName = strtoupper($documentName[0]) . substr($documentName, 1);
$documentName = str_replace("/", "\\", $documentName);
$class = "\\Documents\\$documentName";
$file = getClassPath($class);
if(!file_exists($file) || !is_subclass_of($class, \Elements\Document::class)) {
$document = new \Documents\Document404($user);
} else {
$document = new $class($user);
}
}
$response = $document->getCode();