Esempio n. 1
0
 /**
  * Loads configuration information from an INI file.
  * @param $type The type of configuration information to load: e.g., actions, relationships, valuelists, fields, etc..
  * @param $tablename The name of the table for which to load the configuration information.
  * @return Associative array of configuration options in the same form as they would be returned by parse_ini_file().
  */
 function &loadConfigFromINI($type = null, $tablename = '__global__')
 {
     if (!isset($tablename)) {
         $tablename = '__global__';
     }
     $app =& Dataface_Application::getInstance();
     if ($type == 'lang') {
         if (isset($this->config[$type][$app->_conf['lang']][$tablename])) {
             return $this->config[$type][$app->_conf['lang']][$tablename];
         }
     } else {
         if (isset($this->config[$type][$tablename])) {
             return $this->config[$type][$tablename];
         }
     }
     $app =& Dataface_Application::getInstance();
     $paths = array();
     $lpaths = array();
     if ($type === 'lang') {
         if ($tablename !== '__global__') {
             if (!class_exists('Dataface_Table')) {
                 import('Dataface/Table.php');
             }
             $lpaths[] = Dataface_Table::getBasePath($tablename) . '/tables/' . basename($tablename) . '/lang/' . basename($app->_conf['lang']) . '.ini';
         } else {
             $paths[] = DATAFACE_PATH . '/lang/' . basename($app->_conf['lang']) . '.ini';
             $lpaths[] = DATAFACE_SITE_PATH . '/lang/' . basename($app->_conf['lang']) . '.ini';
         }
     } else {
         if ($tablename !== '__global__') {
             //$paths = array(DATAFACE_SITE_PATH.'/tables/'.$tablename.'/'.$type.'.ini');
             // Valuelists handle their own cascading because it involves loading
             // the valuelist each time... and there may be opportunities to
             // share between tables
             if ($type != 'valuelists') {
                 $paths[] = DATAFACE_PATH . '/' . basename($type) . '.ini';
             }
             if ($type != 'valuelists') {
                 $lpaths[] = DATAFACE_SITE_PATH . '/' . basename($type) . '.ini';
             }
             $lpaths[] = Dataface_Table::getBasePath($tablename) . '/tables/' . basename($tablename) . '/' . basename($type) . '.ini';
         } else {
             $paths[] = DATAFACE_PATH . '/' . basename($type) . '.ini';
             $lpaths[] = DATAFACE_SITE_PATH . '/' . basename($type) . '.ini';
         }
     }
     // Add the ability to override settings in a module.
     // Added Feb. 28, 2007 by Steve Hannah for version 0.6.14
     if (isset($app->_conf['_modules']) and count($app->_conf['_modules']) > 0) {
         foreach ($app->_conf['_modules'] as $classname => $path) {
             $modpath = explode('_', $classname);
             array_shift($modpath);
             $modname = implode('_', $modpath);
             if ($type == 'lang') {
                 $paths[] = DATAFACE_SITE_PATH . '/modules/' . basename($modname) . '/lang/' . basename($app->_conf['lang']) . '.ini';
                 $paths[] = DATAFACE_PATH . '/modules/' . basename($modname) . '/lang/' . basename($app->_conf['lang']) . '.ini';
             } else {
                 $paths[] = DATAFACE_SITE_PATH . '/modules/' . basename($modname) . '/' . basename($type) . '.ini';
                 $paths[] = DATAFACE_PATH . '/modules/' . basename($modname) . '/' . basename($type) . '.ini';
             }
         }
     }
     // Add the ability to override settings in the database.
     // Added Feb. 27, 2007 by Steve Hannah for version 0.6.14
     if (@$app->_conf['enable_db_config'] and $type != 'permissions') {
         if ($type == 'lang') {
             if (isset($tablename)) {
                 $lpaths[] = 'db:tables/' . basename($tablename) . '/lang/' . basename($app->_conf['lang']);
             } else {
                 $paths[] = 'db:lang/' . basename($app->_conf['lang']) . '.ini';
             }
         } else {
             if (isset($tablename)) {
                 $paths[] = 'db:' . basename($type) . '.ini';
                 $lpaths[] = 'db:tables/' . basename($tablename) . '/' . basename($type) . '.ini';
             } else {
                 $paths[] = 'db:' . basename($type) . '.ini';
             }
         }
     }
     if (!$tablename) {
         $tablename = '__global__';
     }
     $paths = array_merge($paths, $lpaths);
     //print_r($paths);
     //print_r($lpaths);
     if (!isset($this->config[$type][$tablename])) {
         $this->config[$type][$tablename] = array();
     }
     //import('Config.php');
     foreach ($paths as $path) {
         if (!isset($this->iniLoaded[$path])) {
             $this->iniLoaded[$path] = true;
             if (is_readable($path) || strstr($path, 'db:') == $path) {
                 $config = $this->parse_ini_file($path, true);
                 if (isset($config['charset']) and function_exists('iconv')) {
                     I18Nv2::recursiveIconv($config, $config['charset'], 'UTF-8');
                 }
                 if (isset($config['__extends__'])) {
                     $config = array_merge_recursive_unique($this->loadConfigFromINI($type, $config['__extends__']), $config);
                 }
                 $this->rawConfig[$path] =& $config;
             } else {
                 $config = array();
                 $this->rawConfig[$path] =& $config;
             }
         } else {
             //echo "getting $path from raw config.";
             //echo "$path already loaded:".implode(',', array_keys($this->iniLoaded));
             $config =& $this->rawConfig[$path];
         }
         //echo "Conf for x".$path."x: ";
         if (!$config) {
             $config = array();
         }
         foreach (array_keys($config) as $entry) {
             if ($type == 'lang') {
                 $this->config[$type][$app->_conf['lang']][$tablename][$entry] =& $config[$entry];
             } else {
                 $sep = null;
                 if (strpos($entry, '>') !== false) {
                     $sep = '>';
                 }
                 if (strpos($entry, ' extends ') !== false) {
                     $sep = ' extends ';
                 }
                 if ($sep and is_array($config[$entry])) {
                     list($newentry, $entryParents) = explode($sep, $entry);
                     $entryParents = array_map('trim', explode(',', $entryParents));
                     $newentry = trim($newentry);
                     $cout = array();
                     foreach ($entryParents as $entryParent) {
                         if (!isset($this->config[$type][$tablename][$entryParent])) {
                             throw new Exception("Illegal extends.  Parent not found: " . $entryParent . " from rule: " . $entry . " in " . $path);
                         }
                         $pconf =& $this->config[$type][$tablename][$entryParent];
                         if (!is_array($pconf)) {
                             throw new Exception("Illegal extends.  Parent is not a section. It is a scalar: " . $entryParent . " from rule: " . $entry . " in " . $path);
                         }
                         foreach ($pconf as $pkey => $pval) {
                             $cout[$pkey] = $pval;
                         }
                         unset($pconf);
                     }
                     $centry =& $config[$entry];
                     foreach ($centry as $ckey => $cval) {
                         $cout[$ckey] = $cval;
                     }
                     unset($centry);
                     unset($this->config[$type][$tablename][$entry]);
                     unset($this->config[$type][$tablename][$newentry]);
                     $this->config[$type][$tablename][$newentry] =& $cout;
                     unset($cout);
                     //$this->config[$type][$tablename][trim($newentry)] = array_merge($this->config[$type][$tablename][trim($entryParent)],$config[$entry]);
                 } else {
                     $this->config[$type][$tablename][$entry] =& $config[$entry];
                 }
             }
         }
         unset($config);
     }
     // New in 2.1.  We load user config if it is available to override the
     // built-in config
     $user_config = $this->userConfig;
     $upaths = array();
     if ($type == 'lang') {
         $upaths[] = 'lang/' . $app->_conf['lang'] . '.ini';
         $upaths[] = 'tables/' . $tablename . '/lang/' . $app->_conf['lang'] . '.ini';
     } else {
         $upaths[] = $type . '.ini';
         $upaths[] = 'tables/' . $tablename . '/' . $type . '.ini';
     }
     foreach ($upaths as $p) {
         if (isset($user_config->{$p})) {
             if ($type == 'lang') {
                 $this->config[$type][$app->_conf['lang']][$tablename] = array_merge_recursive_unique($this->config[$type][$app->_conf['lang']][$tablename], $this->objectToArray($user_config->{$p}));
             } else {
                 $this->config[$type][$tablename] = array_merge_recursive_unique($this->config[$type][$tablename], $this->objectToArray($user_config->{$p}));
             }
         }
     }
     if ($type == 'lang') {
         return $this->config[$type][$app->_conf['lang']][$tablename];
     } else {
         return $this->config[$type][$tablename];
     }
 }
Esempio n. 2
0
 /**
  * Recursive Iconv
  * 
  * @static
  * @access  public
  * @return  void
  * @param   array   $value
  * @param   string  $from
  * @param   string  $to
  */
 function recursiveIconv(&$value, $from, $to)
 {
     foreach ($value as $key => $val) {
         if (is_array($val)) {
             I18Nv2::recursiveIconv($value[$key], $from, $to);
         } else {
             $value[$key] = iconv($from, $to . '//TRANSLIT', $val);
         }
     }
 }