PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 3.6.60
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v3.6.60
6.2.14 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 All 196 releases
fluentform / app / Global / Common.php

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

236 lines 6.4 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 if (!function_exists('wpFluentForm')) {
13 function wpFluentForm($key = null)
14 {
15 return FluentForm\App::make($key);
16 }
17 }
18
19 if (!function_exists('wpFluentFormAddComponent')) {
20 function wpFluentFormAddComponent(FluentFormComponent $component)
21 {
22 return $component->_init();
23 }
24 }
25
26 if (!function_exists('dd')) {
27 function dd()
28 {
29 foreach (func_get_args() as $value) {
30 echo "<pre>";
31 print_r($value);
32 echo "</pre><br>";
33 }
34 die;
35 }
36 }
37
38 if (!function_exists('fluentformMix')) {
39 /**
40 * Get the path to a versioned Mix file.
41 *
42 * @param string $path
43 * @param string $manifestDirectory
44 *
45 * @return string
46 * @throws \Exception
47 */
48 function fluentformMix($path, $manifestDirectory = '')
49 {
50 $env = \FluentForm\App::make('config')->app['env'];
51
52 if ($env != 'dev') {
53 $publicUrl = \FluentForm\App::publicUrl();
54
55 return $publicUrl . $path;
56 }
57
58 static $manifests = [];
59
60 if (substr($path, 0, 1) !== '/') {
61 $path = "/" . $path;
62 }
63
64 if ($manifestDirectory && substr($manifestDirectory, 0, 1) !== '/') {
65 $manifestDirectory = "/" . $manifestDirectory;
66 }
67
68 $publicPath = \FluentForm\App::publicPath();
69 if (file_exists($publicPath . '/hot')) {
70 return (is_ssl() ? "https" : "http") . "://localhost:8080" . $path;
71 }
72
73 $manifestPath = $publicPath . $manifestDirectory . 'mix-manifest.json';
74
75 if (!isset($manifests[$manifestPath])) {
76 if (!file_exists($manifestPath)) {
77 throw new Exception('The Mix manifest does not exist.');
78 }
79
80 $manifests[$manifestPath] = json_decode(file_get_contents($manifestPath), true);
81 }
82
83 $manifest = $manifests[$manifestPath];
84
85 if (!isset($manifest[$path])) {
86 throw new Exception(
87 "Unable to locate Mix file: " . $path . ". Please check your " .
88 'webpack.mix.js output paths and try again.'
89 );
90 }
91
92 return \FluentForm\App::publicUrl($manifestDirectory . $manifest[$path]);
93 }
94 }
95
96 if (!function_exists('fluentFormSanitizer')) {
97 /**
98 * Sanitize form inputs recursively.
99 *
100 * @param $input
101 *
102 * @return string $input
103 */
104 function fluentFormSanitizer($input, $attribute = null, $fields = [])
105 {
106 if (is_string($input)) {
107 if (ArrayHelper::get($fields, $attribute . '.element') === 'post_content') {
108 return wp_kses_post($input);
109 } else if (ArrayHelper::get($fields, $attribute . '.element') === 'textarea') {
110 $input = sanitize_textarea_field($input);
111 } else {
112 $input = sanitize_text_field($input);
113 }
114 } elseif (is_array($input)) {
115 foreach ($input as $key => &$value) {
116 $attribute = $attribute ? $attribute . '[' . $key . ']' : $key;
117
118 $value = fluentFormSanitizer($value, $attribute, $fields);
119
120 $attribute = null;
121 }
122 }
123
124 return $input;
125 }
126 }
127
128 if (!function_exists('fluentFormEditorShortCodes')) {
129 function fluentFormEditorShortCodes()
130 {
131 return apply_filters('fluentform_editor_shortcodes', [
132 EditorShortCode::getGeneralShortCodes()
133 ]);
134 }
135 }
136
137 if (!function_exists('fluentFormGetAllEditorShortCodes')) {
138 function fluentFormGetAllEditorShortCodes($form)
139 {
140 return apply_filters(
141 'fluentform_all_editor_shortcodes',
142 EditorShortCode::getShortCodes($form)
143 );
144 }
145 }
146
147 if (!function_exists('fluentImplodeRecursive')) {
148 /**
149 * Recursively implode a multi-dimentional array
150 * @param string $glue
151 * @param array $array
152 * @return string
153 */
154 function fluentImplodeRecursive($glue, array $array)
155 {
156 $fn = function ($glue, array $array) use (&$fn) {
157 $result = '';
158 foreach ($array as $item) {
159 if (is_array($item)) {
160 $result .= $fn($glue, $item);
161 } else {
162 $result .= $glue . $item;
163 }
164 }
165 return $result;
166 };
167
168 return ltrim($fn($glue, $array), $glue);
169 }
170 }
171
172
173 function fluentform_get_active_theme_slug()
174 {
175 return get_option('stylesheet');
176 }
177
178 if (!function_exists('getFluentFormCountryList')) {
179 function getFluentFormCountryList()
180 {
181 static $countries = null;
182 if (is_null($countries)) {
183 $countries = require(
184 FluentForm\App::appPath('/Services/FormBuilder/CountryNames.php')
185 );
186 }
187 return $countries;
188 }
189 }
190
191 if (!function_exists('fluentFormWasSubmitted')) {
192 function fluentFormWasSubmitted($action = 'fluentform_submit')
193 {
194 return wpFluentForm('request')->get('action') == $action;
195 }
196 }
197
198 if (!function_exists('isWpAsyncRequest')) {
199 function isWpAsyncRequest($action)
200 {
201 return strpos(wpFluentForm('request')->get('action'), $action) !== false;
202 }
203 }
204
205 if (!function_exists('fluentFormIsHandlingSubmission')) {
206 function fluentFormIsHandlingSubmission()
207 {
208 $status = fluentFormWasSubmitted() || isWpAsyncRequest('fluentform_async_request');
209 return apply_filters('fluentform_is_handling_submission', $status);
210 }
211 }
212
213 function fluentform_mb_strpos($haystack, $needle)
214 {
215 if (function_exists('mb_strpos')) {
216 return mb_strpos($haystack, $needle);
217 }
218 return strpos($haystack, $needle);
219 }
220
221 function fluentFormHandleScheduledTasks()
222 {
223 // Let's run the feed actions
224 $handler = new \FluentForm\App\Services\WPAsync\FluentFormAsyncRequest(wpFluentForm());
225 $handler->processActions();
226 }
227
228 function fluentFormHandleScheduledEmailReport()
229 {
230 \FluentForm\App\Services\Scheduler\Scheduler::processEmailReport();
231 }
232
233 function fluentform_upgrade_url()
234 {
235 return 'https://wpmanageninja.com/downloads/fluentform-pro-add-on/?utm_source=plugin&utm_medium=wp_install&utm_campaign=ff_upgrade&theme_style=' . fluentform_get_active_theme_slug();
236 }