Initial commit

This commit is contained in:
2021-09-16 20:27:51 +08:00
commit 5ed6195cc1
41 changed files with 3429 additions and 0 deletions

View File

@ -0,0 +1,3 @@
@extends('post.edit')
@section('submit') Publish @endsection

38
views/post/edit.blade.php Normal file
View File

@ -0,0 +1,38 @@
@extends('layout.master')
@section('content')
<form method="POST" action="">
<input type="hidden" name="_token" value="{{ $_SESSION['_token'] }}">
<div class="form-group">
<input type="text" class="form-control" name="title" placeholder="Enter title" maxlength="255" value="{{ $title ?? $post->title }}">
</div>
<div class="form-group">
<textarea id="source-content" class="form-control" name="content" rows="10">{{ $content ?? $post->content }}</textarea>
</div>
<div class="form-group row">
<label class="col-sm-1 col-form-label text-right">Tags: </label>
<div class="col-sm-11">
<input type="text" class="form-control" name="tags" placeholder="Separated by commas (,)" maxlength="255" value="{{ $tags ?? $post->tags }}">
</div>
</div>
<button type="submit" class="btn btn-primary float-right">@section('submit') Edit @show</button>
<button type="button" id="preview-post-btn" class="preview-post-btn btn btn-secondary float-right" data-toggle="modal" data-target="#preview-post">Preview</button>
</form>
<div class="modal fade" id="preview-post" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Preview</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body" id="preview-content">
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
@endsection

View File

@ -0,0 +1,59 @@
@extends('layout.master')
@section('content')
<div class="posts">
@if(count($posts) == 0)
<h3 class="text-secondary">No content</h3>
@endif
@foreach($posts as $post)
<div>
<span class="text-secondary">{{ explode(' ', $post->create_at)[0] }}</span>
@if(isset($_SESSION['is_auth']) && $post->author == $_SESSION['username'])
<a href="/post/{{ $post->id }}/edit" class="text-primary">Edit</a>
<a href="#" class="text-danger" data-toggle="modal" data-target="#confirm-modal" data-action="/post/{{ $post->id }}/delete">Delete</a>
@endif
</div>
<h2 class="title">
<a href="/post/{{ $post->id }}">{!! isset($keyword) ? preg_replace('/' . preg_quote(e($keyword)) . '/i', '<span class="match">$0</span>', e($post->title)) : e($post->title) !!}</a>
</h2>
@endforeach
<ul class="pager">
@if($page > 1)
<li class="previous"><a href="{{ $pager_uri }}/{{ $page - 1 }}">&larr; Prev</a></li>
@endif
@if(! $is_last)
<li class="next"><a href="{{ $pager_uri }}/{{ $page + 1 }}">Next &rarr;</a></li>
@endif
</ul>
<div class="modal fade" id="confirm-modal" tabindex="-1" role="dialog" aria-labelledby="confirm-label" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="confirm-label">Confirmation</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
Are you sure you want to delete this post?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">No</button>
<form method="POST" action="" id="delete-form">
<input type="hidden" name="_token" value="{{ $_SESSION['_token'] }}">
<button type="submit" class="btn btn-danger">Yes</button>
</form>
</div>
</div>
</div>
</div>
</div>
@endsection
@section('sidebar')
@include('layout.sidebar')
@endsection

139
views/post/show.blade.php Normal file
View File

@ -0,0 +1,139 @@
@extends('layout.master')
@section('title')
{{ $post->title }} -
@endsection
@section('content')
<h2>{{ $post->title }}</h2>
<div>
<span class="text-secondary">Published at: {{ $post->create_at }}</span>,
<span class="text-secondary">Author: <a href="/user/{{ $post->author }}" class="text-info">{{ $post->author }}</a></span>
@if(isset($_SESSION['is_auth']) && $post->author == $_SESSION['username'])
<a href="/post/{{ $post->id }}/edit" class="text-primary">Edit</a>
<a href="#" class="text-danger" data-toggle="modal" data-target="#confirm-modal">Delete</a>
<div class="modal fade" id="confirm-modal" tabindex="-1" role="dialog" aria-labelledby="confirm-label" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="confirm-label">Confirmation</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
Are you sure you want to delete this post?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">No</button>
<form method="POST" action="/post/{{ $post->id }}/delete">
<input type="hidden" name="_token" value="{{ $_SESSION['_token'] }}">
<button type="submit" class="btn btn-danger">Yes</button>
</form>
</div>
</div>
</div>
</div>
@endif
</div>
<article id="content">
@markdown($post->content)
</article>
@if(count($tags))
<div class="tags text-right">
@foreach($tags as $key => $tag)
<a href="/tag/{{ $tag->id }}" class="text-info">{{ $tag->keyword }}</a>
@if($key < count($tags) - 1),@endif
@endforeach
</div>
@endif
@endsection
@section('comments')
<div class="comments">
@if(isset($comment_errors))
<ul class="errors alert alert-danger">
@foreach($comment_errors as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
@endif
@if(isset($_SESSION['is_auth']))
<form method="POST" action="/comment/create" class="comment-form">
<input type="hidden" name="_token" value="{{ $_SESSION['_token'] }}">
<input type="hidden" name="post_id" value="{{ $post->id }}">
<div class="form-group">
<textarea name="content" rows="1" class="form-control"></textarea>
</div>
<button type="submit" class="btn btn-primary float-right">Comment</button>
</form>
@endif
@if(count($comments))
<h3>{{ $post->num_of_comments }} {{ $post->num_of_comments > 1 ? 'comments' : 'comment' }}:</h3>
@foreach($comments as $comment)
<img src="https://www.gravatar.com/avatar/{{ md5(strtolower(trim($comment->email))) }}?s=50&d=mm&r=pg" class="avatar">
<div>
<h5>{{ $comment->author }}</h5>
<span class="text-secondary">{{ $comment->create_at }}</span>
@if(isset($_SESSION['is_auth']))
@if($comment->author == $_SESSION['username'])
<a href="#" class="text-primary" data-toggle="modal" data-target="#comment-edit-modal" data-action="/comment/{{ $comment->id }}/edit">Edit</a>
@endif
@if($post->author == $_SESSION['username'])
<a href="#" class="text-danger" data-toggle="modal" data-target="#comment-confirm-modal" data-action="/comment/{{ $comment->id }}/delete">Delete</a>
@endif
@endif
</div>
<p>{!! nl2br(e($comment->content)) !!}</p>
@endforeach
<div class="modal fade" id="comment-confirm-modal" tabindex="-1" role="dialog" aria-labelledby="confirm-label" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="comment-confirm-label">Confirmation</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
Are you sure you want to delete this comment?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">No</button>
<form method="POST" action="" id="delete-form">
<input type="hidden" name="_token" value="{{ $_SESSION['_token'] }}">
<input type="hidden" name="post_id" value="{{ $post->id }}">
<button type="submit" class="btn btn-danger">Yes</button>
</form>
</div>
</div>
</div>
</div>
<div class="modal fade" id="comment-edit-modal" tabindex="-1" role="dialog" aria-labelledby="edit-label" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="comment-edit-label">Edit Comment</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<form method="POST" action="" id="comment-edit-form">
<input type="hidden" name="_token" value="{{ $_SESSION['_token'] }}">
<input type="hidden" name="post_id" value="{{ $post->id }}">
<div class="modal-body">
<div class="form-group">
<textarea name="content" rows="3" class="form-control"></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary">Edit</button>
</div>
</form>
</div>
</div>
</div>
@endif
</div>
@endsection