PageView / single view

This commit is contained in:
Alexander Yakovlev 2022-08-09 07:41:14 +07:00
parent 0f2186a50c
commit a2aadecea3
Signed by: oreolek
GPG key ID: 8D24103F5EE2A6C0
9 changed files with 34 additions and 13 deletions

View file

@ -0,0 +1,21 @@
<?php
namespace App\Http\Controllers;
use App\Models\Page;
class PageController extends Controller
{
public function read() {
$pages = Page::published()->orderBy('posted_at', 'DESC')->simplePaginate(15);
return view('index', [
'items' => $pages
]);
}
public function view($id) {
$page = Page::findOrFail($id);
return view('single', [
'item' => $page
]);
}
}

View file

@ -14,7 +14,7 @@ class PostController extends Controller
}
public function view($id) {
$post = Post::findOrFail($id);
return view('post.view', [
return view('single', [
'item' => $post
]);
}

View file

@ -107,6 +107,7 @@ class ReadComposer extends GenericView
$view->with('content', $this->content);
$view->with('show_date', $this->show_date);
$view->with('show_create', $this->show_create);
$view->with('navigation', $this->navigation());
$view->with('is_admin', $this->is_admin);
}
}

View file

@ -6,7 +6,6 @@ use App\Models\Post;
use App\Models\Page;
use Illuminate\View\View;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Str;
use Nette\Utils\Html;
class ViewComposer extends GenericView
@ -63,7 +62,7 @@ class ViewComposer extends GenericView
'action' => 'view',
'id' => $item->id
)).'#comments';
if ($item->password !== '') {
if (isset($item->password) && $item->password !== '') {
$output['content'] = _('Введите пароль для просмотра.');
} else {
if (isset($item->content_html) && !empty($item->content_html)) {
@ -72,9 +71,6 @@ class ViewComposer extends GenericView
$output['content'] = $this->markdown->convert($item->content);
}
}
// but we have to close all unclosed tags
// TODO tidy
// $output['content'] = HTML::tidy($output['content']);
return $output;
}
@ -109,13 +105,16 @@ class ViewComposer extends GenericView
}
protected function get_input_password(): string {
if ($this->item->password !== '') {
if (isset($this->item->password) && $this->item->password !== '') {
return '<input type="password" name="password" />';
}
return '';
}
protected function get_tags(): string {
if (!method_exists($this->item, 'tags')) {
return '';
}
$tags = $this->item->tags()->get();
$retval = '';
foreach($tags as $tag) {

View file

@ -16,7 +16,6 @@ class ViewServiceProvider extends ServiceProvider
{
// Using class based composers...
View::composer('read', 'App\Http\View\ReadComposer');
View::composer('post.view', 'App\Http\View\ViewComposer');
View::composer('page.view', 'App\Http\View\ViewComposer');
View::composer('single', 'App\Http\View\ViewComposer');
}
}

View file

@ -67,7 +67,7 @@ return [
|
*/
'timezone' => 'GMT+7',
'timezone' => 'Asia/Krasnoyarsk',
/*
|--------------------------------------------------------------------------

View file

@ -1,3 +0,0 @@
<div class="hyphenate">
{{{content}}}
</div>

View file

@ -9,11 +9,13 @@
<div class="yashare-auto-init" data-yashareL10n="ru" data-yashareType="none" data-yashareQuickServices="vkontakte,facebook,twitter,odnoklassniki,lj,gplus" data-yashareImage="http://oreolek.ru/Oreolek.png"></div>
</div>
<div class="date" property="datePublished">{{$item['date']}}</div>
@if ($input_password)
<div class='row'>
<div class="col-sm-4 col-sm-offset-4">
{!! $input_password !!}
</div>
</div>
@endif
<div class="hyphenate">
<div property="text">{!! $content !!}</div>
<div property="text">{!! $item['content'] !!}</div>

View file

@ -2,6 +2,7 @@
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PostController;
use App\Http\Controllers\PageController;
use App\Http\Controllers\CommentController;
/*
@ -19,6 +20,7 @@ Route::get('/', [PostController::class, 'read']);
Route::get('/Post/read', [PostController::class, 'read'])->name('default');
Route::any('/Post/read/page/{page}', [PostController::class, 'read']);
Route::get('/Post/view/{id}', [PostController::class, 'view'])->name('view');
Route::get('/page/view/{id}', [PageController::class, 'view'])->name('page.view');
Route::get('/Tag/{id}', [PostController::class, 'view'])->name('tag');
Route::any('/Comment/post/{id}', [CommentController::class, 'load'])->name('comments.load');
Route::post('/Comment/post', [CommentController::class, 'post'])->name('comments.post');