function modify($tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters) { switch ($operatorName) { case 'ngurl': if (empty($namedParameters['siteaccess'])) { return; } $ini = eZSiteAccess::getIni($namedParameters['siteaccess'], 'site.ini'); $destinationLocale = $ini->variable('RegionalSettings', 'ContentObjectLocale'); $siteLanguageList = $ini->variable('RegionalSettings', 'SiteLanguageList'); $nodeID = eZURLAliasML::fetchNodeIDByPath($operatorValue); $destinationElement = eZURLAliasML::fetchByAction('eznode', $nodeID, $destinationLocale, false); if (empty($destinationElement) || !isset($destinationElement[0]) && !$destinationElement[0] instanceof eZURLAliasML) { if ($this->isModuleUrl($operatorValue) || $this->isCurrentLocaleAvailable($siteLanguageList)) { $destinationUrl = $operatorValue; } else { $destinationUrl = ''; } } else { $destinationUrl = $destinationElement[0]->getPath($destinationLocale, $siteLanguageList); } $siteaccessUrlMapping = eZINI::instance('nglanguageswitcher.ini')->variable('LanguageSwitcher', 'SiteAccessUrlMapping'); $destinationUrl = eZURI::encodeURL($destinationUrl); $operatorValue = rtrim($siteaccessUrlMapping[$namedParameters['siteaccess']], '/') . '/' . ltrim($destinationUrl, '/'); break; } }
/** * \static * Performs an HTTP redirect. * * \param $path The path to redirect * \param $parameters \see createRedirectUrl() * \param $status The HTTP status code as a string * \param $encodeURL Encode the URL. This should normally be true, but * may be set to false to avoid double encoding when redirect() is called * twice. */ static function redirect($path, $parameters = array(), $status = false, $encodeURL = true) { $url = eZHTTPTool::createRedirectUrl($path, $parameters); if (strlen($status) > 0) { header($_SERVER['SERVER_PROTOCOL'] . " " . $status); eZHTTPTool::headerVariable("Status", $status); } if ($encodeURL) { $url = eZURI::encodeURL($url); } eZHTTPTool::headerVariable('Location', $url); /* Fix for redirecting using workflows and apache 2 */ echo '<HTML><HEAD>'; echo '<META HTTP-EQUIV="Refresh" Content="0;URL=' . htmlspecialchars($url) . '">'; echo '<META HTTP-EQUIV="Location" Content="' . htmlspecialchars($url) . '">'; echo '</HEAD><BODY></BODY></HTML>'; }
/** * Performs a redirection */ protected function redirect() { $GLOBALS['eZRedirection'] = true; $ini = eZINI::instance(); $automaticRedirect = true; if ($GLOBALS['eZDebugAllowed'] && ($redirUri = $ini->variable('DebugSettings', 'DebugRedirection')) !== 'disabled') { if ($redirUri == "enabled") { $automaticRedirect = false; } else { $uri = eZURI::instance(eZSys::requestURI()); $uri->toBeginning(); foreach ($ini->variableArray("DebugSettings", "DebugRedirection") as $redirUri) { $redirUri = new eZURI($redirUri); if ($redirUri->matchBase($uri)) { $automaticRedirect = false; break; } } } } $redirectURI = eZSys::indexDir(); $moduleRedirectUri = $this->module->redirectURI(); if ($ini->variable('URLTranslator', 'Translation') === 'enabled' && eZURLAliasML::urlTranslationEnabledByUri(new eZURI($moduleRedirectUri))) { $translatedModuleRedirectUri = $moduleRedirectUri; if (eZURLAliasML::translate($translatedModuleRedirectUri, true)) { $moduleRedirectUri = $translatedModuleRedirectUri; if (strlen($moduleRedirectUri) > 0 && $moduleRedirectUri[0] !== '/') { $moduleRedirectUri = '/' . $moduleRedirectUri; } } } if (preg_match('#^(\\w+:)|^//#', $moduleRedirectUri)) { $redirectURI = $moduleRedirectUri; } else { $leftSlash = strlen($redirectURI) > 0 && $redirectURI[strlen($redirectURI) - 1] === '/'; $rightSlash = strlen($moduleRedirectUri) > 0 && $moduleRedirectUri[0] === '/'; if (!$leftSlash && !$rightSlash) { // Both are without a slash, so add one $moduleRedirectUri = '/' . $moduleRedirectUri; } else { if ($leftSlash && $rightSlash) { // Both are with a slash, so we remove one $moduleRedirectUri = substr($moduleRedirectUri, 1); } } $redirectURI .= $moduleRedirectUri; } eZStaticCache::executeActions(); eZDB::checkTransactionCounter(); if ($automaticRedirect) { eZHTTPTool::redirect($redirectURI, array(), $this->module->redirectStatus()); } else { // Make sure any errors or warnings are reported if ($ini->variable('DebugSettings', 'DisplayDebugWarnings') === 'enabled') { 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.'))); } } $tpl = eZTemplate::factory(); $tpl->setVariable('site', $this->site); $tpl->setVariable('warning_list', !empty($this->warningList) ? $this->warningList : false); $tpl->setVariable('redirect_uri', eZURI::encodeURL($redirectURI)); $templateResult = $tpl->fetch('design:redirect.tpl'); eZDebug::addTimingPoint("Script end"); eZDisplayResult($templateResult); } eZExecution::cleanExit(); }
// Make sure any errors or warnings are reported if ($ini->variable('DebugSettings', 'DisplayDebugWarnings') == 'enabled') { if (isset($GLOBALS['eZDebugError']) and $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']) and $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.'))); } } $tpl = eZTemplate::factory(); if (empty($warningList)) { $warningList = false; } $tpl->setVariable('site', $site); $tpl->setVariable('warning_list', $warningList); $tpl->setVariable('redirect_uri', eZURI::encodeURL($redirectURI)); $templateResult = $tpl->fetch('design:redirect.tpl'); eZDebug::addTimingPoint("Script end"); eZDisplayResult($templateResult); } eZExecution::cleanExit(); } // 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() && $module->exitStatus() == eZModule::STATUS_OK) { $currentURI = $completeRequestedURI; if (strlen($currentURI) > 0 and $currentURI[0] != '/') { $currentURI = '/' . $currentURI; } $lastAccessedURI = ""; $lastAccessedViewURI = "";
/** * Performs an HTTP redirect. * * @param string $path The path to redirect to * @param array $parameters See createRedirectUrl(). Defaults to empty array. * @param bool $status The HTTP status code as a string (code + text, e.g. "302 Found"). Defaults to false. * @param bool $encodeURL Encodes the URL. * This should normally be true, but may be set to false to avoid double encoding when redirect() is called twice. * Defaults to true * @param bool $returnRedirectObject If true, will return an ezpKernelRedirect object. * * @return null|ezpKernelRedirect */ static function redirect($path, $parameters = array(), $status = false, $encodeURL = true, $returnRedirectObject = false) { $url = eZHTTPTool::createRedirectUrl($path, $parameters); if (strlen($status) > 0) { header($_SERVER['SERVER_PROTOCOL'] . " " . $status); eZHTTPTool::headerVariable("Status", $status); } if ($encodeURL) { $url = eZURI::encodeURL($url); } eZHTTPTool::headerVariable('Location', $url); /* Fix for redirecting using workflows and apache 2 */ $escapedUrl = htmlspecialchars($url); $content = <<<EOT <HTML><HEAD> <META HTTP-EQUIV="Refresh" Content="0;URL={$escapedUrl}"> <META HTTP-EQUIV="Location" Content="{$escapedUrl}"> </HEAD><BODY></BODY></HTML> EOT; if ($returnRedirectObject) { return new ezpKernelRedirect($url, $status ?: null, $content); } echo $content; }