PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.13
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.13
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-campaign-overview.php

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

309 lines 11.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 campaign overview 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_Campaign_Overview' ) ) :
18
19 /**
20 * Class to add campaign overview field to a campaign form in the builder.
21 */
22 class Charitable_Field_Campaign_Overview extends Charitable_Builder_Field {
23
24 /**
25 * Character Limit to show in preview.
26 *
27 * @since 1.8.0
28 *
29 * @var string
30 */
31 public $preview_character_limit = 500;
32
33 /**
34 * Primary class constructor.
35 *
36 * @since 1.8.0
37 */
38 public function init() {
39
40 // Define field type information.
41 $this->name = esc_html__( 'Campaign Overview', 'charitable' );
42 $this->type = 'campaign-overview';
43 $this->icon = 'fa-paragraph';
44 $this->order = 10;
45
46 // Edit/Duplication information.
47 $this->can_be_edited = true;
48 $this->can_be_deleted = true;
49 $this->can_be_duplicated = true;
50 $this->edit_label = esc_html__( 'Edit Campaign Overview', 'charitable' );
51 $this->edit_type = 'campaign-overview'; // was settings.
52 $this->edit_section = 'standard';
53
54 // Misc.
55 $this->tooltip = esc_html__( 'Placeholder tool tip', 'charitable' );
56 $this->preview_character_limit = 550;
57
58 // Define additional field properties.
59 add_action( 'charitable_frontend_js', [ $this, 'frontend_js' ] );
60 }
61
62 /**
63 * Campaign Overview options panel inside the builder.
64 *
65 * @since 1.8.0
66 *
67 * @param array $field Campaign Overview settings.
68 */
69 public function field_options( $field ) {
70 /*
71 * Basic field options.
72 */
73
74 // Options open markup.
75 }
76
77 /**
78 * Campaign Overview preview inside the builder.
79 *
80 * @since 1.8.0
81 * @since 1.8.1.9 Added santization to the overview.
82 *
83 * @param array $field_data Field data and settings.
84 * @param array $campaign_data Campaign data and settings.
85 * @param array $field_id Field ID.
86 * @param string $theme Template data.
87 */
88 public function field_preview( $field_data = false, $campaign_data = false, $field_id = false, $theme = '' ) {
89
90 // santitize the overview, which is user supplied text... remove any JS or other bad stuff.
91 $campaign_overview = ! empty( $campaign_data['settings']['general']['overview'] ) ? wp_kses_post( $campaign_data['settings']['general']['overview'] ) : '';
92
93 $field_preview_html = '<div class="charitable-field-title-overview title-overview" data-field-type="' . $this->type . '">
94 <div class="placeholder">
95 <div class="charitable-campaign-builder-placeholder-preview-text charitable-campaign-builder-no-overview-preview charitable-prevent-select" style="overflow: scroll;">';
96
97 if ( $campaign_overview ) {
98
99 $field_preview_html .= wpautop(
100 wp_kses(
101 strlen( $campaign_overview ) > $this->preview_character_limit ? substr( $campaign_overview, 0, $this->preview_character_limit ) . '...' : $campaign_overview,
102 [
103 'strong' => [],
104 'em' => [],
105 ]
106 )
107 );
108
109 } else {
110
111 $field_preview_html .= '
112 <div>
113 <p><em><strong>This is an example of a campaign overal.</strong> It can include more text that goes into some details about your campaign - such as the history of the organization, testimonials, and more. An overview can work great as a longer overview under the campaign or inside of the visible tabs on the campaign page. The overview here might say something like this:</em></p>
114 <p><br/></p>
115 <p><img src="' . charitable()->get_path( 'assets', false ) . 'images/campaign-builder/photo-default-image.png" alt="" title="" /></p>
116 <p>Hi there! This campaign is to raise money for equipment, uniforms, and various other supplies for our local school sport team, The Tigers. Hi there! This campaign is to raise money for equipment, uniforms, and various other supplies for our local school sport team, The Tigers. Hi there! This campaign is to raise money for equipment, uniforms, and various other supplies for our local school sport team, The Tigers. Hi there! This campaign is to raise money for equipment, uniforms, and various other supplies for our local school sport team, The Tigers.</p>
117 <p><br/></p>
118 <p>The Tigers basebase team was founded in 1971 and has been providing fun after school activities for young children in the Dalls, Texas USA public schools ever since. The campaign is run by Mr. and Mrs. Smith and employs about 5 people including coaches and staff.</p>
119 <p><br/></p>
120 <p>Since this is a new campaign, you as a Charitable admin should update this content by clicking on this block in the preview area in the campaign builder. 😄</p>
121 <p><br/></p>
122 </div>
123 </div>';
124
125 }
126
127 $field_preview_html .= '
128 </div>
129 </div>';
130
131 $html = $this->field_title( $this->name );
132 $html .= $this->field_wrapper( $field_preview_html, $field_data );
133
134 echo $html; // phpcs:ignore
135 }
136
137 /**
138 * Campaign Overview display on the form front-end.
139 *
140 * @since 1.8.0
141 * @version 1.8.9.1
142 *
143 * @param array $field Campaign Overview settings.
144 * @param array $field_data Field Data.
145 * @param array $campaign_data Campaign data and settings.
146 */
147 public function field_display( $field, $field_data = false, $campaign_data = false ) {
148
149 $campaign_overview_raw = ! empty( $campaign_data['settings']['general']['overview'] ) ? ( $campaign_data['settings']['general']['overview'] ) : '';
150 $campaign_overview = wp_kses_post( $campaign_overview_raw );
151 $headline = ! empty( $field_data['headline'] ) ? esc_html( $field_data['headline'] ) : false;
152 $css_class = ! empty( $field_data['css_class'] ) ? ' class="' . esc_html( $field_data['css_class'] ) . '" ' : '';
153
154 ob_start();
155
156 ?>
157
158 <div class="charitable-campaign-field charitable-campaign-field_<?php echo esc_attr( $this->type ); ?> <?php echo esc_attr( $css_class ); ?>">
159
160 <?php if ( $headline ) : ?>
161 <h4><?php echo $headline; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></h4>
162 <?php endif; ?>
163
164 <?php echo $campaign_overview; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
165 </div>
166
167 <?php
168
169 $html = ob_get_clean();
170
171 echo apply_filters( 'charitable_campaign_builder_' . $this->type . '_field_display', $html, $campaign_data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
172 }
173
174 /**
175 * The display on the form settings backend when the user clicks on the field/block.
176 *
177 * @since 1.8.0
178 *
179 * @param array $field_id Field id..
180 * @param array $campaign_data Campaign data and settings.
181 */
182 public function settings_display( $field_id = false, $campaign_data = false ) {
183
184 $charitable_builder_form_fields = new Charitable_Builder_Form_Fields();
185
186 $settings = isset( $campaign_data['fields'][ $field_id ] ) ? $campaign_data['fields'][ $field_id ] : false;
187
188 // $panel_settings = new Charitable_Builder_Panel_Settings();
189
190 ob_start();
191
192 ?>
193
194 <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>
195
196 <?php
197
198 echo $charitable_builder_form_fields->generate_text( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
199 isset( $settings['headline'] ) ? $settings['headline'] : false,
200 esc_html__( 'Headline', 'charitable' ),
201 array(
202 'id' => 'field_' . esc_attr( $this->type ) . '_headline' . '_' . intval( $field_id ), // phpcs:ignore
203 'name' => array( '_fields', intval( $field_id ), 'headline' ),
204 'field_id' => intval( $field_id ),
205 'class' => 'charitable-campaign-builder-headline',
206 )
207 );
208
209 echo $charitable_builder_form_fields->generate_textbox( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
210 isset( $settings['content'] ) ? $settings['content'] : false,
211 esc_html__( 'Campaign Overview', 'charitable' ),
212 array(
213 'id' => 'field_' . esc_attr( $this->type ) . '_html' . '_' . intval( $field_id ), // phpcs:ignore
214 'name' => array( '_fields', intval( $field_id ), 'content' ),
215 'field_id' => intval( $field_id ),
216 'tooltip' => esc_html( $this->tooltip ),
217 'class' => 'campaign-builder-htmleditor',
218 'rows' => 30,
219 'html' => true,
220 'code' => false,
221 'special' => 'campaign_overview',
222 )
223 );
224
225 echo $charitable_builder_form_fields->generate_divider( false, false, array( 'field_id' => $field_id ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
226
227 echo $charitable_builder_form_fields->generate_number_slider( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
228 isset( $settings['width_percentage'] ) ? $settings['width_percentage'] : 100,
229 esc_html__( 'Width', 'charitable' ),
230 array(
231 'id' => 'field_' . esc_attr( $this->type ) . '_width_percentage' . '_' . intval( $field_id ), // phpcs:ignore
232 'name' => array( '_fields', intval( $field_id ), 'width_percentage' ),
233 'field_type' => esc_attr( $this->type ),
234 'field_id' => intval( $field_id ),
235 'symbol' => '%',
236 'min' => 10,
237 'tooltip' => esc_html__( 'Adjust the width of the field within the column.', 'charitable' ),
238 )
239 );
240
241 echo $charitable_builder_form_fields->generate_align( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
242 isset( $settings['align'] ) ? $settings['align'] : false,
243 esc_html__( 'Align', 'charitable' ),
244 array(
245 'id' => 'field_' . esc_attr( $this->type ) . '_align' . '_' . intval( $field_id ), // phpcs:ignore
246 'name' => array( '_fields', intval( $field_id ), 'align' ),
247 'field_id' => intval( $field_id ),
248 )
249 );
250
251 echo $charitable_builder_form_fields->generate_text( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
252 isset( $settings['css_class'] ) ? $settings['css_class'] : false,
253 esc_html__( 'CSS Class', 'charitable' ),
254 array(
255 'id' => 'field_' . esc_attr( $this->type ) . '_css_class' . '_' . intval( $field_id ), // phpcs:ignore
256 'name' => array( '_fields', intval( $field_id ), 'css_class' ),
257 'field_id' => intval( $field_id ),
258 'tooltip' => esc_html__( 'Add CSS classes (seperated by a space) for this field to customize it\'s appearance in your theme.', 'charitable' ),
259 )
260 );
261
262 ?>
263
264 <?php
265
266 $html = ob_get_clean();
267
268 return $html;
269 }
270
271 /**
272 * Enqueue frontend limit option js.
273 *
274 * @since 1.8.0
275 *
276 * @param array $forms Forms on the current page.
277 */
278 public function frontend_js( $forms ) {
279 }
280
281 /**
282 * Format and sanitize field.
283 *
284 * @since 1.8.0
285 *
286 * @param int $field_id Campaign Overview ID.
287 * @param mixed $field_submit Campaign Overview value that was submitted.
288 * @param array $form_data Form data and settings.
289 */
290 public function format( $field_id, $field_submit, $form_data ) {
291 }
292
293 /**
294 * Validate field on form submit.
295 *
296 * @since 1.8.0
297 *
298 * @param int $field_id Campaign Overview ID.
299 * @param mixed $field_submit Campaign Overview value that was submitted.
300 * @param array $form_data Form data and settings.
301 */
302 public function validate( $field_id, $field_submit, $form_data ) {
303 }
304 }
305
306
307 new Charitable_Field_Campaign_Overview();
308
309 endif;