From 7d51652efcfc8755eb0d7100115184ad68c6ce10 Mon Sep 17 00:00:00 2001 From: Diego Najar Date: Sat, 27 May 2017 19:46:46 +0200 Subject: [PATCH] New plugins and plugins updated for v2.0 --- bl-kernel/abstract/dblist.class.php | 17 ++-- bl-kernel/abstract/plugin.class.php | 63 ++++++++------ .../admin/controllers/configure-plugin.php | 33 +++---- bl-kernel/admin/controllers/edit-page.php | 2 +- .../admin/controllers/install-plugin.php | 4 +- bl-kernel/admin/controllers/plugins.php | 2 +- .../admin/controllers/uninstall-plugin.php | 4 +- bl-kernel/admin/views/configure-plugin.php | 4 +- bl-kernel/admin/views/new-page.php | 2 +- bl-kernel/boot/rules/60.plugins.php | 1 - bl-kernel/boot/rules/69.pages.php | 2 +- bl-kernel/functions.php | 8 +- bl-plugins/about/metadata.json | 8 +- bl-plugins/about/plugin.php | 13 +-- bl-plugins/categories/languages/en_US.json | 7 ++ bl-plugins/categories/metadata.json | 10 +++ bl-plugins/categories/plugin.php | 58 +++++++++++++ bl-plugins/menu/languages/en_US.json | 7 ++ bl-plugins/menu/metadata.json | 10 +++ bl-plugins/menu/plugin.php | 67 +++++++++++++++ bl-plugins/pages/plugin.php | 85 ++++++------------- bl-themes/editorial/assets/css/bludit.css | 55 ++++++++++++ bl-themes/editorial/php/head.php | 1 + bl-themes/editorial/php/sidebar.php | 73 +--------------- 24 files changed, 330 insertions(+), 206 deletions(-) create mode 100644 bl-plugins/categories/languages/en_US.json create mode 100644 bl-plugins/categories/metadata.json create mode 100644 bl-plugins/categories/plugin.php create mode 100644 bl-plugins/menu/languages/en_US.json create mode 100644 bl-plugins/menu/metadata.json create mode 100644 bl-plugins/menu/plugin.php create mode 100644 bl-themes/editorial/assets/css/bludit.css diff --git a/bl-kernel/abstract/dblist.class.php b/bl-kernel/abstract/dblist.class.php index d51d97f2..2de37d23 100644 --- a/bl-kernel/abstract/dblist.class.php +++ b/bl-kernel/abstract/dblist.class.php @@ -65,6 +65,8 @@ class dbList extends dbJSON $this->db[$key]['name'] = $name; $this->db[$key]['list'] = array(); + + $this->sortAlphanumeric(); $this->save(); return $key; @@ -93,10 +95,18 @@ class dbList extends dbJSON unset( $this->db[$oldKey] ); } + $this->sortAlphanumeric(); $this->save(); return $newKey; } + // Sort the categories by "Natural order" + private function sortAlphanumeric() + { + // Sort key alphanumeric strings, a01, a10, b10, c02 + return ksort($this->db); + } + // Returns the name associated to the key, FALSE if the key doesn't exist public function getName($key) { @@ -108,18 +118,13 @@ class dbList extends dbJSON } // Returns an array with key=>name of the list - public function getKeyNameArray($sortAlphanumeric=true) + public function getKeyNameArray() { $tmp = array(); foreach($this->db as $key=>$fields) { $tmp[$key] = $fields['name']; } - // Sort alphanumeric strings, a01, a10, a11, a20 - if($sortAlphanumeric) { - natcasesort($tmp); - } - return $tmp; } diff --git a/bl-kernel/abstract/plugin.class.php b/bl-kernel/abstract/plugin.class.php index 13acf26c..9c383e70 100644 --- a/bl-kernel/abstract/plugin.class.php +++ b/bl-kernel/abstract/plugin.class.php @@ -55,6 +55,26 @@ class Plugin { } } + public function setDb($args) + { + foreach($this->dbFields as $key=>$value) { + if( isset($args[$key]) ) { + $value = Sanitize::html( $args[$key] ); + settype($value, gettype($this->dbFields[$key])); + $this->db[$key] = $value; + } + } + + $this->save(); + } + + public function save() + { + $tmp = new dbJSON($this->filenameDb); + $tmp->db = $this->db; + $tmp->save(); + } + public function htmlPath() { return HTML_PATH_PLUGINS.$this->directoryName.'/'; @@ -86,6 +106,22 @@ class Plugin { return true; } + // Returns the value of the field from the database + // (string) $field + // (boolean) $html, TRUE returns the value sanitized, FALSE unsanitized + public function getValue($field, $html=true) + { + if( isset($this->db[$field]) ) { + if($html) { + return $this->db[$field]; + } + else { + return Sanitize::htmlDecode($this->db[$field]); + } + } + return false; + } + public function getDbField($key, $html=true) { if(isset($this->db[$key])) { @@ -103,33 +139,6 @@ class Plugin { return ''; } - public function setDb($args) - { - $tmp = $this->db; - - foreach($this->dbFields as $key=>$value) - { - if(isset($args[$key])) - { - // Sanitize value - $tmpValue = Sanitize::html( $args[$key] ); - - // Set type - settype($tmpValue, gettype($value)); - - // Set value - $tmp[$key] = $tmpValue; - } - } - - $this->db = $tmp; - - // Save db on file - $Tmp = new dbJSON($this->filenameDb); - $Tmp->db = $tmp; - $Tmp->save(); - } - public function name() { return $this->getMetadata('name'); diff --git a/bl-kernel/admin/controllers/configure-plugin.php b/bl-kernel/admin/controllers/configure-plugin.php index 60946a16..822be86b 100644 --- a/bl-kernel/admin/controllers/configure-plugin.php +++ b/bl-kernel/admin/controllers/configure-plugin.php @@ -6,7 +6,7 @@ if($Login->role()!=='admin') { Alert::set($Language->g('you-do-not-have-sufficient-permissions')); - Redirect::page('admin', 'dashboard'); + Redirect::page('dashboard'); } // ============================================================================ @@ -16,24 +16,20 @@ if($Login->role()!=='admin') { // ============================================================================ // Main before POST // ============================================================================ -$_Plugin = false; +$plugin = false; $pluginClassName = $layout['parameters']; -foreach($plugins['all'] as $P) -{ - if($P->className()==$pluginClassName) { - $_Plugin = $P; - } +// Check if the plugin exists +if( isset($plugins['all'][$pluginClassName]) ) { + $plugin = $plugins['all'][$pluginClassName]; } - -// Check if the plugin exists. -if($_Plugin===false) { - Redirect::page('admin', 'plugins'); +else { + Redirect::page('plugins'); } // Check if the plugin has the method form() -if(!method_exists($_Plugin, 'form')) { - Redirect::page('admin', 'plugins'); +if( !method_exists($plugin, 'form') ) { + Redirect::page('plugins'); } // ============================================================================ @@ -42,11 +38,16 @@ if(!method_exists($_Plugin, 'form')) { if( $_SERVER['REQUEST_METHOD'] == 'POST' ) { - $_Plugin->setDb($_POST); + $plugin->setDb($_POST); - Theme::plugins('afterFormSave'); + // Add to syslog + $Syslog->add(array( + 'dictionaryKey'=>'plugin-configured', + 'notes'=>$plugin->name() + )); - Alert::set($Language->g('the-changes-have-been-saved')); + // Create an alert + Alert::set( $Language->g('The changes have been saved') ); } // ============================================================================ diff --git a/bl-kernel/admin/controllers/edit-page.php b/bl-kernel/admin/controllers/edit-page.php index ecc3c651..8c8babab 100644 --- a/bl-kernel/admin/controllers/edit-page.php +++ b/bl-kernel/admin/controllers/edit-page.php @@ -112,4 +112,4 @@ if( !$dbPages->exists($layout['parameters']) ) { Redirect::page('pages'); } -$page = $pagesKey[$layout['parameters']]; +$page = $pagesByKey[$layout['parameters']]; diff --git a/bl-kernel/admin/controllers/install-plugin.php b/bl-kernel/admin/controllers/install-plugin.php index e4ceeaaa..9e46e437 100644 --- a/bl-kernel/admin/controllers/install-plugin.php +++ b/bl-kernel/admin/controllers/install-plugin.php @@ -6,7 +6,7 @@ if($Login->role()!=='admin') { Alert::set($Language->g('you-do-not-have-sufficient-permissions')); - Redirect::page('admin', 'dashboard'); + Redirect::page('dashboard'); } // ============================================================================ @@ -33,4 +33,4 @@ foreach($plugins['all'] as $P) } } -Redirect::page('admin', 'plugins'); +Redirect::page('plugins'); diff --git a/bl-kernel/admin/controllers/plugins.php b/bl-kernel/admin/controllers/plugins.php index 9297c685..554fb3ea 100644 --- a/bl-kernel/admin/controllers/plugins.php +++ b/bl-kernel/admin/controllers/plugins.php @@ -6,7 +6,7 @@ if($Login->role()!=='admin') { Alert::set($Language->g('you-do-not-have-sufficient-permissions')); - Redirect::page('admin', 'dashboard'); + Redirect::page('dashboard'); } // ============================================================================ diff --git a/bl-kernel/admin/controllers/uninstall-plugin.php b/bl-kernel/admin/controllers/uninstall-plugin.php index 6e32daf5..4052eb76 100644 --- a/bl-kernel/admin/controllers/uninstall-plugin.php +++ b/bl-kernel/admin/controllers/uninstall-plugin.php @@ -6,7 +6,7 @@ if($Login->role()!=='admin') { Alert::set($Language->g('you-do-not-have-sufficient-permissions')); - Redirect::page('admin', 'dashboard'); + Redirect::page('dashboard'); } // ============================================================================ @@ -29,4 +29,4 @@ $pluginClassName = $layout['parameters']; $Plugin = new $pluginClassName; $Plugin->uninstall(); -Redirect::page('admin', 'plugins'); +Redirect::page('plugins'); diff --git a/bl-kernel/admin/views/configure-plugin.php b/bl-kernel/admin/views/configure-plugin.php index 564270eb..c684023f 100644 --- a/bl-kernel/admin/views/configure-plugin.php +++ b/bl-kernel/admin/views/configure-plugin.php @@ -1,6 +1,6 @@ $_Plugin->name(), 'icon'=>'puzzle-piece')); +HTML::title(array('title'=>$plugin->name(), 'icon'=>'puzzle-piece')); HTML::formOpen(array('id'=>'jsformplugin')); @@ -11,7 +11,7 @@ HTML::formOpen(array('id'=>'jsformplugin')); )); // Print the plugin form - echo $_Plugin->form(); + echo $plugin->form(); // Form buttons echo '
diff --git a/bl-kernel/admin/views/new-page.php b/bl-kernel/admin/views/new-page.php index 8d35bfc9..cee31e52 100644 --- a/bl-kernel/admin/views/new-page.php +++ b/bl-kernel/admin/views/new-page.php @@ -136,7 +136,7 @@ echo '
'; $options = array(); $parents = $dbPages->getParents(true); foreach( $parents as $key=>$fields ) { - $options[$key] = $pagesKey[$key]->title(); + $options[$key] = $pagesByKey[$key]->title(); } HTML::formSelect(array( diff --git a/bl-kernel/boot/rules/60.plugins.php b/bl-kernel/boot/rules/60.plugins.php index 689ebd1b..8520ac87 100644 --- a/bl-kernel/boot/rules/60.plugins.php +++ b/bl-kernel/boot/rules/60.plugins.php @@ -23,7 +23,6 @@ $plugins = array( 'adminSidebar'=>array(), 'beforeRulesLoad'=>array(), - 'afterFormSave'=>array(), 'afterPageCreate'=>array(), 'afterPageModify'=>array(), diff --git a/bl-kernel/boot/rules/69.pages.php b/bl-kernel/boot/rules/69.pages.php index 95710b44..56a786b9 100644 --- a/bl-kernel/boot/rules/69.pages.php +++ b/bl-kernel/boot/rules/69.pages.php @@ -17,7 +17,7 @@ $page = false; //$pageParents = array(); // Array with all published pages, the array is a key=>Page-object -$pagesKey = array(); +$pagesByKey = array(); // ============================================================================ // Main diff --git a/bl-kernel/functions.php b/bl-kernel/functions.php index 40f9e441..7a3cef64 100644 --- a/bl-kernel/functions.php +++ b/bl-kernel/functions.php @@ -117,7 +117,7 @@ function buildPagesFor($for, $categoryKey=false, $tagKey=false) global $dbCategories; global $Site; global $Url; - global $pagesKey; + global $pagesByKey; global $pages; // Get the page number from URL @@ -150,12 +150,12 @@ function buildPagesFor($for, $categoryKey=false, $tagKey=false) } $pages = array(); // global variable - $pagesKey = array(); // global variable + $pagesByKey = array(); // global variable foreach($list as $pageKey=>$fields) { $page = buildPage($pageKey); if($page!==false) { - // $pagesKey - $pagesKey[$pageKey] = $page; + // $pagesByKey + $pagesByKey[$pageKey] = $page; // $pages array_push($pages, $page); } diff --git a/bl-plugins/about/metadata.json b/bl-plugins/about/metadata.json index 8801aa07..a5c64fc0 100644 --- a/bl-plugins/about/metadata.json +++ b/bl-plugins/about/metadata.json @@ -2,9 +2,9 @@ "author": "Bludit", "email": "", "website": "https://plugins.bludit.com", - "version": "1.5.2", - "releaseDate": "2016-05-28", + "version": "2.0", + "releaseDate": "2017-05-26", "license": "MIT", - "compatible": "1.5.2", + "compatible": "2.0", "notes": "" -} +} \ No newline at end of file diff --git a/bl-plugins/about/plugin.php b/bl-plugins/about/plugin.php index bb3eccb1..96af23d0 100644 --- a/bl-plugins/about/plugin.php +++ b/bl-plugins/about/plugin.php @@ -15,12 +15,13 @@ class pluginAbout extends Plugin { global $Language; $html = '
'; - $html .= ''; - $html .= ''; + $html .= ''; + $html .= ''; $html .= '
'; + $html .= '
'; $html .= ''; - $html .= ''; + $html .= ''; $html .= '
'; return $html; @@ -29,12 +30,12 @@ class pluginAbout extends Plugin { public function siteSidebar() { $html = '
'; - $html .= '

