<?php

/*
	[SupeSite/X-Space] (C)2001-2006 Comsenz Inc.
	个人空间主页文件

	$RCSfile: space.php,v $
	$Revision: 1.100 $
	$Date: 2007/06/05 13:19:37 $
*/

if(!defined('IN_SUPESITE')) {
	exit('Access Denied');
}

$uid = $_SGET['uid'] = empty($_SGET['uid'])?0:intval($_SGET['uid']);
if(empty($uid)) messagebox('error', 'not_found', S_URL);

dbconnect();

//模块布局
$leftblock = $mainblock = $rightblock = $detailblock = '';

//导航
$guidearr = array();

//获取空间信息
$space = getuserspace($uid);
if(empty($space)) {
	dbconnect(1);
	$query = $_SGLOBAL['db_bbs']->query("SELECT m.uid, m.groupid, m.username, m.regdate, m.lastvisit, m.posts, mf.avatar FROM ".tname('members', 1)." m LEFT JOIN ".tname('memberfields', 1)." mf ON mf.uid=m.uid WHERE m.uid='$uid'");
	if($space = $_SGLOBAL['db']->fetch_array($query)) {

		//判断是否有权限自动拥有空间/没有跳转到个人资料
		if(!empty($blackgroupids) && in_array($space['groupid'], $blackgroupids)) sheader(B_URL.'/viewpro.php?uid='.$uid);
		
		include_once(S_ROOT.'./include/common.inc.php');
		
		//判断是否本人
		@include_once(S_ROOT.'./data/system/group.cache.php');
		
		$space['spacename'] = $space['username'].$lang['personal_space'];
		$space['othernum'] = 10;
		
		$space['group'] = array();
		if(!empty($_SGLOBAL['grouparr'][$space['groupid']])) $space['group'] = $_SGLOBAL['grouparr'][$space['groupid']];
		
		getcookie();
		
		$space['showcp'] = 0;
		if($uid == $_SGLOBAL['supe_uid']) {
			if(!empty($space['group']['allowspace'])) $space['showcp'] = 1;
		}
		
		$space['photo'] = $space['avatar'];
		if(empty($space['photo'])) {
			$space['photo'] = S_URL.'/images/base/space_noface.gif';
		} elseif(!strexists($space['photo'], '://')) {
			$space['photo'] = B_URL.'/'.$space['photo'];
		}

		$space['sightml'] = '';
		
		//页面标题
		$title = $space['spacename'].' - '.$_SCONFIG['sitename'].' '.$_SCONFIG['seotitle'].' - Powered by X-Space';

		include_once(S_ROOT.'./include/space_nospace.inc.php');
		
		ob_out();
		exit();
	} else {
		messagebox('error', 'not_found');//不存在的用户
	}
} else {
	$musicmsgs = unserialize($space['music']);
	$musicload = empty($_SGET['notloaded'])?1:0;
	if(!empty($musicmsgs['mp3list']) && $musicload) {
		if(empty($musicmsgs['config']['passpage'])){
			if(empty($_SGET['noframe'])) {
				echo '<script language="javascript" type="text/javascript">parent.window.location.href="'.S_URL.'/iframe.php?uid='.$uid.'&passpage=1";</script>';
			}
		}else {
			$_SCONFIG['htmlspace'] = 0;
			if(empty($_SGET['noframe'])) {
				echo '<script language="javascript" type="text/javascript">parent.window.location.href="'.S_URL.'/iframe.php?uid='.$uid.'";</script>';
			}
		}
	}
	//空间锁定
	if($space['islock']) {
		$_SCONFIG['htmlspace'] = 0;
		getcookie(1);
		if($uid != $_SGLOBAL['supe_uid'] && $_SGLOBAL['member']['groupid'] != 1) messagebox('error', 'space_lock');
	} else {
		getcookie();
	}

	$isupdate = freshcookie('u'.$uid);

	//个人
	$spaceself = 0;
	if($uid == $_SGLOBAL['supe_uid']) {
		$spaceself = 1;
		$space['showcp'] = 1;
		$_SGET['php'] = 1;
	} else {
		$space['showcp'] = 0;
		//留下脚印
		if($isupdate && $_SGLOBAL['supe_uid']) $_SGLOBAL['db']->query("REPLACE INTO ".tname('visitors')." (uid, visitoruid, dateline) VALUES ('$uid', '$_SGLOBAL[supe_uid]', '$_SGLOBAL[timestamp]')");
	}
	
	//CSS预览
	if(!empty($_SGET['css'])) $_SCONFIG['htmlspace'] = 0;
	
	//html静态
	if(!empty($_SCONFIG['htmlspace'])) {
		$_SHTML['uid'] = $uid;
		$_SHTML['action'] = 'space';
		$_SGLOBAL['htmlfile'] = gethtmlfile($_SHTML);
		ehtml('get', $_SCONFIG['htmlspacetime']);
		$_SCONFIG['debug'] = 0;
		$space['showcp'] = 0;//不显示快捷管理
	}

	//更新空间查看数
	if($isupdate || !$_SCONFIG['updateview']) updatespaceviewnum($uid);

	include_once(S_ROOT.'./include/common.inc.php');
	
	//页面标题
	$title = $space['spacename'].' - '.$_SCONFIG['sitename'].' '.$_SCONFIG['seotitle'].' - Powered by X-Space';
	$keywords = $space['username'].','.$space['province'].','.$space['city'];
	$description = $space['announcement'];
	$thepagename = '<a href="'.geturl("uid/$uid").'">'.$lang['front_page_space'].'</a>';
	
	//页面特效
	$effect = '';
	if(!empty($space['flash'])) {
		@include_once(S_ROOT.'./data/system/effect.cache.php');
		if(isset($_SGLOBAL['effect'][$space['flash']])) {
			$flashurl = $_SGLOBAL['effect'][$space['flash']]['file'];
			$flashurl = str_replace('SITEURL', S_URL, $flashurl);
		} else {
			$flashurl = $space['flash'];
		}
		$flashurl = shtmlspecialchars($flashurl);//非html化
		$effect .= '<!--[if IE]><object id="flashplay" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="700" height="400" style="left: 50%; margin-left:-350px; position: absolute; top: -5px">
			<param name="movie" value="'.$flashurl.'" />
			<param name="quality" value="high" />
			<param name="wmode" value="transparent" />
			<embed src="'.$flashurl.'" id="theflash" style="left: 50%; margin-left:-350px; position: absolute; top: -5px" align="right" width="700" height="400" type="application/x-shockwave-flash" wmode="transparent" quality="high"></embed>
			</object><![endif]-->';
	}
	
	//页面公告
	if (strpos('str_'.$_SCONFIG['allowannounce'], 'front')) {
		@include_once(S_ROOT.'./data/system/announcement.cache.php');
		$sitemsg = '';
		if (empty($_SGLOBAL['announcement'])) {
			$_SGLOBAL['announcement'] = array();
		}
		foreach ($_SGLOBAL['announcement'] as $key => $listvalue) {
			$sitemsg .= '<p><a href=\"'.geturl('action/announcement/id/'.$listvalue['id']).'\" target=\"_blank\">' .cutstr($listvalue['subject'], 26, 1).'<\/a><\/p>';
		}
		if(!empty($sitemsg)) {
			$effect .= '<script type="text/javascript" language="javascript">
			<!--
			var siteMsg = "'.$sitemsg.'";
			getMsg();
			//-->
			</script>';
		}
	}

	//模块布局
	//空间模式
	$leftblock = 'search,archive,comment,favorite';
	if($space['spacemode'] == 'diy') {
		//自定义
		$leftblock = $space['choiceblockleft'];
		$mainblock = $space['choiceblockmain'];
		$rightblock = $space['choiceblockright'];
		if($space['blogmod']) $detailblock = 'newblog,newimage,group';
	} elseif($space['spacemode'] == 'bbs') {
		//论坛模式
		$leftblock = 'bbsreply,bbsfavorite,bbsforum';
		$mainblock = 'mythread,myblog,group,newitem';
		$detailblock = 'mythread,group';
	} elseif ($space['spacemode'] == 'blog') {
		//日志模式
		$mainblock = 'newblog,group,newitem,mythread';
		//是否选择只显示标题
		if(empty($space['blogmod'])) {
			$detailblock = 'group';
		} else {
			$detailblock = 'newblog,group';
		}
	} elseif ($space['spacemode'] == 'image') {
		//图片模式
		$mainblock = 'newimage,group,newitem,mythread';
		$detailblock = 'newimage,group';
	} elseif ($space['spacemode'] == 'video') {
		//影音模式
		$mainblock = 'newvideo,group,newitem,mythread';
		$detailblock = 'newvideo,group';
	} elseif ($space['spacemode'] == 'goods') {
		//商品模式
		$mainblock = 'newgoods,group,newitem,mythread';
		$detailblock = 'newgoods,group';
	} elseif ($space['spacemode'] == 'file') {
		//文件模式
		$mainblock = 'newfile,group,newitem,mythread';
		$detailblock = 'newfile,group';
	} elseif ($space['spacemode'] == 'link') {
		//书签模式
		$mainblock = 'newlink,group,newitem,mythread';
		$detailblock = 'newlink,group';
	} elseif ($space['spacemode'] == 'group') {
		//圈子模式
		$mainblock = 'group,newitem,mythread';
		$detailblock = 'group';
	} elseif ($space['spacemode'] == 'fav') {
		//收藏模式
		$mainblock = 'favorite,group,newitem,mythread';
		$detailblock = 'favorite,group';
	} elseif ($space['spacemode'] == 'track') {
		//足迹模式
		$mainblock = 'track,group,newitem,mythread';
		$detailblock = 'track,group';
	} elseif ($space['spacemode'] == 'all') {
		//综合模式
		$leftblock = 'search,archive,guestbook,comment,favorite,bbsreply,bbsforum,bbsfavorite';
		$mainblock = 'newblog,newimage,newvideo,newgoods,newfile,newlink,group,mythread,myblog';
	} else {
		//默认模式
		$leftblock = 'search,comment';
		$mainblock = 'group,newitem';
	}

	$space['showside'] = 1;
	if($space['spacemode'] != 'diy') {
		$leftblock = 'photo,action,calendar,'.(empty($leftblock)?'':$leftblock.',').'visitor,track,friend,userlink,music,information,rss';
	}

	$showtplfile = '';
	include_once(S_ROOT.'./include/space_template.inc.php');
	
	ob_out();
	
	//html静态
	if(!empty($_SCONFIG['htmlspace'])) {
		ehtml('make');
	}
}

?>