129 lines
3.6 KiB
PHP
129 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use cPad\Plugins\Pages\Services\Page;
|
|
|
|
class MainController extends Controller
|
|
{
|
|
protected $lang;
|
|
|
|
public function __construct(protected Page $page)
|
|
{
|
|
$this->lang = app()->getLocale();
|
|
}
|
|
|
|
public function Main(Request $request)
|
|
{
|
|
$page = $this->page->getByKeycode('PAGE-HOME', $this->lang);
|
|
|
|
if (is_null($page)) {
|
|
abort(404);
|
|
}
|
|
|
|
$seo = $this->pageSeo($page, 'Home');
|
|
|
|
return view('pages.index', [
|
|
'page' => 'home',
|
|
'assetBase' => asset('assets'),
|
|
'page_title' => $seo['title'],
|
|
'seo' => $seo,
|
|
'title' => $seo['title'],
|
|
]);
|
|
}
|
|
|
|
public function Page(Request $request, string $lang, int $id)
|
|
{
|
|
$validator = Validator::make([
|
|
'iso' => $lang,
|
|
'id' => $id,
|
|
], [
|
|
'iso' => 'string|required',
|
|
'id' => 'integer|required|min:1',
|
|
]);
|
|
|
|
if ($validator->fails()) {
|
|
abort(404);
|
|
}
|
|
|
|
$content = $this->page->load($id, $lang);
|
|
|
|
if (is_null($content)) {
|
|
abort(404);
|
|
}
|
|
|
|
$slider = null;
|
|
$seo = $this->pageSeo($content, 'Page');
|
|
|
|
return view('pages.page', [
|
|
'page' => Str::slug($seo['title'] ?? 'page'),
|
|
'content' => $content,
|
|
'slider' => $slider,
|
|
'page_title' => $seo['title'],
|
|
'seo' => $seo,
|
|
'assetBase' => asset('assets'),
|
|
'title' => $seo['title'],
|
|
]);
|
|
}
|
|
|
|
public function Slug(Request $request, string $lang, string $slug)
|
|
{
|
|
$slug = Str::slug($slug);
|
|
$lang = Str::slug($lang);
|
|
|
|
#$content = $this->page->slug($slug, $lang);
|
|
$content = $this->page->getBySlug($slug, $lang);
|
|
|
|
if (is_null($content)) {
|
|
abort(404);
|
|
}
|
|
|
|
$seo = $this->pageSeo($content, $slug);
|
|
|
|
return view('pages.page', [
|
|
'page' => $slug,
|
|
'content' => $content,
|
|
'slider' => null,
|
|
'page_title' => $seo['title'],
|
|
'seo' => $seo,
|
|
'assetBase' => asset('assets'),
|
|
'title' => $seo['title'],
|
|
]);
|
|
}
|
|
|
|
private function pageSeo(object $page, ?string $fallbackTitle = null): array
|
|
{
|
|
$meta = data_get($page, 'meta') ?? [];
|
|
$og = data_get($page, 'og') ?? [];
|
|
$translation = data_get($page, 'translation');
|
|
$content = data_get($page, 'content');
|
|
|
|
$title = (string) (data_get($meta, 'title')
|
|
?: data_get($translation, 'page_title')
|
|
?: data_get($content, 'headline')
|
|
?: $fallbackTitle
|
|
?: 'Page');
|
|
|
|
$description = (string) (data_get($meta, 'description')
|
|
?: data_get($translation, 'meta_description')
|
|
?: '');
|
|
|
|
return [
|
|
'title' => $title,
|
|
'meta_description' => $description,
|
|
'meta_keywords' => (string) (data_get($meta, 'keywords') ?: ''),
|
|
'meta_author' => (string) (data_get($meta, 'author') ?: ''),
|
|
'meta_publisher' => (string) (data_get($meta, 'publisher') ?: ''),
|
|
'meta_copyright' => (string) (data_get($meta, 'copyright') ?: ''),
|
|
'meta_refresh' => data_get($meta, 'refresh'),
|
|
'og_title' => (string) (data_get($og, 'title') ?: $title),
|
|
'og_description' => (string) (data_get($og, 'description') ?: $description),
|
|
'og_image' => (string) (data_get($og, 'image') ?: ''),
|
|
'og_type' => (string) (data_get($og, 'type') ?: 'website'),
|
|
];
|
|
}
|
|
}
|