diff --git a/.htaccess b/.htaccess index 7d971ed..00e6896 100644 --- a/.htaccess +++ b/.htaccess @@ -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] diff --git a/core/Documents/Admin.class.php b/core/Documents/Admin.class.php index 14b0425..30fb083 100644 --- a/core/Documents/Admin.class.php +++ b/core/Documents/Admin.class.php @@ -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; } } } diff --git a/core/Documents/Document404.class.php b/core/Documents/Document404.class.php new file mode 100644 index 0000000..581fcf5 --- /dev/null +++ b/core/Documents/Document404.class.php @@ -0,0 +1,60 @@ +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 .= "404 Not Found"; + return $html; + } + } +} + +?> diff --git a/core/Elements/Document.class.php b/core/Elements/Document.class.php index 6199428..0bfa7dd 100644 --- a/core/Elements/Document.class.php +++ b/core/Elements/Document.class.php @@ -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()); } } diff --git a/index.php b/index.php index cb17715..398bb0d 100644 --- a/index.php +++ b/index.php @@ -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();