| 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 keyword API
|
|
|
25 |
*
|
|
|
26 |
* @author Seo panel
|
|
|
27 |
*
|
|
|
28 |
*/
|
|
|
29 |
class KeywordAPI extends Seopanel{
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
* the main controller to get details for api
|
|
|
33 |
* @var Object
|
|
|
34 |
*/
|
|
|
35 |
var $ctrler;
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* The report controller to get details of keyword reports
|
|
|
39 |
* @var Object
|
|
|
40 |
*/
|
|
|
41 |
var $reportCtrler;
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
* The list contains search engine details
|
|
|
45 |
* @var Array
|
|
|
46 |
*/
|
|
|
47 |
var $seList;
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* The constructor of API
|
|
|
51 |
*/
|
|
|
52 |
function __construct() {
|
|
|
53 |
include_once(SP_CTRLPATH . "/keyword.ctrl.php");
|
|
|
54 |
include_once(SP_CTRLPATH . "/report.ctrl.php");
|
|
|
55 |
$this->ctrler = new KeywordController();
|
|
|
56 |
$this->reportCtrler = New ReportController();
|
|
|
57 |
$seController = New SearchEngineController();
|
|
|
58 |
$list = $seController->__getAllSearchEngines();
|
|
|
59 |
$this->seList = array();
|
|
|
60 |
|
|
|
61 |
// loop through the search engine and assign id as key
|
|
|
62 |
foreach ($list as $listInfo) {
|
|
|
63 |
$this->seList[$listInfo['id']] = $listInfo;
|
|
|
64 |
}
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
/**
|
|
|
68 |
* function to get keyword report and format it
|
|
|
69 |
* @param array $keywordInfo The information about keyword
|
|
|
70 |
* @param int $fromTime The time stamp of from time
|
|
|
71 |
* @param int $toTime The time stamp of to time
|
|
|
72 |
* @return $keywordInfo The formatted keyword info with position details
|
|
|
73 |
*/
|
|
|
74 |
function getFormattedReport($keywordInfo, $fromTime, $toTime) {
|
|
|
75 |
$positionInfo = $this->reportCtrler->__getKeywordSearchReport($keywordInfo['id'], $fromTime, $toTime, true);
|
|
|
76 |
|
|
|
77 |
// loop through and add search engine name
|
|
|
78 |
foreach ($positionInfo as $seId => $info) {
|
|
|
79 |
$positionInfo[$seId]['search_engine'] = $this->seList[$seId]['domain'];
|
|
|
80 |
$positionInfo[$seId]['date'] = date('Y-m-d', $toTime);
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
$keywordInfo['position_info'] = $positionInfo;
|
|
|
84 |
return $keywordInfo;
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
/**
|
|
|
88 |
* function to get keyword report using keyword id
|
|
|
89 |
* @param Array $info The input details to process the api
|
|
|
90 |
* $info['id'] The id of the keyword - Mandatory
|
|
|
91 |
* $info['from_time'] The from time of report in (yyyy-mm-dd) Eg: 2014-12-24 - Optional - (default => Yesterday)
|
|
|
92 |
* $info['to_time'] The to time of report in (yyyy-mm-dd) Eg: 2014-12-28 - Optional - (default => Today)
|
|
|
93 |
* @return Array $returnInfo Contains informations about keyword reports
|
|
|
94 |
*/
|
|
|
95 |
function getReportById($info) {
|
|
|
96 |
|
|
|
97 |
$fromTime = getFromTime($info);
|
|
|
98 |
$toTime = getToTime($info);
|
|
|
99 |
$keywordInfo = $this->ctrler->__getKeywordInfo($info['id']);
|
|
|
100 |
$positionInfo = $this->getFormattedReport($keywordInfo, $fromTime, $toTime);
|
|
|
101 |
|
|
|
102 |
// if position information is not empty
|
|
|
103 |
if (empty($positionInfo)) {
|
|
|
104 |
$returnInfo['response'] = 'Error';;
|
|
|
105 |
$returnInfo['result'] = "No reports found!";
|
|
|
106 |
} else {
|
|
|
107 |
$returnInfo['response'] = 'success';
|
|
|
108 |
$returnInfo['result'] = $positionInfo;
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
return $returnInfo;
|
|
|
112 |
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
/**
|
|
|
116 |
* function to get keyword report using website id
|
|
|
117 |
* @param Array $info The input details to process the api
|
|
|
118 |
* $info['id'] The id of the website - Mandatory
|
|
|
119 |
* $info['from_time'] The from time of report in (yyyy-mm-dd) Eg: 2014-12-24 - Optional - (default => Yesterday)
|
|
|
120 |
* $info['to_time'] The to time of report in (yyyy-mm-dd) Eg: 2014-12-28 - Optional - (default => Today)
|
|
|
121 |
* @return Array $returnInfo Contains informations about keyword reports
|
|
|
122 |
*/
|
|
|
123 |
function getReportByWebsiteId($info) {
|
|
|
124 |
|
|
|
125 |
$websiteId = intval($info['id']);
|
|
|
126 |
if (empty($websiteId)) {
|
|
|
127 |
return array(
|
|
|
128 |
'response' => 'Error',
|
|
|
129 |
'result' => 'Invalid website id'
|
|
|
130 |
);
|
|
|
131 |
}
|
|
|
132 |
|
|
|
133 |
$fromTime = getFromTime($info);
|
|
|
134 |
$toTime = getToTime($info);
|
|
|
135 |
$list = $this->ctrler->__getAllKeywords('', $websiteId);
|
|
|
136 |
|
|
|
137 |
// lopp through keywords
|
|
|
138 |
$keywordList = array();
|
|
|
139 |
foreach ($list as $keywordInfo) {
|
|
|
140 |
$keywordList[$keywordInfo['id']] = $this->getFormattedReport($keywordInfo, $fromTime, $toTime);
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
// if position information is not empty
|
|
|
144 |
if (empty($keywordList)) {
|
|
|
145 |
$returnInfo['response'] = 'Error';
|
|
|
146 |
$returnInfo['result'] = "No reports found!";
|
|
|
147 |
} else {
|
|
|
148 |
$returnInfo['response'] = 'success';
|
|
|
149 |
$returnInfo['result'] = $keywordList;
|
|
|
150 |
}
|
|
|
151 |
|
|
|
152 |
return $returnInfo;
|
|
|
153 |
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
/**
|
|
|
157 |
* function to get keyword report using user id
|
|
|
158 |
* @param Array $info The input details to process the api
|
|
|
159 |
* $info['id'] The id of the user - Mandatory
|
|
|
160 |
* $info['from_time'] The from time of report in (yyyy-mm-dd) Eg: 2014-12-24 - Optional - (default => Yesterday)
|
|
|
161 |
* $info['to_time'] The to time of report in (yyyy-mm-dd) Eg: 2014-12-28 - Optional - (default => Today)
|
|
|
162 |
* @return Array $returnInfo Contains informations about keyword reports
|
|
|
163 |
*/
|
|
|
164 |
function getReportByUserId($info) {
|
|
|
165 |
|
|
|
166 |
$userId = intval($info['id']);
|
|
|
167 |
if (empty($userId)) {
|
|
|
168 |
return array(
|
|
|
169 |
'response' => 'Error',
|
|
|
170 |
'result' => 'Invalid user id'
|
|
|
171 |
);
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
$fromTime = getFromTime($info);
|
|
|
175 |
$toTime = getToTime($info);
|
|
|
176 |
|
|
|
177 |
// get all active websites
|
|
|
178 |
$websiteController = New WebsiteController();
|
|
|
179 |
$websiteList = $websiteController->__getAllWebsitesWithActiveKeywords($userId, true);
|
|
|
180 |
|
|
|
181 |
// loop through websites
|
|
|
182 |
$keywordList = array();
|
|
|
183 |
foreach ($websiteList as $websiteInfo) {
|
|
|
184 |
$websiteId = $websiteInfo['id'];
|
|
|
185 |
$list = $this->ctrler->__getAllKeywords('', $websiteId);
|
|
|
186 |
|
|
|
187 |
// loop through keywords
|
|
|
188 |
foreach ($list as $keywordInfo) {
|
|
|
189 |
$keywordList[$keywordInfo['id']] = $this->getFormattedReport($keywordInfo, $fromTime, $toTime);
|
|
|
190 |
}
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
// if position information is not empty
|
|
|
194 |
if (empty($keywordList)) {
|
|
|
195 |
$returnInfo['response'] = 'Error';
|
|
|
196 |
$returnInfo['result'] = "No reports found!";
|
|
|
197 |
} else {
|
|
|
198 |
$returnInfo['response'] = 'success';
|
|
|
199 |
$returnInfo['result'] = $keywordList;
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
return $returnInfo;
|
|
|
203 |
|
|
|
204 |
}
|
|
|
205 |
|
|
|
206 |
/**
|
|
|
207 |
* function to get keyword information
|
|
|
208 |
* @param Array $info The input details to process the api
|
|
|
209 |
* $info['id'] The id of the keyword - Mandatory
|
|
|
210 |
* @return Array $returnInfo Contains informations about keyword
|
|
|
211 |
*/
|
|
|
212 |
function getKeywordInfo($info) {
|
|
|
213 |
$keywordId = intval($info['id']);
|
|
|
214 |
$returnInfo = array();
|
|
|
215 |
|
|
|
216 |
// validate the keyword id and keyword info
|
|
|
217 |
if (!empty($keywordId)) {
|
|
|
218 |
if ($keywordInfo = $this->ctrler->__getKeywordInfo($keywordId)) {
|
|
|
219 |
$returnInfo['response'] = 'success';
|
|
|
220 |
$returnInfo['result'] = $keywordInfo;
|
|
|
221 |
return $returnInfo;
|
|
|
222 |
}
|
|
|
223 |
}
|
|
|
224 |
|
|
|
225 |
$returnInfo['response'] = 'Error';
|
|
|
226 |
$returnInfo['error_msg'] = "The invalid keyword id provided";
|
|
|
227 |
return $returnInfo;
|
|
|
228 |
}
|
|
|
229 |
|
|
|
230 |
/**
|
|
|
231 |
* function to get website keywords
|
|
|
232 |
* @param Array $info The input details to process the api
|
|
|
233 |
* $info['id'] The id of the website - Mandatory
|
|
|
234 |
* $info['status'] The status of the keyword
|
|
|
235 |
* $info['search'] The search keyword
|
|
|
236 |
* @return Array $returnInfo Contains informations about keyword
|
|
|
237 |
*/
|
|
|
238 |
function getWebsiteKeywords($info) {
|
|
|
239 |
$websiteId = intval($info['id']);
|
|
|
240 |
$returnInfo = array();
|
|
|
241 |
|
|
|
242 |
// validate the website id
|
|
|
243 |
if (!empty($websiteId)) {
|
|
|
244 |
$keywordList = $this->ctrler->__getWebisteKeywords($websiteId, $info);
|
|
|
245 |
$returnInfo['response'] = 'success';
|
|
|
246 |
$returnInfo['result'] = $keywordList;
|
|
|
247 |
return $returnInfo;
|
|
|
248 |
}
|
|
|
249 |
|
|
|
250 |
$returnInfo['response'] = 'Error';
|
|
|
251 |
$returnInfo['error_msg'] = "The invalid website id provided";
|
|
|
252 |
return $returnInfo;
|
|
|
253 |
}
|
|
|
254 |
|
|
|
255 |
/**
|
|
|
256 |
* function to create keyword
|
|
|
257 |
* @param Array $info The input details to process the api
|
|
|
258 |
* $info['name'] The name of the keyword - Mandatory
|
|
|
259 |
* $info['website_id'] The website id of keyword - Mandatory
|
|
|
260 |
* $info['searchengines'] The search engine ids of the keyword - Mandatory[id1:id2]
|
|
|
261 |
* $info['lang_code'] The language code of the keyword - Optional[de]
|
|
|
262 |
* $info['country_code'] The country code of the keyword - Optional[ar]
|
|
|
263 |
* $info['status'] The status of the keyword - default[1] - Optional
|
|
|
264 |
* @return Array $returnInfo Contains details about the operation succes or not
|
|
|
265 |
*/
|
|
|
266 |
function createKeyword($info) {
|
|
|
267 |
|
|
|
268 |
// if empty website id provided
|
|
|
269 |
if (empty($info['website_id'])) {
|
|
|
270 |
$returnInfo['response'] = 'Error';
|
|
|
271 |
$returnInfo['error_msg'] = "Please provide valid website id.";
|
|
|
272 |
return $returnInfo;
|
|
|
273 |
}
|
|
|
274 |
|
|
|
275 |
$keywordInfo = $info;
|
|
|
276 |
$keywordInfo['userid'] = $info['user_id'];
|
|
|
277 |
$this->ctrler->spTextKeyword = $this->ctrler->getLanguageTexts('keyword', SP_API_LANG_CODE);
|
|
|
278 |
$keywordInfo['searchengines'] = explode(':', $keywordInfo['searchengines']);
|
|
|
279 |
$return = $this->ctrler->createKeyword($keywordInfo, true);
|
|
|
280 |
|
|
|
281 |
// if keyword creation is success
|
|
|
282 |
if ($return[0] == 'success') {
|
|
|
283 |
$returnInfo['response'] = 'success';
|
|
|
284 |
$returnInfo['result'] = $return[1];
|
|
|
285 |
$returnInfo['keyword_id'] = $this->ctrler->db->getMaxId('keywords');
|
|
|
286 |
} else {
|
|
|
287 |
$returnInfo['response'] = 'Error';
|
|
|
288 |
$returnInfo['error_msg'] = $return[1];
|
|
|
289 |
}
|
|
|
290 |
|
|
|
291 |
return $returnInfo;
|
|
|
292 |
|
|
|
293 |
}
|
|
|
294 |
|
|
|
295 |
/**
|
|
|
296 |
* function to update keyword
|
|
|
297 |
* @param Array $info The input details to process the api
|
|
|
298 |
* $info['id'] The id of the keyword - Mandatory
|
|
|
299 |
* $info['name'] The name of the keyword - Optional
|
|
|
300 |
* $info['lang_code'] The language code of the keyword - Optional[de,fr]
|
|
|
301 |
* $info['country_code'] The country code of the keyword - Optional[ar,in]
|
|
|
302 |
* $info['website_id'] The description of keyword - Optional
|
|
|
303 |
* $info['searchengines'] The search engine ids of the keyword - Optional[id1:id2]
|
|
|
304 |
* $info['status'] The status of the keyword - default[1] - Optional
|
|
|
305 |
* @return Array $returnInfo Contains details about the operation succes or not
|
|
|
306 |
*/
|
|
|
307 |
function updateKeyword($info) {
|
|
|
308 |
|
|
|
309 |
$keywordId = intval($info['id']);
|
|
|
310 |
|
|
|
311 |
// if keyword exists
|
|
|
312 |
if ($keywordInfo = $this->ctrler->__getKeywordInfo($keywordId)) {
|
|
|
313 |
|
|
|
314 |
$keywordInfo['oldName'] = $keywordInfo['name'];
|
|
|
315 |
|
|
|
316 |
// loop through inputs
|
|
|
317 |
foreach ($info as $key => $val) {
|
|
|
318 |
$keywordInfo[$key] = $val;
|
|
|
319 |
}
|
|
|
320 |
|
|
|
321 |
// update keyword call as api call
|
|
|
322 |
$keywordInfo['searchengines'] = explode(':', $keywordInfo['searchengines']);
|
|
|
323 |
$this->ctrler->spTextKeyword = $this->ctrler->getLanguageTexts('keyword', SP_API_LANG_CODE);
|
|
|
324 |
$return = $this->ctrler->updateKeyword($keywordInfo, true);
|
|
|
325 |
|
|
|
326 |
// if keyword creation is success
|
|
|
327 |
if ($return[0] == 'success') {
|
|
|
328 |
$returnInfo['response'] = 'success';
|
|
|
329 |
$returnInfo['result'] = $return[1];
|
|
|
330 |
} else {
|
|
|
331 |
$returnInfo['response'] = 'Error';
|
|
|
332 |
$returnInfo['error_msg'] = $return[1];
|
|
|
333 |
}
|
|
|
334 |
|
|
|
335 |
} else {
|
|
|
336 |
|
|
|
337 |
$returnInfo['response'] = 'Error';
|
|
|
338 |
$returnInfo['error_msg'] = "The invalid keyword id provided";
|
|
|
339 |
}
|
|
|
340 |
|
|
|
341 |
return $returnInfo;
|
|
|
342 |
|
|
|
343 |
}
|
|
|
344 |
|
|
|
345 |
/**
|
|
|
346 |
* function to delete keyword
|
|
|
347 |
* @param Array $info The input details to process the api
|
|
|
348 |
* $info['id'] The id of the keyword - Mandatory
|
|
|
349 |
* @return Array $returnInfo Contains details about the operation succes or not
|
|
|
350 |
*/
|
|
|
351 |
function deleteKeyword($info) {
|
|
|
352 |
|
|
|
353 |
$keywordId = intval($info['id']);
|
|
|
354 |
|
|
|
355 |
// if keyword exists
|
|
|
356 |
if ($keywordInfo = $this->ctrler->__getKeywordInfo($keywordId)) {
|
|
|
357 |
|
|
|
358 |
// update keyword call as api call
|
|
|
359 |
$this->ctrler->__deleteKeyword($keywordId);
|
|
|
360 |
$returnInfo['response'] = 'success';
|
|
|
361 |
$returnInfo['result'] = "Successfully deleted keyword";
|
|
|
362 |
|
|
|
363 |
} else {
|
|
|
364 |
|
|
|
365 |
$returnInfo['response'] = 'Error';
|
|
|
366 |
$returnInfo['error_msg'] = "The invalid keyword id provided";
|
|
|
367 |
}
|
|
|
368 |
|
|
|
369 |
return $returnInfo;
|
|
|
370 |
|
|
|
371 |
}
|
|
|
372 |
|
|
|
373 |
}
|
|
|
374 |
?>
|