Created
December 13, 2010 14:43
-
-
Save netProphET/739044 to your computer and use it in GitHub Desktop.
MODx Revolution plugin bound to OnHandleRequest event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* plugin to map subdomain requests to contexts | |
* @setting event OnHandleRequest | |
* @todo currently, subdomains and context names are bound together.. remove this constraint through some mapping/lookup | |
* @todo currently, assumes first name in host (name before first dot) is what maps to the context | |
*/ | |
$context = 'web'; | |
$host = $_SERVER['HTTP_HOST']; | |
if(!empty($host)) { | |
$names = explode('.', $host); | |
if(is_array($names)) { | |
$subdomain = $names[0]; | |
$modx->getContext($subdomain); | |
if(is_object($modx->contexts[$subdomain])) { | |
$context = $subdomain; | |
} | |
} | |
} | |
if($context !== 'web') { | |
$modx->switchContext($context); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment