<?php
/*
|--------------------------------------------------------------------------
| log.php 后台操作日志
|--------------------------------------------------------------------------
*/
namespace DeverApp\Manage\Filter;

use Dever;

require_once(dirname(__FILE__).'/bao10jie/BCPurifyClient.php');
require_once(dirname(__FILE__).'/bao10jie/BCPurifyItem.php');
require_once(dirname(__FILE__).'/bao10jie/BCPurifyResult.php');

class Bao10jie
{
	static public function cron($config, $content, $project, $table, $id, $ids)
	{
		$data = parse_str($content);
		$param[0]['isBatch'] = 1;
		$param[0]['appType'] = $project;
		$param[0]['textId'] = $ids;
		$param[0]['threadId'] = '';
		$param[0]['class'] = '';
		$param[0]['ip'] = Dever::ip();
		$param[0]['userId'] = '';
		$param[0]['author'] = '';
		$param[0]['title']= isset($data['dever_name']) ? $data['dever_name'] : '';
		$param[0]['text'] = $content;
		$param[0]['url'] = '';
		$param[0]['pubDate'] = date('Y-m-d H:i:s');
		$param[0]['authorEx'] = '';
		$param[0]['contentEx'] = '';
		$param[0]['structureEx'] = '';
		$param[0]['rules'] = '';

		$state = self::run($param, 'Purify');

		if($state == 1)
		{
			self::delete($project, $table, $id);
		}
	}

	static public function delete($project, $table, $id)
	{
		Dever::load($project . '/' . $table . '-update', array('where_id' => $id, 'set_state' => 2));
	}

	static private function run($param, $task)
	{
		// TODO Auto-generated method stub
		$item = new BCPurifyItem();
		$item->m_hlParmas = $param;	
		$client = new BCPurifyClient();
		//	Purify/Feedback/getNotify/getIndexResult
		$result = $client->{$task}($item);		
		if (!$result) {
			//客户端内部错误,返回字段校验错误(例:appType cannot be empty)或网络请求错误(例:http code:404)
			$error .= $client->getError();
			//ErrorLog::addLog($error, 'systemError');
			return -1;
			
		}elseif ($result->isBusinessSuccess()){
			//成功时取结果集,返回数组对象
			if ($result->getMarkResult() != null) {
				$status = $result->getMarkResult();
				return (int)$status->flag;
			}else {
				$error .= var_export($param, true);
				//ErrorLog::addLog($error, 'unknowError');
				return -2;
			}
		}else {
			//失败时取结果集
			$status = (array)$result->getMarkResult();
			$error .= var_export($status, true);
			//ErrorLog::addLog($error, 'verifyError');
			return -3;
		}
	}
}