PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.6.6
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.6.6
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 / public / class-charitable-public.php

class-charitable-public.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.6.6, at includes/public/class-charitable-public.php

318 lines 8.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Charitable Public class.
4 *
5 * @package Charitable/Classes/Charitable_Public
6 * @version 1.0.0
7 * @author Eric Daams
8 * @copyright Copyright (c) 2018, Studio 164a
9 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
10 */
11
12 // Exit if accessed directly.
13 if ( ! defined( 'ABSPATH' ) ) { exit; }
14
15 if ( ! class_exists( 'Charitable_Public' ) ) :
16
17 /**
18 * Charitable Public class.
19 *
20 * @final
21 * @since 1.0.0
22 */
23 final class Charitable_Public {
24
25 /**
26 * The single instance of this class.
27 *
28 * @since 1.2.0
29 *
30 * @var Charitable_Public|null
31 */
32 private static $instance = null;
33
34 /**
35 * Returns and/or create the single instance of this class.
36 *
37 * @since 1.2.0
38 *
39 * @return Charitable_Public
40 */
41 public static function get_instance() {
42 if ( is_null( self::$instance ) ) {
43 self::$instance = new self();
44 }
45
46 return self::$instance;
47 }
48
49 /**
50 * Set up the class.
51 *
52 * @since 1.0.0
53 */
54 private function __construct() {
55 add_action( 'after_setup_theme', array( $this, 'load_template_files' ) );
56 add_action( 'wp_enqueue_scripts', array( $this, 'setup_scripts' ) );
57 add_action( 'wp_enqueue_scripts', array( $this, 'maybe_enqueue_donation_form_scripts' ), 11 );
58 add_action( 'charitable_campaign_loop_before', array( $this, 'maybe_enqueue_donation_form_scripts' ) );
59 add_filter( 'post_class', array( $this, 'campaign_post_class' ) );
60 add_filter( 'comments_open', array( $this, 'disable_comments_on_application_pages' ) );
61
62 do_action( 'charitable_public_start', $this );
63 }
64
65 /**
66 * Load the template functions after theme is loaded.
67 *
68 * This gives themes time to override the functions.
69 *
70 * @since 1.2.3
71 *
72 * @return void
73 */
74 public function load_template_files() {
75 require_once( 'charitable-template-functions.php' );
76 require_once( 'charitable-template-hooks.php' );
77 }
78
79 /**
80 * Loads public facing scripts and stylesheets.
81 *
82 * @since 1.0.0
83 *
84 * @return void
85 */
86 public function setup_scripts() {
87 if ( ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ) {
88 $suffix = '';
89 $version = '';
90 } else {
91 $suffix = '.min';
92 $version = charitable()->get_version();
93 }
94
95 $assets_dir = charitable()->get_path( 'assets', false );
96
97 /* Main Charitable script. */
98 $minimum = charitable_get_minimum_donation_amount();
99 $amount_msg = $minimum > 0
100 ? sprintf(
101 /* Translators: %s: minimum donatino amount */
102 __( 'You must donate at least %s.', 'charitable' ), charitable_format_money( $minimum )
103 )
104 : sprintf(
105 /* Translators: %s: minimum donatino amount */
106 __( 'You must donate more than %s.', 'charitable' ), charitable_format_money( $minimum )
107 );
108
109 /**
110 * Filter the Javascript vars array.
111 *
112 * @since 1.0.0
113 *
114 * @param array $vars The set of vars.
115 */
116 $vars = apply_filters( 'charitable_javascript_vars', array(
117 'ajaxurl' => admin_url( 'admin-ajax.php' ),
118 'loading_gif' => $assets_dir . '/images/charitable-loading.gif',
119 'currency_format_num_decimals' => esc_attr( charitable_get_currency_helper()->get_decimals() ),
120 'currency_format_decimal_sep' => esc_attr( charitable_get_currency_helper()->get_decimal_separator() ),
121 'currency_format_thousand_sep' => esc_attr( charitable_get_currency_helper()->get_thousands_separator() ),
122 'currency_format' => esc_attr( charitable_get_currency_helper()->get_accounting_js_format() ), // For accounting.js.
123 'minimum_donation' => $minimum,
124 'error_invalid_amount' => $amount_msg,
125 'error_required_fields' => __( 'Please fill out all required fields.', 'charitable' ),
126 'error_unknown' => __( 'Your donation could not be processed. Please reload the page and try again.', 'charitable' ),
127 'error_invalid_cc_number' => __( 'The credit card passed is not valid.', 'charitable' ),
128 'error_invalid_cc_expiry' => __( 'The credit card expiry date is not valid.', 'charitable' ),
129 ) );
130
131 /* Accounting.js */
132 wp_register_script(
133 'accounting',
134 $assets_dir . 'js/libraries/accounting'. $suffix . '.js',
135 array( 'jquery-core' ),
136 $version,
137 true
138 );
139
140 $deps = array( 'accounting', 'jquery-core' );
141
142 if ( wp_script_is( 'charitable-sessions', 'enqueued' ) ) {
143 array_unshift( $deps, 'charitable-sessions' );
144 }
145
146 wp_register_script(
147 'charitable-script',
148 $assets_dir . 'js/charitable'. $suffix . '.js',
149 $deps,
150 $version,
151 true
152 );
153
154 wp_localize_script(
155 'charitable-script',
156 'CHARITABLE_VARS',
157 $vars
158 );
159
160 /* Credit card validation */
161 wp_register_script(
162 'charitable-credit-card',
163 $assets_dir . 'js/charitable-credit-card'. $suffix . '.js',
164 array( 'charitable-script' ),
165 $version,
166 true
167 );
168
169 /* Main styles */
170 wp_register_style(
171 'charitable-styles',
172 $assets_dir . 'css/charitable' . $suffix .'.css',
173 array(),
174 $version
175 );
176
177 wp_enqueue_style( 'charitable-styles' );
178
179 /* Lean Modal is registered but NOT enqueued yet. */
180 if ( 'modal' == charitable_get_option( 'donation_form_display', 'separate_page' ) ) {
181
182 wp_register_script(
183 'lean-modal',
184 $assets_dir . 'js/libraries/leanModal' . $suffix . '.js',
185 array( 'jquery-core' ),
186 $version
187 );
188
189 wp_register_style(
190 'lean-modal-css',
191 $assets_dir . 'css/modal' . $suffix .'.css',
192 array(),
193 $version
194 );
195
196 }
197
198 wp_register_style(
199 'charitable-datepicker',
200 $assets_dir . 'css/charitable-datepicker' . $suffix .'.css',
201 array(),
202 $version
203 );
204
205 /* pupload Fields is also registered but NOT enqueued. */
206 $upload_vars = array(
207 'remove_image' => _x( 'Remove', 'remove image button text', 'charitable' ),
208 'max_file_uploads_single' => __( 'You can only upload %d file', 'charitable' ),
209 'max_file_uploads_plural' => __( 'You can only upload a maximum of %d files', 'charitable' ),
210 'max_file_size' => __( '%1$s exceeds the max upload size of %2$s', 'charitable' ),
211 'upload_problem' => __( '%s failed to upload. Please try again.', 'charitable' ),
212 );
213
214 wp_register_script(
215 'charitable-plup-fields',
216 $assets_dir . 'js/charitable-plupload-fields' . $suffix . '.js',
217 array( 'jquery-ui-sortable', 'wp-ajax-response', 'plupload-all' ),
218 $version,
219 true
220 );
221
222 wp_localize_script(
223 'charitable-plup-fields',
224 'CHARITABLE_UPLOAD_VARS',
225 $upload_vars
226 );
227
228 wp_register_style(
229 'charitable-plup-styles',
230 $assets_dir . 'css/charitable-plupload-fields' . $suffix . '.css',
231 array(),
232 $version
233 );
234 }
235
236 /**
237 * Conditionally load the donation form scripts if we're viewing the donation form.
238 *
239 * @since 1.4.0
240 *
241 * @return boolean True if scripts were loaded. False otherwise.
242 */
243 public function maybe_enqueue_donation_form_scripts() {
244 $load = charitable_is_page( 'campaign_donation_page' );
245
246 if ( ! $load ) {
247 $load = 'charitable_campaign_loop_before' == current_action() && 'modal' == charitable_get_option( 'donation_form_display', 'separate_page' );
248 }
249
250 if ( $load ) {
251 $this->enqueue_donation_form_scripts();
252 }
253
254 return $load;
255 }
256
257 /**
258 * Enqueues the donation form scripts.
259 *
260 * @since 1.4.6
261 *
262 * @return void
263 */
264 public function enqueue_donation_form_scripts() {
265 wp_enqueue_script( 'charitable-script' );
266
267 if ( Charitable_Gateways::get_instance()->any_gateway_supports( 'credit-card' ) ) {
268 wp_enqueue_script( 'charitable-credit-card' );
269 }
270 }
271
272 /**
273 * Adds custom post classes when viewing campaign.
274 *
275 * @since 1.0.0
276 *
277 * @param string[] $classes List of classes to be added with post_class().
278 * @return string[]
279 */
280 public function campaign_post_class( $classes ) {
281 $campaign = charitable_get_current_campaign();
282
283 if ( ! $campaign ) {
284 return $classes;
285 }
286
287 $classes[] = $campaign->has_goal() ? 'campaign-has-goal' : 'campaign-has-no-goal';
288 $classes[] = $campaign->is_endless() ? 'campaign-is-endless' : 'campaign-has-end-date';
289 return $classes;
290 }
291
292 /**
293 * Disable comments on application pages like the donation page.
294 *
295 * @since 1.3.0
296 *
297 * @param boolean $open Whether comments are open.
298 * @return boolean
299 */
300 public function disable_comments_on_application_pages( $open ) {
301 /* If open is already false, just hit return. */
302 if ( ! $open ) {
303 return $open;
304 }
305
306 if ( charitable_is_page( 'campaign_donation_page', array( 'strict' => true ) )
307 || charitable_is_page( 'campaign_widget_page' )
308 || charitable_is_page( 'donation_receipt_page' )
309 || charitable_is_page( 'donation_processing_page' ) ) {
310 $open = false;
311 }
312
313 return $open;
314 }
315 }
316
317 endif;
318