Advertisement
ontosys

Untitled

Jul 21st, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.60 KB | None | 0 0
  1. <?php
  2.  
  3.     error_reporting(0);
  4.    
  5.     $action     =   isset($_GET['action'])      ?   $_GET['action']     :   '';
  6.     $file_path  =   isset($_GET['file_path'])   ?   $_GET['file_path']  :   '';
  7.    
  8.     if(empty($action)   ||  empty($file_path))
  9.         die();
  10.        
  11.     //append doc root to path
  12.     $file_path  =   $_SERVER["DOCUMENT_ROOT"] .   $file_path;  
  13.    
  14.     //check if file exists
  15.     if (!file_exists($file_path))
  16.         die();
  17.        
  18.     $WPH_FileProcess  =   new WPH_FileProcess();
  19.    
  20.     $WPH_FileProcess->action        =   $action;
  21.     $WPH_FileProcess->file_path     =   $file_path;
  22.    
  23.     $WPH_FileProcess->run();    
  24.  
  25.     class WPH_FileProcess
  26.         {
  27.             var $action;
  28.             var $file_path;
  29.            
  30.             function __construct()
  31.                 {
  32.                     ob_start("ob_gzhandler");
  33.                 }
  34.            
  35.             function __destruct()
  36.                 {
  37.                     $out = ob_get_contents();
  38.                     ob_end_clean();
  39.                    
  40.                     echo $out;
  41.                 }
  42.                
  43.             function run()
  44.                 {
  45.                     switch($this->action)
  46.                         {
  47.                             case 'style-clean'  :  
  48.                                                     $this->style_clean();
  49.                                                     break;
  50.                            
  51.                         }
  52.                 }
  53.                
  54.                
  55.             function style_clean()
  56.                 {
  57.                     //output headers
  58.                     $expires_offset = 31536000;                    
  59.                    
  60.                     header('Content-Type: text/css; charset=UTF-8');
  61.                     header('Expires: ' . gmdate( "D, d M Y H:i:s", time() + $expires_offset ) . ' GMT');
  62.                     header("Cache-Control: public, max-age=$expires_offset");
  63.                     header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($this->file_path)).' GMT', true);
  64.                    
  65.                     $handle         = fopen($this->file_path, "r");
  66.                     $file_data      = fread($handle, filesize($this->file_path));
  67.                     fclose($handle);
  68.                    
  69.                     $file_data  =   preg_replace('!/\*.*?\*/!s', '', $file_data);
  70.                     $file_data  =   preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $file_data);
  71.                    
  72.                     echo $file_data;
  73.                    
  74.                 }
  75.         }
  76.  
  77.  
  78. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement