This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /** |
||
4 | * This is the main public frontend page of phpMyFAQ. It detects the browser's |
||
5 | * language, gets and sets all cookie, post and get information and includes |
||
6 | * the templates we need and set all internal variables to the template |
||
7 | * variables. That's all. |
||
8 | * |
||
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 was not distributed with this file, You can |
||
11 | * obtain one at http://mozilla.org/MPL/2.0/. |
||
12 | * |
||
13 | * @package phpMyFAQ |
||
14 | * @author Thorsten Rinne <[email protected]> |
||
15 | * @author Lars Tiedemann <[email protected]> |
||
16 | * @author Matteo Scaramuccia <[email protected]> |
||
17 | * @copyright 2001-2019 phpMyFAQ Team |
||
18 | * @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 |
||
19 | * @link https://www.phpmyfaq.de |
||
20 | * @since 2001-02-12 |
||
21 | */ |
||
22 | |||
23 | use phpMyFAQ\Attachment\Factory; |
||
24 | use phpMyFAQ\Auth\Ldap as AuthLdap; |
||
25 | use phpMyFAQ\Auth\Sso as AuthSso; |
||
26 | use phpMyFAQ\Category; |
||
27 | use phpMyFAQ\Exception; |
||
0 ignored issues
–
show
|
|||
28 | use phpMyFAQ\Faq; |
||
29 | use phpMyFAQ\Filter; |
||
30 | use phpMyFAQ\Helper\FaqHelper as HelperFaq; |
||
31 | use phpMyFAQ\Helper\HttpHelper as HelperHttp; |
||
32 | use phpMyFAQ\Helper\CategoryHelper as HelperCategory; |
||
33 | use phpMyFAQ\Language; |
||
34 | use phpMyFAQ\Language\Plurals; |
||
35 | use phpMyFAQ\Link; |
||
36 | use phpMyFAQ\Services; |
||
37 | use phpMyFAQ\Session; |
||
38 | use phpMyFAQ\Seo; |
||
39 | use phpMyFAQ\Strings; |
||
40 | use phpMyFAQ\System; |
||
41 | use phpMyFAQ\Tags; |
||
42 | use phpMyFAQ\Template; |
||
43 | use phpMyFAQ\Template\TemplateHelper; |
||
44 | use phpMyFAQ\User\CurrentUser; |
||
45 | use phpMyFAQ\Utils; |
||
46 | |||
47 | // |
||
48 | // Define the named constant used as a check by any included PHP file |
||
49 | // |
||
50 | define('IS_VALID_PHPMYFAQ', null); |
||
51 | |||
52 | // |
||
53 | // Bootstrapping |
||
54 | // |
||
55 | require __DIR__.'/src/Bootstrap.php'; |
||
56 | |||
57 | // |
||
58 | // HTTP Helper |
||
59 | // |
||
60 | $http = new HelperHttp(); |
||
61 | |||
62 | // |
||
63 | // Get language (default: english) |
||
64 | // |
||
65 | $Language = new Language($faqConfig); |
||
66 | $LANGCODE = $Language->setLanguage($faqConfig->get('main.languageDetection'), $faqConfig->get('main.language')); |
||
67 | // Preload English strings |
||
68 | require_once 'lang/language_en.php'; |
||
69 | $faqConfig->setLanguage($Language); |
||
70 | |||
71 | $showCaptcha = Filter::filterInput(INPUT_GET, 'gen', FILTER_SANITIZE_STRING); |
||
72 | if (isset($LANGCODE) && Language::isASupportedLanguage($LANGCODE) && is_null($showCaptcha)) { |
||
73 | // Overwrite English strings with the ones we have in the current language, |
||
74 | // but don't include UTF-8 encoded files, these will break the captcha images |
||
75 | if (!file_exists('lang/language_'.$LANGCODE.'.php')) { |
||
76 | $LANGCODE = 'en'; |
||
77 | } |
||
78 | require_once 'lang/language_'.$LANGCODE.'.php'; |
||
79 | } else { |
||
80 | $LANGCODE = 'en'; |
||
81 | } |
||
82 | |||
83 | //Load plurals support for selected language |
||
84 | $plr = new Plurals($PMF_LANG); |
||
85 | |||
86 | // |
||
87 | // Initializing static string wrapper |
||
88 | // |
||
89 | Strings::init($LANGCODE); |
||
90 | |||
91 | /* |
||
92 | * Initialize attachment factory |
||
93 | */ |
||
94 | Factory::init( |
||
95 | $faqConfig->get('records.attachmentsStorageType'), |
||
96 | $faqConfig->get('records.defaultAttachmentEncKey'), |
||
97 | $faqConfig->get('records.enableAttachmentEncryption') |
||
98 | ); |
||
99 | |||
100 | // |
||
101 | // Get user action |
||
102 | // |
||
103 | $action = Filter::filterInput(INPUT_GET, 'action', FILTER_SANITIZE_STRING, 'main'); |
||
104 | |||
105 | // |
||
106 | // Authenticate current user |
||
107 | // |
||
108 | $auth = $error = null; |
||
109 | $loginVisibility = 'hidden'; |
||
110 | |||
111 | $faqusername = Filter::filterInput(INPUT_POST, 'faqusername', FILTER_SANITIZE_STRING); |
||
112 | $faqpassword = Filter::filterInput(INPUT_POST, 'faqpassword', FILTER_SANITIZE_STRING); |
||
113 | $faqaction = Filter::filterInput(INPUT_POST, 'faqloginaction', FILTER_SANITIZE_STRING); |
||
114 | $faqremember = Filter::filterInput(INPUT_POST, 'faqrememberme', FILTER_SANITIZE_STRING); |
||
115 | |||
116 | // Set username via SSO |
||
117 | View Code Duplication | if ($faqConfig->get('security.ssoSupport') && isset($_SERVER['REMOTE_USER'])) { |
|
118 | $faqusername = trim($_SERVER['REMOTE_USER']); |
||
119 | $faqpassword = ''; |
||
120 | } |
||
121 | |||
122 | // Login via local DB or LDAP or SSO |
||
123 | if (!is_null($faqusername) && !is_null($faqpassword)) { |
||
124 | $user = new CurrentUser($faqConfig); |
||
125 | if (!is_null($faqremember) && 'rememberMe' === $faqremember) { |
||
126 | $user->enableRememberMe(); |
||
127 | } |
||
128 | View Code Duplication | if ($faqConfig->get('ldap.ldapSupport') && function_exists('ldap_connect')) { |
|
129 | try { |
||
130 | $authLdap = new AuthLdap($faqConfig); |
||
131 | $user->addAuth($authLdap, 'ldap'); |
||
132 | } catch (Exception $e) { |
||
133 | $error = $e->getMessage().'<br>'; |
||
134 | } |
||
135 | } |
||
136 | if ($faqConfig->get('security.ssoSupport')) { |
||
137 | $authSso = new AuthSso($faqConfig); |
||
138 | $user->addAuth($authSso, 'sso'); |
||
139 | } |
||
140 | if ($user->login($faqusername, $faqpassword)) { |
||
141 | if ($user->getStatus() != 'blocked') { |
||
142 | $auth = true; |
||
143 | if (empty($action)) { |
||
144 | $action = $faqaction; // SSO logins don't have $faqaction |
||
145 | } |
||
146 | } else { |
||
147 | $error = $error.$PMF_LANG['ad_auth_fail'].' ('.$faqusername.')'; |
||
148 | $loginVisibility = ''; |
||
149 | $action = 'password' === $action ? 'password' : 'login'; |
||
150 | } |
||
151 | } else { |
||
152 | // error |
||
153 | $error = $error.$PMF_LANG['ad_auth_fail']; |
||
154 | $loginVisibility = ''; |
||
155 | $action = 'password' === $action ? 'password' : 'login'; |
||
156 | } |
||
157 | View Code Duplication | } else { |
|
158 | // Try to authenticate with cookie information |
||
159 | $user = CurrentUser::getFromCookie($faqConfig); |
||
160 | |||
161 | // authenticate with session information |
||
162 | if (!$user instanceof CurrentUser) { |
||
163 | $user = CurrentUser::getFromSession($faqConfig); |
||
164 | } |
||
165 | |||
166 | if ($user instanceof CurrentUser) { |
||
167 | $auth = true; |
||
168 | } else { |
||
169 | $user = new CurrentUser($faqConfig); |
||
170 | } |
||
171 | } |
||
172 | |||
173 | // |
||
174 | // Logout |
||
175 | // |
||
176 | if ('logout' === $action && isset($auth)) { |
||
177 | $user->deleteFromSession(true); |
||
178 | $auth = null; |
||
179 | $action = 'main'; |
||
180 | $ssoLogout = $faqConfig->get('security.ssoLogoutRedirect'); |
||
181 | if ($faqConfig->get('security.ssoSupport') && !empty($ssoLogout)) { |
||
182 | header('Location: '.$ssoLogout); |
||
183 | } else { |
||
184 | header('Location: '.$faqConfig->getDefaultUrl()); |
||
185 | } |
||
186 | } |
||
187 | |||
188 | // |
||
189 | // Get current user and group id - default: -1 |
||
190 | // |
||
191 | View Code Duplication | if (!is_null($user) && $user instanceof CurrentUser) { |
|
192 | $current_user = $user->getUserId(); |
||
193 | if ($user->perm instanceof Medium) { |
||
0 ignored issues
–
show
The class
Medium does not exist. Did you forget a USE statement, or did you not list all dependencies?
This error could be the result of: 1. Missing dependenciesPHP Analyzer uses your Are you sure this class is defined by one of your dependencies, or did you maybe
not list a dependency in either the 2. Missing use statementPHP does not complain about undefined classes in if ($x instanceof DoesNotExist) {
// Do something.
}
If you have not tested against this specific condition, such errors might go unnoticed. ![]() |
|||
194 | $current_groups = $user->perm->getUserGroups($current_user); |
||
195 | } else { |
||
196 | $current_groups = [-1]; |
||
197 | } |
||
198 | if (0 == count($current_groups)) { |
||
199 | $current_groups = [-1]; |
||
200 | } |
||
201 | } else { |
||
202 | $current_user = -1; |
||
203 | $current_groups = [-1]; |
||
204 | } |
||
205 | |||
206 | // |
||
207 | // Use mbstring extension if available and when possible |
||
208 | // |
||
209 | $validMbStrings = ['ja', 'en', 'uni']; |
||
210 | $mbLanguage = ($PMF_LANG['metaLanguage'] != 'ja') ? 'uni' : $PMF_LANG['metaLanguage']; |
||
211 | if (function_exists('mb_language') && in_array($mbLanguage, $validMbStrings)) { |
||
212 | mb_language($mbLanguage); |
||
213 | mb_internal_encoding('utf-8'); |
||
214 | } |
||
215 | |||
216 | // |
||
217 | // Found a session ID in _GET or _COOKIE? |
||
218 | // |
||
219 | $sessionId = null; |
||
220 | $sidGet = Filter::filterInput(INPUT_GET, PMF_GET_KEY_NAME_SESSIONID, FILTER_VALIDATE_INT); |
||
221 | $sidCookie = Filter::filterInput(INPUT_COOKIE, Session::PMF_COOKIE_NAME_SESSIONID, FILTER_VALIDATE_INT); |
||
222 | $faqSession = new Session($faqConfig); |
||
223 | // Note: do not track internal calls |
||
224 | $internal = false; |
||
225 | if (isset($_SERVER['HTTP_USER_AGENT'])) { |
||
226 | $internal = (strpos($_SERVER['HTTP_USER_AGENT'], 'phpMyFAQ%2F') === 0); |
||
227 | } |
||
228 | if (!$internal) { |
||
229 | if (is_null($sidGet) && is_null($sidCookie)) { |
||
230 | // Create a per-site unique SID |
||
231 | try { |
||
232 | $faqSession->userTracking('new_session', 0); |
||
233 | } catch (Exception $e) { |
||
234 | $pmfExceptions[] = $e->getMessage(); |
||
235 | } |
||
236 | } else { |
||
237 | try { |
||
238 | if (!is_null($sidCookie)) { |
||
239 | $faqSession->checkSessionId($sidCookie, $_SERVER['REMOTE_ADDR']); |
||
240 | } else { |
||
241 | $faqSession->checkSessionId($sidGet, $_SERVER['REMOTE_ADDR']); |
||
242 | } |
||
243 | } catch (Exception $e) { |
||
244 | $pmfExceptions[] = $e->getMessage(); |
||
245 | } |
||
246 | } |
||
247 | } |
||
248 | |||
249 | // |
||
250 | // Is user tracking activated? |
||
251 | // |
||
252 | $sids = ''; |
||
253 | if ($faqConfig->get('main.enableUserTracking')) { |
||
254 | if (isset($sessionId)) { |
||
255 | $faqSession->setCookie(Session::PMF_COOKIE_NAME_SESSIONID, $sessionId); |
||
256 | if (is_null($sidCookie)) { |
||
257 | $sids = sprintf('sid=%d&lang=%s&', $sessionId, $LANGCODE); |
||
258 | } |
||
259 | } elseif (is_null($sidGet) || is_null($sidCookie)) { |
||
260 | if (is_null($sidCookie)) { |
||
261 | if (!is_null($sidGet)) { |
||
262 | $sids = sprintf('sid=%d&lang=%s&', $sidGet, $LANGCODE); |
||
263 | } |
||
264 | } |
||
265 | } |
||
266 | } else { |
||
267 | if (!$faqSession->setCookie(Session::PMF_COOKIE_NAME_SESSIONID, $sessionId, $_SERVER['REQUEST_TIME'] + Language_EXPIRED_TIME)) { |
||
268 | $sids = sprintf('lang=%s&', $LANGCODE); |
||
269 | } |
||
270 | } |
||
271 | |||
272 | // |
||
273 | // Found a article language? |
||
274 | // |
||
275 | $lang = Filter::filterInput(INPUT_POST, 'artlang', FILTER_SANITIZE_STRING); |
||
276 | View Code Duplication | if (is_null($lang) && !Language::isASupportedLanguage($lang)) { |
|
277 | $lang = Filter::filterInput(INPUT_GET, 'artlang', FILTER_SANITIZE_STRING); |
||
278 | if (is_null($lang) && !Language::isASupportedLanguage($lang)) { |
||
279 | $lang = $LANGCODE; |
||
280 | } |
||
281 | } |
||
282 | |||
283 | // |
||
284 | // Found a search string? |
||
285 | // |
||
286 | $searchTerm = Filter::filterInput(INPUT_GET, 'search', FILTER_SANITIZE_STRIPPED); |
||
287 | |||
288 | // |
||
289 | // Create a new FAQ object |
||
290 | // |
||
291 | $faq = new Faq($faqConfig); |
||
292 | $faq->setUser($current_user); |
||
293 | $faq->setGroups($current_groups); |
||
294 | |||
295 | // |
||
296 | // Create a new Category object |
||
297 | // |
||
298 | $category = new Category($faqConfig, $current_groups, true); |
||
299 | $category->setUser($current_user); |
||
300 | $category->setGroups($current_groups); |
||
301 | |||
302 | // |
||
303 | // Create a new Tags object |
||
304 | // |
||
305 | $oTag = new Tags($faqConfig); |
||
306 | |||
307 | // |
||
308 | // Create URL |
||
309 | // |
||
310 | $faqSystem = new System(); |
||
311 | $faqLink = new Link($faqSystem->getSystemUri($faqConfig), $faqConfig); |
||
312 | $currentPageUrl = $faqLink->getCurrentUrl(); |
||
313 | |||
314 | // |
||
315 | // Found a record ID? |
||
316 | // |
||
317 | $id = Filter::filterInput(INPUT_GET, 'id', FILTER_VALIDATE_INT); |
||
318 | if (!is_null($id)) { |
||
319 | $faq->getRecord($id); |
||
320 | $title = ' - '.$faq->faqRecord['title']; |
||
321 | $keywords = ','.$faq->faqRecord['keywords']; |
||
322 | $metaDescription = str_replace('"', '', strip_tags($faq->getRecordPreview($id))); |
||
323 | $url = sprintf( |
||
324 | '%sindex.php?%saction=faq&cat=%d&id=%d&artlang=%s', |
||
325 | $faqConfig->getDefaultUrl(), |
||
326 | $sids, |
||
327 | $category->getCategoryIdFromFaq($id), |
||
328 | $id, |
||
329 | $lang |
||
330 | ); |
||
331 | $faqLink = new Link($url, $faqConfig); |
||
332 | $faqLink->itemTitle = $faq->faqRecord['title']; |
||
333 | $currentPageUrl = $faqLink->toString(true); |
||
334 | } else { |
||
335 | $id = ''; |
||
336 | $title = ' - powered by phpMyFAQ '.$faqConfig->get('main.currentVersion'); |
||
337 | $keywords = ''; |
||
338 | $metaDescription = str_replace('"', '', $faqConfig->get('main.metaDescription')); |
||
339 | } |
||
340 | |||
341 | // |
||
342 | // found a solution ID? |
||
343 | // |
||
344 | $solutionId = Filter::filterInput(INPUT_GET, 'solution_id', FILTER_VALIDATE_INT); |
||
345 | if (!is_null($solutionId)) { |
||
346 | $title = ' - powered by phpMyFAQ '.$faqConfig->get('main.currentVersion'); |
||
347 | $keywords = ''; |
||
348 | $faqData = $faq->getIdFromSolutionId($solutionId); |
||
349 | if (is_array($faqData)) { |
||
350 | $id = $faqData['id']; |
||
351 | $lang = $faqData['lang']; |
||
352 | $title = ' - '.$faq->getRecordTitle($id); |
||
353 | $keywords = ','.$faq->getRecordKeywords($id); |
||
354 | $metaDescription = str_replace('"', '', Utils::makeShorterText(strip_tags($faqData['content']), 12)); |
||
355 | $url = sprintf( |
||
356 | '%sindex.php?%saction=faq&cat=%d&id=%d&artlang=%s', |
||
357 | $faqConfig->getDefaultUrl(), |
||
358 | $sids, |
||
359 | $faqData['category_id'], |
||
360 | $id, |
||
361 | $lang |
||
362 | ); |
||
363 | $faqLink = new Link($url, $faqConfig); |
||
364 | $faqLink->itemTitle = $faqData['question']; |
||
365 | $currentPageUrl = $faqLink->toString(true); |
||
366 | } |
||
367 | } |
||
368 | |||
369 | // |
||
370 | // Handle the Tagging ID |
||
371 | // |
||
372 | $tag_id = Filter::filterInput(INPUT_GET, 'tagging_id', FILTER_VALIDATE_INT); |
||
373 | if (!is_null($tag_id)) { |
||
374 | $title = ' - '.$oTag->getTagNameById($tag_id); |
||
375 | $keywords = ''; |
||
376 | } |
||
377 | |||
378 | // |
||
379 | // Handle the SiteMap |
||
380 | // |
||
381 | $letter = Filter::filterInput(INPUT_GET, 'letter', FILTER_SANITIZE_STRIPPED); |
||
382 | if (!is_null($letter) && (1 == Strings::strlen($letter))) { |
||
383 | $title = ' - '.$letter.'...'; |
||
384 | $keywords = $letter; |
||
385 | } |
||
386 | |||
387 | // |
||
388 | // Found a category ID? |
||
389 | // |
||
390 | $cat = Filter::filterInput(INPUT_GET, 'cat', FILTER_VALIDATE_INT, 0); |
||
391 | $categoryFromId = -1; |
||
392 | if (is_numeric($id) && $id > 0) { |
||
393 | $categoryFromId = $category->getCategoryIdFromFaq($id); |
||
394 | } |
||
395 | if ($categoryFromId != -1 && $cat == 0) { |
||
396 | $cat = $categoryFromId; |
||
397 | } |
||
398 | $category->transform(0); |
||
399 | $category->collapseAll(); |
||
400 | if ($cat != 0) { |
||
401 | $category->expandTo($cat); |
||
402 | } |
||
403 | if (isset($cat) && ($cat != 0) && ($id == '') && isset($category->categoryName[$cat]['name'])) { |
||
404 | $title = ' - '.$category->categoryName[$cat]['name']; |
||
405 | $metaDescription = $category->categoryName[$cat]['description']; |
||
406 | } |
||
407 | |||
408 | // |
||
409 | // Found an action request? |
||
410 | // |
||
411 | if (!isset($allowedVariables[$action])) { |
||
412 | $action = 'main'; |
||
413 | } |
||
414 | |||
415 | // |
||
416 | // Select the template for the requested page |
||
417 | // |
||
418 | if ($action !== 'main') { |
||
419 | $includeTemplate = $action.'.html'; |
||
420 | $includePhp = $action.'.php'; |
||
421 | $renderUri = '?sid='.$sessionId; |
||
422 | } else { |
||
423 | if (isset($solutionId) && is_numeric($solutionId)) { |
||
424 | // show the record with the solution ID |
||
425 | $includeTemplate = 'faq.html'; |
||
426 | $includePhp = 'faq.php'; |
||
427 | } else { |
||
428 | $includeTemplate = 'startpage.html'; |
||
429 | $includePhp = 'startpage.php'; |
||
430 | } |
||
431 | $renderUri = '?sid='.$sessionId; |
||
432 | } |
||
433 | |||
434 | // |
||
435 | // Set right column |
||
436 | // |
||
437 | if (($action === 'faq') || ($action === 'show')) { |
||
438 | $sidebarTemplate = $action === 'faq' ? 'sidebar-categories-tags.html' : 'sidebar-tagcloud.html'; |
||
439 | } else { |
||
440 | $sidebarTemplate = 'sidebar-categories-tags.html'; |
||
441 | } |
||
442 | |||
443 | // |
||
444 | // Check if FAQ should be secured |
||
445 | // |
||
446 | if ($faqConfig->get('security.enableLoginOnly')) { |
||
447 | if ($auth) { |
||
448 | $indexSet = 'index.html'; |
||
449 | } else { |
||
450 | switch ($action) { |
||
451 | case 'register': |
||
452 | case 'thankyou': |
||
453 | $indexSet = 'indexNewUser.html'; |
||
454 | break; |
||
455 | case 'password': |
||
456 | $indexSet = 'indexPassword.html'; |
||
457 | break; |
||
458 | default: |
||
459 | $indexSet = 'indexLogin.html'; |
||
460 | break; |
||
461 | } |
||
462 | } |
||
463 | } else { |
||
464 | $indexSet = 'index.html'; |
||
465 | } |
||
466 | |||
467 | // |
||
468 | // phpMyFAQ installation is in maintenance mode |
||
469 | // |
||
470 | if ($faqConfig->get('main.maintenanceMode')) { |
||
471 | $indexSet = 'indexMaintenance.html'; |
||
472 | } |
||
473 | |||
474 | // |
||
475 | // Load template files and set template variables |
||
476 | // |
||
477 | $template = new Template( |
||
478 | [ |
||
479 | 'index' => $indexSet, |
||
480 | 'sidebar' => $sidebarTemplate, |
||
481 | 'writeContent' => $includeTemplate, |
||
482 | ], |
||
483 | new TemplateHelper($faqConfig), |
||
484 | $faqConfig->get('main.templateSet') |
||
485 | ); |
||
486 | |||
487 | $categoryHelper = new HelperCategory(); |
||
488 | $categoryHelper->setCategory($category); |
||
489 | $categoryHelper->setConfiguration($faqConfig); |
||
490 | |||
491 | $keywordsArray = array_merge(explode(',', $keywords), explode(',', $faqConfig->get('main.metaKeywords'))); |
||
492 | $keywordsArray = array_filter($keywordsArray, 'strlen'); |
||
493 | shuffle($keywordsArray); |
||
494 | $keywords = implode(',', $keywordsArray); |
||
495 | |||
496 | if (!is_null($error)) { |
||
497 | $loginMessage = '<p class="error">'.$error.'</p>'; |
||
498 | } else { |
||
499 | $loginMessage = ''; |
||
500 | } |
||
501 | |||
502 | $faqSeo = new Seo($faqConfig); |
||
503 | |||
504 | $tplMainPage = [ |
||
505 | 'msgLoginUser' => $user->isLoggedIn() ? $user->getUserData('display_name') : $PMF_LANG['msgLoginUser'], |
||
506 | 'title' => Strings::htmlspecialchars($faqConfig->get('main.titleFAQ').$title), |
||
507 | 'baseHref' => $faqSystem->getSystemUri($faqConfig), |
||
508 | 'version' => $faqConfig->get('main.currentVersion'), |
||
509 | 'header' => Strings::htmlspecialchars(str_replace('"', '', $faqConfig->get('main.titleFAQ'))), |
||
510 | 'metaTitle' => Strings::htmlspecialchars(str_replace('"', '', $faqConfig->get('main.titleFAQ').$title)), |
||
511 | 'metaDescription' => Strings::htmlspecialchars($metaDescription), |
||
512 | 'metaKeywords' => Strings::htmlspecialchars($keywords), |
||
513 | 'metaPublisher' => $faqConfig->get('main.metaPublisher'), |
||
514 | 'metaLanguage' => $PMF_LANG['metaLanguage'], |
||
515 | 'metaRobots' => $faqSeo->getMetaRobots($action), |
||
516 | 'phpmyfaqversion' => $faqConfig->get('main.currentVersion'), |
||
517 | 'stylesheet' => $PMF_LANG['dir'] == 'rtl' ? 'style.rtl' : 'style', |
||
518 | 'currentPageUrl' => $currentPageUrl, |
||
519 | 'action' => $action, |
||
520 | 'dir' => $PMF_LANG['dir'], |
||
521 | 'writeSendAdress' => '?'.$sids.'action=search', |
||
522 | 'searchBox' => $PMF_LANG['msgSearch'], |
||
523 | 'searchTerm' => $searchTerm, |
||
524 | 'categoryId' => ($cat === 0) ? '%' : (int)$cat, |
||
525 | 'headerCategories' => $PMF_LANG['msgFullCategories'], |
||
526 | 'msgCategory' => $PMF_LANG['msgCategory'], |
||
527 | 'showCategories' => $categoryHelper->renderNavigation($cat), |
||
528 | 'topCategories' => $categoryHelper->renderMainCategories(), |
||
529 | 'msgExportAllFaqs' => $PMF_LANG['msgExportAllFaqs'], |
||
530 | 'languageBox' => $PMF_LANG['msgLanguageSubmit'], |
||
531 | 'renderUri' => $renderUri, |
||
532 | 'switchLanguages' => Language::selectLanguages($LANGCODE, true), |
||
533 | // 'stickyRecordsHeader' => $PMF_LANG['stickyRecordsHeader'], |
||
534 | 'copyright' => 'powered by <a href="https://www.phpmyfaq.de" target="_blank">phpMyFAQ</a> '. |
||
535 | $faqConfig->get('main.currentVersion'), |
||
536 | 'registerUser' => $faqConfig->get('security.enableRegistration') ? '<a href="?action=register">'.$PMF_LANG['msgRegistration'].'</a>' : '', |
||
537 | 'sendPassword' => '<a href="?action=password">'.$PMF_LANG['lostPassword'].'</a>', |
||
538 | 'msgFullName' => $PMF_LANG['ad_user_loggedin'].$user->getLogin(), |
||
539 | 'msgLoginName' => $user->getUserData('display_name'), |
||
540 | 'loginHeader' => $PMF_LANG['msgLoginUser'], |
||
541 | 'loginMessage' => $loginMessage, |
||
542 | 'writeLoginPath' => $faqSystem->getSystemUri($faqConfig).'?'.Filter::getFilteredQueryString(), |
||
543 | 'faqloginaction' => $action, |
||
544 | 'login' => $PMF_LANG['ad_auth_ok'], |
||
545 | 'username' => $PMF_LANG['ad_auth_user'], |
||
546 | 'password' => $PMF_LANG['ad_auth_passwd'], |
||
547 | 'rememberMe' => $PMF_LANG['rememberMe'], |
||
548 | 'headerChangePassword' => $PMF_LANG['ad_passwd_cop'], |
||
549 | 'msgUsername' => $PMF_LANG['ad_auth_user'], |
||
550 | 'msgEmail' => $PMF_LANG['ad_entry_email'], |
||
551 | 'msgSubmit' => $PMF_LANG['msgNewContentSubmit'], |
||
552 | ]; |
||
553 | |||
554 | $template->parseBlock( |
||
555 | 'index', |
||
556 | 'categoryListSection', |
||
557 | [ |
||
558 | 'showCategories' => $categoryHelper->renderNavigation($cat), |
||
559 | 'categoryDropDown' => $categoryHelper->renderCategoryDropDown(), |
||
560 | ] |
||
561 | ); |
||
562 | |||
563 | if ('main' == $action || 'show' == $action) { |
||
564 | $template->parseBlock( |
||
565 | 'index', |
||
566 | 'globalSearchBox', |
||
567 | [ |
||
568 | 'writeSendAdress' => '?'.$sids.'action=search', |
||
569 | 'searchBox' => $PMF_LANG['msgSearch'], |
||
570 | 'categoryId' => ($cat === 0) ? '%' : (int)$cat, |
||
571 | 'msgSearch' => sprintf( |
||
572 | '<a class="help" href="%sindex.php?action=search">%s</a>', |
||
573 | $faqSystem->getSystemUri($faqConfig), |
||
574 | $PMF_LANG['msgAdvancedSearch'] |
||
575 | ), |
||
576 | ] |
||
577 | ); |
||
578 | } |
||
579 | |||
580 | if ($faqConfig->get('main.enableRewriteRules')) { |
||
581 | $tplNavigation = [ |
||
582 | 'msgSearch' => '<a class="nav-link" href="./search.html">'.$PMF_LANG['msgAdvancedSearch'].'</a>', |
||
583 | 'msgAddContent' => '<a class="nav-link" href="'.$faqSystem->getSystemUri($faqConfig).'addcontent.html">'.$PMF_LANG['msgAddContent'].'</a>', |
||
584 | 'msgQuestion' => '<a class="nav-link" href="./ask.html">'.$PMF_LANG['msgQuestion'].'</a>', |
||
585 | 'msgOpenQuestions' => '<a class="nav-link" href="./open.html">'.$PMF_LANG['msgOpenQuestions'].'</a>', |
||
586 | 'msgContact' => '<a href="./contact.html">'.$PMF_LANG['msgContact'].'</a>', |
||
587 | 'msgGlossary' => '<a href="./glossary.html">'.$PMF_LANG['ad_menu_glossary'].'</a>', |
||
588 | 'backToHome' => '<a href="./index.html">'.$PMF_LANG['msgHome'].'</a>', |
||
589 | 'allCategories' => '<a class="nav-link" href="./showcat.html">'.$PMF_LANG['msgShowAllCategories'].'</a>', |
||
590 | 'faqOverview' => '<a href="./overview.html">'.$PMF_LANG['faqOverview'].'</a>', |
||
591 | 'showSitemap' => '<a href="./sitemap/A/'.$LANGCODE.'.html">'.$PMF_LANG['msgSitemap'].'</a>', |
||
592 | 'opensearch' => './opensearch.xml', |
||
593 | 'msgUserRemoval' => '<a href="./request-removal.html">'.$PMF_LANG['msgUserRemoval'].'</a>' |
||
594 | ]; |
||
595 | } else { |
||
596 | $tplNavigation = [ |
||
597 | 'msgSearch' => '<a class="nav-link" href="index.php?'.$sids.'action=search">'.$PMF_LANG['msgAdvancedSearch'].'</a>', |
||
598 | 'msgAddContent' => '<a class="nav-link" href="index.php?'.$sids.'action=add&cat='.$cat.'">'.$PMF_LANG['msgAddContent'].'</a>', |
||
599 | 'msgQuestion' => '<a class="nav-link" href="index.php?'.$sids.'action=ask&category_id='.$cat.'">'.$PMF_LANG['msgQuestion'].'</a>', |
||
600 | 'msgOpenQuestions' => '<a class="nav-link" href="index.php?'.$sids.'action=open">'.$PMF_LANG['msgOpenQuestions'].'</a>', |
||
601 | 'msgContact' => '<a href="index.php?'.$sids.'action=contact">'.$PMF_LANG['msgContact'].'</a>', |
||
602 | 'msgGlossary' => '<a href="index.php?'.$sids.'action=glossary">'.$PMF_LANG['ad_menu_glossary'].'</a>', |
||
603 | 'allCategories' => '<a class="nav-link" href="index.php?'.$sids.'action=show">'.$PMF_LANG['msgShowAllCategories'].'</a>', |
||
604 | 'faqOverview' => '<a href="index.php?'.$sids.'action=overview">'.$PMF_LANG['faqOverview'].'</a>', |
||
605 | 'backToHome' => '<a href="index.php?'.$sids.'">'.$PMF_LANG['msgHome'].'</a>', |
||
606 | 'showSitemap' => '<a href="index.php?'.$sids.'action=sitemap&lang='.$LANGCODE.'">'.$PMF_LANG['msgSitemap'].'</a>', |
||
607 | 'opensearch' => $faqSystem->getSystemUri($faqConfig).'opensearch.php', |
||
608 | 'msgUserRemoval' => '<a href="index.php?'.$sids.'action=request-removal">'.$PMF_LANG['msgUserRemoval'].'</a>', |
||
609 | ]; |
||
610 | } |
||
611 | |||
612 | $tplNavigation['faqHome'] = $faqConfig->getDefaultUrl(); |
||
613 | $tplNavigation['activeSearch'] = ('search' == $action) ? 'active' : ''; |
||
614 | $tplNavigation['activeAllCategories'] = ('show' == $action) ? 'active' : ''; |
||
615 | $tplNavigation['activeAddContent'] = ('add' == $action) ? 'active' : ''; |
||
616 | $tplNavigation['activeAddQuestion'] = ('ask' == $action) ? 'active' : ''; |
||
617 | $tplNavigation['activeOpenQuestions'] = ('open' == $action) ? 'active' : ''; |
||
618 | $tplNavigation['activeLogin'] = ('login' == $action) ? 'active' : ''; |
||
619 | |||
620 | // |
||
621 | // Show login box or logged-in user information |
||
622 | // |
||
623 | if (isset($auth)) { |
||
624 | if ($user->perm->checkRight($user->getUserId(), 'viewadminlink') || $user->isSuperAdmin()) { |
||
625 | $adminSection = sprintf( |
||
626 | '<a class="dropdown-item" href="%s">%s</a>', |
||
627 | $faqSystem->getSystemUri($faqConfig).'admin/index.php', |
||
628 | $PMF_LANG['adminSection'] |
||
629 | ); |
||
630 | } else { |
||
631 | $adminSection = ''; |
||
632 | } |
||
633 | |||
634 | if ($faqConfig->get('ldap.ldapSupport')) { |
||
635 | $userControlDropdown = ''; |
||
636 | } else { |
||
637 | $userControlDropdown = '<a class="dropdown-item" href="?action=ucp">'.$PMF_LANG['headerUserControlPanel'].'</a>'; |
||
638 | } |
||
639 | |||
640 | $template->parseBlock( |
||
641 | 'index', |
||
642 | 'userloggedIn', |
||
643 | [ |
||
644 | 'msgUserControl' => $adminSection, |
||
645 | 'msgLoginName' => $user->getUserData('display_name'), // @deprecated |
||
646 | 'msgUserControlDropDown' => $userControlDropdown, |
||
647 | 'msgUserRemoval' => '<a class="dropdown-item" href="?action=request-removal">'.$PMF_LANG['ad_menu_RequestRemove'].'</a>', |
||
648 | 'msgLogoutUser' => '<a class="dropdown-item" href="?action=logout">'.$PMF_LANG['ad_menu_logout'].'</a>', |
||
649 | 'activeUserControl' => ('ucp' == $action) ? 'active' : '' |
||
650 | ] |
||
651 | ); |
||
652 | } else { |
||
653 | if ($faqConfig->get('main.maintenanceMode')) { |
||
654 | $msgLoginUser = '<a class="dropdown-item" href="./admin/">%s</a>'; |
||
655 | } else { |
||
656 | $msgLoginUser = '<a class="dropdown-item" href="?action=login">%s</a>'; |
||
657 | } |
||
658 | $template->parseBlock( |
||
659 | 'index', |
||
660 | 'notLoggedIn', |
||
661 | array( |
||
662 | 'msgRegisterUser' => $faqConfig->get('security.enableRegistration') ? '<a class="dropdown-item" href="?action=register">'.$PMF_LANG['msgRegisterUser'].'</a>' : '', |
||
663 | 'msgLoginUser' => sprintf($msgLoginUser, $PMF_LANG['msgLoginUser']), |
||
664 | 'activeRegister' => ('register' == $action) ? 'active' : '', |
||
665 | 'activeLogin' => ('login' == $action) ? 'active' : '', |
||
666 | ) |
||
667 | ); |
||
668 | } |
||
669 | |||
670 | if ('faq' == $action || 'show' == $action || is_numeric($solutionId)) { |
||
671 | |||
672 | // We need some Links from social networks |
||
673 | $faqServices = new Services($faqConfig); |
||
674 | $faqServices->setCategoryId($cat); |
||
675 | $faqServices->setFaqId($id); |
||
676 | $faqServices->setLanguage($lang); |
||
677 | $faqServices->setQuestion($faq->getRecordTitle($id)); |
||
678 | |||
679 | $faqHelper = new HelperFaq($faqConfig); |
||
680 | $faqHelper->setSsl((isset($_SERVER['HTTPS']) && is_null($_SERVER['HTTPS']) ? false : true)); |
||
681 | |||
682 | $template->parseBlock( |
||
683 | 'index', |
||
684 | 'socialLinks', |
||
685 | [ |
||
686 | 'baseHref' => $faqSystem->getSystemUri($faqConfig), |
||
687 | 'writePDFTag' => $PMF_LANG['msgPDF'], |
||
688 | 'writePrintMsgTag' => $PMF_LANG['msgPrintArticle'], |
||
689 | 'sendToFriend' => $faqHelper->renderSendToFriend($faqServices->getSuggestLink()), |
||
690 | 'shareOnFacebook' => $faqHelper->renderFacebookShareLink($faqServices->getShareOnFacebookLink()), |
||
691 | 'shareOnTwitter' => $faqHelper->renderTwitterShareLink($faqServices->getShareOnTwitterLink()), |
||
692 | 'link_pdf' => $faqServices->getPdfLink(), |
||
693 | 'facebookLikeButton' => $faqHelper->renderFacebookLikeButton($faqServices->getLink()) |
||
694 | ] |
||
695 | ); |
||
696 | } |
||
697 | |||
698 | if ($faqConfig->get('main.enableRssFeeds')) { |
||
699 | $rssFeedTopTen = '<a href="feed/topten/rss.php" target="_blank"><i class="fas fa-rss-square"></i></a>'; |
||
700 | $rssFeedLatest = '<a href="feed/latest/rss.php" target="_blank"><i class="fas fa-rss-square"></i></a>'; |
||
701 | } else { |
||
702 | $rssFeedTopTen = ''; |
||
703 | $rssFeedLatest = ''; |
||
704 | } |
||
705 | |||
706 | $tplHeaders = [ |
||
707 | 'writeTopTenHeader' => $PMF_LANG['msgTopTen'], |
||
708 | 'rssFeedTopTen' => $rssFeedTopTen, |
||
709 | 'writeNewestHeader' => $PMF_LANG['msgLatestArticles'], |
||
710 | 'rssFeedLatest' => $rssFeedLatest, |
||
711 | 'writeTagCloudHeader' => $PMF_LANG['msg_tags'], |
||
712 | 'writeTags' => $oTag->printHTMLTagsCloud(), |
||
713 | 'msgAllCatArticles' => $PMF_LANG['msgAllCatArticles'], |
||
714 | 'allCatArticles' => $faq->getRecordsWithoutPagingByCategoryId($cat) |
||
715 | ]; |
||
716 | |||
717 | if (DEBUG) { |
||
718 | $template->parseBlock( |
||
719 | 'index', |
||
720 | 'debugMode', |
||
721 | array( |
||
722 | 'debugExceptions' => implode('<br>', $pmfExceptions), |
||
723 | 'debugQueries' => $faqConfig->getDb()->log(), |
||
724 | ) |
||
725 | ); |
||
726 | } |
||
727 | |||
728 | // |
||
729 | // Include requested PHP file |
||
730 | // |
||
731 | require $includePhp; |
||
732 | |||
733 | // |
||
734 | // Get main template, set main variables |
||
735 | // |
||
736 | $template->parse('index', array_merge($tplMainPage, $tplNavigation, $tplHeaders)); |
||
737 | $template->merge('writeContent', 'index'); |
||
738 | |||
739 | // |
||
740 | // Send headers and print template |
||
741 | // |
||
742 | $http->setConfiguration($faqConfig); |
||
743 | $http->setContentType('text/html'); |
||
744 | $http->addHeader(); |
||
745 | $http->startCompression(); |
||
746 | |||
747 | // |
||
748 | // Check for 404 HTTP status code |
||
749 | // |
||
750 | if ($http->getStatusCode() === 404 || $action === '404') { |
||
751 | $template = new Template( |
||
752 | [ |
||
753 | 'index' => '404.html' |
||
754 | ], |
||
755 | new TemplateHelper($faqConfig), |
||
756 | $faqConfig->get('main.templateSet') |
||
757 | ); |
||
758 | $template->parse('index', array_merge($tplMainPage, $tplNavigation, $tplHeaders)); |
||
759 | } |
||
760 | |||
761 | echo $template->render(); |
||
762 | |||
763 | $faqConfig->getDb()->close(); |
||
764 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: