Skip to content

Commit 7203ff5

Browse files
committed
V1.8 Setup pages!
1. Simple setup page with POST request 2. No more custom favicon path as that was a waste of time 3. Top left wiki description And a lot more changes were brought to the code.
1 parent 6768733 commit 7203ff5

5 files changed

Lines changed: 143 additions & 54 deletions

File tree

index.php

Lines changed: 76 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,20 @@
2626
// USER-DEFINED Variables
2727
// if resources/wikiconf.ini exists
2828
if (file_exists("resources/wikiconf.ini")) {
29+
$has_config = true;
2930
$wiki_config = parse_ini_file("resources/wikiconf.ini");
3031
$wiki_name = $wiki_config['wiki_name'];
3132
$wiki_description = $wiki_config['wiki_description'];
3233
$wiki_color = $wiki_config['wiki_color'];
3334
$wiki_default_theme = $wiki_config['wiki_default_theme'];
34-
$wiki_favicon = $wiki_config['wiki_favicon'];
3535
}
36-
36+
else {
37+
$has_config = false;
38+
$wiki_name = "Tiny-wiki";
39+
$wiki_description = "A simple folder-structure-based wiki engine";
40+
$wiki_color = "#0099ff";
41+
$wiki_default_theme = "default";
42+
}
3743
// Don't change anything below unless you know what you're doing.
3844

3945
// page url example:
@@ -53,15 +59,77 @@
5359

5460
/* --- Page Setup --- */
5561

62+
if (!$has_config) {
63+
// For obvious security reasons, the POST check should only be done if the wikiconf file doesn't exist
64+
// otherwise people could just reconfigure the site easily with POST data, crazy right?
65+
if ($_SERVER["REQUEST_METHOD"] == "POST") {
66+
// collect value of form
67+
$wiki_name = $_POST['wiki_name'];
68+
$wiki_description = $_POST['wiki_description'];
69+
$wiki_color = $_POST['wiki_color'];
70+
$wiki_default_theme = $_POST['wiki_default_theme'];
71+
// write to ini file
72+
$file = fopen("resources\wikiconf.ini", "w") or die("Unable to open file!");
73+
fwrite($file, "wiki_name = \"$wiki_name\"\n");
74+
fwrite($file, "wiki_description = \"$wiki_description\"\n");
75+
fwrite($file, "wiki_color = \"$wiki_color\"\n");
76+
fwrite($file, "wiki_default_theme = \"$wiki_default_theme\"\n");
77+
fclose($file);
78+
}
79+
// Setup page basically
80+
echo "<link rel='stylesheet' href='resources/default.css' type='text/css' />";
81+
echo "<div class='setup-page'>";
82+
echo "<h1>Welcome to Tiny-wiki!</h1>";
83+
echo "<p>It looks like this is the first time you are using Tiny-Wiki.</p>";
84+
echo "<p>To make this part pleasant, we've made this configuration form for you!</p>";
85+
echo "<p>Configure your wiki using the options below.</p>";
86+
echo "<form action='index.php' method='POST' enctype='multipart/form-data'>";
87+
echo "<label for='wiki_name'>Wiki Name:</label>";
88+
echo "<input type='text' class='inputfield' name='wiki_name' value='$wiki_name' placeholder='Wiki Name'><br>";
89+
echo "<label for='wiki_description'>Wiki Description:</label>";
90+
echo "<input type='textarea' class='inputfield' name='wiki_description' value='$wiki_description' placeholder='Wiki Description'><br>";
91+
echo "<label for='wiki_color'>Wiki Secondary Color:</label>";
92+
echo "<input type='color' class='inputfield' name='wiki_color' value='$wiki_color'><br>";
93+
echo "<label for='wiki_default_theme'>Wiki Default Cascading Style Sheet:</label>";
94+
echo "<input type='text' class='inputfield' name='wiki_default_theme' value='$wiki_default_theme' placeholder='default.css'><br>";
95+
echo "<label for='setup'>You can change these settings later at resources/wikiconf.ini, press Setup when done.</label>";
96+
echo "<input type='submit' class='setup' name='setup' value='Setup'>";
97+
echo "<script>
98+
// post setup form data to resources/config.php when submit button is clicked
99+
document.getElementsByClassName('setup')[0].addEventListener('click', function(e) {
100+
e.preventDefault();
101+
var wiki_name = document.getElementsByName('wiki_name')[0].value;
102+
var wiki_description = document.getElementsByName('wiki_description')[0].value;
103+
var wiki_color = document.getElementsByName('wiki_color')[0].value;
104+
var wiki_default_theme = document.getElementsByName('wiki_default_theme')[0].value;
105+
var formData = new FormData();
106+
formData.append('wiki_name', wiki_name);
107+
formData.append('wiki_description', wiki_description);
108+
formData.append('wiki_color', wiki_color);
109+
formData.append('wiki_default_theme', wiki_default_theme);
110+
var xhr = new XMLHttpRequest();
111+
xhr.open('POST', 'index.php', true);
112+
xhr.send(formData);
113+
xhr.onload = function() {
114+
if (xhr.status === 200) {
115+
window.location.href = 'index.php';
116+
}
117+
}
118+
});
119+
</script>";
120+
echo "</form>";
121+
echo "</div>";
122+
// script to POST the form data to resources/config.php
123+
124+
return;
125+
}
56126
?>
57127
<!DOCTYPE html>
58128
<html>
59129
<head>
60130
<?php
61131
echo '<title>' . $wiki_name . '</title>';
62-
if ($wiki_favicon != "") {
63-
echo '<link rel="shortcut icon" href="resources\\' . $wiki_favicon . '">';
64-
}
132+
echo '<link rel="shortcut icon" href="resources\\favicon.png">';
65133
?>
66134
<meta charset="utf-8">
67135
<meta name="viewport" content="width=device-width, initial-scale=1">
@@ -77,7 +145,9 @@
77145
<!--wiki name div-->
78146
<div class="sidebar-wiki-name" name="second-color">
79147
<?php
80-
echo '<p><a href="?p=Home">' . $wiki_name . '</a></p>';?>
148+
echo '<h1><a href="?p=Home">' . $wiki_name . '</a></h1>';
149+
echo '<p>' . $wiki_description . '</p>';
150+
?>
81151
</div>
82152
<!--wiki auto-generated buttons div-->
83153
<div class="sidebar-list">

