You are here

function shrinktheweb_checkWebsiteThumbnailCaptured in ShrinkTheWeb 8

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

Method that checks if the thumbnail for the specified website exists.

Parameters

$aArgs:

Return value

array

Throws

\Exception

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

File

./shrinktheweb.api.inc, line 430

Code

function shrinktheweb_checkWebsiteThumbnailCaptured($aArgs) {
  $sRequestUrl = PROTOCOL . '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'],
        'captured_on' => $aResponse['stw_last_captured'],
      );
    }
    elseif ($aResponse['stw_bandwidth_remaining'] == 0 && !$aResponse['locked'] && !$aResponse['invalid'] && !$aResponse['exists'] && !$aResponse['problem']) {
      $aImage = array(
        'status' => 'bandwidth_exceed',
        'url' => $aResponse['thumbnail'],
      );
    }
    elseif ($aResponse['stw_quota_remaining'] == 0 && !$aResponse['locked'] && !$aResponse['invalid'] && !$aResponse['exists'] && !$aResponse['problem']) {
      $aImage = array(
        'status' => 'quota_exceed',
        'url' => $aResponse['thumbnail'],
      );
    }
    elseif (!$aResponse['exists'] && $aResponse['thumbnail'] != '') {
      $aImage = array(
        'status' => 'nosave',
        'url' => $aResponse['thumbnail'],
      );
    }
    else {
      $aImage = array(
        'status' => 'error',
      );
    }

    // Add the request to the database if debug is enabled.
    if (DEBUG) {
      if (isset($aArgs['stwsize'])) {
        switch ($aArgs['stwsize']) {
          case 'mcr':
            $stwxmax = 75;
            $stwymax = 57;
            break;
          case 'tny':
            $stwxmax = 90;
            $stwymax = 68;
            break;
          case 'vsm':
            $stwxmax = 100;
            $stwymax = 75;
            break;
          case 'sm':
            $stwxmax = 120;
            $stwymax = 90;
            break;
          case 'lg':
            $stwxmax = 200;
            $stwymax = 150;
            break;
          case 'xlg':
            $stwxmax = 320;
            $stwymax = 240;
            break;
        }
      }
      $aArgs['stwq'] = isset($aArgs['stwq']) ? $aArgs['stwq'] : 95;
      $aArgs['stwfull'] = isset($aArgs['stwfull']) ? $aArgs['stwfull'] : 0;
      $aArgs['stwxmax'] = isset($aArgs['stwxmax']) ? $aArgs['stwxmax'] : (isset($stwxmax) ? $stwxmax : 0);
      $aArgs['stwymax'] = isset($aArgs['stwymax']) ? $aArgs['stwymax'] : (isset($stwymax) ? $stwymax : 0);
      $aArgs['stwnrx'] = isset($aArgs['stwnrx']) ? $aArgs['stwnrx'] : 1024;
      $aArgs['stwnry'] = isset($aArgs['stwnry']) ? $aArgs['stwnry'] : 768;
      $sHash = shrinktheweb_generateHash($aArgs);
      $aFields = array(
        'stw_domain' => $aArgs['stwurl'],
        'stw_timestamp' => time(),
        'stw_capturedon' => $aResponse['stw_last_captured'],
        'stw_quality' => $aArgs['stwq'],
        'stw_full' => $aArgs['stwfull'],
        'stw_xmax' => $aArgs['stwxmax'],
        'stw_ymax' => $aArgs['stwymax'],
        'stw_nrx' => $aArgs['stwnrx'],
        'stw_nry' => $aArgs['stwnry'],
        'stw_invalid' => $aResponse['invalid'] != '' ? $aResponse['invalid'] : 0,
        'stw_stwerrcode' => $aResponse['stw_response_code'],
        'stw_error' => $aResponse['error'] != '' ? $aResponse['error'] : 0,
        'stw_errcode' => $aResponse['stw_response_status'],
        'stw_hash' => $sHash,
      );
      \Drupal::database()
        ->merge('shrinktheweb_log')
        ->key(array(
        'stw_hash' => $sHash,
      ))
        ->fields($aFields)
        ->updateFields($aFields)
        ->execute();
    }
  }
  return $aImage;
}