From ab1d7952593267e5b3dd8bb73f196dceeaa78f16 Mon Sep 17 00:00:00 2001 From: Diego Najar Date: Sun, 22 Apr 2018 17:45:31 +0200 Subject: [PATCH] Changes on admin panel, move some files, renew html --- bl-kernel/abstract/dblist.class.php | 24 +- bl-kernel/admin/controllers/developers.php | 11 +- bl-kernel/admin/controllers/edit-category.php | 11 +- bl-kernel/admin/controllers/new-category.php | 5 +- bl-kernel/admin/themes/booty/html/topbar.php | 2 +- bl-kernel/admin/themes/booty/init.php | 57 +++- bl-kernel/admin/views/about.php | 55 ++-- bl-kernel/admin/views/categories.php | 2 +- bl-kernel/admin/views/developers.php | 4 +- bl-kernel/admin/views/edit-category.php | 55 ++-- bl-kernel/admin/views/new-category.php | 32 ++- bl-kernel/admin/views/settings-general.php | 112 -------- bl-kernel/admin/views/settings.php | 262 ++++++++++++++++++ bl-kernel/boot/init.php | 3 + bl-kernel/boot/variables.php | 3 - bl-kernel/dbpages.class.php | 8 +- bl-kernel/dbsite.class.php | 8 +- bl-kernel/functions.php | 95 ++++--- bl-kernel/helpers/text.class.php | 4 +- bl-kernel/page.class.php | 6 + 20 files changed, 506 insertions(+), 253 deletions(-) delete mode 100644 bl-kernel/admin/views/settings-general.php create mode 100644 bl-kernel/admin/views/settings.php diff --git a/bl-kernel/abstract/dblist.class.php b/bl-kernel/abstract/dblist.class.php index 26e9f3d5..133b158e 100644 --- a/bl-kernel/abstract/dblist.class.php +++ b/bl-kernel/abstract/dblist.class.php @@ -79,7 +79,7 @@ class dbList extends dbJSON } if (isset($this->db[$key])) { - Log::set(__METHOD__.LOG_SEP.'Error key already exist: '.$key); + Log::set(__METHOD__.LOG_SEP.'Error key already exists: '.$key); return false; } @@ -111,7 +111,27 @@ class dbList extends dbJSON $this->db[$newKey]['list'] = $this->db[$oldKey]['list']; // Remove the old key - if( $oldKey != $newKey ) { + if ($oldKey!=$newKey) { + unset( $this->db[$oldKey] ); + } + + $this->sortAlphanumeric(); + $this->save(); + return $newKey; + } + + public function changeKey($oldKey, $newKey) + { + if ($this->exists($newKey)) { + Log::set(__METHOD__.LOG_SEP.'Error key already exists: '.$newKey); + return false; + } + + $this->db[$newKey]['name'] = $this->db[$oldKey]['name']; + $this->db[$newKey]['list'] = $this->db[$oldKey]['list']; + + // Remove the old key + if ($oldKey!=$newKey) { unset( $this->db[$oldKey] ); } diff --git a/bl-kernel/admin/controllers/developers.php b/bl-kernel/admin/controllers/developers.php index e91d5851..8750639f 100644 --- a/bl-kernel/admin/controllers/developers.php +++ b/bl-kernel/admin/controllers/developers.php @@ -15,15 +15,8 @@ if ($Login->role()!=='admin') { // This function is used on the VIEW to show the tables function printTable($title, $array) { - echo '

'.$title.'

'; - echo ' - - - - - - - + echo '

'.$title.'

