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-donor-wall.php

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

574 lines 19.0 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 foreach ( $defaults as $name => $value ) {
148
149 if ( is_integer( $value ) ) {
150 $shortcode_args .= $name . '=' . $params[ $name ] . ' ';
151 } else {
152 $shortcode_args .= $name . '="' . $params[ $name ] . '" ';
153 }
154 }
155
156 $show_hide_args = array( 'show_name', 'show_location', 'show_amount', 'show_avatar' );
157
158 foreach ( $show_hide_args as $show_hide_arg ) {
159
160 if ( ! empty( $field_data[ $show_hide_arg ] ) && 0 === intval( $field_data[ $show_hide_arg ] ) ) {
161 $shortcode_args .= ' ' . $show_hide_arg . '=0';
162 } elseif ( ! empty( $field_data[ $show_hide_arg ] ) && 1 === intval( $field_data[ $show_hide_arg ] ) ) {
163 $shortcode_args .= ' ' . $show_hide_arg . '=1';
164 } elseif ( empty( $field_data[ $show_hide_arg ] ) ) {
165 $shortcode_args .= ' ' . $show_hide_arg . '=0';
166 }
167 }
168
169 $html = '<div class="charitable-field-preview-html donation-wall charitable-prevent-select" data-field-type="' . $this->type . '">
170 <span class="charitable-field-donation-wall-placeholder charitable-placeholder">';
171
172 $html .= ! empty( $field_data['headline'] ) ? '<h5 class="charitable-field-preview-headline">' . esc_html( $field_data['headline'] ) . '</h5>' : '';
173
174 $html .= do_shortcode( '[charitable_donors ' . $shortcode_args . ' ]' );
175
176 $html .= ' </span>
177 </div>';
178
179 return $html;
180
181 }
182
183 return $html;
184 }
185
186
187 /**
188 * Donation Wall preview inside the builder.
189 *
190 * @since 1.8.0
191 *
192 * @param array $field_data Field data and settings.
193 * @param array $campaign_data Campaign data and settings.
194 * @param array $field_id Field ID.
195 * @param string $theme Template data.
196 */
197 public function field_preview( $field_data = false, $campaign_data = false, $field_id = false, $theme = '' ) {
198
199 $html = $this->field_title( $this->name );
200 $html .= $this->field_wrapper( $this->render( $field_data, $campaign_data, $field_id, 'preview' ), $field_data );
201
202 echo $html; // phpcs:ignore
203 }
204
205 /**
206 * The display on the campaign front-end.
207 *
208 * @since 1.8.0
209 *
210 * @param string $field The passed field type.
211 * @param array $field_data Any field data.
212 * @param array $campaign_data Wall data and settings.
213 */
214 public function field_display( $field, $field_data = false, $campaign_data = false ) {
215
216 $campaign_id = isset( $campaign_data['id'] ) && 0 !== intval( $campaign_data['id'] ) ? intval( $campaign_data['id'] ) : false;
217 $css_class = ! empty( $field_data['css_class'] ) ? ' class="' . esc_html( $field_data['css_class'] ) . '" ' : '';
218 $headline = ! empty( $field_data['headline'] ) ? '<h5 class="charitable-field-template-headline">' . esc_html( $field_data['headline'] ) . '</h5>' : '';
219
220 if ( 0 === intval( $campaign_id ) ) {
221 return;
222 }
223
224 ob_start();
225
226 ?>
227 <?php echo $headline; // phpcs:ignore
228 ?>
229 <div class="charitable-campaign-field charitable-campaign-field_<?php echo esc_attr( $this->type ); ?>">
230 <div <?php echo esc_attr( $css_class ); ?>>
231
232 <?php
233
234 $defaults = array(
235 'number' => 10,
236 'orderby' => 'date',
237 'order' => 'DESC',
238 'campaign_id' => $campaign_id,
239 'campaign' => $campaign_id,
240 'distinct_donors' => 0,
241 'orientation' => 'horizontal',
242 'hide_if_no_donors' => 0,
243 );
244
245 $params = apply_filters( 'charitable_campaign_builder_donation_wall_args', array_replace_recursive( $defaults, $field_data ), $field_data, $campaign_data );
246
247 $shortcode_args = '';
248
249 foreach ( $defaults as $name => $value ) {
250
251 if ( is_integer( $value ) ) {
252 $shortcode_args .= $name . '=' . $params[ $name ] . ' ';
253 } else {
254 $shortcode_args .= $name . '="' . $params[ $name ] . '" ';
255 }
256 }
257
258 $show_hide_args = array( 'show_name', 'show_location', 'show_amount', 'show_avatar' );
259
260 foreach ( $show_hide_args as $show_hide_arg ) {
261
262 if ( ! isset( $field_data['show_hide'][ $show_hide_arg ] ) || empty( $field_data['show_hide'][ $show_hide_arg ] ) ) {
263 $shortcode_args .= ' ' . $show_hide_arg . '=0';
264 } elseif ( ! empty( $field_data['show_hide'][ $show_hide_arg ] ) ) {
265 $shortcode_args .= ' ' . $show_hide_arg . '=1';
266 } elseif ( empty( $field_data['show_hide'][ $show_hide_arg ] ) ) {
267 $shortcode_args .= ' ' . $show_hide_arg . '=0';
268 }
269 }
270
271 echo do_shortcode( '[charitable_donors ' . $shortcode_args . ' ]' );
272
273 ?>
274 </div>
275 </div>
276
277 <?php
278
279 $final_html = ob_get_clean();
280
281 $html = $this->field_display_wrapper( $final_html, $field_data );
282
283 echo apply_filters( 'charitable_campaign_builder_' . $this->type . '_field_display', $html, $campaign_data ); // phpcs:ignore
284 }
285
286 /**
287 * Donation Wall display on the form front-end.
288 *
289 * @since 1.8.0
290 *
291 * @param integer $field_id Number ID.
292 * @param array $campaign_data Wall data and settings.
293 */
294 public function settings_display( $field_id = false, $campaign_data = false ) {
295
296 $charitable_builder_form_fields = new Charitable_Builder_Form_Fields();
297
298 $settings = isset( $campaign_data['fields'][ $field_id ] ) ? $campaign_data['fields'][ $field_id ] : false;
299
300 ob_start();
301
302 ?>
303
304 <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>
305
306 <?php
307
308 echo $charitable_builder_form_fields->generate_text( // phpcs:ignore
309 isset( $settings['headline'] ) ? $settings['headline'] : false,
310 esc_html__( 'Headline', 'charitable' ),
311 array(
312 'id' => 'field_' . esc_attr( $this->type ) . '_headline' . '_' . intval( $field_id ), // phpcs:ignore
313 'name' => array( '_fields', intval( $field_id ), 'headline' ),
314 'field_id' => intval( $field_id ),
315 'class' => 'charitable-campaign-builder-headline',
316 )
317 );
318
319 echo $charitable_builder_form_fields->generate_radio_options( // phpcs:ignore
320 isset( $settings['orientation'] ) ? $settings['orientation'] : false,
321 esc_html__( 'Orientation', 'charitable' ),
322 array(
323 'id' => 'field_' . esc_attr( $this->type ) . '_orientation' . '_' . intval( $field_id ), // phpcs:ignore
324 'name' => array( '_fields', intval( $field_id ), 'orientation' ),
325 'field_id' => esc_attr( $field_id ),
326 'tooltip' => esc_html( $this->tooltip ),
327 'options' => array(
328 'Vertical' => 'vertical',
329 'Horizontal' => 'horizontal',
330 ),
331 'option_default' => 'horizontal',
332 'container_class' => 'charitable-campaign-builder-donor-wall',
333 )
334 );
335
336 echo $charitable_builder_form_fields->generate_text( // phpcs:ignore
337 isset( $settings['number'] ) ? $settings['number'] : false,
338 esc_html__( 'Number of Donors To Show', 'charitable' ),
339 array(
340 'id' => 'field_' . esc_attr( $this->type ) . '_number' . '_' . intval( $field_id ), // phpcs:ignore
341 'name' => array( '_fields', intval( $field_id ), 'number' ),
342 'field_id' => esc_attr( $field_id ),
343 'default' => 10,
344 'type' => 'number',
345 'container_class' => 'charitable-campaign-builder-donor-wall',
346 )
347 );
348
349 $orderby_options = array(
350 'date' => 'Date',
351 'name' => 'Name',
352 );
353
354 echo $charitable_builder_form_fields->generate_dropdown( // phpcs:ignore
355 isset( $settings['orderby'] ) ? $settings['orderby'] : 1,
356 esc_html__( 'Order By', 'charitable' ),
357 array(
358 'id' => 'field_' . esc_attr( $this->type ) . '_orderby',
359 'name' => array( '_fields', intval( $field_id ), 'orderby' ),
360 'container_class' => 'charitable-campaign-builder-donor-wall',
361 'options' => $orderby_options, // phpcs:ignore
362 'default' => 'date',
363 'field_id' => esc_attr( $field_id ),
364
365 )
366 );
367
368 $order_options = array(
369 'DESC' => esc_html__( 'Descending', 'charitable' ),
370 'ASC' => esc_html__( 'Ascending', 'charitable' ),
371 );
372
373 echo $charitable_builder_form_fields->generate_dropdown( // phpcs:ignore
374 isset( $settings['order'] ) ? $settings['order'] : 1,
375 esc_html__( 'Order', 'charitable' ),
376 array(
377 'id' => 'field_' . esc_attr( $this->type ) . '_order',
378 'name' => array( '_fields', intval( $field_id ), 'order' ),
379 'container_class' => 'charitable-campaign-builder-donor-wall',
380 'options' => $order_options, // phpcs:ignore
381 'default' => 'DESC',
382 'field_id' => esc_attr( $field_id ),
383 )
384 );
385
386 echo $charitable_builder_form_fields->generate_toggle( // phpcs:ignore
387 isset( $settings['hide_if_no_donors'] ) ? $settings['hide_if_no_donors'] : false,
388 esc_html__( 'Hide If No Donors', 'charitable' ),
389 array(
390 'id' => 'field_' . esc_attr( $this->type ) . '_hide_if_no_donors' . '_' . intval( $field_id ), // phpcs:ignore
391 'name' => array( '_fields', intval( $field_id ), 'hide_if_no_donors' ),
392 'container_class' => 'charitable-campaign-builder-donor-wall',
393 'field_id' => esc_attr( $field_id ),
394 )
395 );
396
397 echo $charitable_builder_form_fields->generate_toggles( // phpcs:ignore
398 isset( $settings['show_hide'] ) ? $settings['show_hide'] : false,
399 esc_html__( 'Donor Information', 'charitable' ),
400 array(
401 'id' => 'field_' . esc_attr( $this->type ) . '_show_hide' . '_' . intval( $field_id ), // phpcs:ignore
402 'name' => array( '_fields', intval( $field_id ), 'show_hide' ),
403 'field_id' => esc_attr( $field_id ),
404 'tooltip' => esc_html( $this->tooltip ),
405 'default' => array( 'show_name', 'show_amount', 'show_avatar' ),
406 'container_class' => 'charitable-campaign-builder-donor-wall',
407 'options' => array(
408 'Show Name' => 'show_name',
409 'Show Location' => 'show_location',
410 'Show Amount' => 'show_amount',
411 'Show Avatar' => 'show_avatar',
412 )
413 )
414 );
415
416 echo $charitable_builder_form_fields->generate_divider( false, false, array( 'field_id' => intval( $field_id ) ) ); // phpcs:ignore
417
418 echo $charitable_builder_form_fields->generate_number_slider( // phpcs:ignore
419 isset( $settings['width_percentage'] ) ? $settings['width_percentage'] : 100,
420 esc_html__( 'Width', 'charitable' ),
421 array(
422 'id' => 'field_' . esc_attr( $this->type ) . '_width_percentage' . '_' . intval( $field_id ), // phpcs:ignore
423 'name' => array( '_fields', intval( $field_id ), 'width_percentage' ),
424 'field_type' => esc_attr( $this->type ),
425 'css_class' => 'charitable-indicator-on-hover',
426 'field_id' => intval( $field_id ),
427 'symbol' => '%',
428 'min' => 0,
429 'min_actual' => 25,
430 )
431 );
432
433 echo $charitable_builder_form_fields->generate_align( // phpcs:ignore
434 isset( $settings['align'] ) ? $settings['align'] : esc_attr( $this->align_default ),
435 esc_html__( 'align', 'charitable' ),
436 array(
437 'id' => 'field_' . esc_attr( $this->type ) . '_align' . '_' . intval( $field_id ), // phpcs:ignore
438 'name' => array( '_fields', intval( $field_id ), 'align' ),
439 'field_id' => intval( $field_id ),
440 )
441 );
442
443 echo $charitable_builder_form_fields->generate_text( // phpcs:ignore
444 isset( $settings['css_class'] ) ? $settings['css_class'] : false,
445 esc_html__( 'CSS Class', 'charitable' ),
446 array(
447 'id' => 'field_' . esc_attr( $this->type ) . '_css_class' . '_' . intval( $field_id ),
448 'name' => array( '_fields', intval( $field_id ), 'css_class' ),
449 'field_id' => intval( $field_id ),
450 'tooltip' => esc_html__( 'Add CSS classes (seperated by a space) for this field to customize it\'s appearance in your theme.', 'charitable' ),
451 )
452 );
453
454 ?>
455
456 <?php
457
458 $html = ob_get_clean();
459
460 return $html;
461 }
462
463 /**
464 * Generate field vix ajax.
465 *
466 * @since 1.8.0
467 */
468 public function settings_display_ajax() {
469
470 $field_id = isset( $_POST['field_id'] ) ? intval( $_POST['field_id'] ) : 0; // phpcs:ignore
471 $campaign_id = isset( $_POST['campaign_id'] ) ? intval( $_POST['campaign_id'] ) : 0; // phpcs:ignore.
472
473 $charitable_builder_wall_fields = new Charitable_Builder_Form_Fields();
474
475 $campaign_data = get_post_meta( $campaign_id, 'campaign_settings_v2', true );
476 $settings = isset( $campaign_data['fields'][ $field_id ] ) ? $campaign_data['fields'][ $field_id ] : false;
477
478 ob_start();
479
480 ?>
481
482 <?php
483
484 echo $charitable_builder_wall_fields->generate_text( // phpcs:ignore
485 $settings['css_class'],
486 esc_html__( 'CSS Class', 'charitable' ),
487 array(
488 'id' => 'field_' . esc_attr( $this->type ) . '_css_class',
489 'name' => array( 'fields', esc_attr( $this->type ), 'css_class' ),
490 'tooltip' => esc_html( $this->tooltip ),
491 )
492 );
493
494 ?>
495
496 <?php
497
498 $html = ob_get_clean();
499
500 wp_send_json_success( [ 'html' => $html ] );
501
502 exit;
503 }
504
505 /**
506 * Enqueue frontend js.
507 *
508 * @since 1.8.0
509 */
510 public function frontend_js() {
511 }
512
513 /**
514 * Enqueue frontend limit option js.
515 *
516 * @since 1.8.0
517 *
518 * @param array $walls Walls on the current page.
519 */
520 public function builder_js( $min ) {
521 }
522
523 /**
524 * Wallat and sanitize field.
525 *
526 * @since 1.8.0
527 *
528 * @param int $field_id Field type.
529 * @param mixed $field_submit Field value that was submitted.
530 * @param array $campaign_data Campaign data and settings.
531 */
532 public function wallat( $field_id, $field_submit, $campaign_data ) {
533 }
534
535 /**
536 * Validate field on wall submit.
537 *
538 * @since 1.8.0
539 *
540 * @param int $field_id Field ID.
541 * @param mixed $field_submit Field value that was submitted.
542 * @param array $campaign_data Campaign data and settings.
543 */
544 public function validate( $field_id, $field_submit, $campaign_data ) {
545 }
546
547 /**
548 * Possible depreciated function.
549 *
550 * @since 1.8.0
551 *
552 * @param string $field Field ID.
553 * @param array $field_atts Field value that was submitted.
554 * @param array $campaign_data Campaign data and settings.
555 */
556 public function section_top( $field, $field_atts, $campaign_data ) {
557 }
558
559 /**
560 * Possible depreciated function.
561 *
562 * @since 1.8.0
563 *
564 * @param string $field Field type.
565 * @param array $field_atts Field value that was submitted.
566 * @param array $campaign_data Campaign data and settings.
567 */
568 public function section_bottom( $field, $field_atts, $campaign_data ) {
569 }
570 }
571
572 new Charitable_Field_Donation_Wall();
573
574 endif;