bug fixes

This commit is contained in:
Diego Najar 2017-06-23 00:41:00 +02:00
parent c2cf10c39b
commit 304a57beca
9 changed files with 137 additions and 139 deletions

View File

@ -8,83 +8,6 @@
// Functions // Functions
// ============================================================================ // ============================================================================
function editPage($args)
{
global $dbPages;
global $Language;
global $Syslog;
if(!isset($args['parent'])) {
$args['parent'] = NO_PARENT_CHAR;
}
// Edit the page
$key = $dbPages->edit($args);
if($key) {
// Re-index categories
reindexCategories();
// Re-index tags
reindextags();
// Call the plugins after page modified
Theme::plugins('afterPageModify');
// Add to syslog
$Syslog->add(array(
'dictionaryKey'=>'page-edited',
'notes'=>$args['title']
));
// Create an alert
Alert::set( $Language->g('The changes have been saved') );
// Redirect
Redirect::page('edit-page/'.$key);
}
else {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to edit the page.');
}
return false;
}
function deletePage($key)
{
global $dbPages;
global $Language;
global $Syslog;
if( $dbPages->delete($key) ) {
// Re-index categories
reindexCategories();
// Re-index tags
reindextags();
// Call the plugins after page deleted
Theme::plugins('afterPageDelete');
// Add to syslog
$Syslog->add(array(
'dictionaryKey'=>'page-deleted',
'notes'=>$key
));
// Create an alert
Alert::set( $Language->g('The changes have been saved') );
// Redirect
Redirect::page('pages');
}
else {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to delete the page.');
}
return false;
}
// ============================================================================ // ============================================================================
// Main before POST // Main before POST
// ============================================================================ // ============================================================================
@ -96,11 +19,20 @@ function deletePage($key)
if( $_SERVER['REQUEST_METHOD'] == 'POST' ) if( $_SERVER['REQUEST_METHOD'] == 'POST' )
{ {
if( isset($_POST['delete-page']) ) { if( isset($_POST['delete-page']) ) {
deletePage($_POST['key']); if( deletePage($_POST['key']) ) {
Alert::set( $Language->g('The changes have been saved') );
Redirect::page('pages');
}
} }
else { else {
editPage($_POST); $key = editPage($_POST);
if( $key!==false ) {
Alert::set( $Language->g('The changes have been saved') );
Redirect::page('edit-page/'.$key);
}
} }
Redirect::page('pages');
} }
// ============================================================================ // ============================================================================

View File

@ -13,6 +13,7 @@
.label-draft, .label-draft,
.label-fixed, .label-fixed,
.label-sticky, .label-sticky,
.label-scheduled,
.label-empty-title, .label-empty-title,
.label-time { .label-time {
background: #A979D1 none repeat scroll 0 0; background: #A979D1 none repeat scroll 0 0;
@ -30,6 +31,10 @@
background: #7BD179; background: #7BD179;
} }
.label-scheduled {
background: #7BD179;
}
.label-empty-title { .label-empty-title {
background: #53D192; background: #53D192;
} }

View File

@ -135,7 +135,7 @@ echo '<div class="bl-publish-sidebar uk-width-2-10">';
'class'=>'uk-width-1-1 uk-form-medium', 'class'=>'uk-width-1-1 uk-form-medium',
'options'=>array( 'options'=>array(
'published'=>$L->g('Published'), 'published'=>$L->g('Published'),
'draft'=>$L->g('Draft'), 'drpaft'=>$L->g('Draft'),
'fixed'=>$L->g('Fixed'), 'fixed'=>$L->g('Fixed'),
'sticky'=>$L->g('Sticky') 'sticky'=>$L->g('Sticky')
), ),

View File

@ -7,10 +7,10 @@
// Array with all published pages // Array with all published pages
$pages = array(); $pages = array();
// Array with all pages (published, draft, scheduled) // Array with all pages (published, fixed, sticky, draft, scheduled)
$allPages = array(); $allPages = array();
// Object Page for the page filtered bye the user // Object Page for the page filtered by the user
$page = false; $page = false;
// Array with all page parents published // Array with all page parents published
@ -30,6 +30,12 @@ if( $dbPages->scheduler() ) {
// Reindex categories // Reindex categories
reindexCategories(); reindexCategories();
// Add to syslog
$Syslog->add(array(
'dictionaryKey'=>'page-published-from-scheduler',
'notes'=>''
));
} }
// Build specific page // Build specific page

View File

