diff --git a/header.php b/header.php index 877a03f..ddf9024 100644 --- a/header.php +++ b/header.php @@ -1,18 +1,17 @@ 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); - ?> + + diff --git a/pages/edit/index.php b/pages/edit/index.php deleted file mode 100644 index 5edd325..0000000 --- a/pages/edit/index.php +++ /dev/null @@ -1,103 +0,0 @@ - 0) - { - $varRows = $c->query("SELECT * from post where id = ?", $strId); - - if (count($varRows) !== 1) - { - BootstrapRender::message("Zero or more than one row returned", "danger"); - Respond::redirect("/edit"); - } - - $varRow = $varRows[0]; - $strPath = $varRow["path"]; - $strContent = $varRow["content"]; - } - - - if (Request::posts("path", "content")) - { - $strPath = Request::getPosted("path"); - $strContent = Request::getPosted("content"); - - if ($strId == null || strlen($strId) < 1) - { - $c->query( - "INSERT into post (author, path, content) - values (?, ?, ?)", - "caharkness@gmail.com", - $strPath, - $strContent); - - $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( - "UPDATE post - set - path = ?, - content = ?, - updated = current_timestamp - where - id = ?", - $strPath, - $strContent, - $strId); - - Respond::redirect("/edit/{$strId}"); - } -?> - - - -
-
-
- -
- -
- -
- - "path", - "label" => "Path", - "value" => $strPath - ]); ?> - - "content", - "label" => "Content", - "tag" => "textarea", - "value" => $strContent - ]); ?> - - [[ - "label" => "Submit", - "icon" => "save" - ]] - ]); ?> -
-
-
diff --git a/pages/edit/js.php b/pages/edit/js.php new file mode 100644 index 0000000..f23b71f --- /dev/null +++ b/pages/edit/js.php @@ -0,0 +1,67 @@ + + + + + + + + +
+
+ +
+
+ + + diff --git a/pages/index.php b/pages/index.php index a25e3b2..2c4b5e1 100644 --- a/pages/index.php +++ b/pages/index.php @@ -1,42 +1,109 @@ query( - "CREATE table if not exists post ( - id integer primary key autoincrement, - author text not null, - path text not null, - content text not null, - created timestamp not null default current_timestamp, - updated timestamp not null default current_timestamp)"); - $varPosts = $c->query( - "SELECT * - from post + "SELECT + p.*, + u.user_name, + u.display_name + from posts as p + left join users as u on u.email = p.email where path like ? - or path like '*'", + or path like '*' + order by + created desc", $strPath); + $strSearchQuery = Request::getParam("q"); + + if ($strSearchQuery) + { + $varPosts = $c->query( + "SELECT + p.*, + u.user_name, + u.display_name + from posts as p + left join users as u on u.email = p.email + where + content like concat('%', ?, '%') + order by + created desc", + $strSearchQuery); + } + + $varParsedown = new Parsedown(); ?> + + + + + + + + + +
+
+ +
+
+ +
-
-
- text($p["content"]); - echo $strContent; - ?> +
+
+ text($p["content"]); ?>
- ">edit +
+
+
by
+
on UTC
+
+ +
+ ">edit +
+
+ + +
+
+
+

Sorry, there is nothing here to show.

