Skip to content

Commit

Permalink
Merge pull request #2 from bludit/master
Browse files Browse the repository at this point in the history
Pull request
  • Loading branch information
clickwork-git committed Oct 23, 2017
2 parents dd9a14b + 247e229 commit 83747f5
Show file tree
Hide file tree
Showing 25 changed files with 171 additions and 671 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
bl-content/*
bl-plugins/timemachine
bl-plugins/remote-content
bl-kernel/bludit.pro.php
bl-kernel/bludit.pro.php
bl-themes/docs
4 changes: 2 additions & 2 deletions bl-kernel/admin/controllers/settings-advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
// ============================================================================
// Main after POST
// ============================================================================
$allPublishedPages = buildAllpages(true);
$allPages = buildAllpages($publishedPages=true, $staticPages=true, $draftPages=false, $scheduledPages=false);

// Homepage select options
$homepageOptions = array(' '=>'- '.$L->g('Latest content').' -');
foreach($allPublishedPages as $key=>$page) {
foreach ($allPages as $key=>$page) {
$parentKey = $page->parentKey();
if ($parentKey) {
$homepageOptions[$key] = $pagesByParentByKey[PARENT][$parentKey]->title() .'->'. $page->title();
Expand Down
6 changes: 3 additions & 3 deletions bl-kernel/admin/views/edit-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@

// Parent input
// Check if the page has children
if(count($page->children())==0) {
if (count($page->children())==0) {
$options = array(' '=>'- '.$L->g('No parent').' -');
$parentsList = $dbPages->getParents();
$parentsKey = array_keys($parentsList);
Expand All @@ -180,9 +180,9 @@
'selected'=>$page->parentKey(),
'tip'=>''
));
}

echo '<hr>';
echo '<hr>';
}

// Position input
HTML::formInputText(array(
Expand Down
1 change: 0 additions & 1 deletion bl-kernel/boot/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@
include(PATH_KERNEL.'url.class.php');
include(PATH_KERNEL.'login.class.php');
include(PATH_KERNEL.'parsedown.class.php');
include(PATH_KERNEL.'parsedownextra.class.php');
include(PATH_KERNEL.'security.class.php');

// Include functions
Expand Down
12 changes: 11 additions & 1 deletion bl-kernel/boot/rules/69.pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@
*/
$pagesByParentByKey = array(PARENT=>array());

// Array with static content, each item is a Page Object
// Order by position
/*
array(
0 => Page Object,
1 => Page Object,
...
N => Page Object
)
*/
$staticContent = $staticPages = buildStaticPages();

// ============================================================================
Expand All @@ -90,7 +100,7 @@
}

// Generate pages parent tree, only published pages
buildPagesByParent(true);
buildPagesByParent(true, true);

