public static function read($configFile, $allModuleInfo = false, $isCli = false, $pseudoScriptName = '') { $tempPath = jApp::tempBasePath(); $configPath = jApp::configPath(); if ($tempPath == '/') { throw new Exception('Application temp directory doesn\'t exist !', 3); } if (!is_writable($tempPath)) { throw new Exception('Application temp base directory is not writable -- (' . $tempPath . ')', 4); } if (!is_writable(jApp::logPath())) { throw new Exception('Application log directory is not writable -- (' . jApp::logPath() . ')', 4); } self::$commonConfig = jIniFile::read($configPath . 'defaultconfig.ini.php', true); $config = jIniFile::read(JELIX_LIB_CORE_PATH . 'defaultconfig.ini.php'); if (self::$commonConfig) { self::_mergeConfig($config, self::$commonConfig); } if ($configFile != 'defaultconfig.ini.php') { if (!file_exists($configPath . $configFile)) { throw new Exception("Configuration file is missing -- {$configFile} ", 5); } if (false === ($userConfig = parse_ini_file($configPath . $configFile, true))) { throw new Exception("Syntax error in the configuration file -- {$configFile}", 6); } self::_mergeConfig($config, $userConfig); } $config = (object) $config; self::prepareConfig($config, $allModuleInfo, $isCli, $pseudoScriptName); self::$commonConfig = null; return $config; }
/** * read the given ini file, for the current entry point, or for the entrypoint given * in $pseudoScriptName. Merge it with the content of defaultconfig.ini.php * It also calculates some options. * If you are in a CLI script but you want to load a configuration file for a web entry point * or vice-versa, you need to indicate the $pseudoScriptName parameter with the name of the entry point * @param string $configFile the config file name * @param boolean $allModuleInfo may be true for the installer, which needs all informations * else should be false, these extra informations are * not needed to run the application * @param boolean $isCli indicate if the configuration to read is for a CLI script or no * @param string $pseudoScriptName the name of the entry point, relative to the base path, * corresponding to the readed configuration * @return object an object which contains configuration values */ public static function read($configFile, $allModuleInfo = false, $isCli = false, $pseudoScriptName = '') { $tempPath = jApp::tempBasePath(); $configPath = jApp::configPath(); if ($tempPath == '/') { // if it equals to '/', this is because realpath has returned false in the application.init.php // so this is because the path doesn't exist. throw new Exception('Application temp directory doesn\'t exist !', 3); } if (!is_writable($tempPath)) { throw new Exception('Application temp base directory (' . $tempPath . ') is not writable', 4); } self::$commonConfig = jIniFile::read($configPath . 'defaultconfig.ini.php', true); #if ENABLE_PHP_JELIX $config = jelix_read_ini(JELIX_LIB_CORE_PATH . 'defaultconfig.ini.php'); @jelix_read_ini($configPath . 'defaultconfig.ini.php', $config); if ($configFile != 'defaultconfig.ini.php') { if (!file_exists($configPath . $configFile)) { throw new Exception("Config file {$configFile} is missing !", 5); } if (false === @jelix_read_ini($configPath . $configFile, $config)) { throw new Exception("Syntax error in the config file {$configFile} !", 6); } } #else $config = jIniFile::read(JELIX_LIB_CORE_PATH . 'defaultconfig.ini.php'); if (self::$commonConfig) { self::_mergeConfig($config, self::$commonConfig); } if ($configFile != 'defaultconfig.ini.php') { if (!file_exists($configPath . $configFile)) { throw new Exception("Config file {$configFile} is missing !", 5); } if (false === ($userConfig = parse_ini_file($configPath . $configFile, true))) { throw new Exception("Syntax error in the config file {$configFile} !", 6); } self::_mergeConfig($config, $userConfig); } $config = (object) $config; #endif self::prepareConfig($config, $allModuleInfo, $isCli, $pseudoScriptName); self::$commonConfig = null; return $config; }
/** * read the given ini file. Merge it with the content of defaultconfig.ini.php * It also calculates some options. It stores the result in a temporary file * @param string $configFile the config file name * @return object an object which contains configuration values */ public static function read($configFile) { if (JELIX_APP_TEMP_PATH == '/') { // if it equals to '/', this is because realpath has returned false in the application.init.php // so this is because the path doesn't exist. die('Jelix Error: Application temp directory doesn\'t exist !'); } if (!is_writable(JELIX_APP_TEMP_PATH)) { die('Jelix Error: Application temp directory is not writable'); } $config = jIniFile::read(JELIX_LIB_CORE_PATH . 'defaultconfig.ini.php'); if ($commonConfig = parse_ini_file(JELIX_APP_CONFIG_PATH . 'defaultconfig.ini.php', true)) { self::_mergeConfig($config, $commonConfig); } if ($configFile != 'defaultconfig.ini.php') { if (!file_exists(JELIX_APP_CONFIG_PATH . $configFile)) { die("Jelix config file {$configFile} is missing !"); } if (false === ($userConfig = parse_ini_file(JELIX_APP_CONFIG_PATH . $configFile, true))) { die("Syntax error in the Jelix config file {$configFile} !"); } self::_mergeConfig($config, $userConfig); } $config = (object) $config; self::prepareConfig($config); if (BYTECODE_CACHE_EXISTS) { $filename = JELIX_APP_TEMP_PATH . str_replace('/', '~', $configFile) . '.conf.php'; if ($f = @fopen($filename, 'wb')) { fwrite($f, '<?php $config = ' . var_export(get_object_vars($config), true) . ";\n?>"); fclose($f); } else { throw new Exception('(24)Error while writing config cache file ' . $filename); } } else { jIniFile::write(get_object_vars($config), JELIX_APP_TEMP_PATH . str_replace('/', '~', $configFile) . '.resultini.php', ";<?php die('');?>\n"); } return $config; }
function jelix_read_ini($fileName, $config = null) { $conf = jIniFile::read($fileName); if ($config !== null) { foreach ($conf as $k => $v) { if (!isset($config->{$k})) { $config->{$k} = $v; continue; } if ($k[1] == '_') { continue; } if (is_array($v)) { $config->{$k} = array_merge($config->{$k}, $v); } else { $config->{$k} = $v; } } return $config; } $conf = (object) $conf; return $conf; }
/** * private function to handle the database migration */ private function _updateDatabase() { //1) if the file installer.ini.php does not exist we cant install jelix nor havefnubb; // then the application has not been installed with jelix 1.2 // so we copy the installer.ini.php build for the application havefnubb //2) if the file exists, that means jelix 1.2 is "installed" // so no need to try to install jelix if (!file_exists(jApp::configPath() . 'installer.ini.php')) { copy(dirname(__FILE__) . '/../../../install/installer.ini.php', jApp::configPath() . 'installer.ini.php'); } jApp::loadConfig('havefnubb/config.ini.php'); //get the dbprofils file $dbProfile = jIniFile::read(jApp::configPath() . jApp::config()->dbProfils); //get the default profile $tools = jDb::getTools($dbProfile['default']); // migrate from 1.3.6 to 1.4.0 $tools->execSQLScript(dirname(__FILE__) . '/../../../sql/update_to_1.4.0.mysql.sql'); }
protected static function _getPrefFile() { return jIniFile::read(jApp::configPath(self::$_pref_config_file)); }
/** * @since 1.6.5 */ public static function importFromIni($iniFile) { $ini = jIniFile::read($iniFile); if ($ini === false) { throw new Exception('Bad ini file: ' . basename($iniFile)); } foreach ($ini as $section => $node) { if (strpos($section, 'pref:') === 0) { $p = new jPrefItem(); $p->setFromIniNode($section, $node); self::addPreference($p); } elseif (strpos($section, 'group:') === 0) { $p = new jPrefItemGroup(); $p->setFromIniNode($section, $node); self::addGroup($p); } } }
<?php // check version from 2 files : // from the defaultconfig.ini.php file // and // from the VERSION file and compare them $currentVersion = jIniFile::read(jApp::configPath() . 'defaultconfig.ini.php'); $newVersion = jFile::read(jApp::appPath() . 'VERSION'); if (trim($currentVersion['havefnubb']['version']) == trim($newVersion)) { $alreadyInstalled = true; } else { $alreadyInstalled = false; } // check if the application is already installed $appInstalled = file_exists(jApp::configPath() . 'installer.ini.php');
/** * Let's see if the current user uses a Browser or is a Bot/Spider/Crawler * then return the name of this one or null */ protected function getBots() { if (!isset($_SERVER['HTTP_USER_AGENT']) || $_SERVER['HTTP_USER_AGENT'] == '') { return null; } $browser = $_SERVER['HTTP_USER_AGENT']; // read the list of bots $botsList = jIniFile::read(jApp::configPath() . "botsagent.ini.php"); if ($botsList) { $q_s = array("#\\.#", "#\\*#", "#\\?#"); $q_r = array("\\.", ".*", ".?"); foreach ($botsList as $name => $bot) { if ($bot['active']) { $pattern = preg_replace($q_s, $q_r, $bot['agent']); if (preg_match('#' . $pattern . '#i', $browser)) { return $name; } } } } return null; }