'.$this->getDbField('label').'

'; + $html .= '

'.$this->getValue('label').'

'; $html .= '
'; - $html .= html_entity_decode(nl2br($this->getDbField('text'))); + $html .= html_entity_decode(nl2br($this->getValue('text'))); $html .= '
'; $html .= '
'; return $html; } -} +} \ No newline at end of file diff --git a/bl-plugins/categories/languages/en_US.json b/bl-plugins/categories/languages/en_US.json new file mode 100644 index 00000000..72e749cd --- /dev/null +++ b/bl-plugins/categories/languages/en_US.json @@ -0,0 +1,7 @@ +{ + "plugin-data": + { + "name": "Categories", + "description": "Shows all categories." + } +} diff --git a/bl-plugins/categories/metadata.json b/bl-plugins/categories/metadata.json new file mode 100644 index 00000000..a5c64fc0 --- /dev/null +++ b/bl-plugins/categories/metadata.json @@ -0,0 +1,10 @@ +{ + "author": "Bludit", + "email": "", + "website": "https://plugins.bludit.com", + "version": "2.0", + "releaseDate": "2017-05-26", + "license": "MIT", + "compatible": "2.0", + "notes": "" +} \ No newline at end of file diff --git a/bl-plugins/categories/plugin.php b/bl-plugins/categories/plugin.php new file mode 100644 index 00000000..d792eff3 --- /dev/null +++ b/bl-plugins/categories/plugin.php @@ -0,0 +1,58 @@ +dbFields = array( + 'label'=>'Categories' + ); + } + + // Method called on the settings of the plugin on the admin area + public function form() + { + global $Language; + + $html = '
'; + $html .= ''; + $html .= ''; + $html .= '
'; + + return $html; + } + + // Method called on the sidebar of the website + public function siteSidebar() + { + global $Language; + global $dbCategories; + global $Url; + + // URL base filter for categories + $filter = $Url->filters('category'); + + // HTML for sidebar + $html = '
'; + $html .= '

