PageRenderTime 54ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/phpmyfaq/index.php

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