diff options
author | Aleksander Machniak <alec@alec.pl> | 2019-08-30 13:08:48 +0300 |
---|---|---|
committer | Aleksander Machniak <alec@alec.pl> | 2019-08-30 13:08:48 +0300 |
commit | 40967393226ba41e4e0cc4a1ce9022d3fcb99a3f (patch) | |
tree | fd602c507dc648903dd357df9bfdbec5433d3356 /program/include/rcmail.php | |
parent | bdd1b2054f4410fc8b7c3263467c25131c8b9659 (diff) |
Fix including assets that exist only in minified version
Diffstat (limited to 'program/include/rcmail.php')
-rw-r--r-- | program/include/rcmail.php | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/program/include/rcmail.php b/program/include/rcmail.php index e45917a6d..5980bf21f 100644 --- a/program/include/rcmail.php +++ b/program/include/rcmail.php @@ -1178,6 +1178,38 @@ class rcmail extends rcube } /** + * Check if specified asset file exists + * + * @param string $path Asset path + * @param bool $minified Fallback to minified version of the file + * + * @return string Asset path if found (modified if minified file found) + */ + public function find_asset($path, $minified = true) + { + if (empty($path)) { + return; + } + + $assets_dir = $this->config->get('assets_dir'); + $root_path = unslashify($assets_dir ?: INSTALL_PATH) . '/'; + $full_path = $root_path . trim($path, '/'); + + if (file_exists($full_path)) { + return $path; + } + + if ($minified && preg_match('/(?<!\.min)\.(js|css)$/', $path)) { + $path = preg_replace('/\.(js|css)$/', '.min.\\1', $path); + $full_path = $root_path . trim($path, '/'); + + if (file_exists($full_path)) { + return $path; + } + } + } + + /** * Create a HTML table based on the given data * * @param array $attrib Named table attributes @@ -2061,14 +2093,16 @@ class rcmail extends rcube ); if ($path = $this->config->get('editor_css_location')) { - $config['content_css'] = $skin_path . $path; + if ($path = $this->find_asset($skin_path . $path)) { + $config['content_css'] = $path; + } } $this->output->add_label('selectimage', 'addimage', 'selectmedia', 'addmedia'); $this->output->set_env('editor_config', $config); if ($path = $this->config->get('media_browser_css_location', 'program/resources/tinymce/browser.css')) { - if ($path != 'none') { + if ($path != 'none' && ($path = $this->find_asset($path))) { $this->output->include_css($path); } } |