Browse Source

Use api_get_plugin_setting

jmontoyaa 8 years ago
parent
commit
fc556e75c4

+ 17 - 5
main/inc/lib/api.lib.php

@@ -2345,11 +2345,23 @@ function api_get_setting($variable, $subVariable = '')
  */
 function api_get_plugin_setting($plugin, $variable)
 {
-    return null;
-    $variableName = $plugin.'_'.$variable;
-    $result = api_get_setting($variableName);
-    if (isset($result[$plugin])) {
-        return $result[$plugin];
+    $params = [
+        'category = ? AND subkey = ? AND variable = ?' => [
+            'Plugins',
+            $plugin,
+            $variable,
+        ],
+    ];
+    $table = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
+    $result = Database::select(
+        'selected_value',
+        $table,
+        array('where' => $params),
+        'one'
+    );
+    if ($result) {
+        $result = $result['selected_value'];
+        return $result;
     }
 
     return null;

+ 8 - 10
plugin/add_cas_login_button/plugin.php

@@ -10,14 +10,14 @@
  */
 
 //the plugin title
-$plugin_info['title']      = 'Add a button to login using CAS';
+$plugin_info['title'] = 'Add a button to login using CAS';
 
 //the comments that go with the plugin
-$plugin_info['comment']     = "If CAS is activated, this plugin add a text and a button on the login page to login with CAS. Configure plugin to add title, comment and logo.";
+$plugin_info['comment'] = "If CAS is activated, this plugin add a text and a button on the login page to login with CAS. Configure plugin to add title, comment and logo.";
 //the plugin version
-$plugin_info['version']     = '1.0';
+$plugin_info['version'] = '1.0';
 //the plugin author
-$plugin_info['author']      = 'Hubert Borderiou';
+$plugin_info['author'] = 'Hubert Borderiou';
 
 //the plugin configuration
 $form = new FormValidator('add_cas_button_form');
@@ -26,13 +26,11 @@ $form->addElement('text', 'cas_button_comment', 'CAS connexion description', '')
 $form->addElement('text', 'cas_image_url', 'Logo URL if any (image, 50px height)');
 $form->addButtonSave(get_lang('Save'), 'submit_button');
 //get default value for form
-$tab_default_add_cas_login_button_cas_button_label = api_get_setting('add_cas_login_button_cas_button_label');
-$tab_default_add_cas_login_button_cas_button_comment = api_get_setting('add_cas_login_button_cas_button_comment');
-$tab_default_add_cas_login_button_cas_image_url = api_get_setting('add_cas_login_button_cas_image_url');
+
 $defaults = array();
-$defaults['cas_button_label'] = $tab_default_add_cas_login_button_cas_button_label['add_cas_login_button'];
-$defaults['cas_button_comment'] = $tab_default_add_cas_login_button_cas_button_comment['add_cas_login_button'];
-$defaults['cas_image_url'] = $tab_default_add_cas_login_button_cas_image_url['add_cas_login_button'];
+$defaults['cas_button_label'] = api_get_plugin_setting('add_cas_login_button', 'add_cas_login_button_cas_button_label');
+$defaults['cas_button_comment'] = api_get_plugin_setting('add_cas_login_button','add_cas_login_button_cas_button_comment');
+$defaults['cas_image_url'] = api_get_plugin_setting('add_cas_login_button', 'add_cas_login_button_cas_image_url');
 $form->setDefaults($defaults);
 //display form
 $plugin_info['settings_form'] = $form;

+ 11 - 9
plugin/add_shibboleth_login_button/plugin.php

@@ -1,6 +1,7 @@
 <?php
 /**
- * This script is a configuration file for the date plugin. You can use it as a master for other platform plugins (course plugins are slightly different).
+ * This script is a configuration file for the date plugin.
+ * You can use it as a master for other platform plugins (course plugins are slightly different).
  * These settings will be used in the administration interface for plugins (Chamilo configuration settings->Plugins)
  * @package chamilo.plugin
  * @author Julio Montoya <gugli100@gmail.com>
@@ -39,20 +40,21 @@ $form->addElement(
     'Logo URL if any (image, 50px height)'
 );
 $form->addButtonSave(get_lang('Save'), 'submit_button');
-//get default value for form
-$tab_default_add_shibboleth_login_button_shibboleth_button_label = api_get_setting(
+$tab_default_add_shibboleth_login_button_shibboleth_image_url =
+$defaults = array();
+$defaults['shibboleth_button_label'] = api_get_plugin_setting(
+    'add_shibboleth_login_button',
     'add_shibboleth_login_button_shibboleth_button_label'
 );
-$tab_default_add_shibboleth_login_button_shibboleth_button_comment = api_get_setting(
+$defaults['shibboleth_button_comment'] = api_get_plugin_setting(
+    'add_shibboleth_login_button',
     'add_shibboleth_login_button_shibboleth_button_comment'
 );
-$tab_default_add_shibboleth_login_button_shibboleth_image_url = api_get_setting(
+$defaults['shibboleth_image_url'] = api_get_plugin_setting(
+    'add_shibboleth_login_button',
     'add_shibboleth_login_button_shibboleth_image_url'
 );
-$defaults = array();
-$defaults['shibboleth_button_label'] = $tab_default_add_shibboleth_login_button_shibboleth_button_label['add_shibboleth_login_button'];
-$defaults['shibboleth_button_comment'] = $tab_default_add_shibboleth_login_button_shibboleth_button_comment['add_shibboleth_login_button'];
-$defaults['shibboleth_image_url'] = $tab_default_add_shibboleth_login_button_shibboleth_image_url['add_shibboleth_login_button'];
+
 $form->setDefaults($defaults);
 //display form
 $plugin_info['settings_form'] = $form;

+ 1 - 1
plugin/advanced_subscription/src/AdvancedSubscriptionPlugin.php

@@ -64,7 +64,7 @@ class AdvancedSubscriptionPlugin extends Plugin implements HookPluginInterface
      */
     public function uninstall()
     {
-        $setting = api_get_setting('advanced_subscription');
+        $setting = api_get_plugin_setting('advanced_subscription', 'status');
         if (!empty($setting)) {
             $this->uninstallHook();
             // Note: Keeping area field data is intended so it will not be removed

+ 1 - 1
plugin/bbb/lib/bbb.lib.php

@@ -82,7 +82,7 @@ class bbb
             if ($this->groupSupport) {
 
                 // Platform check
-                $bbbSetting = api_get_setting('bbb_enable_conference_in_course_groups');
+                $bbbSetting = api_get_plugin_setting('bbb', 'bbb_enable_conference_in_course_groups');
                 $bbbSetting = isset($bbbSetting['bbb']) ? $bbbSetting['bbb'] === 'true' : false;
 
                 if ($bbbSetting) {

+ 7 - 7
plugin/formLogin_hide_unhide/plugin.php

@@ -1,6 +1,7 @@
 <?php
 /**
- * This script is a configuration file for the date plugin. You can use it as a master for other platform plugins (course plugins are slightly different).
+ * This script is a configuration file for the date plugin.
+ * You can use it as a master for other platform plugins (course plugins are slightly different).
  * These settings will be used in the administration interface for plugins (Chamilo configuration settings->Plugins)
  * @package chamilo.plugin
  * @author Julio Montoya <gugli100@gmail.com>
@@ -10,22 +11,21 @@
  */
 
 //the plugin title
-$plugin_info['title']      = 'Hide/Unhide the Login/Password default form';
+$plugin_info['title'] = 'Hide/Unhide the Login/Password default form';
 
 //the comments that go with the plugin
-$plugin_info['comment']     = "If you use another way of authentication than local, you may want to hide the Login/Password default Form to avoid users mistakes. This plugin replace the Login/Password form with a text that unhide the Login/Password form if you click on it.";
+$plugin_info['comment'] = "If you use another way of authentication than local, you may want to hide the Login/Password default Form to avoid users mistakes. This plugin replace the Login/Password form with a text that unhide the Login/Password form if you click on it.";
 //the plugin version
-$plugin_info['version']     = '1.0';
+$plugin_info['version'] = '1.0';
 //the plugin author
-$plugin_info['author']      = 'Hubert Borderiou';
+$plugin_info['author'] = 'Hubert Borderiou';
 
 //the plugin configuration
 $form = new FormValidator('add_cas_button_form');
 $form->addElement('text', 'label', 'Text label', '');
 //get default value
-$tab_default_formLogin_hide_unhide_label = api_get_setting('formLogin_hide_unhide_label');
 $defaults = array();
-$defaults['label'] = $tab_default_formLogin_hide_unhide_label['formLogin_hide_unhide'];
+$defaults['label'] = api_get_plugin_setting('formLogin_hide_unhide', 'formLogin_hide_unhide_label');
 $form->setDefaults($defaults);
 //display form
 $plugin_info['settings_form'] = $form;

+ 0 - 13
plugin/hello_world/install.php

@@ -1,14 +1 @@
 <?php
-/* PHP code to install the plugin 
- * For example:
- * 
-    // To query something to the database
-  
-    $table = Database::get_main_table(TABLE_MAIN_USER); // TABLE_MAIN_USER is a constant check the main/inc/database.constants.inc.php
-    $sql = "SELECT firstname, lastname FROM $table_users ";
-    $users = Database::query($sql); 
-  
-    You can also use the Chamilo classes 
-    $users = UserManager::get_user_list();    
-    
- */ 

+ 9 - 5
plugin/hello_world/plugin.php

@@ -13,13 +13,13 @@
 /* Plugin config */
 
 //the plugin title
-$plugin_info['title']       = 'Hello world';
+$plugin_info['title'] = 'Hello world';
 //the comments that go with the plugin
-$plugin_info['comment']     = "Shows a hello world message";
+$plugin_info['comment'] = "Shows a hello world message";
 //the plugin version
-$plugin_info['version']     = '1.0';
+$plugin_info['version'] = '1.0';
 //the plugin author
-$plugin_info['author']      = 'Julio Montoya';
+$plugin_info['author'] = 'Julio Montoya';
 
 /* Plugin optional settings */
 
@@ -31,7 +31,11 @@ $plugin_info['author']      = 'Julio Montoya';
 $form = new FormValidator('hello_world_form');
 
 //A simple select
-$options = array('hello_world' => 'Hello World', 'hello' =>'Hello', 'hi' =>'Hi!');
+$options = array(
+    'hello_world' => 'Hello World',
+    'hello' => 'Hello',
+    'hi' => 'Hi!',
+);
 $form->addElement('select', 'show_type', 'Hello world types', $options);
 $form->addButtonSave(get_lang('Save'), 'submit_button');
 

+ 0 - 0
plugin/hello_world/readme.txt → plugin/hello_world/readme.md


+ 1 - 1
plugin/pens/lib/PENSPlugin.php

@@ -55,7 +55,7 @@ class PENSPlugin extends Plugin implements HookPluginInterface
      */
     public function uninstall()
     {
-        $setting = api_get_setting('plugin_pens');
+        $setting = api_get_plugin_setting('pens', 'plugin_pens');
         if (!empty($setting)) {
             $this->uninstallHook();
             // Note: Keeping area field data is intended so it will not be removed

+ 4 - 4
plugin/show_regions/plugin.php

@@ -10,11 +10,11 @@
  */
 
 //the plugin title
-$plugin_info['title']       = 'Show regions';
+$plugin_info['title'] = 'Show regions';
 //the comments that go with the plugin
-$plugin_info['comment']     = "This is useful when trying to find the Chamilo regions, (<strong>only the admin </strong>can view this plugin). You have to activate all the items in the Regions area";
+$plugin_info['comment'] = "This is useful when trying to find the Chamilo regions, (<strong>only the admin </strong>can view this plugin). You have to activate all the items in the Regions area";
 //the plugin version
-$plugin_info['version']     = '1.0';
+$plugin_info['version'] = '1.0';
 //the plugin author
-$plugin_info['author']      = 'Julio Montoya';
+$plugin_info['author'] = 'Julio Montoya';
 

+ 1 - 8
plugin/text/plugin.php

@@ -26,14 +26,7 @@ $form = new FormValidator('text_form');
 $form->addTextarea('content', get_lang('Content'));
 $form->addButtonSave(get_lang('Save'), 'submit_button');
 
-$content = '';
-$setting = api_get_setting('text_content');
-
-if (!empty($setting) && is_array($setting)) {
-    if (isset($setting['text'])) {
-        $content = $setting['text'];
-    }
-}
+$content = api_get_plugin_setting('text', 'text_content');
 
 $form->setDefaults(array('content' => $content));