DataObjects/Core_ip_access.php
[Pman.Core] / Asset.php
index 91c36eb..305f7d3 100644 (file)
--- a/Asset.php
+++ b/Asset.php
@@ -22,8 +22,7 @@
 require_once 'Pman.php';
 
 class Pman_Core_Asset extends Pman {
-    
-    
+     
     var $types = array(
         'css' => 'text/css',
         'js' => 'text/javascript',
@@ -35,9 +34,11 @@ class Pman_Core_Asset extends Pman {
     }
     
     
-    function get($s='')
+    function get($s='', $opts = Array())
     {
-       
+        
+        $this->sessionState(0);
+        
         $bits = explode('/', $s);
         
         if (empty($bits[0]) || empty($bits[1])  || !isset($this->types[$bits[0]])) {
@@ -64,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);
         
         
@@ -85,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;
         
     }