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 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 / dashboard / class-charitable-dashboard-legacy.php

class-charitable-dashboard-legacy.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.11, at includes/admin/dashboard/class-charitable-dashboard-legacy.php

1,499 lines 48.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Charitable Dashboard UI.
4 *
5 * @package Charitable/Classes/Charitable_Dashboard
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.1
10 * @version 1.8.1
11 */
12
13 // Exit if accessed directly.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 if ( ! class_exists( 'Charitable_Dashboard_Legacy' ) ) :
19
20 /**
21 * Charitable_Dashboard_Legacy
22 *
23 * @final
24 * @since 1.8.1
25 */
26 final class Charitable_Dashboard_Legacy {
27
28 /**
29 * The single instance of this class.
30 *
31 * @var Charitable_Dashboard_Legacy|null
32 */
33 private static $instance = null;
34
35 /**
36 * The dashboard data that holds start date, end date, and filter.
37 *
38 * @since 1.8.1
39 *
40 * @var array
41 */
42 public $dashboard_data = array();
43
44 /**
45 * The date filter values.
46 *
47 * @since 1.8.1
48 *
49 * @var array
50 */
51 public $date_range_filter_values = array();
52
53 /**
54 * The start date.
55 *
56 * @since 1.8.1
57 *
58 * @var string
59 */
60 public $start_date = false;
61
62 /**
63 * The end date.
64 *
65 * @since 1.8.1
66 *
67 * @var string
68 */
69 public $end_date = false;
70
71 /**
72 * The number of days.
73 *
74 * @since 1.8.1
75 *
76 * @var int
77 */
78 public $days = false;
79
80 /**
81 * The donation axis of the highlight chart.
82 *
83 * @since 1.8.1
84 *
85 * @var array
86 */
87 public $donation_axis = array();
88
89 /**
90 * The date axis of the highlight chart.
91 *
92 * @since 1.8.1
93 *
94 * @var array
95 */
96 public $date_axis = array();
97
98 /**
99 * The default number of days to show in the filter.
100 *
101 * @since 1.8.1
102 *
103 * @var int
104 */
105 private $filter_days_default = 7;
106
107 /**
108 * Stores the last date/time of cache, false if there is no active or valid cache.
109 *
110 * @since 1.8.1
111 *
112 * @var int
113 */
114 public $is_data_cached = false;
115
116 /**
117 * Create object instance.
118 *
119 * @param array $args The arguments.
120 *
121 * @since 1.8.1
122 */
123 public function __construct( $args = array() ) {
124
125 do_action( 'charitable_admin_reports_start', $this );
126
127 add_action( 'charitable_after_admin_dashboard', array( $this, 'dashboard_cta' ) );
128
129 add_action( 'charitable_admin_dashboard_notifications', array( $this, 'display_notifications' ) );
130
131 $this->init( $args );
132 }
133
134 /**
135 * Run things upon init.
136 *
137 * @since 1.8.1
138 *
139 * @param array $args The arguments.
140 *
141 * @return void
142 */
143 private function init( $args = array() ) {
144
145 $defaults = apply_filters(
146 'charitable_dashboard_data_arg_defaults',
147 array(
148 'start_date' => gmdate( 'Y/m/d', strtotime( '-7 days' ) ),
149 'end_date' => gmdate( 'Y/m/d' ),
150 'days' => 7,
151 )
152 );
153
154 $cached_dashboard_data_args = $this->get_cached_dashboard_data_args();
155
156 if ( ! empty( $cached_dashboard_data_args ) && ! empty( $cached_dashboard_data_args['start_date'] ) && ! empty( $cached_dashboard_data_args['end_date'] ) && ! empty( $cached_dashboard_data_args['days'] ) ) {
157
158 $dashboard_data_args['start_date'] = esc_html( $cached_dashboard_data_args['start_date'] );
159 $dashboard_data_args['end_date'] = esc_html( $cached_dashboard_data_args['end_date'] );
160 $dashboard_data_args['days'] = intval( $cached_dashboard_data_args['days'] );
161
162 $this->is_data_cached = $cached_dashboard_data_args['timestamp'];
163
164 } else {
165
166 $this->is_data_cached = false;
167 $dashboard_data_args = wp_parse_args( $args, $defaults );
168 }
169
170 do_action( 'charitable_admin_dashboard_init_start', $this );
171
172 // Get the date filter values.
173 $this->date_range_filter_values = apply_filters(
174 'charitable_dashboard_date_range_filter_values',
175 array(
176 '7' => __( 'Last 7 Days', 'charitable' ),
177 '14' => __( 'Last 14 Days', 'charitable' ),
178 '30' => __( 'Last 30 Days', 'charitable' ),
179 )
180 );
181
182 $this->start_date = $dashboard_data_args['start_date'];
183 $this->end_date = $dashboard_data_args['end_date'];
184 $this->days = $dashboard_data_args['days'];
185
186 $this->dashboard_data = (array) $dashboard_data_args;
187
188 $this->maybe_load_scripts();
189
190 // Allow Charitable and third-party plugins to hook into the dashboard.
191 do_action( 'charitable_admin_dashboard_init_end', $this );
192 }
193
194 /**
195 * Get the cached dashboard notifications.
196 *
197 * @since 1.8.2
198 *
199 * @return array
200 */
201 public function display_notifications() {
202
203 // Grab the array of notifications, which includes the title, some meta, and the message.
204 $notifications = get_option( 'charitable_dashboard_notifications', array() );
205
206 if ( empty( $notifications ) ) {
207 return false;
208 }
209
210 // remove any notifications that don't have a 'type' key.
211 $notifications = array_filter(
212 $notifications,
213 function ( $notification ) {
214 return isset( $notification['type'] );
215 }
216 );
217
218 // remove any notifications that have a 'dismissed' key.
219 $notifications = array_filter(
220 $notifications,
221 function ( $notification ) {
222 return ! isset( $notification['dismissed'] );
223 }
224 );
225
226 if ( empty( $notifications ) ) {
227 return false;
228 }
229
230 // sort notifications by type = 'error' first, then 'warning', followed by 'notice'.
231 uasort(
232 $notifications,
233 function ( $a, $b ) {
234 $types = array( 'error', 'warning', 'notice' );
235 $pos_a = array_search( $a['type'], $types ); // phpcs:ignore
236 $pos_b = array_search( $b['type'], $types ); // phpcs:ignore
237
238 return $pos_a - $pos_b;
239 }
240 );
241
242 include charitable()->get_path( 'includes' ) . 'admin/templates/dashboard-notifications.php';
243 }
244
245
246 /**
247 * Remove a dashboard notification.
248 *
249 * @since 1.8.2
250 *
251 * @param string $notification_id The notification ID.
252 *
253 * @return boolean
254 */
255 public function charitable_remove_dashboard_notification( $notification_id = false ) {
256
257 // check nonce.
258 if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'charitable_dashboard_notification_nonce' ) ) {
259 wp_send_json_error( array( 'message' => esc_html__( 'Invalid nonce.', 'charitable' ) ) );
260 }
261
262 if ( false === $notification_id ) {
263 return false;
264 }
265
266 $notification_id = sanitize_text_field( wp_unslash( $notification_id ) );
267
268 $notifications = (array) get_option( 'charitable_dashboard_notifications', array() );
269
270 if ( empty( $notifications ) ) {
271 return false;
272 }
273
274 if ( ! empty( $notifications[ $notification_id ] ) ) {
275 unset( $notifications[ $notification_id ] );
276 update_option( 'charitable_dashboard_notifications', $notifications );
277 return true;
278 } else {
279 return false;
280 }
281 }
282
283 /**
284 * Get the donation axis information for the highlight chart.
285 *
286 * @since 1.8.1.6
287 *
288 * @return array
289 */
290 public function enable_tooltips() {
291
292 $donation_axis = $this->get_donation_axis();
293
294 if ( empty( $donation_axis ) ) {
295 return false;
296 }
297
298 // remove any '0' and ',' from the string.
299 $donation_axis = array_map(
300 function ( $value ) {
301 return str_replace( array( '0', ',' ), '', $value );
302 },
303 $donation_axis
304 );
305
306 // if the trimmed length is 0, return false.
307 $enable_tooltips = array_filter(
308 $donation_axis,
309 function ( $value ) {
310 return strlen( trim( $value ) ) > 0;
311 }
312 );
313
314 return $enable_tooltips;
315 }
316
317 /**
318 * Get the donation axis information for the highlight chart.
319 *
320 * @since 1.8.1
321 *
322 * @return array
323 */
324 public function get_donation_axis() {
325
326 $donation_axis = $this->maybe_cache_dashboard() ? get_transient( 'wpch_dashboard_report_html_donation_axis' ) : false;
327 $date_axis = $this->maybe_cache_dashboard() ? get_transient( 'wpch_dashboard_report_html_date_axis' ) : false;
328
329 if ( $donation_axis && $date_axis ) {
330 return $donation_axis;
331 }
332
333 if ( empty( $this->donation_axis ) ) {
334 return array( 0, 0, 0, 0, 0, 0 );
335 }
336
337 return (array) $this->donation_axis;
338 }
339
340 /**
341 * Get the date axis information for the highlight chart.
342 *
343 * @since 1.8.1
344 *
345 * @return array
346 */
347 public function get_date_axis() {
348
349 $donation_axis = $this->maybe_cache_dashboard() ? get_transient( 'wpch_dashboard_report_html_donation_axis' ) : false;
350 $date_axis = $this->maybe_cache_dashboard() ? get_transient( 'wpch_dashboard_report_html_date_axis' ) : false;
351
352 if ( $donation_axis && $date_axis ) {
353 return $date_axis;
354 }
355
356 if ( empty( $this->date_axis ) ) {
357 return $this->get_days_between_dates( gmdate( 'Y/m/d', strtotime( '-7 days' ) ), gmdate( 'Y/m/d' ) );
358 }
359
360 return (array) $this->date_axis;
361 }
362
363 /**
364 * Generate the dashboard HTML.
365 *
366 * @since 1.8.1
367 *
368 * @param array $args The arguments.
369 *
370 * @return array
371 */
372 public function generate_dashboard_report_html( $args = array() ) {
373
374 if ( ! is_array( $args ) ) {
375 $args = array();
376 }
377
378 $defaults = array(
379 'start_date' => false,
380 'end_date' => false,
381 'days' => false,
382 'show_support_box' => true,
383 'include_icons' => true,
384 'action' => false,
385 'show_recommended_addons' => true,
386 'show_recommended_snippets' => true,
387 'show_notifications' => true,
388 'use_cache' => 'no', // 'yes' or 'no' or 'maybe'.
389 );
390
391 $args = apply_filters( 'charitable_dashboard_report_html_args', wp_parse_args( $args, $defaults ) );
392
393 // Extract individual variables from args array.
394 $start_date = $args['start_date'] ?? false;
395 $end_date = $args['end_date'] ?? false;
396 $days = $args['days'] ?? false;
397 $show_support_box = $args['show_support_box'] ?? true;
398 $include_icons = $args['include_icons'] ?? true;
399 $action = $args['action'] ?? false;
400 $show_recommended_addons = $args['show_recommended_addons'] ?? true;
401 $show_recommended_snippets = $args['show_recommended_snippets'] ?? true;
402 $show_notifications = $args['show_notifications'] ?? true;
403 $use_cache = $args['use_cache'] ?? 'no';
404
405 if ( false === $days ) {
406 $args = $this->get_cached_dashboard_data_args();
407 if ( empty( $args ) || false === $args ) {
408 $start_date = gmdate( 'Y/m/d', strtotime( '-' . $days . ' days' ) );
409 $end_date = gmdate( 'Y/m/d' );
410 $days = 7;
411 } else {
412 $start_date = $args['start_date'];
413 $end_date = $args['end_date'];
414 $days = $args['days'];
415 }
416 }
417
418 $html = $this->maybe_cache_dashboard( $use_cache ) ? get_transient( 'wpch_dashboard_report_html_' . intval( $days ) ) : false;
419 $this->donation_axis = $this->maybe_cache_dashboard( $use_cache ) ? get_transient( 'wpch_dashboard_report_html_donation_axis_' . intval( $days ) ) : false;
420 $this->date_axis = $this->maybe_cache_dashboard( $use_cache ) ? get_transient( 'wpch_dashboard_report_html_date_axis_' . intval( $days ) ) : false;
421
422 $show_snippets_on_dashboard = apply_filters( 'charitable_show_snippets_on_dashboard', true );
423
424 // if WPCode isn't activated, then don't show the WPCode snippets on the dashboard.
425 if ( $show_snippets_on_dashboard ) {
426 // is WPCode WordPress plugin activated?
427 $is_activated = Charitable_Admin_Plugins_Third_Party::get_instance()->is_plugin_activated( 'wpcode' );
428
429 // if WPCode is not activated, then don't show the WPCode snippets on the dashboard.
430 if ( ! $is_activated ) {
431 $show_recommended_snippets = false;
432 }
433 } else {
434 $show_recommended_snippets = false;
435 }
436
437 if ( false === $html || false === $this->donation_axis || false === $this->date_axis || ! $this->maybe_cache_dashboard( $use_cache ) ) {
438
439 if ( $days ) {
440 $start_date = gmdate( 'Y/m/d', strtotime( '-' . $days . ' days' ) );
441 $end_date = gmdate( 'Y/m/d' );
442 } else {
443 $start_date = ( false === $start_date ) ? $this->start_date : $start_date;
444 $end_date = ( false === $end_date ) ? $this->end_date : $end_date;
445 }
446
447 $charitable_reports = Charitable_Reports::get_instance();
448
449 $args = array(
450 'start_date' => $start_date,
451 'end_date' => $end_date,
452 'days' => $days,
453 );
454
455 $charitable_reports->init_with_array( 'dashboard', $args );
456
457 // donations.
458 $donations = $charitable_reports->get_donations();
459 $total_count_donations = count( $donations );
460 $total_amount_donations = $charitable_reports->get_donations_total();
461 $donation_average = ( $total_amount_donations > 0 && $total_amount_donations > 0 ) ? ( charitable_format_money( $total_amount_donations / $total_count_donations, 2, true ) ) : charitable_format_money( 0 );
462 $donation_total = charitable_format_money( $total_amount_donations );
463
464 // donors.
465 $total_count_donors = $charitable_reports->get_donors_count();
466
467 // refunds.
468 $refunds_data = $charitable_reports->get_refunds();
469
470 $total_amount_refunds = $refunds_data['total_amount'];
471 $total_count_refunds = $refunds_data['total_count'];
472
473 // campaigns.
474 $args = array( 'posts_per_page' => apply_filters( 'charitable_dashboard_top_campaigns_amount', 5 ) );
475 $top_campaigns = Charitable_Campaigns::ordered_by_amount( $args );
476
477 $this->donation_axis = ! empty( $charitable_reports->donation_axis ) ? (array) $charitable_reports->donation_axis : false;
478 $this->date_axis = ! empty( $charitable_reports->date_axis ) ? (array) $charitable_reports->date_axis : false;
479
480 $html = array();
481
482 ob_start();
483
484 ?>
485
486 <div class="charitable-cards">
487 <div class="charitable-container charitable-report-ui charitable-card"
488 <?php
489 if ( $action === 'download' ) :
490 ?>
491 style="width: 24.5%; display:inline-block;"<?php endif; ?>>
492 <strong><span id="charitable-top-donation-total-amount"><?php echo esc_html( $donation_total ); ?></span></strong>
493 <p><span id="charitable-top-donation-total-count"><?php echo count( $donations ); ?></span> <?php echo esc_html__( 'Total Donations', 'charitable' ); ?></p>
494 </div>
495 <div class="charitable-container charitable-report-ui charitable-card"
496 <?php
497 if ( $action === 'download' ) :
498 ?>
499 style="width: 24.5%; display:inline-block;"<?php endif; ?>>
500 <strong><span id="charitable-top-donation-average"><?php echo esc_html( $donation_average ); ?></span></strong>
501 <p><?php echo esc_html__( 'Average Donation', 'charitable' ); ?></p>
502 </div>
503 <div class="charitable-container charitable-report-ui charitable-card"
504 <?php
505 if ( $action === 'download' ) :
506 ?>
507 style="width: 24.5%; display:inline-block;"<?php endif; ?>>
508 <strong><span id="charitable-top-donor-count"><?php echo intval( $total_count_donors ); ?></span></strong>
509 <p><?php echo esc_html__( 'Donors', 'charitable' ); ?></p>
510 </div>
511 <div class="charitable-container charitable-report-ui charitable-card"
512 <?php
513 if ( $action === 'download' ) :
514 ?>
515 style="width: 24.5%; display:inline-block;"<?php endif; ?>>
516 <strong><span id="charitable-top-refund-total-amount"><?php echo charitable_format_money( $total_amount_refunds ); // phpcs:ignore ?></span></strong>
517 <p><span id="charitable-top-refund-count"><?php echo intval( $total_count_refunds ); ?></span> <?php echo esc_html__( 'Refunds', 'charitable' ); ?></p>
518 </div>
519 </div>
520 <?php
521
522 $html['charitable_cards'] = ob_get_clean();
523
524 $no_items_text = ( $days > 0 ) ? esc_html__( 'There are no donations in the last ', 'charitable' ) . $days . ' ' . esc_html__( 'days.', 'charitable' ) : esc_html__( 'There are no donations for the selected date range.', 'charitable' );
525
526 ob_start();
527 ?>
528 <div class="charitable-container charitable-report-card charitable-recent-donations-report">
529 <div class="header">
530 <h4><?php echo esc_html__( 'Recent Donations', 'charitable' ); ?></h4>
531 <a href="#" class="charitable-toggle"><i class="fa fa-angle-down charitable-angle-down"></i></a>
532 </div>
533 <div class="charitable-toggle-container charitable-report-ui">
534 <?php
535
536 $list = $charitable_reports->generate_recent_donations_list( $donations, 10, $include_icons );
537
538 if ( ! empty( $list ) ) :
539 ?>
540 <div class="the-list">
541 <ul id="charitable-recent-donations-list">
542 <?php echo $list; // phpcs:ignore ?>
543 </ul>
544 </div>
545 <?php else : ?>
546 <div class="no-items">
547 <p><strong><?php echo esc_html( $no_items_text ); ?></strong></p>
548 <p class="link"><a href="<?php echo admin_url( 'post-new.php?post_type=donation' ); // phpcs:ignore ?>"><?php echo esc_html__( 'Add Donation', 'charitable' ); ?>
549 <?php
550 if ( $include_icons ) :
551 ?>
552 <img src="<?php echo esc_url( charitable()->get_path( 'assets', false ) ) . 'images/icons/east.svg'; // phpcs:ignore ?>" /><?php endif; ?></a></p>
553 </div>
554 <?php endif; ?>
555 </div>
556 <div class="more">
557 <?php if ( false === $action ) : ?>
558 <a href="<?php echo admin_url( 'edit.php?post_type=donation' ); // phpcs:ignore ?>"><?php echo esc_html__( 'View All Donations', 'charitable' ); ?>
559 <?php
560 if ( $include_icons ) :
561 ?>
562 <img src="<?php echo esc_url( charitable()->get_path( 'assets', false ) ) . 'images/icons/east.svg'; // phpcs:ignore ?>" /><?php endif; ?></a>
563 <?php endif; ?>
564 </div>
565 </div>
566
567 <div class="charitable-container charitable-report-card charitable-top-campaigns-report">
568 <div class="header">
569 <h4><?php echo esc_html__( 'Top Campaigns', 'charitable' ); ?></h4>
570 <a href="#" class="charitable-toggle"><i class="fa fa-angle-down charitable-angle-down"></i></a>
571 </div>
572 <div class="charitable-toggle-container charitable-report-ui">
573 <?php if ( ! empty( $top_campaigns->posts ) ) : ?>
574 <div class="the-list">
575 <ul id="charitable-top-campaigns-list">
576 <?php echo $charitable_reports->generate_top_campaigns( $top_campaigns ); // phpcs:ignore ?>
577 </ul>
578 </div>
579 <?php else : ?>
580 <div class="no-items">
581 <p><strong><?php echo esc_html__( 'There are no campaigns at the moment.', 'charitable' ); ?></strong></p>
582 <?php if ( false === $action ) : ?>
583 <?php if ( charitable_disable_legacy_campaigns() ) : ?>
584 <p class="link"><a href="<?php echo admin_url( 'admin.php?page=charitable-campaign-builder&view=template' ); // phpcs:ignore ?>"><?php echo esc_html__( 'Add New Campaign', 'charitable' ); ?>
585 <?php else : ?>
586 <p class="link"><a href="<?php echo admin_url( 'post-new.php?post_type=campaign' ); // phpcs:ignore ?>"><?php echo esc_html__( 'Add New Campaign', 'charitable' ); ?>
587 <?php endif; ?>
588
589
590 <?php
591 if ( $include_icons ) :
592 ?>
593 <img src="<?php echo esc_url( charitable()->get_path( 'assets', false ) ) . 'images/icons/east.svg'; // phpcs:ignore ?>" /><?php endif; ?></a></p>
594 <?php endif; ?>
595 </div>
596 <?php endif; ?>
597 </div>
598 <div class="more">
599 <?php if ( ! empty( $top_campaigns->posts ) && false === $action ) : ?>
600 <?php if ( charitable_disable_legacy_campaigns() ) : ?>
601 <a href="<?php echo admin_url( 'admin.php?page=charitable-campaign-builder&view=template' ); // phpcs:ignore ?>"><?php echo esc_html__( 'Add New Campaign', 'charitable' ); ?> <img src="<?php echo esc_url( charitable()->get_path( 'assets', false ) ) . 'images/icons/east.svg'; // phpcs:ignore ?>" /></a>
602 <?php else : ?>
603 <a href="<?php echo admin_url( 'post-new.php?post_type=campaign' ); // phpcs:ignore ?>"><?php echo esc_html__( 'Add New Campaign', 'charitable' ); ?> <img src="<?php echo esc_url( charitable()->get_path( 'assets', false ) ) . 'images/icons/east.svg'; // phpcs:ignore ?>" /></a>
604 <?php endif; ?>
605 <?php endif; ?>
606 </div>
607 </div>
608
609 <?php
610 if ( $show_recommended_snippets ) :
611
612 $recommended_snippets = $this->get_dashboard_recommended_snippets( 2 );
613
614 if ( ! empty( $recommended_snippets ) ) :
615
616 ?>
617 <div class="charitable-container charitable-report-card charitable-recommended-snippets">
618 <div class="header">
619 <h4><?php echo esc_html__( 'Recommended Snippets', 'charitable' ); ?></h4>
620 <a href="#" class="charitable-toggle"><i class="fa fa-angle-down charitable-angle-down"></i></a>
621 </div>
622 <div class="charitable-toggle-container charitable-report-ui">
623 <div id="charitable-wpcode-snippets-list">
624 <div class="charitable-wpcode-snippets-list">
625
626 <?php
627 foreach ( $recommended_snippets as $snippet ) :
628 $button_text = $snippet['installed'] ? __( 'Edit Snippet', 'charitable' ) : __( 'Install Snippet', 'charitable' );
629 $button_type_class = $snippet['installed'] ? 'button-primary' : 'button-secondary';
630 $button_action = $snippet['installed'] ? 'edit' : 'install';
631 $library_id = ! empty( $snippet['library_id'] ) ? ( $snippet['library_id'] ) : false;
632 ?>
633 <div class="charitable-wpcode-snippet">
634 <div class="charitable-wpcode-snippet-header">
635 <h3 class="charitable-wpcode-snippet-title"><?php echo esc_html( $snippet['title'] ); ?></h3>
636 <div class="charitable-wpcode-snippet-note"><?php echo esc_html( $snippet['note'] ); ?></div>
637 </div>
638 <div class="charitable-wpcode-snippet-footer">
639 <a
640 href="<?php echo esc_url( $snippet['install'] ); ?>"
641 class="button charitable-wpcode-snippet-button <?php echo sanitize_html_class( $button_type_class ); ?>"
642 data-action="<?php echo esc_attr( $button_action ); ?>"><?php echo esc_html( $button_text ); ?> </a>
643 <?php if ( $library_id ) : ?>
644 <a class="charitable-wpcode-snippet-external-link" title="<?php esc_html_e( 'View this snippet on WPCode.com', 'charitable' ); ?>" href="https://library.wpcode.com/profile/wpcharitable/?code_type=all&order=popular&view=all&search=<?php echo urlencode( $snippet['title'] ); ?>" target="_blank"><span class="dashicons dashicons-external"></span></a>
645 <?php endif; ?>
646 </div>
647 </div>
648 <?php endforeach; ?>
649 </div>
650 <div class="no-items">
651 <p class="link"><a href="<?php echo esc_url( admin_url( 'admin.php?page=charitable-tools&tab=snippets' ) ); ?>"><?php esc_html_e( 'View All Snippets', 'charitable' ); ?> <img src="<?php echo esc_url( charitable()->get_path( 'assets', false ) ) . 'images/icons/east.svg'; ?>" /> </a></p>
652 </div>
653 </div>
654 </div>
655 </div>
656 <?php
657
658 endif; // snippets links not empty.
659
660 endif;
661
662 if ( $show_support_box ) :
663
664 $dashboard_support_links = $this->get_dashboard_support_links();
665
666 if ( ! empty( $dashboard_support_links ) ) :
667 ?>
668 <div class="charitable-container charitable-report-card charitable-support">
669 <div class="header">
670 <h4><?php echo esc_html__( 'Support', 'charitable' ); ?></h4>
671 <a href="#" class="charitable-toggle"><i class="fa fa-angle-down charitable-angle-down"></i></a>
672 </div>
673 <div class="charitable-toggle-container charitable-report-ui">
674 <div class="the-list">
675 <ul>
676 <?php foreach ( $dashboard_support_links as $dashboard_support_link ) : ?>
677 <?php
678 if ( ! empty( $dashboard_support_link['lite_pro'] )
679 && ( ( $dashboard_support_link['lite_pro'] === 'lite' && charitable_is_pro() ) || ( $dashboard_support_link['lite_pro'] === 'pro' && ! charitable_is_pro() ) ) ) {
680 continue;
681 }
682 ?>
683 <li>
684 <?php if ( ! empty( $dashboard_support_link['icon'] ) ) : ?>
685 <div class="icon">
686 <img src="<?php echo esc_url( $dashboard_support_link['icon'] ); ?>" alt="">
687 </div>
688 <?php endif; ?>
689 <div class="info">
690 <a target="_blank" href="<?php echo esc_url( $dashboard_support_link['url'] ); ?>"><?php echo esc_html( $dashboard_support_link['title'] ); ?></a>
691 </div>
692 </li>
693 <?php endforeach; ?>
694 </ul>
695 </div>
696 </div>
697 </div>
698 <?php
699
700 endif; // support links not empty.
701
702 endif; // show support box.
703
704 if ( $show_notifications ) :
705
706 Charitable_Notifications::get_instance()->output( 'dashboard' );
707
708 endif; // show support box.
709
710 if ( $show_recommended_addons ) :
711
712 $recommended_addons = $this->get_dashboard_recommended_addons();
713
714 if ( ! empty( $recommended_addons ) ) :
715
716 ?>
717 <div class="charitable-container charitable-report-card charitable-recommended-addons">
718 <div class="header">
719 <h4><?php echo esc_html__( 'Recommended Addons', 'charitable' ); ?></h4>
720 <a href="#" class="charitable-toggle"><i class="fa fa-angle-down charitable-angle-down"></i></a>
721 </div>
722 <div class="charitable-toggle-container charitable-report-ui">
723 <div class="the-list">
724 <ul>
725 <?php
726 foreach ( $recommended_addons as $addon_slug => $addon_info ) :
727
728 $extension_url = charitable_ga_url(
729 'https://wpcharitable.com/extensions/charitable-' . $addon_slug,
730 urlencode( 'Recommended Extensions' ), // phpcs:ignore
731 $addon_slug
732 );
733
734 ?>
735 <li class="<?php echo esc_attr( $addon_slug ); ?>">
736 <?php if ( ! empty( $addon_info['recommended'] ) ) : ?>
737 <span class="popular"><?php echo esc_html__( 'Popular', 'charitable' ); ?></span>
738 <?php endif; ?>
739 <a href="<?php echo esc_url( $extension_url ); ?>" target="_blank" rel="noopener">
740 <?php /* translators: %s: extension title */ ?>
741 <img src="<?php echo esc_url( charitable()->get_path( 'assets', false ) ); ?>images/extensions/<?php echo esc_attr( $addon_slug ); ?>.png" alt="<?php echo esc_attr( sprintf( _x( '%s banner', 'extension banner', 'charitable' ), $addon_slug ) ); ?>" />
742 <h4><?php echo esc_html( $addon_info['title'] ); ?></h4>
743 <?php echo esc_html( $addon_info['description'] ); ?>
744 </a>
745 </li><?php endforeach; ?>
746 </ul>
747 </div>
748 </div>
749 </div>
750 <?php
751
752 endif; // support links not empty.
753
754 endif; // show recommended addons box.
755
756 $html['charitable_reports'] = ob_get_clean();
757
758 if ( $this->maybe_cache_dashboard( $use_cache ) ) :
759
760 set_transient( 'wpch_dashboard_report_html_' . intval( $days ), $html, MINUTE_IN_SECONDS );
761 set_transient( 'wpch_dashboard_report_html_donation_axis_' . intval( $days ), $this->donation_axis, MINUTE_IN_SECONDS );
762 set_transient( 'wpch_dashboard_report_html_date_axis_' . intval( $days ), $this->date_axis, MINUTE_IN_SECONDS );
763
764 endif;
765
766 } // End if().
767
768 return $html;
769 }
770
771 /**
772 * Get the cached dashboard data args.
773 *
774 * @since 1.8.1
775 *
776 * @return array
777 */
778 public function get_cached_dashboard_data_args() {
779
780 if ( ! $this->maybe_cache_dashboard() ) {
781 return false;
782 }
783
784 $dashboard_data_args = get_transient( 'wpch_dashboard_data_args' );
785
786 return $dashboard_data_args;
787 }
788
789 /**
790 * Set the cached dashboard data args.
791 *
792 * @since 1.8.1
793 *
794 * @param array $dashboard_data_args The dashboard data args.
795 *
796 * @return bool False if not set, otherwise the date/time of cache.
797 */
798 public function set_cached_dashboard_data_args( $dashboard_data_args = array() ) {
799
800 if ( empty( $dashboard_data_args ) || ! $this->maybe_cache_dashboard() ) {
801 return false;
802 }
803
804 // Set the timestamp.
805 $dashboard_data_args['timestamp'] = gmdate( 'Y/m/d h:i A', current_time( 'timestamp', 0 ) );
806
807 $transient_set = set_transient( 'wpch_dashboard_data_args', $dashboard_data_args, DAY_IN_SECONDS );
808
809 return ( $transient_set ) ? $dashboard_data_args['timestamp'] : false; // phpcs:ignore
810 }
811
812 /**
813 * A check to see if the dashboard data is cached, and if so the timestamp of when it was cached.
814 *
815 * @since 1.8.1
816 *
817 * @return string
818 */
819 public function is_dashboard_data_cached() {
820
821 if ( ! $this->maybe_cache_dashboard() ) {
822 return false;
823 }
824
825 $dashboard_data_args = get_transient( 'wpch_dashboard_data_args' );
826
827 if ( $dashboard_data_args && ! empty( $dashboard_data_args['timestamp'] ) ) {
828 // return format of the date/time to something like March 31, 1970 12:00 AM.
829 return gmdate( 'F j, Y h:i A', strtotime( $dashboard_data_args['timestamp'] ) );
830 }
831
832 return false;
833 }
834
835 /**
836 * Get the start date.
837 *
838 * @since 1.8.1
839 *
840 * @return string
841 */
842 public function get_start_date() {
843
844 $start_date = ! empty( $this->dashboard_data['start_date'] ) ? $this->dashboard_data['start_date'] : false;
845
846 return $start_date;
847 }
848
849 /**
850 * Get the end date.
851 *
852 * @since 1.8.1
853 *
854 * @return string
855 */
856 public function get_end_date() {
857
858 $end_date = ! empty( $this->dashboard_data['end_date'] ) ? $this->dashboard_data['end_date'] : false;
859
860 return $end_date;
861 }
862
863 /**
864 * Get the filter value.
865 *
866 * @since 1.8.1
867 *
868 * @return string
869 */
870 public function get_filter_value() {
871
872 $filter = ! empty( $this->dashboard_data['filter'] ) ? $this->dashboard_data['filter'] : false;
873
874 return $filter;
875 }
876
877 /**
878 * Check if the report should be cached.
879 *
880 * @since 1.8.1
881 *
882 * @param bool $force_cache Force cache. Default is 'maybe'. Accepts 'yes', 'no', 'maybe'. :-).
883 *
884 * @return bool
885 */
886 public function maybe_cache_dashboard( $force_cache = 'maybe' ) {
887
888 if ( $force_cache === 'yes' ) {
889 return true;
890 }
891 if ( $force_cache === 'no' ) {
892 return false;
893 }
894 if ( charitable_is_debug() ) {
895 return false;
896 }
897 if ( defined( 'CHARITABLE_REPORTS_NO_CACHE' ) && CHARITABLE_REPORTS_NO_CACHE ) {
898 return false;
899 }
900
901 return true;
902 }
903
904 /**
905 * Is the data cached?
906 *
907 * @since 1.8.1
908 *
909 * @return boolean
910 */
911 public function is_data_cached() {
912
913 return $this->is_data_cached;
914 }
915
916 /**
917 * Return the HTML of the filter select dropdown.
918 *
919 * @since 1.8.1
920 *
921 * @param string $selected_value The selected value.
922 *
923 * @return string
924 */
925 public function get_filter_dropdown( $selected_value = false ) {
926
927 $options_values = $this->date_range_filter_values;
928
929 $selected_value = false === $selected_value && $this->days ? $this->days : $selected_value;
930 $selected_value = false === $selected_value && $this->filter_days_default ? $this->filter_days_default : $selected_value;
931
932 ob_start();
933
934 ?>
935
936 <select name="action" id="report-date-range-filter">
937 <?php foreach ( $options_values as $value => $label ) : ?>
938 <option value="<?php echo esc_attr( $value ); ?>" <?php selected( $selected_value, $value ); ?>><?php echo esc_html( $label ); ?></option>
939 <?php endforeach; ?>
940 </select>
941
942 <?php
943
944 return ob_get_clean();
945 }
946
947 /**
948 * Return the default number of days for the dashboard filter.
949 *
950 * @since 1.8.1
951 *
952 * @return string
953 */
954 public function get_days() {
955
956 $selected_value = $this->days ? $this->days : false;
957 $selected_value = false === $selected_value && $this->filter_days_default ? $this->filter_days_default : $selected_value;
958
959 return $selected_value;
960 }
961
962 /**
963 * Util function that gets dates between two given dates.
964 *
965 * @param string $start_date The start date.
966 * @param string $end_date The end date.
967 * @param string $format The date format.
968 *
969 * @since 1.8.1
970 *
971 * @return mixed
972 */
973 public function get_days_between_dates( $start_date, $end_date, $format = 'M d' ) { // phpcs:ignore
974 $days = array();
975
976 $current_date = new DateTime( $start_date );
977 $end_date = new DateTime( $end_date );
978
979 while ( $current_date <= $end_date ) {
980 $days[] = $current_date->format( 'M d' ); // 'Y-m-d
981 $current_date->modify( '+1 day' );
982 }
983
984 return $days;
985 }
986
987
988 /**
989 * Load scripts and styles.
990 *
991 * @since 1.8.1
992 *
993 * @return void
994 */
995 public function maybe_load_scripts() {
996
997 if ( ! function_exists( 'get_current_screen' ) ) {
998 return;
999 }
1000
1001 $screen = get_current_screen();
1002
1003 // Add Javascript vars at the footer of the WordPress admin, at the dashboard and the overview tab of reporting.
1004 if ( ! is_null( $screen ) && $screen->id === 'charitable_page_charitable-dashboard' ) {
1005 // Specific styles for the "dashboard".
1006 add_action( 'admin_footer', array( $this, 'report_vars' ), 100 );
1007 }
1008 }
1009
1010 /**
1011 * Enqueue assets and write JS vars for the report.
1012 *
1013 * @since 1.8.1
1014 *
1015 * @return void
1016 */
1017 public function report_vars() {
1018
1019 ?>
1020 <script id="charitable-report-data-js">
1021 var charitable_reporting = <?php echo wp_json_encode( $this->get_localized_strings() ); ?>;
1022 </script>
1023
1024 <?php
1025 }
1026
1027 /**
1028 * Get localized strings.
1029 *
1030 * @since 1.8.1
1031 *
1032 * @return array
1033 */
1034 private function get_localized_strings() {
1035
1036 $currency_helper = charitable_get_currency_helper();
1037
1038 $strings = array(
1039 'version' => Charitable::VERSION,
1040 'nonce' => wp_create_nonce( 'charitable-reporting' ),
1041 'admin_nonce' => wp_create_nonce( 'charitable-admin' ),
1042 'currency_symbol' => $currency_helper->get_currency_symbol(),
1043 'ajax_url' => admin_url( 'admin-ajax.php' ),
1044 'date_select_day' => 'DD',
1045 'date_select_month' => 'MM',
1046 'headline_chart_options' => array(
1047 'donation_axis' => (array) $this->get_donation_axis(),
1048 'date_axis' => (array) $this->get_date_axis(),
1049 'enable_tooltips' => (bool) $this->enable_tooltips(),
1050 ),
1051 'payment_methods_chart_options' => array(
1052 'payment_percentages' => array(),
1053 'payment_labels' => array(),
1054 ),
1055 );
1056
1057 $strings = apply_filters( 'charitable_admin_dashboard_strings', $strings );
1058
1059 return $strings;
1060 }
1061
1062 /**
1063 * Get recommended addons, which can be based on the locale or currency.
1064 *
1065 * @since 1.8.1
1066 * @since 1.8.1.5 Added recommended and $limit.
1067 *
1068 * @param string $currency The currency code.
1069 * @param string $locale The locale.
1070 * @param int $limit The number of recommended addons to return.
1071 *
1072 * @return array
1073 */
1074 public function get_dashboard_recommended_addons( $currency = false, $locale = false, $limit = 6 ) {
1075
1076 $currency = ( false === $currency && function_exists( 'charitable_get_default_currency' ) ? charitable_get_default_currency() : $currency );
1077 $currencies = charitable_get_currency_helper()->get_all_currencies();
1078 $locale = $locale ? $locale : get_locale();
1079
1080 $all_extensions = array(
1081 'payfast' => array(
1082 'title' => esc_html__( 'Refunds', 'charitable' ),
1083 'description' => esc_html__( 'Accept donations in South African Rand', 'charitable' ),
1084 ),
1085 'payu-money' => array(
1086 'title' => esc_html__( 'PayUmoney', 'charitable' ),
1087 'description' => esc_html__( 'Accept donations in Indian Rupees with PayUmoney', 'charitable' ),
1088 ),
1089 'easy-digital-downloads-connect' => array(
1090 'title' => esc_html__( 'Easy Digital Downloads', 'charitable' ),
1091 'description' => esc_html__( 'Collect donations with Easy Digital Downloads', 'charitable' ),
1092 ),
1093 'recurring-donations' => array(
1094 'title' => esc_html__( 'Recurring Donations', 'charitable' ),
1095 'description' => esc_html__( 'Accept recurring donations', 'charitable' ),
1096 ),
1097 'fee-relief' => array(
1098 'title' => esc_html__( 'Fee Relief', 'charitable' ),
1099 'description' => esc_html__( 'Let donors cover the gateway fees', 'charitable' ),
1100 ),
1101 'authorize-net' => array(
1102 'title' => esc_html__( 'Authorize.NET', 'charitable' ),
1103 'description' => esc_html__( 'Collect donations with Authorize.Net', 'charitable' ),
1104 ),
1105 'ambassadors' => array(
1106 'title' => esc_html__( 'Ambassadors', 'charitable' ),
1107 'description' => esc_html__( 'Peer to peer fundraising or crowdfunding', 'charitable' ),
1108 ),
1109 'windcave' => array(
1110 'title' => esc_html__( 'Windcave', 'charitable' ),
1111 'description' => sprintf(
1112 /* translators: %s: currency code */
1113 __( 'Collect donations in %s', 'charitable' ),
1114 $currencies[ $currency ]
1115 ),
1116 ),
1117 'anonymous-donations' => array(
1118 'title' => esc_html__( 'Anonymous Donations', 'charitable' ),
1119 'description' => esc_html__( 'Let donors give anonymously', 'charitable' ),
1120 ),
1121 'user-avatar' => array(
1122 'title' => esc_html__( 'User Avatar', 'charitable' ),
1123 'description' => esc_html__( 'Let your donors upload their own profile photo', 'charitable' ),
1124 ),
1125 'video' => array(
1126 'title' => esc_html__( 'Video', 'charitable' ),
1127 'description' => esc_html__( 'Boost campaigns by adding videos', 'charitable' ),
1128 ),
1129 'annual-receipts' => array(
1130 'title' => esc_html__( 'Annual Receipts', 'charitable' ),
1131 'description' => esc_html__( 'Provide downloadable annual receipts', 'charitable' ),
1132 ),
1133 'pdf-receipts' => array(
1134 'title' => esc_html__( 'PDF Receipts', 'charitable' ),
1135 'description' => esc_html__( 'Make life easy for your donors by providing them with a PDF receipt for their donation', 'charitable' ),
1136 ),
1137 );
1138
1139 if ( 'en_ZA' === $locale || 'ZAR' === $currency ) {
1140 $extensions = array_intersect_key(
1141 $all_extensions,
1142 array(
1143 'payfast' => '',
1144 'recurring-donations' => '',
1145 'ambassadors' => '',
1146 'fee-relief' => '',
1147 )
1148 );
1149 } elseif ( 'hi_IN' === $locale || 'INR' === $currency ) {
1150 $extensions = array_intersect_key(
1151 $all_extensions,
1152 array(
1153 'payu-money' => '',
1154 'ambassadors' => '',
1155 'fee-relief' => '',
1156 'windcave' => '',
1157 )
1158 );
1159 } elseif ( in_array( $locale, array( 'en_NZ', 'ms_MY', 'ja', 'zh_HK' ) ) || in_array( $currency, array( 'NZD', 'MYR', 'JPY', 'HKD' ), true ) ) {
1160 $extensions = array_intersect_key(
1161 $all_extensions,
1162 array(
1163 'recurring-donations' => '',
1164 'windcave' => '',
1165 'fee-relief' => '',
1166 )
1167 );
1168 } elseif ( in_array( $locale, array( 'th' ) ) || in_array( $currency, array( 'BND', 'FJD', 'KWD', 'PGK', 'SBD', 'THB', 'TOP', 'VUV', 'WST' ), true ) ) {
1169 $extensions = array_intersect_key(
1170 $all_extensions,
1171 array(
1172 'windcave' => '',
1173 'fee-relief' => '',
1174 'ambassadors' => '',
1175 'anonymous-donations' => '',
1176 )
1177 );
1178 } elseif ( class_exists( 'EDD' ) ) {
1179 $extensions = array_intersect_key(
1180 $all_extensions,
1181 array(
1182 'ambassadors' => '',
1183 'easy-digital-downloads-connect' => '',
1184 'anonymous-donations' => '',
1185 'user-avatar' => '',
1186 )
1187 );
1188 } else {
1189 $extensions = array_intersect_key(
1190 $all_extensions,
1191 array(
1192 'recurring-donations' => '',
1193 'authorize-net' => '',
1194 'fee-relief' => '',
1195 'ambassadors' => '',
1196 'video' => '',
1197 'annual-receipts' => '',
1198 )
1199 );
1200 }
1201
1202 $recommended_addons = $this->get_recommended_dashboard_addons();
1203
1204 // Recommended addons.
1205 if ( ! empty( $recommended_addons ) ) {
1206
1207 foreach ( $extensions as $key => $value ) {
1208 // go through extensions and remove any that are already recommended.
1209 if ( array_key_exists( $key, $recommended_addons ) ) {
1210 unset( $extensions[ $key ] );
1211 }
1212 // add recommended addons to the front of the extensions array.
1213 $extensions = array_merge( $recommended_addons, $extensions );
1214
1215 }
1216 }
1217
1218 // Chop off array to the limit.
1219 $extensions = array_slice( $extensions, 0, $limit );
1220
1221 return $extensions;
1222 }
1223
1224 /**
1225 * Get the recommended dashboard addons.
1226 *
1227 * @since 1.8.1.5
1228 * @version 1.8.3
1229 * @version 1.8.8.2
1230 *
1231 * @return array
1232 */
1233 public function get_recommended_dashboard_addons() {
1234
1235 $recommended_addons = get_transient( '_charitable_addons' ); // @codingStandardsIgnoreLine - testing.
1236
1237 // Get addons data from transient or perform API query if no transient.
1238 if ( false === $recommended_addons ) {
1239 $recommended_addons = charitable_get_addons_data_from_server();
1240 }
1241
1242 $recommended_to_return = array();
1243
1244 if ( $recommended_addons ) {
1245
1246 foreach ( (array) $recommended_addons as $i => $addon ) {
1247
1248 if ( ! isset( $addon['slug'] ) || $addon['slug'] === '' || strtolower( $addon['slug'] ) === 'auto draft' ) {
1249 continue;
1250 }
1251
1252 if ( ! is_array( $addon ) ) {
1253 $addon = array();
1254 }
1255
1256 if ( isset( $addon['featured'] ) && ! empty( $addon['sections'] ) && in_array( 'recommended', $addon['featured'], true ) ) {
1257
1258 // Check if sections is already an array or needs to be unserialized (added in 1.8.8.2)
1259 $sections = is_array( $addon['sections'] ) ? $addon['sections'] : unserialize( $addon['sections'] );
1260 $description = isset( $sections['description'] ) ? $sections['description'] : '';
1261
1262 // subsutite test for translations, trying in 1.8.3.
1263 $addon['name'] = ! empty( $addon['name'] ) && strtolower( $addon['name'] ) === 'charitable recurring donations' ? __( 'Charitable Recurring Donations', 'charitable' ) : $addon['name'];
1264 $addon['name'] = ! empty( $addon['name'] ) && strtolower( $addon['name'] ) === 'charitable pdf receipts' ? __( 'Charitable PDF Receipts', 'charitable' ) : $addon['name'];
1265 $description = ! empty( $description ) && strpos( $description, 'with recurring donations' ) !== false ? __( 'Grow your organization\'s revenue with recurring donations.', 'charitable' ) : $description;
1266 $description = ! empty( $description ) && strpos( $description, 'PDF receipt' ) !== false ? __( 'Make life easy for your donors by providing them with a PDF receipt for their donation.', 'charitable' ) : $description;
1267
1268 $recommended_to_return[ str_replace( 'charitable-', '', $addon['slug'] ) ] = array(
1269 'title' => $addon['name'],
1270 'description' => wp_strip_all_tags( $description ),
1271 'recommended' => true,
1272 );
1273
1274 }
1275 }
1276 }
1277
1278 return $recommended_to_return;
1279 }
1280
1281 /**
1282 * Get recommended snippets.
1283 *
1284 * @since 1.8.1.6
1285 *
1286 * @param int $limit The number of recommended addons to return.
1287 * @param bool $show_installed Show installed snippets.
1288 *
1289 * @return array
1290 */
1291 public function get_dashboard_recommended_snippets( $limit = 3, $show_installed = true ) { // phpcs:ignore
1292
1293 $snippets = charitable_get_intergration_wpcode()->load_charitable_snippets( $limit, $show_installed );
1294
1295 return $snippets;
1296 }
1297
1298 /**
1299 * Get the dashboard support links, which are displayed in a "card" on the dashboard.
1300 *
1301 * @since 1.8.1
1302 *
1303 * @return array
1304 */
1305 public function get_dashboard_support_links() {
1306
1307 $dashboard_support_links = apply_filters(
1308 'charitable_dashboard_support_links',
1309 array(
1310 array(
1311 'title' => __( 'Getting started? Read the Beginners Guide', 'charitable' ),
1312 'url' => 'https://wpcharitable.com/start-here/?referrer=chariable-dashboard',
1313 'icon' => charitable()->get_path( 'assets', false ) . 'images/icons/stories.svg',
1314 'lite_pro' => false,
1315 ),
1316 array(
1317 'title' => __( 'View Our Documentation', 'charitable' ),
1318 'url' => 'https://wpcharitable.com/documentation?referrer=chariable-dashboard',
1319 'icon' => charitable()->get_path( 'assets', false ) . 'images/icons/menu_book.svg',
1320 'lite_pro' => false,
1321 ),
1322 array(
1323 'title' => __( 'Contact Our Expert Support Team For Help', 'charitable' ),
1324 'url' => 'https://wpcharitable.com/support?referrer=chariable-dashboard',
1325 'icon' => charitable()->get_path( 'assets', false ) . 'images/icons/sms.svg',
1326 'lite_pro' => false,
1327 ),
1328 array(
1329 'title' => __( 'Upgrade From Lite to Unlock More Powerful Features', 'charitable' ),
1330 'url' => 'https://wpcharitable.com/lite-vs-pro?referrer=chariable-dashboard',
1331 'icon' => charitable()->get_path( 'assets', false ) . 'images/icons/bullet_check.svg',
1332 'lite_pro' => 'lite',
1333 ),
1334 array(
1335 'title' => __( 'Upgrade Your Plan to Unlock More Powerful Features', 'charitable' ),
1336 'url' => 'https://wpcharitable.com/pricing?referrer=chariable-dashboard',
1337 'icon' => charitable()->get_path( 'assets', false ) . 'images/icons/bullet_check.svg',
1338 'lite_pro' => 'pro',
1339 ),
1340 )
1341 );
1342
1343 return $dashboard_support_links;
1344 }
1345
1346 /**
1347 * Get the notices to display on the dashboard. Get any stored notices/notifications from the database.
1348 *
1349 * @since 1.8.3
1350 *
1351 * @return array
1352 */
1353 public function get_notifications() {
1354
1355 $notifications_html = Charitable_Notifications::get_instance()->output( 'dashboard' );
1356
1357 return $notifications_html;
1358 }
1359
1360 /**
1361 * Get the notices to display on the dashboard. Get any stored notices/notifications from the database.
1362 *
1363 * @since 1.8.1.6
1364 * @version 1.8.2
1365 *
1366 * @return array
1367 */
1368 public function get_notices() {
1369
1370 return (array) apply_filters( 'charitable_dashboard_notices', get_option( 'charitable_dashboard_notifications', array() ) );
1371 }
1372
1373 /**
1374 * Get the dashboard guide tool notices.
1375 *
1376 * @since 1.8.1.6
1377 * @since 1.8.1.10
1378 *
1379 * @return bool
1380 */
1381 public function maybe_show_dashboard_growth_tool_chart_notice() {
1382
1383 $charitable_growth_tool_notices = get_option( 'charitable_growth_tool_notices', false );
1384
1385 $ret = true;
1386
1387 if ( ! $charitable_growth_tool_notices ) {
1388 $ret = true;
1389 }
1390
1391 if ( ! empty( $charitable_growth_tool_notices['dismiss']['dashboard'] ) ) {
1392 $ret = false;
1393 }
1394
1395 // Don't show this immediately for new users.
1396 $slug = 'dashboard-growth-tool-chart';
1397
1398 // determine when to display this message. for now, there should be some sensible boundaries before showing the notification: a minimum of 14 days of use, created one campaign.
1399 $activated_datetime = ( false !== get_option( 'wpcharitable_activated_datetime' ) ) ? get_option( 'wpcharitable_activated_datetime' ) : false;
1400 $days = 0;
1401 if ( $activated_datetime ) {
1402 $diff = current_time( 'timestamp' ) - $activated_datetime;
1403 $days = abs( round( $diff / 86400 ) );
1404 }
1405
1406 $count_campaigns = wp_count_posts( 'campaign' );
1407 $total_campaigns = isset( $count_campaigns->publish ) ? $count_campaigns->publish : 0;
1408
1409 if ( $days >= apply_filters( 'charitable_days_since_activated', 14 ) && $total_campaigns >= 1 ) {
1410 // check transient.
1411 $help_pointers = get_transient( 'charitable_' . $slug . '_banner' );
1412
1413 // render five star rating banner/notice.
1414 if ( ! $help_pointers ) {
1415 return apply_filters( 'charitable_show_dashboard_growth_tool_chart_notice', $ret );
1416 }
1417 }
1418
1419 return false;
1420 }
1421
1422 /* DEPRECATED FUNCTIONS */
1423
1424 /**
1425 * Display upgrade notice at the bottom on the plugin settings pages.
1426 *
1427 * @since 1.8.1
1428 * @version 1.8.8
1429 *
1430 * @param string $view Current view inside the plugin settings page.
1431 * @param string $css_class CSS class for the cta.
1432 * @param bool $show_close_button Whether to show the close button.
1433 */
1434 public function dashboard_cta( $view = false, $css_class = 'reports-lite-cta', $show_close_button = false ) { // phpcs:ignore
1435
1436 if ( charitable_is_pro() ) {
1437 // no need to display this cta since they have a valid license.
1438 return;
1439 }
1440
1441 if ( get_option( 'charitable_lite_reports_upgrade', false ) || apply_filters( 'charitable_lite_reports_upgrade', false ) ) {
1442 return;
1443 }
1444 ?>
1445 <?php if ( $show_close_button ) : ?>
1446 <div class="charitable-cta-dismiss-container">
1447 <button type="button" class="button-link charitable-banner-dismiss dismiss">x</button>
1448 </div>
1449 <?php endif; ?>
1450 <?php charitable_render_global_upgrade_cta( $css_class ); ?>
1451 <script type="text/javascript">
1452 jQuery( function ( $ ) {
1453 $( document ).on( 'click', '.reports-lite-cta .dismiss', function ( event ) {
1454 event.preventDefault();
1455 $.post( ajaxurl, {
1456 action: 'charitable_lite_reports_upgrade',
1457 charitable_action: 'remove_lite_cta'
1458 } );
1459 $( '.reports-lite-cta' ).remove();
1460 } );
1461 } );
1462 </script>
1463 <?php
1464 }
1465
1466 /**
1467 * Dismiss upgrade notice at the bottom on the plugin settings pages.
1468 *
1469 * @since 1.7.0.4
1470 */
1471 public function reports_cta_dismiss() {
1472
1473 if ( ! charitable_current_user_can() ) {
1474 wp_send_json_error();
1475 }
1476
1477 update_option( 'charitable_lite_reports_upgrade', time() );
1478
1479 wp_send_json_success();
1480 }
1481
1482 /**
1483 * Returns and/or create the single instance of this class.
1484 *
1485 * @since 1.8.1
1486 *
1487 * @return Charitable_Dashboard_Legacy
1488 */
1489 public static function get_instance() {
1490 if ( is_null( self::$instance ) ) {
1491 self::$instance = new self();
1492 }
1493
1494 return self::$instance;
1495 }
1496 }
1497
1498 endif;
1499