Displaying external content through a plugin in the Scribe/Upfront theme

Background: I have an application called The Next Generation of Genealogy Sitebuilding (TNG) installed on my site that integrates its content into WordPress through a plugin. The currently live site is at http://www.larleegenealogy.org. The way the plugin is coded is to more or less hijack the_post() and inject the appropriate TNG page content instead. The actual code in the script that does this is:

/************************************************
*                                               *
*             OUTPUT THE TNG PAGE               *
*                                               *
* mbtng_use_tng_homepage                        *
* mbtng_frontend_header                         *
* mbtng_frontend_footer                         *
* mbtng_fake_post                               *
* mbtng_output_page                             *
* mbtng_buffer_start                            *
* mbtng_buffer_end                              *
* mbtng_discard_output                          *
* mbtng_eval_php                                *
************************************************/

function mbtng_use_tng_homepage() {
	if (get_option('mbtng_use_wordpress_homepage')==TRUE && mbtng_requested_url() == get_option('mbtng_url'))
		return false;
	else
		return true;
}

//Adds TNG header to Wordpress header
function mbtng_frontend_header() {
	global $tng_head, $languages_path;
// Roger - if you want to over-ride these styles, copy these lines to mytngstyle.css and change them there
    $tng_head = &quot;<style type=\&quot;text/css\&quot;>
    #tng_main {line-height: 1.2em}
    #tng_main tr td {padding: 2px 4px; margin:0; border-top: none}
    p, pre {line-height: 1.2em}
    </style>\r\n&quot;.$tng_head;
	if (strpos(mbtng_filename(), 'admin') !== FALSE)
		$tng_head .= '<base href = &quot;'.get_permalink(get_option('mbtng_wordpress_page')).'&quot;/>';
	$tng_head .= &quot;<style type=\&quot;text/css\&quot;>#tng_main td.menuback, #tng_main td.spacercol, #tng_main table.page td.section td.fieldname {display:none}</style>&quot;;
	if ($tng_head != '')
		echo $tng_head;
}

//Adds TNG footer to Wordpress footer
function mbtng_frontend_footer() {
	global $tng_footer;
	if ($tng_footer != '')
		echo $tng_footer;
}

// Returns the TNG Wordpress post whenever a TNG page is requested
function mbtng_fake_post($posts){
	if (mbtng_display_page()){
		$posts = get_pages('include='.get_option('mbtng_wordpress_page'));
		add_filter('user_trailingslashit', 'mbtng_smart_trailingslashit');
	}
	return $posts;
}

//Outputs the TNG code (outside the loop to minimise CSS conflicts)
function mbtng_output_page() {
	global $tng_output;
	include(plugin_dir_path( __FILE__ ).'customconfig.php');
	if (mbtng_display_page() && mbtng_use_tng_homepage()) {
		if (get_option('mbtng_require_login') == '' || is_user_logged_in() || check_permissions('') ) {
			echo $tng_output;
			ob_start();
		}
		else {
			echo tng_login_form( $item );
			ob_start();
		}
	}
}