+
+
+
+ + + + + diff --git a/pages/post/index.php b/pages/post/index.php new file mode 100644 index 0000000..fe1a6d9 --- /dev/null +++ b/pages/post/index.php @@ -0,0 +1,123 @@ + 0) + { + $varRows = $c->query("SELECT * from posts where id = ?", $strId); + + if (count($varRows) !== 1) + { + BootstrapRender::message("Zero or more than one row returned", "danger"); + Respond::redirect("/post"); + } + + $varRow = $varRows[0]; + $strPath = $varRow["path"]; + $strContent = $varRow["content"]; + } + + + if (Request::posts("path", "content")) + { + $strPath = Request::getPosted("path"); + $strContent = Request::getPosted("content"); + + if ($strId == null || strlen($strId) < 1) + { + $c->query( + "INSERT into posts (email, path, content) + values (?, ?, ?)", + $varUser["email"], + $strPath, + $strContent); + + $strId = $c->query("SELECT * from posts where rowid = last_insert_rowid()")[0]["id"]; + } + + if (strlen($strContent) < 1) + { + $c->query("DELETE from posts where id = ?", $strId); + BootstrapRender::message("Post deleted successfully.", "success"); + Respond::redirect("/post"); + } + + $c->query( + "UPDATE posts + set + path = ?, + content = ?, + updated = current_timestamp + where + id = ?", + $strPath, + $strContent, + $strId); + + Respond::redirect("/post/{$strId}"); + } +?> + + + +
+ + + +
+
+ +
+
+
+ + diff --git a/pages/user/info.php b/pages/user/info.php index 8a1c24c..b16b30f 100644 --- a/pages/user/info.php +++ b/pages/user/info.php @@ -5,13 +5,6 @@ if (UserAuth::getUser() == null) Respond::redirect("/user/signin"); - $c->query( - "CREATE table if not exists user_info ( - id integer primary key autoincrement, - email text not null unique, - user_name text null, - display_name text null)"); - $varUser = UserAuth::getUser(); $strUsername = $varUser["user_name"] ?? ""; $strDisplayName = $varUser["display_name"] ?? ""; @@ -30,7 +23,7 @@ throw new Exception("Username must be alphanumeric characters only"); $c->query( - "INSERT or replace into user_info (email, user_name, display_name) + "INSERT or replace into users (email, user_name, display_name) select ?, ?, diff --git a/pages/user/list.php b/pages/user/list.php index e5b1c8f..2581802 100644 --- a/pages/user/list.php +++ b/pages/user/list.php @@ -1,5 +1,5 @@ diff --git a/pages/user/permissions.php b/pages/user/permissions.php index 544ac51..350f393 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 2614f27..350da54 100644 --- a/pages/user/register.php +++ b/pages/user/register.php @@ -3,7 +3,7 @@ try { - $intUserCount = $c->query("SELECT count(*) as val from user")[0]["val"]; + $intUserCount = $c->query("SELECT count(*) as c from credentials")[0]["c"]; if ($intUserCount < 1) { @@ -27,13 +27,7 @@ if (strlen($strPassword) < 6) throw new Exception("Password must be at least 6 characters"); - $c->query( - "CREATE table if not exists user ( - id integer primary key autoincrement, - email text not null unique, - hash text not null)"); - - $varUsers = $c->query("SELECT * from user where email like ?", $strEmail); + $varUsers = $c->query("SELECT * from credentials where email like ?", $strEmail); if (count($varUsers) > 0) throw new Exception("E-mail address in use"); @@ -41,21 +35,18 @@ $strHash = sha1($strPassword); $c->query( - "INSERT into user (email, hash) values (?, ?)", + "INSERT into credentials (email, hash) values (?, ?)", $strEmail, $strHash); - $intUserCount = $c->query("SELECT count(*) as val from user")[0]["val"]; + $intUserCount = $c->query("SELECT count(*) as c from credentials")[0]["c"]; if ($intUserCount == 1) { - // Calling this ensures permission table: - UserAuth::hasPermission("dummy"); - $c->query( - "INSERT into permission (email, name) - values (?, 'admin')", - $strEmail); + "INSERT into permissions (email, permission) values (?, ?)", + $strEmail, + "admin"); } BootstrapRender::message("Registration was a success, please sign in to continue."); diff --git a/pages/user/signin.php b/pages/user/signin.php index f606412..9965e5f 100644 --- a/pages/user/signin.php +++ b/pages/user/signin.php @@ -3,7 +3,7 @@ try { - $intUserCount = $c->query("SELECT count(*) as val from user")[0]["val"]; + $intUserCount = $c->query("SELECT count(*) as c from credentials")[0]["c"]; if ($intUserCount < 1) Respond::redirect("/user/register"); @@ -15,7 +15,7 @@ $strHash = sha1($strPassword); $varUsers = $c->query( "SELECT * - from user + from credentials where email like ? and hash = ?", @@ -27,14 +27,8 @@ $strToken = sha1(microtime()); - $c->query("CREATE table if not exists tokens ( - id integer primary key autoincrement, - email text not null, - token text not null, - expires timestamp null)"); - $c->query( - "INSERT into tokens (email, token) values (?, ?)", + "INSERT into sessions (email, token) values (?, ?)", $strEmail, $strToken); diff --git a/pages/user/signout.php b/pages/user/signout.php index 01c1310..cea6003 100644 --- a/pages/user/signout.php +++ b/pages/user/signout.php @@ -7,7 +7,7 @@ if (Request::getArg(0) == "all") { $c->query( - "UPDATE tokens + "UPDATE sessions set expires = current_timestamp where email = ?", @@ -16,7 +16,7 @@ else { $c->query( - "UPDATE tokens + "UPDATE sessions set expires = current_timestamp where token = ?",