Plugin Directory

Changeset 1336910


Ignore:
Timestamp:
01/27/2016 07:31:58 AM (10 years ago)
Author:
happyplugins
Message:

Update version 1.0.4

Location:
wishlist-member-api-testing
Files:
10 added
4 edited

Legend:

Unmodified
Added
Removed
  • wishlist-member-api-testing/trunk/includes/wlm-api-test.class.php

    r1335028 r1336910  
    2121            /* Process Member REgistration Tests */
    2222            add_action ('admin_init', array ($this, 'member_registration')) ;
     23
     24            add_action ('admin_init', array ($this, 'load_scripts')) ;
     25
     26        }
     27
     28        function load_scripts() {
     29
     30            /* check if we are in the right menu screen and only then load js & css */
     31
     32            $screen = get_current_screen();
     33            if ($screen->id=='tools_page_wlm-api-testing') {
     34
     35                add_action ('wp_print_scripts' , array ($this, 'scripts'));
     36
     37            }
     38
    2339        }
    2440
    2541        function scripts () {
    26 
    27             /* check if we are in the right menu screen and only then load js & css */
    28             $screen = get_current_screen();
    29 
    30             if ($screen->id=='tools_page_wlm-api-testing') {
    3142
    3243                wp_register_script('wlmtest_toggle', plugin_dir_url(__FILE__) . '/js/wlmtest_toggle.js', array('jquery'));
     
    3546                wp_register_style('wlmtest_style', plugins_url('/css/style.css', __FILE__));
    3647                wp_enqueue_style('wlmtest_style');
    37             }
     48
    3849        }
    3950
     
    5364                "Sequential"=> true,
    5465                "SendMail" => 'true',
    55                 // "Levels" => array($level_id)
     66                "Levels" => array($_POST['wlmtest_level_id'])
    5667            );
    5768
     
    120131                            <?php $response = wlmapi_get_levels(); ?>
    121132                            Results Using Internal API -
    122                                     <?php if ($response['success']==1) { ?>
     133                                    <?php if ($response['success']==1) {
     134                                            $level_id = $response['levels']['level'][0]['id'];
     135                                        ?>
    123136                                            <span class="wlmtest_success">Success</span>
     137
    124138                                    <?php } else { ?>
    125139                                            <span class="wlmtest_fail">Failed</span>
     
    150164                                    <input type="submit" class="button-secondary" value="Test Member Registration Using Internal API">
    151165                                    <input type="hidden" name="wlmtest_action" value="member_registration_internal_api">
     166                                    <input type="hidden" name="wlmtest_level_id" value="<?php echo $level_id; ?>">
    152167                                </form>
    153168                            <?php } ?>
     
    179194                                    <input type="submit" class="button-secondary" value="Test Member Registration Using External API">
    180195                                    <input type="hidden" name="wlmtest_action" value="member_registration_external_api">
     196                                    <input type="hidden" name="wlmtest_level_id" value="<?php echo $level_id; ?>">
    181197                                </form>
    182198                                <?php } ?>
  • wishlist-member-api-testing/trunk/includes/wlmapiclass.php

    r1325174 r1336910  
    33/**
    44 * wlmapiclass
     5 * Helper class for WishList Member API 2.0
    56 *
    67 * @author Mike Lopez http://mikelopez.com
    7  * @version 1.3
     8 * @version 1.6
    89 */
    910if ( ! class_exists( 'wlmapiclass' ) ) {
     
    1314        var $url;
    1415        var $key;
    15         var $return_format = 'xml';
    16         var $authenticated = 0;
     16        var $return_format    = 'xml';
     17        var $authenticated    = 0;
     18        var $auth_error       = '';
     19        var $fake             = 0;
     20        var $method_emulation = 0;
    1721
    1822        /**
    1923         * Initailize wlmapi
    20          * @param string $url Wordpress URL
     24         * @param string $url WordPress URL
    2125         * @param string $key API Key
    2226         */
    23         function __construct($url, $key, $tempdir = null) {
    24             if (is_null($tempdir)) {
    25                 if (function_exists('sys_get_temp_dir')) {
     27        function __construct( $url, $key, $tempdir = null ) {
     28            if ( substr( $url, -1 ) != '/' ) {
     29                $url.='/';
     30            }
     31            if ( is_null( $tempdir ) ) {
     32                if ( function_exists( 'sys_get_temp_dir' ) ) {
    2633                    $tempdir = sys_get_temp_dir();
    2734                }
    28                 if (!$tempdir) {
     35                if ( ! $tempdir ) {
    2936                    $tempdir = '/tmp';
    3037                }
    3138            }
    3239            $this->tempdir = $tempdir;
    33             $this->url = $url . '?/wlmapi/2.0/';
    34             $this->key = $key;
    35         }
    36 
    37         private function _request($method, $resource, $data = '') {
    38 
    39             // echo $method, $resource, $data ;
    40 
     40            $this->url     = $url . '?/wlmapi/2.0/';
     41            $this->key     = $key;
     42        }
     43
     44        private function _request( $method, $resource, $data = '' ) {
    4145            static $cookie_file;
    4246
    43             if (empty($cookie_file)) {
    44                 $cookie_file = tempnam($this->tempdir, 'wlmapi');
    45             }
    46 
    47             $data = empty($data) ? '' : http_build_query($data);
    48             $url = $this->url . $this->return_format . $resource;
    49             $ch = curl_init();
    50             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    51             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    52             curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
    53             curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
    54 
    55             switch ($method) {
     47            if ( empty( $cookie_file ) ) {
     48                $cookie_file = tempnam( $this->tempdir, 'wlmapi' );
     49            }
     50
     51            if ( defined( 'WLMAPICLASS_PASS_NOCACHE_DATA' ) && WLMAPICLASS_PASS_NOCACHE_DATA ) {
     52                usleep( 1 );
     53                if( !is_array( $data ) ) {
     54                    $data = array();
     55                }
     56                $data['__nocache__'] = md5( microtime() );
     57            }
     58
     59            $data = empty( $data ) ? '' : http_build_query( $data );
     60            $url  = $this->url . $this->return_format . $resource;
     61            $ch   = curl_init();
     62            curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
     63            curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 );
     64            curl_setopt( $ch, CURLOPT_COOKIEFILE, $cookie_file );
     65            curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookie_file );
     66
     67            switch ( $method ) {
     68                case 'PUT':
     69                case 'DELETE':
     70                    if ( ! empty( $this->fake ) OR ! empty( $this->method_emulation ) ) {
     71                        $fake  = urlencode( '____FAKE____' ) . '=' . $method;
     72                        $fake2 = urlencode( '____METHOD_EMULATION____' ) . '=' . $method;
     73                        if ( empty( $data ) ) {
     74                            $data = $fake . '&' . $fake2;
     75                        } else {
     76                            $data .= '&' . $fake . '&' . $fake2;
     77                        }
     78                        curl_setopt( $ch, CURLOPT_POST, 1 );
     79                        curl_setopt( $ch, CURLOPT_POSTFIELDS, $data );
     80                    } else {
     81                        curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, $method );
     82                        curl_setopt( $ch, CURLOPT_POSTFIELDS, $data );
     83                        curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Content-Length: ' . strlen( $data ) ) );
     84                    }
     85                    break;
    5686                case 'POST':
    57                     curl_setopt($ch, CURLOPT_POST, 1);
    58                     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    59                     break;
    60                 case 'PUT':
    61                     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
    62                     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    63                     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Length: ' . strlen($data)));
    64                     break;
    65                 case 'DELETE':
    66                     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
    67                     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    68                     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Length: ' . strlen($data)));
     87                    curl_setopt( $ch, CURLOPT_POST, 1 );
     88                    curl_setopt( $ch, CURLOPT_POSTFIELDS, $data );
    6989                    break;
    7090                case 'GET':
    71                     if ($data) {
     91                    if ( $data ) {
    7292                        $url .= '/&' . $data;
    7393                    }
    7494                    break;
    7595                default:
    76                     die('Invalid Method: ' . $method);
     96                    die( 'Invalid Method: ' . $method );
    7797            }
    7898            /* set the curl URL */
    79             curl_setopt($ch, CURLOPT_URL, $url);
     99            curl_setopt( $ch, CURLOPT_URL, $url );
    80100
    81101            /* execute and grab the return data */
    82             $out = curl_exec($ch);
    83 
    84             if (defined('WLMAPICLASS_DEBUG')) {
     102            $out = curl_exec( $ch );
     103
     104            if ( defined( 'WLMAPICLASS_DEBUG' ) ) {
    85105                $log = "-- WLMAPICLASS_DEBUG_START --\nURL: {$url}\nMETHOD: {$method}\nDATA: {$data}\nRESULT: {$out}\n-- WLMAPICLASS_DEBUG_END --\n";
    86106
    87                 if (filter_var(WLMAPICLASS_DEBUG, FILTER_VALIDATE_EMAIL)) {
     107                if ( filter_var( WLMAPICLASS_DEBUG, FILTER_VALIDATE_EMAIL ) ) {
    88108                    $log_type = 1;
    89                 } elseif (file_exists(WLMAPICLASS_DEBUG)) {
     109                } elseif ( file_exists( WLMAPICLASS_DEBUG ) ) {
    90110                    $log_type = 3;
    91111                } else {
     
    94114                $log_dest = $log_type ? WLMAPICLASS_DEBUG : null;
    95115
    96                 error_log($log, $log_type, $log_dest);
     116                error_log( $log, $log_type, $log_dest );
    97117            }
    98118
     
    101121        }
    102122
     123        private function _resourcefix( $resource ) {
     124            if ( substr( $resource, 0, 1 ) != '/' ) {
     125                $resource = '/' . $resource;
     126            }
     127            return $resource;
     128        }
     129
     130        private function _auth() {
     131            if ( ! empty( $this->authenticated ) ) {
     132                return true;
     133            }
     134            $m                   = $this->return_format;
     135            $this->return_format = 'php';
     136
     137            $output = unserialize( $this->_request( 'GET', '/auth' ) );
     138            if ( $output['success'] != 1 || empty( $output['lock'] ) ) {
     139                $this->auth_error = 'No auth lock to open';
     140                return false;
     141            }
     142
     143            $hash   = md5( $output['lock'] . $this->key );
     144            $data   = array(
     145                'key'               => $hash,
     146                'support_emulation' => 1,
     147            );
     148            $output = unserialize( $this->_request( 'POST', '/auth', $data ) );
     149            if ( $output['success'] == 1 ) {
     150                $this->authenticated = 1;
     151                if ( ! empty( $output['support_emulation'] ) ) {
     152                    $this->method_emulation = 1;
     153                }
     154            } else {
     155                $this->auth_error = $output['ERROR'];
     156                return false;
     157            }
     158
     159            $this->return_format = $m;
     160            return true;
     161        }
     162
    103163        /**
    104164         * Send a POST request to WishList Member API (add new data)
     165         * Returns API result on success or false on error.
     166         * If an error occured, a short description of the error will be
     167         * stored in the object's auth_error property
     168         *
    105169         * @param string $resource
    106170         * @param array $data
    107          * @return xml|php|json
    108          */
    109         function post($resource, $data) {
    110             $this->_auth();
    111             return $this->_request('POST', $this->_resourcefix($resource), $data);
     171         * @return xml|php|json|false
     172         */
     173        function post( $resource, $data ) {
     174            if ( ! $this->_auth() ) {
     175                return false;
     176            }
     177            return $this->_request( 'POST', $this->_resourcefix( $resource ), $data );
    112178        }
    113179
    114180        /**
    115181         * Send a GET request to WishList Member API (retrieve data)
     182         * Returns API result on success or false on error.
     183         * If an error occured, a short description of the error will be
     184         * stored in the object's auth_error property
     185         *
    116186         * @param string $resource
    117187         * @param array (optional) $data
    118          * @return xml|php|json
    119          */
    120         function get($resource, $data = '') {
    121             $this->_auth();
    122             return $this->_request('GET', $this->_resourcefix($resource), $data);
     188         * @return xml|php|json|false
     189         */
     190        function get( $resource, $data = '' ) {
     191            if ( ! $this->_auth() ) {
     192                return false;
     193            }
     194            return $this->_request( 'GET', $this->_resourcefix( $resource ), $data );
    123195        }
    124196
    125197        /**
    126198         * Send a PUT request to WishList Member API (update existing data)
     199         * Returns API result on success or false on error.
     200         * If an error occured, a short description of the error will be
     201         * stored in the object's auth_error property
     202         *
    127203         * @param string $resource
    128204         * @param array $data
    129          * @return xml|php|json
    130          */
    131         function put($resource, $data) {
    132             $this->_auth();
    133             return $this->_request('PUT', $this->_resourcefix($resource), $data);
     205         * @return xml|php|json|false
     206         */
     207        function put( $resource, $data ) {
     208            if ( ! $this->_auth() ) {
     209                return false;
     210            }
     211            return $this->_request( 'PUT', $this->_resourcefix( $resource ), $data );
    134212        }
    135213
    136214        /**
    137215         * Send a DELETE to WishList Member API (delete the resource)
     216         * Returns API result on success or false on error.
     217         * If an error occured, a short description of the error will be
     218         * stored in the object's auth_error property
     219         *
    138220         * @param string $resource
    139221         * @param array (optional) $data
    140          * @return xml|php|json
    141          */
    142         function delete($resource, $data = '') {
    143             $this->_auth();
    144             return $this->_request('DELETE', $this->_resourcefix($resource), $data);
    145         }
    146 
    147         private function _resourcefix($resource) {
    148             if (substr($resource, 0, 1) != '/') {
    149                 $resource = '/' . $resource;
    150             }
    151             return $resource;
    152         }
    153 
    154         private function _auth() {
    155             if (empty($this->authenticated)) {
    156                 $m = $this->return_format;
    157                 $this->return_format = 'php';
    158 
    159                 $output = unserialize($this->_request('GET', '/auth'));
    160                 if ($output['success'] != 1 || empty($output['lock'])) {
    161                     die('No auth lock to open');
    162                 }
    163 
    164                 $hash = md5($output['lock'] . $this->key);
    165                 $data = array('key' => $hash);
    166                 $output = unserialize($this->_request('POST', '/auth', $data));
    167                 if ($output['success'] == 1) {
    168                     $this->authenticated = 1;
    169                 }
    170 
    171                 $this->return_format = $m;
    172             }
     222         * @return xml|php|json|false
     223         */
     224        function delete( $resource, $data = '' ) {
     225            if ( ! $this->_auth() ) {
     226                return false;
     227            }
     228            return $this->_request( 'DELETE', $this->_resourcefix( $resource ), $data );
    173229        }
    174230
    175231    }
     232
    176233}
  • wishlist-member-api-testing/trunk/readme.txt

    r1335028 r1336910  
    55Requires at least: 4.4
    66Tested up to: 4.4
    7 Stable Tag: 1.0.3
     7Stable Tag: 1.0.4
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    8989
    9090== Changelog ==
     911.0.4
     92+ Fixed scripts loading location
     93+ Updated offical Wishlist Member wlmapiclass to version 1.6
     94
    91951.0.3
    9296+ Fixed external raw response for levels request
  • wishlist-member-api-testing/trunk/wlm-api-test.php

    r1335030 r1336910  
    66Author: HappyPlugins
    77Author URI: https://happyplugins.com
    8 Version: 1.0.3
     8Version: 1.0.4
    99Requires at least: 4.0
    1010Tested up to: 4.3.1
Note: See TracChangeset for help on using the changeset viewer.