Last active
August 29, 2015 13:55
-
-
Save kratkar/8757635 to your computer and use it in GitHub Desktop.
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 | |
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