From cfc9d4995046cb40516ae53b1fc5c990862a04ec Mon Sep 17 00:00:00 2001 From: dignajar Date: Sat, 6 Feb 2016 20:44:43 -0300 Subject: [PATCH] Minor bug fixes --- bl-kernel/abstract/content.class.php | 3 ++- bl-kernel/abstract/dbjson.class.php | 1 + bl-kernel/boot/init.php | 5 ++++- bl-kernel/boot/rules/70.posts.php | 4 ++-- bl-kernel/dbposts.class.php | 21 +++++++++++++-------- bl-kernel/dbtags.class.php | 1 - 6 files changed, 22 insertions(+), 13 deletions(-) diff --git a/bl-kernel/abstract/content.class.php b/bl-kernel/abstract/content.class.php index 710605f5..dcb72fa0 100644 --- a/bl-kernel/abstract/content.class.php +++ b/bl-kernel/abstract/content.class.php @@ -17,6 +17,7 @@ class Content { return($this->vars!==false); } + // Returns the value from the $field, FALSE if the field doesn't exist. public function getField($field) { if(isset($this->vars[$field])) { @@ -38,7 +39,7 @@ class Content { private function build($path) { - if( !Sanitize::pathFile($path, 'index.txt') ) { + if( !Sanitize::pathFile($path.'index.txt') ) { return false; } diff --git a/bl-kernel/abstract/dbjson.class.php b/bl-kernel/abstract/dbjson.class.php index ef881474..04dffaa9 100644 --- a/bl-kernel/abstract/dbjson.class.php +++ b/bl-kernel/abstract/dbjson.class.php @@ -45,6 +45,7 @@ class dbJSON public function restoreDB() { $this->db = $this->dbBackup; + return true; } diff --git a/bl-kernel/boot/init.php b/bl-kernel/boot/init.php index 605b238f..d754fb61 100644 --- a/bl-kernel/boot/init.php +++ b/bl-kernel/boot/init.php @@ -85,9 +85,12 @@ define('POSTS_PER_PAGE_ADMIN', 10); // Check if JSON encode and decode are enabled. // define('JSON', function_exists('json_encode')); -// TRUE if new posts hand-made set published, or FALSE for draft. +// Cli mode status for new posts/pages define('CLI_STATUS', 'published'); +// Cli mode username for new posts/pages +define('CLI_USERNAME', 'admin'); + // Database date format define('DB_DATE_FORMAT', 'Y-m-d H:i:s'); diff --git a/bl-kernel/boot/rules/70.posts.php b/bl-kernel/boot/rules/70.posts.php index e118f999..c9cf812c 100644 --- a/bl-kernel/boot/rules/70.posts.php +++ b/bl-kernel/boot/rules/70.posts.php @@ -20,10 +20,10 @@ function reIndexTagsPosts() // Remove unpublished. $dbPosts->removeUnpublished(); - // Regenerate the tags index for posts + // Regenerate the tags index for posts. $dbTags->reindexPosts( $dbPosts->db ); - // Restore de db on dbPost + // Restore the database, before remove the unpublished. $dbPosts->restoreDB(); return true; diff --git a/bl-kernel/dbposts.class.php b/bl-kernel/dbposts.class.php index f847a80c..7609466e 100644 --- a/bl-kernel/dbposts.class.php +++ b/bl-kernel/dbposts.class.php @@ -244,7 +244,12 @@ class dbPosts extends dbJSON $outrange = $init<0 ? true : $init>$end; if(!$outrange) { - return array_slice($this->db, $init, $postPerPage, true); + $tmp = array_slice($this->db, $init, $postPerPage, true); + + // Restore the database because we delete the unpublished posts. + $this->restoreDB(); + + return $tmp; } return array(); @@ -390,7 +395,7 @@ class dbPosts extends dbJSON return $a['date']<$b['date']; } - // Return TRUE if there are new posts, FALSE otherwise. + // Return TRUE if there are new posts or orphan post deleted, FALSE otherwise. public function regenerateCli() { $db = $this->db; @@ -407,23 +412,23 @@ class dbPosts extends dbJSON $fields['status'] = CLI_STATUS; $fields['date'] = $currentDate; - $fields['username'] = 'admin'; + $fields['username'] = CLI_USERNAME; - // Recovery posts from the first level of directories + // Get all posts from the first level of directories. $tmpPaths = Filesystem::listDirectories(PATH_POSTS); foreach($tmpPaths as $directory) { - if(file_exists($directory.DS.'index.txt')) + // Check if the post have the index.txt file. + if(Sanitize::pathFile($directory.DS.'index.txt')) { // The key is the directory name. $key = basename($directory); - // All keys posts $allPosts[$key] = true; - // Create the new entry if not exist on DATABASE. + // Create the new entry if not exist inside the DATABASE. if(!isset($this->db[$key])) { - // New entry on database + // New entry on database with the default fields and values. $this->db[$key] = $fields; } diff --git a/bl-kernel/dbtags.class.php b/bl-kernel/dbtags.class.php index 157734e6..e338901d 100644 --- a/bl-kernel/dbtags.class.php +++ b/bl-kernel/dbtags.class.php @@ -64,7 +64,6 @@ class dbTags extends dbJSON public function reindexPosts($db) { $tagsIndex = array(); - $currentDate = Date::current(DB_DATE_FORMAT); // Foreach post foreach($db as $postKey=>$values)