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 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-info-bar.php

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

271 lines 8.3 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 info bar 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_Info_Bar' ) ) :
18
19 /**
20 * Class to add campaign info bar field to a campaign form in the builder.
21 */
22 class Charitable_Field_Info_Bar extends Charitable_Builder_Field {
23
24 /**
25 * Primary class constructor.
26 *
27 * @since 1.8.0
28 */
29 public function init() {
30
31 // Basic information.
32 $this->name = esc_html__( 'Info Bar', 'charitable' );
33 $this->type = 'info-bar';
34 $this->icon = 'fa-list-ul';
35 $this->order = 150;
36
37 // Edit/Duplication information.
38 $this->can_be_edited = true;
39 $this->can_be_deleted = true;
40 $this->can_be_duplicated = true;
41 $this->edit_label = 'Edit Info Bar';
42 $this->edit_type = 'info-bar';
43 $this->edit_section = 'standard';
44
45 // Misc.
46 $this->tooltip = '';
47
48 // Define additional field properties.
49 add_action( 'charitable_frontend_js', [ $this, 'frontend_js' ] );
50 }
51
52 /**
53 * Social Sharing options panel inside the builder.
54 *
55 * @since 1.8.0
56 *
57 * @param array $field ProgressBar settings.
58 */
59 public function field_options( $field ) {
60 /*
61 * Basic field options.
62 */
63
64 // Options open markup.
65 }
66
67 /**
68 * Social Sharing preview inside the builder.
69 *
70 * @since 1.8.0
71 *
72 * @param array $field_data Field data and settings.
73 * @param array $campaign_data Campaign data and settings.
74 * @param array $field_id Field ID.
75 * @param string $theme Template data.
76 */
77 public function field_preview( $field_data = false, $campaign_data = false, $field_id = false, $theme = '' ) {
78
79 echo '<h4>' . esc_html( $this->name ) . '</h4>';
80
81 echo '<div class="charitable-field-preview-info-bar"><div class="row">
82 <div class="column">
83 <span class="placeholder"></span>
84 </div>
85 <div class="column">
86 <span class="placeholder"></span>
87 </div>
88 </div></div>';
89 }
90
91 /**
92 * The display on the campaign front-end.
93 *
94 * @since 1.8.0
95 *
96 * @param array $field Campaign Title settings.
97 * @param array $field_data Field Data.
98 * @param array $campaign_data Campaign data and settings.
99 */
100 public function field_display( $field, $field_data = false, $campaign_data = false ) {
101
102 $campaign = isset( $campaign_data['id'] ) && 0 !== intval( $campaign_data['id'] ) ? charitable_get_campaign( $campaign_data['id'] ) : false;
103
104 if ( ! $campaign ) {
105 return;
106 }
107
108 $show_donors = ! empty( $field_data['show_donors'] ) && 'show' === ( $field_data['show_donors'] ) ? true : false;
109 $show_donation_total = ! empty( $field_data['show_donation_total'] ) && 'show' === ( $field_data['show_donation_total'] ) ? true : false;
110 $css_class = ! empty( $field_data['css_class'] ) ? ' class="' . esc_html( $field_data['css_class'] ) . '" ' : '';
111
112 ob_start();
113
114 ?>
115
116 <div class="charitable-campaign-info-bar">
117 <div <?php echo esc_attr( $css_class ); ?>>
118 <div class="charitable-campaign-info-bar-row">
119
120 <?php if ( $show_donation_total ) : ?>
121 <div class="charitable-campaign-info-column">
122 <?php echo wp_kses_post( $campaign->get_donation_summary() ); ?>
123 </div>
124 <?php endif; ?>
125
126 <?php if ( $show_donors ) : ?>
127 <div class="charitable-campaign-info-column">
128 <?php
129 printf(
130 /* translators: %s: number of donors */
131 esc_html_x( '%s Donors', 'number of donors', 'charitable' ),
132 '<span class="donors-count">' . esc_html( $campaign->get_donor_count() ) . '</span>'
133 );
134 ?>
135 </div>
136 <?php endif; ?>
137
138 </div>
139 </div>
140 </div>
141
142 <?php
143
144 $html = ob_get_clean();
145
146 echo wp_kses_post( apply_filters( 'charitable_campaign_builder_' . $this->type . '_field_display', $html, $campaign_data ) );
147 }
148
149 /**
150 * The display on the form settings backend when the user clicks on the field/block.
151 *
152 * @since 1.8.0
153 *
154 * @param array $field Social Sharing settings.
155 * @param array $campaign_data Campaign data and settings.
156 */
157 public function settings_display( $field_id = false, $campaign_data = false ) {
158
159 if ( ! class_exists( 'Charitable_Builder_Form_Fields' ) ) {
160 return;
161 }
162
163 $charitable_builder_form_fields = new Charitable_Builder_Form_Fields();
164
165 $settings = isset( $campaign_data['fields'][ $field_id ] ) ? $campaign_data['fields'][ $field_id ] : false;
166
167 ob_start();
168
169 ?>
170
171 <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>
172
173 <div class="charitable-panel-field charitable-panel-field-section" data-field-id="<?php echo intval( $field_id ); ?>">
174
175 <?php do_action( 'charitable_builder_' . $this->type . '_settings_display_start', $field_id, $campaign_data ); ?>
176
177 </div>
178
179 <?php
180
181 echo $charitable_builder_form_fields->generate_checkbox( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
182 isset( $settings['show_donors'] ) ? $settings['show_donors'] : false,
183 esc_html__( 'Show Donors', 'charitable' ),
184 array(
185 'id' => 'field_' . esc_attr( $this->type ) . '_show_donors' . '_' . intval( $field_id ), // phpcs:ignore
186 'name' => array( '_fields', intval( $field_id ), 'show_donors' ),
187 'checked_value' => 'show',
188 'field_id' => $field_id, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
189 'tooltip' => $this->tooltip, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
190 )
191 );
192
193 echo $charitable_builder_form_fields->generate_checkbox( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
194 isset( $settings['show_donation_total'] ) ? $settings['show_donation_total'] : false,
195 esc_html__( 'Show Donation Total', 'charitable' ),
196 array(
197 'id' => 'field_' . esc_attr( $this->type ) . '_show_donation_total' . '_' . intval( $field_id ), // phpcs:ignore
198 'name' => array( '_fields', intval( $field_id ), 'show_donation_total' ),
199 'checked_value' => 'show',
200 'field_id' => $field_id, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
201 'value' => 'show',
202 'tooltip' => $this->tooltip, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
203 )
204 );
205
206 /* CSS CLASS */
207
208 echo $charitable_builder_form_fields->generate_text( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
209 isset( $settings['css_class'] ) ? $settings['css_class'] : false,
210 esc_html__( 'CSS Class', 'charitable' ),
211 array(
212 'id' => 'field_' . esc_attr( $this->type ) . '_css_class' . '_' . intval( $field_id ),
213 'name' => array( '_fields', intval( $field_id ), 'css_class' ),
214 'field_id' => intval( $field_id ),
215 'tooltip' => esc_html__( 'Add CSS classes (seperated by a space) for this field to customize it\'s appearance in your theme.', 'charitable' ),
216 )
217 );
218
219 ?>
220
221 <div class="charitable-panel-field charitable-panel-field-section" data-field-id="<?php echo intval( $field_id ); ?>">
222
223 <?php do_action( 'charitable_builder_' . $this->type . '_settings_display_end', $field_id, $campaign_data ); ?>
224
225 </div>
226
227 <?php
228
229 $html = ob_get_clean();
230
231 return $html;
232 }
233
234 /**
235 * Enqueue frontend limit option js.
236 *
237 * @since 1.8.0
238 *
239 * @param array $forms Forms on the current page.
240 */
241 public function frontend_js( $forms ) {
242 }
243
244 /**
245 * Format and sanitize field.
246 *
247 * @since 1.8.0
248 *
249 * @param int $field_id ProgressBar ID.
250 * @param mixed $field_submit ProgressBar value that was submitted.
251 * @param array $campaign_data Form data and settings.
252 */
253 public function format( $field_id, $field_submit, $campaign_data ) {
254 }
255
256 /**
257 * Validate field on form submit.
258 *
259 * @since 1.8.0
260 *
261 * @param int $field_id ProgressBar ID.
262 * @param mixed $field_submit ProgressBar value that was submitted.
263 * @param array $campaign_data Form data and settings.
264 */
265 public function validate( $field_id, $field_submit, $campaign_data ) {
266 }
267 }
268
269 new Charitable_Field_Info_Bar();
270
271 endif;