Changeset 13404

Show
Ignore:
Timestamp:
02/08/12 14:27:15 (1 year ago)
Author:
GameGamer43
Message:

re #5545 - ensure compress_framework_css is available to avoid any issues with updating between versions

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/branches/2.10/framework/install.php

    r13160 r13404  
    134134  } 
    135135 
     136    if (!function_exists('compress_framework_css')) { 
     137 
     138        function compress_framework_css() { 
     139            global $amp_conf; 
     140            $mainstyle_css      = $amp_conf['BRAND_CSS_ALT_MAINSTYLE']  
     141                            ? $amp_conf['BRAND_CSS_ALT_MAINSTYLE']  
     142                            : 'assets/css/mainstyle.css';  
     143            $wwwroot            = $amp_conf['AMPWEBROOT'] . "/admin"; 
     144            $mainstyle_css_gen  = $wwwroot . '/' . $amp_conf['mainstyle_css_generated']; 
     145            $mainstyle_css      = $wwwroot . '/' . $mainstyle_css; 
     146            $new_css            = file_get_contents($mainstyle_css)  
     147                            . file_get_contents($wwwroot . '/' . $amp_conf['JQUERY_CSS']); 
     148            $new_css            = CssMin::minify($new_css); 
     149            $new_md5            = md5($new_css); 
     150            $gen_md5            = file_exists($mainstyle_css_gen) ? md5(file_get_contents($mainstyle_css_gen)) : ''; 
     151 
     152     
     153            //regenerate if hashes dont match 
     154            if ($new_md5 != $gen_md5) { 
     155                $ms_path = dirname($mainstyle_css); 
     156 
     157                // it's important for filename tp unique  
     158                //because that will force browsers to reload vs. caching it 
     159                $mainstyle_css_generated = $ms_path.'/mstyle_autogen_' . time() . '.css'; 
     160                $ret = file_put_contents($mainstyle_css_generated, $new_css); 
     161 
     162                // Now assuming we write something reasonable, we need to save the generated file name and mtimes so 
     163                // next time through this ordeal, we see everything is setup and skip all of this. 
     164                //  
     165                // we skip this all this if we get back false or 0 (nothing written) in which case we will use the original 
     166                // We need to set the value in addition to defining the setting  
     167                //since if already defined the value won't be reset. 
     168                if ($ret) { 
     169                    $freepbx_conf =& freepbx_conf::create(); 
     170                    $val_update['mainstyle_css_generated'] = str_replace($wwwroot . '/', '', $mainstyle_css_generated); 
     171             
     172                    // Update the values (in case these are new) and commit 
     173                    $freepbx_conf->set_conf_values($val_update, true, true); 
     174 
     175 
     176                    // If it is a regular file (could have been first time and previous was blank then delete old 
     177                    if (is_file($mainstyle_css_gen) && !unlink($mainstyle_css_gen)) { 
     178                        freepbx_log(FPBX_LOG_WARNING, 
     179                                sprintf(_('failed to delete %s from assets/css directory after ' 
     180                                        . 'creating updated CSS file.'),  
     181                                        $mainstyle_css_generated_full_path)); 
     182                    } 
     183                } 
     184            } 
     185     
     186        } 
     187    } 
     188 
    136189  if ($amp_conf['DISABLE_CSS_AUTOGEN'] != true && function_exists('compress_framework_css')) {  
    137190    compress_framework_css();