eZ Publish  [trunk]
index.php
Go to the documentation of this file.
00001 <?php
00002 /**
00003  * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved.
00004  * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
00005  * @version //autogentag//
00006  * @package kernel
00007  */
00008 
00009 /**
00010  * PHP 5.2 is our hard requirement
00011  */
00012 if ( version_compare( PHP_VERSION, '5.2' ) < 0 )
00013 {
00014     print( "<h1>Unsupported PHP version " . PHP_VERSION . "</h1>" );
00015     print( "<p>eZ Publish 4.x does not run with PHP version lower than 5.2.</p>".
00016            "<p>For more information about supported software please visit ".
00017            "<a href=\"http://ez.no/download/ez_publish\" >eZ Publish download page</a></p>" );
00018     exit;
00019 }
00020 
00021 $scriptStartTime = microtime( true );
00022 
00023 // Set a default time zone if none is given to avoid "It is not safe to rely
00024 // on the system's timezone settings" warnings. The time zone can be overriden
00025 // in config.php or php.ini.
00026 if ( !ini_get( "date.timezone" ) )
00027 {
00028     date_default_timezone_set( "UTC" );
00029 }
00030 
00031 require 'autoload.php';
00032 
00033 ignore_user_abort( true );
00034 
00035 ob_start();
00036 
00037 $use_external_css = true;
00038 $show_page_layout = true;
00039 $moduleRunRequired = true;
00040 $policyCheckRequired = true;
00041 $urlTranslatorAllowed = true;
00042 $validityCheckRequired = false;
00043 $userObjectRequired = true;
00044 $sessionRequired = true;
00045 $dbRequired = true;
00046 $noCacheAdviced = false;
00047 
00048 $siteDesignOverride = false;
00049 
00050 // List of module names which will skip policy checking
00051 $policyCheckOmitList = array();
00052 
00053 // List of directories to search for modules
00054 $moduleRepositories = array();
00055 
00056 $siteBasics = array();
00057 $siteBasics['external-css'] =& $use_external_css;
00058 $siteBasics['show-page-layout'] =& $show_page_layout;
00059 $siteBasics['module-run-required'] =& $moduleRunRequired;
00060 $siteBasics['policy-check-required'] =& $policyCheckRequired;
00061 $siteBasics['policy-check-omit-list'] =& $policyCheckOmitList;
00062 $siteBasics['url-translator-allowed'] =& $urlTranslatorAllowed;
00063 $siteBasics['validity-check-required'] =& $validityCheckRequired;
00064 $siteBasics['user-object-required'] =& $userObjectRequired;
00065 $siteBasics['session-required'] =& $sessionRequired;
00066 $siteBasics['db-required'] =& $dbRequired;
00067 $siteBasics['no-cache-adviced'] =& $noCacheAdviced;
00068 $siteBasics['site-design-override'] =& $siteDesignOverride;
00069 
00070 $siteBasics['module-repositories'] =& $moduleRepositories;
00071 
00072 $GLOBALS['eZSiteBasics'] =& $siteBasics;
00073 
00074 $GLOBALS['eZRedirection'] = false;
00075 
00076 error_reporting ( E_ALL | E_STRICT );
00077 
00078 /*!
00079  Reads settings from site.ini and passes them to eZDebug.
00080 */
00081 function eZUpdateDebugSettings()
00082 {
00083     $ini = eZINI::instance();
00084 
00085     $settings = array();
00086     list( $settings['debug-enabled'], $settings['debug-by-ip'], $settings['log-only'], $settings['debug-by-user'], $settings['debug-ip-list'], $logList, $settings['debug-user-list'] ) =
00087         $ini->variableMulti( 'DebugSettings',
00088                              array( 'DebugOutput', 'DebugByIP', 'DebugLogOnly', 'DebugByUser', 'DebugIPList', 'AlwaysLog', 'DebugUserIDList' ),
00089                              array( 'enabled', 'enabled', 'disabled', 'enabled' ) );
00090     $logMap = array( 'notice' => eZDebug::LEVEL_NOTICE,
00091                      'warning' => eZDebug::LEVEL_WARNING,
00092                      'error' => eZDebug::LEVEL_ERROR,
00093                      'debug' => eZDebug::LEVEL_DEBUG,
00094                      'strict' => eZDebug::LEVEL_STRICT );
00095     $settings['always-log'] = array();
00096     foreach ( $logMap as $name => $level )
00097     {
00098         $settings['always-log'][$level] = in_array( $name, $logList );
00099     }
00100     eZDebug::updateSettings( $settings );
00101 }
00102 
00103 /*!
00104  Reads settings from i18n.ini and passes them to eZTextCodec.
00105 */
00106 function eZUpdateTextCodecSettings()
00107 {
00108     $ini = eZINI::instance( 'i18n.ini' );
00109 
00110     list( $i18nSettings['internal-charset'], $i18nSettings['http-charset'], $i18nSettings['mbstring-extension'] ) =
00111         $ini->variableMulti( 'CharacterSettings', array( 'Charset', 'HTTPCharset', 'MBStringExtension' ), array( false, false, 'enabled' ) );
00112 
00113     eZTextCodec::updateSettings( $i18nSettings );
00114 }
00115 
00116 // Initialize text codec settings
00117 eZUpdateTextCodecSettings();
00118 
00119 // Initialize debug settings.
00120 eZUpdateDebugSettings();
00121 
00122 
00123 // Set the different permissions/settings.
00124 $ini = eZINI::instance();
00125 
00126 // Set correct site timezone
00127 $timezone = $ini->variable( "TimeZoneSettings", "TimeZone");
00128 if ( $timezone )
00129 {
00130     date_default_timezone_set( $timezone );
00131 }
00132 
00133 
00134 list( $iniFilePermission, $iniDirPermission ) =
00135     $ini->variableMulti( 'FileSettings', array( 'StorageFilePermissions', 'StorageDirPermissions' ) );
00136 
00137 $iniVarDirectory = eZSys::cacheDirectory() ;
00138 
00139 // OPTIMIZATION:
00140 // Sets permission array as global variable, this avoids the eZCodePage include
00141 $GLOBALS['EZCODEPAGEPERMISSIONS'] = array( 'file_permission' => octdec( $iniFilePermission ),
00142                                            'dir_permission'  => octdec( $iniDirPermission ),
00143                                            'var_directory'   => $iniVarDirectory );
00144 
00145 //
00146 $warningList = array();
00147 
00148 /*!
00149  Appends a new warning item to the warning list.
00150  \a $parameters must contain a \c error and \c text key.
00151 */
00152 function eZAppendWarningItem( $parameters = array() )
00153 {
00154     global $warningList;
00155     $parameters = array_merge( array( 'error' => false,
00156                                       'text' => false,
00157                                       'identifier' => false ),
00158                                $parameters );
00159     $error = $parameters['error'];
00160     $text = $parameters['text'];
00161     $identifier = $parameters['identifier'];
00162     $warningList[] = array( 'error' => $error,
00163                             'text' => $text,
00164                             'identifier' => $identifier );
00165 }
00166 
00167 function eZDBCleanup()
00168 {
00169     if ( class_exists( 'eZDB' )
00170          and eZDB::hasInstance() )
00171     {
00172         $db = eZDB::instance();
00173         $db->setIsSQLOutputEnabled( false );
00174     }
00175 }
00176 
00177 function eZFatalError()
00178 {
00179     header("HTTP/1.1 500 Internal Server Error");
00180     print( "<b>Fatal error</b>: The web server did not finish its request<br/>" );
00181     if ( ini_get('display_errors') == 1 )
00182     {
00183         if ( eZDebug::isDebugEnabled() )
00184             print( "<p>The execution of eZ Publish was abruptly ended, the debug output is present below.</p>" );
00185         else
00186             print( "<p>Debug information can be found in the log files normally placed in var/log/* or by enabling 'DebugOutput' in site.ini</p>" );
00187     }
00188     else
00189     {
00190         print( "<p>Contact website owner with current url and info on what you did, and owner will be able to debug the issue further (by enabling 'display_errors' in php.ini).</p>" );
00191     }
00192     $templateResult = null;
00193     eZDisplayResult( $templateResult );
00194 }
00195 
00196 eZExecution::addCleanupHandler( 'eZDBCleanup' );
00197 eZExecution::addFatalErrorHandler( 'eZFatalError' );
00198 
00199 eZDebug::setScriptStart( $scriptStartTime );
00200 
00201 // Enable this line to get eZINI debug output
00202 // eZINI::setIsDebugEnabled( true );
00203 // Enable this line to turn off ini caching
00204 // eZINI::setIsCacheEnabled( false);
00205 
00206 function eZDisplayDebug()
00207 {
00208     $ini = eZINI::instance();
00209 
00210     if ( $ini->variable( 'DebugSettings', 'DebugOutput' ) != 'enabled' )
00211         return null;
00212 
00213     $scriptStopTime = microtime( true );
00214 
00215     $type = $ini->variable( "DebugSettings", "Debug" );
00216     //eZDebug::setHandleType( eZDebug::HANDLE_NONE );
00217     if ( $type == "inline" or $type == "popup" )
00218     {
00219         $as_html = true;
00220 
00221         if ( $ini->variable( "DebugSettings", "DebugToolbar" ) == 'enabled' &&
00222              $ini->variable( "SiteAccessSettings", "CheckValidity" ) !== 'true' &&
00223              $as_html == true &&
00224              !$GLOBALS['eZRedirection'] )
00225 
00226         {
00227             $tpl = eZTemplate::factory();
00228             $result = "<tr><td>" . $tpl->fetch( 'design:setup/debug_toolbar.tpl' ) . "</td></tr>";
00229             eZDebug::appendTopReport( "Debug toolbar", $result );
00230         }
00231 
00232         eZDebug::appendBottomReport( 'Template Usage Statistics', eZTemplatesStatisticsReporter::generateStatistics( $as_html ) );
00233 
00234         eZDebug::setScriptStop( $scriptStopTime );
00235         return eZDebug::printReport( $type == "popup", $as_html, true, false, true,
00236             true, $ini->variable( "DebugSettings", "DisplayIncludedFiles" ) == 'enabled' );
00237     }
00238     return null;
00239 }
00240 
00241 /*!
00242   \private
00243 */
00244 function eZDisplayResult( $templateResult )
00245 {
00246     ob_start();
00247     if ( $templateResult !== null )
00248     {
00249         $classname = eZINI::instance()->variable( "OutputSettings", "OutputFilterName" );//deprecated
00250         if( !empty( $classname ) && class_exists( $classname ) )
00251         {
00252             $templateResult = call_user_func( array ( $classname, 'filter' ), $templateResult );
00253         }
00254         $templateResult = ezpEvent::getInstance()->filter( 'response/preoutput', $templateResult );
00255         $debugMarker = '<!--DEBUG_REPORT-->';
00256         $pos = strpos( $templateResult, $debugMarker );
00257         if ( $pos !== false )
00258         {
00259             $debugMarkerLength = strlen( $debugMarker );
00260             echo substr( $templateResult, 0, $pos );
00261             eZDisplayDebug();
00262             echo substr( $templateResult, $pos + $debugMarkerLength );
00263         }
00264         else
00265         {
00266             echo $templateResult, eZDisplayDebug();
00267         }
00268     }
00269     else
00270     {
00271         eZDisplayDebug();
00272     }
00273     $fullPage = ob_get_clean();
00274     echo ezpEvent::getInstance()->filter( 'response/output', $fullPage );
00275 }
00276 
00277 function fetchModule( $uri, $check, &$module, &$module_name, &$function_name, &$params )
00278 {
00279     $module_name = $uri->element();
00280     if ( $check !== null and isset( $check["module"] ) )
00281         $module_name = $check["module"];
00282 
00283     // Try to fetch the module object
00284     $module = eZModule::exists( $module_name );
00285     if ( !( $module instanceof eZModule ) )
00286     {
00287         return false;
00288     }
00289 
00290     $uri->increase();
00291     $function_name = "";
00292     if ( !$module->singleFunction() )
00293     {
00294         $function_name = $uri->element();
00295         $uri->increase();
00296     }
00297     // Override it if required
00298     if ( $check !== null and isset( $check["function"] ) )
00299         $function_name = $check["function"];
00300 
00301     $params = $uri->elements( false );
00302     return true;
00303 }
00304 
00305 $httpCharset = eZTextCodec::httpCharset();
00306 if ( $ini->variable( 'RegionalSettings', 'Debug' ) == 'enabled' )
00307     eZLocale::setIsDebugEnabled( true );
00308 
00309 
00310 eZDebug::setHandleType( eZDebug::HANDLE_FROM_PHP );
00311 
00312 $GLOBALS['eZGlobalRequestURI'] = eZSys::serverVariable( 'REQUEST_URI' );
00313 
00314 // Initialize basic settings, such as vhless dirs and separators
00315 
00316 eZSys::init( 'index.php', $ini->variable( 'SiteAccessSettings', 'ForceVirtualHost' ) === 'true' );
00317 
00318 eZDebug::addTimingPoint( "Script start" );
00319 
00320 $uri = eZURI::instance( eZSys::requestURI() );
00321 $GLOBALS['eZRequestedURI'] = $uri;
00322 
00323 // Check for extension
00324 eZExtension::activateExtensions( 'default' );
00325 // Extension check end
00326 
00327 $access = eZSiteAccess::match( $uri,
00328                       eZSys::hostname(),
00329                       eZSys::serverPort(),
00330                       eZSys::indexFile() );
00331 $access = eZSiteAccess::change( $access );
00332 eZDebugSetting::writeDebug( 'kernel-siteaccess', $access, 'current siteaccess' );
00333 
00334 // Check for siteaccess extension
00335 eZExtension::activateExtensions( 'access' );
00336 // Siteaccess extension check end
00337 
00338 // Now that all extensions are activated and siteaccess has been changed, reset
00339 // all eZINI instances as they may not take into account siteaccess specific settings.
00340 eZINI::resetAllInstances( false );
00341 
00342 ezpEvent::getInstance()->registerEventListeners();
00343 
00344 // Be able to do general events early in process
00345 ezpEvent::getInstance()->notify( 'request/preinput', array( $uri ) );
00346 
00347 $mobileDeviceDetect = new ezpMobileDeviceDetect( ezpMobileDeviceDetectFilter::getFilter() );
00348 if( $mobileDeviceDetect->isEnabled() )
00349 {
00350     $mobileDeviceDetect->process();
00351 
00352     if ( $mobileDeviceDetect->isMobileDevice() )
00353         $mobileDeviceDetect->redirect();
00354 }
00355 
00356 // Initialize module loading
00357 $moduleRepositories = eZModule::activeModuleRepositories();
00358 eZModule::setGlobalPathList( $moduleRepositories );
00359 
00360 // make sure we get a new $ini instance now that it has been reset
00361 $ini = eZINI::instance();
00362 
00363 // start: eZCheckValidity
00364 // pre check, setup wizard related so needs to be before session/db init
00365 if ( $ini->variable( 'SiteAccessSettings', 'CheckValidity' ) === 'true' )
00366 {
00367     $check = array( 'module' => 'setup',
00368                     'function' => 'init' );
00369     // Turn off some features that won't bee needed yet
00370     $siteBasics['policy-check-omit-list'][] = 'setup';
00371     $siteBasics['show-page-layout'] = $ini->variable( 'SetupSettings', 'PageLayout' );
00372     $siteBasics['validity-check-required'] = true;
00373     $siteBasics['session-required'] = $siteBasics['user-object-required'] = false;
00374     $siteBasics['db-required'] = $siteBasics['no-cache-adviced'] = $siteBasics['url-translator-allowed'] = false;
00375     $siteBasics['site-design-override'] = $ini->variable( 'SetupSettings', 'OverrideSiteDesign' );
00376     $access = array( 'name' => 'setup',
00377                      'type' => eZSiteAccess::TYPE_URI );
00378     $access = eZSiteAccess::change( $access );
00379     eZTranslatorManager::enableDynamicTranslations();
00380 }
00381 // stop: eZCheckValidity
00382 
00383 if ( $sessionRequired )
00384 {
00385     // Check if this should be run in a cronjob
00386     if ( $ini->variable( 'Session', 'BasketCleanup' ) !== 'cronjob' )
00387     {
00388         // Functions for session to make sure baskets are cleaned up
00389         function eZSessionBasketDestroy( $db, $key, $escapedKey )
00390         {
00391             $basket = eZBasket::fetch( $key );
00392             if ( is_object( $basket ) )
00393                 $basket->remove();
00394         }
00395 
00396         function eZSessionBasketGarbageCollector( $db, $time )
00397         {
00398             eZBasket::cleanupExpired( $time );
00399         }
00400 
00401         function eZSessionBasketEmpty( $db )
00402         {
00403             eZBasket::cleanup();
00404         }
00405 
00406         // Fill in hooks
00407         eZSession::addCallback( 'destroy_pre', 'eZSessionBasketDestroy');
00408         eZSession::addCallback( 'gc_pre',      'eZSessionBasketGarbageCollector');
00409         eZSession::addCallback( 'cleanup_pre', 'eZSessionBasketCleanup');
00410     }
00411 
00412     // addCallBack to update session id for shop basket on session regenerate
00413     function eZSessionBasketRegenerate( $db, $escNewKey, $escOldKey, $escUserID  )
00414     {
00415         $db->query( "UPDATE ezbasket SET session_id='$escNewKey' WHERE session_id='$escOldKey'" );
00416     }
00417 
00418     eZSession::addCallback( 'regenerate_post', 'eZSessionBasketRegenerate');
00419 
00420     if ( $ini->variable( 'Session', 'ForceStart' ) === 'enabled' )
00421         eZSession::start();
00422     else
00423         eZSession::lazyStart();
00424 
00425     // let session specify if db is required
00426     $dbRequired = eZSession::getHandlerInstance()->dbRequired();
00427 }
00428 
00429 // if $dbRequired, open a db connection and check that db is connected
00430 if ( $dbRequired && !eZDB::instance()->isConnected() )
00431 {
00432     $warningList[] = array( 'error' => array( 'type' => 'kernel',
00433                                               'number' => eZError::KERNEL_NO_DB_CONNECTION ),
00434                             'text' => 'No database connection could be made, the system might not behave properly.' );
00435 }
00436 
00437 // eZCheckUser: pre check, RequireUserLogin & FORCE_LOGIN related so needs to be after session init
00438 if ( !isset( $check ) )
00439 {
00440     $check = eZUserLoginHandler::preCheck( $siteBasics, $uri );
00441 }
00442 
00443 /**
00444  * Check for activating Debug by user ID (Final checking. The first was in eZDebug::updateSettings())
00445  * @uses eZUser::instance() So needs to be executed after eZSession::start()|lazyStart()
00446  */
00447 eZDebug::checkDebugByUser();
00448 
00449 
00450 ezpEvent::getInstance()->notify( 'request/input', array( $uri ) );
00451 
00452 // Initialize with locale settings
00453 $locale = eZLocale::instance();
00454 $languageCode = $locale->httpLocaleCode();
00455 $phpLocale = trim( $ini->variable( 'RegionalSettings', 'SystemLocale' ) );
00456 if ( $phpLocale != '' )
00457 {
00458     setlocale( LC_ALL, explode( ',', $phpLocale ) );
00459 }
00460 
00461 // send header information
00462 $headerList = array( 'Expires' => 'Mon, 26 Jul 1997 05:00:00 GMT',
00463                      'Last-Modified' => gmdate( 'D, d M Y H:i:s' ) . ' GMT',
00464                      'Cache-Control' => 'no-cache, must-revalidate',
00465                      'Pragma' => 'no-cache',
00466                      'X-Powered-By' => 'eZ Publish',
00467                      'Content-Type' => 'text/html; charset=' . $httpCharset,
00468                      'Served-by' => $_SERVER["SERVER_NAME"],
00469                      'Content-language' => $languageCode );
00470 
00471 $site = array( 'title' => $ini->variable( 'SiteSettings', 'SiteName' ),
00472                'design' => $ini->variable( 'DesignSettings', 'SiteDesign' ),
00473                'http_equiv' => array( 'Content-Type' => 'text/html; charset=' . $httpCharset,
00474                                       'Content-language' => $languageCode ) );
00475 
00476 
00477 $headerOverrideArray = eZHTTPHeader::headerOverrideArray( $uri );
00478 
00479 $headerList = array_merge( $headerList, $headerOverrideArray );
00480 
00481 foreach( $headerList as $key => $value )
00482 {
00483     header( $key . ': ' . $value );
00484 }
00485 
00486 // Read role settings
00487 $globalPolicyCheckOmitList = $ini->variable( 'RoleSettings', 'PolicyOmitList' );
00488 $policyCheckOmitList = array_merge( $policyCheckOmitList, $globalPolicyCheckOmitList );
00489 $policyCheckViewMap = array();
00490 foreach ( $policyCheckOmitList as $omitItem )
00491 {
00492     $items = explode( '/', $omitItem );
00493     if ( count( $items ) > 1 )
00494     {
00495         $module = $items[0];
00496         $view = $items[1];
00497         if ( !isset( $policyCheckViewMap[$module] ) )
00498             $policyCheckViewMap[$module] = array();
00499         $policyCheckViewMap[$module][] = $view;
00500     }
00501 }
00502 
00503 
00504 // Start the module loop
00505 while ( $moduleRunRequired )
00506 {
00507     $objectHasMovedError = false;
00508     $objectHasMovedURI = false;
00509     $actualRequestedURI = $uri->uriString();
00510 
00511     // Extract user specified parameters
00512     $userParameters = $uri->userParameters();
00513 
00514     // Generate a URI which also includes the user parameters
00515     $completeRequestedURI = $uri->originalURIString();
00516 
00517     // Check for URL translation
00518     if ( $urlTranslatorAllowed and
00519          eZURLAliasML::urlTranslationEnabledByUri( $uri ) )
00520     {
00521         $translateResult = eZURLAliasML::translate( $uri );
00522 
00523         if ( !is_string( $translateResult ) )
00524         {
00525             $useWildcardTranslation = $ini->variable( 'URLTranslator', 'WildcardTranslation' ) == 'enabled';
00526             if ( $useWildcardTranslation )
00527             {
00528                 $translateResult = eZURLWildcard::translate( $uri );
00529             }
00530         }
00531 
00532         // Check if the URL has moved
00533         if ( is_string( $translateResult ) )
00534         {
00535             $objectHasMovedURI = $translateResult;
00536             foreach ( $userParameters as $name => $value )
00537             {
00538                 $objectHasMovedURI .= '/(' . $name . ')/' . $value;
00539             }
00540 
00541             $objectHasMovedError = true;
00542         }
00543     }
00544 
00545     if ( $uri->isEmpty() )
00546     {
00547         $tmp_uri = new eZURI( $ini->variable( "SiteSettings", "IndexPage" ) );
00548         $moduleCheck = eZModule::accessAllowed( $tmp_uri );
00549     }
00550     else
00551     {
00552         $moduleCheck = eZModule::accessAllowed( $uri );
00553     }
00554 
00555     if ( !$moduleCheck['result'] )
00556     {
00557         if ( $ini->variable( "SiteSettings", "ErrorHandler" ) == "defaultpage" )
00558         {
00559             $defaultPage = $ini->variable( "SiteSettings", "DefaultPage" );
00560             $uri->setURIString( $defaultPage );
00561             $moduleCheck['result'] = true;
00562         }
00563     }
00564 
00565     $http = eZHTTPTool::instance();
00566 
00567     $displayMissingModule = false;
00568     $oldURI = $uri;
00569 
00570     if ( $uri->isEmpty() )
00571     {
00572         if ( !fetchModule( $tmp_uri, $check, $module, $module_name, $function_name, $params ) )
00573             $displayMissingModule = true;
00574     }
00575     else if ( !fetchModule( $uri, $check, $module, $module_name, $function_name, $params ) )
00576     {
00577         if ( $ini->variable( "SiteSettings", "ErrorHandler" ) == "defaultpage" )
00578         {
00579             $tmp_uri = new eZURI( $ini->variable( "SiteSettings", "DefaultPage" ) );
00580             if ( !fetchModule( $tmp_uri, $check, $module, $module_name, $function_name, $params ) )
00581                 $displayMissingModule = true;
00582         }
00583         else
00584             $displayMissingModule = true;
00585     }
00586 
00587     if ( !$displayMissingModule &&
00588          $moduleCheck['result'] &&
00589          $module instanceof eZModule )
00590     {
00591         // Run the module/function
00592         eZDebug::addTimingPoint( "Module start '" . $module->attribute( 'name' ) . "'" );
00593 
00594         $moduleAccessAllowed = true;
00595         $omitPolicyCheck = true;
00596         $runModuleView = true;
00597 
00598         $availableViewsInModule = $module->attribute( 'views' );
00599         if ( !isset( $availableViewsInModule[$function_name] )
00600                 && !$objectHasMovedError
00601                     && !isset( $module->Module['function']['script'] ) )
00602         {
00603             $moduleResult = $module->handleError( eZError::KERNEL_MODULE_VIEW_NOT_FOUND, 'kernel' );
00604             $runModuleView = false;
00605             $policyCheckRequired = false;
00606             $omitPolicyCheck = true;
00607         }
00608 
00609         if ( $policyCheckRequired )
00610         {
00611             $omitPolicyCheck = false;
00612             $moduleName = $module->attribute( 'name' );
00613             $viewName = $function_name;
00614             if ( in_array( $moduleName, $policyCheckOmitList ) )
00615                 $omitPolicyCheck = true;
00616             else if ( isset( $policyCheckViewMap[$moduleName] ) and
00617                       in_array( $viewName, $policyCheckViewMap[$moduleName] ) )
00618                 $omitPolicyCheck = true;
00619         }
00620         if ( !$omitPolicyCheck )
00621         {
00622             $currentUser = eZUser::currentUser();
00623             $siteAccessResult = $currentUser->hasAccessTo( 'user', 'login' );
00624 
00625             $hasAccessToSite = false;
00626             if ( $siteAccessResult[ 'accessWord' ] == 'limited' )
00627             {
00628                 $policyChecked = false;
00629                 foreach ( array_keys( $siteAccessResult['policies'] ) as $key )
00630                 {
00631                     $policy = $siteAccessResult['policies'][$key];
00632                     if ( isset( $policy['SiteAccess'] ) )
00633                     {
00634                         $policyChecked = true;
00635                         $crc32AccessName = eZSys::ezcrc32( $access[ 'name' ] );
00636                         eZDebugSetting::writeDebug( 'kernel-siteaccess', $policy['SiteAccess'], $crc32AccessName );
00637                         if ( in_array( $crc32AccessName, $policy['SiteAccess'] ) )
00638                         {
00639                             $hasAccessToSite = true;
00640                             break;
00641                         }
00642                     }
00643                     if ( $hasAccessToSite )
00644                         break;
00645                 }
00646                 if ( !$policyChecked )
00647                     $hasAccessToSite = true;
00648             }
00649             else if ( $siteAccessResult[ 'accessWord' ] == 'yes' )
00650             {
00651                 eZDebugSetting::writeDebug( 'kernel-siteaccess', "access is yes" );
00652                 $hasAccessToSite = true;
00653             }
00654             else if ( $siteAccessResult['accessWord'] == 'no' )
00655             {
00656                 $accessList = $siteAccessResult['accessList'];
00657             }
00658 
00659             if ( $hasAccessToSite )
00660             {
00661                 $accessParams = array();
00662                 $moduleAccessAllowed = $currentUser->hasAccessToView( $module, $function_name, $accessParams );
00663                 if ( isset( $accessParams['accessList'] ) )
00664                 {
00665                     $accessList = $accessParams['accessList'];
00666                 }
00667             }
00668             else
00669             {
00670                 eZDebugSetting::writeDebug( 'kernel-siteaccess', $access, 'not able to get access to siteaccess' );
00671                 $moduleAccessAllowed = false;
00672                 $requireUserLogin = ( $ini->variable( "SiteAccessSettings", "RequireUserLogin" ) == "true" );
00673                 if ( $requireUserLogin )
00674                 {
00675                     $module = eZModule::exists( 'user' );
00676                     if ( $module instanceof eZModule )
00677                     {
00678                         $moduleResult = $module->run( 'login', array(),
00679                                                        array( 'SiteAccessAllowed' => false,
00680                                                               'SiteAccessName' => $access['name'] ) );
00681                         $runModuleView = false;
00682                     }
00683                 }
00684             }
00685         }
00686 
00687         $GLOBALS['eZRequestedModule'] = $module;
00688 
00689         if ( $runModuleView )
00690         {
00691             if ( $objectHasMovedError == true )
00692             {
00693                 $moduleResult = $module->handleError( eZError::KERNEL_MOVED, 'kernel', array( 'new_location' => $objectHasMovedURI ) );
00694             }
00695             else if ( !$moduleAccessAllowed )
00696             {
00697                 if ( isset( $availableViewsInModule[$function_name][ 'default_navigation_part' ] ) )
00698                 {
00699                     $defaultNavigationPart = $availableViewsInModule[$function_name][ 'default_navigation_part' ];
00700                 }
00701 
00702                 if ( isset( $accessList ) )
00703                     $moduleResult = $module->handleError( eZError::KERNEL_ACCESS_DENIED, 'kernel', array( 'AccessList' => $accessList ) );
00704                 else
00705                     $moduleResult = $module->handleError( eZError::KERNEL_ACCESS_DENIED, 'kernel' );
00706 
00707                 if ( isset( $defaultNavigationPart ) )
00708                 {
00709                     $moduleResult['navigation_part'] = $defaultNavigationPart;
00710                     unset( $defaultNavigationPart );
00711                 }
00712             }
00713             else
00714             {
00715                 if ( !isset( $userParameters ) )
00716                 {
00717                     $userParameters = false;
00718                 }
00719 
00720                 // Check if we should switch access mode (http/https) for this module view.
00721                 eZSSLZone::checkModuleView( $module->attribute( 'name' ), $function_name );
00722 
00723                 $moduleResult = $module->run( $function_name, $params, false, $userParameters );
00724 
00725                 if ( $module->exitStatus() == eZModule::STATUS_FAILED and
00726                      $moduleResult == null )
00727                     $moduleResult = $module->handleError( eZError::KERNEL_MODULE_VIEW_NOT_FOUND, 'kernel', array( 'module' => $module_name,
00728                                                                                                                    'view' => $function_name ) );
00729             }
00730         }
00731     }
00732     else if ( $moduleCheck['result'] )
00733     {
00734         eZDebug::writeError( "Undefined module: $module_name", "index" );
00735         $module = new eZModule( "", "", $module_name );
00736         $GLOBALS['eZRequestedModule'] = $module;
00737         $moduleResult = $module->handleError( eZError::KERNEL_MODULE_NOT_FOUND, 'kernel', array( 'module' => $module_name ) );
00738     }
00739     else
00740     {
00741         if ( $moduleCheck['view_checked'] )
00742             eZDebug::writeError( "View '" . $moduleCheck['view'] . "' in module '" . $moduleCheck['module'] . "' is disabled", "index" );
00743         else
00744             eZDebug::writeError( "Module '" . $moduleCheck['module'] . "' is disabled", "index" );
00745         $module = new eZModule( "", "", $moduleCheck['module'] );
00746         $GLOBALS['eZRequestedModule'] = $module;
00747         $moduleResult = $module->handleError( eZError::KERNEL_MODULE_DISABLED, 'kernel', array( 'check' => $moduleCheck ) );
00748     }
00749     $moduleRunRequired = false;
00750     if ( $module->exitStatus() == eZModule::STATUS_RERUN )
00751     {
00752         if ( isset( $moduleResult['rerun_uri'] ) )
00753         {
00754             $uri = eZURI::instance( $moduleResult['rerun_uri'] );
00755             $moduleRunRequired = true;
00756         }
00757         else
00758             eZDebug::writeError( 'No rerun URI specified, cannot continue', 'index.php' );
00759     }
00760 
00761     if ( is_array( $moduleResult ) )
00762     {
00763         if ( isset( $moduleResult["pagelayout"] ) )
00764         {
00765             $show_page_layout = $moduleResult["pagelayout"];
00766             $GLOBALS['eZCustomPageLayout'] = $moduleResult["pagelayout"];
00767         }
00768         if ( isset( $moduleResult["external_css"] ) )
00769             $use_external_css = $moduleResult["external_css"];
00770     }
00771 }
00772 
00773 
00774 /**
00775  * Ouput an is_logged_in cookie when users are logged in for use by http cache soulutions.
00776  *
00777  * @deprecated As of 4.5, since 4.4 added lazy session support (init on use)
00778  */
00779 if ( $ini->variable( "SiteAccessSettings", "CheckValidity" ) !== 'true' )
00780 {
00781     $currentUser = eZUser::currentUser();
00782 
00783     $wwwDir = eZSys::wwwDir();
00784     // On host based site accesses this can be empty, causing the cookie to be set for the current dir,
00785     // but we want it to be set for the whole eZ publish site
00786     $cookiePath = $wwwDir != '' ? $wwwDir : '/';
00787 
00788     if ( $currentUser->isLoggedIn() )
00789     {
00790         // Only set the cookie if it doesnt exist. This way we are not constantly sending the set request in the headers.
00791         if ( !isset( $_COOKIE['is_logged_in'] ) || $_COOKIE['is_logged_in'] != 'true' )
00792         {
00793             setcookie( 'is_logged_in', 'true', 0, $cookiePath );
00794         }
00795     }
00796     else if ( isset( $_COOKIE['is_logged_in'] ) )
00797     {
00798         setcookie( 'is_logged_in', false, 0, $cookiePath );
00799     }
00800 }
00801 
00802 if ( $module->exitStatus() == eZModule::STATUS_REDIRECT )
00803 {
00804     $GLOBALS['eZRedirection'] = true;
00805     $ini = eZINI::instance();
00806     $automatic_redir = true;
00807 
00808     if ( $GLOBALS['eZDebugAllowed'] && ( $redirUri = $ini->variable( 'DebugSettings', 'DebugRedirection' ) ) != 'disabled' )
00809     {
00810         if ( $redirUri == "enabled" )
00811         {
00812             $automatic_redir = false;
00813         }
00814         else
00815         {
00816             $redirUris = $ini->variableArray( "DebugSettings", "DebugRedirection" );
00817             $uri = eZURI::instance( eZSys::requestURI() );
00818             $uri->toBeginning();
00819             foreach ( $redirUris as $redirUri )
00820             {
00821                 $redirUri = new eZURI( $redirUri );
00822                 if ( $redirUri->matchBase( $uri ) )
00823                 {
00824                     $automatic_redir = false;
00825                     break;
00826                 }
00827             }
00828         }
00829     }
00830 
00831     $redirectURI = eZSys::indexDir();
00832 
00833     $moduleRedirectUri = $module->redirectURI();
00834     $redirectStatus = $module->redirectStatus();
00835     $translatedModuleRedirectUri = $moduleRedirectUri;
00836     if ( $ini->variable( 'URLTranslator', 'Translation' ) == 'enabled' &&
00837          eZURLAliasML::urlTranslationEnabledByUri( new eZURI( $moduleRedirectUri ) ) )
00838     {
00839         if ( eZURLAliasML::translate( $translatedModuleRedirectUri, true ) )
00840         {
00841             $moduleRedirectUri = $translatedModuleRedirectUri;
00842             if ( strlen( $moduleRedirectUri ) > 0 and
00843                  $moduleRedirectUri[0] != '/' )
00844                 $moduleRedirectUri = '/' . $moduleRedirectUri;
00845         }
00846     }
00847 
00848     if ( preg_match( '#^(\w+:)|^//#', $moduleRedirectUri ) )
00849     {
00850         $redirectURI = $moduleRedirectUri;
00851     }
00852     else
00853     {
00854         $leftSlash = false;
00855         $rightSlash = false;
00856         if ( strlen( $redirectURI ) > 0 and
00857              $redirectURI[strlen( $redirectURI ) - 1] == '/' )
00858             $leftSlash = true;
00859         if ( strlen( $moduleRedirectUri ) > 0 and
00860              $moduleRedirectUri[0] == '/' )
00861             $rightSlash = true;
00862 
00863         if ( !$leftSlash and !$rightSlash ) // Both are without a slash, so add one
00864             $moduleRedirectUri = '/' . $moduleRedirectUri;
00865         else if ( $leftSlash and $rightSlash ) // Both are with a slash, so we remove one
00866             $moduleRedirectUri = substr( $moduleRedirectUri, 1 );
00867         $redirectURI .= $moduleRedirectUri;
00868     }
00869 
00870     eZStaticCache::executeActions();
00871 
00872     eZDB::checkTransactionCounter();
00873 
00874     if ( $automatic_redir )
00875     {
00876         eZHTTPTool::redirect( $redirectURI, array(), $redirectStatus );
00877     }
00878     else
00879     {
00880         // Make sure any errors or warnings are reported
00881         if ( $ini->variable( 'DebugSettings', 'DisplayDebugWarnings' ) == 'enabled' )
00882         {
00883             if ( isset( $GLOBALS['eZDebugError'] ) and
00884                  $GLOBALS['eZDebugError'] )
00885             {
00886                 eZAppendWarningItem( array( 'error' => array( 'type' => 'error',
00887                                                               'number' => 1,
00888                                                               'count' => $GLOBALS['eZDebugErrorCount'] ),
00889                                             'identifier' => 'ezdebug-first-error',
00890                                             'text' => ezpI18n::tr( 'index.php', 'Some errors occurred, see debug for more information.' ) ) );
00891             }
00892 
00893             if ( isset( $GLOBALS['eZDebugWarning'] ) and
00894                  $GLOBALS['eZDebugWarning'] )
00895             {
00896                 eZAppendWarningItem( array( 'error' => array( 'type' => 'warning',
00897                                                               'number' => 1,
00898                                                               'count' => $GLOBALS['eZDebugWarningCount'] ),
00899                                             'identifier' => 'ezdebug-first-warning',
00900                                             'text' => ezpI18n::tr( 'index.php', 'Some general warnings occured, see debug for more information.' ) ) );
00901             }
00902         }
00903 
00904         $tpl = eZTemplate::factory();
00905         if ( empty( $warningList ) )
00906             $warningList = false;
00907 
00908         $tpl->setVariable( 'site', $site );
00909         $tpl->setVariable( 'warning_list', $warningList );
00910         $tpl->setVariable( 'redirect_uri', eZURI::encodeURL( $redirectURI ) );
00911         $templateResult = $tpl->fetch( 'design:redirect.tpl' );
00912 
00913         eZDebug::addTimingPoint( "Script end" );
00914 
00915         eZDisplayResult( $templateResult );
00916     }
00917 
00918     eZExecution::cleanExit();
00919 }
00920 
00921 // Store the last URI for access history for login redirection
00922 // Only if user has session and only if there was no error or no redirects happen
00923 if ( eZSession::hasStarted() &&
00924     $module->exitStatus() == eZModule::STATUS_OK )
00925 {
00926     $currentURI = $completeRequestedURI;
00927     if ( strlen( $currentURI ) > 0 and $currentURI[0] != '/' )
00928         $currentURI = '/' . $currentURI;
00929 
00930     $lastAccessedURI = "";
00931     $lastAccessedViewURI = "";
00932 
00933     $http = eZHTTPTool::instance();
00934 
00935     // Fetched stored session variables
00936     if ( $http->hasSessionVariable( "LastAccessesURI" ) )
00937     {
00938         $lastAccessedViewURI = $http->sessionVariable( "LastAccessesURI" );
00939     }
00940     if ( $http->hasSessionVariable( "LastAccessedModifyingURI" ) )
00941     {
00942         $lastAccessedURI = $http->sessionVariable( "LastAccessedModifyingURI" );
00943     }
00944 
00945     // Update last accessed view page
00946     if ( $currentURI != $lastAccessedViewURI and
00947          !in_array( $module->uiContextName(), array( 'edit', 'administration', 'browse', 'authentication' ) ) )
00948     {
00949         $http->setSessionVariable( "LastAccessesURI", $currentURI );
00950     }
00951 
00952     // Update last accessed non-view page
00953     if ( $currentURI != $lastAccessedURI )
00954     {
00955         $http->setSessionVariable( "LastAccessedModifyingURI", $currentURI );
00956     }
00957 }
00958 
00959 
00960 eZDebug::addTimingPoint( "Module end '" . $module->attribute( 'name' ) . "'" );
00961 if ( !is_array( $moduleResult ) )
00962 {
00963     eZDebug::writeError( 'Module did not return proper result: ' . $module->attribute( 'name' ), 'index.php' );
00964     $moduleResult = array();
00965     $moduleResult['content'] = false;
00966 }
00967 
00968 if ( !isset( $moduleResult['ui_context'] ) )
00969 {
00970     $moduleResult['ui_context'] = $module->uiContextName();
00971 }
00972 $moduleResult['ui_component'] = $module->uiComponentName();
00973 $moduleResult['is_mobile_device'] = $mobileDeviceDetect->isMobileDevice();
00974 $moduleResult['mobile_device_alias'] = $mobileDeviceDetect->getUserAgentAlias();
00975 
00976 $templateResult = null;
00977 
00978 eZDebug::setUseExternalCSS( $use_external_css );
00979 if ( $show_page_layout )
00980 {
00981     $tpl = eZTemplate::factory();
00982     if ( $tpl->hasVariable( 'node' ) )
00983         $tpl->unsetVariable( 'node' );
00984 
00985     if ( !isset( $moduleResult['path'] ) )
00986         $moduleResult['path'] = false;
00987     $moduleResult['uri'] = eZSys::requestURI();
00988 
00989     $tpl->setVariable( "module_result", $moduleResult );
00990 
00991     $meta = $ini->variable( 'SiteSettings', 'MetaDataArray' );
00992 
00993     if ( !isset( $meta['description'] ) )
00994     {
00995         $metaDescription = "";
00996         if ( isset( $moduleResult['path'] ) and
00997              is_array( $moduleResult['path'] ) )
00998         {
00999             foreach ( $moduleResult['path'] as $pathPart )
01000             {
01001                 if ( isset( $pathPart['text'] ) )
01002                     $metaDescription .= $pathPart['text'] . " ";
01003             }
01004         }
01005         $meta['description'] = $metaDescription;
01006     }
01007 
01008     $site['uri'] = $oldURI;
01009     $site['redirect'] = false;
01010     $site['meta'] = $meta;
01011     $site['version'] = eZPublishSDK::version();
01012     $site['page_title'] = $module->title();
01013 
01014     $tpl->setVariable( "site", $site );
01015 
01016     if ( $ini->variable( 'DebugSettings', 'DisplayDebugWarnings' ) == 'enabled' )
01017     {
01018         // Make sure any errors or warnings are reported
01019         if ( isset( $GLOBALS['eZDebugError'] ) and
01020              $GLOBALS['eZDebugError'] )
01021         {
01022             eZAppendWarningItem( array( 'error' => array( 'type' => 'error',
01023                                                           'number' => 1 ,
01024                                                           'count' => $GLOBALS['eZDebugErrorCount'] ),
01025                                         'identifier' => 'ezdebug-first-error',
01026                                         'text' => ezpI18n::tr( 'index.php', 'Some errors occurred, see debug for more information.' ) ) );
01027         }
01028 
01029         if ( isset( $GLOBALS['eZDebugWarning'] ) and
01030              $GLOBALS['eZDebugWarning'] )
01031         {
01032             eZAppendWarningItem( array( 'error' => array( 'type' => 'warning',
01033                                                           'number' => 1,
01034                                                           'count' => $GLOBALS['eZDebugWarningCount'] ),
01035                                         'identifier' => 'ezdebug-first-warning',
01036                                         'text' => ezpI18n::tr( 'index.php', 'Some general warnings occured, see debug for more information.' ) ) );
01037         }
01038     }
01039 
01040     if ( $userObjectRequired )
01041     {
01042         $currentUser = eZUser::currentUser();
01043 
01044         $tpl->setVariable( "current_user", $currentUser );
01045         $tpl->setVariable( "anonymous_user_id", $ini->variable( 'UserSettings', 'AnonymousUserID' ) );
01046     }
01047     else
01048     {
01049         $tpl->setVariable( "current_user", false );
01050         $tpl->setVariable( "anonymous_user_id", false );
01051     }
01052 
01053     $tpl->setVariable( "access_type", $access );
01054 
01055     if ( empty( $warningList ) )
01056         $warningList = false;
01057 
01058     $tpl->setVariable( 'warning_list', $warningList );
01059 
01060     $resource = "design:";
01061     if ( is_string( $show_page_layout ) )
01062     {
01063         if ( strpos( $show_page_layout, ":" ) !== false )
01064         {
01065             $resource = "";
01066         }
01067     }
01068     else
01069     {
01070         $show_page_layout = "pagelayout.tpl";
01071     }
01072 
01073     // Set the navigation part
01074     // Check for navigation part settings
01075     $navigationPartString = 'ezcontentnavigationpart';
01076     if ( isset( $moduleResult['navigation_part'] ) )
01077     {
01078         $navigationPartString = $moduleResult['navigation_part'];
01079 
01080         // Fetch the navigation part
01081     }
01082     $navigationPart = eZNavigationPart::fetchPartByIdentifier( $navigationPartString );
01083 
01084     $tpl->setVariable( 'navigation_part', $navigationPart );
01085     $tpl->setVariable( 'uri_string', $uri->uriString() );
01086     if ( isset( $moduleResult['requested_uri_string'] ) )
01087     {
01088         $tpl->setVariable( 'requested_uri_string', $moduleResult['requested_uri_string'] );
01089     }
01090     else
01091     {
01092         $tpl->setVariable( 'requested_uri_string', $actualRequestedURI );
01093     }
01094 
01095     // Set UI context and component
01096     $tpl->setVariable( 'ui_context', $moduleResult['ui_context'] );
01097     $tpl->setVariable( 'ui_component', $moduleResult['ui_component'] );
01098 
01099     $templateResult = $tpl->fetch( $resource . $show_page_layout );
01100 }
01101 else
01102 {
01103     $templateResult = $moduleResult['content'];
01104 }
01105 
01106 
01107 eZDebug::addTimingPoint( "Script end" );
01108 
01109 $out = ob_get_clean();
01110 echo trim( $out );
01111 
01112 eZDB::checkTransactionCounter();
01113 
01114 eZDisplayResult( $templateResult );
01115 
01116 eZExecution::cleanup();
01117 eZExecution::setCleanExit();
01118 
01119 ?>