| GPL V2 or higher. | +-------------------------------------------------------------------+ | block-Sample.php - Example NexOS block file | | Authors: | | Steven Sheeley | | Richard R. Pufky | | and the Myndworx Asylum Dev Team | | eMail: support at myndworx dot com | | Website: http://www.nexoscms.org and http://www.myndworx.com | +-------------------------------------------------------------------+ |Original Copyright below | +-------------------------------------------------------------------+ */ /********************************************* Dragonfly CMS, Copyright (c) 2004 by CPGNuke Dev Team http://dragonflycms.org Released under GNU GPL version 2 or any later version $Source: /cvs/html/includes/load/css.php,v $ $Revision: 1.1 $ $Author: nanocaiordo $ $Date: 2011/04/17 06:50:09 $ **********************************************/ if (!defined('CPG_NUKE')) { exit; } require CLASS_PATH . 'css.php'; if (false === CSS::request()) { HttpHeaders::flush(404, 'File not found'); } CSS::flushToClient();
public static final function flushToClient() { $ETag = md5(implode(';', self::$files)); $gzip = GZIP_OUT ? '.gz' : ''; $cachedFile = CACHE_PATH . 'css#' . $ETag; header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', time() + (DEVELOPER_MODE ? 0 : 60 * 60 * 24))); header('Cache-Control: public'); header('Content-Type: text/css; charset: utf-8'); if (!DEVELOPER_MODE && is_file($cachedFile . $gzip) && filemtime($cachedFile . $gzip) > self::$mtime) { if ($gzip) { header('Content-Encoding: gzip'); } header('Content-Length:' . filesize($cachedFile . $gzip)); if ($status = HttpUtils::entityCache($ETag, self::$mtime)) { HttpHeaders::flush($status); } else { readfile($cachedFile . $gzip); } exit; } $buffer = ''; foreach (self::$files as $file) { $buffer .= file_get_contents($file); } $buffer = preg_replace('#((url\\(|src=)["\']?)(../)?images/#', '$1' . BASEHREF . 'themes/' . self::$theme . '/images/', $buffer); $buffer = trim(preg_replace('#\\s+#', ' ', $buffer)); $buffer = preg_replace('#/\\*.*?\\*/#s', '', $buffer); $buffer = preg_replace('#\\s*[^{}]+{\\s*}\\s*#', '', $buffer); $buffer = preg_replace('#\\s*([{},;:])\\s*#', '$1', $buffer); $buffer = str_replace(';}', '}', $buffer); if (GZIPSUPPORT && ($gz = gzopen($cachedFile . '.gz', 'w9'))) { gzwrite($gz, $buffer); gzclose($gz); } file_put_contents($cachedFile, $buffer); if (is_file($cachedFile . $gzip) || !$gzip) { if ($gzip) { header('Content-Encoding: gzip'); } header('Content-Length:' . filesize($cachedFile . $gzip)); exit(readfile($cachedFile . $gzip)); } else { ob_start('ob_gzhandler'); exit($buffer); } }
public static final function flushToClient() { $ETag = md5(implode(';', self::$files)); $gzip = GZIP_OUT ? '.gz' : ''; $cachedFile = CACHE_PATH . 'js#' . $ETag; header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', time() + (DEVELOPER_MODE ? 0 : 60 * 60 * 24))); header('Cache-Control: public'); header('Content-Type: application/javascript; charset: utf-8'); if (!DEVELOPER_MODE && is_file($cachedFile . $gzip) && filemtime($cachedFile . $gzip) > self::$mtime) { if ($gzip) { header('Content-Encoding: gzip'); } header('Content-Length:' . filesize($cachedFile . $gzip)); if ($status = HttpUtils::entityCache($ETag, self::$mtime)) { HttpHeaders::flush($status); } else { readfile($cachedFile . $gzip); } exit; } $buffer = ''; foreach (self::$files as $file) { $buffer .= file_get_contents($file); } $buffer = preg_replace('#^(\\s+)#m', '', $buffer); $buffer = preg_replace('#[\\r\\n]+#', '', $buffer); $buffer = str_replace(';}', '}', $buffer); if (GZIPSUPPORT && ($gz = gzopen($cachedFile . '.gz', 'w9'))) { gzwrite($gz, $buffer); gzclose($gz); } file_put_contents($cachedFile, $buffer); if (is_file($cachedFile . $gzip) || !$gzip) { if ($gzip) { header('Content-Encoding: gzip'); } header('Content-Length:' . filesize($cachedFile . $gzip)); exit(readfile($cachedFile . $gzip)); } else { ob_start('ob_gzhandler'); exit($buffer); } }
/** * http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.3.3 * http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.19 .24 .25 .26 .28 .44 * if the request method is GET or HEAD, the server SHOULD respond with a 304 (Not Modified) response, * including the cache- related header fields (particularly ETag) of one of the entities that matched. * For all other request methods, the server MUST respond with a status of 412 (Precondition Failed). */ public final function entityCache($ETag, $time) { $ETag = "\"{$ETag}\""; HttpHeaders::add('ETag: ' . $ETag); if (!empty($_SERVER['HTTP_IF_NONE_MATCH'])) { if (false !== strpos($_SERVER['HTTP_IF_NONE_MATCH'], $ETag)) { return 304; } # If none of the entity tags match, # then the server MAY perform the requested method as if the If-None-Match header field did not exist, # but MUST also ignore any If-Modified-Since header field(s) in the request. $_SERVER['HTTP_IF_MODIFIED_SINCE'] = null; } if (isset($_SERVER['HTTP_IF_MATCH']) && false === strpos($_SERVER['HTTP_IF_MATCH'], $ETag)) { return 412; } $time = (int) $time; HttpHeaders::add('Last-Modified: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', $time)); # DATE_RFC1123 if (!empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $time <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { return 304; } if (!empty($_SERVER['HTTP_IF_UNMODIFIED_SINCE']) && $time > strtotime($_SERVER['HTTP_IF_UNMODIFIED_SINCE'])) { return 412; } HttpHeaders::flush(); }