31 require_once
'I18Nv2/I18Nv2.php';
35 var
$configTypes = array(
'actions',
'fields',
'relationships',
'valuelists',
'tables',
'lang',
'metadata');
44 register_shutdown_function(array(&$this,
'apc_save'));
50 var
$nameLookup = array(
'actions'=>array(),
'fields'=>array(),
'table'=>array(),
'relationships'=>array(),
'valuelists'=>array(),
'lang'=>array());
82 if ( $type ==
'lang' ){
83 if ( isset($this->config[$type][
$app->_conf[
'lang']][
$tablename]) ){
87 if ( isset( $this->config[$type][
$tablename] ) ){
94 if ( $type ===
'lang' ){
97 if ( !class_exists(
'Dataface_Table') )
import(
'Dataface/Table.php');
101 $paths[] = DATAFACE_PATH.
'/lang/'.basename(
$app->_conf[
'lang']).
'.ini';
102 $lpaths[] = DATAFACE_SITE_PATH.
'/lang/'.basename(
$app->_conf[
'lang']).
'.ini';
110 if ( $type !=
'valuelists' ) $paths[] = DATAFACE_PATH.
'/'.basename($type).
'.ini';
111 if ( $type !=
'valuelists' ) $lpaths[] = DATAFACE_SITE_PATH.
'/'.basename($type).
'.ini';
116 $paths[] = DATAFACE_PATH.
'/'.basename($type).
'.ini';
117 $lpaths[] = DATAFACE_SITE_PATH.
'/'.basename($type).
'.ini';
122 if ( isset(
$app->_conf[
'_modules']) and count(
$app->_conf[
'_modules']) > 0 ){
123 foreach (
$app->_conf[
'_modules'] as $classname=>
$path ){
124 $modpath = explode(
'_',$classname);
125 array_shift($modpath);
126 $modname = implode(
'_', $modpath);
127 if ( $type ==
'lang' ){
128 $paths[] = DATAFACE_SITE_PATH.
'/modules/'.basename($modname).
'/lang/'.basename(
$app->_conf[
'lang']).
'.ini';
129 $paths[] = DATAFACE_PATH.
'/modules/'.basename($modname).
'/lang/'.basename(
$app->_conf[
'lang']).
'.ini';
131 $paths[] = DATAFACE_SITE_PATH.
'/modules/'.basename($modname).
'/'.basename($type).
'.ini';
132 $paths[] = DATAFACE_PATH.
'/modules/'.basename($modname).
'/'.basename($type).
'.ini';
139 if ( @
$app->_conf[
'enable_db_config'] and $type !=
'permissions'){
140 if ( $type ==
'lang' ){
142 $lpaths[] =
'db:tables/'.basename(
$tablename).
'/lang/'.basename(
$app->_conf[
'lang']);
144 $paths[] =
'db:lang/'.basename(
$app->_conf[
'lang']).
'.ini';
148 $paths[] =
'db:'.basename($type).
'.ini';
149 $lpaths[] =
'db:tables/'.basename(
$tablename).
'/'.basename($type).
'.ini';
151 $paths[] =
'db:'.basename($type).
'.ini';
161 $paths = array_merge($paths, $lpaths);
167 foreach ( $paths as
$path ){
168 if ( !isset( $this->iniLoaded[$path] ) ){
169 $this->iniLoaded[
$path] =
true;
171 if ( is_readable($path) || strstr($path,
'db:') == $path ){
176 if ( isset(
$config[
'charset'] ) and function_exists(
'iconv') ){
181 if ( isset(
$config[
'__extends__']) ){
201 foreach ( array_keys(
$config) as $entry ){
202 if ( $type ==
'lang'){
206 if ( strpos($entry,
'>') !==
false ){
209 if ( strpos($entry,
' extends ') !==
false ){
212 if ( $sep and is_array(
$config[$entry]) ){
213 list($newentry,$entryParents) = explode($sep, $entry);
214 $entryParents = array_map(
'trim',explode(
',', $entryParents));
215 $newentry = trim($newentry);
217 foreach ($entryParents as $entryParent){
218 if ( !isset($this->config[$type][$tablename][$entryParent]) ){
219 throw new Exception(
"Illegal extends. Parent not found: ".$entryParent.
" from rule: ".$entry.
" in ".$path);
221 $pconf =& $this->config[$type][
$tablename][$entryParent];
222 if ( !is_array($pconf) ){
223 throw new Exception(
"Illegal extends. Parent is not a section. It is a scalar: ".$entryParent.
" from rule: ".$entry.
" in ".$path);
226 foreach ($pconf as $pkey=>$pval){
227 $cout[$pkey] = $pval;
233 foreach ($centry as $ckey=>$cval){
234 $cout[$ckey] = $cval;
237 unset($this->config[$type][$tablename][$entry]);
238 unset($this->config[$type][$tablename][$newentry]);
239 $this->config[$type][
$tablename][$newentry] =& $cout;
253 if ( $type ==
'lang' ){
262 if ( function_exists(
'apc_store') and defined(
'DATAFACE_USE_CACHE') and DATAFACE_USE_CACHE ){
263 $res = apc_store($this->
apc_hash().
'$config', $this->config);
264 $res2 = apc_store($this->
apc_hash().
'$iniLoaded', $this->iniLoaded);
270 if ( function_exists(
'apc_fetch') and defined(
'DATAFACE_USE_CACHE') and DATAFACE_USE_CACHE ){
271 $this->config = apc_fetch($this->
apc_hash().
'$config');
272 $this->iniLoaded = apc_fetch($this->
apc_hash().
'$iniLoaded');
277 $appname = basename(DATAFACE_SITE_PATH);
278 return __FILE__.
'-'.$appname;
287 $tables_path = DATAFACE_SITE_PATH.
'/tables';
288 $dir = dir($tables_path);
289 while (
false !== ( $entry = $dir->read() ) ){
290 if ( $entry ===
'.' || $entry ===
'..' )
continue;
291 $full_path = $tables_path.
'/'.$entry;
292 if ( is_dir($full_path) ){
293 foreach ( $this->configTypes as $type ){
298 foreach ($this->configTypes as $type){
307 switch( strtolower(
$app->_conf[
'config_storage']) ){
311 $this->loadConfigFromDB();
337 if ( class_exists(
'Dataface_AuthenticationTool') ){
339 $username = $auth->getLoggedInUsername();
346 $res = @mysql_query($sql,
$app->db());
349 $res = mysql_query($sql,
$app->db());
354 while ( $row = mysql_fetch_assoc($res) ){
355 if ( !$row[
'section'] ){
356 $config[$row[
'file']][$row[
'key']] = $row[
'value'];
358 $config[$row[
'file']][$row[
'section']][$row[
'key']] = $row[
'value'];
361 @mysql_free_result($res);
379 if ( DATAFACE_EXTENSION_LOADED_APC ){
381 apc_store($this->
apc_hash().$path.
'__mtime', time());
395 $sql =
"select * from `".$this->configTableName.
"` where (`lang` IS NULL OR `lang` = '".$lang.
"') and ( `username` IS NULL";
396 if ( isset($username) ){
397 $sql .=
" OR `username` = '".addslashes($username).
"')";
401 if ( isset($where) ) $sql .=
' and ('.$where.
')';
404 $sql .=
' ORDER BY `priority`';
410 import(
'Dataface/ConfigTool/createConfigTable.function.php');
414 function setConfigParam($file, $section, $key, $value, $username=null, $lang=null, $priority=5){
415 import(
'Dataface/ConfigTool/setConfigParam.function.php');
420 import(
'Dataface/ConfigTool/clearConfigParam.function.php');
429 private $keys = array();
430 private function replace_key($matches){
431 $this->keys[] = trim($matches[1]);
432 return 'keys'.(count($this->keys)-1).
'=';
435 private function replace_section($matches){
436 $this->keys[] = trim($matches[1]);
437 return '[keys'.(count($this->keys)-1).
']';
440 private function return_key($matches){
441 $index = intval($matches[1]);
442 if ( isset($this->keys[
$index]) ){
443 return $this->keys[
$index].
'=';
450 private function refill_array($ini){
451 foreach ( $ini as $key=>$val){
452 if ( is_array($val) ){
454 $val = $this->refill_array($val);
457 $val = preg_replace_callback(
'/^keys(\d+)=/m', array($this,
'return_key'), $val);
459 $index = intval(substr($key, 4));
460 if ( isset($this->keys[
$index]) ){
462 $ini[$this->keys[
$index]] = $val;
471 private function parse($file, $sections=
false){
472 $this->keys = array();
473 $contents = file_get_contents($file);
474 $contents = preg_replace_callback(
'/^ *\[([^\]]+)\]/m', array($this,
'replace_section'), $contents);
476 $contents = preg_replace_callback(
'/^([^\[=;"]+)(=)/m', array($this,
'replace_key'), $contents);
478 $ini = parse_ini_string($contents, $sections);
479 return $this->refill_array($ini);
482 if ( version_compare(PHP_VERSION,
'5.3.0') >= 0 and version_compare(PHP_VERSION,
'5.3.1') <= 0 ){
484 return $p->parse($file, $sections);