Source for file class.config_file.php
Documentation is available at class.config_file.php
* @subpackage config_files
* @author linea21 <info@linea21.com>
* @license http://opensource.org/licenses/gpl-3.0.html
* Configuration Management
include_once('system/afiles/class.afiles.php');
include_once('../lib/lib_common.php');
// but we are getting some issues converting it
// when using the installer
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 $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'); //sections autorisées dans le fichier release
* config_file::__construct()
//charge les paramètres et les place en constante globale par define
$this->load_config_ini_file();
$this->load_release_ini_file();
* charge les paramètres des fichiers ini et les place en constante globale avec define
// Notify the beginning of the current method
$this->dispatcher->notify(new sfEvent($this, 'config.init'));
foreach ($existing_params as $existing_param => $existing_value)
define($existing_param,$existing_value);
foreach ($existing_params as $existing_param => $existing_value)
define($existing_param,$existing_value);
* config_file::setParams()
* Ecrase les valeurs contenues dans le tableau stocké dans l'attribut $this->config_params
* pour mise à jour des valeurs
* @param array $array new values to override to params
// 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 ($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);
* config_file::load_release_ini_file()
* charge les paramètres dans l'attribut $release_params
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
* config_file::load_db_ini_file()
* charge les paramètres dans l'attribut $db_params
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
* config_file::writeReleaseParams()
* écrit dans le fichier ini les paramètres du tableau $release_params
// Notify the beginning of the current method
$this->dispatcher->notify(new sfEvent($this, 'config.write_release_params'));
//écrit les paramètres $release_params vers les fichiers release ini et php
//on écrit les params après avoir fait le backup
* config_file::backupParams()
* sauvegarde le fichier $file_name dans le répertoire de backup
* @param string $file_name
// Notify the beginning of the current method
$this->dispatcher->notify(new sfEvent($this, 'config.backup_params', array('filename' => $file_name)));
// do create backup folder is not done yet
* config_file::getReleaseParams()
* retourne le contenu HTML en édition ou non des sections éditables
* @param string $updatable : champ texte modifiable
* @param string $hidden : présence d'input type hidden
// Notify the beginning of the current method
$this->dispatcher->notify(new sfEvent($this, 'config.get_release_params'));
* config_file::getDatabaseParams()
* retourne le contenu HTML en édition ou non des sections éditables
* @param string $updatable : champ texte modifiable
* @param string $hidden : présence d'input type hidden
// Notify the beginning of the current method
$this->dispatcher->notify(new sfEvent($this, 'config.get_db_params'));
* config_file::getParams()
* retourne le contenu HTML en édition ou non des sections éditables
* @param string $updatable : champ texte modifiable
* @param string $hidden : présence d'input type hidden
* @param string $file_name
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)));
$authorized_sections= array();
include('../languages/' . U_L . '/lang_system.'. CHARSET . '.php');
// le tableau de cache à utiliser est celui de realease
//initialisation des sections à afficher/mdofier
//initialisation des sections à afficher/mdofier
foreach ($content as $key => $ini)
if((in_array($key,$authorized_sections)))
if(isset ($GLOBALS['lang']['system'][$key])) $label= '<abbr title="'. $GLOBALS['lang']['system'][$key]. '">'. $key. '</abbr>';
$out .= "\n<br style='clear:both' />\n";
$out .= "\n<h2>". $label. "</h2>\n";
if(!$updatable) $out .= "<dl>\n";
foreach ($ini as $var => $value)
if(isset ($GLOBALS['lang']['system'][$var])) $label= '<abbr title="'. $GLOBALS['lang']['system'][$var]. '">'. $var. '</abbr>';
if($hidden) $out .= "<input name=\"". $var. "\" id=\"". $var. "\" value=\"". $value. "\" type=\"hidden\" />\n";
$out .= "</dt><dd>". preg_replace("/[a-zA-Z0-9_]/", "•", $value). "</dd>\n";
$out .= "</dt><dd>". $value. "</dd>\n";
$out .= "<p><label for=\"". $var. "\">". $label. "</label><input name=\"". $var. "\" id=\"". $var. "\" value=\"". $value. "\" type=\"password\" class=\"textfield\" /></p>\n";
elseif($var != 'LANGUAGE') {
$out .= "<p><label for=\"". $var. "\">". $label. "</label><input name=\"". $var. "\" id=\"". $var. "\" value=\"". $value. "\" type=\"text\" class=\"textfield\" /></p>\n";
$out .= "<p><label for=\"". $var. "\">". $label. "</label>". CultureSelectBox($var, $value). "</p>\n";
if(!$updatable) $out .= "</dl>";
if(!$updatable && $hidden) $out .= "<input name=\"". $key. "\" id=\"". $key. "\" value=\"". $ini. "\" type=\"hidden\" />\n";
if(!$updatable) $out .= "<dt>". $key. "</dt><dd>". $ini. "</dd>\n";
else $out .= "<p><label for=\"". $key. "\">". $key. "</label><input name=\"". $key. "\" id=\"". $key. "\" value=\"". $ini. "\" type=\"text\" class=\"textfield\" /></p>\n";
* config_file::getThemeParams()
* retourne le contenu HTML en édition ou non des sections éditables
* @param string $updatable : champ texte modifiable
* @param string $hidden : présence d'input type hidden
// Notify the beginning of the current method
$this->dispatcher->notify(new sfEvent($this, 'config.get_theme_params'));
$authorized_sections= array();
include('../languages/' . U_L . '/lang_system.'. CHARSET . '.php');
$out .= "\n<h2 style=\"clear:both;\">". $label. "</h2>\n";
foreach ($public_themes as $key => $value)
if($value != $theme_public)
$out .= "\n<h2 style=\"clear:both;\">". $label. "</h2>\n";
foreach ($admin_themes as $key => $value)
if($value != $theme_admin)
$out .= "\n<br style=\"clear:both;\" />\n";
* config_file::getOneThemeParams()
* retourne les informations relatives à un thème
* @param string $updatable
* @param string $selected
* @param string $field_name
* @param string $radio_name
public function getOneThemeParams($updatable = false, $hidden = false, $selected= false,$value,$field_name,$radio_name, $type) {
// Notify the beginning of the current method
$this->dispatcher->notify(new sfEvent($this, 'config.get_one_theme_params'));
include('../languages/' . U_L . '/lang_system.'. CHARSET . '.php');
$selected_pattern= '_selected';
$checked_pattern= 'checked="checked"';
if(!$updatable)$hidden_pattern= 'style="display:none;"';
else $updatable_pattern= "onclick=\"javascript:document.getElementById('". $type. $value. "').checked='checked';\"";
$out .= "<div class=\"config_theme" . $selected_pattern. "\">\n";
$out .= "<img src=\"../templates/" . $type. "/" . $value. "/preview.png\" style=\"width:250px;height:160px;\" alt=\"" . $value. "\" id=\"img_" . $type. "-". $value. "\" ". $updatable_pattern. "/>\n";
$out .= '<input type="radio" name="' . $radio_name. '" id="' . $type. '-'. $value. '" value="' . $value. '" ' . $checked_pattern. ' ' . $hidden_pattern. ' />';
$out .= '<label for="' . $type. '-'. $value. '" class="autowidth">' . $value . '</label>';
$out .= '<div class="themeinfo"><em>'. _t('theme','name'). '</em> : '. $info['name']. '<br />'. END_LINE;
$out .= '<em>'. _t('theme','author'). '</em> : <a href="'. $info['homepage']. '">'. $info['author']. '</a><br />'. END_LINE;
$out .= '<em>'. _t('theme','version'). '</em> : '. $info['version']. ' | ';
$out .= '<em>'. _t('theme','compatibility'). '</em> : '. $info['compatibility']. '<br />'. END_LINE;
$out .= '<em>'. _t('theme','description'). '</em> : '. $info['description']. '<br />'. END_LINE;
* config_file::writePhpParams()
* écrit le fichier $file_name dans le répertoire de config, au format PHP
* @param string $file_name
// Notify the beginning of the current method
$this->dispatcher->notify(new sfEvent($this, 'config.write_php_params', array('filename' => $file_name)));
$content= $this->generateHeader($file_name);
$content.= $this->generateBody($file_name);
$content.= $this->generateFooter($file_name);
//on écrit le contenu dans le fichier php
* config_file::parseConfig()
* retourne un tableau contenant les paramètres du fichier ini $file_name
* @param string $file_name
public function parseConfig($file_name, $whithsection = true)
// Notify the beginning of the current method
$this->dispatcher->notify(new sfEvent($this, 'config.parse_config', array('filename' => $file_name)));
return $this->a_file->parse_ini($this->ini_path. $file_name, $whithsection);
* config_file::generateBody()
* génère le contenu d'un fichier php de configuration à parti du $file_name
* @param string $file_name
private function generateBody($file_name)
foreach ($content as $key => $ini)
$out .= "\n\n// ". $key. " /////// \n\n";
foreach ($ini as $var => $value)
$out .= "define('". $var. "',\t\t". $this->a_file->quote_ini($value). ");\n";
$out .= "define('". $key. "',\t\t". $this->a_file->quote_ini($ini). ");\n";
// Filter data event + return value
$r = $this->dispatcher->filter(new sfEvent($this, 'config.generate_body', array('filename' => $file_name, 'content' => $out)), $out);
$out = $r->getReturnValue();
* config_file::generateHeader()
* génère l'en tête d'un fichier php de configuration à partir du $file_name
* @param string $file_name
private function generateHeader($file_name)
$ret.= "// Linea 21 - PHP ". $file_name. "\n";
$ret.= "// last_modify : ". date("d-m-Y"). "\n";
$ret.= "// http://opensource.org/licenses/gpl-3.0.html\n\n";
$ret.= "// BE CAREFULL THIS FILE IS SYSTEM FILE : use interface or ". $file_name. " FOR CONFIGURATION";
// Filter data event + return value
$r = $this->dispatcher->filter(new sfEvent($this, 'config.generate_header', array('filename' => $file_name, 'content' => $ret)), $ret);
$ret = $r->getReturnValue();
* config_file::generateFooter()
* génère le pied d'un fichier php de configuration à parti du $file_name
* @param string $file_name
private function generateFooter($file_name)
// Filter data event + return value
$r = $this->dispatcher->filter(new sfEvent($this, 'config.generate_footer', array('filename' => $file_name, 'content' => $s)), $s);
$s = $r->getReturnValue();
* config_file::strip_ini_char
* suppression des caractères interdits dans un fichier ini
function strip_ini_char($content)
// on remplace les caractères "[]; par '(),
$ret= strtr($content, "\"[];", "'(),");
* config_file::convert_type()
* conversion d'une variable en entier ou en float selon son contenu
* @param unknown_type $var
if( (float) $var != (int) $var )
if( $var == "true" ) return true;
if( $var == "false" ) return false;
* config_file::getPhpInfo()
* Retourne un string contenant les informations php en html
return preg_replace('%^.*<body>(.*)</body>.*$%ms', '$1', $info);
|