Added live countdown to expiry on ban page.

This commit is contained in:
Paul Merrill 2011-01-02 08:27:34 -08:00
parent db17603221
commit a0ae475ea4

View File

@ -55,10 +55,10 @@
return ($num = round($difference/(60*60))) . ' hour' . ($num != 1 ? 's' : ''); return ($num = round($difference/(60*60))) . ' hour' . ($num != 1 ? 's' : '');
} elseif($difference < 60*60*24*7) { } elseif($difference < 60*60*24*7) {
return ($num = round($difference/(60*60*24))) . ' day' . ($num != 1 ? 's' : ''); return ($num = round($difference/(60*60*24))) . ' day' . ($num != 1 ? 's' : '');
} elseif($difference < 60*60*24*7*52) { } elseif($difference < 60*60*24*365) {
return ($num = round($difference/(60*60*24*7))) . ' week' . ($num != 1 ? 's' : ''); return ($num = round($difference/(60*60*24*7))) . ' week' . ($num != 1 ? 's' : '');
} else { } else {
return ($num = round($difference/(60*60*24*7*52))) . ' year' . ($num != 1 ? 's' : ''); return ($num = round($difference/(60*60*24*365))) . ' year' . ($num != 1 ? 's' : '');
} }
} }
@ -99,11 +99,38 @@
formatDate($ban['set']) . formatDate($ban['set']) .
'</strong>, and ' . '</strong>, and ' .
($ban['expires'] ? ($ban['expires'] ?
'expires ' . until($ban['expires']) . ' from now, which is on <strong>' . 'expires <span id="until">' . until($ban['expires']) . '</span> from now, which is on <strong><span id="enddate">' .
formatDate($ban['expires']) . formatDate($ban['expires']) .
'</strong>' '</span></strong>
<script>
// return date("jS F, Y", $timestamp);
var secondsLeft = ' . ($ban['expires'] - time()) . '
var end = new Date().getTime() + secondsLeft*1000;
function updateExpiresTime() {
document.getElementById("until").innerHTML = until(end);
}
function until(end) {
var now = new Date().getTime();
var diff = Math.round((end - now) / 1000); // in seconds
if (diff < 60) {
return diff + " second" + (diff == 1 ? "" : "s");
} else if (diff < 60*60) {
return (num = Math.round(diff/(60))) + " minute" + (num == 1 ? "" : "s");
} else if (diff < 60*60*24) {
return (num = Math.round(diff/(60*60))) + " hour" + (num == 1 ? "" : "s");
} else if (diff < 60*60*24*7) {
return (num = Math.round(diff/(60*60*24))) + " day" + (num == 1 ? "" : "s");
} else if (diff < 60*60*24*365) {
return (num = Math.round(diff/(60*60*24*7))) + " week" + (num == 1 ? "" : "s");
} else {
return (num = Math.round(diff/(60*60*365))) + " year" + (num == 1 ? "" : "s");
}
}
updateExpiresTime();
setInterval(updateExpiresTime, 1000);
</script>'
: '<em>will not expire</em>' ) . : '<em>will not expire</em>' ) .
'.</p> '</p>
<p>Your IP address is <strong>' . $_SERVER['REMOTE_ADDR'] . '</strong>.</p> <p>Your IP address is <strong>' . $_SERVER['REMOTE_ADDR'] . '</strong>.</p>
</div>'; </div>';
@ -739,4 +766,4 @@
function int_to_word($n) { function int_to_word($n) {
return chr($n & 255).chr(($n >> 8) & 255); return chr($n & 255).chr(($n >> 8) & 255);
} }
?> ?>