Changeset 1336910
- Timestamp:
- 01/27/2016 07:31:58 AM (10 years ago)
- Location:
- wishlist-member-api-testing
- Files:
-
- 10 added
- 4 edited
-
tags/1.0.4 (added)
-
tags/1.0.4/includes (added)
-
tags/1.0.4/includes/css (added)
-
tags/1.0.4/includes/css/style.css (added)
-
tags/1.0.4/includes/js (added)
-
tags/1.0.4/includes/js/wlmtest_toggle.js (added)
-
tags/1.0.4/includes/wlm-api-test.class.php (added)
-
tags/1.0.4/includes/wlmapiclass.php (added)
-
tags/1.0.4/readme.txt (added)
-
tags/1.0.4/wlm-api-test.php (added)
-
trunk/includes/wlm-api-test.class.php (modified) (6 diffs)
-
trunk/includes/wlmapiclass.php (modified) (4 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/wlm-api-test.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
wishlist-member-api-testing/trunk/includes/wlm-api-test.class.php
r1335028 r1336910 21 21 /* Process Member REgistration Tests */ 22 22 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 23 39 } 24 40 25 41 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') {31 42 32 43 wp_register_script('wlmtest_toggle', plugin_dir_url(__FILE__) . '/js/wlmtest_toggle.js', array('jquery')); … … 35 46 wp_register_style('wlmtest_style', plugins_url('/css/style.css', __FILE__)); 36 47 wp_enqueue_style('wlmtest_style'); 37 } 48 38 49 } 39 50 … … 53 64 "Sequential"=> true, 54 65 "SendMail" => 'true', 55 // "Levels" => array($level_id)66 "Levels" => array($_POST['wlmtest_level_id']) 56 67 ); 57 68 … … 120 131 <?php $response = wlmapi_get_levels(); ?> 121 132 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 ?> 123 136 <span class="wlmtest_success">Success</span> 137 124 138 <?php } else { ?> 125 139 <span class="wlmtest_fail">Failed</span> … … 150 164 <input type="submit" class="button-secondary" value="Test Member Registration Using Internal API"> 151 165 <input type="hidden" name="wlmtest_action" value="member_registration_internal_api"> 166 <input type="hidden" name="wlmtest_level_id" value="<?php echo $level_id; ?>"> 152 167 </form> 153 168 <?php } ?> … … 179 194 <input type="submit" class="button-secondary" value="Test Member Registration Using External API"> 180 195 <input type="hidden" name="wlmtest_action" value="member_registration_external_api"> 196 <input type="hidden" name="wlmtest_level_id" value="<?php echo $level_id; ?>"> 181 197 </form> 182 198 <?php } ?> -
wishlist-member-api-testing/trunk/includes/wlmapiclass.php
r1325174 r1336910 3 3 /** 4 4 * wlmapiclass 5 * Helper class for WishList Member API 2.0 5 6 * 6 7 * @author Mike Lopez http://mikelopez.com 7 * @version 1. 38 * @version 1.6 8 9 */ 9 10 if ( ! class_exists( 'wlmapiclass' ) ) { … … 13 14 var $url; 14 15 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; 17 21 18 22 /** 19 23 * Initailize wlmapi 20 * @param string $url Word press URL24 * @param string $url WordPress URL 21 25 * @param string $key API Key 22 26 */ 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' ) ) { 26 33 $tempdir = sys_get_temp_dir(); 27 34 } 28 if ( !$tempdir) {35 if ( ! $tempdir ) { 29 36 $tempdir = '/tmp'; 30 37 } 31 38 } 32 39 $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 = '' ) { 41 45 static $cookie_file; 42 46 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; 56 86 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 ); 69 89 break; 70 90 case 'GET': 71 if ( $data) {91 if ( $data ) { 72 92 $url .= '/&' . $data; 73 93 } 74 94 break; 75 95 default: 76 die( 'Invalid Method: ' . $method);96 die( 'Invalid Method: ' . $method ); 77 97 } 78 98 /* set the curl URL */ 79 curl_setopt( $ch, CURLOPT_URL, $url);99 curl_setopt( $ch, CURLOPT_URL, $url ); 80 100 81 101 /* 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' ) ) { 85 105 $log = "-- WLMAPICLASS_DEBUG_START --\nURL: {$url}\nMETHOD: {$method}\nDATA: {$data}\nRESULT: {$out}\n-- WLMAPICLASS_DEBUG_END --\n"; 86 106 87 if ( filter_var(WLMAPICLASS_DEBUG, FILTER_VALIDATE_EMAIL)) {107 if ( filter_var( WLMAPICLASS_DEBUG, FILTER_VALIDATE_EMAIL ) ) { 88 108 $log_type = 1; 89 } elseif ( file_exists(WLMAPICLASS_DEBUG)) {109 } elseif ( file_exists( WLMAPICLASS_DEBUG ) ) { 90 110 $log_type = 3; 91 111 } else { … … 94 114 $log_dest = $log_type ? WLMAPICLASS_DEBUG : null; 95 115 96 error_log( $log, $log_type, $log_dest);116 error_log( $log, $log_type, $log_dest ); 97 117 } 98 118 … … 101 121 } 102 122 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 103 163 /** 104 164 * 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 * 105 169 * @param string $resource 106 170 * @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 ); 112 178 } 113 179 114 180 /** 115 181 * 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 * 116 186 * @param string $resource 117 187 * @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 ); 123 195 } 124 196 125 197 /** 126 198 * 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 * 127 203 * @param string $resource 128 204 * @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 ); 134 212 } 135 213 136 214 /** 137 215 * 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 * 138 220 * @param string $resource 139 221 * @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 ); 173 229 } 174 230 175 231 } 232 176 233 } -
wishlist-member-api-testing/trunk/readme.txt
r1335028 r1336910 5 5 Requires at least: 4.4 6 6 Tested up to: 4.4 7 Stable Tag: 1.0. 37 Stable Tag: 1.0.4 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 89 89 90 90 == Changelog == 91 1.0.4 92 + Fixed scripts loading location 93 + Updated offical Wishlist Member wlmapiclass to version 1.6 94 91 95 1.0.3 92 96 + Fixed external raw response for levels request -
wishlist-member-api-testing/trunk/wlm-api-test.php
r1335030 r1336910 6 6 Author: HappyPlugins 7 7 Author URI: https://happyplugins.com 8 Version: 1.0. 38 Version: 1.0.4 9 9 Requires at least: 4.0 10 10 Tested up to: 4.3.1
Note: See TracChangeset
for help on using the changeset viewer.