Plugin Directory

Changeset 573301


Ignore:
Timestamp:
07/16/2012 11:18:54 PM (14 years ago)
Author:
ShopSite
Message:
 
Location:
shopsite-plugin/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • shopsite-plugin/trunk/oauth.php

    r514950 r573301  
    4040 
    4141  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $verify_peer);
     42  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    4243 
    4344  $json = curl_exec($ch);
    4445 
    4546 
    46   if (!$json) {
     47  if ($json == false) {
    4748    return array('success'=>false, 'error'=>'Curl OAUTH call failed. Curl error: '.curl_error($ch));
    4849  }
     
    5455 
    5556  $json = json_decode($json, true);
     57  if (!is_array($json))
     58    return array('success'=>false, 'error'=>'Malformed response or bad URL');
    5659 
    5760  if (array_key_exists("error", $json)) {
     
    116119  $db_request = trim($db_request, "&");
    117120
    118   debug_print("db_request: $db_request");
     121  //debug_print("db_request: $db_request");
    119122 
    120123  $ch = curl_init();
     
    137140 
    138141  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $verify_peer);
     142  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    139143 
    140144  $downloaddata = curl_exec($ch);
     
    146150 
    147151  //debug_print($downloaddata);
    148   debug_print("downloaddata: $downloaddata");
     152  //debug_print("downloaddata: $downloaddata");
    149153 
    150154  if (($json2 = json_decode($downloaddata, true)) != NULL) {
     
    195199    curl_setopt($ch, CURLOPT_POSTFIELDS, $db_request);
    196200    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $verify_peer);
     201    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    197202    $downloaddata = curl_exec($ch);
    198203   
  • shopsite-plugin/trunk/readme.txt

    r556965 r573301  
    2929
    3030== Changelog ==
     31= 1.2 =
     32* Added a Test Connection button on the configuration screen. Added a 30-second connection timeout.
     33
    3134= 1.1 =
    3235* Fixed a bug preventing product display in the blog for some PHP config settings
  • shopsite-plugin/trunk/shopsite.php

    r556965 r573301  
    22/**
    33 * @package ShopSite
    4  * @version 1.1
     4 * @version 1.2
    55 */
    66/*
     
    99Description: ShopSite plugin to put products into your WordPress blog
    1010Author: ShopSite
    11 Version: 1.1
     11Version: 1.2
    1212Author URI: http://shopsite.com/
    1313*/
     
    3434}
    3535
     36
     37
    3638$product_list;
    3739$wp_id;
     
    5153function show_shopsite_menu() {
    5254    global $wpdb;
     55  include_once "oauth.php";
     56  $testing = false;
    5357
    5458    add_option('shopsite_url');
     
    7175 
    7276  if (isset($_REQUEST['identifier'])) update_option('identifier', $_REQUEST['identifier']);
     77  if (isset($_REQUEST['test'])) {
     78    $testing = true;
     79    $test_result = test_connection();
     80  }
     81   
    7382   
    7483    $shopsite_url = get_option('shopsite_url');
     
    8695    $GUID_selected = "checked";
    8796
     97//ss_action=plugins.php?page=shopsite_menu
    8898    echo    "<h1>ShopSite configuration</h1>
    89         <form method=post ss_action=plugins.php?page=shopsite_menu >
     99        <form method=post>
    90100    <table>
    91101    <tr><th colspan=2>Application settings</th></tr>
    92     <tr><td>Client ID:</td><td><input type=text name=clientid value='$clientid' size=100></td></tr>
    93     <tr><td>Secret Key for Signing:</td><td><input type=text name=secretkey value='$secretkey' size=100></td></tr>
    94     <tr><td>Authorization Code:</td><td><input type=text name=code value='$code' size=100></td></tr>
    95     <tr><td>Authorization URL:</td><td><input type=text name=authorizationurl value='$authorizationurl' size=100></td></tr>
    96     <tr><th colspan=2>Other settings</th></tr>
     102    <tr><td>Client ID:</td><td><input type=text name=clientid id=clientid value='$clientid' size=100></td></tr>
     103    <tr><td>Secret Key for Signing:</td><td><input type=text name=secretkey id=secretkey value='$secretkey' size=100></td></tr>
     104    <tr><td>Authorization Code:</td><td><input type=text name=code id=code value='$code' size=100></td></tr>
     105    <tr><td>Authorization URL:</td><td><input type=text name=authorizationurl id=authorizationurl value='$authorizationurl' size=100></td></tr>";
     106   
     107
     108 
     109  echo "<tr><th colspan=2>Other settings</th></tr>
    97110    <tr><td>ShopSite callback URL:</td><td><input type=text name=shopsite_url value='$shopsite_url' size=100></td></tr>
    98111    <tr><td>Unique product identifier:</td>
     
    101114    <input type=radio name=identifier value='SKU' $SKU_selected/>SKU</td></tr>
    102115    </table>
    103         <br/><input type=submit value='Save settings'></form>";
    104 }
    105 
    106 
    107 
     116    <br/><input type=submit name=test value='Test connection'>";
     117 
     118  if ($testing) {
     119    echo "<br>";
     120    if ($test_result['success'] == true)
     121      echo "<font color=green><b>Connection test successful</b></font>";
     122    if ($test_result['success'] == false) {
     123      echo "<font color=red><b>Connection test failed, check your settings.<br>Error: ".$test_result["error"];
     124    }
     125  }
     126 
     127  echo "<br/><input type=submit value='Save settings'></form>";
     128}
     129
     130/*onclick='window.open(\"".plugin_dir_url(__FILE__)."shopsite.php?ss_action=test&clientid=\"+document.forms[0].clientid.value+\"&secretkey=\"+document.forms[0].secretkey.value
     131      +\"&code=\"+document.forms[0].code.value+\"&authorizationurl=\"+document.forms[0].authorizationurl.value
     132      ,\"\",\"width=400,height=300\");' */
     133//document.forms[0].clientid.value
    108134
    109135
     
    479505}
    480506
     507function test_connection() {
     508  $test_download_xml = oauth(
     509    get_option('clientid'), get_option('secretkey'), get_option('code'), get_option('authorizationurl'),
     510    DOWNLOAD,
     511    array('clientApp'=>'1', 'dbname'=>'products', 'version'=>'11.2', 'fields'=>'|Product GUID|Name|SKU|', 'search_term'=>"B0gu5", 'search_on'=>'name', 'search_filter'=>'contains', 'limit'=>1)
     512  );
     513  if (!$test_download_xml["success"])
     514    return $test_download_xml;
     515   
     516 
     517   
     518  $shopsite_url = get_option('shopsite_url');
     519  $url_openable = ini_get('allow_url_fopen');
     520  ini_set('allow_url_fopen', true);
     521  $url = $shopsite_url;
     522  $handle = fopen($url,'r');
     523  ini_set('allow_url_fopen', $url_openable);
     524 
     525  if ($handle == false)
     526    return array("success"=>false, "error"=>"Check your callback URL");
     527 
     528  return array("success"=>true);
     529}
     530
    481531function debug_print($text) {
    482532  file_put_contents("log.txt", $text."\n", FILE_APPEND);
Note: See TracChangeset for help on using the changeset viewer.