| 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 |
/**
|
|
|
24 |
* Class defines all functions for managing website API
|
|
|
25 |
*
|
|
|
26 |
* @author Seo panel
|
|
|
27 |
*
|
|
|
28 |
*/
|
|
|
29 |
class WebsiteAPI extends Seopanel{
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
* the main controller to get details for api
|
|
|
33 |
* @var Object
|
|
|
34 |
*/
|
|
|
35 |
var $ctrler;
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* The list contains search engine details
|
|
|
39 |
* @var Array
|
|
|
40 |
*/
|
|
|
41 |
var $seList;
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
* The constructor of API
|
|
|
45 |
*/
|
|
|
46 |
function __construct() {
|
|
|
47 |
$this->ctrler = new WebsiteController();
|
|
|
48 |
$seController = New SearchEngineController();
|
|
|
49 |
$list = $seController->__getAllSearchEngines();
|
|
|
50 |
$this->seList = array();
|
|
|
51 |
|
|
|
52 |
// loop through the search engine and assign id as key
|
|
|
53 |
foreach ($list as $listInfo) {
|
|
|
54 |
$this->seList[$listInfo['id']] = $listInfo;
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
include_once(SP_CTRLPATH."/saturationchecker.ctrl.php");
|
|
|
58 |
include_once(SP_CTRLPATH."/rank.ctrl.php");
|
|
|
59 |
include_once(SP_CTRLPATH."/backlink.ctrl.php");
|
|
|
60 |
include_once(SP_CTRLPATH."/directory.ctrl.php");
|
|
|
61 |
include_once(SP_CTRLPATH."/keyword.ctrl.php");
|
|
|
62 |
include_once(SP_CTRLPATH."/pagespeed.ctrl.php");
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
/**
|
|
|
66 |
* function to get website reports rank, backlinks, saturation and directory submission
|
|
|
67 |
* @param array $websiteInfo The information about website
|
|
|
68 |
* @param int $fromTime The time stamp of from time
|
|
|
69 |
* @param int $toTime The time stamp of to time
|
|
|
70 |
* @return $websiteInfo The formatted website info with position details
|
|
|
71 |
*/
|
|
|
72 |
function getFormattedReport($websiteInfo, $fromTime, $toTime) {
|
|
|
73 |
|
|
|
74 |
// create required controllers
|
|
|
75 |
$rankCtrler = New RankController();
|
|
|
76 |
$backlinlCtrler = New BacklinkController();
|
|
|
77 |
$saturationCtrler = New SaturationCheckerController();
|
|
|
78 |
$dirCtrler = New DirectoryController();
|
|
|
79 |
$pagespeedCtrler = New PageSpeedController();
|
|
|
80 |
|
|
|
81 |
// rank reports
|
|
|
82 |
$report = $rankCtrler->__getWebsiteRankReport($websiteInfo['id'], $fromTime, $toTime);
|
|
|
83 |
$report = $report[0];
|
|
|
84 |
$toTimeDate = date('Y-m-d', $toTime);
|
|
|
85 |
$websiteInfo['alexa']['alexarank']['rank'] = empty($report['alexa_rank']) ? "-" : $report['alexa_rank'];
|
|
|
86 |
$websiteInfo['alexa']['alexarank']['diff'] = removeBraces($report['rank_diff_alexa']);
|
|
|
87 |
$websiteInfo['alexa']['alexarank']['date'] = $toTimeDate;
|
|
|
88 |
$websiteInfo['moz']['pagerank']['rank'] = empty($report['moz_rank']) ? "-" : $report['moz_rank'];
|
|
|
89 |
$websiteInfo['moz']['pagerank']['diff'] = removeBraces($report['rank_diff_moz']);
|
|
|
90 |
$websiteInfo['noz']['pagerank']['date'] = $toTimeDate;
|
|
|
91 |
|
|
|
92 |
// back links reports
|
|
|
93 |
$report = $backlinlCtrler->__getWebsitebacklinkReport($websiteInfo['id'], $fromTime, $toTime);
|
|
|
94 |
$report = $report[0];
|
|
|
95 |
$websiteInfo['google']['backlinks']['rank'] = empty($report['google']) ? "-" : $report['google'];
|
|
|
96 |
$websiteInfo['google']['backlinks']['diff'] = $report['rank_diff_google'];
|
|
|
97 |
$websiteInfo['google']['backlinks']['date'] = $toTimeDate;
|
|
|
98 |
$websiteInfo['alexa']['backlinks']['rank'] = empty($report['alexa']) ? "-" : $report['alexa'];
|
|
|
99 |
$websiteInfo['alexa']['backlinks']['diff'] = $report['rank_diff_alexa'];
|
|
|
100 |
$websiteInfo['alexa']['backlinks']['date'] = $toTimeDate;
|
|
|
101 |
$websiteInfo['bing']['backlinks']['rank'] = empty($report['msn']) ? "-" : $report['msn'];
|
|
|
102 |
$websiteInfo['bing']['backlinks']['diff'] = $report['rank_diff_msn'];
|
|
|
103 |
$websiteInfo['bing']['backlinks']['date'] = $toTimeDate;
|
|
|
104 |
|
|
|
105 |
// saturaton rank reports
|
|
|
106 |
$report = $saturationCtrler->__getWebsiteSaturationReport($websiteInfo['id'], $fromTime, $toTime);
|
|
|
107 |
$report = $report[0];
|
|
|
108 |
$websiteInfo['google']['indexed']['rank'] = empty($report['google']) ? "-" : $report['google'];
|
|
|
109 |
$websiteInfo['google']['indexed']['diff'] = $report['rank_diff_google'];
|
|
|
110 |
$websiteInfo['google']['indexed']['date'] = $toTimeDate;
|
|
|
111 |
$websiteInfo['bing']['indexed']['rank'] = empty($report['msn']) ? "-" : $report['msn'];
|
|
|
112 |
$websiteInfo['bing']['indexed']['diff'] = $report['rank_diff_msn'];
|
|
|
113 |
$websiteInfo['bing']['indexed']['date'] = $toTimeDate;
|
|
|
114 |
|
|
|
115 |
// directory submission stats
|
|
|
116 |
$websiteInfo['dirsub']['total'] = $dirCtrler->__getTotalSubmitInfo($websiteInfo['id']);
|
|
|
117 |
$websiteInfo['dirsub']['active'] = $dirCtrler->__getTotalSubmitInfo($websiteInfo['id'], true);
|
|
|
118 |
$websiteInfo['dirsub']['date'] = $toTimeDate;
|
|
|
119 |
|
|
|
120 |
// pagespeed reports
|
|
|
121 |
$report = $pagespeedCtrler->__getWebsitePageSpeedReport($websiteInfo['id'], $fromTime, $toTime);
|
|
|
122 |
$report = $report[0];
|
|
|
123 |
$websiteInfo['google']['pagespeed']['desktop_speed'] = empty($report['desktop_speed_score']) ? "-" : $report['desktop_speed_score'];
|
|
|
124 |
$websiteInfo['google']['pagespeed']['ds_diff'] = empty($report['rank_diff_desktop_speed_score']) ? "-" : $report['rank_diff_desktop_speed_score'];
|
|
|
125 |
$websiteInfo['google']['pagespeed']['mobile_speed'] = empty($report['mobile_speed_score']) ? "-" : $report['mobile_speed_score'];
|
|
|
126 |
$websiteInfo['google']['pagespeed']['ms_diff'] = empty($report['rank_diff_mobile_speed_score']) ? "-" : $report['rank_diff_mobile_speed_score'];
|
|
|
127 |
$websiteInfo['google']['pagespeed']['mobile_usability'] = empty($report['mobile_usability_score']) ? "-" : $report['mobile_usability_score'];
|
|
|
128 |
$websiteInfo['google']['pagespeed']['mu_diff'] = empty($report['rank_diff_mobile_usability_score']) ? "-" : $report['rank_diff_mobile_usability_score'];
|
|
|
129 |
$websiteInfo['google']['pagespeed']['date'] = $toTimeDate;
|
|
|
130 |
|
|
|
131 |
return $websiteInfo;
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
/**
|
|
|
135 |
* function to get website report using website id
|
|
|
136 |
* @param Array $info The input details to process the api
|
|
|
137 |
* $info['id'] The id of the website - Mandatory
|
|
|
138 |
* $info['from_time'] The from time of report in (yyyy-mm-dd) Eg: 2014-12-24 - Optional - (default => Yesterday)
|
|
|
139 |
* $info['to_time'] The to time of report in (yyyy-mm-dd) Eg: 2014-12-28 - Optional - (default => Today)
|
|
|
140 |
* @return Array $returnInfo Contains informations about website reports
|
|
|
141 |
*/
|
|
|
142 |
function getReportById($info) {
|
|
|
143 |
|
|
|
144 |
$fromTime = getFromTime($info);
|
|
|
145 |
$toTime = getToTime($info);
|
|
|
146 |
$websiteInfo = $this->ctrler->__getWebsiteInfo($info['id']);
|
|
|
147 |
|
|
|
148 |
// if website not exists
|
|
|
149 |
if (empty($websiteInfo['id'])) {
|
|
|
150 |
$returnInfo['response'] = 'Error';
|
|
|
151 |
$returnInfo['error_msg'] = "The invalid website id provided";
|
|
|
152 |
} else {
|
|
|
153 |
$returnInfo['response'] = 'success';
|
|
|
154 |
$returnInfo['result'] = $this->getFormattedReport($websiteInfo, $fromTime, $toTime);
|
|
|
155 |
}
|
|
|
156 |
|
|
|
157 |
return $returnInfo;
|
|
|
158 |
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
/**
|
|
|
162 |
* function to get website report using user id
|
|
|
163 |
* @param Array $info The input details to process the api
|
|
|
164 |
* $info['id'] The id of the user - Mandatory
|
|
|
165 |
* $info['from_time'] The from time of report in (yyyy-mm-dd) Eg: 2014-12-24 - Optional - (default => Yesterday)
|
|
|
166 |
* $info['to_time'] The to time of report in (yyyy-mm-dd) Eg: 2014-12-28 - Optional - (default => Today)
|
|
|
167 |
* @return Array $returnInfo Contains informations about website reports
|
|
|
168 |
*/
|
|
|
169 |
function getReportByUserId($info) {
|
|
|
170 |
|
|
|
171 |
// if not valid user
|
|
|
172 |
$userId = intval($info['id']);
|
|
|
173 |
if (empty($userId)) {
|
|
|
174 |
return array(
|
|
|
175 |
'response' => 'Error',
|
|
|
176 |
'result' => 'Invalid user id'
|
|
|
177 |
);
|
|
|
178 |
}
|
|
|
179 |
|
|
|
180 |
// get all active websites
|
|
|
181 |
$wbList = $this->ctrler->__getAllWebsites($userId);
|
|
|
182 |
$fromTime = getFromTime($info);
|
|
|
183 |
$toTime = getToTime($info);
|
|
|
184 |
|
|
|
185 |
// loop through websites
|
|
|
186 |
$websiteList = array();
|
|
|
187 |
foreach ($wbList as $websiteInfo) {
|
|
|
188 |
$websiteList[$websiteInfo['id']] = $this->getFormattedReport($websiteInfo, $fromTime, $toTime);
|
|
|
189 |
}
|
|
|
190 |
|
|
|
191 |
// if position information is not empty
|
|
|
192 |
if (empty($websiteList)) {
|
|
|
193 |
$returnInfo['response'] = 'Error';
|
|
|
194 |
$returnInfo['result'] = "No reports found!";
|
|
|
195 |
} else {
|
|
|
196 |
$returnInfo['response'] = 'success';
|
|
|
197 |
$returnInfo['result'] = $websiteList;
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
return $returnInfo;
|
|
|
201 |
|
|
|
202 |
}
|
|
|
203 |
|
|
|
204 |
/**
|
|
|
205 |
* function to get website information
|
|
|
206 |
* @param Array $info The input details to process the api
|
|
|
207 |
* $info['id'] The id of the website - Mandatory
|
|
|
208 |
* @return Array $returnInfo Contains informations about website
|
|
|
209 |
*/
|
|
|
210 |
function getWebsiteInfo($info) {
|
|
|
211 |
$websiteId = intval($info['id']);
|
|
|
212 |
$returnInfo = array();
|
|
|
213 |
|
|
|
214 |
// validate the website ifd and website info
|
|
|
215 |
if (!empty($websiteId)) {
|
|
|
216 |
if ($websiteInfo = $this->ctrler->__getWebsiteInfo($websiteId)) {
|
|
|
217 |
$returnInfo['response'] = 'success';
|
|
|
218 |
$returnInfo['result'] = $websiteInfo;
|
|
|
219 |
return $returnInfo;
|
|
|
220 |
}
|
|
|
221 |
}
|
|
|
222 |
|
|
|
223 |
$returnInfo['response'] = 'Error';
|
|
|
224 |
$returnInfo['error_msg'] = "The invalid website id provided";
|
|
|
225 |
return $returnInfo;
|
|
|
226 |
}
|
|
|
227 |
|
|
|
228 |
/**
|
|
|
229 |
* function to get user websites
|
|
|
230 |
* @param Array $info The input details to process the api
|
|
|
231 |
* $info['id'] The id of the user - Mandatory
|
|
|
232 |
* $info['status'] The status of the websites[0/1]
|
|
|
233 |
* $info['search'] The search keyword
|
|
|
234 |
* @return Array $returnInfo Contains informations about website
|
|
|
235 |
*/
|
|
|
236 |
function getUserWebsites($info) {
|
|
|
237 |
$userId = intval($info['id']);
|
|
|
238 |
$returnInfo = array();
|
|
|
239 |
|
|
|
240 |
// validate the website ifd and website info
|
|
|
241 |
if (!empty($userId)) {
|
|
|
242 |
$websiteList = $this->ctrler->__getUserWebsites($userId, $info);
|
|
|
243 |
$returnInfo['response'] = 'success';
|
|
|
244 |
$returnInfo['result'] = $websiteList;
|
|
|
245 |
return $returnInfo;
|
|
|
246 |
}
|
|
|
247 |
|
|
|
248 |
$returnInfo['response'] = 'Error';
|
|
|
249 |
$returnInfo['error_msg'] = "The invalid user id provided";
|
|
|
250 |
return $returnInfo;
|
|
|
251 |
}
|
|
|
252 |
|
|
|
253 |
/**
|
|
|
254 |
* function to create website
|
|
|
255 |
* @param Array $info The input details to process the api
|
|
|
256 |
* $info['name'] The name of the website - Mandatory
|
|
|
257 |
* $info['url'] The url of the website - Mandatory
|
|
|
258 |
* $info['user_id'] The user id of website - Mandatory
|
|
|
259 |
* $info['title'] The title of the website - Optional
|
|
|
260 |
* $info['description'] The description of website - Optional
|
|
|
261 |
* $info['keywords'] The keyword of the website - Optional
|
|
|
262 |
* $info['status'] The status of the website - default[1] - Optional
|
|
|
263 |
* @return Array $returnInfo Contains details about the operation succes or not
|
|
|
264 |
*/
|
|
|
265 |
function createWebsite($info) {
|
|
|
266 |
$websiteInfo = $info;
|
|
|
267 |
|
|
|
268 |
// check for user id
|
|
|
269 |
if (empty($info['user_id'])) {
|
|
|
270 |
$returnInfo['response'] = 'Error';
|
|
|
271 |
$returnInfo['error_msg'] = 'Invalid user id';
|
|
|
272 |
return $returnInfo;
|
|
|
273 |
}
|
|
|
274 |
|
|
|
275 |
$websiteInfo['userid'] = $info['user_id'];
|
|
|
276 |
$this->ctrler->spTextWeb = $this->ctrler->getLanguageTexts('website', SP_API_LANG_CODE);
|
|
|
277 |
$return = $this->ctrler->createWebsite($websiteInfo, true);
|
|
|
278 |
|
|
|
279 |
// if website creation is success
|
|
|
280 |
if ($return[0] == 'success') {
|
|
|
281 |
$returnInfo['response'] = 'success';
|
|
|
282 |
$returnInfo['result'] = $return[1];
|
|
|
283 |
$returnInfo['website_id'] = $this->ctrler->db->getMaxId('websites');
|
|
|
284 |
} else {
|
|
|
285 |
$returnInfo['response'] = 'Error';
|
|
|
286 |
$returnInfo['error_msg'] = $return[1];
|
|
|
287 |
}
|
|
|
288 |
|
|
|
289 |
return $returnInfo;
|
|
|
290 |
|
|
|
291 |
}
|
|
|
292 |
|
|
|
293 |
/**
|
|
|
294 |
* function to update website
|
|
|
295 |
* @param Array $info The input details to process the api
|
|
|
296 |
* $info['id'] The id of the website - Mandatory
|
|
|
297 |
* $info['name'] The name of the website - Optional
|
|
|
298 |
* $info['url'] The url of the website - Optional
|
|
|
299 |
* $info['title'] The title of the website - Optional
|
|
|
300 |
* $info['description'] The description of website - Optional
|
|
|
301 |
* $info['keywords'] The keyword of the website - Optional
|
|
|
302 |
* $info['user_id'] The user id of website - Optional
|
|
|
303 |
* $info['status'] The status of the website - default[1] - Optional
|
|
|
304 |
* @return Array $returnInfo Contains details about the operation succes or not
|
|
|
305 |
*/
|
|
|
306 |
function updateWebsite($info) {
|
|
|
307 |
|
|
|
308 |
$websiteId = intval($info['id']);
|
|
|
309 |
|
|
|
310 |
// if website exists
|
|
|
311 |
if ($websiteInfo = $this->ctrler->__getWebsiteInfo($websiteId)) {
|
|
|
312 |
|
|
|
313 |
$websiteInfo['oldName'] = $websiteInfo['name'];
|
|
|
314 |
|
|
|
315 |
// loop through inputs
|
|
|
316 |
foreach ($info as $key => $val) {
|
|
|
317 |
$websiteInfo[$key] = $val;
|
|
|
318 |
}
|
|
|
319 |
|
|
|
320 |
// update website call as api call
|
|
|
321 |
$this->ctrler->spTextWeb = $this->ctrler->getLanguageTexts('website', SP_API_LANG_CODE);
|
|
|
322 |
$return = $this->ctrler->updateWebsite($websiteInfo, true);
|
|
|
323 |
|
|
|
324 |
// if website creation is success
|
|
|
325 |
if ($return[0] == 'success') {
|
|
|
326 |
$returnInfo['response'] = 'success';
|
|
|
327 |
$returnInfo['result'] = $return[1];
|
|
|
328 |
} else {
|
|
|
329 |
$returnInfo['response'] = 'Error';
|
|
|
330 |
$returnInfo['error_msg'] = $return[1];
|
|
|
331 |
}
|
|
|
332 |
|
|
|
333 |
} else {
|
|
|
334 |
|
|
|
335 |
$returnInfo['response'] = 'Error';
|
|
|
336 |
$returnInfo['error_msg'] = "The invalid website id provided";
|
|
|
337 |
}
|
|
|
338 |
|
|
|
339 |
return $returnInfo;
|
|
|
340 |
|
|
|
341 |
}
|
|
|
342 |
|
|
|
343 |
/**
|
|
|
344 |
* function to delete website
|
|
|
345 |
* @param Array $info The input details to process the api
|
|
|
346 |
* $info['id'] The id of the website - Mandatory
|
|
|
347 |
* @return Array $returnInfo Contains details about the operation success or not
|
|
|
348 |
*/
|
|
|
349 |
function deleteWebsite($info) {
|
|
|
350 |
|
|
|
351 |
$websiteId = intval($info['id']);
|
|
|
352 |
|
|
|
353 |
// if website exists
|
|
|
354 |
if ($websiteInfo = $this->ctrler->__getWebsiteInfo($websiteId)) {
|
|
|
355 |
|
|
|
356 |
|
|
|
357 |
$this->ctrler->__deleteWebsite($websiteId);
|
|
|
358 |
$returnInfo['response'] = 'success';
|
|
|
359 |
$returnInfo['result'] = "Successfully deleted website and related data.";
|
|
|
360 |
|
|
|
361 |
} else {
|
|
|
362 |
$returnInfo['response'] = 'Error';
|
|
|
363 |
$returnInfo['error_msg'] = "The invalid website id provided";
|
|
|
364 |
}
|
|
|
365 |
|
|
|
366 |
return $returnInfo;
|
|
|
367 |
}
|
|
|
368 |
|
|
|
369 |
}
|
|
|
370 |
?>
|