PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.2
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.2
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 / Services / FormBuilder / EditorShortCode.php

EditorShortCode.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 6.2.2, at app/Services/FormBuilder/EditorShortCode.php

195 lines 8.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentForm\App\Services\FormBuilder;
4
5 use FluentForm\App\Modules\Form\FormFieldsParser;
6
7 class EditorShortCode
8 {
9 public static function getGeneralShortCodes()
10 {
11 return [
12 'title' => __('General SmartCodes','fluentform'),
13 'shortcodes' => [
14 '{wp.admin_email}' => __('Admin Email', 'fluentform'),
15 '{wp.site_url}' => __('Site URL', 'fluentform'),
16 '{wp.site_title}' => __('Site Title', 'fluentform'),
17 '{ip}' => __('IP Address', 'fluentform'),
18 '{date.m/d/Y}' => __('Date (mm/dd/yyyy)', 'fluentform'),
19 '{date.d/m/Y}' => __('Date (dd/mm/yyyy)', 'fluentform'),
20 '{embed_post.ID}' => __('Embedded Post/Page ID', 'fluentform'),
21 '{embed_post.post_title}' => __('Embedded Post/Page Title', 'fluentform'),
22 '{embed_post.permalink}' => __('Embedded URL', 'fluentform'),
23 '{http_referer}' => __('HTTP Referer URL', 'fluentform'),
24 '{user.ID}' => __('User ID', 'fluentform'),
25 '{user.display_name}' => __('User Display Name', 'fluentform'),
26 '{user.first_name}' => __('User First Name', 'fluentform'),
27 '{user.last_name}' => __('User Last Name', 'fluentform'),
28 '{user.user_email}' => __('User Email', 'fluentform'),
29 '{user.user_login}' => __('User Username', 'fluentform'),
30 '{browser.name}' => __('User Browser Client', 'fluentform'),
31 '{browser.platform}' => __('User Operating System', 'fluentform'),
32 '{random_string.your_prefix}' => __('Random String with Prefix', 'fluentform'),
33 ],
34 ];
35 }
36
37 public static function getFormShortCodes($form)
38 {
39 $form = static::getForm($form);
40 $formFields = FormFieldsParser::getShortCodeInputs(
41 $form,
42 [
43 'admin_label', 'attributes', 'options',
44 ]
45 );
46
47 $formShortCodes = [
48 'shortcodes' => [],
49 'title' => __('Input Options','fluentform')
50 ];
51
52 $formShortCodes['shortcodes']['{all_data}'] = 'All Submitted Data';
53 $formShortCodes['shortcodes']['{all_data_without_hidden_fields}'] = 'All Data Without Hidden Fields';
54 foreach ($formFields as $key => $value) {
55 $formShortCodes['shortcodes']['{inputs.' . $key . '}'] = $value['admin_label'];
56 }
57
58 $formShortCodes['shortcodes']['{form_title}'] = __('Form Title', 'fluentform');
59
60 return $formShortCodes;
61 }
62
63 public static function getFormLabelShortCodes($form)
64 {
65 $form = static::getForm($form);
66 $formFields = FormFieldsParser::getShortCodeInputs($form, ['admin_label', 'label',]);
67 $formLabelShortCodes = [
68 'shortcodes' => [],
69 'title' => __('Label Options','fluentform')
70 ];
71 foreach ($formFields as $key => $value) {
72 $formLabelShortCodes['shortcodes']['{labels.' . $key . '}'] = wp_strip_all_tags ($value['admin_label']);
73 }
74 return $formLabelShortCodes;
75 }
76
77 public static function getSubmissionShortcodes($form = false)
78 {
79 $submissionProperties = [
80 '{submission.id}' => __('Submission ID', 'fluentform'),
81 '{submission.serial_number}' => __('Submission Serial Number', 'fluentform'),
82 '{submission.source_url}' => __('Source URL', 'fluentform'),
83 '{submission.user_id}' => __('User Id', 'fluentform'),
84 '{submission.browser}' => __('Submitter Browser', 'fluentform'),
85 '{submission.device}' => __('Submitter Device', 'fluentform'),
86 '{submission.status}' => __('Submission Status', 'fluentform'),
87 '{submission.created_at}' => __('Submission Create Date', 'fluentform'),
88 '{submission.admin_view_url}' => __('Submission Admin View URL', 'fluentform'),
89 ];
90
91 if ($form) {
92 $form = static::getForm($form);
93 if ($form && $form->has_payment) {
94 $submissionProperties['{submission.currency}'] = __('Currency', 'fluentform');
95 $submissionProperties['{submission.payment_method}'] = __('Payment Method', 'fluentform');
96 $submissionProperties['{submission.payment_status}'] = __('Payment Status', 'fluentform');
97 $submissionProperties['{submission.total_paid}'] = __('Paid Total Amount', 'fluentform');
98 $submissionProperties['{submission.payment_total}'] = __('Payment Amount', 'fluentform');
99 }
100 }
101
102 $submissionShortcodes = [
103 'title' => __('Entry Attributes','fluentform'),
104 'shortcodes' => $submissionProperties,
105 ];
106
107 return apply_filters('fluentform/submission_shortcodes', $submissionShortcodes, $form);
108 }
109
110 public static function getPaymentShortcodes($form)
111 {
112 return [
113 'title' => __('Payment Details','fluentform'),
114 'shortcodes' => [
115 '{payment.receipt}' => __('Payment Receipt', 'fluentform'),
116 '{payment.summary}' => __('Payment Summary', 'fluentform'),
117 '{payment.order_items}' => __('Order Items Table', 'fluentform'),
118 '{payment.payment_status}' => __('Payment Status', 'fluentform'),
119 '{payment.payment_total}' => __('Payment Total', 'fluentform'),
120 '{payment.payment_method}' => __('Payment Method', 'fluentform'),
121 ],
122 ];
123 }
124
125 public static function getShortCodes($form)
126 {
127 $form = static::getForm($form);
128 $groups = [
129 static::getFormShortCodes($form),
130 static::getFormLabelShortCodes($form),
131 static::getGeneralShortCodes(),
132 static::getSubmissionShortcodes($form),
133 ];
134
135 if ($form->has_payment) {
136 $groups[] = static::getPaymentShortcodes($form);
137 }
138
139 $groups = apply_filters_deprecated(
140 'fluentform_form_settings_smartcodes', [
141 $groups,
142 $form
143 ],
144 FLUENTFORM_FRAMEWORK_UPGRADE,
145 'fluentform/form_settings_smartcodes',
146 'Use fluentform/form_settings_smartcodes instead of fluentform_form_settings_smartcodes.'
147 );
148
149 return apply_filters('fluentform/form_settings_smartcodes', $groups, $form);
150 }
151
152 public static function parse($string, $data, ?callable $arrayFormatter = null)
153 {
154 if (is_array($string)) {
155 return static::parseArray($string, $data, $arrayFormatter);
156 }
157
158 return static::parseString($string, $data, $arrayFormatter);
159 }
160
161 public static function parseArray($string, $data, $arrayFormatter)
162 {
163 foreach ($string as $key => $value) {
164 if (is_array($value)) {
165 $string[$key] = static::parseArray($value, $data, $arrayFormatter);
166 } else {
167 $string[$key] = static::parseString($value, $data, $arrayFormatter);
168 }
169 }
170
171 return $string;
172 }
173
174 public static function parseString($string, $data, ?callable $arrayFormatter = null)
175 {
176 return preg_replace_callback('/{+(.*?)}/', function ($matches) use (&$data, &$arrayFormatter) {
177 if (! isset($data[$matches[1]])) {
178 return $matches[0];
179 } elseif (is_array($value = $data[$matches[1]])) {
180 return is_callable($arrayFormatter) ? $arrayFormatter($value) : implode(', ', $value);
181 }
182 return $data[$matches[1]];
183 }, $string);
184 }
185
186 protected static function getForm($form)
187 {
188 if (is_object($form)) {
189 return $form;
190 }
191
192 return wpFluent()->table('fluentform_forms')->find($form);
193 }
194 }
195