|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Sitemap Controller |
| 5 | + * |
| 6 | + * This Source Code Form is subject to the terms of the Mozilla Public License, |
| 7 | + * v. 2.0. If a copy of the MPL was not distributed with this file, You can |
| 8 | + * obtain one at https://mozilla.org/MPL/2.0/. |
| 9 | + * |
| 10 | + * @package phpMyFAQ |
| 11 | + * @author Thomas Zeithaml <[email protected]> |
| 12 | + * @author Thorsten Rinne <[email protected]> |
| 13 | + * @copyright 2005-2026 phpMyFAQ Team |
| 14 | + * @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 |
| 15 | + * @link https://www.phpmyfaq.de |
| 16 | + * @since 2005-08-21 |
| 17 | + */ |
| 18 | + |
| 19 | +namespace phpMyFAQ\Controller\Frontend; |
| 20 | + |
| 21 | +use phpMyFAQ\Core\Exception; |
| 22 | +use phpMyFAQ\Filter; |
| 23 | +use phpMyFAQ\Strings; |
| 24 | +use phpMyFAQ\Translation; |
| 25 | +use phpMyFAQ\User\CurrentUser; |
| 26 | +use Symfony\Component\HttpFoundation\Request; |
| 27 | +use Symfony\Component\HttpFoundation\Response; |
| 28 | +use Symfony\Component\Routing\Attribute\Route; |
| 29 | +use Twig\Error\LoaderError; |
| 30 | + |
| 31 | +class SitemapController extends AbstractFrontController |
| 32 | +{ |
| 33 | + /** |
| 34 | + * @throws Exception |
| 35 | + * @throws LoaderError |
| 36 | + * @throws \Exception |
| 37 | + */ #[Route(path: '/sitemap/{letter}/{language}.html', name: 'public.sitemap')] |
| 38 | + public function index(Request $request): Response |
| 39 | + { |
| 40 | + $faqSession = $this->container->get('phpmyfaq.user.session'); |
| 41 | + $faqSession->setCurrentUser($this->currentUser); |
| 42 | + $faqSession->userTracking('sitemap', 0); |
| 43 | + |
| 44 | + $letter = Filter::filterVar($request->attributes->get('letter'), FILTER_SANITIZE_SPECIAL_CHARS); |
| 45 | + if (!is_null($letter) && 1 == Strings::strlen($letter)) { |
| 46 | + $currLetter = strtoupper(Strings::substr($letter, 0, 1)); |
| 47 | + } else { |
| 48 | + $currLetter = ''; |
| 49 | + } |
| 50 | + |
| 51 | + [$currentUser, $currentGroups] = CurrentUser::getCurrentUserGroupId($this->currentUser); |
| 52 | + |
| 53 | + $siteMap = $this->container->get('phpmyfaq.sitemap'); |
| 54 | + $siteMap->setUser($currentUser); |
| 55 | + $siteMap->setGroups($currentGroups); |
| 56 | + |
| 57 | + return $this->render('sitemap.twig', [ |
| 58 | + ...$this->getHeader($request), |
| 59 | + 'title' => sprintf('%s - %s', Translation::get(key: 'msgSitemap'), $this->configuration->getTitle()), |
| 60 | + 'metaDescription' => sprintf(Translation::get(key: 'msgSitemapMetaDesc'), $this->configuration->getTitle()), |
| 61 | + 'pageHeader' => |
| 62 | + $currLetter === '' || $currLetter === '0' ? Translation::get(key: 'msgSitemap') : $currLetter, |
| 63 | + 'letters' => $siteMap->getAllFirstLetters(), |
| 64 | + 'faqs' => $siteMap->getFaqsFromLetter($currLetter), |
| 65 | + 'writeCurrentLetter' => |
| 66 | + $currLetter === '' || $currLetter === '0' ? Translation::get(key: 'msgSitemap') : $currLetter, |
| 67 | + ]); |
| 68 | + } |
| 69 | +} |
0 commit comments