diff --git a/bl-kernel/abstract/dblist.class.php b/bl-kernel/abstract/dblist.class.php index 9dd9d3a6..b1d04c01 100644 --- a/bl-kernel/abstract/dblist.class.php +++ b/bl-kernel/abstract/dblist.class.php @@ -135,4 +135,15 @@ class dbList extends dbJSON return isset( $this->db[$key] ); } + // Returns an array with a portion of the database filtered by key + // Returns array( 'name'=>'', 'list'=>array() ) + public function getMap($key) + { + if( isset($this->db[$key]) ) { + return $this->db[$key]; + } + + return false; + } + } \ No newline at end of file diff --git a/bl-kernel/admin/controllers/edit-page.php b/bl-kernel/admin/controllers/edit-page.php index 56fd16a8..95544ba9 100644 --- a/bl-kernel/admin/controllers/edit-page.php +++ b/bl-kernel/admin/controllers/edit-page.php @@ -81,10 +81,9 @@ if( $_SERVER['REQUEST_METHOD'] == 'POST' ) // Main after POST // ============================================================================ -if(!$dbPages->pageExists($layout['parameters'])) -{ +if( !$dbPages->exists($layout['parameters']) ) { Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to get the page: '.$layout['parameters']); - Redirect::page('admin', 'manage-pages'); + Redirect::page('pages'); } -$_Page = $pages[$layout['parameters']]; +$page = $pagesKey[$layout['parameters']]; diff --git a/bl-kernel/admin/controllers/settings-advanced.php b/bl-kernel/admin/controllers/settings-advanced.php index 949ee783..df5c332f 100644 --- a/bl-kernel/admin/controllers/settings-advanced.php +++ b/bl-kernel/admin/controllers/settings-advanced.php @@ -58,21 +58,4 @@ if( $_SERVER['REQUEST_METHOD'] == 'POST' ) // Main after POST // ============================================================================ -// Default home page -$_homePageList = array(''=>$Language->g('Show blog')); -foreach($pagesParents as $parentKey=>$pageList) -{ - foreach($pageList as $Page) - { - if($parentKey!==NO_PARENT_CHAR) { - $parentTitle = $pages[$Page->parentKey()]->title().'->'; - } - else { - $parentTitle = ''; - } - if($Page->published()) { - $_homePageList[$Page->key()] = $Language->g('Page').': '.$parentTitle.$Page->title(); - } - } -} diff --git a/bl-kernel/admin/themes/default/init.php b/bl-kernel/admin/themes/default/init.php index c32dca33..4cfef8df 100644 --- a/bl-kernel/admin/themes/default/init.php +++ b/bl-kernel/admin/themes/default/init.php @@ -70,6 +70,32 @@ class HTML { echo $html; } + // label, name, value, tip + public static function formInputRadio($args) + { + $id = 'js'.$args['name']; + $type = isset($args['type']) ? $args['type'] : 'text'; + $class = empty($args['class']) ? '' : 'class="'.$args['class'].'"'; + $placeholder = empty($args['placeholder']) ? '' : 'placeholder="'.$args['placeholder'].'"'; + $disabled = empty($args['disabled']) ? '' : 'disabled'; + + $html = '
'; + + $html .= '
'; + $html .= ''; + + if(!empty($args['tip'])) { + $html .= '

'.$args['tip'].'

