page.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. use App\Settings;
  3. use App\Models\Page;
  4. use App\Models\SeoMeta;
  5. use App\Models\Faq;
  6. // Получение страницы по slug
  7. $pageModel = new Page();
  8. $seoMetaModel = new SeoMeta();
  9. $faqModel = new Faq();
  10. // Получаем slug из URL
  11. $slug = $slug ?? $_GET['slug'] ?? '';
  12. // Находим страницу по slug
  13. $currentPage = \db()->fetchOne("SELECT * FROM pages WHERE slug = ? AND is_homepage = 0", [$slug]);
  14. // Если страница не найдена, возвращаем 404
  15. if (!$currentPage) {
  16. http_response_code(404);
  17. die('404 - Page not found');
  18. }
  19. // Получаем данные из настроек
  20. $content = (new Settings('content'))->getAll();
  21. // Получаем SEO данные для страницы
  22. $seo = $seoMetaModel->getForRecord('page', $currentPage['id']) ?: [];
  23. // Контент страницы
  24. $pageContent = $currentPage['content'] ?? '';
  25. // Получаем топ контент если есть
  26. $topContent = $currentPage['top_content'] ?? '';
  27. // Получаем FAQ для этой страницы
  28. $faqItems = $faqModel->getByMorphable('page', $currentPage['id']);
  29. // Данные для домена
  30. $currentDomain = getCurrentDomain();
  31. $currentUrl = getCurrentUrl();
  32. // Определение типа пользователя
  33. $ip = getUserIp();
  34. $isSearchBot = preg_match('/bot|crawl|slurp|spider/i', $_SERVER['HTTP_USER_AGENT'] ?? '');
  35. // Определяем лейаут страницы
  36. $layout = \App\Enums\PageLayout::tryFrom($currentPage['layout'] ?? 'default') ?? \App\Enums\PageLayout::Default;
  37. $layoutFile = $layout->viewPath();
  38. return ViewRender($layoutFile, [
  39. 'content' => $content,
  40. 'seo' => $seo,
  41. 'faqItems' => $faqItems,
  42. 'pageContent' => $pageContent,
  43. 'pageData' => $currentPage,
  44. 'topContent' => $topContent,
  45. 'currentDomain' => $currentDomain,
  46. 'currentUrl' => $currentUrl,
  47. 'isHomepage' => false,
  48. 'isSearchBot' => $isSearchBot,
  49. 'userIp' => $ip,
  50. ]);