Skip to content

Commit bd2ba72

Browse files
committed
fix: corrected some issues (#3834)
1 parent b8435c4 commit bd2ba72

File tree

4 files changed

+8
-166
lines changed

4 files changed

+8
-166
lines changed

phpmyfaq/index.php

Lines changed: 3 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* variables. That's all.
88
*
99
* This Source Code Form is subject to the terms of the Mozilla Public License,
10-
* v. 2.0. If a copy of the MPL wasn't distributed with this file, You can
10+
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
1111
* obtain one at https://mozilla.org/MPL/2.0/.
1212
*
1313
* @package phpMyFAQ
@@ -23,7 +23,6 @@
2323

2424
use phpMyFAQ\Application;
2525
use phpMyFAQ\Core\Exception;
26-
use phpMyFAQ\Link;
2726
use Symfony\Component\Config\FileLocator;
2827
use Symfony\Component\DependencyInjection\ContainerBuilder;
2928
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
@@ -48,6 +47,8 @@
4847
$loader->load('./src/services.php');
4948
} catch (Exception $exception) {
5049
echo sprintf('Error: %s at line %d at %s', $exception->getMessage(), $exception->getLine(), $exception->getFile());
50+
} catch(\Exception $e) {
51+
5152
}
5253

5354
$routes = include PMF_SRC_DIR . '/public-routes.php';
@@ -58,164 +59,3 @@
5859
} catch (Exception $exception) {
5960
echo sprintf('Error: %s at line %d at %s', $exception->getMessage(), $exception->getLine(), $exception->getFile());
6061
}
61-
62-
/*
63-
64-
if (!isset($user)) {
65-
// Try to authenticate with cookie information
66-
try {
67-
$user = CurrentUser::getCurrentUser($faqConfig);
68-
} catch (Exception $e) {
69-
$faqConfig->getLogger()->error('Failed to authenticate via cookie: ' . $e->getMessage());
70-
$user = new CurrentUser($faqConfig);
71-
}
72-
}
73-
74-
75-
76-
// Note: do not track internal calls
77-
$internal = false;
78-
79-
if ($request->headers->get('user-agent') !== null) {
80-
$internal = str_starts_with($request->headers->get('user-agent'), 'phpMyFAQ%2F');
81-
}
82-
83-
if (!$internal) {
84-
if (is_null($sidGet) && is_null($sidCookie)) {
85-
// Create a per-site unique SID
86-
$faqSession->userTracking('new_session', 0);
87-
} elseif (!is_null($sidCookie)) {
88-
$faqSession->checkSessionId($sidCookie, $request->getClientIp());
89-
} else {
90-
$faqSession->checkSessionId($sidGet, $request->getClientIp());
91-
}
92-
}
93-
94-
//
95-
// Is user tracking activated?
96-
//
97-
$sids = '';
98-
if ($faqConfig->get('main.enableUserTracking')) {
99-
if ($faqSession->getCurrentSessionId() > 0) {
100-
$faqSession->setCookie(UserSession::COOKIE_NAME_SESSION_ID, $faqSession->getCurrentSessionId());
101-
if (is_null($sidCookie)) {
102-
$sids = sprintf('sid=%d&lang=%s&', $faqSession->getCurrentSessionId(), $faqLangCode);
103-
}
104-
} elseif (is_null($sidGet) || is_null($sidCookie)) {
105-
if (is_null($sidCookie) && !is_null($sidGet)) {
106-
$sids = sprintf('sid=%d&lang=%s&', $sidGet, $faqLangCode);
107-
}
108-
}
109-
} else {
110-
$faqSession->setCookie(
111-
UserSession::COOKIE_NAME_SESSION_ID,
112-
$faqSession->getCurrentSessionId(),
113-
$request->server->get('REQUEST_TIME') + 3600,
114-
);
115-
$sids = sprintf('lang=%s&', $faqLangCode);
116-
}
117-
118-
//
119-
// Found a record ID?
120-
//
121-
$id = Filter::filterVar($request->query->get('id'), FILTER_VALIDATE_INT, 0);
122-
if ($id !== 0) {
123-
$faq->getFaq($id);
124-
125-
$seoEntity->setSeoType(SeoType::FAQ)->setReferenceId($id);
126-
$seoData = $seo->get($seoEntity);
127-
128-
$title = $seoData->getTitle();
129-
$metaDescription = str_replace('"', '', $seoData->getDescription() ?? '');
130-
$url = sprintf(
131-
'%sindex.php?%saction=faq&cat=%d&id=%d&artlang=%s',
132-
Strings::htmlentities($faqConfig->getDefaultUrl()),
133-
$sids,
134-
$category->getCategoryIdFromFaq($id),
135-
$id,
136-
$lang,
137-
);
138-
$faqLink = new Link($url, $faqConfig);
139-
$faqLink->setTitle($faq->faqRecord['title']);
140-
} else {
141-
$title = '';
142-
$metaDescription = str_replace('"', '', $faqConfig->get('seo.description'));
143-
}
144-
145-
//
146-
// found a solution ID?
147-
//
148-
$solutionId = Filter::filterVar($request->query->get('solution_id'), FILTER_VALIDATE_INT);
149-
if ($solutionId) {
150-
$faqData = $faq->getIdFromSolutionId($solutionId);
151-
$id = $faqData['id'];
152-
$lang = $faqData['lang'];
153-
154-
$seoEntity->setSeoType(SeoType::FAQ)->setReferenceId($id)->setReferenceLanguage($lang);
155-
$seoData = $seo->get($seoEntity);
156-
157-
$title = $seoData->getTitle();
158-
$metaDescription = str_replace('"', '', $seoData->getDescription());
159-
$url = sprintf(
160-
'%sindex.php?%saction=faq&cat=%d&id=%d&artlang=%s',
161-
Strings::htmlentities($faqConfig->getDefaultUrl()),
162-
$sids,
163-
$faqData['category_id'],
164-
$id,
165-
$lang,
166-
);
167-
$faqLink = new Link($url, $faqConfig);
168-
$faqLink->setTitle(Strings::htmlentities($faqData['question']));
169-
}
170-
171-
if (isset($cat) && $cat !== 0 && $id === 0 && $category->getCategoryName($cat) !== null) {
172-
$seoEntity->setSeoType(SeoType::CATEGORY)->setReferenceId($cat);
173-
$seoData = $seo->get($seoEntity);
174-
$title = $seoData->getTitle() ?? $category->getCategoryName($cat);
175-
$metaDescription = $seoData->getDescription() ?? $category->getCategoryDescription($cat);
176-
}
177-
178-
//
179-
// Handle 404 action with PageNotFoundController
180-
//
181-
if ('404' === $action) {
182-
$pageNotFoundController = new PageNotFoundController();
183-
$notFoundResponse = $pageNotFoundController->index($request);
184-
$notFoundResponse->send();
185-
exit();
186-
}
187-
188-
//
189-
// Check for 404 HTTP status code
190-
//
191-
if ($response->getStatusCode() === Response::HTTP_NOT_FOUND) {
192-
$response->setStatusCode(Response::HTTP_NOT_FOUND);
193-
}
194-
195-
$response->setCache([
196-
'must_revalidate' => false,
197-
'no_cache' => false,
198-
'no_store' => false,
199-
'no_transform' => false,
200-
'public' => true,
201-
'private' => false,
202-
'proxy_revalidate' => false,
203-
'max_age' => 600,
204-
's_maxage' => 600,
205-
'stale_if_error' => 86400,
206-
'stale_while_revalidate' => 60,
207-
'immutable' => true,
208-
'last_modified' => new DateTime(),
209-
]);
210-
211-
//
212-
// Avoid automatic downloads
213-
// and prevent browsers from interpreting files as a different MIME type than what is specified
214-
//
215-
if ($action !== 'attachment') {
216-
$response->headers->set('Content-Disposition', 'inline');
217-
}
218-
219-
$response->headers->set('X-Content-Type-Options', 'nosniff');
220-
221-
$response->send();

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

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

2020
namespace phpMyFAQ\Controller\Frontend;
2121

22+
use phpMyFAQ\Core\Exception;
2223
use phpMyFAQ\Date;
2324
use phpMyFAQ\Entity\SeoEntity;
2425
use phpMyFAQ\Enums\PermissionType;
@@ -38,14 +39,15 @@
3839
use Symfony\Component\HttpFoundation\Request;
3940
use Symfony\Component\HttpFoundation\Response;
4041
use Symfony\Component\Routing\Attribute\Route;
42+
use Twig\Error\LoaderError;
4143
use Twig\TwigFilter;
4244

4345
final class FaqController extends AbstractFrontController
4446
{
4547
/**
4648
* Displays the form to add a new FAQ
4749
*
48-
* @throws Exception
50+
* @throws Exception|LoaderError
4951
*/
5052
#[Route(path: '/add-faq.html', name: 'public.faq.add', methods: ['GET'])]
5153
public function add(Request $request): Response

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function index(Request $request): Response
8080
*
8181
* @throws \Exception
8282
*/
83-
#[Route(path: '/ask.html', name: 'public.question.ask', methods: ['GET'])]
83+
#[Route(path: '/add-question.html', name: 'public.question.ask', methods: ['GET'])]
8484
public function ask(Request $request): Response
8585
{
8686
$faqSession = $this->container->get('phpmyfaq.user.session');

phpmyfaq/src/public-routes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
'methods' => 'GET',
126126
],
127127
'public.question.ask' => [
128-
'path' => '/ask.html',
128+
'path' => '/add-question.html',
129129
'controller' => [QuestionsController::class, 'ask'],
130130
'methods' => 'GET',
131131
],

0 commit comments

Comments
 (0)