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