* @author Lars Tiedemann ' . $error . '
';
}
}
if ($faqConfig->get('security.ssoSupport')) {
$authSso = new AuthSso($faqConfig);
$user->addAuth($authSso, 'sso');
}
if ($user->login($faqusername, $faqpassword)) {
if ($user->getStatus() != 'blocked') {
$auth = true;
if (empty($action)) {
$action = $faqaction; // SSO logins don't have $faqaction
}
} else {
$error = $error . $PMF_LANG['ad_auth_fail'] . ' (' . $faqusername . ')';
$loginVisibility = '';
$action = 'password' === $action ? 'password' : 'login';
}
} else {
// error
$error = $error . $PMF_LANG['ad_auth_fail'];
$loginVisibility = '';
$action = 'password' === $action ? 'password' : 'login';
}
} else {
// Try to authenticate with cookie information
$user = CurrentUser::getFromCookie($faqConfig);
// authenticate with session information
if (!$user instanceof CurrentUser) {
$user = CurrentUser::getFromSession($faqConfig);
}
if ($user instanceof CurrentUser) {
$auth = true;
} else {
$user = new CurrentUser($faqConfig);
}
}
//
// Logout
//
if ($csrfChecked && 'logout' === $action && isset($auth)) {
$user->deleteFromSession(true);
$auth = null;
$action = 'main';
$ssoLogout = $faqConfig->get('security.ssoLogoutRedirect');
if ($faqConfig->get('security.ssoSupport') && !empty($ssoLogout)) {
header('Location: ' . $ssoLogout);
} else {
header('Location: ' . $faqConfig->getDefaultUrl());
}
}
//
// Get current user and group id - default: -1
//
if (!is_null($user) && $user instanceof CurrentUser) {
$currentUser = $user->getUserId();
if ($user->perm instanceof MediumPermission) {
$currentGroups = $user->perm->getUserGroups($currentUser);
} else {
$currentGroups = [-1];
}
if (0 == count($currentGroups)) {
$currentGroups = [-1];
}
} else {
$currentUser = -1;
$currentGroups = [-1];
}
//
// Use mbstring extension if available and when possible
//
$validMbStrings = ['ja', 'en', 'uni'];
$mbLanguage = ($PMF_LANG['metaLanguage'] != 'ja') ? 'uni' : $PMF_LANG['metaLanguage'];
if (function_exists('mb_language') && in_array($mbLanguage, $validMbStrings)) {
mb_language($mbLanguage);
mb_internal_encoding('utf-8');
}
//
// Found a session ID in _GET or _COOKIE?
//
$sidGet = Filter::filterInput(INPUT_GET, PMF_GET_KEY_NAME_SESSIONID, FILTER_VALIDATE_INT);
$sidCookie = Filter::filterInput(INPUT_COOKIE, Session::PMF_COOKIE_NAME_SESSIONID, FILTER_VALIDATE_INT);
$faqSession = new Session($faqConfig);
$faqSession->setCurrentUser($user);
// Note: do not track internal calls
$internal = false;
if (isset($_SERVER['HTTP_USER_AGENT'])) {
$internal = (strpos($_SERVER['HTTP_USER_AGENT'], 'phpMyFAQ%2F') === 0);
}
if (!$internal) {
if (is_null($sidGet) && is_null($sidCookie)) {
// Create a per-site unique SID
try {
$faqSession->userTracking('new_session', 0);
} catch (Exception $e) {
$pmfExceptions[] = $e->getMessage();
}
} elseif (!is_null($sidCookie)) {
try {
$faqSession->checkSessionId($sidCookie, $_SERVER['REMOTE_ADDR']);
} catch (Exception $e) {
$pmfExceptions[] = $e->getMessage();
}
} else {
try {
$faqSession->checkSessionId($sidGet, $_SERVER['REMOTE_ADDR']);
} catch (Exception $e) {
$pmfExceptions[] = $e->getMessage();
}
}
}
//
// Is user tracking activated?
//
$sids = '';
if ($faqConfig->get('main.enableUserTracking')) {
if ($faqSession->getCurrentSessionId() > 0) {
$faqSession->setCookie(Session::PMF_COOKIE_NAME_SESSIONID, $faqSession->getCurrentSessionId());
if (is_null($sidCookie)) {
$sids = sprintf('sid=%d&lang=%s&', $faqSession->getCurrentSessionId(), $faqLangCode);
}
} elseif (is_null($sidGet) || is_null($sidCookie)) {
if (is_null($sidCookie)) {
if (!is_null($sidGet)) {
$sids = sprintf('sid=%d&lang=%s&', $sidGet, $faqLangCode);
}
}
}
} elseif (
!$faqSession->setCookie(
Session::PMF_COOKIE_NAME_SESSIONID,
$faqSession->getCurrentSessionId(),
$_SERVER['REQUEST_TIME'] + PMF_LANGUAGE_EXPIRED_TIME
)
) {
$sids = sprintf('lang=%s&', $faqLangCode);
}
//
// Found a article language?
//
$lang = Filter::filterInput(INPUT_POST, 'artlang', FILTER_UNSAFE_RAW);
if (is_null($lang) && !Language::isASupportedLanguage($lang)) {
$lang = Filter::filterInput(INPUT_GET, 'artlang', FILTER_UNSAFE_RAW);
if (is_null($lang) && !Language::isASupportedLanguage($lang)) {
$lang = $faqLangCode;
}
}
//
// Sanitize language string
//
if (!Language::isASupportedLanguage($lang)) {
$lang = $faqConfig->getDefaultLanguage();
}
//
// Found a search string?
//
$searchTerm = Filter::filterInput(INPUT_GET, 'search', FILTER_UNSAFE_RAW, '');
//
// Create a new FAQ object
//
$faq = new Faq($faqConfig);
$faq->setUser($currentUser)
->setGroups($currentGroups);
//
// Create a new Category object
//
$category = new Category($faqConfig, $currentGroups, true);
$category->setUser($currentUser)
->setGroups($currentGroups);
//
// Create a new Tags object
//
$oTag = new Tags($faqConfig);
//
// Create URL
//
$faqSystem = new System();
$faqLink = new Link($faqSystem->getSystemUri($faqConfig), $faqConfig);
$currentPageUrl = Strings::htmlentities($faqLink->getCurrentUrl());
//
// Found a record ID?
//
$id = Filter::filterInput(INPUT_GET, 'id', FILTER_VALIDATE_INT);
if (!is_null($id)) {
$faq->getRecord($id);
$title = ' - ' . $faq->faqRecord['title'];
$keywords = ',' . $faq->faqRecord['keywords'];
$metaDescription = str_replace('"', '', strip_tags($faq->getRecordPreview($id)));
$url = sprintf(
'%sindex.php?%saction=faq&cat=%d&id=%d&artlang=%s',
Strings::htmlentities($faqConfig->getDefaultUrl()),
$sids,
$category->getCategoryIdFromFaq($id),
$id,
$lang
);
$faqLink = new Link($url, $faqConfig);
$faqLink->itemTitle = $faq->faqRecord['title'];
$currentPageUrl = $faqLink->toString(true);
} else {
$id = '';
$title = ' - powered by phpMyFAQ ' . $faqConfig->getVersion();
$keywords = '';
$metaDescription = str_replace('"', '', $faqConfig->get('main.metaDescription'));
}
//
// found a solution ID?
//
$solutionId = Filter::filterInput(INPUT_GET, 'solution_id', FILTER_VALIDATE_INT);
if (!is_null($solutionId)) {
$title = ' - powered by phpMyFAQ ' . $faqConfig->getVersion();
$keywords = '';
$faqData = $faq->getIdFromSolutionId($solutionId);
if (is_array($faqData)) {
$id = $faqData['id'];
$lang = $faqData['lang'];
$title = ' - ' . $faq->getRecordTitle($id);
$keywords = ',' . $faq->getRecordKeywords($id);
$metaDescription = str_replace('"', '', Utils::makeShorterText(strip_tags($faqData['content']), 12));
$url = sprintf(
'%sindex.php?%saction=faq&cat=%d&id=%d&artlang=%s',
Strings::htmlentities($faqConfig->getDefaultUrl()),
$sids,
$faqData['category_id'],
$id,
$lang
);
$faqLink = new Link($url, $faqConfig);
$faqLink->itemTitle = $faqData['question'];
$currentPageUrl = $faqLink->toString(true);
}
}
//
// Handle the Tagging ID
//
$tag_id = Filter::filterInput(INPUT_GET, 'tagging_id', FILTER_VALIDATE_INT);
if (!is_null($tag_id)) {
$title = ' - ' . $oTag->getTagNameById($tag_id);
$keywords = '';
}
//
// Handle the SiteMap
//
$letter = Filter::filterInput(INPUT_GET, 'letter', FILTER_UNSAFE_RAW);
if (!is_null($letter) && (1 == Strings::strlen($letter))) {
$title = ' - ' . $letter . '...';
$keywords = $letter;
}
//
// Found a category ID?
//
$cat = Filter::filterInput(INPUT_GET, 'cat', FILTER_VALIDATE_INT, 0);
$categoryFromId = -1;
if (is_numeric($id) && $id > 0) {
$categoryFromId = $category->getCategoryIdFromFaq($id);
}
if ($categoryFromId != -1 && $cat == 0) {
$cat = $categoryFromId;
}
$category->transform(0);
$category->collapseAll();
if ($cat != 0) {
$category->expandTo($cat);
}
if (isset($cat) && ($cat != 0) && ($id == '') && isset($category->categoryName[$cat]['name'])) {
$title = ' - ' . $category->categoryName[$cat]['name'];
$metaDescription = $category->categoryName[$cat]['description'];
}
//
// Found an action request?
//
if (!isset(Link::$allowedActionParameters[$action])) {
$action = 'main';
}
//
// Select the template for the requested page
//
if ($action !== 'main') {
$includeTemplate = $action . '.html';
$includePhp = $action . '.php';
$renderUri = '?sid=' . $faqSession->getCurrentSessionId();
} else {
if (isset($solutionId) && is_numeric($solutionId)) {
// show the record with the solution ID
$includeTemplate = 'faq.html';
$includePhp = 'faq.php';
} else {
$includeTemplate = 'startpage.html';
$includePhp = 'startpage.php';
}
$renderUri = '?sid=' . $faqSession->getCurrentSessionId();
}
//
// Set sidebar column
//
if (($action === 'faq') || ($action === 'show') || ($action === 'main')) {
$sidebarTemplate = 'sidebar-tagcloud.html';
} else {
$sidebarTemplate = 'sidebar-empty.html';
}
//
// Check if FAQ should be secured
//
if ($faqConfig->get('security.enableLoginOnly')) {
if ($auth) {
$indexSet = 'index.html';
} else {
switch ($action) {
case 'register':
case 'thankyou':
$indexSet = 'new-user.page.html';
break;
case 'password':
$indexSet = 'password.page.html';
break;
default:
$indexSet = 'login.page.html';
break;
}
}
} else {
$indexSet = 'index.html';
}
//
// phpMyFAQ installation is in maintenance mode
//
if ($faqConfig->get('main.maintenanceMode')) {
$indexSet = 'maintenance.page.html';
}
//
// Load template files and set template variables
//
$template = new Template(
[
'index' => $indexSet,
'sidebar' => $sidebarTemplate,
'mainPageContent' => $includeTemplate,
],
new TemplateHelper($faqConfig),
$faqConfig->get('main.templateSet')
);
$categoryRelation = new CategoryRelation($faqConfig);
$categoryHelper = new HelperCategory();
$categoryHelper->setCategory($category);
$categoryHelper->setConfiguration($faqConfig);
$categoryHelper->setCategoryRelation($categoryRelation);
$keywordsArray = array_merge(explode(',', $keywords), explode(',', $faqConfig->get('main.metaKeywords')));
$keywordsArray = array_filter($keywordsArray, 'strlen');
shuffle($keywordsArray);
$keywords = implode(',', $keywordsArray);
if (!is_null($error)) {
$loginMessage = '