Add a way to include plugin stylesheets optionally only if the file exists

pull/6040/head
Aleksander Machniak 7 years ago
parent f3ce401def
commit 69f50b122d

@ -25,11 +25,7 @@ class archive extends rcube_plugin
if ($rcmail->task == 'mail' && ($rcmail->action == '' || $rcmail->action == 'show') if ($rcmail->task == 'mail' && ($rcmail->action == '' || $rcmail->action == 'show')
&& ($archive_folder = $rcmail->config->get('archive_mbox')) && ($archive_folder = $rcmail->config->get('archive_mbox'))
) { ) {
$skin_path = $this->local_skin_path(); $this->include_stylesheet($this->local_skin_path() . '/archive.css', true);
if (is_file($this->home . "/$skin_path/archive.css")) {
$this->include_stylesheet("$skin_path/archive.css");
}
$this->include_script('archive.js'); $this->include_script('archive.js');
$this->add_texts('localization', true); $this->add_texts('localization', true);
$this->add_button( $this->add_button(

@ -55,10 +55,7 @@ class help extends rcube_plugin
} }
// add style for taskbar button (must be here) and Help UI // add style for taskbar button (must be here) and Help UI
$skin_path = $this->local_skin_path(); $this->include_stylesheet($this->local_skin_path() . '/help.css', true);
if (is_file($this->home . "/$skin_path/help.css")) {
$this->include_stylesheet("$skin_path/help.css");
}
} }
function action() function action()

@ -21,14 +21,9 @@ class markasjunk extends rcube_plugin
$this->add_hook('storage_init', array($this, 'storage_init')); $this->add_hook('storage_init', array($this, 'storage_init'));
if ($rcmail->action == '' || $rcmail->action == 'show') { if ($rcmail->action == '' || $rcmail->action == 'show') {
$skin_path = $this->local_skin_path();
$this->add_texts('localization', true); $this->add_texts('localization', true);
$this->include_script('markasjunk.js'); $this->include_script('markasjunk.js');
$this->include_stylesheet($this->local_skin_path() . '/markasjunk.css', true);
if (is_file($this->home . "/$skin_path/markasjunk.css")) {
$this->include_stylesheet("$skin_path/markasjunk.css");
}
$this->add_button(array( $this->add_button(array(
'type' => 'link', 'type' => 'link',

@ -86,7 +86,7 @@ class zipdownload extends rcube_plugin
break; break;
} }
$this->include_stylesheet($this->local_skin_path() . '/zipdownload.css'); $this->include_stylesheet($this->local_skin_path() . '/zipdownload.css', true);
} }
return $p; return $p;

@ -355,10 +355,11 @@ abstract class rcube_plugin
* Make this stylesheet available on the client * Make this stylesheet available on the client
* *
* @param string $fn File path; absolute or relative to the plugin directory * @param string $fn File path; absolute or relative to the plugin directory
* @param bool $if_exists Include the file only if exists
*/ */
public function include_stylesheet($fn) public function include_stylesheet($fn, $if_exists = false)
{ {
$this->api->include_stylesheet($this->resource_url($fn)); $this->api->include_stylesheet($this->resource_url($fn), $if_exists);
} }
/** /**

@ -605,10 +605,20 @@ class rcube_plugin_api
* Include a plugin stylesheet in the current HTML page * Include a plugin stylesheet in the current HTML page
* *
* @param string $fn Path to stylesheet * @param string $fn Path to stylesheet
* @param bool $if_exists Include stylesheet only if the file exists
*/ */
public function include_stylesheet($fn) public function include_stylesheet($fn, $if_exists = false)
{ {
if (is_object($this->output) && $this->output->type == 'html') { 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);
if (!is_file("$path/$fn")) {
return;
}
}
$src = $this->resource_url($fn); $src = $this->resource_url($fn);
$this->output->include_css($src); $this->output->include_css($src);
} }

Loading…
Cancel
Save