<?php

/*
	[SupeSite/X-Space] (C)2001-2006 Comsenz Inc.
	­º­¶

	$RCSfile: index.php,v $
	$Revision: 1.45 $
	$Date: 2006/10/31 03:15:34 $
*/

include_once('./include/main.inc.php');

if($_SCONFIG['urltype'] == '2') $parsegetvar = empty($_SERVER['PATH_INFO'])?'':substr($_SERVER['PATH_INFO'], 1);
if(empty($parsegetvar)) $parsegetvar = empty($_SERVER['QUERY_STRING'])?'':$_SERVER['QUERY_STRING'];

if(!empty($parsegetvar)) {
	$parsegetvar = addslashes($parsegetvar);
	if($_SCONFIG['allowdomain'] == 3 && strpos($parsegetvar, '_') === false && !is_numeric(substr($parsegetvar, 0, 1))) mydomain($parsegetvar);
	$_SGET = parseparameter(str_replace('_', '/', $parsegetvar));
} else {
	if(!empty($_SCONFIG['allowdomain'])) {
		if(strpos(S_URL, $_SERVER['HTTP_HOST']) === false) {
			$hostarr = explode('.', $_SERVER['HTTP_HOST']);
			if(count($hostarr) > 2) {
				if(count($hostarr) > 3 && $hostarr[0] == 'www') {
					$hostdomain = $hostarr[1];
				} else {
					$hostdomain = $hostarr[0];
				}
			}
		}
		if(!empty($hostdomain)) mydomain(rawurlencode($hostdomain));
	}
}

if(empty($_SGET['action'])) {
	if(empty($_SGET['uid'])) {
		$_SGET['action'] = 'index';
	} else {
		$_SGET['action'] = 'space';
	}
}

$channelmenu = $showmenu = array();
$channeldefault = array('action'=>'index', 'name'=>'');
foreach ($_SCONFIG['channel'] as $value) {
	if(in_array($value['action'], array('index', 'news', 'blog', 'image', 'goods', 'file', 'link', 'bbs'))) {
		if($value['show'] && ($value['action'] == 'bbs' || strpos('usetype'.$_SCONFIG['usetype'], $value['action']))) {
			$channelmenu[] = $value;
			$showmenu[$value['action']] = 1;
		}
		if($value['default']) {
			$channeldefault = array('action'=>$value['action'], 'name'=>'');
		}
	} else {
		if($value['show']) $channelmenu[] = $value;
		if($value['default']) $channeldefault = array('action'=>'channel', 'name'=>$value['action']);
	}
}

$keywordarr = $descriptionarr = $guidearr = $titlearr = array();

if($_SGET['action'] == 'channel' && !empty($_SGET['name'])) {
	$scriptfile = S_ROOT.'./channel/channel_'.str_replace(array('/', '\\'), '', $_SGET['name']).'.php';
	if(file_exists($scriptfile)) {
		include_once($scriptfile);
		exit;
	}
}
if($_SGET['action'] != 'index') {
	$scriptfile = S_ROOT.'./'.str_replace(array('/', '\\'), '', $_SGET['action']).'.php';
	if(file_exists($scriptfile)) {
		include_once($scriptfile);
		exit;
	}
}
if($channeldefault['action'] == 'channel') {

	$_SGET['name'] = $channeldefault['name'];
	include_once(S_ROOT.'./channel/channel_'.$channeldefault['name'].'.php');

} elseif($channeldefault['action'] == 'index') {

	if(!empty($_SCONFIG['htmlindex'])) {
		$_SHTML['action'] = 'index';
		$_SGLOBAL['htmlfile'] = gethtmlfile($_SHTML);
		ehtml('get', $_SCONFIG['htmlindextime']);
		$_SCONFIG['debug'] = 0;
	}

	include_once(S_ROOT.'./include/common.inc.php');

	$title = $_SCONFIG['sitename'];
	$keywords = $_SCONFIG['sitename'];
	$description = $_SCONFIG['sitename'];

	$guidearr = array();

	include template('index');

	if(!empty($_SCONFIG['htmlindex'])) {
		ehtml('make');
	} else {
		maketplblocknames('index');
		maketplblockvalue('cache');
	}
} else {
	include_once(S_ROOT.'./'.$channeldefault['action'].'.php');
}

?>