function ws_plugin__qcache_builder($buffer = FALSE)
 {
     if (defined("QUICK_CACHE_ALLOWED") && !QUICK_CACHE_ALLOWED) {
         return $buffer;
     } else {
         if (isset($_SERVER["QUICK_CACHE_ALLOWED"]) && !$_SERVER["QUICK_CACHE_ALLOWED"]) {
             return $buffer;
         } else {
             if (isset($_GET["qcAC"]) && !$_GET["qcAC"]) {
                 return $buffer;
             } else {
                 if (defined("DONOTCACHEPAGE")) {
                     return $buffer;
                 } else {
                     if (QUICK_CACHE_DONT_CACHE_WHEN_LOGGED_IN && function_exists("is_user_logged_in") && is_user_logged_in()) {
                         return $buffer;
                     }
                 }
             }
         }
     }
     /* Do NOT cache. * Re-checking this here ( when possible ) because it's so important! */
     /*
     										Now, we need to make sure NO theme and/or other plugins have used `ob_start("ob_gzhandler")`, or another form of gzip after the first phase of Quick Cache.
     										In other words, we must NOT store a cache of already-compressed data. This often occurs when a theme attempts to use `ob_start("ob_gzhandler")` in `/header.php`.
     										That should NOT be done in `/header.php`. If you must use `ob_start("ob_gzhandler")`, place it in: `/wp-config.php` so it's the top-level output buffer.
     										*Note* If `zlib.output_compression` is enabled, we should EXPECT to see `zlib_get_coding_type()`. It's fine to use `zlib.output_compression`.
     										* Using `zlib.output_compression` is preferred over `ob_start("ob_gzhandler")`, even when it's used inside `/wp-config.php`. */
     if (function_exists("zlib_get_coding_type") && zlib_get_coding_type() === "gzip" && !QUICK_CACHE_DETECTED_ZLIB_OC) {
         if (!headers_sent() && ($_decoded = ws_plugin__qcache_gzdecode($buffer))) {
             $buffer = $_decoded;
             /* OK, now we'll use the decoded version. */
             header("Content-Encoding:");
             /* And ditch this header. */
         } else {
             /* If headers were already sent, it's too late. */
             return $buffer;
         }
         /* Unable to cache this. */
     }
     /*
     										Resume buffer scans. Buffer should be in an uncompressed format now. */
     if (!strlen($buffer = trim($buffer))) {
         return $buffer;
     } else {
         if (strlen($buffer) <= 2000 && preg_match("/\\<h1\\>Error/i", $buffer)) {
             return $buffer;
         } else {
             if ($GLOBALS["QUICK_CACHE_STATUS"] && preg_match("/^5/", $GLOBALS["QUICK_CACHE_STATUS"])) {
                 return $buffer;
             }
         }
     }
     /* Do NOT cache. */
     /**/
     foreach ($headers = headers_list() as $i => $header) {
         if (preg_match("/^Retry-After\\:/i", $header) || preg_match("/^Status\\: 5/i", $header)) {
             return $buffer;
         } else {
             if (preg_match("/^Content-Type\\:/i", $header)) {
                 $content_type = $header;
             }
         }
         /* The "last" one. */
     }
     /**/
     /* Disables caching when a PHP routine sets an incompatible Content-Type. */
     if ($content_type && !preg_match("/xhtml|html|xml/i", $content_type)) {
         return $buffer;
     } else {
         if (function_exists("is_maintenance") && is_maintenance()) {
             return $buffer;
         } else {
             if (function_exists("did_action") && did_action("wm_head")) {
                 return $buffer;
             }
         }
     }
     /* Do NOT cache. */
     /**/
     if (!is_dir(WP_CONTENT_DIR . "/cache")) {
         @mkdir(WP_CONTENT_DIR . "/cache", 0777, true);
     }
     /**/
     if (is_dir(WP_CONTENT_DIR . "/cache") && is_writable(WP_CONTENT_DIR . "/cache")) {
         $total_time = number_format(microtime(true) - QUICK_CACHE_TIMER, 5, ".", "");
         /**/
         $cache = $buffer . "\n<!-- This Quick Cache file was built for ( " . QUICK_CACHE_FILE_DESC . " ) in " . $total_time . " seconds, on " . date("M jS, Y \\a\\t g:i a T") . ". -->";
         $cache .= "\n<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on " . date("M jS, Y \\a\\t g:i a T", strtotime("+" . QUICK_CACHE_EXPIRATION . " seconds")) . " -->";
         /**/
         if (QUICK_CACHE_USE_FLOCK_OR_SEM === "sem" && function_exists("sem_get") && ($mutex = @sem_get(1976, 1, 0644 | IPC_CREAT, 1)) && @sem_acquire($mutex) && ($cached = true)) {
             file_put_contents(QUICK_CACHE_FILE, serialize($headers) . "<!--headers-->" . $cache) . sem_release($mutex);
         } else {
             if (($mutex = @fopen(WP_CONTENT_DIR . "/cache/qc-l-mutex.lock", "w")) && @flock($mutex, LOCK_EX) && ($cached = true)) {
                 file_put_contents(QUICK_CACHE_FILE, serialize($headers) . "<!--headers-->" . $cache) . flock($mutex, LOCK_UN);
             }
         }
         /**/
         return $cached ? $cache : $buffer . "\n<!-- Quick Cache: failed to write cache, unable to obtain a mutex lock at the moment. Quick Cache will try again later. -->";
     } else {
         return $buffer . "\n<!-- Quick Cache: failed to write cache. The cache/ directory is either non-existent ( and could not be created ) or it is not writable. -->";
     }
 }
 /**
  * Output buffer handler; i.e. the cache file generator.
  *
  * @note We CANNOT depend on any WP functionality here; it will cause problems.
  *    Anything we need from WP should be saved in the postload phase as a scalar value.
  *
  * @since 140422 First documented version.
  *
  * @param string  $buffer The buffer from {@link \ob_start()}.
  * @param integer $phase A set of bitmask flags.
  *
  * @return string|boolean The output buffer, or `FALSE` to indicate no change.
  *
  * @throws \exception If unable to handle output buffering for any reason.
  *
  * @attaches-to {@link \ob_start()}
  */
 public function output_buffer_callback_handler($buffer, $phase)
 {
     if (!($phase & PHP_OUTPUT_HANDLER_END)) {
         // We do NOT chunk the buffer; so this should NOT occur.
         throw new \exception(sprintf(__('Unexpected OB phase: `%1$s`.', 'zencache'), $phase));
     }
     # Exclusion checks; there are MANY of these...
     advanced_cache_back_compat::QUICK_CACHE_constants();
     $cache = trim((string) $buffer);
     if (!isset($cache[0])) {
         // Allows a `0`.
         return FALSE;
     }
     // Don't cache an empty buffer.
     if (!isset($GLOBALS[__NAMESPACE__ . '__shutdown_flag'])) {
         return (bool) $this->maybe_set_debug_info($this::NC_DEBUG_EARLY_BUFFER_TERMINATION);
     }
     if (isset($_GET['zcAC']) && !filter_var($_GET['zcAC'], FILTER_VALIDATE_BOOLEAN)) {
         return (bool) $this->maybe_set_debug_info($this::NC_DEBUG_QCAC_GET_VAR);
     }
     if (defined('ZENCACHE_ALLOWED') && !ZENCACHE_ALLOWED) {
         return (bool) $this->maybe_set_debug_info($this::NC_DEBUG_ZENCACHE_ALLOWED_CONSTANT);
     }
     if (isset($_SERVER['ZENCACHE_ALLOWED']) && !$_SERVER['ZENCACHE_ALLOWED']) {
         return (bool) $this->maybe_set_debug_info($this::NC_DEBUG_ZENCACHE_ALLOWED_SERVER_VAR);
     }
     if (defined('DONOTCACHEPAGE')) {
         // WP Super Cache compatible.
         return (bool) $this->maybe_set_debug_info($this::NC_DEBUG_DONOTCACHEPAGE_CONSTANT);
     }
     if (isset($_SERVER['DONOTCACHEPAGE'])) {
         // WP Super Cache compatible.
         return (bool) $this->maybe_set_debug_info($this::NC_DEBUG_DONOTCACHEPAGE_SERVER_VAR);
     }
     if ($this->is_user_logged_in) {
         // Actually logged into the site.
         return (bool) $this->maybe_set_debug_info($this::NC_DEBUG_IS_LOGGED_IN_USER);
     }
     if ($this->is_like_user_logged_in()) {
         // Commenters, password-protected access, or actually logged-in.
         return (bool) $this->maybe_set_debug_info($this::NC_DEBUG_IS_LIKE_LOGGED_IN_USER);
     }
     // Separate debug notice.
     if ($this->is_404 && !ZENCACHE_CACHE_404_REQUESTS) {
         // Not caching 404 errors.
         return (bool) $this->maybe_set_debug_info($this::NC_DEBUG_404_REQUEST);
     }
     if (stripos($cache, '<body id="error-page">') !== FALSE) {
         // A WordPress-generated error?
         return (bool) $this->maybe_set_debug_info($this::NC_DEBUG_WP_ERROR_PAGE);
     }
     if (!$this->function_is_possible('http_response_code')) {
         // Unable to reliably detect HTTP status code?
         if (stripos($cache, '<title>database error</title>') !== FALSE) {
             // Fallback on this hackety hack.
             return (bool) $this->maybe_set_debug_info($this::NC_DEBUG_WP_ERROR_PAGE);
         }
     }
     if (!$this->has_a_cacheable_content_type()) {
         // Exclude non-HTML/XML content types.
         return (bool) $this->maybe_set_debug_info($this::NC_DEBUG_UNCACHEABLE_CONTENT_TYPE);
     }
     if (!$this->has_a_cacheable_status()) {
         // This will catch WP Maintenance Mode too.
         return (bool) $this->maybe_set_debug_info($this::NC_DEBUG_UNCACHEABLE_STATUS);
     }
     if ($this->is_maintenance) {
         // <http://wordpress.org/extend/plugins/maintenance-mode>
         return (bool) $this->maybe_set_debug_info($this::NC_DEBUG_MAINTENANCE_PLUGIN);
     }
     if ($this->function_is_possible('zlib_get_coding_type') && zlib_get_coding_type() && (!($zlib_oc = ini_get('zlib.output_compression')) || !filter_var($zlib_oc, FILTER_VALIDATE_BOOLEAN))) {
         return (bool) $this->maybe_set_debug_info($this::NC_DEBUG_OB_ZLIB_CODING_TYPE);
     }
     # Lock the cache directory while writes take place here.
     $cache_lock = $this->cache_lock();
     // Lock cache directory.
     # Construct a temp file for atomic cache writes.
     $cache_file_tmp = $this->add_tmp_suffix($this->cache_file);
     # Cache directory checks. The cache file directory is created here if necessary.
     if (!is_dir(ZENCACHE_DIR) && mkdir(ZENCACHE_DIR, 0775, TRUE) && !is_file(ZENCACHE_DIR . '/.htaccess')) {
         file_put_contents(ZENCACHE_DIR . '/.htaccess', $this->htaccess_deny);
     }
     // We know it's writable here.
     if (!is_dir($cache_file_dir = dirname($this->cache_file))) {
         $cache_file_dir_writable = mkdir($cache_file_dir, 0775, TRUE);
     }
     if (empty($cache_file_dir_writable) && !is_writable($cache_file_dir)) {
         // Only check if it's writable, if we didn't just successfully create it.
         throw new \exception(sprintf(__('Cache directory not writable. %1$s needs this directory please: `%2$s`. Set permissions to `755` or higher; `777` might be needed in some cases.', 'zencache'), $this->name, $cache_file_dir));
     }
     # This is where a new 404 request might be detected for the first time; and where the 404 error file already exists in this case.
     if ($this->is_404 && is_file($this->cache_file_404)) {
         if (!(symlink($this->cache_file_404, $cache_file_tmp) && rename($cache_file_tmp, $this->cache_file))) {
             throw new \exception(sprintf(__('Unable to create symlink: `%1$s` » `%2$s`. Possible permissions issue (or race condition), please check your cache directory: `%3$s`.', 'zencache'), $this->cache_file, $this->cache_file_404, ZENCACHE_DIR));
         }
         $this->cache_unlock($cache_lock);
         // Unlock cache directory.
         return (bool) $this->maybe_set_debug_info($this::NC_DEBUG_1ST_TIME_404_SYMLINK);
     }
     /* ------- Otherwise, we need to construct & store a new cache file. ----------------------------------------------- */
     if (ZENCACHE_DEBUGGING_ENABLE && $this->is_html_xml_doc($cache)) {
         $total_time = number_format(microtime(TRUE) - $this->timer, 5, '.', '');
         $cache .= "\n" . '<!-- ' . htmlspecialchars(sprintf(__('%1$s file path: %2$s', 'zencache'), $this->name, str_replace(WP_CONTENT_DIR, '', $this->is_404 ? $this->cache_file_404 : $this->cache_file))) . ' -->';
         $cache .= "\n" . '<!-- ' . htmlspecialchars(sprintf(__('%1$s file built for (%2$s) in %3$s seconds, on: %4$s.', 'zencache'), $this->name, $this->is_404 ? '404 [error document]' : $this->salt_location, $total_time, date('M jS, Y @ g:i a T'))) . ' -->';
         $cache .= "\n" . '<!-- ' . htmlspecialchars(sprintf(__('This %1$s file will auto-expire (and be rebuilt) on: %2$s (based on your configured expiration time).', 'zencache'), $this->name, date('M jS, Y @ g:i a T', strtotime('+' . ZENCACHE_MAX_AGE)))) . ' -->';
     }
     # NOT a 404, or it is 404 and the 404 cache file doesn't yet exist (so we need to create it).
     if ($this->is_404) {
         if (file_put_contents($cache_file_tmp, serialize($this->cacheable_headers_list()) . '<!--headers-->' . $cache) && rename($cache_file_tmp, $this->cache_file_404)) {
             if (!(symlink($this->cache_file_404, $cache_file_tmp) && rename($cache_file_tmp, $this->cache_file))) {
                 throw new \exception(sprintf(__('Unable to create symlink: `%1$s` » `%2$s`. Possible permissions issue (or race condition), please check your cache directory: `%3$s`.', 'zencache'), $this->cache_file, $this->cache_file_404, ZENCACHE_DIR));
             }
             $this->cache_unlock($cache_lock);
             // Unlock cache directory.
             return $cache;
             // Return the newly built cache; with possible debug information also.
         }
     } else {
         if (file_put_contents($cache_file_tmp, serialize($this->cacheable_headers_list()) . '<!--headers-->' . $cache) && rename($cache_file_tmp, $this->cache_file)) {
             $this->cache_unlock($cache_lock);
             // Unlock cache directory.
             return $cache;
             // Return the newly built cache; with possible debug information also.
         }
     }
     @unlink($cache_file_tmp);
     // Clean this up (if it exists); and throw an exception with information for the site owner.
     throw new \exception(sprintf(__('%1$s: failed to write cache file for: `%2$s`; possible permissions issue (or race condition), please check your cache directory: `%3$s`.', 'zencache'), $this->name, $_SERVER['REQUEST_URI'], ZENCACHE_DIR));
 }
