Difference between revisions of "Configuration Class"

From GeeklogWiki
Jump to: navigation, search
(function add())
 
(8 intermediate revisions by 3 users not shown)
Line 1: Line 1:
== Adding Configuration Paramaters ==
 
 
To add configuration settings to the config, several files must be altered.
 
 
First, admin/install/config-install.php must be altered by adding a new $c->add() line. This will also involves adding entries to the core config lang arrays in the language files.
 
 
Then, the same $c->add() line must be added to the function create_ConfValues() in the sql/updates/m*sql_1.x_to_1.x.php files.
 
 
 
== Function Reference ==
 
== Function Reference ==
  
'''public add()'''
+
===Controlling specific groups and values===
 +
====function add()====
  
 
This function will add a variable to the database
 
This function will add a variable to the database
Line 40: Line 33:
 
  boolean ''$set''             
 
  boolean ''$set''             
 
   Whether or not this parameter is set (defaults to TRUE)
 
   Whether or not this parameter is set (defaults to TRUE)
 +
string  ''$group''
 +
  The group (or plugin) for the config option (defaults to "Core")
 +
int $tab
 +
  the tab to display the variable under - the integer is the index of the lang array for the tab
 +
 +
===== Adding Plugins' Configuration Parameters =====
 +
See [[PluginConfiguration|Configuration Class in plugins]].
 +
 +
===== Adding Global Configuration Parameters =====
  
'''public static create()'''
+
To add global configuration settings to the config, several files must be altered.
  
This function will return an instance of the config class. If an instance with the given group/reference name does not exist, then it will create a new one. This function insures that there is only one instance for a given group name.
+
First, admin/install/config-install.php must be altered by adding a new $c->add() line. This will also involve adding entries to the core config lang arrays in the language files.
  
Parameters:
+
Then, the same $c->add() line must be added to the function create_ConfValues() in the sql/updates/m*sql_1.x_to_1.x.php files.
string ''group_name''
 
    This is simply the group name that this config object will control - for the main gl settings this is 'Core'
 
  
'''public set()'''
+
====function set()====
  
 
This function sets a configuration variable to a value in the database and in the current array. If the variable does not already exist, nothing will happen.
 
This function sets a configuration variable to a value in the database and in the current array. If the variable does not already exist, nothing will happen.
Line 58: Line 58:
 
  mixed ''value''
 
  mixed ''value''
 
     This is the new value for the variable.
 
     This is the new value for the variable.
 +
string  ''$group''
 +
    The group (or plugin) for the config option (defaults to "Core")
 +
 +
====function del()====
 +
 +
This function deletes a configuration variable. (If the variable does not already exist, nothing will happen?)
 +
 +
Parameters:
 +
string ''variable_name''
 +
    This is the name of the variable to delete
 +
string  ''$group''
 +
    The group (or plugin) for the config option (defaults to <nowiki>''</nowiki>)
 +
 +
====Deleting a whole group====
 +
There's no internal command to delete a whole group. Just use:
 +
