aboutsummaryrefslogtreecommitdiffstats
path: root/admin/page
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2025-04-18 16:05:44 +0200
committerThomas Lange <code@nerdmind.de>2025-04-18 16:58:05 +0200
commite4bbba8222bbde52f4078a5e4ad18745f6ca6ed0 (patch)
tree1fdb2fd2d18e3b9e0f86b3b5a839a0b5a1838341 /admin/page
parent9d13d9aa49d7b92cfcfcfcad0e1de37079127e81 (diff)
downloadblog-e4bbba8222bbde52f4078a5e4ad18745f6ca6ed0.tar.gz
blog-e4bbba8222bbde52f4078a5e4ad18745f6ca6ed0.tar.xz
blog-e4bbba8222bbde52f4078a5e4ad18745f6ca6ed0.zip
Move admin area logic into core/include/admin
This commit overhauls the admin area a little bit by moving all logic into the core/include/admin directory and using the routing system to address it. In addition, duplicated code mess is reduced by using generic entity action/controller files in core/include/admin/entity.
Diffstat (limited to 'admin/page')
-rw-r--r--admin/page/delete.php59
-rw-r--r--admin/page/index.php75
-rw-r--r--admin/page/insert.php79
-rw-r--r--admin/page/search.php78
-rw-r--r--admin/page/update.php81
5 files changed, 0 insertions, 372 deletions
diff --git a/admin/page/delete.php b/admin/page/delete.php
deleted file mode 100644
index a0924c8..0000000
--- a/admin/page/delete.php
+++ /dev/null
@@ -1,59 +0,0 @@
-<?php
-#===============================================================================
-# DEFINE: Administration
-#===============================================================================
-const ADMINISTRATION = true;
-const AUTHENTICATION = true;
-
-#===============================================================================
-# INCLUDE: Initialization
-#===============================================================================
-require '../../core/application.php';
-
-#===============================================================================
-# Get repositories
-#===============================================================================
-$PageRepository = Application::getRepository('Page');
-
-#===============================================================================
-# Throw 404 error if page could not be found
-#===============================================================================
-if(!$Page = $PageRepository->find(HTTP::GET('id'))) {
- Application::error404();
-}
-
-#===============================================================================
-# Check for delete request
-#===============================================================================
-if(HTTP::issetPOST('delete')) {
- if(HTTP::issetPOST(['token' => Application::getSecurityToken()])) {
- try {
- $PageRepository->delete($Page);
- HTTP::redirect(Application::getAdminURL('page/'));
- } catch(PDOException $Exception) {
- $messages[] = $Exception->getMessage();
- }
- } else {
- $messages[] = $Language->text('error_security_csrf');
- }
-}
-
-#===============================================================================
-# Build document
-#===============================================================================
-$FormTemplate = Template\Factory::build('page/form');
-$FormTemplate->set('HTML', parseEntityContent($Page));
-$FormTemplate->set('FORM', [
- 'TYPE' => 'DELETE',
- 'INFO' => $messages ?? [],
- 'DATA' => array_change_key_case($Page->getAll(), CASE_UPPER),
- 'TOKEN' => Application::getSecurityToken()
-]);
-
-$DeleteTemplate = Template\Factory::build('page/delete');
-$DeleteTemplate->set('HTML', $FormTemplate);
-
-$MainTemplate = Template\Factory::build('main');
-$MainTemplate->set('NAME', $Language->text('title_page_delete'));
-$MainTemplate->set('HTML', $DeleteTemplate);
-echo $MainTemplate;
diff --git a/admin/page/index.php b/admin/page/index.php
deleted file mode 100644
index b533cf3..0000000
--- a/admin/page/index.php
+++ /dev/null
@@ -1,75 +0,0 @@
-<?php
-#===============================================================================
-# DEFINE: Administration
-#===============================================================================
-const ADMINISTRATION = true;
-const AUTHENTICATION = true;
-
-#===============================================================================
-# INCLUDE: Initialization
-#===============================================================================
-require '../../core/application.php';
-
-#===============================================================================
-# Get repositories
-#===============================================================================
-$PageRepository = Application::getRepository('Page');
-$UserRepository = Application::getRepository('User');
-
-#===============================================================================
-# Pagination
-#===============================================================================
-$site_size = Application::get('ADMIN.PAGE.LIST_SIZE');
-$site_sort = Application::get('ADMIN.PAGE.LIST_SORT');
-
-$count = $PageRepository->getCount();
-$lastSite = ceil($count / $site_size);
-
-$currentSite = HTTP::GET('site') ?? 1;
-$currentSite = intval($currentSite);
-
-#===============================================================================
-# Redirect to page create form if no page exists
-#===============================================================================
-if(!$count) {
- HTTP::redirect(Application::getAdminURL('page/insert.php'));
-}
-
-if($currentSite < 1 or ($currentSite > $lastSite and $lastSite > 0)) {
- Application::error404();
-}
-
-#===============================================================================
-# Get paginated page list
-#===============================================================================
-$pages = $PageRepository->getPaginated(
- $site_sort,
- $site_size,
- ($currentSite-1) * $site_size
-);
-
-foreach($pages as $Page) {
- $User = $UserRepository->find($Page->get('user'));
- $templates[] = generatePageItemTemplate($Page, $User);
-}
-
-#===============================================================================
-# Build document
-#===============================================================================
-$ListTemplate = Template\Factory::build('page/index');
-$ListTemplate->set('LIST', [
- 'PAGES' => $templates ?? []
-]);
-
-$ListTemplate->set('PAGINATION', [
- 'THIS' => $currentSite,
- 'LAST' => $lastSite,
- 'HTML' => createPaginationTemplate(
- $currentSite, $lastSite, Application::getAdminURL('page/')
- )
-]);
-
-$MainTemplate = Template\Factory::build('main');
-$MainTemplate->set('NAME', $Language->text('title_page_overview', $currentSite));
-$MainTemplate->set('HTML', $ListTemplate);
-echo $MainTemplate;
diff --git a/admin/page/insert.php b/admin/page/insert.php
deleted file mode 100644
index 7577433..0000000
--- a/admin/page/insert.php
+++ /dev/null
@@ -1,79 +0,0 @@
-<?php
-#===============================================================================
-# DEFINE: Administration
-#===============================================================================
-const ADMINISTRATION = true;
-const AUTHENTICATION = true;
-
-#===============================================================================
-# INCLUDE: Initialization
-#===============================================================================
-require '../../core/application.php';
-
-#===============================================================================
-# Get repositories
-#===============================================================================
-$PageRepository = Application::getRepository('Page');
-$UserRepository = Application::getRepository('User');
-
-#===============================================================================
-# Instantiate new Page entity
-#===============================================================================
-$Page = new ORM\Entities\Page;
-
-#===============================================================================
-# Check for insert request
-#===============================================================================
-if(HTTP::issetPOST('insert')) {
- $Page->set('user', HTTP::POST('user'));
- $Page->set('slug', HTTP::POST('slug') ?: generateSlug(HTTP::POST('name')));
- $Page->set('name', HTTP::POST('name') ?: null);
- $Page->set('body', HTTP::POST('body') ?: null);
- $Page->set('argv', HTTP::POST('argv') ?: null);
- $Page->set('time_insert', HTTP::POST('time_insert') ?: date('Y-m-d H:i:s'));
- $Page->set('time_update', HTTP::POST('time_update') ?: date('Y-m-d H:i:s'));
-
- if(HTTP::issetPOST(['token' => Application::getSecurityToken()])) {
- try {
- $PageRepository->insert($Page);
- HTTP::redirect(Application::getAdminURL('page/'));
- } catch(PDOException $Exception) {
- $messages[] = $Exception->getMessage();
- }
- }
-
- else {
- $messages[] = $Language->text('error_security_csrf');
- }
-}
-
-#===============================================================================
-# Generate user list
-#===============================================================================
-foreach($UserRepository->getAll([], 'fullname ASC') as $User) {
- $userList[] = [
- 'ID' => $User->getID(),
- 'FULLNAME' => $User->get('fullname'),
- 'USERNAME' => $User->get('username'),
- ];
-}
-
-#===============================================================================
-# Build document
-#===============================================================================
-$FormTemplate = Template\Factory::build('page/form');
-$FormTemplate->set('FORM', [
- 'TYPE' => 'INSERT',
- 'INFO' => $messages ?? [],
- 'DATA' => array_change_key_case($Page->getAll(), CASE_UPPER),
- 'USER_LIST' => $userList ?? [],
- 'TOKEN' => Application::getSecurityToken()
-]);
-
-$InsertTemplate = Template\Factory::build('page/insert');
-$InsertTemplate->set('HTML', $FormTemplate);
-
-$MainTemplate = Template\Factory::build('main');
-$MainTemplate->set('NAME', $Language->text('title_page_insert'));
-$MainTemplate->set('HTML', $InsertTemplate);
-echo $MainTemplate;
diff --git a/admin/page/search.php b/admin/page/search.php
deleted file mode 100644
index 7310e2a..0000000
--- a/admin/page/search.php
+++ /dev/null
@@ -1,78 +0,0 @@
-<?php
-#===============================================================================
-# DEFINE: Administration
-#===============================================================================
-const ADMINISTRATION = true;
-const AUTHENTICATION = true;
-
-#===============================================================================
-# INCLUDE: Initialization
-#===============================================================================
-require '../../core/application.php';
-
-#===============================================================================
-# Get repositories
-#===============================================================================
-$PageRepository = Application::getRepository('Page');
-$UserRepository = Application::getRepository('User');
-
-#===============================================================================
-# Pagination
-#===============================================================================
-$site_size = Application::get('ADMIN.PAGE.LIST_SIZE');
-$site_sort = Application::get('ADMIN.PAGE.LIST_SORT');
-
-$currentSite = HTTP::GET('site') ?? 1;
-$currentSite = intval($currentSite);
-$offset = ($currentSite-1) * $site_size;
-
-#===============================================================================
-# Check for search request
-#===============================================================================
-if($search = HTTP::GET('q')) {
- try {
- if(!$pages = $PageRepository->search($search, [], $site_size, $offset)) {
- $messages[] = Application::getLanguage()->text(
- 'search_no_results', htmlspecialchars($search));
- }
-
- foreach($pages as $Page) {
- $User = $UserRepository->find($Page->get('user'));
- $templates[] = generatePageItemTemplate($Page, $User);
- }
- } catch(PDOException $Exception) {
- $messages[] = $Exception->getMessage();
- }
-}
-
-#===============================================================================
-# Create pagination only if there are results
-#===============================================================================
-if($count = $PageRepository->getLastSearchOverallCount()) {
- $last = ceil($count / $site_size);
-
- $pagination_data = [
- 'THIS' => $currentSite,
- 'LAST' => $last,
- 'HTML' => createPaginationTemplate(
- $currentSite, $last, Application::getAdminURL('page/search.php')
- )
- ];
-}
-
-#===============================================================================
-# Build document
-#===============================================================================
-$SearchTemplate = Template\Factory::build('page/search');
-$SearchTemplate->set('QUERY', $search);
-$SearchTemplate->set('PAGES', $templates ?? []);
-$SearchTemplate->set('FORM', [
- 'INFO' => $messages ?? []
-]);
-$SearchTemplate->set('PAGINATION', $pagination_data ?? []);
-
-$MainTemplate = Template\Factory::build('main');
-$MainTemplate->set('NAME', $Language->text('title_page_search'));
-$MainTemplate->set('HTML', $SearchTemplate);
-
-echo $MainTemplate;
diff --git a/admin/page/update.php b/admin/page/update.php
deleted file mode 100644
index e123205..0000000
--- a/admin/page/update.php
+++ /dev/null
@@ -1,81 +0,0 @@
-<?php
-#===============================================================================
-# DEFINE: Administration
-#===============================================================================
-const ADMINISTRATION = true;
-const AUTHENTICATION = true;
-
-#===============================================================================
-# INCLUDE: Initialization
-#===============================================================================
-require '../../core/application.php';
-
-#===============================================================================
-# Get repositories
-#===============================================================================
-$PageRepository = Application::getRepository('Page');
-$UserRepository = Application::getRepository('User');
-
-#===============================================================================
-# Throw 404 error if page could not be found
-#===============================================================================
-if(!$Page = $PageRepository->find(HTTP::GET('id'))) {
- Application::error404();
-}
-
-#===============================================================================
-# Check for update request
-#===============================================================================
-if(HTTP::issetPOST('update')) {
- $Page->set('user', HTTP::POST('user'));
- $Page->set('slug', HTTP::POST('slug') ?: generateSlug(HTTP::POST('name')));
- $Page->set('name', HTTP::POST('name') ?: null);
- $Page->set('body', HTTP::POST('body') ?: null);
- $Page->set('argv', HTTP::POST('argv') ?: null);
- $Page->set('time_insert', HTTP::POST('time_insert') ?: date('Y-m-d H:i:s'));
- $Page->set('time_update', HTTP::POST('time_update') ?: date('Y-m-d H:i:s'));
-
- if(HTTP::issetPOST(['token' => Application::getSecurityToken()])) {
- try {
- $PageRepository->update($Page);
- } catch(PDOException $Exception) {
- $messages[] = $Exception->getMessage();
- }
- }
-
- else {
- $messages[] = $Language->text('error_security_csrf');
- }
-}
-
-#===============================================================================
-# Generate user list
-#===============================================================================
-foreach($UserRepository->getAll([], 'fullname ASC') as $User) {
- $userList[] = [
- 'ID' => $User->getID(),
- 'FULLNAME' => $User->get('fullname'),
- 'USERNAME' => $User->get('username'),
- ];
-}
-
-#===============================================================================
-# Build document
-#===============================================================================
-$FormTemplate = Template\Factory::build('page/form');
-$FormTemplate->set('FORM', [
- 'TYPE' => 'UPDATE',
- 'INFO' => $messages ?? [],
- 'DATA' => array_change_key_case($Page->getAll(), CASE_UPPER),
- 'USER_LIST' => $userList ?? [],
- 'TOKEN' => Application::getSecurityToken()
-]);
-
-$UpdateTemplate = Template\Factory::build('page/update');
-$UpdateTemplate->set('PAGE', generateItemTemplateData($Page));
-$UpdateTemplate->set('HTML', $FormTemplate);
-
-$MainTemplate = Template\Factory::build('main');
-$MainTemplate->set('NAME', $Language->text('title_page_update'));
-$MainTemplate->set('HTML', $UpdateTemplate);
-echo $MainTemplate;