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-text.php

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

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