<?php

/*
		[FuShow.cn] (C) 2013-2014 HXWY Inc.

		FuShow Friend V3.0				Id: common.php
		Email <service@fushow.cn>		http://fushow.cn/
*/



@define('IN_FUSHOW', TRUE);

define('X_VER', '1.5');

define('X_RELEASE', '20090114');

define('D_BUG', '0');



D_BUG?error_reporting(7):error_reporting(0);

$_SGLOBAL = $_SCONFIG = $_SBLOCK = $_TPL = $_SCOOKIE = $_SN = $space = array();



//程序目录

define('S_ROOT', dirname(__FILE__).DIRECTORY_SEPARATOR);



//基本文件
if(!@include_once(S_ROOT.'./config.php')) {
	//header("Location: install/session.php");//安装
	//exit();
}
if(!file_exists(S_ROOT.'./data/install.lock')){
		header("Location: install/session.php");//安装
		exit();
}



//通用函数

include_once(S_ROOT.'./source/function_common.php');



//时间

$mtime = explode(' ', microtime());

$_SGLOBAL['timestamp'] = $mtime[1];

$_SGLOBAL['supe_starttime'] = $_SGLOBAL['timestamp'] + $mtime[0];



//GPC过滤

$magic_quote = get_magic_quotes_gpc();

if(empty($magic_quote)) {

	$_GET = saddslashes($_GET);

	$_POST = saddslashes($_POST);

}



//本站URL

if(empty($_SC['siteurl'])) $_SC['siteurl'] = getsiteurl();



//链接数据库

dbconnect();



//缓存文件

foreach (array('config', 'app', 'userapp', 'ad') as $value) {

	if(!@include_once(S_ROOT.'./data/data_'.$value.'.php')) {

		include_once(S_ROOT.'./source/function_cache.php');

		$cache_func = $value.'_cache';

		$cache_func();

	}

}



//COOKIE

$prelength = strlen($_SC['cookiepre']);

foreach($_COOKIE as $key => $val) {

	if(substr($key, 0, $prelength) == $_SC['cookiepre']) {

		$_SCOOKIE[(substr($key, $prelength))] = empty($magic_quote) ? saddslashes($val) : $val;

	}

}



//启用GIP

if ($_SC['gzipcompress'] && function_exists('ob_gzhandler')) {

	ob_start('ob_gzhandler');

} else {

	ob_start();

}



//初始化

$_SGLOBAL['supe_uid'] = 0;

$_SGLOBAL['supe_username'] = '';

$_SGLOBAL['inajax'] = empty($_GET['inajax'])?0:intval($_GET['inajax']);

$_SGLOBAL['ajaxmenuid'] = empty($_GET['ajaxmenuid'])?'':$_GET['ajaxmenuid'];

$_SGLOBAL['refer'] = empty($_SERVER['HTTP_REFERER'])?'':$_SERVER['HTTP_REFERER'];



//登录注册防灌水机

if(empty($_SCONFIG['login_action'])) $_SCONFIG['login_action'] = md5('login'.md5($_SCONFIG['sitekey']));

if(empty($_SCONFIG['register_action'])) $_SCONFIG['register_action'] = md5('register'.md5($_SCONFIG['sitekey']));



//整站风格

if(empty($_SCONFIG['template'])) {

	$_SCONFIG['template'] = 'default';

}

if($_SCOOKIE['mytemplate']) {

	$_SCOOKIE['mytemplate'] = str_replace('.','',trim($_SCOOKIE['mytemplate']));

	if(file_exists(S_ROOT.'./template/'.$_SCOOKIE['mytemplate'].'/style.css')) {

		$_SCONFIG['template'] = $_SCOOKIE['mytemplate'];

	} else {

		ssetcookie('mytemplate', '');

	}

}



//处理REQUEST_URI

if(!isset($_SERVER['REQUEST_URI'])) {  

	$_SERVER['REQUEST_URI'] = $_SERVER['PHP_SELF'];

	if(isset($_SERVER['QUERY_STRING'])) $_SERVER['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];

}

	

//判断用户登录状态

checkauth();



//用户菜单

getuserapp();

//导航栏*毕文汉_2014年4月2
getnav();

getattid();

$configs = array();
$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('config'));
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
	$configs[$value['var']] = shtmlspecialchars($value['datavalue']);
}



//处理UC应用

$_SGLOBAL['appmenus'] = $_SGLOBAL['appmenu'] = array();

if($_SGLOBAL['app']) {

	foreach ($_SGLOBAL['app'] as $value) {

		if($value['open']) {

			if(empty($_SGLOBAL['appmenu'])) {

				$_SGLOBAL['appmenu'] = $value;

			} else {

				$_SGLOBAL['appmenus'][] = $value;

			}

		}

	}

}

include_once(S_ROOT.'./pay/function.php');
if (!empty($_SGLOBAL['supe_uid'])) {
$vips = ckvip($_SGLOBAL['supe_uid']);
}

?>