PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 5.0.12
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v5.0.12
6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 3.6.66 All 195 releases
fluentform / boot / globals.php

globals.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 5.0.12, at boot/globals.php

478 lines 12.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 function wpFluentForm($key = null)
40 {
41 return \FluentForm\App\App::make($key);
42 }
43
44 /**
45 * Generate URL for static assets
46 *
47 * @param string $path
48 *
49 * @return string
50 */
51 function fluentFormMix($path = '')
52 {
53 return wpFluentForm('url.assets') . ltrim($path, '/');
54 }
55
56 if (! function_exists('wpFluent')) {
57 /**
58 * @return \FluentForm\Framework\Database\Query\Builder|\FluentForm\Framework\Database\Query\WPDBConnection
59 */
60 function wpFluent()
61 {
62 return wpFluentForm('db');
63 }
64 }
65
66
67 function wpFluentFormAddComponent(BaseComponent $component)
68 {
69 return $component->_init();
70 }
71
72 /**
73 * Sanitize form inputs recursively.
74 *
75 * @param $input
76 *
77 * @return mixed $input
78 */
79 function fluentFormSanitizer($input, $attribute = null, $fields = [])
80 {
81 if (is_string($input)) {
82 $element = ArrayHelper::get($fields, $attribute . '.element');
83
84 if (in_array($element, ['post_content', 'rich_text_input'])) {
85 return wp_kses_post($input);
86 } elseif ('textarea' === $element) {
87 $input = sanitize_textarea_field($input);
88 } elseif ('input_email' === $element) {
89 $input = strtolower(sanitize_text_field($input));
90 } elseif ('input_url' === $element) {
91 $input = sanitize_url($input);
92 } else {
93 $input = sanitize_text_field($input);
94 }
95 } elseif (is_array($input)) {
96 foreach ($input as $key => &$value) {
97 $attribute = $attribute ? $attribute . '[' . $key . ']' : $key;
98
99 $value = fluentFormSanitizer($value, $attribute, $fields);
100
101 $attribute = null;
102 }
103 }
104
105 return $input;
106 }
107
108 function fluentFormEditorShortCodes()
109 {
110 $generalShortCodes = [EditorShortCode::getGeneralShortCodes()];
111 /* This filter is deprecated, will be removed soon. */
112 $generalShortCodes = apply_filters('fluentform_editor_shortcodes', $generalShortCodes);
113
114 return apply_filters('fluentform/editor_shortcodes', $generalShortCodes);
115 }
116
117 function fluentFormGetAllEditorShortCodes($form)
118 {
119 $editorShortCodes = EditorShortCode::getShortCodes($form);
120 /* This filter is deprecated and will be removed soon */
121 $editorShortCodes = apply_filters(
122 'fluentform_all_editor_shortcodes',
123 $editorShortCodes,
124 $form
125 );
126 return apply_filters(
127 'fluentform/all_editor_shortcodes',
128 $editorShortCodes,
129 $form
130 );
131 }
132
133 /**
134 * Recursively implode a multi-dimentional array
135 *
136 * @param string $glue
137 * @param array $array
138 *
139 * @return string
140 */
141 function fluentImplodeRecursive($glue, array $array)
142 {
143 $fn = function ($glue, array $array) use (&$fn) {
144 $result = '';
145 foreach ($array as $item) {
146 if (is_array($item)) {
147 $result .= $fn($glue, $item);
148 } else {
149 $result .= $glue . $item;
150 }
151 }
152
153 return $result;
154 };
155
156 return ltrim($fn($glue, $array), $glue);
157 }
158
159 function fluentform_get_active_theme_slug()
160 {
161 $ins = get_option('_ff_ins_by');
162
163 if ($ins) {
164 return sanitize_text_field($ins);
165 }
166
167 if (defined('TEMPLATELY_FILE')) {
168 return 'templately';
169 }
170
171 return get_option('template');
172 }
173
174 function getFluentFormCountryList()
175 {
176 static $countries = null;
177
178 if (is_null($countries)) {
179 $countries = fluentformLoadFile('/Services/FormBuilder/CountryNames.php');
180 }
181
182 return $countries;
183 }
184
185 function fluentFormWasSubmitted($action = 'fluentform_submit')
186 {
187 return wpFluentForm('request')->get('action') == $action;
188 }
189
190 if (!function_exists('isWpAsyncRequest')) {
191 function isWpAsyncRequest($action)
192 {
193 return false !== strpos(wpFluentForm('request')->get('action'), $action);
194 }
195 }
196
197 function fluentFormIsHandlingSubmission()
198 {
199 $status = fluentFormWasSubmitted() || isWpAsyncRequest('fluentform_async_request');
200
201 $status = apply_filters_deprecated(
202 'fluentform_is_handling_submission',
203 [
204 $status
205 ],
206 FLUENTFORM_FRAMEWORK_UPGRADE,
207 'fluentform/is_handling_submission',
208 'Use fluentform/is_handling_submission instead of fluentform_is_handling_submission'
209 );
210 return apply_filters('fluentform/is_handling_submission', $status);
211 }
212
213 function fluentform_mb_strpos($haystack, $needle)
214 {
215 if (function_exists('mb_strpos')) {
216 return mb_strpos($haystack, $needle);
217 }
218
219 return strpos($haystack, $needle);
220 }
221
222 function fluentFormHandleScheduledTasks()
223 {
224 $failedActions = wpFluent()->table('ff_scheduled_actions')->where('status', 'failed')->where('retry_count', '<', 4)->get();
225
226 if ($failedActions) {
227 $scheduler = wpFluentForm('fluentFormAsyncRequest');
228
229 foreach ($failedActions as $action) {
230 $scheduler->process($action);
231 }
232 }
233
234 $rand = mt_rand(1, 10);
235 if ($rand >= 5) {
236 do_action('fluentform/maybe_scheduled_jobs');
237 }
238 }
239
240 function fluentFormHandleScheduledEmailReport()
241 {
242 \FluentForm\App\Services\Scheduler\Scheduler::processEmailReport();
243 }
244
245 function fluentform_upgrade_url()
246 {
247 return 'https://fluentforms.com/pricing/?utm_source=plugin&utm_medium=wp_install&utm_campaign=ff_upgrade&theme_style=' . fluentform_get_active_theme_slug();
248 }
249
250 function fluentform_integrations_url()
251 {
252 return 'https://fluentforms.com/integration/?utm_source=plugin&utm_medium=wp_install&utm_campaign=ff_upgrade&theme_style=' . fluentform_get_active_theme_slug();
253 }
254
255 function fluentFormApi($module = 'forms')
256 {
257 if ('forms' == $module) {
258 return new \FluentForm\App\Api\Form();
259 } elseif ('submissions' == $module) {
260 return new \FluentForm\App\Api\Submission();
261 }
262
263 throw new \Exception('No Module found with name ' . $module);
264 }
265
266 function fluentFormGetRandomPhoto()
267 {
268 $photos = [
269 'demo_1.jpg',
270 'demo_2.jpg',
271 'demo_3.jpg',
272 'demo_4.jpg',
273 'demo_5.jpg',
274 ];
275
276 $selected = array_rand($photos, 1);
277
278 $photoName = $photos[$selected];
279
280 return fluentformMix('img/conversational/' . $photoName);
281 }
282
283 function fluentFormRender($atts)
284 {
285 $shortcodeDefaults = [
286 'id' => null,
287 'title' => null,
288 'css_classes' => '',
289 'permission' => '',
290 'type' => 'classic',
291 'permission_message' => __('Sorry, You do not have permission to view this form', 'fluentform'),
292 ];
293 $atts = shortcode_atts($shortcodeDefaults, $atts);
294
295 return (new \FluentForm\App\Modules\Component\Component(wpFluentForm()))->renderForm($atts);
296 }
297
298 /**
299 * Print internal content (not user input) without escaping.
300 */
301 function fluentFormPrintUnescapedInternalString($string)
302 {
303 echo $string; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- deprecated function, should remove it later.
304 }
305
306 function fluentform_options_sanitize($options)
307 {
308 $maps = [
309 'label' => 'wp_kses_post',
310 'value' => 'sanitize_text_field',
311 'image' => 'sanitize_url',
312 'calc_value' => 'sanitize_text_field',
313 ];
314
315 $mapKeys = array_keys($maps);
316
317 foreach ($options as $optionIndex => $option) {
318 $attributes = array_filter(ArrayHelper::only($option, $mapKeys));
319 foreach ($attributes as $key => $value) {
320 $options[$optionIndex][$key] = call_user_func($maps[$key], $value);
321 }
322 }
323
324 return $options;
325 }
326
327 function fluentform_sanitize_html($html)
328 {
329 if (!$html) {
330 return $html;
331 }
332
333 // Return $html if it's just a plain text
334 if (!preg_match('/<[^>]*>/', $html)) {
335 return $html;
336 }
337
338 $tags = wp_kses_allowed_html('post');
339 $tags['style'] = [
340 'types' => [],
341 ];
342 // iframe
343 $tags['iframe'] = [
344 'width' => [],
345 'height' => [],
346 'src' => [],
347 'srcdoc' => [],
348 'title' => [],
349 'frameborder' => [],
350 'allow' => [],
351 'class' => [],
352 'id' => [],
353 'allowfullscreen' => [],
354 'style' => [],
355 ];
356 //button
357 $tags['button']['onclick'] = [];
358
359 //svg
360 if (empty($tags['svg'])) {
361 $svg_args = [
362 'svg' => [
363 'class' => true,
364 'aria-hidden' => true,
365 'aria-labelledby' => true,
366 'role' => true,
367 'xmlns' => true,
368 'width' => true,
369 'height' => true,
370 'viewbox' => true,
371 'fill' => true,
372 'stroke' => true,
373 'stroke-width' => true,
374 'stroke-linecap' => true,
375 'stroke-linejoin' => true
376 ],
377 'g' => ['fill' => true],
378 'title' => ['title' => true],
379 'path' => [
380 'd' => true,
381 'fill' => true,
382 'transform' => true,
383 ],
384 'polyline' => [
385 'points' => true
386 ]
387 ];
388 $tags = array_merge($tags, $svg_args);
389 }
390
391 $tags = apply_filters_deprecated(
392 'fluentform_allowed_html_tags',
393 [
394 $tags
395 ],
396 FLUENTFORM_FRAMEWORK_UPGRADE,
397 'fluentform/allowed_html_tags',
398 'Use fluentform/allowed_html_tags instead of fluentform_allowed_html_tags'
399 );
400
401 $tags = apply_filters('fluentform/allowed_html_tags', $tags);
402
403 return wp_kses($html, $tags);
404 }
405
406 function fluentform_kses_js($content)
407 {
408 return preg_replace('/<script.*?>[\s\S]*<\/script>/is', '', $content);
409 }
410
411 /**
412 * Sanitize inputs recursively.
413 *
414 * @param array $input
415 * @param array $sanitizeMap
416 *
417 * @return array $input
418 */
419 function fluentform_backend_sanitizer($inputs, $sanitizeMap = [])
420 {
421 $originalValues = $inputs;
422 foreach ($inputs as $key => &$value) {
423 if (is_array($value)) {
424 $value = fluentform_backend_sanitizer($value, $sanitizeMap);
425 } else {
426 $method = ArrayHelper::get($sanitizeMap, $key);
427 if (is_callable($method)) {
428 $value = call_user_func($method, $value);
429 }
430 }
431 }
432
433 return apply_filters('fluentform/backend_sanitized_values', $inputs, $originalValues);
434 }
435
436 /**
437 * Sanitizes CSS.
438 *
439 * @return mixed $css
440 */
441 function fluentformSanitizeCSS($css)
442 {
443 return preg_match('#</?\w+#', $css) ? '' : $css;
444 }
445
446 function fluentformCanUnfilteredHTML()
447 {
448 return current_user_can('unfiltered_html') || apply_filters('fluentform/disable_fields_sanitize', false);
449 }
450
451 function fluentformLoadFile($path)
452 {
453 return require wpFluentForm('path.app') . '/' . ltrim($path, '/');
454 }
455
456 if (!function_exists('fluentValidator')) {
457 function fluentValidator($data = [], $rules = [], $messages = [])
458 {
459 return wpFluentForm('validator')->make($data, $rules, $messages);
460 }
461 }
462
463 function fluentformGetPages()
464 {
465 $pages = get_pages();
466 $formattedPages = [];
467
468 foreach ($pages as $page) {
469 $formattedPages[] = [
470 'ID' => $page->ID,
471 'post_title' => $page->post_title,
472 'guid' => $page->guid,
473 ];
474 }
475
476 return $formattedPages;
477 }
478