PageRenderTime 58ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/phpmyfaq/index.php

https://github.com/NHLH-ITM/phpMyFAQ-kindeditor
PHP | 768 lines | 563 code | 71 blank | 134 comment | 142 complexity | 7022da193fde146be4350fcb70abc044 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, LGPL-3.0
  1. <?php
  2. /**
  3. * This is the main public frontend page of phpMyFAQ. It detects the browser's
  4. * language, gets and sets all cookie, post and get informations and includes
  5. * the templates we need and set all internal variables to the template
  6. * variables. That's all.
  7. *
  8. * PHP Version 5.4
  9. *
  10. * This Source Code Form is subject to the terms of the Mozilla Public License,
  11. * v. 2.0. If a copy of the MPL was not distributed with this file, You can
  12. * obtain one at http://mozilla.org/MPL/2.0/.
  13. *
  14. * @category phpMyFAQ
  15. * @package Frontend
  16. * @author Thorsten Rinne <thorsten@phpmyfaq.de>
  17. * @author Lars Tiedemann <php@larstiedemann.de>
  18. * @author Matteo Scaramuccia <matteo@phpmyfaq.de>
  19. * @copyright 2001-2014 phpMyFAQ Team
  20. * @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
  21. * @link http://www.phpmyfaq.de
  22. * @since 2001-02-12
  23. */
  24. use Symfony\Component\HttpFoundation\RedirectResponse;
  25. use Symfony\Component\HttpFoundation\Response;
  26. use PMF\Helper\ResponseWrapper;
  27. //
  28. // Define the named constant used as a check by any included PHP file
  29. //
  30. define('IS_VALID_PHPMYFAQ', null);
  31. //
  32. // Bootstrapping
  33. //
  34. require 'inc/Bootstrap.php';
  35. //
  36. // Get language (default: english)
  37. //
  38. $Language = new PMF_Language($faqConfig);
  39. $LANGCODE = $Language->setLanguage($faqConfig->get('main.languageDetection'), $faqConfig->get('main.language'));
  40. // Preload English strings
  41. require_once 'lang/language_en.php';
  42. $faqConfig->setLanguage($Language);
  43. $showCaptcha = PMF_Filter::filterInput(INPUT_GET, 'gen', FILTER_SANITIZE_STRING);
  44. if (isset($LANGCODE) && PMF_Language::isASupportedLanguage($LANGCODE) && is_null($showCaptcha)) {
  45. // Overwrite English strings with the ones we have in the current language,
  46. // but don't include UTF-8 encoded files, these will break the captcha images
  47. if (! file_exists('lang/language_' . $LANGCODE . '.php')) {
  48. $LANGCODE = 'en';
  49. }
  50. require_once 'lang/language_' . $LANGCODE . '.php';
  51. } else {
  52. $LANGCODE = 'en';
  53. }
  54. //Load plurals support for selected language
  55. $plr = new PMF_Language_Plurals($PMF_LANG);
  56. //
  57. // Initalizing static string wrapper
  58. //
  59. PMF_String::init($LANGCODE);
  60. /**
  61. * Initialize attachment factory
  62. */
  63. PMF_Attachment_Factory::init(
  64. $faqConfig->get('records.attachmentsStorageType'),
  65. $faqConfig->get('records.defaultAttachmentEncKey'),
  66. $faqConfig->get('records.enableAttachmentEncryption')
  67. );
  68. //
  69. // Get user action
  70. //
  71. $action = PMF_Filter::filterInput(INPUT_GET, 'action', FILTER_SANITIZE_STRING, 'main');
  72. //
  73. // Authenticate current user
  74. //
  75. $auth = $error = null;
  76. $loginVisibility = 'hidden';
  77. $faqusername = PMF_Filter::filterInput(INPUT_POST, 'faqusername', FILTER_SANITIZE_STRING);
  78. $faqpassword = PMF_Filter::filterInput(INPUT_POST, 'faqpassword', FILTER_SANITIZE_STRING);
  79. $faqaction = PMF_Filter::filterInput(INPUT_POST, 'faqloginaction', FILTER_SANITIZE_STRING);
  80. $faqremember = PMF_Filter::filterInput(INPUT_POST, 'faqrememberme', FILTER_SANITIZE_STRING);
  81. // Set username via SSO
  82. if ($faqConfig->get('security.ssoSupport') && isset($_SERVER['REMOTE_USER'])) {
  83. $faqusername = trim($_SERVER['REMOTE_USER']);
  84. $faqpassword = '';
  85. }
  86. // Login via local DB or LDAP or SSO
  87. if (!is_null($faqusername) && !is_null($faqpassword)) {
  88. $user = new PMF_User_CurrentUser($faqConfig);
  89. if (!is_null($faqremember) && 'rememberMe' === $faqremember) {
  90. $user->enableRememberMe();
  91. }
  92. if ($faqConfig->get('security.ldapSupport') && function_exists('ldap_connect')) {
  93. $authLdap = new PMF_Auth_Ldap($faqConfig);
  94. $user->addAuth($authLdap, 'ldap');
  95. }
  96. if ($faqConfig->get('security.ssoSupport')) {
  97. $authSso = new PMF_Auth_Sso($faqConfig);
  98. $user->addAuth($authSso, 'sso');
  99. }
  100. if ($user->login($faqusername, $faqpassword)) {
  101. if ($user->getStatus() != 'blocked') {
  102. $auth = true;
  103. if (empty($action)) {
  104. $action = $faqaction; // SSO logins don't have $faqaction
  105. }
  106. } else {
  107. $error = $PMF_LANG['ad_auth_fail'] . ' (' . $faqusername . ')';
  108. $loginVisibility = '';
  109. $action = 'password' === $action ? 'password' : 'login';
  110. }
  111. } else {
  112. // error
  113. $error = $PMF_LANG['ad_auth_fail'];
  114. $loginVisibility = '';
  115. $action = 'password' === $action ? 'password' : 'login';
  116. }
  117. } else {
  118. // Try to authenticate with cookie information
  119. $user = PMF_User_CurrentUser::getFromCookie($faqConfig);
  120. // authenticate with session information
  121. if (! $user instanceof PMF_User_CurrentUser) {
  122. $user = PMF_User_CurrentUser::getFromSession($faqConfig);
  123. }
  124. if ($user instanceof PMF_User_CurrentUser) {
  125. $auth = true;
  126. } else {
  127. $user = new PMF_User_CurrentUser($faqConfig);
  128. }
  129. }
  130. //
  131. // Logout
  132. //
  133. if ('logout' === $action && isset($auth)) {
  134. $user->deleteFromSession(true);
  135. $auth = null;
  136. $action = 'main';
  137. $ssoLogout = $faqConfig->get('security.ssoLogoutRedirect');
  138. if ($faqConfig->get('security.ssoSupport') && !empty ($ssoLogout)) {
  139. $location = $ssoLogout;
  140. } else {
  141. $location = $faqConfig->get('main.referenceURL');
  142. }
  143. RedirectResponse::create($location)->send();
  144. exit;
  145. }
  146. //
  147. // Get current user and group id - default: -1
  148. //
  149. if (!is_null($user) && $user instanceof PMF_User_CurrentUser) {
  150. $current_user = $user->getUserId();
  151. if ($user->perm instanceof PMF_Perm_Medium) {
  152. $current_groups = $user->perm->getUserGroups($current_user);
  153. } else {
  154. $current_groups = array(-1);
  155. }
  156. if (0 == count($current_groups)) {
  157. $current_groups = array(-1);
  158. }
  159. } else {
  160. $current_user = -1;
  161. $current_groups = array(-1);
  162. }
  163. //
  164. // Use mbstring extension if available and when possible
  165. //
  166. $validMbStrings = array('ja', 'en', 'uni');
  167. $mbLanguage = ($PMF_LANG['metaLanguage'] != 'ja') ? 'uni' : $PMF_LANG['metaLanguage'];
  168. if (function_exists('mb_language') && in_array($mbLanguage, $validMbStrings)) {
  169. mb_language($mbLanguage);
  170. mb_internal_encoding('utf-8');
  171. }
  172. //
  173. // Found a session ID in _GET or _COOKIE?
  174. //
  175. $sid = null;
  176. $sidGet = PMF_Filter::filterInput(INPUT_GET, PMF_GET_KEY_NAME_SESSIONID, FILTER_VALIDATE_INT);
  177. $sidCookie = PMF_Filter::filterInput(INPUT_COOKIE, PMF_Session::PMF_COOKIE_NAME_SESSIONID, FILTER_VALIDATE_INT);
  178. $faqsession = new PMF_Session($faqConfig);
  179. // Note: do not track internal calls
  180. $internal = false;
  181. if (isset($_SERVER['HTTP_USER_AGENT'])) {
  182. $internal = (strpos($_SERVER['HTTP_USER_AGENT'], 'phpMyFAQ%2F') === 0);
  183. }
  184. if (!$internal) {
  185. if (is_null($sidGet) && is_null($sidCookie)) {
  186. // Create a per-site unique SID
  187. try {
  188. $faqsession->userTracking('new_session', 0);
  189. } catch (PMF_Exception $e) {
  190. $pmfExeptions[] = $e->getMessage();
  191. }
  192. } else {
  193. try {
  194. if (!is_null($sidCookie)) {
  195. $faqsession->checkSessionId($sidCookie, $_SERVER['REMOTE_ADDR']);
  196. } else {
  197. $faqsession->checkSessionId($sidGet, $_SERVER['REMOTE_ADDR']);
  198. }
  199. } catch (PMF_Exception $e) {
  200. $pmfExeptions[] = $e->getMessage();
  201. }
  202. }
  203. }
  204. //
  205. // Is user tracking activated?
  206. //
  207. $sids = '';
  208. if ($faqConfig->get('main.enableUserTracking')) {
  209. if (isset($sid)) {
  210. PMF_Session::setCookie(PMF_Session::PMF_COOKIE_NAME_SESSIONID, $sid);
  211. if (is_null($sidCookie)) {
  212. $sids = sprintf('sid=%d&amp;lang=%s&amp;', $sid, $LANGCODE);
  213. }
  214. } elseif (is_null($sidGet) || is_null($sidCookie)) {
  215. if (is_null($sidCookie)) {
  216. if (!is_null($sidGet)) {
  217. $sids = sprintf('sid=%d&amp;lang=%s&amp;', $sidGet, $LANGCODE);
  218. }
  219. }
  220. }
  221. } else {
  222. if (!PMF_Session::setCookie(PMF_Session::PMF_COOKIE_NAME_SESSIONID, $sid, $_SERVER['REQUEST_TIME'] + PMF_LANGUAGE_EXPIRED_TIME)) {
  223. $sids = sprintf('lang=%s&amp;', $LANGCODE);
  224. }
  225. }
  226. //
  227. // Found a article language?
  228. //
  229. $lang = PMF_Filter::filterInput(INPUT_POST, 'artlang', FILTER_SANITIZE_STRING);
  230. if (is_null($lang) && !PMF_Language::isASupportedLanguage($lang) ) {
  231. $lang = PMF_Filter::filterInput(INPUT_GET, 'artlang', FILTER_SANITIZE_STRING);
  232. if (is_null($lang) && !PMF_Language::isASupportedLanguage($lang) ) {
  233. $lang = $LANGCODE;
  234. }
  235. }
  236. //
  237. // Create a new FAQ object
  238. //
  239. $faq = new PMF_Faq($faqConfig);
  240. $faq->setUser($current_user);
  241. $faq->setGroups($current_groups);
  242. //
  243. // Create a new Category object
  244. //
  245. $category = new PMF_Category($faqConfig, $current_groups, true);
  246. $category->setUser($current_user);
  247. //
  248. // Create a new Tags object
  249. //
  250. $oTag = new PMF_Tags($faqConfig);
  251. //
  252. // Found a record ID?
  253. //
  254. $id = PMF_Filter::filterInput(INPUT_GET, 'id', FILTER_VALIDATE_INT);
  255. if (!is_null($id)) {
  256. $title = ' - ' . $faq->getRecordTitle($id);
  257. $keywords = ',' . $faq->getRecordKeywords($id);
  258. $metaDescription = $faq->getRecordPreview($id);
  259. } else {
  260. $id = '';
  261. $title = ' - powered by phpMyFAQ ' . $faqConfig->get('main.currentVersion');
  262. $keywords = '';
  263. $metaDescription = $faqConfig->get('main.metaDescription');
  264. }
  265. //
  266. // found a solution ID?
  267. //
  268. $solutionId = PMF_Filter::filterInput(INPUT_GET, 'solution_id', FILTER_VALIDATE_INT);
  269. if (! is_null($solutionId)) {
  270. $title = ' - powered by phpMyFAQ ' . $faqConfig->get('main.currentVersion');
  271. $keywords = '';
  272. $faqData = $faq->getIdFromSolutionId($solutionId);
  273. if (is_array($faqData)) {
  274. $id = $faqData['id'];
  275. $lang = $faqData['lang'];
  276. $title = ' - ' . $faq->getRecordTitle($id);
  277. $keywords = ',' . $faq->getRecordKeywords($id);
  278. $metaDescription = str_replace('"', '', PMF_Utils::makeShorterText(strip_tags($faqData['content']), 12));
  279. }
  280. }
  281. //
  282. // Handle the Tagging ID
  283. //
  284. $tag_id = PMF_Filter::filterInput(INPUT_GET, 'tagging_id', FILTER_VALIDATE_INT);
  285. if (!is_null($tag_id)) {
  286. $title = ' - ' . $oTag->getTagNameById($tag_id);
  287. $keywords = '';
  288. }
  289. //
  290. // Handle the SiteMap
  291. //
  292. $letter = PMF_Filter::filterInput(INPUT_GET, 'letter', FILTER_SANITIZE_STRIPPED);
  293. if (!is_null($letter) && (1 == PMF_String::strlen($letter))) {
  294. $title = ' - ' . $letter . '...';
  295. $keywords = $letter;
  296. }
  297. //
  298. // Found a category ID?
  299. //
  300. $cat = PMF_Filter::filterInput(INPUT_GET, 'cat', FILTER_VALIDATE_INT, 0);
  301. $cat_from_id = -1;
  302. if (is_numeric($id) && $id > 0) {
  303. $cat_from_id = $category->getCategoryIdFromArticle($id);
  304. }
  305. if ($cat_from_id != -1 && $cat == 0) {
  306. $cat = $cat_from_id;
  307. }
  308. $category->transform(0);
  309. $category->collapseAll();
  310. if ($cat != 0) {
  311. $category->expandTo($cat);
  312. }
  313. if (isset($cat) && ($cat != 0) && ($id == '') && isset($category->categoryName[$cat]['name'])) {
  314. $title = ' - '.$category->categoryName[$cat]['name'];
  315. }
  316. //
  317. // Found an action request?
  318. //
  319. if (!isset($allowedVariables[$action])) {
  320. $action = 'main';
  321. }
  322. //
  323. // Select the template for the requested page
  324. //
  325. if ($action != 'main') {
  326. $includeTemplate = $action . '.tpl';
  327. $includePhp = $action . '.php';
  328. $writeLangAdress = '?sid=' . $sid;
  329. } else {
  330. if (isset($solutionId) && is_numeric($solutionId)) {
  331. // show the record with the solution ID
  332. $includeTemplate = 'artikel.tpl';
  333. $includePhp = 'artikel.php';
  334. } else {
  335. $includeTemplate = 'main.tpl';
  336. $includePhp = 'main.php';
  337. }
  338. $writeLangAdress = '?sid=' . $sid;
  339. }
  340. //
  341. // Set right column
  342. //
  343. // Check in any tags with at least one entry exist
  344. //
  345. $hasTags = $oTag->existTagRelations();
  346. if ($hasTags && (($action == 'artikel') || ($action == 'show'))) {
  347. $rightSidebarTemplate = $action == 'artikel' ? 'catandtag.tpl' : 'tagcloud.tpl';
  348. } else {
  349. $rightSidebarTemplate = 'startpage.tpl';
  350. }
  351. //
  352. // Check if FAQ should be secured
  353. //
  354. if ($faqConfig->get('security.enableLoginOnly')) {
  355. if ($auth) {
  356. $indexSet = 'index.tpl';
  357. } else {
  358. switch($action) {
  359. case 'register':
  360. case 'thankyou':
  361. $indexSet = 'indexNewUser.tpl';
  362. break;
  363. case 'password':
  364. $indexSet = 'indexPassword.tpl';
  365. break;
  366. default:
  367. $indexSet = 'indexLogin.tpl';
  368. break;
  369. }
  370. }
  371. } else {
  372. $indexSet = 'index.tpl';
  373. }
  374. //
  375. // phpMyFAQ installtion is in maintenance mode
  376. //
  377. if ($faqConfig->get('main.maintenanceMode')) {
  378. $indexSet = 'indexMaintenance.tpl';
  379. }
  380. //
  381. // Load template files and set template variables
  382. //
  383. $tpl = new PMF_Template(
  384. array(
  385. 'index' => $indexSet,
  386. 'rightBox' => $rightSidebarTemplate,
  387. 'writeContent' => $includeTemplate
  388. ),
  389. $faqConfig->get('main.templateSet')
  390. );
  391. if ($faqConfig->get('main.enableUserTracking')) {
  392. $users = $faqsession->getUsersOnline();
  393. $totUsers = $users[0] + $users[1];
  394. $usersOnline = $plr->getMsg('plmsgUserOnline', $totUsers) . ' | ' .
  395. $plr->getMsg('plmsgGuestOnline', $users[0]) .
  396. $plr->getMsg('plmsgRegisteredOnline',$users[1]);
  397. } else {
  398. $usersOnline = '';
  399. }
  400. $faqSystem = new PMF_System();
  401. $categoryHelper = new PMF_Helper_Category();
  402. $categoryHelper->setCategory($category);
  403. $categoryHelper->setConfiguration($faqConfig);
  404. $keywordsArray = array_merge(explode(',', $keywords), explode(',', $faqConfig->get('main.metaKeywords')));
  405. $keywordsArray = array_filter($keywordsArray, 'strlen');
  406. shuffle($keywordsArray);
  407. $keywords = implode(',', $keywordsArray);
  408. $faqLink = new PMF_Link($faqSystem->getSystemUri($faqConfig), $faqConfig);
  409. $currentPageUrl = $faqLink->getCurrentUrl();
  410. if (is_null($error)) {
  411. $loginMessage = '<p>' . $PMF_LANG['ad_auth_insert'] . '</p>';
  412. } else {
  413. $loginMessage = '<p class="error">' . $error . '</p>';
  414. }
  415. $tplMainPage = array(
  416. 'msgLoginUser' => $PMF_LANG['msgLoginUser'],
  417. 'title' => $faqConfig->get('main.titleFAQ') . $title,
  418. 'baseHref' => $faqSystem->getSystemUri($faqConfig),
  419. 'version' => $faqConfig->get('main.currentVersion'),
  420. 'header' => str_replace('"', '', $faqConfig->get('main.titleFAQ')),
  421. 'metaTitle' => str_replace('"', '', $faqConfig->get('main.titleFAQ') . $title),
  422. 'metaDescription' => $metaDescription,
  423. 'metaKeywords' => $keywords,
  424. 'metaPublisher' => $faqConfig->get('main.metaPublisher'),
  425. 'metaLanguage' => $PMF_LANG['metaLanguage'],
  426. 'metaCharset' => 'utf-8', // backwards compability
  427. 'phpmyfaqversion' => $faqConfig->get('main.currentVersion'),
  428. 'stylesheet' => $PMF_LANG['dir'] == 'rtl' ? 'style.rtl' : 'style',
  429. 'currentPageUrl' => $currentPageUrl,
  430. 'action' => $action,
  431. 'dir' => $PMF_LANG['dir'],
  432. 'headerCategories' => $PMF_LANG['msgFullCategories'],
  433. 'msgCategory' => $PMF_LANG['msgCategory'],
  434. 'msgExportAllFaqs' => $PMF_LANG['msgExportAllFaqs'],
  435. 'languageBox' => $PMF_LANG['msgLangaugeSubmit'],
  436. 'writeLangAdress' => $writeLangAdress,
  437. 'switchLanguages' => PMF_Language::selectLanguages($LANGCODE, true),
  438. 'userOnline' => $usersOnline,
  439. 'copyright' => 'powered by <a href="http://www.phpmyfaq.de" target="_blank">phpMyFAQ</a> ' .
  440. $faqConfig->get('main.currentVersion'),
  441. 'registerUser' => '<a href="?action=register">' . $PMF_LANG['msgRegistration'] . '</a>',
  442. 'sendPassword' => '<a href="?action=password">' . $PMF_LANG['lostPassword'] . '</a>',
  443. 'loginHeader' => $PMF_LANG['msgLoginUser'],
  444. 'loginMessage' => $loginMessage,
  445. 'writeLoginPath' => $faqSystem->getSystemUri($faqConfig) . '?' . PMF_Filter::getFilteredQueryString(),
  446. 'faqloginaction' => $action,
  447. 'login' => $PMF_LANG['ad_auth_ok'],
  448. 'username' => $PMF_LANG['ad_auth_user'],
  449. 'password' => $PMF_LANG['ad_auth_passwd'],
  450. 'rememberMe' => $PMF_LANG['rememberMe'],
  451. 'headerChangePassword' => $PMF_LANG['ad_passwd_cop'],
  452. 'msgUsername' => $PMF_LANG['ad_auth_user'],
  453. 'msgEmail' => $PMF_LANG['ad_entry_email'],
  454. 'msgSubmit' => $PMF_LANG['msgNewContentSubmit']
  455. );
  456. $tpl->parseBlock(
  457. 'index',
  458. 'categoryListSection',
  459. array(
  460. 'showCategories' => $categoryHelper->renderNavigation($cat),
  461. 'categoryDropDown' => $categoryHelper->renderCategoryDropDown($cat)
  462. )
  463. );
  464. if ('main' == $action || 'show' == $action) {
  465. if ('main' == $action && $faqConfig->get('search.useAjaxSearchOnStartpage')) {
  466. $tpl->parseBlock(
  467. 'index',
  468. 'globalSuggestBox',
  469. array(
  470. 'ajaxlanguage' => $LANGCODE,
  471. 'msgDescriptionInstantResponse' => $PMF_LANG['msgDescriptionInstantResponse'],
  472. 'msgSearch' => sprintf(
  473. '<a class="help" href="%sindex.php?action=search">%s</a>',
  474. $faqSystem->getSystemUri($faqConfig),
  475. $PMF_LANG["msgAdvancedSearch"]
  476. )
  477. )
  478. );
  479. } else {
  480. $tpl->parseBlock(
  481. 'index',
  482. 'globalSearchBox',
  483. array(
  484. 'writeSendAdress' => '?'.$sids.'action=search',
  485. 'searchBox' => $PMF_LANG['msgSearch'],
  486. 'categoryId' => ($cat === 0) ? '%' : (int)$cat,
  487. 'msgSearch' => sprintf(
  488. '<a class="help" href="%sindex.php?action=search">%s</a>',
  489. $faqSystem->getSystemUri($faqConfig),
  490. $PMF_LANG["msgAdvancedSearch"]
  491. )
  492. )
  493. );
  494. }
  495. }
  496. $stickyRecordsParams = $faq->getStickyRecords();
  497. if (!isset($stickyRecordsParams['error'])) {
  498. $tpl->parseBlock(
  499. 'index',
  500. 'stickyFaqs',
  501. array(
  502. 'stickyRecordsHeader' => $PMF_LANG['stickyRecordsHeader'],
  503. 'stickyRecordsList' => $stickyRecordsParams['html']
  504. )
  505. );
  506. }
  507. if ($faqConfig->get('main.enableRewriteRules')) {
  508. $tplNavigation = array(
  509. "msgSearch" => '<a href="' . $faqSystem->getSystemUri($faqConfig) . 'search.html">'.$PMF_LANG["msgAdvancedSearch"].'</a>',
  510. 'msgAddContent' => '<a href="' . $faqSystem->getSystemUri($faqConfig) . 'addcontent.html">'.$PMF_LANG["msgAddContent"].'</a>',
  511. "msgQuestion" => '<a href="' . $faqSystem->getSystemUri($faqConfig) . 'ask.html">'.$PMF_LANG["msgQuestion"].'</a>',
  512. "msgOpenQuestions" => '<a href="' . $faqSystem->getSystemUri($faqConfig) . 'open.html">'.$PMF_LANG["msgOpenQuestions"].'</a>',
  513. 'msgHelp' => '<a href="' . $faqSystem->getSystemUri($faqConfig) . 'help.html">'.$PMF_LANG["msgHelp"].'</a>',
  514. "msgContact" => '<a href="' . $faqSystem->getSystemUri($faqConfig) . 'contact.html">'.$PMF_LANG["msgContact"].'</a>',
  515. 'msgGlossary' => '<a href="' . $faqSystem->getSystemUri($faqConfig) . 'glossary.html">' . $PMF_LANG['ad_menu_glossary'] . '</a>',
  516. "backToHome" => '<a href="' . $faqSystem->getSystemUri($faqConfig) . 'index.html">'.$PMF_LANG["msgHome"].'</a>',
  517. "allCategories" => '<a href="' . $faqSystem->getSystemUri($faqConfig) . 'showcat.html">'.$PMF_LANG["msgShowAllCategories"].'</a>',
  518. 'showInstantResponse' => '<a href="' . $faqSystem->getSystemUri($faqConfig) . 'instantresponse.html">'.$PMF_LANG['msgInstantResponse'].'</a>',
  519. 'showSitemap' => '<a href="' . $faqSystem->getSystemUri($faqConfig) . 'sitemap/A/'.$LANGCODE.'.html">'.$PMF_LANG['msgSitemap'].'</a>',
  520. 'opensearch' => $faqSystem->getSystemUri($faqConfig) . 'opensearch.html');
  521. } else {
  522. $tplNavigation = array(
  523. "msgSearch" => '<a href="index.php?'.$sids.'action=search">'.$PMF_LANG["msgAdvancedSearch"].'</a>',
  524. "msgAddContent" => '<a href="index.php?'.$sids.'action=add&cat='.$cat.'">'.$PMF_LANG["msgAddContent"].'</a>',
  525. "msgQuestion" => '<a href="index.php?'.$sids.'action=ask&category_id='.$cat.'">'.$PMF_LANG["msgQuestion"].'</a>',
  526. "msgOpenQuestions" => '<a href="index.php?'.$sids.'action=open">'.$PMF_LANG["msgOpenQuestions"].'</a>',
  527. "msgHelp" => '<a href="index.php?'.$sids.'action=help">'.$PMF_LANG["msgHelp"].'</a>',
  528. "msgContact" => '<a href="index.php?'.$sids.'action=contact">'.$PMF_LANG["msgContact"].'</a>',
  529. 'msgGlossary' => '<a href="index.php?'.$sids.'action=glossary">' . $PMF_LANG['ad_menu_glossary'] . '</a>',
  530. "allCategories" => '<a href="index.php?'.$sids.'action=show">'.$PMF_LANG["msgShowAllCategories"].'</a>',
  531. "backToHome" => '<a href="index.php?'.$sids.'">'.$PMF_LANG["msgHome"].'</a>',
  532. 'showInstantResponse' => '<a href="index.php?'.$sids.'action=instantresponse">'.$PMF_LANG['msgInstantResponse'].'</a>',
  533. 'showSitemap' => '<a href="index.php?'.$sids.'action=sitemap&amp;lang='.$LANGCODE.'">'.$PMF_LANG['msgSitemap'].'</a>',
  534. 'opensearch' => $faqSystem->getSystemUri($faqConfig) . 'opensearch.php');
  535. }
  536. $tplNavigation['faqHome'] = $faqConfig->get('main.referenceURL');
  537. $tplNavigation['activeQuickfind'] = ('instantresponse' == $action) ? 'active' : '';
  538. $tplNavigation['activeAddContent'] = ('add' == $action) ? 'active' : '';
  539. $tplNavigation['activeAddQuestion'] = ('ask' == $action) ? 'active' : '';
  540. $tplNavigation['activeOpenQuestions'] = ('open' == $action) ? 'active' : '';
  541. //
  542. // Show login box or logged-in user information
  543. //
  544. if (isset($auth)) {
  545. if (count($user->perm->getAllUserRights($user->getUserId()))) {
  546. $adminSection = sprintf(
  547. '<a href="%s">%s</a>',
  548. $faqSystem->getSystemUri($faqConfig) . 'admin/index.php',
  549. $PMF_LANG['adminSection']
  550. );
  551. } else {
  552. $adminSection = sprintf(
  553. '<a href="%s">%s</a>',
  554. $faqSystem->getSystemUri($faqConfig) . 'index.php?action=ucp',
  555. $PMF_LANG['headerUserControlPanel']
  556. );
  557. }
  558. $tpl->parseBlock(
  559. 'index',
  560. 'userloggedIn',
  561. array(
  562. 'msgUserControl' => $adminSection,
  563. 'msgFullName' => $PMF_LANG['ad_user_loggedin'] . $user->getLogin(),
  564. 'msgLoginName' => $user->getUserData('display_name'),
  565. 'msgUserControlDropDown' => '<a href="?action=ucp">' . $PMF_LANG['headerUserControlPanel'] . '</a>',
  566. 'msgLogoutUser' => '<a href="?action=logout">' . $PMF_LANG['ad_menu_logout'] . '</a>',
  567. 'activeUserControl' => ('ucp' == $action) ? 'active' : ''
  568. )
  569. );
  570. } else {
  571. if ($faqConfig->get('main.maintenanceMode')) {
  572. $msgLoginUser = '<a href="./admin/">%s</a>';
  573. } else {
  574. $msgLoginUser = '<a href="?action=login">%s</a>';
  575. }
  576. $tpl->parseBlock(
  577. 'index',
  578. 'notLoggedIn',
  579. array(
  580. 'msgRegisterUser' => '<a href="?action=register">' . $PMF_LANG['msgRegisterUser'] . '</a>',
  581. 'msgLoginUser' => sprintf($msgLoginUser, $PMF_LANG['msgLoginUser']),
  582. 'activeRegister' => ('register' == $action) ? 'active' : '',
  583. 'activeLogin' => ('login' == $action) ? 'active' : ''
  584. )
  585. );
  586. }
  587. // generate top ten list
  588. if ($faqConfig->get('records.orderingPopularFaqs') == 'visits') {
  589. $param = 'visits';
  590. } else {
  591. $param = 'voted';
  592. }
  593. $toptenParams = $faq->getTopTen($param);
  594. if (!isset($toptenParams['error'])) {
  595. $tpl->parseBlock(
  596. 'rightBox',
  597. 'toptenList',
  598. array(
  599. 'toptenUrl' => $toptenParams['url'],
  600. 'toptenTitle' => $toptenParams['title'],
  601. 'toptenPreview' => $toptenParams['preview'],
  602. 'toptenVisits' => $toptenParams[$param]
  603. )
  604. );
  605. } else {
  606. $tpl->parseBlock(
  607. 'rightBox',
  608. 'toptenListError',
  609. array(
  610. 'errorMsgTopTen' => $toptenParams['error']
  611. )
  612. );
  613. }
  614. $latestEntriesParams = $faq->getLatest();
  615. if (!isset($latestEntriesParams['error'])) {
  616. $tpl->parseBlock(
  617. 'rightBox',
  618. 'latestEntriesList',
  619. array(
  620. 'latestEntriesUrl' => $latestEntriesParams['url'],
  621. 'latestEntriesTitle' => $latestEntriesParams['title'],
  622. 'latestEntriesPreview' => $latestEntriesParams['preview'],
  623. 'latestEntriesDate' => $latestEntriesParams['date']
  624. )
  625. );
  626. } else {
  627. $tpl->parseBlock('rightBox', 'latestEntriesListError', array(
  628. 'errorMsgLatest' => $latestEntriesParams['error'])
  629. );
  630. }
  631. if ('artikel' == $action || 'show' == $action || is_numeric($solutionId)) {
  632. // We need some Links from social networks
  633. $faqServices = new PMF_Services($faqConfig);
  634. $faqServices->setCategoryId($cat);
  635. $faqServices->setFaqId($id);
  636. $faqServices->setLanguage($lang);
  637. $faqServices->setQuestion($faq->getRecordTitle($id));
  638. $faqHelper = new PMF_Helper_Faq($faqConfig);
  639. $faqHelper->setSsl((isset($_SERVER['HTTPS']) && is_null($_SERVER['HTTPS']) ? false : true));
  640. $tpl->parseBlock(
  641. 'rightBox',
  642. 'socialLinks',
  643. array(
  644. 'writePDFTag' => $PMF_LANG['msgPDF'],
  645. 'writePrintMsgTag' => $PMF_LANG['msgPrintArticle'],
  646. 'writeSend2FriendMsgTag' => $PMF_LANG['msgSend2Friend'],
  647. 'shareOnFacebook' => $faqHelper->renderFacebookShareLink($faqServices->getShareOnFacebookLink()),
  648. 'shareOnTwitter' => $faqHelper->renderTwitterShareLink($faqServices->getShareOnTwitterLink()),
  649. 'link_email' => $faqServices->getSuggestLink(),
  650. 'link_pdf' => $faqServices->getPdfLink(),
  651. 'facebookLikeButton' => $faqHelper->renderFacebookLikeButton($faqServices->getLink())
  652. )
  653. );
  654. }
  655. $tpl->parse(
  656. 'rightBox',
  657. array(
  658. 'writeTopTenHeader' => $PMF_LANG['msgTopTen'],
  659. 'writeNewestHeader' => $PMF_LANG['msgLatestArticles'],
  660. 'writeTagCloudHeader' => $PMF_LANG['msg_tags'],
  661. 'writeTags' => $oTag->printHTMLTagsCloud(),
  662. 'msgAllCatArticles' => $PMF_LANG['msgAllCatArticles'],
  663. 'allCatArticles' => $faq->showAllRecordsWoPaging($cat)
  664. )
  665. );
  666. if (DEBUG) {
  667. $tpl->parseBlock(
  668. 'index',
  669. 'debugMode',
  670. array(
  671. 'debugExceptions' => implode('<br>', $pmfExeptions),
  672. 'debugQueries' => $faqConfig->getDb()->log()
  673. )
  674. );
  675. }
  676. //
  677. // Get main template, set main variables
  678. //
  679. $tpl->parse('index', array_merge($tplMainPage, $tplNavigation));
  680. $tpl->merge('rightBox', 'index');
  681. //
  682. // Include requested PHP file
  683. //
  684. require_once $includePhp;
  685. //
  686. // Prepate the response
  687. //
  688. $response = Response::create();
  689. //
  690. // Send headers and print template
  691. //
  692. $responseWrapper = new ResponseWrapper($response);
  693. $responseWrapper->addContentTypeHeader('text/html');
  694. $responseWrapper->addCommonHeaders();
  695. $response->setContent($tpl->render());
  696. $response->send();
  697. $faqConfig->getDb()->close();