Subversion Repositories cheapmusic

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
103 - 1
<?php
2
 
3
/***************************************************************************
4
 *   Copyright (C) 2009-2011 by Geo Varghese(www.seofreetools.net)  	   *
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
include_once(SP_CTRLPATH."/keyword.ctrl.php");
24
include_once(SP_CTRLPATH."/moz.ctrl.php");
25
 
26
# class defines all cron controller functions
27
class CronController extends Controller {
28
 
29
	var $cronList;			    // the array includes all tools avialable for cron
30
	var $repTools;			    // the array includes all tools avialable for report generation
31
	var $debug = true;		    // to show debug message or not
32
	var $layout = 'ajax';       // ajax layout or not
33
	var $timeStamp;             // timestamp for storing reports
34
	var $checkedKeywords = 0;   // the number of keywords checked in cron, this is used for split cron execution feature
35
	var $checkedWebsites = 0;   // the number of websites checked in cron, this is used for split cron execution feature
36
 
37
	# function to load all tools required for report generation
38
	function loadReportGenerationTools($includeList=array()){
39
		$includeList = formatSQLParamList($includeList);
40
		$sql = "select * from seotools where status=1 and reportgen=1";
41
		if(count($includeList) > 0) $sql .= " and id in (".implode(',', $includeList).")";
42
		$this->repTools = $this->db->select($sql);
43
	}
44
 
45
	# function to load all tools required for cron job
46
	function loadCronJobTools($includeList=array()){
47
		$sql = "select * from seotools where status=1 and cron=1";
48
		if(count($includeList) > 0) $sql .= " and id in (".implode(',', $includeList).")";
49
		$sql .= " order by id ASC";
50
		$this->cronList = $this->db->select($sql);
51
	}
52
 
53
	# function to show report generation manager
54
	function showReportGenerationManager(){
55
 
56
		$userId = isLoggedIn();
57
		$websiteController = New WebsiteController();
58
		$websiteList = $websiteController->__getAllWebsites($userId, true);
59
		$this->set('websiteList', $websiteList);
60
		$this->set('websiteNull', false);
61
 
62
		$this->loadReportGenerationTools();
63
		$this->set('repTools', $this->repTools);
64
 
65
		$this->render('report/reportgenerationmanager');
66
	}
67
 
68
	# function to show cron command
69
	function showCronCommand(){
70
 
71
		$this->render('report/croncommand');
72
	}
73
 
74
	# common report generation function
75
	function executeReportGenerationScript($info='') {
76
 
77
		if(count($info['repTools']) <= 0){
78
			showErrorMsg($this->spTextKeyword['pleaseselecttool']."!");
79
		}
80
 
81
		$websiteCtrler = New WebsiteController();
82
		if(!empty($info['website_id'])){
83
			$allWebsiteList[] = $websiteCtrler->__getWebsiteInfo($info['website_id']);
84
		}else{
85
			$userCtrler = New UserController();
86
			$userList = $userCtrler->__getAllUsers();
87
			$allWebsiteList = array();
88
			foreach($userList as $userInfo){
89
 
90
				$websiteList = $websiteCtrler->__getAllWebsites($userInfo['id']);
91
				foreach($websiteList as $websiteInfo){
92
					$allWebsiteList[] = $websiteInfo;
93
				}
94
			}
95
		}
96
 
97
		if(count($allWebsiteList) <= 0){
98
			showErrorMsg($_SESSION['text']['common']['nowebsites']."!");
99
		}
100
 
101
		$this->set('allWebsiteList', $allWebsiteList);
102
		$this->set('repTools', implode(':', $info['repTools']));
103
		$this->render('report/reportgenerator');
104
	}
105
 
106
	# common cron execute function
107
	function executeCron($includeList=array(), $userSelectList=array()) {
108
 
109
		$this->loadCronJobTools($includeList);
110
		$lastGenerated = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
111
 
112
		$userCtrler = New UserController();
113
 
114
		// if user list selected is not empty
115
		if (!empty($userSelectList)) {
116
			$userList = $userSelectList;
117
		} else {
118
			$userList = $userCtrler->__getAllUsers(true, true, "utype_id DESC");
119
		}
120
 
121
		foreach($userList as $userInfo){
122
 
123
			// check whethere user id is existing
124
			if (empty($userInfo['id'])) continue;
125
 
126
			// check whether user expired
127
			if (!$userCtrler->isUserExpired($userInfo['id'])) {
128
				continue;
129
			}
130
 
131
		    // create report controller
132
		    $reportCtrler = New ReportController();
133
 
134
		    // check for user report schedule
135
		    $repSetInfo = $reportCtrler->isGenerateReportsForUser($userInfo['id']);
136
 
137
			if (!empty($repSetInfo['generate_report'])) {
138
 
139
			    $websiteCtrler = New WebsiteController();
140
			    $sql = "select * from websites where status=1 and user_id=" . $userInfo['id'] . " and crawled=0 order by name";
141
			    $websiteList = $websiteCtrler->db->select($sql);
142
			    $websiteCount = count($websiteList);
143
 
144
    			// if websites are available
145
    			if ($websiteCount > 0) {
146
 
147
        			foreach($websiteList as $websiteInfo){
148
 
149
        				$this->websiteInfo = $websiteInfo;
150
        				$this->routeCronJob($websiteInfo['id'], '', true);
151
        				$this->checkedWebsites++;
152
 
153
        				// change website crawl status
154
        				$sql = "update websites set crawled=1 where id=" . $websiteInfo['id'];
155
        				$websiteList = $websiteCtrler->db->query($sql);
156
 
157
        				// if all websites checked, mark as report generated for the day
158
        				if ($this->checkedWebsites != $websiteCount) {
159
 
160
	        				// to implement split cron execution feature
161
	        				if ( SP_NUMBER_WEBSITES_CRON > 0) {
162
	        					if ($this->checkedWebsites == SP_NUMBER_WEBSITES_CRON) {
163
	        						die("Reached total number of allowed websites(" . SP_NUMBER_WEBSITES_CRON. ") in each cron job");
164
	        					}
165
	        				}
166
 
167
        				}
168
 
169
        			}
170
 
171
        			// save report generated time
172
    				$reportCtrler->updateUserReportSetting($userInfo['id'], 'last_generated', $lastGenerated);
173
 
174
    				// update report generation logs
175
    				$reportCtrler->updateUserReportGenerationLogs($userInfo['id'], date('Y-m-d H:i:s'));
176
 
177
    				// update user alerts section
178
    				$alertCtrl = new AlertController();
179
    				$reportTxt = $this->getLanguageTexts('reports', $_SESSION['lang_code']);
180
    				$alertInfo = array(
181
    					'alert_subject' => $reportTxt["Reports Generated Successfully"],
182
    					'alert_message' => $reportTxt['report_email_subject'],
183
    					'alert_category' => "reports",
184
    					'alert_url' => SP_WEBPATH,
185
    				);
186
    				$alertCtrl->createAlert($alertInfo, $userInfo['id']);
187
 
188
    				// send email notification if enabled
189
    				if (SP_REPORT_EMAIL_NOTIFICATION && $repSetInfo['email_notification']) {
190
    					$reportCtrler->spTextTools = $this->getLanguageTexts('seotools', $_SESSION['lang_code']);
191
    					$reportCtrler->set('spTextTools', $reportCtrler->spTextTools);
192
    				    $reportCtrler->sentEmailNotificationForReportGen($userInfo, $repSetInfo['last_generated'], $lastGenerated);
193
    				}
194
 
195
    			}
196
 
197
			}
198
		}
199
 
200
		// if user selected list empty
201
		if (empty($userSelectList)) {
202
 
203
			// reset all keywords crawl status
204
			$keywordCtrler = New KeywordController();
205
			$keywordCtrler->__changeCrawledStatus(0);
206
			$this->debugMsg("Reset all keywords crawl status\n");
207
 
208
			// change all website crawl status
209
			$sql = "update websites set crawled=0";
210
			$keywordCtrler->db->query($sql);
211
			$this->debugMsg("Change all websites crawl status\n");
212
		}
213
 
214
	}
215
 
216
	# function to route the cronjobs to different methods
217
	function routeCronJob($websiteId, $repTools='', $cron=false){
218
 
219
		$websiteId = intval($websiteId);
220
		if(empty($this->websiteInfo)){
221
			$websiteCtrler = New WebsiteController();
222
			$this->websiteInfo = $websiteCtrler->__getWebsiteInfo($websiteId);
223
		}
224
 
225
		if($cron){
226
			if(empty($this->cronList)){
227
				$this->loadCronJobTools();
228
			}
229
			$seoTools = $this->cronList;
230
		}else{
231
			$this->loadReportGenerationTools(explode(':', $repTools));
232
			$seoTools = $this->repTools;
233
		}
234
 
235
		// check whethre user access to seo tools and plugins
236
		$userCtrler = New UserController();
237
		$userInfo = $userCtrler->__getUserInfo($this->websiteInfo['user_id']);
238
		$userTypeCtrler = new UserTypeController();
239
 
240
		// check whethere user is admin
241
		if ($userInfo['utype_id'] == $userTypeCtrler->getAdminUserTypeId()) {
242
		    $isAdmin = true;
243
		} else {
244
		    $isAdmin = false;
245
		    $toolAccessList = $userTypeCtrler->getSeoToolAccessSettings($userInfo['utype_id']);
246
		}
247
 
248
		foreach ($seoTools as $cronInfo) {
249
 
250
		    // check whether user have acccess to the tool
251
		    if (!$isAdmin && empty($toolAccessList[$cronInfo['id']]['value']) ) continue;
252
 
253
			switch($cronInfo['url_section']){
254
 
255
				case "webmaster-tools":
256
					$this->webmasterToolsCron($websiteId);
257
					break;
258
 
259
				case "keyword-position-checker":
260
					$this->keywordPositionCheckerCron($websiteId);
261
					break;
262
 
263
				case "rank-checker":
264
					$this->rankCheckerCron($websiteId);
265
					break;
266
 
267
				case "backlink-checker":
268
					$this->backlinkCheckerCron($websiteId);
269
					break;
270
 
271
				case "saturation-checker":
272
					$this->saturationCheckerCron($websiteId);
273
					break;
274
 
275
				case "pagespeed":
276
					$this->pageSpeedCheckerCron($websiteId);
277
					break;
278
 
279
				case "sm-checker":
280
					$this->socialMediaCheckerCron($websiteId);
281
					break;
282
 
283
				case "review-manager":
284
					$this->reviewCheckerCron($websiteId);
285
					break;
286
 
287
				case "web-analytics":
288
					$this->analyticsCron($websiteId);
289
					break;
290
			}
291
		}
292
 
293
	}
294
 
295
	# func to generate search engine saturation reports from cron
296
	function saturationCheckerCron($websiteId){
297
 
298
		include_once(SP_CTRLPATH."/saturationchecker.ctrl.php");
299
		$this->debugMsg("Starting Search engine saturation Checker cron for website: {$this->websiteInfo['name']}....<br>\n");
300
 
301
		$saturationCtrler = New SaturationCheckerController();
302
		$websiteInfo = $this->websiteInfo;
303
 
304
		if (SP_MULTIPLE_CRON_EXEC && $saturationCtrler->isReportsExists($websiteInfo['id'], $this->timeStamp)) return;
305
 
306
		$saturationCtrler->url = $websiteUrl = addHttpToUrl($websiteInfo['url']);
307
		foreach ($saturationCtrler->colList as $col => $dbCol) {
308
			$websiteInfo[$col] = $saturationCtrler->__getSaturationRank($col);
309
		}
310
 
311
		$saturationCtrler->saveRankResults($websiteInfo, true);
312
		echo "Saved Search Engine Saturation results of <b>$websiteUrl</b>.....</br>\n";
313
 
314
	}
315
 
316
	# func to generate pagespeed reports from cron
317
	function pageSpeedCheckerCron($websiteId){
318
 
319
		include_once(SP_CTRLPATH."/pagespeed.ctrl.php");
320
		$this->debugMsg("Starting page speed Checker cron for website: {$this->websiteInfo['name']}....<br>\n");
321
 
322
		$pageSpeedCtrler = New PageSpeedController();
323
		$websiteInfo = $this->websiteInfo;
324
 
325
		if (SP_MULTIPLE_CRON_EXEC && $pageSpeedCtrler->isReportsExists($websiteInfo['id'], $this->timeStamp)) return;
326
 
327
		$userCtrler = new UserController();
328
		$userInfo = $userCtrler->__getUserInfo($websiteInfo['user_id']);
329
		$langCode = $userInfo['lang_code'];
330
 
331
		$websiteUrl = addHttpToUrl($websiteInfo['url']);
332
		$params = array('screenshot' => false, 'strategy' => 'desktop', 'locale' => $langCode);
333
		$websiteInfo['desktop'] = $pageSpeedCtrler->__getPageSpeedInfo($websiteUrl, $params);
334
		$params = array('screenshot' => false, 'strategy' => 'mobile', 'locale' => $langCode);
335
		$websiteInfo['mobile'] = $pageSpeedCtrler->__getPageSpeedInfo($websiteUrl, $params);
336
 
337
		$pageSpeedCtrler->savePageSpeedResults($websiteInfo, true);
338
		echo "Saved page speed results of <b>$websiteUrl</b>.....</br>\n";
339
 
340
	}
341
 
342
	# func to generate social media checker reports from cron
343
	function socialMediaCheckerCron($websiteId){
344
 
345
		include_once(SP_CTRLPATH."/social_media.ctrl.php");
346
		$this->debugMsg("Starting social media Checker cron for website: {$this->websiteInfo['name']}....<br>\n");
347
 
348
		$socialMediaCtrler = New SocialMediaController();
349
		$websiteInfo = $this->websiteInfo;
350
 
351
		$linkList = $socialMediaCtrler->getAllLinksWithOutReports($websiteInfo['id'], date('Y-m-d', $this->timeStamp));
352
		if (SP_MULTIPLE_CRON_EXEC && empty($linkList)) {
353
			$this->debugMsg("No social media links left to generate report for website: {$this->websiteInfo['name']}....<br>\n");
354
			return true;
355
		}
356
 
357
		// loop through link list and save the data
358
		foreach ($linkList as $linkInfo) {
359
			$result = $socialMediaCtrler->getSocialMediaDetails($linkInfo['type'], $linkInfo['url']);
360
 
361
			if ($result['status']) {
362
				echo "Crawled social media results of <b>{$linkInfo['name']}</b>.....</br>\n";
363
			} else {
364
				echo "Failed Crawling of social media results of <b>{$linkInfo['name']}</b>.....</br>\n";
365
				echo $result['msg'];
366
			}
367
 
368
			// save the social media data
369
			$socialMediaCtrler->saveSocialMediaLinkResults($linkInfo['id'], $result);
370
			sleep(SP_CRAWL_DELAY + 5);
371
		}
372
 
373
		echo "Saved social media results of website id: <b>$websiteId</b>.....</br>\n";
374
 
375
	}
376
 
377
	# func to generate review checker reports from cron
378
	function reviewCheckerCron($websiteId) {
379
		include_once(SP_CTRLPATH."/review_manager.ctrl.php");
380
		$this->debugMsg("Starting review Checker cron for website: {$this->websiteInfo['name']}....<br>\n");
381
 
382
		$reviewController = New ReviewManagerController();
383
		$websiteInfo = $this->websiteInfo;
384
 
385
		$linkList = $reviewController->getAllLinksWithOutReports($websiteInfo['id'], date('Y-m-d', $this->timeStamp));
386
		if (SP_MULTIPLE_CRON_EXEC && empty($linkList)) {
387
			$this->debugMsg("No review links left to generate report for website: {$this->websiteInfo['name']}....<br>\n");
388
			return true;
389
		}
390
 
391
		// loop through link list and save the data
392
		foreach ($linkList as $linkInfo) {
393
			$result = $reviewController->getReviewDetails($linkInfo['type'], $linkInfo['url']);
394
 
395
			if ($result['status']) {
396
				echo "Crawled review results of <b>{$linkInfo['name']}</b>.....</br>\n";
397
			} else {
398
				echo "Failed Crawling of review results of <b>{$linkInfo['name']}</b>.....</br>\n";
399
				echo $result['msg'];
400
			}
401
 
402
			// save the review data
403
			$reviewController->saveReviewLinkResults($linkInfo['id'], $result);
404
			sleep(SP_CRAWL_DELAY + 5);
405
		}
406
 
407
		echo "Saved review results of website id: <b>$websiteId</b>.....</br>\n";
408
	}
409
 
410
	# func to generate backlink reports from cron
411
	function backlinkCheckerCron($websiteId){
412
 
413
		include_once(SP_CTRLPATH."/backlink.ctrl.php");
414
		$this->debugMsg("Starting Backlink Checker cron for website: {$this->websiteInfo['name']}....<br>\n");
415
 
416
		$backlinkCtrler = New BacklinkController();
417
		$websiteInfo = $this->websiteInfo;
418
 
419
		if (SP_MULTIPLE_CRON_EXEC && $backlinkCtrler->isReportsExists($websiteInfo['id'], $this->timeStamp)) return;
420
 
421
		$backlinkCtrler->url = $websiteUrl = addHttpToUrl($websiteInfo['url']);
422
		foreach ($backlinkCtrler->colList as $col => $dbCol) {
423
			$websiteInfo[$col] = $backlinkCtrler->__getBacklinks($col);
424
		}
425
 
426
		$backlinkCtrler->saveRankResults($websiteInfo, true);
427
		echo "Saved backlink results of <b>$websiteUrl</b>.....</br>\n";
428
 
429
	}
430
 
431
	# func to generate rank reports from cron
432
	function rankCheckerCron($websiteId){
433
 
434
		include_once(SP_CTRLPATH."/rank.ctrl.php");
435
		$this->debugMsg("Starting Rank Checker cron for website: {$this->websiteInfo['name']}....<br>\n");
436
 
437
		$rankCtrler = New RankController();
438
		$websiteInfo = $this->websiteInfo;
439
 
440
		if (SP_MULTIPLE_CRON_EXEC && $rankCtrler->isReportsExists($websiteInfo['id'], $this->timeStamp)) return;
441
 
442
		$websiteUrl = addHttpToUrl($websiteInfo['url']);
443
		/*$mozRankInfo = $rankCtrler->__getMozRank(array($websiteUrl));*/
