From cb0ddf9069696629707e8db6ae32c05dd68ffd9c Mon Sep 17 00:00:00 2001 From: Diego Najar Date: Sat, 15 Jul 2017 15:47:37 +0200 Subject: [PATCH] Fixed installer, kernel panic theme, fixed content pages --- .../admin/controllers/settings-advanced.php | 2 +- bl-kernel/boot/init.php | 2 +- bl-kernel/boot/rules/69.pages.php | 2 +- bl-kernel/dbpages.class.php | 44 ++++++++++++++----- bl-kernel/functions.php | 41 ++++++++++------- bl-kernel/page.class.php | 19 +++----- bl-languages/en_US.json | 8 +++- bl-plugins/sitemap/plugin.php | 9 ++-- bl-themes/kernel-panic/css/bludit.css | 20 ++++++++- install.php | 10 ++--- 10 files changed, 103 insertions(+), 54 deletions(-) diff --git a/bl-kernel/admin/controllers/settings-advanced.php b/bl-kernel/admin/controllers/settings-advanced.php index fdcd4cb0..5b614cbe 100644 --- a/bl-kernel/admin/controllers/settings-advanced.php +++ b/bl-kernel/admin/controllers/settings-advanced.php @@ -83,7 +83,7 @@ if( $_SERVER['REQUEST_METHOD'] == 'POST' ) // ============================================================================ // Main after POST // ============================================================================ -$allPublishedPages = buildAllpages(false); +$allPublishedPages = buildAllpages(true); // Homepage select options $homepageOptions = array(); diff --git a/bl-kernel/boot/init.php b/bl-kernel/boot/init.php index bfe56c75..02b06f15 100644 --- a/bl-kernel/boot/init.php +++ b/bl-kernel/boot/init.php @@ -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'); diff --git a/bl-kernel/boot/rules/69.pages.php b/bl-kernel/boot/rules/69.pages.php index d5037c71..0d81dc9b 100644 --- a/bl-kernel/boot/rules/69.pages.php +++ b/bl-kernel/boot/rules/69.pages.php @@ -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' ) { diff --git a/bl-kernel/dbpages.class.php b/bl-kernel/dbpages.class.php index cd27c139..0a32f375 100644 --- a/bl-kernel/dbpages.class.php +++ b/bl-kernel/dbpages.class.php @@ -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 ''; + } + } + + // Legacy style of Bludit with index.txt + if ($field==='content') { + return 'Content:'.PHP_EOL.$value; + } + return Text::firstCharUp($field).': '.$value; + } // ----- OLD diff --git a/bl-kernel/functions.php b/bl-kernel/functions.php index 65697f0b..a33efce4 100644 --- a/bl-kernel/functions.php +++ b/bl-kernel/functions.php @@ -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) { diff --git a/bl-kernel/page.class.php b/bl-kernel/page.class.php index 4b4cc461..9425e6c7 100644 --- a/bl-kernel/page.class.php +++ b/bl-kernel/page.class.php @@ -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; diff --git a/bl-languages/en_US.json b/bl-languages/en_US.json index 726e172c..cb02359d 100644 --- a/bl-languages/en_US.json +++ b/bl-languages/en_US.json @@ -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", diff --git a/bl-plugins/sitemap/plugin.php b/bl-plugins/sitemap/plugin.php index 5d6a7137..a8125901 100644 --- a/bl-plugins/sitemap/plugin.php +++ b/bl-plugins/sitemap/plugin.php @@ -14,11 +14,12 @@ class pluginSitemap extends Plugin { $xml .= ''.$Site->url().''; $xml .= ''; - // 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); diff --git a/bl-themes/kernel-panic/css/bludit.css b/bl-themes/kernel-panic/css/bludit.css index b6d84167..e37c8ba6 100755 --- a/bl-themes/kernel-panic/css/bludit.css +++ b/bl-themes/kernel-panic/css/bludit.css @@ -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,10 +48,23 @@ div.plugin ul { padding: 0; } +/* PLUGIN MENU */ + div.plugin-menu li.menu:not(:last-child) { margin-bottom: 10px; } 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; } \ No newline at end of file diff --git a/install.php b/install.php index 9d469be6..db022f71 100644 --- a/install.php +++ b/install.php @@ -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