Alternc  3.2
Alternc logiel libre pour l'h├ębergement
 All Data Structures Namespaces Files Functions Variables Pages
m_variables Class Reference

Persistent variable table. More...

Public Member Functions

 m_variables ()
 type $L_FQDN
 variable_init ()
 Load the persistent variable table.
 get_impersonated ($fqdn=null, $uid=null, $var=null)
 Return the var for a specific environnement :
 variable_init_maybe ($force=false)
 Initialize the global $conf array if necessary.
 variable_get ($name, $default=null, $createit_comment=null, $type=null)
 Return a persistent variable.
 variable_update_or_create ($var_name, $var_value, $strata=null, $strata_id=null, $var_id=null, $comment=null, $type=null)
 Create or update a variable.
 del ($id)
 Unset a persistent variable.
 display_valueraw_html ($v, $varname, $echo=true)
 echo HTML code to display a variable passed in parameters
 display_value_html ($tab, $strata, $id, $varname, $echo=TRUE)
 Display a variable if is set.
 variables_list_name ()
 return hashtable with variable_name => comment for all the vars
 variables_list ()
 return a multidimensionnal array used to build vars

Data Fields

 $strata_order = array('DEFAULT','GLOBAL','FQDN_CREATOR','FQDN','CREATOR','MEMBER','DOMAIN')
 $cache_variable_list = false
 $replace_array = array()

Private Member Functions

 variable_merge ($father, $son)
 used by get_impersonated to merge array.

Detailed Description

Persistent variable table.

Author
Drupal Developpement Team &view=auto

Definition at line 35 of file m_variables.php.

Member Function Documentation

del (   $id)

Unset a persistent variable.

Parameters
$nameThe name of the variable to undefine.

Definition at line 283 of file m_variables.php.

References $db, and variable_init_maybe().

{
global $db;
$result = $db->query("DELETE FROM `variable` WHERE id = '".intval($id)."'");
$this->variable_init_maybe(true);
return $result;
}
display_value_html (   $tab,
  $strata,
  $id,
  $varname,
  $echo = TRUE 
)

Display a variable if is set.

Parameters
type$tab
type$strata
type$id
type$varname
type$echo
Returns
string

Definition at line 367 of file m_variables.php.

References $tab, display_valueraw_html(), and isset.

{
$output = "";
if (isset($tab[$strata][$id][$varname]['value'])) {
$v = $tab[$strata][$id][$varname]['value'];
$output .= $this->display_valueraw_html($v, $varname);
} else {
$output .= "<em>"._("None defined")."</em>";
}
if( $echo){
echo $output;
}
return $output;
}
display_valueraw_html (   $v,
  $varname,
  $echo = true 
)

echo HTML code to display a variable passed in parameters

Parameters
type$v
type$varname
type$echo
Returns
type

Definition at line 298 of file m_variables.php.

References isset, and variables_list().

Referenced by display_value_html().

{
$output = "";
if (is_array($v)) {
if (empty($v)) {
$output .= "<em>"._("Empty array")."</em>";
} else {
$output .= "<ul>";
foreach ( $v as $k=>$l) {
$output .= "<li>";
if (! is_numeric($k)) {
if (is_null($varname)) {
$output .= "$k";
} else {
if ( !isset($this->variables_list()['DEFAULT'][null][$varname]['type'][$k]) || is_array( $this->variables_list()['DEFAULT'][null][$varname]['type'][$k] ) ) {
if (isset($this->variables_list()['DEFAULT'][null][$varname]['type'][$k]['desc'])) {
$output .= $this->variables_list()['DEFAULT'][null][$varname]['type'][$k]['desc'];
} else {
$output .= $k;
}
} else {
$output .= $this->variables_list()['DEFAULT'][null][$varname]['type'][$k];
}
}
} else {
if (isset($this->variables_list()['DEFAULT'][null][$varname]['type'][$k]['desc'] )) {
$output .= $this->variables_list()['DEFAULT'][null][$varname]['type'][$k]['desc'];
}
}
if (is_array($l)) {
$output .= "<ul>";
foreach ($l as $m => $n ) {
$output .= "<li>";
if ( is_numeric($m)) {
$output .= "$m";
} else {
$output .= $this->variables_list()['DEFAULT'][null][$varname]['type'][$k][$m]['desc'];
}
$output .= " => $n";
$output .= "</li>";
}
$output .= "</ul>";
} else {
$output .= " => $l";
}
$output .= "</li>";
}
$output .= "</ul>";
} // empty $v
} else if (empty($v) && $v != '0') {
$output .= "<em>"._("Empty")."</em>";
} else {
$output .= $v;
}
if( $echo ){
echo $output;
}
return $output;
}
get_impersonated (   $fqdn = null,
  $uid = null,
  $var = null 
)

