<?php
/*
		[FuShow.cn] (C) 2013-2014 HXWY Inc.
		FuShow Friend V3.0				Id: index.php
		Email <service@fushow.cn>		http://fushow.cn/
*/

include_once('./common.php');

if(is_numeric($_SERVER['QUERY_STRING'])) {
	showmessage('enter_the_space', "fushow.php?uid=$_SERVER[QUERY_STRING]", 0);
}

//二级域名
if(!isset($_GET['do']) && $_SCONFIG['allowdomain']) {
	$hostarr = explode('.', $_SERVER['HTTP_HOST']);
	$domainrootarr = explode('.', $_SCONFIG['domainroot']);
	if(count($hostarr) > 2 && count($hostarr) > count($domainrootarr) && $hostarr[0] != 'www' && !isholddomain($hostarr[0])) {
		showmessage('enter_the_space', $_SCONFIG['siteallurl'].'fushow.php?domain='.$hostarr[0], 0);
	}
}



if($_SCONFIG['networkpublic'])
 {
	
	$cachefile = S_ROOT.'./data/cache_index.txt';
	$cache_malefile = S_ROOT.'./data/cache_index_male.txt';
	$cache_femalefile = S_ROOT.'./data/cache_indfex_female.txt';
	$cachetime = @filemtime($cachefile);
	
	$spacelist = array();
	$malelist = array();
	$femalelist = array();
	if($_SGLOBAL['timestamp'] - $cachetime > 900) {//900) {
		//12位热门用户
		//$query = $_SGLOBAL['db']->query("SELECT s.*, sf.note, sf.residecity, sf.sex, (YEAR(now())-birthyear) as age FROM ".tname('space')." s LEFT JOIN ".tname('spacefield')." sf ON sf.uid=s.uid ORDER BY s.friendnum DESC LIMIT 0,12");
		$query = $_SGLOBAL['db']->query("SELECT s.*, sf.note, sf.residecity, sf.sex, (YEAR(now())-birthyear) as age, m.realName, m.hospital, m.profession, m.work FROM ".tname('major')." m JOIN ".tname('collate')." c ON m.u_id=c.u_id LEFT JOIN ".tname('space')." s ON m.u_id=s.uid LEFT JOIN ".tname('spacefield')." sf ON sf.uid=s.uid WHERE c.collated=1 ORDER BY s.friendnum DESC LIMIT 0,6");
		while ($value = $_SGLOBAL['db']->fetch_array($query)) {
			$spacelist[] = $value;
		}

		// 男male
		$query_m = $_SGLOBAL['db']->query("SELECT * FROM ".tname('space')." s LEFT JOIN ".tname('spacefield')." sf ON s.uid=sf.uid  WHERE  sf.sex=1 ORDER BY s.experience LIMIT 9;");
		while ($valuemale = $_SGLOBAL['db']->fetch_array($query_m)) {
			$malelist[] = $valuemale;
		}
		// 女female
		$query_f = $_SGLOBAL['db']->query("SELECT * FROM ".tname('space')." s LEFT JOIN ".tname('spacefield')." sf ON s.uid=sf.uid  WHERE  sf.sex=2 ORDER BY s.experience LIMIT 9;");
		while ($valuefemale = $_SGLOBAL['db']->fetch_array($query_f)) {
			$femalelist[] = $valuefemale;
		}

		swritefile($cachefile, serialize($spacelist));
		swritefile($cache_malefile, serialize($malelist));
		swritefile($cache_femalefile, serialize($femalelist));
	} else {
		$spacelist = unserialize(sreadfile($cachefile));
		$malelist = unserialize(sreadfile($cache_malefile));
		$femalelist = unserialize(sreadfile($cache_femalefile));
	}	

$nyear=date("Y");


		$spacelist2 = array();	
		//推荐最好的她-给在最美年华的你
		$query2 = $_SGLOBAL['db']->query("SELECT * FROM ".tname('space')." s LEFT JOIN ".tname('spacefield')." sf ON s.uid=sf.uid  ORDER BY s.dateline LIMIT 9;");
		while ($value2 = $_SGLOBAL['db']->fetch_array($query2)) {
			$spacelist2[] = $value2;
		}
		
		$spacelist3 = array();
		//寻找优质的他，结合完美的你
		$query3 = $_SGLOBAL['db']->query("SELECT * FROM ".tname('space')." s LEFT JOIN ".tname('spacefield')." sf ON s.uid=sf.uid  ORDER BY s.experience LIMIT 12;");
		while ($value3 = $_SGLOBAL['db']->fetch_array($query3)) {
			$spacelist3[] = $value3;
		}


	
	$sql = "'SELECT * FROM `".tname('space')."` AS `space` LEFT JOIN `".tname('spacefield')."` AS `spacefield` on `space`.`uid`=`spacefield`.`uid` WHERE `spacefield`.`sex`=\'2\' ORDER BY RAND()'"; 
	//应用
	$myappcount = 0;
	$myapplist = array();
	if($_SCONFIG['my_status']) {
		$myappcount = $_SGLOBAL['db']->result($_SGLOBAL['db']->query("SELECT COUNT(*) FROM ".tname('myapp')." WHERE flag>='0'"), 0);
		if($myappcount) {
			$query = $_SGLOBAL['db']->query("SELECT appid,appname FROM ".tname('myapp')." WHERE flag>=0 ORDER BY flag DESC, displayorder LIMIT 0,7");
			while ($value = $_SGLOBAL['db']->fetch_array($query)) {
				$myapplist[] = $value;
			}
		}
	}
		
	//实名
	foreach ($spacelist as $key => $value) {
		realname_set($value['uid'], $value['username'], $value['name'], $value['namestatus']);
	}
	realname_get();
	
	$_TPL['css'] = 'network';
	include_once template("index");
} else {
	include_once(S_ROOT.'./source/network.php');
}

?>