Subversion Repositories cheapmusic

Rev

Rev 103 | Details | Compare with Previous | 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.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 directory controller functions
24
class DirectoryController extends Controller{
25
	var $noTitles = 5; 			  # no of titles and description for submission
26
	var $capchaFile = "captcha";  # captcha file name
27
	var $checkPR = 0;
28
 
29
	function showSubmissionPage( ) {
30
 
31
		$userId = isLoggedIn();
32
		$this->session->setSession('dirsub_pr', '');
33
 
34
		$websiteController = New WebsiteController();
35
		$this->set('websiteList', $websiteController->__getAllWebsites($userId, true));
36
 
37
		$langCtrler = New LanguageController();
38
		$langList = $langCtrler->__getAllLanguages();
39
		$this->set('langList', $langList);
40
 
155 - 41
		$this->render('directory/showsubmission');
103 - 42
	}
43
 
44
	function __getDirectoryInfo($dirId){
45
		$sql = "select * from directories where id=$dirId";
46
		$listInfo = $this->db->select($sql, true);
47
		return empty($listInfo['id']) ? false :  $listInfo;
48
	}
49
 
50
	function showWebsiteSubmissionPage($submitInfo, $error=false) {
51
 
52
		if(empty($submitInfo['website_id'])) {
53
			showErrorMsg($this->spTextDir['Please select a website to proceed']."!");
54
		}
55
 
56
		# check whether the sitemap directory is writable
57
 		if(!is_writable(SP_TMPPATH ."/".$this->sitemapDir)){
58
 			showErrorMsg("Directory '<b>".SP_TMPPATH."</b>' is not <b>writable</b>. Please change its <b>permission</b> !");
59
 		}
60
 
61
		if(empty($error)){
62
			$websiteController = New WebsiteController();
63
			$websiteInfo = $websiteController->__getWebsiteInfo($submitInfo['website_id']);
64
			$websiteInfo['website_id'] = $submitInfo['website_id'];
65
		}else{
66
			$websiteInfo = $submitInfo;
67
		}
68
 
69
		$this->set('websiteInfo', $websiteInfo);
70
		$this->session->setSession('no_captcha', empty($submitInfo['no_captcha']) ? 0 : 1);
71
		$this->session->setSession('dirsub_pr', $submitInfo['pagerank']);
72
		$this->session->setSession('dirsub_lang', $submitInfo['lang_code']);
73
		$this->set('noTitles', $this->noTitles);
155 - 74
		$this->render('directory/showsitesubmission');
103 - 75
	}
76
 
77
	function saveSubmissiondata( $submitInfo ) {
78
 
79
		$submitInfo['website_id']= intval($submitInfo['website_id']);
80
		if(empty($submitInfo['website_id'])) {
81
			showErrorMsg("Please select a website to proceed!");
82
		}
83
 
84
		$_SESSION['skipped'][$submitInfo['website_id']] = array();
85
 
86
		if(!SP_DEMO){
87
			$errMsg['url'] = formatErrorMsg($this->validate->checkBlank($submitInfo['url']));
88
			$errMsg['owner_name'] = formatErrorMsg($this->validate->checkBlank($submitInfo['owner_name']));
89
			$errMsg['category'] = formatErrorMsg($this->validate->checkBlank($submitInfo['category']));
90
			$errMsg['title'] = formatErrorMsg($this->validate->checkBlank($submitInfo['title']));
91
			$errMsg['description'] = formatErrorMsg($this->validate->checkBlank($submitInfo['description']));
92
			$errMsg['keywords'] = formatErrorMsg($this->validate->checkBlank($submitInfo['keywords']));
93
			$errMsg['owner_email'] = formatErrorMsg($this->validate->checkEmail($submitInfo['owner_email']));
94
 
95
			# error occurs
96
			if($this->validate->flagErr){
97
				$this->set('errMsg', $errMsg);
98
				$submitInfo['sec'] = '';
99
				$this->showWebsiteSubmissionPage($submitInfo, true);
100
				return;
101
			}
102
 
103
			$submitInfo['url'] = addHttpToUrl($submitInfo['url']);
104
			$recUrl = formatUrl($submitInfo['reciprocal_url']);
105
			$submitInfo['reciprocal_url'] = empty($recUrl) ? "" : addHttpToUrl($submitInfo['reciprocal_url']);
106
 
107
			$sql = "update websites set " .
108
					"url='".addslashes($submitInfo['url'])."'," .
109
					"owner_name='".addslashes($submitInfo['owner_name'])."'," .
110
					"owner_email='".addslashes($submitInfo['owner_email'])."'," .
111
					"category='".addslashes($submitInfo['category'])."'," .
112
			        "reciprocal_url='".addslashes($submitInfo['reciprocal_url'])."'," .
113
					"title='".addslashes($submitInfo['title'])."'," .
114
					"description='".addslashes($submitInfo['description'])."',";
115
			for($i=2;$i<=$this->noTitles;$i++){
116
				$sql .= "title$i='".addslashes($submitInfo['title'.$i])."'," .
117
					"description$i='".addslashes($submitInfo['description'.$i])."',";
118
			}
119
			$sql .=	"keywords='".addslashes($submitInfo['keywords'])."' " .
120
					"where id={$submitInfo['website_id']}";
121
			$this->db->query($sql);
122
		}
123
		$this->startSubmission($submitInfo['website_id']);
155 - 124
 
103 - 125
	}
126
 
127
	function isCategoryExists($page,$categoryCol) {
128
		$matches = array();
129
		$pattern1 = '/<select name="'.$categoryCol.'".*?<\/select>/is';
130
		$pattern2 = '/<select.*?'.$categoryCol.'.*?<\/select>/is';
131
		$pattern3 = '/<select.*?'.$categoryCol.'.*<\/select>/is';
132
		$matched = 0;
133
		if($matched = preg_match($pattern1, $page, $matches)){
134
		}elseif($matched = preg_match($pattern2, $page, $matches)){
135
		}elseif($matched = preg_match($pattern3, $page, $matches)){
136
		}
137
 
138
		return $matches;
139
	}
140
 
141
	# func to create captcha image in system
142
	function __getCreatedCaptchaUrl($captchaUrl, $submitUrl, $phpsessid){
143
		$captchaUrlInfo = ['url' => $captchaUrl, 'code' => ''];
144
 
145
		$spider = new Spider();
146
		$spider->_CURLOPT_REFERER = $submitUrl;
147
		$spider->_CURLOPT_TIMEOUT = 30;
148
 
149
		if(!empty($phpsessid)){
150
			$spider->_CURLOPT_COOKIE = 'PHPSESSID=' . $phpsessid . '; path=/';
151
		}
152
 
153
		$ret = $spider->getContent($captchaUrl);
154
 
155
		if(!empty($ret['page'])){
156
			$captchaFile = $this->capchaFile .isLoggedIn() . ".jpg";
157
			$fp = fopen(SP_TMPPATH."/".$captchaFile, 'w');
158
			fwrite($fp, $ret['page']);
159
			fclose($fp);
160
			$captchaUrl = SP_WEBPATH. "/tmp/" .$captchaFile ."?rand=".mktime();
161
			$captchaUrlInfo['url'] = $captchaUrl;
162
 
163
			// check for captcha bypass plugin enabled or not
164
			if (isPluginActivated("CaptchaBypass")) {
165
				$seopluginCtrler = new SeoPluginsController();
166
				$pluginCtrler = $seopluginCtrler->createPluginObject("CaptchaBypass");
167
				$captchaUrlInfo['code'] = $pluginCtrler->solveCaptchaImage(['img_path' => SP_TMPPATH."/".$captchaFile]);
168
			}
169
 
170
		}
171
 
172
		return $captchaUrlInfo;
173
	}
174
 
175
	# func to show submission page
176
	function startSubmission( $websiteId, $dirId='' ) {
177
		$dirId = intval($dirId);
178
		$websiteId = intval($websiteId);
179
 
180
		$websiteController = New WebsiteController();
181
		$websiteInfo = $websiteController->__getWebsiteInfo($websiteId);
182
		$this->set('websiteId', $websiteId);
183
 
184
		// submission count validation
185
		$this->validateDirectorySubmissionCount($websiteInfo['user_id']);
186
 
187
		# get list of already submitted directories
188
		$sql = "select directory_id from dirsubmitinfo where website_id=$websiteId";
189
		$list = $this->db->select($sql);
190
		$dirList = array();
191
		foreach($list as $listInfo){
192
			$dirList[] = $listInfo['directory_id'];
193
		}
194
 
195
		# to get skipped directories
196
		$skipDirList = $this->__getAllSkippedDir($websiteId);
197
		if( count($skipDirList) > 0){
198
			$dirList = array_merge($dirList, $skipDirList);
199
		}
200
 
201
		$sql = "select * from directories where working=1";
202
		if(!empty($_SESSION['no_captcha'])) $sql .= " and is_captcha=0";
203
 
204
		// check for page rank
205
		if(!empty($_SESSION['dirsub_pr'])) {
206
			$prMax = intval($_SESSION['dirsub_pr']) + 0.5;
207
			$prMin = intval($_SESSION['dirsub_pr']) - 0.5;
208
			$sql .= " and pagerank<$prMax and pagerank>=$prMin";
209
		}
210
 
211
		if(!empty($_SESSION['dirsub_lang'])) $sql .= " and lang_code='{$_SESSION['dirsub_lang']}'";
212
 
213
		// if reciprocal directory needs to be filtered
214
		if(!empty($_SESSION['no_reciprocal'])) {
215
			$sql .= " and extra_val not like '%LINK_TYPE=reciprocal%' and is_reciprocal=0";
216
		}
217
 
218
		if(!empty($dirId)) $sql .= " and id=$dirId";
219
		if(count($dirList) > 0) $sql .= " and id not in (".implode(',', $dirList).")";
155 - 220
		$sql .= " order by `rank` DESC, extra_val ASC, id ASC";
103 - 221
		$dirInfo = $this->db->select($sql, true);
222
		$this->set('dirInfo', $dirInfo);
223
 
224
		# directory list is empty
225
		if(empty($dirInfo['id'])) {
226
			showErrorMsg($this->spTextDir['nodirnote'].". Please <a href='".SP_CONTACT_LINK."' target='_blank'>Contact</a> <b>Seo Panel Team</b> to get more <b>directories</b>.");
227
		}
228
 
229
		$spider = new Spider();
230
		$spider->_CURLOPT_HEADER = 1;
231
		$ret = $spider->getContent(addHttpToUrl($dirInfo['submit_url']));
232
 
233
		if($ret['error']){
234
			$this->set('error', 1);
235
			$this->set('msg', $ret['errmsg']);
236
		}
237
 
238
		$page = $ret['page'];
239
		if(!empty($page)){
240
			$matches = $this->isCategoryExists($page, $dirInfo['category_col']);
241
		}
242
 
243
		# if category exists proceed submission
244
		if(!empty($matches[0])){
245
 
246
			$categorysel = $matches[0];
247
			$this->set('catSelectStr', $websiteInfo['category']);
248
 
249
			// replaced with jquery script
250
			/*$catList = explode(',', $websiteInfo['category']);
251
			if(count($catList) > 0){
252
				foreach($catList as $category){
253
					$category = trim($category);
254
					$categorysel = preg_replace("/<(option.*?$category.*?)>/si", '<$1 selected>', $categorysel, 1, $count);
255
					if($count > 0) break;
256
				}
257
 
258
				if($count <= 0){
259
					$categorysel = $matches[0];
260
				}
261
			}*/
262
 
263
			$categorysel = str_replace("ADD_CATEGORY_ID[]", $dirInfo['category_col'], $categorysel);
264
			$this->set('categorySel', $categorysel);
265
 
266
			$captchaUrl = '';
267
			if(stristr($page, $dirInfo['captcha_script'])){
268
				$captchaUrl = $dirInfo['captcha_script'];
269
			}
270
 
271
			$imageHash = $addParams = "";
272
			if(preg_match('/name="'.$dirInfo['imagehash_col'].'".*?value="(.*?)"/is', $page, $hashMatch)){
273
				$imageHash = $hashMatch[1];
274
			}
275
			$this->set('imageHash', $imageHash);
276
			$phpsessid = $spider->getSessionId($page);
277
			$this->set('phpsessid', $phpsessid);
278
 
279
			if(!empty($captchaUrl)){
280
				$captchaUrl = preg_replace('/^\//', '', $captchaUrl);
281
				$dirInfo['domain'] = addHttpToUrl($dirInfo['domain']);
282
				if(preg_match('/\/$/', $dirInfo['domain'])){
283
					$captchaUrl = $dirInfo['domain']. $captchaUrl;
284
				} else {
285
					$captchaUrl =  $dirInfo['domain']."/". $captchaUrl;
286
				}
287
 
288
				if(!stristr($captchaUrl, '?')){
289
					if(!empty($imageHash)) {
290
						$captchaUrl .= "?".$dirInfo['imagehashurl_col']."=".$imageHash;
291
					}else $captchaUrl .= "?rand=".rand(1,1000);
292
				}else{
293
					if(!empty($imageHash)) {
294
						$captchaUrl .= "&".$dirInfo['imagehashurl_col']."=".$imageHash;
295
					}else $captchaUrl .= "&rand=".rand(1,1000);
296
				}
297
 
298
				# to get stored image path if hot linking is prevented
299
				$captchaUrlInfo = $this->__getCreatedCaptchaUrl($captchaUrl, $dirInfo['submit_url'], $phpsessid);
300
				$captchaUrl = $captchaUrlInfo['url'];
301
 
302
			} else {
303
 
304
				// check for number question existing there
305
				if (preg_match('/(\d+) \+ (\d+) =/is', $page, $numMatch)) {
306
					$sumMath = intval($numMatch[1]) + intval($numMatch[2]);
307
					$addParams = "&DO_MATH=$sumMath&Anti_Spam_Field=$sumMath";
308
				}
309
 
310
				if (isPluginActivated("CaptchaBypass")) {
311
					$seopluginCtrler = new SeoPluginsController();
312
					$pluginCtrler = $seopluginCtrler->createPluginObject("CaptchaBypass");
313
				}
314
 
315
			}
316
 
317
			$this->set('captchaCode', !empty($captchaUrlInfo['code']) ? $captchaUrlInfo['code'] : "");
318
			$this->set('captchaUrl', $captchaUrl);
319
			$this->set('addParams', $addParams);
320
 
321
			// function check whether recriprocal directory
322
			$scriptInfo = $this->getDirectoryScriptMetaInfo($dirInfo['script_type_id']);
323
			$checkArg = $scriptInfo['link_type_col']."=".$scriptInfo['reciprocal'];
324
			$reciprocalUrl = '';
325
			$reciprocalDir = false;
326
			if (!empty($dirInfo['is_reciprocal']) || stristr($dirInfo['extra_val'], $checkArg)) {
327
				$reciprocalDir = true;
328
                $reciprocalUrl =  $websiteInfo['reciprocal_url'];
329
                if (empty($reciprocalUrl)) {
330
                    if (preg_match("/&{$scriptInfo['reciprocal_col']}=(.*)/", $dirInfo['extra_val'], $matches)) {
331
                        if (!empty($matches[1])) $reciprocalUrl = $matches[1];
332
                    }
333
                }
334
			}
335
 
336
			$this->set('reciprocalDir', $reciprocalDir);
337
			$this->set('reciprocalUrl', $reciprocalUrl);
338
 
339
		}else{
340
			$this->set('error', 1);
341
			$this->set('msg', $this->spTextDir['nocatnote']);
342
		}
343
 
155 - 344
		$this->render('directory/showsubmissionform');
103 - 345
	}
346
 
347
	# to get random title and description for submisiion
348
	function __getSubmitTitleDes($websiteInfo){
349
		$titleList = array();
350
 
351
		$titleList[0]['title'] = $websiteInfo['title'];
352
		$titleList[0]['description'] = $websiteInfo['description'];
353
		for($i=2;$i<=$this->noTitles;$i++){
354
			$titleInfo = array();
355
			if(!empty($websiteInfo['title'.$i]) && !empty($websiteInfo['description'.$i])){
356
				$titleInfo['title'] = $websiteInfo['title'.$i];
357
				$titleInfo['description'] = $websiteInfo['description'.$i];
358
				$titleList[] = $titleInfo;
359
			}
360
		}
361
		if($index = array_rand($titleList, 1)){
362
			$websiteInfo['title'] = $titleList[$index]['title'];
363
			$websiteInfo['description'] = $titleList[$index]['description'];
364
		}
365
 
366
		return $websiteInfo;
367
	}
368
 
369
	# submitting site directory
370
	function submitSite( $submitInfo ) {
371
 
372
		$submitInfo['dir_id'] = intval($submitInfo['dir_id']);
373
		$submitInfo['website_id'] = intval($submitInfo['website_id']);
374
		$dirInfo = $this->__getDirectoryInfo($submitInfo['dir_id']);
375
 
376
		$websiteController = New WebsiteController();
377
		$websiteInfo = $websiteController->__getWebsiteInfo($submitInfo['website_id']);
378
		$websiteInfo = $this->__getSubmitTitleDes($websiteInfo);
379
 
380
		$postData = $dirInfo['title_col']."=".$websiteInfo['title'];
381
		$postData .= "&".$dirInfo['url_col']."=".$websiteInfo['url'];
382
		$postData .= "&".$dirInfo['description_col']."=".$websiteInfo['description'];
383
		$postData .= "&".$dirInfo['name_col']."=".$websiteInfo['owner_name'];
384
		$postData .= "&".$dirInfo['email_col']."=".$websiteInfo['owner_email'];
385
		$postData .= "&".$dirInfo['category_col']."=".$submitInfo[$dirInfo['category_col']];
386
		$postData .= "&".$dirInfo['cptcha_col']."=".$submitInfo[$dirInfo['cptcha_col']];
387
		$postData .= $submitInfo['add_params'];
388
 
389
		// check image hash there
390
		if(!empty($submitInfo[$dirInfo['imagehash_col']])){
391
			$postData .= "&".$dirInfo['imagehash_col']."=".$submitInfo[$dirInfo['imagehash_col']];
392
		}
393
 
394
		// check for reciprocal link
395
		$scriptInfo = $this->getDirectoryScriptMetaInfo($dirInfo['script_type_id']);
396
		if (!empty($submitInfo['reciprocal_url'])) {
397
 
398
		    // if extra values contain the reciprocal col name
399
			$reciprocalUrl = addHttpToUrl($submitInfo['reciprocal_url']);
400
		    if (stristr($dirInfo['extra_val'], $scriptInfo['reciprocal_col'])) {
401
		    	$dirInfo['extra_val'] = preg_replace("/&{$scriptInfo['reciprocal_col']}=(.*)/", "&{$scriptInfo['reciprocal_col']}=$reciprocalUrl", $dirInfo['extra_val']);
402
		    } else {
403
		    	$postData .= "&".$dirInfo['reciprocal_col']."=$reciprocalUrl";
404
		    }
405
 
406
		}
407
 
408
		$postData .= "&".$dirInfo['extra_val'];
409
 
410
		// check phpLD directory. Then add extra values
411
		if ($scriptInfo['name'] == 'phpLD') {
412
			$postData .= "&OWNER_NEWSLETTER_ALLOW=on&META_KEYWORDS={$websiteInfo['keywords']}
413
			&META_DESCRIPTION=" . substr($websiteInfo['description'], 0, 249) . "&META_DESCRIPTION_limit=250&formSubmitted=1";
414
		}
415
 
416
		$spider = new Spider();
417
		$spider->_CURLOPT_POSTFIELDS = $postData;
418
		$spider->_CURLOPT_REFERER = $dirInfo['submit_url'];
419
		if(!empty($submitInfo['phpsessid'])){
420
			$spider->_CURLOPT_COOKIE = 'PHPSESSID=' . $submitInfo['phpsessid'] . '; path=/';
421
		}
422
		$ret = $spider->getContent($dirInfo['submit_url']);
423
 
424
		if($ret['error']){
425
			$this->set('error', 1);
426
			$this->set('msg', $ret['errmsg']);
427
		}else{
428
 
429
			$page = $ret['page'];
430
 
431
			if(SP_DEBUG) $this->logSubmissionResult($page, $submitInfo['dir_id'], $submitInfo['website_id']);
432
 
433
			// check success messages
434
			if (preg_match('/<td.*?class="msg".*?>(.*?)<\/td>/is', $page, $matches)) {
435
			} elseif (preg_match('/<p.*?class="box success".*?>(.*?)<\/p>/is', $page, $matches)) {
436
			} else{
437
				$status = 0;
438
				$this->set('msg', $this->spTextDir['nosuccessnote']);
439
			}
440
 
441
			// if $matches[1] is not empty
442
			if (!empty($matches[1])) {
443
				$this->set('msg', $matches[1]);
444
				$status = 1;
445
 
446
				// to update the rank of directory
155 - 447
				$sql = "update directories set `rank`=`rank`+1 where id=".$submitInfo['dir_id'];
103 - 448
				$this->db->query($sql);
449
			}
450
 
451
 
452
			$sql = "select id from dirsubmitinfo where website_id={$submitInfo['website_id']} and directory_id={$submitInfo['dir_id']}";
453
			$subInfo = $this->db->select($sql);
454
			if(empty($subInfo[0][id])){
455
				$sql = "insert into dirsubmitinfo(website_id,directory_id,status,submit_time) values({$submitInfo['website_id']}, {$submitInfo['dir_id']}, $status,".mktime().")";
456
			}else{
457
				$sql = "update dirsubmitinfo set status=$status,submit_time=".mktime()." where id={$subInfo[0][id]}";
458
			}
459
			$this->db->query($sql);
460
		}
461
		$this->render('directory/showsubmissionstats');
462
 
463
		$this->set('error', 0);
464
		$this->set('msg', '');
465
 
155 - 466
		$this->startSubmission($submitInfo['website_id']);
103 - 467
	}
468
 
469
	# to skip submission
470
	function skipSubmission( $info ) {
471
 
472
		$info['website_id'] = intval($info['website_id']);
473
		$info['dir_id'] = intval($info['dir_id']);
474
		$sql = "Insert into skipdirectories(website_id,directory_id) values({$info['website_id']}, {$info['dir_id']})";
475
		$this->db->query($sql);
155 - 476
		$this->startSubmission($info['website_id']);
103 - 477
	}
478
 
479
	# to unskip submission
480
	function unSkipSubmission( $skipId ) {
481
 
482
		$skipId = intval($skipId);
483
		$sql = "delete from skipdirectories where id=$skipId";
484
		$this->db->query($sql);
485
	}
486
 
487
	# to get all skipped directories
488
	function __getAllSkippedDir($websiteId){
489
 
490
		$websiteId = intval($websiteId);
491
		$dirList = array();
492
		$sql = "select directory_id from skipdirectories where website_id=$websiteId";
493
		$list = $this->db->select($sql);
494
		if(count($list) > 0){
495
			foreach($list as $listInfo){
496
				$dirList[] = $listInfo['directory_id'];
497
			}
498
		}
499
 
500
		return $dirList;
501
	}
502
 
503
	# func to show Skipped Directories
504
	function showSkippedDirectories($searchInfo=''){
505
 
506
		$userId = isLoggedIn();
507
		$websiteController = New WebsiteController();
508
		$websiteList = $websiteController->__getAllWebsites($userId, true);
509
		$this->set('websiteList', $websiteList);
510
		$websiteId = empty ($searchInfo['website_id']) ? $websiteList[0]['id'] : intval($searchInfo['website_id']);
511
		$this->set('websiteId', $websiteId);
512
		$this->set('onChange', "scriptDoLoadPost('directories.php', 'search_form', 'content', '&sec=skipped')");
513
 
514
		$conditions = empty ($websiteId) ? "" : " and ds.website_id=$websiteId";
515
		$pageScriptPath = 'directories.php?sec=skipped&website_id='.$websiteId;
516
		$this->set('searchInfo', $searchInfo);
517
 
518
		// search for name
519
		if (!empty($searchInfo['search_name'])) {
520
			$conditions .= " and d.submit_url like '%".addslashes($searchInfo['search_name'])."%'";
521
			$pageScriptPath .= "&search_name=" . $searchInfo['search_name'];
522
		}
523
 
524
		$sql = "select ds.* ,d.domain,d.pagerank, d.submit_url
525
		from skipdirectories ds,directories d where ds.directory_id=d.id $conditions order by id desc,d.domain";
526
 
527
		# pagination setup
528
		$this->db->query($sql, true);
529
		$this->paging->setDivClass('pagingdiv');
530
		$this->paging->loadPaging($this->db->noRows, SP_PAGINGNO);
531
		$pagingDiv = $this->paging->printPages($pageScriptPath, '', 'scriptDoLoad', 'content');
532
		$this->set('pagingDiv', $pagingDiv);
533
		$sql .= " limit ".$this->paging->start .",". $this->paging->per_page;
534
 
535
		$reportList = $this->db->select($sql);
536
 
537
		$this->set('list', $reportList);
538
		$this->set('pageNo', $_GET['pageno']);
539
		$this->set('websiteId', $websiteId);
540
		$this->render('directory/skippeddirs');
541
	}
542
 
543
	# func to show submision reports
544
	function showSubmissionReports($searchInfo=''){
545
 
546
		$userId = isLoggedIn();
547
		$websiteController = New WebsiteController();
548
		$websiteList = $websiteController->__getAllWebsites($userId, true);
549
		$this->set('websiteList', $websiteList);
550
		$websiteId = empty ($searchInfo['website_id']) ? $websiteList[0]['id'] : intval($searchInfo['website_id']);
551
		$this->set('websiteId', $websiteId);
552
		$this->set('onChange', "scriptDoLoadPost('directories.php', 'search_form', 'content', '&sec=reports')");
553
 
554
		$conditions = empty ($websiteId) ? "" : " and ds.website_id=$websiteId";
555
		$conditions .= empty ($searchInfo['active']) ? "" : " and ds.active=".($searchInfo['active']=='pending' ? 0 : 1);
556
 
557
		$pageScriptPath = 'directories.php?sec=reports&website_id='.$websiteId.'&active='.$searchInfo['active'];
558
		$this->set('searchInfo', $searchInfo);
559
 
560
		// search for name
561
		if (!empty($searchInfo['search_name'])) {
562
			$conditions .= " and d.submit_url like '%".addslashes($searchInfo['search_name'])."%'";
563
			$pageScriptPath .= "&search_name=" . $searchInfo['search_name'];
564
		}
565
 
566
		$sql = "select ds.* ,d.domain,d.pagerank, d.submit_url from dirsubmitinfo ds,directories d
567
		where ds.directory_id=d.id $conditions order by submit_time desc,d.domain";
568
 
569
		# pagination setup
570
		$this->db->query($sql, true);
571
		$this->paging->setDivClass('pagingdiv');
572
		$this->paging->loadPaging($this->db->noRows, SP_PAGINGNO);
573
		$pagingDiv = $this->paging->printPages($pageScriptPath, '', 'scriptDoLoad', 'content');
574
		$this->set('pagingDiv', $pagingDiv);
575
		$sql .= " limit ".$this->paging->start .",". $this->paging->per_page;
576
 
577
		$reportList = $this->db->select($sql);
578
		$this->set('pageScriptPath', $pageScriptPath);
579
		$this->set('pageNo', $_GET['pageno']);
580
		$this->set('activeVal', $searchInfo['active']);
581
		$this->set('list', $reportList);
582
		$this->render('directory/directoryreport');
583
	}
584
 
585
	function changeConfirmStatus($dirInfo){
586
 
587
		$dirInfo['id'] = intval($dirInfo['id']);
588
		$status = ($dirInfo['confirm']=='Yes') ? 0 : 1;
589
		$sql = "Update dirsubmitinfo set status=$status where id=".$dirInfo['id'];
590
		$this->db->query($sql);
591
	}
592
 
593
	function showConfirmStatus($id){
594
 
595
		$id = intval($id);
596
		$sql = "select status from dirsubmitinfo where id=".$id;
597
		$statusInfo = $this->db->select($sql, true);
598
 
599
		$confirm = empty($statusInfo['status']) ? "No" : "Yes";
600
        $confirmId = "confirm_".$id;
601
        $confirmLink = "<a href='javascript:void(0);' onclick=\"scriptDoLoad('directories.php', '$confirmId', 'sec=changeconfirm&id=$id&confirm=$confirm')\">$confirm</a>";
602
 
603
        print $confirmLink;
604
	}
605
 
606
	function checkSubmissionStatus($dirInfo){
607
 
608
		$dirInfo['id'] = intval($dirInfo['id']);
609
		$sql = "select ds.* ,d.domain,d.search_script,w.url
610
					from dirsubmitinfo ds,directories d,websites w
611
					where ds.directory_id=d.id and ds.website_id=w.id
612
					and ds.id=". $dirInfo['id'];
613
		$statusInfo = $this->db->select($sql, true);
614
 
615
		$searchUrl = (preg_match('/\/$/', $statusInfo['domain'])) ? $statusInfo['domain'].$statusInfo['search_script'] : $statusInfo['domain']."/".$statusInfo['search_script'];
616
		$keyword = formatUrl($statusInfo['url']);
617
		$searchUrl = str_replace('[--keyword--]', urlencode($keyword), $searchUrl);
618
 
619
		$ret = $this->spider->getContent($searchUrl);
620
		if(empty($ret['error'])){
621
			if(stristr($ret['page'], 'href="'.$statusInfo['url'].'"')){
622
				return 1;
623
			}elseif(stristr($ret['page'], "href='".$statusInfo['url']."'")){
624
				return 1;
625
			}elseif(stristr($ret['page'], 'href='.$statusInfo['url'])){
626
				return 1;
627
			}
628
		}
629
		return 0;
630
	}
631
 
632
	function updateSubmissionStatus($dirId, $status){
633
		$status = intval($status);
634
		$dirId = intval($dirId);
635
		$sql = "Update dirsubmitinfo set active=$status where id=".$dirId;
636
		$this->db->query($sql);
637
	}
638
 
639
	function showSubmissionStatus($id){
640
 
641
		$id = intval($id);
642
		$sql = "select active from dirsubmitinfo where id=".$id;
643
		$statusInfo = $this->db->select($sql, true);
644
 
645
        print empty($statusInfo['active']) ? $this->spTextDir["Pending"] : $this->spTextDir["Approved"];
646
	}
647
 
648
	function checkSubmissionReports( $searchInfo ) {
649
 
650
		$userId = isLoggedIn();
651
		$websiteController = New WebsiteController();
652
		$this->set('websiteList', $websiteController->__getAllWebsites($userId, true));
653
		$this->set('websiteNull', true);
654
		$this->set('onClick', "scriptDoLoadPost('directories.php', 'search_form', 'subcontent', '&sec=checksub')");
655
 
656
		$this->render('directory/checksubmission');
657
	}
658
 
659
	function generateSubmissionReports( $searchInfo ){
660
 
661
		$searchInfo['website_id'] = intval($searchInfo['website_id']);
662
		if(empty($searchInfo['website_id'])) {
663
			echo "<script>scriptDoLoad('directories.php', 'content', 'sec=checksub');</script>";
664
			return;
665
		}
666
 
667
		$sql = "select ds.* ,d.domain
668
								from dirsubmitinfo ds,directories d
669
								where ds.directory_id=d.id
670
								and ds.website_id={$searchInfo['website_id']} and ds.active=0
671
								order by submit_time";
672
		$reportList = $this->db->select($sql);
673
		$this->set('list', $reportList);
674
		$this->render('directory/generatesubmission');
675
	}
676
 
677
	function deleteSubmissionReports($dirSubId){
678
 
679
		$dirSubId = intval($dirSubId);
680
		$sql = "delete from dirsubmitinfo where id=$dirSubId";
681
		$this->db->query($sql);
682
 
683
		echo "<script>scriptDoLoadPost('directories.php', 'search_form', 'content', '&sec=reports');</script>";
684
	}
685
 
686
	# function to show featured directories
687
	function showFeaturedSubmission($info="") {
688
	    $dirList = $this->getAllFeaturedDirectories();
689
	    $this->set('list', $dirList);
155 - 690
		$this->render('directory/featuredsubmission');
103 - 691
	}
692
 
693
	# function to get all features directories
694
    function getAllFeaturedDirectories() {
695
		$sql = "SELECT * FROM featured_directories where status=1 order by  google_pagerank DESC";
696
		$list = $this->db->select($sql);
697
		$dirList = array();
698
		foreach ($list as $listInfo) {
699
		    $dirList[$listInfo['id']] = $listInfo;
700
		}
701
		return $dirList;
702
	}
703
 
704
	# func to get all directories
705
	function getAllDirectories($searchInfo=array()) {
706
		$sql = "SELECT * FROM directories ";
707
		$i = 0;
708
		foreach($searchInfo as $col => $value){
709
			$and = ($i++) ? "and" : "where";
710
			$sql .= " $and $col='$value'";
711
		}
712
		$sql .= "order by id";
713
		$dirList = $this->db->select($sql);
714
 
715
		return $dirList;
716
	}
717
 
718
	# func to get dir info
719
	function getDirectoryInfo($dirId) {
720
 
721
		$dirId = intval($dirId);
722
		$sql = "SELECT * FROM directories where id=$dirId";
723
		$dirInfo = $this->db->select($sql, true);
724
		return $dirInfo;
725
	}
726
 
727
	# func to show directory manager
728
	function showDirectoryManager($info=''){
729
		$info = sanitizeData($info);
730
		$info['stscheck'] = isset($info['stscheck']) ? intval($info['stscheck']) : 1;
731
		$capcheck = isset($info['capcheck']) ? (($info['capcheck'] == 'yes') ? 1 : 0 ) : "";
732
		$sql = "SELECT *,l.lang_name FROM directories d,languages l where d.lang_code=l.lang_code and working='{$info['stscheck']}'";
733
		if(!empty($info['dir_name'])) $sql .= " and domain like '%".addslashes($info['dir_name'])."%'";
734
		if($info['capcheck'] != '') $sql .= " and is_captcha='$capcheck'";
735
 
736
		// check for page rank
737
		if(isset($info['pagerank']) && ($info['pagerank'] != '')) {
738
			$prMax = intval($info['pagerank']) + 0.5;
739
			$prMin = intval($info['pagerank']) - 0.5;
740
			$sql .= " and pagerank<$prMax and pagerank>=$prMin";
741
		}
742
 
743
		if (!empty($info['langcode'])) { $info['lang_code'] = $info['langcode']; }
744
		if(!empty($info['lang_code'])) $sql .= " and d.lang_code='".addslashes($info['lang_code'])."'";
745
		$sql .= " order by id";
746
 
747
		# pagination setup
748
		$this->db->query($sql, true);
749
		$this->paging->setDivClass('pagingdiv');
750
		$this->paging->loadPaging($this->db->noRows, SP_PAGINGNO);
751
		$pageScriptPath = 'directories.php?sec=directorymgr&dir_name='.urlencode($info['dir_name'])."&stscheck={$info['stscheck']}&capcheck=".$info['capcheck'];
752
		$pageScriptPath .= "&pagerank=".$info['pagerank']."&langcode=".$info['lang_code'];
753
		$pagingDiv = $this->paging->printPages($pageScriptPath);
754
		$this->set('pagingDiv', $pagingDiv);
755
		$sql .= " limit ".$this->paging->start .",". $this->paging->per_page;
756
 
757
		$statusList = array(
758
			$_SESSION['text']['common']['Active'] => 1,
759
			$_SESSION['text']['common']['Inactive'] => 0,
760
		);
761
		$captchaList = array(
762
			$_SESSION['text']['common']['Yes'] => 'yes',
763
			$_SESSION['text']['common']['No'] => 'no',
764
		);
765
 
766
		$langCtrler = New LanguageController();
767
		$langList = $langCtrler->__getAllLanguages();
768
		$this->set('langList', $langList);
769
 
770
		$this->set('statusList', $statusList);
771
		$this->set('captchaList', $captchaList);
772
		$dirList = $this->db->select($sql);
773
		$this->set('list', $dirList);
774
		$this->set('info', $info);
775
		$this->set('ctrler', $this);
776
		$this->render('directory/list');
777
	}
778
 
779
	# func to change status of directory
780
	function changeStatusDirectory($dirId, $status, $printLink=false){
781
 
782
	    $status = intval($status);
783
		$dirId = intval($dirId);
784
		$sql = "update directories set working=$status where id=$dirId";
785
		$this->db->query($sql);
786
 
787
		if($printLink){
788
			echo $this->getStatusLink($dirId, $status);
789
		}
790
	}
791
 
792
	# func to show directory check interface
793
	function showCheckDirectory() {
794
 
795
		$this->render('directory/showcheckdir');
796
	}
797
 
798
	# function to start directory check
799
	function startDirectoryCheckStatus($info=''){
800
 
801
		$searchInfo = array();
802
		if(isset($info['stscheck']) && ($info['stscheck'] != '')){
803
			$searchInfo = array(
804
				'working' => intval($info['stscheck']),
805
			);
806
		}
807
 
808
		$dirList = $this->getAllDirectories($searchInfo);
809
 
810
		$this->set('dirList', $dirList);
811
		$this->render('directory/dirstatusgenerator');
812
	}
813
 
814
	# func to check directories active or not
815
	function checkDirectoryStatus($dirId, $nodebug=0) {
816
 
817
		$dirId = intval($dirId);
818
		$dirInfo = $this->getDirectoryInfo($dirId);
819
		$active = 0;
820
		$captcha = 0;
821
		$spider = new Spider();
822
		$ret = $spider->getContent(addHttpToUrl($dirInfo['submit_url']));
823
		$prUpdate = '';
824
		$searchUpdate = '';
825
		$extraValUpdate = '';
826
 
827
		if(empty($ret['error']) && !empty($ret['page'])) {
828
			$page = $ret['page'];
829
 
830
			$matches = $this->isCategoryExists($page, $dirInfo['category_col']);
831
			$active = empty($matches[0]) ? 0 : 1;
832
 
833
			$captcha = stristr($page, $dirInfo['captcha_script']) ? 1 : 0;
834
 
835
			// to check search script
836
			if (stristr($page, 'name="search"')) {
837
				$searchUpdate = ",search_script='index.php?search=[--keyword--]'";
838
			}
839
 
840
			// to check  the value of the LINK_TYPE if phpld directory
841
			if (($dirInfo['script_type_id'] == 1) && preg_match('/name="LINK_TYPE" value="(\d)"/s', $page)) {
842
			    $subject = array('LINK_TYPE=reciprocal', 'LINK_TYPE=normal', 'LINK_TYPE=free');
843
			    $replace = array('reciprocal=1&LINK_TYPE=1', 'LINK_TYPE=2', 'LINK_TYPE=3');
844
			    $dirInfo['extra_val'] = str_replace($subject, $replace, $dirInfo['extra_val']);
845
				$extraValUpdate = ",extra_val='{$dirInfo['extra_val']}'";
846
			}
847
 
848
			if ($this->checkPR) {
849
				include_once(SP_CTRLPATH."/moz.ctrl.php");
850
				$mozCtrler = new MozController();
851
				$mozRankList = $mozCtrler->__getMozRankInfo(array($dirInfo['domain']));
852
				$pagerank = !empty($mozRankList[0]['moz_rank']) ? $mozRankList[0]['moz_rank'] : 0;
853
				$domainAuthority = !empty($mozRankList[0]['domain_authority']) ? $mozRankList[0]['domain_authority'] : 0;
854
				$pageAuthority = !empty($mozRankList[0]['page_authority']) ? $mozRankList[0]['page_authority'] : 0;
855
				$prUpdate = ",pagerank=$pagerank,domain_authority=$domainAuthority,page_authority=$pageAuthority";
856
			}
857
 
858
		}
859
 
860
		$sql = "update directories set working=$active,is_captcha=$captcha,checked=1 $prUpdate $searchUpdate $extraValUpdate where id=$dirId";
861
		$this->db->query($sql);
862
 
863
		if($nodebug){
864
			$captchaLabel = $captcha ? $_SESSION['text']['common']['Yes'] : $_SESSION['text']['common']['No'];
865
			?>
866
			<script type="text/javascript">
867
				document.getElementById('captcha_<?php echo $dirId?>').innerHTML = '<?php echo $captchaLabel?>';
868
			</script>
869
			<?php
870
			if ($this->checkPR) {
871
				?>
872
				<script type="text/javascript">
873
					document.getElementById('pr_<?php echo $dirId?>').innerHTML = '<?php echo $pagerank?>';
874
					document.getElementById('da_<?php echo $dirId?>').innerHTML = '<?php echo $domainAuthority?>';
875
					document.getElementById('pa_<?php echo $dirId?>').innerHTML = '<?php echo $pageAuthority?>';
876
				</script>
877
				<?php
878
			}
879
			echo $this->getStatusLink($dirId, $active);
880
		}else{
881
			echo "<p class='note notesuccess'>Saved status of directory <b>{$dirInfo['domain']}</b>.....</p>";
882
		}
883
	}
884
 
885
	# func to get status link
886
	function getStatusLink($dirId, $status){
887
		if($status){
888
			$statLabel = "Active";
889
			$statVal = 0;
890
		}else{
891
			$statLabel = "Inactive";
892
			$statVal = 1;
893
		}
894
		if (SP_DEMO) {
895
			$statusLink = scriptAJAXLinkHref('demo', "", "", $_SESSION['text']['common'][$statLabel]);
896
		} else {
897
			$statusLink = scriptAJAXLinkHref('directories.php', 'status_'.$dirId, "sec=dirstatus&dir_id=$dirId&status=$statVal", $_SESSION['text']['common'][$statLabel]);
898
		}
899
 
900
		return $statusLink;
901
	}
902
 
903
	# to get total directory submission info
904
	function __getTotalSubmitInfo($websiteId, $activeCheck=false){
905
		$sql = "select count(*) count from dirsubmitinfo where website_id=$websiteId";
906
		if($activeCheck) $sql .= " and active=1";
907
 
908
		$countInfo = $this->db->select($sql, true);
909
		return empty($countInfo['count']) ? 0 : $countInfo['count'];
910
	}
911
 
912
	# function to log submission data
913
	function logSubmissionResult($content, $dirId, $websiteId) {
914
 
915
		$filename = SP_TMPPATH."/subres_web".$websiteId."_dir".$dirId.".html";
916
		$fp = fopen($filename, 'w');
917
		fwrite($fp, $content);
918
		fclose($fp);
919
 
920
	}
921
 
922
	# function to get directory script type meta info
923
	function getDirectoryScriptMetaInfo($id) {
924
	    $id = empty($id) ? 1 : $id;
925
	    $sql = "SELECT * FROM di_directory_meta where id=$id";
926
	    $scriptInfo = $this->db->select($sql, true);
927
	    return $scriptInfo;
928
	}
929
 
930
	// Function to check / validate the user type directory submission count
931
	function validateDirectorySubmissionCount($userId, $exit = true) {
932
		$userCtrler = new UserController();
933
		$validation = array('error' => false);
934
 
935
		// if admin user id return true
936
		if ($userCtrler->isAdminUserId($userId)) {
937
			return $validation;
938
		}
939
 
940
		$userTypeCtrlr = new UserTypeController();
941
		$userTypeDetails = $userTypeCtrlr->getUserTypeSpecByUser($userId);
942
 
943
		// if limit is set and not -1
944
		if (isset($userTypeDetails['directory_submit_limit']) || isset($userTypeDetails['directory_submit_daily_limit'])) {
945
 
946
			$spTextSubs = $userTypeCtrlr->getLanguageTexts('subscription', $_SESSION['lang_code']);
947
			$websiteCtrler = new WebsiteController();
948
			$websiteList = $websiteCtrler->__getAllWebsites($userId);
949
			$websiteIdList = array();
950
			foreach ($websiteList as $info) {
951
				$websiteIdList[] = $info['id'];
952
			}
953
 
954
			$whereCond = " website_id in (".implode(',', $websiteIdList).")";
955
 
956
			// if whole submit limit set
957
			if ($userTypeDetails['directory_submit_limit'] >= 0) {
958
				$submitInfo = $this->dbHelper->getRow("dirsubmitinfo", $whereCond, "count(*) count");
959
 
960
				// check whether count greater than limit
961
				if ($submitInfo['count'] >= $userTypeDetails['directory_submit_limit']) {
962
					$validation['error'] = true;
963
					$validation['msg'] = formatErrorMsg(str_replace("[limit]", $userTypeDetails['directory_submit_limit'], $spTextSubs['total_count_greater_account_limit_dir_sub']), "error", "");
964
				}
965
 
966
			}
967
 
968
			// if daily submit limit is set
969
			if (!$validation['error'] && $userTypeDetails['directory_submit_daily_limit'] >= 0) {
970
				$dateStr = date("Y-m-d");
971
				$fromTime = strtotime($dateStr . " 00:00:00");
972
				$toTime = strtotime($dateStr . " 23:59:59");
973
				$whereCond .= " and submit_time>=$fromTime and submit_time<=$toTime";
974
				$submitInfo = $this->dbHelper->getRow("dirsubmitinfo", $whereCond, "count(*) count");
975
 
976
				// check whether count greater than limit
977
				if ($submitInfo['count'] >= $userTypeDetails['directory_submit_daily_limit']) {
978
					$validation['error'] = true;
979
					$validation['msg'] = formatErrorMsg(str_replace("[limit]", $userTypeDetails['directory_submit_daily_limit'], $spTextSubs['total_count_greater_account_limit_dir_sub_daily']), "error", "");
980
				}
981
 
982
			}
983
 
984
		}
985
 
986
		// if exit after error
987
		if ($exit && $validation['error']) {
988
			showErrorMsg($validation['msg']);
989
		}
990
 
991
		return $validation;
992
	}
993
}
994
?>