Skip to content

Commit

Permalink
fix: make string translatable
Browse files Browse the repository at this point in the history
  • Loading branch information
ravinderk committed Jun 21, 2022
1 parent f2c4fa6 commit 2154dc2
Show file tree
Hide file tree
Showing 3 changed files with 291 additions and 275 deletions.
211 changes: 107 additions & 104 deletions templates/shortcode-donor-wall.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,170 +4,173 @@
*/

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
if (!defined('ABSPATH')) {
exit;
}

/** @var $donor Give_Donor */
$donation = $args[0];

$give_settings = $args[1]; // Give settings.
$atts = $args[2]; // Shortcode attributes.
$atts = $args[2]; // Shortcode attributes.

$primary_color = $atts['color'];
$avatarSize = (int) $atts['avatar_size'] ;
$tribute_background_color = ! empty( $atts['color']) ? $atts['color'] . '20' :'#219653';
$avatarSize = (int)$atts['avatar_size'];
$tribute_background_color = !empty($atts['color']) ? $atts['color'] . '20' : '#219653';

?>


<div class="give-grid__item">
<div class="give-donor give-card">
<div class="give-donor-container">
<?php
if ( $atts['show_avatar'] ) {

if ( !empty($donation['_give_anonymous_donation'])) {
// Donor gave anonymously
$imageUrl = GIVE_PLUGIN_URL . 'assets/dist/images/anonymous-user.svg';
$alt = __('Anonymous User', 'give');

echo "
<?php
if ($atts['show_avatar']) {
if (!empty($donation['_give_anonymous_donation'])) {
// Donor gave anonymously
$imageUrl = GIVE_PLUGIN_URL . 'assets/dist/images/anonymous-user.svg';
$alt = __('Anonymous User', 'give');

echo "
<div class='give-donor-container__image' >
<img class='give-donor-container__image__anonymous' src='$imageUrl' alt='$alt' style='height: {$avatarSize}px;'/>
</div>
";

} elseif( $donation['_give_payment_donor_email'] && give_validate_gravatar($donation['_give_payment_donor_email'])) {
// Donor has a valid Gravatar
$hash = md5( strtolower( trim( $donation['_give_payment_donor_email'] ) ) );
} elseif ($donation['_give_payment_donor_email'] && give_validate_gravatar(
$donation['_give_payment_donor_email']
)) {
// Donor has a valid Gravatar
$hash = md5(strtolower(trim($donation['_give_payment_donor_email'])));


echo "
echo "
<div class='give-donor-container__image' >
<img src='https://gravatar.com/avatar/$hash' alt='$donor->name' style='height: $avatarSize px;'/>
</div>
";
} else {
// Everyone else

} else {
// Everyone else

$initial = esc_html($donation['name_initial']);
echo "
$initial = esc_html($donation['name_initial']);
echo "
<div class='give-donor-container__image' style='height: {$avatarSize}px; width: {$avatarSize}px;'>
<span class='give-donor-container__image__name_initial'>$initial</span>
</div>
";
}
}
?>

<?php if ( $atts['show_name'] ) : ?>
<h3 class="give-donor-container__name" style='<?php echo ($atts['show_avatar']) ? "text-align: center" : "text-align: left"?>'>
<?php
// Get donor name based on donation parameter.
$donor_name = ! empty( $donation['_give_anonymous_donation'] )
? esc_html__( 'Anonymous', 'give' )
: trim( $donation['_give_donor_billing_first_name'] . ' ' . $donation['_give_donor_billing_last_name'] );
?>
<?php echo esc_html( $donor_name ); ?>
</h3>
<?php endif; ?>

<?php if ( $atts['show_company_name'] && isset( $donation['_give_donation_company'] ) ) : ?>
<h3 class="give-donor-container__name">
<?php echo esc_html( $donation['_give_donation_company'] ); ?>
</h3>
<?php endif; ?>

<?php
if (
$atts['show_comments']
&& absint( $atts['comment_length'] )
&& ! empty( $donation['donor_comment'] )
&& ! $donation['_give_anonymous_donation']
) :
}
?>

<?php if ($atts['show_name']) : ?>
<h3 class="give-donor-container__name"
style='<?php echo ($atts['show_avatar']) ? "text-align: center" : "text-align: left" ?>'>
<?php
// Get donor name based on donation parameter.
$donor_name = !empty($donation['_give_anonymous_donation'])
? esc_html__('Anonymous', 'give')
: trim(
$donation['_give_donor_billing_first_name'] . ' ' . $donation['_give_donor_billing_last_name']
);
?>
<?php echo esc_html($donor_name); ?>
</h3>
<?php endif; ?>

<?php if ($atts['show_company_name'] && isset($donation['_give_donation_company'])) : ?>
<h3 class="give-donor-container__name">
<?php echo esc_html($donation['_give_donation_company']); ?>
</h3>
<?php endif; ?>

<?php
if (
$atts['show_comments']
&& absint($atts['comment_length'])
&& !empty($donation['donor_comment'])
&& !$donation['_give_anonymous_donation']
) :
?>
<div class="give-donor-wrapper">
<div class="give-donor-content" style="border-color: <?php echo ! empty( $atts['color']) ? $atts['color'] :'#219653' ?>">
<div class="give-donor-content"
style="border-color: <?php echo !empty($atts['color']) ? $atts['color'] : '#219653' ?>">
<?php
$comment = trim( $donation['donor_comment'] );
$total_chars = strlen( $comment );
$max_chars = $atts['comment_length'];
$comment = trim($donation['donor_comment']);
$total_chars = strlen($comment);
$max_chars = $atts['comment_length'];
$read_more_text = $atts['readmore_text'];


// A truncated excerpt is displayed if the comment is too long.
if ( $max_chars < $total_chars ) {
$excerpt = '';
$offset = -( $total_chars - $max_chars );
$last_space = strrpos( $comment, ' ', $offset );
if ($max_chars < $total_chars) {
$excerpt = '';
$offset = -($total_chars - $max_chars);
$last_space = strrpos($comment, ' ', $offset);

if ( $last_space ) {
if ($last_space) {
// Truncate excerpt at last space before limit.
$excerpt = substr( $comment, 0, $last_space );
$excerpt = substr($comment, 0, $last_space);
} else {
// There are no spaces, so truncate excerpt at limit.
$excerpt = substr( $comment, 0, $max_chars );
$excerpt = substr($comment, 0, $max_chars);
}

$excerpt = trim( $excerpt, '.!,:;' );
$excerpt = trim($excerpt, '.!,:;');

echo "<p class='give-donor-content__excerpt'>$excerpt &hellip;
<span> <a class='give-donor-content__read-more' style='color: {$primary_color}'> $read_more_text </a></span>
</p>";

echo "<p class='give-donor-content__comment'> $comment </p>";

}
?>
</div>
</div>
<?php endif; ?>
<div class="give-donor-details">
<div class="give-donor-details__wrapper">
<?php
$full_form_name = esc_html($donation['_give_payment_form_title']);
$word_count = 3;
preg_match("/(\S+\s*){0,$word_count}/", esc_html($donation['_give_payment_form_title']), $regs);
$truncated_form_name = trim($regs[0] . "...");

// Determine whether to truncate form name based on amount of words
if ( $atts['show_form'] && $atts['show_total'] && isset( $donation['_give_payment_form_title'] ) ) {
if (str_word_count($donation['_give_payment_form_title'], 0) <= $word_count) {
echo "<span class='give-donor-details__form_title'> $full_form_name </span>";
}
else {
echo "<span class='give-donor-details__form_title'> $truncated_form_name </span>";
}
}

// Display full form name if ['show_total'] is false
else if ($atts['show_form'] && ! $atts['show_total'] && isset( $donation['_give_payment_form_title'] ) ) {
echo "<span class='give-donor-details__form_title' style='text-align: center'> $full_form_name </span>";
}
<?php endif; ?>
<div class="give-donor-details">
<div class="give-donor-details__wrapper">
<?php
$full_form_name = esc_html($donation['_give_payment_form_title']);
$word_count = 3;
preg_match("/(\S+\s*){0,$word_count}/", esc_html($donation['_give_payment_form_title']), $regs);
$truncated_form_name = trim($regs[0] . "...");

// Determine whether to truncate form name based on amount of words
if ($atts['show_form'] && $atts['show_total'] && isset($donation['_give_payment_form_title'])) {
if (str_word_count($donation['_give_payment_form_title'], 0) <= $word_count) {
echo "<span class='give-donor-details__form_title'> $full_form_name </span>";
} else {
echo "<span class='give-donor-details__form_title'> $truncated_form_name </span>";
}
} // Display full form name if ['show_total'] is false
else {
if ($atts['show_form'] && !$atts['show_total'] && isset($donation['_give_payment_form_title'])) {
echo "<span class='give-donor-details__form_title' style='text-align: center'> $full_form_name </span>";
}
}

if ($atts['show_total'] ) {
echo "<span class='give-donor-details__amount_donated'>Amount Donated</span>";
if ($atts['show_total']) {
echo sprintf(
'<span class=\'give - donor - details__amount_donated\'>%1$s</span>',
esc_html__('Amount Donated', 'give')
);
}
?>
</div>
?>
</div>

<?php
$donation_total = give_donation_amount( $donation['donation_id'], true );
$donation_amount = esc_html(substr($donation_total, 0, strpos($donation_total, ".")));
$donation_total = give_donation_amount($donation['donation_id'], true);
$donation_amount = esc_html(substr($donation_total, 0, strpos($donation_total, ".")));

if ($atts['show_total'] ){
echo "
if ($atts['show_total']) {
echo "
<span class= 'give-donor-details__total' style='color: {$primary_color}'> $donation_amount </span>
";
}
?>
</div>
}
?>
</div>
</div>
<?php
if ($atts['show_tributes'] && (isset( $donation['_give_tributes_first_name'] ) || isset( $donation['_give_tributes_Last_name']))) {

if ($atts['show_tributes'] && (isset($donation['_give_tributes_first_name']) || isset($donation['_give_tributes_Last_name']))) {
$tribute_message = esc_html($donation['_give_tributes_type']);
$honoree_first_name = esc_html($donation['_give_tributes_first_name']);
$honoree_last_name = esc_html($donation['_give_tributes_last_name']);
Expand All @@ -176,12 +179,12 @@
//Determine if a last name is available
$donation['_give_tributes_last_name'] ?
//Remove full last name, and add as an initial.
trim($honoree_first_name . " " . strtoupper($honoree_last_name [0]) . "." ) :
trim($honoree_first_name . " " . strtoupper($honoree_last_name [0]) . ".") :
// Else add period at the end of first name
trim($honoree_first_name) . ".";

echo
"<div class='give-donor-tribute' style='background-color: {$tribute_background_color} '>
"<div class='give-donor-tribute' style='background-color: {$tribute_background_color} '>
<span>
<svg width='16' height='16' viewBox='0 0 16 16' xmlns='http://www.w3.org/2000/svg' class='give-donor-tribute__svg'>
<path fill='$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'/>
Expand All @@ -195,7 +198,7 @@
<span> $honoree_full_name </span>
</span>
</div>";
}
}
?>
</div>
</div>
Expand Down
Loading

0 comments on commit 2154dc2

Please sign in to comment.