示例#3
0
<?php

// initweb.php -- HotCRP initialization for web scripts
// HotCRP is Copyright (c) 2006-2015 Eddie Kohler and Regents of the UC
// Distributed under an MIT-like license; see LICENSE
require_once "init.php";
global $Conf, $Opt;
// Check for redirect to https
if (@$Opt["redirectToHttps"]) {
    Navigation::redirect_http_to_https(@$Opt["allowLocalHttp"]);
}
// Check and fix zlib output compression
global $zlib_output_compression;
$zlib_output_compression = false;
if (function_exists("zlib_get_coding_type")) {
    $zlib_output_compression = zlib_get_coding_type();
}
if ($zlib_output_compression) {
    header("Content-Encoding: {$zlib_output_compression}");
    header("Vary: Accept-Encoding", false);
}
// Set up sessions
$Opt["globalSessionLifetime"] = ini_get("session.gc_maxlifetime");
if (!isset($Opt["sessionLifetime"])) {
    $Opt["sessionLifetime"] = 86400;
}
ini_set("session.gc_maxlifetime", $Opt["sessionLifetime"]);
ensure_session();
// Initialize user
function initialize_user()
{
示例#4
0
// -- Initialize kernel and launch bootstrap
require_once ICMS_LIBRARIES_PATH . "/icms.php";
icms::setup();
icms::boot();
// -- Easiest ML by Gijoe (no longer needed here)
// Disable gzip compression if PHP is run under CLI mode
// To be refactored
if (empty($_SERVER['SERVER_NAME']) || substr(PHP_SAPI, 0, 3) == 'cli') {
    $icmsConfig['gzip_compression'] = 0;
}
if ($icmsConfig['gzip_compression'] == 1 && extension_loaded('zlib') && !ini_get('zlib.output_compression')) {
    ini_set('zlib.output_compression', TRUE);
    if (ini_get('zlib.output_compression_level') < 0) {
        ini_set('zlib.output_compression_level', 6);
    }
    if (!zlib_get_coding_type()) {
        ini_set('zlib.output_compression', FALSE);
        ob_start('ob_gzhandler');
    }
}
// Include openid common functions if needed
if (defined('ICMS_INCLUDE_OPENID')) {
    require_once ICMS_LIBRARIES_PATH . "/phpopenid/occommon.php";
}
/* This address the strict compliance for PHP 5.3/5.4, but the rest of our timezone handling
 * can be improved beyond this. ~skenow
 */
date_default_timezone_set(timezone_name_from_abbr("", $icmsConfig['default_TZ'] * 3600, 0));
// -- Include site-wide lang file
icms_loadLanguageFile('core', 'global');
icms_loadLanguageFile('core', 'theme');
示例#5
0
 }
 if (!$self->functionIsPossible('http_response_code')) {
     if (stripos($cache, '<title>database error</title>') !== false) {
         return (bool) $self->maybeSetDebugInfo(NC_DEBUG_WP_ERROR_PAGE);
     }
 }
 if (!$self->hasACacheableContentType()) {
     return (bool) $self->maybeSetDebugInfo(NC_DEBUG_UNCACHEABLE_CONTENT_TYPE);
 }
 if (!$self->hasACacheableStatus()) {
     return (bool) $self->maybeSetDebugInfo(NC_DEBUG_UNCACHEABLE_STATUS);
 }
 if ($self->is_maintenance) {
     return (bool) $self->maybeSetDebugInfo(NC_DEBUG_MAINTENANCE_PLUGIN);
 }
 if ($self->functionIsPossible('zlib_get_coding_type') && zlib_get_coding_type() && (!($zlib_oc = ini_get('zlib.output_compression')) || !filter_var($zlib_oc, FILTER_VALIDATE_BOOLEAN))) {
     return (bool) $self->maybeSetDebugInfo(NC_DEBUG_OB_ZLIB_CODING_TYPE);
 }
 # Lock the cache directory while writes take place here.
 $cache_lock = $self->cacheLock();
 // Lock cache directory.
 # Construct a temp file for atomic cache writes.
 $cache_file_tmp = $self->addTmpSuffix($self->cache_file);
 # Cache directory checks. The cache file directory is created here if necessary.
 if (!is_dir(ZENCACHE_DIR) && mkdir(ZENCACHE_DIR, 0775, true) && !is_file(ZENCACHE_DIR . '/.htaccess')) {
     file_put_contents(ZENCACHE_DIR . '/.htaccess', $self->htaccess_deny);
 }
 if (!is_dir($cache_file_dir = dirname($self->cache_file))) {
     $cache_file_dir_writable = mkdir($cache_file_dir, 0775, true);
 }
 if (empty($cache_file_dir_writable) && !is_writable($cache_file_dir)) {
}
// Here we go!
$ch = curl_init();
// Set up the basic cURL details
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_USERPWD, $pingdomCredentials['username'] . ':' . $pingdomCredentials['password']);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['App-Key: ' . $pingdomCredentials['appKey']]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Recommended by Pingdom's API page
// @link https://www.pingdom.com/features/api/documentation/#php+code+example
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
}
// If the PHP installation has gzip compression enabled, we'll use it
// @link https://www.pingdom.com/features/api/documentation/#gzip
if (zlib_get_coding_type() == 'gzip') {
    curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
}
// Here I quickly pull your account Localization settings for time and date stamps
curl_setopt($ch, CURLOPT_URL, 'https://api.pingdom.com/api/2.0/settings');
$settingsResponse = json_decode(curl_exec($ch), true);
$dateFormat = $settingsResponse['settings']['dateformat'];
$timeFormat = $settingsResponse['settings']['timeformat'];
// Instead of filling out the $checkHosts array in config.php, should we instead get each host from Pingdom?
if ($autoHost) {
    curl_setopt($ch, CURLOPT_URL, 'https://api.pingdom.com/api/2.0/checks');
    $response = json_decode(curl_exec($ch), true);
    // Reset $checkHosts just so it doesn't double up any hosts from config.php
    $checkHosts = [];
    // Grab each host's name and ID
    foreach ($response['checks'] as $host) {
示例#7
0
 /**
  * Returns the coding type used for output compression
  *
  * @return string
  */
 public function getCodingType() : string
 {
     return zlib_get_coding_type();
 }
示例#8
0
 public function output_buffer_callback_handler($buffer)
 {
     if (defined('DONOTCACHEPAGE')) {
         return $buffer;
     }
     if (isset($_SERVER['DONOTCACHEPAGE'])) {
         return $buffer;
     }
     if (isset($_GET['qcAC']) && !$_GET['qcAC']) {
         return $buffer;
     }
     if (defined('QUICK_CACHE_ALLOWED') && !QUICK_CACHE_ALLOWED) {
         return $buffer;
     }
     if (isset($_SERVER['QUICK_CACHE_ALLOWED']) && !$_SERVER['QUICK_CACHE_ALLOWED']) {
         return $buffer;
     }
     if (!QUICK_CACHE_WHEN_LOGGED_IN && $this->is_like_user_logged_in()) {
         return $buffer;
     }
     // Just to make sure.
     if (!QUICK_CACHE_WHEN_LOGGED_IN && function_exists('is_user_logged_in') && is_user_logged_in()) {
         return $buffer;
     }
     if (function_exists('zlib_get_coding_type') && zlib_get_coding_type() && (!($zlib_oc = ini_get('zlib.output_compression')) || !preg_match('/^(?:1|on|yes|true)$/i', $zlib_oc))) {
         throw new \exception(__('Unable to cache already-compressed output. Please use `mod_deflate` w/ Apache; or use `zlib.output_compression` in your `php.ini` file. Quick Cache is NOT compatible with `ob_gzhandler()` and others like this.', $this->text_domain));
     }
     if (function_exists('is_maintenance') && is_maintenance()) {
         return $buffer;
     }
     # http://wordpress.org/extend/plugins/maintenance-mode
     if (function_exists('did_action') && did_action('wm_head')) {
         return $buffer;
     }
     # http://wordpress.org/extend/plugins/wp-maintenance-mode
     $buffer = trim($buffer);
     // Trim buffer.
     $cache = $buffer;
     // Initialize cache value.
     $buffer_length = strlen($buffer);
     // Call this ONE time here.
     $headers = headers_list();
     // Need these headers below.
     $content_type = '';
     // Initialize possible content type.
     if (!$buffer_length) {
         return $buffer;
     }
     // Don't cache an empty buffer.
     if (strpos($buffer, '<body id="error-page">') !== FALSE) {
         return $buffer;
     }
     // Don't cache WP errors.
     foreach ($headers as $_header) {
         if (preg_match('/^(?:Retry\\-After\\:|Status\\:\\s+[^2]|HTTP\\/1\\.[01]\\s+[^2])/i', $_header)) {
             return $buffer;
         }
         // Don't cache errors (anything that's NOT a 2xx status).
         if (stripos($_header, 'Content-Type:') === 0) {
             $content_type = $_header;
         }
         // Last one.
     }
     unset($_header);
     // Just a little houskeeping.
     if ($content_type) {
         // If we found a Content-Type; make sure it's XML/HTML code.
         if (!preg_match('/xhtml|html|xml|' . preg_quote(__NAMESPACE__, '/') . '/i', $content_type)) {
             return $buffer;
         }
     }
     // Caching occurs here; we're good-to-go now :-)
     if (!is_dir(QUICK_CACHE_DIR) && mkdir(QUICK_CACHE_DIR, 0775, TRUE)) {
         if (is_writable(QUICK_CACHE_DIR) && !is_file(QUICK_CACHE_DIR . '/.htaccess')) {
             file_put_contents(QUICK_CACHE_DIR . '/.htaccess', 'deny from all');
         }
     }
     if (!is_dir(QUICK_CACHE_DIR) || !is_writable(QUICK_CACHE_DIR)) {
         // Must have this directory.
         throw new \exception(sprintf(__('Cache directory not writable. Quick Cache needs this directory please: `%1$s`. Set permissions to `755` or higher; `777` might be needed in some cases.', $this->text_domain), QUICK_CACHE_DIR));
     }
     if (QUICK_CACHE_DEBUGGING_ENABLE) {
         $total_time = number_format(microtime(TRUE) - $this->timer, 5, '.', '');
         $cache .= "\n" . '<!-- ' . htmlspecialchars(sprintf(__('Quick Cache file built for (%1$s%2$s) in %3$s seconds, on: %4$s.', $this->text_domain), $this->salt_location, $this->md5_4 ? '; ' . sprintf(__('user token: %1$s', $this->text_domain), substr($this->md5_4, 0, 8)) : '', $total_time, date('M jS, Y @ g:i a T'))) . ' -->';
         $cache .= "\n" . '<!-- ' . htmlspecialchars(sprintf(__('This Quick Cache file will auto-expire (and be rebuilt) on: %1$s (based on your configured expiration time).', $this->text_domain), date('M jS, Y @ g:i a T', strtotime('+' . QUICK_CACHE_MAX_AGE)))) . ' -->';
     }
     $cache_file_tmp = $this->cache_file . '.' . uniqid('', TRUE) . '.tmp';
     // Cache creation is atomic; e.g. tmp file w/ rename.
     if (file_put_contents($cache_file_tmp, serialize($headers) . '<!--headers-->' . $cache) && rename($cache_file_tmp, $this->cache_file)) {
         return $cache;
     }
     // Return the newly built cache; with possible debug information also.
     @unlink($cache_file_tmp);
     // Clean this up (if it exists); and throw an exception with information for the site owner.
     throw new \exception(sprintf(__('Quick Cache: failed to write cache file for: `%1$s`; possible permissions issue (or race condition), please check your cache directory: `%2$s`.', $this->text_domain), $_SERVER['REQUEST_URI'], QUICK_CACHE_DIR));
 }
示例#9
0
 /**
  * Output buffer handler; i.e. the cache file generator.
  *
  * @note We CANNOT depend on any WP functionality here; it will cause problems.
  *    Anything we need from WP should be saved in the postload phase as a scalar value.
  *
  * @since 150422 Rewrite.
  *
  * @param string $buffer The buffer from {@link \ob_start()}.
  * @param int    $phase  A set of bitmask flags.
  *
  * @throws \Exception If unable to handle output buffering for any reason.
  *
  * @return string|bool The output buffer, or `FALSE` to indicate no change.
  *
  * @attaches-to {@link \ob_start()}
  */
 public function outputBufferCallbackHandler($buffer, $phase)
 {
     if (!($phase & PHP_OUTPUT_HANDLER_END)) {
         throw new \Exception(sprintf(__('Unexpected OB phase: `%1$s`.', 'comet-cache'), $phase));
     }
     Classes\AdvCacheBackCompat::zenCacheConstants();
     $cache = trim((string) $buffer);
     if (!isset($cache[0])) {
         return false;
         // Don't cache an empty buffer.
     }
     if (!isset($GLOBALS[GLOBAL_NS . '_shutdown_flag'])) {
         return (bool) $this->maybeSetDebugInfo($this::NC_DEBUG_EARLY_BUFFER_TERMINATION);
     }
     if (defined('COMET_CACHE_ALLOWED') && !COMET_CACHE_ALLOWED) {
         return (bool) $this->maybeSetDebugInfo($this::NC_DEBUG_COMET_CACHE_ALLOWED_CONSTANT);
     }
     if (isset($_SERVER['COMET_CACHE_ALLOWED']) && !$_SERVER['COMET_CACHE_ALLOWED']) {
         return (bool) $this->maybeSetDebugInfo($this::NC_DEBUG_COMET_CACHE_ALLOWED_SERVER_VAR);
     }
     if (defined('DONOTCACHEPAGE')) {
         return (bool) $this->maybeSetDebugInfo($this::NC_DEBUG_DONOTCACHEPAGE_CONSTANT);
     }
     if (isset($_SERVER['DONOTCACHEPAGE'])) {
         return (bool) $this->maybeSetDebugInfo($this::NC_DEBUG_DONOTCACHEPAGE_SERVER_VAR);
     }
     if ((!IS_PRO || !COMET_CACHE_WHEN_LOGGED_IN) && $this->is_user_logged_in) {
         return (bool) $this->maybeSetDebugInfo($this::NC_DEBUG_IS_LOGGED_IN_USER);
     }
     if ((!IS_PRO || !COMET_CACHE_WHEN_LOGGED_IN) && $this->isLikeUserLoggedIn()) {
         return (bool) $this->maybeSetDebugInfo($this::NC_DEBUG_IS_LIKE_LOGGED_IN_USER);
     }
     if (!COMET_CACHE_CACHE_NONCE_VALUES && preg_match('/\\b(?:_wpnonce|akismet_comment_nonce)\\b/u', $cache)) {
         if (IS_PRO && COMET_CACHE_WHEN_LOGGED_IN && $this->isLikeUserLoggedIn()) {
             if (!COMET_CACHE_CACHE_NONCE_VALUES_WHEN_LOGGED_IN) {
                 return (bool) $this->maybeSetDebugInfo($this::NC_DEBUG_IS_LOGGED_IN_USER_NONCE);
             }
         } else {
             // Use the default debug notice for nonce conflicts.
             return (bool) $this->maybeSetDebugInfo($this::NC_DEBUG_PAGE_CONTAINS_NONCE);
         }
         // An nonce makes the page dynamic; i.e., NOT cache compatible.
     }
     if ($this->is_404 && !COMET_CACHE_CACHE_404_REQUESTS) {
         return (bool) $this->maybeSetDebugInfo($this::NC_DEBUG_404_REQUEST);
     }
     if (mb_stripos($cache, '<body id="error-page">') !== false) {
         return (bool) $this->maybeSetDebugInfo($this::NC_DEBUG_WP_ERROR_PAGE);
     }
     if (!$this->hasACacheableContentType()) {
         return (bool) $this->maybeSetDebugInfo($this::NC_DEBUG_UNCACHEABLE_CONTENT_TYPE);
     }
     if (!$this->hasACacheableStatus()) {
         return (bool) $this->maybeSetDebugInfo($this::NC_DEBUG_UNCACHEABLE_STATUS);
     }
     if ($this->is_maintenance) {
         return (bool) $this->maybeSetDebugInfo($this::NC_DEBUG_MAINTENANCE_PLUGIN);
     }
     if ($this->functionIsPossible('zlib_get_coding_type') && zlib_get_coding_type() && (!($zlib_oc = ini_get('zlib.output_compression')) || !filter_var($zlib_oc, FILTER_VALIDATE_BOOLEAN))) {
         return (bool) $this->maybeSetDebugInfo($this::NC_DEBUG_OB_ZLIB_CODING_TYPE);
     }
     # Lock the cache directory while writes take place here.
     $cache_lock = $this->cacheLock();
     // Lock cache directory.
     # Construct a temp file for atomic cache writes.
     $cache_file_tmp = $this->addTmpSuffix($this->cache_file);
     # Cache directory checks. The cache file directory is created here if necessary.
     if (!is_dir(COMET_CACHE_DIR) && mkdir(COMET_CACHE_DIR, 0775, true) && !is_file(COMET_CACHE_DIR . '/.htaccess')) {
         file_put_contents(COMET_CACHE_DIR . '/.htaccess', $this->htaccess_deny);
     }
     if (!is_dir($cache_file_dir = dirname($this->cache_file))) {
         $cache_file_dir_writable = mkdir($cache_file_dir, 0775, true);
     }
     if (empty($cache_file_dir_writable) && !is_writable($cache_file_dir)) {
         throw new \Exception(sprintf(__('Cache directory not writable. %1$s needs this directory please: `%2$s`. Set permissions to `755` or higher; `777` might be needed in some cases.', 'comet-cache'), NAME, $cache_file_dir));
     }
     # This is where a new 404 request might be detected for the first time.
     if ($this->is_404 && is_file($this->cache_file_404)) {
         if (!(symlink($this->cache_file_404, $cache_file_tmp) && rename($cache_file_tmp, $this->cache_file))) {
             throw new \Exception(sprintf(__('Unable to create symlink: `%1$s` » `%2$s`. Possible permissions issue (or race condition), please check your cache directory: `%3$s`.', 'comet-cache'), $this->cache_file, $this->cache_file_404, COMET_CACHE_DIR));
         }
         $this->cacheUnlock($cache_lock);
         // Release.
         return (bool) $this->maybeSetDebugInfo($this::NC_DEBUG_1ST_TIME_404_SYMLINK);
     }
     /* ------- Otherwise, we need to construct & store a new cache file. ----------------------------------------------- */
     if (COMET_CACHE_DEBUGGING_ENABLE && $this->isHtmlXmlDoc($cache)) {
         $total_time = number_format(microtime(true) - $this->timer, 5, '.', '');
         // Based on the original timer.
         $via = IS_PRO && $this->isAutoCacheEngine() ? __('Auto-Cache Engine', 'comet-cache') : __('HTTP request', 'comet-cache');
         $cache .= "\n" . '<!-- ' . htmlspecialchars(sprintf(__('%1$s file path: %2$s', 'comet-cache'), NAME, str_replace(WP_CONTENT_DIR, '', $this->is_404 ? $this->cache_file_404 : $this->cache_file))) . ' -->';
         $cache .= "\n" . '<!-- ' . htmlspecialchars(sprintf(__('%1$s file built for (%2$s%3$s) in %4$s seconds, on: %5$s; via %6$s.', 'comet-cache'), NAME, $this->is_404 ? '404 [error document]' : $this->salt_location, IS_PRO && COMET_CACHE_WHEN_LOGGED_IN && $this->user_token ? '; ' . sprintf(__('user token: %1$s', 'comet-cache'), $this->user_token) : '', $total_time, date('M jS, Y @ g:i a T'), $via)) . ' -->';
         $cache .= "\n" . '<!-- ' . htmlspecialchars(sprintf(__('This %1$s file will auto-expire (and be rebuilt) on: %2$s (based on your configured expiration time).', 'comet-cache'), NAME, date('M jS, Y @ g:i a T', strtotime('+' . COMET_CACHE_MAX_AGE)))) . ' -->';
     }
     if ($this->is_404) {
         if (file_put_contents($cache_file_tmp, serialize($this->cacheableHeadersList()) . '<!--headers-->' . $cache) && rename($cache_file_tmp, $this->cache_file_404)) {
             if (!(symlink($this->cache_file_404, $cache_file_tmp) && rename($cache_file_tmp, $this->cache_file))) {
                 throw new \Exception(sprintf(__('Unable to create symlink: `%1$s` » `%2$s`. Possible permissions issue (or race condition), please check your cache directory: `%3$s`.', 'comet-cache'), $this->cache_file, $this->cache_file_404, COMET_CACHE_DIR));
             }
             $this->cacheUnlock($cache_lock);
             // Release.
             return $cache;
             // Return the newly built cache; with possible debug information also.
         }
     } elseif (file_put_contents($cache_file_tmp, serialize($this->cacheableHeadersList()) . '<!--headers-->' . $cache) && rename($cache_file_tmp, $this->cache_file)) {
         $this->cacheUnlock($cache_lock);
         // Release.
         return $cache;
         // Return the newly built cache; with possible debug information also.
     }
     @unlink($cache_file_tmp);
     // Clean this up (if it exists); and throw an exception with information for the site owner.
     throw new \Exception(sprintf(__('%1$s: failed to write cache file for: `%2$s`; possible permissions issue (or race condition), please check your cache directory: `%3$s`.', 'comet-cache'), NAME, $_SERVER['REQUEST_URI'], COMET_CACHE_DIR));
 }
示例#10
0
 public function encodingType()
 {
     return zlib_get_coding_type();
 }