444
 
445
		$mozCtrler = new MozController();
446
		$mozRankInfo = $mozCtrler->__getMozRankInfo(array($websiteUrl));
447
 
448
		$websiteInfo['moz_rank'] = $mozRankInfo[0]['moz_rank'];
449
		$websiteInfo['page_authority'] = $mozRankInfo[0]['page_authority'];
450
		$websiteInfo['domain_authority'] = $mozRankInfo[0]['domain_authority'];
451
 
452
		$websiteInfo['alexaRank'] = $rankCtrler->__getAlexaRank($websiteUrl);
453
		$rankCtrler->saveRankResults($websiteInfo, true);
454
		$this->debugMsg("Saved rank results of <b>$websiteUrl</b>.....<br>\n");
455
 
456
	}
457
 
458
	# func to find the keyword position checker
459
	function keywordPositionCheckerCron($websiteId){
460
 
461
		include_once(SP_CTRLPATH."/searchengine.ctrl.php");
462
		include_once(SP_CTRLPATH."/report.ctrl.php");
463
 
464
		$reportController = New ReportController();
465
		$keywordCtrler = New KeywordController();
466
 
467
		$seController = New SearchEngineController();
468
		$reportController->seList = $seController->__getAllCrawlFormatedSearchEngines();
469
 
470
		// get keywords not to be checked
471
		$time = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
472
		$sql = "select distinct(keyword_id) from keywordcrontracker kc, keywords k where k.id=kc.keyword_id and k.website_id=$websiteId and time=$time";
473
		$keyList = $this->db->select($sql);
474
		$excludeKeyList = array(0);
475
		foreach ($keyList as $info) {
476
			$excludeKeyList[] = $info['keyword_id'];
477
		}
478
 
479
		// get keywords needs to be checked
480
		$sql = "select k.*,w.url from keywords k,websites w where k.website_id=w.id and w.id=$websiteId and k.status=1 and k.crawled=0";
481
		$sql .= " and k.id not in(".implode(",", $excludeKeyList).") order by k.name";
482
		$keywordList = $reportController->db->select($sql);
483
		$this->debugMsg("Starting keyword position checker cron for website: {$this->websiteInfo['name']}....<br>\n");
484
 
485
		// loop through each keyword
486
		foreach ( $keywordList as $keywordInfo ) {
487
			$reportController->seFound = 0;
488
			$crawlResult = $reportController->crawlKeyword($keywordInfo, '', true);
489
			foreach($crawlResult as $sengineId => $matchList){
490
				if($matchList['status']){
491
					foreach($matchList['matched'] as $i => $matchInfo){
492
						$remove = ($i == 0) ? true : false;
493
						$matchInfo['se_id'] = $sengineId;
494
						$matchInfo['keyword_id'] = $keywordInfo['id'];
495
 
496
						$repCtrler = New ReportController();
497
						$repCtrler->saveMatchedKeywordInfo($matchInfo, $remove);
498
					}
499
					$this->debugMsg("Successfully crawled keyword <b>{$keywordInfo['name']}</b> results from ".$reportController->seList[$sengineId]['domain'].".....<br>\n");
500
				}else{
501
					$this->debugMsg("Crawling keyword <b>{$keywordInfo['name']}</b> results from ".$reportController->seList[$sengineId]['domain']." failed......<br>\n");
502
				}
503
			}
504
 
505
			$keywordCtrler->__changeCrawledStatus(1, 'id=' . $keywordInfo['id']);
506
 
507
			// to implement split cron execution feature
508
			if ( (SP_NUMBER_KEYWORDS_CRON > 0) && !empty($crawlResult) ) {
509
			    $this->checkedKeywords++;
510
			    if ($this->checkedKeywords == SP_NUMBER_KEYWORDS_CRON) {
511
			        die("Reached total number of allowed keywords(".SP_NUMBER_KEYWORDS_CRON.") in each cron job");
512
			    }
513
			}
514
 
515
			if(empty($reportController->seFound)){
516
				$this->debugMsg("Keyword <b>{$keywordInfo['name']}</b> not assigned to required search engines........\n");
517
			}
518
			sleep(SP_CRAWL_DELAY);
519
		}
520
	}
