Minor restructure of donation progress bar

This commit is contained in:
Alex Cabal 2023-12-26 11:05:30 -06:00
parent 637b245bcd
commit a82130ea91
3 changed files with 31 additions and 22 deletions

View file

@ -98,6 +98,13 @@ define('PD_STRING', 'January 1, ' . (PD_YEAR + 1));
define('DONATION_HOLIDAY_ALERT_ON', time() > strtotime('November 15, ' . gmdate('Y')) || time() < strtotime('January 7, ' . gmdate('Y')));
define('DONATION_ALERT_ON', DONATION_HOLIDAY_ALERT_ON || rand(1, 4) == 2);
define('DONATION_DRIVE_ON', false);
define('DONATION_DRIVE_COUNTER_ON', false);
// Controls the progress bar donation dialog
const DONATION_DRIVE_ON = false;
const DONATION_DRIVE_START = 'December 11, 2023 00:00:00 America/New_York';
const DONATION_DRIVE_END = 'January 7, 2024 23:59:00 America/New_York';
// Controls the countdown donation dialog
const DONATION_DRIVE_COUNTER_ON = false;
const DONATION_DRIVE_COUNTER_START = 'May 2, 2022 00:00:00 America/New_York';
const DONATION_DRIVE_COUNTER_END = 'May 8, 2022 23:59:00 America/New_York';

View file

@ -1,7 +1,7 @@
<?
$start = new DateTime('May 2, 2022 00:00:00 America/New_York');
$end = new DateTime('May 8, 2022 23:59:00 America/New_York');
$start = new DateTime(DONATION_DRIVE_COUNTER_START);
$end = new DateTime(DONATION_DRIVE_COUNTER_END);
$now = new DateTime();
// Hide the alert if the user has closed it

View file

@ -1,7 +1,12 @@
<?
$start = new DateTime('November 28, 2022 00:00:00 America/New_York');
$end = new DateTime('December 31, 2022 23:59:00 America/New_York');
$start = new DateTime(DONATION_DRIVE_START);
$end = new DateTime(DONATION_DRIVE_END);
$totalCurrent = 0;
$baseTarget = 30;
$stretchCurrent = 0;
$stretchTarget = 20;
$now = new DateTime();
// Hide the alert if the user has closed it
@ -11,7 +16,7 @@ if(!DONATION_DRIVE_ON || ($autoHide ?? $_COOKIE['hide-donation-alert'] ?? false)
$autoHide = $autoHide ?? true;
$showDonateButton = $showDonateButton ?? true;
$current = Db::QueryInt('
$totalCurrent = Db::QueryInt('
SELECT sum(cnt)
from
(
@ -35,11 +40,8 @@ $current = Db::QueryInt('
)
) x
', [$start, $start, $start]);
$target = 75;
$stretchCurrent = 0;
$stretchTarget = 20;
$totalCurrent = $current;
$totalTarget = $target;
$totalTarget = $baseTarget;
$deadline = $end->format('F j');
$timeLeft = $now->diff($end);
$timeString = '';
@ -66,10 +68,10 @@ else{
}
$stretchOn = false;
if($stretchTarget > 0 && $current >= $target){
if($stretchTarget > 0 && $totalCurrent >= $baseTarget){
$stretchOn = true;
$totalCurrent = $current + $stretchCurrent;
$totalTarget = $target + $stretchTarget;
$stretchCurrent = $totalCurrent - $baseTarget;
$totalTarget = $baseTarget + $stretchTarget;
}
?>
@ -83,14 +85,14 @@ if($stretchTarget > 0 && $current >= $target){
<? if(!$stretchOn){ ?>
<header>
<? if($timeLeft->days > 5){ ?>
<p>Help us reach <?= number_format($target) ?> new patrons by <?= $deadline ?></p>
<p>Help us reach <?= number_format($baseTarget) ?> new patrons by <?= $deadline ?></p>
<? }else{ ?>
<p><?= $timeString ?> left to help us reach <?= number_format($target) ?> new patrons!</p>
<p><?= $timeString ?> left to help us reach <?= number_format($baseTarget) ?> new patrons!</p>
<? } ?>
</header>
<? }else{ ?>
<header>
<p>Help us meet our stretch goal of <?= number_format($totalTarget) ?> new patrons by <?= $deadline ?></p>
<p>Help us meet our stretch goal of<br/> <?= number_format($totalTarget) ?> new patrons by <?= $deadline ?></p>
</header>
<? } ?>
<div class="progress">
@ -98,18 +100,18 @@ if($stretchTarget > 0 && $current >= $target){
<p class="start">0</p>
<p><?= number_format($totalCurrent) ?>/<?= number_format($totalTarget) ?></p>
<? if($stretchOn){ ?>
<p class="stretch-base"><?= number_format($target) ?></p>
<p class="stretch-base"><?= number_format($baseTarget) ?></p>
<? } ?>
<p class="target"><?= number_format($totalTarget) ?></p>
</div>
<progress max="<?= $target ?>" value="<?= $current ?>"></progress>
<progress max="<?= $baseTarget ?>" value="<?= $totalCurrent - $stretchCurrent ?>"></progress>
<? if($stretchOn){ ?><progress class="stretch" max="<?= $stretchTarget ?>" value="<?= $stretchCurrent ?>"></progress><? } ?>
</div>
<? if($stretchOn){ ?>
<p>When we started this drive, we set a goal of <?= number_format($target) ?> Patrons Circle members by <?= $deadline ?>. Thanks to the incredible generosity of literature lovers from all walks of life, we hit that goal in just over a week!</p>
<p>When we started this drive, we set a goal of <?= number_format($baseTarget) ?> Patrons Circle members by <?= $deadline ?>. Thanks to the incredible generosity of literature lovers from all walks of life, we hit that goal in just over a week!</p>
<p>Since there are still weeks left in our drive, we thought wed challenge our readers to help us reach our stretch goal of <?= number_format($totalTarget) ?> patrons, so that we can start the year off on a rock-solid financial footing. Will you help us with a donation, and support free and unrestricted digital literature?</p>
<? }else{ ?>
<p>It takes a huge amount of resources and highly-skilled work to create and distribute each of our free ebooks, and we need your support to keep it up. Thats why we want to welcome <?= number_format($target) ?> new patrons by <?= $deadline ?>. Its our patrons who keep us on the stable financial footing we need to continue producing and giving away beautiful ebooks.</p>
<p>It takes a huge amount of resources and highly-skilled work to create and distribute each of our free ebooks, and we need your support to keep it up. Thats why we want to welcome <?= number_format($baseTarget) ?> new patrons by <?= $deadline ?>. Its our patrons who keep us on the stable financial footing we need to continue producing and giving away beautiful ebooks.</p>
<p>Will you become a patron, and support free and unrestricted digital literature?</p>
<? } ?>
<? if($showDonateButton){ ?><p class="donate-button"><a class="button" href="/donate#patrons-circle">Join the patrons circle</a></p><? } ?>