From 2f76c1ae35b15b940becca61657595ecff6f7203 Mon Sep 17 00:00:00 2001 From: Nick Yeoman Date: Tue, 12 Aug 2025 23:08:20 -0700 Subject: [PATCH] Edit page working --- config/routes.php | 9 +++ controllers/editpage.php | 30 ++++++++ controllers/init.php | 2 +- controllers/pages.php | 16 ++++ controllers/savepage.php | 55 ++++++++++++++ docs/StyleSheets-sass.md | 7 ++ skeleton/novaconium/App/views/index.html.twig | 4 +- skeleton/novaconium/public/css/novaconium.css | 75 ++++++++++++++++++- src/MessageHandler.php | 4 + src/novaconium.php | 1 + twig/left.html.twig | 10 +++ twig/master.html.twig | 4 + twig/right.html.twig | 1 + views/editpage.html.twig | 32 ++++++++ views/pages.html.twig | 29 +++++++ 15 files changed, 272 insertions(+), 7 deletions(-) create mode 100644 controllers/editpage.php create mode 100644 controllers/pages.php create mode 100644 controllers/savepage.php create mode 100644 docs/StyleSheets-sass.md create mode 100644 twig/left.html.twig create mode 100644 twig/right.html.twig create mode 100644 views/editpage.html.twig create mode 100644 views/pages.html.twig diff --git a/config/routes.php b/config/routes.php index fdaa7c4..edf20bd 100644 --- a/config/routes.php +++ b/config/routes.php @@ -13,6 +13,15 @@ $framework_routes = [ '/novaconium/dashboard' => [ 'get' => 'NOVACONIUM/dashboard' ], + '/novaconium/pages' => [ + 'get' => 'NOVACONIUM/pages' + ], + '/novaconium/page/edit/{id}' => [ + 'get' => 'NOVACONIUM/editpage' + ], + '/novaconium/savePage' => [ + 'post' => 'NOVACONIUM/savepage' + ], '/novaconium/logout' => [ 'post' => 'NOVACONIUM/logout', 'get' => 'NOVACONIUM/logout' diff --git a/controllers/editpage.php b/controllers/editpage.php new file mode 100644 index 0000000..b653a6e --- /dev/null +++ b/controllers/editpage.php @@ -0,0 +1,30 @@ +get('username'))) { + $redirect->url('/novaconium/login'); + $messages->error('You are not loggedin'); + makeitso(); +} + +$pageid = $router->parameters['id']; +$query=<<getRow($query); +$data = array_merge($data, [ + 'tinymce' => true, + 'pageid' => 'admin-edit-page' +]); +view('@novacore/editpage', $data); \ No newline at end of file diff --git a/controllers/init.php b/controllers/init.php index 55158df..962edbe 100644 --- a/controllers/init.php +++ b/controllers/init.php @@ -88,7 +88,7 @@ $result = $db->query($query); if ($result->num_rows === 0) { $query = <<get('username'))) { + $redirect->url('/novaconium/login'); + $messages->error('You are not loggedin'); + makeitso(); +} + +// Get the pages +$query = "SELECT id, title, created, updated, draft FROM pages"; +$matched = $db->getRows($query); + +$data['pages'] = $matched; + +view('@novacore/pages', $data); \ No newline at end of file diff --git a/controllers/savepage.php b/controllers/savepage.php new file mode 100644 index 0000000..9e279e1 --- /dev/null +++ b/controllers/savepage.php @@ -0,0 +1,55 @@ +get('id'); // Redirect back to the page edit form on error + +if ( empty($session->get('username'))) { + $redirect->url('/novaconium/login'); + $messages->error('You are not loggedin'); + makeitso(); +} + +// Check Token +if ($session->get('token') != $post->get('token')) { + $redirect->url('/novaconium/pages'); + $messages->error('Invalid Token'); + makeitso(); +} + +$id = $post->get('id'); +$slug = $post->get('slug'); +$title = $_POST['title']; +$body = $_POST['body']; // We want it dirty +$intro = $_POST['intro']; // We want it dirty + +if ( empty( $post->get('draft') ) ) { + $draft = 0; +} else { + $draft = 1; +} + +if ( empty($id) || empty($slug) || empty($body) ) { + $messages->error('One of the fields was empty.'); + $redirect->url($url_fail); + makeitso(); +} + +try { + + $query = "UPDATE `pages` SET `title` = ?, `slug` = ?, `body` = ?, `intro` = ?, `draft` = ?, `updated` = NOW() WHERE `id` = ?"; + $params = [$title, $slug, $body, $intro, $draft, $id]; + + $db->query($query, $params); + + $messages->notice('Page Saved'); + +} catch (Exception $e) { + + $messages->notice($e->getMessage()); + +} + +$redirect->url('/novaconium/page/edit/' . $id); diff --git a/docs/StyleSheets-sass.md b/docs/StyleSheets-sass.md new file mode 100644 index 0000000..9544160 --- /dev/null +++ b/docs/StyleSheets-sass.md @@ -0,0 +1,7 @@ +# Style Sheets + +The idea is to use sass to generate only what you need for style sheets. + +```bash +sudo docker run --rm -v $(pwd):/usr/src/app sass-container sass sass/project.sass public/css/main.css +``` diff --git a/skeleton/novaconium/App/views/index.html.twig b/skeleton/novaconium/App/views/index.html.twig index fc033c9..ff4cbdf 100644 --- a/skeleton/novaconium/App/views/index.html.twig +++ b/skeleton/novaconium/App/views/index.html.twig @@ -11,8 +11,8 @@

