| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- use App\Settings;
- use App\Models\Page;
- use App\Models\SeoMeta;
- use App\Models\Faq;
- // Получение страницы по slug
- $pageModel = new Page();
- $seoMetaModel = new SeoMeta();
- $faqModel = new Faq();
- // Получаем 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']) ?: [];
- // Контент страницы
- $pageContent = $currentPage['content'] ?? '';
- // Получаем топ контент если есть
- $topContent = $currentPage['top_content'] ?? '';
- // Подготавливаем содержание для контента
- $headings = getContainsByText($pageContent);
- $pageContent = addIdToHInText($pageContent, $headings);
- // Получаем 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,
- 'headings' => $headings,
- 'currentDomain' => $currentDomain,
- 'currentUrl' => $currentUrl,
- 'isHomepage' => !empty($currentPage['is_homepage']),
- 'isSearchBot' => $isSearchBot,
- 'userIp' => $ip,
- ]);
|