'.$this->getValue('label').'

'; + $html .= '
'; + $html .= ''; + $html .= '
'; + $html .= '
'; + + return $html; + } +} \ No newline at end of file diff --git a/bl-plugins/menu/languages/en_US.json b/bl-plugins/menu/languages/en_US.json new file mode 100644 index 00000000..5f3395cf --- /dev/null +++ b/bl-plugins/menu/languages/en_US.json @@ -0,0 +1,7 @@ +{ + "plugin-data": + { + "name": "Menu", + "description": "Show a menu organized by categories and pages." + } +} diff --git a/bl-plugins/menu/metadata.json b/bl-plugins/menu/metadata.json new file mode 100644 index 00000000..a5c64fc0 --- /dev/null +++ b/bl-plugins/menu/metadata.json @@ -0,0 +1,10 @@ +{ + "author": "Bludit", + "email": "", + "website": "https://plugins.bludit.com", + "version": "2.0", + "releaseDate": "2017-05-26", + "license": "MIT", + "compatible": "2.0", + "notes": "" +} \ No newline at end of file diff --git a/bl-plugins/menu/plugin.php b/bl-plugins/menu/plugin.php new file mode 100644 index 00000000..37037439 --- /dev/null +++ b/bl-plugins/menu/plugin.php @@ -0,0 +1,67 @@ +dbFields = array( + 'label'=>'Menu' + ); + } + + // Method called on the settings of the plugin on the admin area + public function form() + { + global $Language; + + $html = '
'; + $html .= ''; + $html .= ''; + $html .= '
'; + + return $html; + } + + // Method called on the sidebar of the website + public function siteSidebar() + { + global $Language; + global $dbCategories; + global $Url; + global $pagesByKey; + + // HTML for sidebar + $html = '
'; + $html .= '

