示例#1
0
/**
 * Check if there's a cached error for the specified arguments.
 * 
 * @param Array $args The arguments to check the cache log for.
 * @return Boolean True if there's a cached error, false otherwise.
 */
function STWWT_debug_gotCachedError($args)
{
    global $wpdb;
    $wpdb->show_errors();
    $error_log = $wpdb->prefix . STWWT_TABLE_ERRORS;
    $argHash = md5(serialize($args));
    $SQL = $wpdb->prepare("\r\n\t\tSELECT *, UNIX_TIMESTAMP(request_date) AS request_date_ts \r\n\t\tFROM {$error_log}\r\n\t\tWHERE request_param_hash = %s\r\n\t\t  AND request_result = 'error'\r\n\t\tORDER BY request_date DESC\r\n\t\t", $argHash);
    $errorCache = $wpdb->get_row($SQL);
    // No error cached at all, so no need to do further checks.
    if (!$errorCache) {
        return false;
    } else {
        // 12 hours in seconds = 43200
        // Check if error occurred within 12 hours, if so, our error is cached
        if ($errorCache->request_date_ts > time() - 43200) {
            // See if error thumbnail exists or not. If it doesn't, we can return
            // false to say there's no error cached, and a re-fetch will be attempted.
            // This is added just in case the cache file has been deleted, but the error
            // log has not been emptied.
            if (!file_exists(STWWT_plugin_getCacheDirectory($argHash . '.jpg', true))) {
                return false;
            }
            return true;
        } else {
            @unlink(STWWT_plugin_getCacheDirectory($argHash . '.jpg', true));
            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();
}