PageRenderTime 7ms CodeModel.GetById 4ms app.highlight 31ms RepoModel.GetById 0ms app.codeStats 1ms

/phpmyfaq/index.php

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