diff --git a/bl-kernel/admin/controllers/edit-page.php b/bl-kernel/admin/controllers/edit-page.php index 23e53c51..856d9275 100644 --- a/bl-kernel/admin/controllers/edit-page.php +++ b/bl-kernel/admin/controllers/edit-page.php @@ -8,83 +8,6 @@ // 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 // ============================================================================ @@ -96,11 +19,20 @@ function deletePage($key) if( $_SERVER['REQUEST_METHOD'] == 'POST' ) { 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 { - 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'); } // ============================================================================ diff --git a/bl-kernel/admin/themes/default/css/default.css b/bl-kernel/admin/themes/default/css/default.css index 3369e64c..ce418b10 100644 --- a/bl-kernel/admin/themes/default/css/default.css +++ b/bl-kernel/admin/themes/default/css/default.css @@ -13,6 +13,7 @@ .label-draft, .label-fixed, .label-sticky, +.label-scheduled, .label-empty-title, .label-time { background: #A979D1 none repeat scroll 0 0; @@ -30,6 +31,10 @@ background: #7BD179; } +.label-scheduled { + background: #7BD179; +} + .label-empty-title { background: #53D192; } diff --git a/bl-kernel/admin/views/edit-page.php b/bl-kernel/admin/views/edit-page.php index 80583795..8e62cf26 100644 --- a/bl-kernel/admin/views/edit-page.php +++ b/bl-kernel/admin/views/edit-page.php @@ -135,7 +135,7 @@ echo '
'; 'class'=>'uk-width-1-1 uk-form-medium', 'options'=>array( 'published'=>$L->g('Published'), - 'draft'=>$L->g('Draft'), + 'drpaft'=>$L->g('Draft'), 'fixed'=>$L->g('Fixed'), 'sticky'=>$L->g('Sticky') ), diff --git a/bl-kernel/boot/rules/69.pages.php b/bl-kernel/boot/rules/69.pages.php index bc94890e..5aaa2d82 100644 --- a/bl-kernel/boot/rules/69.pages.php +++ b/bl-kernel/boot/rules/69.pages.php @@ -7,10 +7,10 @@ // Array with all published pages $pages = array(); -// Array with all pages (published, draft, scheduled) +// Array with all pages (published, fixed, sticky, draft, scheduled) $allPages = array(); -// Object Page for the page filtered bye the user +// Object Page for the page filtered by the user $page = false; // Array with all page parents published @@ -30,6 +30,12 @@ if( $dbPages->scheduler() ) { // Reindex categories reindexCategories(); + + // Add to syslog + $Syslog->add(array( + 'dictionaryKey'=>'page-published-from-scheduler', + 'notes'=>'' + )); } // Build specific page diff --git a/bl-kernel/dbcategories.class.php b/bl-kernel/dbcategories.class.php index 8229e53a..5510d480 100644 --- a/bl-kernel/dbcategories.class.php +++ b/bl-kernel/dbcategories.class.php @@ -21,8 +21,9 @@ class dbCategories extends dbList $this->db[$key]['list'] = array(); } - // Foreach post in the database - $db = $dbPages->getDB(); + // Get a database with published pages + $db = $dbPages->getPublishedDB(); + foreach($db as $pageKey=>$pageFields) { if( !empty($pageFields['category']) ) { $categoryKey = $pageFields['category']; diff --git a/bl-kernel/dbpages.class.php b/bl-kernel/dbpages.class.php index 637c6ae7..a4465803 100644 --- a/bl-kernel/dbpages.class.php +++ b/bl-kernel/dbpages.class.php @@ -42,7 +42,7 @@ class dbPages extends dbJSON $key = $this->generateKey($args['slug'], $args['parent']); // Generate UUID - $args['uuid'] = md5( uniqid() ); + $args['uuid'] = $this->generateUUID(); // Date $currentDate = Date::current(DB_DATE_FORMAT); @@ -314,6 +314,9 @@ class dbPages extends dbJSON $db = $this->getPublishedDB(); } + // Remove Error page from the list + unset($db['error']); + // The first page number is 1, so the real is 0 $realPageNumber = $pageNumber - 1; @@ -360,7 +363,7 @@ class dbPages extends dbJSON return $db; } - // Return TRUE if the page exists, FALSE otherwise. + // Return TRUE if the page exists, FALSE otherwise public function exists($key) { return isset( $this->db[$key] ); @@ -413,6 +416,43 @@ class dbPages extends dbJSON 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 @@ -518,37 +558,6 @@ class dbPages extends dbJSON 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; - } - -} +} \ No newline at end of file diff --git a/bl-kernel/dbtags.class.php b/bl-kernel/dbtags.class.php index 8da9eb0f..6cbaaa96 100644 --- a/bl-kernel/dbtags.class.php +++ b/bl-kernel/dbtags.class.php @@ -16,7 +16,9 @@ class dbTags extends dbList { global $dbPages; - $db = $dbPages->getDB(); + // Get a database with published pages + $db = $dbPages->getPublishedDB(); + $tagsIndex = array(); foreach($db as $pageKey=>$pageFields) { diff --git a/bl-kernel/functions.php b/bl-kernel/functions.php index 09f7f387..253b022c 100644 --- a/bl-kernel/functions.php +++ b/bl-kernel/functions.php @@ -59,30 +59,14 @@ function buildPage($key) function reindexCategories() { - global $dbPages; global $dbCategories; - - // Get a database with published pages - $db = $dbPages->getPublishedDB(); - - // Regenerate the tags - $dbCategories->reindex($db); - - return true; + return $dbCategories->reindex(); } function reindexTags() { - global $dbPages; global $dbTags; - - // Get a database with published pages - $db = $dbPages->getPublishedDB(); - - // Regenerate the tags - $dbTags->reindex($db); - - return true; + return $dbTags->reindex(); } function buildPagesForAdmin() @@ -209,4 +193,61 @@ function createNewPage($args) { $dbPages->delete($key); return false; -} \ No newline at end of file +} + +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; +} diff --git a/bl-themes/editorial/php/page.php b/bl-themes/editorial/php/page.php index 9af8a2f0..be886b3c 100644 --- a/bl-themes/editorial/php/page.php +++ b/bl-themes/editorial/php/page.php @@ -12,4 +12,6 @@ - \ No newline at end of file + + + \ No newline at end of file