本文整理汇总了PHP中SEFTools::redirect方法的典型用法代码示例。如果您正苦于以下问题:PHP SEFTools::redirect方法的具体用法?PHP SEFTools::redirect怎么用?PHP SEFTools::redirect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SEFTools
的用法示例。
在下文中一共展示了SEFTools::redirect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _parseRawRoute
function _parseRawRoute(&$uri)
{
$sefConfig =& SEFConfig::getConfig();
// Make sure that Itemid is numeric
$Itemid = $uri->getVar('Itemid');
if (!empty($Itemid)) {
$uri->setVar('Itemid', intval($Itemid));
}
// Redirect to correct language if set to
if ($sefConfig->langEnable && $sefConfig->mismatchedLangHandling == _COM_SEF_MISMATCHED_LANG_FIX && count($_POST) == 0) {
$langVar = $uri->getVar('lang');
$itemidVar = $uri->getVar('Itemid');
if (!empty($langVar) && !empty($itemidVar)) {
// Get menu item language
$menu = JFactory::getApplication()->getMenu('site');
$item = $menu->getItem($itemidVar);
if (is_object($item) && !empty($item->language) && $item->language != '*') {
$langsCode = JLanguageHelper::getLanguages('lang_code');
if ($langsCode[$item->language]->sef != $langVar) {
// Redirect to correct language
$curUri = JURI::getInstance();
$curUri->setVar('lang', $langsCode[$item->language]->sef);
SEFTools::redirect($curUri->toString(), true);
}
}
}
}
if (is_null($uri->getVar('option'))) {
// Set the URI from Itemid
$menu = JFactory::getApplication()->getMenu('site');
$item = $menu->getItem($uri->getVar('Itemid'));
if (!is_null($item)) {
$uri->setQuery($item->query);
$uri->setVar('Itemid', $item->id);
}
}
$extAuto = 2;
if (isset($params)) {
$extAuto = $params->get('autoCanonical', 2);
}
$autoCanonical = $extAuto == 2 ? $sefConfig->autoCanonical : $extAuto;
if ($sefConfig->nonSefRedirect && count($_POST) == 0 || $autoCanonical) {
// Try to find the non-SEF URL in the database - don't create new!
$oldDisable = $sefConfig->disableNewSEF;
$sefConfig->disableNewSEF = true;
$uri->setPath('index.php');
$url = $uri->toString(array('path', 'query', 'fragment'));
$sef = JRoute::_($url);
// Revert, otherwise Joomla in its router thinks this is SEF URL,
// because its path is not empty!
$uri->setPath('');
// Restore the configuration
$sefConfig->disableNewSEF = $oldDisable;
if ($sefConfig->nonSefRedirect && count($_POST) == 0) {
// Non-SEF redirect
if (strpos($sef, 'index.php?') === false) {
// Check if it's different from current URL
$curUri = JURI::getInstance();
if ($sef[0] == '/') {
$curUrl = $curUri->toString(array('path', 'query', 'fragment'));
} else {
$curUrl = JoomSefUri::getUri($curUri);
}
// Fix the & characters
$sef = str_replace('&', '&', $sef);
if ($sef != $curUrl) {
// Seems the URL is SEF, let's redirect
SEFTools::redirect($sef, true);
}
}
} else {
if ($autoCanonical) {
// Only set canonical URL
$mainframe =& JFactory::getApplication();
// Remove the query part from SEF URL
$pos = strpos($sef, '?');
if ($pos !== false) {
$sef = substr($sef, 0, $pos);
}
JoomSEF::set('sef.link.canonical', $sef);
}
}
}
return $uri->getQuery(true);
}
示例2: revert
function revert($route, &$disabled)
{
$sefConfig =& SEFConfig::getConfig();
$cache =& SEFCache::getInstance();
$vars = array();
$route = html_entity_decode(urldecode($route));
$routeNoSlash = rtrim($route, '/');
// try to use cache
$row = null;
if ($sefConfig->useCache) {
// There can be multiple non-SEF URLs for the same SEF URL
$rows = $cache->getNonSefUrl($route);
if ($rows) {
// If there is a language from domain, try to find the correct URL
$lang = JoomSEF::get('domain_lang');
if (!empty($lang)) {
$row = $this->findUrlForLanguage($rows, $lang);
} else {
$row = reset($rows);
}
}
}
// cache worked
if ($row) {
$fromCache = true;
} else {
// URL isn't in cache or cache disabled
$fromCache = false;
if ($sefConfig->transitSlash) {
$where = "(`sefurl` = " . $this->_db->Quote($routeNoSlash) . ") OR (`sefurl` = " . $this->_db->Quote($routeNoSlash . '/') . ")";
} else {
$where = "`sefurl` = " . $this->_db->Quote($route);
}
$sql = "SELECT * FROM #__sefurls WHERE ({$where}) AND (`origurl` != '') ORDER BY `priority`";
// Try to find URL with correct language if using domains
$lang = JoomSEF::get('domain_lang');
if (!empty($lang)) {
// Get all SEF URLs
$row = null;
$this->_db->setQuery($sql);
$rows = $this->_db->loadObjectList();
// Try to find the URL with correct language
if (is_array($rows) && count($rows) > 0) {
$pattern = "#[?&]lang={$lang}(&|\$)#i";
foreach ($rows as $item) {
if (preg_match($pattern, $item->origurl)) {
$row = $item;
break;
}
}
// No URL with correct language found, use the first one
if (is_null($row)) {
$row = reset($rows);
}
}
} else {
// Find the first matching URL
$sql .= ' LIMIT 1';
$this->_db->setQuery($sql);
$row = $this->_db->loadObject();
}
}
if ($row) {
// Search in database is not case-sensitive, but URLs are case-sensitive so we should check
// if the found route really matches the searched one and redirect if necessary to avoid duplicate content
if ($sefConfig->transitSlash && $row->sefurl != $routeNoSlash && $row->sefurl != $routeNoSlash . '/' || !$sefConfig->transitSlash && $row->sefurl != $route) {
// Redirect if possible
if (empty($_POST)) {
$redir = JURI::getInstance();
$redir->setPath('/' . ltrim($row->sefurl, '/'));
SEFTools::redirect($redir->toString(), true);
}
}
// Set the disabled flag (old cache records don't need to have enabled set)
if (!isset($row->enabled)) {
$row->enabled = 1;
}
if ($row->enabled) {
$disabled = false;
} else {
$disabled = true;
}
// Use the already created URL
$string = $row->origurl;
if (isset($row->Itemid) && $row->Itemid != '') {
$string .= (strpos($string, '?') ? '&' : '?') . 'Itemid=' . $row->Itemid;
}
// update the hits count if needed
if (!$fromCache || $sefConfig->cacheRecordHits) {
$where = '';
if (!empty($row->id)) {
$where = " WHERE `id` = '{$row->id}'";
} else {
$where = " WHERE `sefurl` = '{$row->sefurl}' AND `origurl` != ''";
}
$this->_db->setQuery("UPDATE #__sefurls SET cpt=(cpt+1)" . $where);
$this->_db->query();
}
$string = str_replace('&', '&', $string);
$QUERY_STRING = str_replace('index.php?', '', $string);
//.........这里部分代码省略.........