'; + echo '
'; diff --git a/bl-kernel/admin/controllers/edit-category.php b/bl-kernel/admin/controllers/edit-category.php index f93e541c..8675480f 100644 --- a/bl-kernel/admin/controllers/edit-category.php +++ b/bl-kernel/admin/controllers/edit-category.php @@ -23,10 +23,9 @@ if ($Login->role()!=='admin') { if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (isset($_POST['delete'])) { - deleteCategory($_POST['categoryKey']); - } - elseif (isset($_POST['edit'])) { - editCategory($_POST['categoryKey'], $_POST['category']); + deleteCategory($_POST); + } elseif (isset($_POST['edit'])) { + editCategory($_POST); } Redirect::page('categories'); @@ -42,7 +41,7 @@ if (!$dbCategories->exists($categoryKey)) { Redirect::page('categories'); } -$category = $dbCategories->getName($layout['parameters']); +$categoryName = $dbCategories->getName($layout['parameters']); // Title of the page -$layout['title'] .= ' - '.$Language->g('Edit Category').' - '.$category; \ No newline at end of file +$layout['title'] .= ' - '.$Language->g('Edit Category').' - '.$categoryName; \ No newline at end of file diff --git a/bl-kernel/admin/controllers/new-category.php b/bl-kernel/admin/controllers/new-category.php index b752efb5..6199222c 100644 --- a/bl-kernel/admin/controllers/new-category.php +++ b/bl-kernel/admin/controllers/new-category.php @@ -22,8 +22,9 @@ if ($Login->role()!=='admin') { // ============================================================================ if ($_SERVER['REQUEST_METHOD'] == 'POST') { - createCategory($_POST['category']); - Redirect::page('categories'); + if (createCategory($_POST['category'])) { + Redirect::page('categories'); + } } // ============================================================================ diff --git a/bl-kernel/admin/themes/booty/html/topbar.php b/bl-kernel/admin/themes/booty/html/topbar.php index 35cd83ab..b8ebbcf7 100644 --- a/bl-kernel/admin/themes/booty/html/topbar.php +++ b/bl-kernel/admin/themes/booty/html/topbar.php @@ -7,7 +7,7 @@ - Bludit + Bludit diff --git a/bl-kernel/admin/themes/booty/init.php b/bl-kernel/admin/themes/booty/init.php index d323bb33..4f4b1502 100644 --- a/bl-kernel/admin/themes/booty/init.php +++ b/bl-kernel/admin/themes/booty/init.php @@ -48,6 +48,34 @@ class Bootstrap { return '

'.$args['title'].'

'; } + public static function formOpen($args) + { + $class = empty($args['class']) ? '' : ' '.$args['class']; + $id = empty($args['id']) ? '' : ' id="'.$args['id'].'" '; + $enctype = empty($args['enctype']) ? '' : ' enctype="'.$args['enctype'].'" '; + + $html = ''; + return $html; + } + + public static function formClose() + { + $html = ''; + + $script = ''; + + return $html.$script; + } + public static function formTitle($args) { return '

'.$args['title'].'

'; @@ -71,7 +99,7 @@ class Bootstrap { $html .= ''; } - $html .= ''; + $html .= ''; if (isset($args['tip'])) { $html .= ''.$args['tip'].''; @@ -131,6 +159,33 @@ class Bootstrap { return $html; } + public static function formInputGroupText($args) + { + $label = $args['label']; + $labelInside = $args['labelInside']; + $tip = $args['tip']; + $value = $args['value']; + $name = $args['name']; + $id = 'js'.$name; + if (isset($args['id'])) { + $id = $args['id']; + } + $disabled = isset($args['disabled'])?'disabled':''; + +return << + +
+
+ $labelInside +
+ +
+ $tip + +EOF; + } + public static function formInputText($args) { $id = 'js'.$args['name']; diff --git a/bl-kernel/admin/views/about.php b/bl-kernel/admin/views/about.php index 130915cb..b728f7d1 100644 --- a/bl-kernel/admin/views/about.php +++ b/bl-kernel/admin/views/about.php @@ -1,42 +1,37 @@ $L->g('About'), 'icon'=>'support')); +echo Bootstrap::pageTitle(array('title'=>$L->g('About'), 'icon'=>'person')); echo ' -
- - - - - - - +
+ '; - echo ''; - echo ''; - if (defined('BLUDIT_PRO')) { - echo ''; - } else { - echo ''; - } - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; +echo ''; +echo ''; +if (defined('BLUDIT_PRO')) { + echo ''; +} else { + echo ''; +} +echo ''; - echo ''; - echo ''; - echo ''; - echo ''; +echo ''; +echo ''; +echo ''; +echo ''; - echo ''; - echo ''; - echo ''; - echo ''; +echo ''; +echo ''; +echo ''; +echo ''; + +echo ''; +echo ''; +echo ''; +echo ''; echo ' - +
Bludit EditionPRO - '.$L->g('Thanks for support Bludit').'Standard - '.$L->g('Upgrade to Bludit PRO').'
Bludit Version'.BLUDIT_VERSION.'
Bludit EditionPRO - '.$L->g('Thanks for support Bludit').'Standard - '.$L->g('Upgrade to Bludit PRO').'
Bludit Codename'.BLUDIT_CODENAME.'
Bludit Version'.BLUDIT_VERSION.'
Bludit Build Number'.BLUDIT_BUILD.'
Bludit Codename'.BLUDIT_CODENAME.'
Bludit Build Number'.BLUDIT_BUILD.'
'; diff --git a/bl-kernel/admin/views/categories.php b/bl-kernel/admin/views/categories.php index 2c262235..3c85278a 100644 --- a/bl-kernel/admin/views/categories.php +++ b/bl-kernel/admin/views/categories.php @@ -1,4 +1,4 @@ -$L->g('Categories'), 'icon'=>'grid-three-up')); diff --git a/bl-kernel/admin/views/developers.php b/bl-kernel/admin/views/developers.php index 68de5e16..b11f7d83 100644 --- a/bl-kernel/admin/views/developers.php +++ b/bl-kernel/admin/views/developers.php @@ -1,8 +1,8 @@ $L->g('Developers'), 'icon'=>'support')); +echo Bootstrap::pageTitle(array('title'=>$L->g('Developers'), 'icon'=>'beaker')); -echo '

