function shrinktheweb_getXMLResponse in ShrinkTheWeb 8
Same name and namespace in other branches
- 6 shrinktheweb.api.inc \shrinktheweb_getXMLResponse()
- 7 shrinktheweb.api.inc \shrinktheweb_getXMLResponse()
Store the XML response in an array and generate status bits.
Parameters
$sResponse:
Return value
mixed
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 673
Code
function shrinktheweb_getXMLResponse($sResponse) {
// If simplexml is available, we can do more stuff!
if (extension_loaded('simplexml')) {
$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.
$thumbnail = (array) $sXML
->children($sXMLLayout)->Response->ThumbnailResult->Thumbnail;
$aResponse['thumbnail'] = $thumbnail[0];
$aResponse['stw_action'] = $thumbnail[1];
// HTTP Response Code.
$aResponse['stw_response_status'] = $sXML
->children($sXMLLayout)->Response->ResponseStatus->StatusCode;
// STW Error Response.
$aResponse['stw_response_code'] = $sXML
->children($sXMLLayout)->Response->ResponseCode->StatusCode;
// Last Captured.
$aResponse['stw_last_captured'] = $sXML
->children($sXMLLayout)->Response->ResponseTimestamp->StatusCode;
// New Reqs left for today.
$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;
// Not yet implemented.
$aResponse['stw_category_code'] = $sXML
->children($sXMLLayout)->Response->CategoryCode->StatusCode;
}
else {
// LEGACY SUPPORT.
$aResponse['stw_response_status'] = shrinktheweb_getLegacyResponse('ResponseStatus', $sResponse);
$aResponse['stw_response_code'] = shrinktheweb_getLegacyResponse('ResponseCode', $sResponse);
// Check remaining quota.
$aResponse['stw_quota_remaining'] = shrinktheweb_getLegacyResponse('Quota_Remaining', $sResponse);
// Check remaining bandwidth.
$aResponse['stw_bandwidth_remaining'] = shrinktheweb_getLegacyResponse('Bandwidth_Remaining', $sResponse);
// Get thumbnail and status.
$aThumbnail = shrinktheweb_getThumbnailStatus($sResponse);
$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;
}