Changeset 1765

Show
Ignore:
Timestamp:
01/21/2008 06:18:56 AM (10 months ago)
Author:
Geert
Message:

Follow-up to r1763:

  • Took a more solid approach on the whitespace stripping
  • Now also stripping empty CSS declarations like h1 { /*nothing*/ }
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/modules/media/controllers/media.php

    r1763 r1765  
    170170                echo $data; 
    171171        } 
    172          
     172 
    173173        public function _default() 
    174174        { 
     
    179179        } 
    180180 
    181         // Based on http://www.ibloomstudios.com/articles/php_css_compressor/    
     181        // Based on http://www.ibloomstudios.com/articles/php_css_compressor/ 
    182182        public function _css_compress($data) 
    183183        { 
     
    186186                 
    187187                // Remove tabs, spaces, newlines, etc. 
     188                $data = preg_replace('/\s+/s', ' ', $data); 
    188189                $data = str_replace 
    189190                ( 
    190                         array("\r\n", "\r", "\n", "\t", '  ', ' {', '{ ', ' }', '} ', ' +', '+ ', ' >', '> ', ' :', ': ', ' ;', '; ', ' ,', ', ', ';}'), 
    191                         array(' ',    ' ',  ' ',  ' ',  ' ',  '{',  '{',  '}',  '}',  '+',  '+',  '>',  '>',  ':',  ':',  ';',  ';',  ',',  ',',  '}' ), 
     191                        array(' {', '{ ', ' }', '} ', ' +', '+ ', ' >', '> ', ' :', ': ', ' ;', '; ', ' ,', ', ', ';}'), 
     192                        array('{',  '{',  '}',  '}',  '+',  '+',  '>',  '>',  ':',  ':',  ';',  ';',  ',',  ',',  '}' ), 
    192193                        $data 
    193194                ); 
    194                  
     195 
     196                // Remove empty CSS declarations 
     197                $data = preg_replace('/[^{}]++\{\}/', '', $data); 
     198 
    195199                return $data; 
    196200        }