<?php
@session_start ();
@ob_start ();
@ob_implicit_flush ( 0 );

define ( 'DATALIFEENGINE', true );

$member_id = FALSE;
$is_logged = FALSE;

define ( 'ROOT_DIR', dirname ( __FILE__ ) );
define ( 'SYSTEM_DIR', ROOT_DIR . '/system' );

require_once ROOT_DIR . '/system/init.php';
require_once ROOT_DIR.'/system/modules/forum/show.last.php';

if (clean_url ( $_SERVER['HTTP_HOST'] ) != clean_url ( $config['http_home_url'] )) {$replace_url = array ();$replace_url[0] = clean_url ( $config['http_home_url'] );$replace_url[1] = clean_url ( $_SERVER['HTTP_HOST'] );} else $replace_url = false;

if ($do=="forum") $tpl->load_template('forum/index.tpl');
else $tpl->load_template('main.tpl');

$tpl->set('{toporders}', $toporders);
$tpl->set ( '{login}', $tpl->result['login_panel'] );
$tpl->set ( '{info}', "<div id='dle-info'>" . $tpl->result['info'] . "</div>" );
$tpl->set('{online}', $tpl->result['online']);
$tpl->set ( '{minichat}', $tpl->result['minichat'] );
$tpl->set('{forum}', $tpl->result['forum_table']);
$tpl->set ( '{comments-last}', $commentslast );
$tpl->set('{category_menu}', $cat_menu);

if ($allow_active_news AND $do != "userinfo") {$tpl->set ( '[sort]', "" );$tpl->set ( '{sort}', news_sort ( $do ) );$tpl->set ( '[/sort]', "" );} else {$tpl->set_block ( "'\\[sort\\](.*?)\\[/sort\\]'si", "" );}
if ($dle_module == "showfull" ) {if (is_array($cat_list) AND count($cat_list) > 1 ) $category_id = implode(",", $cat_list);}

if (strpos ( $tpl->copy_template, "[category=" ) !== false) {$tpl->copy_template = preg_replace ( "#\\[category=(.+?)\\](.*?)\\[/category\\]#ies", "check_category('\\1', '\\2', '{$category_id}')", $tpl->copy_template );}
if (strpos ( $tpl->copy_template, "[not-category=" ) !== false) {$tpl->copy_template = preg_replace ( "#\\[not-category=(.+?)\\](.*?)\\[/not-category\\]#ies", "check_category('\\1', '\\2', '{$category_id}', false)", $tpl->copy_template );}

$config['http_home_url'] = explode ( "index.php", strtolower ( $_SERVER['PHP_SELF'] ) );
$config['http_home_url'] = reset ( $config['http_home_url'] );

if (! $user_group[$member_id['user_group']]['allow_admin']) $config['admin_path'] = "";

$ajax .= <<<HTML
<script language="javascript" type="text/javascript">
<!--
var dle_root       = '{$config['http_home_url']}';
var dle_admin      = '{$config['admin_path']}';
var dle_login_hash = '{$dle_login_hash}';
var dle_skin       = '{$config['skin']}';
var dle_group = {$member_id['user_group']};
var menu_short     = '{$lang['menu_short']}';
var menu_full      = '{$lang['menu_full']}';
var menu_profile   = '{$lang['menu_profile']}';
var menu_fnews     = '{$lang['menu_fnews']}';
var menu_fcomments = '{$lang['menu_fcomments']}';
var menu_send      = '{$lang['menu_send']}';
var menu_uedit     = '{$lang['menu_uedit']}';
var dle_req_field  = '{$lang['comm_req_f']}';
var dle_del_agree  = '{$lang['news_delcom']}';
var dle_del_news   = '{$lang['news_delnews']}';
HTML;

$ajax .= <<<HTML
//-->
</script>
<script type="text/javascript" src="{$config['http_home_url']}system/js/jquery.js"></script>
<script type="text/javascript" src="{$config['http_home_url']}system/js/main.js"></script>
<div id="loading-layer" style="display:none"><div id="loading-layer-text"><img src="{THEME}/images/ajax-loader.gif" alt="Загрузка..."></div></div>
HTML;

if (strpos ( $tpl->result['content'], "hs.expand" ) !== false or strpos ( $tpl->copy_template, "hs.expand" ) !== false or $pm_alert != "") {
$ajax .= <<<HTML
<script type="text/javascript" src="{$config['http_home_url']}system/js/highslide.js"></script>
<script language="javascript" type="text/javascript">
<!--
	hs.dimmingOpacity = 0.80;
	hs.graphicsDir = '{THEME}/images/';
	hs.align = 'center';
	hs.outlineType = 'rounded-white';
	hs.numberOfImagesToPreload = 0;
	hs.showCredits = false;
//-->
</script>
{$pm_alert}
HTML;
}
$tpl->set ( '{AJAX}', $ajax );

if(isset($_GET['category'])){
    $tpl->set('[newslist]','');
    $tpl->set('{newslist}', "/newslist/".$_GET['category']."/");
    $tpl->set('{news_pol}', $_GET['category']."/");
    $tpl->set('[/newslist]','');
}   else{$tpl->set_block("'\[newslist\](.*?)\[/newslist\]'si",""); $tpl->set('{news_pol}', "");}

$tpl->set ( '{headers}', $metatags );
$tpl->set ( '{content}', "<div id='dle-content'>" . $tpl->result['content'] . "</div>" );

$tpl->compile ( 'main' );
$tpl->result['main'] = str_replace ( '{THEME}', $config['http_home_url'] . 'templates/' . $config['skin'], $tpl->result['main'] );
if ($replace_url) $tpl->result['main'] = str_replace ( $replace_url[0]."/", $replace_url[1]."/", $tpl->result['main'] );
$tpl->result['main'] = str_replace("%username%", $is_logged?$member_id['name']:'Юзер', $tpl->result['main']);

echo $tpl->result['main'];
$tpl->global_clear ();
$db->close ();

GzipOut ();
?>