521
 
522
	# func to generate webmaster tools reports from cron
523
	function webmasterToolsCron($websiteId){
524
 
525
		include_once(SP_CTRLPATH."/webmaster.ctrl.php");
526
		$this->debugMsg("Starting webmaster tools cron for website: {$this->websiteInfo['name']}....<br>\n");
527
 
528
		$wmCtrler = New WebMasterController();
529
		$websiteInfo = $this->websiteInfo;
530
 
531
		// check whether old reports are not generated. Then generate from it.
532
		for ($i=4; $i>=2; $i--) {
533
 
534
			// report date should be less than 2 days, then only reports will be generated
535
			$reportDate = date('Y-m-d', $this->timeStamp - ($i * 60 * 60 * 24));
536
 
537
			// loop through source list
538
			foreach ($wmCtrler->sourceList as $source) {
539
 
540
				// check whether reports already existing
541
				if (SP_MULTIPLE_CRON_EXEC && $wmCtrler->isReportsExists($websiteInfo['id'], $reportDate, $source)) {
542
					$this->debugMsg("Skip webmaster tools report($reportDate) generation of <b>{$this->websiteInfo['name']}</b>.....<br>\n");
543
					continue;
544
				}
545
 
546
				// store results
547
				$wmCtrler->storeWebsiteAnalytics($websiteInfo['id'], $reportDate, $source);
548
			}
549
 
550
			$this->debugMsg("Saved webmaster tools report($reportDate) of <b>{$this->websiteInfo['name']}</b>.....<br>\n");
551
		}
552
 
553
		// update webmaster tools sitemaps
554
		$websiteController = New WebsiteController();
555
		$websiteController->importWebmasterToolsSitemaps($websiteId, true);
556
		$this->debugMsg("Saved webmaster tools sitemaps of <b>{$this->websiteInfo['name']}</b>.....<br>\n");
557
 
558
	}