DB_query ("DELETE FROM {$_TABLES['conf_values']}
 +
WHERE group_name = '$group_name'");
 +
Note that it's done automatically for bundled plugins or other plugins that use "function plugin_'''autouninstall'''_PLUGINNAME" instead of "function plugin_'''uninstall'''_PLUGINNAME".
 +
 +
===Controlling the overall config===
 +
====function static get_instance()====
 +
 +
This function will return an instance of the config class. If an instance does not exist, then it will create a new one. Only one instance will ever exist.
 +
 +
Parameters:
 +
string ''group_name''
 +
    This is simply the group name that this config object will control -
 +
for the main gl settings this is 'Core'
 +
 +
====function &get_config()====
 +
This returns the config array for the given group.
 +
 +
Parameters:
 +
string ''$group''
 +
    The group (or plugin) for the config array
  
'''public &init_config()'''
+
====function config()====
  
This function returns a reference to the configuration variables array (e.g. $_CONF)
+
This function returns a reference to the core config array.
  
'''public set_configfile()'''
+
====function &init_config()====
 +
 
 +
This function returns a reference to the configuration variables array (e.g. $_CONF) and initializes the core config values.
 +
 
 +
====function set_configfile()====
  
 
This function sets the secure configuration file (database related settings) for the configuration class to read. This should only need to be called for the 'Core' group. It also ''must'' be called before load_baseconfig()
 
This function sets the secure configuration file (database related settings) for the configuration class to read. This should only need to be called for the 'Core' group. It also ''must'' be called before load_baseconfig()
Line 71: Line 110:
 
     This is the path and name of the secure configuration file.
 
     This is the path and name of the secure configuration file.
  
'''public load_baseconfig()'''
+
====function load_baseconfig()====
  
 
This function reads the secure configuration file and loads lib-database.php. This needs to be called in the 'Core' group before &init_config() can be used. It only needs to be called once.
 
This function reads the secure configuration file and loads lib-database.php. This needs to be called in the 'Core' group before &init_config() can be used. It only needs to be called once.
 +
 +
 +
[[Category:Development]]

Latest revision as of 13:49, 19 August 2011

Function Reference

Controlling specific groups and values

function add()

This function will add a variable to the database

Parameters:

string $param_name
  name of the parameter to add
mixed  $default_value    
  the default value of the parameter (also will be the initial value)
string $type             
  This is the type of the configuration variable
  If the configuration variable is an array, prefix this string with
      '@' if the administrator should NOT be able to add or remove keys
      '*' if the administrator should be able to add named keys
      '%' if the administrator should be able to add numbered keys
  These symbols can be repeated like such: @@text if the configuration variable is an array of arrays of text.
  The base variable types are:
      'text'    textbox displayed     string  value stored
      'select'  selectbox displayed   string  value stored
      'hidden'  no display            string  value stored
int $subgroup
  subgroup of the variable - the integer is the index of the lang array for the subgroup
int $fieldset
  the fieldset to display the variable under - the integer is the index of the lang array for the fieldset
int  $selection_array
  These are the possible selections for the 'select' type. This MUST be passed if you use the 'select' type - otherwise it will just display a textbox (defaults to NULL) - the integer is the index of the lang array for the selection array 
int    $sort
  sort rank on the user interface (ascending, defaults to 0)
boolean $set            
  Whether or not this parameter is set (defaults to TRUE)
string  $group
  The group (or plugin) for the config option (defaults to "Core")

int $tab

 the tab to display the variable under - the integer is the index of the lang array for the tab
Adding Plugins' Configuration Parameters

See Configuration Class in plugins.

Adding Global Configuration Parameters

To add global configuration settings to the config, several files must be altered.

First, admin/install/config-install.php must be altered by adding a new $c->add() line. This will also involve adding entries to the core config lang arrays in the language files.

Then, the same $c->add() line must be added to the function create_ConfValues() in the sql/updates/m*sql_1.x_to_1.x.php files.

function set()

This function sets a configuration variable to a value in the database and in the current array. If the variable does not already exist, nothing will happen.

Parameters:

string variable_name
   This is the name of the variable to change
mixed value
   This is the new value for the variable.
string  $group
   The group (or plugin) for the config option (defaults to "Core")

function del()

This function deletes a configuration variable. (If the variable does not already exist, nothing will happen?)

Parameters:

string variable_name
   This is the name of the variable to delete
string  $group
   The group (or plugin) for the config option (defaults to '')

Deleting a whole group

There's no internal command to delete a whole group. Just use:

DB_query ("DELETE FROM {$_TABLES['conf_values']}
WHERE group_name = '$group_name'");

Note that it's done automatically for bundled plugins or other plugins that use "function plugin_autouninstall_PLUGINNAME" instead of "function plugin_uninstall_PLUGINNAME".

Controlling the overall config

function static get_instance()

This function will return an instance of the config class. If an instance does not exist, then it will create a new one. Only one instance will ever exist.

Parameters:

string group_name
   This is simply the group name that this config object will control -
for the main gl settings this is 'Core'

function &get_config()

This returns the config array for the given group.

Parameters:

string $group
   The group (or plugin) for the config array

function config()

This function returns a reference to the core config array.

function &init_config()

This function returns a reference to the configuration variables array (e.g. $_CONF) and initializes the core config values.

function set_configfile()

This function sets the secure configuration file (database related settings) for the configuration class to read. This should only need to be called for the 'Core' group. It also must be called before load_baseconfig()

Parameters:

string $sf
   This is the path and name of the secure configuration file.

function load_baseconfig()

This function reads the secure configuration file and loads lib-database.php. This needs to be called in the 'Core' group before &init_config() can be used. It only needs to be called once.