本文整理汇总了PHP中SEFTools::getAllSubdomains方法的典型用法代码示例。如果您正苦于以下问题:PHP SEFTools::getAllSubdomains方法的具体用法?PHP SEFTools::getAllSubdomains怎么用?PHP SEFTools::getAllSubdomains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SEFTools
的用法示例。
在下文中一共展示了SEFTools::getAllSubdomains方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onAfterInitialise
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;
}