<commit_before><?php
/**
* $Id: index.php,v 1.43 2006-01-04 14:47:02 b33blebr0x Exp $
*
* This is the main public frontend page of phpMyFAQ. It detects the browser's
* language, gets all cookie, post and get informations and includes the 
* templates we need and set all internal variables to the template variables.
* That's all.
*
* @author       <NAME> <<EMAIL>>
* @author       <NAME> <<EMAIL>>
* @since        2001-02-12
* @copyright:   (c) 2001-2006 phpMyFAQ Team
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*/



//
// Check if config.php and data.php exist -> if not, redirect to installer
//
if (!file_exists('inc/config.php') || !file_exists('inc/data.php')) {
    header("Location: install/installer.php");
    exit();
}


//
// Prepend
//
require_once('inc/init.php');
define('IS_VALID_PHPMYFAQ', null);
PMF_Init::cleanRequest();



//
// Include required template parser class, category class, the main FAQ class
// and the IDNA class
//
require_once('inc/parser.php');
require_once('inc/Category.php');
require_once('inc/Faq.php');
require_once('inc/idna_convert.class.php');
$IDN = new idna_convert;



//
// get language (default: english)
//
$pmf = new PMF_Init();
$LANGCODE = $pmf->setLanguage((isset($PMF_CONF['detection']) ? true : false), $PMF_CONF['language']);

if (isset($LANGCODE) && isset($languageCodes[strtoupper($LANGCODE)])) {
    require_once('lang/language_'.$LANGCODE.'.php');
} else {
    $LANGCODE = 'en';
    require_once ('lang/language_en.php');
}



//
// Authenticate current user
//
require_once ('inc/PMF_User/CurrentUser.php');
unset($auth);
if (isset($_POST['faqpassword']) and isset($_POST['faqusername'])) {
    // login with username and password
    $user = new PMF_CurrentUser();
    if ($user->login($db->escape_string($_POST['faqusername']),$db->escape_string($_POST['faqpassword']))) {
        // login, if user account is NOT blocked
        if ($user->getStatus() != 'blocked') {
            $auth = true;
        } else {
            $error = $PMF_LANG['ad_auth_fail'];
        }
    } else {
        // error
        $error = $PMF_LANG["ad_auth_fail"]." (".$user->getUserData('login')." / *)";
        unset($user);
    }
} else {
    // authenticate with session information
    $ip_check = (isset($PMF_CONF['ipcheck']) && $PMF_CONF['ipcheck']) ? true : false;
    $user = PMF_CurrentUser::getFromSession($ip_check);
    if ($user) {
        $auth = true;
    }
}



//
// Get current user rights
//
$permission = array();
if (isset($auth)) {
    // read all rights, set them FALSE
    $allRights = $user->perm->getAllRightsData();
    foreach ($allRights as $right) {
        $permission[$right['name']] = false;
    }
    // check user rights, set them TRUE
    $allUserRights = $user->perm->getAllUserRights($user->getUserId());
    foreach ($allRights as $right) {
        if (in_array($right['right_id'], $allUserRights))
            $permission[$right['name']] = true;
    }
}



//
// Logout
//
if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'logout' && $auth) {
    $user->deleteFromSession();
    unset($user);
    unset($auth);
}



//
// use mbstring extension if available
//
$valid_mb_strings = array('ja', 'en');
if (function_exists('mb_language') && in_array($PMF_LANG['metaLanguage'], $valid_mb_strings)) {
    mb_language($PMF_LANG['metaLanguage']);
    mb_internal_encoding($PMF_LANG['metaCharset']);
}



//
// found a session ID?
//
if (!isset($_GET["sid"]) && !isset($_COOKIE["sid"])) {
	Tracking("new_session", 0);
    setcookie("sid", $sid, time()+3600);
} else {
	if (isset($_REQUEST["sid"]) && is_numeric($_REQUEST["sid"]) == TRUE) {
		CheckSID($_REQUEST["sid"], getenv("REMOTE_ADDR"));
	}
}



