<?php
if (!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
	exit('Access Denied');
}
$server_url='action=plugins&operation=config&do=' . $pluginid . '&identifier=csdn123_news&pmod=chrome';
$regvest_url='?action=plugins&operation=config&do=' . $pluginid . '&identifier=csdn123_news&pmod=adminVest&subpmod=regvest&formhash=' . FORMHASH;
require './source/plugin/csdn123_news/function_common.php';
if (!isset($_G['cache']['csdn123_news_send'])) {
	loadcache('csdn123_news_send');
}
$zhiwu55_data=array();
$zhiwu55_data = dunserialize($_G['cache']['csdn123_news_send']);
if(empty($zhiwu55_data['post_safecode']))
{
	$zhiwu55_data['post_safecode']=md5(uniqid());
	$csdn123_news_send = serialize($zhiwu55_data);
	savecache('csdn123_news_send',$csdn123_news_send);
}
if($_GET['formhash'] == FORMHASH && !empty($_GET['zhiwu55_agrs']) && $_GET['zhiwu55_agrs']=='yes')
{
	if(empty($_GET['first_uid']))
	{
		cpmsg("csdn123_news:uid_error","","error");
	} else {
		$first_uid=$_GET['first_uid'];
	}
	if(empty($_GET['reply_uid']))
	{
		cpmsg("csdn123_news:uid_error","","error");
	} else {
		$reply_uid=$_GET['reply_uid'];
	}
	if(preg_match('/^[\d+,?]+$/',$first_uid)===0 || preg_match('/^[\d+,?]+$/',$reply_uid)===0)
	{
		cpmsg("csdn123_news:uid_error","","error");
	}
	$zhiwu55_data=array_merge($zhiwu55_data,$_GET);
	$csdn123_news_send = serialize($zhiwu55_data);
	savecache('csdn123_news_send',$csdn123_news_send);
	cpmsg("csdn123_news:succeed",$server_url,"succeed");

} elseif($_GET['formhash'] == FORMHASH && !empty($_GET['zhiwu55_send_form']) && $_GET['zhiwu55_send_form']=='yes') {
	
	require_once libfile('function/forumlist');
	require_once libfile('function/portalcp');
	require_once libfile('function/group');
	$grouplistArr=grouplist('displayorder',false,100);
	if(!empty($zhiwu55_data['fid']))
	{
		$typeclassArr = C::t('forum_threadclass')->fetch_all_by_fid($zhiwu55_data['fid']);
	}
	$first_uid = getRndUid_zhiwu55fun(30);
	$reply_uid = getRndUid_zhiwu55fun(30);
	if(strlen($first_uid)<5)
	{
		$first_uid = 1;
	}
	if(strlen($reply_uid)<5)
	{
		$reply_uid = 1;
	}
	if(empty($zhiwu55_data['first_uid']))
	{
		$zhiwu55_data['first_uid'] = $first_uid;
	}
	if(empty($zhiwu55_data['reply_uid']))
	{
		$zhiwu55_data['reply_uid'] = $reply_uid;
	}
	if(empty($zhiwu55_data['intval_time']) && !is_numeric($zhiwu55_data['intval_time']))
	{
		$zhiwu55_data['intval_time']=3600;
	}
	if(empty($zhiwu55_data['min_views']))
	{
		$zhiwu55_data['min_views']=1;
	}
	if(empty($zhiwu55_data['max_views']))
	{
		$zhiwu55_data['max_views']=1000;
	}
	if(empty($zhiwu55_data['forum_portal']))
	{
		$zhiwu55_data['forum_portal']='forum';
	}
	if(empty($zhiwu55_data['replaynum']) && !is_numeric($zhiwu55_data['replaynum']))
	{
		$zhiwu55_data['replaynum']=3;
	}
	if(empty($zhiwu55_data['sendtime']) && !is_numeric($zhiwu55_data['sendtime']))
	{
		$zhiwu55_data['sendtime']=1;
	}	
	$zhiwu55_data['image_localized']=1;
	if(empty($zhiwu55_data['chinese_encoding']) && !is_numeric($zhiwu55_data['chinese_encoding']))
	{
		$zhiwu55_data['chinese_encoding']=1;
	}
	if(empty($zhiwu55_data['image_center']) && !is_numeric($zhiwu55_data['image_center']))
	{
		$zhiwu55_data['image_center']=1;
	}
	if(empty($zhiwu55_data['auth_admin']))
	{
		$zhiwu55_data['auth_admin']=$_G['uid'];
	}
	if(empty($zhiwu55_data['hzw_remotefile']))
	{
		$zhiwu55_data['hzw_remotefile']=1;
	}
	include template('csdn123_news:send');

} else {
	
	if(!empty($zhiwu55_data['forum_portal']) && $zhiwu55_data['forum_portal']=='forum')
	{
		require_once libfile('function/forumlist');
		if(!isset($_G['cache']['forums'])) {
			loadcache('forums');
		}
		$forumcache = $_G['cache']['forums'];
		$send_hint_info=lang('plugin/csdn123_news', 'forum');
		$send_hint_info=$send_hint_info.' -- '.$forumcache[$zhiwu55_data['fid']]['name'];
		if ($zhiwu55_data['threadtypeid'] > 0) {
			$typeidInfo = C::t('forum_threadclass')->fetch_all_by_typeid_fid($zhiwu55_data['threadtypeid'], $zhiwu55_data['fid']);
			if(empty($typeidInfo)==false)
			{
				$send_hint_info=$send_hint_info . ' -- ' . $typeidInfo[$zhiwu55_data['threadtypeid']]['name'];
			}
		}
		
	} elseif(!empty($zhiwu55_data['forum_portal']) && $zhiwu55_data['forum_portal']=='portal') {
		
		$send_hint_info=lang('plugin/csdn123_news', 'portal');
		require_once libfile('function/portalcp');
		loadcache('portalcategory');
		$category = $_G['cache']['portalcategory'];
		$send_hint_info=$send_hint_info.' -- '.$category[$zhiwu55_data['portal_catid']]['catname'];
		
	} elseif(!empty($zhiwu55_data['forum_portal']) && $zhiwu55_data['forum_portal']=='group') {
		
		require_once libfile('function/group');
		$grouplistArr=grouplist('displayorder',false,100);
		$send_hint_info=lang('plugin/csdn123_news', 'group');
		$send_hint_info=$send_hint_info.' -- '.$grouplistArr[$zhiwu55_data['group_fid']]['name'];
		
	} else {
		
		$send_hint_info='<a href="?'.$server_url.'&zhiwu55_send_form=yes&formhash='.FORMHASH.'" style="color:red;font-weight:bold;">'.lang('plugin/csdn123_news', 'zhiwu55_com_13').'</a>';
		
	}
	$hzw_safecode = $zhiwu55_data['post_safecode'];
	$postDataUrl = $_G['siteurl'];
	$Chrome=$_SERVER['HTTP_USER_AGENT'];
	if(stripos($Chrome,'Chrome')===false)
	{
		$showChrome=true;
	} else {
		$showChrome=false;
	}
	include template('csdn123_news:chrome');

}