index.php 12.4 KB
<?php
define('WP_USER_ADMIN', true);
require_once( dirname(dirname(__FILE__)) . '/admin.php');
function google_xml_to_array($startDate,$endDate) {
	$url = "http://api.semalt.com/api.php?key=c21c862a9b&method=xml&need=positions&id=2317297&startdate=".$startDate."&enddate=".$endDate;
	$xmlstring = file_get_contents($url);
    $datas = json_decode(json_encode((array) simplexml_load_string($xmlstring)), true);
	$k=A;
	foreach($datas['keyword'] as $val){
		foreach($val['date'] as $v){
			$s[$v['@attributes']['value']][$k]['change']=intval($v['change']);
			$s[$v['@attributes']['value']][$k]['class']=$v['class'];
			$s[$v['@attributes']['value']][$k]['position']=intval($v['position']);
		}
		$k++;
		$list_arr=$s;
	}
	return $list_arr;
}
$startDate = date("Y-m-d",strtotime("-2 day"));
$endDate = date("Y-m-d",strtotime("-1 day"));  //昨天
$google_data = get_option("_google_data"); 

if($google_data==''){
	$google_data['dateline']=$endDate;
	$list_arr = google_xml_to_array($startDate,$endDate);
	$google_data['data']=$list_arr[$endDate];
	add_option("_google_data", $google_data); 
}else if($google_data['dateline']!=$endDate){
	$google_data['dateline']=$endDate;
	$list_arr = google_xml_to_array($startDate,$endDate);
	$google_data['data']=$list_arr[$endDate];
	update_option("_google_data", $google_data); 
}else{
	$list_arr = $google_data['data'];
}

$rank_home_num = $rank_3days_num = 0;
foreach($list_arr[$endDate] as $value){
	if(($value['position']<10||$value['position']==10)&&$value['position']>0){
        $rank_home_num++;
	}
	if(($value['position']<30||$value['position']==30)&&$value['position']>0){
        $rank_3days_num++;
	}
}

$qualified_days = get_option("_qualified_days"); 
if(!$qualified_days){
	$list_arr = array();
	$pass_days = 0;
	//方案达标天数累计开始时间,修改实例:$startDate = "2015-08-11";
    $startDate = "2015-08-11";
	$endDate = date("Y-m-d",strtotime("-1 day"));
	$list_arr = google_xml_to_array($startDate,$endDate);
	foreach($list_arr as $key=>$value){
		$rank_home_num2 = $rank_3days_num2 = 0;
		foreach($list_arr[$key] as $value){
			if(($value['position']<10||$value['position']==10)&&$value['position']>0){
				$rank_home_num2++;
			}
		}
		if($rank_home_num2>50){
			$pass_days++;
		}else{
			$res = 	$rank_home_num2/50;
			$pass_days = $pass_days + $res;
		}
	}
	$qualified_days_data['update']=$endDate;
	$qualified_days_data['data']=$pass_days;
     add_option("_qualified_days", $qualified_days_data); 
}else if($qualified_days['update']!=$endDate){
	$list_arr = array();
	$pass_days = $qualified_days['data'];
	$startDate = $qualified_days['update'];
	$endDate = date("Y-m-d",strtotime("-1 day"));
	$list_arr = google_xml_to_array($startDate,$endDate);
	unset($list_arr[$qualified_days['update']]);
	foreach($list_arr as $key=>$value){
		$rank_home_num2 = $rank_3days_num2 = 0;
		foreach($list_arr[$key] as $value){
			if(($value['position']<10||$value['position']==10)&&$value['position']>0){
				$rank_home_num2++;
			}
		}
		if($rank_home_num2>50){
			$pass_days++;
		}else{
			$res = 	$rank_home_num2/50;
			$pass_days = $pass_days + $res;
		}
	}
	$qualified_days_data['update']=$endDate;
	$qualified_days_data['data']=$pass_days;
    update_option("_qualified_days", $qualified_days_data); 
}
$qualified_days = get_option("_qualified_days"); 

//重置达标天数累计为0:去掉下面语句的注释,刷新页面可重置为0,$endDate可以重置开始时间
/*
$qualified_days_data['update']=$endDate;
$qualified_days_data['data']=0;
update_option("_qualified_days", $qualified_days_data); 
*/
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>关键词Google排名</title>
<script src="jquery.min.js"></script><!-- 套程序后删除 -->
<link href="/admin/admin.css" rel="stylesheet">
</head>

<body style="background:#fff;">
<style type="text/css">

