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.

0 commit comments

Comments
 (0)