function build(&$uri, $check = false) { static $extsCache; if (!isset($extsCache)) { $extsCache = array(); } $mainframe = JFactory::getApplication(); $jRouter = $mainframe->getRouter(); $jRouter->SetMode(JROUTER_MODE_SEF); $config = JFactory::getConfig(); $sefConfig = SEFConfig::getConfig(); $cache = SEFCache::getInstance(); // Restore global "Add suffix to URLs" $sefSuffix = JoomSEF::get('sef.global.orig_sef_suffix'); $config->set('sef_suffix', $sefSuffix); // trigger onSefStart patches $mainframe->triggerEvent('onSefStart'); // Do not SEF URLs with specific format or template according to configuration if (in_array($uri->getVar('format'), array('raw', 'json', 'xml')) || $uri->getVar('tmpl') == 'raw' || !$sefConfig->sefComponentUrls && $uri->getVar('tmpl') == 'component') { $uri = JoomSEF::_createUri($uri); $mainframe->triggerEvent('onSefEnd'); $jRouter->SetMode(JROUTER_MODE_RAW); return; } // check URL for junk if set to $vars = $uri->getQuery(true); if ($sefConfig->checkJunkUrls) { $junkWords =& $sefConfig->getJunkWords(); $seferr = false; if (substr($uri->getVar('option', ''), 0, 4) != 'com_') { $seferr = true; } elseif (count($junkWords)) { $exclude =& $sefConfig->getJunkExclude(); foreach ($vars as $key => $val) { if (in_array($key, $exclude)) { continue; } // Check junk words foreach ($junkWords as $word) { if (is_string($val)) { if (strpos($val, $word) !== false) { $seferr = true; break; } } } if ($seferr) { break; } } } if ($seferr) { // trigger onSefEnd patches $mainframe->triggerEvent('onSefEnd'); $jRouter->SetMode(JROUTER_MODE_RAW); // fix the path $path = $uri->getPath(); return; } } // Handle lang variable if ($sefConfig->langEnable && $check == false) { $langs = JLanguageHelper::getLanguages('sef'); $langsCode = JLanguageHelper::getLanguages('lang_code'); $langVar = $uri->getVar('lang'); if (empty($langVar)) { $langVar = JRequest::getVar('lang'); $uri->setVar('lang', $langVar); } // Check for non-existent language if (!isset($langs[$langVar])) { // Not a SEF code, check for long code if (isset($langsCode[$langVar])) { // Fix the code to short version $uri->setVar('lang', $langsCode[$langVar]->sef); } else { // Non-existent language, use current $curLang = JFactory::getLanguage(); $uri->setVar('lang', $langsCode[$curLang->getTag()]->sef); } } // Check for mismatched language and Itemid? if ($sefConfig->mismatchedLangHandling != _COM_SEF_MISMATCHED_LANG_DONT_HANDLE) { $langVar = $uri->getVar('lang'); $itemidVar = $uri->getVar('Itemid'); if (!empty($langVar) && !empty($itemidVar)) { // Get menu item language $menu = $mainframe->getMenu('site'); $item = $menu->getItem($itemidVar); if (is_object($item) && !empty($item->language) && $item->language != '*') { if ($langsCode[$item->language]->sef != $langVar) { if ($sefConfig->mismatchedLangHandling == _COM_SEF_MISMATCHED_LANG_DONT_SEF) { // Don't SEF $mainframe->triggerEvent('onSefEnd'); $jRouter->SetMode(JROUTER_MODE_RAW); return; } else { // Fix lang variable $uri->setVar('lang', $langsCode[$item->language]->sef); } } } } } } // Correct FaLang support for translations $prevLang = ''; if ($sefConfig->langEnable && $check == false) { $langVar = $uri->getVar('lang'); if (!empty($langVar)) { $langCode = JoomSEF::getLangCode($langVar); if (!is_null($langCode)) { $curCode = JoomSEF::getLangCode(); if ($langCode != $curCode) { // URL language is different from current language, // change current language for correct translations $language = JFactory::getLanguage(); $prevLang = $language->setLanguage($langCode); // 6.12.2012 dajo: Make sure that loaded language overwrites current strings! $language->load('joomla', JPATH_BASE, null, true); } } } } // if there are no variables and only single language is used $vars = $uri->getQuery(true); if (empty($vars) && !isset($lang)) { JoomSEF::_endSef($prevLang); return; } $option = $uri->getVar('option'); if (!is_null($option)) { $params =& SEFTools::getExtParams($option); // Check the stop rule $stopRule = trim($params->get('stopRule', '')); if ($stopRule != '') { if (preg_match('/' . $stopRule . '/', $uri->toString()) > 0) { // Don't SEF this URL $uri = JoomSEF::_createUri($uri); JoomSEF::_endSef($prevLang); $jRouter->SetMode(JROUTER_MODE_RAW); return; } } if (strlen($uri->getVar('Itemid')) == 0) { $uri->delVar('Itemid'); } $handling = $params->get('handling', '0'); switch ($handling) { // skipped extensions case '2': // Check homepage if (JoomSEF::_isHomePage($uri)) { $lang = $uri->getVar('lang'); if (empty($lang)) { JoomSefUri::updateUri($uri, 'index.php'); } else { JoomSefUri::updateUri($uri, 'index.php?lang=' . $lang); } } // Build URL $uri = JoomSEF::_createUri($uri); JoomSEF::_endSef($prevLang); $jRouter->SetMode(JROUTER_MODE_RAW); return; // non-cached extensions // non-cached extensions case '1': // Check homepage if (JoomSEF::_isHomePage($uri)) { $lang = $uri->getVar('lang'); if (empty($lang)) { JoomSefUri::updateUri($uri, 'index.php'); } else { JoomSefUri::updateUri($uri, 'index.php?lang=' . $lang); } } JoomSEF::_endSef($prevLang); return; // default handler or basic rewriting // default handler or basic rewriting default: // if component has its own sef_ext plug-in included. // however, prefer own plugin if exists (added by Michal, 28.11.2006) $compExt = JPATH_ROOT . '/components/' . $option . '/router.php'; $ownExt = JPATH_ROOT . '/components/com_sef/sef_ext/' . $option . '.php'; // compatible extension build block if (file_exists($compExt) && !file_exists($ownExt) && $handling == '0') { // Check homepage if (JoomSEF::_isHomePage($uri)) { $lang = $uri->getVar('lang'); if (empty($lang)) { JoomSefUri::updateUri($uri, 'index.php'); } else { JoomSefUri::updateUri($uri, 'index.php?lang=' . $lang); } // Create homepage SEF URL $title = array(); $data = JoomSEF::_sefGetLocation($uri, $title, null, null, null, $uri->getVar('lang')); $uri = JoomSEF::_storeLocation($data); // remove path as Joomla will add it back $uri->setPath(preg_replace("@^" . $uri->base(true) . "@", "", $uri->getPath())); // Disable global "Add suffix to URLs" again $config->set('sef_suffix', 0); JoomSEF::_endSef($prevLang); return; } // load the plug-in file self::_isolatedRequireOnce($compExt); $app = JFactory::getApplication(); $menu = $app->getMenu('site'); $route = $uri->getPath(); $query = $uri->getQuery(true); $component = preg_replace('/[^A-Z0-9_\\.-]/i', '', $query['option']); $tmp = ''; // Replace limitstart -> start, which is default Joomla's behaviour if (isset($query['limitstart'])) { $query['start'] = (int) $query['limitstart']; unset($query['limitstart']); } // Get component router object if supported $componentRouter = self::getComponentRouter($component); if ($componentRouter) { // Use the new Joomla 3 interface $parts = $componentRouter->build($query); } else { // Use old procedural approach $function = substr($component, 4) . 'BuildRoute'; $parts = $function($query); } if (!is_array($parts)) { if (is_string($parts)) { $parts = array($parts); } else { // Don't SEF JoomSEF::_endSef($prevLang); // Disable global "Add suffix to URLs" again $config->set('sef_suffix', 0); return; } } $total = count($parts); for ($i = 0; $i < $total; $i++) { $parts[$i] = str_replace(':', '-', $parts[$i]); } $result = implode('/', $parts); $tmp = $result != "" ? '/' . $result : ''; // build the application route $built = false; if (isset($query['Itemid']) && !empty($query['Itemid'])) { $item = $menu->getItem($query['Itemid']); if (is_object($item) && $query['option'] == $item->component) { $tmp = !empty($tmp) ? $item->route . $tmp : $item->route; $built = true; } } if (!$built) { $tmp = 'component/' . substr($query['option'], 4) . $tmp; } $route .= '/' . $tmp; if ($app->getCfg('sef_suffix') && !(substr($route, -9) == 'index.php' || substr($route, -1) == '/')) { if ($format = $uri->getVar('format', 'html')) { $route .= '.' . $format; $uri->delVar('format'); } } if ($app->getCfg('sef_rewrite')) { // transform the route $route = str_replace('index.php/', '', $route); } // Unset unneeded query information unset($query['Itemid']); unset($query['option']); //Set query again in the URI $uri->setQuery($query); $uri->setPath($route); $uri = JoomSEF::_createUri($uri); JoomSEF::_endSef($prevLang); // Disable global "Add suffix to URLs" again $config->set('sef_suffix', 0); return; } else { // Disable global "Add suffix to URLs" $config->set('sef_suffix', 0); if ($handling == '3') { // Basic rewriting $class = 'SefExt_Basic'; } else { if (file_exists($ownExt)) { $class = 'SefExt_' . $option; } else { $class = 'SefExt'; } } // Extensions cache if (!class_exists($class)) { require $ownExt; } $sef_ext = new $class(); $extsCache[$class] = $sef_ext; // Set currently handled URI $sef_ext->setCurrentUri($uri); // 17.2.2012, dajo: isHomePage should be tested before the beforeCreate() is called // Grr Joomla SEF router adds home Itemid to Items without menu Item assigned $homes = array_keys(SEFTools::getHomeQueries()); if (in_array($uri->getVar('Itemid'), $homes) && !JoomSEF::_isHomePage($uri)) { $uri->setVar('Itemid', JRequest::getInt('Itemid')); } // Let the extension change the url and options $sef_ext->beforeCreate($uri); list($sid, $mosmsg) = self::_prepareUriForCreate($params, $uri); // Get nonsef and ignore vars from extension list($nonSefVars, $ignoreVars) = $sef_ext->getNonSefVars($uri); // Create array of all the non sef vars $nonSefVars = SEFTools::getNonSefVars($uri, $nonSefVars, $ignoreVars); // Create a copy of JURI object $uri2 = clone $uri; // Remove nonsef variables from our JURI copy $nonSefUrl = SEFTools::RemoveVariables($uri2, array_keys($nonSefVars)); // Check homepage if (JoomSEF::_isHomePage($uri2, true)) { $title = array(); $lng = $uri2->getVar('lang'); if ($sefConfig->langEnable && $sefConfig->langPlacementJoomla != _COM_SEF_LANG_DOMAIN && ($sefConfig->alwaysUseLangHomeJoomla || $lng != $sefConfig->mainLanguageJoomla)) { $title[] = $lng; } $pagination = false; if (method_exists($sef_ext, "_processPagination")) { $title = array_merge($title, $sef_ext->_processPagination($uri2)); $pagination = true; } if ($uri2->getVar('format') == 'feed') { $title[] = $uri2->getVar('type'); } $data = JoomSEF::_sefGetLocation($uri2, $title, null, null, null, $uri->getVar('lang'), null, null, null, null, $pagination); unset($data["lang"]); // We need to copy data, otherwise we would return $uri2 object - not working in Joomla 3 JoomSefUri::copyUri(JoomSEF::_storeLocation($data), $uri); // remove path as Joomla will add it back $uri->setPath(preg_replace("@^" . $uri->base(true) . "@", "", $uri->getPath())); // Set non-SEF variables $uri->setQuery($nonSefUrl); // Set domain if ($sefConfig->langEnable && $sefConfig->langPlacementJoomla == _COM_SEF_LANG_DOMAIN) { if (!empty($lng) && isset($sefConfig->subDomainsJoomla[$lng])) { $uri->setHost($sefConfig->subDomainsJoomla[$lng]); } } JoomSEF::_endSef($prevLang); return; } // clean Itemid if desired // David: only if overriding is disabled $override = $params->get('itemid', '0'); if (isset($sefConfig->excludeSource) && $sefConfig->excludeSource && $override == '0') { $Itemid = $uri->getVar('Itemid'); $uri2->delVar('Itemid'); } $url = JoomSEF::_uriToUrl($uri2); // try to get url from cache $sefUrl = false; if ($sefConfig->useCache) { if (!$check) { $sefUrl = $cache->GetSefUrl($url); } } if (!$sefConfig->useCache || !$sefUrl) { // check if the url is already saved in the database $sefUrl = $sef_ext->getSefUrlFromDatabase($uri2); if (is_string($sefUrl)) { // Backward compatibility $sefstring = $sefUrl; $sefUrl = new stdClass(); $sefUrl->sefurl = $sefstring; $sefUrl->sef = 1; $sefUrl->host = ''; } } // unknown URL yet if (!$sefUrl || $check) { // load JoomSEF Language File JFactory::getLanguage()->load('com_sef', JPATH_ADMINISTRATOR); // rewrite the URL, creating new JURI object $data = $sef_ext->create($uri); if (is_object($data) && is_a($data, 'JURI')) { // Backwards compatibility JoomSefUri::copyUri($data, $uri); } else { if ($sefConfig->langPlacementJoomla == _COM_SEF_LANG_PATH) { // if data is not array, then we don't have in lang language from SEF extension, because it's original URL if (is_array($data)) { if ($data['lang'] == '*') { // If we don't want to have language in multilanguage content strip down the language from path to eleminate duplicit pages with same content if ($sefConfig->addLangMulti) { $data["lang"] = $data["uri"]->getVar('lang'); } else { unset($data["lang"]); $data["uri"]->delVar('lang'); } } else { $langs = JLanguageHelper::getLanguages('lang_code'); if (array_key_exists($data["lang"], $langs)) { $data["lang"] = $langs[$data["lang"]]->sef; } if (!strlen($data["lang"])) { $data["lang"] = $data["uri"]->getVar('lang'); } } } if ($sefConfig->alwaysUseLangJoomla == false) { if (isset($data["lang"]) && $data["lang"] == $sefConfig->mainLanguageJoomla) { unset($data["lang"]); $data["uri"]->delVar('lang'); } } } $titlepage = false; $subdomain = SEFTools::getSubdomain($uri->getVar('Itemid'), $uri, $titlepage); if (strlen($subdomain)) { $curHost = JFactory::getURI()->getHost(); if (substr($curHost, 0, 4) == 'www.') { $curHost = substr($curHost, 4); } $uri->setHost($subdomain . '.' . $curHost); } if ($titlepage) { $data["title"] = array(); } if (!isset($data["host"])) { $data["host"] = $uri->getHost(); } if ($check) { $this->_data = $data; } // 12.11.2012 dajo: Itemid must be removed in _storeLocation after the menu title is removed too /*if (isset($sefConfig->excludeSource) && $sefConfig->excludeSource && ($override == '0')) { if (isset($data['uri'])) { $data['uri']->delVar('Itemid'); } }*/ $removeItemid = isset($sefConfig->excludeSource) && $sefConfig->excludeSource && $override == '0'; JoomSefUri::copyUri(JoomSEF::_storeLocation($data, $check, $removeItemid), $uri); } } else { // if SEF is disabled, don't SEF if (isset($sefUrl->sef) && !$sefUrl->sef) { $uri = JoomSEF::_createUri($uri); JoomSEF::_endSef($prevLang); $jRouter->SetMode(JROUTER_MODE_RAW); return; } // Create new JURI object from $sefstring if (!isset($sefUrl->host) || !strlen($sefUrl->host)) { $root = JFactory::getUri()->toString(array('host', 'port')); } else { $root = $sefUrl->host; } $url = JFactory::getURI()->getScheme() . "://" . $root . JURI::root(true); if (substr($url, -1) != '/') { $url .= '/'; } if (isset($sefUrl->sefurl)) { $url .= $sefUrl->sefurl; } // Add nonSef part if set if (!empty($nonSefUrl)) { $url .= '?' . $nonSefUrl; } // Add fragment if set $fragment = $uri->getFragment(); if (!empty($fragment)) { $url .= '#' . $fragment; } JoomSefUri::updateUri($uri, $url); } // Set domain if ($sefConfig->langEnable && $sefConfig->langPlacementJoomla == _COM_SEF_LANG_DOMAIN) { $lng = $uri2->getVar('lang'); if (!empty($lng) && isset($sefConfig->subDomainsJoomla[$lng])) { $uri->setHost($sefConfig->subDomainsJoomla[$lng]); } } // reconnect the sid to the url if (!empty($sid) && COM_SEF_CONFIG_REMOVE_SID) { $uri->setVar('sid', $sid); } // reconnect mosmsg to the url if (!empty($mosmsg)) { $uri->setVar('mosmsg', $mosmsg); } // reconnect ItemID to the url // David: only if extension doesn't set its own Itemid through overrideId parameter if (isset($sefConfig->excludeSource) && $sefConfig->excludeSource && $sefConfig->reappendSource && $override == '0' && !empty($Itemid)) { $uri->setVar('Itemid', $Itemid); } // let the extension change the resulting SEF url $sef_ext->afterCreate($uri); } } } else { if (!is_null($uri->getVar('Itemid'))) { // there is only Itemid present - we must override the Ignore multiple sources option $oldIgnore = $sefConfig->ignoreSource; $sefConfig->ignoreSource = 0; $lang = ""; $title = array(); $title[] = JoomSEF::_getMenuTitleLang(null, $lang, $uri->getVar('Itemid')); $data = JoomSEF::_sefGetLocation($uri, $title, null, null, null, strlen($lang) ? $lang : $uri->getVar('lang')); $uri = JoomSEF::_storeLocation($data); $sefConfig->ignoreSource = $oldIgnore; } } $uri->setPath(preg_replace("@^" . $uri->base(true) . "@", "", $uri->getPath())); JoomSEF::_endSef($prevLang); // Set Joomla's router so it doesn't process URL further $jRouter->SetMode(JROUTER_MODE_RAW); }
function build(&$uri) { $mainframe =& JFactory::getApplication(); $config =& JFactory::getConfig(); $sefConfig =& SEFConfig::getConfig(); $cache =& SEFCache::getInstance(); // trigger onSefStart patches $mainframe->triggerEvent('onSefStart'); $prevLang = ''; // for correct title translations // do not SEF URLs with tmpl=component if set to if (!$sefConfig->sefComponentUrls && $uri->getVar('tmpl') == 'component') { $mainframe->triggerEvent('onSefEnd'); return; } // check if this is site root; // if site is root, do not do anything else // except if we have to set language every time $vars = $uri->getQuery(true); if (empty($vars) && (!SEFTools::JoomFishInstalled() || !$sefConfig->alwaysUseLang)) { // trigger onSefEnd patches $mainframe->triggerEvent('onSefEnd'); $uri = new JURI(JURI::root()); return; } // check URL for junk if set to if ($sefConfig->checkJunkUrls) { $junkWords =& $sefConfig->getJunkWords(); $seferr = false; if (substr($uri->getVar('option', ''), 0, 4) != 'com_') { $seferr = true; } elseif (count($junkWords)) { $exclude =& $sefConfig->getJunkExclude(); foreach ($vars as $key => $val) { if (in_array($key, $exclude)) { continue; } // Check junk words foreach ($junkWords as $word) { if (is_string($val)) { if (strpos($val, $word) !== false) { $seferr = true; break; } } } if ($seferr) { break; } } } if ($seferr) { // trigger onSefEnd patches $mainframe->triggerEvent('onSefEnd'); // fix the path $path = $uri->getPath(); if ($path[0] != '/') { $path = JURI::base(true) . '/' . $path; $uri->setPath($path); } return; } } if (SEFTools::JoomFishInstalled()) { $lang = $uri->getVar('lang'); // if lang not set if (empty($lang)) { if ($sefConfig->alwaysUseLang) { // add lang variable if set to $uri->setVar('lang', SEFTools::getLangCode()); } else { // delete lang variable so it is not empty $uri->delVar('lang'); } } // get the URL's language and set it as global language (for correct translation) $lang = $uri->getVar('lang'); $code = ''; if (!empty($lang)) { $code = SEFTools::getLangLongCode($lang); if (!is_null($code)) { if ($code != SEFTools::getLangLongCode()) { $language =& JFactory::getLanguage(); $prevLang = $language->setLanguage($code); $language->load(); } } } // set the live_site according to language if ($sefConfig->langPlacement == _COM_SEF_LANG_DOMAIN) { $u =& JURI::getInstance(); $curdomain = $sefdomain = $u->getHost(); if (!empty($lang)) { if (isset($sefConfig->jfSubDomains[$lang])) { $sefdomain = $sefConfig->jfSubDomains[$lang]; //$uri->delVar('lang'); } } $config =& JFactory::getConfig(); $config->setValue('joomfish.current_host', $curdomain); $config->setValue('joomfish.sef_host', $sefdomain); } } // if there are no variables and only single language is used $vars = $uri->getQuery(true); if (empty($vars) && !isset($lang)) { JoomSEF::_endSef($prevLang); return; } $option = $uri->getVar('option'); if (!is_null($option)) { $params =& SEFTools::getExtParams($option); // Check the stop rule $stopRule = trim($params->get('stopRule', '')); if ($stopRule != '') { if (preg_match('/' . $stopRule . '/', $uri->toString()) > 0) { // Don't SEF this URL $uri = JoomSEF::_createUri($uri); JoomSEF::_endSef($prevLang); return; } } $handling = $params->get('handling', '0'); switch ($handling) { // skipped extensions case '2': // Check homepage if (JoomSEF::_isHomePage($uri)) { $lang = $uri->getVar('lang'); if (empty($lang)) { $uri = new JURI('index.php'); } else { $uri = new JURI('index.php?lang=' . $lang); } } // Build URL $uri = JoomSEF::_createUri($uri); JoomSEF::_endSef($prevLang); return; // non-cached extensions // non-cached extensions case '1': $router = JoomSEF::get('sef.global.jrouter'); if (!empty($router)) { // Store language for later use $uriLang = $uri->getVar('lang'); $uri->delVar('lang'); // Check homepage if (JoomSEF::_isHomePage($uri)) { $url = 'index.php'; } else { $url = $uri->toString(); } // Build URL $uri = $router->build($url); // Add language if needed if (!is_null($uriLang)) { $route = $uri->getPath(); $route = JoomSEF::_addLangToRoute($route, $uriLang); $uri->setPath($route); } } JoomSEF::_endSef($prevLang); return; // default handler or basic rewriting // default handler or basic rewriting default: // if component has its own sef_ext plug-in included. // however, prefer own plugin if exists (added by Michal, 28.11.2006) $compExt = JPATH_ROOT . DS . 'components' . DS . $option . DS . 'router.php'; $ownExt = JPATH_ROOT . DS . 'components' . DS . 'com_sef' . DS . 'sef_ext' . DS . $option . '.php'; // compatible extension build block if (file_exists($compExt) && !file_exists($ownExt) && $handling == '0') { // Check homepage if (JoomSEF::_isHomePage($uri)) { $lang = $uri->getVar('lang'); if (empty($lang)) { $uri = new JURI('index.php'); } else { $uri = new JURI('index.php?lang=' . $lang); } // Build URL $uri = JoomSEF::_createUri($uri); JoomSEF::_endSef($prevLang); return; } // load the plug-in file require_once $compExt; // Store the language for later use $uriLang = $uri->getVar('lang'); $uri->delVar('lang'); $app =& JFactory::getApplication(); $menu =& JSite::getMenu(); $route = $uri->getPath(); $query = $uri->getQuery(true); $component = preg_replace('/[^A-Z0-9_\\.-]/i', '', $query['option']); $tmp = ''; $function = substr($component, 4) . 'BuildRoute'; $parts = $function($query); $total = count($parts); for ($i = 0; $i < $total; $i++) { $parts[$i] = str_replace(':', '-', $parts[$i]); } $result = implode('/', $parts); $tmp = $result != "" ? '/' . $result : ''; // build the application route $built = false; if (isset($query['Itemid']) && !empty($query['Itemid'])) { $item = $menu->getItem($query['Itemid']); if (is_object($item) && $query['option'] == $item->component) { $tmp = !empty($tmp) ? $item->route . $tmp : $item->route; $built = true; } } if (!$built) { $tmp = 'component/' . substr($query['option'], 4) . $tmp; } $route .= '/' . $tmp; if ($app->getCfg('sef_suffix') && !(substr($route, -9) == 'index.php' || substr($route, -1) == '/')) { if ($format = $uri->getVar('format', 'html')) { $route .= '.' . $format; $uri->delVar('format'); } } if ($app->getCfg('sef_rewrite')) { // transform the route $route = str_replace('index.php/', '', $route); } // Unset unneeded query information unset($query['Itemid']); unset($query['option']); // Add language to route if needed if (!is_null($uriLang)) { $route = JoomSEF::_addLangToRoute($route, $uriLang); } //Set query again in the URI $uri->setQuery($query); $uri->setPath($route); $uri = JoomSEF::_createUri($uri); JoomSEF::_endSef($prevLang); return; } else { if ($handling == '3') { // Basic rewriting $class = 'SefExt_Basic'; } else { if (file_exists($ownExt)) { $class = 'SefExt_' . $option; require_once $ownExt; if (!class_exists($class)) { $class = 'SefExt'; } } else { $class = 'SefExt'; } } $sef_ext = new $class(); // Set currently handled URI $sef_ext->setCurrentUri($uri); // Let the extension change the url and options $origUri = clone $uri; $sef_ext->beforeCreate($uri); // Ensure that the session IDs are removed // If set to $sid = $uri->getVar('sid'); if (!$sefConfig->dontRemoveSid) { $uri->delVar('sid'); } // Ensure that the mosmsg are removed. $mosmsg = $uri->getVar('mosmsg'); $uri->delVar('mosmsg'); // override Itemid if set to $override = $params->get('itemid', '0'); $overrideId = $params->get('overrideId', ''); if ($override != '0' && $overrideId != '') { $uri->setVar('Itemid', $overrideId); } // clean Itemid if desired // David: only if overriding is disabled if (isset($sefConfig->excludeSource) && $sefConfig->excludeSource && $override == '0') { $Itemid = $uri->getVar('Itemid'); $uri->delVar('Itemid'); } // Get nonsef and ignore vars from extension list($nonSefVars, $ignoreVars) = $sef_ext->getNonSefVars($uri); // Create array of all the non sef vars $nonSefVars = SEFTools::getNonSefVars($uri, $nonSefVars, $ignoreVars); // Create a copy of JURI object $uri2 = clone $uri; // Remove nonsef variables from our JURI copy $nonSefUrl = SEFTools::RemoveVariables($uri2, array_keys($nonSefVars)); // Check homepage if (JoomSEF::_isHomePage($uri2, true)) { // Create homepage SEF URL without non-SEF variables $title = array(); $data = JoomSEF::_sefGetLocation($uri2, $title, null, null, null, $uri->getVar('lang')); $uri = JoomSEF::_storeLocation($data); // Add non-SEF variables $uri->setQuery($nonSefUrl); JoomSEF::_endSef($prevLang); return; } if (!SEFTools::JoomFishInstalled()) { $titlepage = false; $subdomain = SEFTools::getSubdomain($origUri, $titlepage); if (strlen($subdomain)) { $uri->setHost($subdomain . "." . JFactory::getURI()->getHost()); } } $url = JoomSEF::_uriToUrl($uri2); // try to get url from cache $sefUrl = false; if ($sefConfig->useCache) { $sefUrl = $cache->GetSefUrl($url); } if (!$sefConfig->useCache || !$sefUrl) { // check if the url is already saved in the database $sefUrl = $sef_ext->getSefUrlFromDatabase($uri2); if (is_string($sefUrl)) { // Backward compatibility $sefstring = $sefUrl; $sefUrl = new stdClass(); $sefUrl->sefurl = $sefstring; $sefUrl->sef = 1; } } if (!$sefUrl) { // rewrite the URL, creating new JURI object $data = $sef_ext->create($uri); if (is_object($data) && is_a($data, 'JURI')) { // Backwards compatibility $uri = $data; } else { // Handle subdomains if (!SEFTools::JoomFishInstalled()) { if (!isset($data["host"])) { $comp_host = $sef_ext->getParam('subdomain'); if (!strlen($comp_host) && strlen($subdomain)) { $data["host"] = $uri->getHost(); } else { if (strlen($comp_host)) { $data["host"] = $comp_host . "." . JFactory::getURI()->getHost(); } } } else { $data["host"] = null; } } if ($titlepage) { $data["title"] = array(); } $uri = JoomSEF::_storeLocation($data); } } else { // if SEF is disabled, don't SEF if (isset($sefUrl->sef) && !$sefUrl->sef) { $uri = JoomSEF::_createUri($uri); JoomSEF::_endSef($prevLang); return; } // Create new JURI object from $sefstring if (!strlen($sefUrl->host)) { $root = JFactory::getUri()->toString(array('host', 'port')); } else { $root = $sefUrl->host; } $url = JFactory::getURI()->getScheme() . "://" . $root . JURI::root(true); if (substr($url, -1) != '/') { $url .= '/'; } $url .= $sefUrl->sefurl; // Add nonSef part if set if (!empty($nonSefUrl)) { $url .= '?' . $nonSefUrl; } // Add fragment if set $fragment = $uri->getFragment(); if (!empty($fragment)) { $url .= '#' . $fragment; } $uri = new JURI($url); } // reconnect the sid to the url if (!empty($sid) && !$sefConfig->dontRemoveSid) { $uri->setVar('sid', $sid); } // reconnect mosmsg to the url if (!empty($mosmsg)) { $uri->setVar('mosmsg', $mosmsg); } // reconnect ItemID to the url // David: only if extension doesn't set its own Itemid through overrideId parameter if (isset($sefConfig->excludeSource) && $sefConfig->excludeSource && $sefConfig->reappendSource && $override == '0' && !empty($Itemid)) { $uri->setVar('Itemid', $Itemid); } // let the extension change the resulting SEF url $sef_ext->afterCreate($uri); } } } else { if (!is_null($uri->getVar('Itemid'))) { // there is only Itemid present - we must override the Ignore multiple sources option $oldIgnore = $sefConfig->ignoreSource; $sefConfig->ignoreSource = 0; $title = array(); $title[] = JoomSEF::_getMenuTitle(null, null, $uri->getVar('Itemid')); $data = JoomSEF::_sefGetLocation($uri, $title, null, null, null, $uri->getVar('lang')); $uri = JoomSEF::_storeLocation($data); $sefConfig->ignoreSource = $oldIgnore; } } JoomSEF::_endSef($prevLang); }