chaihongjun.me

dedecms后台控制内容是否需要主动提交到百度

QQ截图20160608091439.jpg  

QQ截图20160608100026.jpg

########### 2017.11.16 更新,直接按照步骤操作即可 ####

特别说明,此方法适合自定义文档模型和默认文章模型的数据推送。附件分两种,一种是针对只有PC端的网站,另外一种是针对PC和M端共用一个数据的,两个网站。

操作步骤:

1.进入数据找到#@_archives,在这个表的最后添加一个字段push,代表推送,数据类型为tinyint,默认值为1,表示默认就是推送的,另外,设置当这个字段为0的时候,表示不推送。这样安排的目的是,以便后面根据这个字段的值来操作是否推送。这里截取后台文件article_add.php部分关于推送的代码,预览一下:

/*  这段代码适合双端网站,根据实际情况可以改成仅仅针对PC或者M端网站 */
if($push==1) {
    //PC端URL推送
$urls[]=$cfg_baiduhost.'/'.$artUrl;
$api = 'http://data.zz.baidu.com/urls?site='.$cfg_baiduhost.'&token='.$cfg_baidutoken;
$ch = curl_init();
$options =  array(
    CURLOPT_URL => $api,
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS => implode("\n", $urls),
    CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
//手机版URL推送
$urls_m[]=$cfg_baiduhost_m.'/'.$artUrl;
$api = 'http://data.zz.baidu.com/urls?site='.$cfg_baiduhost_m.'&token='.$cfg_baidutoken;
$ch = curl_init();
$options =  array(
    CURLOPT_URL => $api,
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS => implode("\n", $urls_m),
    CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
);
curl_setopt_array($ch, $options);
$result_m = curl_exec($ch);

    ClearMyAddon($arcID, $title);
    //返回成功信息
    $msg = "      请选择你的后续操作:
    <a href='article_add.php?cid=$typeid'><u>继续发布文章</u></a>
    &nbsp;&nbsp;
    <a href='$artUrl' target='_blank'><u>查看文章</u></a>
    &nbsp;&nbsp;
    <a href='archives_do.php?aid=".$arcID."&dopost=editArchives'><u>更改文章</u></a>
    &nbsp;&nbsp;
    <a href='catalog_do.php?cid=$typeid&dopost=listArchives'><u>已发布文章管理</u></a>
    <a href=''><u>百度提交返回,PC版:".$result."手机版:".$result_m."</u></a>
    &nbsp;&nbsp;
    $backurl
  ";
  $msg = "<div style=\"line-height:36px;height:36px\">{$msg}</div>".GetUpdateTest();
    $wintitle = "成功发布文章!";
    $wecome_info = "文章管理::发布文章";
    $win = new OxWindow();
    $win->AddTitle("成功发布文章:");
    $win->AddMsgItem($msg);
    $winform = $win->GetWindow("hand","&nbsp;",false);
    $win->Display();
}
else {
 ClearMyAddon($arcID, $title);
  //返回成功信息
    $msg = "      请选择你的后续操作:
    <a href='article_add.php?cid=$typeid'><u>继续发布文章</u></a>
    &nbsp;&nbsp;
    <a href='$artUrl' target='_blank'><u>查看文章</u></a>
    &nbsp;&nbsp;
    <a href='archives_do.php?aid=".$arcID."&dopost=editArchives'><u>更改文章</u></a>
    &nbsp;&nbsp;
    <a href='catalog_do.php?cid=$typeid&dopost=listArchives'><u>已发布文章管理</u></a>
    &nbsp;&nbsp;
    $backurl
  ";
  $msg = "<div style=\"line-height:36px;height:36px\">{$msg}</div>".GetUpdateTest();
    $wintitle = "成功发布文章!";
    $wecome_info = "文章管理::发布文章";
    $win = new OxWindow();
    $win->AddTitle("成功发布文章:");
    $win->AddMsgItem($msg);
    $winform = $win->GetWindow("hand","&nbsp;",false);
    $win->Display();
}

2.在系统后台添加3个变量,分别是cfg_baidutoken,cfg_baiduhost,cfg_baiduhost_m,分别代表百度站长平台的token,以及需要推送的网站域名(PC和M端),域名需要带协议(http或则https),如果只是推送一个端网站则只需要设置一个域名即可。

QQ截图20171116151549.jpg

3.将附件内的文件上传替换(注意备份)

PC和移动站.zip

单独网站.zip

###########  以下是之前的做法,写的好像有些逻辑不清晰,上面的最新的,直接操作即可。##############

这篇文章介绍的内容与之前的文章《Ueditor编辑器超链接增加rel属性及外链跳转头部自动添加方法》有直接关系,需要在前文基础之上做好准备才可进行。由于前文介绍的方法,只要在后台发布内容了,都会主动提交,这样的功能显然不够灵活,如果需要在后台发布的内容是测试的呢?如果后台发布的内容是不希望百度抓取收录的呢?本站就发现有一条内容,不需要被百度抓取索引,结果不随愿......

  基于需要这样一种情况,显然在发布的时候有个“开关”去选择是否主动推送,这样就可以设置内容的推送行为,显然需要在数据库内设置一个字段去记录是推送还是不推送。

  操作思路如下:

  1. 数据库内选择推送字段设置为1,不推送则为0

  2. HTML标签选择使用radio类型的input控件

  3. 当选择推送的时候,input的value值为1,并且输出"checked=1",数据库记录字段push值为1;

    当选择不推送的时候,input的value值为0,并且不输出"checked=1",数据库记录字段push值为0。

    涉及修改文件:

系统后台 article_add.php  article_edit.php

系统后台模板 article_add.htm article_edit.htm

以及数据库表 #@_archives


修改步骤


  1. 修改数据库

在数据表chj_archives添加一个字段push,类型tinyint,默认值为1(默认是选择推送)


2.分别修改article_add.php  和 article_edit.php

article_add.php 代码片段:

1.

 //保存到主表
    $query = "INSERT INTO `chj_archives`(id,typeid,typeid2,sortrank,flag,ismake,channel,arcrank,click,money,title,shorttitle,
    color,writer,source,litpic,pubdate,senddate,mid,voteid,notpost,description,keywords,filename,dutyadmin,weight,push)
    VALUES ('$arcID','$typeid','$typeid2','$sortrank','$flag','$ismake','$channelid','$arcrank','$click','$money',
    '$title','$shorttitle','$color','$writer','$source','$litpic','$pubdate','$senddate',
    '$adminid','$voteid','$notpost','$description','$keywords','$filename','$adminid','$weight','$push');";
    
    // 在weight和'$weight' 后面分别添加push和,'$push'


