From c54e64a94d80185c9a520985891fd0dc618dc964 Mon Sep 17 00:00:00 2001 From: Diego Najar Date: Mon, 19 Jun 2017 23:14:38 +0200 Subject: [PATCH] Improves on plugins, post method, improves on database for plugins, css styling --- bl-kernel/abstract/plugin.class.php | 24 +++++- .../admin/controllers/configure-plugin.php | 14 ++-- .../admin/themes/default/css/default.css | 19 +++++ bl-kernel/admin/themes/default/index.php | 14 ---- bl-kernel/admin/views/configure-plugin.php | 12 +-- bl-kernel/boot/init.php | 3 - bl-kernel/functions.php | 6 ++ bl-plugins/links/plugin.php | 82 ++++++++++++++++--- 8 files changed, 133 insertions(+), 41 deletions(-) diff --git a/bl-kernel/abstract/plugin.class.php b/bl-kernel/abstract/plugin.class.php index e1e13e2b..7c96c2c1 100644 --- a/bl-kernel/abstract/plugin.class.php +++ b/bl-kernel/abstract/plugin.class.php @@ -28,6 +28,8 @@ class Plugin { // (array) Database fields, only for initialize public $dbFields; + public $formButtons; + function __construct() { $this->dbFields = array(); @@ -40,6 +42,8 @@ class Plugin { // Class Name $this->className = $reflector->getName(); + $this->formButtons = true; + // Call the method init() from the children $this->init(); @@ -60,6 +64,8 @@ class Plugin { } } + // DEPRECATED + // 2017-06-19 public function setDb($args) { foreach($this->dbFields as $key=>$value) { @@ -189,6 +195,11 @@ class Plugin { return $this->className; } + public function formButtons() + { + return $this->formButtons; + } + public function isCompatible() { $bluditRoot = explode('.', BLUDIT_VERSION); @@ -255,7 +266,18 @@ class Plugin { public function post() { - $this->setDb($_POST); + $args = $_POST; + foreach($this->dbFields as $key=>$value) { + if( isset($args[$key]) ) { + $value = Sanitize::html( $args[$key] ); + if($value==='false') { $value = false; } + elseif($value==='true') { $value = true; } + settype($value, gettype($this->dbFields[$key])); + $this->db[$key] = $value; + } + } + + return $this->save(); } } \ No newline at end of file diff --git a/bl-kernel/admin/controllers/configure-plugin.php b/bl-kernel/admin/controllers/configure-plugin.php index 29b30d40..2423dbb8 100644 --- a/bl-kernel/admin/controllers/configure-plugin.php +++ b/bl-kernel/admin/controllers/configure-plugin.php @@ -38,17 +38,21 @@ if( !method_exists($plugin, 'form') ) { if( $_SERVER['REQUEST_METHOD'] == 'POST' ) { - // Call the method post of the plugin - $plugin->post(); - // Add to syslog $Syslog->add(array( 'dictionaryKey'=>'plugin-configured', 'notes'=>$plugin->name() )); - // Create an alert - Alert::set( $Language->g('The changes have been saved') ); + // Call the method post of the plugin + if( $plugin->post() ) { + // Create an alert + Alert::set( $Language->g('The changes have been saved') ); + } + else { + // Create an alert + Alert::set( $Language->g('Complete all fields') ); + } } // ============================================================================ diff --git a/bl-kernel/admin/themes/default/css/default.css b/bl-kernel/admin/themes/default/css/default.css index 10d53efc..3533bfd8 100644 --- a/bl-kernel/admin/themes/default/css/default.css +++ b/bl-kernel/admin/themes/default/css/default.css @@ -673,11 +673,30 @@ div.plugin-links > span.separator { #jsformplugin > div > label, #jsformplugin > div > input[type=text], #jsformplugin > div > input[type=checkbox], +#jsformplugin > div > button[type=submit], #jsformplugin > div > textarea, #jsformplugin > div > select { display: table-cell; } +#jsformplugin > div > button[type=submit] { + margin-left: 200px; + border-radius: 2px; + padding: 1px 20px; + border: 0; + box-shadow: inset 0 0 5px rgba(0,0,0,.05); + text-shadow: 0 -1px 0 rgba(0,0,0,.1); + line-height: 28px; + min-height: 30px; + font-size: 1rem; + cursor: pointer; +} + +#jsformplugin > div > button[type=submit].blue { + background: #007add !important; + color: #fff; +} + #jsformplugin > div > span.tip { color: #999; margin-top: 5px; diff --git a/bl-kernel/admin/themes/default/index.php b/bl-kernel/admin/themes/default/index.php index 6a1db99a..c6b809b2 100644 --- a/bl-kernel/admin/themes/default/index.php +++ b/bl-kernel/admin/themes/default/index.php @@ -149,20 +149,6 @@ $(document).ready(function() { ?> - - - diff --git a/bl-kernel/admin/views/configure-plugin.php b/bl-kernel/admin/views/configure-plugin.php index c684023f..a6f3d275 100644 --- a/bl-kernel/admin/views/configure-plugin.php +++ b/bl-kernel/admin/views/configure-plugin.php @@ -13,10 +13,12 @@ HTML::formOpen(array('id'=>'jsformplugin')); // Print the plugin form echo $plugin->form(); - // Form buttons - echo '
- - '.$L->g('Cancel').' -
'; + if($plugin->formButtons()) { + // Form buttons + echo '
+ + '.$L->g('Cancel').' +
'; + } HTML::formClose(); diff --git a/bl-kernel/boot/init.php b/bl-kernel/boot/init.php index 11a1b518..b3bf0f2a 100644 --- a/bl-kernel/boot/init.php +++ b/bl-kernel/boot/init.php @@ -67,9 +67,6 @@ if(!defined('JSON_PRETTY_PRINT')) { // Protecting against Symlink attacks define('CHECK_SYMBOLIC_LINKS', TRUE); -// Auto scroll -define('AUTO_SCROLL', TRUE); - // Alert status ok define('ALERT_STATUS_OK', 0); diff --git a/bl-kernel/functions.php b/bl-kernel/functions.php index dd0e9094..4de24bed 100644 --- a/bl-kernel/functions.php +++ b/bl-kernel/functions.php @@ -172,4 +172,10 @@ function pluginEnabled($pluginName) { } return false; +} + +function printDebug($array) { + echo '
';
+	var_dump($array);
+	echo '
'; } \ No newline at end of file diff --git a/bl-plugins/links/plugin.php b/bl-plugins/links/plugin.php index 75a19980..589e5696 100644 --- a/bl-plugins/links/plugin.php +++ b/bl-plugins/links/plugin.php @@ -4,6 +4,7 @@ class pluginLinks extends Plugin { public function init() { + // JSON database $jsondb = json_encode(array( 'Bludit'=>'https://bludit.com', 'Donate'=>'https://paypal.me/bludit' @@ -14,20 +15,44 @@ class pluginLinks extends Plugin { 'label'=>'Links', 'jsondb'=>$jsondb ); + + $this->formButtons = false; } + // Method called when a POST request is sent public function post() { + // Get current jsondb value from database $jsondb = $this->getValue('jsondb', $unsanitized=false); + + // Convert JSON to Array $links = json_decode($jsondb, true); - $name = $_POST['linkName']; - $url = $_POST['linkURL']; + if( isset($_POST['deleteLink']) ) { + // Values from $_POST + $name = $_POST['deleteLink']; - $links[$url] = $name; + // Delete the link + unset($links[$name]); + } + elseif( isset($_POST['addLink']) ) { + // Values from $_POST + $name = $_POST['linkName']; + $url = $_POST['linkURL']; - $this->db['jsondb'] = json_encode($links); - $this->save(); + // Check empty string + if( empty($name) ) { return false; } + + // Add the link + $links[$name] = $url; + } + + // Sanitize the new values and replace the current values of the database + $this->db['label'] = Sanitize::html($_POST['label']); + $this->db['jsondb'] = Sanitize::html(json_encode($links)); + + // Save the database + return $this->save(); } // Method called on plugin settings on the admin area @@ -37,23 +62,54 @@ class pluginLinks extends Plugin { $html = '
'; $html .= ''; - $html .= ''; + $html .= ''; + $html .= ''.$Language->get('Title of the plugin for the sidebar').''; $html .= '
'; + $html .= '
'; + $html .= ''; + $html .= '
'; + + // New link, when the user click on save button this call the method post() + // and the new link is added to the database + $html .= ''.$Language->get('Add a new link').''; + + $html .= '
'; + $html .= ''; + $html .= ''; + $html .= '
'; + + $html .= '
'; + $html .= ''; + $html .= ''; + $html .= '
'; + + $html .= '
'; + $html .= ''; + $html .= '
'; + + $html .= ''.$Language->get('Links').''; + // Get the JSON DB, getValue() with the option unsanitized HTML code $jsondb = $this->getValue('jsondb', $unsanitized=false); $links = json_decode($jsondb, true); foreach($links as $name=>$url) { $html .= '
'; - $html .= ''; - $html .= ''; + $html .= ''; + $html .= ''; $html .= '
'; - } - $html .= '
'; - $html .= 'Nombre '; - $html .= '
URL '; - $html .= '
'; + $html .= '
'; + $html .= ''; + $html .= ''; + $html .= '
'; + + $html .= '
'; + $html .= ''; + $html .= '
'; + + $html .= '
'; + } return $html; }