| | 94 | } |
|---|
| | 95 | |
|---|
| | 96 | function compress_framework_css() { |
|---|
| | 97 | global $amp_conf; |
|---|
| | 98 | $mainstyle_css = $amp_conf['BRAND_CSS_ALT_MAINSTYLE'] |
|---|
| | 99 | ? $amp_conf['BRAND_CSS_ALT_MAINSTYLE'] |
|---|
| | 100 | : 'assets/css/mainstyle.css'; |
|---|
| | 101 | $wwwroot = $amp_conf['AMPWEBROOT'] . "/admin"; |
|---|
| | 102 | $mainstyle_css_gen = $wwwroot . '/' . $amp_conf['mainstyle_css_generated']; |
|---|
| | 103 | $mainstyle_css = $wwwroot . '/' . $mainstyle_css; |
|---|
| | 104 | $new_css = file_get_contents($mainstyle_css) |
|---|
| | 105 | . file_get_contents($wwwroot . '/' . $amp_conf['JQUERY_CSS']); |
|---|
| | 106 | $new_css = CssMin::minify($new_css); |
|---|
| | 107 | $new_md5 = md5($new_css); |
|---|
| | 108 | $gen_md5 = file_exists($mainstyle_css_gen) ? md5(file_get_contents($mainstyle_css_gen)) : ''; |
|---|
| | 109 | |
|---|
| | 110 | |
|---|
| | 111 | //regenerate if hashes dont match |
|---|
| | 112 | if ($new_md5 != $gen_md5) { |
|---|
| | 113 | $ms_path = dirname($mainstyle_css); |
|---|
| | 114 | |
|---|
| | 115 | // it's important for filename tp unique |
|---|
| | 116 | //because that will force browsers to reload vs. caching it |
|---|
| | 117 | $mainstyle_css_generated = $ms_path.'/mstyle_autogen_' . time() . '.css'; |
|---|
| | 118 | $ret = file_put_contents($mainstyle_css_generated, $new_css); |
|---|
| | 119 | |
|---|
| | 120 | // Now assuming we write something reasonable, we need to save the generated file name and mtimes so |
|---|
| | 121 | // next time through this ordeal, we see everything is setup and skip all of this. |
|---|
| | 122 | // |
|---|
| | 123 | // we skip this all this if we get back false or 0 (nothing written) in which case we will use the original |
|---|
| | 124 | // We need to set the value in addition to defining the setting |
|---|
| | 125 | //since if already defined the value won't be reset. |
|---|
| | 126 | if ($ret) { |
|---|
| | 127 | $freepbx_conf =& freepbx_conf::create(); |
|---|
| | 128 | $val_update['mainstyle_css_generated'] = str_replace($wwwroot . '/', '', $mainstyle_css_generated); |
|---|
| | 129 | |
|---|
| | 130 | // Update the values (in case these are new) and commit |
|---|
| | 131 | $freepbx_conf->set_conf_values($val_update, true, true); |
|---|
| | 132 | |
|---|
| | 133 | |
|---|
| | 134 | // If it is a regular file (could have been first time and previous was blank then delete old |
|---|
| | 135 | if (is_file($mainstyle_css_gen) && !unlink($mainstyle_css_gen)) { |
|---|
| | 136 | freepbx_log(FPBX_LOG_WARNING, |
|---|
| | 137 | sprintf(_('failed to delete %s from assets/css directory after ' |
|---|
| | 138 | . 'creating updated CSS file.'), |
|---|
| | 139 | $mainstyle_css_generated_full_path)); |
|---|
| | 140 | } |
|---|
| | 141 | } |
|---|
| | 142 | } |
|---|
| | 143 | |
|---|