Ejemplo n.º 1
0
 public static function readAndCache($configFile, $isCli = null, $pseudoScriptName = '')
 {
     if ($isCli === null) {
         $isCli = jServer::isCLI();
     }
     $config = self::read($configFile, false, $isCli, $pseudoScriptName);
     $tempPath = jApp::tempPath();
     jFile::createDir($tempPath);
     if (BYTECODE_CACHE_EXISTS) {
         $filename = $tempPath . 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('Error while writing configuration cache file -- ' . $filename);
         }
     } else {
         jIniFile::write(get_object_vars($config), $tempPath . str_replace('/', '~', $configFile) . '.resultini.php', ";<?php die('');?>\n");
     }
     return $config;
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
 /**
  * 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');
 }
Ejemplo n.º 5
0
 protected static function _getPrefFile()
 {
     return jIniFile::read(jApp::configPath(self::$_pref_config_file));
 }
Ejemplo n.º 6
0
 /**
  * @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);
         }
     }
 }
Ejemplo n.º 7
0
<?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');
Ejemplo n.º 8
0
 /**
  * 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;
 }