|
7 | 7 | * variables. That's all. |
8 | 8 | * |
9 | 9 | * 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 |
11 | 11 | * obtain one at https://mozilla.org/MPL/2.0/. |
12 | 12 | * |
13 | 13 | * @package phpMyFAQ |
|
23 | 23 |
|
24 | 24 | use phpMyFAQ\Application; |
25 | 25 | use phpMyFAQ\Core\Exception; |
26 | | -use phpMyFAQ\Link; |
27 | 26 | use Symfony\Component\Config\FileLocator; |
28 | 27 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
29 | 28 | use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; |
|
48 | 47 | $loader->load('./src/services.php'); |
49 | 48 | } catch (Exception $exception) { |
50 | 49 | echo sprintf('Error: %s at line %d at %s', $exception->getMessage(), $exception->getLine(), $exception->getFile()); |
| 50 | +} catch(\Exception $e) { |
| 51 | + |
51 | 52 | } |
52 | 53 |
|
53 | 54 | $routes = include PMF_SRC_DIR . '/public-routes.php'; |
|
58 | 59 | } catch (Exception $exception) { |
59 | 60 | echo sprintf('Error: %s at line %d at %s', $exception->getMessage(), $exception->getLine(), $exception->getFile()); |
60 | 61 | } |
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(); |
0 commit comments