PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.11
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.11
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-description.php

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

333 lines 11.8 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 description 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_Description' ) ) :
18
19 /**
20 * Class to add campaign description field to a campaign form in the builder.
21 *
22 * @version 1.8.9.1
23 */
24 class Charitable_Field_Campaign_Description extends Charitable_Builder_Field {
25
26 /**
27 * Character Limit to show in preview.
28 *
29 * @since 1.8.0
30 *
31 * @var string
32 */
33 public $preview_character_limit = 500;
34
35 /**
36 * Primary class constructor.
37 *
38 * @since 1.8.0
39 */
40 public function init() {
41
42 // Define field type information.
43 $this->name = esc_html__( 'Campaign Description', 'charitable' );
44 $this->type = 'campaign-description';
45 $this->icon = 'fa-paragraph';
46 $this->order = 10;
47
48 $this->align_default = 'center';
49
50 // Edit/Duplication information.
51 $this->can_be_edited = true;
52 $this->can_be_deleted = true;
53 $this->can_be_duplicated = false;
54 $this->edit_label = esc_html__( 'Edit Campaign Description', 'charitable' );
55 $this->edit_type = 'campaign-description'; // was settings.
56 $this->edit_section = 'recommended';
57 $this->max_allowed = 1;
58
59 // Misc.
60 $this->tooltip = esc_html__( 'Placeholder tool tip', 'charitable' );
61 $this->preview_character_limit = 99550;
62
63 // Define additional field properties.
64 add_action( 'charitable_frontend_js', [ $this, 'frontend_js' ] );
65 }
66
67 /**
68 * Campaign Description options panel inside the builder.
69 *
70 * @since 1.8.0
71 *
72 * @param array $field Campaign Description settings.
73 */
74 public function field_options( $field ) {
75 /*
76 * Basic field options.
77 */
78
79 // Options open markup.
80 }
81
82 /**
83 * Render the field.
84 *
85 * @since 1.8.0
86 *
87 * @param array $field_data Any field data.
88 * @param array $campaign_data Amount data and settings.
89 * @param integer $field_id The field ID.
90 * @param string $mode Where the field is being displayed ("preview" or "template").
91 * @param array $template_data Tempalate data.
92 */
93 public function render( $field_data = false, $campaign_data = false, $field_id = false, $mode = 'template', $template_data = false ) {
94
95 $campaign_description = ! empty( $campaign_data['settings']['general']['description'] ) ? ( $campaign_data['settings']['general']['description'] ) : ''; // todo: santitize.
96 $campaign_description = ( $campaign_description === '' && ! empty( $field_data['content'] ) ) ? ( $field_data['content'] ) : $campaign_description; // todo: santitize.
97 $headline = ! empty( $field_data['headline'] ) ? esc_html( $field_data['headline'] ) : false;
98
99 $field_preview_html = '<div class="charitable-field-title-description title-description" data-field-type="' . $this->type . '">
100 <div class="placeholder charitable-placeholder"><h5 class="charitable-field-' . $mode . '-headline">' . $headline . '</h5>
101 <div class="charitable-campaign-builder-placeholder-' . $mode . '-text charitable-campaign-builder-no-description-' . $mode . ' charitable-prevent-select">';
102
103 if ( '' !== $campaign_description ) {
104
105 // Adjust the character limit - no character limit for the campaign description on the frontend. Limit for admin preview only.
106 $preview_character_limit = $mode === 'template' ? $this->preview_character_limit : strlen( $campaign_description );
107
108 $field_preview_html .= wpautop(
109 wp_kses(
110 strlen( $campaign_description ) > $preview_character_limit ? substr( $campaign_description, 0, $this->preview_character_limit ) . '...' : $campaign_description,
111 [
112 'strong' => [],
113 'em' => [],
114 'h1' => [],
115 'h2' => [],
116 'h3' => [],
117 'h4' => [],
118 'h5' => [],
119 'h6' => [],
120 'p' => [],
121 'span' => [],
122 ]
123 )
124 ) . '</div>';
125
126 } else {
127
128 $field_preview_html .= '
129 <div>
130 <p><em><strong>This is an example of a campaign description.</strong> It should summarize thoughtfully what your campaign is about and what your goal(s) are. If this is the only campaign of your site you can link to a more detailed About page that introduces into more detail. The description here might say something like this:</em></p>
131 <p><br/></p>
132 <p>Hi there! This campaign is to raise money for equipment, uniforms, and various other supplies for our local school sport team, The Tigers.</p>
133 <p><br/></p>
134 <p>...or something like this:</p>
135 <p><br/></p>
136 <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>
137 <p><br/></p>
138 <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>
139 <p><br/></p>
140 </div>
141 </div>';
142
143 }
144
145 $field_preview_html .= '
146 </div>
147 </div>';
148
149 $html = $field_preview_html;
150
151 return $html;
152 }
153
154
155 /**
156 * Campaign Description preview inside the builder.
157 *
158 * @since 1.8.0
159 * @version 1.8.9.1
160 *
161 * @param array $field_data Field data and settings.
162 * @param array $campaign_data Campaign data and settings.
163 * @param array $field_id Field ID.
164 * @param string $theme Template data.
165 */
166 public function field_preview( $field_data = false, $campaign_data = false, $field_id = false, $theme = '' ) {
167
168 $html = $this->field_title( $this->name );
169 $html .= $this->field_wrapper( $this->render( $field_data, $campaign_data, $field_id, 'preview' ), $field_data );
170
171 echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
172 }
173
174 /**
175 * The display on the campaign front-end.
176 *
177 * @since 1.8.0
178 * @version 1.8.9.1
179 *
180 * @param string $field_type The passed field type.
181 * @param array $field_data Any field data.
182 * @param array $campaign_data Amount data and settings.
183 */
184 public function field_display( $field_type = '', $field_data = false, $campaign_data = false ) {
185
186 $html = $this->field_display_wrapper( $this->render( $field_data, $campaign_data ), $field_data );
187
188 echo apply_filters( 'charitable_campaign_builder_' . $this->type . '_field_display', $html, $campaign_data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
189 }
190
191 /**
192 * The display on the form settings backend when the user clicks on the field/block.
193 *
194 * @since 1.8.0
195 * @version 1.8.9.1
196 *
197 * @param array $field_id Field ID.
198 * @param array $campaign_data Campaign data and settings.
199 */
200 public function settings_display( $field_id = false, $campaign_data = false ) {
201
202 $charitable_builder_form_fields = new Charitable_Builder_Form_Fields();
203
204 $settings = isset( $campaign_data['fields'][ $field_id ] ) ? $campaign_data['fields'][ $field_id ] : false;
205
206 ob_start();
207
208 ?>
209
210 <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>
211
212 <?php
213
214 echo $charitable_builder_form_fields->generate_text( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
215 isset( $settings['headline'] ) ? $settings['headline'] : false,
216 esc_html__( 'Headline', 'charitable' ),
217 array(
218 'id' => 'field_' . esc_attr( $this->type ) . '_headline' . '_' . intval( $field_id ), // phpcs:ignore
219 'name' => array( '_fields', intval( $field_id ), 'headline' ),
220 'field_id' => intval( $field_id ),
221 'class' => 'charitable-campaign-builder-headline',
222 )
223 );
224
225 $campaign_description = ! empty( $campaign_data['settings']['general']['description'] ) ? ( $campaign_data['settings']['general']['description'] ) : 'Add your description here.'; // todo: santitize.
226
227 echo $charitable_builder_form_fields->generate_textbox( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
228 $campaign_description,
229 esc_html__( 'Campaign Description', 'charitable' ),
230 array(
231 'id' => 'field_' . esc_attr( $this->type ) . '_html' . '_' . intval( $field_id ), // phpcs:ignore
232 'name' => array( '_fields', intval( $field_id ), 'content' ),
233 'field_id' => intval( $field_id ),
234 'tooltip' => esc_html( $this->tooltip ),
235 'class' => 'campaign-builder-htmleditor',
236 'rows' => 30,
237 'html' => true,
238 'code' => false,
239 'special' => 'campaign_description',
240 )
241 );
242
243 echo $charitable_builder_form_fields->generate_divider( false, false, array( 'field_id' => intval( $field_id ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
244
245 echo $charitable_builder_form_fields->generate_number_slider( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
246 isset( $settings['width_percentage'] ) ? $settings['width_percentage'] : 100,
247 esc_html__( 'Width', 'charitable' ),
248 array(
249 'id' => 'field_' . esc_attr( $this->type ) . '_width_percentage' . '_' . intval( $field_id ), // phpcs:ignore
250 'name' => array( '_fields', intval( $field_id ), 'width_percentage' ),
251 'field_type' => esc_attr( $this->type ),
252 'field_id' => intval( $field_id ),
253 'symbol' => '%',
254 'css_class' => 'charitable-indicator-on-hover',
255 'min' => 0,
256 'min_actual' => 20,
257 'tooltip' => esc_html__( 'Adjust the width of the field within the column.', 'charitable' ),
258 )
259 );
260
261 echo $charitable_builder_form_fields->generate_align( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
262 isset( $settings['align'] ) ? $settings['align'] : esc_attr( $this->align_default ),
263 esc_html__( 'Align', 'charitable' ),
264 array(
265 'id' => 'field_' . esc_attr( $this->type ) . '_align' . '_' . intval( $field_id ), // phpcs:ignore
266 'name' => array( '_fields', intval( $field_id ), 'align' ),
267 'field_id' => intval( $field_id ),
268 )
269 );
270
271 echo $charitable_builder_form_fields->generate_text( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
272 isset( $settings['css_class'] ) ? $settings['css_class'] : false,
273 esc_html__( 'CSS Class', 'charitable' ),
274 array(
275 'id' => 'field_' . esc_attr( $this->type ) . '_css_class' . '_' . intval( $field_id ), // phpcs:ignore
276 'name' => array( '_fields', intval( $field_id ), 'css_class' ),
277 'field_id' => intval( $field_id ),
278 'tooltip' => esc_html__( 'Add CSS classes (seperated by a space) for this field to customize it\'s appearance in your theme.', 'charitable' ),
279 )
280 );
281
282 ?>
283
284 <?php
285
286 $html = ob_get_clean();
287
288 return $html;
289 }
290
291 /**
292 * Enqueue frontend limit option js.
293 *
294 * @since 1.8.0
295 *
296 * @param array $forms Forms on the current page.
297 */
298 public function frontend_js( $forms ) {
299 }
300
301 /**
302 * Format and sanitize field.
303 *
304 * @since 1.8.0
305 *
306 * @param int $field_id Campaign Description ID.
307 * @param mixed $field_submit Campaign Description value that was submitted.
308 * @param array $form_data Form data and settings.
309 */
310 public function format( $field_id, $field_submit, $form_data ) {
311 }
312
313 /**
314 * Validate field on form submit.
315 *
316 * @since 1.8.0
317 *
318 * @param int $field_id Campaign Description ID.
319 * @param mixed $field_submit Campaign Description value that was submitted.
320 * @param array $form_data Form data and settings.
321 */
322 public function validate( $field_id, $field_submit, $form_data ) {
323 }
324 }
325
326
327
328 new Charitable_Field_Campaign_Description();
329
330
331
332 endif;
333