PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.13.1
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.13.1
1.8.13.1 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 All 212 releases
charitable / includes / admin / campaign-builder / fields / class-donor-wall.php

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

599 lines 20.4 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 donation wall 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.0
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 if ( ! class_exists( 'Charitable_Field_Donation_Wall' ) ) :
18
19 /**
20 * Class to add campaign donation wall to a campaign form in the builder.
21 */
22 class Charitable_Field_Donation_Wall extends Charitable_Builder_Field {
23
24 /**
25 * Primary class constructor.
26 *
27 * @since 1.8.0
28 */
29 public function init() {
30
31 // Basic inwallation.
32 $this->name = esc_html__( 'Donation Wall', 'charitable' );
33 $this->type = 'donation-wall';
34 $this->icon = 'fa fa-user';
35 $this->order = 100;
36 $this->group = 'pro';
37
38 $this->align_default = 'center';
39
40 // Edit/Duplication inwallation.
41 $this->can_be_edited = true;
42 $this->can_be_deleted = true;
43 $this->can_be_duplicated = true;
44 $this->edit_label = esc_html__( 'Edit Donation Wall', 'charitable' );
45 $this->edit_type = 'donation-wall';
46 $this->edit_section = 'pro';
47
48 // Misc.
49 $this->tooltip = '';
50
51 // Define additional field properties.
52 add_action( 'charitable_frontend_js', [ $this, 'frontend_js' ] );
53 add_action( 'charitable_builder_backend_scripts', [ $this, 'builder_js' ] ); // admin_enqueue_scripts.
54
55 // Defaults.
56 add_filter( 'charitable_field_new_default', [ $this, 'new_field_defaults' ] );
57 }
58
59 /**
60 * Field options panel inside the builder.
61 *
62 * @since 1.8.0
63 *
64 * @param array $field Field settings.
65 */
66 public function field_options( $field ) {
67 /*
68 * Basic field options.
69 */
70
71 // Options open markup.
72 }
73
74 /**
75 * Set default values for a new field.
76 *
77 * @since 1.8.0
78 *
79 * @param array $field The field settings.
80 * @return array
81 */
82 public function new_field_defaults( $field ) {
83
84 if ( isset( $field['type'] ) && 'donation-wall' !== $field['type'] ) {
85 return $field;
86 }
87
88 $field['show_name'] = 'show_name';
89 $field['show_amount'] = 'show_amount';
90 $field['show_avatar'] = 'show_avatar';
91
92 return $field;
93 }
94
95 /**
96 * Render the field.
97 *
98 * @since 1.8.0
99 *
100 * @param array $field_data Any field data.
101 * @param array $campaign_data Amount data and settings.
102 * @param integer $field_id The field ID.
103 * @param string $mode Where the field is being displayed ("preview" or "template").
104 * @param array $template_data Tempalate data.
105 */
106 public function render( $field_data = false, $campaign_data = false, $field_id = false, $mode = 'template', $template_data = false ) {
107
108 $html = '';
109
110 if ( 'preview' === $mode ) {
111
112 if ( false === $field_data || ! is_array( $field_data ) ) {
113 $field_data = array();
114 }
115
116 $field_data['show_name'] = ( empty( $field_data['show_name'] ) ) ? 0 : 1;
117 $field_data['show_location'] = ( empty( $field_data['show_location'] ) ) ? 0 : 1;
118 $field_data['show_amount'] = ( empty( $field_data['show_amount'] ) ) ? 0 : 1;
119 $field_data['show_avatar'] = ( empty( $field_data['show_avatar'] ) ) ? 0 : 1;
120
121 $field_data['show_name'] = ( isset( $field_data['show_hide']['show_name'] ) && 'show_name' === $field_data['show_hide']['show_name'] ) ? 1 : $field_data['show_name'];
122 $field_data['show_location'] = ( isset( $field_data['show_hide']['show_location'] ) && 'show_location' === $field_data['show_hide']['show_location'] ) ? 1 : $field_data['show_location'];
123 $field_data['show_amount'] = ( isset( $field_data['show_hide']['show_amount'] ) && 'show_amount' === $field_data['show_hide']['show_amount'] ) ? 1 : $field_data['show_amount'];
124 $field_data['show_avatar'] = ( isset( $field_data['show_hide']['show_avatar'] ) && 'show_avatar' === $field_data['show_hide']['show_avatar'] ) ? 1 : $field_data['show_avatar'];
125
126 $defaults = array(
127 'number' => 10,
128 'orderby' => 'date',
129 'order' => 'DESC',
130 'campaign_id' => ! empty( $campaign_data['id'] ) ? intval( $campaign_data['id'] ) : 0,
131 'campaign' => ! empty( $campaign_data['id'] ) ? intval( $campaign_data['id'] ) : 0,
132 'distinct_donors' => 0,
133 'orientation' => 'horizontal',
134 'show_name' => 1,
135 'show_location' => 0,
136 'show_amount' => 1,
137 'show_avatar' => 1,
138
139 'hide_if_no_donors' => 0,
140 'builder_preview' => 1,
141 );
142
143 $params = apply_filters( 'charitable_campaign_builder_donation_wall_args', array_replace_recursive( $defaults, $field_data ), $field_data, $campaign_data );
144
145 $shortcode_args = '';
146
147 /*
148 * Both branches must neutralise the value, because this string is handed to
149 * do_shortcode() below (1.8.13.1).
150 *
151 * An integer-typed default was previously interpolated raw and UNQUOTED, so a
152 * value like `1] [some_other_shortcode] [x` closed the charitable_donors tag and
153 * had do_shortcode() execute whatever came next. intval() makes that impossible
154 * for the numeric keys, and esc_attr() closes the quoted branch.
155 *
156 * Note the branch tests the DEFAULT's type while interpolating the value from
157 * $params, which is seeded from request data and has been through the
158 * charitable_campaign_builder_donation_wall_args filter -- so the type of what is
159 * actually interpolated is not guaranteed by the branch it took, and neither
160 * branch can be trusted.
161 */
162 foreach ( $defaults as $name => $value ) {
163
164 if ( is_integer( $value ) ) {
165 $shortcode_args .= $name . '=' . intval( $params[ $name ] ) . ' ';
166 } else {
167 $shortcode_args .= $name . '="' . esc_attr( $params[ $name ] ) . '" ';
168 }
169 }
170
171 $show_hide_args = array( 'show_name', 'show_location', 'show_amount', 'show_avatar' );
172
173 foreach ( $show_hide_args as $show_hide_arg ) {
174
175 if ( ! empty( $field_data[ $show_hide_arg ] ) && 0 === intval( $field_data[ $show_hide_arg ] ) ) {
176 $shortcode_args .= ' ' . $show_hide_arg . '=0';
177 } elseif ( ! empty( $field_data[ $show_hide_arg ] ) && 1 === intval( $field_data[ $show_hide_arg ] ) ) {
178 $shortcode_args .= ' ' . $show_hide_arg . '=1';
179 } elseif ( empty( $field_data[ $show_hide_arg ] ) ) {
180 $shortcode_args .= ' ' . $show_hide_arg . '=0';
181 }
182 }
183
184 $html = '<div class="charitable-field-preview-html donation-wall charitable-prevent-select" data-field-type="' . $this->type . '">
185 <span class="charitable-field-donation-wall-placeholder charitable-placeholder">';
186
187 $html .= ! empty( $field_data['headline'] ) ? '<h5 class="charitable-field-preview-headline">' . esc_html( $field_data['headline'] ) . '</h5>' : '';
188
189 $html .= do_shortcode( '[charitable_donors ' . $shortcode_args . ' ]' );
190
191 $html .= ' </span>
192 </div>';
193
194 return $html;
195
196 }
197
198 return $html;
199 }
200
201
202 /**
203 * Donation Wall preview inside the builder.
204 *
205 * @since 1.8.0
206 *
207 * @param array $field_data Field data and settings.
208 * @param array $campaign_data Campaign data and settings.
209 * @param array $field_id Field ID.
210 * @param string $theme Template data.
211 */
212 public function field_preview( $field_data = false, $campaign_data = false, $field_id = false, $theme = '' ) {
213
214 $html = $this->field_title( $this->name );
215 $html .= $this->field_wrapper( $this->render( $field_data, $campaign_data, $field_id, 'preview' ), $field_data );
216
217 echo $html; // phpcs:ignore
218 }
219
220 /**
221 * The display on the campaign front-end.
222 *
223 * @since 1.8.0
224 *
225 * @param string $field The passed field type.
226 * @param array $field_data Any field data.
227 * @param array $campaign_data Wall data and settings.
228 */
229 public function field_display( $field, $field_data = false, $campaign_data = false ) {
230
231 $campaign_id = isset( $campaign_data['id'] ) && 0 !== intval( $campaign_data['id'] ) ? intval( $campaign_data['id'] ) : false;
232 $css_class = ! empty( $field_data['css_class'] ) ? ' class="' . esc_html( $field_data['css_class'] ) . '" ' : '';
233 $headline = ! empty( $field_data['headline'] ) ? '<h5 class="charitable-field-template-headline">' . esc_html( $field_data['headline'] ) . '</h5>' : '';
234
235 if ( 0 === intval( $campaign_id ) ) {
236 return;
237 }
238
239 ob_start();
240
241 ?>
242 <?php echo $headline; // phpcs:ignore
243 ?>
244 <div class="charitable-campaign-field charitable-campaign-field_<?php echo esc_attr( $this->type ); ?>">
245 <div <?php echo esc_attr( $css_class ); ?>>
246
247 <?php
248
249 $defaults = array(
250 'number' => 10,
251 'orderby' => 'date',
252 'order' => 'DESC',
253 'campaign_id' => $campaign_id,
254 'campaign' => $campaign_id,
255 'distinct_donors' => 0,
256 'orientation' => 'horizontal',
257 'hide_if_no_donors' => 0,
258 );
259
260 $params = apply_filters( 'charitable_campaign_builder_donation_wall_args', array_replace_recursive( $defaults, $field_data ), $field_data, $campaign_data );
261
262 $shortcode_args = '';
263
264 /*
265 * Same neutralisation as the loop in render() above (1.8.13.1). This is
266 * the FRONT-END display path rather than the builder preview, fed from
267 * saved campaign data rather than $_POST, so the injection here is stored
268 * rather than reflected: whoever could save the campaign chooses the
269 * value, and it executes for every public visitor to the campaign page.
270 *
271 * Worth noting that Pro fixed only its render() copy in a8f1d3d00a and
272 * left its equivalent of this loop raw, so Pro still needs this half.
273 */
274 foreach ( $defaults as $name => $value ) {
275
276 if ( is_integer( $value ) ) {
277 $shortcode_args .= $name . '=' . intval( $params[ $name ] ) . ' ';
278 } else {
279 $shortcode_args .= $name . '="' . esc_attr( $params[ $name ] ) . '" ';
280 }
281 }
282
283 $show_hide_args = array( 'show_name', 'show_location', 'show_amount', 'show_avatar' );
284
285 foreach ( $show_hide_args as $show_hide_arg ) {
286
287 if ( ! isset( $field_data['show_hide'][ $show_hide_arg ] ) || empty( $field_data['show_hide'][ $show_hide_arg ] ) ) {
288 $shortcode_args .= ' ' . $show_hide_arg . '=0';
289 } elseif ( ! empty( $field_data['show_hide'][ $show_hide_arg ] ) ) {
290 $shortcode_args .= ' ' . $show_hide_arg . '=1';
291 } elseif ( empty( $field_data['show_hide'][ $show_hide_arg ] ) ) {
292 $shortcode_args .= ' ' . $show_hide_arg . '=0';
293 }
294 }
295
296 echo do_shortcode( '[charitable_donors ' . $shortcode_args . ' ]' );
297
298 ?>
299 </div>
300 </div>
301
302 <?php
303
304 $final_html = ob_get_clean();
305
306 $html = $this->field_display_wrapper( $final_html, $field_data );
307
308 echo apply_filters( 'charitable_campaign_builder_' . $this->type . '_field_display', $html, $campaign_data ); // phpcs:ignore
309 }
310
311 /**
312 * Donation Wall display on the form front-end.
313 *
314 * @since 1.8.0
315 *
316 * @param integer $field_id Number ID.
317 * @param array $campaign_data Wall data and settings.
318 */
319 public function settings_display( $field_id = false, $campaign_data = false ) {
320
321 $charitable_builder_form_fields = new Charitable_Builder_Form_Fields();
322
323 $settings = isset( $campaign_data['fields'][ $field_id ] ) ? $campaign_data['fields'][ $field_id ] : false;
324
325 ob_start();
326
327 ?>
328
329 <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>
330
331 <?php
332
333 echo $charitable_builder_form_fields->generate_text( // phpcs:ignore
334 isset( $settings['headline'] ) ? $settings['headline'] : false,
335 esc_html__( 'Headline', 'charitable' ),
336 array(
337 'id' => 'field_' . esc_attr( $this->type ) . '_headline' . '_' . intval( $field_id ), // phpcs:ignore
338 'name' => array( '_fields', intval( $field_id ), 'headline' ),
339 'field_id' => intval( $field_id ),
340 'class' => 'charitable-campaign-builder-headline',
341 )
342 );
343
344 echo $charitable_builder_form_fields->generate_radio_options( // phpcs:ignore
345 isset( $settings['orientation'] ) ? $settings['orientation'] : false,
346 esc_html__( 'Orientation', 'charitable' ),
347 array(
348 'id' => 'field_' . esc_attr( $this->type ) . '_orientation' . '_' . intval( $field_id ), // phpcs:ignore
349 'name' => array( '_fields', intval( $field_id ), 'orientation' ),
350 'field_id' => esc_attr( $field_id ),
351 'tooltip' => esc_html( $this->tooltip ),
352 'options' => array(
353 'Vertical' => 'vertical',
354 'Horizontal' => 'horizontal',
355 ),
356 'option_default' => 'horizontal',
357 'container_class' => 'charitable-campaign-builder-donor-wall',
358 )
359 );
360
361 echo $charitable_builder_form_fields->generate_text( // phpcs:ignore
362 isset( $settings['number'] ) ? $settings['number'] : false,
363 esc_html__( 'Number of Donors To Show', 'charitable' ),
364 array(
365 'id' => 'field_' . esc_attr( $this->type ) . '_number' . '_' . intval( $field_id ), // phpcs:ignore
366 'name' => array( '_fields', intval( $field_id ), 'number' ),
367 'field_id' => esc_attr( $field_id ),
368 'default' => 10,
369 'type' => 'number',
370 'container_class' => 'charitable-campaign-builder-donor-wall',
371 )
372 );
373
374 $orderby_options = array(
375 'date' => 'Date',
376 'name' => 'Name',
377 );
378
379 echo $charitable_builder_form_fields->generate_dropdown( // phpcs:ignore
380 isset( $settings['orderby'] ) ? $settings['orderby'] : 1,
381 esc_html__( 'Order By', 'charitable' ),
382 array(
383 'id' => 'field_' . esc_attr( $this->type ) . '_orderby',
384 'name' => array( '_fields', intval( $field_id ), 'orderby' ),
385 'container_class' => 'charitable-campaign-builder-donor-wall',
386 'options' => $orderby_options, // phpcs:ignore
387 'default' => 'date',
388 'field_id' => esc_attr( $field_id ),
389
390 )
391 );
392
393 $order_options = array(
394 'DESC' => esc_html__( 'Descending', 'charitable' ),
395 'ASC' => esc_html__( 'Ascending', 'charitable' ),
396 );
397
398 echo $charitable_builder_form_fields->generate_dropdown( // phpcs:ignore
399 isset( $settings['order'] ) ? $settings['order'] : 1,
400 esc_html__( 'Order', 'charitable' ),
401 array(
402 'id' => 'field_' . esc_attr( $this->type ) . '_order',
403 'name' => array( '_fields', intval( $field_id ), 'order' ),
404 'container_class' => 'charitable-campaign-builder-donor-wall',
405 'options' => $order_options, // phpcs:ignore
406 'default' => 'DESC',
407 'field_id' => esc_attr( $field_id ),
408 )
409 );
410
411 echo $charitable_builder_form_fields->generate_toggle( // phpcs:ignore
412 isset( $settings['hide_if_no_donors'] ) ? $settings['hide_if_no_donors'] : false,
413 esc_html__( 'Hide If No Donors', 'charitable' ),
414 array(
415 'id' => 'field_' . esc_attr( $this->type ) . '_hide_if_no_donors' . '_' . intval( $field_id ), // phpcs:ignore
416 'name' => array( '_fields', intval( $field_id ), 'hide_if_no_donors' ),
417 'container_class' => 'charitable-campaign-builder-donor-wall',
418 'field_id' => esc_attr( $field_id ),
419 )
420 );
421
422 echo $charitable_builder_form_fields->generate_toggles( // phpcs:ignore
423 isset( $settings['show_hide'] ) ? $settings['show_hide'] : false,
424 esc_html__( 'Donor Information', 'charitable' ),
425 array(
426 'id' => 'field_' . esc_attr( $this->type ) . '_show_hide' . '_' . intval( $field_id ), // phpcs:ignore
427 'name' => array( '_fields', intval( $field_id ), 'show_hide' ),
428 'field_id' => esc_attr( $field_id ),
429 'tooltip' => esc_html( $this->tooltip ),
430 'default' => array( 'show_name', 'show_amount', 'show_avatar' ),
431 'container_class' => 'charitable-campaign-builder-donor-wall',
432 'options' => array(
433 'Show Name' => 'show_name',
434 'Show Location' => 'show_location',
435 'Show Amount' => 'show_amount',
436 'Show Avatar' => 'show_avatar',
437 )
438 )
439 );
440
441 echo $charitable_builder_form_fields->generate_divider( false, false, array( 'field_id' => intval( $field_id ) ) ); // phpcs:ignore
442
443 echo $charitable_builder_form_fields->generate_number_slider( // phpcs:ignore
444 isset( $settings['width_percentage'] ) ? $settings['width_percentage'] : 100,
445 esc_html__( 'Width', 'charitable' ),
446 array(
447 'id' => 'field_' . esc_attr( $this->type ) . '_width_percentage' . '_' . intval( $field_id ), // phpcs:ignore
448 'name' => array( '_fields', intval( $field_id ), 'width_percentage' ),
449 'field_type' => esc_attr( $this->type ),
450 'css_class' => 'charitable-indicator-on-hover',
451 'field_id' => intval( $field_id ),
452 'symbol' => '%',
453 'min' => 0,
454 'min_actual' => 25,
455 )
456 );
457
458 echo $charitable_builder_form_fields->generate_align( // phpcs:ignore
459 isset( $settings['align'] ) ? $settings['align'] : esc_attr( $this->align_default ),
460 esc_html__( 'align', 'charitable' ),
461 array(
462 'id' => 'field_' . esc_attr( $this->type ) . '_align' . '_' . intval( $field_id ), // phpcs:ignore
463 'name' => array( '_fields', intval( $field_id ), 'align' ),
464 'field_id' => intval( $field_id ),
465 )
466 );
467
468 echo $charitable_builder_form_fields->generate_text( // phpcs:ignore
469 isset( $settings['css_class'] ) ? $settings['css_class'] : false,
470 esc_html__( 'CSS Class', 'charitable' ),
471 array(
472 'id' => 'field_' . esc_attr( $this->type ) . '_css_class' . '_' . intval( $field_id ),
473 'name' => array( '_fields', intval( $field_id ), 'css_class' ),
474 'field_id' => intval( $field_id ),
475 'tooltip' => esc_html__( 'Add CSS classes (seperated by a space) for this field to customize it\'s appearance in your theme.', 'charitable' ),
476 )
477 );
478
479 ?>
480
481 <?php
482
483 $html = ob_get_clean();
484
485 return $html;
486 }
487
488 /**
489 * Generate field vix ajax.
490 *
491 * @since 1.8.0
492 */
493 public function settings_display_ajax() {
494
495 $field_id = isset( $_POST['field_id'] ) ? intval( $_POST['field_id'] ) : 0; // phpcs:ignore
496 $campaign_id = isset( $_POST['campaign_id'] ) ? intval( $_POST['campaign_id'] ) : 0; // phpcs:ignore.
497
498 $charitable_builder_wall_fields = new Charitable_Builder_Form_Fields();
499
500 $campaign_data = get_post_meta( $campaign_id, 'campaign_settings_v2', true );
501 $settings = isset( $campaign_data['fields'][ $field_id ] ) ? $campaign_data['fields'][ $field_id ] : false;
502
503 ob_start();
504
505 ?>
506
507 <?php
508
509 echo $charitable_builder_wall_fields->generate_text( // phpcs:ignore
510 $settings['css_class'],
511 esc_html__( 'CSS Class', 'charitable' ),
512 array(
513 'id' => 'field_' . esc_attr( $this->type ) . '_css_class',
514 'name' => array( 'fields', esc_attr( $this->type ), 'css_class' ),
515 'tooltip' => esc_html( $this->tooltip ),
516 )
517 );
518
519 ?>
520
521 <?php
522
523 $html = ob_get_clean();
524
525 wp_send_json_success( [ 'html' => $html ] );
526
527 exit;
528 }
529
530 /**
531 * Enqueue frontend js.
532 *
533 * @since 1.8.0
534 */
535 public function frontend_js() {
536 }
537
538 /**
539 * Enqueue frontend limit option js.
540 *
541 * @since 1.8.0
542 *
543 * @param array $walls Walls on the current page.
544 */
545 public function builder_js( $min ) {
546 }
547
548 /**
549 * Wallat and sanitize field.
550 *
551 * @since 1.8.0
552 *
553 * @param int $field_id Field type.
554 * @param mixed $field_submit Field value that was submitted.
555 * @param array $campaign_data Campaign data and settings.
556 */
557 public function wallat( $field_id, $field_submit, $campaign_data ) {
558 }
559
560 /**
561 * Validate field on wall submit.
562 *
563 * @since 1.8.0
564 *
565 * @param int $field_id Field ID.
566 * @param mixed $field_submit Field value that was submitted.
567 * @param array $campaign_data Campaign data and settings.
568 */
569 public function validate( $field_id, $field_submit, $campaign_data ) {
570 }
571
572 /**
573 * Possible depreciated function.
574 *
575 * @since 1.8.0
576 *
577 * @param string $field Field ID.
578 * @param array $field_atts Field value that was submitted.
579 * @param array $campaign_data Campaign data and settings.
580 */
581 public function section_top( $field, $field_atts, $campaign_data ) {
582 }
583
584 /**
585 * Possible depreciated function.
586 *
587 * @since 1.8.0
588 *
589 * @param string $field Field type.
590 * @param array $field_atts Field value that was submitted.
591 * @param array $campaign_data Campaign data and settings.
592 */
593 public function section_bottom( $field, $field_atts, $campaign_data ) {
594 }
595 }
596
597 new Charitable_Field_Donation_Wall();
598
599 endif;