SEO SQUIRRLY™ - Version 10.0.04

Version Description

  • 05/25/2020 =
  • Fix - Audit Term ID in the Audit Page returned an error if post ID wasn't found
  • Fix - Focus Pages audit info to show data in case not all the Focus Pages have valid audits
  • Fix - Show the Google Search Console connection button in Focus Pages when needed
  • Fix - Show the Google Analytics connection button in Focus Pages when needed
  • Fix - Keyword Research speed and increased the number of keyword results
  • Fix - Keyword Research competition info to show it every time
  • Update - Tooltip messages in the Bulk SEO and Focus Pages
Download this release

Release Info

Developer cifi
Plugin Icon 128x128 SEO SQUIRRLY™
Version 10.0.04
Comparing to
See all releases

Code changes from version 9.2.21 to 10.0.04

Files changed (53) hide show
  1. classes/ActionController.php +1 -1
  2. classes/BlockController.php +1 -1
  3. classes/DisplayController.php +2 -3
  4. classes/Error.php +8 -1
  5. classes/FrontController.php +7 -0
  6. classes/RemoteController.php +484 -243
  7. classes/helpers/Sanitize.php +16 -26
  8. classes/helpers/Tools.php +65 -41
  9. config.json +63 -9
  10. config/config.php +3 -2
  11. config/paths.php +2 -4
  12. controllers/Account.php +30 -2
  13. controllers/Api.php +89 -6
  14. controllers/Assistant.php +8 -2
  15. controllers/Audits.php +263 -8
  16. controllers/BulkSeo.php +107 -0
  17. controllers/CheckSeo.php +273 -28
  18. controllers/Cron.php +3 -29
  19. controllers/Dashboard.php +25 -20
  20. controllers/FocusPages.php +241 -111
  21. controllers/Frontend.php +8 -29
  22. controllers/Help.php +1 -0
  23. controllers/Menu.php +89 -24
  24. controllers/Onboarding.php +3 -2
  25. controllers/Overview.php +35 -0
  26. controllers/Patterns.php +1 -0
  27. controllers/Post.php +260 -99
  28. controllers/PostsList.php +21 -3
  29. controllers/Ranking.php +27 -21
  30. controllers/Research.php +80 -88
  31. controllers/SeoSettings.php +116 -233
  32. controllers/Sitemaps.php +9 -5
  33. controllers/Snippet.php +13 -10
  34. core/BlockAssistant.php +1 -0
  35. core/BlockAudits.php +1 -0
  36. core/BlockConnect.php +54 -0
  37. core/BlockFocusPages.php +1 -0
  38. core/BlockJorney.php +16 -20
  39. core/BlockKRFound.php +1 -0
  40. core/BlockKRHistory.php +1 -0
  41. core/BlockKnowledgeBase.php +1 -0
  42. core/BlockRanks.php +1 -0
  43. core/BlockSEOIssues.php +1 -0
  44. core/BlockSearch.php +1 -0
  45. core/BlockStats.php +7 -6
  46. core/BlockSupport.php +1 -0
  47. core/BlockToolbar.php +1 -0
  48. core/Blocklogin.php +25 -31
  49. demo.json +1 -1
  50. languages/squirrly-seo-cs_CZ.mo +0 -0
  51. languages/squirrly-seo-cs_CZ.po +7718 -3366
  52. languages/squirrly-seo-de_DE.mo +0 -0
  53. languages/squirrly-seo-de_DE.po +4121 -2323
