function shrinktheweb_getCachedThumbnail in ShrinkTheWeb 7
Same name and namespace in other branches
- 8 shrinktheweb.api.inc \shrinktheweb_getCachedThumbnail()
- 6 shrinktheweb.api.inc \shrinktheweb_getCachedThumbnail()
Get a thumbnail, caching it first if possible
1 call to shrinktheweb_getCachedThumbnail()
- shrinktheweb_getThumbnail in ./
shrinktheweb.api.inc - Gets the thumbnail for the specified website, stores it in the cache, and then returns the relative path to the cached image.
File
- ./
shrinktheweb.api.inc, line 244
Code
function shrinktheweb_getCachedThumbnail($aArgs = null) {
$aArgs = is_array($aArgs) ? $aArgs : array();
// Use arguments to work out the target filename
$sFilename = shrinktheweb_generateHash($aArgs) . '.jpg';
$sFile = THUMBNAIL_DIR . $sFilename;
$sReturnName = false;
// Work out if we need to update the cached thumbnail
$iForceUpdate = $aArgs['stwredo'] ? true : false;
if ($iForceUpdate || shrinktheweb_cacheFileExpired($sFile)) {
// if bandwidth limit has reached return the BANDWIDTH_IMAGE
if (shrinktheweb_checkLimitReached(THUMBNAIL_DIR . BANDWIDTH_IMAGE)) {
$sFilename = BANDWIDTH_IMAGE;
// if quota limit has reached return the QUOTA_IMAGE
}
else {
if (shrinktheweb_checkLimitReached(THUMBNAIL_DIR . QUOTA_IMAGE)) {
$sFilename = QUOTA_IMAGE;
// if WAY OVER the limits (i.e. request is ignored by STW) return the NO_RESPONSE_IMAGE
}
else {
if (shrinktheweb_checkLimitReached(THUMBNAIL_DIR . NO_RESPONSE_IMAGE)) {
$sFilename = NO_RESPONSE_IMAGE;
}
else {
// check if the thumbnail was captured
$aImage = shrinktheweb_checkWebsiteThumbnailCaptured($aArgs);
switch ($aImage['status']) {
case 'save':
// download the image to local path
shrinktheweb_downloadRemoteImageToLocalPath($aImage['url'], $sFile);
break;
case 'nosave':
// dont save the image but return the url
return $aImage['url'];
break;
case 'quota_exceed':
// download the image to local path for locking requests
$sFilename = QUOTA_IMAGE;
$sFile = THUMBNAIL_DIR . $sFilename;
shrinktheweb_downloadRemoteImageToLocalPath($aImage['url'], $sFile);
break;
case 'bandwidth_exceed':
// download the image to local path for locking requests
$sFilename = BANDWIDTH_IMAGE;
$sFile = THUMBNAIL_DIR . $sFilename;
shrinktheweb_downloadRemoteImageToLocalPath($aImage['url'], $sFile);
break;
default:
// otherwise return the status
return $aImage['status'];
}
}
}
}
}
$sFile = THUMBNAIL_DIR . $sFilename;
// Check if file exists
if (file_exists($sFile)) {
$sReturnName = THUMBNAIL_URI . $sFilename;
}
return $sReturnName;
}