<?php
/**
 * 文档编辑
 *
 * @version        $Id: article_edit.php 1 14:12 2010年7月12日Z tianya $
 * @package        DedeCMS.Administrator
 * @copyright      Copyright (c) 2007 - 2010, DesDev, Inc.
 * @license        http://help.dedecms.com/usersguide/license.html
 * @link           http://www.dedecms.com
 */
ini_set('display_errors','on');
ini_set('display_startup_errors','on');
error_reporting(E_ERROR);
require_once __DIR__ . '/../webapi/vendor/autoload.php';
require_once(dirname(__FILE__)."/config.php");
require_once __DIR__ . '/../include/redis/Rediscluster.php';

use elecfans\MsgQueue;
use elecfans\Queue;
use elecfans\Rediscluster;
use hqjfmanage\utils\UtilHelper;
use hqjfmanage\repository\article\ArchivesResearchRepository;

CheckPurview('a_Edit,a_AccEdit,a_MyEdit');
require_once(DEDEINC."/customfields.func.php");
require_once(DEDEADMIN."/inc/inc_archives_functions.php");
require_once(DEDEADMIN."/inc/inc_archives_about_tag.php");
require_once(DEDEADMIN."/inc/inc_network.php");
require_once(DEDEINC . '/userlogin.class.php');
if(file_exists(DEDEDATA.'/template.rand.php'))
{
    require_once(DEDEDATA.'/template.rand.php');
}
ini_set('display_errors','on');
ini_set('display_startup_errors','on');
error_reporting(E_ERROR);
if(empty($dopost)) $dopost = '';
$aid = isset($aid) && is_numeric($aid) ? $aid : 0;