Return the var for a specific environnement :

  • logged via $fqdn url
  • the user is $uid
  • $var if we want only 1 var instead of all of them

If $fqdn and $uid aren't specified, return the default value

type $db type $err

Parameters
type$fqdn
type$uid
type$var
Returns
array

Definition at line 110 of file m_variables.php.

References $creator, $db, $err, $uid, $variables, m_mem\get_creator_by_uid(), m_dom\get_sub_domain_id_and_member_by_name(), isset, variable_merge(), and variables_list().

Referenced by variable_init().

{
global $db, $err;
$arr_var=$this->variables_list();
// Get some vars we are going to need.
if ($fqdn != NULL) {
$sub_infos=m_dom::get_sub_domain_id_and_member_by_name( strtolower($fqdn) );
} else {
$sub_infos=false;
}
if ( $uid != NULL ) {
} else {
$creator=false;
}
$variables = array();
// Browse the array in the specific order of the strata
foreach ( $this->strata_order as $strata) {
if (! isset($arr_var[$strata]) || !is_array($arr_var[$strata])) continue;
switch($strata) {
case 'DEFAULT':
// $variables = $this->variable_merge(array(),$arr_var['DEFAULT'][NULL]);
$variablesList = current($arr_var["DEFAULT"]);
$variables = $this->variable_merge(array(),$variablesList);
break;
case 'GLOBAL':
$variables = $this->variable_merge($variables, $arr_var['GLOBAL'][NULL]);
break;
case 'FQDN_CREATOR':
if ( is_array($sub_infos) && isset($arr_var['FQDN_CREATOR'][$sub_infos['member_id']]) && is_array($arr_var['FQDN_CREATOR'][$sub_infos['member_id']])) {
$variables = $this->variable_merge($variables, $arr_var['FQDN_CREATOR'][$sub_infos['member_id']]);
}
break;
case 'FQDN':
if ( is_array($sub_infos) && isset($arr_var['FQDN'][$sub_infos['sub_id']]) && is_array($arr_var['FQDN'][$sub_infos['sub_id']])) {
$variables = $this->variable_merge($variables, $arr_var['FQDN'][$sub_infos['sub_id']]);
}
break;
case 'CREATOR':
if ( $creator && isset($arr_var['CREATOR'][$creator]) && is_array($arr_var['CREATOR'][$creator])) {
$variables = $this->variable_merge($variables, $arr_var['CREATOR'][$creator] );
}
break;
case 'MEMBER':
if ( $uid && isset($arr_var['MEMBER'][$uid]) && is_array($arr_var['MEMBER'][$uid])) {
$variables = $this->variable_merge($variables, $arr_var['MEMBER'][$uid] );
}
break;
case 'DOMAIN':
//FIXME TODO
break;
} //switch
} //foreach
// Replace needed vars
foreach ($variables as $vv => $hh) {
if (!isset($hh['value'])) {
continue;
}
$variables[$vv]['value'] = strtr($hh['value'], $this->replace_array );
}
if ($var && isset($variables[$var])) {
return $variables[$var];
} else {
return $variables;
}
}

type $L_FQDN

Definition at line 44 of file m_variables.php.

{
global $L_FQDN;
$this->replace_array = array(
"%%FQDN%%"=> $L_FQDN,
);
}
variable_get (   $name,
  $default = null,
  $createit_comment = null,
  $type = null 
)

Return a persistent variable.

Parameters
$nameThe name of the variable to return.
$defaultThe default value to use if this variable has never been set.
$createit_commentIf variable doesn't exist, create it with the default value and createit_comment value as comment
Returns
The value of the variable. $conf A cache of the configuration.

Definition at line 213 of file m_variables.php.

References $conf, isset, variable_init_maybe(), and variable_update_or_create().

{
global $conf;
if (isset($conf[$name])) {
return $conf[$name]['value'];
} elseif (!is_null($createit_comment)) {
$this->variable_update_or_create($name, $default, 'DEFAULT', 'null', 'null', $createit_comment, $type);
}
return $default;
}
variable_init ( )

Load the persistent variable table.

The variable table is composed of values that have been saved in the table with variable_set() as well as those explicitly specified in the configuration file.

int $cuid

Returns
array

Definition at line 78 of file m_variables.php.

References $cuid, $host, get_impersonated(), and isset.

Referenced by variable_init_maybe().

