PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / trunk
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress vtrunk
4.16.18 4.16.17 4.16.16 trunk 1.0 1.0.1 1.0.2 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5a 1.1.6 1.1.7 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4 1.4.1 1.4.2 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.7 1.7.1 1.7.2 1.8 1.8.1 1.8.10 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.1.9 2.2.10 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.2 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 3.0 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10.0 4.10.1 4.10.2 4.10.3 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.13.3 4.13.4 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.15.0 4.15.1 4.15.10 4.15.11 4.15.12 4.15.13 4.15.14 4.15.15 4.15.16 4.15.17 4.15.18 4.15.19 4.15.2 4.15.20 4.15.20.1 4.15.21 4.15.22 4.15.23 4.15.24 4.15.25 4.15.3 4.15.4 4.15.5 4.15.6 4.15.7 4.15.8 4.15.9 4.16.0 4.16.1 4.16.10 4.16.11 4.16.12 4.16.13 4.16.14 4.16.15 4.16.2 4.16.3 4.16.4 4.16.5 4.16.6 4.16.7 4.16.8 4.16.9 4.2.0 4.3.0 4.3.1 4.3.2 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.5.3 4.5.4 4.5.5 4.6.0 4.7.0 4.8.0 4.9.0
wp-user-avatar / src / Themes / DragDrop / FieldListing.php
wp-user-avatar / src / Themes / DragDrop Last commit date
EditProfile 5 years ago Login 3 years ago MemberDirectory 7 months ago PasswordReset 5 years ago Registration 3 years ago UserProfile 1 year ago AbstractBuildScratch.php 7 months ago AbstractMemberDirectoryTheme.php 4 months ago AbstractTheme.php 11 months ago FieldListing.php 7 months ago MemberDirectoryListing.php 2 months ago MemberDirectoryTrait.php 1 year ago ProfileFieldListing.php 2 months ago ThemeInterface.php 5 years ago ThemesRepository.php 1 year ago index.php 5 years ago
FieldListing.php
286 lines
1 <?php
2
3 namespace ProfilePress\Core\Themes\DragDrop;
4
5 use ProfilePress\Core\Classes\ExtensionManager as EM;
6 use ProfilePress\Core\Classes\FormRepository as FR;
7 use ProfilePress\Core\Classes\UserAvatar;
8 use ProfilePress\Libsodium\Recaptcha\Recaptcha;
9
10 class FieldListing
11 {
12 private $form_id;
13 private $form_type;
14 private $is_buildscratch;
15
16 private $field_settings = [];
17
18 private $defaults;
19
20 private $shortcode_field_wrap_start = '';
21
22 private $shortcode_field_wrap_end = '';
23
24 public function __construct($form_id, $form_type, $is_buildscratch = false)
25 {
26 $this->form_id = $form_id;
27 $this->form_type = $form_type;
28 $this->is_buildscratch = $is_buildscratch;
29
30 $field_settings = FR::get_form_meta($form_id, $form_type, FR::FORM_BUILDER_FIELDS_SETTINGS);
31 if ( ! empty($field_settings)) {
32 $this->field_settings = json_decode($field_settings, true);
33 }
34 }
35
36 public function shortcode_field_wrap_start($wrapper = '')
37 {
38 $this->shortcode_field_wrap_start = $wrapper;
39
40 return $this;
41 }
42
43 public function shortcode_field_wrap_end($wrapper = '')
44 {
45 $this->shortcode_field_wrap_end = $wrapper;
46
47 return $this;
48 }
49
50 public function defaults($defaults)
51 {
52 $this->defaults = $defaults;
53
54 return $this;
55 }
56
57 protected function is_field_required($field_setting)
58 {
59 $field_type = $field_setting['fieldType'];
60
61 // the str_replace sorcery checks if field type contains any of the strings https://stackoverflow.com/a/42311760/2648410
62 // we are using edit-profile-password and reg-password because we have other password custom fields that ends with -password
63 if (str_replace(['-username', 'reg-password', 'login-password', 'edit-profile-password', '-email'], '', $field_type) != $field_type) return true;
64
65 return isset($field_setting['required']) && ($field_setting['required'] === true || $field_setting['required'] == 'true' || $field_setting['required'] == '1');
66 }
67
68 protected function label_structure($field_setting, $field_id)
69 {
70 $field_type = $field_setting['fieldType'];
71
72 if ( ! in_array($field_type, ['login-remember']) && strpos($field_type, 'agreeable') === false && ! empty($field_setting['label'])) {
73 $output = sprintf('<div class="pp-form-label-wrap"><label for="%s" class="pp-form-label">', $field_id);
74 $output .= wp_kses_post($field_setting['label']);
75
76 if ($this->is_field_required($field_setting)) {
77 $output .= ' <span class="pp-form-required-label">*</span>';
78 }
79
80 if (isset($field_setting['description_appearance']) && $field_setting['description_appearance'] == 'tooltip' && ! empty($field_setting['description'])) {
81 $output .= sprintf(
82 ' <span class="ppress-hint-tooltip ppress-hint-wrap hint--top hint--medium hint--bounce" aria-label="%s"><i class="pp-form-material-icons">help</i></span>',
83 sanitize_text_field($field_setting['description'])
84 );
85 }
86
87 $output .= sprintf('</label></div>');
88
89 return $output;
90 }
91 }
92
93 public function is_avatar($field_type)
94 {
95 return $field_type == 'pp-user-avatar';
96 }
97
98 public function is_cover_image($field_type)
99 {
100 return $field_type == 'pp-user-cover-image';
101 }
102
103 public function is_recaptcha($field_type)
104 {
105 return $field_type == 'pp-recaptcha';
106 }
107
108 public function is_cloudflare_turnstile($field_type)
109 {
110 return $field_type == 'pp-turnstile';
111 }
112
113 public function is_recaptcha_v3($field_type)
114 {
115 return $this->is_recaptcha($field_type) && class_exists('ProfilePress\Libsodium\Recaptcha\Recaptcha') && Recaptcha::$type == 'v3';
116 }
117
118 public function forge()
119 {
120 $output = '';
121
122 foreach ($this->field_settings as $field_setting) {
123
124 $field_type = $field_setting['fieldType'];
125
126 if ($this->is_recaptcha($field_type) && ! EM::is_enabled(EM::RECAPTCHA)) continue;
127
128 if ($this->is_cloudflare_turnstile($field_type) && ! EM::is_enabled(EM::TURNSTILE)) continue;
129
130 if (isset($this->defaults, $this->defaults[$field_type])) {
131 $field_setting = wp_parse_args($field_setting, $this->defaults[$field_type]);
132 }
133
134 $raw_field_setting = $field_setting;
135
136 $pp_form_field_wrap_classes = '';
137
138 $field_with_class = 'full';
139 if ( ! empty($field_setting['field_width'])) {
140 $field_with_class = $field_setting['field_width'];
141 unset($field_setting['field_width']);
142 }
143
144 $pp_form_field_wrap_classes .= ' fw-' . esc_attr($field_with_class);
145
146 if ( ! empty($field_setting['icon'])) {
147 $pp_form_field_wrap_classes .= ' field-has-icon';
148 unset($field_setting['icon']);
149 }
150
151 if (isset($field_setting['password_visibility_icon']) && $field_setting['password_visibility_icon'] === true) {
152 $pp_form_field_wrap_classes .= ' has-password-visibility-icon';
153 unset($field_setting['password_visibility_icon']);
154 }
155
156 $description_appearance = 'standard';
157 if ( ! empty($field_setting['description_appearance'])) {
158 $description_appearance = $field_setting['description_appearance'];
159 unset($field_setting['description_appearance']);
160 }
161 $pp_form_field_wrap_classes .= ' fda-' . esc_attr($description_appearance);
162
163 $label_display = 'above';
164 if ( ! empty($field_setting['label_display'])) {
165 $label_display = $field_setting['label_display'];
166 unset($field_setting['label_display']);
167 }
168
169 $pp_form_field_wrap_classes .= ' fld-' . $label_display;
170
171 if ( ! $this->is_buildscratch) {
172 $pp_form_field_wrap_classes = '';
173 }
174
175 if ( ! $this->is_recaptcha_v3($field_type)) {
176 $output .= sprintf('<div class="pp-form-field-wrap %s%s">', str_replace('_', '-', $field_type), $pp_form_field_wrap_classes);
177 }
178
179 $field_setting = apply_filters("ppress_form_field_listing_setting_{$field_type}", $field_setting);
180
181 if (strpos($field_type, 'reg-cpf') !== false) {
182 $field_type = sprintf('reg-cpf key="%s"', $field_setting['definedFieldKey']);
183 unset($field_setting['definedFieldKey']);
184 unset($field_setting['definedFieldType']);
185 }
186
187 if (strpos($field_type, 'edit-profile-cpf') !== false) {
188 $field_type = sprintf('edit-profile-cpf key="%s"', $field_setting['definedFieldKey']);
189 unset($field_setting['definedFieldKey']);
190 unset($field_setting['definedFieldType']);
191 }
192
193 $field_id = $field_type;
194 if (isset($field_setting['key'])) {
195 $field_id .= '_' . $field_setting['key'];
196 }
197
198 $field_id = ppress_md5($field_id);
199
200 $output .= $this->label_structure($raw_field_setting, $field_id);
201
202 $field_description = $field_setting['description'] ?? '';
203
204 unset($field_setting['label']);
205 unset($field_setting['description']);
206 unset($field_setting['fieldBarTitle']);
207 unset($field_setting['fieldTitle']);
208 unset($field_setting['fieldType']);
209 unset($field_setting['fieldIcon']);
210 unset($field_setting['sortID']);
211
212 // add field class
213 $field_type_class = strpos($field_type, 'reg-cpf') !== false ? 'reg-cpf' : $field_type;
214 $field_type_class = strpos($field_type_class, 'edit-profile-cpf') !== false ? 'edit-profile-cpf' : $field_type_class;
215 $saved_classes = ' ' . $field_type_class;
216 if ( ! empty($field_setting['class'])) {
217 $saved_classes .= ' ' . $field_setting['class'];
218 }
219
220 $field_setting['class'] = "pp-form-field{$saved_classes}";
221
222 if ($this->is_recaptcha($field_type) || $this->is_cloudflare_turnstile($field_type) || $this->is_avatar($field_type) || $this->is_cover_image($field_type)) {
223 $field_setting['class'] = $saved_classes;
224 }
225
226 $attributes = sprintf('id="%s" ', $field_id);
227
228 foreach ($field_setting as $key => $value) {
229 // the str_replace sorcery/ritual checks if field type contains any of the strings https://stackoverflow.com/a/42311760/2648410
230 if ($key == 'options' && str_replace(['-select-dropdown', '-checkbox-list', '-radio-buttons'], '', $field_type) != $field_type) {
231 /** @source https://stackoverflow.com/a/3997367/2648410 */
232 $value = array_map('trim', preg_split('/\r\n|\r|\n/', $value, -1, PREG_SPLIT_NO_EMPTY));
233 $value = implode(',', $value);
234 }
235
236 $val = esc_attr($value);
237 //do not escape custom HTML
238 if ($key == 'custom_html') {
239 $val = base64_encode($value);
240 }
241
242 $attributes .= $key . "='" . $val . "' ";
243 }
244
245 $output .= $this->shortcode_field_wrap_start;
246
247 if ($this->is_avatar($field_type)) {
248 $output .= sprintf('<div class="pp-field-user-avatar-picture-wrap" style="width:%s">', esc_attr($field_setting['size']) . 'px');
249 }
250
251 if ($this->is_cover_image($field_type)) {
252 $output .= '<div class="pp-field-user-cover-image-wrap">';
253 }
254
255 $output .= apply_filters("ppress_form_field_listing_$field_type", '[' . $field_type . ' ' . $attributes . ']', $raw_field_setting, $this->form_id, $this->form_type);
256
257 if ($this->is_avatar($field_type) && UserAvatar::user_has_pp_avatar(get_current_user_id())) {
258 $output .= '<span class="pp-profile-avatar-overlay-wrap"><span class="pp-profile-avatar-overlay"><ins><i class="pp-form-material-icons pp-del-profile-avatar">delete</i></ins></span></span>';
259 }
260
261 if ($this->is_cover_image($field_type) && ppress_user_has_cover_image()) {
262 $output .= '<span class="pp-cover-image-overlay-wrap"><span class="pp-cover-image-overlay"><ins><i class="pp-form-material-icons pp-del-cover-image">delete</i></ins></span></span>';
263 }
264
265 if ($this->is_avatar($field_type) || $this->is_cover_image($field_type)) {
266 $output .= '</div>';
267 }
268
269 $output .= apply_filters('ppress_form_after_field_listing', '', $raw_field_setting, $this->form_id, $this->form_type);
270 if ( ! empty($field_description)) {
271 $output .= '<div class="pp-form-field-description">';
272 $output .= wp_kses_post($field_description);
273 $output .= '</div>';
274 }
275
276 $output .= $this->shortcode_field_wrap_end;
277
278 if ( ! $this->is_recaptcha_v3($field_type)) {
279 $output .= '</div>';
280 }
281 }
282
283 return $output;
284 }
285 }
286