1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
<?php
/**
* jQuery UI
*
* Provide the jQuery UI library with according themes.
*
* @version 1.13.2
* @author Cor Bosman <roundcube@wa.ter.net>
* @author Thomas Bruederli <roundcube@gmail.com>
* @author Aleksander Machniak <alec@alec.pl>
* @license GNU GPLv3+
*/
class jqueryui extends rcube_plugin
{
public $noajax = true;
public $version = '1.13.2';
private static $features = [];
private static $ui_theme;
private static $css_path;
private static $skin_map = [
'larry' => 'larry',
'default' => 'elastic',
];
/**
* Plugin initialization
*/
public function init()
{
$rcmail = rcmail::get_instance();
// the plugin might have been force-loaded so do some sanity check first
if ($rcmail->output->type != 'html' || self::$ui_theme) {
return;
}
$this->load_config();
// include UI scripts
$this->include_script("js/jquery-ui.min.js");
$this->include_script("js/jquery-ui-accessible-datepicker.min.js");
// include UI stylesheet
$skin = $rcmail->config->get('skin');
$ui_map = $rcmail->config->get('jquery_ui_skin_map', self::$skin_map);
$skins = array_keys($rcmail->output->skins);
$skins[] = 'elastic';
foreach ($skins as $skin) {
self::$ui_theme = !empty($ui_map[$skin]) ? $ui_map[$skin] : $skin;
self::$css_path = $this->local_skin_path('themes', self::$ui_theme);
$css = self::$css_path . '/jquery-ui.css';
if (self::asset_exists($css)) {
$this->include_stylesheet($css);
break;
}
}
// jquery UI localization
$jquery_ui_i18n = $rcmail->config->get('jquery_ui_i18n', ['datepicker']);
if (count($jquery_ui_i18n) > 0) {
$lang_l = str_replace('_', '-', substr($_SESSION['language'], 0, 5));
$lang_s = substr($_SESSION['language'], 0, 2);
foreach ($jquery_ui_i18n as $package) {
if (self::asset_exists("js/i18n/$package-$lang_l.min.js", false)) {
$this->include_script("js/i18n/$package-$lang_l.min.js");
}
else if ($lang_s != 'en' && self::asset_exists("js/i18n/$package-$lang_s.min.js", false)) {
$this->include_script("js/i18n/$package-$lang_s.min.js");
}
}
}
// Date format for datepicker
$date_format = $date_format_localized = $rcmail->config->get('date_format', 'Y-m-d');
$date_format = strtr($date_format, [
'y' => 'y',
'Y' => 'yy',
'm' => 'mm',
'n' => 'm',
'd' => 'dd',
'j' => 'd',
]);
$replaces = ['Y' => 'yyyy', 'y' => 'yy', 'm' => 'mm', 'd' => 'dd', 'j' => 'd', 'n' => 'm'];
foreach (array_keys($replaces) as $key) {
if ($rcmail->text_exists("dateformat$key")) {
$replaces[$key] = $rcmail->gettext("dateformat$key");
}
}
$date_format_localized = strtr($date_format_localized, $replaces);
$rcmail->output->set_env('date_format', $date_format);
$rcmail->output->set_env('date_format_localized', $date_format_localized);
}
/**
* Initialize and include miniColors widget
*/
public static function miniColors()
{
if (in_array('miniColors', self::$features)) {
return;
}
self::$features[] = 'miniColors';
$rcube = rcube::get_instance();
$script = 'plugins/jqueryui/js/jquery.minicolors.min.js';
$css = self::$css_path . "/jquery.minicolors.css";
$colors_theme = $rcube->config->get('jquery_ui_colors_theme', 'default');
$config = ['theme' => $colors_theme];
$config_str = rcube_output::json_serialize($config);
$rcube->output->include_css('plugins/jqueryui/' . $css);
$rcube->output->include_script($script, 'head', false);
$rcube->output->add_script('$.fn.miniColors = $.fn.minicolors; $("input.colors").minicolors(' . $config_str . ')', 'docready');
$rcube->output->set_env('minicolors_config', $config);
}
/**
* Initialize and include tagedit widget
*/
public static function tagedit()
{
if (in_array('tagedit', self::$features)) {
return;
}
self::$features[] = 'tagedit';
$script = 'plugins/jqueryui/js/jquery.tagedit.js';
$rcube = rcube::get_instance();
$css = self::$css_path . "/tagedit.css";
if (!array_key_exists('elastic', (array) $rcube->output->skins)) {
$rcube->output->include_css('plugins/jqueryui/' . $css);
}
$rcube->output->include_script($script, 'head', false);
}
/**
* Checks if an asset file exists in specified location (with assets_dir support)
*/
protected static function asset_exists($path, $minified = true)
{
$rcube = rcube::get_instance();
$path = (strpos($path, 'plugins/') !== false ? '/' : '/plugins/jqueryui/') . $path;
return $rcube->find_asset($path, $minified) !== null;
}
}
|