|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* The Ajax driven response page. |
|
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 http://mozilla.org/MPL/2.0/. |
|
9
|
|
|
* |
|
10
|
|
|
* @package phpMyFAQ |
|
11
|
|
|
* @author Thorsten Rinne <[email protected]> |
|
12
|
|
|
* @copyright 2007-2019 phpMyFAQ Team |
|
13
|
|
|
* @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 |
|
14
|
|
|
* @link https://www.phpmyfaq.de |
|
15
|
|
|
* @since 2007-03-27 |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
use phpMyFAQ\Category; |
|
19
|
|
|
use phpMyFAQ\Faq; |
|
20
|
|
|
use phpMyFAQ\Filter; |
|
21
|
|
|
use phpMyFAQ\Helper\HttpHelper; |
|
22
|
|
|
use phpMyFAQ\Helper\SearchHelper; |
|
23
|
|
|
use phpMyFAQ\Language; |
|
24
|
|
|
use phpMyFAQ\Language\Plurals; |
|
25
|
|
|
use phpMyFAQ\Permission\MediumPermission; |
|
26
|
|
|
use phpMyFAQ\Strings; |
|
27
|
|
|
use phpMyFAQ\Search; |
|
28
|
|
|
use phpMyFAQ\Search\Exception; |
|
|
|
|
|
|
29
|
|
|
use phpMyFAQ\Search\Resultset; |
|
30
|
|
|
use phpMyFAQ\User\CurrentUser; |
|
31
|
|
|
|
|
32
|
|
|
define('IS_VALID_PHPMYFAQ', null); |
|
33
|
|
|
|
|
34
|
|
|
// |
|
35
|
|
|
// Prepend and start the PHP session |
|
36
|
|
|
// |
|
37
|
|
|
require 'src/Bootstrap.php'; |
|
38
|
|
|
|
|
39
|
|
|
$searchString = Filter::filterInput(INPUT_GET, 'search', FILTER_SANITIZE_STRIPPED); |
|
40
|
|
|
$ajaxLanguage = Filter::filterInput(INPUT_POST, 'ajaxlanguage', FILTER_SANITIZE_STRING, 'en'); |
|
41
|
|
|
$categoryId = Filter::filterInput(INPUT_GET, 'searchcategory', FILTER_VALIDATE_INT, '%'); |
|
42
|
|
|
|
|
43
|
|
|
$language = new Language($faqConfig); |
|
44
|
|
|
$languageCode = $language->setLanguage( |
|
45
|
|
|
$faqConfig->get('main.languageDetection'), |
|
46
|
|
|
$faqConfig->get('main.language') |
|
47
|
|
|
); |
|
48
|
|
|
$faqConfig->setLanguage($language); |
|
49
|
|
|
|
|
50
|
|
|
require_once 'lang/language_en.php'; |
|
51
|
|
|
|
|
52
|
|
View Code Duplication |
if (Language::isASupportedLanguage($ajaxLanguage)) { |
|
53
|
|
|
$languageCode = trim($ajaxLanguage); |
|
54
|
|
|
require_once 'lang/language_'.$languageCode.'.php'; |
|
55
|
|
|
} else { |
|
56
|
|
|
$languageCode = 'en'; |
|
57
|
|
|
require_once 'lang/language_en.php'; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
//Load plurals support for selected language |
|
61
|
|
|
$plr = new Plurals($PMF_LANG); |
|
62
|
|
|
|
|
63
|
|
|
// |
|
64
|
|
|
// Initializing static string wrapper |
|
65
|
|
|
// |
|
66
|
|
|
Strings::init($languageCode); |
|
67
|
|
|
|
|
68
|
|
|
// |
|
69
|
|
|
// Get current user and group id - default: -1 |
|
70
|
|
|
// |
|
71
|
|
|
$user = CurrentUser::getFromCookie($faqConfig); |
|
72
|
|
|
if (!$user instanceof CurrentUser) { |
|
73
|
|
|
$user = CurrentUser::getFromSession($faqConfig); |
|
74
|
|
|
} |
|
75
|
|
|
if (isset($user) && is_object($user)) { |
|
76
|
|
|
$current_user = $user->getUserId(); |
|
77
|
|
|
if ($user->perm instanceof MediumPermission) { |
|
78
|
|
|
$current_groups = $user->perm->getUserGroups($current_user); |
|
79
|
|
|
} else { |
|
80
|
|
|
$current_groups = array(-1); |
|
81
|
|
|
} |
|
82
|
|
|
if (0 == count($current_groups)) { |
|
83
|
|
|
$current_groups = array(-1); |
|
84
|
|
|
} |
|
85
|
|
|
} else { |
|
86
|
|
|
$user = new CurrentUser($faqConfig); |
|
87
|
|
|
$current_user = -1; |
|
88
|
|
|
$current_groups = array(-1); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
$category = new Category($faqConfig, $current_groups); |
|
92
|
|
|
$category->setUser($current_user); |
|
93
|
|
|
$category->setGroups($current_groups); |
|
94
|
|
|
$category->transform(0); |
|
95
|
|
|
$category->buildTree(); |
|
96
|
|
|
|
|
97
|
|
|
$faq = new Faq($faqConfig); |
|
98
|
|
|
$faqSearch = new Search($faqConfig); |
|
99
|
|
|
$faqSearchResult = new Resultset($user, $faq, $faqConfig); |
|
100
|
|
|
|
|
101
|
|
|
// |
|
102
|
|
|
// Send headers |
|
103
|
|
|
// |
|
104
|
|
|
$http = new HttpHelper(); |
|
105
|
|
|
$http->setContentType('application/json'); |
|
106
|
|
|
$http->addHeader(); |
|
107
|
|
|
|
|
108
|
|
|
// |
|
109
|
|
|
// Handle the search requests |
|
110
|
|
|
// |
|
111
|
|
|
if (!is_null($searchString)) { |
|
112
|
|
|
$faqSearch->setCategory($category); |
|
113
|
|
|
|
|
114
|
|
|
try { |
|
115
|
|
|
$searchResult = $faqSearch->autoComplete($searchString); |
|
116
|
|
|
$faqSearchResult->reviewResultset($searchResult); |
|
|
|
|
|
|
117
|
|
|
} catch (Exception $e) { |
|
118
|
|
|
$http->sendWithHeaders($e->getMessage()); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
$faqSearchHelper = new SearchHelper($faqConfig); |
|
122
|
|
|
$faqSearchHelper->setSearchterm($searchString); |
|
123
|
|
|
$faqSearchHelper->setCategory($category); |
|
124
|
|
|
$faqSearchHelper->setPlurals($plr); |
|
125
|
|
|
|
|
126
|
|
|
$http->sendWithHeaders($faqSearchHelper->renderInstantResponseResult($faqSearchResult)); |
|
127
|
|
|
} |
|
128
|
|
|
|
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare 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.phpHowever, as
OtherDir/Foo.phpdoes 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: