From 5b0b8b874cbc00a62ba4ea80593afdb27004282a Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 25 Jan 2025 15:01:12 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20(content):=20add=20a=20pagetype=20c?= =?UTF-8?q?lass?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bl-kernel/boot/init.php | 4 ++ bl-kernel/helpers/updater.class.php | 15 ++++++- bl-kernel/pagetype.class.php | 61 +++++++++++++++++++++++++++++ bl-kernel/pagetypes.class.php | 36 +++++++++++++++++ bl-languages/fr_FR.json | 4 ++ install.php | 6 +++ 6 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 bl-kernel/pagetype.class.php create mode 100644 bl-kernel/pagetypes.class.php diff --git a/bl-kernel/boot/init.php b/bl-kernel/boot/init.php index 0f35b018..e1e0d433 100644 --- a/bl-kernel/boot/init.php +++ b/bl-kernel/boot/init.php @@ -63,6 +63,7 @@ define('DEBUG_FILE', PATH_CONTENT . 'debug.txt'); // PAGES DATABASE define('DB_PAGES', PATH_DATABASES . 'pages.php'); +define('DB_PAGE_TYPES', PATH_DATABASES . 'pagetypes.php'); define('DB_SITE', PATH_DATABASES . 'site.php'); define('DB_CATEGORIES', PATH_DATABASES . 'categories.php'); define('DB_TAGS', PATH_DATABASES . 'tags.php'); @@ -87,6 +88,7 @@ include(PATH_ABSTRACT . 'dblist.class.php'); include(PATH_ABSTRACT . 'plugin.class.php'); // Inclde Classes +include(PATH_KERNEL . 'pagetypes.class.php'); include(PATH_KERNEL . 'pages.class.php'); include(PATH_KERNEL . 'users.class.php'); include(PATH_KERNEL . 'tags.class.php'); @@ -96,6 +98,7 @@ include(PATH_KERNEL . 'language.class.php'); include(PATH_KERNEL . 'site.class.php'); include(PATH_KERNEL . 'categories.class.php'); include(PATH_KERNEL . 'syslog.class.php'); +include(PATH_KERNEL . 'pagetype.class.php'); include(PATH_KERNEL . 'pagex.class.php'); include(PATH_KERNEL . 'category.class.php'); include(PATH_KERNEL . 'tag.class.php'); @@ -130,6 +133,7 @@ include(PATH_HELPERS . 'cookie.class.php'); include(PATH_HELPERS . 'updater.class.php'); // Objects +$pagetypes = new PageTypes(); $pages = new Pages(); $users = new Users(); $tags = new Tags(); diff --git a/bl-kernel/helpers/updater.class.php b/bl-kernel/helpers/updater.class.php index 1fda64a7..ab0e5421 100644 --- a/bl-kernel/helpers/updater.class.php +++ b/bl-kernel/helpers/updater.class.php @@ -5,7 +5,11 @@ class KoblogUpdater { // Special function to upgrade public static function upgradeArticlesToPageTypes() { + $dataHead = "" . PHP_EOL; + global $pages; + global $L; + foreach ($pages->db as $key => $fields) { if ($fields['type'] === "published") { $pages->db[$key]['type'] = "article"; @@ -35,7 +39,16 @@ class KoblogUpdater { $pages->db[$key]['sticky'] = false; } } - + + // + if (!file_exists(PATH_DATABASES . 'pagetypes.php')) { + $data = array( + 'article' => array('name' => $L->g("Article"), 'plural' => $L->g("Articles"), 'icon'=>'fa-file-text'), + 'static' => array('name' => $L->g("Static page"), 'plural' => $L->g("Static pages"), 'icon'=>'fa-file'), + ); + file_put_contents(PATH_DATABASES . 'pagetypes.php', $dataHead . json_encode($data, JSON_PRETTY_PRINT), LOCK_EX); + } + return $pages->save(); } diff --git a/bl-kernel/pagetype.class.php b/bl-kernel/pagetype.class.php new file mode 100644 index 00000000..c5f821bb --- /dev/null +++ b/bl-kernel/pagetype.class.php @@ -0,0 +1,61 @@ +vars['type'] = $type; + + if (Text::isEmpty($type) || !$pagetypes->exists($type)) { + $errorMessage = 'Page Type not found in the database [' . $type . ']'; + Log::set(__METHOD__ . LOG_SEP . $errorMessage); + throw new Exception($errorMessage); + } + $row = $pagetypes->getTypeDB($type); + + foreach ($row as $field => $value) { + $this->setField($field, $value); + } + } + + public function getValue($field) + { + if (isset($this->vars[$field])) { + return $this->vars[$field]; + } + return false; + } + + public function setField($field, $value) + { + $this->vars[$field] = $value; + return true; + } + + public function getDB() + { + return $this->vars; + } + + public function type() + { + return $this->getValue("type"); + } + public function icon() + { + return $this->getValue("icon"); + } + public function name() + { + return $this->getValue("name"); + } + public function plural() + { + return $this->getValue("plural"); + } + +} \ No newline at end of file diff --git a/bl-kernel/pagetypes.class.php b/bl-kernel/pagetypes.class.php new file mode 100644 index 00000000..5a4d249b --- /dev/null +++ b/bl-kernel/pagetypes.class.php @@ -0,0 +1,36 @@ +'', + 'plural'=>'', + 'icon'=>'fa-file' + ); + + function __construct() + { + parent::__construct(DB_PAGE_TYPES); + } + + public function getDefaultFields() + { + return $this->dbFields; + } + + // Return an array with the database of the user, FALSE otherwise + public function getTypeDB($type) + { + if ($this->exists($type)) { + return $this->db[$type]; + } + return false; + } + + // Return TRUE if the type exists, FALSE otherwise + public function exists($type) + { + return isset($this->db[$type]); + } + +} \ No newline at end of file diff --git a/bl-languages/fr_FR.json b/bl-languages/fr_FR.json index 72192ee8..28c4e145 100644 --- a/bl-languages/fr_FR.json +++ b/bl-languages/fr_FR.json @@ -262,6 +262,10 @@ "type": "Type", "draft-content": "Contenu brouillon", "post": "Article", + "article": "Article", + "articles": "Articles", + "static-page": "Page statique", + "static-pages": "Pages statiques", "default": "Défaut", "latest-content": "Dernier contenu", "default-message": "Message par défaut", diff --git a/install.php b/install.php index ced49f0b..ccbcfb79 100644 --- a/install.php +++ b/install.php @@ -468,6 +468,12 @@ function install($adminPassword, $timezone) ); file_put_contents(PATH_DATABASES . 'categories.php', $dataHead . json_encode($data, JSON_PRETTY_PRINT), LOCK_EX); + $data = array( + 'article' => array('name' => $L->g("Article"), 'plural' => $L->g("Articles"), 'icon'=>'fa-file-text'), + 'static' => array('name' => $L->g("Static page"), 'plural' => $L->g("Static pages"), 'icon'=>'fa-file'), + ); + file_put_contents(PATH_DATABASES . 'pagetypes.php', $dataHead . json_encode($data, JSON_PRETTY_PRINT), LOCK_EX); + // File tags.php $data = array(); file_put_contents(PATH_DATABASES . 'tags.php', $dataHead . json_encode($data, JSON_PRETTY_PRINT), LOCK_EX);