/** * Match a url to the associated function, then call it * Takes: * $url - url to run on, probably $_REQUEST['path'] or something * $url_patterns - url regexes and functions to pass them to **/ function urlresolver($kwargs) { extract($kwargs); if (!isset($url)) { $url = get_default($_REQUEST, 'url', ''); } if (!isset($url_patterns)) { throw new BadFunctionCallException(__('url_patterns keyword argument required', 'mtv')); } try { // Start buffering so we can toss output in case we get an exception ob_start(); if (resolve($url, $url_patterns)) { // everything worked! Flush the buffer and return ob_end_flush(); return true; } else { // We didn't find any matching patterns :( So... 404! if (defined('DOING_AJAX') && DOING_AJAX) { throw new AjaxHttp404(); } else { throw new Http404(); } } } catch (HttpException $e) { ob_end_clean(); // Our view threw an HttpException, so display it $e->display(); } catch (Exception $e) { ob_end_clean(); // Somebody threw some sort of exception, so display 500 if (defined('DOING_AJAX') && DOING_AJAX) { $http_ex = new AjaxHttp500($e->getMessage(), $e->getCode(), $e); } else { $http_ex = new Http500($e->getMessage(), $e->getCode(), $e); } $http_ex->display(); } return false; // We had some errors, so return false }