<?php

/**
 *      [Discuz!] (C)2001-2099 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: plugin.php 20095 2011-02-14 09:32:12Z liulanbo $
 */

define('APPTYPEID', 227);
define('CURSCRIPT', 'dzz');
define('DZZSCRIPT', basename(__FILE__));
require './source/class/class_core.php';
require './dzz/function/dzz_core.php';
require './dzz/dzz_version.php';
require_once './source/function/function_home.php';
$discuz = & discuz_core::instance();
if($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST)) {
	$_GET = array_merge($_GET, $_POST);
}
$discuz->init();
$mod = htmlspecialchars(!empty($_GET['mod']) ? $_GET['mod'] : (!empty($_POST['mod']) ? $_POST['mod'] : ''));
$op = htmlspecialchars(!empty($_GET['op']) ? $_GET['op'] : (!empty($_POST['op']) ? $_POST['op'] : 'index'));

$lang=& dzzlang('message');
$agent=$_SERVER["HTTP_USER_AGENT"];
 if(strpos($agent,"MSIE 6.0"))   $_G['browser']='ie6'; 
 if(strpos($agent,"MSIE 7.0"))   $_G['browser']='ie7'; 
 if(strpos($agent,"MSIE 8.0"))  $_G['browser']='ie8'; 

define('DZZ_ROOT', DISCUZ_ROOT.'./dzz/');

$uid = $_GET['uid']=='' ? intval($_G['uid']) : intval($_GET['uid']);
if($_GET['username']) {
	$member = DB::fetch_first("SELECT uid FROM ".DB::table('common_member')." WHERE username='$_GET[username]' LIMIT 1");
	if(empty($member)) {
		showmessage('space_does_not_exist',DZZSCRIPT);
	}
	$uid = $member['uid'];
}
$space = dzzgetspace($uid);
$space['self']=intval($space['self']);

if($uid>0 && !$space['uid']) {
		showmessage('space_does_not_exist',DZZSCRIPT);
}
if($uid==0 && $_G['uid']>0 && $_G['adminid']!=1){
	showmessage('space_does_not_exist',DZZSCRIPT);
}
if($_G['adminid']==1) $space['self']=2;
if($_G['setting']['dzz_sysconfig']){
	$sysconfig=dstripslashes(unserialize(stripslashes($_G['setting']['dzz_sysconfig'])));
}else{
	$sysconfig=DB::fetch_first("select * from ".DB::table('dzz_config')." where id='1'");
}
$sysconfig['ucenterurl']=$_G['setting']['ucenterurl'];
	
if(empty($mod)){
	define('CURMODULE', 'dzzindex');
	if($space['spacename']) $navtitle=$space['spacename'];
	elseif($space['username']) $navtitle=$space['username'].$lang['de'].$lang['desktop'];
	else $navtitle='';
	if($space['metakeyword']) $metakeywords=$space['metakeyword'];
	else $metakeywords=$sysconfig['keywords'];
	if($space['metadescription']) $metadescription=$space['metadescription'];
	else $metadescription=$sysconfig['description'];
	
	$navbar=array();
	if($_G['setting']['dzz_nav']){
		$navbar=dstripslashes(unserialize(stripslashes($_G['setting']['dzz_nav'])));
	}else{
		$query=DB::query("select * from ".DB::table('dzz_navbar')." where `avaliable`>0 ORDER BY disp");
		while($value=DB::fetch($query)){
			$navbar[$value['navid']]=$value;
		}
	}
	$nav=array();	
	foreach($navbar as $key=>$value){
		if($value['navicon']) $value['navicon']=$_G['setting']['attachurl'].$value['navicon'];
		$value['navname_short']=str_replace('...','',getstr($value['navname'],12));
		$nav[$value['navid']]=$value;
	}
	if($_G['setting']['dzz_iconview']){
		$iconview=dstripslashes(unserialize(stripslashes($_G['setting']['dzz_iconview'])));
	}else{
		$query=DB::query("select * from ".DB::table('dzz_iconview')." where `avaliable`>0 ORDER BY disp");
		$iconview=array();
		while($value=DB::fetch($query)){
			$iconview[$value['id']]=$value;
		}
	}
	include dzztemplate('index');
}else{
	define('CURMODULE', $mod);
	runhooks();
	if(strpos(strtolower($mod),'plugin:')!==false){
		list($folder,$identifier) = explode(':', $mod);
		$modfile='./dzz/'.$folder.'/'.$identifier.'/'.($op?$op:'index.php');
		if(@!file_exists(DISCUZ_ROOT.$modfile)){
			showmessage('plugin_nonexistence');
		}
	}else{
		if(@!file_exists(DISCUZ_ROOT.($modfile = './dzz/'.$mod.'/'.$op.'.php'))) {
			showmessage('undefined_action', '', array('mod' => $mod));
		}
	}
	include DISCUZ_ROOT.$modfile;
}
?>