-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinit.php
More file actions
367 lines (318 loc) · 10.4 KB
/
init.php
File metadata and controls
367 lines (318 loc) · 10.4 KB
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<?php
/**
* Editor Init Functions -- init.php
*
* PHP version 5
*
* @category CMSimple_XH
* @package Tinymce4
* @author The CMSimple_XH developers <devs@cmsimple-xh.org>
* @copyright 2009-2015 The CMSimple_XH developers <http://cmsimple-xh.org/?The_Team>
* @license http://www.gnu.org/licenses/gpl-3.0.en.html GNU GPLv3
* @link http://cmsimple-xh.org/
*/
/**
* defines admin mode
*/
if (!defined('XH_ADM')) {
define('XH_ADM', $adm);
}
/**
* Returns the JS to activate the configured filebrowser.
*
* @return string filebrowser script
*/
function tinymce4_filebrowser()
{
global $cf, $edit;
if (!XH_ADM) { // no filebrowser, if editor is called from front-end
$_SESSION['tinymce_fb_callback'] = ''; // suppress filebrowsercall
return '';
}
$url = '';
$script = ''; //holds the code of the callback-function
/**
* Einbindung alternativer Filebrowser, gesteuert über
* $cf['filebrowser']['external'] und den Namen des aufrufenden Editors.
*/
if ($cf['filebrowser']['external'] != false) {
$fbConnector = CMSIMPLE_BASE . 'plugins/' .
$cf['filebrowser']['external'] .
'/connectors/tinymce4/tinymce4.php';
if (is_readable($fbConnector)) {
include_once $fbConnector;
$init_function = $cf['filebrowser']['external'] . '_tinymce4_init';
if (function_exists($init_function)) {
$script = $init_function();
return $script;
}
}
}
//default filebrowser
$_SESSION['tinymce_fb_callback'] = 'wrFilebrowser';
//principle occurance of XH_VERSION is checked in index.php
if (CMSIMPLE_XH_VERSION != '@CMSIMPLE_XH_VERSION@'
&& version_compare(CMSIMPLE_XH_VERSION, 'CMSimple_XH 1.7', 'lt')
) {
$url = CMSIMPLE_ROOT .
'plugins/filebrowser/editorbrowser.php?editor=tinymce4&prefix=' .
CMSIMPLE_BASE .
'&base=./';
} else { // CMSimple_XH v1.7 (r1518)
$url = CMSIMPLE_ROOT .
'?filebrowser=editorbrowser&editor=tinymce4&prefix=' .
CMSIMPLE_BASE;
}
$script = file_get_contents(dirname(__FILE__) . '/filebrowser.js');
$script = str_replace('%URL%', $url, $script);
return $script;
}
/**
* Writes the basic JS of the editor to $hjs. No editors are actually created.
* Multiple calls are allowed; all but the first should be ignored.
* This is called from init_EDITOR() automatically, but not from EDITOR_replace().
*
* @global string $hjs
* @return void
*/
function include_tinymce4()
{
global $edit, $pth, $h, $u, $l, $hjs, $plugin_cf;
$pcf = $plugin_cf['tinymce4'];
static $again = false;
if ($again) {
return;
}
$again = true;
if ($pcf['CDN'] == true) { //CDN Version
//do not use defaultconfig, leave the chance to update the std CDN_src
$tiny_src = empty($pcf['CDN_alt_src']) ? TINYMCE4_CDN_ORIG : $pcf['CDN_alt_src'];
} else {
$tiny_src = $pth['folder']['plugins'] .
'tinymce4/' .
'tinymce/tinymce.min.js';
}
if (XH_ADM) {
include_once $pth['folder']['plugins'] . 'tinymce4/' . 'links.php';
$imageList = 'myImageList = ' .
get_images($pth['folder']['images']) .
';';
$linkList = 'var myLinkList = ' .
get_internal_links($h, $u, $l, $pth['folder']['downloads']) .
';';
} else {
$imageList = $linkList = '';
}
$hjs .='
<script language="javascript" type="text/javascript" src="'.
$tiny_src.
'"></script>
<script type="text/javascript">
' . tinymce4_filebrowser() . '
var myImageList;
' . $imageList . '
var myLinkList;
' . $linkList . '
</script>
<style type="text/css">
div.mce-fullscreen {z-index: 999;} /*fullscreen overlays admin toolbar */
</style>
';
}
/**
* Returns the config object.
*
* @param string $config manual config string.
* @param string $selector manual manual editor DOM node.
*
* @return string editor config
*/
function tinymce4_config($config, $selector)
{
global $cl, $pth, $sl, $cf, $plugin_cf, $plugin_tx, $s;
$pcf = $plugin_cf['tinymce4'];
$ptx = $plugin_tx['tinymce4'];
$pluginName = basename(dirname(__FILE__), "/");
$pluginPth = $pth['folder']['plugins'] . $pluginName . '/';
if (!isset($pcf)) {
include_once $pluginPth . 'config/config.php';
}
$tiny_mode
= isset($pcf['init'])
&& file_exists($pluginPth . 'inits/init_' . $pcf['init'] . '.js') ?
$pcf['init'] :
'full';
$initFile = $pluginPth . 'inits/init_' . $tiny_mode . '.js';
if ($config) {
$initFile = false;
$inits = glob($pluginPth.'inits/*.js');
foreach ($inits as $init) {
$temp = explode('_', basename($init, '.js'));
if (isset($temp[1]) && $temp[1] === $config) {
$tiny_mode = $config;
$initFile = $pluginPth . 'inits/init_' . $tiny_mode . '.js';
break;
}
}
}
if ($initFile) {
$temp = file_get_contents($initFile);
} else {
$temp = $config;
}
/*
* use english if tiny doesn't know $sl resp. $cf['default']['language']
*/
if (file_exists($pluginPth . 'tinymce/langs/' . $sl . '.js')) {
$tiny_language = $sl;
} elseif (file_exists(
$pluginPth . 'tinymce/langs/' .
$cf['language']['default'] . '.js'
)) {
$tiny_language = $cf['language']['default'];
} else {
$tiny_language = 'en';
}
/*
* The styles of this sheet will be used inside the editor.
*
* All css classes will be available in the style-selectbox.
*
* If you have a lot of classes that are of no use for text editing,
* you might want to create a special editor.css.
*/
$temp = str_replace(
'%STYLESHEET%', $pth['folder']['template'] .
'stylesheet.css', $temp
);
/* %LANGUAGE% = language:"[lang]" and language_url = path to
* tinymce language file(in regard to the TinyMCE CDN Variant)
* if lang other than en
*/
$temp = str_replace(
'%LANGUAGE%', 'language: "' . $tiny_language .'",'
. ($tiny_language !='en' && $pcf['CDN'] == true ?
'
language_url: "' .
CMSIMPLE_ROOT.'plugins/tinymce4/tinymce/langs/' .
$tiny_language.'.js",' : ''), $temp
);
/*
* compute CMSIMPLEROOT faciliates usage of init_fontawesome.js
*/
$temp = str_replace(
'%CMSIMPLE_ROOT%', CMSIMPLE_ROOT, $temp
);
$elementFormat = $cf['xhtml']['endtags'] == 'true' ? 'xhtml' : 'html';
$temp = str_replace('%ELEMENT_FORMAT%', $elementFormat, $temp);
$_named_pageheaders = $_pageheaders = $_headers = array();
for ( $i = 1; $i <= 6; $i++ ) {
$_pageheaders [] = "Header $i=h$i";
$_named_pageheaders [] = sprintf($ptx['pageheader'], $i) . "=h$i";
$_headers[] = "Header $i=h$i";
};
$temp = str_replace('%PAGEHEADERS%', implode(';', $_pageheaders), $temp);
$temp = str_replace('%HEADERS%', implode(';', $_headers), $temp);
$temp = str_replace(
'%NAMED_PAGEHEADERS%',
implode(
';',
($s >= 0 && $s < $cl) ?
$_named_pageheaders :
$_pageheaders
), $temp
);
$temp = str_replace('%SELECTOR%', $selector, $temp);
$temp = str_replace(
'"%FILEBROWSER_CALLBACK%"',
XH_ADM ?
$_SESSION['tinymce_fb_callback'] :
'""',
$temp
);
return $temp;
}
/**
* Returns the JS to actually instantiate a single editor on the textarea
* given by $element_id. $config can be 'full', 'medium', 'minimal', 'sidebar'
* or '' (which will use the users default configuration). Other values are editor
* dependent. Typically this will be a string in JSON format enclosed in { },
* that can contain %PLACEHOLDER%s, that will be substituted.
*
* To actually create the editor, the caller has to write the the return value
* to the (X)HTML output, properly enclosed as <script>, after the according
* <textarea>, or execute the return value by other means.
*
* @param string $elementID The id of the textarea that should become an
* editor instance.
* @param string $config The configuration string.
*
* @return string The JS to actually create the editor.
*/
function tinymce4_replace($elementID = false, $config = '')
{
if (!$elementID) {
return '';
}
$config = tinymce4_config($config, '#' . $elementID);
return _setInit($config);
}
/**
* Instantiates the editor(s) on the textarea(s) given by $element_classes.
* $config is exactly the same as for EDITOR_replace().
*
* @param string $classes The element classes of the textarea(s) that should
* become an editor instance.
* An empty array means .xh-editor.
* @param string $config The configuration string.
*
* @return void
*/
function init_tinymce4($classes = array(), $config = false)
{
global $hjs;
include_tinymce4();
$initClasses = '.xh-editor';
if (is_array($classes) && (bool) $classes) {
$initClasses = '.' . implode(',.', $classes);
}
$temp = tinymce4_config($config, $initClasses);
$hjs .= '
<script language="javascript" type="text/javascript">
' . _setInit($temp) . '
</script>
';
return;
}
/**
* Helper sequence to set the init JS string correctly.
*
* @param string $config The configuration string.
*
* @return string the whole editor js string
*/
function _setInit($config)
{
static $run = 0;
$js = str_replace(
'tinyArgs', 'tinyArgs'.$run, '
if (typeof(tinymce) === "undefined" || tinymce === null) {
alert("tinyMCE not present! Either offline or local library missing.")
} else {
var tinyArgs = ' . $config . ';
if (myImageList && myImageList.length > 0 )
tinyArgs.image_list = myImageList;
else
delete tinyArgs.image_list;
if (myLinkList)
tinyArgs.link_list = myLinkList;
tinymce.init(tinyArgs);
}
'
);
$run++;
return $js;
}
/*
* End of file plugins/tinymce4/init.php
*/