diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 77e9928..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -config/config.php \ No newline at end of file diff --git a/.htaccess b/.htaccess new file mode 100755 index 0000000..ef14c16 --- /dev/null +++ b/.htaccess @@ -0,0 +1,5 @@ + + RewriteEngine on + RewriteRule ^$ public/ [L] + RewriteRule (.*) public/$1 [L] + \ No newline at end of file diff --git a/FRAMEWORK.md b/FRAMEWORK.md old mode 100644 new mode 100755 diff --git a/LICENSE.md b/LICENSE.md new file mode 100755 index 0000000..20825c0 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,6 @@ +Copyright 2021 Aaron Gensetter +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 24fead7..57dff90 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ +# Feautures + +- Markdown Support +- User Management +- Installer # Installation Base OS: Ubuntu-server 20.04 @@ -56,25 +61,15 @@ EXIT; ``` bash $ cd /var/www/html -$ git clone https://github.com/HATBE/PHP-MVC-Blog.git . -$ sudo mysql -u root -p blog < dump.sql +$ git clone https://github.com/HATBE/Blog.git . +$ sudo chmod 755 /var/www/html -R +$ sudo chown www-data:www-data /var/www/html ``` -Changing Config - -``` bash -$ nano src/config/config.php -``` - -``` php -define('DB_HOST', ''); -define('DB_USER', ''); -define('DB_PASSWORD', ''); -define('DB_NAME', ''); -``` +Now, you can navigate to https:// in your browser. -Now, you can navigate to http:// in your browser. +Follow the instructions of the installer. -Standard credentials (from dump.sql): +Standard credentials: Username: admin Password: 1234 diff --git a/TODO.md b/TODO.md old mode 100644 new mode 100755 index 6fc5bf3..3a9c97c --- a/TODO.md +++ b/TODO.md @@ -1,8 +1,5 @@ # TODO - Prio / description -- 100 markdown -> parsedown - 40 Search system -- 20 Searchbar -- 5 installer \ No newline at end of file +- 20 Searchbar \ No newline at end of file diff --git a/config/config.php b/config/config.php deleted file mode 100644 index 798732f..0000000 --- a/config/config.php +++ /dev/null @@ -1,15 +0,0 @@ -query($sql); + + if($result->num_rows !== 0) { + echo "Database is not empty, delete all tables!"; + exit(); + } + + mysqli_select_db($conn, $dbname); + + $templine = ''; + $lines = file(__DIR__ . '/blog.sql'); + + foreach ($lines as $line) { + if (substr($line, 0, 2) == '--' || $line == '') { + continue; + } + $templine .= $line; + if (substr(trim($line), -1, 1) == ';') { + mysqli_query($conn, $templine); + $templine = ''; + } + + } + + file_put_contents(__DIR__ . '/../config/config.php', $config); + + file_put_contents(__DIR__ . '/../install/.installed', 'true'); + header('Location: ' . $url); + } +?> + + + + + + + + + + Installation + + + +
+

Installation