// Buffers Wordpress and TNG code to allow for correct merging of HTML
function mbtng_buffer_start() {
	global $tng_output, $tng_head, $tng_footer;
	$query = mbtng_requested('query');
	if (mbtng_display_page()) {
		$tng_folder = get_option('mbtng_path');
		$filename = mbtng_filename();
		if (mbtng_extension() == 'php') {
 			if ($filename == 'newacctform.php' && get_option('mbtng_integrate_logins')) {
				header(&quot;Location: &quot;.trailingslashit(get_bloginfo('wpurl')).&quot;wp-login.php?action=register&quot;);
				die();
			}
 			if ($filename == 'login.php' && get_option('mbtng_integrate_logins')) {
				header(&quot;Location: &quot;.trailingslashit(get_bloginfo('wpurl')).&quot;wp-login.php&quot;);
				die();
			}
 			if ($filename == 'logout.php' && get_option('mbtng_integrate_logins')) {
				if (function_exists('wp_logout_url'))
					header(&quot;Location: &quot;.html_entity_decode(wp_logout_url()));
				else
					header(&quot;Location: &quot;.trailingslashit(get_bloginfo('wpurl')).&quot;wp-login.php?action=logout&quot;);
				die();
			}
			$tng_output = mbtng_eval_php($filename);
			$non_template_files = array ('tngrss.php', 'addbookmark.php', 'fpdf.php', 'ufpdf.php');
			if (in_array($filename, $non_template_files) || (isset($_REQUEST['tngprint']) && $_REQUEST['tngprint']==1) || stripos($filename, 'admin') !== FALSE || stripos($filename, 'ajx_') !== FALSE || stripos($filename, 'img_') !== FALSE || stripos($filename, 'find') !== FALSE || stripos($filename, 'rpt_') !== FALSE || stripos($tng_output, '<!-- The Next Generation of Genealogy Sitebuilding') === FALSE) {
				echo $tng_output;
				die();
			} else {
				if ($filename == 'admin/index.php') {
					$tng_output = '<div id=&quot;tng_main&quot;>'.mbtng_display_tng_admin(false).'</div>';
				}
				else {
					$head_start = stripos ($tng_output, '<head>')+6;
					$head_end = stripos ($tng_output, '</head>');
					$tng_head = substr ($tng_output, $head_start, $head_end-$head_start);
					$tng_head = str_replace('.css?', '.css?frontend&', $tng_head);
                    $tng_head = str_replace('.css&quot; rel', '.css?frontend&quot; rel', $tng_head);
					$footer_start = stripos ($tng_output, '</body>')+7;
					$footer_end = stripos ($tng_output, '</html>');
					$tng_footer = substr ($tng_output, $footer_start, $footer_end-$footer_start);
					$output_start = stripos($tng_output, '>', stripos ($tng_output, '<body'))+1;
					$output_end = $footer_start-8;
					$tng_output = '<div id=&quot;tng_main&quot;>'.substr ($tng_output, $output_start, $output_end-$output_start).'</div>';
				}
				ob_start( );
			}
		}
	}
}

//Flushes the output buffer
function mbtng_buffer_end() {
	@ob_end_flush();
}

// Discards contents of page if TNG is displayed
function mbtng_discard_output() {
	if (mbtng_display_page() && mbtng_use_tng_homepage()) {
		ob_clean();
		// Remove actions in case loop used elsewhere (e.g. in sidebar)
		remove_action('loop_start', 'mbtng_output_page');
		remove_action('loop_end', 'mbtng_discard_output');
	}

}

//Runs the TNG PHP code and returns the HTML
function mbtng_eval_php($filename) {
	global $tng_output;
	if ($tng_output == '') {
		$tng_folder = get_option('mbtng_path');
		if (stripos($filename, 'admin') !== FALSE) {
			//$filename = substr ($filename, 6);
			$admin = true;
			//$tng_folder .= 'admin';
		} else {
			ini_set('include_path', ini_get('include_path').PATH_SEPARATOR.$tng_folder);
			$admin = false;
		}
		eval('?>'.get_option('mbtng_globalvars').'<?php ');
		ob_start();
		$code = file_get_contents(mbtng_folder_trailingslashit($tng_folder).$filename);
		if ($admin || $filename == 'pdfform.php')
			chdir($tng_folder);
		eval(&quot;?>$code<?php &quot;);
		$output = ob_get_contents();
		ob_end_clean();
		$tng_output = $output;
	}
	mbtng_close_tng_table();
	return $tng_output;
}

If you need to see the whole file I can attach it later. The problem I am having right now is that instead of displaying the content inside the template, in Scribe it is displaying the content above the template. I am attaching two screenshots -- one is the way it is being displayed in the Scribe theme on my development site; the other is the way it is displayed correctly on the live site.

I suspect the problem has to do with the way Upfront constructs the template layouts, but I can't wrap my head around the code. I realize I am pushing boundaries here, but it was be so totally awesome if I could have help coming up with a customized template to handle this kind of setup. I have enabled Support Access in the dashboard if that will help in any way.

Thanks!