Guest User

Richard Cotton

a guest
Nov 12th, 2008
378
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.     // PHP-CSS-Compiler
  3.    
  4.     // setup:
  5.    
  6.     function ob_filter_terse($t)
  7.     {
  8.         // this filter minifies the CSS
  9.         $t = str_replace(array("\t","\r", "\n"), array(' ', '', ' '), $t);
  10.         while(strpos('  ', $t) !== FALSE)
  11.             $t = str_replace('  ', ' ', $t);       
  12.         return $t;
  13.     }
  14.    
  15.     function ob_filter_verbose($t)
  16.     {
  17.         // this function leaves CSS as it is and adds a little debug info
  18.         $t = "/* CSS Compiled ".strftime("%Y-%m-%d %H:%M:%S")." */\n" . $t;
  19.         return $t;
  20.     }
  21.    
  22.     // configuration:
  23.     // its important that we use soft-namespaces in this process
  24.     // since all the variables in the main section are exposed to all the included files
  25.    
  26.     $comp_verbose = (isset($_REQUEST['v']) && $_REQUEST['v']=='true' ? TRUE : FALSE);
  27.  
  28.     $comp_includes = array();
  29.     if(isset($_REQUEST['i']))
  30.     {
  31.         $comp_includes = explode(',', $_REQUEST['i']);
  32.     }  
  33.    
  34.     // compilation:
  35.    
  36.     header("Content-Type: text/css");
  37.    
  38.     ob_start(($comp_verbose ? 'ob_filter_verbose' : 'ob_filter_terse')); // set which filter function to use
  39.  
  40.     if($comp_verbose)
  41.     {
  42.         foreach($comp_includes as $f)
  43.             echo "/* Source: $f */\n";
  44.         echo "\n\n";
  45.     }
  46.        
  47.     foreach($comp_includes as $f)
  48.     {
  49.         include($f);
  50.     }  
  51.    
  52.     ob_end_flush(); //calls the filter function
  53. ?>
RAW Paste Data