| 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 |
$publicUrl = \FluentForm\App::publicUrl(); |
| 51 |
return $publicUrl . $path; |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
if (!function_exists('fluentFormSanitizer')) { |
| 56 |
/** |
| 57 |
* Sanitize form inputs recursively. |
| 58 |
* |
| 59 |
* @param $input |
| 60 |
* |
| 61 |
* @return string $input |
| 62 |
*/ |
| 63 |
function fluentFormSanitizer($input, $attribute = null, $fields = []) |
| 64 |
{ |
| 65 |
if (is_string($input)) { |
| 66 |
if (ArrayHelper::get($fields, $attribute . '.element') === 'post_content') { |
| 67 |
return wp_kses_post($input); |
| 68 |
} else if (ArrayHelper::get($fields, $attribute . '.element') === 'textarea') { |
| 69 |
$input = sanitize_textarea_field($input); |
| 70 |
} else if (ArrayHelper::get($fields, $attribute . '.element') === 'input_email') { |
| 71 |
$input = strtolower(sanitize_text_field($input)); |
| 72 |
} else { |
| 73 |
$input = sanitize_text_field($input); |
| 74 |
} |
| 75 |
} elseif (is_array($input)) { |
| 76 |
foreach ($input as $key => &$value) { |
| 77 |
$attribute = $attribute ? $attribute . '[' . $key . ']' : $key; |
| 78 |
|
| 79 |
$value = fluentFormSanitizer($value, $attribute, $fields); |
| 80 |
|
| 81 |
$attribute = null; |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
return $input; |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
if (!function_exists('fluentFormEditorShortCodes')) { |
| 90 |
function fluentFormEditorShortCodes() |
| 91 |
{ |
| 92 |
return apply_filters('fluentform_editor_shortcodes', [ |
| 93 |
EditorShortCode::getGeneralShortCodes() |
| 94 |
]); |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
if (!function_exists('fluentFormGetAllEditorShortCodes')) { |
| 99 |
function fluentFormGetAllEditorShortCodes($form) |
| 100 |
{ |
| 101 |
return apply_filters( |
| 102 |
'fluentform_all_editor_shortcodes', |
| 103 |
EditorShortCode::getShortCodes($form), |
| 104 |
$form |
| 105 |
); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
if (!function_exists('fluentImplodeRecursive')) { |
| 110 |
/** |
| 111 |
* Recursively implode a multi-dimentional array |
| 112 |
* @param string $glue |
| 113 |
* @param array $array |
| 114 |
* @return string |
| 115 |
*/ |
| 116 |
function fluentImplodeRecursive($glue, array $array) |
| 117 |
{ |
| 118 |
$fn = function ($glue, array $array) use (&$fn) { |
| 119 |
$result = ''; |
| 120 |
foreach ($array as $item) { |
| 121 |
if (is_array($item)) { |
| 122 |
$result .= $fn($glue, $item); |
| 123 |
} else { |
| 124 |
$result .= $glue . $item; |
| 125 |
} |
| 126 |
} |
| 127 |
return $result; |
| 128 |
}; |
| 129 |
|
| 130 |
return ltrim($fn($glue, $array), $glue); |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
function fluentform_get_active_theme_slug() |
| 136 |
{ |
| 137 |
if(defined('TEMPLATELY_FILE')) { |
| 138 |
return 'templately'; |
| 139 |
} |
| 140 |
return get_option('template'); |
| 141 |
} |
| 142 |
|
| 143 |
if (!function_exists('getFluentFormCountryList')) { |
| 144 |
function getFluentFormCountryList() |
| 145 |
{ |
| 146 |
static $countries = null; |
| 147 |
if (is_null($countries)) { |
| 148 |
$countries = require( |
| 149 |
FluentForm\App::appPath('/Services/FormBuilder/CountryNames.php') |
| 150 |
); |
| 151 |
} |
| 152 |
return $countries; |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
if (!function_exists('fluentFormWasSubmitted')) { |
| 157 |
function fluentFormWasSubmitted($action = 'fluentform_submit') |
| 158 |
{ |
| 159 |
return wpFluentForm('request')->get('action') == $action; |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
if (!function_exists('isWpAsyncRequest')) { |
| 164 |
function isWpAsyncRequest($action) |
| 165 |
{ |
| 166 |
return strpos(wpFluentForm('request')->get('action'), $action) !== false; |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
if (!function_exists('fluentFormIsHandlingSubmission')) { |
| 171 |
function fluentFormIsHandlingSubmission() |
| 172 |
{ |
| 173 |
$status = fluentFormWasSubmitted() || isWpAsyncRequest('fluentform_async_request'); |
| 174 |
return apply_filters('fluentform_is_handling_submission', $status); |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
function fluentform_mb_strpos($haystack, $needle) |
| 179 |
{ |
| 180 |
if (function_exists('mb_strpos')) { |
| 181 |
return mb_strpos($haystack, $needle); |
| 182 |
} |
| 183 |
return strpos($haystack, $needle); |
| 184 |
} |
| 185 |
|
| 186 |
function fluentFormHandleScheduledTasks() |
| 187 |
{ |
| 188 |
// Let's run the feed actions |
| 189 |
$handler = new \FluentForm\App\Services\WPAsync\FluentFormAsyncRequest(wpFluentForm()); |
| 190 |
$handler->processActions(); |
| 191 |
|
| 192 |
$rand = mt_rand(1,10); |
| 193 |
if($rand >= 7) { |
| 194 |
do_action('fluentform_maybe_scheduled_jobs'); |
| 195 |
} |
| 196 |
} |
| 197 |
|
| 198 |
function fluentFormHandleScheduledEmailReport() |
| 199 |
{ |
| 200 |
\FluentForm\App\Services\Scheduler\Scheduler::processEmailReport(); |
| 201 |
} |
| 202 |
|
| 203 |
function fluentform_upgrade_url() |
| 204 |
{ |
| 205 |
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(); |
| 206 |
} |
| 207 |
|
| 208 |
function fluentFormApi($module = 'forms') |
| 209 |
{ |
| 210 |
if($module == 'forms') { |
| 211 |
return (new \FluentForm\App\Api\Form()); |
| 212 |
} else if($module == 'submissions') { |
| 213 |
return (new \FluentForm\App\Api\Submission()); |
| 214 |
} |
| 215 |
|
| 216 |
throw new \Exception('No Module found with name '. $module); |
| 217 |
} |
| 218 |
|
| 219 |
function fluentFormGetRandomPhoto() |
| 220 |
{ |
| 221 |
$photos = [ |
| 222 |
'demo_1.jpg', |
| 223 |
'demo_2.jpg', |
| 224 |
'demo_3.jpg', |
| 225 |
'demo_4.jpg', |
| 226 |
'demo_5.jpg' |
| 227 |
]; |
| 228 |
|
| 229 |
$selected = array_rand($photos, 1); |
| 230 |
|
| 231 |
$photoName = $photos[$selected]; |
| 232 |
|
| 233 |
return fluentformMix('img/conversational/' . $photoName); |
| 234 |
} |
| 235 |
|
| 236 |
if (! function_exists('fluentFormRender')) { |
| 237 |
function fluentFormRender($atts) |
| 238 |
{ |
| 239 |
$shortcodeDefaults = array( |
| 240 |
'id' => null, |
| 241 |
'title' => null, |
| 242 |
'css_classes' => '', |
| 243 |
'permission' => '', |
| 244 |
'type' => 'classic', |
| 245 |
'permission_message' => __('Sorry, You do not have permission to view this form', 'fluentform') |
| 246 |
); |
| 247 |
$atts = shortcode_atts($shortcodeDefaults, $atts); |
| 248 |
|
| 249 |
return (new \FluentForm\App\Modules\Component\Component(wpFluentForm()))->renderForm($atts); |
| 250 |
} |
| 251 |
} |
| 252 |
|
| 253 |
/** |
| 254 |
* Print internal content (not user input) without escaping. |
| 255 |
*/ |
| 256 |
function fluentFormPrintUnescapedInternalString($string) |
| 257 |
{ |
| 258 |
echo $string; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 259 |
} |
| 260 |
|