PHP version: '.phpversion().'

'; +echo '

PHP version: '.phpversion().'

'; // PHP Ini $uploadOptions = array( diff --git a/bl-kernel/admin/views/edit-category.php b/bl-kernel/admin/views/edit-category.php index 70f660c9..e8c669f5 100644 --- a/bl-kernel/admin/views/edit-category.php +++ b/bl-kernel/admin/views/edit-category.php @@ -1,32 +1,49 @@ -$L->g('Edit Category'), 'icon'=>'globe')); +echo Bootstrap::pageTitle(array('title'=>$L->g('Edit Category'), 'icon'=>'grid-three-up')); -HTML::formOpen(array('class'=>'uk-form-horizontal')); +echo Bootstrap::formOpen(array()); - HTML::formInputHidden(array( + echo Bootstrap::formInputHidden(array( 'name'=>'tokenCSRF', 'value'=>$Security->getTokenCSRF() )); - HTML::formInputHidden(array( - 'name'=>'categoryKey', + echo Bootstrap::formInputHidden(array( + 'name'=>'oldCategoryName', + 'value'=>$categoryName + )); + + echo Bootstrap::formInputHidden(array( + 'name'=>'oldCategoryKey', 'value'=>$categoryKey )); - HTML::formInputText(array( - 'name'=>'category', - 'label'=>$L->g('Name'), - 'value'=>$category, - 'class'=>'uk-width-1-2 uk-form-medium' + echo Bootstrap::formInputTextBlock(array( + 'name'=>'categoryName', + 'label'=>$L->g('Category name'), + 'value'=>$categoryName, + 'class'=>'', + 'placeholder'=>'', + 'tip'=>'' )); - echo '
-
- - - '.$L->g('Cancel').' -
-
'; + echo Bootstrap::formInputGroupText(array( + 'name'=>'categoryKey', + 'label'=>$L->g('Category key'), + 'labelInside'=>DOMAIN_CATEGORIES, + 'value'=>$categoryKey, + 'class'=>'', + 'placeholder'=>'', + 'tip'=>'' + )); -HTML::formClose(); + echo ' +
+ + + '.$L->g('Cancel').' +
+ '; + +echo Bootstrap::formClose(); diff --git a/bl-kernel/admin/views/new-category.php b/bl-kernel/admin/views/new-category.php index 2e917f77..eea927df 100644 --- a/bl-kernel/admin/views/new-category.php +++ b/bl-kernel/admin/views/new-category.php @@ -1,26 +1,28 @@ -$L->g('New Category'), 'icon'=>'tag')); +echo Bootstrap::pageTitle(array('title'=>$L->g('New Category'), 'icon'=>'grid-three-up')); -HTML::formOpen(array('class'=>'uk-form-horizontal')); +echo Bootstrap::formOpen(array()); - HTML::formInputHidden(array( + echo Bootstrap::formInputHidden(array( 'name'=>'tokenCSRF', 'value'=>$Security->getTokenCSRF() )); - HTML::formInputText(array( + echo Bootstrap::formInputTextBlock(array( 'name'=>'category', - 'label'=>$L->g('Name'), - 'value'=>'', - 'class'=>'uk-width-1-2 uk-form-medium' + 'label'=>$L->g('Category name'), + 'value'=>isset($_POST['category'])?$_POST['category']:'', + 'class'=>'', + 'placeholder'=>'', + 'tip'=>'' )); - echo '
-
- - '.$L->g('Cancel').' -
-
'; + echo ' +
+ + Cancel +
+ '; -HTML::formClose(); \ No newline at end of file +echo Bootstrap::formClose(); diff --git a/bl-kernel/admin/views/settings-general.php b/bl-kernel/admin/views/settings-general.php deleted file mode 100644 index 075542e4..00000000 --- a/bl-kernel/admin/views/settings-general.php +++ /dev/null @@ -1,112 +0,0 @@ -$L->g('General settings'), 'icon'=>'cogs')); - -HTML::formOpen(array('class'=>'uk-form-horizontal')); - - // Security token - HTML::formInputHidden(array( - 'name'=>'tokenCSRF', - 'value'=>$Security->getTokenCSRF() - )); - - HTML::legend(array('value'=>$L->g('Site information'), 'class'=>'first-child')); - - HTML::formInputText(array( - 'name'=>'title', - 'label'=>$L->g('Site title'), - 'value'=>$Site->title(), - 'class'=>'uk-width-1-2 uk-form-medium', - 'tip'=>$L->g('use-this-field-to-name-your-site') - )); - - HTML::formInputText(array( - 'name'=>'slogan', - 'label'=>$L->g('Site slogan'), - 'value'=>$Site->slogan(), - 'class'=>'uk-width-1-2 uk-form-medium', - 'tip'=>$L->g('use-this-field-to-add-a-catchy-phrase') - )); - - HTML::formInputText(array( - 'name'=>'description', - 'label'=>$L->g('Site description'), - 'value'=>$Site->description(), - 'class'=>'uk-width-1-2 uk-form-medium', - 'tip'=>$L->g('you-can-add-a-site-description-to-provide') - )); - - HTML::formInputText(array( - 'name'=>'footer', - 'label'=>$L->g('Footer text'), - 'value'=>$Site->footer(), - 'class'=>'uk-width-1-2 uk-form-medium', - 'tip'=>$L->g('you-can-add-a-small-text-on-the-bottom') - )); - - HTML::legend(array('value'=>$L->g('Social networks links'))); - - HTML::formInputText(array( - 'name'=>'twitter', - 'label'=>'Twitter', - 'value'=>$Site->twitter(), - 'class'=>'uk-width-1-2 uk-form-medium', - 'tip'=>'' - )); - - HTML::formInputText(array( - 'name'=>'facebook', - 'label'=>'Facebook', - 'value'=>$Site->facebook(), - 'class'=>'uk-width-1-2 uk-form-medium', - 'tip'=>'' - )); - - HTML::formInputText(array( - 'name'=>'codepen', - 'label'=>'Codepen', - 'value'=>$Site->codepen(), - 'class'=>'uk-width-1-2 uk-form-medium', - 'tip'=>'' - )); - - HTML::formInputText(array( - 'name'=>'googlePlus', - 'label'=>'Google+', - 'value'=>$Site->googlePlus(), - 'class'=>'uk-width-1-2 uk-form-medium', - 'tip'=>'' - )); - - HTML::formInputText(array( - 'name'=>'instagram', - 'label'=>'Instagram', - 'value'=>$Site->instagram(), - 'class'=>'uk-width-1-2 uk-form-medium', - 'tip'=>'' - )); - - HTML::formInputText(array( - 'name'=>'github', - 'label'=>'Github', - 'value'=>$Site->github(), - 'class'=>'uk-width-1-2 uk-form-medium', - 'tip'=>'' - )); - - HTML::formInputText(array( - 'name'=>'linkedin', - 'label'=>'Linkedin', - 'value'=>$Site->linkedin(), - 'class'=>'uk-width-1-2 uk-form-medium', - 'tip'=>'' - )); - - echo '
-
- - '.$L->g('Cancel').' -
-
'; - -HTML::formClose(); \ No newline at end of file diff --git a/bl-kernel/admin/views/settings.php b/bl-kernel/admin/views/settings.php new file mode 100644 index 00000000..351b1fae --- /dev/null +++ b/bl-kernel/admin/views/settings.php @@ -0,0 +1,262 @@ +$L->g('Settings'), 'icon'=>'cog')); + +?> + + + +
+ + 'tokenCSRF', + 'value'=>$Security->getTokenCSRF() + )); + ?> + + +
+ 'title', + 'label'=>$L->g('Site title'), + 'value'=>$Site->title(), + 'class'=>'', + 'placeholder'=>'', + 'tip'=>$L->g('use-this-field-to-name-your-site') + )); + + echo Bootstrap::formInputText(array( + 'name'=>'slogan', + 'label'=>$L->g('Site slogan'), + 'value'=>$Site->slogan(), + 'class'=>'', + 'placeholder'=>'', + 'tip'=>$L->g('use-this-field-to-add-a-catchy-phrase') + )); + + echo Bootstrap::formInputText(array( + 'name'=>'description', + 'label'=>$L->g('Site description'), + 'value'=>$Site->description(), + 'class'=>'', + 'placeholder'=>'', + 'tip'=>$L->g('you-can-add-a-site-description-to-provide') + )); + + echo Bootstrap::formInputText(array( + 'name'=>'footer', + 'label'=>$L->g('Footer text'), + 'value'=>$Site->footer(), + 'class'=>'', + 'placeholder'=>'', + 'tip'=>$L->g('you-can-add-a-small-text-on-the-bottom') + )); + ?> +
+ + +
+ $L->g('Content'))); + + echo Bootstrap::formSelect(array( + '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', '-1'=>$L->g('All content')), + 'selected'=>$Site->itemsPerPage(), + 'class'=>'', + 'tip'=>$L->g('Number of items to show per page') + )); + + echo Bootstrap::formSelect(array( + 'name'=>'orderBy', + 'label'=>$L->g('Order content by'), + 'options'=>array('date'=>$L->g('Date'),'position'=>$L->g('Position')), + 'selected'=>$Site->orderBy(), + 'class'=>'', + 'tip'=>$L->g('order-the-content-by-date-to-build-a-blog') + )); + + echo Bootstrap::formTitle(array('title'=>$L->g('Predefined pages'))); + + echo Bootstrap::formSelect(array( + 'name'=>'homepage', + 'label'=>$L->g('Homepage'), + 'options'=>array(),//$homepageOptions, + 'selected'=>$Site->homepage(), + 'class'=>'', + 'tip'=>$L->g('Returning page for the main page') + )); + + $homepageOptions[' '] = '- '.$L->g('Default message').' -'; + echo Bootstrap::formSelect(array( + 'name'=>'pageNotFound', + 'label'=>$L->g('Page not found'), + 'options'=>$homepageOptions, + 'selected'=>$Site->pageNotFound(), + 'class'=>'', + 'tip'=>$L->g('Returning page when the page doesnt exist') + )); + + echo Bootstrap::formTitle(array('title'=>$L->g('Email account settings'))); + + echo Bootstrap::formInputText(array( + 'name'=>'emailFrom', + 'label'=>$L->g('Sender email'), + 'value'=>$Site->emailFrom(), + 'class'=>'', + 'placeholder'=>'', + 'tip'=>$L->g('Emails will be sent from this address') + )); + + echo Bootstrap::formTitle(array('title'=>$L->g('Site URL'))); + + echo Bootstrap::formInputText(array( + 'name'=>'url', + 'label'=>'', + 'value'=>$Site->url(), + 'class'=>'', + 'placeholder'=>'', + 'tip'=>$L->g('full-url-of-your-site'), + 'placeholder'=>'https://' + )); + + echo Bootstrap::formSelect(array( + 'name'=>'extremeFriendly', + 'label'=>$L->g('Extreme Friendly URL'), + 'options'=>array('true'=>'Enabled', 'false'=>'Disable'), + 'selected'=>$Site->extremeFriendly(), + 'class'=>'', + 'tip'=>'Is on, allow unicode characters in the URL and some part of the system' + )); + + echo Bootstrap::formTitle(array('title'=>$L->g('URL Filters'))); + + echo Bootstrap::formInputText(array( + 'name'=>'uriPage', + 'label'=>$L->g('Pages'), + 'value'=>$Site->uriFilters('page'), + 'class'=>'', + 'placeholder'=>'', + 'tip'=>DOMAIN_PAGES + )); + + echo Bootstrap::formInputText(array( + 'name'=>'uriTag', + 'label'=>$L->g('Tags'), + 'value'=>$Site->uriFilters('tag'), + 'class'=>'', + 'placeholder'=>'', + 'tip'=>DOMAIN_TAGS + )); + + echo Bootstrap::formInputText(array( + 'name'=>'uriCategory', + 'label'=>$L->g('Category'), + 'value'=>$Site->uriFilters('category'), + 'class'=>'', + 'placeholder'=>'', + 'tip'=>DOMAIN_CATEGORIES + )); + + echo Bootstrap::formInputText(array( + 'name'=>'uriBlog', + 'label'=>$L->g('Blog'), + 'value'=>$Site->uriFilters('blog'), + 'class'=>'', + 'placeholder'=>'', + 'tip'=>DOMAIN.$Site->uriFilters('blog'), + 'disabled'=>!$Site->uriFilters('blog') + )); + ?> +
+ + +
+ 'twitter', + 'label'=>'Twitter', + 'value'=>$Site->twitter(), + 'class'=>'', + 'placeholder'=>'', + 'tip'=>'' + )); + + echo Bootstrap::formInputText(array( + 'name'=>'facebook', + 'label'=>'Facebook', + 'value'=>$Site->facebook(), + 'class'=>'', + 'placeholder'=>'', + 'tip'=>'' + )); + + echo Bootstrap::formInputText(array( + 'name'=>'codepen', + 'label'=>'Codepen', + 'value'=>$Site->codepen(), + 'class'=>'', + 'placeholder'=>'', + 'tip'=>'' + )); + + echo Bootstrap::formInputText(array( + 'name'=>'googlePlus', + 'label'=>'Google+', + 'value'=>$Site->googlePlus(), + 'class'=>'', + 'placeholder'=>'', + 'tip'=>'' + )); + + echo Bootstrap::formInputText(array( + 'name'=>'instagram', + 'label'=>'Instagram', + 'value'=>$Site->instagram(), + 'class'=>'', + 'placeholder'=>'', + 'tip'=>'' + )); + + echo Bootstrap::formInputText(array( + 'name'=>'github', + 'label'=>'Github', + 'value'=>$Site->github(), + 'class'=>'', + 'placeholder'=>'', + 'tip'=>'' + )); + + echo Bootstrap::formInputText(array( + 'name'=>'linkedin', + 'label'=>'Linkedin', + 'value'=>$Site->linkedin(), + 'class'=>'', + 'placeholder'=>'', + 'tip'=>'' + )); + ?> +
+ + +
+ +
+
\ No newline at end of file diff --git a/bl-kernel/boot/init.php b/bl-kernel/boot/init.php index ab6312a4..599641b6 100644 --- a/bl-kernel/boot/init.php +++ b/bl-kernel/boot/init.php @@ -201,6 +201,9 @@ define('PAGE_URI_FILTER', $Url->filters('page')); // Content order by: date / position define('ORDER_BY', $Site->orderBy()); +// Allow unicode characters in the URL +define('EXTREME_FRIENDLY_URL', $Site->extremeFriendly()); + // --- PHP paths with dependency --- // This paths are absolutes for the OS define('THEME_DIR', PATH_ROOT.'bl-themes'.DS.$Site->theme().DS); diff --git a/bl-kernel/boot/variables.php b/bl-kernel/boot/variables.php index 38c9c2f4..f3262968 100644 --- a/bl-kernel/boot/variables.php +++ b/bl-kernel/boot/variables.php @@ -86,9 +86,6 @@ define('TOKEN_EMAIL_TTL', '+15 minutes'); // Charset, default UTF-8. define('CHARSET', 'UTF-8'); -// EXTREME FRIENDLY URL, TRUE for dissmiss internet standard. Experimental! -define('EXTREME_FRIENDLY_URL', FALSE); - // Permissions for new directories define('DIR_PERMISSIONS', 0755); diff --git a/bl-kernel/dbpages.class.php b/bl-kernel/dbpages.class.php index 9283d3f2..8d09490d 100644 --- a/bl-kernel/dbpages.class.php +++ b/bl-kernel/dbpages.class.php @@ -763,16 +763,14 @@ class dbPages extends dbJSON return $tmp; } - // Change all posts with the old category key for the new category key + // Change all pages with the old category key to the new category key public function changeCategory($oldCategoryKey, $newCategoryKey) { - foreach($this->db as $key=>$value) { - if($value['category']==$oldCategoryKey) { + foreach ($this->db as $key=>$value) { + if ($value['category']===$oldCategoryKey) { $this->db[$key]['category'] = $newCategoryKey; } } - - // Save database return $this->save(); } diff --git a/bl-kernel/dbsite.class.php b/bl-kernel/dbsite.class.php index ae73e547..09564d3f 100644 --- a/bl-kernel/dbsite.class.php +++ b/bl-kernel/dbsite.class.php @@ -31,7 +31,8 @@ class dbSite extends dbJSON 'instagram'=> array('inFile'=>false, 'value'=>''), 'github'=> array('inFile'=>false, 'value'=>''), 'linkedin'=> array('inFile'=>false, 'value'=>''), - 'orderBy'=> array('inFile'=>false, 'value'=>'date') // date or position + 'orderBy'=> array('inFile'=>false, 'value'=>'date'), // date or position + 'extremeFriendly'=> array('inFile'=>false, 'value'=>true) ); function __construct() @@ -100,6 +101,11 @@ class dbSite extends dbJSON return DOMAIN_BASE.'sitemap.xml'; } + public function extremeFriendly() + { + return $this->getField('extremeFriendly'); + } + public function twitter() { return $this->getField('twitter'); diff --git a/bl-kernel/functions.php b/bl-kernel/functions.php index cb2e6c87..b408e96b 100644 --- a/bl-kernel/functions.php +++ b/bl-kernel/functions.php @@ -323,7 +323,7 @@ function pluginActivated($pluginClassName) { function activatePlugin($pluginClassName) { global $plugins; - global $Syslog; + global $syslog; global $Language; // Check if the plugin exists @@ -331,7 +331,7 @@ function activatePlugin($pluginClassName) { $plugin = $plugins['all'][$pluginClassName]; if ($plugin->install()) { // Add to syslog - $Syslog->add(array( + $syslog->add(array( 'dictionaryKey'=>'plugin-activated', 'notes'=>$plugin->name() )); @@ -346,7 +346,7 @@ function activatePlugin($pluginClassName) { function deactivatePlugin($pluginClassName) { global $plugins; - global $Syslog; + global $syslog; global $Language; // Check if the plugin exists @@ -355,7 +355,7 @@ function deactivatePlugin($pluginClassName) { if ($plugin->uninstall()) { // Add to syslog - $Syslog->add(array( + $syslog->add(array( 'dictionaryKey'=>'plugin-deactivated', 'notes'=>$plugin->name() )); @@ -370,7 +370,7 @@ function deactivatePlugin($pluginClassName) { function changePluginsPosition($pluginClassList) { global $plugins; - global $Syslog; + global $syslog; global $Language; foreach ($pluginClassList as $position=>$pluginClassName) { @@ -381,7 +381,7 @@ function changePluginsPosition($pluginClassList) { } // Add to syslog - $Syslog->add(array( + $syslog->add(array( 'dictionaryKey'=>'plugins-sorted', 'notes'=>'' )); @@ -391,7 +391,7 @@ function changePluginsPosition($pluginClassList) { function createPage($args) { global $dbPages; - global $Syslog; + global $syslog; global $Language; // The user is always the one loggued @@ -419,7 +419,7 @@ function createPage($args) { reindextags(); // Add to syslog - $Syslog->add(array( + $syslog->add(array( 'dictionaryKey'=>'new-content-created', 'notes'=>$args['title'] )); @@ -439,7 +439,7 @@ function createPage($args) { function editPage($args) { global $dbPages; - global $Syslog; + global $syslog; // Check the key is not empty if (empty($args['key'])) { @@ -482,7 +482,7 @@ function editPage($args) { reindextags(); // Add to syslog - $Syslog->add(array( + $syslog->add(array( 'dictionaryKey'=>'content-edited', 'notes'=>$args['title'] )); @@ -496,7 +496,7 @@ function editPage($args) { function deletePage($key) { global $dbPages; - global $Syslog; + global $syslog; if( $dbPages->delete($key) ) { // Call the plugins after page deleted @@ -509,7 +509,7 @@ function deletePage($key) { reindextags(); // Add to syslog - $Syslog->add(array( + $syslog->add(array( 'dictionaryKey'=>'content-deleted', 'notes'=>$key )); @@ -523,7 +523,7 @@ function deletePage($key) { function disableUser($username) { global $dbUsers; global $Login; - global $Syslog; + global $syslog; // The editors can't disable users if($Login->role()!=='admin') { @@ -532,7 +532,7 @@ function disableUser($username) { if( $dbUsers->disableUser($username) ) { // Add to syslog - $Syslog->add(array( + $syslog->add(array( 'dictionaryKey'=>'user-disabled', 'notes'=>$username )); @@ -545,11 +545,11 @@ function disableUser($username) { function editUser($args) { global $dbUsers; - global $Syslog; + global $syslog; if( $dbUsers->set($args) ) { // Add to syslog - $Syslog->add(array( + $syslog->add(array( 'dictionaryKey'=>'user-edited', 'notes'=>$args['username'] )); @@ -563,7 +563,7 @@ function editUser($args) { function deleteUser($args, $deleteContent=false) { global $dbUsers; global $Login; - global $Syslog; + global $syslog; // The user admin cannot be deleted if($args['username']=='admin') { @@ -584,7 +584,7 @@ function deleteUser($args, $deleteContent=false) { if( $dbUsers->delete($args['username']) ) { // Add to syslog - $Syslog->add(array( + $syslog->add(array( 'dictionaryKey'=>'user-deleted', 'notes'=>$args['username'] )); @@ -598,7 +598,7 @@ function deleteUser($args, $deleteContent=false) { function createUser($args) { global $dbUsers; global $Language; - global $Syslog; + global $syslog; // Check empty username if( Text::isEmpty($args['new_username']) ) { @@ -634,7 +634,7 @@ function createUser($args) { // Add the user to the database if( $dbUsers->add($tmp) ) { // Add to syslog - $Syslog->add(array( + $syslog->add(array( 'dictionaryKey'=>'new-user-created', 'notes'=>$tmp['username'] )); @@ -647,7 +647,7 @@ function createUser($args) { function editSettings($args) { global $Site; - global $Syslog; + global $syslog; global $Language; global $dbPages; @@ -692,7 +692,7 @@ function editSettings($args) { } // Add syslog - $Syslog->add(array( + $syslog->add(array( 'dictionaryKey'=>'changes-on-settings', 'notes'=>'' )); @@ -706,71 +706,80 @@ function editSettings($args) { } // Add a new category to the system -// Returns TRUE is success added, FALSE otherwise +// Returns TRUE is successfully added, FALSE otherwise function createCategory($category) { global $dbCategories; global $Language; - global $Syslog; + global $syslog; if (Text::isEmpty($category)) { - // Set an alert Alert::set($Language->g('Category name is empty'), ALERT_STATUS_FAIL); return false; } if ($dbCategories->add($category)) { - // Add to syslog - $Syslog->add(array( + $syslog->add(array( 'dictionaryKey'=>'new-category-created', 'notes'=>$category )); - // Set an alert Alert::set($Language->g('Category added'), ALERT_STATUS_OK); return true; } + Alert::set($Language->g('The category already exists'), ALERT_STATUS_FAIL); return false; } -function editCategory($oldCategoryKey, $newCategory) { +function editCategory($args) { global $Language; global $dbPages; global $dbCategories; - global $Syslog; + global $syslog; - if( Text::isEmpty($oldCategoryKey) || Text::isEmpty($newCategory) ) { + if (Text::isEmpty($args['categoryName']) || Text::isEmpty($args['categoryKey']) ) { Alert::set($Language->g('Empty fields')); return false; } - if( $dbCategories->edit($oldCategoryKey, $newCategory) == false ) { - Alert::set($Language->g('Already exist a category')); + if ($args['oldCategoryKey']!==$args['categoryKey']) { + // Edit the category key and keep the category name + $newCategoryKey = $dbCategories->changeKey($args['oldCategoryKey'], $args['categoryKey']); + } else { + // Edit the category name + $newCategoryKey = $dbCategories->edit($args['oldCategoryKey'], $args['categoryName']); + } + + if ($newCategoryKey==false) { + Alert::set($Language->g('The category already exists')); return false; } - $dbPages->changeCategory($oldCategoryKey, $newCategory); + // Change the category key in the pages database + $dbPages->changeCategory($args['oldCategoryKey'], $newCategoryKey); - $Syslog->add(array( + $syslog->add(array( 'dictionaryKey'=>'category-edited', - 'notes'=>$newCategory + 'notes'=>$newCategoryKey )); Alert::set($Language->g('The changes have been saved')); return true; } -function deleteCategory($categoryKey) { +function deleteCategory($args) { global $Language; global $dbCategories; - global $Syslog; + global $syslog; // Remove the category by key - $dbCategories->remove($categoryKey); + $dbCategories->remove($args['oldCategoryKey']); - $Syslog->add(array( + // Remove the category from the pages ? or keep it if the user want to recovery the category ? + + $syslog->add(array( 'dictionaryKey'=>'category-deleted', - 'notes'=>$categoryKey + 'notes'=>$args['oldCategoryKey'] )); Alert::set($Language->g('The changes have been saved')); @@ -814,12 +823,12 @@ function getTags() { function activateTheme($themeDirectory) { global $Site; - global $Syslog; + global $syslog; if (Sanitize::pathFile(PATH_THEMES.$themeDirectory)) { $Site->set(array('theme'=>$themeDirname)); - $Syslog->add(array( + $syslog->add(array( 'dictionaryKey'=>'new-theme-configured', 'notes'=>$themeDirname )); diff --git a/bl-kernel/helpers/text.class.php b/bl-kernel/helpers/text.class.php index d029601d..fadd820f 100644 --- a/bl-kernel/helpers/text.class.php +++ b/bl-kernel/helpers/text.class.php @@ -121,7 +121,7 @@ class Text { return str_replace(array_keys($replace), array_values($replace), $text); } - // Convert invalid characters to valid characters for a URL + // Convert unicode characters to utf-8 characters // Characters that cannot be converted will be removed from the string // This function can return an empty string public static function cleanUrl($string, $separator='-') @@ -129,6 +129,8 @@ class Text { global $Language; if (EXTREME_FRIENDLY_URL) { + $string = trim($string, '-'); + $string = self::lowercase($string); $string = preg_replace("/[\/_|+ -]+/", $separator, $string); return $string; } diff --git a/bl-kernel/page.class.php b/bl-kernel/page.class.php index e5b5ac30..cc4d0b61 100644 --- a/bl-kernel/page.class.php +++ b/bl-kernel/page.class.php @@ -222,6 +222,12 @@ class Page { return $this->getValue('category'); } + // Returns the category permalink + public function categoryPermalink() + { + return DOMAIN_CATEGORIES.$this->categoryKey(); + } + // Returns the field from the array // categoryMap = array( 'name'=>'', 'list'=>array() ) public function categoryMap($field)