'; + } + + $html .= '
'; + $html .= '
'; + + echo $html; + } + public static function tags($args) { global $L; diff --git a/bl-kernel/admin/views/edit-page.php b/bl-kernel/admin/views/edit-page.php index 4413174a..6c45f6cb 100644 --- a/bl-kernel/admin/views/edit-page.php +++ b/bl-kernel/admin/views/edit-page.php @@ -13,7 +13,7 @@ HTML::formOpen(array('class'=>'uk-form-stacked')); // Key input HTML::formInputHidden(array( 'name'=>'key', - 'value'=>$_Page->key() + 'value'=>$page->key() )); // LEFT SIDE @@ -24,7 +24,7 @@ echo '
'; // Title input HTML::formInputText(array( 'name'=>'title', - 'value'=>$_Page->title(), + 'value'=>$page->title(), 'class'=>'uk-width-1-1 uk-form-large', 'placeholder'=>$L->g('Title') )); @@ -32,7 +32,7 @@ echo '
'; // Content input HTML::formTextarea(array( 'name'=>'content', - 'value'=>$_Page->contentRaw(false), + 'value'=>$page->contentRaw(false), 'class'=>'uk-width-1-1 uk-form-large', 'placeholder'=>'' )); @@ -44,7 +44,7 @@ echo '
'; '; -if(count($_Page->children())===0) +if(count($page->children())===0) { echo ' '; echo ' '.$L->g('Cancel').''; @@ -66,22 +66,21 @@ echo '
'; echo ''; @@ -135,25 +134,34 @@ echo '
'; 'label'=>$L->g('Status'), 'class'=>'uk-width-1-1 uk-form-medium', 'options'=>array('published'=>$L->g('Published'), 'draft'=>$L->g('Draft')), - 'selected'=>($_Page->draft()?'draft':'published'), + 'selected'=>($page->draft()?'draft':'published'), 'tip'=>'' )); + // Date input + HTML::formInputText(array( + 'name'=>'date', + 'value'=>$page->dateRaw(), + 'class'=>'uk-width-1-1 uk-form-medium', + 'tip'=>$L->g('To schedule the post just select the date and time'), + 'label'=>$L->g('Date') + )); + // If the page is parent then doesn't can have a parent. -if(count($_Page->children())===0) +if(count($page->children())===0) { // Parent input $options = array(); $options[NO_PARENT_CHAR] = '('.$Language->g('No parent').')'; $options += $dbPages->parentKeyList(); - unset($options[$_Page->key()]); + unset($options[$page->key()]); HTML::formSelect(array( 'name'=>'parent', 'label'=>$L->g('Parent'), 'class'=>'uk-width-1-1 uk-form-medium', 'options'=>$options, - 'selected'=>$_Page->parentKey(), + 'selected'=>$page->parentKey(), 'tip'=>'' )); } @@ -161,16 +169,16 @@ if(count($_Page->children())===0) // Position input HTML::formInputText(array( 'name'=>'position', - 'value'=>$_Page->position(), - 'class'=>'uk-width-1-1 uk-form-large', + 'value'=>$page->position(), + 'class'=>'uk-width-1-1 uk-form-medium', 'label'=>$L->g('Position') )); // Slug input HTML::formInputText(array( 'name'=>'slug', - 'value'=>$_Page->slug(), - 'class'=>'uk-width-1-1 uk-form-large', + 'value'=>$page->slug(), + 'class'=>'uk-width-1-1 uk-form-medium', 'tip'=>$L->g('you-can-modify-the-url-which-identifies'), 'label'=>$L->g('Friendly URL') )); @@ -191,6 +199,8 @@ $(document).ready(function() { var key = $("#jskey").val(); + $("#jsdate").datetimepicker({format:""}); + $("#jsslug").keyup(function() { var text = $(this).val(); var parent = $("#jsparent").val(); diff --git a/bl-kernel/admin/views/new-page.php b/bl-kernel/admin/views/new-page.php index 39b5475b..8d35bfc9 100644 --- a/bl-kernel/admin/views/new-page.php +++ b/bl-kernel/admin/views/new-page.php @@ -127,7 +127,7 @@ echo '
'; HTML::formInputText(array( 'name'=>'date', 'value'=>Date::current(DB_DATE_FORMAT), - 'class'=>'uk-width-1-1 uk-form-large', + 'class'=>'uk-width-1-1 uk-form-medium', 'tip'=>$L->g('To schedule the post just select the date and time'), 'label'=>$L->g('Date') )); @@ -153,7 +153,7 @@ echo '
'; HTML::formInputText(array( 'name'=>'position', 'value'=>'1', - 'class'=>'uk-width-1-1 uk-form-large', + 'class'=>'uk-width-1-1 uk-form-medium', 'label'=>$L->g('Position') )); @@ -161,7 +161,7 @@ echo '
'; HTML::formInputText(array( 'name'=>'slug', 'value'=>'', - 'class'=>'uk-width-1-1 uk-form-large', + 'class'=>'uk-width-1-1 uk-form-medium', 'tip'=>$L->g('you-can-modify-the-url-which-identifies'), 'label'=>$L->g('Friendly URL') )); diff --git a/bl-kernel/admin/views/settings-advanced.php b/bl-kernel/admin/views/settings-advanced.php index 2252a180..7b2dffe6 100644 --- a/bl-kernel/admin/views/settings-advanced.php +++ b/bl-kernel/admin/views/settings-advanced.php @@ -12,23 +12,14 @@ HTML::formOpen(array('class'=>'uk-form-horizontal')); HTML::legend(array('value'=>$L->g('General'), 'class'=>'first-child')); HTML::formSelect(array( - 'name'=>'postsperpage', - 'label'=>$L->g('Posts per page'), + 'name'=>'itemsPerPage', + 'label'=>$L->g('Items per page'), 'options'=>array('1'=>'1','2'=>'2','3'=>'3','4'=>'4','5'=>'5','6'=>'6','7'=>'7','8'=>'8'), - 'selected'=>$Site->postsPerPage(), + 'selected'=>$Site->itemsPerPage(), 'class'=>'uk-width-1-3 uk-form-medium', 'tip'=>$L->g('number-of-posts-to-show-per-page') )); - HTML::formSelect(array( - 'name'=>'homepage', - 'label'=>$L->g('Default home page'), - 'options'=>$_homePageList, - 'selected'=>$Site->homepage(), - 'class'=>'uk-width-1-3 uk-form-medium', - 'tip'=>'' - )); - HTML::formInputText(array( 'name'=>'url', 'label'=>$L->g('Site URL'), @@ -37,6 +28,25 @@ HTML::formOpen(array('class'=>'uk-form-horizontal')); 'tip'=>$L->g('the-url-of-your-site') )); + HTML::legend(array('value'=>$L->g('Website or Blog'))); + + HTML::formInputRadio(array( + 'name'=>'orderBy', + 'type'=>'radio', + 'label'=>$L->g('Website'), + 'value'=>'position', + 'class'=>'', + 'tip'=>'Select this option if you want to order your pages by position.' + )); + + HTML::formInputRadio(array( + 'name'=>'orderBy', + 'type'=>'radio', + 'label'=>$L->g('Blog'), + 'value'=>'date', + 'class'=>'' + )); + HTML::legend(array('value'=>$L->g('Email account settings'))); HTML::formInputText(array( @@ -49,14 +59,6 @@ HTML::formOpen(array('class'=>'uk-form-horizontal')); HTML::legend(array('value'=>$L->g('URL Filters'))); - HTML::formInputText(array( - 'name'=>'uriPost', - 'label'=>$L->g('Posts'), - 'value'=>$Site->uriFilters('post'), - 'class'=>'uk-width-1-2 uk-form-medium', - 'tip'=>'' - )); - HTML::formInputText(array( 'name'=>'uriPage', 'label'=>$L->g('Pages'), @@ -73,15 +75,6 @@ HTML::formOpen(array('class'=>'uk-form-horizontal')); 'tip'=>'' )); - HTML::formInputText(array( - 'name'=>'uriBlog', - 'label'=>$L->g('Blog'), - 'value'=>$Site->uriFilters('blog'), - 'class'=>'uk-width-1-2 uk-form-medium', - 'tip'=>'' - )); - -/* HTML::formInputText(array( 'name'=>'uriCategory', 'label'=>$L->g('Category'), @@ -89,7 +82,7 @@ HTML::formOpen(array('class'=>'uk-form-horizontal')); 'class'=>'uk-width-1-2 uk-form-medium', 'tip'=>'' )); -*/ + echo '
diff --git a/bl-kernel/boot/init.php b/bl-kernel/boot/init.php index 510cd33b..5123d763 100644 --- a/bl-kernel/boot/init.php +++ b/bl-kernel/boot/init.php @@ -271,6 +271,9 @@ $Url->checkFilters( $Site->uriFilters() ); // --- Objects shortcuts --- $L = $Language; +// --- CONSTANTS with dependency --- +define('ORDER_BY', $Site->orderBy()); + // DEBUG: Print constants // $arr = array_filter(get_defined_constants(), 'is_string'); // echo json_encode($arr); diff --git a/bl-kernel/dbpages.class.php b/bl-kernel/dbpages.class.php index 6fd83885..e4bd61cb 100644 --- a/bl-kernel/dbpages.class.php +++ b/bl-kernel/dbpages.class.php @@ -214,7 +214,7 @@ class dbPages extends dbJSON public function delete($key) { // Page doesn't exist in database - if(!$this->pageExists($key)) { + if(!$this->exists($key)) { Log::set(__METHOD__.LOG_SEP.'The page does not exist. Key: '.$key); } @@ -254,7 +254,7 @@ class dbPages extends dbJSON // Return an array with the database for a page, FALSE otherwise. public function getPageDB($key) { - if( $this->pageExists($key) ) { + if( $this->exists($key) ) { return $this->db[$key]; } @@ -316,6 +316,12 @@ class dbPages extends dbJSON return $db; } + // Return TRUE if the page exists, FALSE otherwise. + public function exists($key) + { + return isset( $this->db[$key] ); + } + // Sort pages by date public function sortByDate($HighToLow=true) { @@ -340,7 +346,7 @@ class dbPages extends dbJSON // Set a field of the database public function setField($key, $field, $value) { - if( $this->pageExists($key) ) { + if( $this->exists($key) ) { settype($value, gettype($this->dbFields[$key]['value'])); $this->db[$key][$field] = $value; } @@ -348,11 +354,7 @@ class dbPages extends dbJSON return false; } - // Return TRUE if the page exists, FALSE otherwise. - public function pageExists($key) - { - return isset($this->db[$key]); - } + public function parentKeyList() { diff --git a/bl-kernel/dbsite.class.php b/bl-kernel/dbsite.class.php index bac58a6d..4909fc32 100644 --- a/bl-kernel/dbsite.class.php +++ b/bl-kernel/dbsite.class.php @@ -26,7 +26,8 @@ class dbSite extends dbJSON 'facebook'=> array('inFile'=>false, 'value'=>''), 'googlePlus'=> array('inFile'=>false, 'value'=>''), 'instagram'=> array('inFile'=>false, 'value'=>''), - 'github'=> array('inFile'=>false, 'value'=>'') + 'github'=> array('inFile'=>false, 'value'=>''), + 'orderBy'=> array('inFile'=>false, 'value'=>'date') // date or position ); function __construct() @@ -123,6 +124,11 @@ class dbSite extends dbJSON return $this->getField('googlePlus'); } + public function orderBy() + { + return $this->getField('orderBy'); + } + // Returns the site title public function title() { diff --git a/bl-kernel/functions.php b/bl-kernel/functions.php index 6a3a0411..e1248b9e 100644 --- a/bl-kernel/functions.php +++ b/bl-kernel/functions.php @@ -4,6 +4,7 @@ function buildPage($key) { global $dbPages; global $dbUsers; + global $dbCategories; global $Parsedown; global $Site; @@ -49,6 +50,10 @@ function buildPage($key) $username = $page->username(); $page->setField('user', $dbUsers->getUser($username)); + // Category + $categoryKey = $page->categoryKey(); + $page->setField('categoryMap', $dbCategories->getMap($categoryKey)); + return $page; } diff --git a/bl-kernel/page.class.php b/bl-kernel/page.class.php index 7929a37b..4fb95de6 100644 --- a/bl-kernel/page.class.php +++ b/bl-kernel/page.class.php @@ -177,7 +177,30 @@ class Page { return '/'.$htmlPath.'/'.$tmp; } -// ---- OLD + // Returns the category key + public function categoryKey() + { + return $this->getField('category'); + } + + // Returns the field from the array + // categoryMap = array( 'name'=>'', 'list'=>array() ) + public function categoryMap($field) + { + $map = $this->getField('categoryMap'); + + if($field=='key') { + return $this->categoryKey(); + } + elseif($field=='name') { + return $map['name']; + } + elseif($field=='list') { + return $map['list']; + } + + return false; + } // Returns the user object // (boolean) $field, TRUE returns the value of the field, FALSE returns the object @@ -250,23 +273,18 @@ class Page { // (boolean) $returnsArray, TRUE to get the tags as an array, FALSE to get the tags separeted by comma public function tags($returnsArray=false) { - global $Url; - $tags = $this->getField('tags'); if($returnsArray) { - if($tags==false) { return array(); } - return $tags; } else { if($tags==false) { return false; } - // Return string with tags separeted by comma. return implode(', ', $tags); } @@ -314,12 +332,6 @@ class Page { return $this->getField('readMore'); } - // - public function category() - { - return $this->getField('category'); - } - public function uuid() { return $this->getField('uuid');