Factorise code variables

This commit is contained in:
Alan Garcia 2012-10-18 09:03:26 +00:00
parent 69d8e4f408
commit a2503e395d
2 changed files with 14 additions and 13 deletions

View File

@ -35,16 +35,8 @@ class m_piwik {
/** Constructor /** Constructor
*/ */
function m_piwik() { function m_piwik() {
$this->piwik_server_uri=variable_get('piwik_server_uri',null); $this->piwik_server_uri=variable_get('piwik_server_uri',null,'Remote Piwik server uri');
if (is_null($this->piwik_server_uri)) { // if not configuration var, setup one (with a default value) $this->piwik_admin_token=variable_get('piwik_admin_token',null,'Remote Piwik super-admin token');
variable_set('piwik_server_uri','','Remote Piwik server uri');
$this->piwik_server_uri='';
}
$this->piwik_admin_token=variable_get('piwik_admin_token',null);
if (is_null($this->piwik_admin_token)) { // if not configuration var, setup one (with a default value)
variable_set('piwik_admin_token','','Remote Piwik super-admin token');
$this->piwik_admin_token='';
}
} }
/* ----------------------------------------------------------------- */ /* ----------------------------------------------------------------- */

View File

@ -78,16 +78,25 @@ function variable_init_maybe() {
* The name of the variable to return. * The name of the variable to return.
* @param $default * @param $default
* The default value to use if this variable has never been set. * The default value to use if this variable has never been set.
* @param $createit_comment
* If variable doesn't exist, create it with the default value
* and createit_comment value as comment
* @return * @return
* The value of the variable. * The value of the variable.
* @global $conf * @global $conf
* A cache of the configuration. * A cache of the configuration.
*/ */
function variable_get($name, $default = null) { function variable_get($name, $default = null, $createit_comment = null) {
global $conf; global $conf;
variable_init_maybe(); variable_init_maybe();
return isset($conf[$name]) ? $conf[$name] : $default;
if (isset($conf[$name])) {
return $conf[$name];
} elseif (!is_null($createit_comment)) {
variable_set($name, $default, $createit_comment);
}
return $default;
} }
/** /**
@ -116,7 +125,7 @@ function variable_set($name, $value, $comment=null) {
$db->query("$query"); $db->query("$query");
variable_init_maybe(); variable_init();
} }
/** /**