Skip to content

Commit 9a0ccac

Browse files
committed
refactor: migrated news page (#3834)
1 parent 732925e commit 9a0ccac

File tree

5 files changed

+284
-165
lines changed

5 files changed

+284
-165
lines changed

phpmyfaq/news.php

Lines changed: 0 additions & 164 deletions
This file was deleted.
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?php
2+
3+
/**
4+
* News 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+
* @author Matteo Scaramuccia <matteo@scaramuccia.com>
13+
* @copyright 2006-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 2006-07-23
17+
*/
18+
19+
declare(strict_types=1);
20+
21+
namespace phpMyFAQ\Controller\Frontend;
22+
23+
use phpMyFAQ\Captcha\Helper\CaptchaHelper;
24+
use phpMyFAQ\Comments;
25+
use phpMyFAQ\Core\Exception;
26+
use phpMyFAQ\Entity\CommentType;
27+
use phpMyFAQ\Filter;
28+
use phpMyFAQ\Helper\CommentHelper;
29+
use phpMyFAQ\News\NewsService;
30+
use phpMyFAQ\Session\Token;
31+
use phpMyFAQ\Translation;
32+
use Symfony\Component\HttpFoundation\Request;
33+
use Symfony\Component\HttpFoundation\Response;
34+
use Symfony\Component\Routing\Attribute\Route;
35+
36+
final class NewsController extends AbstractFrontController
37+
{
38+
/**
39+
* Displays a news article with comments.
40+
*
41+
* @throws Exception
42+
* @throws \Exception
43+
*/
44+
#[Route(path: '/news/{newsId}/{newsLang}/{slug}.html', name: 'public.news', requirements: [
45+
'newsId' => '\d+',
46+
'newsLang' => '[a-z\-_]+',
47+
])]
48+
public function index(Request $request): Response
49+
{
50+
$newsId = Filter::filterVar($request->attributes->get('newsId'), FILTER_VALIDATE_INT);
51+
52+
if ($newsId === false || $newsId === null) {
53+
return $this->render('404.twig', [
54+
...$this->getHeader($request),
55+
]);
56+
}
57+
58+
$faqSession = $this->container->get('phpmyfaq.user.session');
59+
$faqSession->setCurrentUser($this->currentUser);
60+
$faqSession->userTracking('news_view', $newsId);
61+
62+
$newsService = new NewsService($this->configuration, $this->currentUser);
63+
$news = $newsService->getProcessedNews($newsId);
64+
65+
$captcha = $this->container->get('phpmyfaq.captcha');
66+
$captchaHelper = CaptchaHelper::getInstance($this->configuration);
67+
68+
$commentHelper = new CommentHelper();
69+
$commentHelper->setConfiguration($this->configuration);
70+
71+
$comment = new Comments($this->configuration);
72+
$comments = $comment->getCommentsData($newsId, CommentType::NEWS);
73+
74+
$session = $this->container->get('session');
75+
76+
return $this->render('news.twig', [
77+
...$this->getHeader($request),
78+
'writeNewsHeader' => $this->configuration->getTitle() . Translation::get(key: 'msgNews'),
79+
'newsHeader' => $news['processedHeader'],
80+
'mainPageContent' => $news['processedContent'],
81+
'writeDateMsg' => $newsService->formatNewsDate($news),
82+
'msgAboutThisNews' => Translation::get(key: 'msgAboutThisNews'),
83+
'writeAuthor' => $newsService->getAuthorInfo($news),
84+
'editThisEntry' => $newsService->getEditLink($newsId),
85+
'writeCommentMsg' => $newsService->getCommentMessage($news),
86+
'msgWriteComment' => Translation::get(key: 'newsWriteComment'),
87+
'newsId' => $newsId,
88+
'newsLang' => $news['lang'],
89+
'msgCommentHeader' => Translation::get(key: 'msgCommentHeader'),
90+
'msgNewContentName' => Translation::get(key: 'msgNewContentName'),
91+
'msgNewContentMail' => Translation::get(key: 'msgNewContentMail'),
92+
'defaultContentMail' => $this->currentUser->getUserId() > 0 ? $this->currentUser->getUserData('email') : '',
93+
'defaultContentName' => $this->currentUser->getUserId() > 0
94+
? $this->currentUser->getUserData('display_name')
95+
: '',
96+
'msgYourComment' => Translation::get(key: 'msgYourComment'),
97+
'csrfInput' => Token::getInstance($session)->getTokenInput('add-comment'),
98+
'msgCancel' => Translation::get(key: 'ad_gen_cancel'),
99+
'msgNewContentSubmit' => Translation::get(key: 'msgNewContentSubmit'),
100+
'captchaFieldset' => $captchaHelper->renderCaptcha(
101+
$captcha,
102+
'writecomment',
103+
Translation::get(key: 'msgCaptcha'),
104+
$this->currentUser->isLoggedIn(),
105+
),
106+
'renderComments' => $commentHelper->getComments($comments),
107+
]);
108+
}
109+
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ final class PdfController extends AbstractFrontController
4141
/**
4242
* @throws Exception|\Exception|CommonMarkException
4343
*/
44-
#[Route(path: '/pdf/{categoryId}/{faqId}/{faqLanguage}', name: 'public.pdf.faq')]
44+
#[Route(path: '/pdf/{categoryId}/{faqId}/{faqLanguage}', name: 'public.pdf.faq', requirements: [
45+
'categoryId' => '\d+',
46+
'faqId' => '\d+',
47+
'faqLanguage' => '[a-z]{2}(_[a-z]{2})?',
48+
])]
4549
public function index(Request $request): Response
4650
{
4751
$categoryId = Filter::filterVar($request->attributes->get('categoryId'), FILTER_VALIDATE_INT);

0 commit comments

Comments
 (0)