Skip to content

Commit

Permalink
Update default theme and fix posts
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMicky-FR committed Oct 21, 2019
1 parent 091d573 commit 5fa134c
Show file tree
Hide file tree
Showing 19 changed files with 236 additions and 90 deletions.
4 changes: 3 additions & 1 deletion app/Http/Controllers/Admin/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
use Azuriom\Models\Post;
use Azuriom\Models\User;
use Carbon\Carbon;
use Illuminate\Http\Request;

class AdminController extends Controller
{
public function index()
public function index(Request $request)
{
return view('admin.dashboard', [
'secure' => $request->secure(),
'userCount' => User::count(),
'postCount' => Post::count(),
'pageCount' => Page::count(),
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Admin/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,13 @@ public function update(Request $request)
'description' => ['required', 'string', 'max:255'],
'url' => ['required', 'url'],
'timezone' => ['required', 'timezone'],
'copyright' => ['nullable', 'string', 'max:150'],
'locale' => ['required', 'string', Rule::in(array_keys(LangHelper::getAvailableLanguages()))],
'icon' => ['nullable', 'exists:images,file']
]);

Setting::updateSettings($request->only([
'name', 'description', 'url', 'timezone', 'locale', 'icon', 'logo', 'footer'
'name', 'description', 'url', 'timezone', 'locale', 'icon', 'logo', 'copyright'
]));

ActionLog::logUpdate('Settings');
Expand Down
9 changes: 8 additions & 1 deletion app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Azuriom\Http\Controllers;

use Azuriom\Models\Post;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;

Expand All @@ -14,7 +15,13 @@ class HomeController extends Controller
*/
public function index()
{
return view('home');
$posts = Post::with(['author', 'image'])
->scopes('published')
->latest('published_at')
->take(3)
->get();

return view('home')->with('posts', $posts);
}

public function maintenance(Request $request)
Expand Down
5 changes: 2 additions & 3 deletions app/Http/Controllers/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ class PageController extends Controller
*
* @param $slug
* @return \Illuminate\Http\Response
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function show($slug)
{
$page = Page::where('slug', $slug)->firstOrFail();

if (! $page->is_published && (Auth::guest() || ! Auth::user()->isAdmin())) {
abort(404);
}
$this->authorize('view', $page);

return view('pages.show')->with('page', $page);
}
Expand Down
4 changes: 2 additions & 2 deletions app/Models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ public function likes()
return $this->hasMany(Like::class);
}

public function hasLiked(User $user)
public function hasLiked(User $user = null)
{
return $this->likes->where('author_id', $user->id)->isNotEmpty();
return $this->likes->where('author_id', $user ? $user->id : auth()->id())->isNotEmpty();
}

public function isPublished()
Expand Down
30 changes: 30 additions & 0 deletions app/Policies/PagePolicy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Azuriom\Policies;

use Azuriom\Models\Page;
use Azuriom\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;

class PagePolicy
{
use HandlesAuthorization;

/**
* Determine whether the user can view the post.
*
* @param \Azuriom\Models\User $user
* @param \Azuriom\Models\Page $page
* @return mixed
*/
public function view(?User $user, Page $page)
{
if (! $page->is_enabled) {
abort(404);

return false;
}

return true;
}
}
3 changes: 3 additions & 0 deletions app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
namespace Azuriom\Providers;

use Azuriom\Models\Comment;
use Azuriom\Models\Page;
use Azuriom\Models\Post;
use Azuriom\Models\User;
use Azuriom\Policies\CommentPolicy;
use Azuriom\Policies\PagePolicy;
use Azuriom\Policies\PostPolicy;
use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
Expand All @@ -18,6 +20,7 @@ class AuthServiceProvider extends ServiceProvider
* @var array
*/
protected $policies = [
Page::class => PagePolicy::class,
Post::class => PostPolicy::class,
Comment::class => CommentPolicy::class,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function up()
$table->string('slug')->unique();
$table->text('content');
$table->boolean('is_pinned');
$table->timestamp('published_at');
$table->timestamp('published_at')->nullable();
$table->timestamps();

$table->foreign('author_id')->references('id')->on('users');
Expand Down
6 changes: 6 additions & 0 deletions resources/views/admin/dashboard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
@endpush

@section('content')
@if(! $secure)
<div class="alert alert-warning shadow-sm">
Your website is not using https, you should enable and force it for your security and the one of the users
</div>
@endif

<!-- Content Row -->
<div class="row">

Expand Down
1 change: 1 addition & 0 deletions resources/views/admin/elements/editor.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
tinymce.init({
selector: '.html-editor',
height: 350,
entity_encoding : 'raw',
plugins: 'preview searchreplace autolink code visualblocks image link media codesample table charmap hr pagebreak nonbreaking anchor toc insertdatetime advlist lists',
toolbar: 'undo redo | formatselect | bold italic underline strikethrough forecolor | link image media | alignleft aligncenter alignright alignjustify | numlist bullist outdent indent | removeformat code'
});
Expand Down
12 changes: 6 additions & 6 deletions resources/views/admin/settings/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@push('footer-scripts')
<script>
document.addEventListener('DOMContentLoaded', function () {
$('[data-image-select]').on('change', function (e) {
$('[data-image-select]').on('change', function () {
const preview = $('#' + $(this).data('image-select'));
if ($(this).val().length === 0) {
preview.parent().addClass('d-none');
Expand Down Expand Up @@ -57,7 +57,7 @@
<div class="input-group-prepend">
<a class="btn btn-outline-success" href="{{ route('admin.images.create') }}" target="_blank"><i class="fas fa-upload"></i></a>
</div>
<select class="custom-select @error('icon') is-invalid @enderror" data-image-select="faviconPreview" name="icon">
<select class="custom-select @error('icon') is-invalid @enderror" id="imageSelect" data-image-select="faviconPreview" name="icon">
<option value="" @if(!$icon) selected @endif>None</option>
@foreach($images as $image)
<option value="{{ $image->file }}" @if($image->file === $icon) selected @endif>{{ $image->name }}</option>
Expand All @@ -80,7 +80,7 @@
<div class="input-group-prepend">
<a class="btn btn-outline-success" href="{{ route('admin.images.create') }}" target="_blank"><i class="fas fa-upload"></i></a>
</div>
<select class="custom-select @error('logo') is-invalid @enderror" data-image-select="logoPreview" name="logo">
<select class="custom-select @error('logo') is-invalid @enderror" id="logoSelect" data-image-select="logoPreview" name="logo">
<option value="" @if(!$logo) selected @endif>None</option>
@foreach($images as $image)
<option value="{{ $image->file }}" @if($image->file === $logo) selected @endif>{{ $image->name }}</option>
Expand Down Expand Up @@ -124,10 +124,10 @@
</div>

<div class="form-group">
<label for="footerInput">Footer</label>
<input type="text" class="form-control @error('footer') is-invalid @enderror" id="footerInput" name="footer" value="{{ old('footer', setting('footer')) }}">
<label for="copyrightInput">Copyright</label>
<input type="text" class="form-control @error('copyright') is-invalid @enderror" id="copyrightInput" name="copyright" value="{{ old('copyright', setting('copyright')) }}">

@error('footer')
@error('copyright')
<span class="invalid-feedback" role="alert"><strong>{{ $message }}</strong></span>
@enderror
</div>
Expand Down
4 changes: 2 additions & 2 deletions resources/views/elements/navbar.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<nav class="navbar navbar-expand-md navbar-light bg-white shadow-sm">
<nav class="navbar navbar-expand-md navbar-light bg-white shadow-sm py-3">
<div class="container">
<a class="navbar-brand" href="{{ url('/') }}">
{{ site_name() }}
Expand Down Expand Up @@ -55,7 +55,7 @@
{{ __('Profile') }}
</a>

@if(Auth::user()->hasAdminAccess())
@if(auth()->user()->hasAdminAccess())
<a class="dropdown-item" href="{{ route('admin.dashboard') }}">
Admin
</a>
Expand Down
61 changes: 42 additions & 19 deletions resources/views/home.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,50 @@
@section('title', 'Home')

@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">Dashboard</div>

<div class="card-body">
@if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
<div class="home-background mb-4" style="background: url(https://via.placeholder.com/2000x500) no-repeat center">

</div>

<div class="container">
<div class="row">
<div class="col-md-8">
@foreach($posts as $post)
<div class="post-preview card mb-3 shadow-sm">
<img src="https://via.placeholder.com/750x300" class="bd-placeholder-img card-img-top">
<div class="card-body">
<h3 class="card-title">
<a href="{{ route('posts.show', $post->slug) }}">{{ $post->title }}</a></h3>
<p class="card-text">{{ Str::limit(strip_tags($post->content), 250, '...') }}</p>
<a class="btn btn-primary" href="{{ route('posts.show', $post->slug) }}">Read more</a>
</div>
@endif

@auth
You are logged in!
@else
You are a guest !
@endauth
</div>
<div class="card-footer text-muted">
Posted on {{ $post->published_at }} by {{ $post->author->name }}
</div>
</div>
@endforeach
</div>

<div class="col-md-4">
<iframe src="https://discordapp.com/widget?id=430338873000984576&theme=dark" height="500" class="discord-widget mb-3" allowtransparency="true"></iframe>

<a class="twitter-timeline" data-theme="dark" data-height="500" href="https://twitter.com/LaravelPHP">Tweets by Laravel</a>
<script async src="https://platform.twitter.com/widgets.js"></script>
</div>
</div>
</div>
</div>
@endsection

@push('styles')
<style>
.home-background {
margin-top: -2rem;
background-size: cover;
height: 500px;
}
.discord-widget {
border: none;
width: 100%;
}
</style>
@endpush
25 changes: 25 additions & 0 deletions resources/views/layouts/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,32 @@
</main>
</div>

<footer class="bg-dark text-white py-4 text-center">
<div class="copyright">
<div class="container">
{{ setting('copyright') }} |
Powered by <a href="https://azuriom.com" target="_blank" rel="noreferrer">Azuriom</a>.
</div>
</div>
</footer>

@stack('footer-scripts')

<style>
html, body {
height: 100%;
}
body {
display: flex;
flex-direction: column;
}
#app {
flex-shrink: 0;
}
footer {
margin-top: auto;
}
</style>

</body>
</html>
3 changes: 1 addition & 2 deletions resources/views/pages/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@

@section('content')
<div class="container">
<div class="card">
<div class="card shadow-sm">
<div class="card-body">
<h1>{{ $page->title }}</h1>
<hr>

{!! $page->content !!}
</div>
Expand Down
34 changes: 21 additions & 13 deletions resources/views/posts/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,28 @@
<div class="container">
<h1>News</h1>

@foreach($posts as $post)
<div class="card mb-4">
<div class="card-body">
@if($post->image !== null)
<div class="text-center">
<img class="rounded" src="{{ $post->image->url() }}" alt="{{ $post->image->name }}" height="300">
<div class="row">
@foreach($posts as $post)
<div class="col-md-6">
<div class="post-preview card my-2 shadow-sm">
{{-- @if($post->image !== null)
<div class="text-center">
<img class="rounded" src="{{ $post->image->url() }}" alt="{{ $post->image->name }}" height="300">
</div>
@endif --}}
<img src="https://via.placeholder.com/750x300" class="bd-placeholder-img card-img-top">
<div class="card-body">
<h3 class="card-title">
<a href="{{ route('posts.show', $post->slug) }}">{{ $post->title }}</a></h3>
<p class="card-text">{{ Str::limit(strip_tags($post->content), 250, '...') }}</p>
<a class="btn btn-primary" href="{{ route('posts.show', $post->slug) }}">Read more</a>
</div>
@endif
<h2 class="card-title">{{ $post->title }}</h2>
<p class="card-text">{!! $post->content !!}</p>
<a href="{{ route('posts.show', $post->slug) }}" class="btn btn-primary">Lire la suite</a>
<div class="card-footer text-muted">
Posted on {{ $post->published_at }} by {{ $post->author->name }}
</div>
</div>
</div>
<div class="card-footer text-muted">Posted on {{ $post->published_at }} by {{ $post->author->name }} @if($post->is_pinned) - Pinned @endif</div>
</div>
@endforeach
@endforeach
</div>
</div>
@endsection
Loading

0 comments on commit 5fa134c

Please sign in to comment.