function _context_prefix_init in Context 5
Helper function to initialize, parse + set prefixed contexts.
1 call to _context_prefix_init()
- context_prefix_init in context_prefix/
context_prefix.module - Implementation of hook_init() Checks for any valid context prefixes in request string and sets the context appropriately
File
- context_prefix/
context_prefix.module, line 61
Code
function _context_prefix_init($method = CONTEXT_PREFIX_PATH) {
switch ($method) {
case CONTEXT_PREFIX_PATH:
$q = isset($_REQUEST["q"]) ? trim($_REQUEST["q"], "/") : '';
$parsed = context_prefix_parse(CONTEXT_PREFIX_PATH, $q);
break;
case CONTEXT_PREFIX_PAIR:
$q = isset($_REQUEST["q"]) ? trim($_REQUEST["q"], "/") : '';
$parsed = context_prefix_parse(CONTEXT_PREFIX_PAIR, $q);
break;
case CONTEXT_PREFIX_DOMAIN:
$host = $_SERVER['HTTP_HOST'];
// We handle sub.domain.com, and nothing more (no sub1.sub2.domain.com).
$q = str_replace('http://', '', $host);
$parsed = context_prefix_parse(CONTEXT_PREFIX_DOMAIN, $q);
break;
}
// if $_GET and $_REQUEST are different, the path has NOT been
// aliased. We may need to rewrite the path.
if (in_array($method, array(
CONTEXT_PREFIX_PATH,
CONTEXT_PREFIX_PAIR,
)) && $_GET['q'] == $_REQUEST['q']) {
$q = context_prefix_unprefix($q, $method);
// there is nothing beyond the path prefix -- treat as frontpage
if ($q == '') {
$_GET['q'] = variable_get('site_frontpage', 'node');
}
else {
$_REQUEST['q'] = $_GET['q'] = _context_prefix_get_normal_path($q);
}
}
if (is_array($parsed)) {
foreach ($parsed as $prefix => $info) {
context_prefix_set($method, $prefix, $info);
}
}
}