PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 1.2.4
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v1.2.4
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 1.2.4, at app/Global/Common.php

159 lines 5.0 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 if (! function_exists('dd')) {
9 function dd()
10 {
11 foreach (func_get_args() as $value) {
12 echo "<pre>";
13 print_r($value);
14 echo "</pre><br>";
15 }
16 die;
17 }
18 }
19
20 if (! function_exists('fluentformMix')) {
21 /**
22 * Get the path to a versioned Mix file.
23 *
24 * @param string $path
25 * @param string $manifestDirectory
26 *
27 * @return string
28 * @throws \Exception
29 */
30 function fluentformMix($path, $manifestDirectory = '')
31 {
32 $env = \FluentForm\App::make('config')->app['env'];
33
34 if ($env != 'dev') {
35 $publicUrl = \FluentForm\App::publicUrl();
36
37 return $publicUrl.$path;
38 }
39
40 static $manifests = [];
41
42 if (substr($path, 0, 1) !== '/') {
43 $path = "/".$path;
44 }
45
46 if ($manifestDirectory && substr($manifestDirectory, 0, 1) !== '/') {
47 $manifestDirectory = "/".$manifestDirectory;
48 }
49
50 $publicPath = \FluentForm\App::publicPath();
51 if (file_exists($publicPath.'/hot')) {
52 return (is_ssl() ? "https" : "http")."://localhost:8080".$path;
53 }
54
55 $manifestPath = $publicPath.$manifestDirectory.'mix-manifest.json';
56
57 if (! isset($manifests[$manifestPath])) {
58 if (! file_exists($manifestPath)) {
59 throw new Exception('The Mix manifest does not exist.');
60 }
61
62 $manifests[$manifestPath] = json_decode(file_get_contents($manifestPath), true);
63 }
64
65 $manifest = $manifests[$manifestPath];
66
67 if (! isset($manifest[$path])) {
68 throw new Exception(
69 "Unable to locate Mix file: ".$path.". Please check your ".
70 'webpack.mix.js output paths and try again.'
71 );
72 }
73
74 return \FluentForm\App::publicUrl($manifestDirectory.$manifest[$path]);
75 }
76 }
77
78 if (! function_exists('fluentFormSanitizer')) {
79 /**
80 * Sanitize form inputs recursively.
81 *
82 * @param $input
83 *
84 * @return string $input
85 */
86 function fluentFormSanitizer($input, $attribute = null, $fields = [])
87 {
88 if (is_string($input)) {
89 if (\FluentForm\Framework\Helpers\ArrayHelper::get($fields, $attribute.'.element') === 'textarea') {
90 $input = sanitize_textarea_field($input);
91 } else {
92 $input = sanitize_text_field($input);
93 }
94 } elseif (is_array($input)) {
95 foreach ($input as $key => &$value) {
96 $attribute = $attribute ? $attribute.'['.$key.']' : $key;
97
98 $value = fluentFormSanitizer($value, $attribute, $fields);
99
100 $attribute = null;
101 }
102 }
103
104 return $input;
105 }
106 }
107
108 if (! function_exists('fluentFormEditorShortCodes')) {
109 function fluentFormEditorShortCodes()
110 {
111 $editor_shortcodes = array(
112 array(
113 'title' => 'General Shortcodes',
114 'shortcodes' => array(
115 '{ip}' => __('IP Address', 'fluentform'),
116 '{date.m/d/Y}' => __('Date (mm/dd/yyyy)', 'fluentform'),
117 '{date.d/m/Y}' => __('Date (dd/mm/yyyy)', 'fluentform'),
118 '{embed_post.ID}' => __('Embebeded Post/Page ID', 'fluentform'),
119 '{embed_post.post_title}' => __('Embebeded Post/Page Title', 'fluentform'),
120 '{embed_post.permalink}' => __('Embebeded URL', 'fluentform'),
121 '{user.ID}' => __('User ID', 'fluentform'),
122 '{user.display_name}' => __('User Display Name', 'fluentform'),
123 '{user.first_name}' => __('User First Name', 'fluentform'),
124 '{user.last_name}' => __('User Last Name', 'fluentform'),
125 '{user.user_email}' => __('User Email', 'fluentform'),
126 '{user.user_login}' => __('User Username', 'fluentform'),
127 '{browser.name}' => __('User Browser Client', 'fluentform'),
128 '{browser.platform}' => __('User Operating System', 'fluentform')
129 )
130 )
131 );
132 return apply_filters('fluentform_editor_shortcodes', $editor_shortcodes);
133 }
134 }
135
136 if (!function_exists('implodeRecursive')) {
137 /**
138 * Recursively implode a multi-dimentional array
139 * @param string $glue
140 * @param array $array
141 * @return string
142 */
143 function implodeRecursive($glue, array $array) {
144 $fn = function($glue, array $array) use (&$fn) {
145 $result = '';
146 foreach ($array as $item) {
147 if(is_array($item)) {
148 $result .= $fn($glue, $item);
149 } else {
150 $result .= $glue . $item;
151 }
152 }
153 return $result;
154 };
155
156 return ltrim($fn($glue, $array), $glue);
157 }
158 }
159