diff --git a/includes/Models/Paste.php b/includes/Models/Paste.php index e64988c..3156b0f 100644 --- a/includes/Models/Paste.php +++ b/includes/Models/Paste.php @@ -1,6 +1,7 @@ save(); } + public function expiryDisplay() { + $expiry = $this->expiry; + if (!$expiry) { + return 'Never'; + } + if ($expiry == 'SELF') { + return 'View Once'; + } + $dateTime = new DateTime(); + $dateTime->setTimestamp($expiry); + $ret = $dateTime->format('Y-m-d H:i:s'); + if ($dateTime->diff(new DateTime())->days < 1) { + $ret = "$ret"; + } + return $ret; + } + public static function getRecent(int $count = 10) : Collection { return Paste::with('user') ->orderBy('created_at', 'DESC') diff --git a/public/index.php b/public/index.php index b4c8d96..03469af 100644 --- a/public/index.php +++ b/public/index.php @@ -27,9 +27,9 @@ function verifyCaptcha() : string|bool { * Calculate the expiry of a paste based on user input. * * @param string $expiry Expiry time. - * SELF means to expire upon one view. +10M, +1H, +1D, +1W, +2W, +1M all do the obvious. + * SELF means to expire upon one view. +0Y0M0DT0H10M, +1H, +1D, +1W, +2W, +1M all do the obvious. * Anything unhandled means to expire never. - * @return string|null Expiry time, or NULL if expires never. + * @return string|null 'SELF', Expiry time as Unix timestamp, or NULL if expires never. */ function calculatePasteExpiry(string $expiry) : ?string { // used to use mktime @@ -37,7 +37,7 @@ function calculatePasteExpiry(string $expiry) : ?string { return 'SELF'; } - $valid_expiries = ['10M', '1H', '1D', '1W', '2W', '1M']; + $valid_expiries = ['0Y0M0DT0H10M', '1H', '1D', '1W', '2W', '1M']; return in_array($expiry, $valid_expiries) ? (new DateTime())->add(new DateInterval("P{$expiry}"))->format('U') diff --git a/theme/bulma/main.php b/theme/bulma/main.php index 0dc9cf8..384afd4 100644 --- a/theme/bulma/main.php +++ b/theme/bulma/main.php @@ -218,8 +218,8 @@ diff --git a/theme/bulma/view.php b/theme/bulma/view.php index 60d5bc7..9251f68 100644 --- a/theme/bulma/view.php +++ b/theme/bulma/view.php @@ -129,6 +129,7 @@ $selectedloader = "$bg[$i]"; // set variable equal to which random filename was Updated: = $paste['updated_at'] ?> + Expiry: = $paste->expiryDisplay() ?>