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.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 search engine controller functions
24
class SearchEngineController extends Controller{
25
 
26
	# func to get all search engines
27
	function __getAllSearchEngines(){
28
		$sql = "select * from searchengines where status=1";
29
		$seList = $this->db->select($sql);
30
		return $seList;
31
	}
32
 
33
	function __searchSerachEngines($searchInfo=[]) {
34
	    $cond = "1=1";
35
	    $cond .= isset($searchInfo['status']) ? " and status=".intval($searchInfo['status']) : "";
36
	    $cond .= isset($searchInfo['search']) ? " and url like '%".addslashes($searchInfo['search'])."%'" : "";
37
	    return $this->dbHelper->getAllRows('searchengines', $cond);
38
	}
39
 
40
	# func to get search engine info
41
	function __getsearchEngineInfo($seId){
42
		$sql = "select * from searchengines where id=$seId";
43
		$seList = $this->db->select($sql, true);
44
		return $seList;
45
	}
46
 
47
	# func to get all search engines
48
	function __getAllCrawlFormatedSearchEngines(){
49
		$sql = "select * from searchengines where status=1";
50
		$list = $this->db->select($sql);
51
		$seList = array();
52
		foreach($list as $seInfo){
53
			$seId = $seInfo['id'];
54
			$seInfo['regex'] = "/".$seInfo['regex']."/is";
55
			$search = array('[--num--]');
56
			$replace = array($seInfo['no_of_results_page']);
57
			$seInfo['url'] = str_replace($search, $replace, $seInfo['url']);
58
			$seList[$seId] = $seInfo;
59
		}
60
		return $seList;
61
	}
62
 
63
	# func to show search engines
64
	function listSE($info=''){
65
		$info = sanitizeData($info);
66
		$info['stscheck'] = isset($info['stscheck']) ? intval($info['stscheck']) : 1;
67
		$pageScriptPath = 'searchengine.php?stscheck=' . $info['stscheck'];
68
		$sql = "select * from searchengines where status='{$info['stscheck']}'";
69
 
70
		// search for search engine name
71
		if (!empty($info['se_name'])) {
72
			$sql .= " and domain like '%".addslashes($info['se_name'])."%'";
73
			$pageScriptPath .= "&se_name=" . $info['se_name'];
74
		}
75
 
76
		$sql .= " order by id";
77
 
78
		# pagination setup
79
		$this->db->query($sql, true);
80
		$this->paging->setDivClass('pagingdiv');
81
		$this->paging->loadPaging($this->db->noRows, SP_PAGINGNO);
82
		$pagingDiv = $this->paging->printPages($pageScriptPath, '', 'scriptDoLoad', 'content', 'layout=ajax');
83
		$this->set('pagingDiv', $pagingDiv);
84
		$sql .= " limit ".$this->paging->start .",". $this->paging->per_page;
85
		$seList = $this->db->select($sql);
86
		$this->set('seList', $seList);
87
 
88
		$statusList = array(
89
			$_SESSION['text']['common']['Active'] => 1,
90
			$_SESSION['text']['common']['Inactive'] => 0,
91
		);
92
 
93
		$this->set('statusList', $statusList);
94
		$this->set('info', $info);
95
		$this->set('pageScriptPath', $pageScriptPath);
96
		$this->set('pageNo', $info['pageno']);
97
		$this->render('searchengine/list', 'ajax');
98
	}
99
 
100
	# func to change status of search engine
101
	function __changeStatus($seId, $status){
102
		$seId = intval($seId);
103
		$sql = "update searchengines set status=$status where id=$seId";
104
		$this->db->query($sql);
105
	}
106
 
107
	# func to delete search engine
108
	function __deleteSearchEngine($seId){
109
		$seId = intval($seId);
110
		$sql = "delete from searchengines where id=$seId";
111
		$this->db->query($sql);
112
 
113
 
114
		$sql = "select id from searchresults where searchengine_id=$seId";
115
		$recordList = $this->db->select($sql);
116
 
117
		if(count($recordList) > 0){
118
			foreach($recordList as $recordInfo){
119
				$sql = "delete from searchresultdetails where searchresult_id=".$recordInfo['id'];
120
				$this->db->query($sql);
121
			}
122
 
123
			$sql = "delete from searchresults where searchengine_id=$seId";
124
			$this->db->query($sql);
125
		}
126
 
127
	}
128
 
129
	# function to check whether captcha found in search engine results
130
	public static function isCaptchInSearchResults($searchContent) {
131
 
132
		$captchFound = false;
133
 
134
		// if captcha input field is found
135
		if (stristr($searchContent, 'name="captcha"') || stristr($searchContent, 'id="captcha"') || stristr($searchContent, 'recaptcha/api')) {
136
			$captchFound = true;
137
		}
138
 
139
		return $captchFound;
140
	}
141
 
142
	// Function to check / validate the user type searh engine count
143
	public static function validateSearchEngineCount($userId, $count) {
144
		$userCtrler = new UserController();
145
		$validation = array('error' => false);
146
 
147
		// if admin user id return true
148
		if ($userCtrler->isAdminUserId($userId)) {
149
			return $validation;
150
		}
151
 
152
		$userTypeCtrlr = new UserTypeController();
153
		$userTypeDetails = $userTypeCtrlr->getUserTypeSpecByUser($userId);
154
 
155
		// if limit is set and not -1
156
		if (isset($userTypeDetails['searchengine_count']) && $userTypeDetails['searchengine_count'] >= 0) {
157
 
158
			// check whether count greater than limit
159
			if ($count > $userTypeDetails['searchengine_count']) {
160
				$validation['error'] = true;
161
				$spTextSubs = $userTypeCtrlr->getLanguageTexts('subscription', $_SESSION['lang_code']);
162
				$validation['msg'] = formatErrorMsg(str_replace("[limit]", $userTypeDetails['searchengine_count'], $spTextSubs['total_count_greater_account_limit']));
163
			}
164
 
165
		}
166
 
167
		return $validation;
168
	}
169
 
170
	// func to show sync search engines
171
	function showSyncSearchEngines($info=[]) {
172
 
173
	    $pageScriptPath = 'searchengine.php?sec=sync-se';
174
	    $sql = "select * from sync_searchengines order by sync_time DESC";
175
 
176
	    # pagination setup
177
	    $this->db->query($sql, true);
178
	    $this->paging->setDivClass('pagingdiv');
179
	    $this->paging->loadPaging($this->db->noRows, SP_PAGINGNO);
180
	    $pagingDiv = $this->paging->printPages($pageScriptPath, '', 'scriptDoLoad', 'content', 'layout=ajax');
181
	    $this->set('pagingDiv', $pagingDiv);
182
	    $sql .= " limit ".$this->paging->start .",". $this->paging->per_page;
183
	    $syncList = $this->db->select($sql);
184
	    $this->set('syncList', $syncList);
185
 
186
	    $this->set('pageScriptPath', $pageScriptPath);
187
	    $this->set('pageNo', $info['pageno']);
188
	    $this->render('searchengine/list_sync_searchengines');
189
	}
190
 
191
	// do sync search engines from sp main website
192
	function doSyncSearchEngines($checkAlreadyExecuted = false, $cronJob = false) {
193
 
194
	    // check whether already executed sync
195
	    if ($checkAlreadyExecuted) {
196
	        $row = $this->dbHelper->getRow("sync_searchengines", "sync_time>TIMESTAMP(DATE_SUB(NOW(), INTERVAL ". SP_SYNC_SE_INTERVAL ." day))");
197
	        if (!empty($row['id'])) {
198
	            return ['status' => false, 'result' => "Search engines already synced."];
199
	        }
200
	    }
201
 
202
	    $dataList = ['status' => 0];
203
	    $syncUrl = SP_MAIN_SITE . "/get_searchengine_updates.php";
204
	    $ret = $this->spider->getContent($syncUrl);
205
	    if (!empty($ret['page'])) {
206
 
207
	        // check whethere required content exists in the page crawled
208
	        if (stristr($ret['page'], 'UPDATE ')) {
209
 
210
	            $queryList = explode(';', $ret['page']);
211
	            foreach ($queryList as $query) {
212
	                if (!empty($query)) {
213
	                   $this->db->query(trim($query));
214
	                }
215
	            }
216
 
217
	            $dataList['result'] = "Search engines successfully synced.";
218
	            $dataList['status'] = 1;
219
 
220
	            // update admin alerts section
221
	            if ($cronJob) {
222
	                $alertCtrl = new AlertController();
223
	                $alertInfo = array(
224
	                    'alert_subject' => "Search Engine Sync",
225
	                    'alert_message' => $dataList['result'],
226
	                    'alert_category' => "reports",
227
	                    'alert_url' => SP_WEBPATH,
228
	                );
229
	                $alertCtrl->createAlert($alertInfo, false, true);
230
	            }
231
 
232
	        } else {
233
	            $dataList['result'] = "Internal error occured during search engine sync.";
234
	        }
235
 
236
	    } else {
237
	        $dataList['result'] = $ret['errmsg'];
238
	    }
239
 
240
	    $this->dbHelper->insertRow("sync_searchengines", $dataList);
241
	    return $dataList;
242
	}
243
 
244
}
245
?>