PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 4.3.17
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v4.3.17
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 / app / Global / Common.php

Common.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 4.3.17, at app/Global/Common.php

396 lines 9.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Declare common (backend|frontend) global functions here
5 * but try not to use any global functions unless you need.
6 */
7
8 use FluentForm\App\Modules\Component\BaseComponent as FluentFormComponent;
9 use FluentForm\App\Services\FormBuilder\EditorShortCode;
10 use FluentForm\Framework\Helpers\ArrayHelper;
11
12 function wpFluentForm($key = null)
13 {
14 return FluentForm\App::make($key);
15 }
16
17 function wpFluentFormAddComponent(FluentFormComponent $component)
18 {
19 return $component->_init();
20 }
21
22 if (! function_exists('dd')) {
23 function dd()
24 {
25 foreach (func_get_args() as $value) {
26 echo '<pre>';
27 print_r($value); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $value is only used for debugging in development.
28 echo '</pre><br>';
29 }
30 die;
31 }
32 }
33
34 /**
35 * Get the path to a versioned Mix file.
36 *
37 * @param string $path
38 * @param string $manifestDirectory
39 *
40 * @return string
41 *
42 * @throws \Exception
43 */
44 function fluentformMix($path, $manifestDirectory = '')
45 {
46 $publicUrl = \FluentForm\App::publicUrl();
47 return $publicUrl . $path;
48 }
49
50 /**
51 * Sanitize form inputs recursively.
52 *
53 * @param $input
54 *
55 * @return string $input
56 */
57 function fluentFormSanitizer($input, $attribute = null, $fields = [])
58 {
59 if (is_string($input)) {
60 $element = ArrayHelper::get($fields, $attribute . '.element');
61
62 if (in_array($element, ['post_content', 'rich_text_input'])) {
63 return wp_kses_post($input);
64 } elseif ('textarea' === $element) {
65 $input = sanitize_textarea_field($input);
66 } elseif ('input_email' === $element) {
67 $input = strtolower(sanitize_text_field($input));
68 } elseif ('input_url' === $element) {
69 $input = sanitize_url($input);
70 } else {
71 $input = sanitize_text_field($input);
72 }
73 } elseif (is_array($input)) {
74 foreach ($input as $key => &$value) {
75 $attribute = $attribute ? $attribute . '[' . $key . ']' : $key;
76
77 $value = fluentFormSanitizer($value, $attribute, $fields);
78
79 $attribute = null;
80 }
81 }
82
83 return $input;
84 }
85
86 function fluentFormEditorShortCodes()
87 {
88 return apply_filters('fluentform_editor_shortcodes', [
89 EditorShortCode::getGeneralShortCodes(),
90 ]);
91 }
92
93 function fluentFormGetAllEditorShortCodes($form)
94 {
95 return apply_filters(
96 'fluentform_all_editor_shortcodes',
97 EditorShortCode::getShortCodes($form),
98 $form
99 );
100 }
101
102 /**
103 * Recursively implode a multi-dimentional array
104 *
105 * @param string $glue
106 * @param array $array
107 *
108 * @return string
109 */
110 function fluentImplodeRecursive($glue, array $array)
111 {
112 $fn = function ($glue, array $array) use (&$fn) {
113 $result = '';
114 foreach ($array as $item) {
115 if (is_array($item)) {
116 $result .= $fn($glue, $item);
117 } else {
118 $result .= $glue . $item;
119 }
120 }
121 return $result;
122 };
123
124 return ltrim($fn($glue, $array), $glue);
125 }
126
127 function fluentform_get_active_theme_slug()
128 {
129 $ins = get_option('_ff_ins_by');
130
131 if ($ins) {
132 return sanitize_text_field($ins);
133 }
134
135 if (defined('TEMPLATELY_FILE')) {
136 return 'templately';
137 }
138 return get_option('template');
139 }
140
141 function getFluentFormCountryList()
142 {
143 static $countries = null;
144 if (is_null($countries)) {
145 $countries = require FluentForm\App::appPath('/Services/FormBuilder/CountryNames.php');
146 }
147 return $countries;
148 }
149
150 function fluentFormWasSubmitted($action = 'fluentform_submit')
151 {
152 return wpFluentForm('request')->get('action') == $action;
153 }
154
155 if (! function_exists('isWpAsyncRequest')) {
156 function isWpAsyncRequest($action)
157 {
158 return false !== strpos(wpFluentForm('request')->get('action'), $action);
159 }
160 }
161
162 function fluentFormIsHandlingSubmission()
163 {
164 $status = fluentFormWasSubmitted() || isWpAsyncRequest('fluentform_async_request');
165 return apply_filters('fluentform_is_handling_submission', $status);
166 }
167
168 function fluentform_mb_strpos($haystack, $needle)
169 {
170 if (function_exists('mb_strpos')) {
171 return mb_strpos($haystack, $needle);
172 }
173 return strpos($haystack, $needle);
174 }
175
176 function fluentFormHandleScheduledTasks()
177 {
178 // Let's run the feed actions
179 $handler = new \FluentForm\App\Services\WPAsync\FluentFormAsyncRequest(wpFluentForm());
180 $handler->processActions();
181
182 $rand = mt_rand(1, 10);
183 if ($rand >= 7) {
184 do_action('fluentform_maybe_scheduled_jobs');
185 }
186 }
187
188 function fluentFormHandleScheduledEmailReport()
189 {
190 \FluentForm\App\Services\Scheduler\Scheduler::processEmailReport();
191 }
192
193 function fluentform_upgrade_url()
194 {
195 return 'https://fluentforms.com/pricing/?utm_source=plugin&utm_medium=wp_install&utm_campaign=ff_upgrade&theme_style=' . fluentform_get_active_theme_slug();
196 }
197
198 function fluentform_integrations_url()
199 {
200 return 'https://fluentforms.com/integration/?utm_source=plugin&utm_medium=wp_install&utm_campaign=ff_upgrade&theme_style=' . fluentform_get_active_theme_slug();
201 }
202
203 function fluentFormApi($module = 'forms')
204 {
205 if ('forms' == $module) {
206 return (new \FluentForm\App\Api\Form());
207 } elseif ('submissions' == $module) {
208 return (new \FluentForm\App\Api\Submission());
209 }
210
211 throw new \Exception('No Module found with name ' . $module);
212 }
213
214 function fluentFormGetRandomPhoto()
215 {
216 $photos = [
217 'demo_1.jpg',
218 'demo_2.jpg',
219 'demo_3.jpg',
220 'demo_4.jpg',
221 'demo_5.jpg',
222 ];
223
224 $selected = array_rand($photos, 1);
225
226 $photoName = $photos[$selected];
227
228 return fluentformMix('img/conversational/' . $photoName);
229 }
230
231 function fluentFormRender($atts)
232 {
233 $shortcodeDefaults = [
234 'id' => null,
235 'title' => null,
236 'css_classes' => '',
237 'permission' => '',
238 'type' => 'classic',
239 'permission_message' => __('Sorry, You do not have permission to view this form', 'fluentform'),
240 ];
241 $atts = shortcode_atts($shortcodeDefaults, $atts);
242
243 return (new \FluentForm\App\Modules\Component\Component(wpFluentForm()))->renderForm($atts);
244 }
245
246 /**
247 * Print internal content (not user input) without escaping.
248 */
249 function fluentFormPrintUnescapedInternalString($string)
250 {
251 echo $string; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- deprecated function, should remove it later.
252 }
253
254 function fluentform_options_sanitize($options)
255 {
256 $maps = [
257 'label' => 'wp_kses_post',
258 'value' => 'sanitize_text_field',
259 'image' => 'sanitize_url',
260 'calc_value' => 'sanitize_text_field',
261 ];
262
263 $mapKeys = array_keys($maps);
264
265 foreach ($options as $optionIndex => $option) {
266 $attributes = array_filter(ArrayHelper::only($option, $mapKeys));
267 foreach ($attributes as $key => $value) {
268 $options[$optionIndex][$key] = call_user_func($maps[$key], $value);
269 }
270 }
271
272 return $options;
273 }
274
275 function fluentform_sanitize_html($html, $isSaving = true)
276 {
277 if (! $html) {
278 return $html;
279 }
280
281 if (function_exists('fluentform_kses_advanced')) {
282 return fluentform_kses_advanced($html, $isSaving);
283 }
284
285 return fluentform_kses($html);
286 }
287
288 function fluentform_kses($html)
289 {
290 if (! $html) {
291 return $html;
292 }
293
294 $tags = wp_kses_allowed_html('post');
295 $tags['style'] = [
296 'types' => [],
297 ];
298 // iframe
299 $tags['iframe'] = [
300 'width' => [],
301 'height' => [],
302 'src' => [],
303 'srcdoc' => [],
304 'title' => [],
305 'frameborder' => [],
306 'allow' => [],
307 'class' => [],
308 'id' => [],
309 'allowfullscreen' => [],
310 'style' => [],
311 ];
312 //button
313 $tags['button']['onclick'] = [];
314
315 //svg
316 if (empty($tags['svg'])) {
317 $svg_args = [
318 'svg' => [
319 'class' => true,
320 'aria-hidden' => true,
321 'aria-labelledby' => true,
322 'role' => true,
323 'xmlns' => true,
324 'width' => true,
325 'height' => true,
326 'viewbox' => true, // <= Must be lower case!
327 ],
328 'g' => ['fill' => true],
329 'title' => ['title' => true],
330 'path' => [
331 'd' => true,
332 'fill' => true,
333 'transform' => true,
334 ],
335 ];
336 $tags = array_merge($tags, $svg_args);
337 }
338
339 $tags = apply_filters('fluentform_allowed_html_tags', $tags);
340
341 return wp_kses($html, $tags);
342 }
343
344 function fluentform_kses_js($content)
345 {
346 if (function_exists('fluentform_kses_advanced')) {
347 return fluentform_kses_advanced($content);
348 }
349
350 return html_entity_decode(fluentform_kses($content));
351 }
352
353 /**
354 * Sanitize inputs recursively.
355 *
356 * @param array $input
357 * @param array $sanitizeMap
358 *
359 * @return array $input
360 */
361 function fluentform_backend_sanitizer($array, $sanitizeMap = [])
362 {
363 foreach ($array as $key => &$value) {
364 if (is_array($value)) {
365 $value = fluentform_backend_sanitizer($value, $sanitizeMap);
366 } else {
367 $method = ArrayHelper::get($sanitizeMap, $key);
368
369 if (is_callable($method)) {
370 $value = call_user_func($method, $value);
371 }
372 }
373 }
374
375 return apply_filters('fluent_backend_sanitized_values', $array);
376 }
377
378 /**
379 * Sanitizes CSS.
380 *
381 * @return mixed $css
382 */
383 function fluentformSanitizeCSS($css)
384 {
385 if (function_exists('fluentform_kses_advanced')) {
386 return fluentform_kses_advanced($css);
387 }
388
389 return preg_match('#</?\w+#', $css) ? '' : $css;
390 }
391
392 function fluentformCanUnfilteredHTML()
393 {
394 return current_user_can('unfiltered_html') || apply_filters('fluent_form_disable_fields_sanitize', false);
395 }
396