Skip to content

Commit 52254af

Browse files
authored
Merge pull request #2 from HATBE/dev
adding installer -> finish version
2 parents 7c0a46d + 901dcfc commit 52254af

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+245
-54
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.htaccess

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<IfModule mod_rewrite.c>
2+
RewriteEngine on
3+
RewriteRule ^$ public/ [L]
4+
RewriteRule (.*) public/$1 [L]
5+
</IfModule>

FRAMEWORK.md

100644100755
File mode changed.

LICENSE.md

Lines changed: 6 additions & 0 deletions

README.md

100644100755
Lines changed: 11 additions & 16 deletions

TODO.md

100644100755
Lines changed: 1 addition & 4 deletions

config/config.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

install/blog.sql

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
2+
START TRANSACTION;
3+
SET time_zone = "+00:00";
4+
5+
CREATE TABLE `posts` (
6+
`id` int(11) NOT NULL,
7+
`user_fk` int(11) NOT NULL,
8+
`title` varchar(255) NOT NULL,
9+
`body` text NOT NULL,
10+
`date` datetime NOT NULL DEFAULT current_timestamp()
11+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
12+
13+
INSERT INTO `posts` (`id`, `user_fk`, `title`, `body`, `date`) VALUES
14+
(1, 1, 'Hello World', 'This is the first blog post!', '2021-11-04 12:00:00');
15+
16+
CREATE TABLE `users` (
17+
`id` int(11) NOT NULL,
18+
`username` varchar(255) NOT NULL,
19+
`password` varchar(255) NOT NULL
20+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
21+
22+
INSERT INTO `users` (`id`, `username`, `password`) VALUES
23+
(1, 'admin', '$2y$10$D5Xy0fbHmIz1i0Scu3mD0Oa/eKUaaW/c6Zz0eu1kqsmLM76Cfxdry');
24+
25+
ALTER TABLE `posts`
26+
ADD PRIMARY KEY (`id`),
27+
ADD KEY `posts_users` (`user_fk`);
28+
29+
ALTER TABLE `users`
30+
ADD PRIMARY KEY (`id`);
31+
32+
ALTER TABLE `posts`
33+
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=17;
34+
35+
ALTER TABLE `users`
36+
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;
37+
38+
ALTER TABLE `posts`
39+
ADD CONSTRAINT `posts_users` FOREIGN KEY (`user_fk`) REFERENCES `users` (`id`);
40+
COMMIT;

install/install.php

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<?php
2+
if(!is_writable(__DIR__ . '/../config/')) {
3+
echo "Error! no permissions on /config!";
4+
exit();
5+
}
6+
if(isset($_POST['submit'])) {
7+
$dbhost = $_POST['dbhost'];
8+
$dbuser = $_POST['dbuser'];
9+
$dbpass = $_POST['dbpass'];
10+
$dbname = $_POST['dbname'];
11+
$url = substr($_POST['url'], -1) !== '/' ? $_POST['url'] . '/': $_POST['url'];
12+
$keywords = $_POST['keywords'];
13+
$description = $_POST['description'];
14+
$title = $_POST['title'];
15+
$slogan = $_POST['slogan'];
16+
17+
$config = "<?php
18+
// database
19+
define('DB_HOST', '".$dbhost."');
20+
define('DB_USER', '".$dbuser."');
21+
define('DB_PASS', '".$dbpass."');
22+
define('DB_NAME', '".$dbname."');
23+
24+
// page settings
25+
define('ROOT_PATH', '".$url."'); // domain (must end with a \"/\"!)
26+
define('DEFAULT_KEYWORDS', '".$keywords."');
27+
define('DESCRIPTION', '".$description."');
28+
define('PAGE_TITLE', '".$title."');
29+
define('PAGE_SLOGAN', '".$slogan."');
30+
31+
define('ITEMS_PER_PAGE', 4);";
32+
33+
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
34+
35+
if (mysqli_connect_errno()) {
36+
echo "Connection to database failed";
37+
exit();
38+
}
39+
40+
$sql = "SHOW TABLES IN $dbname";
41+
$result = $conn->query($sql);
42+
43+
if($result->num_rows !== 0) {
44+
echo "Database is not empty, delete all tables!";
45+
exit();
46+
}
47+
48+
mysqli_select_db($conn, $dbname);
49+
50+
$templine = '';
51+
$lines = file(__DIR__ . '/blog.sql');
52+
53+
foreach ($lines as $line) {
54+
if (substr($line, 0, 2) == '--' || $line == '') {
55+
continue;
56+
}
57+
$templine .= $line;
58+
if (substr(trim($line), -1, 1) == ';') {
59+
mysqli_query($conn, $templine);
60+
$templine = '';
61+
}
62+
63+
}
64+
65+
file_put_contents(__DIR__ . '/../config/config.php', $config);
66+
67+
file_put_contents(__DIR__ . '/../install/.installed', 'true');
68+
header('Location: ' . $url);
69+
}
70+
?>
71+
<!DOCTYPE html>
72+
<html lang="en">
73+
<head>
74+
<meta charset="UTF-8">
75+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
76+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
78+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
79+
80+
<title>Installation</title>
81+
</head>
82+
<body>
83+
84+
<div class="container">
85+
<h1>Installation</h1>
86+
<form method="post">
87+
<span>Please Create the Database!</span>
88+
<div class="mb-3">
89+
<label class="form-label">DB Host*</label>
90+
<input name="dbhost" type="text" value="localhost" class="form-control">
91+
</div>
92+
<div class="mb-3">
93+
<label class="form-label">DB User*</label>
94+
<input name="dbuser" type="text" class="form-control">
95+
</div>
96+
<div class="mb-3">
97+
<label class="form-label">DB Password*</label>
98+
<input name="dbpass" type="password" class="form-control">
99+
</div>
100+
<div class="mb-3">
101+
<label class="form-label">DB Name*</label>
102+
<input name="dbname" type="text" class="form-control">
103+
</div>
104+
<hr>
105+
<div class="mb-3">
106+
<label class="form-label">Title*</label>
107+
<input name="title" type="text" class="form-control">
108+
</div>
109+
<div class="mb-3">
110+
<label class="form-label">URL/Path*</label>
111+
<input name="url" value="<?= $_SERVER['HTTPS'] ? 'https://' : 'http://' ?><?= $_SERVER['HTTP_HOST']?>/" type="text" class="form-control">
112+
</div>
113+
<div class="mb-3">
114+
<label class="form-label">Keywords*</label>
115+
<input name="keywords" type="text" class="form-control">
116+
<div class="form-text">Separate with ","</div>
117+
</div>
118+
<div class="mb-3">
119+
<label class="form-label">Description*</label>
120+
<input name="description" type="text" class="form-control">
121+
</div>
122+
<div class="mb-3">
123+
<label class="form-label">Slogan*</label>
124+
<input name="slogan" type="text" class="form-control">
125+
</div>
126+
127+
<button name="submit" type="submit" class="btn btn-primary">Submit</button>
128+
</form>
129+
</div>
130+
131+
</body>
132+
</html>

public/.htaccess

100644100755
File mode changed.

public/assets/css/style.css

100644100755
File mode changed.

public/index.php

100644100755
File mode changed.

public/robots.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
User-agent: *
2+
3+
Disallow: /auth/
4+
Disallow: /users/

src/classes/Controller.php

100644100755
File mode changed.

src/classes/Core.php

100644100755
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ class Core {
55
private $method = 'index'; // this must exist! in /src/classes/controllers/{class}->{method}
66
private $params = [];
77

8-
private $loggedInUser = null;
9-
108
public function __construct() {
119
$this->init();
1210
}
1311

1412
private function init() {
1513
session_start();
14+
15+
$this->checkInstalled();
16+
1617
$this->include();
1718
$this->getUrl();
1819
$this->getController();
@@ -65,4 +66,11 @@ private function getUrl() {
6566
$this->url = $url;
6667
}
6768
}
69+
70+
private function checkInstalled() {
71+
if(!file_exists(__DIR__ . '/../../install/.installed')) {
72+
require_once(__DIR__ . '/../../install/install.php');
73+
exit();
74+
}
75+
}
6876
}

src/classes/Database.php

100644100755
File mode changed.

src/classes/Linker.php

100644100755
File mode changed.

src/classes/Model.php

100644100755
File mode changed.

src/classes/Template.php

100644100755
File mode changed.

src/classes/controllers/AuthController.php

100644100755
File mode changed.

src/classes/controllers/PostsController.php

100644100755
File mode changed.

src/classes/controllers/UsersController.php

100644100755
File mode changed.

src/classes/lib/Parsedown.php

100644100755
File mode changed.

src/classes/models/AuthModel.php

100644100755
File mode changed.

src/classes/models/PostModel.php

100644100755
File mode changed.

src/classes/models/UserModel.php

100644100755
File mode changed.

src/templates/alert.php

100644100755
File mode changed.

src/templates/backBtn.php

100644100755
File mode changed.

src/templates/delete.php

100644100755
File mode changed.

src/templates/footer.php

100644100755
File mode changed.

src/templates/header.php

100644100755
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@
1717

1818
<title><?= PAGE_TITLE?> - <?= $title?></title>
1919
<meta name="description" content="<?= DESCRIPTION?>">
20-
<meta name="keywords" content="<?= DEFAULT_KEYWORDS?>">
20+
<meta name="keywords" content="<?= DEFAULT_KEYWORDS . $tags?>">
2121
<meta name="author" content="hatbe2113">
2222
</head>
2323
<body>
2424
<header class="bg-dark mb-4 shadow text-light">
2525
<div class="container">
2626
<div class="text-center p-3">
27-
<h1>
27+
<h2>
2828
<a href="<?= ROOT_PATH?>" class="link-light text-decoration-none">
2929
<?= PAGE_TITLE?>
3030
</a>
31-
</h1>
31+
</h2>
3232
<h6 class="text-muted">
3333
<?= PAGE_SLOGAN?>
3434
</h6>

src/templates/pagination.php

100644100755
File mode changed.

src/templates/post.php

100644100755
File mode changed.

src/templates/postForm.php

100644100755
File mode changed.

src/templates/postsList.php

100644100755
File mode changed.

src/templates/userForm.php

100644100755
File mode changed.

src/views/auth/login.php

100644100755
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?= Template::load('header', ['title' => 'Login']);?>
1+
<?= Template::load('header', ['title' => 'Login', 'tags' => '']);?>
2+
3+
<h1 class="d-none">Login</h1>
24

35
<?= Template::load('userForm', ['username' => $data['username'], 'msg' => $data['msg'], 'action' => 'Login']);?>
46

src/views/auth/register.php

100644100755
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?= Template::load('header', ['title' => 'Register']);?>
1+
<?= Template::load('header', ['title' => 'Register', 'tags' => '']);?>
2+
3+
<h1 class="d-none">Register</h1>
24

35
<?= Template::load('userForm', ['username' => $data['username'], 'msg' => $data['msg'], 'action' => 'Register']);?>
46

src/views/posts/create.php

100644100755
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
<?= Template::load('header', ['title' => 'Home']);?>
1+
<?= Template::load('header', ['title' => 'Create Post', 'tags' => '']);?>
2+
3+
<h1 class="d-none">Create Post</h1>
24

35
<?= Template::load('backBtn', ['controller' => 'posts', 'method' => 'index', 'args' => ''])?>
4-
<?php Template::load('postForm', array('title' => $data['title'], 'body' => $data['body'], 'actionName' => $data['actionName'], 'errors' => $data['errors']));?>
6+
<?= Template::load('postForm', array('title' => $data['title'], 'body' => $data['body'], 'actionName' => $data['actionName'], 'errors' => $data['errors']));?>
57

68
<?= Template::load('footer');?>

src/views/posts/delete.php

100644100755
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?= Template::load('header', ['title' => 'Home']);?>
1+
<?= Template::load('header', ['title' => 'Delete Post', 'tags' => '']);?>
2+
3+
<h1 class="d-none">Delete Post</h1>
24

35
<?= Template::load('backBtn', ['controller' => 'posts', 'method' => 'index', 'args' => ''])?>
46
<?= Template::load('delete', ['actionName' => 'Post', 'id' => $data['id']]);?>

src/views/posts/edit.php

100644100755
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?= Template::load('header', ['title' => 'Home']);?>
1+
<?= Template::load('header', ['title' => 'Edit Post', 'tags' => '']);?>
2+
3+
<h1 class="d-none">Edit Post</h1>
24

35
<?= Template::load('backBtn', ['controller' => 'posts', 'method' => 'index', 'args' => ''])?>
46
<?= Template::load('postForm', array('title' => $data['title'], 'body' => $data['body'], 'actionName' => $data['actionName'], 'errors' => $data['errors']));?>

src/views/posts/index.php

100644100755
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
<?= Template::load('header', ['title' => 'Home']);?>
1+
<?= Template::load('header', ['title' => 'Home', 'tags' => '']);?>
22

3-
<?= Template::load('postsList', ['posts' => $data['posts']['posts'], 'meta' => $data['posts']['meta']]);?>
4-
<?= Template::load('pagination', ['meta' => $data['posts']['meta'], 'controller' => 'posts', 'method' => 'index']);?>
3+
<h1 class="d-none">Home</h1>
4+
5+
<?= Template::load('postsList', ['posts' => $data['posts']['posts'], 'meta' => $data['posts']['meta']]);?>
6+
<?= Template::load('pagination', ['meta' => $data['posts']['meta'], 'controller' => 'posts', 'method' => 'index']);?>
57

68
<?= Template::load('footer');?>

src/views/posts/post.php

100644100755
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?= Template::load('header', ['title' => $data['post'] != null ? $data['post']->title : 'post not found']);?>
1+
<?= Template::load('header', ['title' => $data['post'] != null ? $data['post']->title : 'post not found', 'tags' => '']);?>
2+
3+
<h1 class="d-none"><?=$data['post'] != null ? $data['post']->title : 'post not found'?></h1>
24

35
<?= Template::load('backBtn', ['controller' => 'posts', 'method' => 'index', 'args' => $data['page']])?>
46
<?php if($data['post'] !== null):?>

src/views/users/delete.php

100644100755
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?= Template::load('header', ['title' => 'Home']);?>
1+
<?= Template::load('header', ['title' => 'Delete User', 'tags' => '']);?>
2+
3+
<h1 class="d-none">Delete User</h1>
24

35
<?= Template::load('backBtn', ['controller' => 'users', 'method' => 'index', 'args' => ''])?>
46
<?= Template::load('delete', ['actionName' => 'User', 'id' => $data['id']]);?>

0 commit comments

Comments
 (0)