From fc02a68691c3b3c355b5d91d387e6ec8154a9f6a Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Thu, 4 Feb 2016 21:57:14 -0500 Subject: [PATCH] Some temporary fixes for tempramental minifiers --- app/views/anime/add.php | 2 +- app/views/anime/cover.php | 2 +- app/views/anime/edit.php | 2 +- app/views/anime/list.php | 2 +- app/views/collection/add.php | 2 +- app/views/collection/edit.php | 2 +- app/views/collection/list.php | 2 +- app/views/footer.php | 2 +- app/views/header.php | 4 +-- app/views/manga/add.php | 2 +- app/views/manga/cover.php | 2 +- app/views/manga/edit.php | 1 - app/views/manga/list.php | 2 +- public/css.php | 38 ++++++++++++++-------------- public/js.php | 18 ++++++++------ public/min.php | 47 +++++++++++++++++++++++++++++++++++ 16 files changed, 88 insertions(+), 42 deletions(-) create mode 100644 public/min.php diff --git a/app/views/anime/add.php b/app/views/anime/add.php index 2fbdd582..9224905d 100644 --- a/app/views/anime/add.php +++ b/app/views/anime/add.php @@ -35,5 +35,5 @@ - + \ No newline at end of file diff --git a/app/views/anime/cover.php b/app/views/anime/cover.php index 92577322..8140430b 100644 --- a/app/views/anime/cover.php +++ b/app/views/anime/cover.php @@ -65,5 +65,5 @@ is_authenticated()): ?> - + diff --git a/app/views/anime/edit.php b/app/views/anime/edit.php index 3c44d7b3..6b1f7015 100644 --- a/app/views/anime/edit.php +++ b/app/views/anime/edit.php @@ -85,5 +85,5 @@ - + \ No newline at end of file diff --git a/app/views/anime/list.php b/app/views/anime/list.php index c173c738..055f2b29 100644 --- a/app/views/anime/list.php +++ b/app/views/anime/list.php @@ -74,4 +74,4 @@ is_authenticated()) ? 'table_edit' : 'table' ?> - + diff --git a/app/views/collection/add.php b/app/views/collection/add.php index d8fb65f2..c5b3742e 100644 --- a/app/views/collection/add.php +++ b/app/views/collection/add.php @@ -40,5 +40,5 @@ {{:title}} - + \ No newline at end of file diff --git a/app/views/collection/edit.php b/app/views/collection/edit.php index 8afecb81..17bcd1cd 100644 --- a/app/views/collection/edit.php +++ b/app/views/collection/edit.php @@ -52,5 +52,5 @@ {{:title}} - + \ No newline at end of file diff --git a/app/views/collection/list.php b/app/views/collection/list.php index 934468c5..77f61bca 100644 --- a/app/views/collection/list.php +++ b/app/views/collection/list.php @@ -49,4 +49,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/app/views/footer.php b/app/views/footer.php index d9e45b6b..ca4c3ba4 100644 --- a/app/views/footer.php +++ b/app/views/footer.php @@ -1,3 +1,3 @@ - + \ No newline at end of file diff --git a/app/views/header.php b/app/views/header.php index ad56fd7a..0dd2ee52 100644 --- a/app/views/header.php +++ b/app/views/header.php @@ -6,8 +6,8 @@ - - + +
diff --git a/app/views/manga/add.php b/app/views/manga/add.php index a50dde2c..33609c55 100644 --- a/app/views/manga/add.php +++ b/app/views/manga/add.php @@ -35,5 +35,5 @@ - + \ No newline at end of file diff --git a/app/views/manga/cover.php b/app/views/manga/cover.php index 9afec5e4..0677ff34 100644 --- a/app/views/manga/cover.php +++ b/app/views/manga/cover.php @@ -56,5 +56,5 @@ is_authenticated()): ?> - + diff --git a/app/views/manga/edit.php b/app/views/manga/edit.php index 71bef259..b281bb0e 100644 --- a/app/views/manga/edit.php +++ b/app/views/manga/edit.php @@ -85,5 +85,4 @@ - \ No newline at end of file diff --git a/app/views/manga/list.php b/app/views/manga/list.php index 5f90970b..92593abe 100644 --- a/app/views/manga/list.php +++ b/app/views/manga/list.php @@ -45,4 +45,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/public/css.php b/public/css.php index 72eaf1b2..7404e65c 100644 --- a/public/css.php +++ b/public/css.php @@ -13,16 +13,19 @@ namespace Aviat\EasyMin; +require_once('./min.php'); + /** * Simple CSS Minifier */ -class CSSMin { +class CSSMin extends BaseMin { protected $css_root; protected $path_from; protected $path_to; protected $group; protected $last_modified; + protected $requested_time; public function __construct(array $config, array $groups) { @@ -33,6 +36,11 @@ class CSSMin { $this->group = $groups[$group]; $this->last_modified = $this->get_last_modified(); + $this->requested_time = $this->get_if_modified(); + } + + public function __destruct() + { $this->send(); } @@ -43,16 +51,11 @@ class CSSMin { */ protected function send() { - $requested_time=(isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) - ? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) - : 0; - - // Send 304 when not modified for faster response - if($this->last_modified === $requested_time) + /*if($this->last_modified >= $this->requested_time) { - header("HTTP/1.1 304 Not Modified"); - exit(); - } + header('304 Not Modified'); + die(); + }*/ $css = ( ! array_key_exists('debug', $_GET)) ? $this->compress($this->get_css()) @@ -69,7 +72,6 @@ class CSSMin { */ public function compress($buffer) { - //Remove CSS comments $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer); @@ -119,9 +121,8 @@ class CSSMin { //Get the latest modified date rsort($modified); - $last_modified = $modified[0]; - return $last_modified; + return array_shift($modified); } /** @@ -133,18 +134,15 @@ class CSSMin { { $css = ''; - if(isset($this->group)) + foreach($this->group as $file) { - foreach($this->group as $file) - { - $new_file = realpath("{$this->css_root}{$file}"); - $css .= file_get_contents($new_file); - } + $new_file = realpath("{$this->css_root}{$file}"); + $css .= file_get_contents($new_file); } // Correct paths that have changed due to concatenation // based on rules in the config file - $css = str_replace($this->path_from, $this->path_to, $css); + // $css = str_replace($this->path_from, $this->path_to, $css); return $css; } diff --git a/public/js.php b/public/js.php index 00936d91..6fccc8ea 100644 --- a/public/js.php +++ b/public/js.php @@ -18,11 +18,12 @@ use GuzzleHttp\Psr7\Request; // Include guzzle require_once('../vendor/autoload.php'); +require_once('./min.php'); /** * Simple Javascript minfier, using google closure compiler */ -class JSMin { +class JSMin extends BaseMin { protected $js_root; protected $js_group; @@ -43,14 +44,15 @@ class JSMin { $this->cache_file = "{$this->js_root}cache/{$group}"; $this->last_modified = $this->get_last_modified(); - $this->requested_time = (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) - ? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) - : time(); + $this->requested_time = $this->get_if_modified(); $this->cache_modified = (is_file($this->cache_file)) ? filemtime($this->cache_file) : 0; + } + public function __destruct() + { // Output some JS! $this->send(); } @@ -59,11 +61,11 @@ class JSMin { { // If the browser's cached version is up to date, // don't resend the file - if($this->last_modified === $this->requested_time) + /*if($this->last_modified === $this->requested_time) { - header('HTTP/1.1 304 Not Modified'); + header($_SERVER['SERVER_PROTOCOL'].' 304 Not Modified'); exit(); - } + }*/ //Determine what to do: rebuild cache, send files as is, or send cache. // If debug is set, just concatenate @@ -86,7 +88,7 @@ class JSMin { // Otherwise, send the cached file else { - return $this->output(file_get_contents($cache_file)); + return $this->output(file_get_contents($this->cache_file)); } } diff --git a/public/min.php b/public/min.php new file mode 100644 index 00000000..be3fc0da --- /dev/null +++ b/public/min.php @@ -0,0 +1,47 @@ +