mirror of
https://github.com/Neetpone/ponepaste.git
synced 2025-03-12 06:30:07 +01:00
Expiry display and fixes (#16)
* Expiry display and fixes * rm * space * stray tag
This commit is contained in:
parent
aa2ac2c5a7
commit
81333996d4
4 changed files with 25 additions and 6 deletions
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace PonePaste\Models;
|
namespace PonePaste\Models;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
@ -41,6 +42,23 @@ class Paste extends Model {
|
||||||
$this->save();
|
$this->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function expiryDisplay() {
|
||||||
|
$expiry = $this->expiry;
|
||||||
|
if (!$expiry) {
|
||||||
|
return 'Never';
|
||||||
|
}
|
||||||
|
if ($expiry == 'SELF') {
|
||||||
|
return '<b>View Once</b>';
|
||||||
|
}
|
||||||
|
$dateTime = new DateTime();
|
||||||
|
$dateTime->setTimestamp($expiry);
|
||||||
|
$ret = $dateTime->format('Y-m-d H:i:s');
|
||||||
|
if ($dateTime->diff(new DateTime())->days < 1) {
|
||||||
|
$ret = "<b>$ret</b>";
|
||||||
|
}
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
public static function getRecent(int $count = 10) : Collection {
|
public static function getRecent(int $count = 10) : Collection {
|
||||||
return Paste::with('user')
|
return Paste::with('user')
|
||||||
->orderBy('created_at', 'DESC')
|
->orderBy('created_at', 'DESC')
|
||||||
|
|
|
@ -27,9 +27,9 @@ function verifyCaptcha() : string|bool {
|
||||||
* Calculate the expiry of a paste based on user input.
|
* Calculate the expiry of a paste based on user input.
|
||||||
*
|
*
|
||||||
* @param string $expiry Expiry time.
|
* @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.
|
* 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 {
|
function calculatePasteExpiry(string $expiry) : ?string {
|
||||||
// used to use mktime
|
// used to use mktime
|
||||||
|
@ -37,7 +37,7 @@ function calculatePasteExpiry(string $expiry) : ?string {
|
||||||
return 'SELF';
|
return 'SELF';
|
||||||
}
|
}
|
||||||
|
|
||||||
$valid_expiries = ['10M', '1H', '1D', '1W', '2W', '1M'];
|
$valid_expiries = ['0Y0M0DT0H10M', '1H', '1D', '1W', '2W', '1M'];
|
||||||
|
|
||||||
return in_array($expiry, $valid_expiries)
|
return in_array($expiry, $valid_expiries)
|
||||||
? (new DateTime())->add(new DateInterval("P{$expiry}"))->format('U')
|
? (new DateTime())->add(new DateInterval("P{$expiry}"))->format('U')
|
||||||
|
|
|
@ -219,7 +219,7 @@
|
||||||
|
|
||||||
<?= optionsForSelect(
|
<?= optionsForSelect(
|
||||||
['Never', 'View Once', '10 minutes', '1 hour', '1 day', '1 week', '2 weeks', '1 month'],
|
['Never', 'View Once', '10 minutes', '1 hour', '1 day', '1 week', '2 weeks', '1 month'],
|
||||||
['N', 'self', '10M', '1H', '1D', '1W', '2W', '1M'],
|
['N', 'self', '0Y0M0DT0H10M', '1H', '1D', '1W', '2W', '1M'],
|
||||||
$post_expire
|
$post_expire
|
||||||
); ?>
|
); ?>
|
||||||
</select>
|
</select>
|
||||||
|
|
|
@ -129,6 +129,7 @@ $selectedloader = "$bg[$i]"; // set variable equal to which random filename was
|
||||||
<?php if ($paste['updated_at'] != $paste['created_at']): ?>
|
<?php if ($paste['updated_at'] != $paste['created_at']): ?>
|
||||||
Updated: <?= $paste['updated_at'] ?>
|
Updated: <?= $paste['updated_at'] ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
Expiry: <?= $paste->expiryDisplay() ?>
|
||||||
</small>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
<div class="column is-4 has-text-right">
|
<div class="column is-4 has-text-right">
|
||||||
|
@ -298,7 +299,7 @@ $selectedloader = "$bg[$i]"; // set variable equal to which random filename was
|
||||||
<select name="paste_expire_date">
|
<select name="paste_expire_date">
|
||||||
<option value="N" selected="selected">Never</option>
|
<option value="N" selected="selected">Never</option>
|
||||||
<option value="self">View Once</option>
|
<option value="self">View Once</option>
|
||||||
<option value="10M">10 Minutes</option>
|
<option value="0Y0M0DT0H10M">10 Minutes</option>
|
||||||
<option value="1H">1 Hour</option>
|
<option value="1H">1 Hour</option>
|
||||||
<option value="1D">1 Day</option>
|
<option value="1D">1 Day</option>
|
||||||
<option value="1W">1 Week</option>
|
<option value="1W">1 Week</option>
|
||||||
|
|
Loading…
Add table
Reference in a new issue