-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.php
337 lines (303 loc) · 10.6 KB
/
index.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
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
<?php
/**
* Front-end of Expandcontract_XH.
*
* @category CMSimple_XH Plugin
* @author svasti <[email protected]>
* @copyright 2014-16 by svasti < http://svasti.de >
* @copyright 2022 The CMSimple_XH Community < https://www.cmsimple-xh.org/ >
* @version 1.0 - 2022.03.31
*/
/**
* Prevent direct access.
*/
if (!defined('CMSIMPLE_XH_VERSION')) {
header('HTTP/1.0 403 Forbidden');
exit;
}
function expand()
{
global $s, $cl, $l, $cf, $h, $hjs, $c, $u, $plugin_cf, $plugin_tx, $pth, $bjs;
$ec_pcf = $plugin_cf['expandcontract'];
static $count = 1;
static $nested = false;
$uniqueId = '_ec' . $count;
if ($nested) return XH_message('warning', 'Nested calls of ExpandContract are not possible!'); //i18n
if ($s < 0) return;
$params = func_get_args();
$tmp_params = array();
foreach($params as $param) {
if (strpos($param, '=') !== false) {
list ($pKey, $pValue) = explode('=', $param, 2);
$pKey = str_replace('-', '', $pKey);
$pKey = ec_removeSpaces($pKey);
$pValue = ec_removeSpaces($pValue);
if ($pKey != '' && $pValue != '') {
$tmp_params[strtolower($pKey)] = $pValue;
}
}
}
if (array_key_exists('pages', $tmp_params)) {
$link = $tmp_params['pages'];
} else {
$link = false;
}
if (array_key_exists('headlines', $tmp_params)) {
$linktext = $tmp_params['headlines'];
} else {
$linktext = false;
}
$limitheight = false;
if (array_key_exists('maxheight', $tmp_params)) {
$tmp_params['maxheight'] = ec_lowercase('px|em|rem|vh|off',
$tmp_params['maxheight']);
if (ec_validateCSS($tmp_params['maxheight'])) {
$limitheight = $tmp_params['maxheight'];
}
}
if ($ec_pcf['expand-content_max-height'] != ''
&& $limitheight === false) {
$ec_pcf['expand-content_max-height'] = ec_lowercase('px|em|rem|vh|off',
$ec_pcf['expand-content_max-height']);
if (ec_validateCSS($ec_pcf['expand-content_max-height'])) {
$limitheight = $ec_pcf['expand-content_max-height'];
}
}
if ($limitheight == '0'
|| $limitheight == 'off') {
$limitheight = false;
}
$contentpadding = 0;
$temp = '';
if (array_key_exists('contentpadding', $tmp_params)) {
$temp = ec_removeSpaces($tmp_params['contentpadding']);
} elseif ($ec_pcf['expand-content_padding'] != '') {
$temp = trim($ec_pcf['expand-content_padding']);
}
if ($temp !== '') {
$temp = ec_lowercase('px|off', $temp);
if ($temp == '0'
|| $temp == 'off') {
$paddings[] = '0';
} else {
$t = preg_split('#\s+#u', $temp, -1, PREG_SPLIT_NO_EMPTY);
$paddings = array();
$fe_count = 0;
foreach ($t as $padding) {
$fe_count++;
if ($fe_count === 5) {
break;
}
if ($padding == '0') {
$paddings[] = $padding;
} else {
if (!ec_validateCSS($padding)) {
return XH_message('fail',
'There is an error in the definition of "Content-Padding"'); //i18n
}
$paddings[] = $padding;
}
}
if (count($t) !== count($paddings)) {
return XH_message('fail',
'There is an error in the definition of "Content-Padding"'); //i18n;
}
$contentpadding = implode(' ', $paddings);
}
}
$closebutton = ec_validateOnOff($tmp_params, 'showclose', 'expand-content_show_close_button');
$autoclose = ec_validateOnOff($tmp_params, 'autoclose', 'expand-content_auto_close');
$usebuttons = ec_validateOnOff($tmp_params, 'showinline', 'use_inline_buttons');
$firstopen = ec_validateOnOff($tmp_params, 'firstopen', 'expand-content_first_open');
$targetid = 'ecId' . $count;
// Fuer CMS-Suche alle Container geschlossen lassen
if (isset($_GET['search'])) {
$firstopen = $autoclose = false;
}
$options =
'data-autoclose="' . $autoclose . '" ' .
'data-firstopen="' . $firstopen . '"'
;
$o = $t = '';
$pageNrArray = array();
if ($link) {
if (strpos($link, ',')) {
$link = str_replace('\,', ',', $link);
$linklist = explode(',', $link);
foreach ($linklist as $singlelink) {
$singlelink = str_replace(',', ',', $singlelink);
$singlelink = ec_removeSpaces($singlelink);
if ($singlelink != '') {
$pageNr = array_search($singlelink, $h);
if ($pageNr === false) {
return XH_message('fail', 'Page "%s" not found!', $singlelink); //i18n
}
$pageNrArray[] = $pageNr;
}
}
} else {
$link = ec_removeSpaces($link);
$pageNr = array_search($link, $h);
if ($pageNr === false || $link == '' ) {
return XH_message('fail', 'Page "%s" not found!', $link); //i18n
}
$pageNrArray[] = $pageNr;
}
} else {
$tl = $l[$s] + 1 + $cf['menu']['levelcatch'];
for ($i = $s + 1; $i < $cl; $i++) {
if ($l[$i] <= $l[$s]) {
break;
}
if ($l[$i] <= $tl) {
if (hide($i)) {
$pageNrArray[] = $i;
}
}
if ($l[$i] < $tl) {
$tl = $l[$i];
}
}
}
if (count($pageNrArray) > 0) {
$link = false;
} else {
return XH_message('fail', 'No hidden pages found!'); //i18n
}
$headlineArray = array('headlines');
if ($linktext) {
if (strpos($linktext, ',')) {
$linktext = str_replace('\,', ',', $linktext);
$linktextlist = explode(',', $linktext);
foreach ($linktextlist as $singlelinktext) {
$singlelinktext = str_replace(',', ',', $singlelinktext);
$singlelinktext = ec_removeSpaces($singlelinktext);
if ($singlelinktext != '') {
$headlineArray[] = $singlelinktext;
}
}
} else {
$headlineArray[] = $linktext;
}
}
if (!$link) {
$o .= '<div class="expand_area" id="' . $targetid . '" '. $options .'>';
}
if ($usebuttons) {
$o .= '<div class="expand_linkArea">';
}
$i = 1;
foreach ($pageNrArray as $value) {
$js = '" class="linkBtn" id="deeplink'.$i.$uniqueId
.'" onclick="expandcontract(\'popup'
.$i.$uniqueId.'\'); return false;';
$expContent = str_replace('#CMSimple hide#', '', $c[$value]);
if ($usebuttons) {
$o .= '<form method="post" class="expand_button" action="?'
. $u[$value] . $js . '"><input type="submit" value="';
$o .= !empty($headlineArray[$i]) ? $headlineArray[$i] : $h[$value];
$o .= '"></form>';
} else {
if (!$link) {
$t .= '<p class="expand_link">';
}
$t .= a($value,$js);
$t .= !empty($headlineArray[$i]) ? $headlineArray[$i] : $h[$value];
$t .= '</a>';
if (!$link) {
$t .= '</p>';
}
}
$t .= '<div id="popup'.$i.$uniqueId.'" class="expand_content"'
. 'style="max-height: 0px;"><div class="expand_contentwrap"'
. ' style = "padding: ' . $contentpadding . '">';
$linkU = $_SERVER['REQUEST_URI'];
$t .= '<div class="deepLink"><a href="' . $linkU . '#popup'
. $i.$uniqueId . '">🔗</a></div>';
if ($limitheight) {
$t .= '<div style="height:' . $limitheight
. ';overflow-y:auto;padding-right:1em;">';
}
$t .= $expContent;
$t .= '<div style="clear:both"></div>';
if ($limitheight) {
$t .= '</div>';
}
if ($closebutton) {
$t .= '<div class="ecClose">'
. '<button class="ecCloseButton" type="button" '
. 'onclick="expandcontract(\'popup' . $i.$uniqueId . '\'); '
. 'return false;">' . $plugin_tx['expandcontract']['close']
. '</button>'
. '</div>';
}
$t .= '</div></div>';
$i++;
}
if ($usebuttons) {
$o .= '</div>';
}
if ($s >= 0) {
$nested = true;
$o .= evaluate_scripting($t);
$nested = false;
}
if (!$link) $o .= '</div>';
// JS & CSS nur einmal laden
if ($count === 1) {
$expandcontractStyles = $ec_pcf['use_stylesheet'];
if ($expandcontractStyles != '') {
$hjs .= '<link rel="stylesheet" href="' . $pth['folder']['plugins']
. 'expandcontract/css/'
. $expandcontractStyles . '" type="text/css">';
}
$jsFile = $pth['folder']['plugins'] . 'expandcontract/expandcontract.js';
$bjs .= '<script src="' . $jsFile . '"></script>';
}
$count++;
return $o;
}
function ec_validateOnOff($args = array(), $param = '', $default = '') {
global $plugin_cf;
$ec_pcf = $plugin_cf['expandcontract'];
if (!array_key_exists($param, $args)) {
return $ec_pcf[$default];
} else {
$args[$param] = ec_lowercase('on|off',$args[$param]);
}
switch ($args[$param]) {
case 'on':
return true;
case 'off':
return false;
default:
return $ec_pcf[$default];
}
}
// clean spaces at the beginning
// and at the end from $data
// from WYSIWYG-Mode
function ec_removeSpaces($data = '') {
return $data = preg_replace('/^\s+|\s+$/u', '', $data);
}
// Checks for valid CSS specifications, off or 0
// $data => string
function ec_validateCSS($data = '') {
$filter = '([\d]{1,4})(\.[\d]{1,4})?';
$units = 'px|em|rem|\%|vh';
if (preg_match('#(^' . $filter . '(' . $units . ')$|^(off)$|^(0)$)#uim', $data)) {
return true;
} else {
return false;
}
}
// change to lowercase
// $words => i.e. 'px|em|rem|vh|off'
// $data => string
function ec_lowercase($words = '', $data = '') {
$wordsArray = explode('|', $words);
foreach($wordsArray as $tmp) {
$data = str_ireplace($tmp, $tmp, $data);
}
return $data;
}