Skip to content

Commit

Permalink
burn
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Tinard committed Mar 22, 2018
1 parent 21403a6 commit bac59a7
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 40 deletions.
48 changes: 27 additions & 21 deletions app/Http/Controllers/PasteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,32 +63,32 @@ public function submit(Request $request){
// Si l'user a choisi password-protected, on hash son pass, sinon on met 'disabled' dans la variable
if ($privacy == 'password') $password = bcrypt(Input::get('pastePassword'));
else $password = 'disabled';

$burnAfter = 0;
// Ici on génère le timestamp d'expiration
switch ($expiration) {
case 'never':
$timestampExp = 0;
break;
$timestampExp = 0;
break;
case 'burn':
$timestampExp = date('Y-m-d H:i:s');
$burnAfter = 0;
break;
$timestampExp = date('Y-m-d H:i:s', time());
$burnAfter = 1;
break;
case '10m':
$timestampExp = date('Y-m-d H:i:s', time()+600);
break;
$timestampExp = date('Y-m-d H:i:s', time()+600);
break;
case '1h':
$timestampExp = date('Y-m-d H:i:s', time()+3600);
break;
$timestampExp = date('Y-m-d H:i:s', time()+3600);
break;
case '1d':
$timestampExp = date('Y-m-d H:i:s', time()+86400);
break;
$timestampExp = date('Y-m-d H:i:s', time()+86400);
break;
case '1w':
$timestampExp = date('Y-m-d H:i:s', time()+604800);
break;
$timestampExp = date('Y-m-d H:i:s', time()+604800);
break;
default:
die("User input error.");
break;
die("User input error.");
break;
}


Expand Down Expand Up @@ -134,8 +134,17 @@ public function view($link){
}
else $expiration = Carbon\Carbon::parse($paste->expiration)->diffForHumans();
}
else $expiration = "Burn after reading";
else {
// On retire le mode burn after reading que si la paste ne vient pas d'être crée
if (time() - strtotime($paste->expiration) > 3) {
$paste->burnAfter = 0;
$paste->save();
$expiration = "Burn after reading (next time)";
}
else $expiration = "Burn after reading";
}
}
// Petite vérification au cas où l'admin n'ait pas migrate
elseif ($paste->expiration == "10m" || $paste->expiration == "1h" || $paste->expiration == "1d" || $paste->expiration == "1w" || $paste->expiration == "never" || $paste->expiration == "burn") die("Paste expiration error. Please make sure you have the latest commit of EdPaste and run 'php artisan migrate'.");
else $expiration = "Never";

Expand Down Expand Up @@ -197,10 +206,7 @@ public function view($link){
}

// On regarde si la paste est en burn after reading (et donc qu'elle a été vue une seule fois, par son créateur, juste après la rédaction)
if (isset($burn)) {
$paste->expiration = "expired";
$paste->save();
}


// Ici on incrémente le compteur de vues à chaque vue
if (time()-$paste->created_at->timestamp > 10) DB::table('pastes')->where('link', $link)->increment('views');
Expand Down
48 changes: 29 additions & 19 deletions resources/views/paste/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
<i>This paste has expired, however since you've wrote it you may view it whenever you want.</i>
</div>
@elseif ($expiration == "Burn after reading (next time)")
<div class="alert alert-warning" role="alert">
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
<i>This paste is in burn after reading. From now, it could be viewed only one time.</i>
</div>
@elseif ($expiration == "Burn after reading")
<div class="alert alert-warning" role="alert">
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
<i>This paste is in burn after reading mode and has been destroyed.</i>
</div>
@endif
<div class="row">
<div class="col-sm-11">
Expand All @@ -79,22 +89,22 @@
<button class="btn btn-danger btn-sm pull-right" type="button" data-toggle="modal" data-target="#delete" aria-expanded="false" aria-controls="collapse}"><i class="fa fa-trash-o"></i></button>
</div>
<div class="modal fade" id="delete" tabindex="-1" role="dialog" aria-labelledby="preview" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title" id="preview" style="word-wrap: break-word;">Delete "<i>{{ $title }}</i>" ?</h4>
</div>
<div class="modal-body">Are you sure ? You <b>cannot</b> undo this !</div>
<div class="modal-footer">
<a class="btn btn-danger btn-sm" href="/users/delete/{{ $link }}" role="button">Yes</a>
<button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">No</button>
</div>
</div>
</div>
</div>
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title" id="preview" style="word-wrap: break-word;">Delete "<i>{{ $title }}</i>" ?</h4>
</div>
<div class="modal-body">Are you sure ? You <b>cannot</b> undo this !</div>
<div class="modal-footer">
<a class="btn btn-danger btn-sm" href="/users/delete/{{ $link }}" role="button">Yes</a>
<button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">No</button>
</div>
</div>
</div>
</div>
@endif
</div>
<div class="row">
Expand All @@ -114,7 +124,7 @@
@else
<li><i class="fa fa-clock-o" data-toggle="tooltip" data-placement="bottom" title="Expiration"></i> <i>{{ $expiration }}</i></li>
@endif

{{-- Privacy cachée si xs --}}
@if ($privacy == "Public")
<li class="hidden-xs"><i class="fa fa-lock" data-toggle="tooltip" data-placement="bottom" title="Privacy"></i> <i>{{ $privacy }}</i></li>
Expand All @@ -124,15 +134,15 @@
</ul>
</div>
</div>

{{-- N'est formaté que si le SH est activé --}}
<div class="row" @if ($noSyntax == true) style="margin-bottom:20px;" @endif>
<div class="col-sm-12">
<label for="paste"><i>@if ($noSyntax == false) Syntax-highlighted @else Plain-text @endif</i></label><i class="pull-right"><a href="/{{ $link }}/raw">Raw paste</a></i>
<pre id="paste"><code>@if ($noSyntax == true)<i>@endif{{ $content }} @if ($noSyntax == true)</i>@endif</code></pre>
</div>
</div>

{{-- N'apparaît que si le SH est activé --}}
@if ($noSyntax == false)
<div class="row" style="margin-bottom:20px;">
Expand Down

0 comments on commit bac59a7

Please sign in to comment.