+
+ Please Create the Database! +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+
+ + +
+
+ + +
Separate with ","
+
+
+ + +
+
+ + +
+ + +
+
+ + + \ No newline at end of file diff --git a/public/.htaccess b/public/.htaccess old mode 100644 new mode 100755 diff --git a/public/assets/css/style.css b/public/assets/css/style.css old mode 100644 new mode 100755 diff --git a/public/index.php b/public/index.php old mode 100644 new mode 100755 diff --git a/public/robots.txt b/public/robots.txt new file mode 100755 index 0000000..67337b3 --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,4 @@ +User-agent: * + +Disallow: /auth/ +Disallow: /users/ \ No newline at end of file diff --git a/src/classes/Controller.php b/src/classes/Controller.php old mode 100644 new mode 100755 diff --git a/src/classes/Core.php b/src/classes/Core.php old mode 100644 new mode 100755 index d4e39fc..414eacc --- a/src/classes/Core.php +++ b/src/classes/Core.php @@ -5,14 +5,15 @@ class Core { private $method = 'index'; // this must exist! in /src/classes/controllers/{class}->{method} private $params = []; - private $loggedInUser = null; - public function __construct() { $this->init(); } private function init() { session_start(); + + $this->checkInstalled(); + $this->include(); $this->getUrl(); $this->getController(); @@ -65,4 +66,11 @@ private function getUrl() { $this->url = $url; } } + + private function checkInstalled() { + if(!file_exists(__DIR__ . '/../../install/.installed')) { + require_once(__DIR__ . '/../../install/install.php'); + exit(); + } + } } \ No newline at end of file diff --git a/src/classes/Database.php b/src/classes/Database.php old mode 100644 new mode 100755 diff --git a/src/classes/Linker.php b/src/classes/Linker.php old mode 100644 new mode 100755 diff --git a/src/classes/Model.php b/src/classes/Model.php old mode 100644 new mode 100755 diff --git a/src/classes/Template.php b/src/classes/Template.php old mode 100644 new mode 100755 diff --git a/src/classes/controllers/AuthController.php b/src/classes/controllers/AuthController.php old mode 100644 new mode 100755 diff --git a/src/classes/controllers/PostsController.php b/src/classes/controllers/PostsController.php old mode 100644 new mode 100755 diff --git a/src/classes/controllers/UsersController.php b/src/classes/controllers/UsersController.php old mode 100644 new mode 100755 diff --git a/src/classes/lib/Parsedown.php b/src/classes/lib/Parsedown.php old mode 100644 new mode 100755 diff --git a/src/classes/models/AuthModel.php b/src/classes/models/AuthModel.php old mode 100644 new mode 100755 diff --git a/src/classes/models/PostModel.php b/src/classes/models/PostModel.php old mode 100644 new mode 100755 diff --git a/src/classes/models/UserModel.php b/src/classes/models/UserModel.php old mode 100644 new mode 100755 diff --git a/src/templates/alert.php b/src/templates/alert.php old mode 100644 new mode 100755 diff --git a/src/templates/backBtn.php b/src/templates/backBtn.php old mode 100644 new mode 100755 diff --git a/src/templates/delete.php b/src/templates/delete.php old mode 100644 new mode 100755 diff --git a/src/templates/footer.php b/src/templates/footer.php old mode 100644 new mode 100755 diff --git a/src/templates/header.php b/src/templates/header.php old mode 100644 new mode 100755 index 22f78e4..577a4e4 --- a/src/templates/header.php +++ b/src/templates/header.php @@ -17,18 +17,18 @@ <?= PAGE_TITLE?> - <?= $title?> - +
-

+

-

+
diff --git a/src/templates/pagination.php b/src/templates/pagination.php old mode 100644 new mode 100755 diff --git a/src/templates/post.php b/src/templates/post.php old mode 100644 new mode 100755 diff --git a/src/templates/postForm.php b/src/templates/postForm.php old mode 100644 new mode 100755 diff --git a/src/templates/postsList.php b/src/templates/postsList.php old mode 100644 new mode 100755 diff --git a/src/templates/userForm.php b/src/templates/userForm.php old mode 100644 new mode 100755 diff --git a/src/views/auth/login.php b/src/views/auth/login.php old mode 100644 new mode 100755 index b3fe90f..20bda57 --- a/src/views/auth/login.php +++ b/src/views/auth/login.php @@ -1,4 +1,6 @@ - 'Login']);?> + 'Login', 'tags' => '']);?> + +

Login

$data['username'], 'msg' => $data['msg'], 'action' => 'Login']);?> diff --git a/src/views/auth/register.php b/src/views/auth/register.php old mode 100644 new mode 100755 index 25ad3af..1d5ad1d --- a/src/views/auth/register.php +++ b/src/views/auth/register.php @@ -1,4 +1,6 @@ - 'Register']);?> + 'Register', 'tags' => '']);?> + +

Register

