diff --git a/mtv.php b/mtv.php index 15b45b1..c17a5c8 100644 --- a/mtv.php +++ b/mtv.php @@ -103,10 +103,11 @@ function load( $apps ) { * run MTV * Takes: * $url - url to run on, probably $_REQUEST['path'] or something - * $url_patterns - url regexes and functions to pass them to * $apps - MTV apps to load. Apps must be registered. Loads in order. **/ function run( $kwargs ) { + global $registered_apps; + extract( $kwargs ); load( $apps ); @@ -115,8 +116,17 @@ function run( $kwargs ) { if ( ! $url ) $url = $_REQUEST['path']; + $all_url_patterns = array(); + foreach ( $apps as $name ) { + $app = $registered_apps[$name]; + if ( $app['urls'] ) include_once $app['urls']; + if (is_array($url_patterns)) { + $all_url_patterns = array_merge($all_url_patterns, $url_patterns); + } + } + # globalize our $url_patterns - if ( $url_patterns ) $GLOBALS['url_patterns'] = $url_patterns; + $GLOBALS['url_patterns'] = $all_url_patterns; # oh, right, we gotta do something with our url http\urlresolver( array('url'=>$url, 'url_patterns'=>$url_patterns) ); diff --git a/wp-plugin.php b/wp-plugin.php index da1eae4..98f1385 100644 --- a/wp-plugin.php +++ b/wp-plugin.php @@ -55,15 +55,6 @@ * Use the URL resolver for ajax calls **/ $handle_ajax = function() { - // get the url patterns for the current theme - if ( file_exists( get_stylesheet_directory() . DIRECTORY_SEPARATOR . 'urls.php' ) ) - include get_stylesheet_directory() . DIRECTORY_SEPARATOR . 'urls.php'; - else if ( file_exists( get_template_directory() . DIRECTORY_SEPARATOR . 'urls.php' ) ) - include get_template_directory() . DIRECTORY_SEPARATOR . 'urls.php'; - else if ( ! empty( $GLOBALS['ajax_url_patterns'] ) ) - global $ajax_url_patterns; - else - throw new Exception("Can't find a urls.php file in your theme"); // whatever is in the $apps global is what we're going to load global $apps; @@ -71,7 +62,6 @@ // run MTV mtv\run( array( 'url' => get_default( $_REQUEST, 'path', '' ), - 'url_patterns' => $ajax_url_patterns, 'apps' => $apps ) ); // That's all folks @@ -165,21 +155,12 @@ // reset wp_query's is_whatever flags and posts shortcuts\reset_wp_query(); - // get the url patterns for the current theme - if ( file_exists( get_stylesheet_directory() . DIRECTORY_SEPARATOR . 'urls.php' ) ) - include get_stylesheet_directory() . DIRECTORY_SEPARATOR . 'urls.php'; - else if ( file_exists( get_template_directory() . DIRECTORY_SEPARATOR . 'urls.php' ) ) - include get_template_directory() . DIRECTORY_SEPARATOR . 'urls.php'; - else - throw new Exception("Can't find a urls.php file in your theme"); - // whatever is in the $apps global is what we're going to load global $apps; // run MTV mtv\run( array( 'url' => $wp_query->query_vars['path'], - 'url_patterns' => $url_patterns, 'apps' => $apps ) ); // That's all folks