Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
24 / 24 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ContactController | |
100.00% |
24 / 24 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| index | |
100.00% |
23 / 23 |
|
100.00% |
1 / 1 |
4 | |||
| 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 2002-2025 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 2002-09-16 |
| 16 | */ |
| 17 | |
| 18 | declare(strict_types=1); |
| 19 | |
| 20 | namespace phpMyFAQ\Controller\Frontend; |
| 21 | |
| 22 | use Exception; |
| 23 | use phpMyFAQ\Captcha\CaptchaInterface; |
| 24 | use phpMyFAQ\Captcha\Helper\CaptchaHelperInterface; |
| 25 | use phpMyFAQ\Translation; |
| 26 | use phpMyFAQ\User\UserSession; |
| 27 | use Symfony\Component\HttpFoundation\Request; |
| 28 | use Symfony\Component\HttpFoundation\Response; |
| 29 | use Symfony\Component\Routing\Attribute\Route; |
| 30 | |
| 31 | final class ContactController extends AbstractFrontController |
| 32 | { |
| 33 | public function __construct( |
| 34 | private readonly UserSession $userSession, |
| 35 | private readonly CaptchaInterface $captcha, |
| 36 | private readonly CaptchaHelperInterface $captchaHelper, |
| 37 | ) { |
| 38 | parent::__construct(); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Handles both GET and POST requests for the contact form |
| 43 | * @throws Exception |
| 44 | */ |
| 45 | #[Route(path: '/contact.html', name: 'public.contact', methods: ['GET'])] |
| 46 | public function index(Request $request): Response |
| 47 | { |
| 48 | $this->userSession->setCurrentUser($this->currentUser); |
| 49 | $this->userSession->userTracking('contact', 0); |
| 50 | |
| 51 | $contactText = nl2br((string) $this->configuration->get('main.contactInformation')); |
| 52 | if ($this->configuration->get('layout.contactInformationHTML')) { |
| 53 | $contactText = html_entity_decode((string) $this->configuration->get('main.contactInformation')); |
| 54 | } |
| 55 | |
| 56 | return $this->render('contact.twig', [ |
| 57 | ...$this->getHeader($request), |
| 58 | 'title' => sprintf('%s - %s', Translation::getString(key: 'msgContact'), $this->configuration->getTitle()), |
| 59 | 'msgContactOwnText' => $contactText, |
| 60 | 'privacyURL' => $this->configuration->get('main.privacyURL'), |
| 61 | 'lang' => $this->configuration->getLanguage()->getLanguage(), |
| 62 | 'defaultContentMail' => $this->currentUser->getUserId() > 0 ? $this->currentUser->getUserData('email') : '', |
| 63 | 'defaultContentName' => $this->currentUser->getUserId() > 0 |
| 64 | ? $this->currentUser->getUserData('display_name') |
| 65 | : '', |
| 66 | 'version' => $this->configuration->getVersion(), |
| 67 | 'captchaFieldset' => $this->captchaHelper->renderCaptcha( |
| 68 | $this->captcha, |
| 69 | 'contact', |
| 70 | Translation::getString(key: 'msgCaptcha'), |
| 71 | $this->currentUser->isLoggedIn(), |
| 72 | ), |
| 73 | ]); |
| 74 | } |
| 75 | } |