Skip to content

Commit 808ecac

Browse files
committed
refactor: migrated sitemap page (#3834)
1 parent f1c9df7 commit 808ecac

File tree

5 files changed

+82
-74
lines changed

5 files changed

+82
-74
lines changed

phpmyfaq/index.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,31 +121,27 @@
121121
// Try Symfony Router first
122122
//
123123
try {
124-
// Load routes
125124
$routes = require __DIR__ . '/src/public-routes.php';
126125

127-
// Create URL matcher
128126
$context = new RequestContext();
129127
$context->fromRequest($request);
130128
$matcher = new UrlMatcher($routes, $context);
131129

132-
// Try to match the current route
133130
$parameters = $matcher->match($request->getPathInfo());
134131

135-
// Extract controller and method
136132
$controllerCallable = $parameters['_controller'];
137133
unset($parameters['_controller'], $parameters['_route'], $parameters['_methods']);
138134

139-
// Instantiate controller and call method
135+
$request->attributes->add($matcher->match($request->getPathInfo()));
136+
140137
if (is_array($controllerCallable)) {
141138
[$controllerClass, $method] = $controllerCallable;
142139
$controller = new $controllerClass();
143-
$routeResponse = $controller->$method($request, ...$parameters);
140+
$routeResponse = $controller->$method($request);
144141
} else {
145-
$routeResponse = $controllerCallable($request, ...$parameters);
142+
$routeResponse = $controllerCallable($request);
146143
}
147144

148-
// Send response and exit
149145
$routeResponse->send();
150146
exit();
151147
} catch (ResourceNotFoundException $e) {

phpmyfaq/sitemap.php

Lines changed: 0 additions & 64 deletions
This file was deleted.

phpmyfaq/src/phpMyFAQ/Controller/Frontend/OverviewController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
* Contact Controller
4+
* Overview Controller
55
*
66
* This Source Code Form is subject to the terms of the Mozilla Public License,
77
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
}

phpmyfaq/src/public-routes.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919

2020
use phpMyFAQ\Controller\Frontend\Api\SetupController;
2121
use phpMyFAQ\Controller\Frontend\ContactController;
22-
use phpMyFAQ\Controller\Frontend\OverviewController;use phpMyFAQ\Controller\Frontend\PageNotFoundController;
22+
use phpMyFAQ\Controller\Frontend\OverviewController;
23+
use phpMyFAQ\Controller\Frontend\PageNotFoundController;
24+
use phpMyFAQ\Controller\Frontend\SitemapController as FrontendSitemapController;
2325
use phpMyFAQ\Controller\Frontend\WebAuthnController;
2426
use phpMyFAQ\Controller\LlmsController;
2527
use phpMyFAQ\Controller\RobotsController;
@@ -40,6 +42,11 @@
4042
'controller' => [OverviewController::class, 'index'],
4143
'methods' => 'GET',
4244
],
45+
'public.sitemap' => [
46+
'path' => '/sitemap/{letter}/{language}.html',
47+
'controller' => [FrontendSitemapController::class, 'index'],
48+
'methods' => 'GET',
49+
],
4350
'public.404' => [
4451
'path' => '/404.html',
4552
'controller' => [PageNotFoundController::class, 'index'],

0 commit comments

Comments
 (0)