Exemplo n.º 1
0
 /**
  * Execution point for controller actions
  */
 public function run()
 {
     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' => 'eZ Publish', 'Content-Type' => 'text/html; charset=' . $this->httpCharset, 'Served-by' => $_SERVER["SERVER_NAME"], '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') {
         $currentUser = eZUser::currentUser();
         $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 ($currentUser->isLoggedIn()) {
             // 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->redirect();
     }
     // 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($this->module->uiContextName(), array('edit', 'administration', 'browse', 'authentication'))) {
             $http->setSessionVariable("LastAccessesURI", $currentURI);
         }
         // Update last accessed non-view page
         if ($currentURI != $lastAccessedURI) {
             $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'] = $this->module->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);
 }
Exemplo n.º 2
0
    static function headerOverrideArray( $uri )
    {
        $headerArray = array();

        if ( !eZHTTPHeader::enabled() )
        {
            return $headerArray;
        }

        $contentView = false;

        $uriString = eZURLAliasML::cleanURL( $uri->uriString() );

        // If content/view used, get url alias for node
        if ( strpos( $uriString, 'content/view/' ) === 0 )
        {
            $urlParts = explode( '/', $uriString );
            $nodeID = $urlParts[3];
            if ( !$nodeID )
            {
                return $headerArray;
            }

            $node = eZContentObjectTreeNode::fetch( $nodeID );
            if ( !$node )
            {
                return $headerArray;
            }

            $uriString = $node->pathWithNames();
            $contentView = true;
        }
        else
        {
            $uriCopy = clone $uri;
            eZURLAliasML::translate( $uriCopy );
            if ( strpos( $uriCopy->uriString(), 'content/view' ) === 0 )
            {
                $contentView = true;
            }
        }

        $uriString = '/' . eZURLAliasML::cleanURL( $uriString );
        $ini = eZINI::instance();

        foreach( $ini->variable( 'HTTPHeaderSettings', 'HeaderList' ) as $header )
        {
            foreach( $ini->variable( 'HTTPHeaderSettings', $header ) as $path => $value )
            {
                $path = '/' . eZURLAliasML::cleanURL( $path );
                if ( strlen( $path ) == 1 &&
                     ( !$contentView && ( $ini->variable( 'HTTPHeaderSettings', 'OnlyForContent' ) === 'enabled' ) ) &&
                     $uriString != '/' )
                {
                    continue;
                }

                if ( strpos( $uriString, $path ) === 0 )
                {
                    @list( $headerValue, $depth, $level ) = explode( ';', $value );

                    if ( $header == 'Expires' )
                    {
                        $headerValue = gmdate( 'D, d M Y H:i:s', time() + $headerValue ) . ' GMT';
                    }

                    if ( $depth === null )
                    {
                        $headerArray[$header] = $headerValue;
                    }
                    else
                    {
                        $pathLevel = count( explode( '/', $path ) );
                        $uriLevel = count( explode( '/', $uriString ) );
                        if ( $level === null )
                        {
                            if ( $uriLevel <= $pathLevel + $depth )
                            {
                                $headerArray[$header] = $headerValue;
                            }
                        }
                        else
                        {
                            if ( $uriLevel <= $pathLevel + $depth &&
                                 $uriLevel >= $pathLevel + $level )
                            {
                                $headerArray[$header] = $headerValue;
                            }
                        }
                    }
                }
            }
        }

        return $headerArray;
    }
Exemplo n.º 3
0
 * 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();
ezpEvent::getInstance()->notify('request/input', array($uri));
// Initialize with locale settings
$locale = eZLocale::instance();
$languageCode = $locale->httpLocaleCode();
$phpLocale = trim($ini->variable('RegionalSettings', 'SystemLocale'));
if ($phpLocale != '') {
    setlocale(LC_ALL, explode(',', $phpLocale));
}
// send header information
$headerList = 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' => 'eZ Publish', 'Content-Type' => 'text/html; charset=' . $httpCharset, 'Served-by' => $_SERVER["SERVER_NAME"], 'Content-language' => $languageCode);
$site = array('title' => $ini->variable('SiteSettings', 'SiteName'), 'design' => $ini->variable('DesignSettings', 'SiteDesign'), 'http_equiv' => array('Content-Type' => 'text/html; charset=' . $httpCharset, 'Content-language' => $languageCode));
$headerOverrideArray = eZHTTPHeader::headerOverrideArray($uri);
$headerList = array_merge($headerList, $headerOverrideArray);
foreach ($headerList as $key => $value) {
    header($key . ': ' . $value);
}
// Read role settings
$globalPolicyCheckOmitList = $ini->variable('RoleSettings', 'PolicyOmitList');
$policyCheckOmitList = array_merge($policyCheckOmitList, $globalPolicyCheckOmitList);
$policyCheckViewMap = array();
foreach ($policyCheckOmitList as $omitItem) {
    $items = explode('/', $omitItem);
    if (count($items) > 1) {
        $module = $items[0];
        $view = $items[1];
        if (!isset($policyCheckViewMap[$module])) {
            $policyCheckViewMap[$module] = array();