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 | * Shows the page with the FAQ record and - when available - the user comments. |
||
5 | * |
||
6 | * |
||
7 | * |
||
8 | * This Source Code Form is subject to the terms of the Mozilla Public License, |
||
9 | * v. 2.0. If a copy of the MPL was not distributed with this file, You can |
||
10 | * obtain one at http://mozilla.org/MPL/2.0/. |
||
11 | * |
||
12 | * @package phpMyFAQ |
||
13 | * @author Thorsten Rinne <[email protected]> |
||
14 | * @author Lars Tiedemann <[email protected]> |
||
15 | * @copyright 2002-2019 phpMyFAQ Team |
||
16 | * @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 |
||
17 | * @link https://www.phpmyfaq.de |
||
18 | * @since 2002-08-27 |
||
19 | */ |
||
20 | |||
21 | use phpMyFAQ\Attachment\Factory; |
||
22 | use phpMyFAQ\Captcha; |
||
23 | use phpMyFAQ\Comment; |
||
24 | use phpMyFAQ\Date; |
||
25 | use phpMyFAQ\Filter; |
||
26 | use phpMyFAQ\Glossary; |
||
27 | use phpMyFAQ\Helper\CaptchaHelper; |
||
28 | use phpMyFAQ\Helper\FaqHelper as HelperFaq; |
||
29 | use phpMyFAQ\Helper\SearchHelper; |
||
30 | use phpMyFAQ\Language; |
||
31 | use phpMyFAQ\Link; |
||
32 | use phpMyFAQ\Linkverifier; |
||
33 | use phpMyFAQ\Rating; |
||
34 | use phpMyFAQ\Relation; |
||
35 | use phpMyFAQ\Strings; |
||
36 | use phpMyFAQ\Tags; |
||
37 | use phpMyFAQ\User\CurrentUser; |
||
38 | use phpMyFAQ\Utils; |
||
39 | use phpMyFAQ\Visits; |
||
40 | |||
41 | View Code Duplication | if (!defined('IS_VALID_PHPMYFAQ')) { |
|
42 | $protocol = 'http'; |
||
43 | if (isset($_SERVER['HTTPS']) && strtoupper($_SERVER['HTTPS']) === 'ON') { |
||
44 | $protocol = 'https'; |
||
45 | } |
||
46 | header('Location: '.$protocol.'://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME'])); |
||
47 | exit(); |
||
48 | } |
||
49 | |||
50 | $captcha = new Captcha($faqConfig); |
||
51 | $oGlossary = new Glossary($faqConfig); |
||
52 | $faqTagging = new Tags($faqConfig); |
||
53 | $faqRelation = new Relation($faqConfig); |
||
54 | $faqRating = new Rating($faqConfig); |
||
55 | $faqComment = new Comment($faqConfig); |
||
56 | $markDown = new \ParsedownExtra(); |
||
57 | $faqHelper = new HelperFaq($faqConfig); |
||
58 | |||
59 | if (is_null($user)) { |
||
60 | $user = new CurrentUser($faqConfig); |
||
61 | } |
||
62 | |||
63 | $faqSearchResult = new SearchResultset($user, $faq, $faqConfig); |
||
64 | |||
65 | $captcha->setSessionId($sids); |
||
66 | if (!is_null($showCaptcha)) { |
||
67 | $captcha->showCaptchaImg(); |
||
68 | exit; |
||
69 | } |
||
70 | |||
71 | $currentCategory = $cat; |
||
72 | |||
73 | $recordId = Filter::filterInput(INPUT_GET, 'id', FILTER_VALIDATE_INT); |
||
74 | $solutionId = Filter::filterInput(INPUT_GET, 'solution_id', FILTER_VALIDATE_INT); |
||
75 | |||
76 | // Get all data from the FAQ record |
||
77 | if (0 === (int)$solutionId) { |
||
78 | $faq->getRecord($recordId); |
||
79 | } else { |
||
80 | $faq->getRecordBySolutionId($solutionId); |
||
81 | } |
||
82 | $recordId = $faq->faqRecord['id']; |
||
83 | |||
84 | try { |
||
85 | $faqSession->userTracking('article_view', $recordId); |
||
86 | } catch (Exception $e) { |
||
87 | // @todo handle the exception |
||
88 | } |
||
89 | |||
90 | $faqVisits = new Visits($faqConfig); |
||
91 | $faqVisits->logViews($recordId); |
||
92 | |||
93 | // Add Glossary entries for answers only |
||
94 | $question = $faq->getRecordTitle($recordId); |
||
95 | if ($faqConfig->get('main.enableMarkdownEditor')) { |
||
96 | $answer = $markDown->text($faq->faqRecord['content']); |
||
97 | } else { |
||
98 | $answer = $faqHelper->renderMarkupContent($faq->faqRecord['content']); |
||
99 | } |
||
100 | $answer = $oGlossary->insertItemsIntoContent($answer); |
||
101 | |||
102 | // Set the path of the current category |
||
103 | $categoryName = $category->getPath($currentCategory, ' » ', true); |
||
104 | |||
105 | $highlight = Filter::filterInput(INPUT_GET, 'highlight', FILTER_SANITIZE_STRIPPED); |
||
106 | if (!is_null($highlight) && $highlight != '/' && $highlight != '<' && $highlight != '>' && Strings::strlen($highlight) > 3) { |
||
107 | $highlight = str_replace("'", '´', $highlight); |
||
108 | $highlight = str_replace(array('^', '.', '?', '*', '+', '{', '}', '(', ')', '[', ']'), '', $highlight); |
||
109 | $highlight = preg_quote($highlight, '/'); |
||
110 | $searchItems = explode(' ', $highlight); |
||
111 | |||
112 | View Code Duplication | foreach ($searchItems as $item) { |
|
113 | if (Strings::strlen($item) > 2) { |
||
114 | $question = Utils::setHighlightedString($question, $item); |
||
115 | $answer = Utils::setHighlightedString($answer, $item); |
||
0 ignored issues
–
show
|
|||
116 | } |
||
117 | } |
||
118 | } |
||
119 | |||
120 | $linkVerifier = new Linkverifier($faqConfig); |
||
121 | $linkArray = $linkVerifier->getUrlpool(); |
||
122 | if (isset($linkArray['href'])) { |
||
123 | foreach (array_unique($linkArray['href']) as $_url) { |
||
124 | $xpos = strpos($_url, 'index.php?action=faq'); |
||
125 | if (!($xpos === false)) { |
||
126 | // Get the FaqHelper link title |
||
127 | $matches = array(); |
||
128 | preg_match('/id=([\d]+)/ism', $_url, $matches); |
||
129 | $_id = $matches[1]; |
||
130 | $_title = $faq->getRecordTitle($_id); |
||
131 | $_link = substr($_url, $xpos + 9); |
||
132 | if (strpos($_url, '&') === false) { |
||
133 | $_link = str_replace('&', '&', $_link); |
||
134 | } |
||
135 | $oLink = new Link(Link::getSystemRelativeUri().$_link, $faqConfig); |
||
136 | $oLink->itemTitle = $oLink->tooltip = $_title; |
||
137 | $newFaqPath = $oLink->toString(); |
||
138 | $answer = str_replace($_url, $newFaqPath, $answer); |
||
139 | } |
||
140 | } |
||
141 | } |
||
142 | |||
143 | // List all faq attachments |
||
144 | if ($faqConfig->get('records.disableAttachments') && 'yes' == $faq->faqRecord['active']) { |
||
145 | $attList = Factory::fetchByRecordId($faqConfig, $recordId); |
||
146 | $outstr = ''; |
||
147 | |||
148 | foreach ($attList as $att) { |
||
149 | $outstr .= sprintf('<a href="%s">%s</a>, ', |
||
150 | $att->buildUrl(), |
||
151 | $att->getFilename()); |
||
152 | } |
||
153 | if (count($attList) > 0) { |
||
154 | $answer .= '<p>'.$PMF_LANG['msgAttachedFiles'].' '.Strings::substr($outstr, 0, -2).'</p>'; |
||
155 | } |
||
156 | } |
||
157 | |||
158 | // List all categories for this faq |
||
159 | $htmlAllCategories = ''; |
||
160 | $multiCategories = $category->getCategoriesFromFaq($recordId); |
||
161 | if (count($multiCategories) > 1) { |
||
162 | foreach ($multiCategories as $multiCat) { |
||
163 | $path = $category->getPath($multiCat['id'], ' » ', true, 'breadcrumb-related-categories'); |
||
164 | if ('' === trim($path)) { |
||
165 | continue; |
||
166 | } |
||
167 | $htmlAllCategories .= $path; |
||
168 | } |
||
169 | } |
||
170 | |||
171 | // Related FAQs |
||
172 | $faqSearchResult->reviewResultset( |
||
173 | $faqRelation->getAllRelatedById( |
||
174 | $recordId, |
||
175 | $faq->faqRecord['title'], |
||
176 | $faq->faqRecord['keywords'] |
||
177 | ) |
||
178 | ); |
||
179 | |||
180 | $searchHelper = new SearchHelper($faqConfig); |
||
181 | $relatedFaqs = $searchHelper->renderRelatedFaqs($faqSearchResult, $recordId); |
||
182 | |||
183 | // Show link to edit the faq? |
||
184 | $editThisEntry = ''; |
||
185 | if ($user->perm->checkRight($user->getUserId(), 'edit_faq')) { |
||
186 | $editThisEntry = sprintf( |
||
187 | '<i aria-hidden="true" class="fas fa-pencil"></i> <a class="data" href="%sadmin/index.php?action=editentry&id=%d&lang=%s">%s</a>', |
||
188 | Link::getSystemRelativeUri('index.php'), |
||
189 | $recordId, |
||
190 | $lang, |
||
191 | $PMF_LANG['ad_entry_edit_1'].' '.$PMF_LANG['ad_entry_edit_2'] |
||
192 | ); |
||
193 | } |
||
194 | |||
195 | // Is the faq expired? |
||
196 | $expired = (date('YmdHis') > $faq->faqRecord['dateEnd']); |
||
197 | |||
198 | // Does the user have the right to add a comment? |
||
199 | if ((-1 === $user->getUserId() && !$faqConfig->get('records.allowCommentsForGuests')) || |
||
200 | ($faq->faqRecord['active'] === 'no') || ('n' === $faq->faqRecord['comment']) || $expired) { |
||
201 | $commentMessage = $PMF_LANG['msgWriteNoComment']; |
||
202 | } else { |
||
203 | $commentMessage = sprintf( |
||
204 | '%s<a href="#" class="show-comment-form">%s</a>', |
||
205 | $PMF_LANG['msgYouCan'], |
||
206 | $PMF_LANG['msgWriteComment'] |
||
207 | ); |
||
208 | } |
||
209 | |||
210 | $translationUrl = sprintf( |
||
211 | str_replace( |
||
212 | '%', |
||
213 | '%%', |
||
214 | Link::getSystemRelativeUri('index.php') |
||
215 | ).'index.php?%saction=translate&cat=%s&id=%d&srclang=%s', |
||
216 | $sids, |
||
217 | $currentCategory, |
||
218 | $recordId, |
||
219 | $lang |
||
220 | ); |
||
221 | |||
222 | $availableLanguages = $faqConfig->getLanguage()->languageAvailable($faq->faqRecord['id']); |
||
223 | |||
224 | if (!empty($availableLanguages) && count($availableLanguages) > 1) { |
||
225 | $template->parseBlock( |
||
226 | 'writeContent', |
||
227 | 'switchLanguage', |
||
228 | [ |
||
229 | 'msgChangeLanguage' => $PMF_LANG['msgLanguageSubmit'], |
||
230 | ] |
||
231 | ); |
||
232 | } |
||
233 | |||
234 | if ($user->perm->checkRight($user->getUserId(), 'addtranslation') && |
||
235 | !empty($availableLanguages) && count($availableLanguages) > 1) { |
||
236 | $template->parseBlock( |
||
237 | 'writeContent', |
||
238 | 'addTranslation', |
||
239 | [ |
||
240 | 'msgTranslate' => $PMF_LANG['msgTranslate'], |
||
241 | ] |
||
242 | ); |
||
243 | } |
||
244 | |||
245 | if ($user->perm->checkRight($user->getUserId(), 'edit_faq') && !empty($faq->faqRecord['notes'])) { |
||
246 | $template->parseBlock( |
||
247 | 'writeContent', |
||
248 | 'privateNotes', |
||
249 | [ |
||
250 | 'notesHeader' => $PMF_LANG['ad_admin_notes'], |
||
251 | 'notes' => $faq->faqRecord['notes'] |
||
252 | ] |
||
253 | ); |
||
254 | } |
||
255 | |||
256 | if ('-' !== $faqTagging->getAllLinkTagsById($recordId)) { |
||
257 | $template->parseBlock( |
||
258 | 'writeContent', |
||
259 | 'tagsAvailable', |
||
260 | [ |
||
261 | 'renderTags' => $PMF_LANG['msg_tags'].': '.$faqTagging->getAllLinkTagsById($recordId), |
||
262 | ] |
||
263 | ); |
||
264 | } |
||
265 | |||
266 | if ('' !== $htmlAllCategories) { |
||
267 | $template->parseBlock( |
||
268 | 'writeContent', |
||
269 | 'relatedCategories', |
||
270 | [ |
||
271 | 'renderRelatedCategoriesHeader' => $PMF_LANG['msgArticleCategories'], |
||
272 | 'renderRelatedCategories' => $htmlAllCategories, |
||
273 | ] |
||
274 | ); |
||
275 | } |
||
276 | |||
277 | if ('' !== $relatedFaqs) { |
||
278 | $template->parseBlock( |
||
279 | 'writeContent', |
||
280 | 'relatedFaqs', |
||
281 | [ |
||
282 | 'renderRelatedArticlesHeader' => $PMF_LANG['msg_related_articles'], |
||
283 | 'renderRelatedArticles' => $relatedFaqs, |
||
284 | ] |
||
285 | ); |
||
286 | } |
||
287 | |||
288 | $date = new Date($faqConfig); |
||
289 | $captchaHelper = new CaptchaHelper($faqConfig); |
||
290 | |||
291 | $numComments = $faqComment->getNumberOfComments(); |
||
292 | |||
293 | // Check if category ID and FAQ ID are linked together |
||
294 | $isLinkedFAQ = $category->categoryHasLinkToFaq($recordId, $currentCategory); |
||
295 | if (!$isLinkedFAQ) { |
||
296 | $http->sendStatus(404); |
||
297 | } |
||
298 | |||
299 | $template->parse( |
||
300 | 'writeContent', |
||
301 | array( |
||
302 | 'baseHref' => $faqSystem->getSystemUri($faqConfig), |
||
303 | 'writeRubrik' => $categoryName, |
||
304 | 'solution_id' => $faq->faqRecord['solution_id'], |
||
305 | 'solution_id_link' => Link::getSystemRelativeUri().'?solution_id='.$faq->faqRecord['solution_id'], |
||
306 | 'writeThema' => $question, |
||
307 | 'writeContent' => $answer, |
||
308 | 'writeDateMsg' => $date->format($faq->faqRecord['date']), |
||
309 | 'writeAuthor' => $faq->faqRecord['author'], |
||
310 | 'numberOfComments' => sprintf( |
||
311 | '%d %s', |
||
312 | isset($numComments[$recordId]) ? $numComments[$recordId] : 0, |
||
313 | $PMF_LANG['ad_start_comments'] |
||
314 | ), |
||
315 | 'editThisEntry' => $editThisEntry, |
||
316 | 'translationUrl' => $translationUrl, |
||
317 | 'languageSelection' => Language::selectLanguages($LANGCODE, false, $availableLanguages, 'translation'), |
||
318 | 'msgTranslateSubmit' => $PMF_LANG['msgTranslateSubmit'], |
||
319 | 'saveVotingPATH' => sprintf( |
||
320 | str_replace( |
||
321 | '%', |
||
322 | '%%', |
||
323 | Link::getSystemRelativeUri('index.php') |
||
324 | ).'index.php?%saction=savevoting', |
||
325 | $sids |
||
326 | ), |
||
327 | 'saveVotingID' => $recordId, |
||
328 | 'saveVotingIP' => $_SERVER['REMOTE_ADDR'], |
||
329 | 'msgAverageVote' => $PMF_LANG['msgAverageVote'], |
||
330 | 'renderVotingStars' => '', |
||
331 | 'printVotings' => $faqRating->getVotingResult($recordId), |
||
332 | 'switchLanguage' => $faqHelper->renderChangeLanguageSelector($faq, $currentCategory), |
||
333 | 'msgVoteUseability' => $PMF_LANG['msgVoteUseability'], |
||
334 | 'msgVoteBad' => $PMF_LANG['msgVoteBad'], |
||
335 | 'msgVoteGood' => $PMF_LANG['msgVoteGood'], |
||
336 | 'msgVoteSubmit' => $PMF_LANG['msgVoteSubmit'], |
||
337 | 'writeCommentMsg' => $commentMessage, |
||
338 | 'msgWriteComment' => $PMF_LANG['msgWriteComment'], |
||
339 | 'id' => $recordId, |
||
340 | 'lang' => $lang, |
||
341 | 'msgCommentHeader' => $PMF_LANG['msgCommentHeader'], |
||
342 | 'msgNewContentName' => $PMF_LANG['msgNewContentName'], |
||
343 | 'msgNewContentMail' => $PMF_LANG['msgNewContentMail'], |
||
344 | 'defaultContentMail' => ($user instanceof CurrentUser) ? $user->getUserData('email') : '', |
||
345 | 'defaultContentName' => ($user instanceof CurrentUser) ? $user->getUserData('display_name') : '', |
||
346 | 'msgYourComment' => $PMF_LANG['msgYourComment'], |
||
347 | 'msgNewContentSubmit' => $PMF_LANG['msgNewContentSubmit'], |
||
348 | 'captchaFieldset' => $captchaHelper->renderCaptcha($captcha, 'writecomment', $PMF_LANG['msgCaptcha'], $auth), |
||
349 | 'writeComments' => $faqComment->getComments($recordId, Comment::COMMENT_TYPE_FAQ), |
||
350 | 'msg_about_faq' => $PMF_LANG['msg_about_faq'], |
||
351 | ) |
||
352 | ); |
||
353 | |||
354 | $template->parseBlock( |
||
355 | 'index', |
||
356 | 'breadcrumb', |
||
357 | [ |
||
358 | 'breadcrumbHeadline' => $categoryName |
||
359 | ] |
||
360 | ); |
||
361 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.