'.$this->getValue('label').'

'; + $html .= '
'; + $html .= ''; + $html .= '
'; + $html .= '
'; + + return $html; + } +} \ No newline at end of file diff --git a/bl-plugins/pages/plugin.php b/bl-plugins/pages/plugin.php index ca3ac36d..26a3cd1b 100644 --- a/bl-plugins/pages/plugin.php +++ b/bl-plugins/pages/plugin.php @@ -4,103 +4,68 @@ class pluginPages extends Plugin { public function init() { + // Fields and default values for the database of this plugin $this->dbFields = array( - 'homeLink'=>1, - 'children'=>1, - 'label'=>'Pages' + 'label'=>'Pages', + 'homeLink'=>true, + 'children'=>true ); } + // Method called on the settings of the plugin on the admin area public function form() { global $Language; $html = '
'; - $html .= ''; - $html .= ''; + $html .= ''; + $html .= ''; $html .= '
'; $html .= '
'; $html .= ''; - $html .= 'getDbField('homeLink')?'checked':'').'>'; + $html .= 'getValue('homeLink')?'checked':'').'>'; $html .= ''; $html .= '
'; - + $html .= '
'; $html .= ''; - $html .= 'getDbField('children')?'checked':'').'>'; + $html .= 'getValue('children')?'checked':'').'>'; $html .= ''; $html .= '
'; return $html; } + // Method called on the sidebar of the website public function siteSidebar() { global $Language; - global $pagesParents; - global $Site, $Url; + global $pages; + global $Url; + // URL base filter for categories + $filter = $Url->filters('page'); + + // HTML for sidebar $html = '
'; - - // Print the label if not empty. - $label = $this->getDbField('label'); - if( !empty($label) ) { - $html .= '