//
// is user tracking activated?
//
if (isset($PMF_CONF["tracking"])) {
	if (isset($sid)) {
        if (!isset($_COOKIE["sid"])) {
            $sids = "sid=".$sid."&amp;lang=".$LANGCODE."&amp;";
        } else {
            $sids = "";
        }
	} elseif (isset($_REQUEST["sid"])) {
        if (!isset($_COOKIE["sid"])) {
            $sids = "sid=".$_REQUEST["sid"]."&amp;lang=".$LANGCODE."&amp;";
        } else {
            $sids = "";
        }
	}
} else {
    if (!setcookie("lang", $LANGCODE, time()+3600)) {
        $sids = "lang=".$LANGCODE."&amp;";
    } else {
        $sids = "";
    }
}



//
// Create a new FAQ object
//
$faq = new FAQ($db, $LANGCODE);


//
// Found a article language?
//
if (isset($_GET["artlang"]) && strlen($_GET["artlang"]) <= 2 && !preg_match("=/=", $_GET["artlang"])) {
	$lang = $_GET["artlang"];
} else {
	$lang = $LANGCODE;
}



//
// Found a record ID?
//
if (isset($_REQUEST["id"]) && is_numeric($_REQUEST["id"]) == true) {
	$id = (int)$_REQUEST["id"];
    $title = ' - '.stripslashes($faq->getRecordTitle($id, $lang));
    $keywords = ' '.stripslashes($faq->getRecordKeywords($id, $lang));
} else {
	$id = '';
    $title = ' -  powered by phpMyFAQ '.$PMF_CONF['version'];
    $keywords = '';
}



//
// Found a category ID?
//
if (isset($_GET["cat"])) {
    $cat = $_GET["cat"];
} else {
    $cat = 0;
}
$tree = new Category($LANGCODE);
$cat_from_id = -1;
if (is_numeric($id) && $id > 0) {<commit_msg>MFB: Added support for solution id<commit_after><?php
/**
* $Id: index.php,v 1.44 2006-04-09 09:52:56 thorstenr Exp $
*
* This is the main public frontend page of phpMyFAQ. It detects the browser's
* language, gets all cookie, post and get informations and includes the 
* templates we need and set all internal variables to the template variables.
* That's all.
*
* @author       <NAME> <<EMAIL>>
* @author       <NAME> <<EMAIL>>
* @since        2001-02-12
* @copyright:   (c) 2001-2006 phpMyFAQ Team
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*/



//
// Check if config.php and data.php exist -> if not, redirect to installer
//
if (!file_exists('inc/config.php') || !file_exists('inc/data.php')) {
    header("Location: install/installer.php");
    exit();
}


//
// Prepend
//
require_once('inc/init.php');
define('IS_VALID_PHPMYFAQ', null);
PMF_Init::cleanRequest();



//
// Include required template parser class, category class, the main FAQ class
// and the IDNA class
//
require_once('inc/parser.php');
require_once('inc/captcha.php');
require_once('inc/Category.php');
require_once('inc/Faq.php');
require_once('inc/idna_convert.class.php');
$IDN = new idna_convert;



//
// get language (default: english)
//
$pmf = new PMF_Init();
$LANGCODE = $pmf->setLanguage((isset($PMF_CONF['detection']) ? true : false), $PMF_CONF['language']);
// Preload English strings
require_once ('lang/language_en.php');

if (isset($LANGCODE) && PMF_Init::isASupportedLanguage($LANGCODE)) {
    // Overwrite English strings with the ones we have in the current language
    require_once('lang/language_'.$LANGCODE.'.php');
} else {
    $LANGCODE = 'en';
}



//
// Authenticate current user
//
require_once ('inc/PMF_User/CurrentUser.php');
unset($auth);
if (isset($_POST['faqpassword']) and isset($_POST['faqusername'])) {
    // login with username and password
    $user = new PMF_CurrentUser();
    if ($user->login($db->escape_string($_POST['faqusername']),$db->escape_string($_POST['faqpassword']))) {
        // login, if user account is NOT blocked
        if ($user->getStatus() != 'blocked') {
            $auth = true;
        } else {
            $error = $PMF_LANG['ad_auth_fail'];
        }
    } else {
        // error
        $error = $PMF_LANG["ad_auth_fail"]." (".$user->getUserData('login')." / *)";
        unset($user);
    }
} else {
    // authenticate with session information
    $ip_check = (isset($PMF_CONF['ipcheck']) && $PMF_CONF['ipcheck']) ? true : false;
    $user = PMF_CurrentUser::getFromSession($ip_check);
    if ($user) {
        $auth = true;
    }
}



//
// Get current user rights
//
$permission = array();
if (isset($auth)) {
    // read all rights, set them FALSE
    $allRights = $user->perm->getAllRightsData();
    foreach ($allRights as $right) {
        $permission[$right['name']] = false;
    }
    // check user rights, set them TRUE
    $allUserRights = $user->perm->getAllUserRights($user->getUserId());
    foreach ($allRights as $right) {
        if (in_array($right['right_id'], $allUserRights))
            $permission[$right['name']] = true;
    }
}



//
// Logout
//
if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'logout' && $auth) {
    $user->deleteFromSession();
    unset($user);
    unset($auth);
}



//
// use mbstring extension if available
//
$valid_mb_strings = array('ja', 'en');
if (function_exists('mb_language') && in_array($PMF_LANG['metaLanguage'], $valid_mb_strings)) {
    mb_language($PMF_LANG['metaLanguage']);
    mb_internal_encoding($PMF_LANG['metaCharset']);
}



//
// found a session ID?
//
if (!isset($_GET["sid"]) && !isset($_COOKIE["sid"])) {
	Tracking("new_session", 0);
    setcookie("sid", $sid, time()+3600);
} else {
	if (isset($_REQUEST["sid"]) && is_numeric($_REQUEST["sid"]) == TRUE) {
		CheckSID($_REQUEST["sid"], getenv("REMOTE_ADDR"));
	}
}



//
// is user tracking activated?
//
if (isset($PMF_CONF["tracking"])) {
	if (isset($sid)) {
        if (!isset($_COOKIE["sid"])) {
            $sids = "sid=".$sid."&amp;lang=".$LANGCODE."&amp;";
        } else {
            $sids = "";
        }
	} elseif (isset($_REQUEST["sid"])) {
        if (!isset($_COOKIE["sid"])) {
            $sids = "sid=".$_REQUEST["sid"]."&amp;lang=".$LANGCODE."&amp;";
        } else {
            $sids = "";
        }
	}
} else {
    if (!setcookie("lang", $LANGCODE, time()+3600)) {
        $sids = "lang=".$LANGCODE."&amp;";
    } else {
        $sids = "";
    }
}



//
// Create a new FAQ object
//
$faq = new FAQ($db, $LANGCODE);


//
// Found a article language?
//
if (isset($_POST["artlang"]) && PMF_Init::isASupportedLanguage($_POST["artlang"]) ) {
    $lang = $_POST["artlang"];
} else {
    $lang = $LANGCODE;
}



//
// Found a record ID?
//
if (isset($_REQUEST["id"]) && is_numeric($_REQUEST["id"]) == true) {
	$id = (int)$_REQUEST["id"];
    $title = ' - '.stripslashes($faq->getRecordTitle($id, $lang));
    $keywords = ' '.stripslashes($faq->getRecordKeywords($id, $lang));
} else {
	$id = '';
    $title = ' -  powered by phpMyFAQ '.$PMF_CONF['version'];
    $keywords = '';
}



//
// found a solution ID?
//
if (isset($_REQUEST['solution_id']) && is_numeric($_REQUEST['solution_id']) === true) {
    $solution_id = $_REQUEST['solution_id'];
    $title = ' -  powered by phpMyFAQ '.$PMF_CONF['version'];
    $keywords = '';
    $a = $faq->getIdFromSolutionId($solution_id);
    if (is_array($a)) {
        $id = $a['id'];
        $lang = $a['lang'];
    }
}



//
// Found a category ID?
//
if (isset($_GET["cat"])) {
    $cat = $_GET["cat"];
} else {
    $cat = 0;
}
$tree = new Category($LANGCODE);
$cat_from_id = -1;
if (is_numeric($id) && $id > 0) {
{'fraction_non_alphanumeric': 0.19651591864755857, 'fraction_numerical': 0.008409851540375868, 'mean_word_length': 3.319495922905856, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6156467', 'n_tokens_mistral': 4100, 'n_tokens_neox': 3928, 'n_words': 910}