| 1 |
<?php |
| 2 |
|
| 3 |
use Give\Campaigns\Actions\RenderDonateButton; |
| 4 |
use Give\Campaigns\Models\Campaign; |
| 5 |
|
| 6 |
/** |
| 7 |
* @var Campaign $campaign |
| 8 |
* @var array $attributes |
| 9 |
*/ |
| 10 |
|
| 11 |
$sortBy = $attributes['sortBy'] ?? 'top-donations'; |
| 12 |
$blockTitle = $sortBy === 'top-donations' ? __('Top Donations', 'give') : __('Recent Donations', 'give'); |
| 13 |
$donateButtonText = $attributes['donateButtonText'] ?? __('Donate', 'give'); |
| 14 |
|
| 15 |
$blockInlineStyles = sprintf( |
| 16 |
'--givewp-primary-color: %s; --givewp-secondary-color: %s;', |
| 17 |
esc_attr($campaign->primaryColor ?? '#0b72d9'), |
| 18 |
esc_attr($campaign->secondaryColor ?? '#27ae60') |
| 19 |
); |
| 20 |
?> |
| 21 |
<div |
| 22 |
<?php |
| 23 |
echo wp_kses_data(get_block_wrapper_attributes(['class' => 'givewp-campaign-donations-block'])); ?> |
| 24 |
style="<?php |
| 25 |
echo esc_attr($blockInlineStyles); ?>"> |
| 26 |
<div class="givewp-campaign-donations-block__header"> |
| 27 |
<h2 class="givewp-campaign-donations-block__title"><?php |
| 28 |
echo esc_html($blockTitle); ?></h2> |
| 29 |
<?php |
| 30 |
if ($attributes['showButton'] && ! empty($donations)) : ?> |
| 31 |
<div class="givewp-campaign-donations-block__donate-button"> |
| 32 |
<?php |
| 33 |
echo wp_kses_post(give(RenderDonateButton::class)($campaign, $attributes, $donateButtonText)); |
| 34 |
?> |
| 35 |
</div> |
| 36 |
<?php |
| 37 |
endif; ?> |
| 38 |
</div> |
| 39 |
|
| 40 |
<?php |
| 41 |
if (empty($donations)) : ?> |
| 42 |
<div class="givewp-campaign-donations-block__empty-state"> |
| 43 |
<h3 class="givewp-campaign-donations-block__empty-title"> |
| 44 |
<?php |
| 45 |
esc_html_e('Every campaign starts with one donation.', 'give'); ?> |
| 46 |
</h3> |
| 47 |
<p class="givewp-campaign-donations-block__empty-description"> |
| 48 |
<?php |
| 49 |
esc_html_e('Be the one to make it happen!', 'give'); ?> |
| 50 |
</p> |
| 51 |
|
| 52 |
<div class="givewp-campaign-donations-block__empty-icon"> |
| 53 |
<img |
| 54 |
src="<?php |
| 55 |
echo esc_url(plugin_dir_url(__DIR__) . 'icons/empty-state.svg'); ?>" |
| 56 |
alt="<?php |
| 57 |
esc_attr_e('Empty state icon', 'give'); ?>" |
| 58 |
/> |
| 59 |
</div> |
| 60 |
|
| 61 |
<?php |
| 62 |
if ($attributes['showButton']) : ?> |
| 63 |
<div class="givewp-campaign-donations-block__empty-button"> |
| 64 |
<?php |
| 65 |
$firstDonationButtonText = __('Be the first', 'give'); |
| 66 |
|
| 67 |
echo wp_kses_post(give(RenderDonateButton::class)($campaign, $attributes, $firstDonationButtonText)); |
| 68 |
?> |
| 69 |
</div> |
| 70 |
<?php |
| 71 |
endif; ?> |
| 72 |
</div> |
| 73 |
<?php |
| 74 |
else : ?> |
| 75 |
<ul class="givewp-campaign-donations-block__donations"> |
| 76 |
<?php |
| 77 |
foreach ($donations as $key => $donation) : ?> |
| 78 |
<li class="givewp-campaign-donations-block__donation"> |
| 79 |
<?php |
| 80 |
if ($attributes['showIcon']) : ?> |
| 81 |
<div class="givewp-campaign-donations-block__donation-icon"> |
| 82 |
<img |
| 83 |
src="<?php |
| 84 |
echo esc_url($donation->donorAvatarUrl); ?>" |
| 85 |
alt="<?php |
| 86 |
esc_attr_e('Donation icon', 'give'); ?>" |
| 87 |
/> |
| 88 |
</div> |
| 89 |
<?php |
| 90 |
endif; ?> |
| 91 |
|
| 92 |
<div class="givewp-campaign-donations-block__donation-info"> |
| 93 |
<div class="givewp-campaign-donations-block__donation-description"> |
| 94 |
<?php |
| 95 |
printf( |
| 96 |
/* translators: %1$s: donor name, %2$s: donation amount */ |
| 97 |
esc_html_x('%1$s donated %2$s', 'donor name and donation amount', 'give'), |
| 98 |
'<strong>' . esc_html(!$donation->isAnonymous ? $donation->donorName : __('Anonymous', 'give')) . '</strong>', |
| 99 |
'<strong>' . esc_html($donation->amount->formatToLocale()) . '</strong>' |
| 100 |
); |
| 101 |
?> |
| 102 |
</div> |
| 103 |
|
| 104 |
<span class="givewp-campaign-donations-block__donation-date"><?php |
| 105 |
echo esc_html( |
| 106 |
sprintf( |
| 107 |
/* translators: %s: human-readable time difference */ |
| 108 |
esc_html_x('%s ago', 'human-readable time difference', 'give'), |
| 109 |
$donation->date |
| 110 |
) |
| 111 |
); ?></span> |
| 112 |
</div> |
| 113 |
|
| 114 |
<?php |
| 115 |
if ($sortBy === 'top-donations' && $key < 3) : ?> |
| 116 |
<div class="givewp-campaign-donations-block__donation-ribbon" data-position="<?php |
| 117 |
echo esc_attr($key + 1); ?>"> |
| 118 |
<img |
| 119 |
src="<?php |
| 120 |
echo esc_url(plugin_dir_url(__DIR__) . 'icons/ribbon.svg'); ?>" |
| 121 |
alt="<?php |
| 122 |
esc_attr_e('Ribbon', 'give'); ?>" |
| 123 |
/> |
| 124 |
</div> |
| 125 |
<?php |
| 126 |
endif; ?> |
| 127 |
</li> |
| 128 |
<?php |
| 129 |
endforeach; ?> |
| 130 |
</ul> |
| 131 |
<?php |
| 132 |
endif; ?> |
| 133 |
</div> |
| 134 |
|