/**
  * Execution point for controller actions
  */
 public function run()
 {
     if ($this->mobileDeviceDetect->isEnabled()) {
         $this->mobileDeviceDetect->process();
         if ($this->mobileDeviceDetect->isMobileDevice()) {
             $this->mobileDeviceDetect->redirect();
         }
     }
     ob_start();
     $this->requestInit();
     // send header information
     foreach (eZHTTPHeader::headerOverrideArray($this->uri) + array('Expires' => 'Mon, 26 Jul 1997 05:00:00 GMT', 'Last-Modified' => gmdate('D, d M Y H:i:s') . ' GMT', 'Cache-Control' => 'no-cache, must-revalidate', 'Pragma' => 'no-cache', 'X-Powered-By' => eZPublishSDK::EDITION, 'Content-Type' => 'text/html; charset=' . $this->httpCharset, 'Served-by' => isset($_SERVER["SERVER_NAME"]) ? $_SERVER['SERVER_NAME'] : null, 'Content-language' => $this->languageCode) as $key => $value) {
         header($key . ': ' . $value);
     }
     try {
         $moduleResult = $this->dispatchLoop();
     } catch (Exception $e) {
         $this->shutdown();
         throw $e;
     }
     $ini = eZINI::instance();
     /**
      * Ouput an is_logged_in cookie when users are logged in for use by http cache solutions.
      *
      * @deprecated As of 4.5, since 4.4 added lazy session support (init on use)
      */
     if ($ini->variable("SiteAccessSettings", "CheckValidity") !== 'true') {
         $wwwDir = eZSys::wwwDir();
         // On host based site accesses this can be empty, causing the cookie to be set for the current dir,
         // but we want it to be set for the whole eZ publish site
         $cookiePath = $wwwDir != '' ? $wwwDir : '/';
         if (eZUser::isCurrentUserRegistered()) {
             // Only set the cookie if it doesnt exist. This way we are not constantly sending the set request in the headers.
             if (!isset($_COOKIE['is_logged_in']) || $_COOKIE['is_logged_in'] !== 'true') {
                 setcookie('is_logged_in', 'true', 0, $cookiePath);
             }
         } else {
             if (isset($_COOKIE['is_logged_in'])) {
                 setcookie('is_logged_in', false, 0, $cookiePath);
             }
         }
     }
     if ($this->module->exitStatus() == eZModule::STATUS_REDIRECT) {
         $this->shutdown();
         return $this->redirect();
     }
     $uiContextName = $this->module->uiContextName();
     // Store the last URI for access history for login redirection
     // Only if user has session and only if there was no error or no redirects happen
     if (eZSession::hasStarted() && $this->module->exitStatus() == eZModule::STATUS_OK) {
         $currentURI = $this->completeRequestedURI;
         if (strlen($currentURI) > 0 && $currentURI[0] !== '/') {
             $currentURI = '/' . $currentURI;
         }
         $lastAccessedURI = "";
         $lastAccessedViewURI = "";
         $http = eZHTTPTool::instance();
         // Fetched stored session variables
         if ($http->hasSessionVariable("LastAccessesURI")) {
             $lastAccessedViewURI = $http->sessionVariable("LastAccessesURI");
         }
         if ($http->hasSessionVariable("LastAccessedModifyingURI")) {
             $lastAccessedURI = $http->sessionVariable("LastAccessedModifyingURI");
         }
         // Update last accessed view page
         if ($currentURI != $lastAccessedViewURI && !in_array($uiContextName, array('edit', 'administration', 'ajax', 'browse', 'authentication'))) {
             $http->setSessionVariable("LastAccessesURI", $currentURI);
         }
         // Update last accessed non-view page
         if ($currentURI != $lastAccessedURI && $uiContextName != 'ajax') {
             $http->setSessionVariable("LastAccessedModifyingURI", $currentURI);
         }
     }
     eZDebug::addTimingPoint("Module end '" . $this->module->attribute('name') . "'");
     if (!is_array($moduleResult)) {
         eZDebug::writeError('Module did not return proper result: ' . $this->module->attribute('name'), 'index.php');
         $moduleResult = array();
         $moduleResult['content'] = false;
     }
     if (!isset($moduleResult['ui_context'])) {
         $moduleResult['ui_context'] = $uiContextName;
     }
     $moduleResult['ui_component'] = $this->module->uiComponentName();
     $moduleResult['is_mobile_device'] = $this->mobileDeviceDetect->isMobileDevice();
     $moduleResult['mobile_device_alias'] = $this->mobileDeviceDetect->getUserAgentAlias();
     $templateResult = null;
     eZDebug::setUseExternalCSS($this->siteBasics['external-css']);
     if ($this->siteBasics['show-page-layout']) {
         $tpl = eZTemplate::factory();
         if ($tpl->hasVariable('node')) {
             $tpl->unsetVariable('node');
         }
         if (!isset($moduleResult['path'])) {
             $moduleResult['path'] = false;
         }
         $moduleResult['uri'] = eZSys::requestURI();
         $tpl->setVariable("module_result", $moduleResult);
         $meta = $ini->variable('SiteSettings', 'MetaDataArray');
         if (!isset($meta['description'])) {
             $metaDescription = "";
             if (isset($moduleResult['path']) && is_array($moduleResult['path'])) {
                 foreach ($moduleResult['path'] as $pathPart) {
                     if (isset($pathPart['text'])) {
                         $metaDescription .= $pathPart['text'] . " ";
                     }
                 }
             }
             $meta['description'] = $metaDescription;
         }
         $this->site['uri'] = $this->oldURI;
         $this->site['redirect'] = false;
         $this->site['meta'] = $meta;
         $this->site['version'] = eZPublishSDK::version();
         $this->site['page_title'] = $this->module->title();
         $tpl->setVariable("site", $this->site);
         if ($ini->variable('DebugSettings', 'DisplayDebugWarnings') === 'enabled') {
             // Make sure any errors or warnings are reported
             if (isset($GLOBALS['eZDebugError']) && $GLOBALS['eZDebugError']) {
                 eZAppendWarningItem(array('error' => array('type' => 'error', 'number' => 1, 'count' => $GLOBALS['eZDebugErrorCount']), 'identifier' => 'ezdebug-first-error', 'text' => ezpI18n::tr('index.php', 'Some errors occurred, see debug for more information.')));
             }
             if (isset($GLOBALS['eZDebugWarning']) && $GLOBALS['eZDebugWarning']) {
                 eZAppendWarningItem(array('error' => array('type' => 'warning', 'number' => 1, 'count' => $GLOBALS['eZDebugWarningCount']), 'identifier' => 'ezdebug-first-warning', 'text' => ezpI18n::tr('index.php', 'Some general warnings occured, see debug for more information.')));
             }
         }
         if ($this->siteBasics['user-object-required']) {
             $currentUser = eZUser::currentUser();
             $tpl->setVariable("current_user", $currentUser);
             $tpl->setVariable("anonymous_user_id", $ini->variable('UserSettings', 'AnonymousUserID'));
         } else {
             $tpl->setVariable("current_user", false);
             $tpl->setVariable("anonymous_user_id", false);
         }
         $tpl->setVariable("access_type", $this->access);
         $tpl->setVariable('warning_list', !empty($this->warningList) ? $this->warningList : false);
         $resource = "design:";
         if (is_string($this->siteBasics['show-page-layout'])) {
             if (strpos($this->siteBasics['show-page-layout'], ":") !== false) {
                 $resource = "";
             }
         } else {
             $this->siteBasics['show-page-layout'] = "pagelayout.tpl";
         }
         // Set the navigation part
         // Check for navigation part settings
         $navigationPartString = 'ezcontentnavigationpart';
         if (isset($moduleResult['navigation_part'])) {
             $navigationPartString = $moduleResult['navigation_part'];
             // Fetch the navigation part
         }
         $navigationPart = eZNavigationPart::fetchPartByIdentifier($navigationPartString);
         $tpl->setVariable('navigation_part', $navigationPart);
         $tpl->setVariable('uri_string', $this->uri->uriString());
         if (isset($moduleResult['requested_uri_string'])) {
             $tpl->setVariable('requested_uri_string', $moduleResult['requested_uri_string']);
         } else {
             $tpl->setVariable('requested_uri_string', $this->actualRequestedURI);
         }
         // Set UI context and component
         $tpl->setVariable('ui_context', $moduleResult['ui_context']);
         $tpl->setVariable('ui_component', $moduleResult['ui_component']);
         $templateResult = $tpl->fetch($resource . $this->siteBasics['show-page-layout']);
     } else {
         $templateResult = $moduleResult['content'];
     }
     eZDebug::addTimingPoint("Script end");
     $content = trim(ob_get_clean());
     ob_start();
     eZDB::checkTransactionCounter();
     eZDisplayResult($templateResult);
     $content .= ob_get_clean();
     $this->shutdown();
     return new ezpKernelResult($content, array('module_result' => $moduleResult));
 }
