PageRenderTime 49ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/phpmyfaq/index.php

https://github.com/max-koehler/phpMyFAQ
PHP | 688 lines | 465 code | 62 blank | 161 comment | 128 complexity | 302e9bc3750ddbf3924e0210738ff718 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1
  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.2
  9. *
  10. * The contents of this file are subject to the Mozilla Public License
  11. * Version 1.1 (the "License"); you may not use this file except in
  12. * compliance with the License. You may obtain a copy of the License at
  13. * http://www.mozilla.org/MPL/
  14. *
  15. * Software distributed under the License is distributed on an "AS IS"
  16. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  17. * License for the specific language governing rights and limitations
  18. * under the License.
  19. *
  20. * @category phpMyFAQ
  21. * @package Frontend
  22. * @author Thorsten Rinne <thorsten@phpmyfaq.de>
  23. * @author Lars Tiedemann <php@larstiedemann.de>
  24. * @author Matteo Scaramuccia <matteo@phpmyfaq.de>
  25. * @copyright 2001-2010 phpMyFAQ Team
  26. * @license http://www.mozilla.org/MPL/MPL-1.1.html Mozilla Public License Version 1.1
  27. * @link http://www.phpmyfaq.de
  28. * @since 2001-02-12
  29. */
  30. //
  31. // Check if config/database.php exist -> if not, redirect to installer
  32. //
  33. if (!file_exists('config/database.php')) {
  34. header("Location: install/setup.php");
  35. exit();
  36. }
  37. //
  38. // Define the named constant used as a check by any included PHP file
  39. //
  40. define('IS_VALID_PHPMYFAQ', null);
  41. //
  42. // Autoload classes, prepend and start the PHP session
  43. //
  44. require_once 'inc/Init.php';
  45. PMF_Init::cleanRequest();
  46. session_name(PMF_COOKIE_NAME_AUTH . trim($faqconfig->get('main.phpMyFAQToken')));
  47. session_start();
  48. //
  49. // Get language (default: english)
  50. //
  51. $Language = new PMF_Language();
  52. $LANGCODE = $Language->setLanguage($faqconfig->get('main.languageDetection'), $faqconfig->get('main.language'));
  53. // Preload English strings
  54. require_once 'lang/language_en.php';
  55. $showCaptcha = PMF_Filter::filterInput(INPUT_GET, 'gen', FILTER_SANITIZE_STRING);
  56. if (isset($LANGCODE) && PMF_Language::isASupportedLanguage($LANGCODE) && is_null($showCaptcha)) {
  57. // Overwrite English strings with the ones we have in the current language,
  58. // but don't include UTF-8 encoded files, these will break the captcha images
  59. require_once 'lang/language_'.$LANGCODE.'.php';
  60. } else {
  61. $LANGCODE = 'en';
  62. }
  63. //Load plurals support for selected language
  64. $plr = new PMF_Language_Plurals($PMF_LANG);
  65. //
  66. // Initalizing static string wrapper
  67. //
  68. PMF_String::init($LANGCODE);
  69. /**
  70. * Initialize attachment factory
  71. */
  72. PMF_Attachment_Factory::init($faqconfig->get('main.attachmentsStorageType'),
  73. $faqconfig->get('main.defaultAttachmentEncKey'),
  74. $faqconfig->get('main.enableAttachmentEncryption'));
  75. //
  76. // Get user action
  77. //
  78. $action = PMF_Filter::filterInput(INPUT_GET, 'action', FILTER_SANITIZE_STRING, 'main');
  79. //
  80. // Authenticate current user
  81. //
  82. $auth = null;
  83. $error = '';
  84. $faqusername = PMF_Filter::filterInput(INPUT_POST, 'faqusername', FILTER_SANITIZE_STRING);
  85. $faqpassword = PMF_Filter::filterInput(INPUT_POST, 'faqpassword', FILTER_SANITIZE_STRING);
  86. if (!is_null($faqusername) && !is_null($faqpassword)) {
  87. $user = new PMF_User_CurrentUser();
  88. if ($faqconfig->get('main.ldapSupport')) {
  89. $authLdap = new PMF_Auth_AuthLdap();
  90. $user->addAuth($authLdap, 'ldap');
  91. }
  92. if ($user->login($faqusername, $faqpassword)) {
  93. if ($user->getStatus() != 'blocked') {
  94. $auth = true;
  95. } else {
  96. $error = $PMF_LANG["ad_auth_fail"]." (".$faqusername." / *)";
  97. $user = null;
  98. }
  99. } else {
  100. // error
  101. $error = sprintf(
  102. '%s<br /><a href="admin/password.php" title="%s">%s</a>',
  103. $PMF_LANG['ad_auth_fail'],
  104. $PMF_LANG['lostPassword'],
  105. $PMF_LANG['lostPassword']
  106. );
  107. $user = null;
  108. }
  109. $action = 'main';
  110. } else {
  111. // authenticate with session information
  112. $user = PMF_User_CurrentUser::getFromSession($faqconfig->get('main.ipCheck'));
  113. if ($user) {
  114. $auth = true;
  115. } else {
  116. $user = null;
  117. }
  118. }
  119. //
  120. // Get current user rights
  121. //
  122. $permission = array();
  123. if (isset($auth)) {
  124. // read all rights, set them FALSE
  125. $allRights = $user->perm->getAllRightsData();
  126. foreach ($allRights as $right) {
  127. $permission[$right['name']] = false;
  128. }
  129. // check user rights, set them TRUE
  130. $allUserRights = $user->perm->getAllUserRights($user->getUserId());
  131. foreach ($allRights as $right) {
  132. if (in_array($right['right_id'], $allUserRights))
  133. $permission[$right['name']] = true;
  134. }
  135. }
  136. //
  137. // Logout
  138. //
  139. if ('logout' === $action && isset($auth)) {
  140. $user->deleteFromSession();
  141. $user = null;
  142. $auth = null;
  143. $action = 'main';
  144. }
  145. //
  146. // Get current user and group id - default: -1
  147. //
  148. if (!is_null($user) && $user instanceof PMF_User_CurrentUser) {
  149. $current_user = $user->getUserId();
  150. if ($user->perm instanceof PMF_Perm_PermMedium) {
  151. $current_groups = $user->perm->getUserGroups($current_user);
  152. } else {
  153. $current_groups = array(-1);
  154. }
  155. if (0 == count($current_groups)) {
  156. $current_groups = array(-1);
  157. }
  158. } else {
  159. $current_user = -1;
  160. $current_groups = array(-1);
  161. }
  162. //
  163. // Use mbstring extension if available and when possible
  164. //
  165. $valid_mb_strings = array('ja', 'en', 'uni');
  166. $mbLanguage = ($PMF_LANG['metaLanguage'] != 'ja') ? 'uni' : $PMF_LANG['metaLanguage'];
  167. if (function_exists('mb_language') && in_array($mbLanguage, $valid_mb_strings)) {
  168. mb_language($mbLanguage);
  169. mb_internal_encoding('utf-8');
  170. }
  171. //
  172. // Found a session ID in _GET or _COOKIE?
  173. //
  174. $sid = null;
  175. $sid_get = PMF_Filter::filterInput(INPUT_GET, PMF_GET_KEY_NAME_SESSIONID, FILTER_VALIDATE_INT);
  176. $sid_cookie = PMF_Filter::filterInput(INPUT_COOKIE, PMF_COOKIE_NAME_SESSIONID, FILTER_VALIDATE_INT);
  177. $faqsession = new PMF_Session();
  178. // Note: do not track internal calls
  179. $internal = false;
  180. if (isset($_SERVER['HTTP_USER_AGENT'])) {
  181. $internal = (strpos($_SERVER['HTTP_USER_AGENT'], 'phpMyFAQ%2F') === 0);
  182. }
  183. if (!$internal) {
  184. if (is_null($sid_get) && is_null($sid_cookie)) {
  185. // Create a per-site unique SID
  186. $faqsession->userTracking('new_session', 0);
  187. } else {
  188. if (!is_null($sid_cookie)) {
  189. $faqsession->checkSessionId($sid_cookie, $_SERVER['REMOTE_ADDR']);
  190. } else {
  191. $faqsession->checkSessionId($sid_get, $_SERVER['REMOTE_ADDR']);
  192. }
  193. }
  194. }
  195. //
  196. // Is user tracking activated?
  197. //
  198. $sids = '';
  199. if ($faqconfig->get('main.enableUserTracking')) {
  200. if (isset($sid)) {
  201. PMF_Session::setCookie($sid);
  202. if (is_null($sid_cookie)) {
  203. $sids = sprintf('sid=%d&amp;lang=%s&amp;', $sid, $LANGCODE);
  204. }
  205. } elseif (is_null($sid_get) || is_null($sid_cookie)) {
  206. if (is_null($sid_cookie)) {
  207. if (!is_null($sid_get)) {
  208. $sids = sprintf('sid=%d&amp;lang=%s&amp;', $sid_get, $LANGCODE);
  209. }
  210. }
  211. }
  212. } else {
  213. if (!setcookie(PMF_GET_KEY_NAME_LANGUAGE, $LANGCODE, $_SERVER['REQUEST_TIME'] + PMF_LANGUAGE_EXPIRED_TIME)) {
  214. $sids = sprintf('lang=%s&amp;', $LANGCODE);
  215. }
  216. }
  217. //
  218. // Found a article language?
  219. //
  220. $lang = PMF_Filter::filterInput(INPUT_POST, 'artlang', FILTER_SANITIZE_STRING);
  221. if (is_null($lang) && !PMF_Language::isASupportedLanguage($lang) ) {
  222. $lang = $LANGCODE;
  223. }
  224. //
  225. // Create a new FAQ object
  226. //
  227. $faq = new PMF_Faq($current_user, $current_groups);
  228. //
  229. // Create a new Category data provider
  230. //
  231. $categoryData = new PMF_Category_Tree_DataProvider_SingleQuery($LANGCODE);
  232. //
  233. // Create a new Tags object
  234. //
  235. $oTag = new PMF_Tags();
  236. //
  237. // Found a record ID?
  238. //
  239. $id = PMF_Filter::filterInput(INPUT_GET, 'id', FILTER_VALIDATE_INT);
  240. if (!is_null($id)) {
  241. $title = ' - ' . $faq->getRecordTitle($id);
  242. $keywords = ',' . $faq->getRecordKeywords($id);
  243. $metaDescription = $faq->getRecordPreview($id);
  244. } else {
  245. $id = '';
  246. $title = ' - powered by phpMyFAQ ' . $faqconfig->get('main.currentVersion');
  247. $keywords = '';
  248. $metaDescription = $faqconfig->get('main.metaDescription');
  249. }
  250. //
  251. // found a solution ID?
  252. //
  253. $solution_id = PMF_Filter::filterInput(INPUT_GET, 'solution_id', FILTER_VALIDATE_INT);
  254. if (!is_null($solution_id)) {
  255. $title = ' - powered by phpMyFAQ ' . $faqconfig->get('main.currentVersion');
  256. $keywords = '';
  257. $faqData = $faq->getIdFromSolutionId($solution_id);
  258. if (is_array($faqData)) {
  259. $id = $faqData['id'];
  260. $lang = $faqData['lang'];
  261. $title = ' - ' . $faq->getRecordTitle($id);
  262. $keywords = ',' . $faq->getRecordKeywords($id);
  263. $metaDescription = PMF_Utils::makeShorterText(strip_tags($faqData['content']), 12);
  264. }
  265. }
  266. //
  267. // Handle the Tagging ID
  268. //
  269. $tag_id = PMF_Filter::filterInput(INPUT_GET, 'tagging_id', FILTER_VALIDATE_INT);
  270. if (!is_null($tag_id)) {
  271. $title = ' - ' . $oTag->getTagNameById($tag_id);
  272. $keywords = '';
  273. }
  274. //
  275. // Handle the SiteMap
  276. //
  277. $letter = PMF_Filter::filterInput(INPUT_GET, 'letter', FILTER_SANITIZE_STRIPPED);
  278. if (!is_null($letter) && (1 == PMF_String::strlen($letter))) {
  279. $title = ' - ' . $letter . '...';
  280. $keywords = $letter;
  281. }
  282. //
  283. // Found a category ID?
  284. //
  285. $cat = PMF_Filter::filterInput(INPUT_GET, 'cat', FILTER_VALIDATE_INT, 0);
  286. $cat_from_id = -1;
  287. $categoryPath = array(0);
  288. if (is_numeric($id) && $id > 0) {
  289. $categoryRelations = new PMF_Category_Relations();
  290. foreach ($categoryRelations->fetchAll() as $relation) {
  291. if ($relation->record_id == $id) {
  292. $cat_from_id = $relation->category_id;
  293. break;
  294. }
  295. }
  296. }
  297. if ($cat_from_id != -1 && $cat == 0) {
  298. $cat = $cat_from_id;
  299. }
  300. if ($cat != 0) {
  301. $categoryPath = $categoryData->getPath($cat);
  302. }
  303. /* @todo: Fix this old code
  304. if (isset($cat) && ($cat != 0) && ($id == '') && isset($category->categoryName[$cat]['name'])) {
  305. $title = ' - '.$category->categoryName[$cat]['name'];
  306. }
  307. */
  308. //
  309. // Found an action request?
  310. //
  311. if (!isset($allowedVariables[$action])) {
  312. $action = 'main';
  313. }
  314. //
  315. // Select the template for the requested page
  316. //
  317. if (isset($auth)) {
  318. $login_tpl = 'loggedin.tpl';
  319. } else {
  320. if (isset($_SERVER['HTTPS']) || !$faqconfig->get('main.useSslForLogins')) {
  321. $login_tpl = 'loginbox.tpl';
  322. } else {
  323. $login_tpl = 'secureswitch.tpl';
  324. }
  325. }
  326. if ($action != 'main') {
  327. $inc_tpl = $action . '.tpl';
  328. $inc_php = $action . ".php";
  329. $writeLangAdress = "?" . PMF_Filter::getFilteredQueryString();
  330. } else {
  331. if (isset($solution_id) && is_numeric($solution_id)) {
  332. // show the record with the solution ID
  333. $inc_tpl = 'artikel.tpl';
  334. $inc_php = 'artikel.php';
  335. } else {
  336. $inc_tpl = 'main.tpl';
  337. $inc_php = 'main.php';
  338. }
  339. if($faqconfig->get('main.useAjaxMenu')) {
  340. $writeLangAdress = "?";
  341. }
  342. else {
  343. $writeLangAdress = '?'.(int)$sids;
  344. }
  345. }
  346. //
  347. // Set right column
  348. //
  349. // Check in any tags with at leat one entry exist
  350. $hasTags = $oTag->existTagRelations();
  351. if ($hasTags && (($action == 'artikel') || ($action == 'show'))) {
  352. $right_tpl = $action == 'artikel' ? 'catandtag.tpl' : 'tagcloud.tpl';
  353. } else {
  354. $right_tpl = 'startpage.tpl';
  355. }
  356. //
  357. // Load template files and set template variables
  358. // Check on mobile devices first, if iPhone detected, switch to iPhone layout
  359. //
  360. /*
  361. if (stristr($_SERVER['HTTP_USER_AGENT'], 'iPhone')) {
  362. $templateSet = 'mobile';
  363. } else {
  364. $templateSet = $faqconfig->get('main.templateSet');
  365. }
  366. */
  367. $tpl = new PMF_Template(array('index' => 'index.tpl',
  368. 'loginBox' => $login_tpl,
  369. 'rightBox' => $right_tpl,
  370. 'writeContent' => $inc_tpl),
  371. $faqconfig->get('main.templateSet'));
  372. $tpl->ajax_active = $faqconfig->get('main.useAjaxMenu');
  373. if ($tpl->ajax_active) {
  374. switch ($_SERVER['REQUEST_METHOD']) {
  375. case "GET":
  376. $tpl->ajax_request = PMF_Filter::filterInput(INPUT_GET, 'ajax', FILTER_SANITIZE_STRING);
  377. break;
  378. case "POST":
  379. $tpl->ajax_request = PMF_Filter::filterInput(INPUT_POST, 'ajax', FILTER_SANITIZE_STRING);
  380. break;
  381. }
  382. if ($tpl->ajax_request&&$tpl->ajax_request!='ajax_init'){
  383. // If it's not the ajax initialization, set the request
  384. switch($_SERVER['REQUEST_METHOD']) {
  385. case "GET":
  386. $true_request = PMF_Filter::filterInput(INPUT_GET, 'action', FILTER_SANITIZE_STRING);
  387. break;
  388. case "POST":
  389. $true_request = PMF_Filter::filterInput(INPUT_POST, 'action', FILTER_SANITIZE_STRING);
  390. break;
  391. }
  392. //If it's a login or logout request, reload only the login box
  393. if ($true_request=="login" || $true_request=="logout") {
  394. $tpl->ajax_request=$true_request;
  395. } else {
  396. $tpl->ajax_request=$action;
  397. }
  398. }
  399. if (strstr($writeLangAdress, "&")) {
  400. $writeLangAdress.= '&change_lang=true';
  401. } elseif (strstr($writeLangAdress, "?")) {
  402. $writeLangAdress.= 'change_lang=true';
  403. } else{
  404. $writeLangAdress.= '?change_lang=true';
  405. }
  406. $tpl->change_lang = PMF_Filter::filterInput(INPUT_POST, 'change_lang', FILTER_SANITIZE_STRING);
  407. //Associate a action request with template blocks
  408. $all_action = '(main|'.implode('|', array_keys($allowedVariables)).')';
  409. $tpl->varAjax = array('showCategories' => 'ajax_init',
  410. 'title' => $all_action,
  411. 'writeContent' => $all_action,
  412. 'writeLangAdress' => $all_action,
  413. 'action' => $all_action,
  414. 'userOnline' => $all_action,
  415. 'loginBox' => '(login|logout)',
  416. 'rightBox' => 'artikel');
  417. if (DEBUG) {
  418. $tpl->varAjax['debugMessages'] = $all_action;
  419. //If debug mode active reload also debug messages
  420. }
  421. //Init the ajax template map and store the data in session for better performance
  422. if (isset($_SESSION['parsedTemplates'])&&$tpl->ajax_request) {
  423. $tpl->parsedTemplates = $_SESSION['parsedTemplates'];
  424. } else {
  425. $tpl->TemplateAjaxInit();
  426. $_SESSION['parsedTemplates'] = $tpl->parsedTemplates;
  427. }
  428. }
  429. $usersOnLine = getUsersOnline();
  430. $totUsersOnLine = $usersOnLine[0] + $usersOnLine[1];
  431. $systemUri = PMF_Link::getSystemUri('index.php');
  432. $categoryTree = new PMF_Category_Tree($categoryData);
  433. // If it's an ajax request , get the whole tree else get the filtered tree
  434. if ($tpl->ajax_active && $tpl->ajax_request == 'ajax_init') {
  435. $categoryLayout = new PMF_Category_Layout(new PMF_Category_Tree_Helper($categoryTree));
  436. } else {
  437. $categoryLayout = new PMF_Category_Layout(
  438. new PMF_Category_Tree_Helper(
  439. new PMF_Category_Path($categoryTree, $categoryPath)));
  440. }
  441. $keywordsArray = array_merge(explode(',', $keywords), explode(',', $faqconfig->get('main.metaKeywords')));
  442. $keywordsArray = array_filter($keywordsArray, 'strlen');
  443. shuffle($keywordsArray);
  444. $keywords = implode(',', $keywordsArray);
  445. $main_template_vars = array(
  446. 'title' => $faqconfig->get('main.titleFAQ').$title,
  447. 'baseHref' => $systemUri,
  448. 'version' => $faqconfig->get('main.currentVersion'),
  449. 'header' => str_replace('"', '', $faqconfig->get('main.titleFAQ')),
  450. 'metaTitle' => str_replace('"', '', $faqconfig->get('main.titleFAQ')),
  451. 'metaDescription' => $metaDescription,
  452. 'metaKeywords' => $keywords,
  453. 'metaPublisher' => $faqconfig->get('main.metaPublisher'),
  454. 'metaLanguage' => $PMF_LANG['metaLanguage'],
  455. 'metaCharset' => 'utf-8', // backwards compability
  456. 'phpmyfaqversion' => $faqconfig->get('main.currentVersion'),
  457. 'stylesheet' => $PMF_LANG['dir'] == 'rtl' ? 'style.rtl' : 'style',
  458. 'action' => $action,
  459. 'dir' => $PMF_LANG['dir'],
  460. 'msgCategory' => $PMF_LANG['msgCategory'],
  461. 'showCategories' => $categoryLayout->renderNavigation($cat),
  462. 'languageBox' => $PMF_LANG['msgLangaugeSubmit'],
  463. 'writeLangAdress' => $writeLangAdress,
  464. 'switchLanguages' => PMF_Language::selectLanguages($LANGCODE, true),
  465. 'userOnline' => $plr->getMsg('plmsgUserOnline', $totUsersOnLine) .
  466. $plr->getMsg('plmsgGuestOnline', $usersOnLine[0]) .
  467. $plr->getMsg('plmsgRegisteredOnline',$usersOnLine[1]),
  468. 'stickyRecordsHeader' => $PMF_LANG['stickyRecordsHeader'],
  469. 'copyright' => 'powered by <a href="http://www.phpmyfaq.de" target="_blank">phpMyFAQ</a> ' .
  470. $faqconfig->get('main.currentVersion'));
  471. if ('main' == $action || 'show' == $action) {
  472. if ('main' == $action && PMF_Configuration::getInstance()->get('main.useAjaxSearchOnStartpage')) {
  473. $tpl->processBlock('index', 'globalSuggestBox', array('ajaxlanguage' => $LANGCODE));
  474. } else {
  475. $tpl->processBlock('index', 'globalSearchBox', array(
  476. 'writeSendAdress' => '?'.$sids.'action=search',
  477. 'searchBox' => $PMF_LANG['msgSearch'],
  478. 'categoryId' => ($cat === 0) ? '%' : (int)$cat));
  479. }
  480. }
  481. $stickyRecordsParams = $faq->getStickyRecords();
  482. if (!isset($stickyRecordsParams['error'])) {
  483. $tpl->processBlock('index', 'stickyRecordsList', array(
  484. 'stickyRecordsUrl' => $stickyRecordsParams['url'],
  485. 'stickyRecordsTitle' => $stickyRecordsParams['title']));
  486. }
  487. if ($faqconfig->get('main.enableRewriteRules')) {
  488. $links_template_vars = array(
  489. "faqHome" => $faqconfig->get('main.referenceURL'),
  490. "msgSearch" => '<a href="' . $systemUri . 'search.html">'.$PMF_LANG["msgAdvancedSearch"].'</a>',
  491. 'msgAddContent' => '<a href="' . $systemUri . 'addcontent.html">'.$PMF_LANG["msgAddContent"].'</a>',
  492. "msgQuestion" => '<a href="' . $systemUri . 'ask.html">'.$PMF_LANG["msgQuestion"].'</a>',
  493. "msgOpenQuestions" => '<a href="' . $systemUri . 'open.html">'.$PMF_LANG["msgOpenQuestions"].'</a>',
  494. 'msgHelp' => '<a href="' . $systemUri . 'help.html">'.$PMF_LANG["msgHelp"].'</a>',
  495. "msgContact" => '<a href="' . $systemUri . 'contact.html">'.$PMF_LANG["msgContact"].'</a>',
  496. "backToHome" => '<a href="' . $systemUri . 'index.html">'.$PMF_LANG["msgHome"].'</a>',
  497. "allCategories" => '<a href="' . $systemUri . 'showcat.html">'.$PMF_LANG["msgShowAllCategories"].'</a>',
  498. 'showInstantResponse' => '<a href="' . $systemUri . 'instantresponse.html">'.$PMF_LANG['msgInstantResponse'].'</a>',
  499. 'showSitemap' => '<a href="' . $systemUri . 'sitemap/A/'.$LANGCODE.'.html">'.$PMF_LANG['msgSitemap'].'</a>',
  500. 'opensearch' => $systemUri . 'opensearch.html');
  501. } else {
  502. $links_template_vars = array(
  503. "faqHome" => $faqconfig->get('main.referenceURL'),
  504. "msgSearch" => '<a href="index.php?'.$sids.'action=search">'.$PMF_LANG["msgAdvancedSearch"].'</a>',
  505. "msgAddContent" => '<a href="index.php?'.$sids.'action=add">'.$PMF_LANG["msgAddContent"].'</a>',
  506. "msgQuestion" => '<a href="index.php?'.$sids.'action=ask">'.$PMF_LANG["msgQuestion"].'</a>',
  507. "msgOpenQuestions" => '<a href="index.php?'.$sids.'action=open">'.$PMF_LANG["msgOpenQuestions"].'</a>',
  508. "msgHelp" => '<a href="index.php?'.$sids.'action=help">'.$PMF_LANG["msgHelp"].'</a>',
  509. "msgContact" => '<a href="index.php?'.$sids.'action=contact">'.$PMF_LANG["msgContact"].'</a>',
  510. "allCategories" => '<a href="index.php?'.$sids.'action=show">'.$PMF_LANG["msgShowAllCategories"].'</a>',
  511. "backToHome" => '<a href="index.php?'.$sids.'">'.$PMF_LANG["msgHome"].'</a>',
  512. 'showInstantResponse' => '<a href="index.php?'.$sids.'action=instantresponse">'.$PMF_LANG['msgInstantResponse'].'</a>',
  513. 'showSitemap' => '<a href="index.php?'.$sids.'action=sitemap&amp;lang='.$LANGCODE.'">'.$PMF_LANG['msgSitemap'].'</a>',
  514. 'opensearch' => $systemUri . 'opensearch.php');
  515. }
  516. //
  517. // Add debug info if needed
  518. //
  519. if (DEBUG) {
  520. $debug_template_vars = array(
  521. 'debugMessages' => "\n".'<div id="debug_main">DEBUG INFORMATION:<br />'.$db->sqllog().'</div>'
  522. );
  523. } else {
  524. $debug_template_vars = array('debugMessages' => '');
  525. }
  526. //
  527. // Get main template, set main variables
  528. //
  529. $tpl->processTemplate('index', array_merge($main_template_vars, $links_template_vars, $debug_template_vars));
  530. //
  531. // Show login box or logged-in user information
  532. //
  533. if (isset($auth)) {
  534. $tpl->processTemplate('loginBox', array(
  535. 'loggedinas' => $PMF_LANG['ad_user_loggedin'],
  536. 'currentuser' => $user->getUserData('display_name'),
  537. 'printAdminPath' => (in_array(true, $permission)) ? 'admin/index.php' : '#',
  538. 'adminSection' => $PMF_LANG['adminSection'],
  539. 'printLogoutPath' => '?action=logout',
  540. 'logout' => $PMF_LANG['ad_menu_logout']));
  541. } else {
  542. if (isset($_SERVER['HTTPS']) || !$faqconfig->get('main.useSslForLogins')) {
  543. $tpl->processTemplate('loginBox', array(
  544. 'writeLoginPath' => '?action=login',
  545. 'login' => $PMF_LANG['ad_auth_ok'],
  546. 'username' => $PMF_LANG['ad_auth_user'],
  547. 'password' => $PMF_LANG['ad_auth_passwd'],
  548. 'msgRegisterUser' => '<a href="?' . $sids . 'action=register">' . $PMF_LANG['msgRegisterUser'] . '</a>',
  549. 'msgLoginFailed' => $error));
  550. } else {
  551. $tpl->processTemplate('loginBox', array(
  552. 'secureloginurl' => sprintf('https://%s%s', $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI']),
  553. 'securelogintext' => $PMF_LANG['msgSecureSwitch']));
  554. }
  555. }
  556. $tpl->includeTemplate('loginBox', 'index');
  557. // generate top ten list
  558. if ($faqconfig->get('main.orderingPopularFaqs') == 'visits') {
  559. // top ten list for most viewed entries
  560. $toptenParams = $faq->getTopTen('visits');
  561. if (!isset($toptenParams['error'])) {
  562. $tpl->processBlock('rightBox', 'toptenList', array(
  563. 'toptenUrl' => $toptenParams['url'],
  564. 'toptenTitle' => $toptenParams['title'],
  565. 'toptenVisits' => $toptenParams['visits'])
  566. );
  567. } else {
  568. $tpl->processBlock('rightBox', 'toptenListError', array(
  569. 'errorMsgTopTen' => $toptenParams['error'])
  570. );
  571. }
  572. } else {
  573. // top ten list for most voted entries
  574. $toptenParams = $faq->getTopTen('voted');
  575. if (!isset($toptenParams['error'])) {
  576. $tpl->processBlock('rightBox', 'toptenList', array(
  577. 'toptenUrl' => $toptenParams['url'],
  578. 'toptenTitle' => $toptenParams['title'],
  579. 'toptenVisits' => $toptenParams['voted'])
  580. );
  581. } else {
  582. $tpl->processBlock('rightBox', 'toptenListError', array(
  583. 'errorMsgTopTen' => $toptenParams['error'])
  584. );
  585. }
  586. }
  587. $latestEntriesParams = $faq->getLatest();
  588. if (!isset($latestEntriesParams['error'])) {
  589. $tpl->processBlock('rightBox', 'latestEntriesList', array(
  590. 'latestEntriesUrl' => $latestEntriesParams['url'],
  591. 'latestEntriesTitle' => $latestEntriesParams['title'],
  592. 'latestEntriesDate' => $latestEntriesParams['date'])
  593. );
  594. } else {
  595. $tpl->processBlock('rightBox', 'latestEntriesListError', array(
  596. 'errorMsgLatest' => $latestEntriesParams['error'])
  597. );
  598. }
  599. $tpl->processTemplate('rightBox', array(
  600. 'writeTopTenHeader' => $PMF_LANG['msgTopTen'],
  601. 'writeNewestHeader' => $PMF_LANG['msgLatestArticles'],
  602. 'writeTagCloudHeader' => $PMF_LANG['msg_tags'],
  603. 'writeTags' => $oTag->printHTMLTagsCloud(),
  604. 'msgAllCatArticles' => $PMF_LANG['msgAllCatArticles'],
  605. 'allCatArticles' => $faq->showAllRecordsWoPaging($cat))
  606. );
  607. $tpl->includeTemplate('rightBox', 'index');
  608. //
  609. // Include requested PHP file
  610. //
  611. require_once $inc_php;
  612. //
  613. // Send headers and print template
  614. //
  615. header("Expires: Thu, 07 Apr 1977 14:47:00 GMT");
  616. header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
  617. header("Cache-Control: no-store, no-cache, must-revalidate");
  618. header("Cache-Control: post-check=0, pre-check=0", false);
  619. header("Pragma: no-cache");
  620. header("Content-type: text/html; charset=utf-8");
  621. header("Vary: Negotiate,Accept");
  622. $tpl->printTemplate();
  623. //
  624. // Disconnect from database
  625. //
  626. $db->dbclose();