index.php
12.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
<?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>