<?php
if(!isset($txt_file)) {
	$txt_file = $pagemeta['pageid'];
}
if(!isset($template_dir)) {
	$template_dir = CORE_TEMPLATE;
}
if(!isset($template_file)) {
	$template_file = 'default.inc';
}
if(!isset($output_display)) {
	$output_display = 1;
}
if(isset($content2)) {
	$tmp_content = $content2;
}
$content2 = '';
if(!isset($content) || empty($content)) {
	$file = $pagemeta['pageid'] . '/' . $txt_file . "_" . $lang . '.txt';

	if(file_exists(PATH_DATA . '/' . $file)) {
		require_once (CORE_LIB . '/markdown.php');
		if(isset($internal))
			$content = include PATH_DATA . '/' . $file;
		else $content = file_get_contents(PATH_DATA . '/' . $file);
		$content = Markdown($content);
		$pos = strpos($content, "<hr />");
		if($pos !== FALSE) {
			$content2 = substr($content,$pos+6);
			$content = substr($content, 0, $pos);
		}
	} else {
		$error_message = sprintf($coretxt['file_error'],$file);
	}
}

if(isset($tmp_content)) {
	$content2 .= $tmp_content;
}
if(!isset($layout))
	$layout = array();
$empty = array();

$TBS = new clsTinyButStrong;
$TBS->LoadTemplate($template_dir . '/' . $template_file);
$TBS->MergeBlock('menu_block','array', $txt['main_menu']);
$TBS->MergeBlock('mob_menu_block','array', $txt['main_menu']);
$TBS->MergeBlock('lang_block','array', $allowed_langs);
$TBS->MergeBlock('lang_block_flagg','array', $allowed_langs);
$TBS->MergeBlock('footer_block','array', $txt['footer_links']);
foreach($pagemeta['locations'] as $location) {
	if(isset($layout[$location])) {
		$TBS->MergeBlock($location . '_block','array', isset($layout[$location]['data'])?$layout[$location]['data']:$empty);
		$TBS->MergeField($location . '_class', $layout[$location]['class']);
		$TBS->MergeField($location . '_close', $layout[$location]['close_link']);
	} else {
		$TBS->MergeBlock($location . '_block','array', $empty);
		$TBS->MergeField($location . '_class', '');
		$TBS->MergeField($location . '_close', '');
	}
}
if($output_display) {
	$TBS->Show();
} else {
	$TBS->Show(TBS_NOTHING);
	$content = $TBS->Source;
}
?>