From 86686c1ab75362eb9cc3f7ec8e737317d2400df1 Mon Sep 17 00:00:00 2001 From: Shane Mc Cormack Date: Sun, 10 Mar 2019 19:13:27 +0000 Subject: [PATCH] Start work on article admin. --- mydnshost-php-api | 2 +- src/DisplayEngine.php | 3 ++ src/routes/AdminRoutes.php | 44 ++++++++++++++++++++ templates/default/admin/article.tpl | 58 ++++++++++++++++++++++++++ templates/default/admin/articles.tpl | 61 ++++++++++++++++++++++++++++ 5 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 templates/default/admin/article.tpl create mode 100644 templates/default/admin/articles.tpl diff --git a/mydnshost-php-api b/mydnshost-php-api index b4fb058..92d5d03 160000 --- a/mydnshost-php-api +++ b/mydnshost-php-api @@ -1 +1 @@ -Subproject commit b4fb05808bf2148572c0b3a077a3adfc6a2b89f2 +Subproject commit 92d5d03f8d9330fe05bd0aaa7a44000b4ec53999 diff --git a/src/DisplayEngine.php b/src/DisplayEngine.php index bd9c92a..2d4e5fd 100644 --- a/src/DisplayEngine.php +++ b/src/DisplayEngine.php @@ -299,6 +299,9 @@ public function showHeaderMenu() { if ($this->hasPermission(['manage_domains'])) { $menu[] = ['link' => $this->getURL('/admin/domains'), 'title' => 'Manage Domains', 'active' => ($this->pageID == '/admin/domains')]; } + if ($this->hasPermission(['manage_articles'])) { + $menu[] = ['link' => $this->getURL('/admin/articles'), 'title' => 'Manage Articles', 'active' => ($this->pageID == '/admin/aticles')]; + } if ($this->hasPermission(['system_stats'])) { $menu[] = ['link' => $this->getURL('/admin/stats'), 'title' => 'System Statistics', 'active' => ($this->pageID == '/admin/stats')]; } diff --git a/src/routes/AdminRoutes.php b/src/routes/AdminRoutes.php index f10710c..3f4825e 100644 --- a/src/routes/AdminRoutes.php +++ b/src/routes/AdminRoutes.php @@ -195,5 +195,49 @@ public function addRoutes($router, $displayEngine, $api) { return; }); } + + + if ($displayEngine->hasPermission(['manage_articles'])) { + $router->get('/admin/articles', function() use ($displayEngine, $api) { + $displayEngine->setPageID('/admin/articles')->setTitle('Admin :: Articles'); + + $articles = $api->getAllArticles(); + $displayEngine->setVar('articles', $articles); + $displayEngine->setVar('time', time()); + + $displayEngine->display('admin/articles.tpl'); + }); + + $router->get('/admin/articles/(.*)', function($articleid) use ($displayEngine, $api) { + $displayEngine->setPageID('/admin/articles')->setTitle('Admin :: Articles :: ' . $articleid); + + $article = $api->getArticle($articleid); + $displayEngine->setVar('article', $article); + $displayEngine->setVar('time', time()); + + $displayEngine->display('admin/article.tpl'); + }); + + $router->post('/admin/articles/(.*)', function($articleid) use ($displayEngine, $api) { + + }); + + $router->post('/admin/articles/(.*)/delete', function($articleid) use ($displayEngine, $api) { + + }); + + $router->get('/admin/articles/create', function() use ($displayEngine, $api) { + $displayEngine->setPageID('/admin/articles')->setTitle('Admin :: Articles :: Create'); + $displayEngine->setVar('create', true); + $displayEngine->setVar('time', time()); + $displayEngine->display('admin/article.tpl'); + }); + + $router->post('/admin/articles/create', function() use ($displayEngine, $api) { + + }); + } + + } } diff --git a/templates/default/admin/article.tpl b/templates/default/admin/article.tpl new file mode 100644 index 0000000..396cf5a --- /dev/null +++ b/templates/default/admin/article.tpl @@ -0,0 +1,58 @@ +

Article :: {{ article.id }}

+ + + + + + {% if not create %} + + + + + {% endif %} + + + + + + + + + + + + + + + + + + + + + + + + + +
ID + {{ article.id }} +
Title + +
Content + +
Full Content + +
Created + {% if not create %} + {{ article.created }} ({{ article.created | date }}) + {% else %} + {{ time }} ({{ time | date }}) + {% endif %} +
Visible From + +
Visible Until + +
+ + diff --git a/templates/default/admin/articles.tpl b/templates/default/admin/articles.tpl new file mode 100644 index 0000000..458991c --- /dev/null +++ b/templates/default/admin/articles.tpl @@ -0,0 +1,61 @@ +

Article List

+ + +
+ +
+ Add Article +
+

+ + + + + + + + + + + + + {% for article in articles %} + + + + + + + + {% endfor %} + +
IDTitleContentVisibleActions
+ {{ article.id }} + + {{ article.title }} + + {{ article.content }} + + {% set visible = article.visiblefrom < time and (article.visibleuntil == -1 or article.visibleuntil > time) %} + + + {{ visible | yesno }} + + + {% if userinfo.email != user.email %} + View/Edit +
+ +{% embed 'blocks/modal_confirm.tpl' with {'id': 'confirmDelete'} only %} + {% block title %} + Delete Article + {% endblock %} + + {% block body %} + Are you sure you want to delete this Article? + {% endblock %} +{% endembed %} + +