Changeset 2010190
- Timestamp:
- 01/10/2019 07:24:49 PM (7 years ago)
- Location:
- shopsite-plugin/trunk
- Files:
-
- 2 edited
-
oauth.php (modified) (9 diffs)
-
shopsite.php (modified) (42 diffs)
Legend:
- Unmodified
- Added
- Removed
-
shopsite-plugin/trunk/oauth.php
r1079131 r2010190 18 18 $nonce2 = mt_rand(10000000,99999999); # nonce for download request 19 19 $timestamp = time(); # in UNIX time 20 21 20 22 21 # create the data string for the authorization request and get length for Content-Length 23 22 $request = "grant_type=authorization_code&code=$code&client_credentials=$encodedcredentials&signature=$signature1"; 24 23 $length = strlen($request); 25 26 24 25 $response = wp_remote_post($authorizationurl, array( 26 'headers' => array('Content-Type: application/x-www-form-urlencoded', "Content-Length: $length"), 27 'body' => $request, 28 'timeout' => 30 29 )); 27 30 31 if (wp_remote_retrieve_response_code($response) != 200) { 32 return array('success'=>false, 'error'=>'OAUTH call failed. Error: '.wp_remote_retrieve_response_message($response)); 33 } else 34 $json = wp_remote_retrieve_body($response); 28 35 29 $ch = curl_init();30 curl_setopt($ch, CURLOPT_URL, $authorizationurl);31 32 curl_setopt($ch, CURLOPT_HEADER, false);33 curl_setopt($ch, CURLOPT_HTTPHEADER, array(34 "Content-Type: application/x-www-form-urlencoded",35 "Content-Length: $length"36 ));37 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);38 curl_setopt($ch, CURLOPT_POST, true);39 curl_setopt($ch, CURLOPT_POSTFIELDS, $request);40 41 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $verify_peer);42 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);43 44 $json = curl_exec($ch);45 46 47 if ($json == false) {48 return array('success'=>false, 'error'=>'Curl OAUTH call failed. Curl error: '.curl_error($ch));49 }50 51 curl_close($ch);52 53 36 //debug_print($json); 54 55 37 56 38 $json = json_decode($json, true); 57 39 if (!is_array($json)) 58 40 return array('success'=>false, 'error'=>'Malformed response or bad URL'); 59 41 60 42 if (array_key_exists("error", $json)) { 61 43 return array('success'=>false, 'error'=>"OAUTH request error: ".$json['error_description']); 62 44 } 63 64 //var_dump($json);65 45 66 46 switch ($request_type) { 67 47 case DOWNLOAD: 68 48 $endpointurl = $json['download_url']; 69 70 49 break; 71 50 case UPLOAD: … … 77 56 } 78 57 //debug_print("endpoint: ".$endpointurl); 79 58 80 59 $url_stuff = parse_url($endpointurl); 81 60 $endpoint = $url_stuff['path']; … … 85 64 else 86 65 $port = 80; 87 88 89 66 90 67 # get query parameters into array, and sort alphabetically ascending (not up to spec) 91 68 $data = $options; 92 /*if ($request_type == UPLOAD) {93 if (!array_key_exists('filename', $data))94 $data['filename'] = $options['dbname'].".xml";95 }*/96 69 ksort($data); 97 70 98 71 # should also percent encode names and values according to http://tools.ietf.org/html/draft-hammer-oauth-v2-mac-token-02#section-3.3.1.1 99 72 $token = $json['access_token']; … … 114 87 $data['timestamp']=$timestamp; 115 88 $data['nonce']=$nonce2; 116 89 90 if ($request_type == UPLOAD && !array_key_exists('filename', $data)) { 91 $data['UploadFile'] = "@$xml_file;type=text/xml"; 92 } 93 117 94 $db_request = ""; 118 95 foreach ($data as $k=>$v) { … … 122 99 123 100 //debug_print("db_request: $db_request"); 124 125 $ch = curl_init(); 126 curl_setopt($ch, CURLOPT_URL, $endpointurl); 127 128 curl_setopt($ch, CURLOPT_HEADER, false); 129 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 130 curl_setopt($ch, CURLOPT_POST, true); 131 132 if ($request_type != UPLOAD) 133 curl_setopt($ch, CURLOPT_POSTFIELDS, $db_request); 134 else { 135 if (array_key_exists('filename', $data)) { 136 curl_setopt($ch, CURLOPT_POSTFIELDS, $db_request); 137 } else { 138 $data['UploadFile'] = "@$xml_file;type=text/xml"; 139 curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 140 } 101 102 $response = wp_remote_post($endpointurl, array('body' => $db_request)); 103 if (wp_remote_retrieve_response_code($response) != 200) { 104 return array('success'=>false, 'error'=>'Data request failed. Error: '.wp_remote_retrieve_response_message($response)); 141 105 } 142 143 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $verify_peer); 144 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); 145 146 $downloaddata = curl_exec($ch); 147 if (!$downloaddata) { 148 return array('success'=>false, 'error'=>'Curl data call failed. Curl error: '.curl_error($ch)); 149 } 150 151 curl_close($ch); 152 153 //debug_print($downloaddata); 106 $downloaddata = wp_remote_retrieve_body($response); 107 154 108 //debug_print("downloaddata: $downloaddata"); 155 109 156 110 if (($json2 = json_decode($downloaddata, true)) != NULL) { 157 111 if (array_key_exists('error', $json2)) { … … 174 128 $timestamp3 = time(); 175 129 //$db_request = $downloaddata."&token=$token×tamp=$timestamp3&nonce=$nonce3"; 176 130 177 131 $pieces = explode("&", $downloaddata); 178 132 sort($pieces); 179 133 $imploded = implode("\n",$pieces); 180 134 181 135 $url_stuff = parse_url($endpointurl); 182 136 $endpoint = $url_stuff['path']; … … 186 140 else 187 141 $port = 80; 188 142 189 143 $macdigest = "$token\n$timestamp3\n$nonce3\n\nPOST\n$domain\n$port\n$endpoint\n$imploded\n"; 190 144 $macdigesthash = hash_hmac("sha1", $macdigest, $secretkey, true); 191 145 $signature3 = base64_encode($macdigesthash); 192 146 $db_request = $downloaddata."&token=$token×tamp=$timestamp3&nonce=$nonce3&signature=$signature3"; 193 194 195 196 $ch = curl_init(); 197 curl_setopt($ch, CURLOPT_URL, $endpointurl); 198 curl_setopt($ch, CURLOPT_HEADER, false); 199 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 200 curl_setopt($ch, CURLOPT_POST, true); 201 curl_setopt($ch, CURLOPT_POSTFIELDS, $db_request); 202 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $verify_peer); 203 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); 204 $downloaddata = curl_exec($ch); 205 206 207 208 if (!$downloaddata) { 209 return array('success'=>false, 'error'=>'Curl dbmake call failed. Curl error: '.curl_error($ch)); 147 148 $response = wp_remote_post($endpointurl, array('body' => $db_request)); 149 if (wp_remote_retrieve_response_code($response) != 200) { 150 return array('success'=>false, 'error'=>'DBmake request failed. Error: '.wp_remote_retrieve_response_message($response)); 210 151 } 211 152 $downloaddata = wp_remote_retrieve_body($response); 153 212 154 if (($json2 = json_decode($downloaddata, true)) != NULL) { 213 155 if (array_key_exists('error', $json2)) { … … 215 157 } 216 158 } 217 218 curl_close($ch); 219 220 221 159 222 160 return array('success'=>true); 223 161 } 224 162 225 163 if ($request_type == DOWNLOAD) { 226 164 return array('success'=>true, 'data'=>$downloaddata); 227 165 } 228 166 229 167 if ($request_type == PUBLISH) { 230 168 return array('success'=>true); … … 232 170 } 233 171 234 ?> -
shopsite-plugin/trunk/shopsite.php
r1707265 r2010190 2 2 /** 3 3 * @package ShopSite 4 * @version 1.5. 64 * @version 1.5.7 5 5 */ 6 6 /* … … 9 9 Description: ShopSite plugin to put products into your WordPress blog 10 10 Author: ShopSite 11 Version: 1.5. 611 Version: 1.5.7 12 12 Author URI: http://shopsite.com/ 13 */ 14 15 13 */ 16 14 17 15 if (isset($_REQUEST['ss_action'])) { … … 25 23 } 26 24 require_once(WP_LOAD_PATH.'wp-load.php'); 27 28 //echo "<script>alert('".$_REQUEST['shopsite_url']."')</script>"; 29 ///debug_print("Called with action ".$_REQUEST['ss_action']); 25 26 //debug_print("Called with action ".$_REQUEST['ss_action']); 30 27 if ($_REQUEST['ss_action'] == 'insert') 31 28 show_search_form(); … … 37 34 } 38 35 39 40 41 36 $product_list; 42 37 $wp_id; 43 44 38 45 39 register_uninstall_hook(__FILE__, 'on_uninstall'); … … 58 52 59 53 function load_plugin() { 60 $version = "1.5.6"; 61 if ( is_admin() ) { 62 $running_version = get_option('ss_version'); 63 if (!$running_version) 64 $running_version = "1"; 65 66 update_option('ss_version', $version); 67 if ($running_version < "1.5.1") { 68 69 //updating, rename to ss_ options to prevent conflicts with other plugins 70 { 71 $option_list = array('shopsite_url', 'config_dump', 'config_type', 'clientid', 'secretkey', 'code', 'authorizationurl', 'identifier', 'remember_search', 'remembered_search_string', 'media_url'); 72 foreach ($option_list as $option) { 73 $option_val = get_option($option); 74 if ($option_val) { 75 update_option('ss_'.$option, $option_val); 76 delete_option($option); 77 } else 78 add_option('ss_'+$option); 79 } 80 } 54 $version = "1.5.7"; 55 if ( is_admin() ) { 56 $running_version = get_option('ss_version'); 57 if (!$running_version) 58 $running_version = "1"; 59 60 update_option('ss_version', $version); 61 if ($running_version < "1.5.1") { 62 //updating, rename to ss_ options to prevent conflicts with other plugins 63 $option_list = array('shopsite_url', 'config_dump', 'config_type', 'clientid', 'secretkey', 'code', 'authorizationurl', 'identifier', 'remember_search', 'remembered_search_string', 'media_url'); 64 foreach ($option_list as $option) { 65 $option_val = get_option($option); 66 if ($option_val) { 67 update_option('ss_'.$option, $option_val); 68 delete_option($option); 69 } else 70 add_option('ss_'+$option); 81 71 } 82 83 if (get_option('ss_just_activated')) { 84 delete_option( 'ss_just_activated' );85 $shopsite_url = get_option('ss_shopsite_url');86 if ($shopsite_url == false || strlen($shopsite_url) < 10) {87 add_action( 'admin_head', 'start_tutorial');88 }72 } 73 74 if (get_option('ss_just_activated')) { 75 delete_option( 'ss_just_activated' ); 76 $shopsite_url = get_option('ss_shopsite_url'); 77 if ($shopsite_url == false || strlen($shopsite_url) < 10) { 78 add_action( 'admin_head', 'start_tutorial'); 89 79 } 90 91 92 80 } 81 } 93 82 } 94 83 … … 100 89 echo "<script>request_output_url();</script>"; 101 90 } 102 103 /*function link_jquery() {104 $jquery_url = includes_url()."js/jquery/jquery.js";105 //echo "<script type='text/javascript' src='".$jquery_url."'></script>";106 echo "<script>107 if (typeof $ !== \"undefined\") jQuery = $;108 if (typeof jQuery !== \"undefined\") $ = jQuery;109 </script>";110 }*/111 91 112 92 function link_tutorial() { … … 115 95 echo "<script type='text/javascript' src=".plugin_dir_url(__FILE__)."tutorial_driver.js></script>"; 116 96 echo "<link rel='stylesheet' href=".plugin_dir_url(__FILE__)."shopsite.css type='text/css' />"; 117 118 97 } 119 98 … … 121 100 echo "<script>var ss_path='".plugin_dir_url(__FILE__)."';</script>"; 122 101 } 123 124 102 125 103 //add_action( 'admin_enqueue_scripts', 'link_jquery' ); … … 136 114 137 115 function add_shopsite_menu() { 138 add_submenu_page( "options-general.php", "ShopSite", "ShopSite", "manage_options", "shopsite_menu", "show_shopsite_menu" );116 add_submenu_page( "options-general.php", "ShopSite", "ShopSite", "manage_options", "shopsite_menu", "show_shopsite_menu" ); 139 117 } 140 118 141 119 function show_shopsite_menu() { 142 global $wpdb;120 global $wpdb; 143 121 include_once "oauth.php"; 144 122 $testing = false; 145 123 $state = 'new_config'; 146 124 147 125 /*$option_list = array('shopsite_url', 'config_dump', 'config_type', 'clientid', 'secretkey', 'code', 'authorizationurl', 'identifier', 'remember_search', 'remembered_search_string', 'media_url'); 148 126 foreach ($option_list as $option) { 149 127 echo "<br>$option |".get_option($option)."| |".get_option('ss_'.$option)."|"; 150 128 }*/ 151 152 129 130 153 131 if (isset($_REQUEST['config_type'])) { 154 132 155 133 $config_type = trim($_REQUEST['config_type']); 156 134 //echo "<script>alert('$config_type');</script>"; … … 158 136 update_option('ss_config_type', $config_type); 159 137 $state = 'settings_saved'; 160 138 161 139 delete_option('ss_media_url'); 162 140 163 141 if ($config_type == 'ss_12') { 164 142 update_option('ss_config_dump', trim($_REQUEST['config_dump'])); 165 166 143 144 167 145 $decoded = base64_decode(trim($_REQUEST['config_dump'])); 168 146 $decoded = explode('^',$decoded); 169 147 170 148 update_option('ss_clientid', trim($decoded[0])); 171 149 update_option('ss_secretkey', trim($decoded[1])); … … 174 152 update_option('ss_shopsite_url', trim($decoded[4])); 175 153 } else { 176 154 177 155 $clientid = trim($_REQUEST['clientid']); update_option('ss_clientid', $clientid); 178 156 $secretkey = trim($_REQUEST['secretkey']); update_option('ss_secretkey', $secretkey); … … 184 162 } 185 163 } 186 187 /*if (isset($_REQUEST['shopsite_url'])) { update_option('shopsite_url', trim($_REQUEST['shopsite_url'])); $state = 'settings_saved';} 188 if (isset($_REQUEST['clientid'])) update_option('clientid', trim($_REQUEST['clientid'])); 189 if (isset($_REQUEST['secretkey'])) update_option('secretkey', trim($_REQUEST['secretkey'])); 190 if (isset($_REQUEST['code'])) update_option('code', trim($_REQUEST['code'])); 191 if (isset($_REQUEST['authorizationurl'])) update_option('authorizationurl', trim($_REQUEST['authorizationurl']));*/ 192 164 193 165 if (isset($_REQUEST['identifier'])) update_option('ss_identifier', trim($_REQUEST['identifier'])); 194 166 if (isset($_REQUEST['test'])) { … … 197 169 $state = 'testing_completed'; 198 170 } 199 171 200 172 $config_type = get_option('ss_config_type'); 201 173 if (strlen($config_type) == 0) 202 174 $config_type = 'ss_12'; 203 $config_dump = get_option('ss_config_dump');204 $shopsite_url = get_option('ss_shopsite_url');175 $config_dump = get_option('ss_config_dump'); 176 $shopsite_url = get_option('ss_shopsite_url'); 205 177 $clientid = get_option('ss_clientid'); 206 178 $secretkey = get_option('ss_secretkey'); 207 179 $code = get_option('ss_code'); 208 180 $authorizationurl = get_option('ss_authorizationurl'); 209 210 181 182 211 183 $identifier = get_option('ss_identifier'); 212 184 213 185 $SKU_selected = $GUID_selected = ""; 214 186 if ($identifier == 'SKU') … … 216 188 else 217 189 $GUID_selected = "checked"; 218 190 219 191 $ss_12_extra = ""; 220 192 $ss_11_extra = ""; … … 224 196 } 225 197 226 //ss_action=plugins.php?page=shopsite_menu198 //ss_action=plugins.php?page=shopsite_menu 227 199 echo 228 200 "<script> 229 201 230 202 \$('#ss_11').live('click', function() {\$('#config_type').val('ss_11'); \$('#ss_12_settings').css({'display':'none'}); \$('#ss_11_settings').css({'display':'table-row-group'}); }); 231 \$('#ss_12').live('click', function() {\$('#config_type').val('ss_12'); \$('#ss_11_settings').css({'display':'none'}); \$('#ss_12_settings').css({'display':'table-row-group'}); });203 \$('#ss_12').live('click', function() {\$('#config_type').val('ss_12'); \$('#ss_11_settings').css({'display':'none'}); \$('#ss_12_settings').css({'display':'table-row-group'}); }); 232 204 </script>"; 233 205 234 echo206 echo 235 207 "<h1>ShopSite configuration</h1> 236 Don't have a ShopSite store? <a id=get_shopsite target=_blank href='http ://saas.shopsite.com/express/'>Get a free 10-product Express store</a>.237 <form method=post>208 Don't have a ShopSite store? <a id=get_shopsite target=_blank href='https://saas.shopsite.com/express/'>Get a free 10-product Express store</a>. 209 <form method=post> 238 210 <input type=hidden id=config_type name=config_type value=$config_type> 239 211 <table> 240 212 <thead><tr><th colspan=2>Application settings</th></tr></thead>"; 241 213 242 214 echo 243 215 "<tbody id='ss_12_settings' $ss_12_extra><tr><td>Configuration data (paste from ShopSite) 244 216 <br><a id=ss_11>Click here if you have 5 fields to copy and paste in your ShopSite backoffice WordPress config</a></td> 245 217 <td><textarea name=config_dump id=config_dump style='height:100px;width:675px;'>$config_dump</textarea></td></tr></tbody>"; 246 247 218 219 248 220 echo 249 221 "<tbody id='ss_11_settings' $ss_11_extra> … … 254 226 <tr><td>Authorization URL:</td><td><input type=text name=authorizationurl id=authorizationurl value='$authorizationurl' size=100></td></tr> 255 227 <tr><td>ShopSite callback URL:</td><td><input type=text name=shopsite_url value='$shopsite_url' size=100></td></tr>"; 256 257 /*echo 258 "<tr id=store_url_instructions><td colspan=2>You can find Store URL under 'Preferences'->'Hosting Service'</td></tr> 259 <tr><td>Store URL:</td><td><input type=text name=store_url value='$store_url' size=100></td></tr>";*/ 260 228 261 229 echo 262 230 "</tbody>"; 263 //http://eval.shopsite.com/cgi-bin/ilya/ss/preview.cgi?&storeid=*0c5125a8823496a6&image_preview=1&page=2 264 265 266 /*echo "<tr><th colspan=2>Other settings</th></tr>*/ 267 268 231 269 232 echo "<tbody><tr><th colspan=2>Other settings</th></tr> 270 233 <tr><td>Unique product identifier:</td> … … 274 237 </tbody></table> 275 238 <br/><input type=submit name=test id=test_connection value='Test connection'>"; 276 239 277 240 if ($testing) { 278 241 echo "<div id=test_result>"; … … 283 246 } 284 247 echo "</div>"; 285 286 } 287 248 249 } 250 288 251 echo "<input type=hidden name=state id=state value=$state>"; 289 252 echo "<br/><input type=submit id=save_settings value='Save settings'></form>"; 290 253 } 291 292 /*onclick='window.open(\"".plugin_dir_url(__FILE__)."shopsite.php?ss_action=test&clientid=\"+document.forms[0].clientid.value+\"&secretkey=\"+document.forms[0].secretkey.value293 +\"&code=\"+document.forms[0].code.value+\"&authorizationurl=\"+document.forms[0].authorizationurl.value294 ,\"\",\"width=400,height=300\");' */295 //document.forms[0].clientid.value296 297 298 299 300 254 301 255 function shopsite_addbuttons() { … … 303 257 if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') ) 304 258 return; 305 259 306 260 // Add only in Rich Editor mode 307 261 if ( get_user_option('rich_editing') == 'true') { … … 310 264 } 311 265 } 312 266 313 267 function register_shopsite_button($buttons) { 314 268 array_push($buttons, "separator", "shopsite"); 315 269 return $buttons; 316 270 } 317 271 318 272 // Load the TinyMCE plugin : editor_plugin.js (wp2.5) 319 320 321 273 function add_shopsite_tinymce_plugin($plugin_array) { 322 274 $path = plugin_dir_url(__FILE__).'editor_plugin.js'; … … 324 276 return $plugin_array; 325 277 } 326 327 328 329 330 331 278 332 279 function show_search_form() { … … 334 281 $tinymce_url = includes_url()."js/tinymce/tiny_mce_popup.js"; 335 282 $jquery_url = includes_url()."js/jquery/jquery.js"; 336 283 337 284 $search_string = "*"; 338 285 339 286 $remember_search = ""; 340 287 $selected_name = ""; … … 342 289 if (get_option('ss_remember_search') == 'true') { 343 290 $remember_search = "checked"; 344 291 345 292 if (strlen(get_option('ss_remembered_search_string'))) 346 293 $search_string = get_option('ss_remembered_search_string'); 347 348 } 349 294 } 295 350 296 echo " 351 297 <html> … … 356 302 <script type='text/javascript' src='".plugin_dir_url(__FILE__)."search_products.js?".time()."'></script> 357 303 <script type='text/javascript'> var ss_remembered_search_string = '".$search_string."';</script> 358 359 360 304 </head> 361 305 <body>"; 362 363 364 365 306 echo "<div id=top_bar>"; 366 307 echo "<div id=message>You can use CTRL and SHIFT keys to select multiple products.</div>"; … … 370 311 echo "</div>"; 371 312 echo "<div id=search_results></div>"; 372 313 373 314 $extra_space = ""; 374 315 $message = ""; … … 379 320 $message = "<div id=extra_message>Upgrade your store to ShopSite v12 sp1 or greater to see product images above.</div>"; 380 321 } 381 322 382 323 echo "<div id=\"bottom_fix\"$extra_space>$message<div id=\"insert_button\">Insert selected products into post</div></div>"; 383 324 384 325 echo " 385 326 </body> … … 392 333 $shopsite_url = get_option('ss_shopsite_url'); 393 334 $url = $shopsite_url."&operation=get_setting&setting=output_url"; 394 $ curl_res = curl_open($url);395 $outputurl = $ curl_res[0];335 $resp = get_url($url); 336 $outputurl = $resp[0]; 396 337 if ($outputurl && strlen($outputurl) > 10) { 397 338 $media_url = $outputurl."/media/"; … … 408 349 //echo ("in:|".$_REQUEST['search_string']."|<br>"); 409 350 $search_string = stripslashes(trim($_REQUEST['search_string'])); 410 411 351 412 352 $remember_search = $_REQUEST['remember_search']; 413 353 414 354 ///debug_print("Updating remember_search to $remember_search"); 415 355 update_option('ss_remember_search', $remember_search); 416 356 417 357 if ($remember_search == 'true') { 418 358 update_option('ss_remembered_search_string', $search_string); 419 359 } 420 360 421 361 422 362 $shopsite_url = get_option('ss_shopsite_url'); 423 363 424 364 425 365 $media_url = get_media_url(); 426 427 428 366 429 367 $list_all = false; 430 368 if ($search_string == '*') { … … 432 370 $list_all = true; 433 371 } 434 435 372 436 373 if (!$list_all) { 437 374 if ($media_url) … … 440 377 $search_array = array('search_on'=>"name", 'search_term'=>$search_string, 'search_filter'=>'contains'); 441 378 } 442 379 443 380 $products_xml = oauth( 444 381 get_option('ss_clientid'), get_option('ss_secretkey'), get_option('ss_code'), get_option('ss_authorizationurl'), … … 446 383 array_merge(array('clientApp'=>'1', 'dbname'=>'products', 'version'=>'11.2', 'fields'=>'|Product GUID|Name|SKU|Graphic|', 'limit'=>$limit), $search_array) 447 384 ); 448 449 debug_print(print_r(html_entity_decode($products_xml['data']),true));450 385 386 //debug_print(print_r(html_entity_decode($products_xml['data']),true)); 387 451 388 if (!$products_xml['success']) { 452 389 echo "<div id=error_head>Unfortunately, something went wrong.</div>"; … … 466 403 } 467 404 } 468 405 469 406 //if media_url is absent, that means shopsite's XML API can't handle searches on multiple fields at once. We'll perform two separate searches then. 470 407 if (!$list_all && !$media_url) { … … 483 420 } 484 421 } 485 422 486 423 if (count($products_ar) == 0) { 487 424 echo "<div id=no_products>No matching products.</div>"; 488 425 return; 489 426 } 490 427 491 428 492 429 ksort($products_ar); 493 430 $products_ar = array_slice($products_ar,0,$limit); 494 431 495 432 echo "<div id=\"products\">"; 496 433 if (count($products_ar) == $limit) { … … 507 444 508 445 function print_product ($count, $name, $data, $media_url) { 509 446 510 447 $id = $data[0]; 511 448 $sku = rawurlencode($data[1]); 512 449 $image = $data[2]; 513 450 514 451 if (!strstr($image, "://")) { 515 452 if ($image && strstr($image,".") && $image != "no-image.png") { … … 520 457 $image = "ss_size2/".$image_ar[0]; 521 458 } else 522 $image = "ss_size2/no-image.png";523 } 524 459 $image = false;//"ss_size2/no-image.png"; 460 } 461 525 462 $outdated = ""; 526 463 if (!$media_url) 527 464 $outdated = " outdated"; 528 465 529 466 echo "<div class=\"wp_product$outdated\" id=\"wp_product_$count\">"; 530 if ($media_url )467 if ($media_url && $image) 531 468 if (strstr($image, "://")) 532 echo "<img class=\"product_image\" src=\"".$image."\">";469 echo "<img class=\"product_image\" alt=\"\" src=\"".$image."\">"; 533 470 else 534 echo "<img class=\"product_image\" src=\"".$media_url.$image."\">";471 echo "<img class=\"product_image\" alt=\"\" src=\"".$media_url.$image."\">"; 535 472 if (strlen($sku) > 0) 536 473 echo "<div class='product_sku'>".strip_tags($sku)."</div>"; 537 474 echo "<a class=\"product_name\" title=\"".str_replace("\"",""",$name)."\">".strip_tags($name)."</a>"; 538 475 539 476 echo '<input type=hidden class="name_input" name="name_input" value="'.str_replace("\"",""",$name).'">'; 540 477 echo '<input type=hidden class="guid_input" name="guid_input" value="'.$id.'">'; … … 547 484 global $product_list, $wp_id; 548 485 ///debug_print("product_handler entered"); 549 //return "<iframe src='$content' width='100%' height='300px' ><p>IFRAME FAIL!</p></iframe>";550 486 //return "<iframe src='$content' width='100%' height='300px' ><p>IFRAME FAIL!</p></iframe>"; 487 551 488 extract( shortcode_atts( array( 552 'id' => '',489 'id' => '', 553 490 'sku'=>'' 554 ), $atts ) );555 491 ), $atts ) ); 492 556 493 if (get_option('ss_identifier') == 'SKU') 557 494 $identifier = $sku; 558 495 else 559 496 $identifier = $id; 560 561 497 498 562 499 if ($identifier == '') 563 500 return ""; 564 565 501 502 566 503 /*$shopsite_url = get_option('shopsite_url'); 567 504 $handle = fopen($shopsite_url."&operation=get_product&id=$id",'r'); 568 $contents = stream_get_contents($handle);*/569 505 $contents = stream_get_contents($handle);*/ 506 570 507 $wp_id++; 571 572 508 509 573 510 if (!isset($product_list[$identifier])) { 574 511 ///debug_print("sticking stuff into product_list for $identifier"); … … 577 514 ///debug_print("sticking stuff into product_list 2"); 578 515 array_push($product_list[$identifier], $wp_id); 579 580 516 517 581 518 //$product_list["wp".$wp_id] = $id; 582 519 return "<div class=ss_product id=product_".$wp_id."></div>"; 583 520 584 521 //return $contents; 585 522 } … … 593 530 function init_product_list() { 594 531 global $product_list; 595 532 596 533 echo "<script type='text/javascript' src=".plugin_dir_url(__FILE__)."populate_products.js></script>"; 597 534 $product_list = array(); … … 607 544 $identifier = get_option('ss_identifier'); 608 545 $id_list = implode(",",array_unique(array_keys($product_list))); 609 546 610 547 //debug_print("dispatched:|$id_list|"); 611 612 548 549 613 550 echo 614 551 "<script> var ss_path='".plugin_dir_url(__FILE__)."'; 615 var ss_identifier = \"$identifier\";616 var ss_product_map = $product_map;617 var ss_id_list = \"$id_list\";618 var ss_shopsite_url=\"".get_option('ss_shopsite_url')."\";</script>";552 var ss_identifier = \"$identifier\"; 553 var ss_product_map = $product_map; 554 var ss_id_list = '$id_list'; 555 var ss_shopsite_url='".get_option('ss_shopsite_url')."';</script>"; 619 556 //echo "<script> var product_mapping = ".json_encode($product_list).";</script>"; 620 557 } … … 634 571 $hmachash = hash_hmac("sha1", $data, $secretkey, true); 635 572 $signature = rawurlencode(base64_encode($hmachash)); 636 573 637 574 $identifier = get_option('ss_identifier'); 638 639 //$shopsite_url = $_REQUEST['shopsite_url']; 575 640 576 $shopsite_url = get_option('ss_shopsite_url'); 641 //$id_list = "\"".str_replace(",","\",\"",$id_list)."\"";642 577 $url = $shopsite_url."&operation=get_products&".$identifier."_list=".$id_list."&signature=".$signature; 643 578 //debug_print("DATA URL |$url|"); 644 /*$url_openable = ini_get('allow_url_fopen'); 645 ini_set('allow_url_fopen', true); 646 $handle = fopen($url,'r'); 647 ini_set('allow_url_fopen', $url_openable); 648 print(stream_get_contents($handle));*/ 649 $curl_res = curl_open($url); 650 $product_data = $curl_res[0]; 579 $resp = get_url($url); 580 $product_data = $resp[0]; 651 581 if ($product_data) 652 582 print($product_data); … … 656 586 657 587 function test_connection() { 658 659 if (!in_array ('curl', get_loaded_extensions())) {660 return array("success"=>false, "error"=>"CURL PHP extension is not installed on your server. Contact your hosting provider.");661 }662 663 588 $test_download_xml = oauth( 664 589 get_option('ss_clientid'), get_option('ss_secretkey'), get_option('ss_code'), get_option('ss_authorizationurl'), … … 668 593 if (!$test_download_xml["success"]) 669 594 return $test_download_xml; 670 671 672 $res = curl_open(get_option('ss_shopsite_url')); 595 596 $res = get_url(get_option('ss_shopsite_url')); 673 597 if ($res[0] == false) 674 598 return array("success"=>false, "error"=>$res[1]); 675 599 676 600 return array("success"=>true); 677 601 } 678 602 679 603 function debug_print($text) { 680 file_put_contents("log.txt", $text."\n", FILE_APPEND); 681 } 682 683 function curl_open($url) { 684 $ch = curl_init(); 685 curl_setopt($ch, CURLOPT_URL, $url); 686 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 687 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); 688 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 689 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 690 $html = curl_exec($ch); 691 if (curl_errno($ch)) 692 $retval = array(false, curl_error($ch)); 693 else 694 $retval = array($html); 695 696 curl_close($ch); 697 604 //file_put_contents("log.txt", $text."\n", FILE_APPEND); 605 } 606 607 function get_url($url) { 608 $response = wp_remote_get($url); 609 if(wp_remote_retrieve_response_code($response) != 200) { 610 $retval = array(false, wp_remote_retrieve_response_message($response)); 611 } else { 612 $retval = array(wp_remote_retrieve_body($response)); 613 } 614 698 615 return $retval; 699 616 } 700 617 701 ?>
Note: See TracChangeset
for help on using the changeset viewer.