| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- <?php
- /********** 配置教程 ****************
-
- ********************************************/
- set_time_limit ( 0 );
- include ("../config/conn.php");
- include ("../config/function.php");
- AdminSes_audit ();
- $uip = getuip ();
- $configfile = "chajian_pushLink2Baidu_config.ini";
- $host = $_SERVER['HTTP_HOST'];
- //$testtoken="yCNM9gL9dYR6WZVt"; // 百度token
- $token = readBaiduToken($configfile);
- #empty()使用变量,不支持php5.3以下版本
- $baiduWebsite = readBaiduWebsite($configfile);
- $protocalHeader = readProtocolHeader($configfile);
- $baiduwebsite = empty($baiduWebsite)?$host:$baiduWebsite;
- if(empty($_POST['protocolheader'])){
- $protocolheader = empty($protocalHeader)?"http":$protocalHeader;
- }else {
- $protocolheader = $_POST['protocolheader'];
- }
- $rooturl = $protocolheader."://".$_SERVER['HTTP_HOST']."/";
- $productSize = empty($_POST[productsize])?20:$_POST[productsize];
- $newsSize = empty($_POST[newssize])?20:$_POST[newssize];
- if(isset($_POST['newurl'])){
- $productSize = $_POST[productsize];//empty($_POST[t1])?20:$_POST[t1]; // 商品推送数
- $newsSize = $_POST[newssize];//empty($_POST[t2])?20:$_POST[t2]; // 新闻推送数
-
- // 最新商品
- $px="order by lastsj desc";
- pagef($ses,$productSize,"yjcode_pro",$px);
- $producturls = array();
-
- $result = "";
- while($row=mysql_fetch_array($res)){
- $au=$rooturl."product/view".$row[id].".html";
- array_push($producturls,$au);
- }
-
- foreach ($producturls as $url){
- $result = $result.$url."\r\n";
- }
-
- // 最新文章
- $newsurls = array();
-
- pagef($ses,$newsSize,"yjcode_news","order by lastsj desc");
- while($row=mysql_fetch_array($res)){
- if (empty ( $row ["tit"] ) || ($row ["tit"] == ""))
- continue;
-
- if (empty ( $row ["txt"] ) || ($row ["txt"] == ""))
- continue;
-
- $aurl = $rooturl."news/txtlist_i".$row[id]."v.html";
- array_push($newsurls,$aurl);
- }
-
- foreach ($newsurls as $url){
- $result = $result.$url."\r\n";
- }
-
- //echo $result;
-
- $setSize = $productSize + $newsSize;
- $actualCount = count($producturls) + count($newsurls);
- $failSize = $setSize - $actualCount;
- $resultCount = "设置链接数: ".$setSize." 实际链接数: ".$actualCount." 失败链接数: ".$failSize;
-
- $token = $_POST[baidutoken];
- saveBaiduToken($configfile,$token,$baiduwebsite,$protocolheader);
- }
- //if ($_GET [control] == "push") {
- if(isset($_POST['push2baidu'])){
- if (! strstr ( $adminqx, ",0," )) {
- Audit_alert ( "权限不够", "default.php" );
- }
- zwzr ();
- $ifadminreg = 1;
- $r1 = intval ( $_POST [R1] );
-
- if ($r1 == 1) {
- // 自动生成
- $t1 = $_POST [t1];
-
- $token = $_POST[baidutoken];
-
- $urlarr = explode ( "\\r\\n", $t1 );
-
- foreach ( $urlarr as $url ) {
- //echo $url,'<br />';
- }
-
- $api = "http://data.zz.baidu.com/urls?site=".$baiduwebsite."&token=".$token;
- $ch = curl_init ();
- $options = array (
- CURLOPT_URL => $api,
- CURLOPT_POST => true,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_POSTFIELDS => implode ( "\n", $urlarr ),
- CURLOPT_HTTPHEADER => array (
- 'Content-Type: text/plain'
- )
- );
- curl_setopt_array ( $ch, $options );
- $result = curl_exec ( $ch );
- saveBaiduToken($configfile,$token,$baiduwebsite,$protocolheader);
- //echo $result;
- } elseif ($r1 == 2) {
- }
-
- }
- //读ini文件
- function readini($name)
- {
- if (file_exists($name))
- {
- $data = parse_ini_file($name,true);
- if ($data)
- {
- return $data;
- }
- }
- else
- {
- return false;
- }
- }
- function writeini($assoc_arr, $path, $has_sections=FALSE)
- {
- $content = "";
- if ($has_sections)
- {
- foreach ($assoc_arr as $key=>$elem)
- {
- $content .= "[".$key."]\n";
- foreach ($elem as $key2=>$elem2)
- {
- if(is_array($elem2))
- {
- for($i=0;$i<count($elem2);$i++)
- {
- $content .= $key2."[] = \"".$elem2[$i]."\"\n";
- }
- }
- else if($elem2=="") $content .= $key2." = \n";
- else $content .= $key2." = \"".$elem2."\"\n";
- }
- }
- }
- else
- {
- foreach ($assoc_arr as $key=>$elem)
- {
- if(is_array($elem))
- {
- for($i=0;$i<count($elem);$i++)
- {
- $content .= $key2."[] = \"".$elem[$i]."\"\n";
- }
- }
- else if($elem=="") $content .= $key2." = \n";
- else $content .= $key2." = \"".$elem."\"\n";
- }
- }
- if (!$handle = fopen($path, 'w'))
- {
- return false;
- }
- if (!fwrite($handle, $content))
- {
- return false;
- }
- fclose($handle);
- return true;
- }
- function saveBaiduToken($configfile,$token,$baiduwebsite,$protocolheader){
- $config = array(
- 'pushLink2Baidu' => array(
- 'baidutoken' => $token,
- 'baiduwebsite' => $baiduwebsite,
- 'protocolheader' => $protocolheader,
- ));
- writeini($config, $configfile, true);
- }
- function readBaiduToken($configfile){
- $configarr = readini($configfile);
- return $configarr[pushLink2Baidu][baidutoken];
- }
- function readBaiduWebsite($configfile){
- $configarr = readini($configfile);
- return $configarr[pushLink2Baidu][baiduwebsite];
- }
- function readProtocolHeader($configfile){
- $configarr = readini($configfile);
- return $configarr[pushLink2Baidu][protocolheader];
- }
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="x-ua-compatible" content="ie=7" />
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- <title><?=webname?>管理系统</title>
- <link href="css/basic.css" rel="stylesheet" type="text/css" />
- <script type="text/javascript" src="js/jquery.min.js"></script>
- <script language="javascript" src="js/basic.js"></script>
- <script language="javascript" src="js/layer.js"></script>
- <script language="javascript">
- function r1onc(x){
- document.getElementById("r1main1").style.display="none";
- document.getElementById("r1main2").style.display="none";
- document.getElementById("r1main"+x).style.display="";
- }
- </script>
- </head>
- <body>
- <? include("top.php");?>
- <script language="javascript">
- document.getElementById("menu7").className="a1";
- </script>
- <div class="yjcode">
- <? $leftid=1;include("menu_chajian.php");?>
- <div class="right">
- <!--B-->
- <? systs("恭喜您,操作成功!","chajian_pushLink2Baidu.php")?>
- <div class="bqu1">
- <a href="javascript:void(0);" class="a1">百度链接主动提交</a>
- </div>
- <div class="rkuang">
- <script language="javascript">
- function tj(){
- layer.msg('正在提交', {icon: 16 ,time: 0,shade :0.25});
- f1.action="chajian_pushLink2Baidu.php?control=push";
- }
- </script>
- <!-- <form name="f1" method="post" onsubmit="return tj()"
- enctype="multipart/form-data">
- -->
- <form name="f1" method="post" enctype="multipart/form-data">
- <ul class="uk">
- <li class="l1">链接总数:</li>
- <li class="l21"><?php echo ($resultCount);?></li>
- <li class="l1">添加方式:</li>
- <li class="l2">
- <label><input name="R1" type="radio" value="1"
- onclick="r1onc(1)" checked="checked" /> 自动生成</label>
- <!-- <label><input name="R1" type="radio" value="2" onclick="r1onc(2)" /> 批量上传</label> -->
- <li class="l1">商品数量:</li>
- <li class="l2"><input type="text" class="inp" value="<?php echo $productSize;?>" size="10" name="productsize"/><span class="fd">条</span></li>
-
- <li class="l1">文章数量:</li>
- <li class="l2"><input type="text" class="inp" value="<?php echo $newsSize;?>" size="10" name="newssize"/><span class="fd">条</span></li>
- <li class="l1">协议头:</li>
- <li class="l2"><input type="text" class="inp" value="<?php echo $protocolheader;?>" size="10" name="protocolheader" style="width: 300px"/><span class="fd">(默认http)</span></li>
- <li class="l1">站点名称:</li>
- <li class="l2"><input type="text" class="inp" value="<?php echo $baiduwebsite;?>" size="10" name="baiduwebsite" style="width: 300px"/><span class="fd">(从百度获取,需要验证的站点,注意一级域名和二级域名是独立的站点)</span></li>
- <li class="l1">百度Token:</li>
- <li class="l2"><input type="text" class="inp" value="<?php echo $token;?>" size="10" name="baidutoken" style="width: 300px"/><span class="fd">(从百度获取)</span></li>
- </li>
- </ul>
- <ul class="uk uk0" id="r1main1">
- <li class="l1">生成链接:</li>
- <li class="l2"><textarea cols="400" rows="150"
- style="width: 400px; height: 50px;" id="idTextarea1"
- class="inp" value="0" size="100" name="t1" v-model="vmTextarea1"><?php echo($result); ?></textarea></li>
- </ul>
- <ul class="uk uk0" id="r1main2" style="display: none;">
- <li class="l1">选择文件:</li>
- <li class="l2"><input type="file" name="inp1" class="inp1"
- id="inp1" size="25"></li>
- <li class="l1"></li>
- <li class="l21">上传格式为xls文件,即excel,程序会自动识别,但必须保证符合规则,<strong
- class="red">第一列为账号,第二列为密码</strong></li>
- </ul>
- <ul class="uk uk0">
- <!-- <li class="l3"><input type="submit" value="生成链接" class="btn1" /></li> -->
- <li class="l3">
- <input type="submit" name="newurl" id="newurl" value="生成链接" class="btn1" style="float: none"/>
- <input type="submit" name="push2baidu" id="push2baidu" value="开始推送" class="btn1" style="float: none"/>
- </li>
-
- <a href="https://ziyuan.baidu.com/linksubmit/index" target="_blank">推送查询</a>
- </li>
- </ul>
- </form>
- </div>
- <!--E-->
- </div>
- </div>
- <?php include("bottom.php");?>
- </body>
- </html>
|