function onAfterInitialise() { $sefConfig = SEFConfig::getConfig(); $mainframe = JFactory::getApplication(); // Enable menu associations if set to $joomlaVersion = new JVersion(); if ($joomlaVersion->isCompatible('3.0')) { $mainframe->item_associations = $sefConfig->langMenuAssociations ? 1 : 0; } else { $mainframe->set('menu_associations', $sefConfig->langMenuAssociations ? 1 : 0); } // Register installer and updater adapters in admin area $this->registerAdapters(); // Check if JoomSEF should be run if (!self::_isEnabled()) { return true; } // Store the router for later use $router = $mainframe->getRouter(); JoomSEF::set('sef.global.jrouter', $router); // Load JoomSEF language file $jLang = JFactory::getLanguage(); $jLang->load('com_sef', JPATH_ADMINISTRATOR); require_once JPATH_ROOT . '/components/com_sef/sef.router.php'; $jsRouter = new JRouterJoomsef(); $router->attachParseRule(array($jsRouter, 'parse')); $router->attachBuildRule(array($jsRouter, 'build')); // Disable global "Add suffix to URLs" before parsing and store current config $config = JFactory::getConfig(); $oldSuffix = $config->get('sef_suffix', 0); $config->set('sef_suffix', 0); JoomSEF::set('sef.global.orig_sef_suffix', $oldSuffix); // Get all configured subdomains $subdomains = SEFTools::getAllSubdomains(); // Redirect only when there's no POST variables if ($sefConfig->wwwHandling != _COM_SEF_WWW_NONE && empty($_POST)) { // Handle www and non-www domain $uri = JURI::getInstance(); $host = $uri->getHost(); $redirect = false; // Check if host is only IP $isIP = preg_match('/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\z/', $host); if ($sefConfig->wwwHandling == _COM_SEF_WWW_USE_WWW && !$isIP && strpos($host, 'www.') !== 0) { // Check if host starts with one of our subdomains if (isset($subdomains['*']) && count($subdomains['*']) > 0) { $parts = explode('.', $host); $domain = $parts[0]; $found = false; foreach ($subdomains['*'] as $sub) { if ($domain == $sub->subdomain) { $found = true; break; } } if (!$found) { // Redirect to www form $redirect = true; $uri->setHost('www.' . $host); } } else { // Redirect to www form $redirect = true; $uri->setHost('www.' . $host); } } else { if ($sefConfig->wwwHandling == _COM_SEF_WWW_USE_NONWWW && strpos($host, 'www.') === 0) { // host must not begin with www. $redirect = true; $uri->setHost(substr($host, 4)); } } // Redirect if needed if ($redirect) { $url = $uri->toString(); header('Location: ' . $url, true, 301); jexit(); } } // Load custom files only if needed for language or subdomains if ($sefConfig->langPlacementJoomla == _COM_SEF_LANG_DOMAIN || count($subdomains) > 0) { JLoader::register("JRoute", JPATH_SITE . '/components/com_sef/helpers/methods.php', true); JLoader::register("JText", JPATH_SITE . '/components/com_sef/helpers/methods.php', true); } return true; }