WordPress.org

Plugin Directory

Changeset 349742


Ignore:
Timestamp:
02/23/11 13:01:24 (3 years ago)
Author:
tott
Message:

Add support for full stops (.) in server parameters and switch to remote.api as default. Switch to hash_hmac

Location:
remote-api/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • remote-api/trunk/client.php

    r342299 r349742  
    2323     * @param string $api_key. (default: '') 
    2424     * @param string $secret. (default: '') 
    25      * @param string $server_entry_key. (default: 'remote-api') 
     25     * @param string $server_entry_key. (default: 'remote.api') 
    2626     * @param string $server_format_key. (default: 'format') 
    2727     * @return void 
    2828     */ 
    29     public function __construct( $server_uri = '', $api_key = '', $secret = '', $server_entry_key = 'remote-api', $server_format_key = 'format' ) { 
     29    public function __construct( $server_uri = '', $api_key = '', $secret = '', $server_entry_key = '', $server_format_key = '' ) { 
    3030        $params = array( 'server_uri', 'api_key', 'secret', 'server_entry_key', 'server_format_key' ); 
    3131        foreach( $params as $param ) 
     
    4545    private function build_request_uri( $request_string, $format ) { 
    4646        $parts = array( $this->server_uri, $this->server_entry_key, $request_string, $this->server_format_key, $format ); 
    47         return join( "/", $parts ); 
     47        return implode( "/", $parts ); 
    4848    } 
    4949     
  • remote-api/trunk/config.php

    r339479 r349742  
    4444     * @return void 
    4545     */ 
    46     public function get( $key ) { 
     46    public function get( $key, $reformat = false ) { 
    4747        if ( isset( $this->config[$key] ) ) { 
    48             return $this->config[$key]; 
     48            switch( $reformat ) { 
     49                case false: 
     50                    return $this->config[$key]; 
     51                    break; 
     52                case 'query': 
     53                    return preg_replace( "#[^a-z0-9-_]#siU", "-", $this->config[$key] ); 
     54                    break; 
     55                case 'rewrite': 
     56                    return preg_quote( $this->config[$key] ); 
     57                    break; 
     58            } 
    4959        } else { 
    5060            return false; 
  • remote-api/trunk/readme.txt

    r339479 r349742  
    66Stable tag: trunk 
    77 
    8 A set of extendable classes that allow the creation of a remote API. A basic use case for this would be lazy loading content segments or performing cross-blog actions. 
    9 It includes a simple example for lazy loading widgets, but is mainly aimed for developers who like to built on top of this functionality. 
     8A set of extendable classes that allow the creation of a remote API.  
    109 
    1110== Description == 
     11 
     12A basic use case for this plugin would be lazy loading content segments or performing cross-blog actions. 
     13It includes a simple example for lazy loading widgets, but is mainly aimed for developers who like to built on top of this functionality. 
    1214 
    1315Features: 
     
    3032 
    31331. Widget admin interface showing the widget (left), the placeholder widget in the primary sidebar (top-right) and the resulting sidebar / dropzone for the placeholder widget (bottom-right)  
     34 
     35== Changelog == 
     36 
     37= 0.2 = 
     38* Add support for full stops (.) in server parameters and switch to `remote.api` as default url to avoid conflicts with page names. 
     39* Switching to hash_hmac instead of crypt for request format validation string. 
     40 
     41= 0.1 = 
     42* Basic implementation 
  • remote-api/trunk/remote-api.php

    r339479 r349742  
    55Plugin URI: http://wordpress.org/extend/plugins/remote-api/ 
    66Description: A set of extendable classes that allow the creation of a remote API. A basic use case for this would be lazy loading content segments or performing cross-blog actions. 
    7 Version: 0.1 
     7Version: 0.2 
    88Author: Thorsten Ott 
    99Author URI: http://automattic.com 
     
    3030    Remote_API_Config::instance()->set( 'api_key', SECRET_KEY );                                                        // api key which is appended to request strings. YOU SHOULD CHANGE THIS 
    3131    Remote_API_Config::instance()->set( 'secret', SECRET_SALT );                                                        // secret server key used as salt in the encryption process. YOU SHOULD CHANGE THIS 
    32     Remote_API_Config::instance()->set( 'server_entry_key', 'remote-api' );                                             // url entry point for the remote api ( http://blogname/remote-api/' ).  
    33     Remote_API_Config::instance()->set( 'server_format_key', 'format' );                                                // url identifier for the response format ( http://blogname/remote-api/<request_string>/format/<format>/ ) 
     32    Remote_API_Config::instance()->set( 'server_entry_key', 'remote.api' );                                             // url entry point for the remote api ( http://blogname/remote.api/' ).  
     33    Remote_API_Config::instance()->set( 'server_format_key', 'format' );                                                // url identifier for the response format ( http://blogname/remote.api/<request_string>/format/<format>/ ) 
    3434    Remote_API_Config::instance()->set( 'server_uri', preg_replace( "/\/$/", "", get_bloginfo( 'url' ) ) );             // url for the server. used by client and server unless overwritten. no closing slash! 
    3535     
     
    5858// load basic client class 
    5959require_once( 'client.php' ); 
     60 
    6061// load example widget that allows lazy loading existing widgets using this classes 
     62//* 
    6163require_once( 'examples/lazy-loading-widget.php' ); 
     64//*/ 
     65 
     66 
     67// custom client classes need to be included  
     68 
     69 
     70// here ^^^^ 
  • remote-api/trunk/request.php

    r339479 r349742  
    7676        } 
    7777         
    78         $this->set_argument( 'hash', crypt( serialize( $this->get_arguments() ) . Remote_API_Config::instance()->get( 'api_key' ), Remote_API_Config::instance()->get( 'secret' ) ) ); 
     78        $this->set_argument( 'chk', hash_hmac( 'md5', serialize( $this->get_arguments() ) . Remote_API_Config::instance()->get( 'api_key' ), Remote_API_Config::instance()->get( 'secret' ) ) ); 
    7979 
    8080        $this->request = base64_encode( serialize( $this->args ) ) . md5( Remote_API_Config::instance()->get( 'api_key' ) ); 
     
    107107        $data_raw = base64_decode( substr( $request_string, 0, strlen( $request_string ) - strlen( md5( Remote_API_Config::instance()->get( 'api_key' ) ) - 1 ) ) ); 
    108108        $data = unserialize( $data_raw ); 
    109         $data_hash = $data['hash']; 
    110         unset( $data['hash'] ); 
     109        $data_chk = $data['chk']; 
     110        unset( $data['chk'] ); 
    111111 
    112         if ( $public_key <> md5( Remote_API_Config::instance()->get( 'api_key' ) ) || crypt( serialize( $data ) . Remote_API_Config::instance()->get( 'api_key' ), Remote_API_Config::instance()->get( 'secret' ) ) <> $data_hash ) 
     112        if ( $public_key <> md5( Remote_API_Config::instance()->get( 'api_key' ) ) || hash_hmac( 'md5', serialize( $data ) . Remote_API_Config::instance()->get( 'api_key' ), Remote_API_Config::instance()->get( 'secret' ) ) <> $data_chk ) 
    113113            return false; 
    114114             
  • remote-api/trunk/server.php

    r339479 r349742  
    3434     */ 
    3535    public function add_query_vars( $query_vars ) { 
    36         if ( !in_array( Remote_API_Config::instance()->get( 'server_entry_key' ), $query_vars ) ) 
    37             $query_vars[] = Remote_API_Config::instance()->get( 'server_entry_key' ); 
    38         if ( !in_array( Remote_API_Config::instance()->get( 'server_format_key' ), $query_vars ) ) 
    39             $query_vars[] = Remote_API_Config::instance()->get( 'server_format_key' ); 
     36        if ( !in_array( Remote_API_Config::instance()->get( 'server_entry_key', 'query' ), $query_vars ) ) 
     37            $query_vars[] = Remote_API_Config::instance()->get( 'server_entry_key', 'query' ); 
     38        if ( !in_array( Remote_API_Config::instance()->get( 'server_format_key', 'query' ), $query_vars ) ) 
     39            $query_vars[] = Remote_API_Config::instance()->get( 'server_format_key', 'query' ); 
    4040        return $query_vars; 
    4141    } 
     
    4949     */ 
    5050    public function intercept_request( &$request ) { 
    51         if ( array_key_exists( Remote_API_Config::instance()->get( 'server_entry_key' ), $request->query_vars) && array_key_exists( Remote_API_Config::instance()->get( 'server_format_key' ), $request->query_vars ) ) { 
    52             $this->handle_request( $request->query_vars[ Remote_API_Config::instance()->get( 'server_entry_key' ) ], $request->query_vars[ Remote_API_Config::instance()->get( 'server_format_key' ) ] ); 
     51        if ( array_key_exists( Remote_API_Config::instance()->get( 'server_entry_key', 'query' ), $request->query_vars) && array_key_exists( Remote_API_Config::instance()->get( 'server_format_key', 'query' ), $request->query_vars ) ) { 
     52            $this->handle_request( $request->query_vars[ Remote_API_Config::instance()->get( 'server_entry_key', 'query' ) ], $request->query_vars[ Remote_API_Config::instance()->get( 'server_format_key', 'query' ) ] ); 
    5353        } 
    5454        return $request; 
     
    6767            return $rules; 
    6868 
    69         $rapi_rule = Remote_API_Config::instance()->get( 'server_entry_key' ) . '/(.+)/' . Remote_API_Config::instance()->get( 'server_format_key' ) . '/(' . join( "|", Remote_API_Response_Format::get() ) . ')/?$'; 
    70         $rapi_dst = 'index.php?' . Remote_API_Config::instance()->get( 'server_entry_key' ) . '=$matches[1]&' . Remote_API_Config::instance()->get( 'server_format_key' ) . '=$matches[2]'; 
     69        $rapi_rule = Remote_API_Config::instance()->get( 'server_entry_key', 'rewrite' ) . '/(.+)/' . Remote_API_Config::instance()->get( 'server_format_key', 'rewrite' ) . '/(' . implode( "|", Remote_API_Response_Format::get() ) . ')/?$'; 
     70        $rapi_dst = 'index.php?' . Remote_API_Config::instance()->get( 'server_entry_key', 'query' ) . '=$matches[1]&' . Remote_API_Config::instance()->get( 'server_format_key', 'query' ) . '=$matches[2]'; 
    7171         
    7272        if ( !isset( $rules[$rapi_rule] ) ) { 
Note: See TracChangeset for help on using the changeset viewer.