Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions mtv.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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) );
Expand Down
19 changes: 0 additions & 19 deletions wp-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,13 @@
* 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;

// run MTV
mtv\run( array(
'url' => get_default( $_REQUEST, 'path', '' ),
'url_patterns' => $ajax_url_patterns,
'apps' => $apps ) );

// That's all folks
Expand Down Expand Up @@ -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
Expand Down