'.$label.'

'; - } - + $html .= '

'.$this->getValue('label').'

'; $html .= '
'; - $html .= '
    '; + $html .= '
      '; - // Show home link ? - if($this->getDbField('homeLink')) { + // By default the database of categories are alphanumeric sorted + foreach( $pages as $page ) { $html .= '
    • '; - $html .= ''.$Language->get('Home').''; + $html .= ''; + $html .= $page->title(); + $html .= ''; $html .= '
    • '; } - $parents = $pagesParents[NO_PARENT_CHAR]; - foreach($parents as $parent) - { - // Check if the parent is published - if( $parent->published() ) - { - // Print the parent - $html .= '
    • '; - $html .= ''.$parent->title().''; - - // Show children elements? - if($this->getDbField('children')) { - - // Check if the parent has children - if(isset($pagesParents[$parent->key()])) - { - $children = $pagesParents[$parent->key()]; - - // Print children - $html .= '
        '; - foreach($children as $child) - { - // Check if the child is published - if( $child->published() ) - { - $html .= '
      • '; - $html .= ''.$child->title().''; - $html .= '
      • '; - } - } - $html .= '
      '; - } - } - - $html .= '
    • '; - } - } - $html .= '
    '; $html .= '
'; $html .= '
'; return $html; } -} +} \ No newline at end of file diff --git a/bl-themes/editorial/assets/css/bludit.css b/bl-themes/editorial/assets/css/bludit.css new file mode 100644 index 00000000..1b7fd90f --- /dev/null +++ b/bl-themes/editorial/assets/css/bludit.css @@ -0,0 +1,55 @@ + +/* Plugins +------------------------------------------------------------------------------ */ + +div.plugin { + +} + +div.plugin h2.plugin-label { + border-bottom: solid 3px #f56a6a; + display: inline-block; + margin: 0 0 2em 0; + padding: 0 0.75em 0.5em 0; +} + +div.plugin ul { + list-style: none; +} + +div.plugin ul li { + border-top: solid 1px rgba(210, 215, 217, 0.75); + margin: 0.5em 0 0 0; + padding: 0.5em 0 0 0; +} + +div.plugin a { + border-bottom: 0; + color: inherit; + cursor: pointer; + display: block; + font-size: 1.1em; + padding: 0.625em 0; +} + +/* Plugin Menu +------------------------------------------------------------------------------ */ + +div.plugin-menu ul.menu { + margin: 0; + padding: 0; +} + +div.plugin-menu ul.submenu li { + border: none; +} + +div.plugin-menu span.category-name { + color: #3d4449 !important; + opacity: 1.0; + text-transform: uppercase; +} + +div.plugin-menu a.page-title { + padding: 0; +} \ No newline at end of file diff --git a/bl-themes/editorial/php/head.php b/bl-themes/editorial/php/head.php index 7f2f0504..1723a1bc 100644 --- a/bl-themes/editorial/php/head.php +++ b/bl-themes/editorial/php/head.php @@ -9,6 +9,7 @@ echo Theme::css('assets/css/main.css'); echo ''; + echo Theme::css('assets/css/bludit.css'); // Load plugins with the hook siteHead Theme::plugins('siteHead'); diff --git a/bl-themes/editorial/php/sidebar.php b/bl-themes/editorial/php/sidebar.php index c2e5164b..5654e1aa 100644 --- a/bl-themes/editorial/php/sidebar.php +++ b/bl-themes/editorial/php/sidebar.php @@ -1,75 +1,4 @@ - - - - -
-
-

Ante interdum

-
-
-
- -

Aenean ornare velit lacus, ac varius enim lorem ullamcorper dolore aliquam.

-
-
- -

Aenean ornare velit lacus, ac varius enim lorem ullamcorper dolore aliquam.

-
-
- -

Aenean ornare velit lacus, ac varius enim lorem ullamcorper dolore aliquam.

-
-
- -
- - -
-
-

Get in touch

-
-

Sed varius enim lorem ullamcorper dolore aliquam aenean ornare velit lacus, ac varius enim lorem ullamcorper dolore. Proin sed aliquam facilisis ante interdum. Sed nulla amet lorem feugiat tempus aliquam.

- -
+