Skip to content

Instantly share code, notes, and snippets.

@kratkar
Last active August 29, 2015 13:55
Show Gist options
  • Save kratkar/8757635 to your computer and use it in GitHub Desktop.
Save kratkar/8757635 to your computer and use it in GitHub Desktop.
<?php
if ($modx->context->get('key') == 'mgr') return;
if (!function_exists('contextbyurl_error_handler')) {
function contextbyurl_error_handler($errno, $errstr) {
global $modx;
$modx->log(E_ERROR, $errstr);
}
}
$conditions = $modx->getCollection('modContextSetting', array('key' => 'condition.regex'));
set_error_handler('contextbyurl_error_handler');
foreach($conditions as $cn) {
if ($cn) {
$condition = $cn->toArray();
if (preg_match($condition['value'], $_SERVER['REQUEST_URI']) > 0) {
$modx->switchContext($condition['context_key']);
return;
}
}
}
restore_error_handler();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment