forked from FriendsOfREDAXO/fa_iconpicker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
boot.php
74 lines (61 loc) · 3.38 KB
/
boot.php
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
<?php
// add perm for picker usage
rex_perm::register("fa_iconpicker[picker]", "Icon-Pickers: Nutzung des Widgets", rex_perm::GENERAL);
rex_perm::register("fa_iconpicker[settings]", "Icon-Picker: Einstellungen & Management der Pakete", rex_perm::GENERAL);
if (rex_addon::get('media_manager')->isAvailable()) {
rex_media_manager::addEffect(rex_effect_font_awesome_path::class);
rex_media_manager::addEffect(rex_effect_font_awesome_fontsrc_path::class);
}
// include current active set
if (rex::isBackend()) {
// push translation data for init function to use it
rex_extension::register('PAGE_HEADER', function($ep){
$file = rex_path::addon(rex_fa_package::PACKAGE)."lang".DIRECTORY_SEPARATOR.rex_i18n::getLocale().'.lang';
$faPickerTranslations = [];
if (($content = rex_file::get($file)) && preg_match_all('/^([^=\s]+)\h*=\h*(\S.*)(?<=\S)/m', $content, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
$faPickerTranslations[$match[1]] = $match[2];
}
} else {
return $ep->getSubject();
}
$subject = $ep->getSubject();
// ensure all config params are present
require_once rex_path::addon(rex_fa_package::PACKAGE)."/lib/rex.fa.settings.php";
$currentConfig = rex_addon::get(rex_fa_package::PACKAGE)->getConfig();
$config = [];
foreach($faIconPickerSettings as $key => $installValue) {
$config[$key] = (
isset($currentConfig["widget-".$key]) ?
(gettype($installValue) == "boolean" ?
(boolean)$currentConfig["widget-".$key] :
(gettype($installValue) == "integer" ? (int)$currentConfig["widget-".$key] : $currentConfig["widget-".$key])
) :
$installValue
);
}
$subject .= '
<!-- fa picker addon -->
<script type="text/javascript">
let FAPickerAddonI18N = '.json_encode($faPickerTranslations).';
let FAPickerSettings = '.json_encode($config).';
let FAPickerPackage = {
variant: "'. rex_fa_iconpicker::getActiveVariant() .'",
version: "'. rex_fa_iconpicker::getActiveVersion() .'",
subset: '.(rex_fa_iconpicker::getActiveSubset() === null ? 'null' : '"'. rex_fa_iconpicker::getActiveSubset() .'"').'
};
</script>
<script src="'.rex_url::addonAssets(rex_fa_package::PACKAGE, "js/fa-iconpicker.js").'?buster='. filemtime(rex_path::addonAssets(rex_fa_package::PACKAGE, "js/fa-iconpicker.js")). '"></script>
<!-- end fa picker addon -->
';
return $subject;
}, rex_extension::LATE, ['addon' => $this]);
rex_view::addJsFile($this->getAssetsUrl('js/vendor/dropzone-5.7.0/dist/min/dropzone.min.js'));
rex_view::addCssFile($this->getAssetsUrl('js/vendor/dropzone-5.7.0/dist/min/basic.min.css'));
rex_view::addCssFile($this->getAssetsUrl('js/vendor/dropzone-5.7.0/dist/min/dropzone.min.css'));
rex_view::addCssFile($this->getAssetsUrl('css/rex-fa-icons-backend.css'));
// add current package if existing
if(!is_null(rex_fa_iconpicker::getCssPath())) {
rex_view::addCssFile(rtrim(rex::getServer(), "/").'/index.php?rex_media_type='.rex_i18n::msg('fa_iconpicker_mm_name').'&rex_media_file='.rex_fa_iconpicker::getActiveCssFileName());
}
}