From e6cef37e0c782fe770db20888d99c17d10e2c479 Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Thu, 1 Jul 2021 20:11:34 +0200 Subject: Add category system to categorize posts (readme) This commit implements a new category system to categorize posts. Each category can have an unlimited number of nested children categories. A single post don't necessarily need to be in a category, but it can. Each category can have a full content body like posts or pages, so you have enough space to describe the content of your categories. Please note that you need to have at least the following MySQL/MariaDB versions to use the category system, because it uses "WITH RECURSIVE" database queries, the so-called "Common-Table-Expressions (CTE)". MariaDB: 10.2.2 MySQL: 8.0 See: https://mariadb.com/kb/en/with/ See: https://dev.mysql.com/doc/refman/8.0/en/with.html --- theme/admin/html/category/delete.php | 6 ++ theme/admin/html/category/form.php | 112 +++++++++++++++++++++++++++++++++++ theme/admin/html/category/index.php | 15 +++++ theme/admin/html/category/insert.php | 6 ++ theme/admin/html/category/item.php | 33 +++++++++++ theme/admin/html/category/update.php | 6 ++ theme/admin/html/main.php | 1 + theme/admin/html/post/form.php | 27 ++++++++- theme/admin/html/post/item.php | 3 + 9 files changed, 208 insertions(+), 1 deletion(-) create mode 100644 theme/admin/html/category/delete.php create mode 100644 theme/admin/html/category/form.php create mode 100644 theme/admin/html/category/index.php create mode 100644 theme/admin/html/category/insert.php create mode 100644 theme/admin/html/category/item.php create mode 100644 theme/admin/html/category/update.php (limited to 'theme/admin/html') diff --git a/theme/admin/html/category/delete.php b/theme/admin/html/category/delete.php new file mode 100644 index 0000000..635e9a8 --- /dev/null +++ b/theme/admin/html/category/delete.php @@ -0,0 +1,6 @@ +
+

text('delete_category')?>

+

text('delete_category_desc')?>

+ + +
diff --git a/theme/admin/html/category/form.php b/theme/admin/html/category/form.php new file mode 100644 index 0000000..2cb7b20 --- /dev/null +++ b/theme/admin/html/category/form.php @@ -0,0 +1,112 @@ +%s%s [%d]'; + $select = ($category['ID'] == $selected) ? ' selected' : ''; + $select = ($category['ID'] == $current) ? ' disabled' : $select; + + printf($option, $category['ID'], $select, $prefix, escapeHTML($category['NAME']), $category['ID']); + + if(isset($category['CHILDS'])) { + # If there are children, call self and pass children array. + (__FUNCTION__)($category['CHILDS'], $selected, $current, $prefix.'– '); + } + } +} +?> + +
+ +
+ + +
+ + + +
+ + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+
+ +
+
+
    +
  • +
  • +
  • + +
  • +
  • +
  • +
  • +
  • +
+
+ +
+
+
    + $explanation):?> +
  • + +
+
+
+ +
+ +
+ +
+ + +
+ + + + + + + +
+
diff --git a/theme/admin/html/category/index.php b/theme/admin/html/category/index.php new file mode 100644 index 0000000..e2c35a4 --- /dev/null +++ b/theme/admin/html/category/index.php @@ -0,0 +1,15 @@ +
+

text('category_overview')?>

+

text('overview_category_desc')?>

+ + +
+ + + +
+ + +
diff --git a/theme/admin/html/category/insert.php b/theme/admin/html/category/insert.php new file mode 100644 index 0000000..be9fdfe --- /dev/null +++ b/theme/admin/html/category/insert.php @@ -0,0 +1,6 @@ +
+

text('insert_category')?>

+

text('insert_category_desc')?>

+ + +
diff --git a/theme/admin/html/category/item.php b/theme/admin/html/category/item.php new file mode 100644 index 0000000..05212e7 --- /dev/null +++ b/theme/admin/html/category/item.php @@ -0,0 +1,33 @@ +
+
+

+
+ # + + text('posts')?>: + text('categories')?>: +
+
+
+ + + +

+
+ + + + + + +
diff --git a/theme/admin/html/category/update.php b/theme/admin/html/category/update.php new file mode 100644 index 0000000..fefaa18 --- /dev/null +++ b/theme/admin/html/category/update.php @@ -0,0 +1,6 @@ +
+

text('update_category')?>

+

text('update_category_desc')?>

+ + +
diff --git a/theme/admin/html/main.php b/theme/admin/html/main.php index 9a5de23..45cdc41 100644 --- a/theme/admin/html/main.php +++ b/theme/admin/html/main.php @@ -26,6 +26,7 @@
  • Dashboard
  • text('posts')?>
  • +
  • text('categories')?>
  • text('pages')?>
  • text('users')?>
  • text('overview_database_text')?>
  • diff --git a/theme/admin/html/post/form.php b/theme/admin/html/post/form.php index 346d6f4..4ae07bd 100644 --- a/theme/admin/html/post/form.php +++ b/theme/admin/html/post/form.php @@ -1,3 +1,18 @@ +%s%s [%d]'; + $select = ($category['ID'] == $selected) ? ' selected' : ''; + + printf($option, $category['ID'], $select, $prefix, escapeHTML($category['NAME']), $category['ID']); + + if(isset($category['CHILDS'])) { + # If there are children, call self and pass children array. + (__FUNCTION__)($category['CHILDS'], $selected, $prefix.'– '); + } + } +} +?>