forked from FriendsOfREDAXO/redactor2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboot.php
146 lines (124 loc) · 5.42 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
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
<?php
if (rex::isBackend() && !empty(rex::getUser())) {
rex_view::addCssFile($this->getAssetsUrl('redactor.css'));
rex_view::addCssFile($this->getAssetsUrl('redactor_custom.css'));
if (file_exists($this->getAssetsPath('skin.css'))) {
rex_view::addCssFile($this->getAssetsUrl('skin.css'));
}
rex_view::addJsFile($this->getAssetsUrl('redactor.js'));
rex_view::addJsFile($this->getAssetsUrl('redactor_plugins.min.js'));
$redactorLanguage = rex::getProperty('lang');
$contentLanguage = rex_clang::getCurrent();
$redactorLanguage = substr($redactorLanguage, 0, 2);
rex_view::addJsFile($this->getAssetsUrl('langs/'.$redactorLanguage.'.js'));
//Start - get redactor-profiles
$sql = rex_sql::factory();
$profiles = $sql->setQuery("SELECT * FROM `".rex::getTablePrefix()."redactor2_profiles` ORDER BY `name` ASC")->getArray();
unset($sql);
$jsCode = [];
$jsCode[] = 'var redactorSetup = false;';
$jsCode[] = 'function redactorInit() {';
$jsCode[] = 'var Editor = null;';
foreach ($profiles as $profile) {
$jsCode[] = 'var Editor = $(\'.redactorEditor2-'.$profile['name'].'\');';
$redactorConfig = [];
$jsCode[] = 'if (redactorSetup == true && Editor.parent().is(\'.redactor-box\')) {';
$jsCode[] = ' Editor.each(function() {';
$jsCode[] = ' $(this).insertBefore($(this).parent()).next().remove();';
$jsCode[] = ' });';
$jsCode[] = '}';
$jsCode[] = 'Editor.redactor({';
$jsCode[] = ' callbacks: {';
$jsCode[] = ' init: function() {';
$jsCode[] = ' redactorSetup = true;';
$jsCode[] = ' }';
$jsCode[] = ' },';
$jsCode[] = ' linkSize: 1000,';
$jsCode[] = ' imageCaption: false,';
$jsCode[] = ' linkify: '.(($profile['linkify']) ? 'true' : 'false').',';
$jsCode[] = ' lang: \''.$redactorLanguage.'\',';
$jsCode[] = ' minHeight: '.$profile['minheight'].',';
$jsCode[] = ' maxHeight: '.$profile['maxheight'].',';
$jsCode[] = ' urltype: \''.$profile['urltype'].'\',';
$jsCode[] = ' toolbarFixed: '.(($profile['toolbarfixed']) ? 'true' : 'false').',';
$jsCode[] = ' shortcutsAdd: '.(($profile['shortcuts']) ? 'true' : 'false').',';
$jsCode[] = ' imageTag: \'\',';
if ($profile['characterlimit'] != 0) {
$jsCode[] = ' limiter: '.$profile['characterlimit'].',';
}
//Start - get pluginconfiguration
$redactorPlugins = [];
if (trim($profile['redactor_plugins']) != '') {
$plugins = explode(',', $profile['redactor_plugins']);
foreach ($plugins as $plugin) {
$plugin = trim($plugin);
if (preg_match('/(.*)\[(.*)\]/', $plugin, $matches)) {
//Start - explode parameters
$parameters = explode('|', $matches[2]);
$parameterString = '';
foreach ($parameters as $parameter) {
if (strpos($parameter, '=') !== false) {
list($key, $value) = explode('=',$parameter,2);
$parameterString .= "['".addslashes($key)."', '".addslashes($value)."'],";
} else {
$parameterString .= "'".$parameter."',";
}
}
$redactorConfig[] = $matches[1].': ['.$parameterString.'],';
//End - explode parameters
$redactorPlugins[] = $matches[1];
} else {
$redactorPlugins[] = $plugin;
}
}
}
//End - get pluginconfiguration
//Start - get pluginconfiguration for custom plugins
if (trim($profile['redactor_customplugins']) != '') {
$plugins = explode(',', $profile['redactor_customplugins']);
foreach ($plugins as $plugin) {
list($pluginName, $pluginPath) = explode(':', $plugin);
$plugin = trim($pluginName);
if (!in_array(rex_url::assets($pluginPath), rex_view::getJsFiles())) {
rex_view::addJsFile(rex_url::assets($pluginPath));
}
if (preg_match('/(.*)\[(.*)\]/', $plugin, $matches)) {
//Start - explode parameters
$parameters = explode('|', $matches[2]);
$parameterString = '';
foreach ($parameters as $parameter) {
if (strpos($parameter, '=') !== false) {
list($key, $value) = explode('=',$parameter,2);
$parameterString .= "['".addslashes($key)."', '".addslashes($value)."'],";
} else {
$parameterString .= "'".$parameter."',";
}
}
$redactorConfig[] = $matches[1].': ['.$parameterString.'],';
$redactorPlugins[] = $matches[1];
//End - explode parameters
} else {
$redactorPlugins[] = $pluginName;
}
}
}
//End - get pluginconfiguration for custom plugins
$jsCode[] = 'clang_id: '. $contentLanguage->getId() .',';
$jsCode[] = 'buttons: [],';
$jsCode[] = 'plugins: [\'limiter\',\''.implode('\',\'', $redactorPlugins).'\'],';
$jsCode[] = implode(PHP_EOL, $redactorConfig);
$jsCode[] = '});';
}
$jsCode[] = '}';
$jsCode[] = '$(document).on(\'ready pjax:success\',function() {';
$jsCode[] = ' redactorInit();';
$jsCode[] = '});';
$jsCode[] = '$(document).on(\'be_table:row-added\',function() {';
$jsCode[] = ' redactorInit();';
$jsCode[] = '});';
if (!rex_file::put($this->getAssetsPath('cache/redactor2_profiles.js').'', implode(PHP_EOL, $jsCode))) {
echo 'js-file konnte nicht gespeichert werden';
}
rex_view::addJsFile($this->getAssetsUrl('cache/redactor2_profiles.js'));
//End - get redactor-profiles
}