// Set home page is the user defined one
if ($Site->homepage() && $Url->whereAmI()==='home') {
Expand Down
7 changes: 3 additions & 4 deletions bl-kernel/boot/site.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
Theme::plugins('beforeSiteLoad');

// Theme init.php
if( Sanitize::pathFile(PATH_THEMES, $Site->theme().DS.'init.php') ) {
if (Sanitize::pathFile(PATH_THEMES, $Site->theme().DS.'init.php')) {
include(PATH_THEMES.$Site->theme().DS.'init.php');
}

// Theme HTML
if( Sanitize::pathFile(PATH_THEMES, $Site->theme().DS.'index.php') ) {
if (Sanitize::pathFile(PATH_THEMES, $Site->theme().DS.'index.php')) {
include(PATH_THEMES.$Site->theme().DS.'index.php');
}
else {
} else {
$Language->p('Please check your theme configuration');
}

Expand Down
21 changes: 15 additions & 6 deletions bl-kernel/dbpages.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,17 @@ public function setField($key, $field, $value)
}

// Returns a database with published pages
public function getPublishedDB()
public function getPublishedDB($onlyKeys=false)
{
$tmp = $this->db;
foreach ($tmp as $key=>$fields) {
if ($fields['status']!='published') {
unset($tmp[$key]);
}
}
if ($onlyKeys) {
return array_keys($tmp);
}
return $tmp;
}

Expand All @@ -293,26 +296,32 @@ public function getStaticDB($onlyKeys=false)
}

// Returns an array with a list of keys/database of draft pages
public function getDraftDB()
public function getDraftDB($onlyKeys=false)
{
$tmp = $this->db;
foreach ($tmp as $key=>$fields) {
if($fields['status']!='draft') {
unset($tmp[$key]);
}
}
if ($onlyKeys) {
return array_keys($tmp);
}
return $tmp;
}

// Returns an array with a list of keys/database of scheduled pages
public function getScheduledDB()
public function getScheduledDB($onlyKeys=false)
{
$tmp = $this->db;
foreach($tmp as $key=>$fields) {
if($fields['status']!='scheduled') {
unset($tmp[$key]);
}
}
if ($onlyKeys) {
return array_keys($tmp);
}
return $tmp;
}

Expand Down Expand Up @@ -386,10 +395,10 @@ public function count($onlyPublished=true)
// Returns an array with all parents pages key, a parent page is not a child
public function getParents()
{
$db = $this->getPublishedDB();
foreach($db as $key=>$fields) {
$db = $this->getPublishedDB() + $this->getStaticDB();
foreach ($db as $key=>$fields) {
// if the key has slash then is a child
if( Text::stringContains($key, '/') ) {
if (Text::stringContains($key, '/')) {
unset($db[$key]);
}
}
Expand Down
48 changes: 30 additions & 18 deletions bl-kernel/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,28 +168,30 @@ 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($onlyPublished=true) {
function buildPagesByParent($publishedPages=true, $staticPages=true) {
global $dbPages;
global $pagesByParent;
global $pagesByParentByKey;

// Get DB
$pageNumber = 1;
$amountOfItems = -1;
$db = $dbPages->getList($pageNumber, $amountOfItems, $onlyPublished);
$onlyKeys = true;
$keys = array();
if ($publishedPages) {
$keys = array_merge($keys, $dbPages->getPublishedDB($onlyKeys));
}
if ($staticPages) {
$keys = array_merge($keys, $dbPages->getStaticDB($onlyKeys));
}

// Get Keys
$keys = array_keys($db);
foreach($keys as $pageKey) {
foreach ($keys as $pageKey) {
$page = buildPage($pageKey);
if($page!==false) {
if ($page!==false) {
$parentKey = $page->parentKey();
// FALSE if the page is parent
if($parentKey===false) {
if ($parentKey===false) {
array_push($pagesByParent[PARENT], $page);
$pagesByParentByKey[PARENT][$page->key()] = $page;
} else {
if( !isset($pagesByParent[$parentKey]) ) {
if (!isset($pagesByParent[$parentKey])) {
$pagesByParent[$parentKey] = array();
}
array_push($pagesByParent[$parentKey], $page);
Expand Down Expand Up @@ -221,19 +223,29 @@ function buildStaticPages() {
pageKeyN => Page object,
)
*/
function buildAllpages($onlyPublished=true) {
function buildAllpages($publishedPages=true, $staticPages=true, $draftPages=true, $scheduledPages=true) {
global $dbPages;

// Get DB
$pageNumber = 1;
$amountOfItems = -1;
$db = $dbPages->getList($pageNumber, $amountOfItems, $onlyPublished);
$onlyKeys = true;
$keys = array();
if ($publishedPages) {
$keys = array_merge($keys, $dbPages->getPublishedDB($onlyKeys));
}
if ($staticPages) {
$keys = array_merge($keys, $dbPages->getStaticDB($onlyKeys));
}
if ($draftPages) {
$keys = array_merge($keys, $dbPages->getDraftDB($onlyKeys));
}
if ($scheduledPages) {
$keys = array_merge($keys, $dbPages->getScheduledDB($onlyKeys));
}

$tmp = array();
$keys = array_keys($db);
foreach($keys as $pageKey) {
foreach ($keys as $pageKey) {
$page = buildPage($pageKey);
if($page!==false) {
if ($page!==false) {
$tmp[$page->key()] = $page;
}
}
Expand Down
2 changes: 2 additions & 0 deletions bl-kernel/helpers/dom.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class DOM {

public static function getFirstImage($content)
{
// Disable warning
libxml_use_internal_errors(true);
$dom = new DOMDocument();
$dom->loadHTML('<meta http-equiv="content-type" content="text/html; charset=utf-8">'.$content);
$finder = new DomXPath($dom);
Expand Down

0 comments on commit 83747f5

Please sign in to comment.