-
Home
+
diff --git a/init.php b/init.php
index d026042..cd40a5e 100644
--- a/init.php
+++ b/init.php
@@ -5,6 +5,30 @@
"sqlite",
"sqlite.db");
+ $c->query(
+ "CREATE table if not exists links (
+ id integer primary key autoincrement,
+ label text not null,
+ url text not null,
+ icon text not null,
+ position text not null,
+ sort integer not null default 0)");
+
+ $varLinks = $c->query("SELECT * from links");
+
+ if (count($varLinks) < 1)
+ {
+ $c->query(
+ "INSERT into links (label, url, icon, position)
+ values
+ ('Home', '/', 'home', 'navbar'),
+ ('Post', '/edit', 'edit', 'navbar'),
+ ('Links', '/edit/links', 'link', 'navbar'),
+ ('Go home', '/', 'home', 'sidebar'),
+ ('Copyright © 2025 Your Company.', '/', 'home', 'footer')");
+ }
+
+
class UserAuth
{
public static function getUser()
diff --git a/lib/TableEditor.php b/lib/TableEditor.php
index e2f0de9..8510453 100644
--- a/lib/TableEditor.php
+++ b/lib/TableEditor.php
@@ -5,7 +5,7 @@
{
global $c;
- $varRows = $c->query("SELECT * from {$strTableName}");
+ $varRows = $c->query("SELECT * from {$strTableName} order by `sort` asc");
$varKeys = [];
$strInput = file_get_contents("php://input");
@@ -34,8 +34,6 @@
$strQMarks = preg_replace("/, $/", "", $strQMarks);
$strSetLns = preg_replace("/, $/", "", $strSetLns);
-
-
if (strlen($r["id"]) < 1)
{
$c->query(
@@ -117,6 +115,8 @@
$v): ?>
= $k; ?>
@@ -141,6 +141,11 @@
+
+
+
+
+
@@ -156,9 +161,16 @@
query("SELECT * from post where rowid = last_insert_rowid()")[0]["id"];
}
+ if (strlen($strContent) < 1)
+ {
+ $c->query("DELETE from post where id = ?", $strId);
+ BootstrapRender::message("Post deleted successfully.", "success");
+ Respond::redirect("/edit");
+ }
+
$c->query(
"UPDATE post
set
path = ?,
content = ?,
- updated = current_timestamp",
+ updated = current_timestamp
+ where
+ id = ?",
$strPath,
- $strContent);
+ $strContent,
+ $strId);
Respond::redirect("/edit/{$strId}");
- }
-
- if (strlen($strId) > 0)
- {
- $varRows = $c->query("SELECT * from post where id = ?", $strId);
-
-
-
-
-
}
?>
+
+
diff --git a/pages/edit/links.php b/pages/edit/links.php
new file mode 100644
index 0000000..c801dc9
--- /dev/null
+++ b/pages/edit/links.php
@@ -0,0 +1,5 @@
+
diff --git a/pages/index.php b/pages/index.php
index fe8f119..a25e3b2 100644
--- a/pages/index.php
+++ b/pages/index.php
@@ -29,10 +29,13 @@
- text($p["content"]);
- echo $strContent;
- ?>
+
+ text($p["content"]);
+ echo $strContent;
+ ?>
+
+
">edit
diff --git a/pages/user/info.php b/pages/user/info.php
index ab0c2a8..8a1c24c 100644
--- a/pages/user/info.php
+++ b/pages/user/info.php
@@ -2,6 +2,9 @@
global $c;
$strError = null;
+ if (UserAuth::getUser() == null)
+ Respond::redirect("/user/signin");
+
$c->query(
"CREATE table if not exists user_info (
id integer primary key autoincrement,
diff --git a/pages/user/list.php b/pages/user/list.php
index 587ee6c..e5b1c8f 100644
--- a/pages/user/list.php
+++ b/pages/user/list.php
@@ -3,4 +3,3 @@
UserAuth::requirePermission("hello_world");
TableEditor::render("user", ["email", "hash"]);
?>
-
diff --git a/pages/user/permissions.php b/pages/user/permissions.php
index 3888096..544ac51 100644
--- a/pages/user/permissions.php
+++ b/pages/user/permissions.php
@@ -1,5 +1,5 @@
diff --git a/pages/user/register.php b/pages/user/register.php
index 84ad9b1..2614f27 100644
--- a/pages/user/register.php
+++ b/pages/user/register.php
@@ -3,6 +3,15 @@
try
{
+ $intUserCount = $c->query("SELECT count(*) as val from user")[0]["val"];
+
+ if ($intUserCount < 1)
+ {
+ BootstrapRender::message(
+ "Please create an administrator account.",
+ "warning");
+ }
+
if (Request::posts("email", "password", "repeat"))
{
$strEmail = Request::getPosted("email");
@@ -36,6 +45,19 @@
$strEmail,
$strHash);
+ $intUserCount = $c->query("SELECT count(*) as val from user")[0]["val"];
+
+ if ($intUserCount == 1)
+ {
+ // Calling this ensures permission table:
+ UserAuth::hasPermission("dummy");
+
+ $c->query(
+ "INSERT into permission (email, name)
+ values (?, 'admin')",
+ $strEmail);
+ }
+
BootstrapRender::message("Registration was a success, please sign in to continue.");
Respond::redirect("/user/signin");
diff --git a/pages/user/signin.php b/pages/user/signin.php
index b675ef9..f606412 100644
--- a/pages/user/signin.php
+++ b/pages/user/signin.php
@@ -3,6 +3,11 @@
try
{
+ $intUserCount = $c->query("SELECT count(*) as val from user")[0]["val"];
+
+ if ($intUserCount < 1)
+ Respond::redirect("/user/register");
+
if (Request::posts("email", "password"))
{
$strEmail = Request::getPosted("email");