Index: branches/5.1.x/core/kernel/utility/unit_config_reader.php =================================================================== diff -u -N -r12127 -r12657 --- branches/5.1.x/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 12127) +++ branches/5.1.x/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 12657) @@ -1,6 +1,6 @@ _directorySeparator = preg_quote(DIRECTORY_SEPARATOR); + $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 + + $editor_path = explode('/', trim(EDITOR_PATH, '/')); + $this->_skipFolders[] = array_pop($editor_path); // last of cmseditor folders } function CacheParsedData() @@ -69,7 +73,8 @@ $config_vars = Array ( 'SessionTimeout', 'SessionCookieName', - 'SessionReferrerCheck', + 'SessionBrowserSignatureCheck', + 'SessionIPAddressCheck', 'CookieSessions', 'UseCronForRegularEvent', 'User_GuestGroup', @@ -82,6 +87,7 @@ 'Config_Server_Time', 'Config_Site_Time', 'UseChangeLog', + 'UseVisitorTracking', ); foreach ($config_vars as $var) { @@ -105,6 +111,7 @@ 'Application.ConfigCacheIds' => $this->Application->ConfigCacheIds, 'Application.ConfigHash' => $this->Application->ConfigHash, 'Application.ReplacementTemplates' => $this->Application->ReplacementTemplates, + 'Application.RewriteListeners' => $this->Application->RewriteListeners, 'Application.ModuleInfo' => $this->Application->ModuleInfo, ); @@ -153,6 +160,7 @@ $this->Application->ConfigCacheIds = $cache['Application.ConfigCacheIds']; $this->Application->ReplacementTemplates = $cache['Application.ReplacementTemplates']; + $this->Application->RewriteListeners = $cache['Application.RewriteListeners']; $this->Application->ModuleInfo = $cache['Application.ModuleInfo']; @@ -216,6 +224,9 @@ $base_folder = FULL_PATH . $folderPath . DIRECTORY_SEPARATOR; $sub_folders = glob($base_folder . '*', GLOB_ONLYDIR); + if (!$sub_folders) { + return ; + } if ($level == 0) { // don't scan Front-End themes because of extensive directory structure @@ -234,8 +245,10 @@ continue; } - if (file_exists(FULL_PATH . $this->getConfigName($folderPath . DIRECTORY_SEPARATOR . $sub_folder))) { - $this->configFiles[] = $this->getConfigName($folderPath . DIRECTORY_SEPARATOR . $sub_folder); + $config_name = $this->getConfigName($folderPath . DIRECTORY_SEPARATOR . $sub_folder); + + if (file_exists(FULL_PATH . $config_name)) { + $this->configFiles[] = $config_name; } $this->findConfigFiles($full_path, $level + 1); @@ -254,27 +267,22 @@ $conn =& $this->Application->GetADODBConnection(); if (!isset($this->Application->Memcached) || !($data = $this->Application->Memcached->get('master:config_files'))) { - $data = $conn->GetOne('SELECT Data FROM '.TABLE_PREFIX.'Cache WHERE VarName = "config_files"'); + $data = $conn->GetOne('SELECT Data FROM ' . TABLE_PREFIX . 'Cache WHERE VarName = "config_files"'); } + if ($cache && $data) { $this->configFiles = unserialize($data); 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 } foreach ($this->configFiles as $filename) { $prefix = $this->PreloadConfigFile($filename); if (!$prefix) { - trigger_error('Prefix not defined in config file '.$filename, E_USER_ERROR); + trigger_error('Prefix not defined in config file ' . $filename, E_USER_ERROR); } } } @@ -333,12 +341,14 @@ if ($store_cache || (defined('IS_INSTALL') && IS_INSTALL)) { // cache is not stored during install, but dynamic clones should be processed in any case $this->processDynamicClones(); + $this->retrieveCollections(); } if ($store_cache) { + $this->_sortRewriteListeners(); $this->CacheParsedData(); - if ($this->Application->isDebugMode(false) && constOn('DBG_VALIDATE_CONFIGS')) { + if (defined('DEBUG_MODE') && DEBUG_MODE && defined('DBG_VALIDATE_CONFIGS') && DBG_VALIDATE_CONFIGS) { // validate configs here to have changes from OnAfterConfigRead hooks to prefixes foreach ($this->configData as $prefix => $config) { if (!isset($config['TableName'])) continue; @@ -352,6 +362,34 @@ } /** + * Sort rewrite listeners according to RewritePriority (non-prioritized listeners goes first) + * + */ + function _sortRewriteListeners() + { + $listeners = Array (); + $prioritized_listeners = Array (); + + // process non-prioritized listeners + foreach ($this->Application->RewriteListeners as $prefix => $listener_data) { + if ($listener_data['priority'] === false) { + $listeners[$prefix] = $listener_data; + } + else { + $prioritized_listeners[$prefix] = $listener_data['priority']; + } + } + + // process prioritized listeners + asort($prioritized_listeners); + foreach ($prioritized_listeners as $prefix => $priority) { + $listeners[$prefix] = $this->Application->RewriteListeners[$prefix]; + } + + $this->Application->RewriteListeners = $listeners; + } + + /** * Re-reads all configs * */ @@ -376,6 +414,7 @@ $this->ParseConfigs(); $this->AfterConfigRead(false); $this->processDynamicClones(); + $this->retrieveCollections(); } /** @@ -405,6 +444,32 @@ } /** + * Process all collectable unit config options here to also catch ones, defined from OnAfterConfigRead events + * + */ + function retrieveCollections() + { + foreach ($this->configData as $prefix => $config) { + // collect replacement templates + if (array_key_exists('ReplacementTemplates', $config) && $config['ReplacementTemplates']) { + $this->Application->ReplacementTemplates = array_merge($this->Application->ReplacementTemplates, $config['ReplacementTemplates']); + } + + // collect rewrite listeners + if (array_key_exists('RewriteListener', $config) && $config['RewriteListener']) { + $rewrite_listener = $config['RewriteListener']; + if (strpos($rewrite_listener, ':') === false) { + $rewrite_listener = $prefix . '_EventHandler:' . $rewrite_listener; + } + + $rewrite_priority = array_key_exists('RewritePriority', $config) ? $config['RewritePriority'] : false; + + $this->Application->RewriteListeners[$prefix] = Array ('listener' => $rewrite_listener, 'priority' => $rewrite_priority); + } + } + } + + /** * Register nessasary classes * This method should only process the data which is cached! * @@ -415,6 +480,7 @@ { $config =& $this->configData[$prefix]; $event_manager =& $this->Application->recallObject('EventManager'); + /* @var $event_manager kEventManager */ $register_classes = getArrayValue($config,'RegisterClasses'); if (!$register_classes) $register_classes = Array(); @@ -451,11 +517,10 @@ } $regular_events = getArrayValue($config, 'RegularEvents'); - if($regular_events) - { - foreach($regular_events as $short_name => $regular_event_info) - { - $event_manager->registerRegularEvent( $short_name, $config['Prefix'].':'.$regular_event_info['EventName'], $regular_event_info['RunInterval'], $regular_event_info['Type'] ); + if ($regular_events) { + foreach ($regular_events as $short_name => $regular_event_info) { + $event_status = array_key_exists('Status', $regular_event_info) ? $regular_event_info['Status'] : STATUS_ACTIVE; + $event_manager->registerRegularEvent( $short_name, $config['Prefix'].':'.$regular_event_info['EventName'], $regular_event_info['RunInterval'], $regular_event_info['Type'], $event_status); } } @@ -513,11 +578,6 @@ $this->Application->registerAggregateTag($aggregate_tag); } } - - if (isset($config['ReplacementTemplates']) && $config['ReplacementTemplates']) { - // replacement templates defined in this config - $this->Application->ReplacementTemplates = array_merge_recursive2($this->Application->ReplacementTemplates, $config['ReplacementTemplates']); - } } function ValidateConfig($prefix) @@ -721,8 +781,18 @@ $config['AdminTemplatePath'] = $module_templates . $config['AdminTemplatePath']; } + if (array_key_exists($prefix, $this->prefixFiles) && ($this->prefixFiles[$prefix] != $filename)) { + trigger_error( + 'Single unit config prefix "' . $prefix . '" ' . + 'is used in multiple unit config files: ' . + '"' . $this->prefixFiles[$prefix] . '", "' . $filename . '"', + E_USER_WARNING + ); + } + $this->configData[$prefix] = $config; $this->prefixFiles[$prefix] = $filename; + return $prefix; } elseif ($prefix = array_search($filename, $this->prefixFiles)) { @@ -919,7 +989,4 @@ } } -} - - -?> \ No newline at end of file +} \ No newline at end of file