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

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

164 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 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',
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 'admin_label', 'attributes', 'options'
43 ]);
44
45 $formShortCodes = [
46 'shortcodes' => [],
47 'title' => 'Input Options'
48 ];
49
50 $formShortCodes['shortcodes']['{all_data}'] = 'All Submitted Data';
51 $formShortCodes['shortcodes']['{all_data_without_hidden_fields}'] = 'All Data Without Hidden Fields';
52 foreach ($formFields as $key => $value) {
53 $formShortCodes['shortcodes']['{inputs.' . $key . '}'] = $value['admin_label'];
54 }
55
56 return $formShortCodes;
57 }
58
59 public static function getSubmissionShortcodes($form = false)
60 {
61 $submissionProperties = [
62 '{submission.id}' => __('Submission ID', 'fluentform'),
63 '{submission.serial_number}' => __('Submission Serial Number', 'fluentform'),
64 '{submission.source_url}' => __('Source URL', 'fluentform'),
65 '{submission.user_id}' => __('User Id', 'fluentform'),
66 '{submission.browser}' => __('Submitter Browser', 'fluentform'),
67 '{submission.device}' => __('Submitter Device', 'fluentform'),
68 '{submission.status}' => __('Submission Status', 'fluentform'),
69 '{submission.created_at}' => __('Submission Create Date', 'fluentform'),
70 '{submission.admin_view_url}' => __('Submission Admin View URL', 'fluentform')
71 ];
72
73 if ($form) {
74 $form = static::getForm($form);
75 if ($form && $form->has_payment) {
76 $submissionProperties['{submission.currency}'] = __('Currency', 'fluentform');
77 $submissionProperties['{submission.payment_method}'] = __('Payment Method', 'fluentform');
78 $submissionProperties['{submission.payment_status}'] = __('Payment Status', 'fluentform');
79 $submissionProperties['{submission.total_paid}'] = __('Paid Total Amount', 'fluentform');
80 $submissionProperties['{submission.payment_total}'] = __('Payment Amount', 'fluentform');
81 }
82 }
83
84 return [
85 'title' => 'Entry Attributes',
86 'shortcodes' => $submissionProperties
87 ];
88 }
89
90 public static function getPaymentShortcodes($form)
91 {
92 return [
93 'title' => 'Payment Details',
94 'shortcodes' => [
95 '{payment.receipt}' => __('Payment Receipt', 'fluentform'),
96 '{payment.summary}' => __('Payment Summary', 'fluentform'),
97 '{payment.order_items}' => __('Order Items Table', 'fluentform'),
98 '{payment.payment_status}' => __('Payment Status', 'fluentform'),
99 '{payment.payment_total}' => __('Payment Total', 'fluentform'),
100 '{payment.payment_method}' => __('Payment Method', 'fluentform'),
101 ]
102 ];
103 }
104
105 public static function getShortCodes($form)
106 {
107 $form = static::getForm($form);
108 $groups = [
109 static::getFormShortCodes($form),
110 static::getGeneralShortCodes(),
111 static::getSubmissionShortcodes($form)
112 ];
113
114 if ($form->has_payment) {
115 $groups[] = static::getPaymentShortcodes($form);
116 }
117
118 return apply_filters('fluentform_form_settings_smartcodes', $groups, $form);
119 }
120
121 public static function parse($string, $data, callable $arrayFormatter = null)
122 {
123 if (is_array($string)) {
124 return static::parseArray($string, $data, $arrayFormatter);
125 }
126
127 return static::parseString($string, $data, $arrayFormatter);
128 }
129
130 public static function parseArray($string, $data, $arrayFormatter)
131 {
132 foreach ($string as $key => $value) {
133 if (is_array($value)) {
134 $string[$key] = static::parseArray($value, $data, $arrayFormatter);
135 } else {
136 $string[$key] = static::parseString($value, $data, $arrayFormatter);
137 }
138 }
139
140 return $string;
141 }
142
143 public static function parseString($string, $data, callable $arrayFormatter = null)
144 {
145 return preg_replace_callback('/{+(.*?)}/', function ($matches) use (&$data, &$arrayFormatter) {
146 if (!isset($data[$matches[1]])) {
147 return $matches[0];
148 } elseif (is_array($value = $data[$matches[1]])) {
149 return is_callable($arrayFormatter) ? $arrayFormatter($value) : implode(', ', $value);
150 }
151 return $data[$matches[1]];
152 }, $string);
153 }
154
155 protected static function getForm($form)
156 {
157 if (is_object($form)) {
158 return $form;
159 }
160
161 return wpFluent()->table('fluentform_forms')->find($form);
162 }
163 }
164