Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/fluentform/boot/globals.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
3
+
use FluentForm\Framework\Helpers\ArrayHelper;
4
+
use FluentForm\App\Modules\Component\BaseComponent;
5
+
use FluentForm\App\Services\FormBuilder\EditorShortCode;
6
+
7
+
/**
8
+
***** DO NOT CALL ANY FUNCTIONS DIRECTLY FROM THIS FILE ******
9
+
*
10
+
* This file will be loaded even before the framework is loaded
11
+
* so the $app is not available here, only declare functions here.
12
+
*/
13
+
14
+
//if ('dev' == $app->config->get('app.env')) {
15
+
// $globalsDevFile = __DIR__ . '/globals_dev.php';
16
+
//
17
+
// is_readable($globalsDevFile) && include $globalsDevFile;
18
+
//}
19
+
20
+
if (!function_exists('dd')) {
21
+
// function dd()
22
+
// {
23
+
// foreach (func_get_args() as $arg) {
24
+
// echo '<pre>';
25
+
// print_r($arg); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $value is only used for debugging in development.
26
+
// echo '</pre>';
27
+
// }
28
+
// exit();
29
+
// }
30
+
}
31
+
32
+
/**
33
+
* Get fluentform instance or other core modules
34
+
*
35
+
* @param string $key
36
+
*
37
+
* @return mixed
38
+
*/
39
+
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Global helper function, part of plugin API
40
+
function wpFluentForm($key = null)
41
+
{
42
+
return \FluentForm\App\App::make($key);
43
+
}
44
+
45
+
/**
46
+
* Generate URL for static assets
47
+
*
48
+
* @param string $path
49
+
*
50
+
* @return string
51
+
*/
52
+
function fluentFormMix($path = '')
53
+
{
54
+
return wpFluentForm('url.assets') . ltrim($path, '/');
55
+
}
56
+
57
+
if (! function_exists('wpFluent')) {
58
+
/**
59
+
* @return \FluentForm\Framework\Database\Query\Builder|\FluentForm\Framework\Database\Query\WPDBConnection
60
+
*/
61
+
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Global helper function, part of plugin API
62
+
function wpFluent()
63
+
{
64
+
return wpFluentForm('db');
65
+
}
66
+
}
67
+
68
+
69
+
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Global helper function, part of plugin API
70
+
function wpFluentFormAddComponent(BaseComponent $component)
71
+
{
72
+
return $component->_init();
73
+
}
74
+
75
+
/**
76
+
* Sanitize form inputs recursively.
77
+
*
78
+
* @param $input
79
+
*
80
+
* @return mixed $input
81
+
*/
82
+
function fluentFormSanitizer($input, $attribute = null, $fields = [])
83
+
{
84
+
if (is_string($input)) {
85
+
$element = ArrayHelper::get($fields, $attribute . '.element');
86
+
87
+
if (in_array($element, ['post_content', 'rich_text_input'])) {
88
+
return wp_kses_post($input);
89
+
} elseif ('textarea' === $element) {
90
+
$input = sanitize_textarea_field($input);
91
+
} elseif ('input_email' === $element) {
92
+
$input = strtolower(sanitize_text_field($input));
93
+
} elseif ('input_url' === $element) {
94
+
$input = sanitize_url($input);
95
+
} elseif ('input_password' === $element) {
96
+
$input = trim($input);
97
+
} else {
98
+
$input = sanitize_text_field($input);
99
+
}
100
+
} elseif (is_array($input)) {
101
+
$sanitizedInput = [];
102
+
103
+
foreach ($input as $key => &$value) {
104
+
$key = fluentFormSanitizer($key);
105
+
$attribute = $attribute ? $attribute . '[' . $key . ']' : $key;
106
+
107
+
$value = fluentFormSanitizer($value, $attribute, $fields);
108
+
$attribute = null;
109
+
$sanitizedInput[$key] = $value;
110
+
}
111
+
112
+
$input = $sanitizedInput;
113
+
}
114
+
115
+
return $input;
116
+
}
117
+
118
+
function fluentFormEditorShortCodes()
119
+
{
120
+
$generalShortCodes = [EditorShortCode::getGeneralShortCodes()];
121
+
/* This filter is deprecated, will be removed soon. */
122
+
$generalShortCodes = apply_filters('fluentform_editor_shortcodes', $generalShortCodes);
123
+
124
+
return apply_filters('fluentform/editor_shortcodes', $generalShortCodes);
125
+
}
126
+
127
+
function fluentFormGetAllEditorShortCodes($form)
128
+
{
129
+
$editorShortCodes = EditorShortCode::getShortCodes($form);
130
+
/* This filter is deprecated and will be removed soon */
131
+
$editorShortCodes = apply_filters(
132
+
'fluentform_all_editor_shortcodes',
133
+
$editorShortCodes,
134
+
$form
135
+
);
136
+
return apply_filters(
137
+
'fluentform/all_editor_shortcodes',
138
+
$editorShortCodes,
139
+
$form
140
+
);
141
+
}
142
+
143
+
/**
144
+
* Recursively implode a multi-dimentional array
145
+
*
146
+
* @param string $glue
147
+
* @param array $array
148
+
*
149
+
* @return string
150
+
*/
151
+
function fluentImplodeRecursive($glue, array $array)
152
+
{
153
+
$fn = function ($glue, array $array) use (&$fn) {
154
+
$result = '';
155
+
foreach ($array as $item) {
156
+
if (is_array($item)) {
157
+
$result .= $fn($glue, $item);
158
+
} else {
159
+
$result .= $glue . $item;
160
+
}
161
+
}
162
+
163
+
return $result;
164
+
};
165
+
166
+
return ltrim($fn($glue, $array), $glue);
167
+
}
168
+
169
+
function fluentform_get_active_theme_slug()
170
+
{
171
+
$ins = get_option('_ff_ins_by');
172
+
173
+
if ($ins) {
174
+
return sanitize_text_field($ins);
175
+
}
176
+
177
+
if (defined('TEMPLATELY_FILE')) {
178
+
return 'templately';
179
+
}
180
+
181
+
return get_option('template');
182
+
}
183
+
184
+
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Global helper function, part of plugin API
185
+
function getFluentFormCountryList()
186
+
{
187
+
static $countries = null;
188
+
189
+
if (is_null($countries)) {
190
+
$countries = fluentformLoadFile('/Services/FormBuilder/CountryNames.php');
191
+
}
192
+
193
+
return $countries;
194
+
}
195
+
196
+
function fluentFormWasSubmitted($action = 'fluentform_submit')
197
+
{
198
+
return wpFluentForm('request')->get('action') == $action;
199
+
}
200
+
201
+
if (!function_exists('isWpAsyncRequest')) {
202
+
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Global helper function, part of plugin API
203
+
function isWpAsyncRequest($action)
204
+
{
205
+
return false !== strpos(wpFluentForm('request')->get('action'), $action);
206
+
}
207
+
}
208
+
209
+
function fluentFormIsHandlingSubmission()
210
+
{
211
+
$status = fluentFormWasSubmitted() || isWpAsyncRequest('fluentform_async_request');
212
+
213
+
$status = apply_filters_deprecated(
214
+
'fluentform_is_handling_submission',
215
+
[
216
+
$status
217
+
],
218
+
FLUENTFORM_FRAMEWORK_UPGRADE,
219
+
'fluentform/is_handling_submission',
220
+
'Use fluentform/is_handling_submission instead of fluentform_is_handling_submission'
221
+
);
222
+
return apply_filters('fluentform/is_handling_submission', $status);
223
+
}
224
+
225
+
function fluentform_mb_strpos($haystack, $needle)
226
+
{
227
+
if (function_exists('mb_strpos')) {
228
+
return mb_strpos($haystack, $needle);
229
+
}
230
+
231
+
return strpos($haystack, $needle);
232
+
}
233
+
234
+
function fluentFormHandleScheduledTasks()
235
+
{
236
+
$failedActions = wpFluent()->table('ff_scheduled_actions')->where('status', 'failed')->where('retry_count', '<', 4)->get();
237
+
238
+
if ($failedActions) {
239
+
$scheduler = wpFluentForm('fluentFormAsyncRequest');
240
+
241
+
foreach ($failedActions as $action) {
242
+
$scheduler->process($action);
243
+
}
244
+
}
245
+
246
+
$rand = wp_rand(1, 10);
247
+
if ($rand >= 5) {
248
+
do_action('fluentform/maybe_scheduled_jobs');
249
+
}
250
+
}
251
+
252
+
function fluentFormHandleScheduledEmailReport()
253
+
{
254
+
\FluentForm\App\Services\Scheduler\Scheduler::processEmailReport();
255
+
}
256
+
257
+
function fluentform_upgrade_url()
258
+
{
259
+
return 'https://fluentforms.com/pricing/?utm_source=plugin&utm_medium=wp_install&utm_campaign=ff_upgrade&theme_style=' . fluentform_get_active_theme_slug();
260
+
}
261
+
262
+
function fluentform_integrations_url()
263
+
{
264
+
return 'https://fluentforms.com/integration/?utm_source=plugin&utm_medium=wp_install&utm_campaign=ff_upgrade&theme_style=' . fluentform_get_active_theme_slug();
265
+
}
266
+
267
+
function fluentFormApi($module = 'forms')
268
+
{
269
+
if ('forms' == $module) {
270
+
return new \FluentForm\App\Api\Form();
271
+
} elseif ('submissions' == $module) {
272
+
return new \FluentForm\App\Api\Submission();
273
+
}
274
+
275
+
throw new \Exception(esc_html('No Module found with name ' . $module));
276
+
}
277
+
278
+
function fluentFormGetRandomPhoto()
279
+
{
280
+
$photos = [
281
+
'demo_1.jpg',
282
+
'demo_2.jpg',
283
+
'demo_3.jpg',
284
+
'demo_4.jpg',
285
+
'demo_5.jpg',
286
+
];
287
+
288
+
$selected = array_rand($photos, 1);
289
+
290
+
$photoName = $photos[$selected];
291
+
292
+
return fluentformMix('img/conversational/' . $photoName);
293
+
}
294
+
295
+
function fluentFormRender($atts)
296
+
{
297
+
$shortcodeDefaults = [
298
+
'id' => null,
299
+
'title' => null,
300
+
'css_classes' => '',
301
+
'permission' => '',
302
+
'type' => 'classic',
303
+
'permission_message' => __('Sorry, You do not have permission to view this form', 'fluentform'),
304
+
];
305
+
$atts = shortcode_atts($shortcodeDefaults, $atts);
306
+
307
+
return (new \FluentForm\App\Modules\Component\Component(wpFluentForm()))->renderForm($atts);
308
+
}
309
+
310
+
/**
311
+
* Print internal content (not user input) without escaping.
312
+
*/
313
+
function fluentFormPrintUnescapedInternalString($string)
314
+
{
315
+
echo $string; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- deprecated function, should remove it later.
316
+
}
317
+
318
+
function fluentform_options_sanitize($options)
319
+
{
320
+
$maps = [
321
+
'label' => 'wp_kses_post',
322
+
'value' => 'sanitize_text_field',
323
+
'image' => 'sanitize_url',
324
+
'calc_value' => 'sanitize_text_field',
325
+
];
326
+
327
+
$mapKeys = array_keys($maps);
328
+
329
+
foreach ($options as $optionIndex => $option) {
330
+
$attributes = array_filter(ArrayHelper::only($option, $mapKeys));
331
+
foreach ($attributes as $key => $value) {
332
+
$options[$optionIndex][$key] = call_user_func($maps[$key], $value);
333
+
}
334
+
}
335
+
336
+
return $options;
337
+
}
338
+
339
+
function fluentform_iframe_srcdoc_sanitize($value)
340
+
{
341
+
$tags = wp_kses_allowed_html('post');
342
+
$tags['style'] = [
343
+
'types' => [],
344
+
];
345
+
// Check if decoding is necessary
346
+
if (strpos($value, '&') !== false) {
347
+
// Decode HTML entities
348
+
$value = html_entity_decode($value, ENT_QUOTES | ENT_HTML5, 'UTF-8');
349
+
$value = stripslashes($value);
350
+
}
351
+
return wp_kses($value, $tags);
352
+
}
353
+
354
+
355
+
function fluentform_sanitize_html($html)
356
+
{
357
+
if (!$html) {
358
+
return $html;
359
+
}
360
+
361
+
// Remove event handlers (e.g., onerror, onclick, onmouseover)
362
+
$html = preg_replace('/\s+on[a-z]+\s*=\s*([\'"])[^\'"]*\1/i', '', $html);
363
+
364
+
// Remove JavaScript protocol (e.g., `href="javascript:alert(1)"`)
365
+
$html = preg_replace('/\bjavascript\s*:/i', '', $html);
366
+
367
+
$tags = wp_kses_allowed_html('post');
368
+
$tags['style'] = [
369
+
'types' => [],
370
+
];
371
+
// iframe
372
+
$tags['iframe'] = [
373
+
'width' => [],
374
+
'height' => [],
375
+
'src' => [],
376
+
'srcdoc' => [
377
+
'value_callback' => 'fluentform_iframe_srcdoc_sanitize'
378
+
],
379
+
'title' => [],
380
+
'frameborder' => [],
381
+
'allow' => [],
382
+
'class' => [],
383
+
'id' => [],
384
+
'allowfullscreen' => [],
385
+
'style' => [],
386
+
];
387
+
388
+
//button
389
+
$tags['button']['onclick'] = [];
390
+
391
+
//svg
392
+
if (empty($tags['svg'])) {
393
+
$svg_args = [
394
+
'svg' => [
395
+
'class' => true,
396
+
'aria-hidden' => true,
397
+
'aria-labelledby' => true,
398
+
'role' => true,
399
+
'xmlns' => true,
400
+
'width' => true,
401
+
'height' => true,
402
+
'viewbox' => true,
403
+
'fill' => true,
404
+
'stroke' => true,
405
+
'stroke-width' => true,
406
+
'stroke-linecap' => true,
407
+
'stroke-linejoin' => true
408
+
],
409
+
'g' => ['fill' => true],
410
+
'title' => ['title' => true],
411
+
'path' => [
412
+
'd' => true,
413
+
'fill' => true,
414
+
'transform' => true,
415
+
],
416
+
'polyline' => [
417
+
'points' => true
418
+
]
419
+
];
420
+
$tags = array_merge($tags, $svg_args);
421
+
}
422
+
423
+
$tags = apply_filters_deprecated(
424
+
'fluentform_allowed_html_tags',
425
+
[
426
+
$tags
427
+
],
428
+
FLUENTFORM_FRAMEWORK_UPGRADE,
429
+
'fluentform/allowed_html_tags',
430
+
'Use fluentform/allowed_html_tags instead of fluentform_allowed_html_tags'
431
+
);
432
+
433
+
$tags = apply_filters('fluentform/allowed_html_tags', $tags);
434
+
435
+
return wp_kses($html, $tags);
436
+
}
437
+
438
+
function fluentform_kses_js($content)
439
+
{
440
+
return $content ? preg_replace('/<script.*?>[\s\S]*<\/script>/is', '', $content) : '';
441
+
}
442
+
443
+
/**
444
+
* Sanitize inputs recursively.
445
+
*
446
+
* @param array $input
447
+
* @param array $sanitizeMap
448
+
*
449
+
* @return array $input
450
+
*/
451
+
function fluentform_backend_sanitizer($inputs, $sanitizeMap = [])
452
+
{
453
+
$originalValues = $inputs;
454
+
foreach ($inputs as $key => &$value) {
455
+
if (is_array($value)) {
456
+
$value = fluentform_backend_sanitizer($value, $sanitizeMap);
457
+
} else {
458
+
$method = ArrayHelper::get($sanitizeMap, $key);
459
+
if (is_callable($method)) {
460
+
$value = call_user_func($method, $value);
461
+
}
462
+
}
463
+
}
464
+
465
+
return apply_filters('fluentform/backend_sanitized_values', $inputs, $originalValues);
466
+
}
467
+
468
+
/**
469
+
* Sanitizes CSS.
470
+
*
471
+
* @return mixed $css
472
+
*/
473
+
function fluentformSanitizeCSS($css)
474
+
{
475
+
if ($css === null || $css === '') {
476
+
return '';
477
+
}
478
+
479
+
// Convert to string if not already
480
+
if (!is_string($css)) {
481
+
$css = (string) $css;
482
+
}
483
+
484
+
return preg_match('#</?\w+#', $css) ? '' : $css;
485
+
}
486
+
487
+
function fluentformCanUnfilteredHTML()
488
+
{
489
+
return current_user_can('unfiltered_html') || apply_filters('fluentform/disable_fields_sanitize', false);
490
+
}
491
+
492
+
function fluentformLoadFile($path)
493
+
{
494
+
return require wpFluentForm('path.app') . '/' . ltrim($path, '/');
495
+
}
496
+
497
+
if (!function_exists('fluentValidator')) {
498
+
function fluentValidator($data = [], $rules = [], $messages = [])
499
+
{
500
+
return wpFluentForm('validator')->make($data, $rules, $messages);
501
+
}
502
+
}
503
+
504
+
function fluentformGetPages()
505
+
{
506
+
$pages = get_pages();
507
+
$formattedPages = [];
508
+
509
+
foreach ($pages as $page) {
510
+
$formattedPages[] = [
511
+
'ID' => $page->ID,
512
+
'post_title' => $page->post_title,
513
+
'guid' => $page->guid,
514
+
];
515
+
}
516
+
517
+
return $formattedPages;
518
+
}
519
+