559
 
560
	// func to generate analytics reports from cron
561
	function analyticsCron($websiteId){
562
 
563
		include_once(SP_CTRLPATH."/analytics.ctrl.php");
564
		$this->debugMsg("Starting analytics cron for website: {$this->websiteInfo['name']}....<br>\n");
565
 
566
		$wmCtrler = New AnalyticsController();
567
		$websiteInfo = $this->websiteInfo;
568
		$reportDate = date('Y-m-d', $this->timeStamp - (60 * 60 * 24));
569
 
570
		// check whether reports already existing
571
		if (SP_MULTIPLE_CRON_EXEC && $wmCtrler->isReportsExists($websiteInfo['id'], $reportDate)) {
572
		    $this->debugMsg("Analytics results already generated of <b>{$this->websiteInfo['name']}</b>.....<br>\n");
573
		    return FALSE;
574
		}
575
 
576
		// store results
577
		$wmCtrler->storeWebsiteAnalytics($websiteInfo['id'], $reportDate);
578
		$this->debugMsg("Saved analytics results of <b>{$this->websiteInfo['name']}</b>.....<br>\n");
579
	}
580
 
581
	// func to show debug messages
582
	function debugMsg($msg='') {
583
		if($this->debug == true) print $msg;
584
	}
585
 
586
}
587
?>