-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNaverBlogVisitorCntCrawler.php
More file actions
38 lines (30 loc) · 1.09 KB
/
NaverBlogVisitorCntCrawler.php
File metadata and controls
38 lines (30 loc) · 1.09 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
<?php
class NaverBlogVisitorCntCrawler {
private $blogId;
function __construct($blogId = null) {
$this->blogId = $blogId;
}
function setBlogId($blogId) {
$this->blogId = $blogId;
}
function getBlogId() {
return $this->blogId;
}
function getAverageVisitorCnt() {
if ($this->blogId == null) {
return false;
}
$xmlGetterURL = curl_init("http://blog.naver.com/NVisitorgp4Ajax.nhn?blogId=".$this->blogId);
curl_setopt($xmlGetterURL, CURLOPT_RETURNTRANSFER, true);
$naverBlogVisitorCntXml = curl_exec($xmlGetterURL);
$resultXml = simplexml_load_string($naverBlogVisitorCntXml);
// exclude today's visitor count
$averagePeriod = 4;
$totalVisitorCnt = 0;
for ($i = 0; $i < $averagePeriod; $i++) {
$totalVisitorCnt += $resultXml->visitorcnt[$i]['cnt'];
}
$averageVisitorCnt = $totalVisitorCnt / $averagePeriod;
return $averageVisitorCnt;
}
}