Skip to content

Commit

Permalink
Merge pull request #2953 from WPO-Foundation/AZU174879
Browse files Browse the repository at this point in the history
AZU174879: Update Messaging on Page Displayed when Anonymous User Hits Limit
  • Loading branch information
mjkozicki authored Jul 25, 2023
2 parents 641aeba + ae5230d commit 436daf8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
23 changes: 12 additions & 11 deletions www/runtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@

$redirect_cache = array();
$error = null;
$errorTitle = null;
$xml = false;
$usingAPI = false;
$usingApi2 = false;
Expand Down Expand Up @@ -897,7 +898,7 @@ function buildSelfHost($hosts)
}


if (!strlen($error) && CheckIp($test) && CheckUrl($test['url']) && CheckRateLimit($test, $error)) {
if (!strlen($error) && CheckIp($test) && CheckUrl($test['url']) && CheckRateLimit($test, $error, $errorTitle)) {
$total_runs = Util::getRunCount($test['runs'], $test['fvonly'], $test['lighthouse'], $test['type']);
$hasRunsAvailable = !is_null($request_context->getUser()) && $request_context->getUser()->hasEnoughRemainingRuns($total_runs);
$isAnon = !is_null($request_context->getUser()) && $request_context->getUser()->isAnon();
Expand Down Expand Up @@ -1452,6 +1453,7 @@ function buildSelfHost($hosts)
echo $tpl->render('runlimit');
} else {
echo $tpl->render('runtest', array(
'errorTitle' => $errorTitle,
'error' => $error
));
}
Expand Down Expand Up @@ -3498,8 +3500,8 @@ function loggedOutLoginForm()
{
$ret = <<<HTML
<ul class="testerror_login">
<li><a href="/login">Login</a></li>
<li><a class="pill" href="/signup">Sign-up</a></li>
<li><a href="/login">Login</a></li>
</ul>
HTML;

Expand All @@ -3510,15 +3512,15 @@ function loggedInPerks()
{
$msg = <<<HTML
<ul class="testerror_loginperks">
<li>Access to 13 months of saved tests, making it easier to compare tests and analyze trends.</li>
<li>The ability to save your tests! Access up to 13 months of tests, making it easier to compare tests and analyze results.</li>
<li>Ability to contribute to the <a href="https://forums.webpagetest.org/">WebPageTest Forum</a>.</li>
<li>Access to upcoming betas and new features that will enhance your WebPageTest experience.</li>
<li>Access to upcoming betas and new features to enhance your WebPageTest experience.</li>
</ul>
HTML;
return $msg;
}

function CheckRateLimit($test, &$error)
function CheckRateLimit($test, &$error, &$errorTitle)
{
global $USER_EMAIL;
global $supportsCPAuth;
Expand Down Expand Up @@ -3551,8 +3553,11 @@ function CheckRateLimit($test, &$error)
$cmrl = new RateLimiter($test['ip'], $monthly_limit);
$passesMonthly = $cmrl->check($total_runs);

$error = "<p>Don't worry! You can keep testing for free once you log in, which will give you access to other excellent features like:</p>";
$errorTitleTemplate = "You've reached the limit for";

if (!$passesMonthly) {
$error = "<p>You've reached the limit for logged-out tests this month, but don't worry! You can keep testing once you log in, which will give you access to other nice features like:</p>";
$errorTitle = "{$errorTitleTemplate} this month";
$error .= <<<HTML
<script>
var intervalId = setInterval(function () {
Expand Down Expand Up @@ -3580,8 +3585,7 @@ function CheckRateLimit($test, &$error)
$count += $total_runs;
Cache::store($cache_key, $count, 1800);
} else {
$apiUrl = Util::getSetting('api_url');
$error = '<p>You\'ve reached the limit for logged-out tests per hour, but don\'t worry! You can keep testing once you log in, which will give you access to other nice features like:</p>';
$errorTitle = "{$errorTitleTemplate} this month";
$error .= <<<HTML
<script>
var intervalId = setInterval(function () {
Expand All @@ -3594,9 +3598,6 @@ function CheckRateLimit($test, &$error)
HTML;

$error .= loggedInPerks();
if ($apiUrl) {
$error .= "<p>And also, if you need to run tests programmatically you might be interested in the <a href='$apiUrl'>WebPageTest API</a></p>";
}
$error .= loggedOutLoginForm();
$ret = false;
}
Expand Down
6 changes: 2 additions & 4 deletions www/templates/errors/runtest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<div class="testerror box">
<h1>Oops! <em>There was a problem with the test.</em></h1>
<?php

echo $error; ?>
<h1>Oops! <em><?= $errorTitle ?? "There was a problem with the test." ?></em></h1>
<?= $error ?>
</div>

0 comments on commit 436daf8

Please sign in to comment.