2.

 $artUrl = MakeArt($arcID,true,true,$isremote);
    if($artUrl=='')
    {
        $artUrl = $cfg_phpurl."/view.php?aid=$arcID";
    }
    
/* else  */     将else 改成 if($push==1) 判断是否选择推送
if($push==1) 

{
$urls[]='http://'.$cfg_baiduhost.'/'.$artUrl;  
$api = 'http://data.zz.baidu.com/urls?site='.$cfg_baiduhost.'&token='.$cfg_badutoken;
$ch = curl_init();
$options =  array(
    CURLOPT_URL => $api,
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS => implode("\n", $urls),
    CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
}

    ClearMyAddon($arcID, $title);

article_edit.php 代码片段:

1.

//更新数据库的SQL语句
    $query = "UPDATE chj_archives SET
    typeid='$typeid',
    typeid2='$typeid2',
    sortrank='$sortrank',
    flag='$flag',
    click='$click',
    ismake='$ismake',
    arcrank='$arcrank',
    money='$money',
    title='$title',
    color='$color',
    writer='$writer',
    source='$source',
    litpic='$litpic',
    pubdate='$pubdate',
    voteid='$voteid',
    notpost='$notpost',
    description='$description',
    keywords='$keywords',
    shorttitle='$shorttitle',
    filename='$filename',
    dutyadmin='$adminid',
    weight='$weight',
    push='$push'   /* 推送 */ /* 增加一行这个 */
    WHERE id='$id'; ";

2.

  $artUrl = MakeArt($id,true,true,$isremote);
    if($artUrl=='')
    {
        $artUrl = $cfg_phpurl."/view.php?aid=$id";

    }

/* else */    /* else 改成 if($push=="1")  判断是否选择了推送   */

if($push=="1")  {
        $urls = array(
    'http://'.$cfg_baiduhost.$artUrl,
);

$api = 'http://data.zz.baidu.com/update?site='.$cfg_baiduhost.'&token='.$cfg_badutoken;
$ch = curl_init();
$options =  array(
    CURLOPT_URL => $api,
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS => implode("\n", $urls),
    CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
}

3.分别修改article_add.htm article_edit.htm

article_add.htm 代码片段:

<tr>
            <td width="90">&nbsp;文章标题:</td>
            <td width='408'><input name="title" type="text" id="title" value="<?php echo $title; ?>" style="width:388px" /></td>
            <td width="90">&nbsp;简略标题:</td>
            <td>
                <input name="shorttitle" type="text" id="shorttitle" style="width:150px" />
            </td>
           
<!--主动推送数据 -->
<td width="100">主动推送到百度:</td>
<td><input type='radio' name='push' value="0" /> 不推送
    <input type='radio' name='push' value="1"  checked='1'/> 推送</td>
<!--主动推送数据 -->

          </tr>

article_edit.htm 代码片段:

<tr>
            <td width="90">&nbsp;文章标题:</td>
            <td width='408'><input name="title" type="text" id="title" value="<?php echo $arcRow['title']; ?>" style="width:388px"></td>
            <td width="90">&nbsp;简略标题:</td>
            <td><input name="shorttitle" type="text" id="shorttitle" style="width:150px"  value="<?php echo $arcRow['shorttitle']; ?>"></td>


<!-- 主动推送数据 -->
<td width="100">主动推送到百度:</td>
<td><input type='radio' name='push' value="0"  <?php if($arcRow['push']=='0') echo " checked='1' "?>/> 不推送
    <input type='radio' name='push' value="1"  <?php if($arcRow['push']=='1') echo " checked='1' "?>/> 推送</td>

<!-- 主动推送数据 -->
          </tr>

放出整合版本:

Documents.zip


知识共享许可协议本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可。作者:柴宏俊»