PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.11.3
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.11.3
1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 1.7.0.9 All 211 releases
charitable / includes / admin / campaign-builder / fields / class-organizer.php

class-organizer.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.11.3, at includes/admin/campaign-builder/fields/class-organizer.php

502 lines 18.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class to add organizer field to a campaign form in the builder.
4 *
5 * @package Charitable
6 * @author David Bisset
7 * @copyright Copyright (c) 2023, WP Charitable LLC
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.8.0
10 * @version 1.8.9.1
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 if ( ! class_exists( 'Charitable_Field_Organizer' ) ) :
18
19 /**
20 * Class to add campaign organizer field to a campaign form in the builder.
21 */
22 class Charitable_Field_Organizer extends Charitable_Builder_Field {
23
24 /**
25 * Primary class constructor.
26 *
27 * @since 1.8.0
28 */
29 public function init() {
30
31 // Define field type information.
32 $this->name = esc_html__( 'Organizer', 'charitable' );
33 $this->type = 'organizer';
34 $this->icon = 'fa-user';
35 $this->order = 30;
36
37 $this->align_default = 'left';
38
39 // Edit/Duplication information.
40 $this->edit_label = esc_html__( 'Edit Organizer', 'charitable' );
41 $this->edit_type = 'organizer';
42 $this->edit_section = 'standard';
43 $this->can_be_edited = true;
44 $this->can_be_deleted = true;
45 $this->can_be_duplicated = true;
46
47 // Misc.
48 $this->tooltip = '';
49
50 // Define additional field properties.
51 add_action( 'charitable_builder_frontend_js', [ $this, 'frontend_js' ] );
52 add_action( 'charitable_builder_backend_scripts', [ $this, 'builder_js' ] );
53 }
54
55 /**
56 * Organizer options panel inside the builder.
57 *
58 * @since 1.8.0
59 *
60 * @param array $field Organizer settings.
61 */
62 public function field_options( $field ) {
63 /*
64 * Basic field options.
65 */
66
67 // Options open markup.
68 }
69
70 /**
71 * Render the field.
72 *
73 * @since 1.8.0
74 * @version 1.1.8.16 added 'charitable_campaign_builder_organizer_image' filter.
75 *
76 * @param array $field_data Any field data.
77 * @param array $campaign_data Amount data and settings.
78 * @param integer $field_id The field ID.
79 * @param string $mode Where the field is being displayed ("preview" or "template").
80 * @param array $template_data Tempalate data.
81 */
82 public function render( $field_data = false, $campaign_data = false, $field_id = false, $mode = 'template', $template_data = false ) {
83
84 if ( 'preview' === $mode ) {
85
86 // Define data.
87 $campaign_creator_id = ! empty( $campaign_data['settings']['general']['campaign_creator_id'] ) ? intval( $campaign_data['settings']['general']['campaign_creator_id'] ) : false;
88 if ( false === $campaign_creator_id && ! empty( $campaign_data['id'] ) ) {
89 $campaign_post = get_post( intval( $campaign_data['id'] ) );
90 $campaign_creator_id = ! empty( $campaign_post->post_author ) ? $campaign_post->post_author : false;
91 }
92 $campaign_creator_id = ( false === $campaign_creator_id ) ? get_current_user_id() : $campaign_creator_id;
93
94 $image_url = apply_filters( 'charitable_campaign_builder_organizer_image', esc_url( get_avatar_url( $campaign_creator_id ) ), $campaign_creator_id, $campaign_data );
95 $creator_name = $this->get_creator_data( $campaign_creator_id );
96 $role_or_title = ! empty( $field_data['role_or_title'] ) ? esc_html( $field_data['role_or_title'] ) : 'Organizer';
97 $organizer_content = ! empty( $field_data['content'] ) ? $this->format( $field_id, $field_data['content'], $campaign_data ) : '';
98
99 $image_bg_css = ( $image_url ) ? ' style="background-image: url(' . esc_url( $image_url ) . ');"' : false;
100
101 return '<div class="charitable-organizer-container">
102 <div class="charitable-organizer-image-column">
103 <div class="charitable-organizer-image" ' . $image_bg_css . '></div>
104 </div>
105 <div class="charitable-organizer-info">
106 <div class="charitable-organizer-name">' . esc_html( $creator_name ) . '</div>
107 <div class="charitable-organizer-title charitable-main-placeholder"><h5 class="charitable-field-preview-headline">' . $role_or_title . '</h5></div>
108 <div class="charitable-organizer-description">' . ( $organizer_content ) . '</div>
109 </div>
110 </div>';
111
112 } else {
113
114 // Define data.
115 $campaign_creator_id = ! empty( $campaign_data['settings']['general']['campaign_creator_id'] ) ? intval( $campaign_data['settings']['general']['campaign_creator_id'] ) : false;
116 if ( false === $campaign_creator_id && ! empty( $campaign_data['id'] ) ) {
117 $campaign_post = get_post( intval( $campaign_data['id'] ) );
118 $campaign_creator_id = ! empty( $campaign_post->post_author ) ? $campaign_post->post_author : false;
119 }
120 $campaign_creator_id = ( false === $campaign_creator_id ) ? get_current_user_id() : $campaign_creator_id;
121
122 $image_url = apply_filters( 'charitable_campaign_builder_organizer_image', esc_url( get_avatar_url( $campaign_creator_id ) ), $campaign_creator_id, $campaign_data );
123 $creator_name = $this->get_creator_data( $campaign_creator_id );
124 $role_or_title = ! empty( $field_data['role_or_title'] ) ? esc_html( $field_data['role_or_title'] ) : 'Organizer';
125 $organizer_content = ! empty( $field_data['content'] ) ? trim( $field_data['content'] ) : '';
126
127 $image_bg_css = ( $image_url ) ? ' style="background-image: url(' . esc_url( $image_url ) . ');"' : false;
128
129 return '<div class="charitable-organizer-container">
130 <div class="charitable-organizer-image-column">
131 <div class="charitable-organizer-image" ' . $image_bg_css . '></div>
132 </div>
133 <div class="charitable-organizer-info">
134 <div class="charitable-organizer-name">' . esc_html( $creator_name ) . '</div>
135 <div class="charitable-organizer-title charitable-main-placeholder"><h5 class="charitable-field-template-headline">' . $role_or_title . '</h5></div>
136 <div class="charitable-organizer-description">' . $this->format( $field_id, $organizer_content, $campaign_data ) . '</div>
137 </div>
138 </div>';
139
140 }
141 }
142
143 /**
144 * Organizer preview inside the builder.
145 *
146 * @since 1.8.0
147 *
148 * @param array $field_data Field data and settings.
149 * @param array $campaign_data Campaign data and settings.
150 * @param array $field_id Field ID.
151 * @param string $theme Template data.
152 */
153 public function field_preview( $field_data = false, $campaign_data = false, $field_id = false, $theme = '' ) {
154
155 $html = $this->field_title( $this->name );
156 $html .= $this->field_wrapper( $this->render( $field_data, $campaign_data, $field_id, 'preview' ), $field_data );
157
158 echo $html; // phpcs:ignore
159 }
160
161 /**
162 * Organizer display on the form front-end.
163 *
164 * @since 1.8.0
165 *
166 * @param string $field_type Field Type.
167 * @param array $field_data Deprecated.
168 * @param array $campaign_data Form data and settings.
169 */
170 public function field_display( $field_type = '', $field_data = false, $campaign_data = false ) {
171
172 $html = $this->field_display_wrapper( $this->render( $field_data, $campaign_data ), $field_data );
173
174 echo apply_filters( 'charitable_campaign_builder_' . $this->type . '_field_display', $html, $campaign_data ); // phpcs:ignore
175 }
176
177 /**
178 * Organizer display on the form front-end.
179 *
180 * @since 1.8.0
181 *
182 * @param array $field_id Field id.
183 * @param array $campaign_data Form data and settings.
184 */
185 public function settings_display( $field_id = false, $campaign_data = false ) {
186
187 $charitable_builder_form_fields = new Charitable_Builder_Form_Fields();
188
189 $settings = isset( $campaign_data['fields'][ $field_id ] ) ? $campaign_data['fields'][ $field_id ] : false;
190
191 // special check - if "default" is just a filename, readjust the default to a full url.
192 if ( ! empty( $settings['default'] ) && ! empty( $campaign_data['template_id'] ) ) {
193 $default_basename = basename( $settings['default'] );
194 if ( $default_basename === $settings['default'] ) {
195 $settings['default'] = charitable()->get_path( 'assets', false ) . 'images/campaign-builder/templates/' . $campaign_data['template_id'] . '/' . $default_basename;
196 }
197 }
198
199 ob_start();
200
201 ?>
202
203 <h4 class="charitable-panel-field" data-field-id="<?php echo intval( $field_id ); ?>"><?php echo esc_html( $this->name ); ?> (ID: <?php echo intval( $field_id ); ?>)</h4>
204
205 <?php
206
207 echo $charitable_builder_form_fields->generate_text( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
208 isset( $settings['role_or_title'] ) ? $settings['role_or_title'] : esc_html__( 'Organizer', 'charitable' ),
209 esc_html__( 'Role or Title', 'charitable' ),
210 array(
211 'id' => 'field_' . esc_attr( $this->type ) . '_role_or_title' . '_' . intval( $field_id ), // phpcs:ignore
212 'name' => array( '_fields', intval( $field_id ), 'role_or_title' ),
213 'field_id' => intval( $field_id ),
214 'tooltip' => esc_html__( 'Add a headline to this field.', 'charitable' ),
215 'class' => 'charitable-campaign-builder-headline',
216 )
217 );
218
219 $campaign_creator_id = ! empty( $campaign_data['settings']['general']['campaign_creator_id'] ) ? intval( $campaign_data['settings']['general']['campaign_creator_id'] ) : false;
220
221 $users = apply_filters( 'charitable_allowed_campaign_creators', [] );
222 if ( empty( $users ) ) {
223 $users = get_users();
224 }
225 foreach ( $users as $user ) {
226 $users_to_pass[ $user->data->ID ] = array(
227 'avatar' => esc_url( get_avatar_url( $user->data->ID ) ),
228 'text' => ( '' . charitable_get_creator_data( $user->data->ID ) ),
229 'meta' => '&nbsp;( ID: ' . $user->data->ID . ' )&nbsp;Joined: ' . gmdate( 'M d, Y ', strtotime( $user->data->user_registered ) ) . ' ',
230 );
231 }
232
233 echo $charitable_builder_form_fields->generate_user_dropdown_mini( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
234 $campaign_data,
235 esc_html__( 'Campaign Creator', 'charitable' ),
236 array(
237 'from' => 'field',
238 'id' => 'field_' . esc_attr( $this->type ) . '_campaign_creator' . '_' . intval( $field_id ), // phpcs:ignore
239 'name' => array( '_fields', intval( $field_id ), 'campaign_creator' ),
240 'field_id' => esc_attr( $field_id ),
241 'default' => get_current_user_id(), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
242 'options' => $users_to_pass, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
243 'selected_value' => intval( $campaign_creator_id ),
244 'container_class' => 'campaign-builder-campaign-creator-id-mini',
245 )
246 );
247
248 echo $charitable_builder_form_fields->generate_textbox( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
249 isset( $settings['content'] ) ? $settings['content'] : false,
250 esc_html__( 'Organizer Description', 'charitable' ),
251 array(
252 'id' => 'field_' . esc_attr( $this->type ) . '_html' . '_' . intval( $field_id ), // phpcs:ignore
253 'name' => array( '_fields', intval( $field_id ), 'content' ),
254 'field_id' => esc_attr( $field_id ),
255 'tooltip' => esc_html( $this->tooltip ),
256 'class' => 'campaign-builder-htmleditor',
257 'rows' => 30,
258 'html' => true,
259 'code' => false,
260 'container_class' => 'campaign-builder-campaign-creator-description',
261 'special' => 'organizer_content',
262 )
263 );
264
265 echo $charitable_builder_form_fields->generate_number_slider( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
266 isset( $settings['width_percentage'] ) ? $settings['width_percentage'] : 100,
267 esc_html__( 'Width', 'charitable' ),
268 array(
269 'id' => 'field_' . esc_attr( $this->type ) . '_width_percentage' . '_' . intval( $field_id ), // phpcs:ignore
270 'name' => array( '_fields', intval( $field_id ), 'width_percentage' ),
271 'field_type' => esc_attr( $this->type ),
272 'field_id' => intval( $field_id ),
273 'symbol' => '%',
274 'min' => 0,
275 'min_actual' => 40,
276 'css_class' => 'charitable-indicator-on-hover',
277 'tooltip' => esc_html__( 'Adjust the width of the field within the column.', 'charitable' ),
278 )
279 );
280
281 echo $charitable_builder_form_fields->generate_align( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
282 isset( $settings['align'] ) ? $settings['align'] : esc_attr( $this->align_default ),
283 esc_html__( 'Align', 'charitable' ),
284 array(
285 'id' => 'field_' . esc_attr( $this->type ) . '_align' . '_' . intval( $field_id ), // phpcs:ignore
286 'name' => array( '_fields', intval( $field_id ), 'align' ),
287 'field_id' => intval( $field_id ),
288 )
289 );
290
291 echo $charitable_builder_form_fields->generate_text( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
292 isset( $settings['css_class'] ) ? $settings['css_class'] : false,
293 esc_html__( 'CSS Class', 'charitable' ),
294 array(
295 'id' => 'field_' . esc_attr( $this->type ) . '_css_class' . '_' . intval( $field_id ), // phpcs:ignore
296 'name' => array( '_fields', intval( $field_id ), 'css_class' ),
297 'field_id' => intval( $field_id ),
298 'tooltip' => esc_html__( 'Add CSS classes (seperated by a space) for this field to customize it\'s appearance in your theme.', 'charitable' ),
299 )
300 );
301
302 $html = ob_get_clean();
303
304 return $html;
305 }
306
307 /**
308 * Return HTML for display via ajax.
309 *
310 * @since 1.8.0
311 */
312 public function settings_display_ajax() {
313
314 $field_id = isset( $_POST['field_id'] ) ? intval( $_POST['field_id'] ) : false; // phpcs:ignore
315 $campaign_id = isset( $_POST['campaign_id'] ) ? intval( $_POST['campaign_id'] ) : false; // phpcs:ignore
316
317 if ( false === $field_id ) {
318 return;
319 }
320
321 $charitable_builder_form_fields = new Charitable_Builder_Form_Fields();
322
323 $campaign_data = get_post_meta( $campaign_id, 'campaign_settings_v2', true );
324 $settings = isset( $campaign_data['fields'][ $field_id ] ) ? $campaign_data['fields'][ $field_id ] : false;
325
326 ob_start();
327
328 ?>
329
330 <?php
331
332 echo $charitable_builder_form_fields->generate_number_slider( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
333 isset( $settings['width_percentage'] ) ? $settings['width_percentage'] : 100,
334 esc_html__( 'Width', 'charitable' ),
335 array(
336 'id' => 'field_' . esc_attr( $this->type ) . '_width_percentage' . '_' . intval( $field_id ), // phpcs:ignore
337 'name' => array( '_fields', intval( $field_id ), 'width_percentage' ),
338 'field_type' => esc_attr( $this->type ),
339 'field_id' => intval( $field_id ),
340 'symbol' => '%',
341 'min' => 10,
342 'tooltip' => esc_html__( 'Adjust the width of the field within the column.', 'charitable' ),
343 )
344 );
345
346 echo $charitable_builder_form_fields->generate_align( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
347 isset( $settings['align'] ) ? $settings['align'] : false,
348 esc_html__( 'Align', 'charitable' ),
349 array(
350 'id' => 'field_' . esc_attr( $this->type ) . '_align' . '_' . intval( $field_id ), // phpcs:ignore
351 'name' => array( '_fields', intval( $field_id ), 'align' ),
352 'field_id' => intval( $field_id ),
353 )
354 );
355
356 echo $charitable_builder_form_fields->generate_text( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
357 $settings['css_class'],
358 esc_html__( 'CSS Class', 'charitable' ),
359 array(
360 'id' => 'field_' . esc_attr( $this->type ) . '_css_class',
361 'name' => array( 'fields', esc_attr( $this->type ), 'css_class' ),
362 'tooltip' => esc_html( $this->tooltip ),
363 )
364 );
365
366 ?>
367
368 <?php
369
370 $html = ob_get_clean();
371
372 wp_send_json_success( [ 'html' => $html ] );
373
374 exit;
375 }
376
377 /**
378 * Enqueue frontend limit option js.
379 *
380 * @since 1.8.0
381 *
382 * @param string $min The suffix, if any, to include for the minified version.
383 */
384 public function builder_js( $min = '' ) {
385 }
386
387 /**
388 * Enqueue frontend limit option js.
389 *
390 * @since 1.8.0
391 *
392 * @param string $min The suffix, if any, to include for the minified version.
393 */
394 public function frontend_js( $min = '' ) {
395 }
396
397 /**
398 * Format and sanitize field.
399 *
400 * @since 1.8.0
401 *
402 * @param int $field_id Field type.
403 * @param mixed $field_submit Field value that was submitted.
404 * @param array $campaign_data Campaign data and settings.
405 */
406 public function format( $field_id, $field_submit, $campaign_data ) {
407
408 $allowed_html_tags = apply_filters(
409 'charitable_campaign_builder_html_allowed_tags',
410 array(
411 'a' => [
412 'href' => [],
413 'class' => [],
414 'target' => [],
415 ],
416 'p' => [
417 'class' => [],
418 ],
419 'span' => [
420 'class' => [],
421 ],
422 'div' => [
423 'class' => [],
424 ],
425 'strong' => [
426 'class' => [],
427 ],
428 'em' => [
429 'class' => [],
430 ],
431 'b' => [
432 'class' => [],
433 ],
434 'i' => [
435 'class' => [],
436 ],
437 'h1' => [
438 'class' => [],
439 ],
440 'h2' => [
441 'class' => [],
442 ],
443 'h3' => [
444 'class' => [],
445 ],
446 'h4' => [
447 'class' => [],
448 ],
449 'h5' => [
450 'class' => [],
451 ],
452 'h6' => [
453 'class' => [],
454 ],
455 ),
456 $campaign_data
457 );
458
459 return wp_kses( $field_submit, $allowed_html_tags );
460 }
461
462 /**
463 * Validate field on form submit.
464 *
465 * @since 1.8.0
466 *
467 * @param int $field Field.
468 * @param mixed $field_data Field data.
469 * @param array $campaign_data Form data and settings.
470 */
471 public function validate( $field, $field_data = false, $campaign_data = false ) {
472 }
473
474 /**
475 * Get the creator data.
476 *
477 * @since 1.8.0
478 *
479 * @param int|null $user_id The user ID.
480 *
481 * @return string The creator data.
482 */
483 public function get_creator_data( $user_id = null ) {
484
485 $user_info = $user_id ? new WP_User( $user_id ) : wp_get_current_user();
486
487 if ( $user_info->first_name ) {
488
489 if ( $user_info->last_name ) {
490 return $user_info->first_name . ' ' . $user_info->last_name;
491 }
492
493 return $user_info->first_name;
494 }
495
496 return $user_info->display_name;
497 }
498 }
499
500 new Charitable_Field_Organizer();
501
502 endif;