PageRenderTime 45ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/phpmyfaq/artikel.php

https://github.com/cyrke/phpMyFAQ
PHP | 315 lines | 254 code | 31 blank | 30 comment | 37 complexity | 93ec6fa65326855e5186ed3ec9e3d034 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. * Shows the page with the FAQ record and - when available - the user comments
  4. *
  5. * PHP Version 5.3
  6. *
  7. * This Source Code Form is subject to the terms of the Mozilla Public License,
  8. * v. 2.0. If a copy of the MPL was not distributed with this file, You can
  9. * obtain one at http://mozilla.org/MPL/2.0/.
  10. *
  11. * @category phpMyFAQ
  12. * @package Frontend
  13. * @author Thorsten Rinne <thorsten@phpmyfaq.de>
  14. * @author Lars Tiedemann <larstiedemann@yahoo.de>
  15. * @copyright 2002-2012 phpMyFAQ Team
  16. * @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
  17. * @link http://www.phpmyfaq.de
  18. * @since 2002-08-27
  19. */
  20. if (!defined('IS_VALID_PHPMYFAQ')) {
  21. header('Location: http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME']));
  22. exit();
  23. }
  24. $captcha = new PMF_Captcha($faqConfig);
  25. $oGlossary = new PMF_Glossary($faqConfig);
  26. $oLnk = new PMF_Linkverifier($faqConfig);
  27. $faqTagging = new PMF_Tags($faqConfig);
  28. $faqRelation = new PMF_Relation($faqConfig);
  29. $faqRating = new PMF_Rating($faqConfig);
  30. $faqComment = new PMF_Comment($faqConfig);
  31. if (is_null($user)) {
  32. $user = new PMF_User_CurrentUser($faqConfig);
  33. }
  34. $faqSearchResult = new PMF_Search_Resultset($user, $faq, $faqConfig);
  35. $captcha->setSessionId($sids);
  36. if (!is_null($showCaptcha)) {
  37. $captcha->showCaptchaImg();
  38. exit;
  39. }
  40. $currentCategory = $cat;
  41. $recordId = PMF_Filter::filterInput(INPUT_GET, 'id', FILTER_VALIDATE_INT);
  42. $solutionId = PMF_Filter::filterInput(INPUT_GET, 'solution_id', FILTER_VALIDATE_INT);
  43. $highlight = PMF_Filter::filterInput(INPUT_GET, 'highlight', FILTER_SANITIZE_STRIPPED);
  44. // Get all data from the FAQ record
  45. if (0 == $solutionId) {
  46. $faq->getRecord($recordId);
  47. } else {
  48. $faq->getRecordBySolutionId($solutionId);
  49. }
  50. $faqsession->userTracking('article_view', $faq->faqRecord['id']);
  51. $faqVisits = new PMF_Visits($faqConfig);
  52. $faqVisits->logViews($faq->faqRecord['id']);
  53. // Add Glossary entries
  54. $question = $oGlossary->insertItemsIntoContent($faq->getRecordTitle($faq->faqRecord['id']));
  55. $answer = $oGlossary->insertItemsIntoContent($faq->faqRecord['content']);
  56. // Set the path of the current category
  57. $categoryName = $category->getPath($currentCategory, ' &raquo; ', true);
  58. $changeLanguagePath = PMF_Link::getSystemRelativeUri() .
  59. sprintf(
  60. '?%saction=artikel&amp;cat=%d&amp;id=%d&amp;artlang=%s',
  61. $sids,
  62. $currentCategory,
  63. $faq->faqRecord['id'],
  64. $LANGCODE
  65. );
  66. $oLink = new PMF_Link($changeLanguagePath, $faqConfig);
  67. $oLink->itemTitle = $faq->getRecordTitle($faq->faqRecord['id'], false);
  68. $changeLanguagePath = $oLink->toString();
  69. $highlight = PMF_Filter::filterInput(INPUT_GET, 'highlight', FILTER_SANITIZE_STRIPPED);
  70. if (!is_null($highlight) && $highlight != "/" && $highlight != "<" && $highlight != ">" && PMF_String::strlen($highlight) > 3) {
  71. $highlight = str_replace("'", "´", $highlight);
  72. $highlight = str_replace(array('^', '.', '?', '*', '+', '{', '}', '(', ')', '[', ']'), '', $highlight);
  73. $highlight = preg_quote($highlight, '/');
  74. $searchItems = explode(' ', $highlight);
  75. foreach ($searchItems as $item) {
  76. $question = PMF_Utils::setHighlightedString($question, $item);
  77. $answer = PMF_Utils::setHighlightedString($answer, $item);
  78. }
  79. }
  80. // Hack: Apply the new SEO schema to those HTML anchors to
  81. // other faq records (Internal Links) added with WYSIWYG Editor:
  82. // href="index.php?action=artikel&cat=NNN&id=MMM&artlang=XYZ"
  83. // Search for href attribute links
  84. $oLnk->resetPool();
  85. $oLnk->parse_string($answer);
  86. $fixedContent = str_replace('href="#',
  87. sprintf('href="index.php?action=artikel&amp;lang=%s&amp;cat=%d&amp;id=%d&amp;artlang=%s#',
  88. $LANGCODE,
  89. $currentCategory,
  90. $faq->faqRecord['id'],
  91. $LANGCODE),
  92. $answer);
  93. $oLnk->resetPool();
  94. $oLnk->parse_string($fixedContent);
  95. // Search for href attributes only
  96. $linkArray = $oLnk->getUrlpool();
  97. if (isset($linkArray['href'])) {
  98. foreach (array_unique($linkArray['href']) as $_url) {
  99. $xpos = strpos($_url, 'index.php?action=artikel');
  100. if (!($xpos === false)) {
  101. // Get the Faq link title
  102. $matches = array();
  103. preg_match('/id=([\d]+)/ism', $_url, $matches);
  104. $_id = $matches[1];
  105. $_title = $faq->getRecordTitle($_id, false);
  106. $_link = substr($_url, $xpos + 9);
  107. if (strpos($_url, '&amp;') === false) {
  108. $_link = str_replace('&', '&amp;', $_link);
  109. }
  110. $oLink = new PMF_Link(PMF_Link::getSystemRelativeUri().$_link, $faqConfig);
  111. $oLink->itemTitle = $oLink->tooltip = $_title;
  112. $newFaqPath = $oLink->toString();
  113. $fixedContent = str_replace($_url, $newFaqPath, $fixedContent);
  114. }
  115. }
  116. }
  117. $answer = $fixedContent;
  118. // Check for the languages for a faq
  119. $arrLanguage = $faqConfig->getLanguage()->languageAvailable($faq->faqRecord['id']);
  120. $switchLanguage = '';
  121. $check4Lang = '';
  122. if (count($arrLanguage) > 1) {
  123. foreach ($arrLanguage as $language) {
  124. $check4Lang .= "<option value=\"".$language."\"";
  125. $check4Lang .= ($lang == $language ? ' selected="selected"' : '');
  126. $check4Lang .= ">".$languageCodes[strtoupper($language)]."</option>\n";
  127. }
  128. $switchLanguage .= "<form action=\"".$changeLanguagePath."\" method=\"post\" style=\"display: inline;\">\n";
  129. $switchLanguage .= "<select name=\"artlang\" size=\"1\">\n";
  130. $switchLanguage .= $check4Lang;
  131. $switchLanguage .= "</select>\n";
  132. $switchLanguage .= "&nbsp;\n";
  133. $switchLanguage .= "<input class=\"submit\" type=\"submit\" name=\"submit\" value=\"".$PMF_LANG["msgLangaugeSubmit"]."\" />\n";
  134. $switchLanguage .= "</form>\n";
  135. }
  136. // List all faq attachments
  137. if ($faqConfig->get('records.disableAttachments') && 'yes' == $faq->faqRecord['active']) {
  138. $attList = PMF_Attachment_Factory::fetchByRecordId($faqConfig, $faq->faqRecord['id']);
  139. $outstr = '';
  140. while (list(,$att) = each($attList)) {
  141. $outstr .= sprintf('<a href="%s">%s</a>, ',
  142. $att->buildUrl(),
  143. $att->getFilename());
  144. }
  145. if (count($attList) > 0) {
  146. $answer .= '<p>'.$PMF_LANG['msgAttachedFiles'].' '.PMF_String::substr($outstr, 0, -2).'</p>';
  147. }
  148. }
  149. // List all categories for this faq
  150. $htmlAllCategories = '';
  151. $multiCategories = $category->getCategoriesFromArticle($faq->faqRecord['id']);
  152. if (count($multiCategories) > 1) {
  153. $htmlAllCategories .= ' <div id="article_categories">';
  154. $htmlAllCategories .= ' <p>' . $PMF_LANG['msgArticleCategories'] . '</p>';
  155. $htmlAllCategories .= ' <ul>';
  156. foreach ($multiCategories as $multiCat) {
  157. $path = $category->getPath($multiCat['id'], ' &raquo; ', true);
  158. if ('' === trim($path)) {
  159. continue;
  160. }
  161. $htmlAllCategories .= sprintf("<li>%s</li>\n", $path);
  162. }
  163. $htmlAllCategories .= ' </ul>';
  164. $htmlAllCategories .= ' </div>';
  165. }
  166. // Related FAQs
  167. $faqSearchResult->reviewResultset(
  168. $faqRelation->getAllRelatedById(
  169. $faq->faqRecord['id'],
  170. $faq->faqRecord['title'],
  171. $faq->faqRecord['keywords']
  172. )
  173. );
  174. $searchHelper = new PMF_Helper_Search($faqConfig);
  175. $relatedFaqs = $searchHelper->renderRelatedFaqs($faqSearchResult, $faq->faqRecord['id']);
  176. // Show link to edit the faq?
  177. $editThisEntry = '';
  178. if (isset($permission['editbt']) && $permission['editbt']) {
  179. $editThisEntry = sprintf(
  180. '<a href="%sadmin/index.php?action=editentry&amp;id=%d&amp;lang=%s">%s</a>',
  181. PMF_Link::getSystemRelativeUri('index.php'),
  182. $faq->faqRecord['id'],
  183. $lang,
  184. $PMF_LANG['ad_entry_edit_1'].' '.$PMF_LANG['ad_entry_edit_2']
  185. );
  186. }
  187. // Is the faq expired?
  188. $expired = (date('YmdHis') > $faq->faqRecord['dateEnd']);
  189. // Does the user have the right to add a comment?
  190. if (($faq->faqRecord['active'] != 'yes') || ('n' == $faq->faqRecord['comment']) || $expired) {
  191. $commentMessage = $PMF_LANG['msgWriteNoComment'];
  192. } else {
  193. $commentMessage = sprintf(
  194. "%s<a href=\"javascript:void(0);\" onclick=\"javascript:$('#commentForm').show();\">%s</a>",
  195. $PMF_LANG['msgYouCan'],
  196. $PMF_LANG['msgWriteComment']);
  197. }
  198. $translationUrl = sprintf(
  199. str_replace(
  200. '%',
  201. '%%',
  202. PMF_Link::getSystemRelativeUri('index.php')
  203. ) . 'index.php?%saction=translate&amp;cat=%s&amp;id=%d&amp;srclang=%s',
  204. $sids,
  205. $currentCategory,
  206. $faq->faqRecord['id'],
  207. $lang
  208. );
  209. if (!empty($switchLanguage)) {
  210. $tpl->parseBlock(
  211. 'writeContent',
  212. 'switchLanguage',
  213. array(
  214. 'msgChangeLanguage' => $PMF_LANG['msgLangaugeSubmit']
  215. )
  216. );
  217. }
  218. if (isset($permission['addtranslation']) && $permission['addtranslation']) {
  219. $tpl->parseBlock(
  220. 'writeContent',
  221. 'addTranslation',
  222. array(
  223. 'msgTranslate' => $PMF_LANG['msgTranslate'],
  224. )
  225. );
  226. }
  227. $date = new PMF_Date($faqConfig);
  228. $captchaHelper = new PMF_Helper_Captcha($faqConfig);
  229. $tpl->parse('writeContent', array(
  230. 'writeRubrik' => $categoryName,
  231. 'solution_id' => $faq->faqRecord['solution_id'],
  232. 'solution_id_link' => PMF_Link::getSystemRelativeUri() . '?solution_id=' . $faq->faqRecord['solution_id'],
  233. 'writeThema' => $question,
  234. 'writeArticleCategoryHeader' => $PMF_LANG['msgArticleCategories'],
  235. 'writeArticleCategories' => $htmlAllCategories,
  236. 'writeContent' => $answer,
  237. 'writeTagHeader' => $PMF_LANG['msg_tags'] . ': ',
  238. 'writeArticleTags' => $faqTagging->getAllLinkTagsById($faq->faqRecord['id']),
  239. 'writeRelatedArticlesHeader' => $PMF_LANG['msg_related_articles'] . ': ',
  240. 'writeRelatedArticles' => $relatedFaqs,
  241. 'writeDateMsg' => $PMF_LANG['msgLastUpdateArticle'] . $date->format($faq->faqRecord['date']),
  242. 'writeRevision' => $PMF_LANG['ad_entry_revision'] . ': 1.' . $faq->faqRecord['revision_id'],
  243. 'writeAuthor' => $PMF_LANG['msgAuthor'] . ': ' . $faq->faqRecord['author'],
  244. 'editThisEntry' => $editThisEntry,
  245. 'translationUrl' => $translationUrl,
  246. 'languageSelection' => PMF_Language::selectLanguages($LANGCODE, false, $arrLanguage, 'translation'),
  247. 'msgTranslateSubmit' => $PMF_LANG['msgTranslateSubmit'],
  248. 'saveVotingPATH' => sprintf(
  249. str_replace(
  250. '%',
  251. '%%',
  252. PMF_Link::getSystemRelativeUri('index.php')
  253. ) . 'index.php?%saction=savevoting',
  254. $sids
  255. ),
  256. 'saveVotingID' => $faq->faqRecord['id'],
  257. 'saveVotingIP' => $_SERVER['REMOTE_ADDR'],
  258. 'msgAverageVote' => $PMF_LANG['msgAverageVote'],
  259. 'renderVotingStars' => '',
  260. 'printVotings' => $faqRating->getVotingResult($recordId),
  261. 'switchLanguage' => $switchLanguage,
  262. 'msgVoteUseability' => $PMF_LANG['msgVoteUseability'],
  263. 'msgVoteBad' => $PMF_LANG['msgVoteBad'],
  264. 'msgVoteGood' => $PMF_LANG['msgVoteGood'],
  265. 'msgVoteSubmit' => $PMF_LANG['msgVoteSubmit'],
  266. 'writeCommentMsg' => $commentMessage,
  267. 'msgWriteComment' => $PMF_LANG['msgWriteComment'],
  268. 'id' => $faq->faqRecord['id'],
  269. 'lang' => $lang,
  270. 'msgCommentHeader' => $PMF_LANG['msgCommentHeader'],
  271. 'msgNewContentName' => $PMF_LANG['msgNewContentName'],
  272. 'msgNewContentMail' => $PMF_LANG['msgNewContentMail'],
  273. 'defaultContentMail' => ($user instanceof PMF_User_CurrentUser) ? $user->getUserData('email') : '',
  274. 'defaultContentName' => ($user instanceof PMF_User_CurrentUser) ? $user->getUserData('display_name') : '',
  275. 'msgYourComment' => $PMF_LANG['msgYourComment'],
  276. 'msgNewContentSubmit' => $PMF_LANG['msgNewContentSubmit'],
  277. 'captchaFieldset' => $captchaHelper->renderCaptcha($captcha, 'writecomment',$PMF_LANG['msgCaptcha'], $auth),
  278. 'writeComments' => $faqComment->getComments($faq->faqRecord['id'], PMF_Comment::COMMENT_TYPE_FAQ),
  279. 'msg_about_faq' => $PMF_LANG['msg_about_faq']
  280. )
  281. );
  282. $tpl->merge('writeContent', 'index');