ROEmulator/www/data/back3a631fed9543b261a4f1ada7396b68c0/Discuz! X3.2 Release[20140603]/source/plugin/wechat/wsq_setting.inc.php
<?php

/**
 *      [Discuz!] (C)2001-2099 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: wsq_setting.inc.php 34566 2014-05-30 07:07:04Z nemohou $
 */

if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
	exit('Access Denied');
}

$setting = C::t('common_setting')->fetch_all(array('mobilewechat'));
$setting = (array)unserialize($setting['mobilewechat']);

require_once DISCUZ_ROOT.'./source/plugin/wechat/wechat.lib.class.php';
require_once DISCUZ_ROOT.'./source/plugin/wechat/wsq.class.php';

if(!empty($_GET['recheck'])) {
	wsq::recheck();
	$siteinfo = wsq::info();
	$setting['wsq_status'] = $siteinfo->res->status;
	$setting['wsq_lastrequest'] = $siteinfo->res->lasttime;
	$settings = array('mobilewechat' => serialize($setting));
	C::t('common_setting')->update_batch($settings);
}

if(!submitcheck('settingsubmit')) {

	if($setting['wsq_siteid']) {
			if(in_array('plugin', $_G['setting']['rewritestatus'])) {
			$url = $_G['siteurl'].rewriteoutput('plugin', 1, 'wechat', 'access', '', 'op=access');
		} else {
			$url = $_G['siteurl'].'plugin.php?id=wechat:access';
		}
	}

	$setting['wsq_siteurl'] = $setting['wsq_siteurl'] ? $setting['wsq_siteurl'] : $_G['siteurl'];
	$setting['wsq_sitename'] = $setting['wsq_sitename'] ? $setting['wsq_sitename'] : $_G['setting']['bbname'];

	require_once libfile('function/forumlist');
	$forums = '<select name="setting[wsq_fid]"><option value="">'.cplang('plugins_empty').'</option>'.forumselect(FALSE, 0, $setting['wsq_fid'], TRUE).'</select>';

	$sitelogo = $setting['wsq_sitelogo'] ? '<img src="'.$setting['wsq_sitelogo'].'" width="150" />' : '';
	$qrcode = $setting['wechat_qrcode'] ? '<img src="'.$_G['setting']['attachurl'].'common/'.$setting['wechat_qrcode'].'" width="150" />' : '';

	showtips(lang('plugin/wechat', 'wsq_tips', array('ADMINSCRIPT' => ADMINSCRIPT.'?action=')));
	showformheader('plugins&operation=config&do='.$pluginid.'&identifier=wechat&pmod=wsq_setting', 'enctype');

	showtableheader(lang('plugin/wechat', 'wechat_wsq_setting').' '.($setting['wsq_status'] ? ' ('.lang('plugin/wechat', 'wsq_status_open').')' : ($setting['wsq_siteid'] ? ' ('.lang('plugin/wechat', 'wsq_status_ing').(TIMESTAMP - $setting['wsq_lastrequest'] > 3600 ? ' <a href="'.ADMINSCRIPT.'?action=plugins&operation=config&do='.$pluginid.'&identifier=wechat&pmod=wsq_setting&recheck=yes">['.lang('plugin/wechat', 'wsq_status_try').']</a>)' : ')') : ' ('.lang('plugin/wechat', 'wsq_status_close').')')));

	showsetting(lang('plugin/wechat', 'wsq_allow'), 'setting[wsq_allow]', $setting['wsq_allow'], 'radio', 0, 0, lang('plugin/wechat', 'wsq_allow_comment'));
	if($setting['wsq_allow'] && $setting['wsq_siteid']) {
		showtablefooter();
		showtableheader();
		showsetting(lang('plugin/wechat', 'wsq_url'), '', '', '<span style="white-space:nowrap">'.$url.'</span>');
		showtablefooter();
		showtableheader();
		showsetting(lang('plugin/wechat', 'wsq_siteid'), '', '', $setting['wsq_siteid']);
		showsetting(lang('plugin/wechat', 'wsq_sitetoken'), '', '', $setting['wsq_sitetoken']);
	}
	showsetting(lang('plugin/wechat', 'wsq_sitename'), 'setting[wsq_sitename]', $setting['wsq_sitename'], 'text');
	showsetting(lang('plugin/wechat', 'wsq_sitelogo'), 'wsq_sitelogo', $setting['wsq_sitelogo'], 'file', 0, 0, lang('plugin/wechat', 'wsq_sitelogo_comment', array('sitelogo' => $sitelogo)));
	showsetting(lang('plugin/wechat', 'wsq_sitesummary'), 'setting[wsq_sitesummary]', $setting['wsq_sitesummary'], 'textarea');
	showsetting(lang('plugin/wechat', 'wsq_siteurl'), 'setting[wsq_siteurl]', $setting['wsq_siteurl'], 'text', 0, 0, lang('plugin/wechat', 'wsq_siteurl_comment'));
	showsetting(lang('plugin/wechat', 'wsq_fid'), '', '', $forums, 0, 0, lang('plugin/wechat', 'wsq_fid_comment'));
	if(!empty($_G['setting']['domain']['root']['forum'])) {
		showsetting(lang('plugin/wechat', 'wsq_domain'), '', '', 'http://<input type="text" name="setting[wsq_domain]" class="txt" value="'.$setting['wsq_domain'].'" style="width:100px; margin-right:0px;" >.'.$_G['setting']['domain']['root']['forum'], !function_exists('domain_create'), 0, lang('plugin/wechat', 'wsq_domain_comment'));
	} else {
		showsetting(lang('plugin/wechat', 'wsq_domain'), 'setting[wsq_domain]', '', 'text', 1, 0, lang('plugin/wechat', 'wsq_domain_comment'));
	}
	showsetting(lang('plugin/wechat', 'wechat_float_qrcode'), 'setting[wechat_float_qrcode]', $setting['wechat_float_qrcode'], 'radio');
	showsubmit('settingsubmit');
	showtablefooter();

	showformfooter();

} else {

	if($_FILES['wsq_sitelogo']['tmp_name']) {
		$upload = new discuz_upload();
		if(!$upload->init($_FILES['wsq_sitelogo'], 'common', random(3, 1), random(8)) || !$upload->save()) {
			cpmsg($upload->errormessage(), '', 'error');
		}
		$parsev = parse_url($_G['setting']['attachurl']);
		$_GET['setting']['wsq_sitelogo'] = ($parsev['host'] ? '' : $_G['siteurl']).$_G['setting']['attachurl'].'common/'.$upload->attach['attachment'];
	} else {
		$_GET['setting']['wsq_sitelogo'] = $setting['wsq_sitelogo'];
	}

	if(!$_GET['setting']['wsq_fid']) {
		cpmsg(lang('plugin/wechat', 'wsq_fid_empty'), '', 'error');
	}

	if(!$setting['wsq_sitetoken']) {
		$siteinfo = wsq::register($_GET['setting']['wsq_sitename'], $_GET['setting']['wsq_siteurl'], $_GET['setting']['wsq_sitelogo'], $_GET['setting']['wsq_sitesummary'], $setting['wechat_mtype'], $setting['wechat_qrtype']);
		if(!$siteinfo || $siteinfo->code) {
			cpmsg(lang('plugin/wechat', 'wsq_api_register_error'), '', 'error');
		}
		$_GET['setting']['wsq_siteid'] = $siteinfo->res->siteid;
		$_GET['setting']['wsq_sitetoken'] = $siteinfo->res->token;
	} else {
		$siteinfo = wsq::edit($_GET['setting']['wsq_sitename'], $_GET['setting']['wsq_siteurl'], $_GET['setting']['wsq_sitelogo'], $_GET['setting']['wsq_sitesummary'], $setting['wechat_mtype'], $setting['wechat_qrtype']);
		if(!$siteinfo || $siteinfo->code) {
			cpmsg(lang('plugin/wechat', 'wsq_api_edit_error'), '', 'error');
		}
	}

	if(function_exists('domain_create')) {
		if(preg_match('/^((http|https|ftp):\/\/|\.)|(\/|\.)$/i', $_GET['setting']['wsq_domain'])) {
			cpmsg('setting_domain_http_error', '', 'error');
		}
	}

	$_GET['setting']['wsq_status'] = $siteinfo->res->status;
	$_GET['setting']['wsq_lastrequest'] = $siteinfo->res->lasttime;

	$settings = array('mobilewechat' => serialize($_GET['setting'] + $setting));
	C::t('common_setting')->update_batch($settings);

	updatecache('setting');

	if($_GET['setting']['wsq_allow']) {
		WeChatHook::updateResponse(array(
			'receiveMsg::text' => array('plugin' => 'wechat', 'include' => 'response.class.php', 'class' => 'WSQResponse', 'method' => 'text'),
			'receiveEvent::click' => array('plugin' => 'wechat', 'include' => 'response.class.php', 'class' => 'WSQResponse', 'method' => 'click'),
			'receiveEvent::subscribe' => array('plugin' => 'wechat', 'include' => 'response.class.php', 'class' => 'WSQResponse', 'method' => 'subscribe'),
			'receiveEvent::scan' => array('plugin' => 'wechat', 'include' => 'response.class.php', 'class' => 'WSQResponse', 'method' => 'scan'),
		));
		WeChatHook::updateRedirect(array('plugin' => 'wechat', 'include' => 'response.class.php', 'class' => 'WSQResponse', 'method' => 'redirect'));
		WeChatHook::updateViewPluginId('wechat');
	} else {
		$wechatredirect = WeChatHook::getRedirect();
		if($wechatredirect['plugin'] == 'wechat') {
			$wechatredirect = array();
		}
		WeChatHook::updateRedirect($wechatredirect);
		WeChatHook::updateViewPluginId('');
	}

	if(function_exists('domain_create') && $_G['setting']['domain']['root']['forum']) {
		if($_GET['setting']['wsq_domain']) {
			domain_create('wechat', $_GET['setting']['wsq_domain'], $_G['setting']['domain']['root']['forum']);
		} else {
			domain_delete('wechat');
		}
	}

	cpmsg('setting_update_succeed', 'action=plugins&operation=config&do='.$pluginid.'&identifier=wechat&pmod=wsq_setting', 'succeed');
}

?>