You are here

function shrinktheweb_checkWebsiteThumbnailCaptured in ShrinkTheWeb 6

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

Method that checks if the thumbnail for the specified website exists

1 call to shrinktheweb_checkWebsiteThumbnailCaptured()
shrinktheweb_getCachedThumbnail in ./shrinktheweb.api.inc
Get a thumbnail, caching it first if possible

File

./shrinktheweb.api.inc, line 327

Code

function shrinktheweb_checkWebsiteThumbnailCaptured($aArgs) {
  $sRequestUrl = 'http://images.shrinktheweb.com/xino.php';
  $sRemoteData = shrinktheweb_fileGetContent($sRequestUrl, $aArgs);

  // check if we get no response or the maintenance string
  if ($sRemoteData == '' || $sRemoteData == 'offline') {
    $aImage = array(
      'status' => 'no_response',
    );
    if ($sRemoteData != '') {
      $aImage['message'] = MAINTENANCE;
    }
  }
  else {
    $aResponse = shrinktheweb_getXMLResponse($sRemoteData);

    // thumbnail is existing, download it
    if ($aResponse['exists'] && $aResponse['thumbnail'] != '') {
      $aImage = array(
        'status' => 'save',
        'url' => $aResponse['thumbnail'],
      );

      // bandwidth limit has reached, grab embedded image and store it as BANDWIDTH_IMAGE
    }
    else {
      if ($aResponse['stw_bandwidth_remaining'] == 0 && !$aResponse['locked'] && !$aResponse['invalid'] && !$aResponse['exists'] && !$aResponse['problem']) {
        $aImage = array(
          'status' => 'bandwidth_exceed',
          'url' => $aResponse['thumbnail'],
        );

        // quota limit has reached, grab embedded image and store it as QUOTA_IMAGE
      }
      else {
        if ($aResponse['stw_quota_remaining'] == 0 && !$aResponse['locked'] && !$aResponse['invalid'] && !$aResponse['exists'] && !$aResponse['problem']) {
          $aImage = array(
            'status' => 'quota_exceed',
            'url' => $aResponse['thumbnail'],
          );

          // an error has occured, return the url but dont save the image
        }
        else {
          if (!$aResponse['exists'] && $aResponse['thumbnail'] != '') {
            $aImage = array(
              'status' => 'nosave',
              'url' => $aResponse['thumbnail'],
            );

            // otherwise return error because we dont know the situation
          }
          else {
            $aImage = array(
              'status' => 'error',
            );
          }
        }
      }
    }

    // add the request to the database if debug is enabled
    if (DEBUG) {
      shrinktheweb_addRequestToDB($aArgs, $aResponse, shrinktheweb_generateHash($aArgs));
    }
  }
  return $aImage;
}