function contexturl_condition_url::execute in Context URL 7
execute function
File
- plugins/
contexturl_condition_url.inc, line 63 - Adds url argument condition to Context
Class
- contexturl_condition_url
- URL as a Context condition.
Code
function execute() {
foreach (context_enabled_contexts() as $context) {
$options = $this
->fetch_from_context($context, 'options');
if (!empty($options['pageurl'])) {
$current_url = $_SERVER['HTTP_HOST'] . request_uri();
$evaluationtype = explode("\n", isset($options['evaluationtype']) ? $options['evaluationtype'] : 1);
$patterns = explode("\n", $options['pageurl']);
$return = FALSE;
foreach ($patterns as $pattern) {
$pattern = trim($pattern);
if ($pattern) {
$negate = FALSE;
if (strpos($pattern, '~') === 0) {
$negate = TRUE;
$pattern = substr($pattern, 1);
}
if ($evaluationtype == 'preg_match') {
if ($negate && !preg_match($pattern, $current_url) || !$negate && preg_match($pattern, $current_url)) {
$return = TRUE;
break;
}
}
else {
if ($negate && !fnmatch($pattern, $current_url) || !$negate && fnmatch($pattern, $current_url)) {
$return = TRUE;
break;
}
}
}
}
if ($return == TRUE) {
$this
->condition_met($context, $return);
}
}
}
}