Skip to content

Commit f1c9df7

Browse files
committed
refactor: migrated FAQ overview page (#3834)
1 parent d19971d commit f1c9df7

File tree

5 files changed

+86
-62
lines changed

5 files changed

+86
-62
lines changed

phpmyfaq/.htaccess

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ Header set Access-Control-Allow-Headers "Content-Type, Authorization"
110110
RewriteRule ^show-categories.html$ index.php?action=show [L,QSA]
111111
RewriteRule ^forgot-password$ index.php?action=password [L,QSA]
112112
RewriteRule ^(search|open-questions|glossary|overview|login|privacy|contact)\.html$ index.php?action=$1 [L,QSA]
113+
RewriteRule ^404\.html$ index.php [L,QSA]
113114
RewriteRule ^(login) index.php?action=login [L,QSA]
114115
# start page
115116
RewriteRule ^index.html$ index.php [L,QSA]
@@ -143,7 +144,7 @@ Header set Access-Control-Allow-Headers "Content-Type, Authorization"
143144
# Authentication services
144145
RewriteRule ^services/webauthn(.*) index.php [L,QSA]
145146
# User pages
146-
RewriteRule ^user/(ucp|bookmarks|request-removal|logout|register) index.php?action=$1 [L,QSA]
147+
RewriteRule ^user/(ucp|bookmarks|request-removal|logout|register)/?$ index.php?action=$1 [L,QSA]
147148
# Administration API
148149
RewriteRule ^admin/api/(.*) admin/api/index.php [L,QSA]
149150
# Administration pages

phpmyfaq/overview.php

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
namespace phpMyFAQ\Controller\Frontend;
2121

2222
use Exception;
23-
use phpMyFAQ\Controller\Route;
2423
use phpMyFAQ\Translation;
2524
use Symfony\Component\HttpFoundation\Request;
2625
use Symfony\Component\HttpFoundation\Response;
26+
use Symfony\Component\Routing\Attribute\Route;
2727

2828
final class ContactController extends AbstractFrontController
2929
{
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
/**
4+
* Contact 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 Thorsten Rinne <thorsten@phpmyfaq.de>
12+
* @copyright 2015-2026 phpMyFAQ Team
13+
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
14+
* @link https://www.phpmyfaq.de
15+
* @since 2015-09-27
16+
*/
17+
18+
namespace phpMyFAQ\Controller\Frontend;
19+
20+
use phpMyFAQ\Category;
21+
use phpMyFAQ\Core\Exception;
22+
use phpMyFAQ\Translation;
23+
use phpMyFAQ\Twig\Extensions\CategoryNameTwigExtension;
24+
use phpMyFAQ\Twig\Extensions\CreateLinkTwigExtension;
25+
use phpMyFAQ\Twig\Extensions\FaqTwigExtension;
26+
use phpMyFAQ\User\CurrentUser;
27+
use Symfony\Component\HttpFoundation\Request;
28+
use Symfony\Component\HttpFoundation\Response;
29+
use Symfony\Component\Routing\Attribute\Route;
30+
use Twig\Error\LoaderError;
31+
use Twig\Extension\AttributeExtension;
32+
33+
class OverviewController extends AbstractFrontController
34+
{
35+
/**
36+
* @throws Exception
37+
* @throws LoaderError
38+
* @throws \Exception
39+
*/ #[Route(path: '/overview.html', name: 'public.overview')]
40+
public function index(Request $request): Response
41+
{
42+
$faqSession = $this->container->get('phpmyfaq.user.session');
43+
$faqSession->setCurrentUser($this->currentUser);
44+
$faqSession->userTracking('overview', 0);
45+
46+
$faqHelper = $this->container->get('phpmyfaq.helper.faq');
47+
48+
[$currentUser, $currentGroups] = CurrentUser::getCurrentUserGroupId($this->currentUser);
49+
50+
$category = new Category($this->configuration, $currentGroups, true);
51+
$category->setUser($currentUser)->setGroups($currentGroups);
52+
53+
$faq = $this->container->get('phpmyfaq.faq');
54+
$faq->setUser($currentUser);
55+
$faq->setGroups($currentGroups);
56+
57+
$this->addExtension(new AttributeExtension(CategoryNameTwigExtension::class));
58+
$this->addExtension(new AttributeExtension(CreateLinkTwigExtension::class));
59+
$this->addExtension(new AttributeExtension(FaqTwigExtension::class));
60+
return $this->render('overview.twig', [
61+
...$this->getHeader($request),
62+
'title' => sprintf('%s - %s', Translation::get(key: 'faqOverview'), $this->configuration->getTitle()),
63+
'metaDescription' => sprintf(
64+
Translation::get(key: 'msgOverviewMetaDesc'),
65+
$this->configuration->getTitle(),
66+
),
67+
'pageHeader' => Translation::get(key: 'faqOverview'),
68+
'faqOverview' => $faqHelper->createOverview(
69+
$category,
70+
$faq,
71+
$this->configuration->getLanguage()->getLanguage(),
72+
),
73+
'msgAuthor' => Translation::get(key: 'msgAuthor'),
74+
'msgLastUpdateArticle' => Translation::get(key: 'msgLastUpdateArticle'),
75+
]);
76+
}
77+
}

phpmyfaq/src/public-routes.php

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

2020
use phpMyFAQ\Controller\Frontend\Api\SetupController;
2121
use phpMyFAQ\Controller\Frontend\ContactController;
22-
use phpMyFAQ\Controller\Frontend\PageNotFoundController;
22+
use phpMyFAQ\Controller\Frontend\OverviewController;use phpMyFAQ\Controller\Frontend\PageNotFoundController;
2323
use phpMyFAQ\Controller\Frontend\WebAuthnController;
2424
use phpMyFAQ\Controller\LlmsController;
2525
use phpMyFAQ\Controller\RobotsController;
@@ -35,6 +35,11 @@
3535
'controller' => [ContactController::class, 'index'],
3636
'methods' => 'GET|POST',
3737
],
38+
'public.overview' => [
39+
'path' => '/overview.html',
40+
'controller' => [OverviewController::class, 'index'],
41+
'methods' => 'GET',
42+
],
3843
'public.404' => [
3944
'path' => '/404.html',
4045
'controller' => [PageNotFoundController::class, 'index'],

0 commit comments

Comments
 (0)