Fixed installer, kernel panic theme, fixed content pages

This commit is contained in:
Diego Najar 2017-07-15 15:47:37 +02:00
parent 0676b0b768
commit cb0ddf9069
10 changed files with 103 additions and 54 deletions

View File

@ -83,7 +83,7 @@ if( $_SERVER['REQUEST_METHOD'] == 'POST' )
// ============================================================================
// Main after POST
// ============================================================================
$allPublishedPages = buildAllpages(false);
$allPublishedPages = buildAllpages(true);
// Homepage select options
$homepageOptions = array();

View File

@ -110,7 +110,7 @@ define('CLI_STATUS', 'published');
define('CLI_USERNAME', 'admin');
// Filename
define('FILENAME', 'index.md');
define('FILENAME', 'index.txt');
// Database date format
define('DB_DATE_FORMAT', 'Y-m-d H:i:s');

View File

@ -100,7 +100,7 @@ if( $dbPages->scheduler() ) {
}
// Generate pages parent tree, only published pages
buildPagesByParent(false);
//buildPagesByParent(true);
// Set home page is the user defined one
if( $Site->homepage() && $Url->whereAmI()==='home' ) {

View File

@ -72,10 +72,9 @@ class dbPages extends dbJSON
}
// Where the data is stored
if($options['inFile']) {
$dataForFile[$field] = Text::firstCharUp($field).': '.$value;
}
else {
if ($options['inFile']) {
$dataForFile[$field] = $this->stylingFieldsForFile($field, $value);
} else {
// Set type
settype($value, gettype($options['value']));
@ -84,7 +83,7 @@ class dbPages extends dbJSON
}
}
if( $climode===false ) {
if ($climode===false) {
// Create the directory
if( Filesystem::mkdir(PATH_PAGES.$key, true) === false ) {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to create the directory '.PATH_PAGES.$key);
@ -92,7 +91,7 @@ class dbPages extends dbJSON
}
// Make the index.txt and save the file.
$data = implode("\n", $dataForFile);
$data = implode(PHP_EOL, $dataForFile);
if( file_put_contents(PATH_PAGES.$key.DS.FILENAME, $data) === false ) {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to put the content in the file '.FILENAME);
return false;
@ -155,11 +154,9 @@ class dbPages extends dbJSON
$value = $options['value'];
}
// Where the data is stored
if($options['inFile']) {
$dataForFile[$field] = Text::firstCharUp($field).': '.$value;
}
else {
if ($options['inFile']) {
$dataForFile[$field] = $this->stylingFieldsForFile($field, $value);
} else {
// Set type
settype($value, gettype($options['value']));
@ -309,7 +306,7 @@ class dbPages extends dbJSON
// Returns an array with a list of pages
// The database is sorted by date or by position
// (int) $pageNumber, the page number
// (int) $amountOfItems, amount of items to return
// (int) $amountOfItems, amount of items to return, if -1 returns all the items
// (boolean) $onlyPublished, TRUE to return only published pages
public function getList($pageNumber, $amountOfItems, $onlyPublished=true)
{
@ -322,6 +319,10 @@ class dbPages extends dbJSON
// Remove Error page from the list
unset($db['error']);
if($amountOfItems==-1) {
return $db;
}
// The first page number is 1, so the real is 0
$realPageNumber = $pageNumber - 1;
@ -583,6 +584,25 @@ class dbPages extends dbJSON
}
}
private function stylingFieldsForFile($field, $value)
{
// Support for Markdown files, good approach for Github
if (FILENAME==='index.md') {
if ($field==='title') {
return '#Title: '.$value;
} elseif ($field==='content') {
return '---'.PHP_EOL.$value;
} else {
return '<!-- '.Text::firstCharUp($field).': '.$value.' -->';
}
}
// Legacy style of Bludit with index.txt
if ($field==='content') {
return 'Content:'.PHP_EOL.$value;
}
return Text::firstCharUp($field).': '.$value;
}
// ----- OLD

View File

@ -149,28 +149,32 @@ function buildPagesFor($for, $categoryKey=false, $tagKey=false)
// Generate the global variable $pagesByParent, defined on 69.pages.php
// (boolean) $allPages, TRUE include all status, FALSE only include published status
function buildPagesByParent($allPages=true) {
function buildPagesByParent($onlyPublished=true) {
global $dbPages;
global $pagesByParent;
global $pagesByParentByKey;
$keys = array_keys($dbPages->db);
// Get DB
$pageNumber = 1;
$amountOfItems = -1;
$db = $dbPages->getList($pageNumber, $amountOfItems, $onlyPublished);
// Get Keys
$keys = array_keys($db);
foreach($keys as $pageKey) {
$page = buildPage($pageKey);
if($page!==false) {
if($allPages || $page->published()) {
$parentKey = $page->parentKey();
// FALSE if the page is parent
if($parentKey===false) {
array_push($pagesByParent[PARENT], $page);
$pagesByParentByKey[PARENT][$page->key()] = $page;
} else {
if( !isset($pagesByParent[$parentKey]) ) {
$pagesByParent[$parentKey] = array();
}
array_push($pagesByParent[$parentKey], $page);
$pagesByParentByKey[$parentKey][$page->key()] = $page;
$parentKey = $page->parentKey();
// FALSE if the page is parent
if($parentKey===false) {
array_push($pagesByParent[PARENT], $page);
$pagesByParentByKey[PARENT][$page->key()] = $page;
} else {
if( !isset($pagesByParent[$parentKey]) ) {
$pagesByParent[$parentKey] = array();
}
array_push($pagesByParent[$parentKey], $page);
$pagesByParentByKey[$parentKey][$page->key()] = $page;
}
}
}
@ -186,11 +190,16 @@ function buildPagesByParent($allPages=true) {
pageKeyN => Page object,
)
*/
function buildAllpages($allPages=true) {
function buildAllpages($onlyPublished=true) {
global $dbPages;
// Get DB
$pageNumber = 1;
$amountOfItems = -1;
$db = $dbPages->getList($pageNumber, $amountOfItems, $onlyPublished);
$tmp = array();
$keys = array_keys($dbPages->db);
$keys = array_keys($db);
foreach($keys as $pageKey) {
$page = buildPage($pageKey);
if($page!==false) {

View File

@ -24,8 +24,8 @@ class Page {
}
$tmp = 0;
$lines = file($filePath);
foreach($lines as $lineNumber=>$line) {
$file = file($filePath);
foreach($file as $lineNumber=>$line) {
// Split the line in 2 parts, limiter by :
$parts = explode(':', $line, 2);
@ -60,20 +60,15 @@ class Page {
}
// Process the content
if($tmp!==0) {
if ($tmp!==0) {
// Next line after "Content:" or "---"
$tmp++;
// Remove lines after Content
$output = array_slice($lines, $tmp);
// Get all lines after "Content:" or "---"
$content = array_slice($file, $tmp);
if( !empty($parts[1]) ) {
array_unshift($output, "\n");
array_unshift($output, $parts[1]);
}
$implode = implode($output);
$this->vars['contentRaw'] = $implode;
// Join lines in one variable, this is RAW content from file
$this->vars['contentRaw'] = implode($content);
}
return true;

View File

@ -9,6 +9,12 @@
"website": ""
},
"installer-page-about-content": "The about page is an important and powerful tool for potential clients and partners. For those who wonder who is behind the website, your About page is the first source of information. \n Change this page's content on the admin panel, manage, pages and click on the about page.",
"installer-page-error-content": "Opps, page not found, sorry!",
"page-not-found": "Page not found",
"about-your-site-or-yourself": "About your site or yourself",
"welcome-to-bludit": "Welcome to Bludit",
"username": "Username",
"password": "Password",
"confirm-password": "Confirm Password",
@ -215,7 +221,7 @@
"the-about-page-is-very-important": "The about page is an important and powerful tool for potential clients and partners. For those who wonder who is behind the website, your About page is the first source of information.",
"change-this-pages-content-on-the-admin-panel": "Change this page's content on the admin panel, manage, pages and click on the about page.",
"about-your-site-or-yourself": "About your site or yourself",
"welcome-to-bludit": "Welcome to Bludit",
"site-information": "Site information",
"date-and-time-formats": "Date and time formats",

View File

@ -14,11 +14,12 @@ class pluginSitemap extends Plugin {
$xml .= '<loc>'.$Site->url().'</loc>';
$xml .= '</url>';
// Get keys of pages
$keys = $dbPages->db;
unset($keys['error']);
$keys = array_keys($keys);
// Get DB
$pageNumber = 1;
$amountOfItems = -1;
$db = $dbPages->getList($pageNumber, $amountOfItems, $onlyPublished);
$keys = array_keys($db);
foreach($keys as $pageKey) {
// Create the page object from the page key
$page = buildPage($pageKey);

View File

@ -32,8 +32,13 @@ div.plugin:not(:last-child) {
margin-bottom: 40px;
}
div.plugin h2.plugin-label {
div.plugin > h1,h2,h3,h4 {
font-size: 1em;
}
div.plugin h2.plugin-label {
border-bottom: 1px solid #ebebeb;
padding-bottom: 5px;
text-transform: uppercase;
margin: 20px 0;
}
@ -43,6 +48,8 @@ div.plugin ul {
padding: 0;
}
/* PLUGIN MENU */
div.plugin-menu li.menu:not(:last-child) {
margin-bottom: 10px;
}
@ -50,3 +57,14 @@ div.plugin-menu li.menu:not(:last-child) {
div.plugin-menu ul.submenu {
margin-left: 10px;
}
/* PLUGIN PAGES */
div.plugin-pages li.parent h3 {
margin-bottom: 5px;
margin-top: 10px;
}
div.plugin-pages ul.child {
margin-left: 5px;
}

View File

@ -57,7 +57,7 @@ define('PATH_ABSTRACT', PATH_KERNEL.'abstract'.DS);
define('CHECK_SYMBOLIC_LINKS', TRUE);
// Filename for posts and pages
define('FILENAME', 'index.md');
define('FILENAME', 'index.txt');
// Domain and protocol
define('DOMAIN', $_SERVER['HTTP_HOST']);
@ -321,7 +321,7 @@ function install($adminPassword, $email, $timezone)
'description'=>$Language->get('About your site or yourself'),
'username'=>'admin',
'tags'=>array(),
'status'=>'published',
'status'=>'fixed',
'date'=>$currentDate,
'dateModified'=>'',
'allowComments'=>true,
@ -367,7 +367,7 @@ function install($adminPassword, $email, $timezone)
'language'=>$Language->getCurrentLocale(),
'locale'=>$Language->getCurrentLocale(),
'timezone'=>$timezone,
'theme'=>'editorial',
'theme'=>'kernel-panic',
'adminTheme'=>'default',
'homepage'=>'',
'itemsPerPage'=>6,
@ -497,11 +497,11 @@ function install($adminPassword, $email, $timezone)
);
// File for error page
$data = 'Title: '.$Language->get('Error').PHP_EOL.'Content: '.$Language->get('The page has not been found');
$data = 'Title: '.$Language->get('Error').PHP_EOL.'Content: '.PHP_EOL.$Language->get('installer-page-error-content');
file_put_contents(PATH_PAGES.'error'.DS.FILENAME, $data, LOCK_EX);
// File for about page
$data = 'Title: '.$Language->get('About').PHP_EOL.'Content: '.$Language->get('the-about-page-is-very-important').' '.$Language->get('change-this-pages-content-on-the-admin-panel');
$data = 'Title: '.$Language->get('About').PHP_EOL.'Content: '.PHP_EOL.$Language->get('installer-page-about-content');
file_put_contents(PATH_PAGES.'about'.DS.FILENAME, $data, LOCK_EX);
// File for welcome page