@ -21,8 +21,9 @@ class dbCategories extends dbList
$this->db[$key]['list'] = array(); $this->db[$key]['list'] = array();
} }
// Foreach post in the database // Get a database with published pages
$db = $dbPages->getDB(); $db = $dbPages->getPublishedDB();
foreach($db as $pageKey=>$pageFields) { foreach($db as $pageKey=>$pageFields) {
if( !empty($pageFields['category']) ) { if( !empty($pageFields['category']) ) {
$categoryKey = $pageFields['category']; $categoryKey = $pageFields['category'];

View File

@ -42,7 +42,7 @@ class dbPages extends dbJSON
$key = $this->generateKey($args['slug'], $args['parent']); $key = $this->generateKey($args['slug'], $args['parent']);
// Generate UUID // Generate UUID
$args['uuid'] = md5( uniqid() ); $args['uuid'] = $this->generateUUID();
// Date // Date
$currentDate = Date::current(DB_DATE_FORMAT); $currentDate = Date::current(DB_DATE_FORMAT);
@ -314,6 +314,9 @@ class dbPages extends dbJSON
$db = $this->getPublishedDB(); $db = $this->getPublishedDB();
} }
// Remove Error page from the list
unset($db['error']);
// The first page number is 1, so the real is 0 // The first page number is 1, so the real is 0
$realPageNumber = $pageNumber - 1; $realPageNumber = $pageNumber - 1;
@ -360,7 +363,7 @@ class dbPages extends dbJSON
return $db; return $db;
} }
// Return TRUE if the page exists, FALSE otherwise. // Return TRUE if the page exists, FALSE otherwise
public function exists($key) public function exists($key)
{ {
return isset( $this->db[$key] ); return isset( $this->db[$key] );
@ -413,6 +416,43 @@ class dbPages extends dbJSON
return $a['date']<$b['date']; return $a['date']<$b['date'];
} }
private function generateUUID() {
return md5( uniqid().time() );
}
// Returns TRUE if there are new pages published, FALSE otherwise
public function scheduler()
{
// Get current date
$currentDate = Date::current(DB_DATE_FORMAT);
$saveDatabase = false;
// The database need to be sorted by date
foreach($this->db as $pageKey=>$fields) {
if($fields['status']=='scheduled') {
if($fields['date']<=$currentDate) {
$this->db[$pageKey]['status'] = 'published';
$saveDatabase = true;
}
}
elseif( ($fields['status']=='published') && (ORDER_BY=='date') ) {
break;
}
}
if($saveDatabase) {
if( $this->save() === false ) {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
return false;
}
Log::set(__METHOD__.LOG_SEP.'New pages published from the scheduler.');
return true;
}
return false;
}
// ----- OLD // ----- OLD
@ -518,37 +558,6 @@ class dbPages extends dbJSON
return $this->save(); return $this->save();
} }
// Return TRUE if there are new pages published, FALSE otherwise.
public function scheduler()
{
// Get current date
$currentDate = Date::current(DB_DATE_FORMAT);
$saveDatabase = false;
// The database need to be sorted by date
foreach($this->db as $pageKey=>$fields) {
if($fields['status']=='scheduled') {
if($fields['date']<=$currentDate) {
$this->db[$pageKey]['status'] = 'published';
$saveDatabase = true;
}
}
elseif($fields['status']=='published') {
break;
}
}
if($saveDatabase) { }
if( $this->save() === false ) {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
return false;
}
Log::set(__METHOD__.LOG_SEP.'New pages published from the scheduler.');
return true;
}
return false;
}
}

View File

@ -16,7 +16,9 @@ class dbTags extends dbList
{ {
global $dbPages; global $dbPages;
$db = $dbPages->getDB(); // Get a database with published pages
$db = $dbPages->getPublishedDB();
$tagsIndex = array(); $tagsIndex = array();
foreach($db as $pageKey=>$pageFields) { foreach($db as $pageKey=>$pageFields) {

View File

@ -59,30 +59,14 @@ function buildPage($key)
function reindexCategories() function reindexCategories()
{ {
global $dbPages;
global $dbCategories; global $dbCategories;
return $dbCategories->reindex();
// Get a database with published pages
$db = $dbPages->getPublishedDB();
// Regenerate the tags
$dbCategories->reindex($db);
return true;
} }
function reindexTags() function reindexTags()
{ {
global $dbPages;
global $dbTags; global $dbTags;
return $dbTags->reindex();
// Get a database with published pages
$db = $dbPages->getPublishedDB();
// Regenerate the tags
$dbTags->reindex($db);
return true;
} }
function buildPagesForAdmin() function buildPagesForAdmin()
@ -209,4 +193,61 @@ function createNewPage($args) {
$dbPages->delete($key); $dbPages->delete($key);
return false; return false;
} }
function editPage($args) {
global $dbPages;
global $Syslog;
if(!isset($args['parent'])) {
$args['parent'] = NO_PARENT_CHAR;
}
$key = $dbPages->edit($args);
if($key) {
// Call the plugins after page modified
Theme::plugins('afterPageModify');
// Re-index categories
reindexCategories();
// Re-index tags
reindextags();
// Add to syslog
$Syslog->add(array(
'dictionaryKey'=>'page-edited',
'notes'=>$args['title']
));
return $key;
}
return false;
}
function deletePage($key) {
global $dbPages;
global $Syslog;
if( $dbPages->delete($key) ) {
// Call the plugins after page deleted
Theme::plugins('afterPageDelete');
// Re-index categories
reindexCategories();
// Re-index tags
reindextags();
// Add to syslog
$Syslog->add(array(
'dictionaryKey'=>'page-deleted',
'notes'=>$key
));
return true;
}
return false;
}

View File

@ -12,4 +12,6 @@
<!-- Plugins with the hook pageEnd --> <!-- Plugins with the hook pageEnd -->
<?php Theme::plugins('pageEnd') ?> <?php Theme::plugins('pageEnd') ?>
</section> </section>
<?php var_dump($page); ?>