Fix including assets that exist only in minified version

pull/6908/head
Aleksander Machniak 5 years ago
parent bdd1b2054f
commit 4096739322

@ -55,10 +55,10 @@ class jqueryui extends rcube_plugin
$lang_s = substr($_SESSION['language'], 0, 2);
foreach ($jquery_ui_i18n as $package) {
if (self::asset_exists("js/i18n/jquery.ui.$package-$lang_l.js")) {
if (self::asset_exists("js/i18n/jquery.ui.$package-$lang_l.js", false)) {
$this->include_script("js/i18n/jquery.ui.$package-$lang_l.js");
}
else if (self::asset_exists("js/i18n/jquery.ui.$package-$lang_s.js")) {
else if ($lang_s != 'en' && self::asset_exists("js/i18n/jquery.ui.$package-$lang_s.js", false)) {
$this->include_script("js/i18n/jquery.ui.$package-$lang_s.js");
}
}
@ -143,12 +143,10 @@ class jqueryui extends rcube_plugin
/**
* Checks if an asset file exists in specified location (with assets_dir support)
*/
protected static function asset_exists($path)
protected static function asset_exists($path, $minified = true)
{
$rcube = rcube::get_instance();
$assets_dir = $rcube->config->get('assets_dir');
$full_path = unslashify($assets_dir ?: INSTALL_PATH) . '/plugins/jqueryui/' . $path;
$rcube = rcube::get_instance();
return file_exists($full_path);
return $rcube->find_asset('/plugins/jqueryui/' . $path, $minified) !== null;
}
}

@ -1177,6 +1177,38 @@ class rcmail extends rcube
self::write_log('userlogins', $message);
}
/**
* 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
*
@ -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);
}
}

@ -32,7 +32,8 @@ class rcmail_html_page extends rcmail_output_html
self::reset(true);
// load embed.css from skin folder (if exists)
if ($embed_css = $this->get_skin_file($this->config->get('embed_css_location', '/embed.css'))) {
$embed_css = $this->config->get('embed_css_location', '/embed.css');
if ($embed_css = $this->get_skin_file($embed_css, $path, null, true)) {
$this->include_css($embed_css);
}
else { // set default styles for warning blocks inside the attachment part frame

@ -398,10 +398,11 @@ EOF;
* @param string $file File name/path to resolve (starting with /)
* @param string &$skin_path Reference to the base path of the matching skin
* @param string $add_path Additional path to search in
* @param bool $minified Fallback to a minified version of the file
*
* @return mixed Relative path to the requested file or False if not found
*/
public function get_skin_file($file, &$skin_path = null, $add_path = null)
public function get_skin_file($file, &$skin_path = null, $add_path = null, $minified = false)
{
$skin_paths = $this->skin_paths;
@ -414,6 +415,14 @@ EOF;
return $skin_path . $file;
}
if ($minified && preg_match('/(?<!\.min)\.(js|css)$/', $file)) {
$file = preg_replace('/\.(js|css)$/', '.min.\\1', $file);
if ($skin_path = $this->find_file_path($file, $skin_paths)) {
return $skin_path . $file;
}
}
return false;
}

Loading…
Cancel
Save