resources/config.php

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

resources/default.css

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,54 @@ table, td, th {
3131
color: #3b3b3b;
3232
}
3333

34+
/* Centered setup page */
35+
.setup-page {
36+
border-radius: 10px;
37+
background-color: #17181a;
38+
color: #ddd;
39+
width: 20%;
40+
height: auto;
41+
padding: 15px;
42+
padding-bottom: 0%;
43+
position: fixed;
44+
top: 50%;
45+
left: 50%;
46+
transform: translate(-50%, -50%);
47+
overflow: none;
48+
font-family: 'Montserrat', sans-serif;
49+
text-align: center;
50+
}
51+
52+
.setup-page .inputfield {
53+
width: 100%;
54+
height: 30px;
55+
border: 1px solid #ddd;
56+
background-color: #000;
57+
color: #ddd;
58+
padding: 2px;
59+
margin-bottom: 10px;
60+
}
61+
62+
.setup-page .setup {
63+
margin-top: 10px;
64+
width: 100%;
65+
height: 60px;
66+
border: 1px solid #ddd;
67+
border-radius: 5px;
68+
background-color: #000;
69+
color: #ddd;
70+
}
71+
72+
/* Create your own styles here */
73+
3474
/* Modern dark sidebar div */
3575
.sidebar {
3676
color: #fff;
3777
position: absolute;
3878
top: 0;
3979
left: 0;
4080
bottom: 0;
41-
width: 15%;
81+
width: 20%;
4282
height: 100%;
4383
font-family: 'Montserrat', sans-serif;
4484
}
@@ -48,14 +88,35 @@ table, td, th {
4888
background-color: inherit;
4989
width: 100%;
5090
height: 5%;
51-
font-weight: bold;
52-
font-size: 23px;
53-
text-align: center;
5491
text-shadow: 1px 1px 1px #000;
5592
/* animation */
5693
transition: all 0.2s ease-in-out;
5794
}
5895

96+
.sidebar-wiki-name h1 {
97+
font-weight: bold;
98+
font-size: 23px;
99+
text-align: center;
100+
position: absolute;
101+
top: 0.5%;
102+
left: 0;
103+
right: 0;
104+
margin: auto;
105+
padding: 0%;
106+
}
107+
108+
.sidebar-wiki-name p {
109+
font-size: 12px;
110+
text-align: center;
111+
line-height: 1;
112+
position: absolute;
113+
top: calc(0.5% + 25px);
114+
left: 0;
115+
right: 0;
116+
margin: auto;
117+
padding: 0%;
118+
}
119+
59120
/* Hide text decoration on hover */
60121
.sidebar-wiki-name:hover {
61122
font-size: 25px;
@@ -125,10 +186,10 @@ table, td, th {
125186

126187
.content {
127188
position: absolute;
128-
left: 15%;
189+
left: 20%;
129190
bottom: 0;
130191
right: 0;
131-
width: 85%;
192+
width: 80%;
132193
height: 100%;
133194
background-color: #0b0c0c;
134195
overflow-x: hidden;

resources/wikiconf.ini

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

0 commit comments

Comments
 (0)