Exemplo n.º 2
0
 /**
  * Constructs an ezpKernel instance
  */
 public function __construct(array $settings = array())
 {
     $this->settings = $settings + array('siteaccess' => null, 'use-exceptions' => false, 'session' => null);
     unset($settings);
     require_once __DIR__ . '/global_functions.php';
     $this->setUseExceptions($this->settings['use-exceptions']);
     $GLOBALS['eZSiteBasics'] = array('external-css' => true, 'show-page-layout' => true, 'module-run-required' => true, 'policy-check-required' => true, 'policy-check-omit-list' => array(), 'url-translator-allowed' => true, 'validity-check-required' => false, 'user-object-required' => true, 'session-required' => true, 'db-required' => false, 'no-cache-adviced' => false, 'site-design-override' => false, 'module-repositories' => array());
     $this->siteBasics =& $GLOBALS['eZSiteBasics'];
     // Reads settings from i18n.ini and passes them to eZTextCodec.
     list($i18nSettings['internal-charset'], $i18nSettings['http-charset'], $i18nSettings['mbstring-extension']) = eZINI::instance('i18n.ini')->variableMulti('CharacterSettings', array('Charset', 'HTTPCharset', 'MBStringExtension'), array(false, false, 'enabled'));
     eZTextCodec::updateSettings($i18nSettings);
     // @todo Change so code only supports utf-8 in 5.0?
     // Initialize debug settings.
     eZUpdateDebugSettings();
     // Set the different permissions/settings.
     $ini = eZINI::instance();
     // Set correct site timezone
     $timezone = $ini->variable("TimeZoneSettings", "TimeZone");
     if ($timezone) {
         date_default_timezone_set($timezone);
     }
     list($iniFilePermission, $iniDirPermission) = $ini->variableMulti('FileSettings', array('StorageFilePermissions', 'StorageDirPermissions'));
     // OPTIMIZATION:
     // Sets permission array as global variable, this avoids the eZCodePage include
     $GLOBALS['EZCODEPAGEPERMISSIONS'] = array('file_permission' => octdec($iniFilePermission), 'dir_permission' => octdec($iniDirPermission), 'var_directory' => eZSys::cacheDirectory());
     unset($i18nSettings, $timezone, $iniFilePermission, $iniDirPermission);
     eZExecution::addCleanupHandler(function () {
         if (class_exists('eZDB', false) && eZDB::hasInstance()) {
             eZDB::instance()->setIsSQLOutputEnabled(false);
         }
     });
     eZExecution::addFatalErrorHandler(function () {
         header("HTTP/1.1 500 Internal Server Error");
         echo "<b>Fatal error</b>: The web server did not finish its request<br/>";
         if (ini_get('display_errors') == 1) {
             if (eZDebug::isDebugEnabled()) {
                 echo "<p>The execution of eZ Publish was abruptly ended, the debug output is present below.</p>";
             } else {
                 echo "<p>Debug information can be found in the log files normally placed in var/log/* or by enabling 'DebugOutput' in site.ini</p>";
             }
         } else {
             echo "<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>";
         }
         eZDisplayResult(null);
     });
     eZExecution::setCleanExit();
     // Enable this line to get eZINI debug output
     // eZINI::setIsDebugEnabled( true );
     // Enable this line to turn off ini caching
     // eZINI::setIsCacheEnabled( false);
     if ($ini->variable('RegionalSettings', 'Debug') === 'enabled') {
         eZLocale::setIsDebugEnabled(true);
     }
     eZDebug::setHandleType(eZDebug::HANDLE_FROM_PHP);
     $GLOBALS['eZGlobalRequestURI'] = eZSys::serverVariable('REQUEST_URI');
     // Initialize basic settings, such as vhless dirs and separators
     eZSys::init('index.php', $ini->variable('SiteAccessSettings', 'ForceVirtualHost') === 'true');
     // Check for extension
     eZExtension::activateExtensions('default');
     // Extension check end
     // Use injected siteaccess if available or match it internally.
     $this->access = isset($this->settings['siteaccess']) ? $this->settings['siteaccess'] : eZSiteAccess::match(eZURI::instance(eZSys::requestURI()), eZSys::hostname(), eZSys::serverPort(), eZSys::indexFile());
     eZSiteAccess::change($this->access);
     eZDebugSetting::writeDebug('kernel-siteaccess', $this->access, 'current siteaccess');
     // Check for siteaccess extension
     eZExtension::activateExtensions('access');
     // Siteaccess extension check end
     // Now that all extensions are activated and siteaccess has been changed, reset
     // all eZINI instances as they may not take into account siteaccess specific settings.
     eZINI::resetAllInstances(false);
     ezpEvent::getInstance()->registerEventListeners();
     $this->mobileDeviceDetect = new ezpMobileDeviceDetect(ezpMobileDeviceDetectFilter::getFilter());
     if ($this->mobileDeviceDetect->isEnabled()) {
         $this->mobileDeviceDetect->process();
         if ($this->mobileDeviceDetect->isMobileDevice()) {
             $this->mobileDeviceDetect->redirect();
         }
     }
     // eZSession::setSessionArray( $mainRequest->session );
     /**
      * Check for activating Debug by user ID (Final checking. The first was in eZDebug::updateSettings())
      * @uses eZUser::instance() So needs to be executed after eZSession::start()|lazyStart()
      */
     eZDebug::checkDebugByUser();
 }