Documentation

Repository

diff --git a/skeleton/novaconium/public/css/novaconium.css b/skeleton/novaconium/public/css/novaconium.css index edc69e5..304c3ba 100644 --- a/skeleton/novaconium/public/css/novaconium.css +++ b/skeleton/novaconium/public/css/novaconium.css @@ -4,14 +4,55 @@ body { font-family: 'Fira Code', 'Source Code Pro', monospace; } +#page .container { + display: flex; + padding: 0; + justify-content: center; + align-items: flex-start; + margin-top: 20px; +} + article { - max-width: 900px; + width: 900px; + flex-shrink: 0; +} + +#leftnav { + width: 320px; + flex-shrink: 0; + margin: 0; + margin-right: 50px; +} + +article, #leftnav { border: 1px solid #3b444c; background-color: #14171a; color: #fff; - margin: 0 auto; padding: 20px; - margin-top: 50px; +} + +ul#leftnav { + list-style: none; + padding: 0; +} + +#leftnav li { + border-bottom: 1px solid #3b444c; +} + +#leftnav a { + display: block; + padding: 10px 15px; + text-decoration: none; + color: #fff; +} + +#leftnav a:hover { + background: #333; +} + +#leftnav li:last-child { + border-bottom: none; } code { @@ -41,7 +82,33 @@ div.error, div#debug { width: 900px; } +div.notice { + border: 1px solid rgb(31, 119, 13); + padding: 30px; + background-color: rgb(169, 218, 163); + color: rgb(20, 56, 13); + margin: 0 auto; + width: 900px; +} + div#debug { margin-top: 100px; margin-bottom: 100px; -} \ No newline at end of file +} + +.pages-table { + width: 100%; + border-collapse: collapse; + border: 1px solid #333; +} + +.pages-table th, +.pages-table td { + padding: 10px; + border: 1px solid #ddd; + text-align: left; +} + +.pages-table th { + font-weight: bold; +} diff --git a/src/MessageHandler.php b/src/MessageHandler.php index f90d90e..074fde7 100644 --- a/src/MessageHandler.php +++ b/src/MessageHandler.php @@ -30,6 +30,10 @@ class MessageHandler { $this->addMessage('error', $message); } + public function notice($message){ + $this->addMessage('notice', $message); + } + // Get all messages of a specific type public function getMessages($type) { return $this->messages[$type] ?? []; diff --git a/src/novaconium.php b/src/novaconium.php index a0644a6..1bc5a9e 100644 --- a/src/novaconium.php +++ b/src/novaconium.php @@ -25,6 +25,7 @@ require_once(FRAMEWORKPATH . '/src/twig.php'); require_once(FRAMEWORKPATH . '/src/Session.php'); $session = new Session(); $data['token'] = $session->get('token'); +$data['username'] = $session->get('username'); if ($config['loglevel'] == 'DEBUG') { $data['debug'] = nl2br(print_r($session->debug(), true)); } diff --git a/twig/left.html.twig b/twig/left.html.twig new file mode 100644 index 0000000..4c2bc14 --- /dev/null +++ b/twig/left.html.twig @@ -0,0 +1,10 @@ +{% if username is not empty %} +
+ +
+{% endif %} \ No newline at end of file diff --git a/twig/master.html.twig b/twig/master.html.twig index d7f516e..da9e08c 100644 --- a/twig/master.html.twig +++ b/twig/master.html.twig @@ -20,6 +20,8 @@
+ {% include ['@override/left.html.twig','@novaconium/left.html.twig'] %} +
{% if error|default is not empty %} {% for key, val in error %} @@ -36,6 +38,8 @@
{% block content %}{% endblock %}
+ + {% include ['@override/right.html.twig','@novaconium/right.html.twig'] %}
diff --git a/twig/right.html.twig b/twig/right.html.twig new file mode 100644 index 0000000..c6d171a --- /dev/null +++ b/twig/right.html.twig @@ -0,0 +1 @@ + diff --git a/views/editpage.html.twig b/views/editpage.html.twig new file mode 100644 index 0000000..f3e0e83 --- /dev/null +++ b/views/editpage.html.twig @@ -0,0 +1,32 @@ +{% extends '@novaconium/master.html.twig' %} + +{% block content %} +

Edit Page - {{ title }}

+ +
+ + + + + + + + + + + + + + + + + +

Created: {{ rows.created|date("Y-m-d H:i:s") }}

+

Last Updated: {{ rows.updated|date("Y-m-d H:i:s") }}

+ + +
+{% endblock %} diff --git a/views/pages.html.twig b/views/pages.html.twig new file mode 100644 index 0000000..90d094b --- /dev/null +++ b/views/pages.html.twig @@ -0,0 +1,29 @@ +{% extends '@novaconium/master.html.twig' %} + +{% block content %} +

{{title}}

+ + + + + + + + + + + {% for page in pages %} + + + + + + + {% else %} + + + + {% endfor %} + +
TitleCreatedUpdatedDraft
{{ page.title }}{{ page.created }}{{ page.updated|default('Not updated') }}{{ page.draft ? 'Draft' : 'Published' }}
No pages found.
+{% endblock %}