* @version $Id$
* @access public
* @license http://opensource.org/licenses/gpl-3.0.html
* Configuration Management
*/
include_once('system/afiles/class.afiles.php');
include_once('../lib/lib_common.php');
// should be a singleton
// but we are getting some issues converting it
// when using the installer
class config_file {
var $file_config = "config.ini"; // fichier define_config
var $file_release = "release.ini"; // fichier define_release
var $extra_configfile = false;
var $section_main = "config";
var $section_theme = "theme"; // section theme dans le fichier de configuration config
var $section_database = "database"; // section database dans le fichier de configuration define_release
var $config_path = '../config/';
var $ini_path = '../config/';
var $backup_config_path = '../tmp/backup/config/';
var $authorized_release_sections = array ('LANGUAGE_SETTINGS','NOTIFICATION_SETTINGS','LOCALES_SETTINGS','MODULES_SETTINGS','DEBUG_SETTINGS', 'COMMENT_SETTINGS', 'SYSTEM_SETTINGS', 'SERVER_SETTINGS','MAIL_SETTINGS','MAIL_INFORMATIONS', 'SUPPORT_SETTINGS','LOGS_SETTINGS','MISC_HIDDEN_SETTINGS'); //sections autorisées dans le fichier release
var $authorized_db_sections = array ('DATABASE_SETTINGS'); //sections autorisées dans le fichier release
var $authorized_theme_sections = array ('THEME_SETTINGS'); //sections autorisées dans le fichier release
var $php_extension = ".php";
var $config_params;
var $release_params;
var $a_file;
var $theme_settings='THEME_SETTINGS';
var $theme_public='THEME_PUBLIC';
var $theme_list_public='THEME_LIST_PUBLIC';
var $theme_admin='THEME_ADMIN';
var $theme_list_admin='THEME_LIST_ADMIN';
protected $dispatcher = null;
/**
* config_file::__construct()
* constructeur de classe
* @access public
* @return void
*/
public function __construct( $extraconfigfile = false)
{
$this->a_file=new afiles;
$this->dispatcher = $GLOBALS['dispatcher'];
if(is_string($extraconfigfile)) {
$this->extra_configfile = $extraconfigfile;
}
//charge les paramètres et les place en constante globale par define
$this->load_config_ini_file();
$this->load_release_ini_file();
}
/**
* config_file::init()
* charge les paramètres des fichiers ini et les place en constante globale avec define
* @access public
* @param void
* @return void
*/
public function init()
{
// Notify the beginning of the current method
$this->dispatcher->notify(new sfEvent($this, 'config.init'));
foreach ($this->config_params as $section => $existing_params)
{
foreach ($existing_params as $existing_param => $existing_value)
{
if(!defined($existing_param))
{
if(is_numeric($existing_value))
{
$existing_value=$this->convert_type($existing_value);
}
define($existing_param,$existing_value);
}
}
}
foreach ($this->release_params as $section => $existing_params)
{
foreach ($existing_params as $existing_param => $existing_value)
{
if(!defined($existing_param))
{
if(is_numeric($existing_value))
{
$existing_value=$this->convert_type($existing_value);
}
define($existing_param,$existing_value);
}
}
}
}
/**
* config_file::rmParams()
* Supprime un paramètre dans la section souhaitée
* @access public
* @param array $array new params - format : array( array('sectionName','parameterName'), array('sectionName','parameterName'), ...);
* @return bool
*/
public function rmParams($array)
{
// Filter data event + return value
$r = $this->dispatcher->filter(new sfEvent($this, 'config.rmParams', array('data' => $array)), $array);
$array = $r->getReturnValue();
//parse du tableau des paramètres
// ajoute les paramètres de post
foreach ($array as $key => $param)
{
// echo '
['.$param[0].']['.$param[1].']
';
if(isset($this->config_params[$param[0]][$param[1]])) unset($this->config_params[$param[0]][$param[1]]);
}
return true;
}
/**
* config_file::addParams()
* Ajoute un paramètre dans la section souhaitée
* @access public
* @param array $array new params - format : array( array('sectionName','parameterName','parameterValue'), array('sectionName','parameterName','parameterValue'), ...);
* @return bool
*/
public function addParams($array)
{
// Filter data event + return value
$r = $this->dispatcher->filter(new sfEvent($this, 'config.addParams', array('data' => $array)), $array);
$array = $r->getReturnValue();
//parse du tableau des paramètres
// ajoute les paramètres de post
foreach ($array as $key => $param)
{
$this->config_params[$param[0]][$param[1]] = $this->strip_ini_char($param[2]);
}
return true;
}
/**
* config_file::setParams()
* Ecrase les valeurs contenues dans le tableau stocké dans l'attribut $this->config_params
* pour mise à jour des valeurs
* @access public
* @param array $array new values to override to params
* @return void
*/
public function setParams($array)
{
// Filter data event + return value
$r = $this->dispatcher->filter(new sfEvent($this, 'config.set_params', array('data' => $array)), $array);
$array = $r->getReturnValue();
//parse du tableau des paramètres
// ajoute les paramètres de post
foreach ($array as $key => $value)
{
foreach ($this->config_params as $section => $existing_params)
{
foreach ($existing_params as $existing_param => $existing_value)
{
// la clé existe dans le tableau de cache release_params, on insère la valeur dans ce tableau
if($existing_param == $key) $this->config_params[$section][$key]=$this->strip_ini_char($value);
// if($existing_param == $key) _debug($this->config_params[$section][$key] . " > " . $this->strip_ini_char($value) , 'theme-debug');
}
}
}
return true;
}
/**
* config_file::load_release_ini_file()
* charge les paramètres dans l'attribut $release_params
* @access private
* @return void
*/
private function load_config_ini_file() {
// Notify the beginning of the current method
$this->dispatcher->notify(new sfEvent($this, 'config.load_release_params'));
//charge les paramètres release dans un tableau $release_params
// if an extra_configfile is given, we use it
if(is_string($this->extra_configfile)) {
$this->config_params=$this->parseConfig($this->extra_configfile);
} else {
$this->config_params=$this->parseConfig($this->file_config);
}
}
/**
* config_file::load_db_ini_file()
* charge les paramètres dans l'attribut $db_params
* @access public
* @return void
*/
private function load_release_ini_file()
{
// Notify the beginning of the current method
$this->dispatcher->notify(new sfEvent($this, 'config.load_db_params'));
//charge les paramètres dans un tableau $db_params
$this->release_params=$this->parseConfig($this->file_release);
}
/**
* config_file::writeReleaseParams()
* écrit dans le fichier ini les paramètres du tableau $release_params
* @access public
* @return boolean
*/
public function writeReleaseParams() {
// Notify the beginning of the current method
$this->dispatcher->notify(new sfEvent($this, 'config.write_release_params'));
// be sure there is no backup files
@SureRemoveDir('../tmp/backup', true); // we delete /tmp/backup folder content
// on écrit les paramètres $release_params vers les fichiers release ini
if($this->a_file->mkini($this->config_params, $this->ini_path.$this->file_config)) return true;
else return false;
}
/**
* config_file::getReleaseParams()
* retourne le contenu HTML en édition ou non des sections éditables
* @access public
* @param string $updatable : champ texte modifiable
* @param string $hidden : présence d'input type hidden
* @return string
*/
public function getReleaseParams($updatable = false, $hidden = false) {
// Notify the beginning of the current method
$this->dispatcher->notify(new sfEvent($this, 'config.get_release_params'));
return $this->getParams($this->section_main, $updatable, $hidden);
}
/**
* config_file::getDatabaseParams()
* retourne le contenu HTML en édition ou non des sections éditables
* @access public
* @param string $updatable : champ texte modifiable
* @param string $hidden : présence d'input type hidden
* @return string
*/
public function getDatabaseParams($updatable = false, $hidden = false) {
// Notify the beginning of the current method
$this->dispatcher->notify(new sfEvent($this, 'config.get_db_params'));
return $this->getParams($this->section_database, $updatable, $hidden);
}
/**
* config_file::getParams()
* retourne le contenu HTML en édition ou non des sections éditables
* @access private
* @param string $updatable : champ texte modifiable
* @param string $hidden : présence d'input type hidden
* @param string $file_name
* @return string
*/
public function getParams($file_name, $updatable = false, $hidden = false)
{
// Notify the beginning of the current method
$this->dispatcher->notify(new sfEvent($this, 'config.get_all_params', array('filename' => $file_name)));
$out = '';
$authorized_sections=array();
include('../languages/' . U_L . '/lang_system.'. CHARSET .'.php');
// le tableau de cache à utiliser est celui de realease
$content=$this->config_params;
if($file_name == $this->section_main) {
//initialisation des sections à afficher/mdofier
$authorized_sections=$this->authorized_release_sections;
}
else if($file_name == $this->section_theme)
{
$authorized_sections=$this->authorized_theme_sections;
}
else if($file_name == $this->section_database)
{
//initialisation des sections à afficher/mdofier
$authorized_sections=$this->authorized_db_sections;
}
if (!is_array($content))
return false;
foreach ($content as $key => $ini)
{
if (is_array($ini))
{
if((in_array($key,$authorized_sections)))
{
if(isset($GLOBALS['lang']['system'][$key])) $label=''.$key.'';
else $label=$key;
$out .= "\n \n";
$out .= "\n