From 29e27722ef9a046de43eef96c92ad5e9514b3b61 Mon Sep 17 00:00:00 2001 From: Greg Thornton Date: Wed, 21 Mar 2012 01:54:14 -0500 Subject: [PATCH 1/2] Delay url patterns compilation until after apps are loaded. Also merge url patterns from all apps --- mtv.php | 17 +++++++++++++++-- wp-plugin.php | 17 ----------------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/mtv.php b/mtv.php index 048ee8d..08881e1 100644 --- a/mtv.php +++ b/mtv.php @@ -100,10 +100,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 ); @@ -112,8 +113,20 @@ 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); + } + } + + var_dump($all_url_patterns); + exit; + # 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 3ac72d4..98f1385 100644 --- a/wp-plugin.php +++ b/wp-plugin.php @@ -55,13 +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 - throw 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; @@ -69,7 +62,6 @@ // run MTV mtv\run( array( 'url' => get_default( $_REQUEST, 'path', '' ), - 'url_patterns' => $ajax_url_patterns, 'apps' => $apps ) ); // That's all folks @@ -163,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 From 402143bdb80eb3b809082bb557848e2e979abc6d Mon Sep 17 00:00:00 2001 From: Greg Thornton Date: Wed, 21 Mar 2012 01:55:22 -0500 Subject: [PATCH 2/2] lol. --- mtv.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/mtv.php b/mtv.php index 08881e1..f0716a9 100644 --- a/mtv.php +++ b/mtv.php @@ -122,9 +122,6 @@ function run( $kwargs ) { } } - var_dump($all_url_patterns); - exit; - # globalize our $url_patterns $GLOBALS['url_patterns'] = $all_url_patterns;