{
global $cuid;
if ($cuid > 1999) {
$mid = $cuid;
} else {
$mid = null;
}
// In case we launch it in a script, there is no $_SERVER
if (isset($_SERVER['HTTP_HOST'])) {
$host=$_SERVER['HTTP_HOST'];
} else {
$host=null;
}
return $this->get_impersonated($host, $mid);
}
variable_init_maybe (   $force = false)

Initialize the global $conf array if necessary.

$conf the global conf array variable_init()

Definition at line 190 of file m_variables.php.

References $conf, $force, isset, and variable_init().

Referenced by del(), variable_get(), and variable_update_or_create().

{
global $conf;
if ($force || !isset($conf)) {
$this->cache_variable_list = false;
$conf = $this->variable_init();
}
}
variable_merge (   $father,
  $son 
)
private

used by get_impersonated to merge array.

Son value overwrite father's value

Parameters
array$father
array$son
Returns
array

Definition at line 60 of file m_variables.php.

Referenced by get_impersonated().

{
if (! is_array($son)) return $father;
foreach ($son as $k=>$v) {
$father[$k] = $v;
}
return $father;
}
variable_update_or_create (   $var_name,
  $var_value,
  $strata = null,
  $strata_id = null,
  $var_id = null,
  $comment = null,
  $type = null 
)

Create or update a variable.

type $db type $err

Parameters
type$var_name
type$var_value
type$strata
null$strata_id
null$var_id
type$comment
type$type
Returns
boolean

Definition at line 240 of file m_variables.php.

References $db, $err, and variable_init_maybe().

Referenced by variable_get().

{
global $db, $err;
$err->log('variable', 'variable_update_or_create');
if ( strtolower($var_id) == 'null' ) $var_id = null;
if ( strtolower($strata_id) == 'null' ) $strata_id = null;
if (is_object($type) || is_array($type)) {
$type = serialize($type);
}
if (is_object($var_value) || is_array($var_value)) {
$var_value = serialize($var_value);
}
if ( ! is_null($var_id) ) {
$sql="UPDATE variable SET value='".mysql_real_escape_string($var_value)."' WHERE id = ".intval($var_id);
} else {
if ( empty($strata) ) {
$err->raise('variables', _("Err: Missing strata when creating var"));
return false;
}
$sql="INSERT INTO
variable (name, value, strata, strata_id, comment, type)
VALUES (
'".mysql_real_escape_string($var_name)."',
'".mysql_real_escape_string($var_value)."',
'".mysql_real_escape_string($strata)."',
".( is_null($strata_id)?'NULL':"'".mysql_real_escape_string($strata_id)."'").",
'".mysql_real_escape_string($comment)."',
'".mysql_real_escape_string($type)."' );";
}
$db->query("$sql");
$this->variable_init_maybe(true);
return true;
}
variables_list ( )

return a multidimensionnal array used to build vars

type $db

Returns
type

Definition at line 408 of file m_variables.php.

References $cache_variable_list, $db, and $value.

Referenced by display_valueraw_html(), and get_impersonated().

{
global $db;
if ( ! $this->cache_variable_list ) {
$result = $db->query('SELECT * FROM `variable`');
$arr_var=array();
while ($db->next_record($result)) {
// Unserialize value if needed
if ( ($value = @unserialize($db->f('value'))) === FALSE) {
$value=$db->f('value');
}
if ( ($type = @unserialize($db->f('type'))) === FALSE) {
$type=$db->f('type');
}
$arr_var[$db->f('strata')][$db->f('strata_id')][$db->f('name')] = array('id'=>$db->f('id') ,'name'=>$db->f('name'), 'value'=>$value, 'comment'=>$db->f('comment'), 'type'=>$type);
}
$this->cache_variable_list = $arr_var;
}
}
variables_list_name ( )

return hashtable with variable_name => comment for all the vars

type $db

Returns
type

Definition at line 387 of file m_variables.php.

References $db, $t, and isset.

{
global $db;
$result = $db->query('SELECT name, comment FROM `variable` order by name');
$t=array();
while ($db->next_record($result)) {
$tname = $db->f('name');
// If not listed of if listed comment is shorter
if ( ! isset( $t[$tname] ) || strlen($t[$tname]) < $db->f('comment') ) {
$t[$db->f('name')] = $db->f('comment');
}
}
return $t;
}

Field Documentation

$cache_variable_list = false

Definition at line 37 of file m_variables.php.

Referenced by variables_list().

$replace_array = array()

Definition at line 38 of file m_variables.php.

$strata_order = array('DEFAULT','GLOBAL','FQDN_CREATOR','FQDN','CREATOR','MEMBER','DOMAIN')

Definition at line 36 of file m_variables.php.


The documentation for this class was generated from the following file: