<commit_before><?php 
/*
 *	Made by Samerton
 *  https://github.com/NamelessMC/Nameless/
 *  NamelessMC version 2.0.0-pr5
 *
 *  License: MIT
 *
 *  View forum page
 */

// Always define page name
define('PAGE', 'forum');

require_once(ROOT_PATH . '/modules/Forum/classes/Forum.php');
$forum = new Forum();
$timeago = new Timeago(TIMEZONE);

require(ROOT_PATH . '/core/includes/paginate.php'); // Get number of topics on a page

// Get forum ID
$fid = explode('/', $route);
$fid = $fid[count($fid) - 1];

if(!isset($fid[count($fid) - 1])){
	Redirect::to(URL::build('/forum/error/', 'error=not_exist'));
	die();
}

$fid = explode('-', $fid);
if(!is_numeric($fid[0])){
	Redirect::to(URL::build('/forum/error/', 'error=not_exist'));
	die();
}
$fid = $fid[0];

// Get user group ID
if($user->isLoggedIn()) {
    $user_group = $user->data()->group_id;
    $secondary_groups = $user->data()->secondary_groups;
} else {
    $user_group = null;
    $secondary_groups = null;
}

// Does the forum exist, and can the user view it?
$list = $forum->forumExist($fid, $user_group, $secondary_groups);
if(!$list){
	Redirect::to(URL::build('/forum/error/', 'error=not_exist'));
	die();
}

// Get data from the database
$forum_query = $queries->getWhere('forums', array('id', '=', $fid));
$forum_query = $forum_query[0];

// Get page
if(isset($_GET['p'])){
    if(!is_numeric($_GET['p'])){
        Redirect::to(URL::build('/forum'));
        die();
    } else {
        if($_GET['p'] == 1){
            // Avoid bug in pagination class
            Redirect::to(URL::build('/forum/view/' . $fid . '-'.  $forum->titleToURL($forum_query->forum_title)));
            die();
        }
        $p = $_GET['p'];
    }
} else {
    $p = 1;
}

$page_metadata = $queries->getWhere('page_descriptions', array('page', '=', '/forum/view'));
if(count($page_metadata)){
	define('PAGE_DESCRIPTION', str_replace(array('{site}', '{forum_title}', '{page}'), array(SITE_NAME, Output::getClean($forum_query->forum_title), Output::getClean($p)), $page_metadata[0]->description));
	define('PAGE_KEYWORDS', $page_metadata[0]->tags);
}

$page_title = $forum_language->get('forum', 'forum');
if(isset($p)) $page_title .= ' - ' . str_replace('{x}', $p, $language->get('general', 'page_x'));
require_once(ROOT_PATH . '/core/templates/frontend_init.php');

// Redirect forum?
if($forum_query->redirect_forum == 1){
	$smarty->assign(array(
		'CONFIRM_REDIRECT' => str_replace('{x}', $forum_query->redirect_url, $forum_language->get('forum', 'forum_redirect_warning')),
		'YES' => $language->get('general', 'yes'),
		'NO' => $language->get('general', 'no'),
		'REDIRECT_URL' => Output::getClean(htmlspecialchars_decode($forum_query->redirect_url)),
		'FORUM_INDEX' => URL::build('/forum')
	));

	// Load modules + template
	Module::loadPage($user, $pages, $cache, $smarty, array($navigation, $cc_nav, $mod_nav), $widgets);

	$page_load = microtime(true) - $start;
	define('PAGE_LOAD_TIME', str_replace('{x}', round($page_load, 3), $language->get('general', 'page_loaded_in')));

	$template->onPageLoad();

	$smarty->assign('WIDGETS', $widgets->getWidgets());

	require(ROOT_PATH . '/core/templates/navbar.php');
	require(ROOT_PATH . '/core/templates/footer.php');

	// Display template<commit_msg>Add forum description to view forum description variables<commit_after><?php 
/*
 *	Made by Samerton
 *  https://github.com/NamelessMC/Nameless/
 *  NamelessMC version 2.0.0-pr5
 *
 *  License: MIT
 *
 *  View forum page
 */

// Always define page name
define('PAGE', 'forum');

require_once(ROOT_PATH . '/modules/Forum/classes/Forum.php');
$forum = new Forum();
$timeago = new Timeago(TIMEZONE);

require(ROOT_PATH . '/core/includes/paginate.php'); // Get number of topics on a page

// Get forum ID
$fid = explode('/', $route);
$fid = $fid[count($fid) - 1];

if(!isset($fid[count($fid) - 1])){
	Redirect::to(URL::build('/forum/error/', 'error=not_exist'));
	die();
}

$fid = explode('-', $fid);
if(!is_numeric($fid[0])){
	Redirect::to(URL::build('/forum/error/', 'error=not_exist'));
	die();
}
$fid = $fid[0];

// Get user group ID
if($user->isLoggedIn()) {
    $user_group = $user->data()->group_id;
    $secondary_groups = $user->data()->secondary_groups;
} else {
    $user_group = null;
    $secondary_groups = null;
}

// Does the forum exist, and can the user view it?
$list = $forum->forumExist($fid, $user_group, $secondary_groups);
if(!$list){
	Redirect::to(URL::build('/forum/error/', 'error=not_exist'));
	die();
}

// Get data from the database
$forum_query = $queries->getWhere('forums', array('id', '=', $fid));
$forum_query = $forum_query[0];

// Get page
if(isset($_GET['p'])){
    if(!is_numeric($_GET['p'])){
        Redirect::to(URL::build('/forum'));
        die();
    } else {
        if($_GET['p'] == 1){
            // Avoid bug in pagination class
            Redirect::to(URL::build('/forum/view/' . $fid . '-'.  $forum->titleToURL($forum_query->forum_title)));
            die();
        }
        $p = $_GET['p'];
    }
} else {
    $p = 1;
}

$page_metadata = $queries->getWhere('page_descriptions', array('page', '=', '/forum/view'));
if(count($page_metadata)){
	define('PAGE_DESCRIPTION', str_replace(array('{site}', '{forum_title}', '{page}', '{description}'), array(SITE_NAME, Output::getClean($forum_query->forum_title), Output::getClean($p), Output::getClean(strip_tags(Output::getDecoded($forum_query->forum_description)))), $page_metadata[0]->description));
	define('PAGE_KEYWORDS', $page_metadata[0]->tags);
}

$page_title = $forum_language->get('forum', 'forum');
if(isset($p)) $page_title .= ' - ' . str_replace('{x}', $p, $language->get('general', 'page_x'));
require_once(ROOT_PATH . '/core/templates/frontend_init.php');

// Redirect forum?
if($forum_query->redirect_forum == 1){
	$smarty->assign(array(
		'CONFIRM_REDIRECT' => str_replace('{x}', $forum_query->redirect_url, $forum_language->get('forum', 'forum_redirect_warning')),
		'YES' => $language->get('general', 'yes'),
		'NO' => $language->get('general', 'no'),
		'REDIRECT_URL' => Output::getClean(htmlspecialchars_decode($forum_query->redirect_url)),
		'FORUM_INDEX' => URL::build('/forum')
	));

	// Load modules + template
	Module::loadPage($user, $pages, $cache, $smarty, array($navigation, $cc_nav, $mod_nav), $widgets);

	$page_load = microtime(true) - $start;
	define('PAGE_LOAD_TIME', str_replace('{x}', round($page_load, 3), $language->get('general', 'page_loaded_in')));

	$template->onPageLoad();

	$smarty->assign('WIDGETS', $widgets->getWidgets());

	require(ROOT_PATH . '/core/templates/navbar.php');
	require(ROOT_PATH . '/core/templates/footer.php');

	// Display template
{'fraction_non_alphanumeric': 0.22327612165010538, 'fraction_numerical': 0.004516711833785004, 'mean_word_length': 4.852863436123348, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 66, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, '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': '7473957', 'n_tokens_mistral': 2457, 'n_tokens_neox': 2363, 'n_words': 408}