<?php
/**
*
* 织梦定时自动审核和生成
require_once(dirname(__FILE__)."/../include/common.inc.php");
require_once(DEDEINC.'/archives.func.php');
$rows = $dsql->GetOne("SELECT * FROM `#@__autorun`");
//每天开始时间
$utime = $rows['utime'];
//已审篇数
$tonum = $rows['tonum'];
if(empty($utime)) exit("后台定时审核生成未配置");
$row = unserialize($rows['msg']);
if($row['start'] == "0") exit("自动审核被关闭");
//已经审核记录
$info = unserialize($rows['info']);
//时间间隔
$otime = $row['otime'];
//可审时段
$ktime = $row['ktime'];
//百度推送API
$baidupush = $row['baidupush'];
//熊掌推送API
$xiongpush = $row['xiongpush'];
//最大篇数
$wnum = $row['wnum'];
//要审核的栏目
$type = $row['type'];
//更新HTML选项
$makeindex = $row['makeindex'];
$makeart = $row['makeart'];
$maketype = $row['maketype'];
$makepagesize = $row['htmlnum'] ? $row['htmlnum'] : 0;
//是否记录
$log = $row['log'];
//当前时间
$newtime = time();
$newhour = date('G');
//时段是否允许审核
if (!array_key_exists($newhour,$ktime))
{
exit("审核时段不在范围内");
}
//时间间隔是否允许
if(($utime - $newtime) > 0)
{
exit("今日允许审核".$wnum."篇,已审".$tonum."篇,还需".($utime-$newtime)."秒才能继续审核!");
}
else
{
//第二天重置
$newday = strtotime(date("Y-m-d",time()));
$sqlday = strtotime(date("Y-m-d",$utime));
if($newday != $sqlday)
{
if(file_exists(dirname(__FILE__).'/../data/pushlog.txt'))
{
@unlink(dirname(__FILE__).'/../data/pushlog.txt');
}
$query = "UPDATE `#@__autorun` SET utime='$newtime',tonum='0',info=''";
$dsql->ExecuteNoneQuery($query);
exit("时间已重新配置,".($utime-$newtime)."秒开始!");
}
//更新时间间隔
$utime = $newtime + $otime;
$query = "UPDATE `#@__autorun` SET utime='$utime'";
$dsql->ExecuteNoneQuery($query);
}
//篇数是否允许
if($tonum >= $wnum)
{
exit("今日允许审核".$wnum."篇,已审".$tonum."篇");
}
//开始工作
$types = join(",",$type);
$arcrow = $dsql->GetOne("SELECT arc.id,arc.typeid,ch.issystem,ch.maintable,ch.addtable FROM `#@__arctiny` arc LEFT JOIN `#@__arctype` tp ON tp.id=arc.typeid LEFT JOIN `#@__channeltype` ch ON ch.id=tp.channeltype WHERE arc.arcrank='-1' AND arc.typeid IN($types) ORDER BY arc.id");
if(!is_array($arcrow)) exit("没有可审核的文章了");
$aid = $arcrow['id'];
$typeid = $arcrow['typeid'];
$issystem = $arcrow['issystem'];
$addtable = trim($arcrow['addtable']);
$maintable = ( trim($arcrow['maintable'])=='' ? '#@__archives' : trim($arcrow['maintable']) );
// 修改发布时间-1
$newdate = time();
// 修改发布时间-2
$atres = $dsql->ExecuteNoneQuery("UPDATE `#@__arctiny` SET sortrank='$newdate',senddate='$newdate',arcrank='0' WHERE id='$aid' ");
// $atres = $dsql->ExecuteNoneQuery("UPDATE `#@__arctiny` SET arcrank='0' WHERE id='$aid' ");
if($issystem==-1)
{
// 修改发布时间-3
$tbres = $dsql->ExecuteNoneQuery("UPDATE `".$addtable."` SET pubdate='$newdate',sortrank='$newdate',senddate='$newdate',arcrank='0' WHERE aid='$aid' ");
// $tbres = $dsql->ExecuteNoneQuery("UPDATE `".$addtable."` SET arcrank='0' WHERE aid='$aid' ");
}
else
{
// 修改发布时间-4
$tbres = $dsql->ExecuteNoneQuery("UPDATE `$maintable` SET pubdate='$newdate',sortrank='$newdate',senddate='$newdate',arcrank='0' WHERE id='$aid' ");
// $tbres = $dsql->ExecuteNoneQuery("UPDATE `$maintable` SET arcrank='0' WHERE id='$aid' ");
}
$dsql->ExecuteNoneQuery("UPDATE `#@__taglist` SET arcrank='0' WHERE aid='$aid' ");
if($atres && $tbres)
{
$tonum = $tonum + 1;
$utime = $newtime + $row['otime'];
$query = "UPDATE `#@__autorun` SET utime='$utime',tonum='$tonum'";
$dsql->ExecuteNoneQuery($query);
}
else
{
exit("审核中遇到未知错误");
}
//更新文档HTML
if($makeart)
{
$artUrl = MakeArt($aid, $typeid, TRUE);
}
else
{
$url = GetOneArchive($aid);
$artUrl = $url['arcurl'];
}
// 主动推送
if(isset($artUrl) && (!empty($baidupush) || !empty($xiongpush)))
{
$artUrl = (strpos($artUrl, $cfg_basehost) === false) ? $cfg_basehost . $artUrl : $artUrl;
if(!empty($baidupush) && function_exists('curl_init'))
{
$bdpsres = "";
$ch = curl_init();
$options = array(
CURLOPT_URL => trim($baidupush),
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => implode("\n", array($artUrl)),
CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
curl_close($ch);
$result = json_decode($result, true);
if(isset($result['success'])){
$not_same_site = isset($result['not_same_site'][0]) ? " 推送链接与百度绑定站点不一致 " : "";
$not_valid = isset($result['not_valid'][0]) ? " 推送链接不合法 " : "";
$bdpsres = $artUrl . $not_same_site . $not_valid . ' 百度主动推送成功 '.$result['success'].' 条!当天剩余 '.$result['remain'].' 条可推送!';
}else{
$bdpsres = $artUrl . ' 百度主动推送失败,错误码:'.$result['error'];
}
savelog($bdpsres."\r\n");
}
if(!empty($xiongpush) && function_exists('curl_init'))
{
$xzpsres = "";
$ch = curl_init();
$options = array(
CURLOPT_URL => trim($xiongpush),
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => implode("\n", array($artUrl)),
CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
curl_close($ch);
$result = json_decode($result, true);
if(isset($result['error'])){
$xzpsres = $artUrl . ' 熊掌主动推送失败,错误码:'.$result['error'].' message:'.$result['message'];
}else{
$not_same_site = isset($result['not_same_site'][0]) ? " 推送链接与熊掌绑定站点不一致 " : "";
$not_valid = isset($result['not_valid'][0]) ? " 推送链接不合法 " : "";
$xzpsres = $artUrl . $not_same_site . $not_valid . ' 熊掌主动推送成功 '.$result['success_batch'].$result['success_realtime'].' 条!当天剩余 '.$result['remain_batch'].$result['remain_realtime'].' 条可推送!'.$artlist;
}
savelog($xzpsres."\r\n");
}
}
//记录
if($log)
{
$info[] = $artUrl;
$infod = serialize($info);
$query = "UPDATE `#@__autorun` SET info='$infod'";
$dsql->ExecuteNoneQuery($query);
}
//更新栏目HTML
if($maketype) MakeType($typeid, $makepagesize);
//更新首页HTML
if($makeindex) MakeIndex();
function MakeIndex()
{
global $dsql, $cfg_df_style, $cfg_basedir, $cfg_templets_dir;
require_once(DEDEINC."/arc.partview.class.php");
$envs = $_sys_globals = array();
$envs['aid'] = 0;
$indexs = $dsql->GetOne("SELECT * FROM `#@__homepageset`");
$templet = str_replace("{style}", $cfg_df_style, $indexs['templet']);
$homeFile = str_replace("../", "",$indexs['position']);
$homeFile = $cfg_basedir.'/'.$homeFile;
$fp = fopen($homeFile, 'w') or die("无法更新网站主页到:$homeFile 位置");
fclose($fp);
$tpl = $cfg_basedir.$cfg_templets_dir.'/'.$templet;
if(!file_exists($tpl)) exit("无法找到主页模板:$tpl ");
$GLOBALS['_arclistEnv'] = 'index';
$pv = new PartView();
$pv->SetTemplet($tpl);
$pv->SaveToHtml($homeFile);
$pv->Close();
}
function MakeArt($aid, $typeid='', $ismakesign=FALSE)
{
global $dsql;
include_once(DEDEINC.'/arc.archives.class.php');
if($ismakesign)
{
$envs['makesign'] = 'yes';
}
$arc = new Archives($aid);
$artUrl = $arc->MakeHtml();
if(isset($typeid))
{
$preRow = $dsql->GetOne("SELECT id FROM `#@__arctiny` WHERE id<$aid AND arcrank>-1 AND typeid='$typeid' ORDER BY id DESC");
$nextRow = $dsql->GetOne("SELECT id FROM `#@__arctiny` WHERE id>$aid AND arcrank>-1 AND typeid='$typeid' ORDER BY id ASC");
if(is_array($preRow))
{
$arc = new Archives($preRow['id']);
$arc->MakeHtml();
}
if(is_array($nextRow))
{
$arc = new Archives($nextRow['id']);
$arc->MakeHtml();
}
}
return $artUrl;
}
function MakeType($typeid, $makepagesize=0)
{
global $dsql;
$typediarr = array();
array_push($typediarr, $typeid);
$row = $dsql->GetOne("SELECT reid,topid FROM `#@__arctype` WHERE id = $typeid");
if(!in_array($row['reid'], $typediarr) && $row['reid'] != 0) array_push($typediarr, $row['reid']);
if(!in_array($row['topid'], $typediarr) && $row['topid'] != 0) array_push($typediarr, $row['topid']);
require_once(DEDEDATA."/cache/inc_catalog_base.inc");
require_once(DEDEINC."/channelunit.func.php");
require_once(DEDEINC."/arc.listview.class.php");
foreach($typediarr as $typeid)
{
$lv = new ListView($typeid);
$lv->MakeHtml(1,$makepagesize);
}
$lv->Close();
}
function savelog($content)
{
$filename = dirname(__FILE__).'/../data/pushlog.txt';
file_put_contents($filename, iconv('UTF-8','GBK',$content), FILE_APPEND);
}