Exemplo n.º 3
0
$access = eZSiteAccess::change($access);
eZDebugSetting::writeDebug('kernel-siteaccess', $access, 'current siteaccess');
// Check for siteaccess extension
eZExtension::activateExtensions('access');
// Siteaccess extension check end
// Now that all extensions are activated and siteaccess has been changed, reset
// all eZINI instances as they may not take into account siteaccess specific settings.
eZINI::resetAllInstances(false);
ezpEvent::getInstance()->registerEventListeners();
// Be able to do general events early in process
ezpEvent::getInstance()->notify('request/preinput', array($uri));
$mobileDeviceDetect = new ezpMobileDeviceDetect(ezpMobileDeviceDetectFilter::getFilter());
if ($mobileDeviceDetect->isEnabled()) {
    $mobileDeviceDetect->process();
    if ($mobileDeviceDetect->isMobileDevice()) {
        $mobileDeviceDetect->redirect();
    }
}
// Initialize module loading
$moduleRepositories = eZModule::activeModuleRepositories();
eZModule::setGlobalPathList($moduleRepositories);
// make sure we get a new $ini instance now that it has been reset
$ini = eZINI::instance();
// start: eZCheckValidity
// pre check, setup wizard related so needs to be before session/db init
if ($ini->variable('SiteAccessSettings', 'CheckValidity') === 'true') {
    $check = array('module' => 'setup', 'function' => 'init');
    // Turn off some features that won't bee needed yet
    $siteBasics['policy-check-omit-list'][] = 'setup';
    $siteBasics['show-page-layout'] = $ini->variable('SetupSettings', 'PageLayout');
    $siteBasics['validity-check-required'] = true;