/* 套程序后删除 --------------------------------------------*/
body,html,h1,h2,h3,h4,h5,h6,p,ul,ol,li,dl,dt,dd,th,td,form,object,iframe,blockquote,pre,a,abbr,address,code,img,fieldset,form,label,figure{margin:0;padding:0;}
body,html,input,button,textarea{color:#333;font:12px/1.8 Arial,Tahoma,Verdana,Helvetica,sans-serif;}
article,aside,figcaption,figure,footer,header,hgroup,main,nav,section{display:block;}
h1{font-size:18px;}
h2{font-size:16px;}
h3,h4,h5{font-size:14px;}
img{border:none;vertical-align:middle;}
li{list-style:none;}
i,em{font-style:normal;}
a{color:#333;text-decoration:none;}
a:focus{outline:none;}
a:hover{color:#000;text-decoration:none;}
input[type="text"]:focus{outline:none;}
input[type="button"],input[type="reset"],input[type="submit"]{cursor:pointer;}
input[type="reset"]::-moz-focus-inner,input[type="button"]::-moz-focus-inner,input[type="submit"]::-moz-focus-inner,
input[type="file"] > input[type="button"]::-moz-focus-inner{border:none;padding:0;}
hr{height:1px;border:none;border-top:1px dashed #C1C1C1;margin:10px 0;}
/*---------------------------------------------- CSS删除结束 */



/* 关键词表格 */
.keyword-table{font-size:14px;margin-bottom:-1px;position:relative;padding:0 1.5%;margin-top:-25px;}
.keyword-table table{width:100%;border-collapse:collapse;border-spacing:0;}
.keyword-table th,.keyword-table td{display:table-cell;width:9%;vertical-align:middle;text-align:center;position:relative;border:1px solid #ddd;padding:8px 0;}
.keyword-table th.row-keyword,.keyword-table td.row-keyword{width:auto;}
.keyword-table .tag-txt{display:inline-block;width:2.5em;height:20px;padding:0 2px;line-height:20px;text-align:center;border-radius:3px;background:#c4c5c9;color:#fff;font-size:14px;font-weight:normal;position:relative;}
.keyword-table .change{display:inline-block;width:2em;height:20px;line-height:20px;text-align:right;font-size:12px;}
.keyword-table .change{*display:inline;}
.keyword-table .green{background:#e4486b;}
.keyword-table .red{background:#2ecc71;}
.keyword-table .row-keyword{text-align:left!important;padding-left:10px!important;}
.keyword-table .row-keyword,.keyword-table .row-keyword a{color:#838383;}
.keyword-table .row-keyword a{text-decoration:underline;}
.keyword-table .table-head{position:relative;background:#f8f8f8; margin-bottom:-1px;}
.keyword-table .table-head tr th{font-weight:bold;border:1px solid #ddd;}
.keyword-table .table-head tr,.keyword-table .table-head tr a{color:#576a78;}
.keyword-table .table-item:nth-child(odd){background:#eff0f4;}
.loading-icon{ display:none; height:80px;background:url(loading.gif) center center no-repeat;}
.xml-loading .loading-icon{display:block;}
.xml-load-error{text-align:center; padding:30px 0;}
.beizhu1{padding: 1.5%; border:1px solid #ddd;padding:5px;font-size:12px;}
.beizhu2{padding: 0 0 10px 0;}
.info-cont em{font-size:9px;font-weight:bold;}

</style>

<script>
$(document).ready(function(){
   //当前日期
   var keyDate=new Date()
   var keyYear=keyDate.getFullYear()
   var keyMonth=keyDate.getMonth()+1
   var keyDay=keyDate.getDate()
   var curDate=keyYear+'-'+(keyMonth<10 ? "0" + keyMonth : keyMonth)+'-'+(keyDay<10 ? "0"+ keyDay : keyDay)
   
   //前一天
   var eDate=new Date()
   eDate.setDate(eDate.getDate()-1);
   var endYear=eDate.getFullYear()
   var endMonth=eDate.getMonth()+1
   var endDay=eDate.getDate()   
   var endDate=endYear+'-'+(endMonth<10 ? "0" + endMonth : startMonth)+'-'+(endDay<10 ? "0"+ endDay : endDay)   
   
   //开始日期
   var sDate=new Date()
   sDate.setDate(sDate.getDate()-7);
   var startYear=sDate.getFullYear()
   var startMonth=sDate.getMonth()+1
   var startDay=sDate.getDate()   
   var startDate=startYear+'-'+(startMonth<10 ? "0" + startMonth : startMonth)+'-'+(startDay<10 ? "0"+ startDay : startDay)
   
   //xml url
   var xmlUrl="http://api.semalt.com/api.php?key=c21c862a9b&method=xml&need=positions&id=2317297&startdate="+startDate+"&enddate="+endDate
   
   $.ajax({
      url: xmlUrl,
	  //url:"xml.xml",
	  type:"get", 
	  data:"XML",
	  timeout:6000000000,
	  error: function (xml) {            
            $('.keyword-table').removeClass('xml-loading').append('<div class="xml-load-error">数据加载失败提示!</div>')
      },
	  success: function (data) {
		 //浏览器兼容
         var xml;
         if( typeof data == "string" ){
			 xml = new ActiveXObject("Microsoft.XMLDOM");
			 xml.async = false;
			 xml.loadXML(data);
          } else {
			 xml = data; 
         }
		  
		 $('.keyword-table').removeClass('xml-loading')
		 $('.table-head tr').append('<th class="row-keyword">KEYWORD</th>')
		 $(xml).find("keyword").eq(1).find('date').each(function(){
            var keyDate=$(this).attr('value').split("-")[1]+'-'+$(this).attr('value').split("-")[2]//获取月-日
			$('.table-head tr').append('<th class="item-hd"><span class="keyword">'+keyDate+"</span>"+'</th>')
		 })
		 $(xml).find("keyword").each(function(i)
		 {
			var keyword=$(this).attr("name")
			$('.table-cont').append('<tr class="table-item"><td class="row-keyword">'+keyword+"</td>"+'</tr>')
			$(xml).find("keyword").eq(i).find('date').each(function(){
			   var cName = $(this).children("class").text();
			   var position = $(this).children("position").text();
			   //过滤掉无排名变化的字符串
			   var change = $(this).children("change").text();
			   if(isNaN(change)){
			      var change = '';
			   }
			   else{
				  var change = $(this).children("change").text();
			   }
			   //生成排名
			   if (position!=''){
				  $(".table-cont .table-item").eq(i).append("<td>"+"<span class='tag-txt"+' '+ cName+"'>"+position+"</span>"+"<i class='change'>"+change+"</i>"+"</td>");
			   }
			   else{
				  $(".table-cont .table-item").eq(i).append("<td></td>");
			   }
			})
		 })	
		 				
      }
   });

});
</script>


<div id="" class="admin-main">
    <div id="" class="main-left">
        <ul class="info-items">
            <li class="info-item top10">
                <span class="info-cont">
                    <i></i>
                    <strong class="tit">
                       排名首页:<?php echo $rank_home_num;?><em> Keywords</em>
                    </strong>
                    <span class="text" width="">
                        统计日期: <?php echo $endDate;?>
                    </span>
                </span>
            </li>
            <li class="info-item top30">
                <span class="info-cont">
                    <i></i>
                    <strong class="tit">
                        排名前三页:<?php echo $rank_3days_num;?><em> Keywords</em>
                    </strong>
                    <span class="text">
                        统计日期: <?php echo $endDate;?>
                    </span>
                </span>
            </li>
        </ul>
    </div>
    <!-- end-->
    <div id="" class="main-right">
        <ul class="info-items">
				<li class="info-item dayok">
                <span class="info-cont">
                    <i>
                    </i>
                    <strong class="tit">
                        方案已达标:<?php echo $qualified_days['data'];?><em> Days</em>
                    </strong>
                    <span class="text">
                        关键词排名首页达标天数
                    </span>
                </span>
            </li>

		            <li class="info-item dayno">
                <span class="info-cont">
                    <i>
                    </i>
                    <strong class="tit">
                        方案剩余:<?php echo intval(365-$qualified_days['data']);?><em> Days</em>
                    </strong>
                    <span class="text">
                        超过365天请按方案续费
                    </span>
                </span>
            </li>

            
        </ul>
    </div>
    <!-- end-->
</div>
<!-- end-->
<div class="clear" ></div>
<div class="keyword-table xml-loading">

   <div class="table-head">
   <table style="margin-top:-45px;">
   <tr></tr>
   </table>
   </div>
   <table class="table-cont"></table>
   <div class="loading-icon"></div>
   <div class="beizhu1">注:云SEO排名系统可以查看最近7天的排名情况,如果需要查看历史排名情况,请联系客服获取;本系统不支持IE9.0版本以下,请用火狐、谷歌、苹果浏览器访问;部分网站关键词较多,加载速度较慢,请耐心等待...</div>

</div>

</body>
</html>