Index: branches/5.2.x/core/kernel/application.php =================================================================== diff -u -N -r14921 -r14934 --- branches/5.2.x/core/kernel/application.php (.../application.php) (revision 14921) +++ branches/5.2.x/core/kernel/application.php (.../application.php) (revision 14934) @@ -1,6 +1,6 @@ getMaintenanceMode(); + + if ( $maintenance_mode == MaintenanceMode::HARD ) { + $this->redirectToMaintenance(); + } + elseif ( $maintenance_mode == MaintenanceMode::SOFT ) { + $maintenance_template = $this->isAdmin ? 'login' : $this->ConfigValue('SoftMaintenanceTemplate'); + + if ( $this->GetVar('t') != $maintenance_template ) { + $redirect_params = Array ('response_code' => 301); + + if (!$this->isAdmin) { + $redirect_params['next_template'] = urlencode($_SERVER['REQUEST_URI']); + } + + $this->Redirect($maintenance_template, $redirect_params); + } + } + // process maintenance mode redirect: end + if ( defined('DEBUG_MODE') && $this->isDebugMode() && kUtil::constOn('DBG_PROFILE_MEMORY') ) { $this->Debugger->appendMemoryUsage('Application before Run:'); } @@ -1016,19 +1052,19 @@ */ function Done() { - $this->HandleEvent( new kEvent('adm:OnBeforeShutdown') ); + $this->HandleEvent(new kEvent('adm:OnBeforeShutdown')); $debug_mode = defined('DEBUG_MODE') && $this->isDebugMode(); - if ($debug_mode && kUtil::constOn('DBG_PROFILE_MEMORY')) { + if ( $debug_mode && kUtil::constOn('DBG_PROFILE_MEMORY') ) { $this->Debugger->appendMemoryUsage('Application before Done:'); } - if ($debug_mode) { + if ( $debug_mode ) { $this->EventManager->runScheduledTasks(reAFTER); $this->Session->SaveData(); - if (kUtil::constOn('DBG_CACHE')) { + if ( kUtil::constOn('DBG_CACHE') ) { $this->cacheManager->printStatistics(); } @@ -1041,10 +1077,10 @@ $this->HTML = ob_get_clean() . $this->HTML; } - if ($this->UseOutputCompression()) { + if ( $this->UseOutputCompression() ) { $compression_level = $this->ConfigValue('OutputCompressionLevel'); - if (!$compression_level || $compression_level < 0 || $compression_level > 9) { + if ( !$compression_level || $compression_level < 0 || $compression_level > 9 ) { $compression_level = 7; } @@ -1058,12 +1094,12 @@ $this->cacheManager->UpdateApplicationCache(); flush(); - if (!$debug_mode) { + if ( !$debug_mode ) { $this->EventManager->runScheduledTasks(reAFTER); $this->Session->SaveData(); } - if (defined('DBG_CAPTURE_STATISTICS') && DBG_CAPTURE_STATISTICS && !$this->isAdmin) { + if ( defined('DBG_CAPTURE_STATISTICS') && DBG_CAPTURE_STATISTICS && !$this->isAdmin ) { $this->_storeStatistics(); } } @@ -1720,9 +1756,18 @@ return $this->cacheManager->ConfigValue($name); } - function SetConfigValue($name, $value) + /** + * Changes value of individual configuration variable (+resets cache, when needed) + * + * @param string $name + * @param string $value + * @param bool $local_cache_only + * @return string + * @access public + */ + public function SetConfigValue($name, $value, $local_cache_only = false) { - return $this->cacheManager->SetConfigValue($name, $value); + return $this->cacheManager->SetConfigValue($name, $value, $local_cache_only); } /** @@ -2795,4 +2840,27 @@ { $this->cacheManager->delayUnitProcessing($method, $params); } + + /** + * Returns current maintenance mode state + * + * @param bool $check_ips + * @return int + * @access public + */ + public function getMaintenanceMode($check_ips = true) + { + $exception_ips = defined('MAINTENANCE_MODE_IPS') ? MAINTENANCE_MODE_IPS : ''; + $setting_name = $this->isAdmin ? 'MAINTENANCE_MODE_ADMIN' : 'MAINTENANCE_MODE_FRONT'; + + if ( defined($setting_name) && constant($setting_name) > MaintenanceMode::NONE ) { + $exception_ip = $check_ips ? kUtil::ipMatch($exception_ips) : false; + + if ( !$exception_ip ) { + return constant($setting_name); + } + } + + return MaintenanceMode::NONE; + } } \ No newline at end of file