103 |
- |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/***************************************************************************
|
|
|
4 |
* Copyright (C) 2009-2011 by Geo Varghese(www.seopanel.in) *
|
|
|
5 |
* sendtogeo@gmail.com *
|
|
|
6 |
* *
|
|
|
7 |
* This program is free software; you can redistribute it and/or modify *
|
|
|
8 |
* it under the terms of the GNU General Public License as published by *
|
|
|
9 |
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
10 |
* (at your option) any later version. *
|
|
|
11 |
* *
|
|
|
12 |
* This program is distributed in the hope that it will be useful, *
|
|
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
15 |
* GNU General Public License for more details. *
|
|
|
16 |
* *
|
|
|
17 |
* You should have received a copy of the GNU General Public License *
|
|
|
18 |
* along with this program; if not, write to the *
|
|
|
19 |
* Free Software Foundation, Inc., *
|
|
|
20 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
21 |
***************************************************************************/
|
|
|
22 |
|
|
|
23 |
# class defines all backlink controller functions
|
|
|
24 |
class SaturationCheckerController extends Controller{
|
|
|
25 |
var $url;
|
|
|
26 |
var $colList = array('google' => 'google', 'msn' => 'msn');
|
|
|
27 |
var $saturationUrlList = array(
|
|
|
28 |
'google' => 'http://www.google.com/search?hl=en&q=site%3A',
|
|
|
29 |
'msn' => 'http://www.bing.com/search?q=site%3A',
|
|
|
30 |
);
|
|
|
31 |
|
|
|
32 |
function showSaturationChecker() {
|
|
|
33 |
|
|
|
34 |
$this->render('saturationchecker/showsaturationchecker');
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
function findSearchEngineSaturation($searchInfo) {
|
|
|
38 |
$urlList = explode("\n", $searchInfo['website_urls']);
|
|
|
39 |
$list = array();
|
|
|
40 |
$i = 1;
|
|
|
41 |
foreach ($urlList as $url) {
|
|
|
42 |
$url = sanitizeData($url);
|
|
|
43 |
if(!preg_match('/\w+/', $url)) continue;
|
|
|
44 |
if (SP_DEMO) {
|
|
|
45 |
if ($i++ > 10) break;
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
$url = addHttpToUrl($url);
|
|
|
49 |
$list[] = str_replace(array("\n", "\r", "\r\n", "\n\r"), "", trim($url));
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
$this->set('list', $list);
|
|
|
53 |
$this->render('saturationchecker/findsearchenginesaturation');
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
function printSearchEngineSaturation($saturationInfo){
|
|
|
57 |
$this->url = $saturationInfo['url'];
|
|
|
58 |
$saturationCount = $this->__getSaturationRank($saturationInfo['engine']);
|
|
|
59 |
$websiteUrl = urldecode($this->url);
|
|
|
60 |
$saturationUrl = $this->saturationUrlList[$saturationInfo['engine']] . $websiteUrl;
|
|
|
61 |
echo "<a href='$saturationUrl' target='_blank'>$saturationCount</a>";
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
function __getSaturationRank ($engine) {
|
|
|
65 |
if (SP_DEMO && !empty($_SERVER['REQUEST_METHOD'])) return 0;
|
|
|
66 |
$saturationCount = 0;
|
|
|
67 |
switch ($engine) {
|
|
|
68 |
|
|
|
69 |
#google
|
|
|
70 |
case 'google':
|
|
|
71 |
$url = $this->saturationUrlList[$engine] . urlencode($this->url);
|
|
|
72 |
$v = $this->spider->getContent($url);
|
|
|
73 |
$pageContent = empty($v['page']) ? '' : $v['page'];
|
|
|
74 |
|
|
|
75 |
if (preg_match('/about ([0-9\,]+) result/si', $pageContent, $r)){
|
|
|
76 |
} elseif (preg_match('/<div id=resultStats>([0-9\,]+) result/si', $pageContent, $r)){
|
|
|
77 |
} elseif (preg_match('/([0-9\,]+) result/si', $pageContent, $r)){
|
|
|
78 |
} elseif (preg_match('/about <b>([0-9\,]+)<\/b> from/si', $pageContent, $r)){
|
|
|
79 |
} elseif (preg_match('/of <b>([0-9\,]+)<\/b>/si', $pageContent, $r) ) {
|
|
|
80 |
} else {
|
|
|
81 |
$crawlInfo['crawl_status'] = 0;
|
|
|
82 |
$crawlInfo['log_message'] = SearchEngineController::isCaptchInSearchResults($pageContent) ? "<font class=error>Captcha found</font> in search result page" : "Regex not matched error occured while parsing search results!";
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
$saturationCount = !empty($r[1]) ? str_replace(',', '', $r[1]) : 0;
|
|
|
86 |
break;
|
|
|
87 |
|
|
|
88 |
#msn
|
|
|
89 |
case 'msn':
|
|
|
90 |
$url = $this->saturationUrlList[$engine] . urlencode(addHttpToUrl($this->url));
|
|
|
91 |
$v = $this->spider->getContent($url);
|
|
|
92 |
$pageContent = empty($v['page']) ? '' : $v['page'];
|
|
|
93 |
if (preg_match('/([0-9\,]+) results/si', $pageContent, $r)) {
|
|
|
94 |
} elseif (preg_match('/id="count".*?>.*?\(([0-9\,]+).*?\)/si', $pageContent, $r)) {
|
|
|
95 |
} elseif (preg_match('/id="count".*?>.*?([0-9\,]+).*?/si', $pageContent, $r)) {
|
|
|
96 |
} elseif (preg_match('/class="sb_count".*?>.*?([0-9\,]+).*?<\/span>/si', $pageContent, $r)) {
|
|
|
97 |
} else {
|
|
|
98 |
$crawlInfo['crawl_status'] = 0;
|
|
|
99 |
$crawlInfo['log_message'] = SearchEngineController::isCaptchInSearchResults($pageContent) ? "<font class=error>Captcha found</font> in search result page" : "Regex not matched error occured while parsing search results!";
|
|
|
100 |
}
|
|
|
101 |
$saturationCount = !empty($r[1]) ? str_replace(',', '', $r[1]) : 0;
|
|
|
102 |
break;
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
// update crawl log
|
|
|
106 |
$crawlLogCtrl = new CrawlLogController();
|
|
|
107 |
$crawlInfo['crawl_type'] = 'saturation';
|
|
|
108 |
$crawlInfo['ref_id'] = $this->url;
|
|
|
109 |
$crawlInfo['subject'] = $engine;
|
|
|
110 |
$crawlLogCtrl->updateCrawlLog($v['log_id'], $crawlInfo);
|
|
|
111 |
|
|
|
112 |
return $saturationCount;
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
# func to show genearte reports interface
|
|
|
116 |
function showGenerateReports($searchInfo = '') {
|
|
|
117 |
|
|
|
118 |
$userId = isLoggedIn();
|
|
|
119 |
$websiteController = New WebsiteController();
|
|
|
120 |
$websiteList = $websiteController->__getAllWebsites($userId, true);
|
|
|
121 |
$this->set('websiteList', $websiteList);
|
|
|
122 |
|
|
|
123 |
$this->render('saturationchecker/generatereport');
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
# func to generate reports
|
|
|
127 |
function generateReports( $searchInfo='' ) {
|
|
|
128 |
|
|
|
129 |
$userId = isLoggedIn();
|
|
|
130 |
$websiteId = empty ($searchInfo['website_id']) ? '' : intval($searchInfo['website_id']);
|
|
|
131 |
|
|
|
132 |
$sql = "select id,url from websites where status=1";
|
|
|
133 |
if(!empty($userId) && !isAdmin()) $sql .= " and user_id=$userId";
|
|
|
134 |
if(!empty($websiteId)) $sql .= " and id=$websiteId";
|
|
|
135 |
$sql .= " order by name";
|
|
|
136 |
$websiteList = $this->db->select($sql);
|
|
|
137 |
|
|
|
138 |
if(count($websiteList) <= 0){
|
|
|
139 |
echo "<p class='note'>".$_SESSION['text']['common']['nowebsites']."!</p>";
|
|
|
140 |
exit;
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
# loop through each websites
|
|
|
144 |
foreach ( $websiteList as $websiteInfo ) {
|
|
|
145 |
$this->url = $websiteUrl = addHttpToUrl($websiteInfo['url']);
|
|
|
146 |
foreach ($this->colList as $col => $dbCol) {
|
|
|
147 |
$websiteInfo[$col] = $this->__getSaturationRank($col);
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
$this->saveRankResults($websiteInfo, true);
|
|
|
151 |
echo "<p class='note notesuccess'>".$this->spTextSat['Saved Search Engine Saturation results of']." <b>$websiteUrl</b>.....</p>";
|
|
|
152 |
}
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
# function to save rank details
|
|
|
156 |
function saveRankResults($matchInfo, $remove=false) {
|
|
|
157 |
$resultDate = date('Y-m-d');
|
|
|
158 |
|
|
|
159 |
if($remove){
|
|
|
160 |
$sql = "delete from saturationresults where website_id={$matchInfo['id']} and result_date='$resultDate'";
|
|
|
161 |
$this->db->query($sql);
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
$sql = "insert into saturationresults(website_id,google,msn,result_date)
|
|
|
165 |
values({$matchInfo['id']},{$matchInfo['google']},{$matchInfo['msn']}, '$resultDate')";
|
|
|
166 |
$this->db->query($sql);
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
# function check whether reports already saved
|
|
|
170 |
function isReportsExists($websiteId, $time) {
|
|
|
171 |
$resultDate = date('Y-m-d', $time);
|
|
|
172 |
$sql = "select website_id from saturationresults where website_id=$websiteId and result_date='$resultDate'";
|
|
|
173 |
$info = $this->db->select($sql, true);
|
|
|
174 |
return empty($info['website_id']) ? false : true;
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
# func to show reports
|
|
|
178 |
function showReports($searchInfo = '') {
|
|
|
179 |
|
|
|
180 |
$userId = isLoggedIn();
|
|
|
181 |
if (!empty ($searchInfo['from_time'])) {
|
|
|
182 |
$fromTime = $searchInfo['from_time'];
|
|
|
183 |
} else {
|
|
|
184 |
$fromTime = date('Y-m-d', strtotime('-30 days'));
|
|
|
185 |
}
|
|
|
186 |
|
|
|
187 |
if (!empty ($searchInfo['to_time'])) {
|
|
|
188 |
$toTime = $searchInfo['to_time'];
|
|
|
189 |
} else {
|
|
|
190 |
$toTime = date('Y-m-d');
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
$fromTime = addslashes($fromTime);
|
|
|
194 |
$toTime = addslashes($toTime);
|
|
|
195 |
$this->set('fromTime', $fromTime);
|
|
|
196 |
$this->set('toTime', $toTime);
|
|
|
197 |
|
|
|
198 |
$websiteController = New WebsiteController();
|
|
|
199 |
$websiteList = $websiteController->__getAllWebsites($userId, true);
|
|
|
200 |
$this->set('websiteList', $websiteList);
|
|
|
201 |
$websiteId = empty ($searchInfo['website_id']) ? $websiteList[0]['id'] : intval($searchInfo['website_id']);
|
|
|
202 |
$this->set('websiteId', $websiteId);
|
|
|
203 |
|
|
|
204 |
$conditions = empty ($websiteId) ? "" : " and s.website_id=$websiteId";
|
|
|
205 |
$sql = "select s.* ,w.name from saturationresults s,websites w where s.website_id=w.id
|
|
|
206 |
and result_date >= '$fromTime' and result_date <= '$toTime' $conditions order by result_date";
|
|
|
207 |
$reportList = $this->db->select($sql);
|
|
|
208 |
|
|
|
209 |
$i = 0;
|
|
|
210 |
$colList = $this->colList;
|
|
|
211 |
foreach ($colList as $col => $dbCol) {
|
|
|
212 |
$prevRank[$col] = 0;
|
|
|
213 |
}
|
|
|
214 |
|
|
|
215 |
# loop throgh rank
|
|
|
216 |
foreach ($reportList as $key => $repInfo) {
|
|
|
217 |
foreach ($colList as $col => $dbCol) {
|
|
|
218 |
$rankDiff[$col] = '';
|
|
|
219 |
}
|
|
|
220 |
|
|
|
221 |
foreach ($colList as $col => $dbCol) {
|
|
|
222 |
if ($i > 0) {
|
|
|
223 |
$rankDiff[$col] = ($prevRank[$col] - $repInfo[$dbCol]) * -1;
|
|
|
224 |
if ($rankDiff[$col] > 0) {
|
|
|
225 |
$rankDiff[$col] = "<font class='green'>($rankDiff[$col])</font>";
|
|
|
226 |
}elseif ($rankDiff[$col] < 0) {
|
|
|
227 |
$rankDiff[$col] = "<font class='red'>($rankDiff[$col])</font>";
|
|
|
228 |
}
|
|
|
229 |
}
|
|
|
230 |
$reportList[$key]['rank_diff_'.$col] = empty ($rankDiff[$col]) ? '' : $rankDiff[$col];
|
|
|
231 |
}
|
|
|
232 |
|
|
|
233 |
foreach ($colList as $col => $dbCol) {
|
|
|
234 |
$prevRank[$col] = $repInfo[$dbCol];
|
|
|
235 |
}
|
|
|
236 |
|
|
|
237 |
$i++;
|
|
|
238 |
}
|
|
|
239 |
|
|
|
240 |
$websiteInfo = $websiteController->__getWebsiteInfo($websiteId);
|
|
|
241 |
$websiteUrl = urldecode($websiteInfo['url']);
|
|
|
242 |
$this->set('directLinkList', array(
|
|
|
243 |
'google' => $this->saturationUrlList['google'] . $websiteUrl,
|
|
|
244 |
'msn' => $this->saturationUrlList['msn'] . $websiteUrl,
|
|
|
245 |
));
|
|
|
246 |
|
|
|
247 |
$this->set('list', array_reverse($reportList, true));
|
|
|
248 |
$this->render('saturationchecker/saturationreport');
|
|
|
249 |
}
|
|
|
250 |
|
|
|
251 |
# func to get reports of saturation of a website
|
|
|
252 |
function __getWebsiteSaturationReport($websiteId, $fromTime, $toTime) {
|
|
|
253 |
|
|
|
254 |
$fromTimeLabel = date('Y-m-d', $fromTime);
|
|
|
255 |
$toTimeLabel = date('Y-m-d', $toTime);
|
|
|
256 |
$sql = "select s.* ,w.name from saturationresults s,websites w where s.website_id=w.id and s.website_id=$websiteId
|
|
|
257 |
and (result_date='$fromTimeLabel' or result_date='$toTimeLabel') order by result_date DESC Limit 0,2";
|
|
|
258 |
$reportList = $this->db->select($sql);
|
|
|
259 |
$reportList = array_reverse($reportList);
|
|
|
260 |
|
|
|
261 |
$i = 0;
|
|
|
262 |
$colList = $this->colList;
|
|
|
263 |
foreach ($colList as $col => $dbCol) {
|
|
|
264 |
$prevRank[$col] = 0;
|
|
|
265 |
}
|
|
|
266 |
|
|
|
267 |
# loop throgh rank
|
|
|
268 |
foreach ($reportList as $key => $repInfo) {
|
|
|
269 |
foreach ($colList as $col => $dbCol) {
|
|
|
270 |
$rankDiff[$col] = '';
|
|
|
271 |
}
|
|
|
272 |
|
|
|
273 |
foreach ($colList as $col => $dbCol) {
|
|
|
274 |
if ($i > 0) {
|
|
|
275 |
$rankDiff[$col] = ($prevRank[$col] - $repInfo[$dbCol]) * -1;
|
|
|
276 |
if ($rankDiff[$col] > 0) {
|
|
|
277 |
$rankDiff[$col] = "<font class='green'>($rankDiff[$col])</font>";
|
|
|
278 |
}elseif ($rankDiff[$col] < 0) {
|
|
|
279 |
$rankDiff[$col] = "<font class='red'>($rankDiff[$col])</font>";
|
|
|
280 |
}
|
|
|
281 |
}
|
|
|
282 |
$reportList[$key]['rank_diff_'.$col] = empty ($rankDiff[$col]) ? '' : $rankDiff[$col];
|
|
|
283 |
}
|
|
|
284 |
|
|
|
285 |
foreach ($colList as $col => $dbCol) {
|
|
|
286 |
$prevRank[$col] = $repInfo[$dbCol];
|
|
|
287 |
}
|
|
|
288 |
|
|
|
289 |
$i++;
|
|
|
290 |
}
|
|
|
291 |
|
|
|
292 |
$reportList = array_reverse(array_slice($reportList, count($reportList) - 1));
|
|
|
293 |
return $reportList;
|
|
|
294 |
}
|
|
|
295 |
|
|
|
296 |
# func to show graphical reports
|
|
|
297 |
function showGraphicalReports($searchInfo = '') {
|
|
|
298 |
|
|
|
299 |
$userId = isLoggedIn();
|
|
|
300 |
$fromTime = !empty($searchInfo['from_time']) ? $searchInfo['from_time'] : date('Y-m-d', strtotime('-30 days'));
|
|
|
301 |
$toTime = !empty ($searchInfo['to_time']) ? $searchInfo['to_time'] : date("Y-m-d");
|
|
|
302 |
$this->set('fromTime', $fromTime);
|
|
|
303 |
$this->set('toTime', $toTime);
|
|
|
304 |
|
|
|
305 |
$websiteController = New WebsiteController();
|
|
|
306 |
$websiteList = $websiteController->__getAllWebsites($userId, true);
|
|
|
307 |
$this->set('websiteList', $websiteList);
|
|
|
308 |
$websiteId = empty ($searchInfo['website_id']) ? $websiteList[0]['id'] : intval($searchInfo['website_id']);
|
|
|
309 |
$this->set('websiteId', $websiteId);
|
|
|
310 |
|
|
|
311 |
$conditions = empty ($websiteId) ? "" : " and s.website_id=$websiteId";
|
|
|
312 |
$sql = "select s.* ,w.name from saturationresults s,websites w where s.website_id=w.id
|
|
|
313 |
and result_date >= '$fromTime' and result_date <= '$toTime' $conditions order by result_date";
|
|
|
314 |
$reportList = $this->db->select($sql);
|
|
|
315 |
|
|
|
316 |
// if reports not empty
|
|
|
317 |
$colList = $this->colList;
|
|
|
318 |
if (!empty($reportList)) {
|
|
|
319 |
|
|
|
320 |
$dataArr = "['Date', '" . implode("', '", array_values($colList)) . "']";
|
|
|
321 |
|
|
|
322 |
// loop through data list
|
|
|
323 |
foreach ($reportList as $dataInfo) {
|
|
|
324 |
|
|
|
325 |
$valStr = "";
|
|
|
326 |
foreach ($colList as $seId => $seVal) {
|
|
|
327 |
$valStr .= ", ";
|
|
|
328 |
$valStr .= !empty($dataInfo[$seId]) ? $dataInfo[$seId] : 0;
|
|
|
329 |
}
|
|
|
330 |
|
|
|
331 |
$dataArr .= ", ['{$dataInfo['result_date']}' $valStr]";
|
|
|
332 |
}
|
|
|
333 |
|
|
|
334 |
$this->set('dataArr', $dataArr);
|
|
|
335 |
$this->set('graphTitle', $this->spTextSat['Search Engine Saturation Reports']);
|
|
|
336 |
$graphContent = $this->getViewContent('report/graph');
|
|
|
337 |
|
|
|
338 |
} else {
|
|
|
339 |
$graphContent = showErrorMsg($_SESSION['text']['common']['No Records Found'], false, true);
|
|
|
340 |
}
|
|
|
341 |
|
|
|
342 |
// get graph content
|
|
|
343 |
$this->set('graphContent', $graphContent);
|
|
|
344 |
$this->render('saturationchecker/graphicalreport');
|
|
|
345 |
}
|
|
|
346 |
|
|
|
347 |
}
|
|
|
348 |
?>
|