Asset.php
[Pman.Core] / Asset.php
index 40c697c..5e565ae 100644 (file)
--- a/Asset.php
+++ b/Asset.php
@@ -65,6 +65,10 @@ class Pman_Core_Asset extends Pman {
             exit;
         }
         
+        
+        $supportsGzip = !empty($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip' ) !== false;
+
+        
         $last_modified_time = filemtime($fn);
         
         
@@ -86,15 +90,32 @@ class Pman_Core_Asset extends Pman {
         
         
         header("Pragma: public");
-        header('Content-Length: '. filesize($fn));
+        
         header('Cache-Control: max-age=2592000, public');
         header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 2592000));
         header('Last-Modified: '.gmdate('D, d M Y H:i:s \G\M\T', $last_modified_time));
         header('Etag: '. md5($fn)); 
         
-        $fh = fopen($fn,'r');
-        fpassthru($fh);
-        fclose($fh);
+         if ( $supportsGzip ) {
+            $content = gzencode( file_get_contents($fn) , 9);
+            
+            header('Content-Encoding: gzip');
+            header('Vary: Accept-Encoding');
+            header('Content-Length: '. strlen($content));
+            
+            echo $content;
+            
+        } else {
+            
+            
+            $fh = fopen($fn,'r');
+            fpassthru($fh);
+            fclose($fh);
+            $content = $data;
+        }
+        
+        
+        
         exit;
         
     }
@@ -102,5 +123,12 @@ class Pman_Core_Asset extends Pman {
         die('invalid');
     }
      
-    
+    static function getAssetDir($type)
+    {
+        if(empty($type)) {
+            return false;
+        }
+        
+        
+    }
 }