Minor bug fixes

This commit is contained in:
dignajar 2016-02-06 20:44:43 -03:00
parent 791f2dfb00
commit cfc9d49950
6 changed files with 22 additions and 13 deletions

View File

@ -17,6 +17,7 @@ class Content {
return($this->vars!==false); return($this->vars!==false);
} }
// Returns the value from the $field, FALSE if the field doesn't exist.
public function getField($field) public function getField($field)
{ {
if(isset($this->vars[$field])) { if(isset($this->vars[$field])) {
@ -38,7 +39,7 @@ class Content {
private function build($path) private function build($path)
{ {
if( !Sanitize::pathFile($path, 'index.txt') ) { if( !Sanitize::pathFile($path.'index.txt') ) {
return false; return false;
} }

View File

@ -45,6 +45,7 @@ class dbJSON
public function restoreDB() public function restoreDB()
{ {
$this->db = $this->dbBackup; $this->db = $this->dbBackup;
return true; return true;
} }

View File

@ -85,9 +85,12 @@ define('POSTS_PER_PAGE_ADMIN', 10);
// Check if JSON encode and decode are enabled. // Check if JSON encode and decode are enabled.
// define('JSON', function_exists('json_encode')); // 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'); define('CLI_STATUS', 'published');
// Cli mode username for new posts/pages
define('CLI_USERNAME', 'admin');
// Database date format // Database date format
define('DB_DATE_FORMAT', 'Y-m-d H:i:s'); define('DB_DATE_FORMAT', 'Y-m-d H:i:s');

View File

@ -20,10 +20,10 @@ function reIndexTagsPosts()
// Remove unpublished. // Remove unpublished.
$dbPosts->removeUnpublished(); $dbPosts->removeUnpublished();
// Regenerate the tags index for posts // Regenerate the tags index for posts.
$dbTags->reindexPosts( $dbPosts->db ); $dbTags->reindexPosts( $dbPosts->db );
// Restore de db on dbPost // Restore the database, before remove the unpublished.
$dbPosts->restoreDB(); $dbPosts->restoreDB();
return true; return true;

View File

@ -244,7 +244,12 @@ class dbPosts extends dbJSON
$outrange = $init<0 ? true : $init>$end; $outrange = $init<0 ? true : $init>$end;
if(!$outrange) { 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(); return array();
@ -390,7 +395,7 @@ class dbPosts extends dbJSON
return $a['date']<$b['date']; 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() public function regenerateCli()
{ {
$db = $this->db; $db = $this->db;
@ -407,23 +412,23 @@ class dbPosts extends dbJSON
$fields['status'] = CLI_STATUS; $fields['status'] = CLI_STATUS;
$fields['date'] = $currentDate; $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); $tmpPaths = Filesystem::listDirectories(PATH_POSTS);
foreach($tmpPaths as $directory) 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. // The key is the directory name.
$key = basename($directory); $key = basename($directory);
// All keys posts
$allPosts[$key] = true; $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])) { if(!isset($this->db[$key])) {
// New entry on database // New entry on database with the default fields and values.
$this->db[$key] = $fields; $this->db[$key] = $fields;
} }

View File

@ -64,7 +64,6 @@ class dbTags extends dbJSON
public function reindexPosts($db) public function reindexPosts($db)
{ {
$tagsIndex = array(); $tagsIndex = array();
$currentDate = Date::current(DB_DATE_FORMAT);
// Foreach post // Foreach post
foreach($db as $postKey=>$values) foreach($db as $postKey=>$values)