From efe9b742c75e68c35fe164989bfb435a60b22e84 Mon Sep 17 00:00:00 2001 From: Diego Najar Date: Sat, 29 Jul 2017 21:03:18 +0200 Subject: [PATCH] bug fixes --- bl-kernel/admin/controllers/edit-category.php | 65 +++---------------- bl-kernel/boot/init.php | 2 +- bl-kernel/dbusers.class.php | 2 +- bl-kernel/functions.php | 50 +++++++++++++- bl-themes/log/index.php | 18 ++++- 5 files changed, 73 insertions(+), 64 deletions(-) diff --git a/bl-kernel/admin/controllers/edit-category.php b/bl-kernel/admin/controllers/edit-category.php index 1f64dcbe..a50e7453 100644 --- a/bl-kernel/admin/controllers/edit-category.php +++ b/bl-kernel/admin/controllers/edit-category.php @@ -6,62 +6,13 @@ if($Login->role()!=='admin') { Alert::set($Language->g('you-do-not-have-sufficient-permissions')); - Redirect::page('admin', 'dashboard'); + Redirect::page('dashboard'); } // ============================================================================ // Functions // ============================================================================ -function edit($oldCategoryKey, $newCategory) -{ - global $Language; - global $dbPages; - global $dbCategories; - - if( Text::isEmpty($oldCategoryKey) || Text::isEmpty($newCategory) ) { - Alert::set($Language->g('Empty fields')); - Redirect::page('categories'); - } - - if( $dbCategories->edit($oldCategoryKey, $newCategory) == false ) { - Alert::set($Language->g('Already exist a category')); - } - else { - $dbPages->changeCategory($oldCategoryKey, $newCategory); - Alert::set($Language->g('The changes have been saved')); - } - - // Add to syslog - $Syslog->add(array( - 'dictionaryKey'=>'category-edited', - 'notes'=>$newCategory - )); - - Redirect::page('categories'); -} - -function delete($categoryKey) -{ - global $Language; - global $dbCategories; - - // Remove the category by key - $dbCategories->remove($categoryKey); - - // Add to syslog - $Syslog->add(array( - 'dictionaryKey'=>'category-deleted', - 'notes'=>$categoryKey - )); - - // Create an alert - Alert::set($Language->g('The changes have been saved')); - - // Redirect - Redirect::page('categories'); -} - // ============================================================================ // Main before POST // ============================================================================ @@ -70,14 +21,16 @@ function delete($categoryKey) // POST Method // ============================================================================ -if( $_SERVER['REQUEST_METHOD'] == 'POST' ) -{ - if( isset($_POST['delete']) ) { - delete($_POST['categoryKey']); +if ($_SERVER['REQUEST_METHOD']=='POST') { + + if (isset($_POST['delete'])) { + deleteCategory($_POST['categoryKey']); } - elseif( isset($_POST['edit']) ) { - edit($_POST['categoryKey'], $_POST['category']); + elseif (isset($_POST['edit'])) { + editCategory($_POST['categoryKey'], $_POST['category']); } + + Redirect::page('categories'); } // ============================================================================ diff --git a/bl-kernel/boot/init.php b/bl-kernel/boot/init.php index 7abfc971..f1cbe32d 100644 --- a/bl-kernel/boot/init.php +++ b/bl-kernel/boot/init.php @@ -111,7 +111,7 @@ define('CLI_STATUS', 'published'); define('CLI_USERNAME', 'admin'); // Filename -define('FILENAME', 'index.md'); +define('FILENAME', 'index.txt'); // Database date format define('DB_DATE_FORMAT', 'Y-m-d H:i:s'); diff --git a/bl-kernel/dbusers.class.php b/bl-kernel/dbusers.class.php index 15c2d87f..ede2db5c 100644 --- a/bl-kernel/dbusers.class.php +++ b/bl-kernel/dbusers.class.php @@ -101,7 +101,7 @@ class dbUsers extends dbJSON public function getUser($username) { - if($this->exists($username)) { + if ($this->exists($username)) { $User = new User(); $User->setField('username', $username); diff --git a/bl-kernel/functions.php b/bl-kernel/functions.php index e6c2a3aa..3ee45ca8 100644 --- a/bl-kernel/functions.php +++ b/bl-kernel/functions.php @@ -10,20 +10,20 @@ function buildPage($key) { // Page object, content from index.txt file $page = new Page($key); - if( !$page->isValid() ) { + if (!$page->isValid()) { Log::set(__METHOD__.LOG_SEP.'Error occurred when trying build the page from file with key: '.$key); return false; } // Get the database from dbPages $db = $dbPages->getPageDB($key); - if( !$db ) { + if (!$db) { Log::set(__METHOD__.LOG_SEP.'Error occurred when trying build the page from database with key: '.$key); return false; } // Foreach field from database set on the object - foreach($db as $field=>$value) { + foreach ($db as $field=>$value) { $page->setField($field, $value); } @@ -497,4 +497,48 @@ function editSettings($args) { } return false; +} + +function editCategory($oldCategoryKey, $newCategory) { + global $Language; + global $dbPages; + global $dbCategories; + global $Syslog; + + if( Text::isEmpty($oldCategoryKey) || Text::isEmpty($newCategory) ) { + Alert::set($Language->g('Empty fields')); + return false; + } + + if( $dbCategories->edit($oldCategoryKey, $newCategory) == false ) { + Alert::set($Language->g('Already exist a category')); + return false; + } + + $dbPages->changeCategory($oldCategoryKey, $newCategory); + + $Syslog->add(array( + 'dictionaryKey'=>'category-edited', + 'notes'=>$newCategory + )); + + Alert::set($Language->g('The changes have been saved')); + return true; +} + +function deleteCategory($categoryKey) { + global $Language; + global $dbCategories; + global $Syslog; + + // Remove the category by key + $dbCategories->remove($categoryKey); + + $Syslog->add(array( + 'dictionaryKey'=>'category-deleted', + 'notes'=>$categoryKey + )); + + Alert::set($Language->g('The changes have been saved')); + return true; } \ No newline at end of file diff --git a/bl-themes/log/index.php b/bl-themes/log/index.php index 17cfa1ad..f9b97e82 100644 --- a/bl-themes/log/index.php +++ b/bl-themes/log/index.php @@ -15,8 +15,10 @@