Added News page
This commit is contained in:
@@ -9,13 +9,12 @@ class GigsController extends Controller
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
private GigsLoader $loader,
|
private GigsLoader $loader,
|
||||||
) {
|
) {
|
||||||
|
$this->addCssFile('gigs.css');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$events = $this->loader->getEvents();
|
$events = $this->loader->getEvents();
|
||||||
$this->addCssFile('gigs.css');
|
|
||||||
|
|
||||||
return $this->render('gigs')
|
return $this->render('gigs')
|
||||||
->with(compact('events'));
|
->with(compact('events'));
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Models\Loaders\NewsLoader;
|
||||||
|
use App\Views\NewsView;
|
||||||
|
|
||||||
|
class NewsController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private NewsLoader $newsLoader,
|
||||||
|
private NewsView $view,
|
||||||
|
) {
|
||||||
|
$this->addCssFile('news.css');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$news = $this->newsLoader->getNews();
|
||||||
|
$this->view->prepareData($news);
|
||||||
|
|
||||||
|
|
||||||
|
return $this->render('news')
|
||||||
|
->with(compact('news'));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Loaders;
|
||||||
|
|
||||||
|
use App\Models\ORM\News;
|
||||||
|
|
||||||
|
class NewsLoader
|
||||||
|
{
|
||||||
|
public function getNews(int $offset = 0, int $limit = 10): array
|
||||||
|
{
|
||||||
|
$data = News::select("*")
|
||||||
|
->limit($limit)
|
||||||
|
->offset($offset)
|
||||||
|
->get();
|
||||||
|
|
||||||
|
return $data ? $data->toArray() : [];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\ORM;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class News extends Model
|
||||||
|
{
|
||||||
|
protected $table = 'allNewsView';
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Views;
|
||||||
|
|
||||||
|
class NewsView
|
||||||
|
{
|
||||||
|
const VK_LINK = 'vk.com';
|
||||||
|
|
||||||
|
public function shortBody(string $text): string
|
||||||
|
{
|
||||||
|
$tmp = explode("<br>",$text);
|
||||||
|
$short = array_slice($tmp,0,1);
|
||||||
|
|
||||||
|
return implode("<br>",$short);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function longBody(string $text): string
|
||||||
|
{
|
||||||
|
$tmp = explode("<br>",$text);
|
||||||
|
$long = array_slice($tmp,1);
|
||||||
|
|
||||||
|
return implode("<br>",$long);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function prepareData(array &$data): void
|
||||||
|
{
|
||||||
|
foreach($data as $index => $row) {
|
||||||
|
if($row['author_type'] === 0) {
|
||||||
|
$keyword = "club";
|
||||||
|
} else {
|
||||||
|
$keyword = "id";
|
||||||
|
}
|
||||||
|
|
||||||
|
if($row['post_type'] === "copy") {
|
||||||
|
$data[$index]['author_link'] = sprintf("%s/%s%d", self::VK_LINK, $keyword, $row['author']);
|
||||||
|
$data[$index]['article_link'] = sprintf("%s/%s%d?w=wall%d_%d",
|
||||||
|
self::VK_LINK, $keyword, $row['author'], $row['author'], $row['copy_post_id']
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$data[$index]['author_link'] = sprintf("%s/%s%d", self::VK_LINK, $keyword, $row['author']);
|
||||||
|
$data[$index]['article_link'] = sprintf("%s/%s%d?w=wall%d_%d",
|
||||||
|
self::VK_LINK, $keyword, $row['author'], $row['author'], $row['id']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$data[$index]['body1'] = $this->convertMediaLinks($this->shortBody($row['article']));
|
||||||
|
$data[$index]['body2'] = $this->convertMediaLinks($this->longBody($row['article']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function cleanBreaks(string $text): string
|
||||||
|
{
|
||||||
|
return str_replace("<br><br>", "<br>", $text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function convertMediaLinks(string $link): string
|
||||||
|
{
|
||||||
|
$pattern = '/(http|https):\/\/(\S+)/i';
|
||||||
|
$replacement = '<a href="$0" target="_blank">$0</a>';
|
||||||
|
$res = preg_replace($pattern,$replacement,$link);
|
||||||
|
|
||||||
|
$pattern = '/\[([^\[\]\|]+)\|([^\[\]\|]+)\]/i';
|
||||||
|
$replacement = sprintf('<a target=\'_blank\' href=\'%s/$1\'>$2</a>', self::VK_LINK);
|
||||||
|
$res = preg_replace($pattern,$replacement,$res);
|
||||||
|
|
||||||
|
#https://vk.com/feed?q=%23ledstarband§ion=search
|
||||||
|
$pattern = '/\#(\S+)/i';
|
||||||
|
$replacement = '<a target=\'_blank\' href="'.self::VK_LINK.'/feed?q=%23$1§ion=search">$0</a>';
|
||||||
|
$res = preg_replace($pattern, $replacement, $res);
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,6 +24,6 @@
|
|||||||
|
|
||||||
@section('breadcrump')
|
@section('breadcrump')
|
||||||
<ol class="breadcrumb bread">
|
<ol class="breadcrumb bread">
|
||||||
<li><a href="main" class="breadcrumb-item">Группа / Состав</a></li>
|
<li>Группа / <a href="main" class="breadcrumb-item">Состав</a></li>
|
||||||
</ol>
|
</ol>
|
||||||
@endsection
|
@endsection
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
<div class="container transp">
|
<div class="container transp">
|
||||||
<div class="row">@include('include.menu')</div>
|
<div class="row">@include('include.menu')</div>
|
||||||
<div class="row">@yield('content')</div>
|
<div class="row">@yield('content')</div>
|
||||||
<div class=row>@include('include.footer')</div>
|
<div class=row>@include('include.footer')</div>content
|
||||||
</div>
|
</div>
|
||||||
@foreach($js_files as $js)
|
@foreach($js_files as $js)
|
||||||
<script type="text/javascript" src="js/{{ $js }}"></script>
|
<script type="text/javascript" src="js/{{ $js }}"></script>
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
@extends('main')
|
||||||
|
@section('title', 'Новости')
|
||||||
|
@section('content')
|
||||||
|
<div class="col-md-10 col-md-offset-1">
|
||||||
|
<div class="emptyrow hidden-sm"></div>
|
||||||
|
|
||||||
|
@foreach($news as $record)
|
||||||
|
<div class="media" id="{{ $record['id'] }}">
|
||||||
|
<div class="media-left media-top hidden-xs">
|
||||||
|
<a target="_blank" href="{{ $record['author_link'] }}">
|
||||||
|
<img width=100 class="media-object" src="{{ $record['img_src'] }}" alt="image"></a>
|
||||||
|
<span class="mday">{{ $record['day'] }}</span>/{{ $record['month'] }} {{ $record['time'] }}
|
||||||
|
</div>
|
||||||
|
<div class="media-body">
|
||||||
|
<div class="newsHeader"><h4 class="media-heading">
|
||||||
|
<a target="_blank" href="{{ $record['author_link'] }}">{{ $record['header'] }}</a></h4>
|
||||||
|
</div>
|
||||||
|
<div class="newsBody">
|
||||||
|
<div id="shortArticle">{!! $record['body1'] !!}</div>
|
||||||
|
<div id="longArticle{{ $record['id'] }}" class="collapse" aria-expanded="false">{!! $record['body2'] !!}</div>
|
||||||
|
<div class="newsFooter">
|
||||||
|
<a target="_blank" href="{{ $record['article_link'] }}">Читать Вконтакте</a>
|
||||||
|
<a class="readMode" data-toggle="collapse" href="#longArticle{{ $record['id'] }}">Показать
|
||||||
|
полностью....</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<hr>
|
||||||
|
</div>
|
||||||
|
@endforeach
|
||||||
|
<div class="emptyrow hidden-xs"></div>
|
||||||
|
</div>
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
@section('breadcrump')
|
||||||
|
<ol class="breadcrumb bread">
|
||||||
|
<li><a href="main" class="breadcrumb-item">Новости</a></li>
|
||||||
|
</ol>
|
||||||
|
@endsection
|
||||||
@@ -6,12 +6,14 @@ use App\Http\Controllers\RiderController;
|
|||||||
use App\Http\Controllers\PlaylistController;
|
use App\Http\Controllers\PlaylistController;
|
||||||
use App\Http\Controllers\BandController;
|
use App\Http\Controllers\BandController;
|
||||||
use App\Http\Controllers\GigsController;
|
use App\Http\Controllers\GigsController;
|
||||||
|
use App\Http\Controllers\NewsController;
|
||||||
|
|
||||||
Route::get('/', [MainController::class, 'index']);
|
Route::get('/', [MainController::class, 'index']);
|
||||||
Route::get('/rider', [RiderController::class, 'index']);
|
Route::get('/rider', [RiderController::class, 'index']);
|
||||||
Route::get('/playlist', [PlaylistController::class, 'index']);
|
Route::get('/playlist', [PlaylistController::class, 'index']);
|
||||||
Route::get('/band', [BandController::class, 'index']);
|
Route::get('/band', [BandController::class, 'index']);
|
||||||
Route::get('/gigs', [GigsController::class, 'index']);
|
Route::get('/gigs', [GigsController::class, 'index']);
|
||||||
|
Route::get('/news', [NewsController::class, 'index']);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Доделать остальные маршруты
|
* Доделать остальные маршруты
|
||||||
|
|||||||
Reference in New Issue
Block a user