Index: branches/RC/core/kernel/utility/unit_config_reader.php =================================================================== diff -u -r11403 -r11711 --- branches/RC/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 11403) +++ branches/RC/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 11711) @@ -21,14 +21,32 @@ var $AfterConfigProcessed = array(); /** - * Scan kernel and user classes - * for available configs - * - * @access protected - */ + * Escaped directory separator for using in regular expressions + * + * @var string + */ + var $_directorySeparator = ''; + + /** + * Folders to skip during unit config search + * + * @var Array + */ + var $_skipFolders = Array ('CVS', '.svn', 'admin_templates', 'libchart'); + + /** + * Scan kernel and user classes + * for available configs + * + * @access protected + */ function Init($prefix,$special) { parent::Init($prefix,$special); + + $this->_directorySeparator = preg_quote(DIRECTORY_SEPARATOR); + $this->_skipFolders[] = trim(WRITEBALE_BASE, '/'); // system folder (where web server can write) + $this->_skipFolders[] = array_pop( explode('/', trim(EDITOR_PATH, '/')) ); // last of cmseditor folders } function CacheParsedData() @@ -170,30 +188,52 @@ $this->StoreCache = $cache; } - function findConfigFiles($folderPath) + function findConfigFiles($folderPath, $level = 0) { + /*if ($level == 0) { + if ($this->Application->isDebugMode()) { + $start_time = getmicrotime(); + $this->Application->Debugger->appendHTML('kUnitConfigReader::findConfigFiles("' . $folderPath . '")'); + $this->Application->Debugger->appendTrace(); + } + }*/ + // if FULL_PATH = "/" ensure, that all "/" in $folderPath are not deleted - $reg_exp = '/^'.preg_quote(FULL_PATH, '/').'/'; + $reg_exp = '/^' . preg_quote(FULL_PATH, '/') . '/'; $folderPath = preg_replace($reg_exp, '', $folderPath, 1); // this make sense, since $folderPath may NOT contain FULL_PATH - $fh = opendir(FULL_PATH.$folderPath); - while (($sub_folder = readdir($fh))) { - $full_path = FULL_PATH.$folderPath.'/'.$sub_folder; - if ($this->isDir($full_path)) { - if (preg_match('/^\./', $sub_folder)) continue; // don't scan .folders - //the following is to exclude OLD, not removed files when upgrading to 'core' - if (preg_match('/^\/kernel\/kernel4\//', $folderPath) || ($folderPath == '/kernel/units' && file_exists(FULL_PATH.$this->getConfigName('/core/units/'.$sub_folder)))) { - continue; - } - if (file_exists(FULL_PATH.$this->getConfigName($folderPath.'/'.$sub_folder))) { - $this->configFiles[] = $this->getConfigName($folderPath.'/'.$sub_folder); - } - $this->findConfigFiles($full_path); + $base_folder = FULL_PATH . $folderPath . DIRECTORY_SEPARATOR; + $sub_folders = glob($base_folder . '*', GLOB_ONLYDIR); - // if (filemtime($full_path) > $cached) { } + if ($level == 0) { + // don't scan Front-End themes because of extensive directory structure + $sub_folders = array_diff($sub_folders, Array ($base_folder . 'themes', $base_folder . 'tools')); + } + foreach ($sub_folders as $full_path) { + $sub_folder = substr($full_path, strlen($base_folder)); + + if (in_array($sub_folder, $this->_skipFolders)) { + continue; } + + if (preg_match('/^\./', $sub_folder)) { + // don't scan ".folders" + continue; + } + + if (file_exists(FULL_PATH . $this->getConfigName($folderPath . DIRECTORY_SEPARATOR . $sub_folder))) { + $this->configFiles[] = $this->getConfigName($folderPath . DIRECTORY_SEPARATOR . $sub_folder); + } + + $this->findConfigFiles($full_path, $level + 1); } + + /*if ($level == 0) { + if ($this->Application->isDebugMode()) { + $this->Application->Debugger->appendHTML('kUnitConfigReader::findConfigFiles("' . FULL_PATH . $folderPath . '"): ' . (getmicrotime() - $start_time)); + } + }*/ } function includeConfigFiles($folderPath, $cache = true) @@ -209,6 +249,12 @@ shuffle($this->configFiles); } else { + $old_kernel_path = FULL_PATH . DIRECTORY_SEPARATOR . 'kernel' . DIRECTORY_SEPARATOR . 'kernel4'; + if (file_exists($old_kernel_path)) { + // when we got both kernel (one from "kernel/kernel4" and other from "core/kernel") version after upgrade + die('Please remove "' . $old_kernel_path . '" folder.'); + } + $this->findConfigFiles($folderPath); // search from base directory } @@ -347,12 +393,12 @@ } /** - * Register nessasary classes - * This method should only process the data which is cached! - * - * @param string $prefix - * @access private - */ + * Register nessasary classes + * This method should only process the data which is cached! + * + * @param string $prefix + * @access private + */ function parseConfig($prefix) { $config =& $this->configData[$prefix]; @@ -380,9 +426,10 @@ } $config['_Dependencies'][$class_info['class']] = array_merge($config['_Dependencies'][$class_info['class']], $require_classes); } + $this->Application->registerClass( $class_info['class'], - $config['BasePath'].'/'.$class_info['file'], + $config['BasePath'] . DIRECTORY_SEPARATOR . $class_info['file'], $class_info['pseudo']/*, getArrayValue($class_info, 'require_classes')*/ ); @@ -626,36 +673,42 @@ { $config_found = file_exists(FULL_PATH.$filename) && $this->configAllowed($filename); - if( defined('DEBUG_MODE') && DEBUG_MODE && constOn('DBG_PROFILE_INCLUDES') ) - { - if ( in_array($filename, get_required_files()) ) return; + if (defined('DEBUG_MODE') && DEBUG_MODE && defined('DBG_PROFILE_INCLUDES') && DBG_PROFILE_INCLUDES) { + if ( in_array($filename, get_required_files()) ) { + return; + } + global $debugger; - if($config_found) { - $file = FULL_PATH.$filename; - $debugger->ProfileStart('inc_'.crc32($file), $file); + + if ($config_found) { + $file = FULL_PATH . $filename; + $file_crc = crc32($file); + + $debugger->ProfileStart('inc_' . $file_crc, $file); include_once($file); - $debugger->ProfileFinish('inc_'.crc32($file)); - $debugger->profilerAddTotal('includes', 'inc_'.crc32($file)); + $debugger->ProfileFinish('inc_' . $file_crc); + $debugger->profilerAddTotal('includes', 'inc_' . $file_crc); } } - else - { - if ($config_found) include_once(FULL_PATH.$filename); + elseif ($config_found) { + include_once(FULL_PATH . $filename); } if ($config_found) { if (isset($config) && $config) { // config file is included for 1st time -> save it's content for future processing - $prefix = isset($config['Prefix']) ? $config['Prefix'] : ''; + $prefix = array_key_exists('Prefix', $config) ? $config['Prefix'] : ''; - preg_match('/\/(.*)\//U', $filename, $rets); + preg_match('#' . $this->_directorySeparator . '(.*)' . $this->_directorySeparator . '#U', $filename, $rets); $config['ModuleFolder'] = $rets[1]; - $config['BasePath'] = dirname(FULL_PATH.$filename); - if (isset($config['AdminTemplatePath'])) { + $config['BasePath'] = dirname(FULL_PATH . $filename); + + if (array_key_exists('AdminTemplatePath', $config)) { // append template base folder for admin templates path of this prefix - $module_templates = $rets[1] == 'core' ? '' : $rets[1].'/'; - $config['AdminTemplatePath'] = $module_templates.$config['AdminTemplatePath']; + $module_templates = $rets[1] == 'core' ? '' : $rets[1] . '/'; + $config['AdminTemplatePath'] = $module_templates . $config['AdminTemplatePath']; } + $this->configData[$prefix] = $config; $this->prefixFiles[$prefix] = $filename; return $prefix; @@ -666,6 +719,7 @@ return $prefix; } } + return 'dummy'; } @@ -692,15 +746,15 @@ } /** - * Reads unit (specified by $prefix) - * option specified by $option - * - * @param string $prefix - * @param string $name - * @param mixed $default - * @return string - * @access public - */ + * Reads unit (specified by $prefix) + * option specified by $option + * + * @param string $prefix + * @param string $name + * @param mixed $default + * @return string + * @access public + */ function getUnitOption($prefix, $name, $default = false) { if (preg_match('/(.*)\.(.*)/', $prefix, $rets)) { @@ -721,12 +775,12 @@ } /** - * Read all unit with $prefix options - * - * @param string $prefix - * @return Array - * @access public - */ + * Read all unit with $prefix options + * + * @param string $prefix + * @return Array + * @access public + */ function getUnitOptions($prefix) { if (!isset($this->configData[$prefix])) { @@ -737,13 +791,13 @@ } /** - * Set's new unit option value - * - * @param string $prefix - * @param string $name - * @param string $value - * @access public - */ + * Set's new unit option value + * + * @param string $prefix + * @param string $name + * @param string $value + * @access public + */ function setUnitOption($prefix, $name, $value) { if (preg_match('/(.*)\.(.*)/', $prefix, $rets)) { @@ -773,71 +827,60 @@ } /** - * Get's config file name based - * on folder name supplied - * - * @param string $folderPath - * @return string - * @access private - */ + * Get's config file name based + * on folder name supplied + * + * @param string $folderPath + * @return string + * @access private + */ function getConfigName($folderPath) { - return $folderPath.'/'.basename($folderPath).'_config.php'; + return $folderPath . DIRECTORY_SEPARATOR . basename($folderPath) . '_config.php'; } /** - * is_dir ajustment to work with - * directory listings too - * - * @param string $folderPath - * @return bool - * @access private - */ - function isDir($folderPath) - { - $base_name = basename($folderPath); - $ret = !( $base_name == '.' || $base_name == '..' ); - return $ret && is_dir($folderPath); - } - - /** - * Checks if config file is allowed for includion (if module of config is installed) - * - * @param string $config_path relative path from in-portal directory - */ + * Checks if config file is allowed for includion (if module of config is installed) + * + * @param string $config_path relative path from in-portal directory + */ function configAllowed($config_path) { if (defined('IS_INSTALL') && IS_INSTALL) { // at installation start no modules in db and kernel configs could not be read return true; } - if (preg_match('#/plugins/|/core#', $config_path)) { + if (preg_match('#' . $this->_directorySeparator . 'plugins' . $this->_directorySeparator . '|' . $this->_directorySeparator . 'core#', $config_path)) { + // always allow to include configs from core and plugins folder return true; } $module_found = false; - if (!$this->Application->ModuleInfo) return false; + if (!$this->Application->ModuleInfo) { + return false; + } - foreach($this->Application->ModuleInfo as $module_name => $module_info) - { - $module_path = '/'.$module_info['Path']; - if (preg_match('/^'.preg_quote($module_path, '/').'/', $config_path)) { - // if (mb_substr($config_path, 0, mb_strlen($module_path)) == $module_path) { - // config file path starts with module folder path + foreach ($this->Application->ModuleInfo as $module_name => $module_info) { + $module_path = DIRECTORY_SEPARATOR . trim($module_info['Path'], '/') . DIRECTORY_SEPARATOR; + + // config file path starts with module folder path + if (substr($config_path, 0, strlen($module_path)) == $module_path) { +// if (preg_match('#^' . preg_quote($module_path, '/') . '#', $config_path)) { $module_found = true; break; } } + return $module_found; } /** - * Returns true if config exists and is allowed for reading - * - * @param string $prefix - * @return bool - */ + * Returns true if config exists and is allowed for reading + * + * @param string $prefix + * @return bool + */ function prefixRegistred($prefix) { return isset($this->prefixFiles[$prefix]) ? true : false;