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); }