Improves on Manage pages and minor fixes

This commit is contained in:
Diego Najar 2017-09-10 23:09:44 +02:00
parent caa96d4fa4
commit 9798bbcd9b
8 changed files with 74 additions and 76 deletions

View File

@ -16,8 +16,7 @@
// POST Method // POST Method
// ============================================================================ // ============================================================================
if( $_SERVER['REQUEST_METHOD'] == 'POST' ) if ($_SERVER['REQUEST_METHOD'] == 'POST') {
{
if( isset($_POST['delete-page']) ) { if( isset($_POST['delete-page']) ) {
if( deletePage($_POST['key']) ) { if( deletePage($_POST['key']) ) {
Alert::set( $Language->g('The changes have been saved') ); Alert::set( $Language->g('The changes have been saved') );
@ -38,13 +37,12 @@ if( $_SERVER['REQUEST_METHOD'] == 'POST' )
// ============================================================================ // ============================================================================
// Main after POST // Main after POST
// ============================================================================ // ============================================================================
$pageKey = $layout['parameters'];
if( !$dbPages->exists($layout['parameters']) ) { $page = buildPage($pageKey);
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to get the page: '.$layout['parameters']); if ($page===false) {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to get the page: '.$pageKey);
Redirect::page('pages'); Redirect::page('pages');
} }
$page = $pagesByKey[$layout['parameters']];
// Title of the page // Title of the page
$layout['title'] .= ' - '.$Language->g('Edit Content').' - '.$page->title(); $layout['title'] .= ' - '.$Language->g('Edit Content').' - '.$page->title();

View File

@ -16,11 +16,8 @@
// POST Method // POST Method
// ============================================================================ // ============================================================================
if( $_SERVER['REQUEST_METHOD'] == 'POST' ) { if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (createPage($_POST)!==false) { createPage($_POST);
Alert::set( $Language->g('Page added successfully') );
}
Redirect::page('pages'); Redirect::page('pages');
} }

View File

@ -20,5 +20,23 @@
// Main after POST // Main after POST
// ============================================================================ // ============================================================================
// List of published pages
$onlyPublished = true;
$amountOfItems = ITEMS_PER_PAGE_ADMIN;
$pageNumber = $Url->pageNumber();
$published = $dbPages->getList($pageNumber, $amountOfItems, $onlyPublished);
// Check if out of range the pageNumber
if (empty($published)) {
Redirect::page('pages');
}
// List of drafts pages
$drafts = $dbPages->getDraftDB();
$scheduled = $dbPages->getScheduledDB();
$fixed = $dbPages->getFixedDB();
// Title of the page // Title of the page
$layout['title'] .= ' - '.$Language->g('Manage Content'); $layout['title'] .= ' - '.$Language->g('Manage Content');

View File

@ -22,42 +22,53 @@ echo '
'; ';
function table($status, $icon='arrow-circle-o-down') { function table($status, $icon='arrow-circle-o-down') {
global $pages;
global $Url; global $Url;
global $Language; global $Language;
global $published;
global $drafts;
global $scheduled;
global $fixed;
$showLegend = true; if ($status=='published') {
foreach ($pages as $key=>$page) { $list = $published;
if ($page->status()==$status) { } elseif ($status=='draft') {
if ($showLegend) { $list = $drafts;
$showLegend = false; } elseif ($status=='scheduled') {
echo '<tr> $list = $scheduled;
<td style="color: #aaa; font-size: 0.9em; text-transform: uppercase;"><i class="fa fa-'.$icon.'" aria-hidden="true"></i> '.$status.'</td> } elseif ($status=='fixed') {
<td></td> $list = $fixed;
<td></td> }
</tr>';
}
unset($pages[$key]);
echo '<tr>';
echo '<td>
<a href="'.HTML_PATH_ADMIN_ROOT.'edit-page/'.$page->key().'">'
.($page->title()?$page->title():'<span class="label-empty-title">'.$Language->g('Empty title').'</span> ')
.'</a>
</td>';
echo '<td class="uk-text-center">'.( (ORDER_BY=='date') ? $page->dateRaw() : $page->position() ).'</td>'; if (!empty($list)) {
echo '<tr>
<td style="color: #aaa; font-size: 0.9em; text-transform: uppercase;"><i class="fa fa-'.$icon.'" aria-hidden="true"></i> '.$status.'</td>
<td></td>
<td></td>
</tr>';
}
$friendlyURL = Text::isEmpty($Url->filters('page')) ? '/'.$page->key() : '/'.$Url->filters('page').'/'.$page->key(); foreach($list as $pageKey=>$fields) {
echo '<td><a target="_blank" href="'.$page->permalink().'">'.$friendlyURL.'</a></td>'; $page = buildPage($pageKey);
echo '</tr>'; echo '<tr>';
} echo '<td>
<a href="'.HTML_PATH_ADMIN_ROOT.'edit-page/'.$page->key().'">'
.($page->title()?$page->title():'<span class="label-empty-title">'.$Language->g('Empty title').'</span> ')
.'</a>
</td>';
echo '<td class="uk-text-center">'.( (ORDER_BY=='date') ? $page->dateRaw() : $page->position() ).'</td>';
$friendlyURL = Text::isEmpty($Url->filters('page')) ? '/'.$page->key() : '/'.$Url->filters('page').'/'.$page->key();
echo '<td><a target="_blank" href="'.$page->permalink().'">'.$friendlyURL.'</a></td>';
echo '</tr>';
} }
} }
table('draft', 'spinner'); if ($Url->pageNumber()==1) {
table('scheduled', 'clock-o'); table('draft', 'spinner');
table('fixed', 'thumb-tack'); table('scheduled', 'clock-o');
table('sticky', 'sticky-note-o'); table('fixed', 'thumb-tack');
}
table('published', 'check'); table('published', 'check');
echo ' echo '

View File

@ -88,5 +88,4 @@ else
// Load plugins after the admin area is loaded. // Load plugins after the admin area is loaded.
Theme::plugins('afterAdminLoad'); Theme::plugins('afterAdminLoad');
} }

View File

@ -16,18 +16,6 @@
*/ */
$pages = array(); $pages = array();
// Array with pages, each page is a Page Object
// Filtered by pagenumber and amount of items per page
/*
array(
"pageKey1" => Page Object,
"pageKey2" => Page Object,
...
"pageKeyN" => Page Object,
)
*/
$pagesByKey = array();
// Page filtered by the user, is a Page Object // Page filtered by the user, is a Page Object
$page = $Page = false; $page = $Page = false;
@ -127,10 +115,6 @@ elseif ($Url->whereAmI()==='category') {
elseif ($Url->whereAmI()==='home') { elseif ($Url->whereAmI()==='home') {
buildPagesForHome(); buildPagesForHome();
} }
// Build pages for the admin area
elseif ($Url->whereAmI()==='admin') {
buildPagesForAdmin();
}
// Set page 404 not found // Set page 404 not found
if ($Url->notFound()) { if ($Url->notFound()) {

View File

@ -100,10 +100,6 @@ function buildThePage() {
return true; return true;
} }
function buildPagesForAdmin() {
return buildPagesFor('admin');
}
function buildPagesForHome() { function buildPagesForHome() {
return buildPagesFor('home'); return buildPagesFor('home');
} }
@ -128,27 +124,21 @@ function buildPagesFor($for, $categoryKey=false, $tagKey=false) {
global $dbTags; global $dbTags;
global $Site; global $Site;
global $Url; global $Url;
global $pagesByKey;
global $pages; global $pages;
// Get the page number from URL // Get the page number from URL
$pageNumber = $Url->pageNumber(); $pageNumber = $Url->pageNumber();
if($for=='admin') { if ($for=='home') {
$onlyPublished = false;
$amountOfItems = ITEMS_PER_PAGE_ADMIN;
$list = $dbPages->getList($pageNumber, $amountOfItems, $onlyPublished);
}
elseif($for=='home') {
$onlyPublished = true; $onlyPublished = true;
$amountOfItems = $Site->itemsPerPage(); $amountOfItems = $Site->itemsPerPage();
$list = $dbPages->getList($pageNumber, $amountOfItems, $onlyPublished); $list = $dbPages->getList($pageNumber, $amountOfItems, $onlyPublished);
} }
elseif($for=='category') { elseif ($for=='category') {
$amountOfItems = $Site->itemsPerPage(); $amountOfItems = $Site->itemsPerPage();
$list = $dbCategories->getList($categoryKey, $pageNumber, $amountOfItems); $list = $dbCategories->getList($categoryKey, $pageNumber, $amountOfItems);
} }
elseif($for=='tag') { elseif ($for=='tag') {
$amountOfItems = $Site->itemsPerPage(); $amountOfItems = $Site->itemsPerPage();
$list = $dbTags->getList($tagKey, $pageNumber, $amountOfItems); $list = $dbTags->getList($tagKey, $pageNumber, $amountOfItems);
} }
@ -160,14 +150,9 @@ function buildPagesFor($for, $categoryKey=false, $tagKey=false) {
} }
$pages = array(); // global variable $pages = array(); // global variable
$pagesByKey = array(); // global variable
foreach($list as $pageKey=>$fields) { foreach($list as $pageKey=>$fields) {
$page = buildPage($pageKey); $page = buildPage($pageKey);
if($page!==false) { if($page!==false) {
// $pagesByKey
$pagesByKey[$pageKey] = $page;
// $pages
array_push($pages, $page); array_push($pages, $page);
} }
} }
@ -309,6 +294,7 @@ function printDebug($array) {
function createPage($args) { function createPage($args) {
global $dbPages; global $dbPages;
global $Syslog; global $Syslog;
global $Language;
// The user is always the one loggued // The user is always the one loggued
$args['username'] = Session::get('username'); $args['username'] = Session::get('username');
@ -339,6 +325,8 @@ function createPage($args) {
'notes'=>$args['title'] 'notes'=>$args['title']
)); ));
Alert::set( $Language->g('new-page-created') );
return $key; return $key;
} }
@ -550,6 +538,7 @@ function editSettings($args) {
global $Site; global $Site;
global $Syslog; global $Syslog;
global $Language; global $Language;
global $dbPages;
if (isset($args['language'])) { if (isset($args['language'])) {
if ($args['language']!=$Site->language()) { if ($args['language']!=$Site->language()) {

View File

@ -199,5 +199,7 @@
"this-title-is-almost-always-used-in-the-sidebar-of-the-site": "This title is almost always used in the sidebar of the site.", "this-title-is-almost-always-used-in-the-sidebar-of-the-site": "This title is almost always used in the sidebar of the site.",
"password-must-be-at-least-6-characters-long": "Password must be at least 6 characters long", "password-must-be-at-least-6-characters-long": "Password must be at least 6 characters long",
"ip-address-has-been-blocked": "IP address has been blocked", "ip-address-has-been-blocked": "IP address has been blocked",
"try-again-in-a-few-minutes": "Try again in a few minutes" "try-again-in-a-few-minutes": "Try again in a few minutes",
"page-published-from-scheduler": "Page published from scheduler",
"installer-page-about-content": "The about page is an important and powerful for potential clients and partners. For those who wonder who is behind the website, your About page is the first source of information."
} }