From 1cf72fa2b69f4788320e96be6d446b76179ca9a3 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Mon, 20 Nov 2017 13:48:07 +0100 Subject: [PATCH] Allow plugins to include Less files (#6051) --- program/include/rcmail_output_html.php | 9 +++++++-- program/lib/Roundcube/rcube_plugin_api.php | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/program/include/rcmail_output_html.php b/program/include/rcmail_output_html.php index 19bfe175c..c7cf011db 100644 --- a/program/include/rcmail_output_html.php +++ b/program/include/rcmail_output_html.php @@ -1716,8 +1716,13 @@ EOF; ) { $css = ''; foreach ($this->css_files as $file) { - $css .= html::tag('link', array('rel' => 'stylesheet', - 'type' => 'text/css', 'href' => $file, 'nl' => true)); + $is_less = substr_compare($file, '.less', -5, 5, true) === 0; + $css .= html::tag('link', array( + 'rel' => $is_less ? 'stylesheet/less' : 'stylesheet', + 'type' => 'text/css', + 'href' => $file, + 'nl' => true, + )); } $output = substr_replace($output, $css, $pos, 0); } diff --git a/program/lib/Roundcube/rcube_plugin_api.php b/program/lib/Roundcube/rcube_plugin_api.php index a20493799..89a6ad430 100644 --- a/program/lib/Roundcube/rcube_plugin_api.php +++ b/program/lib/Roundcube/rcube_plugin_api.php @@ -611,8 +611,18 @@ class rcube_plugin_api { if (is_object($this->output) && $this->output->type == 'html') { if ($if_exists && $fn[0] != '/' && !preg_match('|^https?://|i', $fn)) { - $rcube = rcube::get_instance(); - $path = unslashify($rcube->config->get('assets_dir') ?: RCUBE_INSTALL_PATH); + $rcube = rcube::get_instance(); + $devel_mode = $rcube->config->get('devel_mode'); + $assets_dir = $rcube->config->get('assets_dir'); + $path = unslashify($assets_dir ?: RCUBE_INSTALL_PATH); + + // Prefer .less files in devel_mode (assume less.js is loaded) + if ($devel_mode) { + $less = preg_replace('/\.css$/i', '.less', $fn); + if ($less != $fn && is_file("$path/plugins/$less")) { + $fn = $less; + } + } if (!is_file("$path/plugins/$fn")) { return;