<?php
define('IN_ADMINCP', true);
require '../../../source/class/class_core.php';
require '../config.php';
$chaeset="'".ODZ_CHARSET."'";
if($chaeset == "'utf-8'"){
    $chaeset = 'utf8';
}
header('Content-Type:text/html; charset=utf-8');
error_reporting(0);



//初始化环境
C::app()->init();
$url = parse_url($_G['siteurl']);
$_G['siteurl'] = $url['scheme'].'://'.$url['host'].'/';


include './config.php';


//扩展检测
echo '开始检测扩展<br/>';
$is_ok = true;
foreach($extensions as $extension){
	if(!extension_loaded($extension)){
		echo '<span style="color:red">'.$extension.'扩展不存在</span><br/>';
		$is_ok = false;
	}
}

if(!$is_ok){
	exit;
}

echo '<span style="color:#cc0000">扩展检测正确，检测完毕</span><br/>';

echo '<br/>';


echo '开始安装表情<br/>';
//表情安装
$check_smiley_code = array('{:mocs_25:}','{:mocs_26:}','{:mocs_27:}','{:mocs_28:}','{:mocs_29:}',);
$check_array = array();
foreach($check_smiley_code as $smile){
	if($result = DB::fetch_first('SELECT * FROM '.DB::table('common_smiley')." WHERE code='{$smile}'")){
		if(empty($check_array) || (!empty($check_array) && $check_array[0] == $result['typeid'])){
			$check_array[] = $result['typeid'];
		}
	}
}
if(count($check_array) == 5){
	echo '表情包存在,下面判断是否启用,如果未启用会自动启用<br/>';
	$typeid = $check_array[0];
	$result = DB::fetch_first('SELECT * FROM '.DB::table('forum_imagetype')." WHERE typeid='{$typeid}'");
	if($result['available'] == 1){
		echo '表情正确<br/>';
	}else{
		DB::query('UPDATE '.DB::table('forum_imagetype')." SET  available=1 WHERE typeid='{$typeid}'");
		echo '表情自动启用成功<br/>';
	}
}else{
	//表情包不存在,安装mocuz表情
	require_once libfile('function/importdata');
	require_once libfile('function/admincp');
	global $importtxt;
	$importtxt = file_get_contents('./mocuz_smiles_310.xml');

	$smileyarray = getimportdata('Discuz! Smilies');

$typeid = $check_array[0];

	foreach($smileyarray['smilies'] as $key => $smiley) {
		C::t('common_smiley')->insert(array('type'=>'smiley', 'typeid'=>$typeid, 'displayorder'=>$smiley['displayorder'], 'code'=>$smiley['code'], 'url'=>$smiley['url']));
	}
	echo 'mocuz表情安装成功<br/>';

}
echo '<span style="color:#cc0000">表情安装正确，安装完毕</span><br/>';
updatecache(array('smileytypes', 'smilies', 'smileycodes', 'smilies_js'));

echo '<hr/>';
echo '
<a href="/mocuz/manage/install.php" target="_blank">安装站长管理后台</a>';
/*
echo 'mocuz安装完毕,5秒后跳到五折卡安装';
echo '<script>setTimeout(function(){
	window.location.href = \'/mocuz/card/install.php\'
},5000); </script>';
*/
