You are here

function shrinktheweb_getXMLResponse in ShrinkTheWeb 7

Same name and namespace in other branches
  1. 8 shrinktheweb.api.inc \shrinktheweb_getXMLResponse()
  2. 6 shrinktheweb.api.inc \shrinktheweb_getXMLResponse()

store the XML response in an array and generate status bits

2 calls to shrinktheweb_getXMLResponse()
shrinktheweb_checkWebsiteThumbnailCaptured in ./shrinktheweb.api.inc
Method that checks if the thumbnail for the specified website exists
shrinktheweb_getNoResponseImage in ./shrinktheweb.api.inc
Gets the account problem image and returns the relative path to the cached image

File

./shrinktheweb.api.inc, line 488

Code

function shrinktheweb_getXMLResponse($sResponse) {
  if (extension_loaded('simplexml')) {

    // If simplexml is available, we can do more stuff!
    $oDOM = new DOMDocument();
    $oDOM
      ->loadXML($sResponse);
    $sXML = simplexml_import_dom($oDOM);
    $sXMLLayout = 'http://www.shrinktheweb.com/doc/stwresponse.xsd';

    // Pull response codes from XML feed
    $aResponse['thumbnail'] = $sXML
      ->children($sXMLLayout)->Response->ThumbnailResult->Thumbnail[0];
    $aResponse['stw_action'] = $sXML
      ->children($sXMLLayout)->Response->ThumbnailResult->Thumbnail[1];
    $aResponse['stw_response_status'] = $sXML
      ->children($sXMLLayout)->Response->ResponseStatus->StatusCode;

    // HTTP Response Code
    $aResponse['stw_response_code'] = $sXML
      ->children($sXMLLayout)->Response->ResponseCode->StatusCode;

    // STW Error Response
    $aResponse['stw_last_captured'] = $sXML
      ->children($sXMLLayout)->Response->ResponseTimestamp->StatusCode;

    // Last Captured
    $aResponse['stw_quota_remaining'] = $sXML
      ->children($sXMLLayout)->Response->Quota_Remaining->StatusCode;

    // New Reqs left for today
    $aResponse['stw_bandwidth_remaining'] = $sXML
      ->children($sXMLLayout)->Response->Bandwidth_Remaining->StatusCode;

    // New Reqs left for today
    $aResponse['stw_category_code'] = $sXML
      ->children($sXMLLayout)->Response->CategoryCode->StatusCode;

    // Not yet implemented
  }
  else {

    // LEGACY SUPPPORT
    $aResponse['stw_response_status'] = shrinktheweb_getLegacyResponse('ResponseStatus', $sRemoteData);
    $aResponse['stw_response_code'] = shrinktheweb_getLegacyResponse('ResponseCode', $sRemoteData);

    // check remaining quota
    $aResponse['stw_quota_remaining'] = shrinktheweb_getLegacyResponse('Quota_Remaining', $sRemoteData);

    // check remaining bandwidth
    $aResponse['stw_bandwidth_remaining'] = shrinktheweb_getLegacyResponse('Bandwidth_Remaining', $sRemoteData);

    // get thumbnail and status
    $aThumbnail = shrinktheweb_getThumbnailStatus($sRemoteData);
    $aResponse = array_merge($aResponse, $aThumbnail);
  }
  if ($aResponse['stw_action'] == 'delivered') {
    $aResponse['exists'] = true;
  }
  else {
    $aResponse['exists'] = false;
  }
  if ($aResponse['stw_action'] == 'fix_and_retry') {
    $aResponse['problem'] = true;
  }
  else {
    $aResponse['problem'] = false;
  }
  if ($aResponse['stw_action'] == 'noretry') {
    $aResponse['error'] = true;
  }
  else {
    $aResponse['error'] = false;
  }

  // if we use the advanced api for free account we get an invalid request
  if ($aResponse['stw_response_code'] == 'INVALID_REQUEST') {
    $aResponse['invalid'] = true;
  }
  else {
    $aResponse['invalid'] = false;
  }

  // if our domain or IP is not listed in the account's "Allowed Referrers" AND "Lock to Account" is enabled, then we get this error
  if ($aResponse['stw_response_code'] == 'LOCK_TO_ACCOUNT') {
    $aResponse['locked'] = true;
  }
  else {
    $aResponse['locked'] = false;
  }
  return $aResponse;
}