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