예제 #1
0
/**
 * Method to get image at the specified remote URL and attempt to save it to the specifed local cache path.
 * @param String $remoteURL The URL of the remote image to download.
 * @param Array $args The list of arguments needed to fetch an image.
 * @param Boolean $errorThumb If true, the file should be downloaded to an error filename.
 */
function STWWT_fetch_downloadRemoteImageToLocalPath($remoteURL, $args, $errorThumb)
{
    $resp = wp_remote_get($remoteURL);
    // Some kind of error from STW? e.g. empty request
    if (is_wp_error($resp)) {
        STWWT_debug_logError($args, 'web', false, 'HTTP Error. ' . $resp->get_error_message(), 'Did not get HTTP 200 OK when downloading thumbnail image.');
        return false;
    } else {
        if (200 != $resp['response']['code']) {
            STWWT_debug_logError($args, 'web', false, 'HTTP Error Code ' . $resp['response']['code'], 'Did not get HTTP 200 OK when downloading thumbnail image.');
            return false;
        }
    }
    $imagedata = $resp['body'];
    $cacheFilename = md5(serialize($args)) . '.jpg';
    $createFilepath = STWWT_plugin_getCacheDirectory($cacheFilename, $errorThumb);
    // Only save data if we managed to get the file contents
    if ($imagedata) {
        $fh = fopen($createFilepath, "w+");
        fputs($fh, $imagedata);
        fclose($fh);
        return STWWT_plugin_getCacheURL($cacheFilename, $errorThumb);
    }
    STWWT_debug_logError($args, 'web', false, 'HTTP Error Code ' . $resp['body'], 'Empty image data from ShrinkTheWeb.com.');
    return false;
}
예제 #2
0
/**
 * Shows information about the thumbnail cache.
 */
function STWWT_showPage_ThumbnailCache()
{
    $page = new PageBuilder(false);
    $page->showPageHeader(__('Shrink The Web - Website Thumbnails - Cache', 'stwwt'), '70%');
    ?>
	<h3>Clear Thumbnail Cache</h3>
	<p>Generally speaking, you do not need to clear the thumbnail cache. The plugin automatically manages the thumbnail cache, updating thumbnails automatically. However, if you do need to clear the cache for any reason, you can use the button below to flush the cache.</p>
	<?php 
    $form = new FormBuilder('stwwt_cache_clear');
    $form->setSubmitLabel('Clear Thumbnail Cache');
    if ($form->formSubmitted() && $form->formValid()) {
        STWWT_cache_emptyCache(false);
        $page->showMessage("Cache successfully emptied.");
    }
    echo $form->toString();
    // #### Cache Path Information
    $cachePathDir = STWWT_plugin_getCacheDirectory();
    $cachePathURL = STWWT_plugin_getCacheURL();
    $pathIsWriteable = file_exists($cachePathDir) && is_dir($cachePathDir) && is_writable($cachePathDir);
    ?>
	<br/>
	<h3>Cache Path Information</h3>
	<p>Your server cache path is <b><?php 
    echo $cachePathDir;
    ?>
</b>, which translates to a URL of <b><?php 
    echo $cachePathURL;
    ?>
</b>.</p>
	<p>Your cache path is currently <?php 
    echo $pathIsWriteable ? '<span class="stwwt_cache_status stwwt_cache_ok">Writeable</span>. This is fine, so you do not need to do anything more.' : '<span class="stwwt_cache_status stwwt_cache_error">Not Writeable</span>. This needs fixing for the thumbnail cache to work.';
    ?>
</p>
	<?php 
    $page->showPageFooter();
}