| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- use App\Settings;
- use App\Models\Page;
- use App\Models\Slot;
- use App\Models\SeoMeta;
- use App\Models\Faq;
- use App\Models\Author;
- // Получение страницы по slug
- $pageModel = new Page();
- $seoMetaModel = new SeoMeta();
- $faqModel = new Faq();
- $authorModel = new Author();
- $slotModel = new Slot();
- // Получаем slug из URL
- $slug = $slug ?? $_GET['slug'] ?? '';
- // Находим страницу по slug или главную страницу если slug пустой
- if (empty($slug)) {
- // Главная страница
- $currentPage = \db()->fetchOne("SELECT * FROM pages WHERE is_homepage = 1");
- } else {
- // Обычная страница по slug
- $currentPage = \db()->fetchOne("SELECT * FROM pages WHERE slug = ?", [$slug]);
- }
- // Если страница не найдена, возвращаем 404
- if (!$currentPage) {
- http_response_code(404);
- die('404 - Page not found');
- }
- // Получаем данные из настроек
- $content = (new Settings('content'))->getAll();
- // Получаем SEO данные для страницы
- $seo = $seoMetaModel->getForRecord('page', $currentPage['id']) ?: [];
- // Декодируем extra_fields
- $extraFields = [];
- if (!empty($currentPage['extra_fields'])) {
- $extraFields = json_decode($currentPage['extra_fields'], true) ?: [];
- }
- // Контент страницы
- $pageContent = $currentPage['content'] ?? '';
- // Получаем топ контент из extra_fields
- $topContent = $extraFields['top_content'] ?? '';
- // Получаем FAQ для этой страницы
- $faqItems = $faqModel->getByMorphable('page', $currentPage['id']);
- // Данные для домена
- $currentDomain = getCurrentDomain();
- $currentUrl = getCurrentUrl();
- // Определение типа пользователя
- $ip = getUserIp();
- $isGoogleBot = (strpos(gethostbyaddr($ip), 'google') !== false)
- ? true
- : false;
- $isBingBot = (strpos(gethostbyaddr($ip), 'bing') !== false)
- ? true
- : false;
- $isSearchBot = $isGoogleBot || $isBingBot;
- // Определяем лейаут страницы
- $layout = \App\Enums\PageLayout::tryFrom($currentPage['layout'] ?? 'default') ?? \App\Enums\PageLayout::Default;
- $layoutFile = $layout->viewPath();
- return ViewRender($layoutFile, [
- 'content' => $content,
- 'seo' => $seo,
- 'faqItems' => $faqItems,
- 'pageContent' => $pageContent,
- 'pageData' => $currentPage,
- 'topContent' => $topContent,
- 'currentDomain' => $currentDomain,
- 'currentUrl' => $currentUrl,
- 'isHomepage' => !empty($currentPage['is_homepage']),
- 'isSearchBot' => $isSearchBot,
- 'author' => $authorModel->getAll()[0],
- 'slots' => $slotModel->getAll(),
- 'userIp' => $ip,
- ]);
|