WordPress.org

Plugin Directory

Changeset 391925


Ignore:
Timestamp:
06/02/11 03:02:17 (3 years ago)
Author:
jbrinley
Message:

Merge branch 'master' into svn

Location:
wp-router/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • wp-router/trunk/WP_Route.class.php

    r388695 r391925  
    108108        } 
    109109 
     110        $template = $this->choose_template(); 
     111 
     112        if ( $template === FALSE ) { 
     113            print $page_contents; 
     114            exit(); 
     115        } 
     116 
    110117        $title = $this->get_title($query); 
    111  
    112         $template = $this->choose_template(); 
    113118 
    114119        $page = new WP_Router_Page($page_contents, $title, $template); 
     
    132137    } 
    133138 
     139    /** 
     140     * Get the appropriate callback function for the route, taking the HTTP method into account 
     141     * 
     142     * @return bool|string 
     143     */ 
     144    protected function get_callback( $possibilities ) { 
     145        if ( is_callable($possibilities) ) { 
     146            return $possibilities; 
     147        } 
     148        if ( is_array($possibilities) ) { 
     149            $method = $_SERVER['REQUEST_METHOD']; 
     150            if ( $method && isset($possibilities[$method]) && is_callable($possibilities[$method]) ) { 
     151                return $possibilities[$method]; 
     152            } 
     153            if ( isset($possibilities['default']) && is_callable($possibilities['default']) ) { 
     154                return $possibilities['default']; 
     155            } 
     156        } 
     157        return FALSE; 
     158    } 
     159 
     160    /** 
     161     * Get the contents of the page 
     162     * 
     163     * @param WP $query 
     164     * @return bool|string 
     165     */ 
    134166    protected function get_page( WP $query ) { 
    135         if ( !is_callable($this->page_callback) ) { 
    136             return FALSE; // can't call it 
     167        $callback = $this->get_callback($this->page_callback); 
     168        if ( !$callback ) { 
     169            return FALSE; 
    137170        } 
    138171        $args = $this->get_query_args($query, 'page'); 
     
    149182 
    150183    protected function get_title( WP $query ) { 
    151         if ( !is_callable($this->title_callback) ) { 
     184        $callback = $this->get_callback($this->title_callback); 
     185        if ( !$callback ) { 
    152186            return $this->title; // can't call it 
    153187        } 
     
    166200 
    167201    protected function check_access( WP $query ) { 
    168         if ( $this->access_callback === FALSE ) { 
     202        if ( $this->access_callback === TRUE ) { 
     203            return TRUE; 
     204        } 
     205        $callback = $this->get_callback($this->access_callback); 
     206        if ( !$callback ) { 
    169207            return FALSE; // nobody gets in 
    170208        } 
     
    274312 
    275313    protected function choose_template() { 
     314        if ( $this->template === FALSE ) { 
     315            return FALSE; 
     316        } 
    276317        $template = ''; 
    277318        $extra = array( 
  • wp-router/trunk/WP_Router_Page.class.php

    r388695 r391925  
    150150    } 
    151151 
    152     public function get_single_post_title( $title, $post ) { 
     152    /** 
     153     * Set the title for the placeholder page (again) 
     154     * 
     155     * @param string $title 
     156     * @param object $post 
     157     * @return string 
     158     */ 
     159    public function get_single_post_title( $title, $post = NULL ) { 
     160        // in WP 3.0.x, $post might be NULL. Not true in WP 3.1 
     161        if ( !$post ) { 
     162            $post = $GLOBALS['post']; 
     163        } 
    153164        return $this->get_title($title, $post->ID); 
    154165    } 
    155166 
     167    /** 
     168     * Use the specified template file 
     169     * 
     170     * @param string $template 
     171     * @return string 
     172     */ 
    156173    public function override_template( $template ) { 
    157174        if ( $this->template && file_exists($template) ) { // these checks shouldn't be necessary, but no harm 
  • wp-router/trunk/WP_Router_Utility.class.php

    r388695 r391925  
    1212    const DEBUG = FALSE; 
    1313    const MIN_PHP_VERSION = '5.2'; 
    14     const MIN_WP_VERSION = '3.1'; 
    15     const VERSION = '0.1'; 
     14    const MIN_WP_VERSION = '3.0'; 
    1615    const DB_VERSION = 1; 
    1716    const PLUGIN_INIT_HOOK = 'wp_router_init'; 
  • wp-router/trunk/readme.txt

    r388695 r391925  
    33Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A69NZPKWGB6H2 
    44Tags: URL mapping, callback functions 
    5 Requires at least: 3.1 
     5Requires at least: 3.0 
    66Tested up to: 3.1 
    77Stable tag: trunk 
     
    4545        * `path` (required) - A regular expression to match against the request path. 
    4646            This corresponds to the array key you would use when creating rewrite rules for WordPress. 
     47 
    4748        * `query_vars` - An associative array, with the keys being query vars, and the 
    48             values being explicit strings or integers corresponding to matches in the path regexp. Any query variables included here will be automatically registered. 
     49            values being explicit strings or integers corresponding to matches in the path regexp. 
     50             Any query variables included here will be automatically registered. 
     51 
    4952        * `title` - The title of the page. 
     53 
    5054        * `title_callback` - A callback to use for dynamically generating the title. 
    5155            Defaults to `__()`. If `NULL`, the `title` argument will be used as-is. if 
    5256            `page_callback` or `access_callback` returns `FALSE`, `title_callback` will not be called. 
     57 
     58            `title_callback` can be either a single callback function or an array specifying 
     59            callback functions for specific HTTP methods (e.g., `GET`, `POST`, `PUT`, `DELETE`, etc.). 
     60            If the latter, the `default` key will be used if no other keys match the current 
     61            request method. 
     62 
    5363        * `title_arguments` - An array of query variables whose values will be passed 
    5464            as arguments to `title_callback`. Defaults to the value of `title`. If an argument 
    5565            is not a registered query variable, it will be passed as-is. 
     66 
    5667        * `page_callback` (required) - A callback to use for dynamically generating the 
    5768            contents of the page. The callback should either echo or return the contents of 
     
    6172            phase of WordPress's page load. If `access_callback` returns `FALSE`, `page_callback` 
    6273            will not be called. 
     74 
     75            `page_callback` can be either a single callback function or an array specifying 
     76            callback functions for specific HTTP methods (e.g., `GET`, `POST`, `PUT`, `DELETE`, etc.). 
     77            If the latter, the `default` key will be used if no other keys match the current 
     78            request method. 
     79 
    6380        * `page_arguments` - An array of query variables whose values will be passed as 
    6481            arguments to `page_callback`. If an argument is not a registered query variable, 
    6582            it will be passed as-is. 
     83 
    6684        * `access_callback` - A callback to determine if the user has permission to access 
    6785            this page. If `access_arguments` is provided, default is `current_user_can`, otherwise 
    6886            default is `TRUE`. If the callback returns `FALSE`, anonymous users are redirected to 
    6987            the login page, authenticated users get a 403 error. 
     88 
     89            `access_callback` can be either a single callback function or an array specifying 
     90            callback functions for specific HTTP methods (e.g., `GET`, `POST`, `PUT`, `DELETE`, etc.). 
     91            If the latter, the `default` key will be used if no other keys match the current 
     92            request method. 
     93 
    7094        * `access_arguments` - An array of query variables whose values will be passed 
    7195            as arguments to `access_callback`. If an argument is not a registered query variable, 
    7296            it will be passed as-is. 
     97 
    7398        * `template` - An array of templates that can be used to display the page. If a path 
    7499            is absolute, it will be used as-is; relative paths allow for overrides by the theme. 
    75100            The string `$id` will be replaced with the ID of the route. If no template is found, 
    76101            fallback templates are (in this order): `route-$id.php`, `route.php`, `page-$id.php`, 
    77             `page.php`, `index.php`. 
     102            `page.php`, `index.php`. If FALSE is given instead of an array, the page contents will 
     103            be printed before calling `exit()` (you can also accomplish this by printing your output 
     104            and exiting directly from your callback function). 
    78105 
    79106Example: 
     
    122149 
    123150* Added the `template` argument 
     151 
     152= 0.3 = 
     153 
     154* Added `FALSE` option to template parameter to indicate immediate `exit()` 
     155* Added option to specify different callback functions depending on the HTTP request method 
     156* Verified compatibility with WordPress 3.0 
  • wp-router/trunk/wp-router.php

    r388695 r391925  
    66Author: Adelie Design 
    77Author URI: http://www.adeliedesign.com/ 
    8 Version: 0.2 
     8Version: 0.3 
    99*/ 
    1010/* 
     
    3737 * @return void 
    3838 */ 
    39 function WP_Router_load() { 
    40     if ( !class_exists('WP_Router') ) { 
     39if ( !function_exists('WP_Router_load') ) { 
     40    function WP_Router_load() { 
    4141        // load the base class 
    4242        require_once 'WP_Router_Utility.class.php'; 
     
    5959        } 
    6060    } 
     61    // Fire it up! 
     62    WP_Router_load(); 
    6163} 
    62  
    63 // Fire it up! 
    64 WP_Router_load(); 
Note: See TracChangeset for help on using the changeset viewer.