//缓存不限定过期时间
$redis = Rediscluster::instance();
if($dopost!='save')
{
    require_once(DEDEADMIN."/inc/inc_catalog_options.php");
    require_once(DEDEINC."/dedetag.class.php");
    ClearMyAddon();

    //获取登录信息相关token
    $cuserLogin = new userLogin();
    $zmAuthToken = $cuserLogin->getZmToken();

    //读取归档信息
    $query = "SELECT ch.typename AS channelname,ar.membername AS rankname,arc.*,addattr.fail_reason
    FROM `#@__archives` arc
    LEFT JOIN `#@__channeltype` ch ON ch.id=arc.channel
    LEFT JOIN `#@__archives_additional_attribute` addattr ON addattr.aid=arc.id
    LEFT JOIN `#@__arcrank` ar ON ar.rank=arc.arcrank WHERE arc.id='$aid' ";
    $arcRow = $dsql->GetOne($query,MYSQL_ASSOC, 'master');
    if(!is_array($arcRow))
    {
        ShowMsg("读取档案基本信息出错!","-1");
        exit();
    }

    //加一个专栏标识
    $arcRow['is_zl'] = (strpos($arcRow['flag'], 'z') === false) ? false : true;


    $query = "SELECT * FROM `#@__channeltype` WHERE id='".$arcRow['channel']."'";

    $cInfos = $dsql->GetOne($query);
    if(!is_array($cInfos))
    {
        ShowMsg("读取频道配置信息出错!","javascript:;");
        exit();
    }
    $addtable = $cInfos['addtable'];
     // var_dump($addtable,$aid);exit;
    $addRow = $dsql->GetOne("SELECT * FROM `$addtable` WHERE aid='$aid'", MYSQL_ASSOC, 'master');
    if(!$addRow['matchicpro']){
        $addRow['matchicpro'] = '是';
    }


    //for dzs start
    if($addRow['is_md'] != 1){
        $addRow['body'] = htmlspecialchars_decode($addRow['body']);
    }

    $addRow['body'] = str_replace("`","&#x60;",stripslashes($addRow['body']));
    $addRow['body']  =  str_replace("$","&#036;",$addRow['body']);
    $addRow['body']  =  str_replace("{","&#123;",$addRow['body']);
    $addRow['body']  =  str_replace("}","&#125;",$addRow['body']);
    $addRow['body']  =  str_replace("\\u","&#092;u",$addRow['body']);

    //for dzs end

    //如果是采集的 显示选好的公众号列表 start
    $wx_user_list = array();
    $wx_user_sql = "select name,uid,ch_name from `#@__wx_mp_list` where 1 and status=1 and uid != 0 ORDER BY id DESC";
    $dsql->SetQuery($wx_user_sql);
    $dsql->Execute('wx_user_sql');
    while ($row = $dsql->GetArray('wx_user_sql')) {
        $wx_user_list[] = $row;
    }
    //如果是采集的 显示选好的公众号列表 end

    if(!is_array($addRow))
    {
        ShowMsg("读取附加信息出错!","javascript:;");
        exit();
    }
    $channelid = $arcRow['channel'];
    $tags = GetTags($aid, 'master');
    $timedrelease = $dsql->GetOne("SELECT * from `#@__archives_timerelease` where aid='$aid' limit 1", MYSQL_ASSOC, 'master');

    // 置顶头图
    $topRow = [];
    $topInfo = $dsql->GetOne("SELECT aid,is_valid as isValid,big_picname as bigpicname,update_time as updatetime FROM `#@__archives_top` WHERE aid = {$aid} ORDER BY update_time DESC LIMIT 1");
    if (!empty($topInfo) ) {
        $topRow = $topInfo;
    }

    //获取源地址
    $imgArr = array();
    if (!empty($topInfo['bigpicname'])) {
        $imgArr[] = $topInfo['bigpicname'];
    }
    if (!empty($arcRow['litpic'])) {
        $imgArr[] = $arcRow['litpic'];
    }

    //获取违规信息
    $Violations_type = [100 => "色情",110 => "性感低俗",200 => "广告",210 => "二维码",260 => "广告法",300 => "暴恐",400 => "违禁",500 => "涉政",600 => "谩骂", 700 => "灌水",800 => "恶心类",1100 => "涉价值观"];
    $status_txt = ["待检测","合规","<p style='color: red'>不合规</p>","疑似","失败"];
    $img_status_txt = ["建议通过","不确定","确定","资源异常"];
    $wordViolations = $dsql->GetOne("SELECT * FROM `#@__word_sensitive` WHERE `aid` = $aid LIMIT 1");
    $wordViolations['text_word_content'] = json_decode($wordViolations['text_word_content'],1);
    $wordViolations['img_word_content'] = json_decode($wordViolations['img_word_content'],1);
    $ImageSource = getImageSource($imgArr);

    //add sjl 2024.02.21增加研究院
    $ysLogic = new \hqjfmanage\logic\yingsheng\YsLogic();
    $researchConf = $ysLogic->getCacheVideoTypeConf();
    $arcResearchRepo = new ArchivesResearchRepository();
    $where = ['aid' => $aid, 'deleted' => ArchivesResearchRepository::DELETED_1];
    $researchInfo = $arcResearchRepo->getOneByWhere($where,'aid,industry_type,extra_type');
    if (isset($researchInfo['industry_type'])) {
        $researchInfo['industry_type'] = empty($researchInfo['industry_type']) ? [] : explode(',', $researchInfo['industry_type']);
    }
    //end

    include DedeInclude("templets/article_edit.htm");
    exit();
}
/*--------------------------------
function __save(){  }
-------------------------------*/
else if($dopost=='save')
{
    DebugTime::setDebugTimeInfo("【保存文章】1开始" . $id);
    // var_dump($dopost,$litpic_source);exit;
    require_once(DEDEINC.'/image.func.php');
    require_once(DEDEINC.'/oxwindow.class.php');

    //需要推送异步的数据，将一些业务异步执行，优化速度慢  article_add.php 也会用到
    $pushAsync = array();

    $flag = isset($flags) ? join(',',$flags) : '';
    $weight = isset($weight) ? $weight : 0;
    $notpost = isset($notpost) && $notpost == 1 ? 1: 0;

    if(isset($weight_num)){
        $weight_num = intval($weight_num);
    }else{
        $weight_num = 0;
    }

    if(($weight_num < 0) ){
        ShowMsg("排序权重请输入0-99999的数值", "-1");
        exit();
    }

    //增加研究院必要字段验证 add sjl 2024.2.21
    if (!empty($research)) {
        //验证类型， 和产业分类
        if (empty($extra_type)) {
            ShowMsg("请选择类型！","-1");
            exit();
        }
        if (empty($industry_type)) {
            ShowMsg("请选择产业分类！","-1");
            exit();
        }
    } //end

    $typeid2 = implode(',',array_unique(array_filter(explode(',',$typeid2.','.$typeid2_2))));

    if(empty($typeid2)) $typeid2 = 0;
    if(!isset($autokey)) $autokey = 0;
    if(!isset($remote)) $remote = 0;
    if(!isset($dellink)) $dellink = 0;
    if(!isset($autolitpic)) $autolitpic = 0;
    if(empty($typeid))
    {
        ShowMsg("请指定文档的栏目！", "-1");
        exit();
    }
    if(empty($channelid))
    {
        ShowMsg("文档为非指定的类型，请检查你发布内容的表单是否合法！", "-1");
        exit();
    }

    if(!CheckChannel($typeid, $channelid))
    {
        ShowMsg("你所选择的栏目与当前模型不相符，请选择白色的选项！", "-1");
        exit();
    }

    if(!TestPurview('a_Edit'))
    {
        if(TestPurview('a_AccEdit'))
        {
            CheckCatalog($typeid, "对不起，你没有操作栏目 {$typeid} 的文档权限！");
        }
        else
        {
            CheckArcAdmin($id, $cuserLogin->getUserID());
        }
    }

    //填写图片必须填写来源地址
    if(!empty($bigpicname) && empty($bigpicname_source)){
        ShowMsg("焦点图源地址不能为空", "-1");
        exit();
    }

    if(!empty($picname) && empty($litpic_source)){
        ShowMsg("缩略图源地址不能为空", "-1");
        exit();
    }

    DebugTime::setDebugTimeInfo("【保存文章】2校验参数"  . $id);

    //对保存的内容进行处理
    $pubdate = GetMkTime($pubdate);
    $sortrank = AddDay($pubdate,$sortup);
    $ismake = $ishtml==0 ? -1 : 0;
    $autokey = 1;
    $title = htmlspecialchars(cn_substrR($title,$cfg_title_maxlen));
    $shorttitle = cn_substrR($shorttitle,80);
    $color =  cn_substrR($color,7);
    $writer =  cn_substrR($writer,20);
    $source = cn_substrR($source,30);
    //$description = cn_substrR($description,$cfg_auot_description);
    $description = trim(cn_substrR($description,1000));
    $keywords = trim(cn_substrR($keywords,60));
    $filename = trim(cn_substrR($filename,40));
    $isremote  = (empty($isremote)? 0  : $isremote);
    $serviterm=empty($serviterm)? "" : $serviterm;
    $store_flag = $store_flag ? intval($store_flag) : 0;
    $remote = isset($remote) ? $remote : 0;
    $fail_reason = empty($fail_reason) ? '' : htmlspecialchars($fail_reason);
    $sendDateTime = empty($senddate) ? time() : strtotime($senddate);
    $isValid = empty($isValid) ? 0 : 1;
    $vip_limit = empty($vip_limit) ? 0 : $vip_limit;

    DebugTime::setDebugTimeInfo("【保存文章】3参数接收"  . $id);

    //add sjl20230605 企业号文章不能在主站编辑
    if (15 == $store_flag) {
        ShowMsg("企业号文章/方案禁止编辑", "-1");
        exit();
    }

    //文章审核不通过时，不通过原因必填。
    if(($channelid == 1) && ($arcrank == -3) && empty($fail_reason)){
        ShowMsg("请填写审核不通过原因");
        exit();
    }

    // 需求： 公众号为：采集服务号待审核的文章， 点击确定直接审核  add sunjinliang 2019-07-15
    if ($wx_user_id > 0 && $arcrank == -1) {
        $wx_mp_list_info = $dsql->GetOne('SELECT id FROM #@__wx_mp_list WHERE type =  2 AND uid = ' . $wx_user_id);
        if (!empty($wx_mp_list_info)) {
            $arcrank = 0;
        }
    } //end

      // var_dump($);exit;

    if(!TestPurview('a_Check,a_AccCheck,a_MyCheck'))
    {
        $arcrank = -1;
    }
    // modify by 刘平 2015年8月20日 添加定时发布功能
    if (isset($_POST['timedrelease']) && $timedrelease == 1) {
        $arcrank = -1;
    }
    $adminid = $cuserLogin->getUserID();

    //处理上传的缩略图
    if(empty($ddisremote))
    {
        $ddisremote = 0;
    }

    DebugTime::setDebugTimeInfo("【保存文章】3-1参数接收"  . $id);

    $litpic = GetDDImage('none',$picname,$ddisremote);

    DebugTime::setDebugTimeInfo("【保存文章】4GetDDImage"  . $id);

    //分析body里的内容
    $body = AnalyseHtmlBody($body,$description,$litpic,$keywords,'htmltext');

    DebugTime::setDebugTimeInfo("【保存文章】5AnalyseHtmlBody"  . $id);

    // 去掉URL路径中包含的后台域名
    $body = str_replace('https://'.$_SERVER['HTTP_HOST'].'/', '/', $body);

    //分析处理附加表数据
    $dede_addonData = [];
    $set = explode(';',$dede_addonfields);
    foreach ($set as $k => $v){
        $key = explode(',',$v)[0];
        $dede_addonData[$key] = $$key;
    }
    DebugTime::setDebugTimeInfo("【保存文章】AnalyseHtmlBody GetFieldValueA"  . $id);
    $list = getInfoByBody($dede_addonfields,$dede_addonData);
    $check_video_url = $list['check_video_url'];
    $inadd_f_arr = $list['inadd_f'];
    $inadd_v_arr = $list['inadd_v'];
    foreach ($list['data'] as $k => $v){
        $$k = $v;
    }
    //2020-07-14 周思成 检查视频是否存在
    if(!empty($check_video_url)){
        $urlResult = get_headers($check_video_url,1);

        DebugTime::setDebugTimeInfo("【保存文章】6检查视频是否存在花费"  . $id);

        if(!preg_match('/200/',$urlResult[0])){
            ShowMsg("视频地址不可用,请检查后重新填写", "-1");
            exit();
        }
    }

    //处理图片文档的自定义属性
    //跳转网址的文档强制为动态
    //加mysql中间件后 keywords太长会报错
    $handleFlagInfo = handleFlagInfo($flag,$litpic,$redirecturl,$keywords,$ismake);
    $flag = $handleFlagInfo['flag'];
    $ismake = $handleFlagInfo['ismake'];
    $keywords = $handleFlagInfo['keywords'];


    $voteid  = $voteid ? intval($voteid) : 0;
    $field = 'id,arcrank,mid,litpic,flag,title,store_flag,unionid,channel,typeid,typeid2';
    $article_orgin = $dsql->GetOne("SELECT {$field} FROM `#@__archives` WHERE id='$id' ", MYSQL_ASSOC, 'master');

    //记录缩略图来源地址 周思成 202-05-25
    // var_dump($article_orgin['litpic'], $litpic);exit;
    saveImageSource($article_orgin['litpic'], $litpic, $litpic_source);

    DebugTime::setDebugTimeInfo("【保存文章】6记录缩略图来源地址saveImageSource ".'$article_orgin["litpic"]'  . $id);

    //审核时检查 对采集文章，入库后文章标题不修改的标题 或与原标题相同的则不允许通过 add sunjinliang 2019-10-17
    //d/article/apipicker这个接口采集的文章判断
    $pickInfo = $dsql->GetOne('SELECT title FROM `#@__picker` where  aid = ' . $id . ' LIMIT 1');
    $checkRes = checkCollectArticleWithTitle($id, $pickInfo,$article_orgin, ['title' => $title,'arcrank' => $arcrank]);
    if (!$checkRes) {
        ShowMsg("未修改标题, 请修改标题再发布", "-1");
        exit();
    }//end
    DebugTime::setDebugTimeInfo("【保存文章】7 checkCollectArticleWithTitle"  . $id);

    //添加推荐时间
    $archivesLogic = new \hqjfmanage\logic\article\ArchivesLogic();
    $recommend_date = $archivesLogic->getRecommendTime($id,$isValid, $flag);

    //发送推荐信息
    if(strstr($flag,'c') !== false){
        $res = Setcredits($article_orgin['mid'],$article_orgin['id'],$article_orgin['title'],"TJL","first_recommendation");
        $msg = "";
        if($res){
            $msg = "获得积分+2";
        }
        $url = GetArcUrl($id);
        $subject = "您发布的文章《{$article_orgin['title']}》已管理员设为推荐！{$msg}";
        $message = "<a href='{$url}' target='_blank'>查看</a>";
        abc_sendSystemNoticeNew($article_orgin['mid'], $subject, $message);
    }
    if ($typeid != 1075 && strpos($flag,'z')!==false){
        //不是电子说，却勾选了 z 专栏  需要去掉z
        $flag = explode(',',$flag);
        $flag = implode(',',array_diff($flag, ['z']));
    }
    //更新数据库的SQL语句
    $query = "UPDATE #@__archives SET
    typeid='$typeid',
    typeid2='$typeid2',
    sortrank='$sortrank',
    flag='$flag',
    recommend_date='$recommend_date',
    ismake='$ismake',
    arcrank='$arcrank',
    money='$money',
    title='$title',
    color='$color',
    writer='$writer',
    source='$source',
    litpic='$litpic',
    pubdate='$pubdate',
    senddate=$sendDateTime,
    voteid='$voteid',
    notpost='$notpost',
    description='$description',
    keywords='$keywords',
    shorttitle='$shorttitle',
    filename='$filename',
    weight='$weight',
    store_flag='$store_flag',
    reading_restrict='$reading_restrict',
    reading_restrict_mobile='$reading_restrict_mobile',
    reading_restrict_date='$reading_restrict_date',
    vip_limit='$vip_limit'
    WHERE id='$id'; ";
    //如果加了wx_user_id  重写文章的mid
	if(is_numeric($wx_user_id)&&($wx_user_id>0) && $typeid == 1075){
        //专栏标志
        $flag = ($flag=='' ? 'z' : $flag.',z');

        $query = "UPDATE #@__archives SET
        typeid='$typeid',
        typeid2='$typeid2',
        sortrank='$sortrank',
        flag='$flag',
        ismake='$ismake',
        arcrank='$arcrank',
        money='$money',
        title='$title',
        color='$color',
        writer='$writer',
        source='$source',
        litpic='$litpic',
        pubdate='$pubdate',
        senddate=$sendDateTime,
        recommend_date  ='$recommend_date',
        voteid='$voteid',
        notpost='$notpost',
        description='$description',
        keywords='$keywords',
        shorttitle='$shorttitle',
        filename='$filename',
        weight='$weight',
        mid='$wx_user_id',
        dutyadmin='$adminid',
        store_flag='$store_flag',
        reading_restrict='$reading_restrict',
        reading_restrict_mobile='$reading_restrict_mobile',
        reading_restrict_date='$reading_restrict_date',
        vip_limit='$vip_limit'
        WHERE id='$id'; ";
    }else{
        //如果是第一次修改 重写文章dutyadmin
        $log_arr = $dsql->GetOne("SELECT aid from `#@__arc_edit_log` where aid='{$id}'",MYSQL_ASSOC, 'master');
        if(!$log_arr){
            $query = "UPDATE #@__archives SET
            typeid='$typeid',
            typeid2='$typeid2',
            sortrank='$sortrank',
            flag='$flag',
            ismake='$ismake',
            arcrank='$arcrank',
            money='$money',
            title='$title',
            color='$color',
            writer='$writer',
            source='$source',
            litpic='$litpic',
            pubdate='$pubdate',
            senddate=$sendDateTime,
            recommend_date  ='$recommend_date',
            voteid='$voteid',
            notpost='$notpost',
            description='$description',
            keywords='$keywords',
            shorttitle='$shorttitle',
            filename='$filename',
            weight='$weight',
            dutyadmin='$adminid',
            store_flag='$store_flag',
            reading_restrict='$reading_restrict',
            reading_restrict_mobile='$reading_restrict_mobile',
            reading_restrict_date='$reading_restrict_date',
            vip_limit='$vip_limit'
            WHERE id='$id'; ";
        }
    }

    if(!$dsql->ExecuteNoneQuery($query))
    {
        //ShowMsg('更新数据库archives表时出错，请检查',"javascript:;");
        $gerr = $dsql->GetError();
        ShowMsg("把数据保存到数据库时出错，请检查！".$gerr,"javascript:;");
        exit();
    }

    DebugTime::setDebugTimeInfo("【保存文章】8 一些业务sql "  . $id);
    //add sunjinliang 2024.2.21 增加研究院
    $arcResearchLogic = new \hqjfmanage\logic\article\ResearchLogic();
    $researchData = [
        'research' => empty($research) ? 0 : 1,
        'extra_type' => empty($extra_type) ? 0 : $extra_type,
        'industry_type' => empty($industry_type) ? 0 : $industry_type,
    ];
    $arcResearchLogic->edit($researchData, $arcID);
    //end


    //审核未通过
    if ($arcrank == -3) {
        //添加审核不同原因
        $sql = "INSERT INTO `#@__archives_additional_attribute` (aid,fail_reason) VALUES ($id, '$fail_reason') ON DUPLICATE KEY UPDATE fail_reason =VALUES (fail_reason)";
        $dsql->ExecuteNoneQuery($sql);
        sendSystemNotice($id, 2,$fail_reason);

        DebugTime::setDebugTimeInfo("【保存文章】9 发送短信1 "  . $id);
    }
    //审核通过
    if ($arcrank == 0 && ($article_orgin['arcrank'] == -1)) {
        sendSystemNotice($id, 1);

        $res = Setcredits($article_orgin['mid'],$article_orgin['id'],$article_orgin['title'],"ACT","article");


        DebugTime::setDebugTimeInfo("【保存文章】10 发送短信2 "  . $id);

    }
    //采集属性文章审核通过后 移除入库原标题缓存 add sunjinliang 2019-10-24
    if (empty($pickInfo) && strpos($article_orgin['flag'], 'g') !== false) {
        removeCollectArtOriginTitleCache($id, $article_orgin['arcrank'], $arcrank);
    }// end

    //// modify by 刘平 2015年8月20日 添加文章定时发布功能
    $param = isset($_POST['timedrelease']) && $timedrelease == 1;
    handleTimedrelease($param,$id,$pubdate,$dsql);

    //维护文档主副栏目关系 modify sjl 2023.10.18
    $arcTypeid2Logic = new \hqjfmanage\logic\article\ArchivesTypeid2Logic();
    $arcTypeid2Logic->updateArcTypeid2($id, $typeid, $typeid2,$arcrank);
    //文档属性关系
    $arcFlagLogic = new \hqjfmanage\logic\article\ArcFlagLogic();
    $arcFlagLogic->updateArcFlag($id, $flag);


    $cts = $dsql->GetOne("SELECT addtable FROM `#@__channeltype` WHERE id='$channelid' ");
    $addtable = trim($cts['addtable']);

    if($addtable!='')
    {
        //代码块处理 前端自己处理了
        $body = UtilHelper::doPreCodeOfBody($body);

        $useip = GetIP();
        $templet = empty($templet) ? '' : $templet;
        //推荐权重
        $weight_num = (strstr($flag,'c') !== false) ? $weight_num : 0;
        $inadd_f = '';
        if (!empty($inadd_f_arr)){
            $inadd_f=',';
            foreach ($inadd_f_arr as $k => $v){
                $arr[] = $v . '=\'' .$inadd_v_arr[$k] . '\'';
            }
            $inadd_f.= implode(',',$arr);
        }

        $bodyMd5 = \hqjfmanage\utils\UtilHelper::md5HtmlText($body);
        $iquery = "UPDATE `$addtable` SET typeid='$typeid',body_md5='$bodyMd5',body='$body'{$inadd_f},redirecturl='$redirecturl',templet='$templet',userip='$useip',weight_num=$weight_num WHERE aid='$id'";

        if(!$dsql->ExecuteNoneQuery($iquery))
        {
            $gerr = $dsql->GetError();
            ShowMsg("更新附加表 `$addtable`  时出错，请把相关信息提交给DedeCms官方。".str_replace('"','',$gerr),"javascript:;");
            exit();
        }
    }

    DebugTime::setDebugTimeInfo("【保存文章】11 执行一些sqlredis "  . $id);

    //// 更新标签关联关系
    //UpIndexKey($id, $arcrank, $typeid, $sortrank, $tags);
    //新的函数在 (DEDEADMIN."/inc/inc_archives_about_tag.php");
    UpIndexKey_2017($id, $arcrank, $typeid, $sortrank, $tags);

    DebugTime::setDebugTimeInfo("【保存文章】12 更新标签关联关系 "  . $id);

    //// 维护搜索引擎
    //handleXunsou($id,$arcrank,$dsql);

    //防止主从延迟
    //sleep(2);

    $pushAsync['keyMakeArt'] = array(
        'arcID' => $id,
        'isremote' => $isremote,
    );

    //如果是原创向百度提交 start

    $is_original = 0;
    if(strpos($flag,'y')!==false){
        $is_original = 1;
    }
    if(DEDE_ENV == 'prod' && ($arcrank>-1)){
        if ($ismake == 1) {
            //向百度提交实时资讯
            $push_id_arr = array($id);
            $pushAsync['key_push_content_to_baidu_shishi'] = array(
                'push_id_arr' => $push_id_arr,
            );
        }

        //需要推送百度ping 或者 熊掌号  已改为异步
        $pushAsync['key_push_content_to_baidu_ping_or_xiongzhang'] = array(
            'id' => $id,
            'is_y' => $is_original
        );
        $to_baidu_msg = '推送百度，已改为异步执行';//$pushRes['msg'];
    }
    //如果是原创向百度提交 end


    //维护es索引文档 start
    handleEs($id,$dsql);
    //维护es索引文档 end

    //添加文章添加记录
    $ip = GetIP();
    $now_time = time();
    $visitor = $_COOKIE['visitor'];
    $dsql->ExecuteNoneQuery("insert into #@__arc_edit_log (aid,mid,visitor,ip,addtime) values ($id,$adminid,'$visitor','$ip',$now_time) ");

    if($artUrl=='')
    {
        $artUrl = $cfg_phpurl."/view.php?aid=$id";
    }
    ClearMyAddon($id, $title);
    DebugTime::setDebugTimeInfo("【保存文章】19 ClearMyAddon "  . $id);


    if ($arcrank>=0  && $article_orgin['arcrank']<0) {
        /**
         * 推送到BBS个人主页动态
         */
        $pushAsync['keyPushQueueEdit'] = array(
            'typeid' => $typeid,
            'typeid2' => $typeid2,
            'channelid' => $channelid,
            'article_orgin' => $article_orgin,
            'arcID' => $id,
            'title' => $title,
            'litpic' => $litpic,
            'username' => $username,
        );
    }

    //原来是开放浏览的文章，如果设置成不开放浏览，推送到队列把相关文章动态(论坛Feed)删除
    if ($arcrank<0  && $article_orgin['arcrank']>=0) {
        $pushAsync['keyPushQueueEditDelFeed'] = array(
            'typeid' => $typeid,
//            'typeid2' => $typeid2,
//            'channelid' => $channelid,
            'article_orgin' => $article_orgin,
            'arcID' => $id,
            'title' => $title,
            'litpic' => $litpic,
            'username' => $username,
        );
        DebugTime::setDebugTimeInfo("【保存文章】20 原来是开放浏览的文章，如果设置成不开放浏览，推送到队列把相关文章动态(论坛Feed)删除 "  . $id);
    }

    $unaudited_count = get_unaudited_count($adminid);

    DebugTime::setDebugTimeInfo("【保存文章】21 get_unaudited_count "  . $id);

    $msg_notice = $unaudited_count > 0 ? '<a href="content_list.php?arcrank=-1&mid='.$adminid.'" onclick="window.parent.location.reload()" style="color:#f00" target="main">您有'.$unaudited_count.'篇待审</a>' : '';
    //返回成功信息
    $msg = "
    　　请选择你的后续操作：
    <a href='article_add.php?cid=$typeid'><u>发布新文章</u></a>
    &nbsp;&nbsp;
    <a href='archives_do.php?aid=".$id."&dopost=editArchives'><u>查看更改</u></a>
    &nbsp;&nbsp;
    <a href='$artUrl' target='_blank'><u>查看文章(已改为异步，当前按钮可能不准确)</u></a> 
    &nbsp;&nbsp;
    <a href='catalog_do.php?cid=$typeid&dopost=listArchives'><u>管理文章</u></a>
    &nbsp;&nbsp;
    ".$msg_notice."
    $backurl
    ";
    if($is_original){
      $msg.="&nbsp;&nbsp;".$to_baidu_msg;
    }

    //电子说需要清理下文章缓存
    if($typeid == 1075) {
        $shopToken = md5($shop_token);
        $cacheKey = md5("Home\Model\ArchivesModel_Home\Model\ArchivesModel::getDetail_{$id}lls");
        $sendData = ['token' => $shopToken, 'key' => $cacheKey];
        $pushAsync['key_d_del_cache'] = array(
            'sendData' => $sendData,
            'url' => $cfg_basehost.'/d/Cachemanagement/delCache',
        );
    }

    //更新业界头条置顶数据 modify sjl 20230420
    require_once dirname(__DIR__) . '/hqjf@manage/inc/inc_article_func.php';
    $bigicname = empty($bigpicname) ? '' : $bigpicname;
    $bigpicname_source = empty($bigpicname_source) ? '' : $bigpicname_source;
    $newArcrank = !empty($timedrelease) ? 0 : $arcrank;
    editAritcleTop($id, $isValid, $bigicname, $bigpicname_source, $newArcrank);
    //end
    DebugTime::dumpDebugTime('更改文章'  . $id);
    if (!empty($pushAsync)){
        sleep(2);
        //推送异步消息 elecfans_script项目会消费，并且异步调用 article_add_edit_async.php
        $pushQueue = new \hqjfmanage\logic\queue\Queue();
        //编辑文章事件
        $push = [];
        $push['id'] = $id;
        $push['event'] = 'elecfans.article.edit';
        $push['eventTime'] = time();
        $push['pushTime'] = time();
        //这里需要是jsonobject  不能是 jsonarray
        $push['data'] = $pushAsync;
        //print_r($push);exit;
        $pushQueue->push_topic_queue($push,'elecfansScript',$push['event']);
    }
    $wintitle = "成功更改文章！";
    $wecome_info = "文章管理::更改文章";
    $win = new OxWindow();
    $win->AddTitle("成功更改文章：");
    $win->AddMsgItem($msg);
    $winform = $win->GetWindow("hand","&nbsp;",false);
    $win->Display("");
}

function Setcredits($uid,$archives_id,$title,$operation,$action){
    global $cfg_bbs_domain;
    $url = $cfg_bbs_domain . '/home.php?mod=misc&ac=credit&op=elecfans_credits&action=action';
    $params = ['uid'=>$uid,'archives_id'=> $archives_id,'title'=>$title,'operation'=> $operation,'action'=> $action,"op"=>'elecfans_credits'];
    $data  = Network::doRequest($url,$params,'POST',[],'https',3000);
    $res = json_decode($data['data'],1);
    if($res['data'] != 'lq'){
        return true;
    }
    return false;
}
