| @@ -1,102 +1,229 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 2 | 3 | /** |
| 3 | - * This template is used to display the donation grid with [donation_grid] | |
| 4 | + * This template is used to display the donation grid with [give_donor_wall] | |
| 4 | 5 | */ |
| 5 | 6 | |
| 6 | 7 | // Exit if accessed directly. |
| 7 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 8 | - exit; | |
| 8 | +if (!defined('ABSPATH')) { | |
| 9 | + exit; | |
| 9 | 10 | } |
| 10 | 11 | |
| 12 | +/** @var $args array */ | |
| 13 | +/** @var $donation array kind of like Give_Payment */ | |
| 11 | 14 | /** @var $donor Give_Donor */ |
| 12 | -$donation = $args[0]; | |
| 15 | +/** @var $atts array Shortcode attributes */ | |
| 16 | +/** @var $give_settings array Give settings */ | |
| 13 | 17 | |
| 14 | -$give_settings = $args[1]; // Give settings. | |
| 15 | -$atts = $args[2]; // Shortcode attributes. | |
| 18 | +list($donation, $give_settings, $atts, $donor) = $args; | |
| 19 | + | |
| 20 | +$primary_color = $atts['color']; | |
| 21 | +$avatarSize = (int)$atts['avatar_size']; | |
| 22 | +$tribute_background_color = !empty($atts['color']) ? $atts['color'] . '20' : '#219653'; | |
| 23 | + | |
| 16 | 24 | ?> |
| 17 | 25 | |
| 26 | + | |
| 18 | 27 | <div class="give-grid__item"> |
| 19 | - <div class="give-donor give-card"> | |
| 20 | - <div class="give-donor__header"> | |
| 21 | - <?php | |
| 22 | - if( true === $atts['show_avatar'] ) { | |
| 23 | - $has_avatar = absint( give_validate_gravatar( $donation['_give_payment_donor_email'] ) ); | |
| 24 | - // Maybe display the Avatar. | |
| 25 | - echo sprintf( | |
| 26 | - '<div class="give-donor__image" data-donor_email="%1$s" data-has-valid-gravatar="%2$s">%3$s</div>', | |
| 27 | - md5( strtolower( trim( $donation['_give_payment_donor_email'] ) ) ), | |
| 28 | - $has_avatar, | |
| 29 | - defined( 'REST_REQUEST' ) && $has_avatar | |
| 30 | - ? get_avatar($donation['_give_payment_donor_email']) | |
| 31 | - : $donation['name_initial'] | |
| 32 | - ); | |
| 33 | - } | |
| 34 | - ?> | |
| 28 | + <div class="give-donor give-card"> | |
| 29 | + <div class="give-donor-container"> | |
| 30 | + <?php | |
| 31 | + if ($atts['show_avatar']) { | |
| 32 | + if (!empty($donation['_give_anonymous_donation'])) { | |
| 33 | + // Donor gave anonymously | |
| 34 | + $imageUrl = GIVE_PLUGIN_URL . 'build/assets/dist/images/anonymous-user.svg'; | |
| 35 | + $alt = __('Anonymous User', 'give'); | |
| 35 | 36 | |
| 36 | - <div class="give-donor__details"> | |
| 37 | - <?php if ( true === $atts['show_name'] ) : ?> | |
| 38 | - <h3 class="give-donor__name"> | |
| 39 | - <?php $donor_name = trim( $donation['_give_donor_billing_first_name'] . ' ' . $donation['_give_donor_billing_last_name'] ); ?> | |
| 40 | - <?php esc_html_e( $donor_name ); ?> | |
| 41 | - </h3> | |
| 42 | - <?php endif; ?> | |
| 37 | + echo " | |
| 38 | + <div class='give-donor-container__image' > | |
| 39 | + <img class='give-donor-container__image__anonymous' src='" . esc_url($imageUrl) . "' alt='" . esc_attr($alt) . "' style='" . esc_attr('height: ' . $avatarSize . 'px;') . "'/> | |
| 40 | + </div> | |
| 41 | + "; | |
| 42 | + } elseif (($avatar = $donor->get_meta('_give_donor_avatar_id', true))) { | |
| 43 | + // Donor has an avatar | |
| 44 | + $imageUrl = wp_get_attachment_image_url($avatar, 'thumbnail'); | |
| 45 | + $alt = __('Donor Avatar', 'give'); | |
| 43 | 46 | |
| 44 | - <?php if ( true === $atts['show_total'] ) : ?> | |
| 45 | - <span class="give-donor__total"> | |
| 46 | - <?php echo give_donation_amount( $donation['donation_id'], true ); ?> | |
| 47 | - </span> | |
| 48 | - <?php endif; ?> | |
| 47 | + echo " | |
| 48 | + <div class='give-donor-container__image' > | |
| 49 | + <img src='" . esc_url($imageUrl) . "' alt='" . esc_attr($alt) . "' style='" . esc_attr('height: ' . $avatarSize . 'px;') . "'/> | |
| 50 | + </div> | |
| 51 | + "; | |
| 52 | + } elseif ($donation['_give_payment_donor_email'] && give_validate_gravatar( | |
| 53 | + $donation['_give_payment_donor_email'] | |
| 54 | + )) { | |
| 55 | + // Donor has a valid Gravatar | |
| 56 | + $hash = md5(strtolower(trim($donation['_give_payment_donor_email']))); | |
| 49 | 57 | |
| 50 | - <?php if ( true === $atts['show_time'] ) : ?> | |
| 51 | - <span class="give-donor__timestamp"> | |
| 52 | - <?php echo date_i18n( give_date_format(), strtotime( $donation['_give_completed_date'] ) ); ?> | |
| 53 | - </span> | |
| 54 | - <?php endif; ?> | |
| 55 | - </div> | |
| 56 | - </div> | |
| 57 | 58 | |
| 58 | - <?php | |
| 59 | - if ( | |
| 60 | - true === $atts['show_comments'] | |
| 61 | - && absint( $atts['comment_length'] ) | |
| 62 | - && ! empty( $donation['donor_comment'] ) | |
| 63 | - ) : | |
| 64 | - ?> | |
| 65 | - <div class="give-donor__content"> | |
| 66 | - <?php | |
| 67 | - $comment = trim( $donation['donor_comment'] ); | |
| 68 | - $total_chars = strlen( $comment ); | |
| 69 | - $max_chars = $atts['comment_length']; | |
| 59 | + echo " | |
| 60 | + <div class='give-donor-container__image' > | |
| 61 | + <img src='" . esc_url('https://gravatar.com/avatar/' . $hash) . "' alt='" . esc_attr($donor->name) . "' style='" . esc_attr('height: ' . $avatarSize . 'px;') . "'/> | |
| 62 | + </div> | |
| 63 | + "; | |
| 64 | + } else { | |
| 65 | + // Everyone else | |
| 70 | 66 | |
| 71 | - // A truncated excerpt is displayed if the comment is too long. | |
| 72 | - if ( $max_chars < $total_chars ) { | |
| 73 | - $excerpt = ''; | |
| 74 | - $offset = -( $total_chars - $max_chars ); | |
| 75 | - $last_space = strrpos( $comment, ' ', $offset ); | |
| 67 | + $initial = esc_html($donation['name_initial']); | |
| 68 | + echo " | |
| 69 | + <div class='give-donor-container__image' style='" . esc_attr('height: ' . $avatarSize . 'px; width: ' . $avatarSize . 'px;') . "'> | |
| 70 | + <span class='give-donor-container__image__name_initial'>$initial</span> | |
| 71 | + </div> | |
| 72 | + "; | |
| 73 | + } | |
| 74 | + } | |
| 75 | + ?> | |
| 76 | + <?php | |
| 77 | + $flexDirection = $atts['show_avatar'] ? 'column' : 'row'; | |
| 78 | + $alignItems = $atts['show_avatar'] ? 'center' : 'flex-end'; | |
| 79 | + ?> | |
| 80 | + <div class="give-donor-container-variation" | |
| 81 | + style="<?php echo esc_attr('flex-direction: ' . $flexDirection . '; align-items: ' . $alignItems . ';'); ?>"> | |
| 82 | + <?php if ($atts['show_name']) : ?> | |
| 83 | + <h3 class="give-donor-container-variation__name"> | |
| 84 | + <?php | |
| 85 | + // Get donor name based on donation parameter. | |
| 86 | + $donor_name = ! empty($donation['_give_anonymous_donation']) | |
| 87 | + ? esc_html__('Anonymous', 'give') | |
| 88 | + : trim($donation['_give_donor_billing_first_name'] . ' ' . $donation['_give_donor_billing_last_name']); | |
| 89 | + ?> | |
| 90 | + <?php echo esc_html($donor_name); ?> | |
| 91 | + </h3> | |
| 92 | + <?php endif; ?> | |
| 76 | 93 | |
| 77 | - if ( $last_space ) { | |
| 78 | - // Truncate excerpt at last space before limit. | |
| 79 | - $excerpt = substr( $comment, 0, $last_space ); | |
| 80 | - } else { | |
| 81 | - // There are no spaces, so truncate excerpt at limit. | |
| 82 | - $excerpt = substr( $comment, 0, $max_chars ); | |
| 83 | - } | |
| 94 | + <?php if ($atts['show_company_name'] && isset($donation['_give_donation_company'])) : ?> | |
| 95 | + <h3 class="give-donor-container-variation__name"> | |
| 96 | + <?php echo esc_html($donation['_give_donation_company']); ?> | |
| 97 | + </h3> | |
| 98 | + <?php endif; ?> | |
| 84 | 99 | |
| 85 | - $excerpt = trim( $excerpt, '.!,:;' ); | |
| 100 | + <?php if ($atts['show_time']) : ?> | |
| 101 | + <p class="give-donor-container-variation__timestamp"> | |
| 102 | + <?php echo esc_html(give_get_formatted_date($donation['donation_date'], give_date_format(), 'Y-m-d H:i:s', true)); ?> | |
| 103 | + </p> | |
| 104 | + <?php endif; ?> | |
| 105 | + </div> | |
| 106 | + <?php | |
| 107 | + if ( | |
| 108 | + $atts['show_comments'] | |
| 109 | + && empty($donation['_give_anonymous_donation']) | |
| 110 | + && absint($atts['comment_length']) | |
| 111 | + && !empty($donation['donor_comment']) | |
| 112 | + ) : | |
| 113 | + ?> | |
| 114 | + <div class="give-donor-wrapper"> | |
| 115 | + <div class="give-donor-content" | |
| 116 | + style="border-color: <?php echo !empty($atts['color']) ? esc_attr($atts['color']) : '#219653' ?>"> | |
| 117 | + <?php | |
| 118 | + $comment = esc_html($donation['donor_comment']); | |
| 119 | + $stripped_comment = str_replace(' ', '', $comment); | |
| 86 | 120 | |
| 87 | - echo sprintf( | |
| 88 | - '<p class="give-donor__excerpt">%s…<span> <a class="give-donor__read-more">%s</a></span></p>', | |
| 89 | - nl2br( esc_html( $excerpt ) ), | |
| 90 | - esc_html( $atts['readmore_text'] ) | |
| 91 | - ); | |
| 92 | - } | |
| 121 | + $total_chars = strlen($stripped_comment); | |
| 122 | + $max_chars = $atts['comment_length']; | |
| 123 | + $read_more_text = $atts['readmore_text']; | |
| 93 | 124 | |
| 94 | - echo sprintf( | |
| 95 | - '<p class="give-donor__comment">%s</p>', | |
| 96 | - nl2br( esc_html( $comment ) ) | |
| 97 | - ); | |
| 98 | - ?> | |
| 99 | - </div> | |
| 100 | - <?php endif; ?> | |
| 101 | - </div> | |
| 125 | + // A truncated excerpt is displayed if the comment is too long. | |
| 126 | + if ($max_chars < $total_chars) { | |
| 127 | + $excerpt = ''; | |
| 128 | + $offset = - ($total_chars - $max_chars); | |
| 129 | + $last_space = strrpos($comment, ' ', $offset); | |
| 130 | + | |
| 131 | + if ($last_space) { | |
| 132 | + // Truncate excerpt at last space before limit. | |
| 133 | + $excerpt = substr($comment, 0, $last_space); | |
| 134 | + } else { | |
| 135 | + // There are no spaces, so truncate excerpt at limit. | |
| 136 | + $excerpt = substr($comment, 0, $max_chars); | |
| 137 | + } | |
| 138 | + | |
| 139 | + $excerpt = trim($excerpt, '.!,:;'); | |
| 140 | + | |
| 141 | + echo "<p class='give-donor-content__excerpt'>$excerpt … | |
| 142 | + <span> <a class='give-donor-content__read-more' style='color: " . esc_attr($primary_color) . "'> $read_more_text </a></span> | |
| 143 | + </p>"; | |
| 144 | + | |
| 145 | + echo "<p class='give-donor-content__comment'> $comment </p>"; | |
| 146 | + } else { | |
| 147 | + echo "<p class='give-donor-content__comment'> | |
| 148 | + $comment | |
| 149 | + </p>"; | |
| 150 | + } | |
| 151 | + ?> | |
| 152 | + </div> | |
| 153 | + </div> | |
| 154 | + <?php endif; ?> | |
| 155 | + <div class="give-donor-details"> | |
| 156 | + <div class="give-donor-details__wrapper"> | |
| 157 | + <?php | |
| 158 | + $full_form_name = esc_html($donation['_give_payment_form_title']); | |
| 159 | + $word_count = 3; | |
| 160 | + preg_match("/(\S+\s*){0,$word_count}/", esc_html($donation['_give_payment_form_title']), $regs); | |
| 161 | + $truncated_form_name = trim($regs[0] . "..."); | |
| 162 | + | |
| 163 | + // Determine whether to truncate form name based on amount of words | |
| 164 | + if ($atts['show_form'] && $atts['show_total'] && isset($donation['_give_payment_form_title'])) { | |
| 165 | + if (str_word_count($donation['_give_payment_form_title'], 0) <= $word_count) { | |
| 166 | + echo "<span class='give-donor-details__form_title'> $full_form_name </span>"; | |
| 167 | + } else { | |
| 168 | + echo "<span class='give-donor-details__form_title'> $truncated_form_name </span>"; | |
| 169 | + } | |
| 170 | + } // Display full form name if ['show_total'] is false | |
| 171 | + else { | |
| 172 | + if ($atts['show_form'] && !$atts['show_total'] && isset($donation['_give_payment_form_title'])) { | |
| 173 | + echo "<span class='give-donor-details__form_title' style='text-align: center'> $full_form_name </span>"; | |
| 174 | + } | |
| 175 | + } | |
| 176 | + | |
| 177 | + if ($atts['show_total']) { | |
| 178 | + echo sprintf( | |
| 179 | + '<span class=\'give - donor - details__amount_donated\'>%1$s</span>', | |
| 180 | + esc_html__('Amount Donated', 'give') | |
| 181 | + ); | |
| 182 | + } | |
| 183 | + ?> | |
| 184 | + </div> | |
| 185 | + | |
| 186 | + <?php | |
| 187 | + $donation_amount = give_donation_amount(esc_html($donation['donation_id']), true); | |
| 188 | + | |
| 189 | + if ($atts['show_total']) { | |
| 190 | + echo " | |
| 191 | + <span class= 'give-donor-details__total' style='color: " . esc_attr($primary_color) . "'> $donation_amount </span> | |
| 192 | + "; | |
| 193 | + } | |
| 194 | + ?> | |
| 195 | + </div> | |
| 196 | + </div> | |
| 197 | + <?php | |
| 198 | + if ($atts['show_tributes'] && (isset($donation['_give_tributes_first_name']) || isset($donation['_give_tributes_last_name']))) { | |
| 199 | + $tribute_message = esc_html($donation['_give_tributes_type']); | |
| 200 | + $honoree_first_name = esc_html($donation['_give_tributes_first_name']); | |
| 201 | + $honoree_last_name = esc_html($donation['_give_tributes_last_name']); | |
| 202 | + | |
| 203 | + $honoree_full_name = | |
| 204 | + //Determine if a last name is available | |
| 205 | + $donation['_give_tributes_last_name'] ? | |
| 206 | + //Remove full last name, and add as an initial. | |
| 207 | + trim($honoree_first_name . " " . strtoupper($honoree_last_name[0]) . ".") : | |
| 208 | + // Else add period at the end of first name | |
| 209 | + trim($honoree_first_name) . "."; | |
| 210 | + | |
| 211 | + echo | |
| 212 | + "<div class='give-donor-tribute' style='background-color: " . esc_attr($tribute_background_color) . " '> | |
| 213 | + <span> | |
| 214 | + <svg width='16' height='16' viewBox='0 0 16 16' xmlns='http://www.w3.org/2000/svg' class='give-donor-tribute__svg'> | |
| 215 | + <path fill=' " . esc_attr($primary_color) . "' opacity='0.4' d='M11.9667 5.13998L11.8734 5.08665L10.9467 4.55332L9.0334 3.44665C8.44673 3.10665 7.5534 3.10665 6.96673 3.44665L5.0534 4.55332L4.12673 5.09332L4.00673 5.15998C2.8134 5.95998 2.7334 6.10665 2.7334 7.39332V10.4667C2.7334 11.7533 2.8134 11.9 4.0334 12.72L6.96673 14.4133C7.26007 14.5867 7.62673 14.6667 8.00007 14.6667C8.36673 14.6667 8.74007 14.5867 9.0334 14.4133L11.9934 12.7C13.1867 11.9 13.2667 11.7533 13.2667 10.4667V7.39332C13.2667 6.10665 13.1867 5.95998 11.9667 5.13998Z' fill='#15AE56'/> | |
| 216 | + <path fill=' " . esc_attr($primary_color) . "' d='M4.12671 5.09337L5.05338 4.55337L6.88004 3.50004L6.96671 3.44671C7.55337 3.10671 8.44671 3.10671 9.03338 3.44671L9.12004 3.50004L10.9467 4.55337L11.8734 5.08671V3.66004C11.8734 2.16004 11.0467 1.33337 9.54671 1.33337H6.44671C4.94671 1.33337 4.12671 2.16004 4.12671 3.66004V5.09337Z' fill='#15AE56'/> | |
| 217 | + <path fill=' " . esc_attr($primary_color) . "' d='M9.89333 8.89327L9.47999 9.39994C9.41333 9.47327 9.36666 9.61994 9.37333 9.71994L9.41333 10.3733C9.43999 10.7733 9.15333 10.9799 8.77999 10.8333L8.17333 10.5933C8.07999 10.5599 7.91999 10.5599 7.82666 10.5933L7.21999 10.8333C6.84666 10.9799 6.55999 10.7733 6.58666 10.3733L6.62666 9.71994C6.63333 9.61994 6.58666 9.47327 6.51999 9.39994L6.10666 8.89327C5.84666 8.5866 5.95999 8.2466 6.34666 8.1466L6.97999 7.9866C7.07999 7.95994 7.19999 7.8666 7.25333 7.77994L7.60666 7.23327C7.82666 6.89327 8.17333 6.89327 8.39333 7.23327L8.74666 7.77994C8.79999 7.8666 8.91999 7.95994 9.01999 7.9866L9.65333 8.1466C10.04 8.2466 10.1533 8.5866 9.89333 8.89327Z' fill='#15AE56'/> | |
| 218 | + </svg> | |
| 219 | + </span> | |
| 220 | + | |
| 221 | + <span class='give-donor-tribute__message'> | |
| 222 | + <span> $tribute_message </span> | |
| 223 | + <span> $honoree_full_name </span> | |
| 224 | + </span> | |
| 225 | + </div>"; | |
| 226 | + } | |
| 227 | + ?> | |
| 228 | + </div> | |
| 102 | 229 | </div> |