function check_for_rewrite() { if (defined('KOKEN_REWRITE')) { return KOKEN_REWRITE; } if (!file_exists(FCPATH . '.htaccess') && strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') === 0) { define('KOKEN_REWRITE', false); return false; } $cache_key = 'core/rewrite_check'; $cache = Shutter::get_cache($cache_key, false); if ($cache !== false) { define('KOKEN_REWRITE', trim($cache['data']) === 'on'); return KOKEN_REWRITE; } $s = new Setting(); $s->where('name', 'site_url')->get(); if ($s->value === 'default') { $koken_url_info = $this->config->item('koken_url_info'); $url = $koken_url_info->base . '__rewrite_test/'; } else { $url = 'http://' . $_SERVER['HTTP_HOST'] . rtrim($s->value, '/') . '/__rewrite_test/'; } $headers = array('Cache-Control: must-revalidate'); if (LOOPBACK_HOST_HEADER) { $host = $_SERVER['SERVER_ADDR'] . ':' . $_SERVER['SERVER_PORT']; $headers[] = 'Host: ' . $_SERVER['HTTP_HOST']; $url = str_replace($_SERVER['HTTP_HOST'], $host, $url); } $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); if (strpos($url, 'https://') === 0) { curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); } curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); $return = trim(curl_exec($curl)); $code = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); $rewrite_check = $code === 200 && $return === 'koken:rewrite'; Shutter::write_cache($cache_key, $rewrite_check ? 'on' : 'off'); define('KOKEN_REWRITE', $rewrite_check); return $rewrite_check; }
public static function cache($contents) { $buster = self::$root_path . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'no-site-cache'; $cache_path = Shutter::filter('site.cache.write.path', self::$cache_path); if (isset($cache_path) && error_reporting() == 0 && !file_exists($buster)) { Shutter::write_cache($cache_path, $contents); } }
if ($cache) { if ($cache['status'] === 304) { $server_protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : false; if (substr(php_sapi_name(), 0, 3) === 'cgi') { header('Status: 304 Not Modified', true); } elseif ($server_protocol === 'HTTP/1.1' or $server_protocol === 'HTTP/1.0') { header($server_protocol . ' 304 Not Modified', true, $code); } else { header('HTTP/1.1 304 Not Modified', true, $code); } exit; } else { $blob = $cache['data']; } } else { Shutter::write_cache($cache_key, $blob); } if ($dl) { header("Content-Disposition: attachment; filename=\"" . basename($cache_key) . "\""); header('Content-type: image/' . $ext); header('Content-length: ' . strlen($blob)); echo $blob; } else { if ($base64) { $string = base64_encode($blob); die("data:image/{$ext};base64,{$string}"); } } header('Content-type: image/' . $ext); header('Content-length: ' . strlen($blob)); header('Cache-Control: public');