classes/ActionController.php CHANGED
@@ -43,7 +43,7 @@ class SQ_Classes_ActionController extends SQ_Classes_FrontController {
43
  */
44
  public function hookHead() {
45
  echo '<script>
46
- var sqQuery = {
47
  "adminurl": "' . admin_url() . '",
48
  "ajaxurl": "' . admin_url('admin-ajax.php') . '",
49
  "adminposturl": "' . admin_url('post.php') . '",
43
  */
44
  public function hookHead() {
45
  echo '<script>
46
+ var sqQuery = {
47
  "adminurl": "' . admin_url() . '",
48
  "ajaxurl": "' . admin_url('admin-ajax.php') . '",
49
  "adminposturl": "' . admin_url('post.php') . '",
classes/BlockController.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
 
3
  /**
4
  * The main class for core blocks
@@ -78,7 +79,6 @@ class SQ_Classes_BlockController {
78
  var __blog_url = "' . get_bloginfo('url') . '";
79
  var __token = "' . SQ_Classes_Helpers_Tools::getOption('sq_api') . '";
80
  var __language = "' . get_bloginfo('language') . '";
81
- var __api_url = "' . _SQ_API_URL_ . '";
82
  var __apiv2_url = "' . _SQ_APIV2_URL_ . '";
83
  </script>';
84
  }
1
  <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
 
4
  /**
5
  * The main class for core blocks
79
  var __blog_url = "' . get_bloginfo('url') . '";
80
  var __token = "' . SQ_Classes_Helpers_Tools::getOption('sq_api') . '";
81
  var __language = "' . get_bloginfo('language') . '";
 
82
  var __apiv2_url = "' . _SQ_APIV2_URL_ . '";
83
  </script>';
84
  }
classes/DisplayController.php CHANGED
@@ -96,7 +96,6 @@ class SQ_Classes_DisplayController {
96
  }
97
  }
98
 
99
-
100
  /**
101
  * return the block content from theme directory
102
  *
@@ -107,7 +106,7 @@ class SQ_Classes_DisplayController {
107
  public function getView($block, $view) {
108
 
109
  try {
110
- $file = _SQ_THEME_DIR_ . $block . '.php';
111
 
112
  if (file_exists($file)) {
113
 
@@ -117,7 +116,7 @@ class SQ_Classes_DisplayController {
117
  }
118
 
119
  } catch (Exception $e) {
120
- SQ_Debug::dump($file, $e->getMessage(), $e->getFile(), $e->getLine());
121
  }
122
  return false;
123
  }
96
  }
97
  }
98
 
 
99
  /**
100
  * return the block content from theme directory
101
  *
106
  public function getView($block, $view) {
107
 
108
  try {
109
+ $file = apply_filters('sq_view', _SQ_THEME_DIR_ . $block . '.php', $block);
110
 
111
  if (file_exists($file)) {
112
 
116
  }
117
 
118
  } catch (Exception $e) {
119
+ // SQ_Debug::dump($file, $e->getMessage(), $e->getFile(), $e->getLine());
120
  }
121
  return false;
122
  }
classes/Error.php CHANGED
@@ -25,6 +25,13 @@ class SQ_Classes_Error extends SQ_Classes_FrontController {
25
  return false;
26
  }
27
 
 
 
 
 
 
 
 
28
  /**
29
  * Show the error in wrodpress
30
  *
@@ -89,7 +96,7 @@ class SQ_Classes_Error extends SQ_Classes_FrontController {
89
  self::showError($error['text'], $error['id']);
90
  }
91
  }
92
- self::$errors = array();
93
  }
94
 
95
  /**
25
  return false;
26
  }
27
 
28
+ /**
29
+ * Clear all the Errors from Squirrly SEO
30
+ */
31
+ public static function clearErrors() {
32
+ self::$errors = array();
33
+ }
34
+
35
  /**
36
  * Show the error in wrodpress
37
  *
96
  self::showError($error['text'], $error['id']);
97
  }
98
  }
99
+ //self::$errors = array();
100
  }
101
 
102
  /**
classes/FrontController.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
 
3
  /**
4
  * The main class for controllers
@@ -132,4 +133,10 @@ class SQ_Classes_FrontController {
132
  */
133
  public function hookHead() { }
134
 
 
 
 
 
 
 
135
  }
1
  <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
 
4
  /**
5
  * The main class for controllers
133
  */
134
  public function hookHead() { }
135
 
136
+ /**
137
+ * Show the notification bar
138
+ */
139
+ public function getNotificationBar(){
140
+ echo $this->getView('Blocks/VersionBar');
141
+ }
142
  }
classes/RemoteController.php CHANGED
@@ -3,59 +3,46 @@
3
  class SQ_Classes_RemoteController {
4
 
5
  public static $cache = array();
6
- public static $apiversion = 1;
7
  public static $apimethod = 'get';
8
 
9
  /**
10
  * Call the Squirrly Cloud Server
11
  * @param string $module
12
- * @param array $params
13
  * @param array $options
14
  * @return string
15
  */
16
- public static function apiCall($module, $params = array(), $options = array()) {
17
  $parameters = "";
18
 
19
- if (SQ_Classes_Helpers_Tools::getOption('sq_api') == '' && $module <> 'login' && $module <> 'register') {
20
- return false;
21
- }
22
-
23
- //predefined args
24
- $args = array(
25
- 'user_url' => get_bloginfo('url'),
26
- 'lang' => get_bloginfo('language'),
27
- 'token' => SQ_Classes_Helpers_Tools::getOption('sq_api'),
28
- 'versq' => (int)str_replace('.', '', SQ_VERSION)
29
- );
30
-
31
  //predefined options
32
  $options = array_merge(
33
  array(
34
  'method' => self::$apimethod,
35
  'sslverify' => SQ_CHECK_SSL,
36
- 'timeout' => 10,
37
  'headers' => array(
38
  'USER-TOKEN' => SQ_Classes_Helpers_Tools::getOption('sq_api'),
39
- 'USER-URL' => get_bloginfo('url'),
40
- 'LANG' => get_bloginfo('language'),
41
  'VERSQ' => (int)str_replace('.', '', SQ_VERSION)
42
  )
43
  ),
44
  $options);
45
 
46
  try {
47
- $args = array_merge($args, $params);
48
-
49
- foreach ($args as $key => $value) {
50
- if ($value <> '') {
51
- $parameters .= ($parameters == "" ? "" : "&") . $key . "=" . urlencode($value);
52
  }
53
  }
54
 
55
  //call it with http to prevent curl issues with ssls
56
- $url = self::cleanUrl(((self::$apiversion == 1) ? _SQ_API_URL_ : _SQ_APIV2_URL_) . $module . "?" . $parameters);
57
 
58
- //echo $url .'<br/>';
59
  if (!isset(self::$cache[md5($url)])) {
60
  if ($options['method'] == 'post') {
61
  $options['body'] = $args;
@@ -130,11 +117,15 @@ class SQ_Classes_RemoteController {
130
 
131
  switch ($method) {
132
  case 'get':
 
133
  unset($options['method']);
 
134
  $response = wp_remote_get($url, $options);
135
  break;
136
  case 'post':
 
137
  unset($options['method']);
 
138
  $response = wp_remote_post($url, $options);
139
  break;
140
  default:
@@ -162,17 +153,17 @@ class SQ_Classes_RemoteController {
162
  return trim($response, '()');
163
  }
164
 
165
- /********************** API CALLs ******************************/
166
  /**
167
  * @param array $args
168
  * @return array|mixed|object|WP_Error
169
  */
170
  public static function connect($args = array()) {
171
- self::$apiversion = 1; //api v2
172
- self::$apimethod = 'get'; //call method
173
- $json = json_decode(self::apiCall('user/connect', $args));
174
 
175
  if (isset($json->error) && $json->error <> '') {
 
176
  if ($json->error == 'invalid_token') {
177
  SQ_Classes_Helpers_Tools::saveOptions('sq_api', false);
178
  }
@@ -195,16 +186,21 @@ class SQ_Classes_RemoteController {
195
  * @return bool|WP_Error
196
  */
197
  public static function login($args = array()) {
198
- self::$apiversion = 1; //api v2
199
- self::$apimethod = 'get'; //call method
200
 
201
- $json = json_decode(self::apiCall('login', $args));
202
 
203
  if (isset($json->error) && $json->error <> '') {
204
  return (new WP_Error('api_error', $json->error));
 
 
205
  }
206
 
207
- return $json;
 
 
 
 
208
  }
209
 
210
  /**
@@ -214,50 +210,87 @@ class SQ_Classes_RemoteController {
214
  * @return bool|WP_Error
215
  */
216
  public static function register($args = array()) {
217
- self::$apiversion = 1; //api v2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
  self::$apimethod = 'get'; //call method
219
 
220
- $json = json_decode(self::apiCall('register', $args));
221
 
222
  if (isset($json->error) && $json->error <> '') {
223
  return (new WP_Error('api_error', $json->error));
 
 
224
  }
225
 
226
- return $json;
 
 
 
 
227
  }
228
 
229
  /**
230
- * Checkin on API v2
231
  *
232
  * @param array $args
233
  * @return bool|WP_Error
234
  */
235
  public static function checkin($args = array()) {
236
- self::$apiversion = 2; //api v2
237
  self::$apimethod = 'get'; //call method
238
 
239
  $json = json_decode(self::apiCall('api/user/checkin', $args));
240
 
241
  if (isset($json->error) && $json->error <> '') {
242
- self::connect(); //connect the website
243
 
 
 
 
 
 
 
 
 
 
 
 
 
244
  return (new WP_Error('api_error', $json->error));
 
 
 
245
  }
246
 
247
- if (isset($json->data)) {
248
- //Save the connections into database
249
- if (isset($json->data->connection_gsc) && isset($json->data->connection_ga)) {
250
- $connect = SQ_Classes_Helpers_Tools::getOption('connect');
251
- $connect['google_analytics'] = $json->data->connection_ga;
252
- $connect['google_search_console'] = $json->data->connection_gsc;
253
- SQ_Debug::dump($connect);
254
- SQ_Classes_Helpers_Tools::saveOptions('connect', $connect);
255
- }
256
 
257
- return $json->data;
 
 
 
 
 
258
  }
259
 
260
- return false;
261
  }
262
 
263
  /**
@@ -265,7 +298,6 @@ class SQ_Classes_RemoteController {
265
  * @return array
266
  */
267
  public static function getStats() {
268
- self::$apiversion = 2; //api v2
269
  self::$apimethod = 'get'; //call method
270
 
271
  $args = $stats = array();
@@ -275,6 +307,8 @@ class SQ_Classes_RemoteController {
275
  self::connect(); //connect the website
276
 
277
  return (new WP_Error('api_error', $json->error));
 
 
278
  }
279
 
280
  if (!isset($json->data)) {
@@ -282,20 +316,15 @@ class SQ_Classes_RemoteController {
282
  }
283
 
284
  $data = $json->data;
285
-
286
  if (isset($data->optimized_articles) && isset($data->average_optimization) && isset($data->kr_research) && isset($data->kr_in_briefcase)
287
  && isset($data->ranked_top) && isset($data->audits_made)) {
288
 
289
- //do not show stats if not optimization is made
290
- if ($data->optimized_articles == 0 && $data->kr_research == 0) {
291
- return false;
292
- }
293
 
294
  //Get last month articles
295
  $stats['all_articles'] = array();
296
  $stats['all_articles']['value'] = ((int)$data->optimized_articles);
297
  $stats['all_articles']['text'] = __('Articles optimized so far', _SQ_PLUGIN_NAME_);
298
- $stats['all_articles']['link'] = SQ_Classes_Helpers_Tools::getAdminUrl('post-new.php');
299
  $stats['all_articles']['linktext'] = __('add post', _SQ_PLUGIN_NAME_);
300
 
301
  //Get last month articles
@@ -308,7 +337,7 @@ class SQ_Classes_RemoteController {
308
  //Get all keyword researched
309
  $stats['all_researches'] = array();
310
  $stats['all_researches']['value'] = (int)$data->kr_research;
311
- $stats['all_researches']['text'] = __('All Keyword Researches performed for all websites', _SQ_PLUGIN_NAME_);
312
  $stats['all_researches']['link'] = SQ_Classes_Helpers_Tools::getAdminUrl('sq_research');
313
  $stats['all_researches']['linktext'] = __('do research', _SQ_PLUGIN_NAME_);
314
 
@@ -338,37 +367,67 @@ class SQ_Classes_RemoteController {
338
  return $stats;
339
  }
340
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
341
 
342
  /**
343
  * Get audits from API
 
344
  * @param array $args
345
- * @return array|bool
346
  */
347
  public static function getBlogAudits($args = array()) {
348
- self::$apiversion = 1; //api v1
349
  self::$apimethod = 'get'; //call method
350
 
351
- $json = json_decode(self::apiCall('audit/get-blog-audits', $args));
 
 
 
 
 
 
352
 
353
- if (isset($json->audits)) {
354
- return $json->audits;
355
  }
356
 
357
- return false;
358
  }
359
 
360
  /******************************** BRIEFCASE *********************/
361
  public static function getBriefcase($args = array()) {
362
- self::$apiversion = 2; //api v1
363
  self::$apimethod = 'get'; //call method
364
 
365
  $json = json_decode(self::apiCall('api/briefcase/get', $args));
366
 
367
  if (isset($json->error) && $json->error <> '') {
368
  return (new WP_Error('api_error', $json->error));
 
 
369
  }
370
 
371
- if (isset($json->data)) {
372
  return $json->data;
373
  }
374
 
@@ -376,25 +435,24 @@ class SQ_Classes_RemoteController {
376
  }
377
 
378
  public static function addBriefcaseKeyword($args = array()) {
379
- self::$apiversion = 2; //api v1
380
  self::$apimethod = 'post'; //call method
381
 
382
  $json = json_decode(self::apiCall('api/briefcase/add', $args));
383
 
384
  if (isset($json->error) && $json->error <> '') {
385
  return (new WP_Error('api_error', $json->error));
 
 
386
  }
387
 
388
- if (isset($json->data)) {
389
  return $json->data;
390
  }
391
 
392
-
393
  return false;
394
  }
395
 
396
  public static function removeBriefcaseKeyword($args = array()) {
397
- self::$apiversion = 2; //api v1
398
  self::$apimethod = 'post'; //call method
399
 
400
  if ($json = json_decode(self::apiCall('api/briefcase/hide', $args))) {
@@ -405,7 +463,6 @@ class SQ_Classes_RemoteController {
405
  }
406
 
407
  public static function getBriefcaseStats($args = array()) {
408
- self::$apiversion = 2; //api v2
409
  self::$apimethod = 'get'; //call method
410
 
411
  $json = json_decode(self::apiCall('api/briefcase/stats', $args));
@@ -414,9 +471,11 @@ class SQ_Classes_RemoteController {
414
  self::connect(); //connect the website
415
 
416
  return (new WP_Error('api_error', $json->error));
 
 
417
  }
418
 
419
- if (isset($json->data)) {
420
  return $json->data;
421
  }
422
 
@@ -424,16 +483,17 @@ class SQ_Classes_RemoteController {
424
  }
425
 
426
  public static function saveBriefcaseKeywordLabel($args = array()) {
427
- self::$apiversion = 2; //api v1
428
  self::$apimethod = 'post'; //call method
429
 
430
  $json = json_decode(self::apiCall('api/briefcase/label/keyword', $args));
431
 
432
  if (isset($json->error) && $json->error <> '') {
433
  return (new WP_Error('api_error', $json->error));
 
 
434
  }
435
 
436
- if (isset($json->data)) {
437
  return $json->data;
438
  }
439
 
@@ -442,16 +502,17 @@ class SQ_Classes_RemoteController {
442
 
443
 
444
  public static function addBriefcaseLabel($args = array()) {
445
- self::$apiversion = 2; //api v1
446
  self::$apimethod = 'post'; //call method
447
 
448
  $json = json_decode(self::apiCall('api/briefcase/label/add', $args));
449
 
450
  if (isset($json->error) && $json->error <> '') {
451
  return (new WP_Error('api_error', $json->error));
 
 
452
  }
453
 
454
- if (isset($json->data)) {
455
  return $json->data;
456
  }
457
 
@@ -459,16 +520,17 @@ class SQ_Classes_RemoteController {
459
  }
460
 
461
  public static function saveBriefcaseLabel($args = array()) {
462
- self::$apiversion = 2; //api v1
463
  self::$apimethod = 'post'; //call method
464
 
465
  $json = json_decode(self::apiCall('api/briefcase/label/save', $args));
466
 
467
  if (isset($json->error) && $json->error <> '') {
468
  return (new WP_Error('api_error', $json->error));
 
 
469
  }
470
 
471
- if (isset($json->data)) {
472
  return $json->data;
473
  }
474
 
@@ -476,16 +538,17 @@ class SQ_Classes_RemoteController {
476
  }
477
 
478
  public static function removeBriefcaseLabel($args = array()) {
479
- self::$apiversion = 2; //api v1
480
  self::$apimethod = 'post'; //call method
481
 
482
  $json = json_decode(self::apiCall('api/briefcase/label/delete', $args));
483
 
484
  if (isset($json->error) && $json->error <> '') {
485
  return (new WP_Error('api_error', $json->error));
 
 
486
  }
487
 
488
- if (isset($json->data)) {
489
  return $json->data;
490
  }
491
 
@@ -495,60 +558,84 @@ class SQ_Classes_RemoteController {
495
  /******************************** KEYWORD RESEARCH ****************/
496
 
497
  public static function getKROthers($args = array()) {
498
- self::$apiversion = 1; //api v1
499
  self::$apimethod = 'get'; //call method
500
 
501
- if ($json = json_decode(self::apiCall('kr/other', $args))) {
502
 
503
- if (isset($json->error) && $json->error <> '') {
504
- return (new WP_Error('api_error', $json->error));
505
- }
 
 
506
 
507
- return $json;
 
508
  }
509
 
510
  return false;
511
  }
512
 
513
  /**
514
- * Get Keyword Research Suggestion
515
  *
516
  * @param array $args
517
  * @return array|bool|mixed|object|WP_Error
518
  */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
519
  public static function getKRSuggestion($args = array()) {
520
- self::$apiversion = 1; //api v1
521
  self::$apimethod = 'get'; //call method
522
 
523
- if ($json = json_decode(self::apiCall('kr/suggestion', $args, array('timeout' => 300)))) {
524
 
525
- if (isset($json->error) && $json->error <> '') {
526
- return (new WP_Error('api_error', $json->error));
527
- }
 
 
528
 
529
- return $json;
 
530
  }
531
 
532
  return false;
533
  }
534
 
 
535
  /**
536
  * Get Keyword Research History
537
  * @param array $args
538
  * @return array|bool|mixed|object|WP_Error
539
  */
540
  public static function getKRHistory($args = array()) {
541
- self::$apiversion = 1; //api v1
542
  self::$apimethod = 'get'; //call method
543
 
544
- $json = json_decode(self::apiCall('kr/history/json/1', $args));
545
 
546
  if (isset($json->error) && $json->error <> '') {
547
  return (new WP_Error('api_error', $json->error));
 
 
548
  }
549
 
550
- if (isset($json->json)) {
551
- return $json->json;
552
  }
553
 
554
  return false;
@@ -560,17 +647,18 @@ class SQ_Classes_RemoteController {
560
  * @return bool|WP_Error
561
  */
562
  public static function getKrFound($args = array()) {
563
- self::$apiversion = 1; //api v1
564
  self::$apimethod = 'get'; //call method
565
 
566
- $json = json_decode(self::apiCall('kr/found', $args));
567
 
568
  if (isset($json->error) && $json->error <> '') {
569
  return (new WP_Error('api_error', $json->error));
 
 
570
  }
571
 
572
- if (isset($json->json)) {
573
- return $json->json;
574
  }
575
 
576
  return false;
@@ -582,18 +670,18 @@ class SQ_Classes_RemoteController {
582
  * @return bool|WP_Error
583
  */
584
  public static function getKrCountries($args = array()) {
585
- self::$apiversion = 1; //api v1
586
  self::$apimethod = 'get'; //call method
587
 
588
- $args['json'] = true;
589
- $json = json_decode(self::apiCall('kr/countries', $args));
590
 
591
  if (isset($json->error) && $json->error <> '') {
592
  return (new WP_Error('api_error', $json->error));
 
 
593
  }
594
 
595
- if (isset($json->json)) {
596
- return $json->json;
597
  }
598
 
599
  return false;
@@ -602,14 +690,26 @@ class SQ_Classes_RemoteController {
602
  /******************** WP Posts ***************************/
603
  /**
604
  * Save the post status on API
 
605
  * @param array $args
606
- * @return bool
607
  */
608
  public static function savePost($args = array()) {
609
- self::$apiversion = 1; //api v1
610
- self::$apimethod = 'get'; //call method
 
611
 
612
- return json_decode(self::apiCall('seo/post', $args));
 
 
 
 
 
 
 
 
 
 
613
 
614
  }
615
 
@@ -620,21 +720,21 @@ class SQ_Classes_RemoteController {
620
  * @return array|mixed|object
621
  */
622
  public static function getPostOptimization($args = array()) {
623
- self::$apiversion = 1; //api v1
624
 
625
- return json_decode(self::apiCall('seo/get-optimization', $args));
626
- }
627
 
628
- /**
629
- * Update the post status on API
630
- * @param array $args
631
- * @return bool
632
- */
633
- public static function updatePost($args = array()) {
634
- self::$apiversion = 1; //api v1
635
- self::$apimethod = 'get'; //call method
636
 
637
- return json_decode(self::apiCall('seo/update', $args));
 
 
 
 
638
 
639
  }
640
 
@@ -646,16 +746,17 @@ class SQ_Classes_RemoteController {
646
  * @return bool|WP_Error
647
  */
648
  public static function addSerpKeyword($args = array()) {
649
- self::$apiversion = 2; //api v2
650
  self::$apimethod = 'post'; //call method
651
 
652
  $json = json_decode(self::apiCall('api/briefcase/serp', $args));
653
 
654
  if (isset($json->error) && $json->error <> '') {
655
  return (new WP_Error('api_error', $json->error));
 
 
656
  }
657
 
658
- if (isset($json->data)) {
659
  return $json->data;
660
  }
661
 
@@ -668,16 +769,17 @@ class SQ_Classes_RemoteController {
668
  * @return bool|WP_Error
669
  */
670
  public static function deleteSerpKeyword($args = array()) {
671
- self::$apiversion = 2; //api v2
672
  self::$apimethod = 'post'; //call method
673
 
674
  $json = json_decode(self::apiCall('api/briefcase/serp-delete', $args));
675
 
676
  if (isset($json->error) && $json->error <> '') {
677
  return (new WP_Error('api_error', $json->error));
 
 
678
  }
679
 
680
- if (isset($json->data)) {
681
  return $json->data;
682
  }
683
 
@@ -690,18 +792,20 @@ class SQ_Classes_RemoteController {
690
  * @return bool|WP_Error
691
  */
692
  public static function getRanksStats($args = array()) {
693
- self::$apiversion = 2; //api v2
694
  self::$apimethod = 'get'; //call method
695
 
696
  $json = json_decode(self::apiCall('api/serp/stats', $args));
697
 
698
  if (isset($json->error) && $json->error <> '') {
699
  return (new WP_Error('api_error', $json->error));
 
 
700
  }
701
 
702
- if (isset($json->data)) {
703
  return $json->data;
704
  }
 
705
  return false;
706
  }
707
 
@@ -711,18 +815,20 @@ class SQ_Classes_RemoteController {
711
  * @return bool|WP_Error
712
  */
713
  public static function getRanks($args = array()) {
714
- self::$apiversion = 2; //api v2
715
  self::$apimethod = 'get'; //call method
716
 
717
  $json = json_decode(self::apiCall('api/serp/get-ranks', $args));
718
 
719
  if (isset($json->error) && $json->error <> '') {
720
  return (new WP_Error('api_error', $json->error));
 
 
721
  }
722
 
723
- if (isset($json->data)) {
724
  return $json->data;
725
  }
 
726
  return false;
727
  }
728
 
@@ -733,20 +839,21 @@ class SQ_Classes_RemoteController {
733
  * @return bool|WP_Error
734
  */
735
  public static function checkPostRank($args = array()) {
736
- self::$apiversion = 2; //api v2
737
  self::$apimethod = 'get'; //call method
738
 
739
  $json = json_decode(self::apiCall('api/serp/refresh', $args));
740
 
741
  if (isset($json->error) && $json->error <> '') {
742
  return (new WP_Error('api_error', $json->error));
 
 
743
  }
744
 
745
- if (isset($json->data)) {
746
  return $json->data;
747
  }
748
 
749
- return true;
750
  }
751
 
752
  /******************** FOCUS PAGES ***********************/
@@ -758,18 +865,20 @@ class SQ_Classes_RemoteController {
758
  * @return SQ_Models_Domain_FocusPage|WP_Error|false
759
  */
760
  public static function getFocusPages($args = array()) {
761
- self::$apiversion = 2; //api v2
762
  self::$apimethod = 'get'; //call method
763
 
764
  $json = json_decode(self::apiCall('api/posts/focus', $args));
765
 
766
  if (isset($json->error) && $json->error <> '') {
767
  return (new WP_Error('api_error', $json->error));
 
 
768
  }
769
 
770
- if (isset($json->data)) {
771
  return $json->data;
772
  }
 
773
  return false;
774
  }
775
 
@@ -780,40 +889,19 @@ class SQ_Classes_RemoteController {
780
  * @return bool|WP_Error
781
  */
782
  public static function getFocusAudits($args = array()) {
783
- self::$apiversion = 2; //api v2
784
  self::$apimethod = 'get'; //call method
785
 
786
  $json = json_decode(self::apiCall('api/audits/focus', $args));
787
 
788
  if (isset($json->error) && $json->error <> '') {
789
  return (new WP_Error('api_error', $json->error));
 
 
790
  }
791
 
792
- if (isset($json->data) && !empty($json->data)) {
793
  return $json->data;
794
  }
795
- return false;
796
- }
797
-
798
- /**
799
- * Get the audit for a specific page
800
- * @param array $args
801
- * @return array|bool|mixed|object|WP_Error
802
- */
803
- public static function getSeoAudit($args = array()) {
804
- self::$apiversion = 2; //api v2
805
- self::$apimethod = 'get'; //call method
806
-
807
- if ($json_audit = json_decode(self::apiCall('api/audits/old', $args))) {
808
-
809
- if (isset($json_audit->error) && $json_audit->error <> '') {
810
- return (new WP_Error($json_audit->error));
811
- }
812
-
813
- if (isset($json_audit->data)) {
814
- return json_decode(json_encode($json_audit->data));
815
- }
816
- }
817
 
818
  return false;
819
  }
@@ -824,35 +912,38 @@ class SQ_Classes_RemoteController {
824
  * @return bool|WP_Error
825
  */
826
  public static function addFocusPage($args = array()) {
827
- self::$apiversion = 2; //api v2
828
  self::$apimethod = 'post'; //post call
829
 
830
- if ($json = json_decode(self::apiCall('api/posts/set-focus', $args))) {
831
 
832
- if (isset($json->error) && $json->error <> '') {
833
- return (new WP_Error('api_error', $json->error));
834
- }
 
 
835
 
836
- if (isset($json->data)) {
837
- return $json->data;
838
- }
839
  }
 
840
  return false;
841
  }
842
 
843
  public static function updateFocusPage($args = array()) {
844
- self::$apiversion = 2; //api v2
845
  self::$apimethod = 'post'; //post call
846
 
847
- if ($json = json_decode(self::apiCall('api/posts/update-focus', $args))) {
848
- if (isset($json->error) && $json->error <> '') {
849
- return (new WP_Error('api_error', $json->error));
850
- }
851
 
852
- if (isset($json->data)) {
853
- return $json->data;
854
- }
 
855
  }
 
 
 
 
 
856
  return false;
857
  }
858
 
@@ -862,115 +953,270 @@ class SQ_Classes_RemoteController {
862
  * @return bool|WP_Error
863
  */
864
  public static function deleteFocusPage($args = array()) {
865
- self::$apiversion = 2; //api v2
866
  self::$apimethod = 'post'; //post call
867
 
868
  if (isset($args['user_post_id']) && $args['user_post_id'] > 0) {
869
- if ($json = json_decode(self::apiCall('api/posts/remove-focus/' . $args['user_post_id']))) {
870
 
871
- if (isset($json->error) && $json->error <> '') {
872
- return (new WP_Error('api_error', $json->error));
873
- }
874
-
875
- if (isset($json->data)) {
876
- return $json->data;
877
- }
878
  }
 
 
879
  }
 
880
  return false;
881
  }
882
 
883
  /**************************************** CONNECTIONS */
884
  /**
885
  * Disconnect Google Analytics account
886
- * @param array $args
887
  * @return bool|WP_Error
888
  */
889
- public static function revokeGaConnection($args = array()) {
890
- self::$apiversion = 2; //api v2
891
  self::$apimethod = 'get'; //post call
892
 
893
- if ($json = json_decode(self::apiCall('api/ga/revoke'))) {
894
- if (isset($json->error) && $json->error <> '') {
895
- return (new WP_Error('api_error', $json->error));
896
- }
897
 
898
- if (isset($json->data)) {
899
- return $json->data;
900
- }
 
 
 
 
 
901
  }
902
 
903
  return false;
904
  }
905
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
906
 
907
  /**
908
  * Disconnect Google Search Console account
909
- * @param array $args
910
  * @return bool|WP_Error
911
  */
912
- public static function revokeGscConnection($args = array()) {
913
- self::$apiversion = 2; //api v2
914
  self::$apimethod = 'get'; //post call
915
 
916
- if ($json = json_decode(self::apiCall('api/gsc/revoke'))) {
917
- if (isset($json->error) && $json->error <> '') {
918
- return (new WP_Error('api_error', $json->error));
919
- }
920
 
921
- if (isset($json->data)) {
922
- return $json->data;
923
- }
 
 
 
 
 
924
  }
925
 
926
  return false;
 
927
  }
928
 
929
  public static function syncGSC($args = array()) {
930
- self::$apiversion = 2; //api v2
931
  self::$apimethod = 'get'; //post call
932
 
 
933
 
934
- if ($json = json_decode(self::apiCall('api/gsc/sync/kr', $args))) {
 
 
 
 
935
 
936
- if (isset($json->error) && $json->error <> '') {
937
- return (new WP_Error('api_error', $json->error));
938
- }
939
 
940
- if (isset($json->data)) {
941
- return $json->data;
942
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
943
  }
944
 
945
  return false;
 
946
  }
947
 
 
948
 
949
- /******************** OTHERS *****************************/
950
- public static function crawlURL($args = array()) {
951
- self::$apiversion = 2; //api v2
952
- self::$apimethod = 'get'; //post call
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
953
 
 
 
 
 
 
 
 
954
 
955
- if ($json = json_decode(self::apiCall('api/url/crawl', $args, array('timeout' => 60)))) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
956
 
957
  if (isset($json->error) && $json->error <> '') {
958
  return (new WP_Error('api_error', $json->error));
 
 
959
  }
960
 
961
- if (isset($json->data)) {
962
  return $json->data;
963
  }
964
- }
965
 
 
966
  return false;
967
  }
968
 
 
969
  public static function saveSettings($args) {
970
- self::$apiversion = 1; //api v1
 
 
 
 
 
 
 
 
 
 
971
  self::$apimethod = 'get'; //call method
972
 
973
- self::apiCall('user/settings', array('settings' => json_encode($args)));
 
 
 
 
 
 
 
 
 
 
 
 
974
  }
975
 
976
  /**
@@ -978,27 +1224,35 @@ class SQ_Classes_RemoteController {
978
  */
979
  public static function loadJsVars() {
980
  global $post;
 
 
981
  $sq_postID = (isset($post->ID) ? $post->ID : 0);
982
 
 
 
 
 
 
 
983
  echo '<script>
984
  var SQ_DEBUG = ' . (int)SQ_DEBUG . ';
985
  (function($){
986
  $.sq_config = {
987
  sq_use: ' . (int)SQ_Classes_Helpers_Tools::getOption('sq_use') . ',
988
  sq_version: "' . SQ_VERSION . '",
 
989
  token: "' . SQ_Classes_Helpers_Tools::getOption('sq_api') . '",
990
  sq_baseurl: "' . _SQ_STATIC_API_URL_ . '",
991
  sq_uri: "' . SQ_URI . '",
992
- sq_apiurl: "' . str_replace('/sq', '', _SQ_API_URL_) . '",
993
- user_url: "' . get_bloginfo('url') . '",
994
- language: "' . get_bloginfo('language') . '",
 
995
  sq_keywordtag: ' . (int)SQ_Classes_Helpers_Tools::getOption('sq_keywordtag') . ',
996
- sq_seoversion: "' . ((int)SQ_Classes_Helpers_Tools::getOption('sq_sla') + 1) . '",
997
- keyword_information: ' . (int)SQ_Classes_Helpers_Tools::getOption('sq_keyword_information') . ',
998
  frontend_css: "' . _SQ_ASSETS_URL_ . 'css/frontend' . (SQ_DEBUG ? '' : '.min') . '.css",
999
  postID: "' . $sq_postID . '",
1000
  prevNonce: "' . wp_create_nonce('post_preview_' . $sq_postID) . '",
1001
- __infotext: ["' . __('Recent discussions:', _SQ_PLUGIN_NAME_) . '", "' . __('SEO Search Volume:', _SQ_PLUGIN_NAME_) . '", "' . __('Competition:', _SQ_PLUGIN_NAME_) . '", "' . __('Trend:', _SQ_PLUGIN_NAME_) . '"],
1002
  __keyword: "' . __('Keyword:', _SQ_PLUGIN_NAME_) . '",
1003
  __date: "' . __('date', _SQ_PLUGIN_NAME_) . '",
1004
  __saved: "' . __('Saved!', _SQ_PLUGIN_NAME_) . '",
@@ -1010,19 +1264,12 @@ class SQ_Classes_RemoteController {
1010
  __notrelevant: "' . __('Not relevant?', _SQ_PLUGIN_NAME_) . '",
1011
  __insertparagraph: "' . __('Insert in your article', _SQ_PLUGIN_NAME_) . '",
1012
  __ajaxerror: "' . __(':( An error occurred while processing your request. Please try again', _SQ_PLUGIN_NAME_) . '",
1013
- __krerror: "' . __('Keyword Research takes too long to get the results. Click to try again', _SQ_PLUGIN_NAME_) . '",
1014
  __nofound: "' . __('No results found!', _SQ_PLUGIN_NAME_) . '",
1015
- __morewords: "' . __('Enter one more word to find relevant results', _SQ_PLUGIN_NAME_) . '",
1016
- __toolong: "' . __("It's taking too long to check this keyword", _SQ_PLUGIN_NAME_) . '",
1017
- __doresearch: "' . __('Do a research!', _SQ_PLUGIN_NAME_) . '",
1018
- __morekeywords: "' . __('Do more research!', _SQ_PLUGIN_NAME_) . '",
1019
  __sq_photo_copyright: "' . __('[ ATTRIBUTE: Please check: %s to find out how to attribute this image ]', _SQ_PLUGIN_NAME_) . '",
1020
  __has_attributes: "' . __('Has creative commons attributes', _SQ_PLUGIN_NAME_) . '",
1021
  __no_attributes: "' . __('No known copyright restrictions', _SQ_PLUGIN_NAME_) . '",
1022
  __noopt: "' . __('You haven`t used Squirrly SEO to optimize your article. Do you want to optimize for a keyword before publishing?', _SQ_PLUGIN_NAME_) . '",
1023
- __limit_exceeded: "' . __('Keyword Research limit exceeded', _SQ_PLUGIN_NAME_) . '",
1024
  __subscription_expired: "' . __('Your Subscription has Expired', _SQ_PLUGIN_NAME_) . '",
1025
- __add_keywords: "' . __('Add 20 Keyword Researches', _SQ_PLUGIN_NAME_) . '",
1026
  __no_briefcase: "' . __('There are no keywords saved in briefcase yet', _SQ_PLUGIN_NAME_) . '",
1027
  __fulloptimized: "' . __('Congratulations! Your article is 100% optimized!', _SQ_PLUGIN_NAME_) . '",
1028
  __toomanytimes: "' . __('appears too many times. Try to remove %s of them', _SQ_PLUGIN_NAME_) . '",
@@ -1038,8 +1285,9 @@ class SQ_Classes_RemoteController {
1038
  __addminimumwords: "' . __('write %s more words to start calculating', _SQ_PLUGIN_NAME_) . '",
1039
  __add_to_briefcase: "' . __('Add to Briefcase', _SQ_PLUGIN_NAME_) . '",
1040
  __add_keyword_briefcase: "' . __('Add Keyword to Briefcase', _SQ_PLUGIN_NAME_) . '",
1041
- __usekeyword: "' . __('Use Keyword', _SQ_PLUGIN_NAME_) . '",
1042
- __new_post_title: "' . __('Auto Draft') . '"
 
1043
  };
1044
 
1045
 
@@ -1065,11 +1313,4 @@ class SQ_Classes_RemoteController {
1065
 
1066
  }
1067
 
1068
- public static function versionOne() {
1069
- return 1;
1070
- }
1071
-
1072
- public static function versionTwo() {
1073
- return 2;
1074
- }
1075
  }
3
  class SQ_Classes_RemoteController {
4
 
5
  public static $cache = array();
 
6
  public static $apimethod = 'get';
7
 
8
  /**
9
  * Call the Squirrly Cloud Server
10
  * @param string $module
11
+ * @param array $args
12
  * @param array $options
13
  * @return string
14
  */
15
+ public static function apiCall($module, $args = array(), $options = array()) {
16
  $parameters = "";
17
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  //predefined options
19
  $options = array_merge(
20
  array(
21
  'method' => self::$apimethod,
22
  'sslverify' => SQ_CHECK_SSL,
23
+ 'timeout' => 15,
24
  'headers' => array(
25
  'USER-TOKEN' => SQ_Classes_Helpers_Tools::getOption('sq_api'),
26
+ 'USER-URL' => apply_filters('sq_homeurl', get_bloginfo('url')),
27
+ 'LANG' => apply_filters('sq_language', get_bloginfo('language')),
28
  'VERSQ' => (int)str_replace('.', '', SQ_VERSION)
29
  )
30
  ),
31
  $options);
32
 
33
  try {
34
+ if (!empty($args)) {
35
+ foreach ($args as $key => $value) {
36
+ if ($value <> '') {
37
+ $parameters .= ($parameters == "" ? "" : "&") . $key . "=" . urlencode($value);
38
+ }
39
  }
40
  }
41
 
42
  //call it with http to prevent curl issues with ssls
43
+ $url = self::cleanUrl(_SQ_APIV2_URL_ . $module . "?" . $parameters);
44
 
45
+ //print_R($options) . '<br>';echo $url . '<br>';exit();
46
  if (!isset(self::$cache[md5($url)])) {
47
  if ($options['method'] == 'post') {
48
  $options['body'] = $args;
117
 
118
  switch ($method) {
119
  case 'get':
120
+ //not accepted as option
121
  unset($options['method']);
122
+
123
  $response = wp_remote_get($url, $options);
124
  break;
125
  case 'post':
126
+ //not accepted as option
127
  unset($options['method']);
128
+
129
  $response = wp_remote_post($url, $options);
130
  break;
131
  default:
153
  return trim($response, '()');
154
  }
155
 
156
+ /********************** USER ******************************/
157
  /**
158
  * @param array $args
159
  * @return array|mixed|object|WP_Error
160
  */
161
  public static function connect($args = array()) {
162
+ self::$apimethod = 'post'; //call method
163
+ $json = json_decode(self::apiCall('api/user/connect', $args));
 
164
 
165
  if (isset($json->error) && $json->error <> '') {
166
+
167
  if ($json->error == 'invalid_token') {
168
  SQ_Classes_Helpers_Tools::saveOptions('sq_api', false);
169
  }
186
  * @return bool|WP_Error
187
  */
188
  public static function login($args = array()) {
189
+ self::$apimethod = 'post'; //call method
 
190
 
191
+ $json = json_decode(self::apiCall('api/user/login', $args));
192
 
193
  if (isset($json->error) && $json->error <> '') {
194
  return (new WP_Error('api_error', $json->error));
195
+ } elseif (!isset($json->data)) {
196
+ return (new WP_Error('api_error', 'no_data'));
197
  }
198
 
199
+ if (!empty($json->data)) {
200
+ return $json->data;
201
+ }
202
+
203
+ return false;
204
  }
205
 
206
  /**
210
  * @return bool|WP_Error
211
  */
212
  public static function register($args = array()) {
213
+ self::$apimethod = 'post'; //call method
214
+
215
+ $json = json_decode(self::apiCall('api/user/register', $args));
216
+
217
+ if (isset($json->error) && $json->error <> '') {
218
+ return (new WP_Error('api_error', $json->error));
219
+ } elseif (!isset($json->data)) {
220
+ return (new WP_Error('api_error', 'no_data'));
221
+ }
222
+
223
+ if (!empty($json->data)) {
224
+ return $json->data;
225
+ }
226
+
227
+ return false;
228
+ }
229
+
230
+ public static function getCloudToken($args = array()) {
231
  self::$apimethod = 'get'; //call method
232
 
233
+ $json = json_decode(self::apiCall('api/user/token', $args));
234
 
235
  if (isset($json->error) && $json->error <> '') {
236
  return (new WP_Error('api_error', $json->error));
237
+ } elseif (!isset($json->data)) {
238
+ return (new WP_Error('api_error', 'no_data'));
239
  }
240
 
241
+ if (!empty($json->data)) {
242
+ return $json->data;
243
+ }
244
+
245
+ return false;
246
  }
247
 
248
  /**
249
+ * User Checkin
250
  *
251
  * @param array $args
252
  * @return bool|WP_Error
253
  */
254
  public static function checkin($args = array()) {
 
255
  self::$apimethod = 'get'; //call method
256
 
257
  $json = json_decode(self::apiCall('api/user/checkin', $args));
258
 
259
  if (isset($json->error) && $json->error <> '') {
 
260
 
261
+ //prevent throttling on API
262
+ if ($json->error == 'too_many_requests') {
263
+ SQ_Classes_Error::setError(__("Too many API attempts, please slow down the request.", _SQ_PLUGIN_NAME_));
264
+ SQ_Classes_Error::hookNotices();
265
+ return (new WP_Error('api_error', $json->error));
266
+ } elseif ($json->error == 'maintenance') {
267
+ SQ_Classes_Error::setError(__("Squirrly Cloud is down for a bit of maintenance right now. But we'll be back in a minute.", _SQ_PLUGIN_NAME_));
268
+ SQ_Classes_Error::hookNotices();
269
+ return (new WP_Error('maintenance', $json->error));
270
+ }
271
+
272
+ self::connect(); //connect the website
273
  return (new WP_Error('api_error', $json->error));
274
+
275
+ } elseif (!isset($json->data)) {
276
+ return (new WP_Error('api_error', 'no_data'));
277
  }
278
 
279
+ if (isset($json->data->offer) && $json->data->offer <> '') {
280
+ SQ_Classes_Helpers_Tools::saveOptions('sq_offer', $json->data->offer);
281
+ } else {
282
+ SQ_Classes_Helpers_Tools::saveOptions('sq_offer', false);
283
+ }
 
 
 
 
284
 
285
+ //Save the connections into database
286
+ if (isset($json->data->connection_gsc) && isset($json->data->connection_ga)) {
287
+ $connect = SQ_Classes_Helpers_Tools::getOption('connect');
288
+ $connect['google_analytics'] = $json->data->connection_ga;
289
+ $connect['google_search_console'] = $json->data->connection_gsc;
290
+ SQ_Classes_Helpers_Tools::saveOptions('connect', $connect);
291
  }
292
 
293
+ return $json->data;
294
  }
295
 
296
  /**
298
  * @return array
299
  */
300
  public static function getStats() {
 
301
  self::$apimethod = 'get'; //call method
302
 
303
  $args = $stats = array();
307
  self::connect(); //connect the website
308
 
309
  return (new WP_Error('api_error', $json->error));
310
+ } elseif (!isset($json->data)) {
311
+ return (new WP_Error('api_error', 'no_data'));
312
  }
313
 
314
  if (!isset($json->data)) {
316
  }
317
 
318
  $data = $json->data;
 
319
  if (isset($data->optimized_articles) && isset($data->average_optimization) && isset($data->kr_research) && isset($data->kr_in_briefcase)
320
  && isset($data->ranked_top) && isset($data->audits_made)) {
321
 
 
 
 
 
322
 
323
  //Get last month articles
324
  $stats['all_articles'] = array();
325
  $stats['all_articles']['value'] = ((int)$data->optimized_articles);
326
  $stats['all_articles']['text'] = __('Articles optimized so far', _SQ_PLUGIN_NAME_);
327
+ $stats['all_articles']['link'] = SQ_Classes_Helpers_Tools::getAdminUrl('sq_assistant', 'assistant');
328
  $stats['all_articles']['linktext'] = __('add post', _SQ_PLUGIN_NAME_);
329
 
330
  //Get last month articles
337
  //Get all keyword researched
338
  $stats['all_researches'] = array();
339
  $stats['all_researches']['value'] = (int)$data->kr_research;
340
+ $stats['all_researches']['text'] = __('Keyword Researches', _SQ_PLUGIN_NAME_);
341
  $stats['all_researches']['link'] = SQ_Classes_Helpers_Tools::getAdminUrl('sq_research');
342
  $stats['all_researches']['linktext'] = __('do research', _SQ_PLUGIN_NAME_);
343
 
367
  return $stats;
368
  }
369
 
370
+ /******************************** NOTIFICATIONS *********************/
371
+ /**
372
+ * Get the Notifications from API for the current blog
373
+ * @return array|WP_Error
374
+ */
375
+ public static function getNotifications() {
376
+ self::$apimethod = 'get'; //call method
377
+
378
+ $notifications = array();
379
+ if ($json = json_decode(self::apiCall('api/audits/notifications', array()))) {
380
+
381
+ if (isset($json->error) && $json->error <> '') {
382
+ return (new WP_Error('api_error', $json->error));
383
+ } elseif (!isset($json->data)) {
384
+ return (new WP_Error('api_error', 'no_data'));
385
+ }
386
+
387
+ $notifications = $json->data;
388
+
389
+ }
390
+
391
+ return $notifications;
392
+ }
393
 
394
  /**
395
  * Get audits from API
396
+ *
397
  * @param array $args
398
+ * @return bool|WP_Error
399
  */
400
  public static function getBlogAudits($args = array()) {
 
401
  self::$apimethod = 'get'; //call method
402
 
403
+ $json = json_decode(self::apiCall('api/audits/get-audits', $args));
404
+
405
+ if (isset($json->error) && $json->error <> '') {
406
+ return (new WP_Error('api_error', $json->error));
407
+ } elseif (!isset($json->data)) {
408
+ return (new WP_Error('api_error', 'no_data'));
409
+ }
410
 
411
+ if (!isset($json->data->audits)) {
412
+ return (new WP_Error('api_error', 'no_data'));
413
  }
414
 
415
+ return $json->data->audits;
416
  }
417
 
418
  /******************************** BRIEFCASE *********************/
419
  public static function getBriefcase($args = array()) {
 
420
  self::$apimethod = 'get'; //call method
421
 
422
  $json = json_decode(self::apiCall('api/briefcase/get', $args));
423
 
424
  if (isset($json->error) && $json->error <> '') {
425
  return (new WP_Error('api_error', $json->error));
426
+ } elseif (!isset($json->data)) {
427
+ return (new WP_Error('api_error', 'no_data'));
428
  }
429
 
430
+ if (!empty($json->data)) {
431
  return $json->data;
432
  }
433
 
435
  }
436
 
437
  public static function addBriefcaseKeyword($args = array()) {
 
438
  self::$apimethod = 'post'; //call method
439
 
440
  $json = json_decode(self::apiCall('api/briefcase/add', $args));
441
 
442
  if (isset($json->error) && $json->error <> '') {
443
  return (new WP_Error('api_error', $json->error));
444
+ } elseif (!isset($json->data)) {
445
+ return (new WP_Error('api_error', 'no_data'));
446
  }
447
 
448
+ if (!empty($json->data)) {
449
  return $json->data;
450
  }
451
 
 
452
  return false;
453
  }
454
 
455
  public static function removeBriefcaseKeyword($args = array()) {
 
456
  self::$apimethod = 'post'; //call method
457
 
458
  if ($json = json_decode(self::apiCall('api/briefcase/hide', $args))) {
463
  }
464
 
465
  public static function getBriefcaseStats($args = array()) {
 
466
  self::$apimethod = 'get'; //call method
467
 
468
  $json = json_decode(self::apiCall('api/briefcase/stats', $args));
471
  self::connect(); //connect the website
472
 
473
  return (new WP_Error('api_error', $json->error));
474
+ } elseif (!isset($json->data)) {
475
+ return (new WP_Error('api_error', 'no_data'));
476
  }
477
 
478
+ if (!empty($json->data)) {
479
  return $json->data;
480
  }
481
 
483
  }
484
 
485
  public static function saveBriefcaseKeywordLabel($args = array()) {
 
486
  self::$apimethod = 'post'; //call method
487
 
488
  $json = json_decode(self::apiCall('api/briefcase/label/keyword', $args));
489
 
490
  if (isset($json->error) && $json->error <> '') {
491
  return (new WP_Error('api_error', $json->error));
492
+ } elseif (!isset($json->data)) {
493
+ return (new WP_Error('api_error', 'no_data'));
494
  }
495
 
496
+ if (!empty($json->data)) {
497
  return $json->data;
498
  }
499
 
502
 
503
 
504
  public static function addBriefcaseLabel($args = array()) {
 
505
  self::$apimethod = 'post'; //call method
506
 
507
  $json = json_decode(self::apiCall('api/briefcase/label/add', $args));
508
 
509
  if (isset($json->error) && $json->error <> '') {
510
  return (new WP_Error('api_error', $json->error));
511
+ } elseif (!isset($json->data)) {
512
+ return (new WP_Error('api_error', 'no_data'));
513
  }
514
 
515
+ if (!empty($json->data)) {
516
  return $json->data;
517
  }
518
 
520
  }
521
 
522
  public static function saveBriefcaseLabel($args = array()) {
 
523
  self::$apimethod = 'post'; //call method
524
 
525
  $json = json_decode(self::apiCall('api/briefcase/label/save', $args));
526
 
527
  if (isset($json->error) && $json->error <> '') {
528
  return (new WP_Error('api_error', $json->error));
529
+ } elseif (!isset($json->data)) {
530
+ return (new WP_Error('api_error', 'no_data'));
531
  }
532
 
533
+ if (!empty($json->data)) {
534
  return $json->data;
535
  }
536
 
538
  }
539
 
540
  public static function removeBriefcaseLabel($args = array()) {
 
541
  self::$apimethod = 'post'; //call method
542
 
543
  $json = json_decode(self::apiCall('api/briefcase/label/delete', $args));
544
 
545
  if (isset($json->error) && $json->error <> '') {
546
  return (new WP_Error('api_error', $json->error));
547
+ } elseif (!isset($json->data)) {
548
+ return (new WP_Error('api_error', 'no_data'));
549
  }
550
 
551
+ if (!empty($json->data)) {
552
  return $json->data;
553
  }
554
 
558
  /******************************** KEYWORD RESEARCH ****************/
559
 
560
  public static function getKROthers($args = array()) {
 
561
  self::$apimethod = 'get'; //call method
562
 
563
+ $json = json_decode(self::apiCall('api/kr/other', $args));
564
 
565
+ if (isset($json->error) && $json->error <> '') {
566
+ return (new WP_Error('api_error', $json->error));
567
+ } elseif (!isset($json->data)) {
568
+ return (new WP_Error('api_error', 'no_data'));
569
+ }
570
 
571
+ if (!empty($json->data)) {
572
+ return $json->data;
573
  }
574
 
575
  return false;
576
  }
577
 
578
  /**
579
+ * Set Keyword Research
580
  *
581
  * @param array $args
582
  * @return array|bool|mixed|object|WP_Error
583
  */
584
+ public static function setKRSuggestion($args = array()) {
585
+ self::$apimethod = 'post'; //call method
586
+
587
+ $json = json_decode(self::apiCall('api/kr/suggestion', $args));
588
+
589
+ if (isset($json->error) && $json->error <> '') {
590
+ return (new WP_Error('api_error', $json->error));
591
+ } elseif (!isset($json->data)) {
592
+ return (new WP_Error('api_error', 'no_data'));
593
+ }
594
+
595
+ if (!empty($json->data)) {
596
+ return $json->data;
597
+ }
598
+
599
+ return false;
600
+ }
601
+
602
  public static function getKRSuggestion($args = array()) {
 
603
  self::$apimethod = 'get'; //call method
604
 
605
+ $json = json_decode(self::apiCall('api/kr/suggestion', $args));
606
 
607
+ if (isset($json->error) && $json->error <> '') {
608
+ return (new WP_Error('api_error', $json->error));
609
+ } elseif (!isset($json->data)) {
610
+ return (new WP_Error('api_error', 'no_data'));
611
+ }
612
 
613
+ if (!empty($json->data)) {
614
+ return $json->data;
615
  }
616
 
617
  return false;
618
  }
619
 
620
+
621
  /**
622
  * Get Keyword Research History
623
  * @param array $args
624
  * @return array|bool|mixed|object|WP_Error
625
  */
626
  public static function getKRHistory($args = array()) {
 
627
  self::$apimethod = 'get'; //call method
628
 
629
+ $json = json_decode(self::apiCall('api/kr/history', $args));
630
 
631
  if (isset($json->error) && $json->error <> '') {
632
  return (new WP_Error('api_error', $json->error));
633
+ } elseif (!isset($json->data)) {
634
+ return (new WP_Error('api_error', 'no_data'));
635
  }
636
 
637
+ if (!empty($json->data)) {
638
+ return $json->data;
639
  }
640
 
641
  return false;
647
  * @return bool|WP_Error
648
  */
649
  public static function getKrFound($args = array()) {
 
650
  self::$apimethod = 'get'; //call method
651
 
652
+ $json = json_decode(self::apiCall('api/kr/found', $args));
653
 
654
  if (isset($json->error) && $json->error <> '') {
655
  return (new WP_Error('api_error', $json->error));
656
+ } elseif (!isset($json->data)) {
657
+ return (new WP_Error('api_error', 'no_data'));
658
  }
659
 
660
+ if (!empty($json->data)) {
661
+ return $json->data;
662
  }
663
 
664
  return false;
670
  * @return bool|WP_Error
671
  */
672
  public static function getKrCountries($args = array()) {
 
673
  self::$apimethod = 'get'; //call method
674
 
675
+ $json = json_decode(self::apiCall('api/kr/countries', $args));
 
676
 
677
  if (isset($json->error) && $json->error <> '') {
678
  return (new WP_Error('api_error', $json->error));
679
+ } elseif (!isset($json->data)) {
680
+ return (new WP_Error('api_error', 'no_data'));
681
  }
682
 
683
+ if (!empty($json->data)) {
684
+ return $json->data;
685
  }
686
 
687
  return false;
690
  /******************** WP Posts ***************************/
691
  /**
692
  * Save the post status on API
693
+ *
694
  * @param array $args
695
+ * @return bool|WP_Error
696
  */
697
  public static function savePost($args = array()) {
698
+ self::$apimethod = 'post'; //call method
699
+
700
+ $json = json_decode(self::apiCall('api/posts/update', $args, ['timeout' => 5]));
701
 
702
+ if (isset($json->error) && $json->error <> '') {
703
+ return (new WP_Error('api_error', $json->error));
704
+ } elseif (!isset($json->data)) {
705
+ return (new WP_Error('api_error', 'no_data'));
706
+ }
707
+
708
+ if (!empty($json->data)) {
709
+ return $json->data;
710
+ }
711
+
712
+ return false;
713
 
714
  }
715
 
720
  * @return array|mixed|object
721
  */
722
  public static function getPostOptimization($args = array()) {
723
+ self::$apimethod = 'get'; //call method
724
 
725
+ $json = json_decode(self::apiCall('api/posts/optimizations', $args));
 
726
 
727
+ if (isset($json->error) && $json->error <> '') {
728
+ return (new WP_Error('api_error', $json->error));
729
+ } elseif (!isset($json->data)) {
730
+ return (new WP_Error('api_error', 'no_data'));
731
+ }
 
 
 
732
 
733
+ if (!empty($json->data)) {
734
+ return $json->data;
735
+ }
736
+
737
+ return false;
738
 
739
  }
740
 
746
  * @return bool|WP_Error
747
  */
748
  public static function addSerpKeyword($args = array()) {
 
749
  self::$apimethod = 'post'; //call method
750
 
751
  $json = json_decode(self::apiCall('api/briefcase/serp', $args));
752
 
753
  if (isset($json->error) && $json->error <> '') {
754
  return (new WP_Error('api_error', $json->error));
755
+ } elseif (!isset($json->data)) {
756
+ return (new WP_Error('api_error', 'no_data'));
757
  }
758
 
759
+ if (!empty($json->data)) {
760
  return $json->data;
761
  }
762
 
769
  * @return bool|WP_Error
770
  */
771
  public static function deleteSerpKeyword($args = array()) {
 
772
  self::$apimethod = 'post'; //call method
773
 
774
  $json = json_decode(self::apiCall('api/briefcase/serp-delete', $args));
775
 
776
  if (isset($json->error) && $json->error <> '') {
777
  return (new WP_Error('api_error', $json->error));
778
+ } elseif (!isset($json->data)) {
779
+ return (new WP_Error('api_error', 'no_data'));
780
  }
781
 
782
+ if (!empty($json->data)) {
783
  return $json->data;
784
  }
785
 
792
  * @return bool|WP_Error
793
  */
794
  public static function getRanksStats($args = array()) {
 
795
  self::$apimethod = 'get'; //call method
796
 
797
  $json = json_decode(self::apiCall('api/serp/stats', $args));
798
 
799
  if (isset($json->error) && $json->error <> '') {
800
  return (new WP_Error('api_error', $json->error));
801
+ } elseif (!isset($json->data)) {
802
+ return (new WP_Error('api_error', 'no_data'));
803
  }
804
 
805
+ if (!empty($json->data)) {
806
  return $json->data;
807
  }
808
+
809
  return false;
810
  }
811
 
815
  * @return bool|WP_Error
816
  */
817
  public static function getRanks($args = array()) {
 
818
  self::$apimethod = 'get'; //call method
819
 
820
  $json = json_decode(self::apiCall('api/serp/get-ranks', $args));
821
 
822
  if (isset($json->error) && $json->error <> '') {
823
  return (new WP_Error('api_error', $json->error));
824
+ } elseif (!isset($json->data)) {
825
+ return (new WP_Error('api_error', 'no_data'));
826
  }
827
 
828
+ if (!empty($json->data)) {
829
  return $json->data;
830
  }
831
+
832
  return false;
833
  }
834
 
839
  * @return bool|WP_Error
840
  */
841
  public static function checkPostRank($args = array()) {
 
842
  self::$apimethod = 'get'; //call method
843
 
844
  $json = json_decode(self::apiCall('api/serp/refresh', $args));
845
 
846
  if (isset($json->error) && $json->error <> '') {
847
  return (new WP_Error('api_error', $json->error));
848
+ } elseif (!isset($json->data)) {
849
+ return (new WP_Error('api_error', 'no_data'));
850
  }
851
 
852
+ if (!empty($json->data)) {
853
  return $json->data;
854
  }
855
 
856
+ return false;
857
  }
858
 
859
  /******************** FOCUS PAGES ***********************/
865
  * @return SQ_Models_Domain_FocusPage|WP_Error|false
866
  */
867
  public static function getFocusPages($args = array()) {
 
868
  self::$apimethod = 'get'; //call method
869
 
870
  $json = json_decode(self::apiCall('api/posts/focus', $args));
871
 
872
  if (isset($json->error) && $json->error <> '') {
873
  return (new WP_Error('api_error', $json->error));
874
+ } elseif (!isset($json->data)) {
875
+ return (new WP_Error('api_error', 'no_data'));
876
  }
877
 
878
+ if (!empty($json->data)) {
879
  return $json->data;
880
  }
881
+
882
  return false;
883
  }
884
 
889
  * @return bool|WP_Error
890
  */
891
  public static function getFocusAudits($args = array()) {
 
892
  self::$apimethod = 'get'; //call method
893
 
894
  $json = json_decode(self::apiCall('api/audits/focus', $args));
895
 
896
  if (isset($json->error) && $json->error <> '') {
897
  return (new WP_Error('api_error', $json->error));
898
+ } elseif (!isset($json->data)) {
899
+ return (new WP_Error('api_error', 'no_data'));
900
  }
901
 
902
+ if (!empty($json->data)) {
903
  return $json->data;
904
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
905
 
906
  return false;
907
  }
912
  * @return bool|WP_Error
913
  */
914
  public static function addFocusPage($args = array()) {
 
915
  self::$apimethod = 'post'; //post call
916
 
917
+ $json = json_decode(self::apiCall('api/posts/set-focus', $args));
918
 
919
+ if (isset($json->error) && $json->error <> '') {
920
+ return (new WP_Error('api_error', $json->error));
921
+ } elseif (!isset($json->data)) {
922
+ return (new WP_Error('api_error', 'no_data'));
923
+ }
924
 
925
+ if (!empty($json->data)) {
926
+ return $json->data;
 
927
  }
928
+
929
  return false;
930
  }
931
 
932
  public static function updateFocusPage($args = array()) {
 
933
  self::$apimethod = 'post'; //post call
934
 
935
+ $json = json_decode(self::apiCall('api/posts/update-focus', $args));
 
 
 
936
 
937
+ if (isset($json->error) && $json->error <> '') {
938
+ return (new WP_Error('api_error', $json->error));
939
+ } elseif (!isset($json->data)) {
940
+ return (new WP_Error('api_error', 'no_data'));
941
  }
942
+
943
+ if (!empty($json->data)) {
944
+ return $json->data;
945
+ }
946
+
947
  return false;
948
  }
949
 
953
  * @return bool|WP_Error
954
  */
955
  public static function deleteFocusPage($args = array()) {
 
956
  self::$apimethod = 'post'; //post call
957
 
958
  if (isset($args['user_post_id']) && $args['user_post_id'] > 0) {
959
+ $json = json_decode(self::apiCall('api/posts/remove-focus/' . $args['user_post_id']));
960
 
961
+ if (isset($json->error) && $json->error <> '') {
962
+ return (new WP_Error('api_error', $json->error));
963
+ } elseif (!isset($json->data)) {
964
+ return (new WP_Error('api_error', 'no_data'));
 
 
 
965
  }
966
+
967
+ return $json->data;
968
  }
969
+
970
  return false;
971
  }
972
 
973
  /**************************************** CONNECTIONS */
974
  /**
975
  * Disconnect Google Analytics account
976
+ *
977
  * @return bool|WP_Error
978
  */
979
+ public static function revokeGaConnection() {
 
980
  self::$apimethod = 'get'; //post call
981
 
982
+ $json = json_decode(self::apiCall('api/ga/revoke'));
 
 
 
983
 
984
+ if (isset($json->error) && $json->error <> '') {
985
+ return (new WP_Error('api_error', $json->error));
986
+ } elseif (!isset($json->data)) {
987
+ return (new WP_Error('api_error', 'no_data'));
988
+ }
989
+
990
+ if (!empty($json->data)) {
991
+ return $json->data;
992
  }
993
 
994
  return false;
995
  }
996
 
997
+ public static function getGAToken($args = array()) {
998
+ self::$apimethod = 'get'; //post call
999
+
1000
+ $json = json_decode(self::apiCall('api/ga/token', $args));
1001
+
1002
+ if (isset($json->error) && $json->error <> '') {
1003
+ return (new WP_Error('api_error', $json->error));
1004
+ } elseif (!isset($json->data)) {
1005
+ return (new WP_Error('api_error', 'no_data'));
1006
+ }
1007
+
1008
+ if (!empty($json->data)) {
1009
+ return $json->data;
1010
+ }
1011
+
1012
+ return false;
1013
+
1014
+ }
1015
 
1016
  /**
1017
  * Disconnect Google Search Console account
1018
+ *
1019
  * @return bool|WP_Error
1020
  */
1021
+ public static function revokeGscConnection() {
 
1022
  self::$apimethod = 'get'; //post call
1023
 
1024
+ $json = json_decode(self::apiCall('api/gsc/revoke'));
 
 
 
1025
 
1026
+ if (isset($json->error) && $json->error <> '') {
1027
+ return (new WP_Error('api_error', $json->error));
1028
+ } elseif (!isset($json->data)) {
1029
+ return (new WP_Error('api_error', 'no_data'));
1030
+ }
1031
+
1032
+ if (!empty($json->data)) {
1033
+ return $json->data;
1034
  }
1035
 
1036
  return false;
1037
+
1038
  }
1039
 
1040
  public static function syncGSC($args = array()) {
 
1041
  self::$apimethod = 'get'; //post call
1042
 
1043
+ $json = json_decode(self::apiCall('api/gsc/sync/kr', $args));
1044
 
1045
+ if (isset($json->error) && $json->error <> '') {
1046
+ return (new WP_Error('api_error', $json->error));
1047
+ } elseif (!isset($json->data)) {
1048
+ return (new WP_Error('api_error', 'no_data'));
1049
+ }
1050
 
1051
+ if (!empty($json->data)) {
1052
+ return $json->data;
1053
+ }
1054
 
1055
+ return false;
1056
+
1057
+ }
1058
+
1059
+ public static function getGSCToken($args = array()) {
1060
+ self::$apimethod = 'get'; //post call
1061
+
1062
+ $json = json_decode(self::apiCall('api/gsc/token', $args));
1063
+
1064
+ if (isset($json->error) && $json->error <> '') {
1065
+ return (new WP_Error('api_error', $json->error));
1066
+ } elseif (!isset($json->data)) {
1067
+ return (new WP_Error('api_error', 'no_data'));
1068
+ }
1069
+
1070
+ if (!empty($json->data)) {
1071
+ return $json->data;
1072
  }
1073
 
1074
  return false;
1075
+
1076
  }
1077
 
1078
+ /******************** AUDITS *****************************/
1079
 
1080
+ public static function getAuditPages($args = array()) {
1081
+ self::$apimethod = 'get'; //call method
1082
+
1083
+ $json = json_decode(self::apiCall('api/posts/audits', $args));
1084
+
1085
+ if (isset($json->error) && $json->error <> '') {
1086
+ return (new WP_Error('api_error', $json->error));
1087
+ } elseif (!isset($json->data)) {
1088
+ return (new WP_Error('api_error', 'no_data'));
1089
+ }
1090
+
1091
+ if (!empty($json->data)) {
1092
+ return $json->data;
1093
+ }
1094
+
1095
+ return false;
1096
+
1097
+ }
1098
+
1099
+ /**
1100
+ * Get the audit page
1101
+ *
1102
+ * @param array $args
1103
+ * @return bool|WP_Error
1104
+ */
1105
+ public static function getAudit($args = array()) {
1106
+ self::$apimethod = 'get'; //call method
1107
+
1108
+ $json = json_decode(self::apiCall('api/audits/audit', $args));
1109
+
1110
+ if (isset($json->error) && $json->error <> '') {
1111
+ return (new WP_Error('api_error', $json->error));
1112
+ } elseif (!isset($json->data)) {
1113
+ return (new WP_Error('api_error', 'no_data'));
1114
+ }
1115
 
1116
+ if (!empty($json->data)) {
1117
+ return $json->data;
1118
+ }
1119
+
1120
+ return false;
1121
+
1122
+ }
1123
 
1124
+ /**
1125
+ * Add Audit Page
1126
+ * @param array $args
1127
+ * @return bool|WP_Error
1128
+ */
1129
+ public static function addAuditPage($args = array()) {
1130
+ self::$apimethod = 'post'; //post call
1131
+
1132
+ $json = json_decode(self::apiCall('api/posts/set-audit', $args));
1133
+
1134
+ if (isset($json->error) && $json->error <> '') {
1135
+ return (new WP_Error('api_error', $json->error));
1136
+ } elseif (!isset($json->data)) {
1137
+ return (new WP_Error('api_error', 'no_data'));
1138
+ }
1139
+
1140
+ if (!empty($json->data)) {
1141
+ return $json->data;
1142
+ }
1143
+
1144
+ return false;
1145
+
1146
+ }
1147
+
1148
+ public static function updateAudit($args = array()) {
1149
+ self::$apimethod = 'post'; //post call
1150
+
1151
+ $json = json_decode(self::apiCall('api/posts/update-audit', $args));
1152
+
1153
+ if (isset($json->error) && $json->error <> '') {
1154
+ return (new WP_Error('api_error', $json->error));
1155
+ } elseif (!isset($json->data)) {
1156
+ return (new WP_Error('api_error', 'no_data'));
1157
+ }
1158
+
1159
+ if (!empty($json->data)) {
1160
+ return $json->data;
1161
+ }
1162
+
1163
+ return false;
1164
+ }
1165
+
1166
+ /**
1167
+ * Delete the Audit Page
1168
+ * @param array $args
1169
+ * @return bool|WP_Error
1170
+ */
1171
+ public static function deleteAuditPage($args = array()) {
1172
+ self::$apimethod = 'post'; //post call
1173
+
1174
+ if (isset($args['user_post_id']) && $args['user_post_id'] > 0) {
1175
+
1176
+ $json = json_decode(self::apiCall('api/posts/remove-audit/' . $args['user_post_id']));
1177
 
1178
  if (isset($json->error) && $json->error <> '') {
1179
  return (new WP_Error('api_error', $json->error));
1180
+ } elseif (!isset($json->data)) {
1181
+ return (new WP_Error('api_error', 'no_data'));
1182
  }
1183
 
1184
+ if (!empty($json->data)) {
1185
  return $json->data;
1186
  }
 
1187
 
1188
+ }
1189
  return false;
1190
  }
1191
 
1192
+ /******************** OTHERS *****************************/
1193
  public static function saveSettings($args) {
1194
+ self::$apimethod = 'post'; //call method
1195
+
1196
+ self::apiCall('api/user/settings', array('settings' => json_encode($args)));
1197
+ }
1198
+
1199
+ /**
1200
+ * Get the Facebook APi Code
1201
+ * @param $args
1202
+ * @return bool|WP_Error
1203
+ */
1204
+ public static function getFacebookApi($args) {
1205
  self::$apimethod = 'get'; //call method
1206
 
1207
+ if ($json = json_decode(self::apiCall('api/tools/facebook', $args))) {
1208
+
1209
+ if (isset($json->error) && $json->error <> '') {
1210
+ return (new WP_Error('api_error', $json->error));
1211
+ } elseif (!isset($json->data)) {
1212
+ return (new WP_Error('api_error', 'no_data'));
1213
+ }
1214
+
1215
+ return $json->data;
1216
+ }
1217
+
1218
+ return false;
1219
+
1220
  }
1221
 
1222
  /**
1224
  */
1225
  public static function loadJsVars() {
1226
  global $post;
1227
+ $referer = '';
1228
+
1229
  $sq_postID = (isset($post->ID) ? $post->ID : 0);
1230
 
1231
+ if (SQ_Classes_Helpers_Tools::isPluginInstalled('elementor/elementor.php')) {
1232
+ if (SQ_Classes_Helpers_Tools::getOption('sq_sla_frontend')) {
1233
+ $referer = get_post_meta($sq_postID, '_sq_sla', true);
1234
+ }
1235
+ }
1236
+
1237
  echo '<script>
1238
  var SQ_DEBUG = ' . (int)SQ_DEBUG . ';
1239
  (function($){
1240
  $.sq_config = {
1241
  sq_use: ' . (int)SQ_Classes_Helpers_Tools::getOption('sq_use') . ',
1242
  sq_version: "' . SQ_VERSION . '",
1243
+ sq_sla_type: "' . SQ_Classes_Helpers_Tools::getOption('sq_sla_type') . '",
1244
  token: "' . SQ_Classes_Helpers_Tools::getOption('sq_api') . '",
1245
  sq_baseurl: "' . _SQ_STATIC_API_URL_ . '",
1246
  sq_uri: "' . SQ_URI . '",
1247
+ sq_apiurl: "' . _SQ_APIV2_URL_ . '",
1248
+ user_url: "' . apply_filters('sq_homeurl', get_bloginfo('url')) . '",
1249
+ language: "' . apply_filters('sq_language', get_bloginfo('language')) . '",
1250
+ referer: "' . $referer . '",
1251
  sq_keywordtag: ' . (int)SQ_Classes_Helpers_Tools::getOption('sq_keywordtag') . ',
1252
+ sq_keyword_help: ' . (int)SQ_Classes_Helpers_Tools::getOption('sq_keyword_help') . ',
 
1253
  frontend_css: "' . _SQ_ASSETS_URL_ . 'css/frontend' . (SQ_DEBUG ? '' : '.min') . '.css",
1254
  postID: "' . $sq_postID . '",
1255
  prevNonce: "' . wp_create_nonce('post_preview_' . $sq_postID) . '",
 
1256
  __keyword: "' . __('Keyword:', _SQ_PLUGIN_NAME_) . '",
1257
  __date: "' . __('date', _SQ_PLUGIN_NAME_) . '",
1258
  __saved: "' . __('Saved!', _SQ_PLUGIN_NAME_) . '",
1264
  __notrelevant: "' . __('Not relevant?', _SQ_PLUGIN_NAME_) . '",
1265
  __insertparagraph: "' . __('Insert in your article', _SQ_PLUGIN_NAME_) . '",
1266
  __ajaxerror: "' . __(':( An error occurred while processing your request. Please try again', _SQ_PLUGIN_NAME_) . '",
 
1267
  __nofound: "' . __('No results found!', _SQ_PLUGIN_NAME_) . '",
 
 
 
 
1268
  __sq_photo_copyright: "' . __('[ ATTRIBUTE: Please check: %s to find out how to attribute this image ]', _SQ_PLUGIN_NAME_) . '",
1269
  __has_attributes: "' . __('Has creative commons attributes', _SQ_PLUGIN_NAME_) . '",
1270
  __no_attributes: "' . __('No known copyright restrictions', _SQ_PLUGIN_NAME_) . '",
1271
  __noopt: "' . __('You haven`t used Squirrly SEO to optimize your article. Do you want to optimize for a keyword before publishing?', _SQ_PLUGIN_NAME_) . '",
 
1272
  __subscription_expired: "' . __('Your Subscription has Expired', _SQ_PLUGIN_NAME_) . '",
 
1273
  __no_briefcase: "' . __('There are no keywords saved in briefcase yet', _SQ_PLUGIN_NAME_) . '",
1274
  __fulloptimized: "' . __('Congratulations! Your article is 100% optimized!', _SQ_PLUGIN_NAME_) . '",
1275
  __toomanytimes: "' . __('appears too many times. Try to remove %s of them', _SQ_PLUGIN_NAME_) . '",
1285
  __addminimumwords: "' . __('write %s more words to start calculating', _SQ_PLUGIN_NAME_) . '",
1286
  __add_to_briefcase: "' . __('Add to Briefcase', _SQ_PLUGIN_NAME_) . '",
1287
  __add_keyword_briefcase: "' . __('Add Keyword to Briefcase', _SQ_PLUGIN_NAME_) . '",
1288
+ __usekeyword: "' . __('Select', _SQ_PLUGIN_NAME_) . '",
1289
+ __new_post_title: "' . __('Auto Draft') . '",
1290
+ __frontend_optimized: "' . __('You’ve already used the Live Assistant to optimize this post when creating it in your Page Builder. Please go back and resume your optimization work there.', _SQ_PLUGIN_NAME_) . '",
1291
  };
1292
 
1293
 
1313
 
1314
  }
1315
 
 
 
 
 
 
 
 
1316
  }
classes/helpers/Sanitize.php CHANGED
@@ -91,9 +91,9 @@ class SQ_Classes_Helpers_Sanitize {
91
  }
92
 
93
  //Use internation truncate
94
- if(function_exists('mb_substr')) {
95
  $text = mb_substr($text, 0, $max);
96
- }else{
97
  $text = substr($text, 0, $max);
98
  }
99
 
@@ -161,45 +161,35 @@ class SQ_Classes_Helpers_Sanitize {
161
  * @param string $code
162
  * @return string
163
  */
164
- public static function checkFavebookAdminCode($code) {
165
- $id = '';
166
  if ($code <> '') {
167
  $code = trim($code);
168
- if (strpos($code, '"') !== false) {
169
- preg_match('/[\'\"]([^\'\"]+)[\'\"]/i', $code, $result);
170
- if (isset($result[1]) && !empty($result[1])) {
171
- $id = $result[1];
172
- }
173
- }
174
 
175
  if (strpos($code, 'facebook.com/') !== false) {
176
  preg_match('/facebook.com\/([^\/]+)/i', $code, $result);
177
  if (isset($result[1]) && !empty($result[1])) {
178
  if (is_string($result[1])) {
179
- $response = SQ_Classes_RemoteController::apiCall('seo/facebook-id', array('profile' => $result[1]));
180
- if ($response && $json = json_decode($response)) {
181
- $id = $json->code;
182
  }
183
  } elseif (is_numeric($result[1])) {
184
- $id = $result[1];
185
  }
186
  }
187
- } else {
188
- if (is_string($code)) {
189
- $response = SQ_Classes_RemoteController::apiCall('seo/facebook-id', array('profile' => $code));
190
- if ($response && $json = json_decode($response)) {
191
- $id = $json->code;
192
- }
193
- } elseif (is_numeric($code)) {
194
- $id = $code;
195
  }
 
 
196
  }
197
 
198
- if ($id == '') {
199
- SQ_Classes_Error::setError(__("The code for Facebook is incorrect.", _SQ_PLUGIN_NAME_));
200
- }
201
  }
202
- return $id;
203
  }
204
 
205
  /**
91
  }
92
 
93
  //Use internation truncate
94
+ if (function_exists('mb_substr')) {
95
  $text = mb_substr($text, 0, $max);
96
+ } else {
97
  $text = substr($text, 0, $max);
98
  }
99
 
161
  * @param string $code
162
  * @return string
163
  */
164
+ public static function checkFacebookAdminCode($code) {
 
165
  if ($code <> '') {
166
  $code = trim($code);
 
 
 
 
 
 
167
 
168
  if (strpos($code, 'facebook.com/') !== false) {
169
  preg_match('/facebook.com\/([^\/]+)/i', $code, $result);
170
  if (isset($result[1]) && !empty($result[1])) {
171
  if (is_string($result[1])) {
172
+ $response = SQ_Classes_RemoteController::getFacebookApi(array('profile' => $result[1]));
173
+ if (!is_wp_error($response) && isset($response->code)) {
174
+ return $response->code;
175
  }
176
  } elseif (is_numeric($result[1])) {
177
+ return $result[1];
178
  }
179
  }
180
+ } elseif ($code <> (int)$code) {
181
+ $response = SQ_Classes_RemoteController::getFacebookApi(array('profile' => $code));
182
+ if (!is_wp_error($response) && isset($response->code)) {
183
+ return $response->code;
 
 
 
 
184
  }
185
+ } else {
186
+ return $code;
187
  }
188
 
189
+ SQ_Classes_Error::setError(__("The code for Facebook is incorrect.", _SQ_PLUGIN_NAME_));
190
+
 
191
  }
192
+ return false;
193
  }
194
 
195
  /**
classes/helpers/Tools.php CHANGED
@@ -117,37 +117,48 @@ class SQ_Classes_Helpers_Tools {
117
  public static function getOptions($action = '') {
118
  $default = array(
119
  //Global settings
120
- 'sq_ver' => 0,
121
  'sq_api' => '',
 
 
 
 
 
122
  'sq_logo' => _SQ_THEME_URL_ . 'img/settings/menu_icon_16.png',
123
  'sq_name' => '',
124
- 'sq_checkedissues' => 0,
125
- 'sq_areissues' => 0,
126
- 'sq_seoexpert' => 1, //the user is an SEO expert
127
  'sq_laterload' => 0,
128
- 'sq_support_email' => '',
129
  'sq_audit_email' => '',
 
130
  'sq_seojourney' => 0,
131
  'sq_seojourney_congrats' => 1,
132
  'sq_onboarding' => 0,
133
-
 
 
 
134
  //Settings Assistant
135
  'sq_assistant' => 1,
 
136
 
137
  //Live Assistant
138
  'sq_sla' => 1,
 
 
139
  'sq_sla_exclude_post_types' => array(),
140
  'sq_keyword_information' => 0,
141
  'sq_keyword_help' => 1,
142
  'sq_local_images' => 1,
143
- 'sq_force_savepost' => 0,
144
  'sq_img_licence' => 1,
145
 
146
  //JsonLD
147
  'sq_auto_jsonld' => 1,
148
  'sq_jsonld_type' => 'Organization',
149
  'sq_jsonld_breadcrumbs' => 1,
 
150
  'sq_jsonld_clearcode' => 0,
 
151
  'sq_jsonld' => array(
152
  'Organization' => array(
153
  'name' => '',
@@ -215,6 +226,7 @@ class SQ_Classes_Helpers_Tools {
215
  'sq_auto_noindex' => 1,
216
  'sq_use_frontend' => 1,
217
  'sq_attachment_redirect' => 0,
 
218
  'sq_metas' => array(
219
  'title_maxlength' => 75,
220
  'description_maxlength' => 320,
@@ -313,6 +325,7 @@ class SQ_Classes_Helpers_Tools {
313
  'do_twc' => 1,
314
  'do_analytics' => 1,
315
  'do_fpixel' => 1,
 
316
  ),
317
  'post' => array(
318
  'protected' => 1,
@@ -330,6 +343,7 @@ class SQ_Classes_Helpers_Tools {
330
  'do_twc' => 1,
331
  'do_analytics' => 1,
332
  'do_fpixel' => 1,
 
333
  ),
334
  'page' => array(
335
  'protected' => 1,
@@ -347,6 +361,7 @@ class SQ_Classes_Helpers_Tools {
347
  'do_twc' => 1,
348
  'do_analytics' => 1,
349
  'do_fpixel' => 1,
 
350
  ),
351
  'category' => array(
352
  'protected' => 1,
@@ -364,6 +379,7 @@ class SQ_Classes_Helpers_Tools {
364
  'do_twc' => 1,
365
  'do_analytics' => 1,
366
  'do_fpixel' => 1,
 
367
  ),
368
  'tag' => array(
369
  'protected' => 1,
@@ -381,6 +397,7 @@ class SQ_Classes_Helpers_Tools {
381
  'do_twc' => 1,
382
  'do_analytics' => 1,
383
  'do_fpixel' => 1,
 
384
  ),
385
  'tax-post_format' => array(
386
  'protected' => 1,
@@ -398,6 +415,7 @@ class SQ_Classes_Helpers_Tools {
398
  'do_twc' => 1,
399
  'do_analytics' => 1,
400
  'do_fpixel' => 1,
 
401
  ),
402
  'tax-category' => array(
403
  'protected' => 1,
@@ -415,6 +433,7 @@ class SQ_Classes_Helpers_Tools {
415
  'do_twc' => 1,
416
  'do_analytics' => 1,
417
  'do_fpixel' => 1,
 
418
  ),
419
  'tax-post_tag' => array(
420
  'protected' => 1,
@@ -432,6 +451,7 @@ class SQ_Classes_Helpers_Tools {
432
  'do_twc' => 1,
433
  'do_analytics' => 1,
434
  'do_fpixel' => 1,
 
435
  ),
436
  'tax-product_cat' => array(
437
  'protected' => 1,
@@ -449,6 +469,7 @@ class SQ_Classes_Helpers_Tools {
449
  'do_twc' => 1,
450
  'do_analytics' => 1,
451
  'do_fpixel' => 1,
 
452
  ),
453
  'tax-product_tag' => array(
454
  'protected' => 1,
@@ -466,6 +487,7 @@ class SQ_Classes_Helpers_Tools {
466
  'do_twc' => 1,
467
  'do_analytics' => 1,
468
  'do_fpixel' => 1,
 
469
  ),
470
  'tax-product_shipping_class' => array(
471
  'protected' => 1,
@@ -483,6 +505,7 @@ class SQ_Classes_Helpers_Tools {
483
  'do_twc' => 1,
484
  'do_analytics' => 1,
485
  'do_fpixel' => 1,
 
486
  ),
487
  'profile' => array(
488
  'protected' => 1,
@@ -500,6 +523,7 @@ class SQ_Classes_Helpers_Tools {
500
  'do_twc' => 1,
501
  'do_analytics' => 1,
502
  'do_fpixel' => 1,
 
503
  ),
504
  'shop' => array(
505
  'protected' => 1,
@@ -517,6 +541,7 @@ class SQ_Classes_Helpers_Tools {
517
  'do_twc' => 1,
518
  'do_analytics' => 1,
519
  'do_fpixel' => 1,
 
520
  ),
521
  'product' => array(
522
  'protected' => 1,
@@ -534,6 +559,7 @@ class SQ_Classes_Helpers_Tools {
534
  'do_twc' => 1,
535
  'do_analytics' => 1,
536
  'do_fpixel' => 1,
 
537
  ),
538
  'archive' => array(
539
  'protected' => 1,
@@ -551,6 +577,7 @@ class SQ_Classes_Helpers_Tools {
551
  'do_twc' => 1,
552
  'do_analytics' => 1,
553
  'do_fpixel' => 1,
 
554
  ),
555
  'search' => array(
556
  'protected' => 1,
@@ -585,6 +612,7 @@ class SQ_Classes_Helpers_Tools {
585
  'do_twc' => 1,
586
  'do_analytics' => 1,
587
  'do_fpixel' => 1,
 
588
  ),
589
  '404' => array(
590
  'protected' => 1,
@@ -602,6 +630,7 @@ class SQ_Classes_Helpers_Tools {
602
  'do_twc' => 0,
603
  'do_analytics' => 1,
604
  'do_fpixel' => 1,
 
605
  ),
606
  'custom' => array(
607
  'protected' => 1,
@@ -619,6 +648,7 @@ class SQ_Classes_Helpers_Tools {
619
  'do_twc' => 1,
620
  'do_analytics' => 1,
621
  'do_fpixel' => 1,
 
622
  ),
623
  )
624
 
@@ -626,7 +656,6 @@ class SQ_Classes_Helpers_Tools {
626
  $options = json_decode(get_option(SQ_OPTION), true);
627
 
628
  if ($action == 'reset') {
629
- $init['sq_ver'] = $options['sq_ver'];
630
  $init['sq_api'] = $options['sq_api'];
631
  return $init;
632
  }
@@ -757,7 +786,8 @@ class SQ_Classes_Helpers_Tools {
757
  }
758
  }
759
 
760
- return self::$options['menu'][$key];
 
761
  }
762
 
763
  /**
@@ -766,6 +796,7 @@ class SQ_Classes_Helpers_Tools {
766
  */
767
  public static function setHeader($type) {
768
  if (self::getValue('sq_debug') == 'on') {
 
769
  return;
770
  }
771
 
@@ -892,35 +923,17 @@ class SQ_Classes_Helpers_Tools {
892
  }
893
 
894
  /**
895
- * Triggered when an update is made
896
  */
897
- public static function checkUpgrade() {
898
- if (self::getOption('sq_ver') == 0 || self::getOption('sq_ver') < (int)str_replace('.', '', SQ_VERSION)) {
899
-