added link editor and fixes to login system
This commit is contained in:
parent
664544fea4
commit
7b20cd13b6
@ -1,11 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
global $c;
|
||||||
|
$varFooterLinks = $c->query("SELECT * from links where position like 'footer' order by sort");
|
||||||
|
?>
|
||||||
|
|
||||||
<hr />
|
<hr />
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-4">
|
<div class="col-lg-4">
|
||||||
|
<?php foreach ($varFooterLinks as $varLink): ?>
|
||||||
<div>
|
<div>
|
||||||
Copyright © 2025 Your Company.
|
<a class="link-underline link-underline-opacity-0" href="<?= $varLink["url"]; ?>"><i class="fa fa-fw fa-<?= $varLink["icon"]; ?> pe-2"></i> <?= $varLink["label"]; ?></a>
|
||||||
</div>
|
</div>
|
||||||
|
<?php endforeach; ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
26
header.php
26
header.php
@ -1,9 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
global $c;
|
||||||
|
|
||||||
$varNavbarLinks = [
|
$varNavbarLinks = [
|
||||||
["Home", "/"],
|
["Home", "/"],
|
||||||
["Sign in", "/user/signin"],
|
["Sign in", "/user/signin"],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$varNavbarLinks = $c->query("SELECT * from links where position like 'navbar' order by sort");
|
||||||
|
$varSidebarLinks = $c->query("SELECT * from links where position like 'sidebar' order by sort");
|
||||||
|
|
||||||
|
$varFirstNavbarLink = array_shift($varNavbarLinks);
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@ -11,17 +18,26 @@
|
|||||||
$("body").first().attr("data-bs-theme", "dark");
|
$("body").first().attr("data-bs-theme", "dark");
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="offcanvas offcanvas-start">
|
<div class="offcanvas offcanvas-start" id="sidebar">
|
||||||
<div class="offcanvas-body">
|
<div class="offcanvas-body">
|
||||||
Hello world <span data-bs-dismiss="offcanvas">x</span>
|
|
||||||
|
<?php foreach ($varSidebarLinks as $varLink): ?>
|
||||||
|
<a class="btn btn-outline-secondary d-block w-100 mb-2" href="<?= $varLink["url"]; ?>"><i class="fa fa-fw fa-<?= $varLink["icon"]; ?> pe-2"></i> <?= $varLink["label"]; ?></a>
|
||||||
|
<?php endforeach; ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="navbar navbar-expand bg-secondary d-flex px-3">
|
<div class="navbar navbar-expand bg-secondary d-flex px-3">
|
||||||
|
|
||||||
<div class="container justify-content-between">
|
<div class="container justify-content-between">
|
||||||
|
<div class="navbar-nav d-inline-flex align-items-center">
|
||||||
|
|
||||||
<div class="navbar-nav d-inline-flex">
|
<div class="navbar-nav d-inline-flex">
|
||||||
<span class="navbar-brand">Home</span>
|
<a class="btn btn-secondary me-2" data-bs-toggle="offcanvas" data-bs-target="#sidebar"><i class="fa fa-fw fa-bars"></i></a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<a class="navbar-brand" href="<?= $varFirstNavbarLink["url"]; ?>"><?= $varFirstNavbarLink["label"]; ?></a>
|
||||||
|
|
||||||
|
|
||||||
<div class="dropdown d-lg-none">
|
<div class="dropdown d-lg-none">
|
||||||
@ -29,13 +45,13 @@
|
|||||||
|
|
||||||
<div class="dropdown-menu">
|
<div class="dropdown-menu">
|
||||||
<?php foreach ($varNavbarLinks as $varLink): ?>
|
<?php foreach ($varNavbarLinks as $varLink): ?>
|
||||||
<a class="dropdown-item" href="<?= $varLink[1]; ?>"><i class="fa fa-fw fa-link pe-2"></i> <?= $varLink[0]; ?></a>
|
<a class="dropdown-item" href="<?= $varLink["url"]; ?>"><i class="fa fa-fw fa-<?= $varLink["icon"]; ?> pe-2"></i> <?= $varLink["label"]; ?></a>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php foreach ($varNavbarLinks as $varLink): ?>
|
<?php foreach ($varNavbarLinks as $varLink): ?>
|
||||||
<a class="nav-link d-none d-lg-inline" href="<?= $varLink[1]; ?>"><?= $varLink[0]; ?></a>
|
<a class="nav-link d-none d-lg-inline" href="<?= $varLink["url"]; ?>"><?= $varLink["label"]; ?></a>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
24
init.php
24
init.php
@ -5,6 +5,30 @@
|
|||||||
"sqlite",
|
"sqlite",
|
||||||
"sqlite.db");
|
"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
|
class UserAuth
|
||||||
{
|
{
|
||||||
public static function getUser()
|
public static function getUser()
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
{
|
{
|
||||||
global $c;
|
global $c;
|
||||||
|
|
||||||
$varRows = $c->query("SELECT * from {$strTableName}");
|
$varRows = $c->query("SELECT * from {$strTableName} order by `sort` asc");
|
||||||
$varKeys = [];
|
$varKeys = [];
|
||||||
|
|
||||||
$strInput = file_get_contents("php://input");
|
$strInput = file_get_contents("php://input");
|
||||||
@ -34,8 +34,6 @@
|
|||||||
$strQMarks = preg_replace("/, $/", "", $strQMarks);
|
$strQMarks = preg_replace("/, $/", "", $strQMarks);
|
||||||
$strSetLns = preg_replace("/, $/", "", $strSetLns);
|
$strSetLns = preg_replace("/, $/", "", $strSetLns);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (strlen($r["id"]) < 1)
|
if (strlen($r["id"]) < 1)
|
||||||
{
|
{
|
||||||
$c->query(
|
$c->query(
|
||||||
@ -117,6 +115,8 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<?php foreach($varRows[0] as $k => $v): ?>
|
<?php foreach($varRows[0] as $k => $v): ?>
|
||||||
<?php
|
<?php
|
||||||
|
if ($k == "sort")
|
||||||
|
continue;
|
||||||
$varKeys[] = $k;
|
$varKeys[] = $k;
|
||||||
?>
|
?>
|
||||||
<th><?= $k; ?></th>
|
<th><?= $k; ?></th>
|
||||||
@ -141,6 +141,11 @@
|
|||||||
<input type="hidden" name="delete" value="0" />
|
<input type="hidden" name="delete" value="0" />
|
||||||
<a class="" onclick="fnCloneRow(this);"><i class="fa fa-fw fa-copy"></i></a>
|
<a class="" onclick="fnCloneRow(this);"><i class="fa fa-fw fa-copy"></i></a>
|
||||||
<a class="" onclick="fnDeleteRow(this);"><i class="fa fa-fw fa-trash"></i></a>
|
<a class="" onclick="fnDeleteRow(this);"><i class="fa fa-fw fa-trash"></i></a>
|
||||||
|
|
||||||
|
<?php if (in_array("sort", $varColumns)): ?>
|
||||||
|
<a class="" onclick="fnMoveRowUp(this);"><i class="fa fa-fw fa-arrow-up"></i></a>
|
||||||
|
<a class="" onclick="fnMoveRowDown(this);"><i class="fa fa-fw fa-arrow-down"></i></a>
|
||||||
|
<?php endif; ?>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
@ -156,9 +161,16 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
$(function() {
|
$(function() {
|
||||||
|
$("[name='id']").each(function(i, x) {
|
||||||
|
x = $(x);
|
||||||
|
x.attr("readonly", 1);
|
||||||
|
});
|
||||||
|
|
||||||
fnSerialize = function() {
|
fnSerialize = function() {
|
||||||
var a = [];
|
var a = [];
|
||||||
|
|
||||||
|
var sort = 0;
|
||||||
|
|
||||||
$("table tbody tr").each(function(i, x) {
|
$("table tbody tr").each(function(i, x) {
|
||||||
x = $(x);
|
x = $(x);
|
||||||
|
|
||||||
@ -172,7 +184,10 @@
|
|||||||
o[key] = value;
|
o[key] = value;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
o["sort"] = sort;
|
||||||
|
|
||||||
a.push(o);
|
a.push(o);
|
||||||
|
sort++;
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(a);
|
console.log(a);
|
||||||
@ -190,6 +205,7 @@
|
|||||||
success: function(r)
|
success: function(r)
|
||||||
{
|
{
|
||||||
console.log(r);
|
console.log(r);
|
||||||
|
window.location.href = window.location.href;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -216,6 +232,20 @@
|
|||||||
row.hide();
|
row.hide();
|
||||||
row.find("[name='delete']").first().val("1");
|
row.find("[name='delete']").first().val("1");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
fnMoveRowUp = function(x)
|
||||||
|
{
|
||||||
|
x = $(x);
|
||||||
|
var row = x.parents("tr").first();
|
||||||
|
row.insertBefore(row.prev());
|
||||||
|
}
|
||||||
|
|
||||||
|
fnMoveRowDown = function(x)
|
||||||
|
{
|
||||||
|
x = $(x);
|
||||||
|
var row = x.parents("tr").first();
|
||||||
|
row.insertAfter(row.next());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<?php
|
<?php
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
global $c;
|
global $c;
|
||||||
|
|
||||||
|
UserAuth::requirePermission("admin");
|
||||||
|
|
||||||
$strId = Request::getArg(0);
|
$strId = Request::getArg(0);
|
||||||
$strPath = "";
|
$strPath = "";
|
||||||
$strContent = "";
|
$strContent = "";
|
||||||
@ -12,6 +14,7 @@
|
|||||||
if (count($varRows) !== 1)
|
if (count($varRows) !== 1)
|
||||||
{
|
{
|
||||||
BootstrapRender::message("Zero or more than one row returned", "danger");
|
BootstrapRender::message("Zero or more than one row returned", "danger");
|
||||||
|
Respond::redirect("/edit");
|
||||||
}
|
}
|
||||||
|
|
||||||
$varRow = $varRows[0];
|
$varRow = $varRows[0];
|
||||||
@ -37,29 +40,35 @@
|
|||||||
$strId = $c->query("SELECT * from post where rowid = last_insert_rowid()")[0]["id"];
|
$strId = $c->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(
|
$c->query(
|
||||||
"UPDATE post
|
"UPDATE post
|
||||||
set
|
set
|
||||||
path = ?,
|
path = ?,
|
||||||
content = ?,
|
content = ?,
|
||||||
updated = current_timestamp",
|
updated = current_timestamp
|
||||||
|
where
|
||||||
|
id = ?",
|
||||||
$strPath,
|
$strPath,
|
||||||
$strContent);
|
$strContent,
|
||||||
|
$strId);
|
||||||
|
|
||||||
Respond::redirect("/edit/{$strId}");
|
Respond::redirect("/edit/{$strId}");
|
||||||
}
|
|
||||||
|
|
||||||
if (strlen($strId) > 0)
|
|
||||||
{
|
|
||||||
$varRows = $c->query("SELECT * from post where id = ?", $strId);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
textarea {
|
||||||
|
font-family: monospace;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
<div class="container my-5">
|
<div class="container my-5">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-6">
|
<div class="col-lg-6">
|
||||||
|
5
pages/edit/links.php
Normal file
5
pages/edit/links.php
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
global $c;
|
||||||
|
UserAuth::requirePermission("admin");
|
||||||
|
TableEditor::render("links", ["label", "url", "icon", "position", "sort"]);
|
||||||
|
?>
|
@ -29,11 +29,14 @@
|
|||||||
<div class="container my-5">
|
<div class="container my-5">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-12">
|
<div class="col-lg-12">
|
||||||
|
<div class="border border-secondary rounded p-3">
|
||||||
<?php
|
<?php
|
||||||
$strContent = $varParsedown->text($p["content"]);
|
$strContent = $varParsedown->text($p["content"]);
|
||||||
echo $strContent;
|
echo $strContent;
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
|
<a href="/edit/<?= $p["id"]; ?>">edit</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
global $c;
|
global $c;
|
||||||
$strError = null;
|
$strError = null;
|
||||||
|
|
||||||
|
if (UserAuth::getUser() == null)
|
||||||
|
Respond::redirect("/user/signin");
|
||||||
|
|
||||||
$c->query(
|
$c->query(
|
||||||
"CREATE table if not exists user_info (
|
"CREATE table if not exists user_info (
|
||||||
id integer primary key autoincrement,
|
id integer primary key autoincrement,
|
||||||
|
@ -3,4 +3,3 @@
|
|||||||
UserAuth::requirePermission("hello_world");
|
UserAuth::requirePermission("hello_world");
|
||||||
TableEditor::render("user", ["email", "hash"]);
|
TableEditor::render("user", ["email", "hash"]);
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
global $c;
|
global $c;
|
||||||
UserAuth::requirePermission("hello_world");
|
UserAuth::requirePermission("hello_world");
|
||||||
TableEditor::render("permission", ["email", "name"]);
|
TableEditor::render("permission", ["email", "name", "sort"]);
|
||||||
?>
|
?>
|
||||||
|
@ -3,6 +3,15 @@
|
|||||||
|
|
||||||
try
|
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"))
|
if (Request::posts("email", "password", "repeat"))
|
||||||
{
|
{
|
||||||
$strEmail = Request::getPosted("email");
|
$strEmail = Request::getPosted("email");
|
||||||
@ -36,6 +45,19 @@
|
|||||||
$strEmail,
|
$strEmail,
|
||||||
$strHash);
|
$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.");
|
BootstrapRender::message("Registration was a success, please sign in to continue.");
|
||||||
|
|
||||||
Respond::redirect("/user/signin");
|
Respond::redirect("/user/signin");
|
||||||
|
@ -3,6 +3,11 @@
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
$intUserCount = $c->query("SELECT count(*) as val from user")[0]["val"];
|
||||||
|
|
||||||
|
if ($intUserCount < 1)
|
||||||
|
Respond::redirect("/user/register");
|
||||||
|
|
||||||
if (Request::posts("email", "password"))
|
if (Request::posts("email", "password"))
|
||||||
{
|
{
|
||||||
$strEmail = Request::getPosted("email");
|
$strEmail = Request::getPosted("email");
|
||||||
|
Loading…
Reference in New Issue
Block a user