$data['username'], 'msg' => $data['msg'], 'action' => 'Register']);?> diff --git a/src/views/posts/create.php b/src/views/posts/create.php old mode 100644 new mode 100755 index 9f45312..5eb2467 --- a/src/views/posts/create.php +++ b/src/views/posts/create.php @@ -1,6 +1,8 @@ - 'Home']);?> + 'Create Post', 'tags' => '']);?> + +

Create Post

'posts', 'method' => 'index', 'args' => ''])?> - $data['title'], 'body' => $data['body'], 'actionName' => $data['actionName'], 'errors' => $data['errors']));?> + $data['title'], 'body' => $data['body'], 'actionName' => $data['actionName'], 'errors' => $data['errors']));?> \ No newline at end of file diff --git a/src/views/posts/delete.php b/src/views/posts/delete.php old mode 100644 new mode 100755 index 3b28508..d951cb9 --- a/src/views/posts/delete.php +++ b/src/views/posts/delete.php @@ -1,4 +1,6 @@ - 'Home']);?> + 'Delete Post', 'tags' => '']);?> + +

Delete Post

'posts', 'method' => 'index', 'args' => ''])?> 'Post', 'id' => $data['id']]);?> diff --git a/src/views/posts/edit.php b/src/views/posts/edit.php old mode 100644 new mode 100755 index fccb9c0..3e4c064 --- a/src/views/posts/edit.php +++ b/src/views/posts/edit.php @@ -1,4 +1,6 @@ - 'Home']);?> + 'Edit Post', 'tags' => '']);?> + +

Edit Post

'posts', 'method' => 'index', 'args' => ''])?> $data['title'], 'body' => $data['body'], 'actionName' => $data['actionName'], 'errors' => $data['errors']));?> diff --git a/src/views/posts/index.php b/src/views/posts/index.php old mode 100644 new mode 100755 index 44b94c1..400b865 --- a/src/views/posts/index.php +++ b/src/views/posts/index.php @@ -1,6 +1,8 @@ - 'Home']);?> + 'Home', 'tags' => '']);?> - $data['posts']['posts'], 'meta' => $data['posts']['meta']]);?> - $data['posts']['meta'], 'controller' => 'posts', 'method' => 'index']);?> +

Home

+ + $data['posts']['posts'], 'meta' => $data['posts']['meta']]);?> + $data['posts']['meta'], 'controller' => 'posts', 'method' => 'index']);?> \ No newline at end of file diff --git a/src/views/posts/post.php b/src/views/posts/post.php old mode 100644 new mode 100755 index 8a92245..87ab9b4 --- a/src/views/posts/post.php +++ b/src/views/posts/post.php @@ -1,4 +1,6 @@ - $data['post'] != null ? $data['post']->title : 'post not found']);?> + $data['post'] != null ? $data['post']->title : 'post not found', 'tags' => '']);?> + +

title : 'post not found'?>

'posts', 'method' => 'index', 'args' => $data['page']])?> diff --git a/src/views/users/delete.php b/src/views/users/delete.php old mode 100644 new mode 100755 index 4da11db..f4031f2 --- a/src/views/users/delete.php +++ b/src/views/users/delete.php @@ -1,4 +1,6 @@ - 'Home']);?> + 'Delete User', 'tags' => '']);?> + +

Delete User

'users', 'method' => 'index', 'args' => ''])?> 'User', 'id' => $data['id']]);?> diff --git a/src/views/users/edit.php b/src/views/users/edit.php old mode 100644 new mode 100755 index 663ae46..d8ff7e6 --- a/src/views/users/edit.php +++ b/src/views/users/edit.php @@ -1,4 +1,6 @@ - 'Edit']);?> + 'Edit User', 'tags' => '']);?> + +

Edit User

$data['username'], 'msg' => $data['msg'], 'action' => 'Edit']);?> diff --git a/src/views/users/index.php b/src/views/users/index.php old mode 100644 new mode 100755 index 551dcd6..5c64a71 --- a/src/views/users/index.php +++ b/src/views/users/index.php @@ -1,4 +1,6 @@ - 'Users']);?> + 'Users', 'tags' => '']);?> + +

Users Overview

+ Register