SEO SQUIRRLY™ - Version 11.1.11

Version Description

Download this release

Release Info

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

Code changes from version 11.1.10 to 11.1.11

Files changed (46) hide show
  1. classes/ActionController.php +413 -403
  2. classes/BlockController.php +132 -87
  3. classes/DisplayController.php +127 -123
  4. classes/Error.php +153 -136
  5. classes/FrontController.php +185 -140
  6. classes/HookController.php +131 -115
  7. classes/ObjController.php +176 -164
  8. classes/RemoteController.php +1572 -1455
  9. classes/helpers/DevKit.php +327 -302
  10. classes/helpers/Sanitize.php +605 -553
  11. classes/helpers/Tools.php +1411 -1360
  12. config/config.php +90 -82
  13. config/paths.php +66 -66
  14. controllers/Account.php +45 -39
  15. controllers/Api.php +213 -194
  16. controllers/Assistant.php +157 -151
  17. controllers/Audits.php +411 -381
  18. controllers/BulkSeo.php +115 -111
  19. controllers/CheckSeo.php +392 -381
  20. controllers/Dashboard.php +46 -43
  21. controllers/Features.php +34 -32
  22. controllers/FocusPages.php +459 -430
  23. controllers/Frontend.php +177 -164
  24. controllers/Menu.php +535 -483
  25. controllers/Onboarding.php +104 -95
  26. controllers/Overview.php +109 -101
  27. controllers/Patterns.php +168 -158
  28. controllers/Post.php +658 -635
  29. controllers/PostsList.php +333 -307
  30. controllers/Ranking.php +263 -253
  31. controllers/Research.php +813 -794
  32. controllers/SeoSettings.php +878 -843
  33. controllers/Sitemaps.php +780 -727
  34. controllers/Snippet.php +302 -281
  35. controllers/Uninstall.php +19 -16
  36. core/BlockAssistant.php +11 -9
  37. core/BlockConnect.php +60 -55
  38. core/BlockFeatures.php +664 -661
  39. core/BlockJorney.php +52 -48
  40. core/BlockKnowledgeBase.php +11 -9
  41. core/BlockSearch.php +39 -36
  42. core/BlockStats.php +23 -21
  43. core/BlockSupport.php +66 -63
  44. core/BlockToolbar.php +12 -10
  45. core/Blocklogin.php +159 -149
  46. debug/index.php +0 -156
classes/ActionController.php CHANGED
@@ -1,403 +1,413 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- /**
5
- * Set the ajax action and call for wordpress
6
- */
7
- class SQ_Classes_ActionController extends SQ_Classes_FrontController {
8
-
9
- /** @var array with all form and ajax actions */
10
- var $actions = array();
11
-
12
- /**
13
- * The hookAjax is loaded as custom hook in hookController class
14
- *
15
- * @return void
16
- */
17
- public function hookInit() {
18
- /* Only if ajax */
19
- if (SQ_Classes_Helpers_Tools::isAjax()) {
20
- $this->getActions();
21
- }
22
- }
23
-
24
- /**
25
- * The hookSubmit is loaded when action si posted
26
- *
27
- * @return void
28
- */
29
- public function hookMenu() {
30
- /* Only if post */
31
- if (!SQ_Classes_Helpers_Tools::isAjax()) {
32
- $this->getActions();
33
- }
34
- }
35
-
36
- /**
37
- * The hookHead is loaded as admin hook in hookController class for script load
38
- * Is needed for security check as nonce
39
- *
40
- * @return void
41
- */
42
- public function hookHead() {
43
- echo '<script>var sqQuery = {"adminurl": "' . admin_url() . '","ajaxurl": "' . admin_url('admin-ajax.php') . '","adminposturl": "' . admin_url('post.php') . '","adminlisturl": "' . admin_url('edit.php') . '","nonce": "' . wp_create_nonce(_SQ_NONCE_ID_) . '"}</script>';
44
- }
45
-
46
- public function hookFronthead() {
47
- if (SQ_Classes_Helpers_Tools::isFrontAdmin()) {
48
- echo '<script>var sqQuery = {"adminurl": "' . admin_url() . '","ajaxurl": "' . admin_url('admin-ajax.php') . '","nonce": "' . wp_create_nonce(_SQ_NONCE_ID_) . '"}</script>';
49
- }
50
- }
51
-
52
- public function getActionsList(){
53
- return array(
54
- array(
55
- 'name' => 'SQ_Core_Blocklogin',
56
- 'description' => 'Connection Block',
57
- 'actions' => array(
58
- 'action' => array(
59
- 'sq_login',
60
- 'sq_register',
61
- ),
62
- ),
63
- 'active' => '1',
64
- ),
65
- array(
66
- 'name' => 'SQ_Core_BlockConnect',
67
- 'description' => 'Connection Block to API',
68
- 'actions' => array(
69
- 'action' => array(
70
- 'sq_cloud_connect',
71
- 'sq_cloud_disconnect',
72
- ),
73
- ),
74
- 'active' => '1',
75
- ),
76
- array(
77
- 'name' => 'SQ_Controllers_Account',
78
- 'description' => 'Account Class',
79
- 'actions' => array(
80
- 'action' => array(
81
- 'sq_ajax_account_getaccount',
82
- ),
83
- ),
84
- 'active' => '1',
85
- ),
86
- array(
87
- 'name' => 'SQ_Controllers_FocusPages',
88
- 'description' => 'Focus Pages Controller',
89
- 'actions' => array(
90
- 'action' => array(
91
- 'sq_focuspages_getpage',
92
- 'sq_focuspages_addnew',
93
- 'sq_focuspages_update',
94
- 'sq_focuspages_delete',
95
- 'sq_focuspages_inspecturl',
96
- ),
97
- ),
98
- 'active' => '1',
99
- ),
100
- array(
101
- 'name' => 'SQ_Controllers_PostsList',
102
- 'description' => 'Posts List Page',
103
- 'actions' => array(
104
- 'action' => array(
105
- 'inline-save',
106
- 'sq_ajax_postslist',
107
- ),
108
- ),
109
- 'active' => '1',
110
- ),
111
- array(
112
- 'name' => 'SQ_Controllers_Post',
113
- 'description' => 'Post Page',
114
- 'actions' => array(
115
- 'action' => array(
116
- 'sq_create_demo',
117
- 'sq_ajax_save_ogimage',
118
- 'sq_ajax_get_post',
119
- 'sq_ajax_save_post',
120
- 'sq_ajax_type_click',
121
- 'sq_ajax_search_blog',
122
- ),
123
- ),
124
- 'active' => '1',
125
- ),
126
- array(
127
- 'name' => 'SQ_Controllers_Snippet',
128
- 'description' => 'Snippet Page',
129
- 'actions' => array(
130
- 'action' => array(
131
- 'sq_saveseo',
132
- 'sq_getsnippet',
133
- 'sq_previewsnippet',
134
- ),
135
- ),
136
- 'active' => '1',
137
- ),
138
- array(
139
- 'name' => 'SQ_Controllers_Patterns',
140
- 'description' => 'Patterns Class',
141
- 'actions' => array(
142
- 'action' => array(
143
- 'sq_getpatterns',
144
- ),
145
- ),
146
- 'active' => '1',
147
- ),
148
- array(
149
- 'name' => 'SQ_Controllers_BulkSeo',
150
- 'actions' => array(
151
- 'action' => array(
152
- 'sq_ajax_assistant_bulkseo',
153
- ),
154
- ),
155
- 'active' => '1',
156
- ),
157
- array(
158
- 'name' => 'SQ_Controllers_SeoSettings',
159
- 'actions' => array(
160
- 'action' => array(
161
- 'sq_seosettings_automation',
162
- 'sq_seosettings_bulkseo',
163
- 'sq_seosettings_jsonld',
164
- 'sq_seosettings_metas',
165
- 'sq_seosettings_links',
166
- 'sq_seosettings_social',
167
- 'sq_seosettings_tracking',
168
- 'sq_seosettings_webmaster',
169
- 'sq_seosettings_sitemap',
170
- 'sq_seosettings_robots',
171
- 'sq_seosettings_favicon',
172
- 'sq_seosettings_backupsettings',
173
- 'sq_seosettings_backupseo',
174
- 'sq_seosettings_restoresettings',
175
- 'sq_seosettings_restoreseo',
176
- 'sq_seosettings_importsettings',
177
- 'sq_seosettings_importseo',
178
- 'sq_seosettings_importall',
179
- 'sq_seosettings_ga_revoke',
180
- 'sq_seosettings_gsc_revoke',
181
- 'sq_seosettings_gsc_check',
182
- 'sq_seosettings_ga_check',
183
- 'sq_seosettings_clear_cache',
184
- 'sq_seosettings_ga_save',
185
- 'sq_reinstall',
186
- 'sq_rollback',
187
- 'sq_alerts_close',
188
- 'sq_ajax_seosettings_save',
189
- 'sq_ajax_automation_addpostype',
190
- 'sq_ajax_automation_deletepostype',
191
- 'sq_ajax_sla_sticky',
192
- 'sq_ajax_gsc_code',
193
- 'sq_ajax_ga_code',
194
- 'sq_ajax_connection_check',
195
- 'sq_seosettings_advanced',
196
- ),
197
- ),
198
- 'active' => '1',
199
- ),
200
- array(
201
- 'name' => 'SQ_Controllers_Research',
202
- 'actions' => array(
203
- 'action' => array(
204
- 'sq_briefcase_addlabel',
205
- 'sq_briefcase_editlabel',
206
- 'sq_briefcase_keywordlabel',
207
- 'sq_briefcase_article',
208
- 'sq_briefcase_doresearch',
209
- 'sq_briefcase_addkeyword',
210
- 'sq_briefcase_deletekeyword',
211
- 'sq_briefcase_deletelabel',
212
- 'sq_briefcase_deletefound',
213
- 'sq_briefcase_savemain',
214
- 'sq_briefcase_backup',
215
- 'sq_briefcase_restore',
216
- 'sq_ajax_briefcase_doserp',
217
- 'sq_ajax_research_others',
218
- 'sq_ajax_research_process',
219
- 'sq_ajax_research_history',
220
- 'sq_ajax_briefcase_bulk_delete',
221
- 'sq_ajax_briefcase_bulk_label',
222
- 'sq_ajax_briefcase_bulk_doserp',
223
- 'sq_ajax_labels_bulk_delete',
224
- ),
225
- ),
226
- 'active' => '1',
227
- ),
228
- array(
229
- 'name' => 'SQ_Controllers_Audits',
230
- 'actions' => array(
231
- 'action' => array(
232
- 'sq_audits_settings',
233
- 'sq_auditpages_getaudit',
234
- 'sq_audits_getpage',
235
- 'sq_audits_addnew',
236
- 'sq_audits_page_update',
237
- 'sq_audits_update',
238
- 'sq_audits_delete',
239
- ),
240
- ),
241
- 'active' => '1',
242
- ),
243
- array(
244
- 'name' => 'SQ_Controllers_Ranking',
245
- 'actions' => array(
246
- 'action' => array(
247
- 'sq_ranking_settings',
248
- 'sq_serp_refresh_post',
249
- 'sq_serp_delete_keyword',
250
- 'sq_ajax_rank_bulk_delete',
251
- 'sq_ajax_rank_bulk_refresh',
252
- ),
253
- ),
254
- 'active' => '1',
255
- ),
256
- array(
257
- 'name' => 'SQ_Controllers_Assistant',
258
- 'actions' => array(
259
- 'action' => array(
260
- 'sq_settings_assistant',
261
- 'sq_ajax_assistant',
262
- ),
263
- ),
264
- 'active' => '1',
265
- ),
266
- array(
267
- 'name' => 'SQ_Controllers_CheckSeo',
268
- 'actions' => array(
269
- 'action' => array(
270
- 'sq_checkseo',
271
- 'sq_fixsettings',
272
- 'sq_donetask',
273
- 'sq_resetignored',
274
- 'sq_moretasks',
275
- 'sq_ajax_checkseo',
276
- 'sq_ajax_getgoals',
277
- ),
278
- ),
279
- 'active' => '1',
280
- ),
281
- array(
282
- 'name' => 'SQ_Controllers_Onboarding',
283
- 'actions' => array(
284
- 'action' => array(
285
- 'sq_onboarding_commitment',
286
- 'sq_onboading_checksite',
287
- 'sq_onboarding_settings',
288
- ),
289
- ),
290
- 'active' => '1',
291
- ),
292
- array(
293
- 'name' => 'SQ_Core_BlockJorney',
294
- 'actions' => array(
295
- 'action' => array(
296
- 'sq_journey_close',
297
- ),
298
- ),
299
- 'active' => '1',
300
- ),
301
- array(
302
- 'name' => 'SQ_Core_BlockSupport',
303
- 'actions' => array(
304
- 'action' => array(
305
- 'sq_feedback',
306
- 'sq_uninstall_feedback',
307
- ),
308
- ),
309
- 'active' => '1',
310
- ),
311
- array(
312
- 'name' => 'SQ_Core_BlockSearch',
313
- 'actions' => array(
314
- 'action' => array(
315
- 'sq_ajax_search',
316
- ),
317
- ),
318
- 'active' => '1',
319
- ),
320
- array(
321
- 'name' => 'SQ_Controllers_Dashboard',
322
- 'actions' => array(
323
- 'action' => array(
324
- 'sq_ajaxcheckseo',
325
- ),
326
- ),
327
- 'active' => '1',
328
- ),
329
- );
330
- }
331
-
332
- /**
333
- * Get all actions from config.json in core directory and add them in the WP
334
- *
335
- */
336
- public function getActions() {
337
-
338
- if (!is_admin()) {
339
- return;
340
- }
341
-
342
- $this->actions = array();
343
- $cur_action = SQ_Classes_Helpers_Tools::getValue('action', false);
344
- $http_referer = SQ_Classes_Helpers_Tools::getValue('_wp_http_referer', false);
345
- $sq_nonce = SQ_Classes_Helpers_Tools::getValue('sq_nonce', false);
346
-
347
-
348
- //Let only the logged users to access the actions
349
- if ($cur_action <> '' && $sq_nonce <> '') {
350
-
351
- //load the actions list for each class
352
- $actions = $this->getActionsList();
353
-
354
- if(!empty($actions)) {
355
- foreach ($actions as $block) {
356
- if (isset($block['active']) && $block['active'] == 1) {
357
- /* if there is a single action */
358
- if (isset($block['actions']['action']))
359
- /* if there are more actions for the current block */
360
- if (!is_array($block['actions']['action'])) {
361
- /* add the action in the actions array */
362
- if ($block['actions']['action'] == $cur_action) {
363
- $this->actions[] = array('class' => $block['name']);
364
- }
365
- } else {
366
- /* if there are more actions for the current block */
367
- foreach ($block['actions']['action'] as $action) {
368
- /* add the actions in the actions array */
369
- if ($action == $cur_action) {
370
- $this->actions[] = array('class' => $block['name']);
371
- }
372
- }
373
- }
374
- }
375
- }
376
- }
377
-
378
- //If there is an action found in the config.js file
379
- if (!empty($this->actions)) {
380
- /* add the actions in WP */
381
- foreach ($this->actions as $actions) {
382
- if (SQ_Classes_Helpers_Tools::isAjax() && !$http_referer) {
383
- check_ajax_referer(_SQ_NONCE_ID_, 'sq_nonce');
384
- add_action('wp_ajax_' . $cur_action, array(SQ_Classes_ObjController::getClass($actions['class']), 'action'));
385
- } else {
386
- check_admin_referer($cur_action, 'sq_nonce');
387
- SQ_Classes_ObjController::getClass($actions['class'])->action();
388
- }
389
- }
390
- }
391
- }
392
-
393
- //For Post List
394
- if(SQ_Classes_Helpers_Tools::isAjax() && $cur_action <> '' && $cur_action == 'inline-save'){
395
- check_ajax_referer('inlineeditnonce', '_inline_edit');
396
- SQ_Classes_ObjController::getClass('SQ_Controllers_PostsList')->action();
397
-
398
- }
399
-
400
-
401
- }
402
-
403
- }
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ /**
5
+ * Set the ajax action and call for wordpress
6
+ */
7
+ class SQ_Classes_ActionController extends SQ_Classes_FrontController
8
+ {
9
+
10
+ /**
11
+ *
12
+ *
13
+ * @var array with all form and ajax actions
14
+ */
15
+ var $actions = array();
16
+
17
+ /**
18
+ * The hookAjax is loaded as custom hook in hookController class
19
+ *
20
+ * @return void
21
+ */
22
+ public function hookInit()
23
+ {
24
+ /* Only if ajax */
25
+ if (SQ_Classes_Helpers_Tools::isAjax()) {
26
+ $this->getActions();
27
+ }
28
+ }
29
+
30
+ /**
31
+ * The hookSubmit is loaded when action si posted
32
+ *
33
+ * @return void
34
+ */
35
+ public function hookMenu()
36
+ {
37
+ /* Only if post */
38
+ if (!SQ_Classes_Helpers_Tools::isAjax()) {
39
+ $this->getActions();
40
+ }
41
+ }
42
+
43
+ /**
44
+ * The hookHead is loaded as admin hook in hookController class for script load
45
+ * Is needed for security check as nonce
46
+ *
47
+ * @return void
48
+ */
49
+ public function hookHead()
50
+ {
51
+ echo '<script>var sqQuery = {"adminurl": "' . esc_url(admin_url()) . '","ajaxurl": "' . esc_url(admin_url('admin-ajax.php')) . '","adminposturl": "' . esc_url(admin_url('post.php')) . '","adminlisturl": "' . esc_url(admin_url('edit.php')) . '","nonce": "' . esc_attr(wp_create_nonce(_SQ_NONCE_ID_)) . '"}</script>';
52
+ }
53
+
54
+ public function hookFronthead()
55
+ {
56
+ if (SQ_Classes_Helpers_Tools::isFrontAdmin()) {
57
+ echo '<script>var sqQuery = {"adminurl": "' . esc_url(admin_url()) . '","ajaxurl": "' . esc_url(admin_url('admin-ajax.php')) . '","nonce": "' . esc_attr(wp_create_nonce(_SQ_NONCE_ID_)). '"}</script>';
58
+ }
59
+ }
60
+
61
+ public function getActionsList()
62
+ {
63
+ return array(
64
+ array(
65
+ 'name' => 'SQ_Core_Blocklogin',
66
+ 'description' => 'Connection Block',
67
+ 'actions' => array(
68
+ 'action' => array(
69
+ 'sq_login',
70
+ 'sq_register',
71
+ ),
72
+ ),
73
+ 'active' => '1',
74
+ ),
75
+ array(
76
+ 'name' => 'SQ_Core_BlockConnect',
77
+ 'description' => 'Connection Block to API',
78
+ 'actions' => array(
79
+ 'action' => array(
80
+ 'sq_cloud_connect',
81
+ 'sq_cloud_disconnect',
82
+ ),
83
+ ),
84
+ 'active' => '1',
85
+ ),
86
+ array(
87
+ 'name' => 'SQ_Controllers_Account',
88
+ 'description' => 'Account Class',
89
+ 'actions' => array(
90
+ 'action' => array(
91
+ 'sq_ajax_account_getaccount',
92
+ ),
93
+ ),
94
+ 'active' => '1',
95
+ ),
96
+ array(
97
+ 'name' => 'SQ_Controllers_FocusPages',
98
+ 'description' => 'Focus Pages Controller',
99
+ 'actions' => array(
100
+ 'action' => array(
101
+ 'sq_focuspages_getpage',
102
+ 'sq_focuspages_addnew',
103
+ 'sq_focuspages_update',
104
+ 'sq_focuspages_delete',
105
+ 'sq_focuspages_inspecturl',
106
+ ),
107
+ ),
108
+ 'active' => '1',
109
+ ),
110
+ array(
111
+ 'name' => 'SQ_Controllers_PostsList',
112
+ 'description' => 'Posts List Page',
113
+ 'actions' => array(
114
+ 'action' => array(
115
+ 'inline-save',
116
+ 'sq_ajax_postslist',
117
+ ),
118
+ ),
119
+ 'active' => '1',
120
+ ),
121
+ array(
122
+ 'name' => 'SQ_Controllers_Post',
123
+ 'description' => 'Post Page',
124
+ 'actions' => array(
125
+ 'action' => array(
126
+ 'sq_create_demo',
127
+ 'sq_ajax_save_ogimage',
128
+ 'sq_ajax_get_post',
129
+ 'sq_ajax_save_post',
130
+ 'sq_ajax_type_click',
131
+ 'sq_ajax_search_blog',
132
+ ),
133
+ ),
134
+ 'active' => '1',
135
+ ),
136
+ array(
137
+ 'name' => 'SQ_Controllers_Snippet',
138
+ 'description' => 'Snippet Page',
139
+ 'actions' => array(
140
+ 'action' => array(
141
+ 'sq_saveseo',
142
+ 'sq_getsnippet',
143
+ 'sq_previewsnippet',
144
+ ),
145
+ ),
146
+ 'active' => '1',
147
+ ),
148
+ array(
149
+ 'name' => 'SQ_Controllers_Patterns',
150
+ 'description' => 'Patterns Class',
151
+ 'actions' => array(
152
+ 'action' => array(
153
+ 'sq_getpatterns',
154
+ ),
155
+ ),
156
+ 'active' => '1',
157
+ ),
158
+ array(
159
+ 'name' => 'SQ_Controllers_BulkSeo',
160
+ 'actions' => array(
161
+ 'action' => array(
162
+ 'sq_ajax_assistant_bulkseo',
163
+ ),
164
+ ),
165
+ 'active' => '1',
166
+ ),
167
+ array(
168
+ 'name' => 'SQ_Controllers_SeoSettings',
169
+ 'actions' => array(
170
+ 'action' => array(
171
+ 'sq_seosettings_automation',
172
+ 'sq_seosettings_bulkseo',
173
+ 'sq_seosettings_jsonld',
174
+ 'sq_seosettings_metas',
175
+ 'sq_seosettings_links',
176
+ 'sq_seosettings_social',
177
+ 'sq_seosettings_tracking',
178
+ 'sq_seosettings_webmaster',
179
+ 'sq_seosettings_sitemap',
180
+ 'sq_seosettings_robots',
181
+ 'sq_seosettings_favicon',
182
+ 'sq_seosettings_backupsettings',
183
+ 'sq_seosettings_backupseo',
184
+ 'sq_seosettings_restoresettings',
185
+ 'sq_seosettings_restoreseo',
186
+ 'sq_seosettings_importsettings',
187
+ 'sq_seosettings_importseo',
188
+ 'sq_seosettings_importall',
189
+ 'sq_seosettings_ga_revoke',
190
+ 'sq_seosettings_gsc_revoke',
191
+ 'sq_seosettings_gsc_check',
192
+ 'sq_seosettings_ga_check',
193
+ 'sq_seosettings_clear_cache',
194
+ 'sq_seosettings_ga_save',
195
+ 'sq_reinstall',
196
+ 'sq_rollback',
197
+ 'sq_alerts_close',
198
+ 'sq_ajax_seosettings_save',
199
+ 'sq_ajax_automation_addpostype',
200
+ 'sq_ajax_automation_deletepostype',
201
+ 'sq_ajax_sla_sticky',
202
+ 'sq_ajax_gsc_code',
203
+ 'sq_ajax_ga_code',
204
+ 'sq_ajax_connection_check',
205
+ 'sq_seosettings_advanced',
206
+ ),
207
+ ),
208
+ 'active' => '1',
209
+ ),
210
+ array(
211
+ 'name' => 'SQ_Controllers_Research',
212
+ 'actions' => array(
213
+ 'action' => array(
214
+ 'sq_briefcase_addlabel',
215
+ 'sq_briefcase_editlabel',
216
+ 'sq_briefcase_keywordlabel',
217
+ 'sq_briefcase_article',
218
+ 'sq_briefcase_doresearch',
219
+ 'sq_briefcase_addkeyword',
220
+ 'sq_briefcase_deletekeyword',
221
+ 'sq_briefcase_deletelabel',
222
+ 'sq_briefcase_deletefound',
223
+ 'sq_briefcase_savemain',
224
+ 'sq_briefcase_backup',
225
+ 'sq_briefcase_restore',
226
+ 'sq_ajax_briefcase_doserp',
227
+ 'sq_ajax_research_others',
228
+ 'sq_ajax_research_process',
229
+ 'sq_ajax_research_history',
230
+ 'sq_ajax_briefcase_bulk_delete',
231
+ 'sq_ajax_briefcase_bulk_label',
232
+ 'sq_ajax_briefcase_bulk_doserp',
233
+ 'sq_ajax_labels_bulk_delete',
234
+ ),
235
+ ),
236
+ 'active' => '1',
237
+ ),
238
+ array(
239
+ 'name' => 'SQ_Controllers_Audits',
240
+ 'actions' => array(
241
+ 'action' => array(
242
+ 'sq_audits_settings',
243
+ 'sq_auditpages_getaudit',
244
+ 'sq_audits_getpage',
245
+ 'sq_audits_addnew',
246
+ 'sq_audits_page_update',
247
+ 'sq_audits_update',
248
+ 'sq_audits_delete',
249
+ ),
250
+ ),
251
+ 'active' => '1',
252
+ ),
253
+ array(
254
+ 'name' => 'SQ_Controllers_Ranking',
255
+ 'actions' => array(
256
+ 'action' => array(
257
+ 'sq_ranking_settings',
258
+ 'sq_serp_refresh_post',
259
+ 'sq_serp_delete_keyword',
260
+ 'sq_ajax_rank_bulk_delete',
261
+ 'sq_ajax_rank_bulk_refresh',
262
+ ),
263
+ ),
264
+ 'active' => '1',
265
+ ),
266
+ array(
267
+ 'name' => 'SQ_Controllers_Assistant',
268
+ 'actions' => array(
269
+ 'action' => array(
270
+ 'sq_settings_assistant',
271
+ 'sq_ajax_assistant',
272
+ ),
273
+ ),
274
+ 'active' => '1',
275
+ ),
276
+ array(
277
+ 'name' => 'SQ_Controllers_CheckSeo',
278
+ 'actions' => array(
279
+ 'action' => array(
280
+ 'sq_checkseo',
281
+ 'sq_fixsettings',
282
+ 'sq_donetask',
283
+ 'sq_resetignored',
284
+ 'sq_moretasks',
285
+ 'sq_ajax_checkseo',
286
+ 'sq_ajax_getgoals',
287
+ ),
288
+ ),
289
+ 'active' => '1',
290
+ ),
291
+ array(
292
+ 'name' => 'SQ_Controllers_Onboarding',
293
+ 'actions' => array(
294
+ 'action' => array(
295
+ 'sq_onboarding_commitment',
296
+ 'sq_onboading_checksite',
297
+ 'sq_onboarding_settings',
298
+ ),
299
+ ),
300
+ 'active' => '1',
301
+ ),
302
+ array(
303
+ 'name' => 'SQ_Core_BlockJorney',
304
+ 'actions' => array(
305
+ 'action' => array(
306
+ 'sq_journey_close',
307
+ ),
308
+ ),
309
+ 'active' => '1',
310
+ ),
311
+ array(
312
+ 'name' => 'SQ_Core_BlockSupport',
313
+ 'actions' => array(
314
+ 'action' => array(
315
+ 'sq_feedback',
316
+ 'sq_uninstall_feedback',
317
+ ),
318
+ ),
319
+ 'active' => '1',
320
+ ),
321
+ array(
322
+ 'name' => 'SQ_Core_BlockSearch',
323
+ 'actions' => array(
324
+ 'action' => array(
325
+ 'sq_ajax_search',
326
+ ),
327
+ ),
328
+ 'active' => '1',
329
+ ),
330
+ array(
331
+ 'name' => 'SQ_Controllers_Dashboard',
332
+ 'actions' => array(
333
+ 'action' => array(
334
+ 'sq_ajaxcheckseo',
335
+ ),
336
+ ),
337
+ 'active' => '1',
338
+ ),
339
+ );
340
+ }
341
+
342
+ /**
343
+ * Get all actions from config.json in core directory and add them in the WP
344
+ */
345
+ public function getActions()
346
+ {
347
+
348
+ if (!is_admin()) {
349
+ return;
350
+ }
351
+
352
+ $this->actions = array();
353
+ $cur_action = SQ_Classes_Helpers_Tools::getValue('action', false);
354
+ $http_referer = SQ_Classes_Helpers_Tools::getValue('_wp_http_referer', false);
355
+ $sq_nonce = SQ_Classes_Helpers_Tools::getValue('sq_nonce', false);
356
+
357
+ //Let only the logged users to access the actions
358
+ if ($cur_action <> '' && $sq_nonce <> '') {
359
+
360
+ //load the actions list for each class
361
+ $actions = $this->getActionsList();
362
+
363
+ if(!empty($actions)) {
364
+ foreach ($actions as $block) {
365
+ if (isset($block['active']) && $block['active'] == 1) {
366
+ /* if there is a single action */
367
+ if (isset($block['actions']['action']))
368
+ /* if there are more actions for the current block */
369
+ if (!is_array($block['actions']['action'])) {
370
+ /* add the action in the actions array */
371
+ if ($block['actions']['action'] == $cur_action) {
372
+ $this->actions[] = array('class' => $block['name']);
373
+ }
374
+ } else {
375
+ /* if there are more actions for the current block */
376
+ foreach ($block['actions']['action'] as $action) {
377
+ /* add the actions in the actions array */
378
+ if ($action == $cur_action) {
379
+ $this->actions[] = array('class' => $block['name']);
380
+ }
381
+ }
382
+ }
383
+ }
384
+ }
385
+ }
386
+
387
+ //If there is an action found in the config.js file
388
+ if (!empty($this->actions)) {
389
+ /* add the actions in WP */
390
+ foreach ($this->actions as $actions) {
391
+ if (SQ_Classes_Helpers_Tools::isAjax() && !$http_referer) {
392
+ check_ajax_referer(_SQ_NONCE_ID_, 'sq_nonce');
393
+ add_action('wp_ajax_' . $cur_action, array(SQ_Classes_ObjController::getClass($actions['class']), 'action'));
394
+ } else {
395
+ check_admin_referer($cur_action, 'sq_nonce');
396
+
397
+ SQ_Classes_ObjController::getClass($actions['class'])->action();
398
+ }
399
+ }
400
+ }
401
+ }
402
+
403
+ //For Post List
404
+ if(SQ_Classes_Helpers_Tools::isAjax() && $cur_action <> '' && $cur_action == 'inline-save') {
405
+ check_ajax_referer('inlineeditnonce', '_inline_edit');
406
+ SQ_Classes_ObjController::getClass('SQ_Controllers_PostsList')->action();
407
+
408
+ }
409
+
410
+
411
+ }
412
+
413
+ }
classes/BlockController.php CHANGED
@@ -1,87 +1,132 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- /**
5
- * The main class for core blocks
6
- *
7
- */
8
- class SQ_Classes_BlockController {
9
-
10
- /** @var object of the model class */
11
- protected $model;
12
-
13
- /** @var boolean */
14
- public $flush = true;
15
-
16
- /** @var object of the view class */
17
- protected $view;
18
-
19
- /** @var string name of the class */
20
- private $name;
21
-
22
- public function __construct() {
23
- /* get the name of the current class */
24
- $this->name = get_class($this);
25
-
26
- /* create the model and view instances */
27
- $model_classname = str_replace('Core', 'Models', $this->name);
28
- if (SQ_Classes_ObjController::getClassPath($model_classname)) {
29
- $this->model = SQ_Classes_ObjController::getClass($model_classname);
30
- }
31
- }
32
-
33
- /**
34
- * load sequence of classes
35
- * Function called usualy when the controller is loaded in WP
36
- *
37
- * @return mixed
38
- */
39
- public function init() {
40
- /* check if there is a hook defined in the block class */
41
- SQ_Classes_ObjController::getClass('SQ_Classes_HookController')->setBlockHooks($this);
42
- //get the class path
43
- $class = SQ_Classes_ObjController::getClassPath($this->name);
44
-
45
- if (!$this->flush) {
46
- return $this->getView($class['name']);
47
- }
48
-
49
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia($class['name']);
50
- echo (string)$this->getView($class['name']);
51
-
52
- }
53
-
54
- /**
55
- * Get the block view
56
- *
57
- * @param string $view Class name
58
- * @return mixed
59
- */
60
- public function getView($view) {
61
- return SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->getView($view, $this);
62
- }
63
-
64
- /**
65
- * Called as menu callback to show the block
66
- *
67
- */
68
- public function show() {
69
- $this->flush = true;
70
-
71
- echo $this->init();
72
- }
73
-
74
- /**
75
- * This function is called from Ajax class as a wp_ajax_action
76
- *
77
- */
78
- protected function action() { }
79
-
80
- /**
81
- * This function will load the media in the header for each class
82
- *
83
- * @return void
84
- */
85
- protected function hookHead() { }
86
-
87
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ /**
5
+ * The main class for core blocks
6
+ */
7
+ class SQ_Classes_BlockController
8
+ {
9
+
10
+ /**
11
+ *
12
+ *
13
+ * @var object of the model class
14
+ */
15
+ protected $model;
16
+
17
+ /**
18
+ *
19
+ *
20
+ * @var boolean
21
+ */
22
+ public $flush = true;
23
+
24
+ /**
25
+ *
26
+ *
27
+ * @var object of the view class
28
+ */
29
+ protected $view;
30
+
31
+ /**
32
+ *
33
+ *
34
+ * @var string name of the class
35
+ */
36
+ private $name;
37
+
38
+ public function __construct()
39
+ {
40
+ /* get the name of the current class */
41
+ $this->name = get_class($this);
42
+
43
+ /* create the model and view instances */
44
+ $model_classname = str_replace('Core', 'Models', $this->name);
45
+ if (SQ_Classes_ObjController::getClassPath($model_classname)) {
46
+ $this->model = SQ_Classes_ObjController::getClass($model_classname);
47
+ }
48
+ }
49
+
50
+ /**
51
+ * load sequence of classes
52
+ * Function called usualy when the controller is loaded in WP
53
+ *
54
+ * @return mixed
55
+ */
56
+ public function init()
57
+ {
58
+ /* check if there is a hook defined in the block class */
59
+ SQ_Classes_ObjController::getClass('SQ_Classes_HookController')->setBlockHooks($this);
60
+ //get the class path
61
+ $class = SQ_Classes_ObjController::getClassPath($this->name);
62
+
63
+ if (!$this->flush) {
64
+ return $this->get_view($class['name']);
65
+ }
66
+
67
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia($class['name']);
68
+ $this->show_view($class['name']);
69
+
70
+ }
71
+
72
+ /**
73
+ * Get the block view
74
+ *
75
+ * @param string $view Class name
76
+ * @return string The file from /view directory
77
+ */
78
+ public function get_view($view)
79
+ {
80
+ return SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->get_view($view, $this);
81
+ }
82
+
83
+ /**
84
+ * Show the view block
85
+ *
86
+ * @param string $view Class name
87
+ * @return string the included view file from /view directory
88
+ */
89
+ public function show_view($view)
90
+ {
91
+ $content = SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->get_view($view, $this);
92
+
93
+ //Support for international languages
94
+ if (function_exists('iconv') && SQ_Classes_Helpers_Tools::getOption('sq_non_utf8_support')) {
95
+ if (strpos(get_bloginfo("language"), 'en') === false) {
96
+ $content = iconv('UTF-8', 'UTF-8//IGNORE', $content);
97
+ }
98
+ }
99
+
100
+ //echo the file from /view directory
101
+ //already escaped in the view
102
+ //Contains HTML output
103
+ echo $content;
104
+ }
105
+
106
+ /**
107
+ * Called as menu callback to show the block
108
+ */
109
+ public function show()
110
+ {
111
+ $this->flush = true;
112
+
113
+ echo $this->init();
114
+ }
115
+
116
+ /**
117
+ * This function is called from Ajax class as a wp_ajax_action
118
+ */
119
+ protected function action()
120
+ {
121
+ }
122
+
123
+ /**
124
+ * This function will load the media in the header for each class
125
+ *
126
+ * @return void
127
+ */
128
+ protected function hookHead()
129
+ {
130
+ }
131
+
132
+ }
classes/DisplayController.php CHANGED
@@ -1,123 +1,127 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- /**
5
- * The class handles the theme part in WP
6
- */
7
- class SQ_Classes_DisplayController {
8
-
9
- private static $cache;
10
-
11
- /**
12
- * echo the css link from theme css directory
13
- *
14
- * @param string $uri The name of the css file or the entire uri path of the css file
15
- * @param string $params : trigger, media
16
- *
17
- * @return void
18
- */
19
- public static function loadMedia($uri = '', $params = array()) {
20
- if (SQ_Classes_Helpers_Tools::isAjax()) {
21
- return;
22
- }
23
-
24
- if (empty($params)) {
25
- $params = array(
26
- 'trigger' => false,
27
- 'media' => 'all'
28
- );
29
- }
30
-
31
- $css_uri = '';
32
- $js_uri = '';
33
-
34
- if (isset(self::$cache[$uri]))
35
- return;
36
-
37
- self::$cache[$uri] = true;
38
-
39
- /* if is a custom css file */
40
- if (strpos($uri, '//') === false) {
41
- $name = substr(md5($uri), 0, 10);
42
-
43
- if (strpos($uri, '.css') !== false && file_exists(_SQ_ASSETS_DIR_ . 'css/' . strtolower($uri))) {
44
- $css_uri = _SQ_ASSETS_URL_ . 'css/' . strtolower($uri);
45
- }
46
- if (file_exists(_SQ_ASSETS_DIR_ . 'css/' . strtolower($uri) . (SQ_DEBUG ? '' : '.min') . '.css')) {
47
- $css_uri = _SQ_ASSETS_URL_ . 'css/' . strtolower($uri) . (SQ_DEBUG ? '' : '.min') . '.css';
48
- }
49
-
50
- if (strpos($uri, '.js') !== false && file_exists(_SQ_ASSETS_DIR_ . 'js/' . strtolower($uri))) {
51
- $js_uri = _SQ_ASSETS_URL_ . 'js/' . strtolower($uri);
52
- }
53
- if (file_exists(_SQ_ASSETS_DIR_ . 'js/' . strtolower($uri) . (SQ_DEBUG ? '' : '.min') . '.js')) {
54
- $js_uri = _SQ_ASSETS_URL_ . 'js/' . strtolower($uri) . (SQ_DEBUG ? '' : '.min') . '.js';
55
- }
56
-
57
- } else {
58
-
59
- $name = substr(md5($uri), 0, 10);
60
-
61
- if (strpos($uri, '.css') !== FALSE) {
62
- $css_uri = $uri;
63
- } elseif (strpos($uri, '.js') !== FALSE) {
64
- $js_uri = $uri;
65
- }
66
-
67
- }
68
-
69
-
70
- if ($css_uri <> '') {
71
- if (!wp_style_is($name)) {
72
- wp_enqueue_style($name, $css_uri, null, SQ_VERSION, $params['media']);
73
-
74
- if (is_admin() || (isset($params['trigger']) && $params['trigger'] === true)) { //load CSS for admin or on triggered
75
- wp_print_styles(array($name));
76
- }
77
- }
78
-
79
- }
80
-
81
- if ($js_uri <> '') {
82
- if (!wp_script_is($name)) {
83
-
84
- if (!wp_script_is('jquery')) {
85
- wp_enqueue_script('jquery');
86
- wp_print_scripts(array('jquery'));
87
- }
88
-
89
- wp_enqueue_script($name, $js_uri, null, SQ_VERSION);
90
-
91
- if (is_admin() || isset($params['trigger']) && $params['trigger'] === true) {
92
- wp_print_scripts(array($name));
93
- }
94
- }
95
-
96
- }
97
- }
98
-
99
- /**
100
- * return the block content from theme directory
101
- *
102
- * @param $block
103
- * @param $view
104
- * @return bool|string
105
- */
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
- ob_start();
113
- include($file);
114
- return ob_get_clean();
115
- }
116
-
117
- } catch (Exception $e) {
118
- }
119
-
120
- return false;
121
- }
122
-
123
- }
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ /**
5
+ * The class handles the theme part in WP
6
+ */
7
+ class SQ_Classes_DisplayController
8
+ {
9
+
10
+ private static $cache;
11
+
12
+ /**
13
+ * echo the css link from theme css directory
14
+ *
15
+ * @param string $uri The name of the css file or the entire uri path of the css file
16
+ * @param string $params : trigger, media
17
+ *
18
+ * @return void
19
+ */
20
+ public static function loadMedia($uri = '', $params = array())
21
+ {
22
+ if (SQ_Classes_Helpers_Tools::isAjax()) {
23
+ return;
24
+ }
25
+
26
+ if (empty($params)) {
27
+ $params = array(
28
+ 'trigger' => false,
29
+ 'media' => 'all'
30
+ );
31
+ }
32
+
33
+ $css_uri = '';
34
+ $js_uri = '';
35
+
36
+ if (isset(self::$cache[$uri]))
37
+ return;
38
+
39
+ self::$cache[$uri] = true;
40
+
41
+ /* if is a custom css file */
42
+ if (strpos($uri, '//') === false) {
43
+ $name = substr(md5($uri), 0, 10);
44
+
45
+ if (strpos($uri, '.css') !== false && file_exists(_SQ_ASSETS_DIR_ . 'css/' . strtolower($uri))) {
46
+ $css_uri = _SQ_ASSETS_URL_ . 'css/' . strtolower($uri);
47
+ }
48
+ if (file_exists(_SQ_ASSETS_DIR_ . 'css/' . strtolower($uri) . (SQ_DEBUG ? '' : '.min') . '.css')) {
49
+ $css_uri = _SQ_ASSETS_URL_ . 'css/' . strtolower($uri) . (SQ_DEBUG ? '' : '.min') . '.css';
50
+ }
51
+
52
+ if (strpos($uri, '.js') !== false && file_exists(_SQ_ASSETS_DIR_ . 'js/' . strtolower($uri))) {
53
+ $js_uri = _SQ_ASSETS_URL_ . 'js/' . strtolower($uri);
54
+ }
55
+ if (file_exists(_SQ_ASSETS_DIR_ . 'js/' . strtolower($uri) . (SQ_DEBUG ? '' : '.min') . '.js')) {
56
+ $js_uri = _SQ_ASSETS_URL_ . 'js/' . strtolower($uri) . (SQ_DEBUG ? '' : '.min') . '.js';
57
+ }
58
+
59
+ } else {
60
+
61
+ $name = substr(md5($uri), 0, 10);
62
+
63
+ if (strpos($uri, '.css') !== false) {
64
+ $css_uri = $uri;
65
+ } elseif (strpos($uri, '.js') !== false) {
66
+ $js_uri = $uri;
67
+ }
68
+
69
+ }
70
+
71
+
72
+ if ($css_uri <> '') {
73
+ if (!wp_style_is($name)) {
74
+ wp_enqueue_style($name, $css_uri, null, SQ_VERSION, $params['media']);
75
+
76
+ if (is_admin() || (isset($params['trigger']) && $params['trigger'] === true)) { //load CSS for admin or on triggered
77
+ wp_print_styles(array($name));
78
+ }
79
+ }
80
+
81
+ }
82
+
83
+ if ($js_uri <> '') {
84
+ if (!wp_script_is($name)) {
85
+
86
+ if (!wp_script_is('jquery')) {
87
+ wp_enqueue_script('jquery');
88
+ wp_print_scripts(array('jquery'));
89
+ }
90
+
91
+ wp_enqueue_script($name, $js_uri, null, SQ_VERSION);
92
+
93
+ if (is_admin() || isset($params['trigger']) && $params['trigger'] === true) {
94
+ wp_print_scripts(array($name));
95
+ }
96
+ }
97
+
98
+ }
99
+ }
100
+
101
+ /**
102
+ * return the block content from theme directory
103
+ *
104
+ * @param $block
105
+ * @param $view
106
+ * @return bool|string
107
+ */
108
+ public function get_view($block, $view)
109
+ {
110
+
111
+ try {
112
+ $file = apply_filters('sq_view', _SQ_THEME_DIR_ . $block . '.php', $block);
113
+
114
+ if (file_exists($file)) {
115
+ ob_start();
116
+ include $file;
117
+ return ob_get_clean();
118
+ }
119
+
120
+ } catch (Exception $e) {
121
+ }
122
+
123
+ return false;
124
+ }
125
+
126
+
127
+ }
classes/Error.php CHANGED
@@ -1,136 +1,153 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- class SQ_Classes_Error extends SQ_Classes_FrontController {
5
-
6
- /** @var array */
7
- private static $errors = array();
8
- private static $switch_off = array();
9
-
10
- public function __construct() {
11
- parent::__construct();
12
-
13
- add_action('sq_notices', array('SQ_Classes_Error', 'hookNotices'));
14
- }
15
-
16
- /**
17
- * Get the error message
18
- * @return int
19
- */
20
- public static function getError() {
21
- if (count(self::$errors) > 0) {
22
- return self::$errors[0]['text'];
23
- }
24
-
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
- *
38
- * @param string $error
39
- * @param string $type
40
- * @param string $id
41
- */
42
- public static function setError($error = '', $type = 'notice', $id = '') {
43
- self::$errors[] = array(
44
- 'id' => $id,
45
- 'type' => $type,
46
- 'text' => $error);
47
- }
48
-
49
- /**
50
- * Check if there is a Squirrly Error triggered
51
- * @return bool
52
- */
53
- public static function isError() {
54
- if(!empty(self::$errors)){
55
- foreach (self::$errors as $error){
56
- if($error['type'] <> 'success' ){
57
- return true;
58
- }
59
- }
60
- }
61
- }
62
-
63
- /**
64
- * Set a success message
65
- * @param string $message
66
- * @param string $id
67
- */
68
- public static function setMessage($message = '', $id = '') {
69
- self::$errors[] = array(
70
- 'id' => $id,
71
- 'type' => 'success',
72
- 'text' => $message);
73
- }
74
-
75
- /**
76
- * This hook will show the error in WP header
77
- */
78
- public static function hookNotices() {
79
- if (is_array(self::$errors))
80
- foreach (self::$errors as $error) {
81
-
82
- switch ($error['type']) {
83
- case 'fatal':
84
- self::showError(ucfirst(_SQ_PLUGIN_NAME_ . " " . $error['type']) . ': ' . $error['text'], $error['id']);
85
- die();
86
- break;
87
- case 'settings':
88
- /* switch off option for notifications */
89
- self::showError($error['text'] . " ", $error['id']);
90
- break;
91
-
92
- case 'success':
93
- self::showError($error['text'] . " ", $error['id'], 'sq_success');
94
- break;
95
-
96
- default:
97
- self::showError($error['text'], $error['id']);
98
- }
99
- }
100
- }
101
-
102
- /**
103
- * Show the notices to WP
104
- *
105
- * @param $message
106
- * @param string $type
107
- * @return string
108
- */
109
- public static function showNotices($message, $type = 'sq_notices') {
110
- if (file_exists(_SQ_THEME_DIR_ . 'Notices.php')) {
111
- ob_start();
112
- include(_SQ_THEME_DIR_ . 'Notices.php');
113
- $message = ob_get_contents();
114
- ob_end_clean();
115
- }
116
-
117
- return (string)$message;
118
- }
119
-
120
- /**
121
- * Show the notices to WP
122
- *
123
- * @param $message
124
- * @param string $id
125
- * @param string $type
126
- *
127
- * return void
128
- */
129
- public static function showError($message, $id = '', $type = 'sq_error') {
130
- if (file_exists(_SQ_THEME_DIR_ . 'Notices.php')) {
131
- include(_SQ_THEME_DIR_ . 'Notices.php');
132
- }
133
- }
134
-
135
-
136
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ class SQ_Classes_Error extends SQ_Classes_FrontController
5
+ {
6
+
7
+ /**
8
+ *
9
+ *
10
+ * @var array
11
+ */
12
+ private static $errors = array();
13
+ private static $switch_off = array();
14
+
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+
19
+ add_action('sq_notices', array('SQ_Classes_Error', 'hookNotices'));
20
+ }
21
+
22
+ /**
23
+ * Get the error message
24
+ *
25
+ * @return int
26
+ */
27
+ public static function getError()
28
+ {
29
+ if (count(self::$errors) > 0) {
30
+ return self::$errors[0]['text'];
31
+ }
32
+
33
+ return false;
34
+ }
35
+
36
+ /**
37
+ * Clear all the Errors from Squirrly SEO
38
+ */
39
+ public static function clearErrors()
40
+ {
41
+ self::$errors = array();
42
+ }
43
+
44
+ /**
45
+ * Show the error in wrodpress
46
+ *
47
+ * @param string $error
48
+ * @param string $type
49
+ * @param string $id
50
+ */
51
+ public static function setError($error = '', $type = 'notice', $id = '')
52
+ {
53
+ self::$errors[] = array(
54
+ 'id' => $id,
55
+ 'type' => $type,
56
+ 'text' => $error);
57
+ }
58
+
59
+ /**
60
+ * Check if there is a Squirrly Error triggered
61
+ *
62
+ * @return bool
63
+ */
64
+ public static function isError()
65
+ {
66
+ if(!empty(self::$errors)) {
67
+ foreach (self::$errors as $error){
68
+ if($error['type'] <> 'success' ) {
69
+ return true;
70
+ }
71
+ }
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Set a success message
77
+ *
78
+ * @param string $message
79
+ * @param string $id
80
+ */
81
+ public static function setMessage($message = '', $id = '')
82
+ {
83
+ self::$errors[] = array(
84
+ 'id' => $id,
85
+ 'type' => 'success',
86
+ 'text' => $message);
87
+ }
88
+
89
+ /**
90
+ * This hook will show the error in WP header
91
+ */
92
+ public static function hookNotices()
93
+ {
94
+ if (is_array(self::$errors))
95
+ foreach (self::$errors as $error) {
96
+
97
+ switch ($error['type']) {
98
+ case 'fatal':
99
+ self::showError(ucfirst(_SQ_PLUGIN_NAME_ . " " . $error['type']) . ': ' . $error['text'], $error['id']);
100
+ die();
101
+ break;
102
+ case 'settings':
103
+ /* switch off option for notifications */
104
+ self::showError($error['text'] . " ", $error['id']);
105
+ break;
106
+
107
+ case 'success':
108
+ self::showError($error['text'] . " ", $error['id'], 'sq_success');
109
+ break;
110
+
111
+ default:
112
+ self::showError($error['text'], $error['id']);
113
+ }
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Show the notices to WP
119
+ *
120
+ * @param $message
121
+ * @param string $type
122
+ * @return string
123
+ */
124
+ public static function showNotices($message, $type = 'sq_notices')
125
+ {
126
+ if (file_exists(_SQ_THEME_DIR_ . 'Notices.php')) {
127
+ ob_start();
128
+ include _SQ_THEME_DIR_ . 'Notices.php';
129
+ $message = ob_get_contents();
130
+ ob_end_clean();
131
+ }
132
+
133
+ return (string)$message;
134
+ }
135
+
136
+ /**
137
+ * Show the notices to WP
138
+ *
139
+ * @param $message
140
+ * @param string $id
141
+ * @param string $type
142
+ *
143
+ * return void
144
+ */
145
+ public static function showError($message, $id = '', $type = 'sq_error')
146
+ {
147
+ if (file_exists(_SQ_THEME_DIR_ . 'Notices.php')) {
148
+ include _SQ_THEME_DIR_ . 'Notices.php';
149
+ }
150
+ }
151
+
152
+
153
+ }
classes/FrontController.php CHANGED
@@ -1,140 +1,185 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- /**
5
- * The main class for controllers
6
- *
7
- */
8
- class SQ_Classes_FrontController {
9
-
10
- /** @var object of the model class */
11
- public $model;
12
-
13
- /** @var boolean */
14
- public $flush = true;
15
-
16
- /** @var name of the class */
17
- private $name;
18
-
19
- public function __construct() {
20
- // Load error class
21
- SQ_Classes_ObjController::getClass('SQ_Classes_Error');
22
-
23
- /* get the name of the current class */
24
- $this->name = get_class($this);
25
-
26
- /* load the model and hooks here for wordpress actions to take efect */
27
- /* create the model and view instances */
28
- $model_classname = str_replace('Controllers', 'Models', $this->name);
29
- if (SQ_Classes_ObjController::getClassPath($model_classname)) {
30
- $this->model = SQ_Classes_ObjController::getClass($model_classname);
31
- }
32
-
33
- //IMPORTANT TO LOAD HOOKS HERE
34
- /* check if there is a hook defined in the controller clients class */
35
- SQ_Classes_ObjController::getClass('SQ_Classes_HookController')->setHooks($this);
36
-
37
- /* Load the Submit Actions Handler */
38
- SQ_Classes_ObjController::getClass('SQ_Classes_ActionController');
39
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController');
40
-
41
- // load the abstract classes
42
- SQ_Classes_ObjController::getClass('SQ_Models_Abstract_Domain');
43
- SQ_Classes_ObjController::getClass('SQ_Models_Abstract_Models');
44
- SQ_Classes_ObjController::getClass('SQ_Models_Abstract_Seo');
45
- }
46
-
47
- public function getClass() {
48
- return $this->name;
49
- }
50
-
51
- /**
52
- * load sequence of classes
53
- * Function called usualy when the controller is loaded in WP
54
- *
55
- * @return mixed
56
- */
57
- public function init() {
58
- $class = SQ_Classes_ObjController::getClassPath($this->name);
59
-
60
- if (!$this->flush) {
61
- return $this->getView($class['name']);
62
- }
63
-
64
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia($class['name']);
65
- echo $this->getView($class['name']);
66
-
67
- }
68
-
69
- /**
70
- * Get the block view
71
- *
72
- * @param string $view Class name
73
- * @return mixed
74
- */
75
- public function getView($view) {
76
- return SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->getView($view, $this);
77
- }
78
-
79
- /**
80
- * Called as menu callback to show the block
81
- *
82
- */
83
- public function show() {
84
- $this->flush = true;
85
-
86
- echo $this->init();
87
- }
88
-
89
- /**
90
- * initialize settings
91
- * Called from index
92
- *
93
- * @return void
94
- */
95
- public function runAdmin() {
96
- // load the remote controller in admin
97
- SQ_Classes_ObjController::getClass('SQ_Classes_RemoteController');
98
- SQ_Classes_ObjController::getClass('SQ_Models_Abstract_Assistant');
99
-
100
- // show the admin menu and post actions
101
- SQ_Classes_ObjController::getClass('SQ_Controllers_Menu');
102
- SQ_Classes_ObjController::getClass('SQ_Models_RoleManager');
103
-
104
- }
105
-
106
- /**
107
- * Run fron frontend
108
- */
109
- public function runFrontend() {
110
- //Load Frontend only if Squirrly SEO is enabled
111
- SQ_Classes_ObjController::getClass('SQ_Controllers_Frontend');
112
-
113
- /* show the topbar admin menu and post actions */
114
- SQ_Classes_ObjController::getClass('SQ_Controllers_Snippet');
115
-
116
- /* call the API for save posts */
117
- SQ_Classes_ObjController::getClass('SQ_Controllers_Api');
118
-
119
- }
120
-
121
- /**
122
- * first function call for any class
123
- *
124
- */
125
- protected function action() { }
126
-
127
- /**
128
- * This function will load the media in the header for each class
129
- *
130
- * @return void
131
- */
132
- public function hookHead() { }
133
-
134
- /**
135
- * Show the notification bar
136
- */
137
- public function getNotificationBar(){
138
- echo $this->getView('Blocks/VersionBar');
139
- }
140
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ /**
5
+ * The main class for controllers
6
+ */
7
+ class SQ_Classes_FrontController
8
+ {
9
+
10
+ /**
11
+ *
12
+ *
13
+ * @var object of the model class
14
+ */
15
+ public $model;
16
+
17
+ /**
18
+ *
19
+ *
20
+ * @var boolean
21
+ */
22
+ public $flush = true;
23
+
24
+ /**
25
+ *
26
+ *
27
+ * @var name of the class
28
+ */
29
+ private $name;
30
+
31
+ public function __construct()
32
+ {
33
+ // Load error class
34
+ SQ_Classes_ObjController::getClass('SQ_Classes_Error');
35
+
36
+ /* get the name of the current class */
37
+ $this->name = get_class($this);
38
+
39
+ /* load the model and hooks here for wordpress actions to take efect */
40
+ /* create the model and view instances */
41
+ $model_classname = str_replace('Controllers', 'Models', $this->name);
42
+ if (SQ_Classes_ObjController::getClassPath($model_classname)) {
43
+ $this->model = SQ_Classes_ObjController::getClass($model_classname);
44
+ }
45
+
46
+ //IMPORTANT TO LOAD HOOKS HERE
47
+ /* check if there is a hook defined in the controller clients class */
48
+ SQ_Classes_ObjController::getClass('SQ_Classes_HookController')->setHooks($this);
49
+
50
+ /* Load the Submit Actions Handler */
51
+ SQ_Classes_ObjController::getClass('SQ_Classes_ActionController');
52
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController');
53
+
54
+ // load the abstract classes
55
+ SQ_Classes_ObjController::getClass('SQ_Models_Abstract_Domain');
56
+ SQ_Classes_ObjController::getClass('SQ_Models_Abstract_Models');
57
+ SQ_Classes_ObjController::getClass('SQ_Models_Abstract_Seo');
58
+ }
59
+
60
+ public function getClass()
61
+ {
62
+ return $this->name;
63
+ }
64
+
65
+ /**
66
+ * load sequence of classes
67
+ * Function called usualy when the controller is loaded in WP
68
+ *
69
+ * @return mixed
70
+ */
71
+ public function init()
72
+ {
73
+ $class = SQ_Classes_ObjController::getClassPath($this->name);
74
+
75
+ if (!$this->flush) {
76
+ return $this->get_view($class['name']);
77
+ }
78
+
79
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia($class['name']);
80
+ $this->show_view($class['name']);
81
+
82
+ }
83
+
84
+ /**
85
+ * Get the view block
86
+ *
87
+ * @param string $view Class name
88
+ * @return mixed
89
+ */
90
+ public function get_view($view)
91
+ {
92
+ return SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->get_view($view, $this);
93
+ }
94
+
95
+ /**
96
+ * Show the view block
97
+ *
98
+ * @param string $view Class name
99
+ * @return string the included view file from /view directory
100
+ */
101
+ public function show_view($view)
102
+ {
103
+ $content = SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->get_view($view, $this);
104
+
105
+ //Support for international languages
106
+ if (function_exists('iconv') && SQ_Classes_Helpers_Tools::getOption('sq_non_utf8_support')) {
107
+ if (strpos(get_bloginfo("language"), 'en') === false) {
108
+ $content = iconv('UTF-8', 'UTF-8//IGNORE', $content);
109
+ }
110
+ }
111
+
112
+ //echo the file from /view directory
113
+ //already escaped in the view
114
+ //Contains HTML output
115
+ echo $content;
116
+ }
117
+
118
+ /**
119
+ * Called as menu callback to show the block
120
+ */
121
+ public function show()
122
+ {
123
+ $this->flush = true;
124
+
125
+ echo $this->init();
126
+ }
127
+
128
+ /**
129
+ * initialize settings
130
+ * Called from index
131
+ *
132
+ * @return void
133
+ */
134
+ public function runAdmin()
135
+ {
136
+ // load the remote controller in admin
137
+ SQ_Classes_ObjController::getClass('SQ_Classes_RemoteController');
138
+ SQ_Classes_ObjController::getClass('SQ_Models_Abstract_Assistant');
139
+
140
+ // show the admin menu and post actions
141
+ SQ_Classes_ObjController::getClass('SQ_Controllers_Menu');
142
+ SQ_Classes_ObjController::getClass('SQ_Models_RoleManager');
143
+
144
+ }
145
+
146
+ /**
147
+ * Run fron frontend
148
+ */
149
+ public function runFrontend()
150
+ {
151
+ //Load Frontend only if Squirrly SEO is enabled
152
+ SQ_Classes_ObjController::getClass('SQ_Controllers_Frontend');
153
+
154
+ /* show the topbar admin menu and post actions */
155
+ SQ_Classes_ObjController::getClass('SQ_Controllers_Snippet');
156
+
157
+ /* call the API for save posts */
158
+ SQ_Classes_ObjController::getClass('SQ_Controllers_Api');
159
+
160
+ }
161
+
162
+ /**
163
+ * first function call for any class
164
+ */
165
+ protected function action()
166
+ {
167
+ }
168
+
169
+ /**
170
+ * This function will load the media in the header for each class
171
+ *
172
+ * @return void
173
+ */
174
+ public function hookHead()
175
+ {
176
+ }
177
+
178
+ /**
179
+ * Show the notification bar
180
+ */
181
+ public function getNotificationBar()
182
+ {
183
+ $this->show_view('Blocks/VersionBar');
184
+ }
185
+ }
classes/HookController.php CHANGED
@@ -1,115 +1,131 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- /**
5
- * The class handles the actions in WP
6
- */
7
- class SQ_Classes_HookController {
8
-
9
- /** @var array the WP actions list from admin */
10
- private $admin_hooks = array();
11
- private $front_hooks = array();
12
- private $block_hooks = array();
13
-
14
- public function __construct() {
15
- $this->admin_hooks = array(
16
- 'init' => 'admin_init',
17
- 'head' => 'admin_head',
18
- 'footer' => 'admin_footer',
19
- 'menu' => 'admin_menu',
20
- 'networkMenu' => 'network_admin_menu',
21
- 'notices' => 'admin_notices',
22
- );
23
-
24
- //called in frontend
25
- $this->front_hooks = array(
26
- // --
27
- 'init' => 'init',
28
- 'preload' => 'template_redirect',
29
- 'frontinit' => 'init',
30
- 'fronthead' => 'wp_head',
31
- 'frontfooter' => 'wp_footer',
32
- );
33
-
34
- $this->block_hooks = array('getContent' => 'getContent');
35
- }
36
-
37
- /**
38
- * Calls the specified action in WP
39
- * @param object $instance The parent class instance
40
- *
41
- * @return void
42
- */
43
- public function setHooks($instance) {
44
- if (is_admin() || is_network_admin()) {
45
- $this->setAdminHooks($instance);
46
- } else {
47
- $this->setFrontHooks($instance);
48
- }
49
- }
50
-
51
- /**
52
- * Calls the specified action in WP
53
- * @param object $instance The parent class instance
54
- *
55
- * @return void
56
- */
57
- public function setAdminHooks($instance) {
58
-
59
- /* for each admin action check if is defined in class and call it */
60
- foreach ($this->admin_hooks as $hook => $value) {
61
-
62
- if (is_callable(array($instance, 'hook' . ucfirst($hook)))) {
63
- //call the WP add_action function
64
- add_action($value, array($instance, 'hook' . ucfirst($hook)), 5);
65
- }
66
- }
67
- }
68
-
69
- /**
70
- * Calls the specified action in WP
71
- * @param object $instance The parent class instance
72
- *
73
- * @return void
74
- */
75
- public function setFrontHooks($instance) {
76
- /* for each admin action check if is defined in class and call it */
77
- foreach ($this->front_hooks as $hook => $value) {
78
- if (is_callable(array($instance, 'hook' . ucfirst($hook)))) {
79
- //call the WP add_action function
80
- add_action($value, array($instance, 'hook' . ucfirst($hook)), 5);
81
- }
82
- }
83
- }
84
-
85
- /**
86
- * Calls the specified action in WP
87
- * @param string $action
88
- * @param array $callback Contains the class name or object and the callback function
89
- *
90
- * @return void
91
- */
92
- public function setAction($action, $obj, $callback) {
93
-
94
- /* calls the custom action function from WP */
95
- add_action($action, array($obj, $callback), 10);
96
- }
97
-
98
- /**
99
- * Calls the specified action in WP
100
- * @param object $instance The parent class instance
101
- *
102
- * @return void
103
- */
104
- public function setBlockHooks($instance) {
105
- $param_arr = array();
106
-
107
- /* for each admin action check if is defined in class and call it */
108
- foreach ($this->block_hooks as $hook => $value)
109
- if (is_callable(array($instance, 'hook' . ucfirst($hook)))){
110
- //call the WP add_action function
111
- call_user_func_array(array($instance, 'hook' . ucfirst($hook)), $param_arr);
112
- }
113
- }
114
-
115
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ /**
5
+ * The class handles the actions in WP
6
+ */
7
+ class SQ_Classes_HookController
8
+ {
9
+
10
+ /**
11
+ *
12
+ *
13
+ * @var array the WP actions list from admin
14
+ */
15
+ private $admin_hooks = array();
16
+ private $front_hooks = array();
17
+ private $block_hooks = array();
18
+
19
+ public function __construct()
20
+ {
21
+ $this->admin_hooks = array(
22
+ 'init' => 'admin_init',
23
+ 'head' => 'admin_head',
24
+ 'footer' => 'admin_footer',
25
+ 'menu' => 'admin_menu',
26
+ 'networkMenu' => 'network_admin_menu',
27
+ 'notices' => 'admin_notices',
28
+ );
29
+
30
+ //called in frontend
31
+ $this->front_hooks = array(
32
+ // --
33
+ 'init' => 'init',
34
+ 'preload' => 'template_redirect',
35
+ 'frontinit' => 'init',
36
+ 'fronthead' => 'wp_head',
37
+ 'frontfooter' => 'wp_footer',
38
+ );
39
+
40
+ $this->block_hooks = array('getContent' => 'getContent');
41
+ }
42
+
43
+ /**
44
+ * Calls the specified action in WP
45
+ *
46
+ * @param object $instance The parent class instance
47
+ *
48
+ * @return void
49
+ */
50
+ public function setHooks($instance)
51
+ {
52
+ if (is_admin() || is_network_admin()) {
53
+ $this->setAdminHooks($instance);
54
+ } else {
55
+ $this->setFrontHooks($instance);
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Calls the specified action in WP
61
+ *
62
+ * @param object $instance The parent class instance
63
+ *
64
+ * @return void
65
+ */
66
+ public function setAdminHooks($instance)
67
+ {
68
+
69
+ /* for each admin action check if is defined in class and call it */
70
+ foreach ($this->admin_hooks as $hook => $value) {
71
+
72
+ if (is_callable(array($instance, 'hook' . ucfirst($hook)))) {
73
+ //call the WP add_action function
74
+ add_action($value, array($instance, 'hook' . ucfirst($hook)), 5);
75
+ }
76
+ }
77
+ }
78
+
79
+ /**
80
+ * Calls the specified action in WP
81
+ *
82
+ * @param object $instance The parent class instance
83
+ *
84
+ * @return void
85
+ */
86
+ public function setFrontHooks($instance)
87
+ {
88
+ /* for each admin action check if is defined in class and call it */
89
+ foreach ($this->front_hooks as $hook => $value) {
90
+ if (is_callable(array($instance, 'hook' . ucfirst($hook)))) {
91
+ //call the WP add_action function
92
+ add_action($value, array($instance, 'hook' . ucfirst($hook)), 5);
93
+ }
94
+ }
95
+ }
96
+
97
+ /**
98
+ * Calls the specified action in WP
99
+ *
100
+ * @param string $action
101
+ * @param array $callback Contains the class name or object and the callback function
102
+ *
103
+ * @return void
104
+ */
105
+ public function setAction($action, $obj, $callback)
106
+ {
107
+
108
+ /* calls the custom action function from WP */
109
+ add_action($action, array($obj, $callback), 10);
110
+ }
111
+
112
+ /**
113
+ * Calls the specified action in WP
114
+ *
115
+ * @param object $instance The parent class instance
116
+ *
117
+ * @return void
118
+ */
119
+ public function setBlockHooks($instance)
120
+ {
121
+ $param_arr = array();
122
+
123
+ /* for each admin action check if is defined in class and call it */
124
+ foreach ($this->block_hooks as $hook => $value)
125
+ if (is_callable(array($instance, 'hook' . ucfirst($hook)))) {
126
+ //call the WP add_action function
127
+ call_user_func_array(array($instance, 'hook' . ucfirst($hook)), $param_arr);
128
+ }
129
+ }
130
+
131
+ }
classes/ObjController.php CHANGED
@@ -1,164 +1,176 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- /**
5
- * The class creates object for plugin classes
6
- */
7
- class SQ_Classes_ObjController {
8
-
9
- /** @var array of instances */
10
- public static $instances;
11
-
12
- /**
13
- * @param $className $className
14
- * @param array $args
15
- * @return object|false
16
- */
17
- public static function getClass($className, $args = array()) {
18
-
19
- if ($class = self::getClassPath($className)) {
20
- if (!isset(self::$instances[$className])) {
21
- /* check if class is already defined */
22
- if (!class_exists($className) || $className == get_class()) {
23
- try {
24
- self::includeClass($class['dir'], $class['name']);
25
-
26
- //check if abstract
27
- $check = new ReflectionClass($className);
28
- $abstract = $check->isAbstract();
29
- if (!$abstract) {
30
- self::$instances[$className] = new $className();
31
- if (!empty($args)) {
32
- call_user_func_array(array(self::$instances[$className], '__construct'), $args);
33
- }
34
- return self::$instances[$className];
35
- } else {
36
- self::$instances[$className] = true;
37
- }
38
- } catch (Exception $e) {
39
- }
40
- }
41
- } else
42
- return self::$instances[$className];
43
- }
44
- return false;
45
- }
46
-
47
- /**
48
- * Get a new instance of the class
49
- * @param $className
50
- * @param array $args
51
- * @return bool|mixed
52
- */
53
- public static function getNewClass($className, $args = array()) {
54
- $instance = false;
55
- if ($class = self::getClassPath($className)) {
56
- /* check if class is already defined */
57
- try {
58
- if (!class_exists($className) || $className == get_class()) {
59
- self::includeClass($class['dir'], $class['name']);
60
- }
61
-
62
- //check if abstract
63
- $check = new ReflectionClass($className);
64
- $abstract = $check->isAbstract();
65
- if (!$abstract) {
66
- $instance = new $className();
67
-
68
- if (!empty($args)) {
69
- call_user_func_array(array($instance, '__construct'), $args);
70
- }
71
- return $instance;
72
- } else {
73
- $instance = true;
74
- }
75
- } catch (Exception $e) {
76
- SQ_Debug::dump($e->getMessage());
77
- }
78
-
79
- }
80
- return $instance;
81
- }
82
-
83
- /**
84
- * @param $classDir
85
- * @param $className
86
- * @throws Exception
87
- */
88
- private static function includeClass($classDir, $className) {
89
- $file = $classDir . $className . '.php';
90
- try {
91
- if (file_exists($file)) {
92
- include_once($file);
93
- }
94
- } catch (Exception $e) {
95
- throw new Exception('Controller Error: ' . $e->getMessage());
96
- }
97
- }
98
-
99
- /**
100
- * @param $className
101
- * @param array $args
102
- * @return stdClass
103
- */
104
- public static function getDomain($className, $args = array()) {
105
- try {
106
- if ($class = self::getClassPath($className)) {
107
- self::includeClass($class['dir'], $class['name']);
108
- return new $className($args);
109
- }
110
- } catch (Exception $e) {
111
- SQ_Debug::dump($e->getMessage());
112
- }
113
-
114
- return new stdClass();
115
- }
116
-
117
-
118
- /**
119
- * Check if the class is correctly set
120
- *
121
- * @param string $className
122
- * @return boolean
123
- */
124
- private static function checkClassPath($className) {
125
- $path = preg_split('/[_]+/', $className);
126
- if (is_array($path) && count($path) > 1) {
127
- if (in_array(_SQ_NAMESPACE_, $path)) {
128
- return true;
129
- }
130
- }
131
-
132
- return false;
133
- }
134
-
135
- /**
136
- * Get the path of the class and name of the class
137
- *
138
- * @param string $className
139
- * @return array | boolean
140
- * array(
141
- * dir - absolute path of the class
142
- * name - the name of the file
143
- * }
144
- */
145
- public static function getClassPath($className) {
146
- $dir = '';
147
-
148
-
149
- if (self::checkClassPath($className)) {
150
- $path = preg_split('/[_]+/', $className);
151
- for ($i = 1; $i < sizeof($path) - 1; $i++)
152
- $dir .= strtolower($path[$i]) . '/';
153
-
154
- $class = array('dir' => _SQ_ROOT_DIR_ . $dir,
155
- 'name' => $path[sizeof($path) - 1]);
156
-
157
- if (file_exists($class['dir'] . $class['name'] . '.php')) {
158
- return $class;
159
- }
160
- }
161
- return false;
162
- }
163
-
164
- }
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ /**
5
+ * The class creates object for plugin classes
6
+ */
7
+ class SQ_Classes_ObjController
8
+ {
9
+
10
+ /**
11
+ *
12
+ *
13
+ * @var array of instances
14
+ */
15
+ public static $instances;
16
+
17
+ /**
18
+ * @param $className $className
19
+ * @param array $args
20
+ * @return object|false
21
+ */
22
+ public static function getClass($className, $args = array())
23
+ {
24
+
25
+ if ($class = self::getClassPath($className)) {
26
+ if (!isset(self::$instances[$className])) {
27
+ /* check if class is already defined */
28
+ if (!class_exists($className) || $className == get_class()) {
29
+ try {
30
+ self::includeClass($class['dir'], $class['name']);
31
+
32
+ //check if abstract
33
+ $check = new ReflectionClass($className);
34
+ $abstract = $check->isAbstract();
35
+ if (!$abstract) {
36
+ self::$instances[$className] = new $className();
37
+ if (!empty($args)) {
38
+ call_user_func_array(array(self::$instances[$className], '__construct'), $args);
39
+ }
40
+ return self::$instances[$className];
41
+ } else {
42
+ self::$instances[$className] = true;
43
+ }
44
+ } catch (Exception $e) {
45
+ }
46
+ }
47
+ } else
48
+ return self::$instances[$className];
49
+ }
50
+ return false;
51
+ }
52
+
53
+ /**
54
+ * Get a new instance of the class
55
+ *
56
+ * @param $className
57
+ * @param array $args
58
+ * @return bool|mixed
59
+ */
60
+ public static function getNewClass($className, $args = array())
61
+ {
62
+ $instance = false;
63
+ if ($class = self::getClassPath($className)) {
64
+ /* check if class is already defined */
65
+ try {
66
+ if (!class_exists($className) || $className == get_class()) {
67
+ self::includeClass($class['dir'], $class['name']);
68
+ }
69
+
70
+ //check if abstract
71
+ $check = new ReflectionClass($className);
72
+ $abstract = $check->isAbstract();
73
+ if (!$abstract) {
74
+ $instance = new $className();
75
+
76
+ if (!empty($args)) {
77
+ call_user_func_array(array($instance, '__construct'), $args);
78
+ }
79
+ return $instance;
80
+ } else {
81
+ $instance = true;
82
+ }
83
+ } catch (Exception $e) {
84
+
85
+ }
86
+
87
+ }
88
+ return $instance;
89
+ }
90
+
91
+ /**
92
+ * @param $classDir
93
+ * @param $className
94
+ * @throws Exception
95
+ */
96
+ private static function includeClass($classDir, $className)
97
+ {
98
+ $file = $classDir . $className . '.php';
99
+ try {
100
+ if (file_exists($file)) {
101
+ include_once $file;
102
+ }
103
+ } catch (Exception $e) {
104
+ throw new Exception('Controller Error: ' . $e->getMessage());
105
+ }
106
+ }
107
+
108
+ /**
109
+ * @param $className
110
+ * @param array $args
111
+ * @return stdClass
112
+ */
113
+ public static function getDomain($className, $args = array())
114
+ {
115
+ try {
116
+ if ($class = self::getClassPath($className)) {
117
+ self::includeClass($class['dir'], $class['name']);
118
+ return new $className($args);
119
+ }
120
+ } catch (Exception $e) {
121
+
122
+ }
123
+
124
+ return new stdClass();
125
+ }
126
+
127
+
128
+ /**
129
+ * Check if the class is correctly set
130
+ *
131
+ * @param string $className
132
+ * @return boolean
133
+ */
134
+ private static function checkClassPath($className)
135
+ {
136
+ $path = preg_split('/[_]+/', $className);
137
+ if (is_array($path) && count($path) > 1) {
138
+ if (in_array(_SQ_NAMESPACE_, $path)) {
139
+ return true;
140
+ }
141
+ }
142
+
143
+ return false;
144
+ }
145
+
146
+ /**
147
+ * Get the path of the class and name of the class
148
+ *
149
+ * @param string $className
150
+ * @return array | boolean
151
+ * array(
152
+ * dir - absolute path of the class
153
+ * name - the name of the file
154
+ * }
155
+ */
156
+ public static function getClassPath($className)
157
+ {
158
+ $dir = '';
159
+
160
+
161
+ if (self::checkClassPath($className)) {
162
+ $path = preg_split('/[_]+/', $className);
163
+ for ($i = 1; $i < sizeof($path) - 1; $i++)
164
+ $dir .= strtolower($path[$i]) . '/';
165
+
166
+ $class = array('dir' => _SQ_ROOT_DIR_ . $dir,
167
+ 'name' => $path[sizeof($path) - 1]);
168
+
169
+ if (file_exists($class['dir'] . $class['name'] . '.php')) {
170
+ return $class;
171
+ }
172
+ }
173
+ return false;
174
+ }
175
+
176
+ }
classes/RemoteController.php CHANGED
@@ -1,1455 +1,1572 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- class SQ_Classes_RemoteController {
5
-
6
- public static $cache = array();
7
- public static $apimethod = 'get';
8
-
9
- /**
10
- * Call the Squirrly Cloud Server
11
- * @param string $module
12
- * @param array $args
13
- * @param array $options
14
- * @return string
15
- */
16
- public static function apiCall($module, $args = array(), $options = array()) {
17
- $parameters = "";
18
-
19
- //Don't make API calls without the token unless it's login or register
20
- if (!SQ_Classes_Helpers_Tools::getOption('sq_api')) {
21
- if (!in_array($module, array('api/user/login', 'api/user/register'))) {
22
- return '';
23
- }
24
- }
25
-
26
- //predefined options
27
- $options = array_merge(
28
- array(
29
- 'method' => self::$apimethod,
30
- 'sslverify' => SQ_CHECK_SSL,
31
- 'timeout' => 20,
32
- 'headers' => array(
33
- 'USER-TOKEN' => SQ_Classes_Helpers_Tools::getOption('sq_api'),
34
- 'URL-TOKEN' => (SQ_Classes_Helpers_Tools::getOption('sq_cloud_connect') ? SQ_Classes_Helpers_Tools::getOption('sq_cloud_token') : false),
35
- 'USER-URL' => apply_filters('sq_homeurl', get_bloginfo('url')),
36
- 'LANG' => apply_filters('sq_language', get_bloginfo('language')),
37
- 'VERSQ' => (int)str_replace('.', '', SQ_VERSION)
38
- )
39
- ),
40
- $options);
41
-
42
- try {
43
- if (!empty($args)) {
44
- foreach ($args as $key => $value) {
45
- if ($value <> '') {
46
- $parameters .= ($parameters == "" ? "" : "&") . $key . "=" . urlencode($value);
47
- }
48
- }
49
- }
50
-
51
- //call it with http to prevent curl issues with ssls
52
- $url = self::cleanUrl(_SQ_APIV2_URL_ . $module . "?" . $parameters);
53
-
54
- if (!isset(self::$cache[md5($url)])) {
55
- if ($options['method'] == 'post') {
56
- $options['body'] = $args;
57
- }
58
-
59
- self::$cache[md5($url)] = self::sq_wpcall($url, $options);
60
- }
61
-
62
- return self::$cache[md5($url)];
63
-
64
-
65
- } catch (Exception $e) {
66
- return '';
67
- }
68
-
69
- }
70
-
71
- /**
72
- * Clear the url before the call
73
- * @param string $url
74
- * @return string
75
- */
76
- private static function cleanUrl($url) {
77
- return str_replace(array(' '), array('+'), $url);
78
- }
79
-
80
- public static function generatePassword($length = 12) {
81
- $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
82
-
83
- $password = '';
84
- for ($i = 0; $i < $length; $i++) {
85
- $password .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
86
- }
87
-
88
- return $password;
89
- }
90
-
91
- /**
92
- * Get My Squirrly Link
93
- *
94
- * @param $path
95
- * @return string
96
- */
97
- public static function getMySquirrlyLink($path) {
98
- return apply_filters('sq_cloudmenu', _SQ_DASH_URL_, $path);
99
- }
100
-
101
- /**
102
- * Get API Link
103
- *
104
- * @param string $path
105
- * @param integer $version
106
- * @return string
107
- */
108
- public static function getApiLink($path) {
109
- return _SQ_APIV2_URL_ . $path . '?token=' . SQ_Classes_Helpers_Tools::getOption('sq_api') . '&url_token='.(SQ_Classes_Helpers_Tools::getOption('sq_cloud_connect') ? SQ_Classes_Helpers_Tools::getOption('sq_cloud_token') : false).'&url=' . apply_filters('sq_homeurl', get_bloginfo('url'));
110
- }
111
-
112
- /**
113
- * Use the WP remote call
114
- *
115
- * @param $url
116
- * @param $options
117
- * @return array|bool|string|WP_Error
118
- */
119
- public static function sq_wpcall($url, $options) {
120
- $method = $options['method'];
121
- //not accepted as option
122
- unset($options['method']);
123
-
124
- switch ($method) {
125
- case 'get':
126
- $response = wp_remote_get($url, $options);
127
- break;
128
- case 'post':
129
- $response = wp_remote_post($url, $options);
130
- break;
131
- default:
132
- $response = wp_remote_request($url, $options);
133
- break;
134
- }
135
-
136
- if (is_wp_error($response)) {
137
- SQ_Classes_Error::setError($response->get_error_message(), 'sq_error');
138
- return false;
139
- }
140
-
141
- $response = self::cleanResponce(wp_remote_retrieve_body($response)); //clear and get the body
142
-
143
- SQ_Debug::dump('wp_remote_get', $method, $url, $options, $response); //output debug
144
- return $response;
145
- }
146
-
147
- /**
148
- * Get the Json from responce if any
149
- * @param string $response
150
- * @return string
151
- */
152
- private static function cleanResponce($response) {
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
- }
170
- if ($json->error == 'disconnected') {
171
- SQ_Classes_Helpers_Tools::saveOptions('sq_api', false);
172
- }
173
- if ($json->error == 'banned') {
174
- SQ_Classes_Helpers_Tools::saveOptions('sq_api', false);
175
- }
176
- return (new WP_Error('api_error', $json->error));
177
- }
178
-
179
- //Refresh the checkin on login
180
- delete_transient('sq_checkin');
181
-
182
- return $json;
183
- }
184
-
185
- /**
186
- * Login user to API
187
- *
188
- * @param array $args
189
- * @return bool|WP_Error
190
- */
191
- public static function login($args = array()) {
192
- self::$apimethod = 'post'; //call method
193
-
194
- $json = json_decode(self::apiCall('api/user/login', $args));
195
-
196
- if (isset($json->error) && $json->error <> '') {
197
- return (new WP_Error('api_error', $json->error));
198
- } elseif (!isset($json->data)) {
199
- return (new WP_Error('api_error', 'no_data'));
200
- }
201
-
202
- //Refresh the checkin on login
203
- delete_transient('sq_checkin');
204
-
205
- if (!empty($json->data)) {
206
- return $json->data;
207
- }
208
-
209
- return false;
210
- }
211
-
212
- /**
213
- * Register user to API
214
- *
215
- * @param array $args
216
- * @return bool|WP_Error
217
- */
218
- public static function register($args = array()) {
219
- self::$apimethod = 'post'; //call method
220
-
221
- $json = json_decode(self::apiCall('api/user/register', $args));
222
-
223
- if (isset($json->error) && $json->error <> '') {
224
- return (new WP_Error('api_error', $json->error));
225
- } elseif (!isset($json->data)) {
226
- return (new WP_Error('api_error', 'no_data'));
227
- }
228
-
229
- //Refresh the checkin on login
230
- delete_transient('sq_checkin');
231
-
232
- if (!empty($json->data)) {
233
- return $json->data;
234
- }
235
-
236
- return false;
237
- }
238
-
239
- public static function getCloudToken($args = array()) {
240
- self::$apimethod = 'get'; //call method
241
-
242
- $json = json_decode(self::apiCall('api/user/token', $args));
243
-
244
- if (isset($json->error) && $json->error <> '') {
245
- return (new WP_Error('api_error', $json->error));
246
- } elseif (!isset($json->data)) {
247
- return (new WP_Error('api_error', 'no_data'));
248
- }
249
-
250
- if (!empty($json->data)) {
251
- return $json->data;
252
- }
253
-
254
- return false;
255
- }
256
-
257
- /**
258
- * User Checkin
259
- *
260
- * @param array $args
261
- * @return bool|WP_Error
262
- */
263
- public static function checkin($args = array()) {
264
- self::$apimethod = 'get'; //call method
265
-
266
- if (get_transient('sq_checkin')) {
267
- return get_transient('sq_checkin');
268
- }
269
-
270
- $json = json_decode(self::apiCall('api/user/checkin', $args));
271
-
272
- if (isset($json->error) && $json->error <> '') {
273
-
274
- //prevent throttling on API
275
- if ($json->error == 'too_many_requests') {
276
- SQ_Classes_Error::setError(esc_html__("Too many API attempts, please slow down the request.", _SQ_PLUGIN_NAME_));
277
- SQ_Classes_Error::hookNotices();
278
- return (new WP_Error('api_error', $json->error));
279
- } elseif ($json->error == 'maintenance') {
280
- SQ_Classes_Error::setError(esc_html__("Squirrly Cloud is down for a bit of maintenance right now. But we'll be back in a minute.", _SQ_PLUGIN_NAME_));
281
- SQ_Classes_Error::hookNotices();
282
- return (new WP_Error('maintenance', $json->error));
283
- }
284
-
285
- self::connect(); //connect the website
286
- return (new WP_Error('api_error', $json->error));
287
-
288
- } elseif (!isset($json->data)) {
289
- return (new WP_Error('api_error', 'no_data'));
290
- }
291
-
292
- if (isset($json->data->offer) && $json->data->offer <> '') {
293
- SQ_Classes_Helpers_Tools::saveOptions('sq_offer', $json->data->offer);
294
- } else {
295
- SQ_Classes_Helpers_Tools::saveOptions('sq_offer', false);
296
- }
297
-
298
- //Save the connections into database
299
- if (isset($json->data->connection_gsc) && isset($json->data->connection_ga)) {
300
- $connect = SQ_Classes_Helpers_Tools::getOption('connect');
301
- $connect['google_analytics'] = $json->data->connection_ga;
302
- $connect['google_search_console'] = $json->data->connection_gsc;
303
- SQ_Classes_Helpers_Tools::saveOptions('connect', $connect);
304
- }
305
-
306
- if(isset($json->data->subscription_devkit)){
307
- SQ_Classes_Helpers_Tools::saveOptions('sq_auto_devkit', (int)$json->data->subscription_devkit);
308
- }
309
-
310
- set_transient('sq_checkin', $json->data, 60);
311
- return $json->data;
312
- }
313
-
314
- /******************************** NOTIFICATIONS *********************/
315
- /**
316
- * Get the Notifications from API for the current blog
317
- * @return array|WP_Error
318
- */
319
- public static function getNotifications() {
320
- self::$apimethod = 'get'; //call method
321
-
322
- $notifications = array();
323
- if ($json = json_decode(self::apiCall('api/audits/notifications', array()))) {
324
-
325
- if (isset($json->error) && $json->error <> '') {
326
- return (new WP_Error('api_error', $json->error));
327
- } elseif (!isset($json->data)) {
328
- return (new WP_Error('api_error', 'no_data'));
329
- }
330
-
331
- $notifications = $json->data;
332
-
333
- }
334
-
335
- return $notifications;
336
- }
337
-
338
- /**
339
- * Get the API stats for this blog
340
- *
341
- * @return array|WP_Error|false
342
- */
343
- public static function getStats() {
344
- self::$apimethod = 'get'; //call method
345
-
346
- if (get_transient('sq_stats')) {
347
- return get_transient('sq_stats');
348
- }
349
-
350
- $args = array();
351
- $json = json_decode(self::apiCall('api/user/stats', $args));
352
-
353
- if (isset($json->error) && $json->error <> '') {
354
- return (new WP_Error('api_error', $json->error));
355
- } elseif (!isset($json->data)) {
356
- return (new WP_Error('api_error', 'no_data'));
357
- }
358
-
359
- if (!empty($json->data)) {
360
- set_transient('sq_stats', $json->data, 60);
361
- return $json->data;
362
- }
363
-
364
- return false;
365
-
366
- }
367
-
368
- /**
369
- * Get audits from API
370
- *
371
- * @param array $args
372
- * @return bool|WP_Error
373
- */
374
- public static function getBlogAudits($args = array()) {
375
- self::$apimethod = 'get'; //call method
376
-
377
- $json = json_decode(self::apiCall('api/audits/get-audits', $args));
378
-
379
- if (isset($json->error) && $json->error <> '') {
380
- return (new WP_Error('api_error', $json->error));
381
- } elseif (!isset($json->data)) {
382
- return (new WP_Error('api_error', 'no_data'));
383
- }
384
-
385
- if (!isset($json->data->audits)) {
386
- return (new WP_Error('api_error', 'no_data'));
387
- }
388
-
389
- return $json->data->audits;
390
- }
391
-
392
- public static function saveFeedback($args = array()) {
393
- self::$apimethod = 'post'; //call method
394
-
395
- $json = json_decode(self::apiCall('api/user/feedback', $args));
396
-
397
- if (isset($json->error) && $json->error <> '') {
398
- return (new WP_Error('api_error', $json->error));
399
- } elseif (!isset($json->data)) {
400
- return (new WP_Error('api_error', 'no_data'));
401
- }
402
-
403
- if (!empty($json->data)) {
404
- return $json->data;
405
- }
406
-
407
- return false;
408
- }
409
-
410
-
411
- /******************************** BRIEFCASE *********************/
412
- public static function getBriefcaseStats($args = array()) {
413
- self::$apimethod = 'get'; //call method
414
-
415
- if (get_transient('sq_briefcase_stats')) {
416
- return get_transient('sq_briefcase_stats');
417
- }
418
-
419
- $json = json_decode(self::apiCall('api/briefcase/stats', $args));
420
-
421
- if (isset($json->error) && $json->error <> '') {
422
- return (new WP_Error('api_error', $json->error));
423
- } elseif (!isset($json->data)) {
424
- return (new WP_Error('api_error', 'no_data'));
425
- }
426
-
427
- if (!empty($json->data)) {
428
- set_transient('sq_briefcase_stats', $json->data, 60);
429
- return $json->data;
430
- }
431
-
432
- return false;
433
- }
434
-
435
- public static function getBriefcase($args = array()) {
436
- self::$apimethod = 'get'; //call method
437
-
438
- $json = json_decode(self::apiCall('api/briefcase/get', $args, ['timeout' => 60]));
439
-
440
- if (isset($json->error) && $json->error <> '') {
441
- return (new WP_Error('api_error', $json->error));
442
- } elseif (!isset($json->data)) {
443
- return (new WP_Error('api_error', 'no_data'));
444
- }
445
-
446
- if (!empty($json->data)) {
447
- return $json->data;
448
- }
449
-
450
- return false;
451
- }
452
-
453
- public static function importBriefcaseKeywords($args = array()) {
454
- self::$apimethod = 'post'; //call method
455
-
456
- //clear the briefcase stats
457
- delete_transient('sq_briefcase_stats');
458
-
459
- $json = json_decode(self::apiCall('api/briefcase/import', $args));
460
-
461
- if (isset($json->error) && $json->error <> '') {
462
- return (new WP_Error('api_error', $json->error));
463
- } elseif (!isset($json->data)) {
464
- return (new WP_Error('api_error', 'no_data'));
465
- }
466
-
467
- if (!empty($json->data)) {
468
- return $json->data;
469
- }
470
-
471
- return false;
472
- }
473
-
474
- public static function addBriefcaseKeyword($args = array()) {
475
- self::$apimethod = 'post'; //call method
476
-
477
- //clear the briefcase stats
478
- delete_transient('sq_briefcase_stats');
479
-
480
- $json = json_decode(self::apiCall('api/briefcase/add', $args));
481
-
482
- if (isset($json->error) && $json->error <> '') {
483
- return (new WP_Error('api_error', $json->error));
484
- } elseif (!isset($json->data)) {
485
- return (new WP_Error('api_error', 'no_data'));
486
- }
487
-
488
- if (!empty($json->data)) {
489
- return $json->data;
490
- }
491
-
492
- return false;
493
- }
494
-
495
- public static function removeBriefcaseKeyword($args = array()) {
496
- self::$apimethod = 'post'; //call method
497
-
498
- if ($json = json_decode(self::apiCall('api/briefcase/hide', $args))) {
499
- return $json;
500
- }
501
-
502
- return false;
503
- }
504
-
505
- public static function saveBriefcaseKeywordLabel($args = array()) {
506
- self::$apimethod = 'post'; //call method
507
-
508
- //clear the briefcase stats
509
- delete_transient('sq_briefcase_stats');
510
-
511
- $json = json_decode(self::apiCall('api/briefcase/label/keyword', $args));
512
-
513
- if (isset($json->error) && $json->error <> '') {
514
- return (new WP_Error('api_error', $json->error));
515
- } elseif (!isset($json->data)) {
516
- return (new WP_Error('api_error', 'no_data'));
517
- }
518
-
519
- if (!empty($json->data)) {
520
- return $json->data;
521
- }
522
-
523
- return false;
524
- }
525
-
526
- public static function addBriefcaseLabel($args = array()) {
527
- self::$apimethod = 'post'; //call method
528
-
529
- //clear the briefcase stats
530
- delete_transient('sq_briefcase_stats');
531
-
532
- $json = json_decode(self::apiCall('api/briefcase/label/add', $args));
533
-
534
- if (isset($json->error) && $json->error <> '') {
535
- return (new WP_Error('api_error', $json->error));
536
- } elseif (!isset($json->data)) {
537
- return (new WP_Error('api_error', 'no_data'));
538
- }
539
-
540
- if (!empty($json->data)) {
541
- return $json->data;
542
- }
543
-
544
- return false;
545
- }
546
-
547
- public static function saveBriefcaseLabel($args = array()) {
548
- self::$apimethod = 'post'; //call method
549
-
550
- //clear the briefcase stats
551
- delete_transient('sq_briefcase_stats');
552
-
553
- $json = json_decode(self::apiCall('api/briefcase/label/save', $args));
554
-
555
- if (isset($json->error) && $json->error <> '') {
556
- return (new WP_Error('api_error', $json->error));
557
- } elseif (!isset($json->data)) {
558
- return (new WP_Error('api_error', 'no_data'));
559
- }
560
-
561
- if (!empty($json->data)) {
562
- return $json->data;
563
- }
564
-
565
- return false;
566
- }
567
-
568
- public static function removeBriefcaseLabel($args = array()) {
569
- self::$apimethod = 'post'; //call method
570
-
571
- $json = json_decode(self::apiCall('api/briefcase/label/delete', $args));
572
-
573
- if (isset($json->error) && $json->error <> '') {
574
- return (new WP_Error('api_error', $json->error));
575
- } elseif (!isset($json->data)) {
576
- return (new WP_Error('api_error', 'no_data'));
577
- }
578
-
579
- if (!empty($json->data)) {
580
- return $json->data;
581
- }
582
-
583
- return false;
584
- }
585
-
586
- public static function saveBriefcaseMainKeyword($args = array()) {
587
- self::$apimethod = 'post'; //call method
588
-
589
- $json = json_decode(self::apiCall('api/briefcase/main', $args));
590
-
591
- if (isset($json->error) && $json->error <> '') {
592
- return (new WP_Error('api_error', $json->error));
593
- } elseif (!isset($json->data)) {
594
- return (new WP_Error('api_error', 'no_data'));
595
- }
596
-
597
- if (!empty($json->data)) {
598
- return $json->data;
599
- }
600
-
601
- return false;
602
- }
603
-
604
-
605
- /******************************** KEYWORD RESEARCH ****************/
606
-
607
- /**
608
- * Get KR Countries
609
- * @param array $args
610
- * @return bool|WP_Error
611
- */
612
- public static function getKrCountries($args = array()) {
613
- self::$apimethod = 'get'; //call method
614
-
615
- $json = json_decode(self::apiCall('api/kr/countries', $args));
616
-
617
- if (isset($json->error) && $json->error <> '') {
618
- return (new WP_Error('api_error', $json->error));
619
- } elseif (!isset($json->data)) {
620
- return (new WP_Error('api_error', 'no_data'));
621
- }
622
-
623
- if (!empty($json->data)) {
624
- return $json->data;
625
- }
626
-
627
- return false;
628
- }
629
-
630
- public static function getKROthers($args = array()) {
631
- self::$apimethod = 'get'; //call method
632
-
633
- $json = json_decode(self::apiCall('api/kr/other', $args));
634
-
635
- if (isset($json->error) && $json->error <> '') {
636
- return (new WP_Error('api_error', $json->error));
637
- } elseif (!isset($json->data)) {
638
- return (new WP_Error('api_error', 'no_data'));
639
- }
640
-
641
- if (!empty($json->data)) {
642
- return $json->data;
643
- }
644
-
645
- return false;
646
- }
647
-
648
- /**
649
- * Set Keyword Research
650
- *
651
- * @param array $args
652
- * @return array|bool|mixed|object|WP_Error
653
- */
654
- public static function setKRSuggestion($args = array()) {
655
- self::$apimethod = 'post'; //call method
656
-
657
- //clear the briefcase stats
658
- delete_transient('sq_stats');
659
- delete_transient('sq_briefcase_stats');
660
-
661
- $json = json_decode(self::apiCall('api/kr/suggestion', $args));
662
-
663
- if (isset($json->error) && $json->error <> '') {
664
- return (new WP_Error('api_error', $json->error));
665
- } elseif (!isset($json->data)) {
666
- return (new WP_Error('api_error', 'no_data'));
667
- }
668
-
669
- if (!empty($json->data)) {
670
- return $json->data;
671
- }
672
-
673
- return false;
674
- }
675
-
676
- public static function getKRSuggestion($args = array()) {
677
- self::$apimethod = 'get'; //call method
678
-
679
- $json = json_decode(self::apiCall('api/kr/suggestion', $args));
680
-
681
- if (isset($json->error) && $json->error <> '') {
682
- return (new WP_Error('api_error', $json->error));
683
- } elseif (!isset($json->data)) {
684
- return (new WP_Error('api_error', 'no_data'));
685
- }
686
-
687
- if (!empty($json->data)) {
688
- return $json->data;
689
- }
690
-
691
- return false;
692
- }
693
-
694
- /******************************** KEYWORD HISTORY & FOUND ****************/
695
-
696
- /**
697
- * Get Keyword Research History
698
- * @param array $args
699
- * @return array|bool|mixed|object|WP_Error
700
- */
701
- public static function getKRHistory($args = array()) {
702
- self::$apimethod = 'get'; //call method
703
-
704
- $json = json_decode(self::apiCall('api/kr/history', $args));
705
-
706
- if (isset($json->error) && $json->error <> '') {
707
- return (new WP_Error('api_error', $json->error));
708
- } elseif (!isset($json->data)) {
709
- return (new WP_Error('api_error', 'no_data'));
710
- }
711
-
712
- if (!empty($json->data)) {
713
- return $json->data;
714
- }
715
-
716
- return false;
717
- }
718
-
719
- /**
720
- * Get the Kr Found by API
721
- * @param array $args
722
- * @return bool|WP_Error
723
- */
724
- public static function getKrFound($args = array()) {
725
- self::$apimethod = 'get'; //call method
726
-
727
- $json = json_decode(self::apiCall('api/kr/found', $args));
728
-
729
- if (isset($json->error) && $json->error <> '') {
730
- return (new WP_Error('api_error', $json->error));
731
- } elseif (!isset($json->data)) {
732
- return (new WP_Error('api_error', 'no_data'));
733
- }
734
-
735
- if (!empty($json->data)) {
736
- return $json->data;
737
- }
738
-
739
- return false;
740
- }
741
-
742
- /** Remove Keyword from Suggestions
743
- * @param array $args
744
- * @return bool|WP_Error
745
- */
746
- public static function removeKrFound($args = array()) {
747
- self::$apimethod = 'post'; //call method
748
-
749
- $json = json_decode(self::apiCall('api/kr/found/delete', $args));
750
-
751
- if (isset($json->error) && $json->error <> '') {
752
- return (new WP_Error('api_error', $json->error));
753
- } elseif (!isset($json->data)) {
754
- return (new WP_Error('api_error', 'no_data'));
755
- }
756
-
757
- if (!empty($json->data)) {
758
- return $json->data;
759
- }
760
-
761
- return false;
762
- }
763
- /******************** WP Posts ***************************/
764
- /**
765
- * Save the post status on API
766
- *
767
- * @param array $args
768
- * @return bool|WP_Error
769
- */
770
- public static function savePost($args = array()) {
771
- self::$apimethod = 'post'; //call method
772
-
773
- //clear the briefcase stats
774
- delete_transient('sq_stats');
775
-
776
- $json = json_decode(self::apiCall('api/posts/update', $args, ['timeout' => 5]));
777
-
778
- if (isset($json->error) && $json->error <> '') {
779
- return (new WP_Error('api_error', $json->error));
780
- } elseif (!isset($json->data)) {
781
- return (new WP_Error('api_error', 'no_data'));
782
- }
783
-
784
- if (!empty($json->data)) {
785
- return $json->data;
786
- }
787
-
788
- return false;
789
-
790
- }
791
-
792
- /**
793
- * Get the post optimization
794
- *
795
- * @param array $args
796
- * @return array|mixed|object
797
- */
798
- public static function getPostOptimization($args = array()) {
799
- self::$apimethod = 'get'; //call method
800
-
801
- $json = json_decode(self::apiCall('api/posts/optimizations', $args));
802
-
803
- if (isset($json->error) && $json->error <> '') {
804
- return (new WP_Error('api_error', $json->error));
805
- } elseif (!isset($json->data)) {
806
- return (new WP_Error('api_error', 'no_data'));
807
- }
808
-
809
- if (!empty($json->data)) {
810
- return $json->data;
811
- }
812
-
813
- return false;
814
-
815
- }
816
-
817
- /******************** RANKINGS ***************************/
818
-
819
- /**
820
- * Add a keyword in Rank Checker
821
- * @param array $args
822
- * @return bool|WP_Error
823
- */
824
- public static function addSerpKeyword($args = array()) {
825
- self::$apimethod = 'post'; //call method
826
-
827
- $json = json_decode(self::apiCall('api/briefcase/serp', $args));
828
-
829
- if (isset($json->error) && $json->error <> '') {
830
- return (new WP_Error('api_error', $json->error));
831
- } elseif (!isset($json->data)) {
832
- return (new WP_Error('api_error', 'no_data'));
833
- }
834
-
835
- if (!empty($json->data)) {
836
- return $json->data;
837
- }
838
-
839
- return false;
840
- }
841
-
842
- /**
843
- * Delete a keyword from Rank Checker
844
- * @param array $args
845
- * @return bool|WP_Error
846
- */
847
- public static function deleteSerpKeyword($args = array()) {
848
- self::$apimethod = 'post'; //call method
849
-
850
- $json = json_decode(self::apiCall('api/briefcase/serp-delete', $args));
851
-
852
- if (isset($json->error) && $json->error <> '') {
853
- return (new WP_Error('api_error', $json->error));
854
- } elseif (!isset($json->data)) {
855
- return (new WP_Error('api_error', 'no_data'));
856
- }
857
-
858
- if (!empty($json->data)) {
859
- return $json->data;
860
- }
861
-
862
- return false;
863
- }
864
-
865
- /**
866
- * Get the Ranks for this blog
867
- * @param array $args
868
- * @return bool|WP_Error
869
- */
870
- public static function getRanksStats($args = array()) {
871
- self::$apimethod = 'get'; //call method
872
-
873
- $json = json_decode(self::apiCall('api/serp/stats', $args));
874
-
875
- if (isset($json->error) && $json->error <> '') {
876
- return (new WP_Error('api_error', $json->error));
877
- } elseif (!isset($json->data)) {
878
- return (new WP_Error('api_error', 'no_data'));
879
- }
880
-
881
- if (!empty($json->data)) {
882
- return $json->data;
883
- }
884
-
885
- return false;
886
- }
887
-
888
- /**
889
- * Get the Ranks for this blog
890
- * @param array $args
891
- * @return bool|WP_Error
892
- */
893
- public static function getRanks($args = array()) {
894
- self::$apimethod = 'get'; //call method
895
-
896
- $json = json_decode(self::apiCall('api/serp/get-ranks', $args));
897
-
898
- if (isset($json->error) && $json->error <> '') {
899
- return (new WP_Error('api_error', $json->error));
900
- } elseif (!isset($json->data)) {
901
- return (new WP_Error('api_error', 'no_data'));
902
- }
903
-
904
- if (!empty($json->data)) {
905
- return $json->data;
906
- }
907
-
908
- return false;
909
- }
910
-
911
- /**
912
- * Refresh the rank for a page/post
913
- *
914
- * @param array $args
915
- * @return bool|WP_Error
916
- */
917
- public static function checkPostRank($args = array()) {
918
- self::$apimethod = 'get'; //call method
919
-
920
- $json = json_decode(self::apiCall('api/serp/refresh', $args));
921
-
922
- if (isset($json->error) && $json->error <> '') {
923
- return (new WP_Error('api_error', $json->error));
924
- } elseif (!isset($json->data)) {
925
- return (new WP_Error('api_error', 'no_data'));
926
- }
927
-
928
- if (!empty($json->data)) {
929
- return $json->data;
930
- }
931
-
932
- return false;
933
- }
934
-
935
- /******************** FOCUS PAGES ***********************/
936
-
937
- /**
938
- * Get all focus pages and add them in the SQ_Models_Domain_FocusPage object
939
- * Add the audit data for each focus page
940
- * @param array $args
941
- * @return SQ_Models_Domain_FocusPage|WP_Error|false
942
- */
943
- public static function getFocusPages($args = array()) {
944
- self::$apimethod = 'get'; //call method
945
-
946
- $json = json_decode(self::apiCall('api/posts/focus', $args));
947
-
948
- if (isset($json->error) && $json->error <> '') {
949
- return (new WP_Error('api_error', $json->error));
950
- } elseif (!isset($json->data)) {
951
- return (new WP_Error('api_error', 'no_data'));
952
- }
953
-
954
- if (!empty($json->data)) {
955
- return $json->data;
956
- }
957
-
958
- return false;
959
- }
960
-
961
- /**
962
- * Get the focus page audit
963
- *
964
- * @param array $args
965
- * @return bool|WP_Error
966
- */
967
- public static function getFocusAudits($args = array()) {
968
- self::$apimethod = 'get'; //call method
969
-
970
- $json = json_decode(self::apiCall('api/audits/focus', $args));
971
-
972
- if (isset($json->error) && $json->error <> '') {
973
- return (new WP_Error('api_error', $json->error));
974
- } elseif (!isset($json->data)) {
975
- return (new WP_Error('api_error', 'no_data'));
976
- }
977
-
978
- if (!empty($json->data)) {
979
- return $json->data;
980
- }
981
-
982
- return false;
983
- }
984
-
985
- /**
986
- * Add Focus Page
987
- * @param array $args
988
- * @return bool|WP_Error
989
- */
990
- public static function addFocusPage($args = array()) {
991
- self::$apimethod = 'post'; //post call
992
-
993
- $json = json_decode(self::apiCall('api/posts/set-focus', $args));
994
-
995
- if (isset($json->error) && $json->error <> '') {
996
- return (new WP_Error('api_error', $json->error));
997
- } elseif (!isset($json->data)) {
998
- return (new WP_Error('api_error', 'no_data'));
999
- }
1000
-
1001
- if (!empty($json->data)) {
1002
- return $json->data;
1003
- }
1004
-
1005
- return false;
1006
- }
1007
-
1008
- public static function updateFocusPage($args = array()) {
1009
- self::$apimethod = 'post'; //post call
1010
-
1011
- $json = json_decode(self::apiCall('api/posts/update-focus', $args));
1012
-
1013
- if (isset($json->error) && $json->error <> '') {
1014
- return (new WP_Error('api_error', $json->error));
1015
- } elseif (!isset($json->data)) {
1016
- return (new WP_Error('api_error', 'no_data'));
1017
- }
1018
-
1019
- if (!empty($json->data)) {
1020
- return $json->data;
1021
- }
1022
-
1023
- return false;
1024
- }
1025
-
1026
- /**
1027
- * Delete the Focus Page
1028
- * @param array $args
1029
- * @return bool|WP_Error
1030
- */
1031
- public static function deleteFocusPage($args = array()) {
1032
- self::$apimethod = 'post'; //post call
1033
-
1034
- if (isset($args['user_post_id']) && $args['user_post_id'] > 0) {
1035
- $json = json_decode(self::apiCall('api/posts/remove-focus/' . $args['user_post_id']));
1036
-
1037
- if (isset($json->error) && $json->error <> '') {
1038
- return (new WP_Error('api_error', $json->error));
1039
- } elseif (!isset($json->data)) {
1040
- return (new WP_Error('api_error', 'no_data'));
1041
- }
1042
-
1043
- return $json->data;
1044
- }
1045
-
1046
- return false;
1047
- }
1048
-
1049
- /**
1050
- * Get all focus pages and add them in the SQ_Models_Domain_FocusPage object
1051
- * Add the audit data for each focus page
1052
- * @param array $args
1053
- * @return SQ_Models_Domain_FocusPage|WP_Error|false
1054
- */
1055
- public static function getInspectURL($args = array()) {
1056
- self::$apimethod = 'get'; //call method
1057
-
1058
- $json = json_decode(self::apiCall('api/posts/crawl', $args, ['timeout' => 60]));
1059
-
1060
- if (isset($json->error) && $json->error <> '') {
1061
- return (new WP_Error('api_error', $json->error));
1062
- } elseif (!isset($json->data)) {
1063
- return (new WP_Error('api_error', 'no_data'));
1064
- }
1065
-
1066
- if (!empty($json->data)) {
1067
- return $json->data;
1068
- }
1069
-
1070
- return false;
1071
- }
1072
- /**************************************** CONNECTIONS */
1073
- /**
1074
- * Disconnect Google Analytics account
1075
- *
1076
- * @return bool|WP_Error
1077
- */
1078
- public static function revokeGaConnection() {
1079
- self::$apimethod = 'get'; //post call
1080
-
1081
- $json = json_decode(self::apiCall('api/ga/revoke'));
1082
-
1083
- if (isset($json->error) && $json->error <> '') {
1084
- return (new WP_Error('api_error', $json->error));
1085
- } elseif (!isset($json->data)) {
1086
- return (new WP_Error('api_error', 'no_data'));
1087
- }
1088
-
1089
- //Refresh the checkin on login
1090
- delete_transient('sq_checkin');
1091
-
1092
- if (!empty($json->data)) {
1093
- return $json->data;
1094
- }
1095
-
1096
- return false;
1097
- }
1098
-
1099
- public static function getGAToken($args = array()) {
1100
- self::$apimethod = 'get'; //post call
1101
-
1102
- $json = json_decode(self::apiCall('api/ga/token', $args));
1103
-
1104
- if (isset($json->error) && $json->error <> '') {
1105
- return (new WP_Error('api_error', $json->error));
1106
- } elseif (!isset($json->data)) {
1107
- return (new WP_Error('api_error', 'no_data'));
1108
- }
1109
-
1110
- if (!empty($json->data)) {
1111
- return $json->data;
1112
- }
1113
-
1114
- return false;
1115
-
1116
- }
1117
-
1118
- public static function getGAProperties($args = array()) {
1119
- self::$apimethod = 'get'; //post call
1120
-
1121
- $json = json_decode(self::apiCall('api/ga/properties', $args));
1122
-
1123
- if (isset($json->error) && $json->error <> '') {
1124
- return (new WP_Error('api_error', $json->error));
1125
- } elseif (!isset($json->data)) {
1126
- return (new WP_Error('api_error', 'no_data'));
1127
- }
1128
-
1129
- if (!empty($json->data)) {
1130
- return $json->data;
1131
- }
1132
-
1133
- return false;
1134
-
1135
- }
1136
-
1137
- public static function saveGAProperties($args = array()) {
1138
- self::$apimethod = 'post'; //post call
1139
-
1140
- $json = json_decode(self::apiCall('api/ga/properties', $args));
1141
-
1142
- if (isset($json->error) && $json->error <> '') {
1143
- return (new WP_Error('api_error', $json->error));
1144
- } elseif (!isset($json->data)) {
1145
- return (new WP_Error('api_error', 'no_data'));
1146
- }
1147
-
1148
- if (!empty($json->data)) {
1149
- return $json->data;
1150
- }
1151
-
1152
- return false;
1153
-
1154
- }
1155
-
1156
- /**
1157
- * Disconnect Google Search Console account
1158
- *
1159
- * @return bool|WP_Error
1160
- */
1161
- public static function revokeGscConnection() {
1162
- self::$apimethod = 'get'; //post call
1163
-
1164
- $json = json_decode(self::apiCall('api/gsc/revoke'));
1165
-
1166
- if (isset($json->error) && $json->error <> '') {
1167
- return (new WP_Error('api_error', $json->error));
1168
- } elseif (!isset($json->data)) {
1169
- return (new WP_Error('api_error', 'no_data'));
1170
- }
1171
-
1172
- //Refresh the checkin on login
1173
- delete_transient('sq_checkin');
1174
-
1175
- if (!empty($json->data)) {
1176
- return $json->data;
1177
- }
1178
-
1179
- return false;
1180
-
1181
- }
1182
-
1183
- public static function syncGSC($args = array()) {
1184
- self::$apimethod = 'get'; //post call
1185
-
1186
- $json = json_decode(self::apiCall('api/gsc/sync/kr', $args));
1187
-
1188
- if (isset($json->error) && $json->error <> '') {
1189
- return (new WP_Error('api_error', $json->error));
1190
- } elseif (!isset($json->data)) {
1191
- return (new WP_Error('api_error', 'no_data'));
1192
- }
1193
-
1194
- if (!empty($json->data)) {
1195
- return $json->data;
1196
- }
1197
-
1198
- return false;
1199
-
1200
- }
1201
-
1202
- public static function getGSCToken($args = array()) {
1203
- self::$apimethod = 'get'; //post call
1204
-
1205
- $json = json_decode(self::apiCall('api/gsc/token', $args));
1206
-
1207
- if (isset($json->error) && $json->error <> '') {
1208
- return (new WP_Error('api_error', $json->error));
1209
- } elseif (!isset($json->data)) {
1210
- return (new WP_Error('api_error', 'no_data'));
1211
- }
1212
-
1213
- if (!empty($json->data)) {
1214
- return $json->data;
1215
- }
1216
-
1217
- return false;
1218
-
1219
- }
1220
-
1221
- /******************** AUDITS *****************************/
1222
-
1223
- public static function getAuditPages($args = array()) {
1224
- self::$apimethod = 'get'; //call method
1225
-
1226
- $json = json_decode(self::apiCall('api/posts/audits', $args));
1227
-
1228
- if (isset($json->error) && $json->error <> '') {
1229
- return (new WP_Error('api_error', $json->error));
1230
- } elseif (!isset($json->data)) {
1231
- return (new WP_Error('api_error', 'no_data'));
1232
- }
1233
-
1234
- if (!empty($json->data)) {
1235
- return $json->data;
1236
- }
1237
-
1238
- return false;
1239
-
1240
- }
1241
-
1242
- /**
1243
- * Get the audit page
1244
- *
1245
- * @param array $args
1246
- * @return bool|WP_Error
1247
- */
1248
- public static function getAudit($args = array()) {
1249
- self::$apimethod = 'get'; //call method
1250
-
1251
- $json = json_decode(self::apiCall('api/audits/audit', $args));
1252
-
1253
- if (isset($json->error) && $json->error <> '') {
1254
- return (new WP_Error('api_error', $json->error));
1255
- } elseif (!isset($json->data)) {
1256
- return (new WP_Error('api_error', 'no_data'));
1257
- }
1258
-
1259
- if (!empty($json->data)) {
1260
- return $json->data;
1261
- }
1262
-
1263
- return false;
1264
-
1265
- }
1266
-
1267
- /**
1268
- * Add Audit Page
1269
- * @param array $args
1270
- * @return bool|WP_Error
1271
- */
1272
- public static function addAuditPage($args = array()) {
1273
- self::$apimethod = 'post'; //post call
1274
-
1275
- $json = json_decode(self::apiCall('api/posts/set-audit', $args));
1276
-
1277
- if (isset($json->error) && $json->error <> '') {
1278
- return (new WP_Error('api_error', $json->error));
1279
- } elseif (!isset($json->data)) {
1280
- return (new WP_Error('api_error', 'no_data'));
1281
- }
1282
-
1283
- if (!empty($json->data)) {
1284
- return $json->data;
1285
- }
1286
-
1287
- return false;
1288
-
1289
- }
1290
-
1291
- public static function updateAudit($args = array()) {
1292
- self::$apimethod = 'post'; //post call
1293
-
1294
- $json = json_decode(self::apiCall('api/posts/update-audit', $args));
1295
-
1296
- if (isset($json->error) && $json->error <> '') {
1297
- return (new WP_Error('api_error', $json->error));
1298
- } elseif (!isset($json->data)) {
1299
- return (new WP_Error('api_error', 'no_data'));
1300
- }
1301
-
1302
- if (!empty($json->data)) {
1303
- return $json->data;
1304
- }
1305
-
1306
- return false;
1307
- }
1308
-
1309
- /**
1310
- * Delete the Audit Page
1311
- * @param array $args
1312
- * @return bool|WP_Error
1313
- */
1314
- public static function deleteAuditPage($args = array()) {
1315
- self::$apimethod = 'post'; //post call
1316
-
1317
- if (isset($args['user_post_id']) && $args['user_post_id'] > 0) {
1318
-
1319
- $json = json_decode(self::apiCall('api/posts/remove-audit/' . $args['user_post_id']));
1320
-
1321
- if (isset($json->error) && $json->error <> '') {
1322
- return (new WP_Error('api_error', $json->error));
1323
- } elseif (!isset($json->data)) {
1324
- return (new WP_Error('api_error', 'no_data'));
1325
- }
1326
-
1327
- if (!empty($json->data)) {
1328
- return $json->data;
1329
- }
1330
-
1331
- }
1332
- return false;
1333
- }
1334
-
1335
- /******************** OTHERS *****************************/
1336
- public static function saveSettings($args) {
1337
- self::$apimethod = 'post'; //call method
1338
-
1339
- self::apiCall('api/user/settings', array('settings' => wp_json_encode($args)));
1340
- }
1341
-
1342
- /**
1343
- * Get the Facebook APi Code
1344
- * @param $args
1345
- * @return bool|WP_Error
1346
- */
1347
- public static function getFacebookApi($args) {
1348
- self::$apimethod = 'get'; //call method
1349
-
1350
- $json = json_decode(self::apiCall('api/tools/facebook', $args));
1351
-
1352
- if (isset($json->error) && $json->error <> '') {
1353
- return (new WP_Error('api_error', $json->error));
1354
- } elseif (!isset($json->data)) {
1355
- return (new WP_Error('api_error', 'no_data'));
1356
- }
1357
-
1358
- if (!empty($json->data)) {
1359
- return $json->data;
1360
- }
1361
-
1362
- return false;
1363
-
1364
- }
1365
-
1366
- /**
1367
- * Load the JS for API
1368
- */
1369
- public static function loadJsVars() {
1370
- global $post;
1371
- $referer = '';
1372
-
1373
- $metas = json_decode(wp_json_encode(SQ_Classes_Helpers_Tools::getOption('sq_metas')));
1374
- $sq_postID = (isset($post->ID) ? $post->ID : 0);
1375
-
1376
- //Load Squirrly Live Assistant for Elementor builder
1377
- if (SQ_Classes_Helpers_Tools::isPluginInstalled('elementor/elementor.php')) {
1378
- if (SQ_Classes_Helpers_Tools::getOption('sq_sla_frontend')) {
1379
- $referer = get_post_meta($sq_postID, '_sq_sla', true);
1380
- }
1381
- }
1382
-
1383
- echo '<script>
1384
- var SQ_DEBUG = ' . (int)SQ_DEBUG . ';
1385
- (function($){
1386
- $.sq_config = {
1387
- sq_use: ' . (int)SQ_Classes_Helpers_Tools::getOption('sq_use') . ',
1388
- sq_version: "' . SQ_VERSION . '",
1389
- sq_sla_type: "' . SQ_Classes_Helpers_Tools::getOption('sq_sla_type') . '",
1390
- token: "' . SQ_Classes_Helpers_Tools::getOption('sq_api') . '",
1391
- url_token: "' . (SQ_Classes_Helpers_Tools::getOption('sq_cloud_connect') ? SQ_Classes_Helpers_Tools::getOption('sq_cloud_token') : false) . '",
1392
- sq_baseurl: "' . _SQ_STATIC_API_URL_ . '",
1393
- sq_uri: "' . SQ_URI . '",
1394
- sq_apiurl: "' . _SQ_APIV2_URL_ . '",
1395
- user_url: "' . apply_filters('sq_homeurl', get_bloginfo('url')) . '",
1396
- language: "' . apply_filters('sq_language', get_bloginfo('language')) . '",
1397
- referer: "' . $referer . '",
1398
- sq_keywordtag: ' . (int)SQ_Classes_Helpers_Tools::getOption('sq_keywordtag') . ',
1399
- sq_keyword_help: ' . (int)SQ_Classes_Helpers_Tools::getOption('sq_keyword_help') . ',
1400
- frontend_css: "' . _SQ_ASSETS_URL_ . 'css/frontend' . (SQ_DEBUG ? '' : '.min') . '.css",
1401
- postID: "' . $sq_postID . '",
1402
- prevNonce: "' . wp_create_nonce('post_preview_' . $sq_postID) . '",
1403
- __keyword: "' . esc_html__('Keyword:', _SQ_PLUGIN_NAME_) . '",
1404
- __date: "' . esc_html__('date', _SQ_PLUGIN_NAME_) . '",
1405
- __noconnection: "' . esc_html__("To load the Live Assistant and optimize this page, click to connect to Squirrly Cloud.", _SQ_PLUGIN_NAME_) . '",
1406
- __saved: "' . esc_html__('Saved!', _SQ_PLUGIN_NAME_) . '",
1407
- __readit: "' . esc_html__('Read it!', _SQ_PLUGIN_NAME_) . '",
1408
- __insertit: "' . esc_html__('Insert it!', _SQ_PLUGIN_NAME_) . '",
1409
- __reference: "' . esc_html__('Reference', _SQ_PLUGIN_NAME_) . '",
1410
- __insertasbox: "' . esc_html__('Insert as box', _SQ_PLUGIN_NAME_) . '",
1411
- __addlink: "' . esc_html__('Insert Link', _SQ_PLUGIN_NAME_) . '",
1412
- __notrelevant: "' . esc_html__('Not relevant?', _SQ_PLUGIN_NAME_) . '",
1413
- __insertparagraph: "' . esc_html__('Insert in your article', _SQ_PLUGIN_NAME_) . '",
1414
- __ajaxerror: "' . esc_html__(':( An error occurred while processing your request. Please try again', _SQ_PLUGIN_NAME_) . '",
1415
- __nofound: "' . esc_html__('No results found!', _SQ_PLUGIN_NAME_) . '",
1416
- __sq_photo_copyright: "' . esc_html__('[ ATTRIBUTE: Please check: %s to find out how to attribute this image ]', _SQ_PLUGIN_NAME_) . '",
1417
- __has_attributes: "' . esc_html__('Has creative commons attributes', _SQ_PLUGIN_NAME_) . '",
1418
- __no_attributes: "' . esc_html__('No known copyright restrictions', _SQ_PLUGIN_NAME_) . '",
1419
- __noopt: "' . esc_html__('You haven`t used Squirrly SEO to optimize your article. Do you want to optimize for a keyword before publishing?', _SQ_PLUGIN_NAME_) . '",
1420
- __subscription_expired: "' . esc_html__('Your Subscription has Expired', _SQ_PLUGIN_NAME_) . '",
1421
- __no_briefcase: "' . esc_html__('There are no keywords saved in briefcase yet', _SQ_PLUGIN_NAME_) . '",
1422
- __fulloptimized: "' . esc_html__('Congratulations! Your article is 100% optimized!', _SQ_PLUGIN_NAME_) . '",
1423
- __toomanytimes: "' . esc_html__('appears too many times. Try to remove %s of them', _SQ_PLUGIN_NAME_) . '",
1424
- __writemorewords: "' . esc_html__('write %s more words', _SQ_PLUGIN_NAME_) . '",
1425
- __keywordinintroduction: "' . esc_html__('Add the keyword in the %s of your article', _SQ_PLUGIN_NAME_) . '",
1426
- __clicktohighlight: "' . esc_html__('Click to keep the highlight on', _SQ_PLUGIN_NAME_) . '",
1427
- __introduction: "' . esc_html__('introduction', _SQ_PLUGIN_NAME_) . '",
1428
- __morewordsafter: "' . esc_html__('Write more words after the %s keyword', _SQ_PLUGIN_NAME_) . '",
1429
- __orusesynonyms: "' . esc_html__('or use synonyms', _SQ_PLUGIN_NAME_) . '",
1430
- __addmorewords: "' . esc_html__('add %s more word(s)', _SQ_PLUGIN_NAME_) . '",
1431
- __removewords: "' . esc_html__('or remove %s word(s)', _SQ_PLUGIN_NAME_) . '",
1432
- __addmorekeywords: "' . esc_html__('add the selected keyword %s more time(s) ', _SQ_PLUGIN_NAME_) . '",
1433
- __addminimumwords: "' . esc_html__('write %s more words to start calculating', _SQ_PLUGIN_NAME_) . '",
1434
- __add_to_briefcase: "' . esc_html__('Add to Briefcase', _SQ_PLUGIN_NAME_) . '",
1435
- __add_keyword_briefcase: "' . esc_html__('Add Keyword to Briefcase', _SQ_PLUGIN_NAME_) . '",
1436
- __usekeyword: "' . esc_html__('Select', _SQ_PLUGIN_NAME_) . '",
1437
- __new_post_title: "' . esc_html__('Auto Draft') . '",
1438
- __enter_keyword: "' . esc_html__('Enter keyword above and press ENTER', _SQ_PLUGIN_NAME_) . '",
1439
- __add_keyword: "' . esc_html__('Add Keywords from Briefcase', _SQ_PLUGIN_NAME_) . '",
1440
- __frontend_optimized: "' . esc_html__('Live Assistant was used to optimize this page with the Page Builder. Please go back and resume your optimization work there.', _SQ_PLUGIN_NAME_) . '",
1441
- };
1442
- $.sq_params = {
1443
- max_length_title: ' . (int)$metas->title_maxlength . ',
1444
- max_length_description: ' . (int)$metas->description_maxlength . ',
1445
- };
1446
-
1447
-
1448
- })(jQuery);
1449
- </script>';
1450
-
1451
- echo '<script src="' . _SQ_STATIC_API_URL_ . SQ_URI . '/js/squirrly' . (SQ_DEBUG ? '' : '.min') . '.js?ver=' . SQ_VERSION . '"></script>';
1452
-
1453
- }
1454
-
1455
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ class SQ_Classes_RemoteController
5
+ {
6
+
7
+ public static $cache = array();
8
+ public static $apimethod = 'get';
9
+
10
+ /**
11
+ * Call the Squirrly Cloud Server
12
+ *
13
+ * @param string $module
14
+ * @param array $args
15
+ * @param array $options
16
+ * @return string
17
+ */
18
+ public static function apiCall($module, $args = array(), $options = array())
19
+ {
20
+ $parameters = "";
21
+
22
+ //Don't make API calls without the token unless it's login or register
23
+ if (!SQ_Classes_Helpers_Tools::getOption('sq_api')) {
24
+ if (!in_array($module, array('api/user/login', 'api/user/register'))) {
25
+ return '';
26
+ }
27
+ }
28
+
29
+ //predefined options
30
+ $options = array_merge(
31
+ array(
32
+ 'method' => self::$apimethod,
33
+ 'sslverify' => SQ_CHECK_SSL,
34
+ 'timeout' => 20,
35
+ 'headers' => array(
36
+ 'USER-TOKEN' => SQ_Classes_Helpers_Tools::getOption('sq_api'),
37
+ 'URL-TOKEN' => (SQ_Classes_Helpers_Tools::getOption('sq_cloud_connect') ? SQ_Classes_Helpers_Tools::getOption('sq_cloud_token') : false),
38
+ 'USER-URL' => apply_filters('sq_homeurl', get_bloginfo('url')),
39
+ 'LANG' => apply_filters('sq_language', get_bloginfo('language')),
40
+ 'VERSQ' => (int)str_replace('.', '', SQ_VERSION)
41
+ )
42
+ ),
43
+ $options
44
+ );
45
+
46
+ try {
47
+ if (!empty($args)) {
48
+ foreach ($args as $key => $value) {
49
+ if ($value <> '') {
50
+ $parameters .= ($parameters == "" ? "" : "&") . $key . "=" . urlencode($value);
51
+ }
52
+ }
53
+ }
54
+
55
+ //call it with http to prevent curl issues with ssls
56
+ $url = self::cleanUrl(_SQ_APIV2_URL_ . $module . "?" . $parameters);
57
+
58
+ if (!isset(self::$cache[md5($url)])) {
59
+ if ($options['method'] == 'post') {
60
+ $options['body'] = $args;
61
+ }
62
+
63
+ self::$cache[md5($url)] = self::sq_wpcall($url, $options);
64
+ }
65
+
66
+ return self::$cache[md5($url)];
67
+
68
+
69
+ } catch (Exception $e) {
70
+ return '';
71
+ }
72
+
73
+ }
74
+
75
+ /**
76
+ * Clear the url before the call
77
+ *
78
+ * @param string $url
79
+ * @return string
80
+ */
81
+ private static function cleanUrl($url)
82
+ {
83
+ return str_replace(array(' '), array('+'), $url);
84
+ }
85
+
86
+ public static function generatePassword($length = 12)
87
+ {
88
+ $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
89
+
90
+ $password = '';
91
+ for ($i = 0; $i < $length; $i++) {
92
+ $password .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
93
+ }
94
+
95
+ return $password;
96
+ }
97
+
98
+ /**
99
+ * Get My Squirrly Link
100
+ *
101
+ * @param $path
102
+ * @return string
103
+ */
104
+ public static function getMySquirrlyLink($path)
105
+ {
106
+ return apply_filters('sq_cloudmenu', _SQ_DASH_URL_, $path);
107
+ }
108
+
109
+ /**
110
+ * Get API Link
111
+ *
112
+ * @param string $path
113
+ * @param integer $version
114
+ * @return string
115
+ */
116
+ public static function getApiLink($path)
117
+ {
118
+ return _SQ_APIV2_URL_ . $path . '?token=' . SQ_Classes_Helpers_Tools::getOption('sq_api') . '&url_token='.(SQ_Classes_Helpers_Tools::getOption('sq_cloud_connect') ? SQ_Classes_Helpers_Tools::getOption('sq_cloud_token') : false).'&url=' . apply_filters('sq_homeurl', get_bloginfo('url'));
119
+ }
120
+
121
+ /**
122
+ * Use the WP remote call
123
+ *
124
+ * @param $url
125
+ * @param $options
126
+ * @return array|bool|string|WP_Error
127
+ */
128
+ public static function sq_wpcall($url, $options)
129
+ {
130
+ $method = $options['method'];
131
+ //not accepted as option
132
+ unset($options['method']);
133
+
134
+ switch ($method) {
135
+ case 'get':
136
+ $response = wp_remote_get($url, $options);
137
+ break;
138
+ case 'post':
139
+ $response = wp_remote_post($url, $options);
140
+ break;
141
+ default:
142
+ $response = wp_remote_request($url, $options);
143
+ break;
144
+ }
145
+
146
+ if (is_wp_error($response)) {
147
+ SQ_Classes_Error::setError($response->get_error_message(), 'sq_error');
148
+ return false;
149
+ }
150
+
151
+ $response = self::cleanResponce(wp_remote_retrieve_body($response)); //clear and get the body
152
+
153
+ SQ_Debug::dump('wp_remote_get', $method, $url, $options, $response); //output debug
154
+ return $response;
155
+ }
156
+
157
+ /**
158
+ * Get the Json from responce if any
159
+ *
160
+ * @param string $response
161
+ * @return string
162
+ */
163
+ private static function cleanResponce($response)
164
+ {
165
+ return trim($response, '()');
166
+ }
167
+
168
+ /**********************
169
+ *
170
+ * USER
171
+ ******************************/
172
+ /**
173
+ * @param array $args
174
+ * @return array|mixed|object|WP_Error
175
+ */
176
+ public static function connect($args = array())
177
+ {
178
+ self::$apimethod = 'post'; //call method
179
+ $json = json_decode(self::apiCall('api/user/connect', $args));
180
+
181
+ if (isset($json->error) && $json->error <> '') {
182
+
183
+ if ($json->error == 'invalid_token') {
184
+ SQ_Classes_Helpers_Tools::saveOptions('sq_api', false);
185
+ }
186
+ if ($json->error == 'disconnected') {
187
+ SQ_Classes_Helpers_Tools::saveOptions('sq_api', false);
188
+ }
189
+ if ($json->error == 'banned') {
190
+ SQ_Classes_Helpers_Tools::saveOptions('sq_api', false);
191
+ }
192
+ return (new WP_Error('api_error', $json->error));
193
+ }
194
+
195
+ //Refresh the checkin on login
196
+ delete_transient('sq_checkin');
197
+
198
+ return $json;
199
+ }
200
+
201
+ /**
202
+ * Login user to API
203
+ *
204
+ * @param array $args
205
+ * @return bool|WP_Error
206
+ */
207
+ public static function login($args = array())
208
+ {
209
+ self::$apimethod = 'post'; //call method
210
+
211
+ $json = json_decode(self::apiCall('api/user/login', $args));
212
+
213
+ if (isset($json->error) && $json->error <> '') {
214
+ return (new WP_Error('api_error', $json->error));
215
+ } elseif (!isset($json->data)) {
216
+ return (new WP_Error('api_error', 'no_data'));
217
+ }
218
+
219
+ //Refresh the checkin on login
220
+ delete_transient('sq_checkin');
221
+
222
+ if (!empty($json->data)) {
223
+ return $json->data;
224
+ }
225
+
226
+ return false;
227
+ }
228
+
229
+ /**
230
+ * Register user to API
231
+ *
232
+ * @param array $args
233
+ * @return bool|WP_Error
234
+ */
235
+ public static function register($args = array())
236
+ {
237
+ self::$apimethod = 'post'; //call method
238
+
239
+ $json = json_decode(self::apiCall('api/user/register', $args));
240
+
241
+ if (isset($json->error) && $json->error <> '') {
242
+ return (new WP_Error('api_error', $json->error));
243
+ } elseif (!isset($json->data)) {
244
+ return (new WP_Error('api_error', 'no_data'));
245
+ }
246
+
247
+ //Refresh the checkin on login
248
+ delete_transient('sq_checkin');
249
+
250
+ if (!empty($json->data)) {
251
+ return $json->data;
252
+ }
253
+
254
+ return false;
255
+ }
256
+
257
+ public static function getCloudToken($args = array())
258
+ {
259
+ self::$apimethod = 'get'; //call method
260
+
261
+ $json = json_decode(self::apiCall('api/user/token', $args));
262
+
263
+ if (isset($json->error) && $json->error <> '') {
264
+ return (new WP_Error('api_error', $json->error));
265
+ } elseif (!isset($json->data)) {
266
+ return (new WP_Error('api_error', 'no_data'));
267
+ }
268
+
269
+ if (!empty($json->data)) {
270
+ return $json->data;
271
+ }
272
+
273
+ return false;
274
+ }
275
+
276
+ /**
277
+ * User Checkin
278
+ *
279
+ * @param array $args
280
+ * @return bool|WP_Error
281
+ */
282
+ public static function checkin($args = array())
283
+ {
284
+ self::$apimethod = 'get'; //call method
285
+
286
+ if (get_transient('sq_checkin')) {
287
+ return get_transient('sq_checkin');
288
+ }
289
+
290
+ $json = json_decode(self::apiCall('api/user/checkin', $args));
291
+
292
+ if (isset($json->error) && $json->error <> '') {
293
+
294
+ //prevent throttling on API
295
+ if ($json->error == 'too_many_requests') {
296
+ SQ_Classes_Error::setError(esc_html__("Too many API attempts, please slow down the request.", 'squirrly-seo'));
297
+ SQ_Classes_Error::hookNotices();
298
+ return (new WP_Error('api_error', $json->error));
299
+ } elseif ($json->error == 'maintenance') {
300
+ SQ_Classes_Error::setError(esc_html__("Squirrly Cloud is down for a bit of maintenance right now. But we'll be back in a minute.", 'squirrly-seo'));
301
+ SQ_Classes_Error::hookNotices();
302
+ return (new WP_Error('maintenance', $json->error));
303
+ }
304
+
305
+ self::connect(); //connect the website
306
+ return (new WP_Error('api_error', $json->error));
307
+
308
+ } elseif (!isset($json->data)) {
309
+ return (new WP_Error('api_error', 'no_data'));
310
+ }
311
+
312
+ if (isset($json->data->offer) && $json->data->offer <> '') {
313
+ SQ_Classes_Helpers_Tools::saveOptions('sq_offer', $json->data->offer);
314
+ } else {
315
+ SQ_Classes_Helpers_Tools::saveOptions('sq_offer', false);
316
+ }
317
+
318
+ //Save the connections into database
319
+ if (isset($json->data->connection_gsc) && isset($json->data->connection_ga)) {
320
+ $connect = SQ_Classes_Helpers_Tools::getOption('connect');
321
+ $connect['google_analytics'] = $json->data->connection_ga;
322
+ $connect['google_search_console'] = $json->data->connection_gsc;
323
+ SQ_Classes_Helpers_Tools::saveOptions('connect', $connect);
324
+ }
325
+
326
+ if(isset($json->data->subscription_devkit)) {
327
+ SQ_Classes_Helpers_Tools::saveOptions('sq_auto_devkit', (int)$json->data->subscription_devkit);
328
+ }
329
+
330
+ set_transient('sq_checkin', $json->data, 60);
331
+ return $json->data;
332
+ }
333
+
334
+ /********************************
335
+ *
336
+ * NOTIFICATIONS
337
+ *********************/
338
+ /**
339
+ * Get the Notifications from API for the current blog
340
+ *
341
+ * @return array|WP_Error
342
+ */
343
+ public static function getNotifications()
344
+ {
345
+ self::$apimethod = 'get'; //call method
346
+
347
+ $notifications = array();
348
+ if ($json = json_decode(self::apiCall('api/audits/notifications', array()))) {
349
+
350
+ if (isset($json->error) && $json->error <> '') {
351
+ return (new WP_Error('api_error', $json->error));
352
+ } elseif (!isset($json->data)) {
353
+ return (new WP_Error('api_error', 'no_data'));
354
+ }
355
+
356
+ $notifications = $json->data;
357
+
358
+ }
359
+
360
+ return $notifications;
361
+ }
362
+
363
+ /**
364
+ * Get the API stats for this blog
365
+ *
366
+ * @return array|WP_Error|false
367
+ */
368
+ public static function getStats()
369
+ {
370
+ self::$apimethod = 'get'; //call method
371
+
372
+ if (get_transient('sq_stats')) {
373
+ return get_transient('sq_stats');
374
+ }
375
+
376
+ $args = array();
377
+ $json = json_decode(self::apiCall('api/user/stats', $args));
378
+
379
+ if (isset($json->error) && $json->error <> '') {
380
+ return (new WP_Error('api_error', $json->error));
381
+ } elseif (!isset($json->data)) {
382
+ return (new WP_Error('api_error', 'no_data'));
383
+ }
384
+
385
+ if (!empty($json->data)) {
386
+ set_transient('sq_stats', $json->data, 60);
387
+ return $json->data;
388
+ }
389
+
390
+ return false;
391
+
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
+ {
402
+ self::$apimethod = 'get'; //call method
403
+
404
+ $json = json_decode(self::apiCall('api/audits/get-audits', $args));
405
+
406
+ if (isset($json->error) && $json->error <> '') {
407
+ return (new WP_Error('api_error', $json->error));
408
+ } elseif (!isset($json->data)) {
409
+ return (new WP_Error('api_error', 'no_data'));
410
+ }
411
+
412
+ if (!isset($json->data->audits)) {
413
+ return (new WP_Error('api_error', 'no_data'));
414
+ }
415
+
416
+ return $json->data->audits;
417
+ }
418
+
419
+ public static function saveFeedback($args = array())
420
+ {
421
+ self::$apimethod = 'post'; //call method
422
+
423
+ $json = json_decode(self::apiCall('api/user/feedback', $args));
424
+
425
+ if (isset($json->error) && $json->error <> '') {
426
+ return (new WP_Error('api_error', $json->error));
427
+ } elseif (!isset($json->data)) {
428
+ return (new WP_Error('api_error', 'no_data'));
429
+ }
430
+
431
+ if (!empty($json->data)) {
432
+ return $json->data;
433
+ }
434
+
435
+ return false;
436
+ }
437
+
438
+
439
+ /********************************
440
+ *
441
+ * BRIEFCASE
442
+ *********************/
443
+ public static function getBriefcaseStats($args = array())
444
+ {
445
+ self::$apimethod = 'get'; //call method
446
+
447
+ if (get_transient('sq_briefcase_stats')) {
448
+ return get_transient('sq_briefcase_stats');
449
+ }
450
+
451
+ $json = json_decode(self::apiCall('api/briefcase/stats', $args));
452
+
453
+ if (isset($json->error) && $json->error <> '') {
454
+ return (new WP_Error('api_error', $json->error));
455
+ } elseif (!isset($json->data)) {
456
+ return (new WP_Error('api_error', 'no_data'));
457
+ }
458
+
459
+ if (!empty($json->data)) {
460
+ set_transient('sq_briefcase_stats', $json->data, 60);
461
+ return $json->data;
462
+ }
463
+
464
+ return false;
465
+ }
466
+
467
+ public static function getBriefcase($args = array())
468
+ {
469
+ self::$apimethod = 'get'; //call method
470
+
471
+ $json = json_decode(self::apiCall('api/briefcase/get', $args, ['timeout' => 60]));
472
+
473
+ if (isset($json->error) && $json->error <> '') {
474
+ return (new WP_Error('api_error', $json->error));
475
+ } elseif (!isset($json->data)) {
476
+ return (new WP_Error('api_error', 'no_data'));
477
+ }
478
+
479
+ if (!empty($json->data)) {
480
+ return $json->data;
481
+ }
482
+
483
+ return false;
484
+ }
485
+
486
+ public static function importBriefcaseKeywords($args = array())
487
+ {
488
+ self::$apimethod = 'post'; //call method
489
+
490
+ //clear the briefcase stats
491
+ delete_transient('sq_briefcase_stats');
492
+
493
+ $json = json_decode(self::apiCall('api/briefcase/import', $args));
494
+
495
+ if (isset($json->error) && $json->error <> '') {
496
+ return (new WP_Error('api_error', $json->error));
497
+ } elseif (!isset($json->data)) {
498
+ return (new WP_Error('api_error', 'no_data'));
499
+ }
500
+
501
+ if (!empty($json->data)) {
502
+ return $json->data;
503
+ }
504
+
505
+ return false;
506
+ }
507
+
508
+ public static function addBriefcaseKeyword($args = array())
509
+ {
510
+ self::$apimethod = 'post'; //call method
511
+
512
+ //clear the briefcase stats
513
+ delete_transient('sq_briefcase_stats');
514
+
515
+ $json = json_decode(self::apiCall('api/briefcase/add', $args));
516
+
517
+ if (isset($json->error) && $json->error <> '') {
518
+ return (new WP_Error('api_error', $json->error));
519
+ } elseif (!isset($json->data)) {
520
+ return (new WP_Error('api_error', 'no_data'));
521
+ }
522
+
523
+ if (!empty($json->data)) {
524
+ return $json->data;
525
+ }
526
+
527
+ return false;
528
+ }
529
+
530
+ public static function removeBriefcaseKeyword($args = array())
531
+ {
532
+ self::$apimethod = 'post'; //call method
533
+
534
+ if ($json = json_decode(self::apiCall('api/briefcase/hide', $args))) {
535
+ return $json;
536
+ }
537
+
538
+ return false;
539
+ }
540
+
541
+ public static function saveBriefcaseKeywordLabel($args = array())
542
+ {
543
+ self::$apimethod = 'post'; //call method
544
+
545
+ //clear the briefcase stats
546
+ delete_transient('sq_briefcase_stats');
547
+
548
+ $json = json_decode(self::apiCall('api/briefcase/label/keyword', $args));
549
+
550
+ if (isset($json->error) && $json->error <> '') {
551
+ return (new WP_Error('api_error', $json->error));
552
+ } elseif (!isset($json->data)) {
553
+ return (new WP_Error('api_error', 'no_data'));
554
+ }
555
+
556
+ if (!empty($json->data)) {
557
+ return $json->data;
558
+ }
559
+
560
+ return false;
561
+ }
562
+
563
+ public static function addBriefcaseLabel($args = array())
564
+ {
565
+ self::$apimethod = 'post'; //call method
566
+
567
+ //clear the briefcase stats
568
+ delete_transient('sq_briefcase_stats');
569
+
570
+ $json = json_decode(self::apiCall('api/briefcase/label/add', $args));
571
+
572
+ if (isset($json->error) && $json->error <> '') {
573
+ return (new WP_Error('api_error', $json->error));
574
+ } elseif (!isset($json->data)) {
575
+ return (new WP_Error('api_error', 'no_data'));
576
+ }
577
+
578
+ if (!empty($json->data)) {
579
+ return $json->data;
580
+ }
581
+
582
+ return false;
583
+ }
584
+
585
+ public static function saveBriefcaseLabel($args = array())
586
+ {
587
+ self::$apimethod = 'post'; //call method
588
+
589
+ //clear the briefcase stats
590
+ delete_transient('sq_briefcase_stats');
591
+
592
+ $json = json_decode(self::apiCall('api/briefcase/label/save', $args));
593
+
594
+ if (isset($json->error) && $json->error <> '') {
595
+ return (new WP_Error('api_error', $json->error));
596
+ } elseif (!isset($json->data)) {
597
+ return (new WP_Error('api_error', 'no_data'));
598
+ }
599
+
600
+ if (!empty($json->data)) {
601
+ return $json->data;
602
+ }
603
+
604
+ return false;
605
+ }
606
+
607
+ public static function removeBriefcaseLabel($args = array())
608
+ {
609
+ self::$apimethod = 'post'; //call method
610
+
611
+ $json = json_decode(self::apiCall('api/briefcase/label/delete', $args));
612
+
613
+ if (isset($json->error) && $json->error <> '') {
614
+ return (new WP_Error('api_error', $json->error));
615
+ } elseif (!isset($json->data)) {
616
+ return (new WP_Error('api_error', 'no_data'));
617
+ }
618
+
619
+ if (!empty($json->data)) {
620
+ return $json->data;
621
+ }
622
+
623
+ return false;
624
+ }
625
+
626
+ public static function saveBriefcaseMainKeyword($args = array())
627
+ {
628
+ self::$apimethod = 'post'; //call method
629
+
630
+ $json = json_decode(self::apiCall('api/briefcase/main', $args));
631
+
632
+ if (isset($json->error) && $json->error <> '') {
633
+ return (new WP_Error('api_error', $json->error));
634
+ } elseif (!isset($json->data)) {
635
+ return (new WP_Error('api_error', 'no_data'));
636
+ }
637
+
638
+ if (!empty($json->data)) {
639
+ return $json->data;
640
+ }
641
+
642
+ return false;
643
+ }
644
+
645
+
646
+ /********************************
647
+ *
648
+ * KEYWORD RESEARCH
649
+ ****************/
650
+
651
+ /**
652
+ * Get KR Countries
653
+ *
654
+ * @param array $args
655
+ * @return bool|WP_Error
656
+ */
657
+ public static function getKrCountries($args = array())
658
+ {
659
+ self::$apimethod = 'get'; //call method
660
+
661
+ $json = json_decode(self::apiCall('api/kr/countries', $args));
662
+
663
+ if (isset($json->error) && $json->error <> '') {
664
+ return (new WP_Error('api_error', $json->error));
665
+ } elseif (!isset($json->data)) {
666
+ return (new WP_Error('api_error', 'no_data'));
667
+ }
668
+
669
+ if (!empty($json->data)) {
670
+ return $json->data;
671
+ }
672
+
673
+ return false;
674
+ }
675
+
676
+ public static function getKROthers($args = array())
677
+ {
678
+ self::$apimethod = 'get'; //call method
679
+
680
+ $json = json_decode(self::apiCall('api/kr/other', $args));
681
+
682
+ if (isset($json->error) && $json->error <> '') {
683
+ return (new WP_Error('api_error', $json->error));
684
+ } elseif (!isset($json->data)) {
685
+ return (new WP_Error('api_error', 'no_data'));
686
+ }
687
+
688
+ if (!empty($json->data)) {
689
+ return $json->data;
690
+ }
691
+
692
+ return false;
693
+ }
694
+
695
+ /**
696
+ * Set Keyword Research
697
+ *
698
+ * @param array $args
699
+ * @return array|bool|mixed|object|WP_Error
700
+ */
701
+ public static function setKRSuggestion($args = array())
702
+ {
703
+ self::$apimethod = 'post'; //call method
704
+
705
+ //clear the briefcase stats
706
+ delete_transient('sq_stats');
707
+ delete_transient('sq_briefcase_stats');
708
+
709
+ $json = json_decode(self::apiCall('api/kr/suggestion', $args));
710
+
711
+ if (isset($json->error) && $json->error <> '') {
712
+ return (new WP_Error('api_error', $json->error));
713
+ } elseif (!isset($json->data)) {
714
+ return (new WP_Error('api_error', 'no_data'));
715
+ }
716
+
717
+ if (!empty($json->data)) {
718
+ return $json->data;
719
+ }
720
+
721
+ return false;
722
+ }
723
+
724
+ public static function getKRSuggestion($args = array())
725
+ {
726
+ self::$apimethod = 'get'; //call method
727
+
728
+ $json = json_decode(self::apiCall('api/kr/suggestion', $args));
729
+
730
+ if (isset($json->error) && $json->error <> '') {
731
+ return (new WP_Error('api_error', $json->error));
732
+ } elseif (!isset($json->data)) {
733
+ return (new WP_Error('api_error', 'no_data'));
734
+ }
735
+
736
+ if (!empty($json->data)) {
737
+ return $json->data;
738
+ }
739
+
740
+ return false;
741
+ }
742
+
743
+ /********************************
744
+ *
745
+ * KEYWORD HISTORY & FOUND
746
+ ****************/
747
+
748
+ /**
749
+ * Get Keyword Research History
750
+ *
751
+ * @param array $args
752
+ * @return array|bool|mixed|object|WP_Error
753
+ */
754
+ public static function getKRHistory($args = array())
755
+ {
756
+ self::$apimethod = 'get'; //call method
757
+
758
+ $json = json_decode(self::apiCall('api/kr/history', $args));
759
+
760
+ if (isset($json->error) && $json->error <> '') {
761
+ return (new WP_Error('api_error', $json->error));
762
+ } elseif (!isset($json->data)) {
763
+ return (new WP_Error('api_error', 'no_data'));
764
+ }
765
+
766
+ if (!empty($json->data)) {
767
+ return $json->data;
768
+ }
769
+
770
+ return false;
771
+ }
772
+
773
+ /**
774
+ * Get the Kr Found by API
775
+ *
776
+ * @param array $args
777
+ * @return bool|WP_Error
778
+ */
779
+ public static function getKrFound($args = array())
780
+ {
781
+ self::$apimethod = 'get'; //call method
782
+
783
+ $json = json_decode(self::apiCall('api/kr/found', $args));
784
+
785
+ if (isset($json->error) && $json->error <> '') {
786
+ return (new WP_Error('api_error', $json->error));
787
+ } elseif (!isset($json->data)) {
788
+ return (new WP_Error('api_error', 'no_data'));
789
+ }
790
+
791
+ if (!empty($json->data)) {
792
+ return $json->data;
793
+ }
794
+
795
+ return false;
796
+ }
797
+
798
+ /**
799
+ *
800
+ * Remove Keyword from Suggestions
801
+ *
802
+ * @param array $args
803
+ * @return bool|WP_Error
804
+ */
805
+ public static function removeKrFound($args = array())
806
+ {
807
+ self::$apimethod = 'post'; //call method
808
+
809
+ $json = json_decode(self::apiCall('api/kr/found/delete', $args));
810
+
811
+ if (isset($json->error) && $json->error <> '') {
812
+ return (new WP_Error('api_error', $json->error));
813
+ } elseif (!isset($json->data)) {
814
+ return (new WP_Error('api_error', 'no_data'));
815
+ }
816
+
817
+ if (!empty($json->data)) {
818
+ return $json->data;
819
+ }
820
+
821
+ return false;
822
+ }
823
+ /********************
824
+ *
825
+ * WP Posts
826
+ ***************************/
827
+ /**
828
+ * Save the post status on API
829
+ *
830
+ * @param array $args
831
+ * @return bool|WP_Error
832
+ */
833
+ public static function savePost($args = array())
834
+ {
835
+ self::$apimethod = 'post'; //call method
836
+
837
+ //clear the briefcase stats
838
+ delete_transient('sq_stats');
839
+
840
+ $json = json_decode(self::apiCall('api/posts/update', $args, ['timeout' => 5]));
841
+
842
+ if (isset($json->error) && $json->error <> '') {
843
+ return (new WP_Error('api_error', $json->error));
844
+ } elseif (!isset($json->data)) {
845
+ return (new WP_Error('api_error', 'no_data'));
846
+ }
847
+
848
+ if (!empty($json->data)) {
849
+ return $json->data;
850
+ }
851
+
852
+ return false;
853
+
854
+ }
855
+
856
+ /**
857
+ * Get the post optimization
858
+ *
859
+ * @param array $args
860
+ * @return array|mixed|object
861
+ */
862
+ public static function getPostOptimization($args = array())
863
+ {
864
+ self::$apimethod = 'get'; //call method
865
+
866
+ $json = json_decode(self::apiCall('api/posts/optimizations', $args));
867
+
868
+ if (isset($json->error) && $json->error <> '') {
869
+ return (new WP_Error('api_error', $json->error));
870
+ } elseif (!isset($json->data)) {
871
+ return (new WP_Error('api_error', 'no_data'));
872
+ }
873
+
874
+ if (!empty($json->data)) {
875
+ return $json->data;
876
+ }
877
+
878
+ return false;
879
+
880
+ }
881
+
882
+ /********************
883
+ *
884
+ * RANKINGS
885
+ ***************************/
886
+
887
+ /**
888
+ * Add a keyword in Rank Checker
889
+ *
890
+ * @param array $args
891
+ * @return bool|WP_Error
892
+ */
893
+ public static function addSerpKeyword($args = array())
894
+ {
895
+ self::$apimethod = 'post'; //call method
896
+
897
+ $json = json_decode(self::apiCall('api/briefcase/serp', $args));
898
+
899
+ if (isset($json->error) && $json->error <> '') {
900
+ return (new WP_Error('api_error', $json->error));
901
+ } elseif (!isset($json->data)) {
902
+ return (new WP_Error('api_error', 'no_data'));
903
+ }
904
+
905
+ if (!empty($json->data)) {
906
+ return $json->data;
907
+ }
908
+
909
+ return false;
910
+ }
911
+
912
+ /**
913
+ * Delete a keyword from Rank Checker
914
+ *
915
+ * @param array $args
916
+ * @return bool|WP_Error
917
+ */
918
+ public static function deleteSerpKeyword($args = array())
919
+ {
920
+ self::$apimethod = 'post'; //call method
921
+
922
+ $json = json_decode(self::apiCall('api/briefcase/serp-delete', $args));
923
+
924
+ if (isset($json->error) && $json->error <> '') {
925
+ return (new WP_Error('api_error', $json->error));
926
+ } elseif (!isset($json->data)) {
927
+ return (new WP_Error('api_error', 'no_data'));
928
+ }
929
+
930
+ if (!empty($json->data)) {
931
+ return $json->data;
932
+ }
933
+
934
+ return false;
935
+ }
936
+
937
+ /**
938
+ * Get the Ranks for this blog
939
+ *
940
+ * @param array $args
941
+ * @return bool|WP_Error
942
+ */
943
+ public static function getRanksStats($args = array())
944
+ {
945
+ self::$apimethod = 'get'; //call method
946
+
947
+ $json = json_decode(self::apiCall('api/serp/stats', $args));
948
+
949
+ if (isset($json->error) && $json->error <> '') {
950
+ return (new WP_Error('api_error', $json->error));
951
+ } elseif (!isset($json->data)) {
952
+ return (new WP_Error('api_error', 'no_data'));
953
+ }
954
+
955
+ if (!empty($json->data)) {
956
+ return $json->data;
957
+ }
958
+
959
+ return false;
960
+ }
961
+
962
+ /**
963
+ * Get the Ranks for this blog
964
+ *
965
+ * @param array $args
966
+ * @return bool|WP_Error
967
+ */
968
+ public static function getRanks($args = array())
969
+ {
970
+ self::$apimethod = 'get'; //call method
971
+
972
+ $json = json_decode(self::apiCall('api/serp/get-ranks', $args));
973
+
974
+ if (isset($json->error) && $json->error <> '') {
975
+ return (new WP_Error('api_error', $json->error));
976
+ } elseif (!isset($json->data)) {
977
+ return (new WP_Error('api_error', 'no_data'));
978
+ }
979
+
980
+ if (!empty($json->data)) {
981
+ return $json->data;
982
+ }
983
+
984
+ return false;
985
+ }
986
+
987
+ /**
988
+ * Refresh the rank for a page/post
989
+ *
990
+ * @param array $args
991
+ * @return bool|WP_Error
992
+ */
993
+ public static function checkPostRank($args = array())
994
+ {
995
+ self::$apimethod = 'get'; //call method
996
+
997
+ $json = json_decode(self::apiCall('api/serp/refresh', $args));
998
+
999
+ if (isset($json->error) && $json->error <> '') {
1000
+ return (new WP_Error('api_error', $json->error));
1001
+ } elseif (!isset($json->data)) {
1002
+ return (new WP_Error('api_error', 'no_data'));
1003
+ }
1004
+
1005
+ if (!empty($json->data)) {
1006
+ return $json->data;
1007
+ }
1008
+
1009
+ return false;
1010
+ }
1011
+
1012
+ /********************
1013
+ *
1014
+ * FOCUS PAGES
1015
+ ***********************/
1016
+
1017
+ /**
1018
+ * Get all focus pages and add them in the SQ_Models_Domain_FocusPage object
1019
+ * Add the audit data for each focus page
1020
+ *
1021
+ * @param array $args
1022
+ * @return SQ_Models_Domain_FocusPage|WP_Error|false
1023
+ */
1024
+ public static function getFocusPages($args = array())
1025
+ {
1026
+ self::$apimethod = 'get'; //call method
1027
+
1028
+ $json = json_decode(self::apiCall('api/posts/focus', $args));
1029
+
1030
+ if (isset($json->error) && $json->error <> '') {
1031
+ return (new WP_Error('api_error', $json->error));
1032
+ } elseif (!isset($json->data)) {
1033
+ return (new WP_Error('api_error', 'no_data'));
1034
+ }
1035
+
1036
+ if (!empty($json->data)) {
1037
+ return $json->data;
1038
+ }
1039
+
1040
+ return false;
1041
+ }
1042
+
1043
+ /**
1044
+ * Get the focus page audit
1045
+ *
1046
+ * @param array $args
1047
+ * @return bool|WP_Error
1048
+ */
1049
+ public static function getFocusAudits($args = array())
1050
+ {
1051
+ self::$apimethod = 'get'; //call method
1052
+
1053
+ $json = json_decode(self::apiCall('api/audits/focus', $args));
1054
+
1055
+ if (isset($json->error) && $json->error <> '') {
1056
+ return (new WP_Error('api_error', $json->error));
1057
+ } elseif (!isset($json->data)) {
1058
+ return (new WP_Error('api_error', 'no_data'));
1059
+ }
1060
+
1061
+ if (!empty($json->data)) {
1062
+ return $json->data;
1063
+ }
1064
+
1065
+ return false;
1066
+ }
1067
+
1068
+ /**
1069
+ * Add Focus Page
1070
+ *
1071
+ * @param array $args
1072
+ * @return bool|WP_Error
1073
+ */
1074
+ public static function addFocusPage($args = array())
1075
+ {
1076
+ self::$apimethod = 'post'; //post call
1077
+
1078
+ $json = json_decode(self::apiCall('api/posts/set-focus', $args));
1079
+
1080
+ if (isset($json->error) && $json->error <> '') {
1081
+ return (new WP_Error('api_error', $json->error));
1082
+ } elseif (!isset($json->data)) {
1083
+ return (new WP_Error('api_error', 'no_data'));
1084
+ }
1085
+
1086
+ if (!empty($json->data)) {
1087
+ return $json->data;
1088
+ }
1089
+
1090
+ return false;
1091
+ }
1092
+
1093
+ public static function updateFocusPage($args = array())
1094
+ {
1095
+ self::$apimethod = 'post'; //post call
1096
+
1097
+ $json = json_decode(self::apiCall('api/posts/update-focus', $args));
1098
+
1099
+ if (isset($json->error) && $json->error <> '') {
1100
+ return (new WP_Error('api_error', $json->error));
1101
+ } elseif (!isset($json->data)) {
1102
+ return (new WP_Error('api_error', 'no_data'));
1103
+ }
1104
+
1105
+ if (!empty($json->data)) {
1106
+ return $json->data;
1107
+ }
1108
+
1109
+ return false;
1110
+ }
1111
+
1112
+ /**
1113
+ * Delete the Focus Page
1114
+ *
1115
+ * @param array $args
1116
+ * @return bool|WP_Error
1117
+ */
1118
+ public static function deleteFocusPage($args = array())
1119
+ {
1120
+ self::$apimethod = 'post'; //post call
1121
+
1122
+ if (isset($args['user_post_id']) && $args['user_post_id'] > 0) {
1123
+ $json = json_decode(self::apiCall('api/posts/remove-focus/' . $args['user_post_id']));
1124
+
1125
+ if (isset($json->error) && $json->error <> '') {
1126
+ return (new WP_Error('api_error', $json->error));
1127
+ } elseif (!isset($json->data)) {
1128
+ return (new WP_Error('api_error', 'no_data'));
1129
+ }
1130
+
1131
+ return $json->data;
1132
+ }
1133
+
1134
+ return false;
1135
+ }
1136
+
1137
+ /**
1138
+ * Get all focus pages and add them in the SQ_Models_Domain_FocusPage object
1139
+ * Add the audit data for each focus page
1140
+ *
1141
+ * @param array $args
1142
+ * @return SQ_Models_Domain_FocusPage|WP_Error|false
1143
+ */
1144
+ public static function getInspectURL($args = array())
1145
+ {
1146
+ self::$apimethod = 'get'; //call method
1147
+
1148
+ $json = json_decode(self::apiCall('api/posts/crawl', $args, ['timeout' => 60]));
1149
+
1150
+ if (isset($json->error) && $json->error <> '') {
1151
+ return (new WP_Error('api_error', $json->error));
1152
+ } elseif (!isset($json->data)) {
1153
+ return (new WP_Error('api_error', 'no_data'));
1154
+ }
1155
+
1156
+ if (!empty($json->data)) {
1157
+ return $json->data;
1158
+ }
1159
+
1160
+ return false;
1161
+ }
1162
+ /****************************************
1163
+ *
1164
+ * CONNECTIONS
1165
+ */
1166
+ /**
1167
+ * Disconnect Google Analytics account
1168
+ *
1169
+ * @return bool|WP_Error
1170
+ */
1171
+ public static function revokeGaConnection()
1172
+ {
1173
+ self::$apimethod = 'get'; //post call
1174
+
1175
+ $json = json_decode(self::apiCall('api/ga/revoke'));
1176
+
1177
+ if (isset($json->error) && $json->error <> '') {
1178
+ return (new WP_Error('api_error', $json->error));
1179
+ } elseif (!isset($json->data)) {
1180
+ return (new WP_Error('api_error', 'no_data'));
1181
+ }
1182
+
1183
+ //Refresh the checkin on login
1184
+ delete_transient('sq_checkin');
1185
+
1186
+ if (!empty($json->data)) {
1187
+ return $json->data;
1188
+ }
1189
+
1190
+ return false;
1191
+ }
1192
+
1193
+ public static function getGAToken($args = array())
1194
+ {
1195
+ self::$apimethod = 'get'; //post call
1196
+
1197
+ $json = json_decode(self::apiCall('api/ga/token', $args));
1198
+
1199
+ if (isset($json->error) && $json->error <> '') {
1200
+ return (new WP_Error('api_error', $json->error));
1201
+ } elseif (!isset($json->data)) {
1202
+ return (new WP_Error('api_error', 'no_data'));
1203
+ }
1204
+
1205
+ if (!empty($json->data)) {
1206
+ return $json->data;
1207
+ }
1208
+
1209
+ return false;
1210
+
1211
+ }
1212
+
1213
+ public static function getGAProperties($args = array())
1214
+ {
1215
+ self::$apimethod = 'get'; //post call
1216
+
1217
+ $json = json_decode(self::apiCall('api/ga/properties', $args));
1218
+
1219
+ if (isset($json->error) && $json->error <> '') {
1220
+ return (new WP_Error('api_error', $json->error));
1221
+ } elseif (!isset($json->data)) {
1222
+ return (new WP_Error('api_error', 'no_data'));
1223
+ }
1224
+
1225
+ if (!empty($json->data)) {
1226
+ return $json->data;
1227
+ }
1228
+
1229
+ return false;
1230
+
1231
+ }
1232
+
1233
+ public static function saveGAProperties($args = array())
1234
+ {
1235
+ self::$apimethod = 'post'; //post call
1236
+
1237
+ $json = json_decode(self::apiCall('api/ga/properties', $args));
1238
+
1239
+ if (isset($json->error) && $json->error <> '') {
1240
+ return (new WP_Error('api_error', $json->error));
1241
+ } elseif (!isset($json->data)) {
1242
+ return (new WP_Error('api_error', 'no_data'));
1243
+ }
1244
+
1245
+ if (!empty($json->data)) {
1246
+ return $json->data;
1247
+ }
1248
+
1249
+ return false;
1250
+
1251
+ }
1252
+
1253
+ /**
1254
+ * Disconnect Google Search Console account
1255
+ *
1256
+ * @return bool|WP_Error
1257
+ */
1258
+ public static function revokeGscConnection()
1259
+ {
1260
+ self::$apimethod = 'get'; //post call
1261
+
1262
+ $json = json_decode(self::apiCall('api/gsc/revoke'));
1263
+
1264
+ if (isset($json->error) && $json->error <> '') {
1265
+ return (new WP_Error('api_error', $json->error));
1266
+ } elseif (!isset($json->data)) {
1267
+ return (new WP_Error('api_error', 'no_data'));
1268
+ }
1269
+
1270
+ //Refresh the checkin on login
1271
+ delete_transient('sq_checkin');
1272
+
1273
+ if (!empty($json->data)) {
1274
+ return $json->data;
1275
+ }
1276
+
1277
+ return false;
1278
+
1279
+ }
1280
+
1281
+ public static function syncGSC($args = array())
1282
+ {
1283
+ self::$apimethod = 'get'; //post call
1284
+
1285
+ $json = json_decode(self::apiCall('api/gsc/sync/kr', $args));
1286
+
1287
+ if (isset($json->error) && $json->error <> '') {
1288
+ return (new WP_Error('api_error', $json->error));
1289
+ } elseif (!isset($json->data)) {
1290
+ return (new WP_Error('api_error', 'no_data'));
1291
+ }
1292
+
1293
+ if (!empty($json->data)) {
1294
+ return $json->data;
1295
+ }
1296
+
1297
+ return false;
1298
+
1299
+ }
1300
+
1301
+ public static function getGSCToken($args = array())
1302
+ {
1303
+ self::$apimethod = 'get'; //post call
1304
+
1305
+ $json = json_decode(self::apiCall('api/gsc/token', $args));
1306
+
1307
+ if (isset($json->error) && $json->error <> '') {
1308
+ return (new WP_Error('api_error', $json->error));
1309
+ } elseif (!isset($json->data)) {
1310
+ return (new WP_Error('api_error', 'no_data'));
1311
+ }
1312
+
1313
+ if (!empty($json->data)) {
1314
+ return $json->data;
1315
+ }
1316
+
1317
+ return false;
1318
+
1319
+ }
1320
+
1321
+ /********************
1322
+ *
1323
+ * AUDITS
1324
+ *****************************/
1325
+
1326
+ public static function getAuditPages($args = array())
1327
+ {
1328
+ self::$apimethod = 'get'; //call method
1329
+
1330
+ $json = json_decode(self::apiCall('api/posts/audits', $args));
1331
+
1332
+ if (isset($json->error) && $json->error <> '') {
1333
+ return (new WP_Error('api_error', $json->error));
1334
+ } elseif (!isset($json->data)) {
1335
+ return (new WP_Error('api_error', 'no_data'));
1336
+ }
1337
+
1338
+ if (!empty($json->data)) {
1339
+ return $json->data;
1340
+ }
1341
+
1342
+ return false;
1343
+
1344
+ }
1345
+
1346
+ /**
1347
+ * Get the audit page
1348
+ *
1349
+ * @param array $args
1350
+ * @return bool|WP_Error
1351
+ */
1352
+ public static function getAudit($args = array())
1353
+ {
1354
+ self::$apimethod = 'get'; //call method
1355
+
1356
+ $json = json_decode(self::apiCall('api/audits/audit', $args));
1357
+
1358
+ if (isset($json->error) && $json->error <> '') {
1359
+ return (new WP_Error('api_error', $json->error));
1360
+ } elseif (!isset($json->data)) {
1361
+ return (new WP_Error('api_error', 'no_data'));
1362
+ }
1363
+
1364
+ if (!empty($json->data)) {
1365
+ return $json->data;
1366
+ }
1367
+
1368
+ return false;
1369
+
1370
+ }
1371
+
1372
+ /**
1373
+ * Add Audit Page
1374
+ *
1375
+ * @param array $args
1376
+ * @return bool|WP_Error
1377
+ */
1378
+ public static function addAuditPage($args = array())
1379
+ {
1380
+ self::$apimethod = 'post'; //post call
1381
+
1382
+ $json = json_decode(self::apiCall('api/posts/set-audit', $args));
1383
+
1384
+ if (isset($json->error) && $json->error <> '') {
1385
+ return (new WP_Error('api_error', $json->error));
1386
+ } elseif (!isset($json->data)) {
1387
+ return (new WP_Error('api_error', 'no_data'));
1388
+ }
1389
+
1390
+ if (!empty($json->data)) {
1391
+ return $json->data;
1392
+ }
1393
+
1394
+ return false;
1395
+
1396
+ }
1397
+
1398
+ public static function updateAudit($args = array())
1399
+ {
1400
+ self::$apimethod = 'post'; //post call
1401
+
1402
+ $json = json_decode(self::apiCall('api/posts/update-audit', $args));
1403
+
1404
+ if (isset($json->error) && $json->error <> '') {
1405
+ return (new WP_Error('api_error', $json->error));
1406
+ } elseif (!isset($json->data)) {
1407
+ return (new WP_Error('api_error', 'no_data'));
1408
+ }
1409
+
1410
+ if (!empty($json->data)) {
1411
+ return $json->data;
1412
+ }
1413
+
1414
+ return false;
1415
+ }
1416
+
1417
+ /**
1418
+ * Delete the Audit Page
1419
+ *
1420
+ * @param array $args
1421
+ * @return bool|WP_Error
1422
+ */
1423
+ public static function deleteAuditPage($args = array())
1424
+ {
1425
+ self::$apimethod = 'post'; //post call
1426
+
1427
+ if (isset($args['user_post_id']) && $args['user_post_id'] > 0) {
1428
+
1429
+ $json = json_decode(self::apiCall('api/posts/remove-audit/' . $args['user_post_id']));
1430
+
1431
+ if (isset($json->error) && $json->error <> '') {
1432
+ return (new WP_Error('api_error', $json->error));
1433
+ } elseif (!isset($json->data)) {
1434
+ return (new WP_Error('api_error', 'no_data'));
1435
+ }
1436
+
1437
+ if (!empty($json->data)) {
1438
+ return $json->data;
1439
+ }
1440
+
1441
+ }
1442
+ return false;
1443
+ }
1444
+
1445
+ /********************
1446
+ *
1447
+ * OTHERS
1448
+ *****************************/
1449
+ public static function saveSettings($args)
1450
+ {
1451
+ self::$apimethod = 'post'; //call method
1452
+
1453
+ self::apiCall('api/user/settings', array('settings' => wp_json_encode($args)));
1454
+ }
1455
+
1456
+ /**
1457
+ * Get the Facebook APi Code
1458
+ *
1459
+ * @param $args
1460
+ * @return bool|WP_Error
1461
+ */
1462
+ public static function getFacebookApi($args)
1463
+ {
1464
+ self::$apimethod = 'get'; //call method
1465
+
1466
+ $json = json_decode(self::apiCall('api/tools/facebook', $args));
1467
+
1468
+ if (isset($json->error) && $json->error <> '') {
1469
+ return (new WP_Error('api_error', $json->error));
1470
+ } elseif (!isset($json->data)) {
1471
+ return (new WP_Error('api_error', 'no_data'));
1472
+ }
1473
+
1474
+ if (!empty($json->data)) {
1475
+ return $json->data;
1476
+ }
1477
+
1478
+ return false;
1479
+
1480
+ }
1481
+
1482
+ /**
1483
+ * Load the JS for API
1484
+ */
1485
+ public static function loadJsVars()
1486
+ {
1487
+ global $post;
1488
+ $referer = '';
1489
+
1490
+ $metas = json_decode(wp_json_encode(SQ_Classes_Helpers_Tools::getOption('sq_metas')));
1491
+ $sq_postID = (isset($post->ID) ? $post->ID : 0);
1492
+
1493
+ //Load Squirrly Live Assistant for Elementor builder
1494
+ if (SQ_Classes_Helpers_Tools::isPluginInstalled('elementor/elementor.php')) {
1495
+ if (SQ_Classes_Helpers_Tools::getOption('sq_sla_frontend')) {
1496
+ $referer = get_post_meta($sq_postID, '_sq_sla', true);
1497
+ }
1498
+ }
1499
+
1500
+ echo '<script>
1501
+ var SQ_DEBUG = ' . (int)SQ_DEBUG . ';
1502
+ (function($){
1503
+ $.sq_config = {
1504
+ sq_use: ' . (int)SQ_Classes_Helpers_Tools::getOption('sq_use') . ',
1505
+ sq_version: "' . esc_attr(SQ_VERSION) . '",
1506
+ sq_sla_type: "' . esc_attr(SQ_Classes_Helpers_Tools::getOption('sq_sla_type')) . '",
1507
+ token: "' . esc_attr(SQ_Classes_Helpers_Tools::getOption('sq_api')) . '",
1508
+ url_token: "' . (SQ_Classes_Helpers_Tools::getOption('sq_cloud_connect') ? esc_attr(SQ_Classes_Helpers_Tools::getOption('sq_cloud_token')) : false) . '",
1509
+ sq_baseurl: "' . esc_url(_SQ_STATIC_API_URL_) . '",
1510
+ sq_uri: "' . esc_attr(SQ_URI) . '",
1511
+ sq_apiurl: "' . esc_url(_SQ_APIV2_URL_) . '",
1512
+ user_url: "' . esc_url(apply_filters('sq_homeurl', get_bloginfo('url'))) . '",
1513
+ language: "' . esc_attr(apply_filters('sq_language', get_bloginfo('language'))) . '",
1514
+ referer: "' . esc_attr($referer) . '",
1515
+ sq_keywordtag: ' . (int)SQ_Classes_Helpers_Tools::getOption('sq_keywordtag') . ',
1516
+ sq_keyword_help: ' . (int)SQ_Classes_Helpers_Tools::getOption('sq_keyword_help') . ',
1517
+ frontend_css: "' . esc_url(_SQ_ASSETS_URL_ . 'css/frontend' . (SQ_DEBUG ? '' : '.min') . '.css') . '",
1518
+ postID: "' . (int)$sq_postID . '",
1519
+ prevNonce: "' . esc_attr(wp_create_nonce('post_preview_' . $sq_postID)) . '",
1520
+ __keyword: "' . esc_html__('Keyword:', 'squirrly-seo') . '",
1521
+ __date: "' . esc_html__('date', 'squirrly-seo') . '",
1522
+ __noconnection: "' . esc_html__("To load the Live Assistant and optimize this page, click to connect to Squirrly Cloud.", 'squirrly-seo') . '",
1523
+ __saved: "' . esc_html__('Saved!', 'squirrly-seo') . '",
1524
+ __readit: "' . esc_html__('Read it!', 'squirrly-seo') . '",
1525
+ __insertit: "' . esc_html__('Insert it!', 'squirrly-seo') . '",
1526
+ __reference: "' . esc_html__('Reference', 'squirrly-seo') . '",
1527
+ __insertasbox: "' . esc_html__('Insert as box', 'squirrly-seo') . '",
1528
+ __addlink: "' . esc_html__('Insert Link', 'squirrly-seo') . '",
1529
+ __notrelevant: "' . esc_html__('Not relevant?', 'squirrly-seo') . '",
1530
+ __insertparagraph: "' . esc_html__('Insert in your article', 'squirrly-seo') . '",
1531
+ __ajaxerror: "' . esc_html__(':( An error occurred while processing your request. Please try again', 'squirrly-seo') . '",
1532
+ __nofound: "' . esc_html__('No results found!', 'squirrly-seo') . '",
1533
+ __sq_photo_copyright: "' . esc_html__('[ ATTRIBUTE: Please check: %s to find out how to attribute this image ]', 'squirrly-seo') . '",
1534
+ __has_attributes: "' . esc_html__('Has creative commons attributes', 'squirrly-seo') . '",
1535
+ __no_attributes: "' . esc_html__('No known copyright restrictions', 'squirrly-seo') . '",
1536
+ __noopt: "' . esc_html__('You haven`t used Squirrly SEO to optimize your article. Do you want to optimize for a keyword before publishing?', 'squirrly-seo') . '",
1537
+ __subscription_expired: "' . esc_html__('Your Subscription has Expired', 'squirrly-seo') . '",
1538
+ __no_briefcase: "' . esc_html__('There are no keywords saved in briefcase yet', 'squirrly-seo') . '",
1539
+ __fulloptimized: "' . esc_html__('Congratulations! Your article is 100% optimized!', 'squirrly-seo') . '",
1540
+ __toomanytimes: "' . esc_html__('appears too many times. Try to remove %s of them', 'squirrly-seo') . '",
1541
+ __writemorewords: "' . esc_html__('write %s more words', 'squirrly-seo') . '",
1542
+ __keywordinintroduction: "' . esc_html__('Add the keyword in the %s of your article', 'squirrly-seo') . '",
1543
+ __clicktohighlight: "' . esc_html__('Click to keep the highlight on', 'squirrly-seo') . '",
1544
+ __introduction: "' . esc_html__('introduction', 'squirrly-seo') . '",
1545
+ __morewordsafter: "' . esc_html__('Write more words after the %s keyword', 'squirrly-seo') . '",
1546
+ __orusesynonyms: "' . esc_html__('or use synonyms', 'squirrly-seo') . '",
1547
+ __addmorewords: "' . esc_html__('add %s more word(s)', 'squirrly-seo') . '",
1548
+ __removewords: "' . esc_html__('or remove %s word(s)', 'squirrly-seo') . '",
1549
+ __addmorekeywords: "' . esc_html__('add the selected keyword %s more time(s) ', 'squirrly-seo') . '",
1550
+ __addminimumwords: "' . esc_html__('write %s more words to start calculating', 'squirrly-seo') . '",
1551
+ __add_to_briefcase: "' . esc_html__('Add to Briefcase', 'squirrly-seo') . '",
1552
+ __add_keyword_briefcase: "' . esc_html__('Add Keyword to Briefcase', 'squirrly-seo') . '",
1553
+ __usekeyword: "' . esc_html__('Select', 'squirrly-seo') . '",
1554
+ __new_post_title: "' . esc_html__('Auto Draft') . '",
1555
+ __enter_keyword: "' . esc_html__('Enter keyword above and press ENTER', 'squirrly-seo') . '",
1556
+ __add_keyword: "' . esc_html__('Add Keywords from Briefcase', 'squirrly-seo') . '",
1557
+ __frontend_optimized: "' . esc_html__('Live Assistant was used to optimize this page with the Page Builder. Please go back and resume your optimization work there.', 'squirrly-seo') . '",
1558
+ };
1559
+ $.sq_params = {
1560
+ max_length_title: ' . (int)$metas->title_maxlength . ',
1561
+ max_length_description: ' . (int)$metas->description_maxlength . ',
1562
+ };
1563
+
1564
+
1565
+ })(jQuery);
1566
+ </script>';
1567
+
1568
+ echo '<script src="' . esc_url(_SQ_STATIC_API_URL_ . SQ_URI . '/js/squirrly' . (SQ_DEBUG ? '' : '.min') . '.js?ver=' . SQ_VERSION) . '"></script>';
1569
+
1570
+ }
1571
+
1572
+ }
classes/helpers/DevKit.php CHANGED
@@ -1,302 +1,327 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- class SQ_Classes_Helpers_DevKit {
5
-
6
- public static $plugin;
7
- public static $options;
8
- public static $package;
9
-
10
- public function __construct() {
11
-
12
- if(SQ_Classes_Helpers_DevKit::getOption('sq_auto_devkit')) {
13
-
14
- if (SQ_Classes_Helpers_DevKit::getOption('sq_devkit_name') <> '') {
15
- if (isset($_SERVER['REQUEST_URI']) && function_exists('get_plugin_data')) {
16
- if (strpos($_SERVER['REQUEST_URI'], '/plugins.php') !== false) {
17
- $data = get_plugin_data(_SQ_ROOT_DIR_ . 'squirrly.php');
18
- if (isset($data['Name'])) {
19
- self::$plugin['name'] = $data['Name'];
20
- add_filter('pre_kses', array($this, 'changeString'), 1, 1);
21
- }
22
- }
23
- }
24
- }
25
-
26
- //Hook DevKit options
27
- if (SQ_Classes_Helpers_DevKit::getOption('sq_api')) {
28
- add_filter('admin_head', array($this, 'hookHead'));
29
- add_filter('sq_menu', array($this, 'manageMenu'));
30
- add_filter('sq_features', array($this, 'manageFeatures'));
31
- add_filter('sq_logo', array($this, 'getCustomLogo'));
32
- add_filter('sq_name', array($this, 'getCustomName'));
33
- add_filter('sq_menu_name', array($this, 'getCustomMenuName'));
34
- add_filter('sq_audit_success_task', array($this, 'getCustomAuditSuccessTask'));
35
- add_filter('sq_audit_fail_task', array($this, 'getCustomAuditFailTask'));
36
- add_filter('sq_seo_errors', array($this, 'getSEOErrors'));
37
- add_filter('sq_menu_visible', array($this, 'getDevKitMenuVisible'),11, 2);
38
- }
39
- }
40
- }
41
-
42
- /**
43
- * Show the devkit menu from the main website on wp multisite
44
- * @param $value
45
- * @param $key
46
- * @return bool
47
- */
48
- public function getDevKitMenuVisible($value, $key){
49
-
50
- if (isset(self::$options['menu'][$key])) {
51
- return self::$options['menu'][$key];
52
- }
53
-
54
- return true;
55
- }
56
-
57
- //Check if Next SEO Goals are active
58
- public function getSEOErrors($errors) {
59
- if (SQ_Classes_Helpers_Tools::getMenuVisible('show_seogoals')) {
60
- return $errors;
61
- }
62
-
63
- return 0;
64
- }
65
-
66
- public static function getOptions() {
67
- if (is_multisite()) {
68
- self::$options = json_decode(get_blog_option(get_main_site_id(), SQ_OPTION), true);
69
- } else {
70
- self::$options = json_decode(get_option(SQ_OPTION), true);
71
- }
72
-
73
- return self::$options;
74
- }
75
-
76
- /**
77
- * Get the option from database
78
- * @param $key
79
- * @return mixed
80
- */
81
- public static function getOption($key) {
82
- if (!isset(self::$options[$key])) {
83
- self::$options = self::getOptions();
84
-
85
- if (!isset(self::$options[$key])) {
86
- self::$options[$key] = false;
87
- }
88
- }
89
-
90
- return self::$options[$key];
91
- }
92
-
93
- /**
94
- * Customize the Audit task
95
- * @param $task
96
- * @return mixed
97
- */
98
- public function getCustomAuditSuccessTask($task) {
99
-
100
- if (SQ_Classes_Helpers_DevKit::getOption('sq_devkit_audit_success')) {
101
- if ($customTask = SQ_Classes_Helpers_DevKit::getOption('sq_devkit_audit_success')) {
102
- foreach ($customTask as $key => $value) {
103
- if ($value <> '' || $value === false) {
104
- $task->$key = stripslashes($value);
105
- }
106
- }
107
- }
108
- }
109
-
110
- return $task;
111
- }
112
-
113
- /**
114
- * Customize the Audit task
115
- * @param $task
116
- * @return mixed
117
- */
118
- public function getCustomAuditFailTask($task) {
119
-
120
- if (SQ_Classes_Helpers_DevKit::getOption('sq_devkit_audit_fail')) {
121
- if ($customTask = SQ_Classes_Helpers_DevKit::getOption('sq_devkit_audit_fail')) {
122
- foreach ($customTask as $key => $value) {
123
- if ($value <> '' || $value === false) {
124
- $task->$key = stripslashes($value);
125
- }
126
- }
127
- }
128
- }
129
-
130
- return $task;
131
- }
132
-
133
- /**
134
- * Hook the head
135
- */
136
- public function hookHead() {
137
- //Hide the ads
138
- if (!SQ_Classes_Helpers_Tools::getMenuVisible('show_ads')) {
139
- echo '<style>.sq_offer{display: none !important;}</style>';
140
- }
141
-
142
- //Dev Kit images
143
- if (SQ_Classes_Helpers_DevKit::getOption('sq_devkit_logo')) {
144
- echo '<style>.sq_logo{background-image:url("' . SQ_Classes_Helpers_DevKit::getOption('sq_devkit_logo') . '") !important;}#sq_blocksnippet .postbox-header h2:before,li.toplevel_page_sq_dashboard .wp-menu-image:before{background-image:url("' . SQ_Classes_Helpers_DevKit::getOption('sq_devkit_logo') . '") !important;}.components-squirrly-icon img{content:url("' . SQ_Classes_Helpers_DevKit::getOption('sq_devkit_logo') . '") !important;}.menu-top.toplevel_page_sq_dashboard .wp-menu-image:before {content: " ";width: 24px !important;height: 24px !important;display: inline-block;vertical-align: middle !important;line-height: inherit;background-repeat: no-repeat;background-position: center;background-size: 100%;}li.toplevel_page_sq_dashboard .wp-menu-image img{display: none !important;}</style>';
145
- }
146
- }
147
-
148
- /**
149
- * Change the Squirrly SEO logo in DevKit
150
- * @param $logo
151
- * @return mixed
152
- */
153
- public function getCustomLogo($logo) {
154
-
155
- if (SQ_Classes_Helpers_DevKit::getOption('sq_devkit_logo')) {
156
- $logo = SQ_Classes_Helpers_DevKit::getOption('sq_devkit_logo');
157
- }
158
-
159
- return $logo;
160
- }
161
-
162
- /**
163
- * Get Plugin Custom Name
164
- * @param $name
165
- * @return string
166
- */
167
- public function getCustomName($name) {
168
-
169
- if (SQ_Classes_Helpers_DevKit::getOption('sq_devkit_name')) {
170
- $name = SQ_Classes_Helpers_DevKit::getOption('sq_devkit_name');
171
- }
172
-
173
- return $name;
174
- }
175
-
176
- /**
177
- * Get Plugin Custom Menu Name
178
- * @param $name
179
- * @return string
180
- */
181
- public function getCustomMenuName($name) {
182
-
183
- if (SQ_Classes_Helpers_DevKit::getOption('sq_devkit_menu_name')) {
184
- $name = SQ_Classes_Helpers_DevKit::getOption('sq_devkit_menu_name');
185
- }
186
-
187
- return $name;
188
- }
189
-
190
- //Change the features
191
- public function manageFeatures($features) {
192
- if (!SQ_Classes_Helpers_Tools::getMenuVisible('show_panel')) {
193
- unset($features[0]); //remove the Cloud App features
194
- }
195
-
196
- return $features;
197
- }
198
-
199
- /**
200
- * Manage the menu visibility
201
- */
202
- public function manageMenu($menu) {
203
- if (!SQ_Classes_Helpers_Tools::getMenuVisible('show_tutorial')) {
204
- $menu['sq_onboarding']['leftmenu'] = false;
205
- $menu['sq_onboarding']['topmenu'] = false;
206
- }
207
- if (!SQ_Classes_Helpers_Tools::getMenuVisible('show_audit')) {
208
- $menu['sq_audits']['leftmenu'] = false;
209
- $menu['sq_audits']['topmenu'] = false;
210
- }
211
- if (!SQ_Classes_Helpers_Tools::getMenuVisible('show_rankings')) {
212
- $menu['sq_rankings']['leftmenu'] = false;
213
- $menu['sq_rankings']['topmenu'] = false;
214
- }
215
- if (!SQ_Classes_Helpers_Tools::getMenuVisible('show_focuspages')) {
216
- $menu['sq_focuspages']['leftmenu'] = false;
217
- $menu['sq_focuspages']['topmenu'] = false;
218
- }
219
- if (!SQ_Classes_Helpers_Tools::getMenuVisible('show_bulkseo')) {
220
- $menu['sq_bulkseo']['leftmenu'] = false;
221
- $menu['sq_bulkseo']['topmenu'] = false;
222
- }
223
- if (!SQ_Classes_Helpers_Tools::getMenuVisible('show_assistant')) {
224
- $menu['sq_assistant']['leftmenu'] = false;
225
- $menu['sq_assistant']['topmenu'] = false;
226
- }
227
- if (!SQ_Classes_Helpers_Tools::getMenuVisible('show_research')) {
228
- $menu['sq_research']['leftmenu'] = false;
229
- $menu['sq_research']['topmenu'] = false;
230
- }
231
- if (!SQ_Classes_Helpers_Tools::getMenuVisible('show_account_info')) {
232
- $menu['sq_account']['leftmenu'] = false;
233
- $menu['sq_account']['topmenu'] = false;
234
- }
235
-
236
- return $menu;
237
- }
238
-
239
- /**
240
- * Check if Dev Kit is installed
241
- *
242
- * @return bool
243
- */
244
- public function updatePluginData() {
245
-
246
- $wp_filesystem = SQ_Classes_Helpers_Tools::initFilesystem();
247
-
248
- $package_file = _SQ_ROOT_DIR_ . 'package.json';
249
- if (!$wp_filesystem->exists($package_file)) {
250
- return false;
251
- }
252
-
253
- /* load configuration blocks data from core config files */
254
- $config = json_decode($wp_filesystem->get_contents($package_file), 1);
255
- if (isset($config['package'])) {
256
- self::$package = $config['package'];
257
-
258
- if (isset(self::$package['settings']) && !empty(SQ_Classes_Helpers_Tools::$options) && function_exists('array_replace_recursive')) {
259
- SQ_Classes_Helpers_Tools::$options = array_replace_recursive((array)SQ_Classes_Helpers_Tools::$options, (array)self::$package['settings']);
260
-
261
- SQ_Classes_Helpers_Tools::saveOptions();
262
- unlink($package_file);
263
-
264
- if (SQ_Classes_Helpers_Tools::getMenuVisible('show_tutorial')) {
265
- wp_redirect(SQ_Classes_Helpers_Tools::getAdminUrl('sq_onboarding'));
266
- die();
267
- } else {
268
- wp_redirect(SQ_Classes_Helpers_Tools::getAdminUrl('sq_dashboard'));
269
- die();
270
- }
271
- }
272
- }
273
-
274
-
275
- //remove the package after activation
276
- unlink($package_file);
277
-
278
- return true;
279
- }
280
-
281
- /**
282
- * Change the plugin name
283
- * @param $string
284
- * @return mixed
285
- */
286
- public function changeString($string) {
287
- if (isset(self::$plugin['name'])) {
288
- return str_replace(self::$plugin['name'], apply_filters('sq_name', self::$plugin['name']), $string);
289
- }
290
- return $string;
291
- }
292
-
293
- //Get the package info in case of custom details
294
- public function getPackageInfo($key) {
295
- if (isset(self::$package[$key])) {
296
- return self::$package[$key];
297
- }
298
-
299
- return false;
300
- }
301
-
302
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ class SQ_Classes_Helpers_DevKit
5
+ {
6
+
7
+ public static $plugin;
8
+ public static $options;
9
+ public static $package;
10
+
11
+ public function __construct()
12
+ {
13
+
14
+ if(SQ_Classes_Helpers_DevKit::getOption('sq_auto_devkit')) {
15
+
16
+ if (SQ_Classes_Helpers_DevKit::getOption('sq_devkit_name') <> '') {
17
+ if (isset($_SERVER['REQUEST_URI']) && function_exists('get_plugin_data')) {
18
+ if (strpos($_SERVER['REQUEST_URI'], '/plugins.php') !== false) {
19
+ $data = get_plugin_data(_SQ_ROOT_DIR_ . 'squirrly.php');
20
+ if (isset($data['Name'])) {
21
+ self::$plugin['name'] = $data['Name'];
22
+ add_filter('pre_kses', array($this, 'changeString'), 1, 1);
23
+ }
24
+ }
25
+ }
26
+ }
27
+
28
+ //Hook DevKit options
29
+ if (SQ_Classes_Helpers_DevKit::getOption('sq_api')) {
30
+ add_filter('admin_head', array($this, 'hookHead'));
31
+ add_filter('sq_menu', array($this, 'manageMenu'));
32
+ add_filter('sq_features', array($this, 'manageFeatures'));
33
+ add_filter('sq_logo', array($this, 'getCustomLogo'));
34
+ add_filter('sq_name', array($this, 'getCustomName'));
35
+ add_filter('sq_menu_name', array($this, 'getCustomMenuName'));
36
+ add_filter('sq_audit_success_task', array($this, 'getCustomAuditSuccessTask'));
37
+ add_filter('sq_audit_fail_task', array($this, 'getCustomAuditFailTask'));
38
+ add_filter('sq_seo_errors', array($this, 'getSEOErrors'));
39
+ add_filter('sq_menu_visible', array($this, 'getDevKitMenuVisible'), 11, 2);
40
+ }
41
+ }
42
+ }
43
+
44
+ /**
45
+ * Show the devkit menu from the main website on wp multisite
46
+ *
47
+ * @param $value
48
+ * @param $key
49
+ * @return bool
50
+ */
51
+ public function getDevKitMenuVisible($value, $key)
52
+ {
53
+
54
+ if (isset(self::$options['menu'][$key])) {
55
+ return self::$options['menu'][$key];
56
+ }
57
+
58
+ return true;
59
+ }
60
+
61
+ //Check if Next SEO Goals are active
62
+ public function getSEOErrors($errors)
63
+ {
64
+ if (SQ_Classes_Helpers_Tools::getMenuVisible('show_seogoals')) {
65
+ return $errors;
66
+ }
67
+
68
+ return 0;
69
+ }
70
+
71
+ public static function getOptions()
72
+ {
73
+ if (is_multisite()) {
74
+ self::$options = json_decode(get_blog_option(get_main_site_id(), SQ_OPTION), true);
75
+ } else {
76
+ self::$options = json_decode(get_option(SQ_OPTION), true);
77
+ }
78
+
79
+ return self::$options;
80
+ }
81
+
82
+ /**
83
+ * Get the option from database
84
+ *
85
+ * @param $key
86
+ * @return mixed
87
+ */
88
+ public static function getOption($key)
89
+ {
90
+ if (!isset(self::$options[$key])) {
91
+ self::$options = self::getOptions();
92
+
93
+ if (!isset(self::$options[$key])) {
94
+ self::$options[$key] = false;
95
+ }
96
+ }
97
+
98
+ return self::$options[$key];
99
+ }
100
+
101
+ /**
102
+ * Customize the Audit task
103
+ *
104
+ * @param $task
105
+ * @return mixed
106
+ */
107
+ public function getCustomAuditSuccessTask($task)
108
+ {
109
+
110
+ if (SQ_Classes_Helpers_DevKit::getOption('sq_devkit_audit_success')) {
111
+ if ($customTask = SQ_Classes_Helpers_DevKit::getOption('sq_devkit_audit_success')) {
112
+ foreach ($customTask as $key => $value) {
113
+ if ($value <> '' || $value === false) {
114
+ $task->$key = stripslashes($value);
115
+ }
116
+ }
117
+ }
118
+ }
119
+
120
+ return $task;
121
+ }
122
+
123
+ /**
124
+ * Customize the Audit task
125
+ *
126
+ * @param $task
127
+ * @return mixed
128
+ */
129
+ public function getCustomAuditFailTask($task)
130
+ {
131
+
132
+ if (SQ_Classes_Helpers_DevKit::getOption('sq_devkit_audit_fail')) {
133
+ if ($customTask = SQ_Classes_Helpers_DevKit::getOption('sq_devkit_audit_fail')) {
134
+ foreach ($customTask as $key => $value) {
135
+ if ($value <> '' || $value === false) {
136
+ $task->$key = stripslashes($value);
137
+ }
138
+ }
139
+ }
140
+ }
141
+
142
+ return $task;
143
+ }
144
+
145
+ /**
146
+ * Hook the head
147
+ */
148
+ public function hookHead()
149
+ {
150
+ //Hide the ads
151
+ if (!SQ_Classes_Helpers_Tools::getMenuVisible('show_ads')) {
152
+ echo '<style>.sq_offer{display: none !important;}</style>';
153
+ }
154
+
155
+ //Dev Kit images
156
+ if (SQ_Classes_Helpers_DevKit::getOption('sq_devkit_logo')) {
157
+ echo '<style>.sq_logo{background-image:url("' . SQ_Classes_Helpers_DevKit::getOption('sq_devkit_logo') . '") !important;}#sq_blocksnippet .postbox-header h2:before,li.toplevel_page_sq_dashboard .wp-menu-image:before{background-image:url("' . SQ_Classes_Helpers_DevKit::getOption('sq_devkit_logo') . '") !important;}.components-squirrly-icon img{content:url("' . SQ_Classes_Helpers_DevKit::getOption('sq_devkit_logo') . '") !important;}.menu-top.toplevel_page_sq_dashboard .wp-menu-image:before {content: " ";width: 24px !important;height: 24px !important;display: inline-block;vertical-align: middle !important;line-height: inherit;background-repeat: no-repeat;background-position: center;background-size: 100%;}li.toplevel_page_sq_dashboard .wp-menu-image img{display: none !important;}</style>';
158
+ }
159
+ }
160
+
161
+ /**
162
+ * Change the Squirrly SEO logo in DevKit
163
+ *
164
+ * @param $logo
165
+ * @return mixed
166
+ */
167
+ public function getCustomLogo($logo)
168
+ {
169
+
170
+ if (SQ_Classes_Helpers_DevKit::getOption('sq_devkit_logo')) {
171
+ $logo = SQ_Classes_Helpers_DevKit::getOption('sq_devkit_logo');
172
+ }
173
+
174
+ return $logo;
175
+ }
176
+
177
+ /**
178
+ * Get Plugin Custom Name
179
+ *
180
+ * @param $name
181
+ * @return string
182
+ */
183
+ public function getCustomName($name)
184
+ {
185
+
186
+ if (SQ_Classes_Helpers_DevKit::getOption('sq_devkit_name')) {
187
+ $name = SQ_Classes_Helpers_DevKit::getOption('sq_devkit_name');
188
+ }
189
+
190
+ return $name;
191
+ }
192
+
193
+ /**
194
+ * Get Plugin Custom Menu Name
195
+ *
196
+ * @param $name
197
+ * @return string
198
+ */
199
+ public function getCustomMenuName($name)
200
+ {
201
+
202
+ if (SQ_Classes_Helpers_DevKit::getOption('sq_devkit_menu_name')) {
203
+ $name = SQ_Classes_Helpers_DevKit::getOption('sq_devkit_menu_name');
204
+ }
205
+
206
+ return $name;
207
+ }
208
+
209
+ //Change the features
210
+ public function manageFeatures($features)
211
+ {
212
+ if (!SQ_Classes_Helpers_Tools::getMenuVisible('show_panel')) {
213
+ unset($features[0]); //remove the Cloud App features
214
+ }
215
+
216
+ return $features;
217
+ }
218
+
219
+ /**
220
+ * Manage the menu visibility
221
+ */
222
+ public function manageMenu($menu)
223
+ {
224
+ if (!SQ_Classes_Helpers_Tools::getMenuVisible('show_tutorial')) {
225
+ $menu['sq_onboarding']['leftmenu'] = false;
226
+ $menu['sq_onboarding']['topmenu'] = false;
227
+ }
228
+ if (!SQ_Classes_Helpers_Tools::getMenuVisible('show_audit')) {
229
+ $menu['sq_audits']['leftmenu'] = false;
230
+ $menu['sq_audits']['topmenu'] = false;
231
+ }
232
+ if (!SQ_Classes_Helpers_Tools::getMenuVisible('show_rankings')) {
233
+ $menu['sq_rankings']['leftmenu'] = false;
234
+ $menu['sq_rankings']['topmenu'] = false;
235
+ }
236
+ if (!SQ_Classes_Helpers_Tools::getMenuVisible('show_focuspages')) {
237
+ $menu['sq_focuspages']['leftmenu'] = false;
238
+ $menu['sq_focuspages']['topmenu'] = false;
239
+ }
240
+ if (!SQ_Classes_Helpers_Tools::getMenuVisible('show_bulkseo')) {
241
+ $menu['sq_bulkseo']['leftmenu'] = false;
242
+ $menu['sq_bulkseo']['topmenu'] = false;
243
+ }
244
+ if (!SQ_Classes_Helpers_Tools::getMenuVisible('show_assistant')) {
245
+ $menu['sq_assistant']['leftmenu'] = false;
246
+ $menu['sq_assistant']['topmenu'] = false;
247
+ }
248
+ if (!SQ_Classes_Helpers_Tools::getMenuVisible('show_research')) {
249
+ $menu['sq_research']['leftmenu'] = false;
250
+ $menu['sq_research']['topmenu'] = false;
251
+ }
252
+ if (!SQ_Classes_Helpers_Tools::getMenuVisible('show_account_info')) {
253
+ $menu['sq_account']['leftmenu'] = false;
254
+ $menu['sq_account']['topmenu'] = false;
255
+ }
256
+
257
+ return $menu;
258
+ }
259
+
260
+ /**
261
+ * Check if Dev Kit is installed
262
+ *
263
+ * @return bool
264
+ */
265
+ public function updatePluginData()
266
+ {
267
+
268
+ $wp_filesystem = SQ_Classes_Helpers_Tools::initFilesystem();
269
+
270
+ $package_file = _SQ_ROOT_DIR_ . 'package.json';
271
+ if (!$wp_filesystem->exists($package_file)) {
272
+ return false;
273
+ }
274
+
275
+ /* load configuration blocks data from core config files */
276
+ $config = json_decode($wp_filesystem->get_contents($package_file), 1);
277
+ if (isset($config['package'])) {
278
+ self::$package = $config['package'];
279
+
280
+ if (isset(self::$package['settings']) && !empty(SQ_Classes_Helpers_Tools::$options) && function_exists('array_replace_recursive')) {
281
+ SQ_Classes_Helpers_Tools::$options = array_replace_recursive((array)SQ_Classes_Helpers_Tools::$options, (array)self::$package['settings']);
282
+
283
+ SQ_Classes_Helpers_Tools::saveOptions();
284
+ unlink($package_file);
285
+
286
+ if (SQ_Classes_Helpers_Tools::getMenuVisible('show_tutorial')) {
287
+ wp_redirect(SQ_Classes_Helpers_Tools::getAdminUrl('sq_onboarding'));
288
+ die();
289
+ } else {
290
+ wp_redirect(SQ_Classes_Helpers_Tools::getAdminUrl('sq_dashboard'));
291
+ die();
292
+ }
293
+ }
294
+ }
295
+
296
+
297
+ //remove the package after activation
298
+ unlink($package_file);
299
+
300
+ return true;
301
+ }
302
+
303
+ /**
304
+ * Change the plugin name
305
+ *
306
+ * @param $string
307
+ * @return mixed
308
+ */
309
+ public function changeString($string)
310
+ {
311
+ if (isset(self::$plugin['name'])) {
312
+ return str_replace(self::$plugin['name'], apply_filters('sq_name', self::$plugin['name']), $string);
313
+ }
314
+ return $string;
315
+ }
316
+
317
+ //Get the package info in case of custom details
318
+ public function getPackageInfo($key)
319
+ {
320
+ if (isset(self::$package[$key])) {
321
+ return self::$package[$key];
322
+ }
323
+
324
+ return false;
325
+ }
326
+
327
+ }
classes/helpers/Sanitize.php CHANGED
@@ -1,553 +1,605 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- class SQ_Classes_Helpers_Sanitize {
5
- /**
6
- * Clear the title string
7
- * @param $title
8
- * @return mixed|null|string|string[]
9
- */
10
- public static function clearTitle($title) {
11
- if ($title <> '') {
12
- if (function_exists('preg_replace')) {
13
- $search = array(
14
- "/[\n\r]/si",
15
- "/[\n]/si",
16
- "/&nbsp;/si",
17
- "/\[[^\]]+\]/si",
18
- "/\s{2,}/",
19
- );
20
- $title = preg_replace($search, " ", $title);
21
- }
22
-
23
- $title = SQ_Classes_Helpers_Sanitize::i18n(trim(esc_html(ent2ncr(strip_tags($title)))));
24
-
25
- }
26
- return $title;
27
- }
28
-
29
- /**
30
- * Clear description
31
- * @param $description
32
- * @return null|string|string[]
33
- */
34
- public static function clearDescription($description) {
35
- if ($description <> '') {
36
- if (function_exists('preg_replace')) {
37
- $search = array("'<script[^>]*?>.*?<\/script>'si", // strip out javascript
38
- "/<form.*?<\/form>/si",
39
- "/<iframe.*?<\/iframe>/si",
40
- );
41
- $description = preg_replace($search, "", $description);
42
- $search = array(
43
- "/[\n\r]/si",
44
- "/[\n]/si",
45
- "/&nbsp;/si",
46
- "/\[[^\]]+\]/si",
47
- "/\s{2,}/",
48
- );
49
- $description = preg_replace($search, " ", $description);
50
- }
51
-
52
- $description = SQ_Classes_Helpers_Sanitize::i18n(trim(esc_html(ent2ncr(strip_tags($description)))));
53
- }
54
-
55
- return $description;
56
- }
57
-
58
- /**
59
- * Clear the keywords
60
- * @param $keywords
61
- * @return mixed|null|string|string[]
62
- */
63
- public static function clearKeywords($keywords) {
64
- return self::clearTitle($keywords);
65
- }
66
-
67
- /**
68
- * Escape the keyword for tags and urls
69
- * @param $keyword
70
- * @param string $for
71
- * @return string|void
72
- */
73
- public static function escapeKeyword($keyword, $for = 'all') {
74
- switch ($for){
75
- case 'url':
76
- $keyword = urlencode(esc_attr($keyword));
77
- break;
78
- case 'attr':
79
- $keyword = htmlspecialchars(str_replace('"', '\"', $keyword));
80
- break;
81
- default:
82
- $keyword = esc_attr($keyword);
83
- }
84
- return $keyword;
85
- }
86
-
87
- /**
88
- * Truncate the text
89
- *
90
- * @param $text
91
- * @param int $min
92
- * @param int $max
93
- * @return bool|mixed|null|string|string[]
94
- */
95
- public static function truncate($text, $min = 100, $max = 110) {
96
- //make sure they are values
97
- $max = (int)$max;
98
- $min = (int)$min;
99
-
100
- if ($max > 0 && $text <> '' && strlen($text) > $max) {
101
- if (function_exists('strip_tags')) {
102
- $text = strip_tags($text);
103
- }
104
-
105
- $text = str_replace(']]>', ']]&gt;', $text);
106
- $text = preg_replace('/\[(.+?)\]/is', '', $text);
107
-
108
- if ($max < strlen($text)) {
109
- while ($text[$max] != ' ' && $max > $min) {
110
- $max--;
111
- }
112
- }
113
-
114
- //Use internation truncate
115
- if (function_exists('mb_substr')) {
116
- $text = mb_substr($text, 0, $max);
117
- } else {
118
- $text = substr($text, 0, $max);
119
- }
120
-
121
- return trim(stripcslashes($text));
122
- }
123
-
124
- return $text;
125
- }
126
-
127
- /**
128
- * Replace language-specific characters by ASCII-equivalents.
129
- * @param string $s
130
- * @return string
131
- */
132
- public static function normalizeChars($s) {
133
- $replace = array(
134
- 'ъ'=>'-', 'Ь'=>'-', 'Ъ'=>'-', 'ь'=>'-',
135
- 'Ă'=>'A', 'Ą'=>'A', 'À'=>'A', 'Ã'=>'A', 'Á'=>'A', 'Æ'=>'A', 'Â'=>'A', 'Å'=>'A', 'Ä'=>'Ae',
136
- 'Þ'=>'B',
137
- 'Ć'=>'C', 'ץ'=>'C', 'Ç'=>'C',
138
- 'È'=>'E', 'Ę'=>'E', 'É'=>'E', 'Ë'=>'E', 'Ê'=>'E',
139
- 'Ğ'=>'G',
140
- 'İ'=>'I', 'Ï'=>'I', 'Î'=>'I', 'Í'=>'I', 'Ì'=>'I',
141
- 'Ł'=>'L',
142
- 'Ñ'=>'N', 'Ń'=>'N',
143
- 'Ø'=>'O', 'Ó'=>'O', 'Ò'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'Oe',
144
- 'Ş'=>'S', 'Ś'=>'S', 'Ș'=>'S', 'Š'=>'S',
145
- 'Ț'=>'T',
146
- 'Ù'=>'U', 'Û'=>'U', 'Ú'=>'U', 'Ü'=>'Ue',
147
- 'Ý'=>'Y',
148
- 'Ź'=>'Z', 'Ž'=>'Z', 'Ż'=>'Z',
149
- 'â'=>'a', 'ǎ'=>'a', 'ą'=>'a', 'á'=>'a', 'ă'=>'a', 'ã'=>'a', 'Ǎ'=>'a', 'а'=>'a', 'А'=>'a', 'å'=>'a', 'à'=>'a', 'א'=>'a', 'Ǻ'=>'a', 'Ā'=>'a', 'ǻ'=>'a', 'ā'=>'a', 'ä'=>'ae', 'æ'=>'ae', 'Ǽ'=>'ae', 'ǽ'=>'ae',
150
- 'б'=>'b', 'ב'=>'b', 'Б'=>'b', 'þ'=>'b',
151
- 'ĉ'=>'c', 'Ĉ'=>'c', 'Ċ'=>'c', 'ć'=>'c', 'ç'=>'c', 'ц'=>'c', 'צ'=>'c', 'ċ'=>'c', 'Ц'=>'c', 'Č'=>'c', 'č'=>'c', 'Ч'=>'ch', 'ч'=>'ch',
152
- 'ד'=>'d', 'ď'=>'d', 'Đ'=>'d', 'Ď'=>'d', 'đ'=>'d', 'д'=>'d', 'Д'=>'D', 'ð'=>'d',
153
- 'є'=>'e', 'ע'=>'e', 'е'=>'e', 'Е'=>'e', 'Ə'=>'e', 'ę'=>'e', 'ĕ'=>'e', 'ē'=>'e', 'Ē'=>'e', 'Ė'=>'e', 'ė'=>'e', 'ě'=>'e', 'Ě'=>'e', 'Є'=>'e', 'Ĕ'=>'e', 'ê'=>'e', 'ə'=>'e', 'è'=>'e', 'ë'=>'e', 'é'=>'e',
154
- 'ф'=>'f', 'ƒ'=>'f', 'Ф'=>'f',
155
- 'ġ'=>'g', 'Ģ'=>'g', 'Ġ'=>'g', 'Ĝ'=>'g', 'Г'=>'g', 'г'=>'g', 'ĝ'=>'g', 'ğ'=>'g', 'ג'=>'g', 'Ґ'=>'g', 'ґ'=>'g', 'ģ'=>'g',
156
- 'ח'=>'h', 'ħ'=>'h', 'Х'=>'h', 'Ħ'=>'h', 'Ĥ'=>'h', 'ĥ'=>'h', 'х'=>'h', 'ה'=>'h',
157
- 'î'=>'i', 'ï'=>'i', 'í'=>'i', 'ì'=>'i', 'į'=>'i', 'ĭ'=>'i', 'ı'=>'i', 'Ĭ'=>'i', 'И'=>'i', 'ĩ'=>'i', 'ǐ'=>'i', 'Ĩ'=>'i', 'Ǐ'=>'i', 'и'=>'i', 'Į'=>'i', 'י'=>'i', 'Ї'=>'i', 'Ī'=>'i', 'І'=>'i', 'ї'=>'i', 'і'=>'i', 'ī'=>'i', 'ij'=>'ij', 'IJ'=>'ij',
158
- 'й'=>'j', 'Й'=>'j', 'Ĵ'=>'j', 'ĵ'=>'j', 'я'=>'ja', 'Я'=>'ja', 'Э'=>'je', 'э'=>'je', 'ё'=>'jo', 'Ё'=>'jo', 'ю'=>'ju', 'Ю'=>'ju',
159
- 'ĸ'=>'k', 'כ'=>'k', 'Ķ'=>'k', 'К'=>'k', 'к'=>'k', 'ķ'=>'k', 'ך'=>'k',
160
- 'Ŀ'=>'l', 'ŀ'=>'l', 'Л'=>'l', 'ł'=>'l', 'ļ'=>'l', 'ĺ'=>'l', 'Ĺ'=>'l', 'Ļ'=>'l', 'л'=>'l', 'Ľ'=>'l', 'ľ'=>'l', 'ל'=>'l',
161
- 'מ'=>'m', 'М'=>'m', 'ם'=>'m', 'м'=>'m',
162
- 'ñ'=>'n', 'н'=>'n', 'Ņ'=>'n', 'ן'=>'n', 'ŋ'=>'n', 'נ'=>'n', 'Н'=>'n', 'ń'=>'n', 'Ŋ'=>'n', 'ņ'=>'n', 'ʼn'=>'n', 'Ň'=>'n', 'ň'=>'n',
163
- 'о'=>'o', 'О'=>'o', 'ő'=>'o', 'õ'=>'o', 'ô'=>'o', 'Ő'=>'o', 'ŏ'=>'o', 'Ŏ'=>'o', 'Ō'=>'o', 'ō'=>'o', 'ø'=>'o', 'ǿ'=>'o', 'ǒ'=>'o', 'ò'=>'o', 'Ǿ'=>'o', 'Ǒ'=>'o', 'ơ'=>'o', 'ó'=>'o', 'Ơ'=>'o', 'œ'=>'oe', 'Œ'=>'oe', 'ö'=>'oe',
164
- 'פ'=>'p', 'ף'=>'p', 'п'=>'p', 'П'=>'p',
165
- 'ק'=>'q',
166
- 'ŕ'=>'r', 'ř'=>'r', 'Ř'=>'r', 'ŗ'=>'r', 'Ŗ'=>'r', 'ר'=>'r', 'Ŕ'=>'r', 'Р'=>'r', 'р'=>'r',
167
- 'ș'=>'s', 'с'=>'s', 'Ŝ'=>'s', 'š'=>'s', 'ś'=>'s', 'ס'=>'s', 'ş'=>'s', 'С'=>'s', 'ŝ'=>'s', 'Щ'=>'sch', 'щ'=>'sch', 'ш'=>'sh', 'Ш'=>'sh', 'ß'=>'ss',
168
- 'т'=>'t', 'ט'=>'t', 'ŧ'=>'t', 'ת'=>'t', 'ť'=>'t', 'ţ'=>'t', 'Ţ'=>'t', 'Т'=>'t', 'ț'=>'t', 'Ŧ'=>'t', 'Ť'=>'t', '™'=>'tm',
169
- 'ū'=>'u', 'у'=>'u', 'Ũ'=>'u', 'ũ'=>'u', 'Ư'=>'u', 'ư'=>'u', 'Ū'=>'u', 'Ǔ'=>'u', 'ų'=>'u', 'Ų'=>'u', 'ŭ'=>'u', 'Ŭ'=>'u', 'Ů'=>'u', 'ů'=>'u', 'ű'=>'u', 'Ű'=>'u', 'Ǖ'=>'u', 'ǔ'=>'u', 'Ǜ'=>'u', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'У'=>'u', 'ǚ'=>'u', 'ǜ'=>'u', 'Ǚ'=>'u', 'Ǘ'=>'u', 'ǖ'=>'u', 'ǘ'=>'u', 'ü'=>'ue',
170
- 'в'=>'v', 'ו'=>'v', 'В'=>'v',
171
- 'ש'=>'w', 'ŵ'=>'w', 'Ŵ'=>'w',
172
- 'ы'=>'y', 'ŷ'=>'y', 'ý'=>'y', 'ÿ'=>'y', 'Ÿ'=>'y', 'Ŷ'=>'y',
173
- 'Ы'=>'y', 'ž'=>'z', 'З'=>'z', 'з'=>'z', 'ź'=>'z', 'ז'=>'z', 'ż'=>'z', 'ſ'=>'z', 'Ж'=>'zh', 'ж'=>'zh'
174
- );
175
- return strtr($s, $replace);
176
- }
177
-
178
- /**
179
- * Check the google code saved at settings
180
- *
181
- * @param string $code
182
- * @return string
183
- */
184
- public static function checkGoogleWTCode($code) {
185
- if ($code <> '') {
186
- $code = stripslashes($code);
187
- if (strpos($code, 'content') !== false) {
188
- preg_match('/content\\s*=\\s*[\"]([^\"]+)[\"]/i', $code, $result);
189
- if (isset($result[1]) && !empty($result[1])) $code = $result[1];
190
- }
191
- if (strpos($code, '"') !== false) {
192
- preg_match('/[\"]([^\"]+)[\"]/i', $code, $result);
193
- if (isset($result[1]) && !empty($result[1])) $code = $result[1];
194
- }
195
-
196
- if ($code == '') SQ_Classes_Error::setError(esc_html__("The code for Google Webmaster Tool is incorrect.", _SQ_PLUGIN_NAME_));
197
- }
198
- return $code;
199
- }
200
-
201
- /**
202
- * Check the google code saved at settings
203
- *
204
- * @param string $code
205
- * @return string
206
- */
207
- public static function checkGoogleAnalyticsCode($code) {
208
- if ($code <> '') {
209
- $code = stripslashes($code);
210
-
211
- if (strpos($code, 'GoogleAnalyticsObject') !== false) {
212
- preg_match('/ga\(\'create\',[^\'"]*[\'"]([^\'"]+)[\'"],/i', $code, $result);
213
- if (isset($result[1]) && !empty($result[1])) $code = $result[1];
214
- }
215
-
216
- if (strpos($code, '"') !== false) {
217
- preg_match('/[\"]([^\"]+)[\"]/i', $code, $result);
218
- if (isset($result[1]) && !empty($result[1])) $code = $result[1];
219
- }
220
-
221
- if (strpos($code, 'UA-') === false && strpos($code, 'G-') === false) {
222
- $code = '';
223
- SQ_Classes_Error::setError(esc_html__("The code for Google Analytics is incorrect.", _SQ_PLUGIN_NAME_));
224
- }
225
- }
226
- return trim($code);
227
- }
228
-
229
- /**
230
- * Check the Facebook code saved at settings
231
- *
232
- * @param string $code
233
- * @return string
234
- */
235
- public static function checkFacebookAdminCode($code) {
236
- if ($code <> '') {
237
- $code = trim($code);
238
-
239
- if (strpos($code, 'facebook.com/') !== false) {
240
- preg_match('/facebook.com\/([^\/]+)/i', $code, $result);
241
- if (isset($result[1]) && !empty($result[1])) {
242
- if (is_string($result[1])) {
243
- $response = SQ_Classes_RemoteController::getFacebookApi(array('profile' => $result[1]));
244
- if (!is_wp_error($response) && isset($response->code)) {
245
- return $response->code;
246
- }
247
- } elseif (is_numeric($result[1])) {
248
- return $result[1];
249
- }
250
- }
251
- } elseif ($code <> (int)$code) {
252
- $response = SQ_Classes_RemoteController::getFacebookApi(array('profile' => $code));
253
- if (!is_wp_error($response) && isset($response->code)) {
254
- return $response->code;
255
- }
256
- } else {
257
- return $code;
258
- }
259
-
260
- SQ_Classes_Error::setError(esc_html__("The code for Facebook is incorrect.", _SQ_PLUGIN_NAME_));
261
-
262
- }
263
- return false;
264
- }
265
-
266
- /**
267
- * Check the Pinterest code saved at settings
268
- *
269
- * @param string $code
270
- * @return string
271
- */
272
- public static function checkPinterestCode($code) {
273
- if ($code <> '') {
274
- $code = stripslashes($code);
275
-
276
- if (strpos($code, 'content') !== false) {
277
- preg_match('/content\\s*=\\s*[\"]([^\"]+)[\"]/i', $code, $result);
278
- if (isset($result[1]) && !empty($result[1])) $code = $result[1];
279
- }
280
-
281
- if (strpos($code, '"') !== false) {
282
- preg_match('/[\"]([^\"]+)[\"]/i', $code, $result);
283
- if (isset($result[1]) && !empty($result[1])) $code = $result[1];
284
- }
285
-
286
- if ($code == '') SQ_Classes_Error::setError(esc_html__("The code for Pinterest is incorrect.", _SQ_PLUGIN_NAME_));
287
- }
288
- return $code;
289
- }
290
-
291
- /**
292
- * Check the Bing code saved at settings
293
- *
294
- * @return string
295
- */
296
- public static function checkBingWTCode($code) {
297
- if ($code <> '') {
298
- $code = stripslashes($code);
299
-
300
-
301
- if (strpos($code, 'content') !== false) {
302
- preg_match('/content\\s*=\\s*[\"]([^\"]+)[\"]/i', $code, $result);
303
- if (isset($result[1]) && !empty($result[1])) $code = $result[1];
304
- }
305
-
306
- if (strpos($code, '"') !== false) {
307
- preg_match('/[\"]([^\"]+)[\"]/i', $code, $result);
308
- if (isset($result[1]) && !empty($result[1])) $code = $result[1];
309
- }
310
-
311
- if ($code == '') SQ_Classes_Error::setError(esc_html__("The code for Bing is incorrect.", _SQ_PLUGIN_NAME_));
312
- }
313
- return $code;
314
- }
315
-
316
- /**
317
- * Check the Baidu code saved at settings
318
- *
319
- * @return string
320
- */
321
- public static function checkBaiduWTCode($code) {
322
- if ($code <> '') {
323
- $code = stripslashes($code);
324
-
325
-
326
- if (strpos($code, 'content') !== false) {
327
- preg_match('/content\\s*=\\s*[\"]([^\"]+)[\"]/i', $code, $result);
328
- if (isset($result[1]) && !empty($result[1])) $code = $result[1];
329
- }
330
-
331
- if (strpos($code, '"') !== false) {
332
- preg_match('/[\"]([^\"]+)[\"]/i', $code, $result);
333
- if (isset($result[1]) && !empty($result[1])) $code = $result[1];
334
- }
335
-
336
- if ($code == '') SQ_Classes_Error::setError(esc_html__("The code for Baidu is incorrect.", _SQ_PLUGIN_NAME_));
337
- }
338
- return $code;
339
- }
340
-
341
- /**
342
- * Check the Yandex code saved at settings
343
- *
344
- * @return string
345
- */
346
- public static function checkYandexWTCode($code) {
347
- if ($code <> '') {
348
- $code = stripslashes($code);
349
-
350
-
351
- if (strpos($code, 'content') !== false) {
352
- preg_match('/content\\s*=\\s*[\"]([^\"]+)[\"]/i', $code, $result);
353
- if (isset($result[1]) && !empty($result[1])) $code = $result[1];
354
- }
355
-
356
- if (strpos($code, '"') !== false) {
357
- preg_match('/[\"]([^\"]+)[\"]/i', $code, $result);
358
- if (isset($result[1]) && !empty($result[1])) $code = $result[1];
359
- }
360
-
361
- if ($code == '') SQ_Classes_Error::setError(esc_html__("The code for Yandex is incorrect.", _SQ_PLUGIN_NAME_));
362
- }
363
- return $code;
364
- }
365
-
366
- /**
367
- * Check the Alexa code saved at settings
368
- *
369
- * @return string
370
- */
371
- public static function checkAlexaCode($code) {
372
- if ($code <> '') {
373
- $code = stripslashes($code);
374
-
375
-
376
- if (strpos($code, 'content') !== false) {
377
- preg_match('/content\\s*=\\s*[\"]([^\"]+)[\"]/i', $code, $result);
378
- if (isset($result[1]) && !empty($result[1])) $code = $result[1];
379
- }
380
-
381
- if (strpos($code, '"') !== false) {
382
- preg_match('/[\"]([^\"]+)[\"]/i', $code, $result);
383
- if (isset($result[1]) && !empty($result[1])) $code = $result[1];
384
- }
385
-
386
- if ($code == '') SQ_Classes_Error::setError(esc_html__("The code for Alexa is incorrect.", _SQ_PLUGIN_NAME_));
387
- }
388
- return $code;
389
- }
390
-
391
- /**
392
- * Check the twitter account
393
- *
394
- * @param string $account
395
- * @return string
396
- */
397
- public static function checkTwitterAccount($account) {
398
- if ($account <> '' && strpos($account, '//') === false) {
399
- $account = 'https://twitter.com/' . $account;
400
- }
401
-
402
- return $account;
403
- }
404
-
405
- /**
406
- * Check the twitter account
407
- *
408
- * @param string $account
409
- * @return string
410
- */
411
- public static function checkTwitterAccountName($account) {
412
- if ($account <> '' && strpos($account, '//') !== false) {
413
- $account = parse_url($account, PHP_URL_PATH);
414
- if ($account <> '') {
415
- $account = str_replace('/', '', $account);
416
- }
417
- if (strpos($account, '@') == false) {
418
- $account = '@' . $account;
419
- }
420
- }
421
-
422
- return $account;
423
- }
424
-
425
- /**
426
- * Check the google + account
427
- *
428
- * @param string $account
429
- * @return string
430
- */
431
- public static function checkGoogleAccount($account) {
432
- if ($account <> '' && strpos($account, '//') === false) {
433
- $account = 'https://plus.google.com/' . $account;
434
- }
435
- return str_replace(" ", "+", $account);
436
- }
437
-
438
- /**
439
- * Check the google + account
440
- *
441
- * @param string $account
442
- * @return string
443
- */
444
- public static function checkLinkeinAccount($account) {
445
- if ($account <> '' && strpos($account, '//') === false) {
446
- $account = 'https://www.linkedin.com/in/' . $account;
447
- }
448
- return $account;
449
- }
450
-
451
- /**
452
- * Check the facebook account
453
- *
454
- * @param string $account
455
- * @return string
456
- */
457
- public static function checkFacebookAccount($account) {
458
- if ($account <> '' && strpos($account, '//') === false) {
459
- $account = 'https://www.facebook.com/' . $account;
460
- }
461
- return $account;
462
- }
463
-
464
- /**
465
- * Check the Pinterest account
466
- * @param $account
467
- * @return string
468
- */
469
- public static function checkPinterestAccount($account) {
470
- if ($account <> '' && strpos($account, '//') === false) {
471
- $account = 'https://www.pinterest.com/' . $account;
472
- }
473
- return $account;
474
- }
475
-
476
- /**
477
- * Check the Instagram
478
- *
479
- * @param $account
480
- * @return string
481
- */
482
- public static function checkInstagramAccount($account) {
483
- if ($account <> '' && strpos($account, '//') === false) {
484
- $account = 'https://www.instagram.com/' . $account;
485
- }
486
- return $account;
487
- }
488
-
489
- /**
490
- * Check the Youtube account
491
- *
492
- * @param $account
493
- * @return string
494
- */
495
- public static function checkYoutubeAccount($account) {
496
- if ($account <> '' && strpos($account, '//') === false) {
497
- if (strpos($account, 'user/') === false && strpos($account, 'channel/') === false) {
498
- $account = 'https://www.youtube.com/channel/' . $account;
499
- }
500
- }
501
- return $account;
502
- }
503
-
504
- /**
505
- * Check the Facebook Pixel code
506
- *
507
- * @return string
508
- */
509
- public static function checkFacebookPixel($code) {
510
- if ($code <> '') {
511
- if ((int)$code == 0) {
512
- SQ_Classes_Error::setError(esc_html__("The code for Facebook Pixel must only contain numbers.", _SQ_PLUGIN_NAME_));
513
- $code = '';
514
- }
515
- }
516
- return $code;
517
- }
518
-
519
- /**
520
- * Check the Facebook App code
521
- *
522
- * @return string
523
- */
524
- public static function checkFacebookApp($code) {
525
- if ($code <> '') {
526
- if ((int)$code == 0) {
527
- SQ_Classes_Error::setError(esc_html__("The code for Facebook App must only contain numbers.", _SQ_PLUGIN_NAME_));
528
- $code = '';
529
- }
530
- }
531
- return $code;
532
- }
533
-
534
- /**
535
- * Support for i18n with wpml, polyglot or qtrans
536
- *
537
- * @param string $in
538
- * @return string $in localized
539
- */
540
- public static function i18n($in) {
541
- if (function_exists('langswitch_filter_langs_with_message')) {
542
- $in = langswitch_filter_langs_with_message($in);
543
- }
544
- if (function_exists('polyglot_filter')) {
545
- $in = polyglot_filter($in);
546
- }
547
- if (function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage')) {
548
- $in = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($in);
549
- }
550
- $in = apply_filters('localization', $in);
551
- return $in;
552
- }
553
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ class SQ_Classes_Helpers_Sanitize
5
+ {
6
+
7
+ /**
8
+ * Escape the parameter for html
9
+ *
10
+ * @param $key
11
+ * @return string|void
12
+ */
13
+ public static function escapeGetValue($key)
14
+ {
15
+ return esc_attr(SQ_Classes_Helpers_Tools::getValue($key));
16
+ }
17
+
18
+ /**
19
+ * Clear the title string
20
+ *
21
+ * @param $title
22
+ * @return mixed|null|string|string[]
23
+ */
24
+ public static function clearTitle($title)
25
+ {
26
+ if ($title <> '') {
27
+ if (function_exists('preg_replace')) {
28
+ $search = array(
29
+ "/[\n\r]/si",
30
+ "/[\n]/si",
31
+ "/&nbsp;/si",
32
+ "/\[[^\]]+\]/si",
33
+ "/\s{2,}/",
34
+ );
35
+ $title = preg_replace($search, " ", $title);
36
+ }
37
+
38
+ $title = SQ_Classes_Helpers_Sanitize::i18n(trim(esc_html(ent2ncr(strip_tags($title)))));
39
+
40
+ }
41
+ return $title;
42
+ }
43
+
44
+ /**
45
+ * Clear description
46
+ *
47
+ * @param $description
48
+ * @return null|string|string[]
49
+ */
50
+ public static function clearDescription($description)
51
+ {
52
+ if ($description <> '') {
53
+ if (function_exists('preg_replace')) {
54
+ $search = array(
55
+ "'<!--(.*?)-->'is",
56
+ "'<script[^>]*?>.*?<\/script>'si", // strip out javascript
57
+ "'<style[^>]*?>.*?<\/style>'si", // strip out styles
58
+ "'<form.*?<\/form>'si",
59
+ "'<iframe.*?<\/iframe>'si",
60
+ "'&lt;!--(.*?)--&gt;'is",
61
+ "'&lt;script&gt;.*?&lt;\/script&gt;'si", // strip out javascript
62
+ "'&lt;style&gt;.*?&lt;\/style&gt;'si", // strip out styles
63
+ );
64
+ $description = preg_replace($search, "", $description);
65
+ $search = array(
66
+ "/[\n\r]/si",
67
+ "/[\n]/si",
68
+ "/&nbsp;/si",
69
+ "/\[[^\]]+\]/si",
70
+ "/\s{2,}/",
71
+ );
72
+ $description = preg_replace($search, " ", $description);
73
+ }
74
+
75
+ $description = SQ_Classes_Helpers_Sanitize::i18n(trim(esc_html(ent2ncr(strip_tags($description)))));
76
+ }
77
+
78
+ return $description;
79
+ }
80
+
81
+ /**
82
+ * Clear the keywords
83
+ *
84
+ * @param $keywords
85
+ * @return mixed|null|string|string[]
86
+ */
87
+ public static function clearKeywords($keywords)
88
+ {
89
+ return self::clearTitle($keywords);
90
+ }
91
+
92
+
93
+
94
+ /**
95
+ * Escape the keyword for tags and urls
96
+ *
97
+ * @param $keyword
98
+ * @param string $for
99
+ * @return string|void
100
+ */
101
+ public static function escapeKeyword($keyword, $for = 'all')
102
+ {
103
+ switch ($for){
104
+ case 'url':
105
+ $keyword = urlencode(esc_attr($keyword));
106
+ break;
107
+ case 'attr':
108
+ $keyword = htmlspecialchars(str_replace('"', '\"', $keyword));
109
+ break;
110
+ default:
111
+ $keyword = esc_attr($keyword);
112
+ }
113
+ return $keyword;
114
+ }
115
+
116
+ /**
117
+ * Truncate the text
118
+ *
119
+ * @param $text
120
+ * @param int $min
121
+ * @param int $max
122
+ * @return bool|mixed|null|string|string[]
123
+ */
124
+ public static function truncate($text, $min = 100, $max = 110)
125
+ {
126
+ //make sure they are values
127
+ $max = (int)$max;
128
+ $min = (int)$min;
129
+
130
+ if ($max > 0 && $text <> '' && strlen($text) > $max) {
131
+ if (function_exists('strip_tags')) {
132
+ $text = strip_tags($text);
133
+ }
134
+
135
+ $text = str_replace(']]>', ']]&gt;', $text);
136
+ $text = preg_replace('/\[(.+?)\]/is', '', $text);
137
+
138
+ if ($max < strlen($text)) {
139
+ while ($text[$max] != ' ' && $max > $min) {
140
+ $max--;
141
+ }
142
+ }
143
+
144
+ //Use internation truncate
145
+ if (function_exists('mb_substr')) {
146
+ $text = mb_substr($text, 0, $max);
147
+ } else {
148
+ $text = substr($text, 0, $max);
149
+ }
150
+
151
+ return trim(stripcslashes($text));
152
+ }
153
+
154
+ return $text;
155
+ }
156
+
157
+ /**
158
+ * Replace language-specific characters by ASCII-equivalents.
159
+ *
160
+ * @param string $s
161
+ * @return string
162
+ */
163
+ public static function normalizeChars($s)
164
+ {
165
+ $replace = array(
166
+ 'ъ'=>'-', 'Ь'=>'-', 'Ъ'=>'-', 'ь'=>'-',
167
+ 'Ă'=>'A', 'Ą'=>'A', 'À'=>'A', 'Ã'=>'A', 'Á'=>'A', 'Æ'=>'A', 'Â'=>'A', 'Å'=>'A', 'Ä'=>'Ae',
168
+ 'Þ'=>'B',
169
+ 'Ć'=>'C', 'ץ'=>'C', 'Ç'=>'C',
170
+ 'È'=>'E', 'Ę'=>'E', 'É'=>'E', 'Ë'=>'E', 'Ê'=>'E',
171
+ 'Ğ'=>'G',
172
+ 'İ'=>'I', 'Ï'=>'I', 'Î'=>'I', 'Í'=>'I', 'Ì'=>'I',
173
+ 'Ł'=>'L',
174
+ 'Ñ'=>'N', 'Ń'=>'N',
175
+ 'Ø'=>'O', 'Ó'=>'O', 'Ò'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'Oe',
176
+ 'Ş'=>'S', 'Ś'=>'S', 'Ș'=>'S', 'Š'=>'S',
177
+ 'Ț'=>'T',
178
+ 'Ù'=>'U', 'Û'=>'U', 'Ú'=>'U', 'Ü'=>'Ue',
179
+ 'Ý'=>'Y',
180
+ 'Ź'=>'Z', 'Ž'=>'Z', 'Ż'=>'Z',
181
+ 'â'=>'a', 'ǎ'=>'a', 'ą'=>'a', 'á'=>'a', 'ă'=>'a', 'ã'=>'a', 'Ǎ'=>'a', 'а'=>'a', 'А'=>'a', 'å'=>'a', 'à'=>'a', 'א'=>'a', 'Ǻ'=>'a', 'Ā'=>'a', 'ǻ'=>'a', 'ā'=>'a', 'ä'=>'ae', 'æ'=>'ae', 'Ǽ'=>'ae', 'ǽ'=>'ae',
182
+ 'б'=>'b', 'ב'=>'b', 'Б'=>'b', 'þ'=>'b',
183
+ 'ĉ'=>'c', 'Ĉ'=>'c', 'Ċ'=>'c', 'ć'=>'c', 'ç'=>'c', 'ц'=>'c', 'צ'=>'c', 'ċ'=>'c', 'Ц'=>'c', 'Č'=>'c', 'č'=>'c', 'Ч'=>'ch', 'ч'=>'ch',
184
+ 'ד'=>'d', 'ď'=>'d', 'Đ'=>'d', 'Ď'=>'d', 'đ'=>'d', 'д'=>'d', 'Д'=>'D', 'ð'=>'d',
185
+ 'є'=>'e', 'ע'=>'e', 'е'=>'e', 'Е'=>'e', 'Ə'=>'e', 'ę'=>'e', 'ĕ'=>'e', 'ē'=>'e', 'Ē'=>'e', 'Ė'=>'e', 'ė'=>'e', 'ě'=>'e', 'Ě'=>'e', 'Є'=>'e', 'Ĕ'=>'e', 'ê'=>'e', 'ə'=>'e', 'è'=>'e', 'ë'=>'e', 'é'=>'e',
186
+ 'ф'=>'f', 'ƒ'=>'f', 'Ф'=>'f',
187
+ 'ġ'=>'g', 'Ģ'=>'g', 'Ġ'=>'g', 'Ĝ'=>'g', 'Г'=>'g', 'г'=>'g', 'ĝ'=>'g', 'ğ'=>'g', 'ג'=>'g', 'Ґ'=>'g', 'ґ'=>'g', 'ģ'=>'g',
188
+ 'ח'=>'h', 'ħ'=>'h', 'Х'=>'h', 'Ħ'=>'h', 'Ĥ'=>'h', 'ĥ'=>'h', 'х'=>'h', 'ה'=>'h',
189
+ 'î'=>'i', 'ï'=>'i', 'í'=>'i', 'ì'=>'i', 'į'=>'i', 'ĭ'=>'i', 'ı'=>'i', 'Ĭ'=>'i', 'И'=>'i', 'ĩ'=>'i', 'ǐ'=>'i', 'Ĩ'=>'i', 'Ǐ'=>'i', 'и'=>'i', 'Į'=>'i', 'י'=>'i', 'Ї'=>'i', 'Ī'=>'i', 'І'=>'i', 'ї'=>'i', 'і'=>'i', 'ī'=>'i', 'ij'=>'ij', 'IJ'=>'ij',
190
+ 'й'=>'j', 'Й'=>'j', 'Ĵ'=>'j', 'ĵ'=>'j', 'я'=>'ja', 'Я'=>'ja', 'Э'=>'je', 'э'=>'je', 'ё'=>'jo', 'Ё'=>'jo', 'ю'=>'ju', 'Ю'=>'ju',
191
+ 'ĸ'=>'k', 'כ'=>'k', 'Ķ'=>'k', 'К'=>'k', 'к'=>'k', 'ķ'=>'k', 'ך'=>'k',
192
+ 'Ŀ'=>'l', 'ŀ'=>'l', 'Л'=>'l', 'ł'=>'l', 'ļ'=>'l', 'ĺ'=>'l', 'Ĺ'=>'l', 'Ļ'=>'l', 'л'=>'l', 'Ľ'=>'l', 'ľ'=>'l', 'ל'=>'l',
193
+ 'מ'=>'m', 'М'=>'m', 'ם'=>'m', 'м'=>'m',
194
+ 'ñ'=>'n', 'н'=>'n', 'Ņ'=>'n', 'ן'=>'n', 'ŋ'=>'n', 'נ'=>'n', 'Н'=>'n', 'ń'=>'n', 'Ŋ'=>'n', 'ņ'=>'n', 'ʼn'=>'n', 'Ň'=>'n', 'ň'=>'n',
195
+ 'о'=>'o', 'О'=>'o', 'ő'=>'o', 'õ'=>'o', 'ô'=>'o', 'Ő'=>'o', 'ŏ'=>'o', 'Ŏ'=>'o', 'Ō'=>'o', 'ō'=>'o', 'ø'=>'o', 'ǿ'=>'o', 'ǒ'=>'o', 'ò'=>'o', 'Ǿ'=>'o', 'Ǒ'=>'o', 'ơ'=>'o', 'ó'=>'o', 'Ơ'=>'o', 'œ'=>'oe', 'Œ'=>'oe', 'ö'=>'oe',
196
+ 'פ'=>'p', 'ף'=>'p', 'п'=>'p', 'П'=>'p',
197
+ 'ק'=>'q',
198
+ 'ŕ'=>'r', 'ř'=>'r', 'Ř'=>'r', 'ŗ'=>'r', 'Ŗ'=>'r', 'ר'=>'r', 'Ŕ'=>'r', 'Р'=>'r', 'р'=>'r',
199
+ 'ș'=>'s', 'с'=>'s', 'Ŝ'=>'s', 'š'=>'s', 'ś'=>'s', 'ס'=>'s', 'ş'=>'s', 'С'=>'s', 'ŝ'=>'s', 'Щ'=>'sch', 'щ'=>'sch', 'ш'=>'sh', 'Ш'=>'sh', 'ß'=>'ss',
200
+ 'т'=>'t', 'ט'=>'t', 'ŧ'=>'t', 'ת'=>'t', 'ť'=>'t', 'ţ'=>'t', 'Ţ'=>'t', 'Т'=>'t', 'ț'=>'t', 'Ŧ'=>'t', 'Ť'=>'t', '™'=>'tm',
201
+ 'ū'=>'u', 'у'=>'u', 'Ũ'=>'u', 'ũ'=>'u', 'Ư'=>'u', 'ư'=>'u', 'Ū'=>'u', 'Ǔ'=>'u', 'ų'=>'u', 'Ų'=>'u', 'ŭ'=>'u', 'Ŭ'=>'u', 'Ů'=>'u', 'ů'=>'u', 'ű'=>'u', 'Ű'=>'u', 'Ǖ'=>'u', 'ǔ'=>'u', 'Ǜ'=>'u', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'У'=>'u', 'ǚ'=>'u', 'ǜ'=>'u', 'Ǚ'=>'u', 'Ǘ'=>'u', 'ǖ'=>'u', 'ǘ'=>'u', 'ü'=>'ue',
202
+ 'в'=>'v', 'ו'=>'v', 'В'=>'v',
203
+ 'ש'=>'w', 'ŵ'=>'w', 'Ŵ'=>'w',
204
+ 'ы'=>'y', 'ŷ'=>'y', 'ý'=>'y', 'ÿ'=>'y', 'Ÿ'=>'y', 'Ŷ'=>'y',
205
+ 'Ы'=>'y', 'ž'=>'z', 'З'=>'z', 'з'=>'z', 'ź'=>'z', 'ז'=>'z', 'ż'=>'z', 'ſ'=>'z', 'Ж'=>'zh', 'ж'=>'zh'
206
+ );
207
+ return strtr($s, $replace);
208
+ }
209
+
210
+ /**
211
+ * Check the google code saved at settings
212
+ *
213
+ * @param string $code
214
+ * @return string
215
+ */
216
+ public static function checkGoogleWTCode($code)
217
+ {
218
+ if ($code <> '') {
219
+ $code = stripslashes($code);
220
+ if (strpos($code, 'content') !== false) {
221
+ preg_match('/content\\s*=\\s*[\"]([^\"]+)[\"]/i', $code, $result);
222
+ if (isset($result[1]) && !empty($result[1])) $code = $result[1];
223
+ }
224
+ if (strpos($code, '"') !== false) {
225
+ preg_match('/[\"]([^\"]+)[\"]/i', $code, $result);
226
+ if (isset($result[1]) && !empty($result[1])) $code = $result[1];
227
+ }
228
+
229
+ if ($code == '') SQ_Classes_Error::setError(esc_html__("The code for Google Webmaster Tool is incorrect.", 'squirrly-seo'));
230
+ }
231
+ return $code;
232
+ }
233
+
234
+ /**
235
+ * Check the google code saved at settings
236
+ *
237
+ * @param string $code
238
+ * @return string
239
+ */
240
+ public static function checkGoogleAnalyticsCode($code)
241
+ {
242
+ if ($code <> '') {
243
+ $code = stripslashes($code);
244
+
245
+ if (strpos($code, 'GoogleAnalyticsObject') !== false) {
246
+ preg_match('/ga\(\'create\',[^\'"]*[\'"]([^\'"]+)[\'"],/i', $code, $result);
247
+ if (isset($result[1]) && !empty($result[1])) $code = $result[1];
248
+ }
249
+
250
+ if (strpos($code, '"') !== false) {
251
+ preg_match('/[\"]([^\"]+)[\"]/i', $code, $result);
252
+ if (isset($result[1]) && !empty($result[1])) $code = $result[1];
253
+ }
254
+
255
+ if (strpos($code, 'UA-') === false && strpos($code, 'G-') === false) {
256
+ $code = '';
257
+ SQ_Classes_Error::setError(esc_html__("The code for Google Analytics is incorrect.", 'squirrly-seo'));
258
+ }
259
+ }
260
+ return trim($code);
261
+ }
262
+
263
+ /**
264
+ * Check the Facebook code saved at settings
265
+ *
266
+ * @param string $code
267
+ * @return string
268
+ */
269
+ public static function checkFacebookAdminCode($code)
270
+ {
271
+ if ($code <> '') {
272
+ $code = trim($code);
273
+
274
+ if (strpos($code, 'facebook.com/') !== false) {
275
+ preg_match('/facebook.com\/([^\/]+)/i', $code, $result);
276
+ if (isset($result[1]) && !empty($result[1])) {
277
+ if (is_string($result[1])) {
278
+ $response = SQ_Classes_RemoteController::getFacebookApi(array('profile' => $result[1]));
279
+ if (!is_wp_error($response) && isset($response->code)) {
280
+ return $response->code;
281
+ }
282
+ } elseif (is_numeric($result[1])) {
283
+ return $result[1];
284
+ }
285
+ }
286
+ } elseif ($code <> (int)$code) {
287
+ $response = SQ_Classes_RemoteController::getFacebookApi(array('profile' => $code));
288
+ if (!is_wp_error($response) && isset($response->code)) {
289
+ return $response->code;
290
+ }
291
+ } else {
292
+ return $code;
293
+ }
294
+
295
+ SQ_Classes_Error::setError(esc_html__("The code for Facebook is incorrect.", 'squirrly-seo'));
296
+
297
+ }
298
+ return false;
299
+ }
300
+
301
+ /**
302
+ * Check the Pinterest code saved at settings
303
+ *
304
+ * @param string $code
305
+ * @return string
306
+ */
307
+ public static function checkPinterestCode($code)
308
+ {
309
+ if ($code <> '') {
310
+ $code = stripslashes($code);
311
+
312
+ if (strpos($code, 'content') !== false) {
313
+ preg_match('/content\\s*=\\s*[\"]([^\"]+)[\"]/i', $code, $result);
314
+ if (isset($result[1]) && !empty($result[1])) $code = $result[1];
315
+ }
316
+
317
+ if (strpos($code, '"') !== false) {
318
+ preg_match('/[\"]([^\"]+)[\"]/i', $code, $result);
319
+ if (isset($result[1]) && !empty($result[1])) $code = $result[1];
320
+ }
321
+
322
+ if ($code == '') SQ_Classes_Error::setError(esc_html__("The code for Pinterest is incorrect.", 'squirrly-seo'));
323
+ }
324
+ return $code;
325
+ }
326
+
327
+ /**
328
+ * Check the Bing code saved at settings
329
+ *
330
+ * @return string
331
+ */
332
+ public static function checkBingWTCode($code)
333
+ {
334
+ if ($code <> '') {
335
+ $code = stripslashes($code);
336
+
337
+
338
+ if (strpos($code, 'content') !== false) {
339
+ preg_match('/content\\s*=\\s*[\"]([^\"]+)[\"]/i', $code, $result);
340
+ if (isset($result[1]) && !empty($result[1])) $code = $result[1];
341
+ }
342
+
343
+ if (strpos($code, '"') !== false) {
344
+ preg_match('/[\"]([^\"]+)[\"]/i', $code, $result);
345
+ if (isset($result[1]) && !empty($result[1])) $code = $result[1];
346
+ }
347
+
348
+ if ($code == '') SQ_Classes_Error::setError(esc_html__("The code for Bing is incorrect.", 'squirrly-seo'));
349
+ }
350
+ return $code;
351
+ }
352
+
353
+ /**
354
+ * Check the Baidu code saved at settings
355
+ *
356
+ * @return string
357
+ */
358
+ public static function checkBaiduWTCode($code)
359
+ {
360
+ if ($code <> '') {
361
+ $code = stripslashes($code);
362
+
363
+
364
+ if (strpos($code, 'content') !== false) {
365
+ preg_match('/content\\s*=\\s*[\"]([^\"]+)[\"]/i', $code, $result);
366
+ if (isset($result[1]) && !empty($result[1])) $code = $result[1];
367
+ }
368
+
369
+ if (strpos($code, '"') !== false) {
370
+ preg_match('/[\"]([^\"]+)[\"]/i', $code, $result);
371
+ if (isset($result[1]) && !empty($result[1])) $code = $result[1];
372
+ }
373
+
374
+ if ($code == '') SQ_Classes_Error::setError(esc_html__("The code for Baidu is incorrect.", 'squirrly-seo'));
375
+ }
376
+ return $code;
377
+ }
378
+
379
+ /**
380
+ * Check the Yandex code saved at settings
381
+ *
382
+ * @return string
383
+ */
384
+ public static function checkYandexWTCode($code)
385
+ {
386
+ if ($code <> '') {
387
+ $code = stripslashes($code);
388
+
389
+
390
+ if (strpos($code, 'content') !== false) {
391
+ preg_match('/content\\s*=\\s*[\"]([^\"]+)[\"]/i', $code, $result);
392
+ if (isset($result[1]) && !empty($result[1])) $code = $result[1];
393
+ }
394
+
395
+ if (strpos($code, '"') !== false) {
396
+ preg_match('/[\"]([^\"]+)[\"]/i', $code, $result);
397
+ if (isset($result[1]) && !empty($result[1])) $code = $result[1];
398
+ }
399
+
400
+ if ($code == '') SQ_Classes_Error::setError(esc_html__("The code for Yandex is incorrect.", 'squirrly-seo'));
401
+ }
402
+ return $code;
403
+ }
404
+
405
+ /**
406
+ * Check the Alexa code saved at settings
407
+ *
408
+ * @return string
409
+ */
410
+ public static function checkAlexaCode($code)
411
+ {
412
+ if ($code <> '') {
413
+ $code = stripslashes($code);
414
+
415
+
416
+ if (strpos($code, 'content') !== false) {
417
+ preg_match('/content\\s*=\\s*[\"]([^\"]+)[\"]/i', $code, $result);
418
+ if (isset($result[1]) && !empty($result[1])) $code = $result[1];
419
+ }
420
+
421
+ if (strpos($code, '"') !== false) {
422
+ preg_match('/[\"]([^\"]+)[\"]/i', $code, $result);
423
+ if (isset($result[1]) && !empty($result[1])) $code = $result[1];
424
+ }
425
+
426
+ if ($code == '') SQ_Classes_Error::setError(esc_html__("The code for Alexa is incorrect.", 'squirrly-seo'));
427
+ }
428
+ return $code;
429
+ }
430
+
431
+ /**
432
+ * Check the twitter account
433
+ *
434
+ * @param string $account
435
+ * @return string
436
+ */
437
+ public static function checkTwitterAccount($account)
438
+ {
439
+ if ($account <> '' && strpos($account, '//') === false) {
440
+ $account = 'https://twitter.com/' . $account;
441
+ }
442
+
443
+ return $account;
444
+ }
445
+
446
+ /**
447
+ * Check the twitter account
448
+ *
449
+ * @param string $account
450
+ * @return string
451
+ */
452
+ public static function checkTwitterAccountName($account)
453
+ {
454
+ if ($account <> '' && strpos($account, '//') !== false) {
455
+ $account = parse_url($account, PHP_URL_PATH);
456
+ if ($account <> '') {
457
+ $account = str_replace('/', '', $account);
458
+ }
459
+ if (strpos($account, '@') == false) {
460
+ $account = '@' . $account;
461
+ }
462
+ }
463
+
464
+ return $account;
465
+ }
466
+
467
+ /**
468
+ * Check the google + account
469
+ *
470
+ * @param string $account
471
+ * @return string
472
+ */
473
+ public static function checkGoogleAccount($account)
474
+ {
475
+ if ($account <> '' && strpos($account, '//') === false) {
476
+ $account = 'https://plus.google.com/' . $account;
477
+ }
478
+ return str_replace(" ", "+", $account);
479
+ }
480
+
481
+ /**
482
+ * Check the google + account
483
+ *
484
+ * @param string $account
485
+ * @return string
486
+ */
487
+ public static function checkLinkeinAccount($account)
488
+ {
489
+ if ($account <> '' && strpos($account, '//') === false) {
490
+ $account = 'https://www.linkedin.com/in/' . $account;
491
+ }
492
+ return $account;
493
+ }
494
+
495
+ /**
496
+ * Check the facebook account
497
+ *
498
+ * @param string $account
499
+ * @return string
500
+ */
501
+ public static function checkFacebookAccount($account)
502
+ {
503
+ if ($account <> '' && strpos($account, '//') === false) {
504
+ $account = 'https://www.facebook.com/' . $account;
505
+ }
506
+ return $account;
507
+ }
508
+
509
+ /**
510
+ * Check the Pinterest account
511
+ *
512
+ * @param $account
513
+ * @return string
514
+ */
515
+ public static function checkPinterestAccount($account)
516
+ {
517
+ if ($account <> '' && strpos($account, '//') === false) {
518
+ $account = 'https://www.pinterest.com/' . $account;
519
+ }
520
+ return $account;
521
+ }
522
+
523
+ /**
524
+ * Check the Instagram
525
+ *
526
+ * @param $account
527
+ * @return string
528
+ */
529
+ public static function checkInstagramAccount($account)
530
+ {
531
+ if ($account <> '' && strpos($account, '//') === false) {
532
+ $account = 'https://www.instagram.com/' . $account;
533
+ }
534
+ return $account;
535
+ }
536
+
537
+ /**
538
+ * Check the Youtube account
539
+ *
540
+ * @param $account
541
+ * @return string
542
+ */
543
+ public static function checkYoutubeAccount($account)
544
+ {
545
+ if ($account <> '' && strpos($account, '//') === false) {
546
+ if (strpos($account, 'user/') === false && strpos($account, 'channel/') === false) {
547
+ $account = 'https://www.youtube.com/channel/' . $account;
548
+ }
549
+ }
550
+ return $account;
551
+ }
552
+
553
+ /**
554
+ * Check the Facebook Pixel code
555
+ *
556
+ * @return string
557
+ */
558
+ public static function checkFacebookPixel($code)
559
+ {
560
+ if ($code <> '') {
561
+ if ((int)$code == 0) {
562
+ SQ_Classes_Error::setError(esc_html__("The code for Facebook Pixel must only contain numbers.", 'squirrly-seo'));
563
+ $code = '';
564
+ }
565
+ }
566
+ return $code;
567
+ }
568
+
569
+ /**
570
+ * Check the Facebook App code
571
+ *
572
+ * @return string
573
+ */
574
+ public static function checkFacebookApp($code)
575
+ {
576
+ if ($code <> '') {
577
+ if ((int)$code == 0) {
578
+ SQ_Classes_Error::setError(esc_html__("The code for Facebook App must only contain numbers.", 'squirrly-seo'));
579
+ $code = '';
580
+ }
581
+ }
582
+ return $code;
583
+ }
584
+
585
+ /**
586
+ * Support for i18n with wpml, polyglot or qtrans
587
+ *
588
+ * @param string $in
589
+ * @return string $in localized
590
+ */
591
+ public static function i18n($in)
592
+ {
593
+ if (function_exists('langswitch_filter_langs_with_message')) {
594
+ $in = langswitch_filter_langs_with_message($in);
595
+ }
596
+ if (function_exists('polyglot_filter')) {
597
+ $in = polyglot_filter($in);
598
+ }
599
+ if (function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage')) {
600
+ $in = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($in);
601
+ }
602
+ $in = apply_filters('localization', $in);
603
+ return $in;
604
+ }
605
+ }
classes/helpers/Tools.php CHANGED
@@ -1,1360 +1,1411 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- /**
5
- * Handles the parameters and url
6
- *
7
- * @author Squirrly
8
- */
9
- class SQ_Classes_Helpers_Tools {
10
-
11
- /** @var array Options, User Metas, Package and Plugin details */
12
- public static $options, $usermeta, $allplugins = array();
13
-
14
- public function __construct() {
15
- self::$options = $this->getOptions();
16
-
17
- // $maxmemory = self::getMaxMemory();
18
- // if ($maxmemory && $maxmemory < 60) {
19
- // @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
20
- // }
21
-
22
- SQ_Classes_ObjController::getClass('SQ_Classes_HookController')->setHooks($this);
23
- }
24
-
25
- public static function getMaxMemory() {
26
- try {
27
- $memory_limit = @ini_get('memory_limit');
28
- if ((int)$memory_limit > 0) {
29
- if (preg_match('/^(\d+)(.)$/', $memory_limit, $matches)) {
30
- if ($matches[2] == 'G') {
31
- $memory_limit = $matches[1] * 1024 * 1024 * 1024; // nnnM -> nnn MB
32
- } elseif ($matches[2] == 'M') {
33
- $memory_limit = $matches[1] * 1024 * 1024; // nnnM -> nnn MB
34
- } elseif ($matches[2] == 'K') {
35
- $memory_limit = $matches[1] * 1024; // nnnK -> nnn KB
36
- }
37
- }
38
-
39
- if ((int)$memory_limit > 0) {
40
- return number_format($memory_limit / 1024 / 1024, 0, '', '');
41
- }
42
- }
43
- } catch (Exception $e) {
44
- }
45
-
46
- return false;
47
-
48
- }
49
-
50
- public static function isAjax() {
51
- return (defined('DOING_AJAX') && DOING_AJAX);
52
- }
53
-
54
- /**
55
- * This hook will save the current version in database
56
- *
57
- * @return void
58
- */
59
- function hookInit() {
60
- //Load the languages pack
61
- $this->loadMultilanguage();
62
-
63
- //add extra links to the plugin in the Plugins list
64
- add_filter("plugin_row_meta", array($this, 'hookExtraLinks'), 10, 4);
65
- //add setting link in plugin
66
- add_filter('plugin_action_links', array($this, 'hookActionlink'), 5, 2);
67
- }
68
-
69
- /**
70
- * Add a link to settings in the plugin list
71
- *
72
- * @param array $links
73
- * @param string $file
74
- * @return array
75
- */
76
- public function hookActionlink($links, $file) {
77
- if ($file == _SQ_PLUGIN_NAME_ . '/squirrly.php') {
78
- $link = '<a href="' . self::getAdminUrl('sq_dashboard') . '">' . esc_html__("Getting started", _SQ_PLUGIN_NAME_) . '</a>';
79
- array_unshift($links, $link);
80
- }
81
-
82
- return $links;
83
- }
84
-
85
- /**
86
- * Adds extra links to plugin page
87
- *
88
- * @param $meta
89
- * @param $file
90
- * @param $data
91
- * @param $status
92
- * @return array
93
- */
94
- public function hookExtraLinks($meta, $file, $data = null, $status = null) {
95
- if ($file == _SQ_PLUGIN_NAME_ . '/squirrly.php') {
96
- echo '<style>
97
- .ml-stars{display:inline-block;color:#ffb900;position:relative;top:3px}
98
- .ml-stars svg{fill:#ffb900}
99
- .ml-stars svg:hover{fill:#ffb900}
100
- .ml-stars svg:hover ~ svg{fill:none}
101
- </style>';
102
-
103
- $meta[] = "<a href='https://howto.squirrly.co/wordpress-seo/' target='_blank'>" . esc_html__("Documentation", _SQ_PLUGIN_NAME_) . "</a>";
104
- $meta[] = "<a href='https://wordpress.org/support/plugin/squirrly-seo/reviews/#new-post' target='_blank' title='" . esc_html__("Leave a review", _SQ_PLUGIN_NAME_) . "'><i class='ml-stars'><svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg><svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg><svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg><svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg><svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg></i></a>";
105
- }
106
- return $meta;
107
- }
108
-
109
- /**
110
- * Load the Options from user option table in DB
111
- *
112
- * @param string $action
113
- * @return array|mixed|object
114
- */
115
- public static function getOptions($action = '') {
116
- $default = array(
117
- //Global settings
118
- 'sq_api' => '',
119
- 'sq_installed' => date('Y-m-d H:i:s'),
120
- //
121
- 'sq_cloud_connect' => 0,
122
- 'sq_cloud_token' => false,
123
- 'sq_offer' => false,
124
- 'sq_alert_overview' => true,
125
- 'sq_alert_journey' => true,
126
- //Advanced settings
127
- 'sq_seoexpert' => 0,
128
- //later buffer load
129
- 'sq_laterload' => 0,
130
- 'sq_audit_email' => '',
131
-
132
- //SEO Journey
133
- 'sq_seojourney' => 0,
134
- 'sq_seojourney_congrats' => 1,
135
- 'sq_menu_visited' => array(),
136
-
137
- //minify Squirrly Metas
138
- 'sq_load_css' => 1,
139
- 'sq_minify' => 0,
140
- 'sq_non_utf8_support' => 1,
141
-
142
- //Settings Assistant
143
- 'sq_assistant' => 1,
144
- 'sq_complete_uninstall' => 0,
145
-
146
- //Onboarding
147
- 'sq_onboarding' => 0,
148
- 'sq_onboarding_data' => array(),
149
-
150
- //Live Assistant
151
- 'sq_sla' => 1,
152
- 'sq_sla_frontend' => 1,
153
- 'sq_sla_type' => 'auto',
154
- 'sq_sla_exclude_post_types' => array(),
155
- 'sq_keyword_help' => 1,
156
- 'sq_local_images' => 0,
157
- 'sq_img_licence' => 1,
158
- 'sq_sla_social_fetch' => 1,
159
-
160
- //JsonLD
161
- 'sq_auto_jsonld' => 1,
162
- 'sq_auto_jsonld_local' => 0,
163
- 'sq_jsonld_type' => 'Organization',
164
- 'sq_jsonld_global_person' => 0,
165
- 'sq_jsonld_breadcrumbs' => 1,
166
- 'sq_jsonld_woocommerce' => 1,
167
- 'sq_jsonld_clearcode' => 0,
168
- 'sq_jsonld_product_rating' => 0,
169
- 'sq_jsonld_product_custom' => 1,
170
- 'sq_jsonld_product_defaults' => 1,
171
- 'sq_jsonld_local' => array(
172
- 'priceRange' => '',
173
- 'servesCuisine' => '',
174
- 'menu' => '',
175
- 'acceptsReservations' => '',
176
- 'openingHoursSpecification' => array(
177
- array(
178
- '@type' => 'OpeningHoursSpecification',
179
- 'dayOfWeek' => 'Monday',
180
- 'opens' => '',
181
- 'closes' => '',
182
- ),
183
- array(
184
- '@type' => 'OpeningHoursSpecification',
185
- 'dayOfWeek' => 'Tuesday',
186
- 'opens' => '',
187
- 'closes' => '',
188
- ),
189
- array(
190
- '@type' => 'OpeningHoursSpecification',
191
- 'dayOfWeek' => 'Wednesday',
192
- 'opens' => '',
193
- 'closes' => '',
194
- ),
195
- array(
196
- '@type' => 'OpeningHoursSpecification',
197
- 'dayOfWeek' => 'Thursday',
198
- 'opens' => '',
199
- 'closes' => '',
200
- ),
201
- array(
202
- '@type' => 'OpeningHoursSpecification',
203
- 'dayOfWeek' => 'Friday',
204
- 'opens' => '',
205
- 'closes' => '',
206
- ),
207
- array(
208
- '@type' => 'OpeningHoursSpecification',
209
- 'dayOfWeek' => 'Saturday',
210
- 'opens' => '',
211
- 'closes' => '',
212
- ),
213
- array(
214
- '@type' => 'OpeningHoursSpecification',
215
- 'dayOfWeek' => 'Sunday',
216
- 'opens' => '',
217
- 'closes' => '',
218
- ),
219
-
220
- ),
221
- ),
222
- 'sq_jsonld' => array(
223
- 'Organization' => array(
224
- 'name' => '',
225
- 'logo' => array(
226
- '@type' => 'ImageObject',
227
- 'url' => '',
228
- ),
229
- 'contactPoint' => array(
230
- '@type' => 'ContactPoint',
231
- 'telephone' => '',
232
- 'contactType' => '',
233
- ),
234
- 'address' => array(
235
- '@type' => 'PostalAddress',
236
- 'streetAddress' => '',
237
- 'addressLocality' => '',
238
- 'addressRegion' => '',
239
- 'postalCode' => '',
240
- 'addressCountry' => '',
241
- ),
242
- 'place' => array(
243
- '@type' => 'Place',
244
- 'geo' => array(
245
- '@type' => 'GeoCoordinates',
246
- 'latitude' => '',
247
- 'longitude' => '',
248
- ),
249
-
250
- ),
251
-
252
- 'description' => ''
253
- ),
254
- 'Person' => array(
255
- 'name' => '',
256
- 'image' => array(
257
- '@type' => 'ImageObject',
258
- 'url' => '',
259
- ),
260
- 'telephone' => '',
261
- 'jobTitle' => '',
262
- 'description' => ''
263
- )),
264
-
265
- //Sitemap
266
- 'sq_auto_sitemap' => 1,
267
- 'sq_sitemap_ping' => 0,
268
- 'sq_sitemap_exclude_noindex' => 0,
269
- 'sq_sitemap_show' => array(
270
- 'images' => 1,
271
- 'videos' => 0,
272
- ),
273
- 'sq_sitemap_perpage' => 500,
274
- 'sq_sitemap_frequency' => 'weekly',
275
- 'sq_sitemap_combinelangs' => 0,
276
- 'sq_sitemap' => array(
277
- 'sitemap' => array('sitemap.xml', 1),
278
- 'sitemap-home' => array('sitemap-home.xml', 1),
279
- 'sitemap-news' => array('sitemap-news.xml', 0),
280
- 'sitemap-product' => array('sitemap-product.xml', 1),
281
- 'sitemap-post' => array('sitemap-posts.xml', 1),
282
- 'sitemap-page' => array('sitemap-pages.xml', 1),
283
- 'sitemap-category' => array('sitemap-categories.xml', 1),
284
- 'sitemap-post_tag' => array('sitemap-tags.xml', 1),
285
- 'sitemap-archive' => array('sitemap-archives.xml', 1),
286
- 'sitemap-author' => array('sitemap-authors.xml', 0),
287
- 'sitemap-custom-tax' => array('sitemap-custom-taxonomies.xml', 0),
288
- 'sitemap-custom-post' => array('sitemap-custom-posts.xml', 0),
289
- 'sitemap-attachment' => array('sitemap-attachment.xml', 0),
290
- ),
291
-
292
- //Robots
293
- 'sq_auto_robots' => 1,
294
- 'sq_robots_permission' => array(
295
- 'User-agent: *',
296
- 'Disallow: */trackback/',
297
- 'Disallow: */xmlrpc.php',
298
- 'Disallow: /wp-*.php',
299
- 'Disallow: /cgi-bin/',
300
- 'Disallow: /wp-admin/',
301
- 'Allow: */wp-content/uploads/',),
302
-
303
- //Metas
304
- 'sq_use' => 1,
305
- 'sq_auto_metas' => 1,
306
- 'sq_auto_links' => 0,
307
- 'sq_auto_redirects' => 1,
308
- 'sq_auto_title' => 1,
309
- 'sq_auto_description' => 1,
310
- 'sq_auto_keywords' => 1,
311
- 'sq_keywordtag' => 0,
312
- 'sq_auto_canonical' => 1,
313
- 'sq_auto_dublincore' => 0,
314
- 'sq_auto_feed' => 0,
315
- 'sq_auto_noindex' => 1,
316
- 'sq_use_frontend' => 1,
317
- 'sq_attachment_redirect' => 0,
318
- 'sq_term_noindex_empty' => 1,
319
- '404_url_redirect' => home_url(),
320
- 'sq_external_nofollow' => 1,
321
- 'sq_external_exception' => array(),
322
- 'sq_external_blank' => 0,
323
- 'sq_metas' => array(
324
- 'title_maxlength' => 75,
325
- 'description_maxlength' => 320,
326
- 'og_title_maxlength' => 75,
327
- 'og_description_maxlength' => 200,
328
- 'tw_title_maxlength' => 75,
329
- 'tw_description_maxlength' => 280,
330
- 'jsonld_title_maxlength' => 75,
331
- 'jsonld_description_maxlength' => 320,
332
- ),
333
-
334
- //favicon
335
- 'sq_auto_favicon' => 0,
336
- 'sq_favicon_apple' => 1,
337
- 'favicon' => '',
338
-
339
- //Ranking Option
340
- 'sq_google_country' => 'com',
341
- 'sq_google_language' => 'en',
342
- 'sq_google_device' => 'desktop',
343
- 'sq_google_serpsperhour' => 500,
344
- 'connect' => array(
345
- 'google_analytics' => 0,
346
- 'google_search_console' => 0,
347
- ),
348
-
349
- // dev kit
350
- 'sq_auto_devkit' => 1,
351
- 'sq_devkit_logo' => false,
352
- 'sq_devkit_name' => false,
353
- 'sq_devkit_menu_name' => false,
354
- 'sq_devkit_audit_success' => false,
355
- 'sq_devkit_audit_fail' => false,
356
- //menu restrictions
357
- 'menu' => array(
358
- 'show_account_info' => 1,
359
- 'show_journey' => 1,
360
- 'show_panel' => 1,
361
- 'show_tutorial' => 1,
362
- 'show_audit' => 1,
363
- 'show_assistant' => 1,
364
- 'show_bulkseo' => 1,
365
- 'show_research' => 1,
366
- 'show_rankings' => 1,
367
- 'show_focuspages' => 1,
368
- 'show_seogoals' => 1,
369
- 'show_ads' => 1,
370
- ),
371
-
372
- //socials
373
- 'sq_auto_social' => 1,
374
- 'sq_auto_facebook' => 1,
375
- 'sq_auto_twitter' => 1,
376
- 'sq_og_locale' => 'en_US',
377
- 'sq_og_image' => '',
378
- 'sq_tc_image' => '',
379
-
380
- 'socials' => array(
381
- 'fb_admins' => array(),
382
- 'fbconnectkey' => "",
383
- 'fbadminapp' => "",
384
-
385
- 'facebook_site' => "",
386
- 'twitter_site' => "https://twitter.com/twitter",
387
- 'twitter' => "",
388
- 'instagram_url' => "",
389
- 'linkedin_url' => "",
390
- 'myspace_url' => "",
391
- 'pinterest_url' => "",
392
- 'youtube_url' => "",
393
- 'twitter_card_type' => "summary_large_image",
394
- 'plus_publisher' => ""
395
- ),
396
-
397
- //Webmasters and Tracking
398
- 'sq_auto_amp' => 1,
399
- 'sq_auto_tracking' => 1,
400
- 'sq_auto_pixels' => 1,
401
- 'sq_tracking_logged_users' => 1,
402
- 'sq_tracking_ip_users' => 1,
403
- 'sq_auto_webmasters' => 1,
404
- 'sq_analytics_google_js' => 'analytics',
405
- 'codes' => array(
406
- 'google_wt' => "",
407
- 'google_analytics' => "",
408
- 'facebook_pixel' => "",
409
-
410
- 'bing_wt' => "",
411
- 'baidu_wt' => "",
412
- 'yandex_wt' => "",
413
- 'pinterest_verify' => "",
414
- 'alexa_verify' => "",
415
- 'norton_verify' => "",
416
- ),
417
-
418
- //Patterns
419
- 'sq_auto_pattern' => 1,
420
- 'patterns' => array(
421
- 'home' => array(
422
- 'protected' => 1,
423
- 'sep' => '|',
424
- 'title' => '{{sitename}} {{page}} {{sep}} {{sitedesc}}',
425
- 'description' => '{{excerpt}} {{page}} {{sep}} {{sitename}}',
426
- 'noindex' => 0,
427
- 'nofollow' => 0,
428
- 'og_type' => 'website',
429
- 'jsonld_types' => array('website'),
430
- 'do_metas' => 1,
431
- 'do_sitemap' => 1,
432
- 'do_jsonld' => 1,
433
- 'do_pattern' => 1,
434
- 'do_og' => 1,
435
- 'do_twc' => 1,
436
- 'do_analytics' => 1,
437
- 'do_fpixel' => 1,
438
- 'do_redirects' => 0,
439
- ),
440
- 'post' => array(
441
- 'protected' => 1,
442
- 'sep' => '|',
443
- 'title' => '{{title}} {{page}}',
444
- 'description' => '{{excerpt}}',
445
- 'noindex' => 0,
446
- 'nofollow' => 0,
447
- 'og_type' => 'article',
448
- 'jsonld_types' => array('newsarticle'),
449
- 'do_metas' => 1,
450
- 'do_sitemap' => 1,
451
- 'do_jsonld' => 1,
452
- 'do_pattern' => 1,
453
- 'do_og' => 1,
454
- 'do_twc' => 1,
455
- 'do_analytics' => 1,
456
- 'do_fpixel' => 1,
457
- 'do_redirects' => 1,
458
- ),
459
- 'page' => array(
460
- 'protected' => 1,
461
- 'sep' => '|',
462
- 'title' => '{{title}} {{page}} {{sep}} {{sitename}}',
463
- 'description' => '{{excerpt}}',
464
- 'noindex' => 0,
465
- 'nofollow' => 0,
466
- 'og_type' => 'website',
467
- 'jsonld_types' => array('website'),
468
- 'do_metas' => 1,
469
- 'do_sitemap' => 1,
470
- 'do_jsonld' => 1,
471
- 'do_pattern' => 1,
472
- 'do_og' => 1,
473
- 'do_twc' => 1,
474
- 'do_analytics' => 1,
475
- 'do_fpixel' => 1,
476
- 'do_redirects' => 1,
477
- ),
478
- 'product' => array(
479
- 'protected' => 1,
480
- 'sep' => '|',
481
- 'title' => '{{title}} {{page}} {{sep}} {{sitename}}',
482
- 'description' => '{{excerpt}}',
483
- 'noindex' => 0,
484
- 'nofollow' => 0,
485
- 'og_type' => 'product',
486
- 'jsonld_types' => array('product'),
487
- 'do_metas' => 1,
488
- 'do_sitemap' => 1,
489
- 'do_jsonld' => 1,
490
- 'do_pattern' => 1,
491
- 'do_og' => 1,
492
- 'do_twc' => 1,
493
- 'do_analytics' => 1,
494
- 'do_fpixel' => 1,
495
- 'do_redirects' => 1,
496
- ),
497
- 'category' => array(
498
- 'protected' => 1,
499
- 'sep' => '|',
500
- 'title' => '{{category}} {{page}} {{sep}} {{sitename}}',
501
- 'description' => '{{category_description}}',
502
- 'noindex' => 0,
503
- 'nofollow' => 0,
504
- 'og_type' => 'website',
505
- 'jsonld_types' => array('website'),
506
- 'do_metas' => 1,
507
- 'do_sitemap' => 1,
508
- 'do_jsonld' => 0,
509
- 'do_pattern' => 1,
510
- 'do_og' => 1,
511
- 'do_twc' => 1,
512
- 'do_analytics' => 1,
513
- 'do_fpixel' => 1,
514
- 'do_redirects' => 0,
515
- ),
516
- 'tag' => array(
517
- 'protected' => 1,
518
- 'sep' => '|',
519
- 'title' => '{{tag}} {{page}} {{sep}} {{sitename}}',
520
- 'description' => '{{excerpt}}',
521
- 'noindex' => 0,
522
- 'nofollow' => 0,
523
- 'og_type' => 'website',
524
- 'jsonld_types' => array('website'),
525
- 'do_metas' => 1,
526
- 'do_sitemap' => 1,
527
- 'do_jsonld' => 0,
528
- 'do_pattern' => 1,
529
- 'do_og' => 1,
530
- 'do_twc' => 1,
531
- 'do_analytics' => 1,
532
- 'do_fpixel' => 1,
533
- 'do_redirects' => 0,
534
- ),
535
- 'tax-product_cat' => array(
536
- 'protected' => 1,
537
- 'sep' => '|',
538
- 'title' => '{{term_title}} ' . esc_html__("Category", _SQ_PLUGIN_NAME_) . ' {{page}} {{sep}} {{sitename}}',
539
- 'description' => '{{excerpt}}',
540
- 'noindex' => 0,
541
- 'nofollow' => 0,
542
- 'og_type' => 'website',
543
- 'jsonld_types' => array('website'),
544
- 'do_metas' => 1,
545
- 'do_sitemap' => 1,
546
- 'do_jsonld' => 1,
547
- 'do_pattern' => 1,
548
- 'do_og' => 1,
549
- 'do_twc' => 1,
550
- 'do_analytics' => 1,
551
- 'do_fpixel' => 1,
552
- 'do_redirects' => 0,
553
- ),
554
- 'tax-product_tag' => array(
555
- 'protected' => 1,
556
- 'sep' => '|',
557
- 'title' => '{{term_title}} ' . esc_html__("Tag", _SQ_PLUGIN_NAME_) . ' {{page}} {{sep}} {{sitename}}',
558
- 'description' => '{{excerpt}}',
559
- 'noindex' => 0,
560
- 'nofollow' => 0,
561
- 'og_type' => 'website',
562
- 'jsonld_types' => array('website'),
563
- 'do_metas' => 1,
564
- 'do_sitemap' => 1,
565
- 'do_jsonld' => 1,
566
- 'do_pattern' => 1,
567
- 'do_og' => 1,
568
- 'do_twc' => 1,
569
- 'do_analytics' => 1,
570
- 'do_fpixel' => 1,
571
- 'do_redirects' => 0,
572
- ),
573
- 'tax-post_format' => array(
574
- 'protected' => 1,
575
- 'sep' => '|',
576
- 'title' => '{{term_title}} ' . esc_html__("Format", _SQ_PLUGIN_NAME_) . ' {{page}} {{sep}} {{sitename}}',
577
- 'description' => '{{excerpt}}',
578
- 'noindex' => 0,
579
- 'nofollow' => 0,
580
- 'og_type' => 'website',
581
- 'jsonld_types' => array('website'),
582
- 'do_metas' => 1,
583
- 'do_sitemap' => 1,
584
- 'do_jsonld' => 1,
585
- 'do_pattern' => 1,
586
- 'do_og' => 1,
587
- 'do_twc' => 1,
588
- 'do_analytics' => 1,
589
- 'do_fpixel' => 1,
590
- 'do_redirects' => 0,
591
- ),
592
- 'tax-category' => array(
593
- 'protected' => 1,
594
- 'sep' => '|',
595
- 'title' => '{{term_title}} ' . esc_html__("Category", _SQ_PLUGIN_NAME_) . ' {{page}} {{sep}} {{sitename}}',
596
- 'description' => '{{excerpt}}',
597
- 'noindex' => 0,
598
- 'nofollow' => 0,
599
- 'og_type' => 'website',
600
- 'jsonld_types' => array('website'),
601
- 'do_metas' => 1,
602
- 'do_sitemap' => 1,
603
- 'do_jsonld' => 1,
604
- 'do_pattern' => 1,
605
- 'do_og' => 1,
606
- 'do_twc' => 1,
607
- 'do_analytics' => 1,
608
- 'do_fpixel' => 1,
609
- 'do_redirects' => 0,
610
- ),
611
- 'tax-post_tag' => array(
612
- 'protected' => 1,
613
- 'sep' => '|',
614
- 'title' => '{{term_title}} ' . esc_html__("Tag", _SQ_PLUGIN_NAME_) . ' {{page}} {{sep}} {{sitename}}',
615
- 'description' => '{{excerpt}}',
616
- 'noindex' => 0,
617
- 'nofollow' => 0,
618
- 'og_type' => 'website',
619
- 'jsonld_types' => array('website'),
620
- 'do_metas' => 1,
621
- 'do_sitemap' => 1,
622
- 'do_jsonld' => 1,
623
- 'do_pattern' => 1,
624
- 'do_og' => 1,
625
- 'do_twc' => 1,
626
- 'do_analytics' => 1,
627
- 'do_fpixel' => 1,
628
- 'do_redirects' => 0,
629
- ),
630
- 'tax-product_shipping_class' => array(
631
- 'protected' => 1,
632
- 'sep' => '|',
633
- 'title' => '{{term_title}} ' . esc_html__("Shipping Option", _SQ_PLUGIN_NAME_) . ' {{page}} {{sep}} {{sitename}}',
634
- 'description' => '{{excerpt}}',
635
- 'noindex' => 0,
636
- 'nofollow' => 0,
637
- 'og_type' => 'website',
638
- 'jsonld_types' => array('website'),
639
- 'do_metas' => 1,
640
- 'do_sitemap' => 1,
641
- 'do_jsonld' => 1,
642
- 'do_pattern' => 1,
643
- 'do_og' => 1,
644
- 'do_twc' => 1,
645
- 'do_analytics' => 1,
646
- 'do_fpixel' => 1,
647
- 'do_redirects' => 0,
648
- ),
649
- 'shop' => array(
650
- 'protected' => 1,
651
- 'sep' => '|',
652
- 'title' => '{{title}} {{page}} {{sep}} {{sitename}}',
653
- 'description' => '{{excerpt}}',
654
- 'noindex' => 0,
655
- 'nofollow' => 0,
656
- 'og_type' => 'website',
657
- 'jsonld_types' => array('website'),
658
- 'do_metas' => 1,
659
- 'do_sitemap' => 1,
660
- 'do_jsonld' => 1,
661
- 'do_pattern' => 1,
662
- 'do_og' => 1,
663
- 'do_twc' => 1,
664
- 'do_analytics' => 1,
665
- 'do_fpixel' => 1,
666
- 'do_redirects' => 0,
667
- ),
668
- 'profile' => array(
669
- 'protected' => 1,
670
- 'sep' => '|',
671
- 'title' => '{{name}}, ' . esc_html__("Author at", _SQ_PLUGIN_NAME_) . ' {{sitename}} {{page}}',
672
- 'description' => '{{excerpt}}',
673
- 'noindex' => 0,
674
- 'nofollow' => 0,
675
- 'og_type' => 'profile',
676
- 'jsonld_types' => array('profile'),
677
- 'do_metas' => 1,
678
- 'do_sitemap' => 1,
679
- 'do_jsonld' => 1,
680
- 'do_pattern' => 1,
681
- 'do_og' => 1,
682
- 'do_twc' => 1,
683
- 'do_analytics' => 1,
684
- 'do_fpixel' => 1,
685
- 'do_redirects' => 0,
686
- ),
687
- 'archive' => array(
688
- 'protected' => 1,
689
- 'sep' => '|',
690
- 'title' => '{{plural}} {{date}} {{page}} {{sep}} {{sitename}}',
691
- 'description' => '{{excerpt}}',
692
- 'noindex' => 0,
693
- 'nofollow' => 0,
694
- 'og_type' => 'website',
695
- 'jsonld_types' => array('website'),
696
- 'do_metas' => 1,
697
- 'do_sitemap' => 1,
698
- 'do_jsonld' => 1,
699
- 'do_pattern' => 1,
700
- 'do_og' => 1,
701
- 'do_twc' => 1,
702
- 'do_analytics' => 1,
703
- 'do_fpixel' => 1,
704
- 'do_redirects' => 0,
705
- ),
706
- 'search' => array(
707
- 'protected' => 1,
708
- 'sep' => '|',
709
- 'title' => esc_html__("Are you looking for", _SQ_PLUGIN_NAME_) . ' {{searchphrase}}? {{page}} {{sep}} {{sitename}}',
710
- 'description' => esc_html__("These are the results for", _SQ_PLUGIN_NAME_) . ' {{searchphrase}} ' . esc_html__("that you can find on our website.", _SQ_PLUGIN_NAME_) . ' {{excerpt}}',
711
- 'noindex' => 1,
712
- 'nofollow' => 0,
713
- 'og_type' => 'website',
714
- 'jsonld_types' => array('website'),
715
- 'do_metas' => 1,
716
- 'do_sitemap' => 0,
717
- 'do_jsonld' => 1,
718
- 'do_pattern' => 1,
719
- 'do_og' => 1,
720
- 'do_twc' => 1,
721
- 'do_analytics' => 1,
722
- 'do_fpixel' => 1,
723
- ),
724
- 'attachment' => array(
725
- 'protected' => 1,
726
- 'sep' => '|',
727
- 'title' => '{{title}} {{page}} {{sep}} {{sitename}}',
728
- 'description' => '{{excerpt}}',
729
- 'noindex' => 0,
730
- 'nofollow' => 0,
731
- 'og_type' => 'website',
732
- 'jsonld_types' => array('website'),
733
- 'do_metas' => 1,
734
- 'do_sitemap' => 1,
735
- 'do_jsonld' => 1,
736
- 'do_pattern' => 1,
737
- 'do_og' => 1,
738
- 'do_twc' => 1,
739
- 'do_analytics' => 1,
740
- 'do_fpixel' => 1,
741
- 'do_redirects' => 1,
742
- ),
743
- '404' => array(
744
- 'protected' => 1,
745
- 'sep' => '|',
746
- 'title' => esc_html__("Page not found", _SQ_PLUGIN_NAME_) . ' {{sep}} {{sitename}}',
747
- 'description' => esc_html__("This page could not be found on our website.", _SQ_PLUGIN_NAME_) . ' {{excerpt}}',
748
- 'noindex' => 1,
749
- 'nofollow' => 1,
750
- 'og_type' => 'website',
751
- 'jsonld_types' => array('website'),
752
- 'do_metas' => 1,
753
- 'do_sitemap' => 0,
754
- 'do_jsonld' => 0,
755
- 'do_pattern' => 1,
756
- 'do_og' => 0,
757
- 'do_twc' => 0,
758
- 'do_analytics' => 1,
759
- 'do_fpixel' => 1,
760
- 'do_redirects' => 0,
761
- ),
762
- 'custom' => array(
763
- 'protected' => 1,
764
- 'sep' => '|',
765
- 'title' => '{{title}} {{page}} {{sep}} {{sitename}}',
766
- 'description' => '{{excerpt}}',
767
- 'noindex' => 0,
768
- 'nofollow' => 0,
769
- 'og_type' => 'website',
770
- 'jsonld_types' => array('website'),
771
- 'do_metas' => 1,
772
- 'do_sitemap' => 1,
773
- 'do_jsonld' => 1,
774
- 'do_pattern' => 1,
775
- 'do_og' => 1,
776
- 'do_twc' => 1,
777
- 'do_analytics' => 1,
778
- 'do_fpixel' => 1,
779
- 'do_redirects' => 0,
780
- ),
781
- )
782
-
783
- );
784
- $options = json_decode(get_option(SQ_OPTION), true);
785
-
786
- //Update the Json-LD for Organization Logo
787
- if (isset($options['sq_jsonld']['Organization']['logo']) && !is_array($options['sq_jsonld']['Organization']['logo'])) {
788
- $options['sq_jsonld']['Organization']['logo'] = array(
789
- '@type' => 'ImageObject',
790
- 'url' => $options['sq_jsonld']['Organization']['logo'],
791
- );
792
- }
793
-
794
- if (isset($options['sq_jsonld']['Organization']['telephone']) && isset($options['sq_jsonld']['Organization']['contactType'])) {
795
- $options['sq_jsonld']['Organization']['contactPoint'] = array(
796
- '@type' => 'ContactPoint',
797
- 'telephone' => $options['sq_jsonld']['Organization']['telephone'],
798
- 'contactType' => $options['sq_jsonld']['Organization']['contactType']
799
- );
800
-
801
- unset($options['sq_jsonld']['Organization']['telephone']);
802
- unset($options['sq_jsonld']['Organization']['contactType']);
803
- }
804
-
805
- //Update the Json-LD for Person Image
806
- if (isset($options['sq_jsonld']['Person']['logo'])) {
807
- $options['sq_jsonld']['Person']['image'] = array(
808
- '@type' => 'ImageObject',
809
- 'url' => $options['sq_jsonld']['Person']['logo'],
810
- );
811
-
812
- unset($options['sq_jsonld']['Person']['logo']);
813
- }
814
-
815
- if ($action == 'reset') {
816
- $init['sq_api'] = $options['sq_api'];
817
- return $init;
818
- }
819
-
820
- if (is_array($options)) {
821
- $options = array_replace_recursive((array)$default, (array)$options);
822
- return $options;
823
- }
824
-
825
- return $default;
826
- }
827
-
828
- /**
829
- * Get the option from database
830
- * @param $key
831
- * @return mixed
832
- */
833
- public static function getOption($key) {
834
- if (!isset(self::$options[$key])) {
835
- self::$options = self::getOptions();
836
-
837
- if (!isset(self::$options[$key])) {
838
- self::$options[$key] = false;
839
- }
840
- }
841
-
842
- return apply_filters('sq_option_' . $key, self::$options[$key]);
843
- }
844
-
845
- /**
846
- * Save the Options in user option table in DB
847
- *
848
- * @param null $key
849
- * @param string $value
850
- */
851
- public static function saveOptions($key = null, $value = '') {
852
- if (isset($key)) {
853
- self::$options[$key] = $value;
854
- }
855
-
856
- update_option(SQ_OPTION, wp_json_encode(self::$options));
857
- }
858
-
859
- /**
860
- * Get user metas
861
- * @param null $user_id
862
- * @return array|mixed
863
- */
864
- public static function getUserMetas($user_id = null) {
865
- if (!isset($user_id)) {
866
- $user_id = get_current_user_id();
867
- }
868
-
869
- $default = array('sq_auto_sticky' => 0,);
870
-
871
- $usermeta = get_user_meta($user_id);
872
- $usermetatmp = array();
873
- if (is_array($usermeta)) foreach ($usermeta as $key => $values) {
874
- $usermetatmp[$key] = $values[0];
875
- }
876
- $usermeta = $usermetatmp;
877
-
878
- if (is_array($usermeta)) {
879
- $usermeta = array_merge((array)$default, (array)$usermeta);
880
- } else {
881
- $usermeta = $default;
882
- }
883
- self::$usermeta = $usermeta;
884
- return $usermeta;
885
- }
886
-
887
- /**
888
- * Get use meta
889
- * @param $value
890
- * @return bool
891
- */
892
- public static function getUserMeta($value) {
893
- if (!isset(self::$usermeta[$value])) {
894
- self::getUserMetas();
895
- }
896
-
897
- if (isset(self::$usermeta[$value])) {
898
- return apply_filters('sq_usermeta_' . $value, self::$usermeta[$value]);
899
- }
900
-
901
- return false;
902
- }
903
-
904
- /**
905
- * Save user meta
906
- * @param $key
907
- * @param $value
908
- * @param null $user_id
909
- */
910
- public static function saveUserMeta($key, $value, $user_id = null) {
911
- if (!isset($user_id)) {
912
- $user_id = get_current_user_id();
913
- }
914
- self::$usermeta[$key] = $value;
915
- update_user_meta($user_id, $key, $value);
916
- }
917
-
918
- /**
919
- * Delete User meta
920
- * @param $key
921
- * @param null $user_id
922
- */
923
- public static function deleteUserMeta($key, $user_id = null) {
924
- if (!isset($user_id)) {
925
- $user_id = get_current_user_id();
926
- }
927
- unset(self::$usermeta[$key]);
928
- delete_user_meta($user_id, $key);
929
- }
930
-
931
- /**
932
- * Get the option from database
933
- * @param $key
934
- * @return mixed
935
- */
936
- public static function getMenuVisible($key) {
937
- if(self::$options['sq_auto_devkit']) {
938
- if (!isset(self::$options['menu'][$key])) {
939
- self::$options = self::getOptions();
940
-
941
- if (!isset(self::$options['menu'][$key])) {
942
- self::$options['menu'][$key] = false;
943
- }
944
- }
945
-
946
- return apply_filters('sq_menu_visible', self::$options['menu'][$key], $key);
947
- }
948
-
949
- return true;
950
- }
951
-
952
- /**
953
- * Set the header type
954
- * @param string $type
955
- */
956
- public static function setHeader($type) {
957
- if (self::getValue('sq_debug') == 'on') {
958
- // header("Content-type: text/html");
959
- return;
960
- }
961
-
962
- switch ($type) {
963
- case 'json':
964
- header('Content-Type: application/json');
965
- break;
966
- case 'ico':
967
- header('Content-Type: image/x-icon');
968
- break;
969
- case 'png':
970
- header('Content-Type: image/png');
971
- break;
972
- case'text':
973
- header("Content-type: text/plain");
974
- break;
975
- case'html':
976
- header("Content-type: text/html");
977
- break;
978
- }
979
- }
980
-
981
- /**
982
- * Set the Nonce action
983
- * @param $action
984
- * @param string $name
985
- * @param bool $referer
986
- * @param bool $echo
987
- * @return string
988
- */
989
- public static function setNonce($action, $name = '_wpnonce', $referer = true, $echo = true) {
990
- $name = esc_attr($name);
991
- $nonce_field = '<input type="hidden" name="' . $name . '" value="' . wp_create_nonce($action) . '" />';
992
-
993
- if ($referer) {
994
- $nonce_field .= wp_referer_field(false);
995
- }
996
-
997
- if ($echo) {
998
- echo (string)$nonce_field;
999
- }
1000
-
1001
- return $nonce_field;
1002
- }
1003
-
1004
- /**
1005
- * Get a value from $_POST / $_GET
1006
- * if unavailable, take a default value
1007
- *
1008
- * @param string $key Value key
1009
- * @param mixed $defaultValue (optional)
1010
- * @param bool $htmlcode
1011
- * @param bool $keep_newlines
1012
- * @return mixed Value
1013
- */
1014
- public static function getValue($key, $defaultValue = false, $keep_newlines = false) {
1015
- if (!isset($key) || (isset($key) && $key == '')) {
1016
- return $defaultValue;
1017
- }
1018
-
1019
- if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST') {
1020
- $ret = (isset($_POST[$key]) ? $_POST[$key] : (isset($_GET[$key]) ? $_GET[$key] : ''));
1021
- } else {
1022
- $ret = (isset($_GET[$key]) ? $_GET[$key] : '');
1023
- }
1024
-
1025
- if (is_array($ret)) {
1026
- if (!empty($ret)) {
1027
- foreach ($ret as &$row) {
1028
- if (!is_array($row)) {
1029
- $row = sanitize_text_field($row);
1030
- }
1031
- }
1032
- }
1033
- } elseif (is_string($ret) && $ret <> '') {
1034
- if ($keep_newlines && function_exists('sanitize_textarea_field')) {
1035
- $ret = sanitize_textarea_field($ret);
1036
- } else {
1037
- $ret = sanitize_text_field($ret);
1038
- }
1039
- }
1040
-
1041
- if (!$ret) {
1042
- return $defaultValue;
1043
- } else {
1044
- return wp_unslash($ret);
1045
- }
1046
-
1047
- }
1048
-
1049
- /**
1050
- * Check if the parameter is set
1051
- *
1052
- * @param string $key
1053
- * @return boolean
1054
- */
1055
- public static function getIsset($key) {
1056
- return (isset($_GET[$key]) || isset($_POST[$key]));
1057
- }
1058
-
1059
-
1060
- /**
1061
- * Find the string in the content
1062
- *
1063
- * @param string $content
1064
- * @param string $string
1065
- * @param bool $normalize
1066
- * @return bool|false|int
1067
- */
1068
- public static function findStr($content, $string, $normalize = false) {
1069
- if ($normalize) {
1070
- //Check if the search requires char normalization
1071
- $content = SQ_Classes_Helpers_Sanitize::normalizeChars($content);
1072
- $string = SQ_Classes_Helpers_Sanitize::normalizeChars($string);
1073
- } else {
1074
- //decode the content to match quotes and special chars
1075
- $content = html_entity_decode($content, ENT_QUOTES);
1076
- $string = html_entity_decode($string, ENT_QUOTES);
1077
- }
1078
-
1079
- if (function_exists('mb_stripos')) {
1080
- return mb_stripos($content, $string);
1081
- } else {
1082
- SQ_Classes_Error::setMessage(esc_html__("For better text comparison you need to install PHP mbstring extension.", _SQ_PLUGIN_NAME_));
1083
-
1084
- return stripos($content, $string);
1085
- }
1086
- }
1087
-
1088
- /**
1089
- * Load the multilanguage support from .mo
1090
- */
1091
- private function loadMultilanguage() {
1092
- load_plugin_textdomain(_SQ_PLUGIN_NAME_, false, _SQ_PLUGIN_NAME_ . '/languages/');
1093
- }
1094
-
1095
- /**
1096
- * Hook the activate process
1097
- */
1098
- public function sq_activate() {
1099
- set_transient('sq_activate', true);
1100
- set_transient('sq_import', true);
1101
- SQ_Classes_ObjController::getClass('SQ_Models_RoleManager')->addSQRoles();
1102
- }
1103
-
1104
- /**
1105
- * Hook the deactivate process
1106
- */
1107
- public function sq_deactivate() {
1108
- SQ_Classes_ObjController::getClass('SQ_Models_RoleManager')->removeSQCaps();
1109
- SQ_Classes_ObjController::getClass('SQ_Models_RoleManager')->removeSQRoles();
1110
- }
1111
-
1112
- /**
1113
- * Empty the cache from other plugins
1114
- */
1115
- public static function emptyCache() {
1116
- try {
1117
- //////////////////////////////////////////////////////////////////////////////
1118
- if (function_exists('w3tc_pgcache_flush')) {
1119
- w3tc_pgcache_flush();
1120
- }
1121
-
1122
- if (function_exists('w3tc_minify_flush')) {
1123
- w3tc_minify_flush();
1124
- }
1125
- if (function_exists('w3tc_dbcache_flush')) {
1126
- w3tc_dbcache_flush();
1127
- }
1128
- if (function_exists('w3tc_objectcache_flush')) {
1129
- w3tc_objectcache_flush();
1130
- }
1131
- //////////////////////////////////////////////////////////////////////////////
1132
-
1133
- if (function_exists('wp_cache_clear_cache')) {
1134
- wp_cache_clear_cache();
1135
- }
1136
-
1137
- if (function_exists('rocket_clean_domain') && function_exists('rocket_clean_minify') && function_exists('rocket_clean_cache_busting')) {
1138
- // Remove all cache files
1139
- rocket_clean_domain();
1140
- rocket_clean_minify();
1141
- rocket_clean_cache_busting();
1142
- }
1143
- //////////////////////////////////////////////////////////////////////////////
1144
-
1145
- if (function_exists('apc_clear_cache')) {
1146
- // Remove all apc if enabled
1147
- apc_clear_cache();
1148
- }
1149
- //////////////////////////////////////////////////////////////////////////////
1150
-
1151
- if (class_exists('Cache_Enabler_Disk') && method_exists('Cache_Enabler_Disk', 'clear_cache')) {
1152
- // clear disk cache
1153
- Cache_Enabler_Disk::clear_cache();
1154
- }
1155
- //////////////////////////////////////////////////////////////////////////////
1156
-
1157
- if (class_exists('LiteSpeed_Cache')) {
1158
- LiteSpeed_Cache::get_instance()->purge_all();
1159
- }
1160
- //////////////////////////////////////////////////////////////////////////////
1161
-
1162
- if (self::isPluginInstalled('hummingbird-performance/wp-hummingbird.php')) {
1163
- do_action('wphb_clear_page_cache');
1164
- }
1165
- //////////////////////////////////////////////////////////////////////////////
1166
-
1167
- if (class_exists('WpeCommon')) {
1168
- if (method_exists('WpeCommon', 'purge_memcached')) {
1169
- WpeCommon::purge_memcached();
1170
- }
1171
- if (method_exists('WpeCommon', 'clear_maxcdn_cache')) {
1172
- WpeCommon::clear_maxcdn_cache();
1173
- }
1174
- if (method_exists('WpeCommon', 'purge_varnish_cache')) {
1175
- WpeCommon::purge_varnish_cache();
1176
- }
1177
- }
1178
- //////////////////////////////////////////////////////////////////////////////
1179
-
1180
- if (self::isPluginInstalled('sg-cachepress/sg-cachepress.php') && class_exists('Supercacher')) {
1181
- if (method_exists('Supercacher', 'purge_cache') && method_exists('Supercacher', 'delete_assets')) {
1182
- Supercacher::purge_cache();
1183
- Supercacher::delete_assets();
1184
- }
1185
- }
1186
-
1187
- //Clear the fastest cache
1188
- global $wp_fastest_cache;
1189
- if (isset($wp_fastest_cache) && method_exists($wp_fastest_cache, 'deleteCache')) {
1190
- $wp_fastest_cache->deleteCache();
1191
- }
1192
- //////////////////////////////////////////////////////////////////////////////
1193
- } catch (Exception $e) {
1194
-
1195
- }
1196
- }
1197
-
1198
- /**
1199
- * Check if a plugin is installed
1200
- * @param $name
1201
- * @return bool
1202
- */
1203
- public static function isPluginInstalled($name) {
1204
- if (empty(self::$allplugins)) {
1205
- self::$allplugins = (array)get_option('active_plugins', array());
1206
-
1207
- if (is_multisite()) {
1208
- self::$allplugins = array_merge(array_values(self::$allplugins), array_keys(get_site_option('active_sitewide_plugins')));
1209
- }
1210
- }
1211
-
1212
- if (!empty(self::$allplugins)) {
1213
- return in_array($name, self::$allplugins, true);
1214
- }
1215
-
1216
- return false;
1217
- }
1218
-
1219
- /**
1220
- * Check if frontend and user is logged in
1221
- * @return bool
1222
- */
1223
- public static function isFrontAdmin() {
1224
- return (!is_admin() && (function_exists('is_user_logged_in') && is_user_logged_in()));
1225
- }
1226
-
1227
- /**
1228
- * Check if user is in dashboard
1229
- * @return bool
1230
- */
1231
- public static function isBackedAdmin() {
1232
- return (is_admin() || is_network_admin());
1233
- }
1234
-
1235
- /**
1236
- * Check if the current website is an E-commerce website
1237
- * @return bool
1238
- */
1239
- public static function isEcommerce() {
1240
-
1241
- if(self::isPluginInstalled('woocommerce/woocommerce.php')){
1242
- return true;
1243
- }
1244
-
1245
- $products = array('product', 'wpsc-product');
1246
- $post_types = get_post_types(array('public' => true));
1247
-
1248
- foreach ($products as $type) {
1249
- if (in_array($type, array_keys($post_types))) {
1250
- return true;
1251
- }
1252
- }
1253
-
1254
- return false;
1255
- }
1256
-
1257
- /**
1258
- * Check if it's an AMP Endpoint
1259
- * @return bool|void
1260
- */
1261
- public static function isAMPEndpoint() {
1262
- if (defined('AMPFORWP_AMP_QUERY_VAR')) {
1263
- $url_path = trim(parse_url(add_query_arg(array()), PHP_URL_PATH), '/');
1264
- $explode_path = explode('/', $url_path);
1265
- if (AMPFORWP_AMP_QUERY_VAR === end($explode_path)) {
1266
- return true;
1267
- }
1268
- }
1269
-
1270
- if (function_exists('is_amp_endpoint')) {
1271
- return is_amp_endpoint();
1272
- }
1273
-
1274
- if (function_exists('is_amp') && is_amp()) {
1275
- return is_amp();
1276
- }
1277
-
1278
- if (function_exists('ampforwp_is_amp_endpoint')) {
1279
- return ampforwp_is_amp_endpoint();
1280
- }
1281
-
1282
- return false;
1283
- }
1284
-
1285
- /**
1286
- * Check the user capability for the roles attached
1287
- *
1288
- * @param $cap
1289
- * @param mixed ...$args
1290
- * @return bool
1291
- */
1292
- public static function userCan($cap, ...$args ) {
1293
-
1294
- if (current_user_can($cap, ...$args)) {
1295
- return true;
1296
- }
1297
-
1298
- $user = wp_get_current_user();
1299
- if (count((array)$user->roles) > 1) {
1300
- foreach ($user->roles as $role) {
1301
- $role_object = get_role($role);
1302
- if ($role_object->has_cap($cap)) {
1303
- return true;
1304
- }
1305
- }
1306
- }
1307
-
1308
- return false;
1309
- }
1310
-
1311
- /**
1312
- * Get the admin url for the specific age
1313
- *
1314
- * @param string $page
1315
- * @param string $tab
1316
- * @param array $args
1317
- * @return string
1318
- */
1319
- public static function getAdminUrl($page, $tab = null, $args = array()) {
1320
- if (strpos($page, '.php')) {
1321
- $url = admin_url($page);
1322
- } else {
1323
- $url = admin_url('admin.php?page=' . $page);
1324
- }
1325
-
1326
- if (isset($tab) && $tab <> '') {
1327
- $url .= '&tab=' . $tab;
1328
- }
1329
-
1330
- if (!empty($args)) {
1331
- if (strpos($url, '?') !== false) {
1332
- $url .= '&';
1333
- } else {
1334
- $url .= '?';
1335
- }
1336
- $url .= join('&', $args);
1337
- }
1338
-
1339
- return apply_filters('sq_menu_url', $url, $page, $tab, $args);
1340
- }
1341
-
1342
- /**
1343
- * Instantiates the WordPress filesystem.
1344
- *
1345
- * @static
1346
- * @access public
1347
- * @return object
1348
- */
1349
- public static function initFilesystem() {
1350
- // The WordPress filesystem.
1351
- global $wp_filesystem;
1352
-
1353
- if (!$wp_filesystem || empty($wp_filesystem)) {
1354
- require_once wp_normalize_path(ABSPATH . '/wp-admin/includes/file.php');
1355
- WP_Filesystem();
1356
- }
1357
-
1358
- return $wp_filesystem;
1359
- }
1360
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ /**
5
+ * Handles the parameters and url
6
+ *
7
+ * @author Squirrly
8
+ */
9
+ class SQ_Classes_Helpers_Tools
10
+ {
11
+
12
+ /**
13
+ *
14
+ *
15
+ * @var array Options, User Metas, Package and Plugin details
16
+ */
17
+ public static $options, $usermeta, $allplugins = array();
18
+
19
+ public function __construct()
20
+ {
21
+ self::$options = $this->getOptions();
22
+
23
+ // $maxmemory = self::getMaxMemory();
24
+ // if ($maxmemory && $maxmemory < 60) {
25
+ // @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
26
+ // }
27
+
28
+ SQ_Classes_ObjController::getClass('SQ_Classes_HookController')->setHooks($this);
29
+ }
30
+
31
+ public static function getMaxMemory()
32
+ {
33
+ try {
34
+ $memory_limit = @ini_get('memory_limit');
35
+ if ((int)$memory_limit > 0) {
36
+ if (preg_match('/^(\d+)(.)$/', $memory_limit, $matches)) {
37
+ if ($matches[2] == 'G') {
38
+ $memory_limit = $matches[1] * 1024 * 1024 * 1024; // nnnM -> nnn MB
39
+ } elseif ($matches[2] == 'M') {
40
+ $memory_limit = $matches[1] * 1024 * 1024; // nnnM -> nnn MB
41
+ } elseif ($matches[2] == 'K') {
42
+ $memory_limit = $matches[1] * 1024; // nnnK -> nnn KB
43
+ }
44
+ }
45
+
46
+ if ((int)$memory_limit > 0) {
47
+ return number_format($memory_limit / 1024 / 1024, 0, '', '');
48
+ }
49
+ }
50
+ } catch (Exception $e) {
51
+ }
52
+
53
+ return false;
54
+
55
+ }
56
+
57
+ public static function isAjax()
58
+ {
59
+ return (defined('DOING_AJAX') && DOING_AJAX);
60
+ }
61
+
62
+ /**
63
+ * This hook will save the current version in database
64
+ *
65
+ * @return void
66
+ */
67
+ function hookInit()
68
+ {
69
+ //Load the languages pack
70
+ $this->loadMultilanguage();
71
+
72
+ //add extra links to the plugin in the Plugins list
73
+ add_filter("plugin_row_meta", array($this, 'hookExtraLinks'), 10, 4);
74
+ //add setting link in plugin
75
+ add_filter('plugin_action_links', array($this, 'hookActionlink'), 5, 2);
76
+ }
77
+
78
+ /**
79
+ * Add a link to settings in the plugin list
80
+ *
81
+ * @param array $links
82
+ * @param string $file
83
+ * @return array
84
+ */
85
+ public function hookActionlink($links, $file)
86
+ {
87
+ if ($file == _SQ_PLUGIN_NAME_ . '/squirrly.php') {
88
+ $link = '<a href="' . self::getAdminUrl('sq_dashboard') . '">' . esc_html__("Getting started", 'squirrly-seo') . '</a>';
89
+ array_unshift($links, $link);
90
+ }
91
+
92
+ return $links;
93
+ }
94
+
95
+ /**
96
+ * Adds extra links to plugin page
97
+ *
98
+ * @param $meta
99
+ * @param $file
100
+ * @param $data
101
+ * @param $status
102
+ * @return array
103
+ */
104
+ public function hookExtraLinks($meta, $file, $data = null, $status = null)
105
+ {
106
+ if ($file == _SQ_PLUGIN_NAME_ . '/squirrly.php') {
107
+ echo '<style>
108
+ .ml-stars{display:inline-block;color:#ffb900;position:relative;top:3px}
109
+ .ml-stars svg{fill:#ffb900}
110
+ .ml-stars svg:hover{fill:#ffb900}
111
+ .ml-stars svg:hover ~ svg{fill:none}
112
+ </style>';
113
+
114
+ $meta[] = "<a href='https://howto.squirrly.co/wordpress-seo/' target='_blank'>" . esc_html__("Documentation", 'squirrly-seo') . "</a>";
115
+ $meta[] = "<a href='https://wordpress.org/support/plugin/squirrly-seo/reviews/#new-post' target='_blank' title='" . esc_html__("Leave a review", 'squirrly-seo') . "'><i class='ml-stars'><svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg><svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg><svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg><svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg><svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg></i></a>";
116
+ }
117
+ return $meta;
118
+ }
119
+
120
+ /**
121
+ * Load the Options from user option table in DB
122
+ *
123
+ * @param string $action
124
+ * @return array|mixed|object
125
+ */
126
+ public static function getOptions($action = '')
127
+ {
128
+ $default = array(
129
+ //Global settings
130
+ 'sq_api' => '',
131
+ 'sq_installed' => date('Y-m-d H:i:s'),
132
+ //
133
+ 'sq_cloud_connect' => 0,
134
+ 'sq_cloud_token' => false,
135
+ 'sq_offer' => false,
136
+ 'sq_alert_overview' => true,
137
+ 'sq_alert_journey' => true,
138
+ //Advanced settings
139
+ 'sq_seoexpert' => 0,
140
+ //later buffer load
141
+ 'sq_laterload' => 0,
142
+ 'sq_audit_email' => '',
143
+
144
+ //SEO Journey
145
+ 'sq_seojourney' => 0,
146
+ 'sq_seojourney_congrats' => 1,
147
+ 'sq_menu_visited' => array(),
148
+
149
+ //minify Squirrly Metas
150
+ 'sq_load_css' => 1,
151
+ 'sq_minify' => 0,
152
+ 'sq_non_utf8_support' => 1,
153
+
154
+ //Settings Assistant
155
+ 'sq_assistant' => 1,
156
+ 'sq_complete_uninstall' => 0,
157
+
158
+ //Onboarding
159
+ 'sq_onboarding' => 0,
160
+ 'sq_onboarding_data' => array(),
161
+
162
+ //Live Assistant
163
+ 'sq_sla' => 1,
164
+ 'sq_sla_frontend' => 1,
165
+ 'sq_sla_type' => 'auto',
166
+ 'sq_sla_exclude_post_types' => array(),
167
+ 'sq_keyword_help' => 1,
168
+ 'sq_local_images' => 0,
169
+ 'sq_img_licence' => 1,
170
+ 'sq_sla_social_fetch' => 1,
171
+
172
+ //JsonLD
173
+ 'sq_auto_jsonld' => 1,
174
+ 'sq_auto_jsonld_local' => 0,
175
+ 'sq_jsonld_type' => 'Organization',
176
+ 'sq_jsonld_global_person' => 0,
177
+ 'sq_jsonld_breadcrumbs' => 1,
178
+ 'sq_jsonld_woocommerce' => 1,
179
+ 'sq_jsonld_clearcode' => 0,
180
+ 'sq_jsonld_product_rating' => 0,
181
+ 'sq_jsonld_product_custom' => 1,
182
+ 'sq_jsonld_product_defaults' => 1,
183
+ 'sq_jsonld_local' => array(
184
+ 'priceRange' => '',
185
+ 'servesCuisine' => '',
186
+ 'menu' => '',
187
+ 'acceptsReservations' => '',
188
+ 'openingHoursSpecification' => array(
189
+ array(
190
+ '@type' => 'OpeningHoursSpecification',
191
+ 'dayOfWeek' => 'Monday',
192
+ 'opens' => '',
193
+ 'closes' => '',
194
+ ),
195
+ array(
196
+ '@type' => 'OpeningHoursSpecification',
197
+ 'dayOfWeek' => 'Tuesday',
198
+ 'opens' => '',
199
+ 'closes' => '',
200
+ ),
201
+ array(
202
+ '@type' => 'OpeningHoursSpecification',
203
+ 'dayOfWeek' => 'Wednesday',
204
+ 'opens' => '',
205
+ 'closes' => '',
206
+ ),
207
+ array(
208
+ '@type' => 'OpeningHoursSpecification',
209
+ 'dayOfWeek' => 'Thursday',
210
+ 'opens' => '',
211
+ 'closes' => '',
212
+ ),
213
+ array(
214
+ '@type' => 'OpeningHoursSpecification',
215
+ 'dayOfWeek' => 'Friday',
216
+ 'opens' => '',
217
+ 'closes' => '',
218
+ ),
219
+ array(
220
+ '@type' => 'OpeningHoursSpecification',
221
+ 'dayOfWeek' => 'Saturday',
222
+ 'opens' => '',
223
+ 'closes' => '',
224
+ ),
225
+ array(
226
+ '@type' => 'OpeningHoursSpecification',
227
+ 'dayOfWeek' => 'Sunday',
228
+ 'opens' => '',
229
+ 'closes' => '',
230
+ ),
231
+
232
+ ),
233
+ ),
234
+ 'sq_jsonld' => array(
235
+ 'Organization' => array(
236
+ 'name' => '',
237
+ 'logo' => array(
238
+ '@type' => 'ImageObject',
239
+ 'url' => '',
240
+ ),
241
+ 'contactPoint' => array(
242
+ '@type' => 'ContactPoint',
243
+ 'telephone' => '',
244
+ 'contactType' => '',
245
+ ),
246
+ 'address' => array(
247
+ '@type' => 'PostalAddress',
248
+ 'streetAddress' => '',
249
+ 'addressLocality' => '',
250
+ 'addressRegion' => '',
251
+ 'postalCode' => '',
252
+ 'addressCountry' => '',
253
+ ),
254
+ 'place' => array(
255
+ '@type' => 'Place',
256
+ 'geo' => array(
257
+ '@type' => 'GeoCoordinates',
258
+ 'latitude' => '',
259
+ 'longitude' => '',
260
+ ),
261
+
262
+ ),
263
+
264
+ 'description' => ''
265
+ ),
266
+ 'Person' => array(
267
+ 'name' => '',
268
+ 'image' => array(
269
+ '@type' => 'ImageObject',
270
+ 'url' => '',
271
+ ),
272
+ 'telephone' => '',
273
+ 'jobTitle' => '',
274
+ 'description' => ''
275
+ )),
276
+
277
+ //Sitemap
278
+ 'sq_auto_sitemap' => 1,
279
+ 'sq_sitemap_ping' => 0,
280
+ 'sq_sitemap_exclude_noindex' => 0,
281
+ 'sq_sitemap_show' => array(
282
+ 'images' => 1,
283
+ 'videos' => 0,
284
+ ),
285
+ 'sq_sitemap_perpage' => 500,
286
+ 'sq_sitemap_frequency' => 'weekly',
287
+ 'sq_sitemap_combinelangs' => 0,
288
+ 'sq_sitemap' => array(
289
+ 'sitemap' => array('sitemap.xml', 1),
290
+ 'sitemap-home' => array('sitemap-home.xml', 1),
291
+ 'sitemap-news' => array('sitemap-news.xml', 0),
292
+ 'sitemap-product' => array('sitemap-product.xml', 1),
293
+ 'sitemap-post' => array('sitemap-posts.xml', 1),
294
+ 'sitemap-page' => array('sitemap-pages.xml', 1),
295
+ 'sitemap-category' => array('sitemap-categories.xml', 1),
296
+ 'sitemap-post_tag' => array('sitemap-tags.xml', 1),
297
+ 'sitemap-archive' => array('sitemap-archives.xml', 1),
298
+ 'sitemap-author' => array('sitemap-authors.xml', 0),
299
+ 'sitemap-custom-tax' => array('sitemap-custom-taxonomies.xml', 0),
300
+ 'sitemap-custom-post' => array('sitemap-custom-posts.xml', 0),
301
+ 'sitemap-attachment' => array('sitemap-attachment.xml', 0),
302
+ ),
303
+
304
+ //Robots
305
+ 'sq_auto_robots' => 1,
306
+ 'sq_robots_permission' => array(
307
+ 'User-agent: *',
308
+ 'Disallow: */trackback/',
309
+ 'Disallow: */xmlrpc.php',
310
+ 'Disallow: /wp-*.php',
311
+ 'Disallow: /cgi-bin/',
312
+ 'Disallow: /wp-admin/',
313
+ 'Allow: */wp-content/uploads/',),
314
+
315
+ //Metas
316
+ 'sq_use' => 1,
317
+ 'sq_auto_metas' => 1,
318
+ 'sq_auto_links' => 0,
319
+ 'sq_auto_redirects' => 1,
320
+ 'sq_auto_title' => 1,
321
+ 'sq_auto_description' => 1,
322
+ 'sq_auto_keywords' => 1,
323
+ 'sq_keywordtag' => 0,
324
+ 'sq_auto_canonical' => 1,
325
+ 'sq_auto_dublincore' => 0,
326
+ 'sq_auto_feed' => 0,
327
+ 'sq_auto_noindex' => 1,
328
+ 'sq_use_frontend' => 1,
329
+ 'sq_attachment_redirect' => 0,
330
+ 'sq_term_noindex_empty' => 1,
331
+ '404_url_redirect' => home_url(),
332
+ 'sq_external_nofollow' => 1,
333
+ 'sq_external_exception' => array(),
334
+ 'sq_external_blank' => 0,
335
+ 'sq_metas' => array(
336
+ 'title_maxlength' => 75,
337
+ 'description_maxlength' => 320,
338
+ 'og_title_maxlength' => 75,
339
+ 'og_description_maxlength' => 200,
340
+ 'tw_title_maxlength' => 75,
341
+ 'tw_description_maxlength' => 280,
342
+ 'jsonld_title_maxlength' => 75,
343
+ 'jsonld_description_maxlength' => 320,
344
+ ),
345
+
346
+ //favicon
347
+ 'sq_auto_favicon' => 0,
348
+ 'sq_favicon_apple' => 1,
349
+ 'favicon' => '',
350
+
351
+ //Ranking Option
352
+ 'sq_google_country' => 'com',
353
+ 'sq_google_language' => 'en',
354
+ 'sq_google_device' => 'desktop',
355
+ 'sq_google_serpsperhour' => 500,
356
+ 'connect' => array(
357
+ 'google_analytics' => 0,
358
+ 'google_search_console' => 0,
359
+ ),
360
+
361
+ // dev kit
362
+ 'sq_auto_devkit' => 1,
363
+ 'sq_devkit_logo' => false,
364
+ 'sq_devkit_name' => false,
365
+ 'sq_devkit_menu_name' => false,
366
+ 'sq_devkit_audit_success' => false,
367
+ 'sq_devkit_audit_fail' => false,
368
+ //menu restrictions
369
+ 'menu' => array(
370
+ 'show_account_info' => 1,
371
+ 'show_journey' => 1,
372
+ 'show_panel' => 1,
373
+ 'show_tutorial' => 1,
374
+ 'show_audit' => 1,
375
+ 'show_assistant' => 1,
376
+ 'show_bulkseo' => 1,
377
+ 'show_research' => 1,
378
+ 'show_rankings' => 1,
379
+ 'show_focuspages' => 1,
380
+ 'show_seogoals' => 1,
381
+ 'show_ads' => 1,
382
+ ),
383
+
384
+ //socials
385
+ 'sq_auto_social' => 1,
386
+ 'sq_auto_facebook' => 1,
387
+ 'sq_auto_twitter' => 1,
388
+ 'sq_og_locale' => 'en_US',
389
+ 'sq_og_image' => '',
390
+ 'sq_tc_image' => '',
391
+
392
+ 'socials' => array(
393
+ 'fb_admins' => array(),
394
+ 'fbconnectkey' => "",
395
+ 'fbadminapp' => "",
396
+
397
+ 'facebook_site' => "",
398
+ 'twitter_site' => "https://twitter.com/twitter",
399
+ 'twitter' => "",
400
+ 'instagram_url' => "",
401
+ 'linkedin_url' => "",
402
+ 'myspace_url' => "",
403
+ 'pinterest_url' => "",
404
+ 'youtube_url' => "",
405
+ 'twitter_card_type' => "summary_large_image",
406
+ 'plus_publisher' => ""
407
+ ),
408
+
409
+ //Webmasters and Tracking
410
+ 'sq_auto_amp' => 1,
411
+ 'sq_auto_tracking' => 1,
412
+ 'sq_auto_pixels' => 1,
413
+ 'sq_tracking_logged_users' => 1,
414
+ 'sq_tracking_ip_users' => 1,
415
+ 'sq_auto_webmasters' => 1,
416
+ 'sq_analytics_google_js' => 'analytics',
417
+ 'codes' => array(
418
+ 'google_wt' => "",
419
+ 'google_analytics' => "",
420
+ 'facebook_pixel' => "",
421
+
422
+ 'bing_wt' => "",
423
+ 'baidu_wt' => "",
424
+ 'yandex_wt' => "",
425
+ 'pinterest_verify' => "",
426
+ 'alexa_verify' => "",
427
+ 'norton_verify' => "",
428
+ ),
429
+
430
+ //Patterns
431
+ 'sq_auto_pattern' => 1,
432
+ 'patterns' => array(
433
+ 'home' => array(
434
+ 'protected' => 1,
435
+ 'sep' => '|',
436
+ 'title' => '{{sitename}} {{page}} {{sep}} {{sitedesc}}',
437
+ 'description' => '{{excerpt}} {{page}} {{sep}} {{sitename}}',
438
+ 'noindex' => 0,
439
+ 'nofollow' => 0,
440
+ 'og_type' => 'website',
441
+ 'jsonld_types' => array('website'),
442
+ 'do_metas' => 1,
443
+ 'do_sitemap' => 1,
444
+ 'do_jsonld' => 1,
445
+ 'do_pattern' => 1,
446
+ 'do_og' => 1,
447
+ 'do_twc' => 1,
448
+ 'do_analytics' => 1,
449
+ 'do_fpixel' => 1,
450
+ 'do_redirects' => 0,
451
+ ),
452
+ 'post' => array(
453
+ 'protected' => 1,
454
+ 'sep' => '|',
455
+ 'title' => '{{title}} {{page}}',
456
+ 'description' => '{{excerpt}}',
457
+ 'noindex' => 0,
458
+ 'nofollow' => 0,
459
+ 'og_type' => 'article',
460
+ 'jsonld_types' => array('newsarticle'),
461
+ 'do_metas' => 1,
462
+ 'do_sitemap' => 1,
463
+ 'do_jsonld' => 1,
464
+ 'do_pattern' => 1,
465
+ 'do_og' => 1,
466
+ 'do_twc' => 1,
467
+ 'do_analytics' => 1,
468
+ 'do_fpixel' => 1,
469
+ 'do_redirects' => 1,
470
+ ),
471
+ 'page' => array(
472
+ 'protected' => 1,
473
+ 'sep' => '|',
474
+ 'title' => '{{title}} {{page}} {{sep}} {{sitename}}',
475
+ 'description' => '{{excerpt}}',
476
+ 'noindex' => 0,
477
+ 'nofollow' => 0,
478
+ 'og_type' => 'website',
479
+ 'jsonld_types' => array('website'),
480
+ 'do_metas' => 1,
481
+ 'do_sitemap' => 1,
482
+ 'do_jsonld' => 1,
483
+ 'do_pattern' => 1,
484
+ 'do_og' => 1,
485
+ 'do_twc' => 1,
486
+ 'do_analytics' => 1,
487
+ 'do_fpixel' => 1,
488
+ 'do_redirects' => 1,
489
+ ),
490
+ 'product' => array(
491
+ 'protected' => 1,
492
+ 'sep' => '|',
493
+ 'title' => '{{title}} {{page}} {{sep}} {{sitename}}',
494
+ 'description' => '{{excerpt}}',
495
+ 'noindex' => 0,
496
+ 'nofollow' => 0,
497
+ 'og_type' => 'product',
498
+ 'jsonld_types' => array('product'),
499
+ 'do_metas' => 1,
500
+ 'do_sitemap' => 1,
501
+ 'do_jsonld' => 1,
502
+ 'do_pattern' => 1,
503
+ 'do_og' => 1,
504
+ 'do_twc' => 1,
505
+ 'do_analytics' => 1,
506
+ 'do_fpixel' => 1,
507
+ 'do_redirects' => 1,
508
+ ),
509
+ 'category' => array(
510
+ 'protected' => 1,
511
+ 'sep' => '|',
512
+ 'title' => '{{category}} {{page}} {{sep}} {{sitename}}',
513
+ 'description' => '{{category_description}}',
514
+ 'noindex' => 0,
515
+ 'nofollow' => 0,
516
+ 'og_type' => 'website',
517
+ 'jsonld_types' => array('website'),
518
+ 'do_metas' => 1,
519
+ 'do_sitemap' => 1,
520
+ 'do_jsonld' => 0,
521
+ 'do_pattern' => 1,
522
+ 'do_og' => 1,
523
+ 'do_twc' => 1,
524
+ 'do_analytics' => 1,
525
+ 'do_fpixel' => 1,
526
+ 'do_redirects' => 0,
527
+ ),
528
+ 'tag' => array(
529
+ 'protected' => 1,
530
+ 'sep' => '|',
531
+ 'title' => '{{tag}} {{page}} {{sep}} {{sitename}}',
532
+ 'description' => '{{excerpt}}',
533
+ 'noindex' => 0,
534
+ 'nofollow' => 0,
535
+ 'og_type' => 'website',
536
+ 'jsonld_types' => array('website'),
537
+ 'do_metas' => 1,
538
+ 'do_sitemap' => 1,
539
+ 'do_jsonld' => 0,
540
+ 'do_pattern' => 1,
541
+ 'do_og' => 1,
542
+ 'do_twc' => 1,
543
+ 'do_analytics' => 1,
544
+ 'do_fpixel' => 1,
545
+ 'do_redirects' => 0,
546
+ ),
547
+ 'tax-product_cat' => array(
548
+ 'protected' => 1,
549
+ 'sep' => '|',
550
+ 'title' => '{{term_title}} ' . esc_html__("Category", 'squirrly-seo') . ' {{page}} {{sep}} {{sitename}}',
551
+ 'description' => '{{excerpt}}',
552
+ 'noindex' => 0,
553
+ 'nofollow' => 0,
554
+ 'og_type' => 'website',
555
+ 'jsonld_types' => array('website'),
556
+ 'do_metas' => 1,
557
+ 'do_sitemap' => 1,
558
+ 'do_jsonld' => 1,
559
+ 'do_pattern' => 1,
560
+ 'do_og' => 1,
561
+ 'do_twc' => 1,
562
+ 'do_analytics' => 1,
563
+ 'do_fpixel' => 1,
564
+ 'do_redirects' => 0,
565
+ ),
566
+ 'tax-product_tag' => array(
567
+ 'protected' => 1,
568
+ 'sep' => '|',
569
+ 'title' => '{{term_title}} ' . esc_html__("Tag", 'squirrly-seo') . ' {{page}} {{sep}} {{sitename}}',
570
+ 'description' => '{{excerpt}}',
571
+ 'noindex' => 0,
572
+ 'nofollow' => 0,
573
+ 'og_type' => 'website',
574
+ 'jsonld_types' => array('website'),
575
+ 'do_metas' => 1,
576
+ 'do_sitemap' => 1,
577
+ 'do_jsonld' => 1,
578
+ 'do_pattern' => 1,
579
+ 'do_og' => 1,
580
+ 'do_twc' => 1,
581
+ 'do_analytics' => 1,
582
+ 'do_fpixel' => 1,
583
+ 'do_redirects' => 0,
584
+ ),
585
+ 'tax-post_format' => array(
586
+ 'protected' => 1,
587
+ 'sep' => '|',
588
+ 'title' => '{{term_title}} ' . esc_html__("Format", 'squirrly-seo') . ' {{page}} {{sep}} {{sitename}}',
589
+ 'description' => '{{excerpt}}',
590
+ 'noindex' => 0,
591
+ 'nofollow' => 0,
592
+ 'og_type' => 'website',
593
+ 'jsonld_types' => array('website'),
594
+ 'do_metas' => 1,
595
+ 'do_sitemap' => 1,
596
+ 'do_jsonld' => 1,
597
+ 'do_pattern' => 1,
598
+ 'do_og' => 1,
599
+ 'do_twc' => 1,
600
+ 'do_analytics' => 1,
601
+ 'do_fpixel' => 1,
602
+ 'do_redirects' => 0,
603
+ ),
604
+ 'tax-category' => array(
605
+ 'protected' => 1,
606
+ 'sep' => '|',
607
+ 'title' => '{{term_title}} ' . esc_html__("Category", 'squirrly-seo') . ' {{page}} {{sep}} {{sitename}}',
608
+ 'description' => '{{excerpt}}',
609
+ 'noindex' => 0,
610
+ 'nofollow' => 0,
611
+ 'og_type' => 'website',
612
+ 'jsonld_types' => array('website'),
613
+ 'do_metas' => 1,
614
+ 'do_sitemap' => 1,
615
+ 'do_jsonld' => 1,
616
+ 'do_pattern' => 1,
617
+ 'do_og' => 1,
618
+ 'do_twc' => 1,
619
+ 'do_analytics' => 1,
620
+ 'do_fpixel' => 1,
621
+ 'do_redirects' => 0,
622
+ ),
623
+ 'tax-post_tag' => array(
624
+ 'protected' => 1,
625
+ 'sep' => '|',
626
+ 'title' => '{{term_title}} ' . esc_html__("Tag", 'squirrly-seo') . ' {{page}} {{sep}} {{sitename}}',
627
+ 'description' => '{{excerpt}}',
628
+ 'noindex' => 0,
629
+ 'nofollow' => 0,
630
+ 'og_type' => 'website',
631
+ 'jsonld_types' => array('website'),
632
+ 'do_metas' => 1,
633
+ 'do_sitemap' => 1,
634
+ 'do_jsonld' => 1,
635
+ 'do_pattern' => 1,
636
+ 'do_og' => 1,
637
+ 'do_twc' => 1,
638
+ 'do_analytics' => 1,
639
+ 'do_fpixel' => 1,
640
+ 'do_redirects' => 0,
641
+ ),
642
+ 'tax-product_shipping_class' => array(
643
+ 'protected' => 1,
644
+ 'sep' => '|',
645
+ 'title' => '{{term_title}} ' . esc_html__("Shipping Option", 'squirrly-seo') . ' {{page}} {{sep}} {{sitename}}',
646
+ 'description' => '{{excerpt}}',
647
+ 'noindex' => 0,
648
+ 'nofollow' => 0,
649
+ 'og_type' => 'website',
650
+ 'jsonld_types' => array('website'),
651
+ 'do_metas' => 1,
652
+ 'do_sitemap' => 1,
653
+ 'do_jsonld' => 1,
654
+ 'do_pattern' => 1,
655
+ 'do_og' => 1,
656
+ 'do_twc' => 1,
657
+ 'do_analytics' => 1,
658
+ 'do_fpixel' => 1,
659
+ 'do_redirects' => 0,
660
+ ),
661
+ 'shop' => array(
662
+ 'protected' => 1,
663
+ 'sep' => '|',
664
+ 'title' => '{{title}} {{page}} {{sep}} {{sitename}}',
665
+ 'description' => '{{excerpt}}',
666
+ 'noindex' => 0,
667
+ 'nofollow' => 0,
668
+ 'og_type' => 'website',
669
+ 'jsonld_types' => array('website'),
670
+ 'do_metas' => 1,
671
+ 'do_sitemap' => 1,
672
+ 'do_jsonld' => 1,
673
+ 'do_pattern' => 1,
674
+ 'do_og' => 1,
675
+ 'do_twc' => 1,
676
+ 'do_analytics' => 1,
677
+ 'do_fpixel' => 1,
678
+ 'do_redirects' => 0,
679
+ ),
680
+ 'profile' => array(
681
+ 'protected' => 1,
682
+ 'sep' => '|',
683
+ 'title' => '{{name}}, ' . esc_html__("Author at", 'squirrly-seo') . ' {{sitename}} {{page}}',
684
+ 'description' => '{{excerpt}}',
685
+ 'noindex' => 0,
686
+ 'nofollow' => 0,
687
+ 'og_type' => 'profile',
688
+ 'jsonld_types' => array('profile'),
689
+ 'do_metas' => 1,
690
+ 'do_sitemap' => 1,
691
+ 'do_jsonld' => 1,
692
+ 'do_pattern' => 1,
693
+ 'do_og' => 1,
694
+ 'do_twc' => 1,
695
+ 'do_analytics' => 1,
696
+ 'do_fpixel' => 1,
697
+ 'do_redirects' => 0,
698
+ ),
699
+ 'archive' => array(
700
+ 'protected' => 1,
701
+ 'sep' => '|',
702
+ 'title' => '{{plural}} {{date}} {{page}} {{sep}} {{sitename}}',
703
+ 'description' => '{{excerpt}}',
704
+ 'noindex' => 0,
705
+ 'nofollow' => 0,
706
+ 'og_type' => 'website',
707
+ 'jsonld_types' => array('website'),
708
+ 'do_metas' => 1,
709
+ 'do_sitemap' => 1,
710
+ 'do_jsonld' => 1,
711
+ 'do_pattern' => 1,
712
+ 'do_og' => 1,
713
+ 'do_twc' => 1,
714
+ 'do_analytics' => 1,
715
+ 'do_fpixel' => 1,
716
+ 'do_redirects' => 0,
717
+ ),
718
+ 'search' => array(
719
+ 'protected' => 1,
720
+ 'sep' => '|',
721
+ 'title' => esc_html__("Are you looking for", 'squirrly-seo') . ' {{searchphrase}}? {{page}} {{sep}} {{sitename}}',
722
+ 'description' => esc_html__("These are the results for", 'squirrly-seo') . ' {{searchphrase}} ' . esc_html__("that you can find on our website.", 'squirrly-seo') . ' {{excerpt}}',
723
+ 'noindex' => 1,
724
+ 'nofollow' => 0,
725
+ 'og_type' => 'website',
726
+ 'jsonld_types' => array('website'),
727
+ 'do_metas' => 1,
728
+ 'do_sitemap' => 0,
729
+ 'do_jsonld' => 1,
730
+ 'do_pattern' => 1,
731
+ 'do_og' => 1,
732
+ 'do_twc' => 1,
733
+ 'do_analytics' => 1,
734
+ 'do_fpixel' => 1,
735
+ ),
736
+ 'attachment' => array(
737
+ 'protected' => 1,
738
+ 'sep' => '|',
739
+ 'title' => '{{title}} {{page}} {{sep}} {{sitename}}',
740
+ 'description' => '{{excerpt}}',
741
+ 'noindex' => 0,
742
+ 'nofollow' => 0,
743
+ 'og_type' => 'website',
744
+ 'jsonld_types' => array('website'),
745
+ 'do_metas' => 1,
746
+ 'do_sitemap' => 1,
747
+ 'do_jsonld' => 1,
748
+ 'do_pattern' => 1,
749
+ 'do_og' => 1,
750
+ 'do_twc' => 1,
751
+ 'do_analytics' => 1,
752
+ 'do_fpixel' => 1,
753
+ 'do_redirects' => 1,
754
+ ),
755
+ '404' => array(
756
+ 'protected' => 1,
757
+ 'sep' => '|',
758
+ 'title' => esc_html__("Page not found", 'squirrly-seo') . ' {{sep}} {{sitename}}',
759
+ 'description' => esc_html__("This page could not be found on our website.", 'squirrly-seo') . ' {{excerpt}}',
760
+ 'noindex' => 1,
761
+ 'nofollow' => 1,
762
+ 'og_type' => 'website',
763
+ 'jsonld_types' => array('website'),
764
+ 'do_metas' => 1,
765
+ 'do_sitemap' => 0,
766
+ 'do_jsonld' => 0,
767
+ 'do_pattern' => 1,
768
+ 'do_og' => 0,
769
+ 'do_twc' => 0,
770
+ 'do_analytics' => 1,
771
+ 'do_fpixel' => 1,
772
+ 'do_redirects' => 0,
773
+ ),
774
+ 'custom' => array(
775
+ 'protected' => 1,
776
+ 'sep' => '|',
777
+ 'title' => '{{title}} {{page}} {{sep}} {{sitename}}',
778
+ 'description' => '{{excerpt}}',
779
+ 'noindex' => 0,
780
+ 'nofollow' => 0,
781
+ 'og_type' => 'website',
782
+ 'jsonld_types' => array('website'),
783
+ 'do_metas' => 1,
784
+ 'do_sitemap' => 1,
785
+ 'do_jsonld' => 1,
786
+ 'do_pattern' => 1,
787
+ 'do_og' => 1,
788
+ 'do_twc' => 1,
789
+ 'do_analytics' => 1,
790
+ 'do_fpixel' => 1,
791
+ 'do_redirects' => 0,
792
+ ),
793
+ )
794
+
795
+ );
796
+ $options = json_decode(get_option(SQ_OPTION), true);
797
+
798
+ //Update the Json-LD for Organization Logo
799
+ if (isset($options['sq_jsonld']['Organization']['logo']) && !is_array($options['sq_jsonld']['Organization']['logo'])) {
800
+ $options['sq_jsonld']['Organization']['logo'] = array(
801
+ '@type' => 'ImageObject',
802
+ 'url' => $options['sq_jsonld']['Organization']['logo'],
803
+ );
804
+ }
805
+
806
+ if (isset($options['sq_jsonld']['Organization']['telephone']) && isset($options['sq_jsonld']['Organization']['contactType'])) {
807
+ $options['sq_jsonld']['Organization']['contactPoint'] = array(
808
+ '@type' => 'ContactPoint',
809
+ 'telephone' => $options['sq_jsonld']['Organization']['telephone'],
810
+ 'contactType' => $options['sq_jsonld']['Organization']['contactType']
811
+ );
812
+
813
+ unset($options['sq_jsonld']['Organization']['telephone']);
814
+ unset($options['sq_jsonld']['Organization']['contactType']);
815
+ }
816
+
817
+ //Update the Json-LD for Person Image
818
+ if (isset($options['sq_jsonld']['Person']['logo'])) {
819
+ $options['sq_jsonld']['Person']['image'] = array(
820
+ '@type' => 'ImageObject',
821
+ 'url' => $options['sq_jsonld']['Person']['logo'],
822
+ );
823
+
824
+ unset($options['sq_jsonld']['Person']['logo']);
825
+ }
826
+
827
+ if ($action == 'reset') {
828
+ $init['sq_api'] = $options['sq_api'];
829
+ return $init;
830
+ }
831
+
832
+ if (is_array($options)) {
833
+ $options = array_replace_recursive((array)$default, (array)$options);
834
+ return $options;
835
+ }
836
+
837
+ return $default;
838
+ }
839
+
840
+ /**
841
+ * Get the option from database
842
+ *
843
+ * @param $key
844
+ * @return mixed
845
+ */
846
+ public static function getOption($key)
847
+ {
848
+ if (!isset(self::$options[$key])) {
849
+ self::$options = self::getOptions();
850
+
851
+ if (!isset(self::$options[$key])) {
852
+ self::$options[$key] = false;
853
+ }
854
+ }
855
+
856
+ return apply_filters('sq_option_' . $key, self::$options[$key]);
857
+ }
858
+
859
+ /**
860
+ * Save the Options in user option table in DB
861
+ *
862
+ * @param null $key
863
+ * @param string $value
864
+ */
865
+ public static function saveOptions($key = null, $value = '')
866
+ {
867
+ if (isset($key)) {
868
+ self::$options[$key] = $value;
869
+ }
870
+
871
+ update_option(SQ_OPTION, wp_json_encode(self::$options));
872
+ }
873
+
874
+ /**
875
+ * Get user metas
876
+ *
877
+ * @param null $user_id
878
+ * @return array|mixed
879
+ */
880
+ public static function getUserMetas($user_id = null)
881
+ {
882
+ if (!isset($user_id)) {
883
+ $user_id = get_current_user_id();
884
+ }
885
+
886
+ $default = array('sq_auto_sticky' => 0,);
887
+
888
+ $usermeta = get_user_meta($user_id);
889
+ $usermetatmp = array();
890
+ if (is_array($usermeta)) foreach ($usermeta as $key => $values) {
891
+ $usermetatmp[$key] = $values[0];
892
+ }
893
+ $usermeta = $usermetatmp;
894
+
895
+ if (is_array($usermeta)) {
896
+ $usermeta = array_merge((array)$default, (array)$usermeta);
897
+ } else {
898
+ $usermeta = $default;
899
+ }
900
+ self::$usermeta = $usermeta;
901
+ return $usermeta;
902
+ }
903
+
904
+ /**
905
+ * Get use meta
906
+ *
907
+ * @param $value
908
+ * @return bool
909
+ */
910
+ public static function getUserMeta($value)
911
+ {
912
+ if (!isset(self::$usermeta[$value])) {
913
+ self::getUserMetas();
914
+ }
915
+
916
+ if (isset(self::$usermeta[$value])) {
917
+ return apply_filters('sq_usermeta_' . $value, self::$usermeta[$value]);
918
+ }
919
+
920
+ return false;
921
+ }
922
+
923
+ /**
924
+ * Save user meta
925
+ *
926
+ * @param $key
927
+ * @param $value
928
+ * @param null $user_id
929
+ */
930
+ public static function saveUserMeta($key, $value, $user_id = null)
931
+ {
932
+ if (!isset($user_id)) {
933
+ $user_id = get_current_user_id();
934
+ }
935
+ self::$usermeta[$key] = $value;
936
+ update_user_meta($user_id, $key, $value);
937
+ }
938
+
939
+ /**
940
+ * Delete User meta
941
+ *
942
+ * @param $key
943
+ * @param null $user_id
944
+ */
945
+ public static function deleteUserMeta($key, $user_id = null)
946
+ {
947
+ if (!isset($user_id)) {
948
+ $user_id = get_current_user_id();
949
+ }
950
+ unset(self::$usermeta[$key]);
951
+ delete_user_meta($user_id, $key);
952
+ }
953
+
954
+ /**
955
+ * Get the option from database
956
+ *
957
+ * @param $key
958
+ * @return mixed
959
+ */
960
+ public static function getMenuVisible($key)
961
+ {
962
+ if(self::$options['sq_auto_devkit']) {
963
+ if (!isset(self::$options['menu'][$key])) {
964
+ self::$options = self::getOptions();
965
+
966
+ if (!isset(self::$options['menu'][$key])) {
967
+ self::$options['menu'][$key] = false;
968
+ }
969
+ }
970
+
971
+ return apply_filters('sq_menu_visible', self::$options['menu'][$key], $key);
972
+ }
973
+
974
+ return true;
975
+ }
976
+
977
+ /**
978
+ * Set the header type
979
+ *
980
+ * @param string $type
981
+ */
982
+ public static function setHeader($type)
983
+ {
984
+ if (self::getValue('sq_debug') == 'on') {
985
+ // header("Content-type: text/html");
986
+ return;
987
+ }
988
+
989
+ switch ($type) {
990
+ case 'json':
991
+ header('Content-Type: application/json');
992
+ break;
993
+ case 'ico':
994
+ header('Content-Type: image/x-icon');
995
+ break;
996
+ case 'png':
997
+ header('Content-Type: image/png');
998
+ break;
999
+ case'text':
1000
+ header("Content-type: text/plain");
1001
+ break;
1002
+ case'html':
1003
+ header("Content-type: text/html");
1004
+ break;
1005
+ }
1006
+ }
1007
+
1008
+ /**
1009
+ * Set the Nonce action
1010
+ *
1011
+ * @param $action
1012
+ * @param string $name
1013
+ * @param bool $referer
1014
+ * @param bool $echo
1015
+ * @return string
1016
+ */
1017
+ public static function setNonce($action, $name = '_wpnonce', $referer = true, $echo = true)
1018
+ {
1019
+ $nonce_field = '<input type="hidden" name="' . esc_attr($name) . '" value="' . esc_attr(wp_create_nonce($action)) . '" />';
1020
+
1021
+ if ($referer) {
1022
+ $nonce_field .= wp_referer_field(false);
1023
+ }
1024
+
1025
+ if ($echo) {
1026
+ echo $nonce_field;
1027
+ }
1028
+
1029
+ return $nonce_field;
1030
+ }
1031
+
1032
+ /**
1033
+ * Get a value from $_POST / $_GET
1034
+ * if unavailable, take a default value
1035
+ *
1036
+ * @param string $key Value key
1037
+ * @param mixed $defaultValue (optional)
1038
+ * @param bool $htmlcode
1039
+ * @param bool $keep_newlines
1040
+ * @return mixed Value
1041
+ */
1042
+ public static function getValue($key, $defaultValue = false, $keep_newlines = false)
1043
+ {
1044
+ if (!isset($key) || (isset($key) && $key == '')) {
1045
+ return $defaultValue;
1046
+ }
1047
+
1048
+ //Get the params from forms
1049
+ if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST') {
1050
+ $ret = (isset($_POST[$key]) ? $_POST[$key] : (isset($_GET[$key]) ? $_GET[$key] : ''));
1051
+ } else {
1052
+ $ret = (isset($_GET[$key]) ? $_GET[$key] : '');
1053
+ }
1054
+
1055
+ //Start sanitization of each param
1056
+ //based on the type
1057
+ if (is_array($ret)) { //if array, sanitize each value from the array
1058
+ if (!empty($ret)) {
1059
+ foreach ($ret as &$row) {
1060
+ if (!is_array($row)) {
1061
+ $row = sanitize_text_field($row); //sanitize
1062
+ }
1063
+ }
1064
+ }
1065
+ } elseif (is_string($ret) && $ret <> '' && $keep_newlines && function_exists('sanitize_textarea_field')) {
1066
+ $ret = sanitize_textarea_field($ret);
1067
+ } elseif (is_numeric($ret)) {
1068
+ $ret = (int) $ret;
1069
+ } else{
1070
+ $ret = sanitize_text_field($ret);
1071
+ }
1072
+
1073
+ if (!$ret) {
1074
+ return $defaultValue;
1075
+ } else {
1076
+ return wp_unslash($ret);
1077
+ }
1078
+
1079
+ }
1080
+
1081
+ /**
1082
+ * Check if the parameter is set
1083
+ *
1084
+ * @param string $key
1085
+ * @return boolean
1086
+ */
1087
+ public static function getIsset($key)
1088
+ {
1089
+ return (isset($_GET[$key]) || isset($_POST[$key]));
1090
+ }
1091
+
1092
+
1093
+ /**
1094
+ * Find the string in the content
1095
+ *
1096
+ * @param string $content
1097
+ * @param string $string
1098
+ * @param bool $normalize
1099
+ * @return bool|false|int
1100
+ */
1101
+ public static function findStr($content, $string, $normalize = false)
1102
+ {
1103
+ if ($normalize) {
1104
+ //Check if the search requires char normalization
1105
+ $content = SQ_Classes_Helpers_Sanitize::normalizeChars($content);
1106
+ $string = SQ_Classes_Helpers_Sanitize::normalizeChars($string);
1107
+ } else {
1108
+ //decode the content to match quotes and special chars
1109
+ $content = html_entity_decode($content, ENT_QUOTES);
1110
+ $string = html_entity_decode($string, ENT_QUOTES);
1111
+ }
1112
+
1113
+ if (function_exists('mb_stripos')) {
1114
+ return mb_stripos($content, $string);
1115
+ } else {
1116
+ SQ_Classes_Error::setMessage(esc_html__("For better text comparison you need to install PHP mbstring extension.", 'squirrly-seo'));
1117
+
1118
+ return stripos($content, $string);
1119
+ }
1120
+ }
1121
+
1122
+ /**
1123
+ * Load the multilanguage support from .mo
1124
+ */
1125
+ private function loadMultilanguage()
1126
+ {
1127
+ load_plugin_textdomain(_SQ_PLUGIN_NAME_, false, _SQ_PLUGIN_NAME_ . '/languages/');
1128
+ }
1129
+
1130
+ /**
1131
+ * Hook the activate process
1132
+ */
1133
+ public function sq_activate()
1134
+ {
1135
+ set_transient('sq_activate', true);
1136
+ set_transient('sq_import', true);
1137
+ SQ_Classes_ObjController::getClass('SQ_Models_RoleManager')->addSQRoles();
1138
+ }
1139
+
1140
+ /**
1141
+ * Hook the deactivate process
1142
+ */
1143
+ public function sq_deactivate()
1144
+ {
1145
+ SQ_Classes_ObjController::getClass('SQ_Models_RoleManager')->removeSQCaps();
1146
+ SQ_Classes_ObjController::getClass('SQ_Models_RoleManager')->removeSQRoles();
1147
+ }
1148
+
1149
+ /**
1150
+ * Empty the cache from other plugins
1151
+ */
1152
+ public static function emptyCache()
1153
+ {
1154
+ try {
1155
+ //////////////////////////////////////////////////////////////////////////////
1156
+ if (function_exists('w3tc_pgcache_flush')) {
1157
+ w3tc_pgcache_flush();
1158
+ }
1159
+
1160
+ if (function_exists('w3tc_minify_flush')) {
1161
+ w3tc_minify_flush();
1162
+ }
1163
+ if (function_exists('w3tc_dbcache_flush')) {
1164
+ w3tc_dbcache_flush();
1165
+ }
1166
+ if (function_exists('w3tc_objectcache_flush')) {
1167
+ w3tc_objectcache_flush();
1168
+ }
1169
+ //////////////////////////////////////////////////////////////////////////////
1170
+
1171
+ if (function_exists('wp_cache_clear_cache')) {
1172
+ wp_cache_clear_cache();
1173
+ }
1174
+
1175
+ if (function_exists('rocket_clean_domain') && function_exists('rocket_clean_minify') && function_exists('rocket_clean_cache_busting')) {
1176
+ // Remove all cache files
1177
+ rocket_clean_domain();
1178
+ rocket_clean_minify();
1179
+ rocket_clean_cache_busting();
1180
+ }
1181
+ //////////////////////////////////////////////////////////////////////////////
1182
+
1183
+ if (function_exists('apc_clear_cache')) {
1184
+ // Remove all apc if enabled
1185
+ apc_clear_cache();
1186
+ }
1187
+ //////////////////////////////////////////////////////////////////////////////
1188
+
1189
+ if (class_exists('Cache_Enabler_Disk') && method_exists('Cache_Enabler_Disk', 'clear_cache')) {
1190
+ // clear disk cache
1191
+ Cache_Enabler_Disk::clear_cache();
1192
+ }
1193
+ //////////////////////////////////////////////////////////////////////////////
1194
+
1195
+ if (class_exists('LiteSpeed_Cache')) {
1196
+ LiteSpeed_Cache::get_instance()->purge_all();
1197
+ }
1198
+ //////////////////////////////////////////////////////////////////////////////
1199
+
1200
+ if (self::isPluginInstalled('hummingbird-performance/wp-hummingbird.php')) {
1201
+ do_action('wphb_clear_page_cache');
1202
+ }
1203
+ //////////////////////////////////////////////////////////////////////////////
1204
+
1205
+ if (class_exists('WpeCommon')) {
1206
+ if (method_exists('WpeCommon', 'purge_memcached')) {
1207
+ WpeCommon::purge_memcached();
1208
+ }
1209
+ if (method_exists('WpeCommon', 'clear_maxcdn_cache')) {
1210
+ WpeCommon::clear_maxcdn_cache();
1211
+ }
1212
+ if (method_exists('WpeCommon', 'purge_varnish_cache')) {
1213
+ WpeCommon::purge_varnish_cache();
1214
+ }
1215
+ }
1216
+ //////////////////////////////////////////////////////////////////////////////
1217
+
1218
+ if (self::isPluginInstalled('sg-cachepress/sg-cachepress.php') && class_exists('Supercacher')) {
1219
+ if (method_exists('Supercacher', 'purge_cache') && method_exists('Supercacher', 'delete_assets')) {
1220
+ Supercacher::purge_cache();
1221
+ Supercacher::delete_assets();
1222
+ }
1223
+ }
1224
+
1225
+ //Clear the fastest cache
1226
+ global $wp_fastest_cache;
1227
+ if (isset($wp_fastest_cache) && method_exists($wp_fastest_cache, 'deleteCache')) {
1228
+ $wp_fastest_cache->deleteCache();
1229
+ }
1230
+ //////////////////////////////////////////////////////////////////////////////
1231
+ } catch (Exception $e) {
1232
+
1233
+ }
1234
+ }
1235
+
1236
+ /**
1237
+ * Check if a plugin is installed
1238
+ *
1239
+ * @param $name
1240
+ * @return bool
1241
+ */
1242
+ public static function isPluginInstalled($name)
1243
+ {
1244
+ if (empty(self::$allplugins)) {
1245
+ self::$allplugins = (array)get_option('active_plugins', array());
1246
+
1247
+ if (is_multisite()) {
1248
+ self::$allplugins = array_merge(array_values(self::$allplugins), array_keys(get_site_option('active_sitewide_plugins')));
1249
+ }
1250
+ }
1251
+
1252
+ if (!empty(self::$allplugins)) {
1253
+ return in_array($name, self::$allplugins, true);
1254
+ }
1255
+
1256
+ return false;
1257
+ }
1258
+
1259
+ /**
1260
+ * Check if frontend and user is logged in
1261
+ *
1262
+ * @return bool
1263
+ */
1264
+ public static function isFrontAdmin()
1265
+ {
1266
+ return (!is_admin() && (function_exists('is_user_logged_in') && is_user_logged_in()));
1267
+ }
1268
+
1269
+ /**
1270
+ * Check if user is in dashboard
1271
+ *
1272
+ * @return bool
1273
+ */
1274
+ public static function isBackedAdmin()
1275
+ {
1276
+ return (is_admin() || is_network_admin());
1277
+ }
1278
+
1279
+ /**
1280
+ * Check if the current website is an E-commerce website
1281
+ *
1282
+ * @return bool
1283
+ */
1284
+ public static function isEcommerce()
1285
+ {
1286
+
1287
+ if(self::isPluginInstalled('woocommerce/woocommerce.php')) {
1288
+ return true;
1289
+ }
1290
+
1291
+ $products = array('product', 'wpsc-product');
1292
+ $post_types = get_post_types(array('public' => true));
1293
+
1294
+ foreach ($products as $type) {
1295
+ if (in_array($type, array_keys($post_types))) {
1296
+ return true;
1297
+ }
1298
+ }
1299
+
1300
+ return false;
1301
+ }
1302
+
1303
+ /**
1304
+ * Check if it's an AMP Endpoint
1305
+ *
1306
+ * @return bool|void
1307
+ */
1308
+ public static function isAMPEndpoint()
1309
+ {
1310
+ if (defined('AMPFORWP_AMP_QUERY_VAR')) {
1311
+ $url_path = trim(parse_url(add_query_arg(array()), PHP_URL_PATH), '/');
1312
+ $explode_path = explode('/', $url_path);
1313
+ if (AMPFORWP_AMP_QUERY_VAR === end($explode_path)) {
1314
+ return true;
1315
+ }
1316
+ }
1317
+
1318
+ if (function_exists('is_amp_endpoint')) {
1319
+ return is_amp_endpoint();
1320
+ }
1321
+
1322
+ if (function_exists('is_amp') && is_amp()) {
1323
+ return is_amp();
1324
+ }
1325
+
1326
+ if (function_exists('ampforwp_is_amp_endpoint')) {
1327
+ return ampforwp_is_amp_endpoint();
1328
+ }
1329
+
1330
+ return false;
1331
+ }
1332
+
1333
+ /**
1334
+ * Check the user capability for the roles attached
1335
+ *
1336
+ * @param $cap
1337
+ * @param mixed ...$args
1338
+ * @return bool
1339
+ */
1340
+ public static function userCan($cap, ...$args )
1341
+ {
1342
+
1343
+ if (current_user_can($cap, ...$args)) {
1344
+ return true;
1345
+ }
1346
+
1347
+ $user = wp_get_current_user();
1348
+ if (count((array)$user->roles) > 1) {
1349
+ foreach ($user->roles as $role) {
1350
+ $role_object = get_role($role);
1351
+ if ($role_object->has_cap($cap)) {
1352
+ return true;
1353
+ }
1354
+ }
1355
+ }
1356
+
1357
+ return false;
1358
+ }
1359
+
1360
+ /**
1361
+ * Get the admin url for the specific age
1362
+ *
1363
+ * @param string $page
1364
+ * @param string $tab
1365
+ * @param array $args
1366
+ * @return string
1367
+ */
1368
+ public static function getAdminUrl($page, $tab = null, $args = array())
1369
+ {
1370
+ if (strpos($page, '.php')) {
1371
+ $url = admin_url($page);
1372
+ } else {
1373
+ $url = admin_url('admin.php?page=' . $page);
1374
+ }
1375
+
1376
+ if (isset($tab) && $tab <> '') {
1377
+ $url .= '&tab=' . $tab;
1378
+ }
1379
+
1380
+ if (!empty($args)) {
1381
+ if (strpos($url, '?') !== false) {
1382
+ $url .= '&';
1383
+ } else {
1384
+ $url .= '?';
1385
+ }
1386
+ $url .= join('&', $args);
1387
+ }
1388
+
1389
+ return apply_filters('sq_menu_url', $url, $page, $tab, $args);
1390
+ }
1391
+
1392
+ /**
1393
+ * Instantiates the WordPress filesystem.
1394
+ *
1395
+ * @static
1396
+ * @access public
1397
+ * @return object
1398
+ */
1399
+ public static function initFilesystem()
1400
+ {
1401
+ // The WordPress filesystem.
1402
+ global $wp_filesystem;
1403
+
1404
+ if (!$wp_filesystem || empty($wp_filesystem)) {
1405
+ include_once wp_normalize_path(ABSPATH . '/wp-admin/includes/file.php');
1406
+ WP_Filesystem();
1407
+ }
1408
+
1409
+ return $wp_filesystem;
1410
+ }
1411
+ }
config/config.php CHANGED
@@ -1,82 +1,90 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- /**
5
- * The configuration file
6
- */
7
- if (!defined('_SQ_NONCE_ID_')) {
8
- if (defined('NONCE_KEY')) {
9
- define('_SQ_NONCE_ID_', NONCE_KEY);
10
- } else {
11
- define('_SQ_NONCE_ID_', md5(date('Y-d')));
12
- }
13
- }
14
-
15
- define('_SQ_MOBILE_ICON_SIZES', '76,120,152');
16
-
17
- define('SQ_ONBOARDING', '9.0.0');
18
- defined('SQ_DEBUG') || define('SQ_DEBUG', 0);
19
- define('SQ_REQUEST_TIME', microtime(true));
20
-
21
- /* No path file? error ... */
22
- require_once(dirname(__FILE__) . '/paths.php');
23
-
24
- /* Define the record name in the Option and UserMeta tables */
25
- defined('SQ_OPTION') || define('SQ_OPTION', 'sq_options');
26
- defined('SQ_TASKS') || define('SQ_TASKS', 'sq_tasks');
27
- defined('_SQ_DB_') || define('_SQ_DB_', 'qss');
28
-
29
- define('SQ_ALL_PATTERNS', wp_json_encode(array(
30
- '{{sep}}' => esc_html__("Places a separator between the elements of the post description", _SQ_PLUGIN_NAME_),
31
- '{{title}}' => esc_html__("Adds the title of the post/page/term once it’s published", _SQ_PLUGIN_NAME_),
32
- '{{excerpt}}' => esc_html__("Will display an excerpt from the post/page/term (if not customized, the excerpt will be auto-generated)", _SQ_PLUGIN_NAME_),
33
- '{{excerpt_only}}' => esc_html__("Will display an excerpt from the post/page (no auto-generation)", _SQ_PLUGIN_NAME_),
34
- '{{keyword}}' => esc_html__("Adds the post's keyword to the post description", _SQ_PLUGIN_NAME_),
35
- '{{page}}' => esc_html__("Displays the number of the current page (i.e. 1 of 6)", _SQ_PLUGIN_NAME_),
36
- '{{sitename}}' => esc_html__("Adds the site's name to the post description", _SQ_PLUGIN_NAME_),
37
- '{{sitedesc}}' => esc_html__("Adds the tagline/description of your site", _SQ_PLUGIN_NAME_),
38
- '{{category}}' => esc_html__("Adds the post category (several categories will be comma-separated)", _SQ_PLUGIN_NAME_),
39
- '{{primary_category}}' => esc_html__("Adds the primary category of the post/page", _SQ_PLUGIN_NAME_),
40
- '{{category_description}}' => esc_html__("Adds the category description to the post description", _SQ_PLUGIN_NAME_),
41
- '{{tag}}' => esc_html__("Adds the current tag(s) (several tags will be comma-separated)", _SQ_PLUGIN_NAME_),
42
- '{{tag_description}}' => esc_html__("Adds the tag description", _SQ_PLUGIN_NAME_),
43
- '{{term_title}}' => esc_html__("Adds the term name", _SQ_PLUGIN_NAME_),
44
- '{{term_description}}' => esc_html__("Adds the term description", _SQ_PLUGIN_NAME_),
45
- '{{searchphrase}}' => esc_html__("Displays the search phrase (if it appears in the post)", _SQ_PLUGIN_NAME_),
46
- '{{modified}}' => esc_html__("Replaces the publication date of a post/page with the modified one", _SQ_PLUGIN_NAME_),
47
- '{{name}}' => esc_html__("Displays the author's nicename", _SQ_PLUGIN_NAME_),
48
- '{{single}}' => esc_html__("Displays the post type singular label", _SQ_PLUGIN_NAME_),
49
- '{{plural}}' => esc_html__("Displays the post type plural label", _SQ_PLUGIN_NAME_),
50
- '{{user_description}}' => esc_html__("Adds the author's biographical info to the post description", _SQ_PLUGIN_NAME_),
51
- '{{date}}' => esc_html__("Displays the date of the post/page once it's published", _SQ_PLUGIN_NAME_),
52
- '{{currentdate}}' => esc_html__("Displays the current date", _SQ_PLUGIN_NAME_),
53
- '{{currentday}}' => esc_html__("Adds the current day", _SQ_PLUGIN_NAME_),
54
- '{{currentmonth}}' => esc_html__("Adds the current month", _SQ_PLUGIN_NAME_),
55
- '{{currentyear}}' => esc_html__("Adds the current year", _SQ_PLUGIN_NAME_),
56
- '{{parent_title}}' => esc_html__("Adds the title of a page's parent page", _SQ_PLUGIN_NAME_),
57
- '{{product_name}}' => esc_html__("Adds the product name from Woocommerce for the current product", _SQ_PLUGIN_NAME_),
58
- '{{product_price}}' => esc_html__("Adds the product price from Woocommerce for the current product", _SQ_PLUGIN_NAME_),
59
- '{{product_price_with_tax}}' => esc_html__("Adds the product price with Tax from Woocommerce for the current product", _SQ_PLUGIN_NAME_),
60
- '{{product_sale}}' => esc_html__("Adds the product sale price from Woocommerce for the current product", _SQ_PLUGIN_NAME_),
61
- '{{product_currency}}' => esc_html__("Adds the product price currency from Woocommerce for the current product", _SQ_PLUGIN_NAME_),
62
- '{{product_brand}}' => esc_html__("Adds the product brand from Woocommerce for the current product", _SQ_PLUGIN_NAME_),
63
- )));
64
-
65
- define('SQ_ALL_OG_TYPES', wp_json_encode(array('website', 'article', 'profile', 'book', 'music', 'video')));
66
- define('SQ_ALL_JSONLD_TYPES', wp_json_encode(array('website', 'article', 'newsarticle', 'FAQ page', 'question', 'recipe', 'review', 'movie', 'video', 'local store', 'local restaurant', 'profile')));
67
-
68
- define('SQ_ALL_SEP', wp_json_encode(array(
69
- 'sc-dash' => '-',
70
- 'sc-ndash' => '&ndash;',
71
- 'sc-mdash' => '&mdash;',
72
- 'sc-middot' => '&middot;',
73
- 'sc-bull' => '&bull;',
74
- 'sc-star' => '*',
75
- 'sc-smstar' => '&#8902;',
76
- 'sc-pipe' => '|',
77
- 'sc-tilde' => '~',
78
- 'sc-laquo' => '&laquo;',
79
- 'sc-raquo' => '&raquo;',
80
- 'sc-lt' => '&lt;',
81
- 'sc-gt' => '&gt;',
82
- )));
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ /**
5
+ * The configuration file
6
+ */
7
+ if (!defined('_SQ_NONCE_ID_')) {
8
+ if (defined('NONCE_KEY')) {
9
+ define('_SQ_NONCE_ID_', NONCE_KEY);
10
+ } else {
11
+ define('_SQ_NONCE_ID_', md5(date('Y-d')));
12
+ }
13
+ }
14
+
15
+ define('_SQ_MOBILE_ICON_SIZES', '76,120,152');
16
+
17
+ define('SQ_ONBOARDING', '9.0.0');
18
+ defined('SQ_DEBUG') || define('SQ_DEBUG', 0);
19
+ define('SQ_REQUEST_TIME', microtime(true));
20
+
21
+ /* No path file? error ... */
22
+ require_once dirname(__FILE__) . '/paths.php';
23
+
24
+ /* Define the record name in the Option and UserMeta tables */
25
+ defined('SQ_OPTION') || define('SQ_OPTION', 'sq_options');
26
+ defined('SQ_TASKS') || define('SQ_TASKS', 'sq_tasks');
27
+ defined('_SQ_DB_') || define('_SQ_DB_', 'qss');
28
+
29
+ define(
30
+ 'SQ_ALL_PATTERNS', wp_json_encode(
31
+ array(
32
+ '{{sep}}' => esc_html__("Places a separator between the elements of the post description", 'squirrly-seo'),
33
+ '{{title}}' => esc_html__("Adds the title of the post/page/term once it’s published", 'squirrly-seo'),
34
+ '{{excerpt}}' => esc_html__("Will display an excerpt from the post/page/term (if not customized, the excerpt will be auto-generated)", 'squirrly-seo'),
35
+ '{{excerpt_only}}' => esc_html__("Will display an excerpt from the post/page (no auto-generation)", 'squirrly-seo'),
36
+ '{{keyword}}' => esc_html__("Adds the post's keyword to the post description", 'squirrly-seo'),
37
+ '{{page}}' => esc_html__("Displays the number of the current page (i.e. 1 of 6)", 'squirrly-seo'),
38
+ '{{sitename}}' => esc_html__("Adds the site's name to the post description", 'squirrly-seo'),
39
+ '{{sitedesc}}' => esc_html__("Adds the tagline/description of your site", 'squirrly-seo'),
40
+ '{{category}}' => esc_html__("Adds the post category (several categories will be comma-separated)", 'squirrly-seo'),
41
+ '{{primary_category}}' => esc_html__("Adds the primary category of the post/page", 'squirrly-seo'),
42
+ '{{category_description}}' => esc_html__("Adds the category description to the post description", 'squirrly-seo'),
43
+ '{{tag}}' => esc_html__("Adds the current tag(s) (several tags will be comma-separated)", 'squirrly-seo'),
44
+ '{{tag_description}}' => esc_html__("Adds the tag description", 'squirrly-seo'),
45
+ '{{term_title}}' => esc_html__("Adds the term name", 'squirrly-seo'),
46
+ '{{term_description}}' => esc_html__("Adds the term description", 'squirrly-seo'),
47
+ '{{searchphrase}}' => esc_html__("Displays the search phrase (if it appears in the post)", 'squirrly-seo'),
48
+ '{{modified}}' => esc_html__("Replaces the publication date of a post/page with the modified one", 'squirrly-seo'),
49
+ '{{name}}' => esc_html__("Displays the author's nicename", 'squirrly-seo'),
50
+ '{{single}}' => esc_html__("Displays the post type singular label", 'squirrly-seo'),
51
+ '{{plural}}' => esc_html__("Displays the post type plural label", 'squirrly-seo'),
52
+ '{{user_description}}' => esc_html__("Adds the author's biographical info to the post description", 'squirrly-seo'),
53
+ '{{date}}' => esc_html__("Displays the date of the post/page once it's published", 'squirrly-seo'),
54
+ '{{currentdate}}' => esc_html__("Displays the current date", 'squirrly-seo'),
55
+ '{{currentday}}' => esc_html__("Adds the current day", 'squirrly-seo'),
56
+ '{{currentmonth}}' => esc_html__("Adds the current month", 'squirrly-seo'),
57
+ '{{currentyear}}' => esc_html__("Adds the current year", 'squirrly-seo'),
58
+ '{{parent_title}}' => esc_html__("Adds the title of a page's parent page", 'squirrly-seo'),
59
+ '{{product_name}}' => esc_html__("Adds the product name from Woocommerce for the current product", 'squirrly-seo'),
60
+ '{{product_price}}' => esc_html__("Adds the product price from Woocommerce for the current product", 'squirrly-seo'),
61
+ '{{product_price_with_tax}}' => esc_html__("Adds the product price with Tax from Woocommerce for the current product", 'squirrly-seo'),
62
+ '{{product_sale}}' => esc_html__("Adds the product sale price from Woocommerce for the current product", 'squirrly-seo'),
63
+ '{{product_currency}}' => esc_html__("Adds the product price currency from Woocommerce for the current product", 'squirrly-seo'),
64
+ '{{product_brand}}' => esc_html__("Adds the product brand from Woocommerce for the current product", 'squirrly-seo'),
65
+ )
66
+ )
67
+ );
68
+
69
+ define('SQ_ALL_OG_TYPES', wp_json_encode(array('website', 'article', 'profile', 'book', 'music', 'video')));
70
+ define('SQ_ALL_JSONLD_TYPES', wp_json_encode(array('website', 'article', 'newsarticle', 'FAQ page', 'question', 'recipe', 'review', 'movie', 'video', 'local store', 'local restaurant', 'profile')));
71
+
72
+ define(
73
+ 'SQ_ALL_SEP', wp_json_encode(
74
+ array(
75
+ 'sc-dash' => '-',
76
+ 'sc-ndash' => '&ndash;',
77
+ 'sc-mdash' => '&mdash;',
78
+ 'sc-middot' => '&middot;',
79
+ 'sc-bull' => '&bull;',
80
+ 'sc-star' => '*',
81
+ 'sc-smstar' => '&#8902;',
82
+ 'sc-pipe' => '|',
83
+ 'sc-tilde' => '~',
84
+ 'sc-laquo' => '&laquo;',
85
+ 'sc-raquo' => '&raquo;',
86
+ 'sc-lt' => '&lt;',
87
+ 'sc-gt' => '&gt;',
88
+ )
89
+ )
90
+ );
config/paths.php CHANGED
@@ -1,66 +1,66 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- $currentDir = dirname(__FILE__);
5
-
6
- define('_SQ_NAME_', 'squirrly');
7
- define('_SQ_MENU_NAME_', 'Squirrly SEO');
8
- define('_SQ_NAMESPACE_', 'SQ');
9
- define('_SQ_PLUGIN_NAME_', 'squirrly-seo'); //THIS LINE WILL BE CHANGED WITH THE USER SETTINGS
10
-
11
- defined('SQ_SSL') || define('SQ_SSL', (((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") || (defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN) || (function_exists('is_ssl') && is_ssl())) ? true : false)); //CHECK SSL
12
- defined('SQ_CHECK_SSL') || define('SQ_CHECK_SSL', SQ_SSL);
13
- defined('SQ_URI') || define('SQ_URI', 'wp530');
14
- defined('_SQ_DASH_URL_') || define('_SQ_DASH_URL_', 'https://cloud.squirrly.co/');
15
- defined('_SQ_APIV2_URL_') || define('_SQ_APIV2_URL_', (SQ_SSL ? 'https:' : 'http:') . '//api.squirrly.co/v2/');
16
- define('_SQ_SITE_HOST_', parse_url(home_url(), PHP_URL_HOST));
17
-
18
- define('_SQ_SUPPORT_EMAIL_', 'support@squirrly.co');
19
- defined('_SQ_STATIC_API_URL_') || define('_SQ_STATIC_API_URL_', '//storage.googleapis.com/squirrly/');
20
- defined('_SQ_SUPPORT_EMAIL_URL_') || define('_SQ_SUPPORT_EMAIL_URL_', 'http://plugin.squirrly.co/contact/');
21
- defined('_SQ_SUPPORT_FACEBOOK_URL_') || define('_SQ_SUPPORT_FACEBOOK_URL_', 'https://www.facebook.com/Squirrly.co');
22
- defined('_SQ_HOWTO_URL_') || define('_SQ_HOWTO_URL_', 'https://howto.squirrly.co/wordpress-seo/');
23
- defined('_SQ_SUPPORT_URL_') || define('_SQ_SUPPORT_URL_', 'https://www.dmsuperstars.com/squirrly-support/');
24
-
25
- /* Directories */
26
- define('_SQ_ROOT_DIR_', realpath(dirname($currentDir)) . '/');
27
- define('_SQ_CLASSES_DIR_', _SQ_ROOT_DIR_ . 'classes/');
28
- define('_SQ_CONTROLLER_DIR_', _SQ_ROOT_DIR_ . 'controllers/');
29
- define('_SQ_MODEL_DIR_', _SQ_ROOT_DIR_ . 'models/');
30
- define('_SQ_SERVICE_DIR_', _SQ_MODEL_DIR_ . 'services/');
31
- define('_SQ_TRANSLATIONS_DIR_', _SQ_ROOT_DIR_ . 'translations/');
32
- define('_SQ_CORE_DIR_', _SQ_ROOT_DIR_ . 'core/');
33
- define('_SQ_THEME_DIR_', _SQ_ROOT_DIR_ . 'view/');
34
- define('_SQ_ASSETS_DIR_', _SQ_THEME_DIR_ . 'assets/');
35
-
36
- /* URLS */
37
- define('_SQ_URL_', rtrim(plugins_url('', $currentDir), '/') . '/');
38
- define('_SQ_THEME_URL_', _SQ_URL_ . 'view/');
39
- define('_SQ_ASSETS_URL_', _SQ_THEME_URL_ . 'assets/');
40
- define('_SQ_ASSETS_RELATIVE_URL_', ltrim(parse_url(_SQ_ASSETS_URL_, PHP_URL_PATH), '/'));
41
-
42
-
43
- $upload_dir = array();
44
- $upload_dir['baseurl'] = WP_CONTENT_URL . '/uploads';
45
- $upload_dir['basedir'] = WP_CONTENT_DIR . '/uploads';
46
-
47
- if (!defined('UPLOADS')) {
48
- $basedir = WP_CONTENT_DIR . '/uploads/' . _SQ_NAME_;
49
- $baseurl = rtrim(content_url(), '/') . '/uploads/' . _SQ_NAME_;
50
- } else {
51
- $basedir = rtrim(ABSPATH, '/') . '/' . trim(UPLOADS, '/') . '/' . _SQ_NAME_;
52
- $baseurl = home_url() . '/' . trim(UPLOADS, '/') . '/' . _SQ_NAME_;
53
- }
54
-
55
- if (!is_dir($basedir)) {
56
- @wp_mkdir_p($basedir);
57
- }
58
-
59
- if (!is_dir($basedir) || !function_exists('wp_is_writable') || !wp_is_writable($basedir)) {
60
- $basedir = _SQ_ROOT_DIR_ . 'cache';
61
- $baseurl = _SQ_URL_ . 'cache';
62
- }
63
-
64
- defined('_SQ_CACHE_DIR_') || define('_SQ_CACHE_DIR_', $basedir . '/');
65
- defined('_SQ_CACHE_URL_') || define('_SQ_CACHE_URL_', $baseurl . '/');
66
-
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ $currentDir = dirname(__FILE__);
5
+
6
+ define('_SQ_NAME_', 'squirrly');
7
+ define('_SQ_MENU_NAME_', 'Squirrly SEO');
8
+ define('_SQ_NAMESPACE_', 'SQ');
9
+ define('_SQ_PLUGIN_NAME_', 'squirrly-seo'); //THIS LINE WILL BE CHANGED WITH THE USER SETTINGS
10
+
11
+ defined('SQ_SSL') || define('SQ_SSL', (((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") || (defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN) || (function_exists('is_ssl') && is_ssl())) ? true : false)); //CHECK SSL
12
+ defined('SQ_CHECK_SSL') || define('SQ_CHECK_SSL', SQ_SSL);
13
+ defined('SQ_URI') || define('SQ_URI', 'wp530');
14
+ defined('_SQ_DASH_URL_') || define('_SQ_DASH_URL_', 'https://cloud.squirrly.co/');
15
+ defined('_SQ_APIV2_URL_') || define('_SQ_APIV2_URL_', (SQ_SSL ? 'https:' : 'http:') . '//api.squirrly.co/v2/');
16
+ define('_SQ_SITE_HOST_', parse_url(home_url(), PHP_URL_HOST));
17
+
18
+ define('_SQ_SUPPORT_EMAIL_', 'support@squirrly.co');
19
+ defined('_SQ_STATIC_API_URL_') || define('_SQ_STATIC_API_URL_', '//storage.googleapis.com/squirrly/');
20
+ defined('_SQ_SUPPORT_EMAIL_URL_') || define('_SQ_SUPPORT_EMAIL_URL_', 'http://plugin.squirrly.co/contact/');
21
+ defined('_SQ_SUPPORT_FACEBOOK_URL_') || define('_SQ_SUPPORT_FACEBOOK_URL_', 'https://www.facebook.com/Squirrly.co');
22
+ defined('_SQ_HOWTO_URL_') || define('_SQ_HOWTO_URL_', 'https://howto.squirrly.co/wordpress-seo/');
23
+ defined('_SQ_SUPPORT_URL_') || define('_SQ_SUPPORT_URL_', 'https://www.dmsuperstars.com/squirrly-support/');
24
+
25
+ /* Directories */
26
+ define('_SQ_ROOT_DIR_', realpath(dirname($currentDir)) . '/');
27
+ define('_SQ_CLASSES_DIR_', _SQ_ROOT_DIR_ . 'classes/');
28
+ define('_SQ_CONTROLLER_DIR_', _SQ_ROOT_DIR_ . 'controllers/');
29
+ define('_SQ_MODEL_DIR_', _SQ_ROOT_DIR_ . 'models/');
30
+ define('_SQ_SERVICE_DIR_', _SQ_MODEL_DIR_ . 'services/');
31
+ define('_SQ_TRANSLATIONS_DIR_', _SQ_ROOT_DIR_ . 'translations/');
32
+ define('_SQ_CORE_DIR_', _SQ_ROOT_DIR_ . 'core/');
33
+ define('_SQ_THEME_DIR_', _SQ_ROOT_DIR_ . 'view/');
34
+ define('_SQ_ASSETS_DIR_', _SQ_THEME_DIR_ . 'assets/');
35
+
36
+ /* URLS */
37
+ define('_SQ_URL_', rtrim(plugins_url('', $currentDir), '/') . '/');
38
+ define('_SQ_THEME_URL_', _SQ_URL_ . 'view/');
39
+ define('_SQ_ASSETS_URL_', _SQ_THEME_URL_ . 'assets/');
40
+ define('_SQ_ASSETS_RELATIVE_URL_', ltrim(parse_url(_SQ_ASSETS_URL_, PHP_URL_PATH), '/'));
41
+
42
+
43
+ $upload_dir = array();
44
+ $upload_dir['baseurl'] = WP_CONTENT_URL . '/uploads';
45
+ $upload_dir['basedir'] = WP_CONTENT_DIR . '/uploads';
46
+
47
+ if (!defined('UPLOADS')) {
48
+ $basedir = WP_CONTENT_DIR . '/uploads/' . _SQ_NAME_;
49
+ $baseurl = rtrim(content_url(), '/') . '/uploads/' . _SQ_NAME_;
50
+ } else {
51
+ $basedir = rtrim(ABSPATH, '/') . '/' . trim(UPLOADS, '/') . '/' . _SQ_NAME_;
52
+ $baseurl = home_url() . '/' . trim(UPLOADS, '/') . '/' . _SQ_NAME_;
53
+ }
54
+
55
+ if (!is_dir($basedir)) {
56
+ @wp_mkdir_p($basedir);
57
+ }
58
+
59
+ if (!is_dir($basedir) || !function_exists('wp_is_writable') || !wp_is_writable($basedir)) {
60
+ $basedir = _SQ_ROOT_DIR_ . 'cache';
61
+ $baseurl = _SQ_URL_ . 'cache';
62
+ }
63
+
64
+ defined('_SQ_CACHE_DIR_') || define('_SQ_CACHE_DIR_', $basedir . '/');
65
+ defined('_SQ_CACHE_URL_') || define('_SQ_CACHE_URL_', $baseurl . '/');
66
+
controllers/Account.php CHANGED
@@ -1,39 +1,45 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- /**
5
- * User Account
6
- */
7
- class SQ_Controllers_Account extends SQ_Classes_FrontController {
8
-
9
- /** @var object Checkin process */
10
- public $checkin;
11
-
12
- public function action() {
13
-
14
- switch (SQ_Classes_Helpers_Tools::getValue('action')) {
15
- case 'sq_ajax_account_getaccount':
16
- $json = array();
17
-
18
- $this->checkin = SQ_Classes_RemoteController::checkin();
19
-
20
- if (!is_wp_error($this->checkin)) {
21
-
22
- $json['html'] = $this->getView('Blocks/Account');
23
-
24
- if (SQ_Classes_Helpers_Tools::isAjax()) {
25
- SQ_Classes_Helpers_Tools::setHeader('json');
26
-
27
- if (SQ_Classes_Error::isError()) {
28
- $json['error'] = SQ_Classes_Error::getError();
29
- }
30
-
31
- echo wp_json_encode($json);
32
- exit();
33
- }
34
-
35
- }
36
- break;
37
- }
38
- }
39
- }
 
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ /**
5
+ * User Account
6
+ */
7
+ class SQ_Controllers_Account extends SQ_Classes_FrontController
8
+ {
9
+
10
+ /**
11
+ *
12
+ *
13
+ * @var object Checkin process
14
+ */
15
+ public $checkin;
16
+
17
+ public function action()
18
+ {
19
+
20
+ switch (SQ_Classes_Helpers_Tools::getValue('action')) {
21
+ case 'sq_ajax_account_getaccount':
22
+ $json = array();
23
+
24
+ $this->checkin = SQ_Classes_RemoteController::checkin();
25
+
26
+ if (!is_wp_error($this->checkin)) {
27
+
28
+ $json['html'] = $this->get_view('Blocks/Account');
29
+
30
+ if (SQ_Classes_Helpers_Tools::isAjax()) {
31
+ SQ_Classes_Helpers_Tools::setHeader('json');
32
+
33
+ if (SQ_Classes_Error::isError()) {
34
+ $json['error'] = SQ_Classes_Error::getError();
35
+ }
36
+
37
+ echo wp_json_encode($json);
38
+ exit();
39
+ }
40
+
41
+ }
42
+ break;
43
+ }
44
+ }
45
+ }
controllers/Api.php CHANGED
@@ -1,194 +1,213 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- class SQ_Controllers_Api extends SQ_Classes_FrontController {
5
-
6
- /** @var string token local key */
7
- private $token;
8
-
9
- /**
10
- * Initialize the TinyMCE editor for the current use
11
- *
12
- * @return void
13
- */
14
- public function hookInit() {
15
-
16
- if (SQ_Classes_Helpers_Tools::getOption('sq_api') == '')
17
- return;
18
-
19
- if (!SQ_Classes_Helpers_Tools::getOption('sq_cloud_connect'))
20
- return;
21
-
22
- $this->token = SQ_Classes_Helpers_Tools::getOption('sq_cloud_token');
23
-
24
- //Change the rest api if needed
25
- add_action('rest_api_init', array($this, 'sqApiCall'));
26
- }
27
-
28
-
29
- function sqApiCall() {
30
- if (function_exists('register_rest_route')) {
31
- register_rest_route('save', '/squirrly/', array(
32
- 'methods' => WP_REST_Server::EDITABLE,
33
- 'callback' => array($this, 'savePost'),
34
- 'permission_callback' => '__return_true'
35
- ));
36
-
37
- register_rest_route('test', '/squirrly/', array(
38
- 'methods' => WP_REST_Server::EDITABLE,
39
- 'callback' => array($this, 'testConnection'),
40
- 'permission_callback' => '__return_true'
41
- ));
42
-
43
- register_rest_route('get', '/squirrly/', array(
44
- 'methods' => WP_REST_Server::READABLE,
45
- 'callback' => array($this, 'getData'),
46
- 'permission_callback' => '__return_true'
47
- ));
48
- }
49
- }
50
-
51
- /**
52
- * Test the connection
53
- * @param WP_REST_Request $request Full details about the request.
54
- */
55
- public function testConnection($request) {
56
- SQ_Classes_Helpers_Tools::setHeader('json');
57
-
58
- //get the token from API
59
- $token = $request->get_param('token');
60
- if ($token <> '') {
61
- $token = sanitize_text_field($token);
62
- }
63
-
64
- if (!$this->token || $this->token <> $token) {
65
- exit(wp_json_encode(array('connected' => false, 'error' => esc_html__("Invalid Token. Please try again", _SQ_PLUGIN_NAME_))));
66
- }
67
-
68
- echo wp_json_encode(array('connected' => true, 'error' => false));
69
- exit();
70
- }
71
-
72
- /**
73
- * Save the Post
74
- * @param WP_REST_Request $request Full details about the request.
75
- */
76
- public function savePost($request) {
77
- SQ_Classes_Helpers_Tools::setHeader('json');
78
-
79
- //get the token from API
80
- $token = $request->get_param('token');
81
- if ($token <> '') {
82
- $token = sanitize_text_field($token);
83
- }
84
-
85
- if (!$this->token || $this->token <> $token) {
86
- exit(wp_json_encode(array('error' => esc_html__("Connection expired. Please try again", _SQ_PLUGIN_NAME_))));
87
- }
88
-
89
- $post = $request->get_param('post');
90
- if ($post = json_decode($post)) {
91
- if (isset($post->ID) && $post->ID > 0) {
92
- $post = new WP_Post($post);
93
- $post->ID = 0;
94
- if (isset($post->post_author)) {
95
- if (is_email($post->post_author)) {
96
- if ($user = get_user_by('email', $post->post_author)) {
97
- $post->post_author = $user->ID;
98
- } else {
99
- exit(wp_json_encode(array('error' => esc_html__("Author not found", _SQ_PLUGIN_NAME_))));
100
- }
101
- } else {
102
- exit(wp_json_encode(array('error' => esc_html__("Author not found", _SQ_PLUGIN_NAME_))));
103
- }
104
- } else {
105
- exit(wp_json_encode(array('error' => esc_html__("Author not found", _SQ_PLUGIN_NAME_))));
106
- }
107
-
108
- $post_ID = wp_insert_post($post->to_array());
109
- if (is_wp_error($post_ID)) {
110
- echo wp_json_encode(array('error' => $post_ID->get_error_message()));
111
- } else {
112
- echo wp_json_encode(array('saved' => true, 'post_ID' => $post_ID, 'permalink' => get_permalink($post_ID)));
113
- }
114
- exit();
115
- }
116
- }
117
- echo wp_json_encode(array('error' => true));
118
- exit();
119
- }
120
-
121
- /**
122
- * Get data for the Focus Page Audit
123
- * @param \WP_REST_Request $request
124
- */
125
- public function getData($request) {
126
-
127
- global $wpdb;
128
- $response = array();
129
- SQ_Classes_Helpers_Tools::setHeader('json');
130
-
131
- //get the token from API
132
- $token = $request->get_param('token');
133
- if ($token <> '') {
134
- $token = sanitize_text_field($token);
135
- }
136
-
137
- if (!$this->token || $this->token <> $token) {
138
- exit(wp_json_encode(array('error' => esc_html__("Connection expired. Please try again.", _SQ_PLUGIN_NAME_))));
139
- }
140
-
141
- $select = $request->get_param('select');
142
-
143
-
144
- switch ($select) {
145
- case 'innerlinks':
146
- $url = $request->get_param('url');
147
- if ($url == '') {
148
- exit(wp_json_encode(array('error' => esc_html__("Wrong Params", _SQ_PLUGIN_NAME_))));
149
- }
150
-
151
- //get post inner links
152
- $total_posts = 0;
153
- $inner_links = array();
154
- if ($row = $wpdb->get_row($wpdb->prepare("SELECT COUNT(`ID`) as count FROM `$wpdb->posts` WHERE `post_status` = %s", 'publish'))) {
155
- $total_posts = $row->count;
156
- }
157
- if ($rows = $wpdb->get_results($wpdb->prepare("SELECT `ID` FROM `$wpdb->posts` WHERE `post_content` LIKE '%%%s%' AND `post_status` = %s", $url, 'publish'), OBJECT)) {
158
- if (!empty($rows)) {
159
- foreach ($rows as $row) {
160
- $post = SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->setPostByID($row->ID);
161
- if ($post->sq->nositemap || !$post->sq->do_sitemap) {
162
- continue;
163
- }
164
- $inner_links[] = $post->url;
165
- }
166
- }
167
- }
168
- $response = array('url' => $url, 'total_posts' => $total_posts, 'inner_links' => $inner_links);
169
- break;
170
- case 'post':
171
- $url = $request->get_param('url');
172
- if ($url == '') {
173
- exit(wp_json_encode(array('error' => esc_html__("Wrong Params", _SQ_PLUGIN_NAME_))));
174
- }
175
- //get Squirrly SEO post metas
176
- if ($post = SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->setPostByURL($url)) {
177
- $response = $post->toArray();
178
- }
179
-
180
- break;
181
- case 'squirrly':
182
- //Get Squirrly settings
183
- if ($options = SQ_Classes_Helpers_Tools::getOptions()) {
184
- $response = (array)$options;
185
- }
186
-
187
- break;
188
- }
189
- echo wp_json_encode($response);
190
-
191
- exit();
192
-
193
- }
194
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ class SQ_Controllers_Api extends SQ_Classes_FrontController
5
+ {
6
+
7
+ /**
8
+ *
9
+ *
10
+ * @var string token local key
11
+ */
12
+ private $token;
13
+
14
+ /**
15
+ * Initialize the TinyMCE editor for the current use
16
+ *
17
+ * @return void
18
+ */
19
+ public function hookInit()
20
+ {
21
+
22
+ if (SQ_Classes_Helpers_Tools::getOption('sq_api') == '')
23
+ return;
24
+
25
+ if (!SQ_Classes_Helpers_Tools::getOption('sq_cloud_connect'))
26
+ return;
27
+
28
+ $this->token = SQ_Classes_Helpers_Tools::getOption('sq_cloud_token');
29
+
30
+ //Change the rest api if needed
31
+ add_action('rest_api_init', array($this, 'sqApiCall'));
32
+ }
33
+
34
+
35
+ function sqApiCall()
36
+ {
37
+ if (function_exists('register_rest_route')) {
38
+ register_rest_route(
39
+ 'save', '/squirrly/', array(
40
+ 'methods' => WP_REST_Server::EDITABLE,
41
+ 'callback' => array($this, 'savePost'),
42
+ 'permission_callback' => '__return_true'
43
+ )
44
+ );
45
+
46
+ register_rest_route(
47
+ 'test', '/squirrly/', array(
48
+ 'methods' => WP_REST_Server::EDITABLE,
49
+ 'callback' => array($this, 'testConnection'),
50
+ 'permission_callback' => '__return_true'
51
+ )
52
+ );
53
+
54
+ register_rest_route(
55
+ 'get', '/squirrly/', array(
56
+ 'methods' => WP_REST_Server::READABLE,
57
+ 'callback' => array($this, 'getData'),
58
+ 'permission_callback' => '__return_true'
59
+ )
60
+ );
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Test the connection
66
+ *
67
+ * @param WP_REST_Request $request Full details about the request.
68
+ */
69
+ public function testConnection($request)
70
+ {
71
+ SQ_Classes_Helpers_Tools::setHeader('json');
72
+
73
+ //get the token from API
74
+ $token = $request->get_param('token');
75
+ if ($token <> '') {
76
+ $token = sanitize_text_field($token);
77
+ }
78
+
79
+ if (!$this->token || $this->token <> $token) {
80
+ exit(wp_json_encode(array('connected' => false, 'error' => esc_html__("Invalid Token. Please try again", 'squirrly-seo'))));
81
+ }
82
+
83
+ echo wp_json_encode(array('connected' => true, 'error' => false));
84
+ exit();
85
+ }
86
+
87
+ /**
88
+ * Save the Post
89
+ *
90
+ * @param WP_REST_Request $request Full details about the request.
91
+ */
92
+ public function savePost($request)
93
+ {
94
+ SQ_Classes_Helpers_Tools::setHeader('json');
95
+
96
+ //get the token from API
97
+ $token = $request->get_param('token');
98
+ if ($token <> '') {
99
+ $token = sanitize_text_field($token);
100
+ }
101
+
102
+ if (!$this->token || $this->token <> $token) {
103
+ exit(wp_json_encode(array('error' => esc_html__("Connection expired. Please try again", 'squirrly-seo'))));
104
+ }
105
+
106
+ $post = $request->get_param('post');
107
+ if ($post = json_decode($post)) {
108
+ if (isset($post->ID) && $post->ID > 0) {
109
+ $post = new WP_Post($post);
110
+ $post->ID = 0;
111
+ if (isset($post->post_author)) {
112
+ if (is_email($post->post_author)) {
113
+ if ($user = get_user_by('email', $post->post_author)) {
114
+ $post->post_author = $user->ID;
115
+ } else {
116
+ exit(wp_json_encode(array('error' => esc_html__("Author not found", 'squirrly-seo'))));
117
+ }
118
+ } else {
119
+ exit(wp_json_encode(array('error' => esc_html__("Author not found", 'squirrly-seo'))));
120
+ }
121
+ } else {
122
+ exit(wp_json_encode(array('error' => esc_html__("Author not found", 'squirrly-seo'))));
123
+ }
124
+
125
+ $post_ID = wp_insert_post($post->to_array());
126
+ if (is_wp_error($post_ID)) {
127
+ echo wp_json_encode(array('error' => $post_ID->get_error_message()));
128
+ } else {
129
+ echo wp_json_encode(array('saved' => true, 'post_ID' => $post_ID, 'permalink' => get_permalink($post_ID)));
130
+ }
131
+ exit();
132
+ }
133
+ }
134
+ echo wp_json_encode(array('error' => true));
135
+ exit();
136
+ }
137
+
138
+ /**
139
+ * Get data for the Focus Page Audit
140
+ *
141
+ * @param \WP_REST_Request $request
142
+ */
143
+ public function getData($request)
144
+ {
145
+
146
+ global $wpdb;
147
+ $response = array();
148
+ SQ_Classes_Helpers_Tools::setHeader('json');
149
+
150
+ //get the token from API
151
+ $token = $request->get_param('token');
152
+ if ($token <> '') {
153
+ $token = sanitize_text_field($token);
154
+ }
155
+
156
+ if (!$this->token || $this->token <> $token) {
157
+ exit(wp_json_encode(array('error' => esc_html__("Connection expired. Please try again.", 'squirrly-seo'))));
158
+ }
159
+
160
+ $select = $request->get_param('select');
161
+
162
+
163
+ switch ($select) {
164
+ case 'innerlinks':
165
+ $url = $request->get_param('url');
166
+ if ($url == '') {
167
+ exit(wp_json_encode(array('error' => esc_html__("Wrong Params", 'squirrly-seo'))));
168
+ }
169
+
170
+ //get post inner links
171
+ $total_posts = 0;
172
+ $inner_links = array();
173
+ if ($row = $wpdb->get_row($wpdb->prepare("SELECT COUNT(`ID`) as count FROM `$wpdb->posts` WHERE `post_status` = %s", 'publish'))) {
174
+ $total_posts = $row->count;
175
+ }
176
+ if ($rows = $wpdb->get_results($wpdb->prepare("SELECT `ID` FROM `$wpdb->posts` WHERE `post_content` LIKE '%%%s%' AND `post_status` = %s", $url, 'publish'), OBJECT)) {
177
+ if (!empty($rows)) {
178
+ foreach ($rows as $row) {
179
+ $post = SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->setPostByID($row->ID);
180
+ if ($post->sq->nositemap || !$post->sq->do_sitemap) {
181
+ continue;
182
+ }
183
+ $inner_links[] = $post->url;
184
+ }
185
+ }
186
+ }
187
+ $response = array('url' => $url, 'total_posts' => $total_posts, 'inner_links' => $inner_links);
188
+ break;
189
+ case 'post':
190
+ $url = $request->get_param('url');
191
+ if ($url == '') {
192
+ exit(wp_json_encode(array('error' => esc_html__("Wrong Params", 'squirrly-seo'))));
193
+ }
194
+ //get Squirrly SEO post metas
195
+ if ($post = SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->setPostByURL($url)) {
196
+ $response = $post->toArray();
197
+ }
198
+
199
+ break;
200
+ case 'squirrly':
201
+ //Get Squirrly settings
202
+ if ($options = SQ_Classes_Helpers_Tools::getOptions()) {
203
+ $response = (array)$options;
204
+ }
205
+
206
+ break;
207
+ }
208
+ echo wp_json_encode($response);
209
+
210
+ exit();
211
+
212
+ }
213
+ }
controllers/Assistant.php CHANGED
@@ -1,151 +1,157 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- class SQ_Controllers_Assistant extends SQ_Classes_FrontController {
5
-
6
- /** @var object Checkin process */
7
- public $checkin;
8
-
9
- function init() {
10
-
11
- $tab = SQ_Classes_Helpers_Tools::getValue('tab', 'assistant');
12
-
13
- if (method_exists($this, $tab)) {
14
- call_user_func(array($this, $tab));
15
- }
16
-
17
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap-reboot');
18
- if(is_rtl()){
19
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('popper');
20
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap.rtl');
21
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('rtl');
22
- }else{
23
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap');
24
- }
25
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap-select');
26
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('switchery');
27
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('datatables');
28
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('fontawesome');
29
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('global');
30
-
31
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('assistant');
32
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('navbar');
33
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('assistant');
34
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('chart');
35
-
36
- //@ob_flush();
37
- echo $this->getView('Assistant/' . ucfirst($tab));
38
-
39
- //get the modal window for the assistant popup
40
- echo SQ_Classes_ObjController::getClass('SQ_Models_Assistant')->getModal();
41
- }
42
-
43
- public function assistant() {
44
- //Checkin to API V2
45
- $this->checkin = SQ_Classes_RemoteController::checkin();
46
-
47
- add_action('sq_form_notices', array($this, 'getNotificationBar'));
48
- }
49
-
50
- public function settings() {
51
- $search = (string)SQ_Classes_Helpers_Tools::getValue('skeyword', '');
52
- $labels = SQ_Classes_Helpers_Tools::getValue('slabel', false);
53
-
54
- $args = array();
55
- $args['search'] = $search;
56
- if ($labels && !empty($labels)) {
57
- $args['label'] = join(',', $labels);
58
- }
59
- SQ_Debug::dump($args);
60
-
61
- $json = SQ_Classes_RemoteController::getBriefcase($args);
62
-
63
- $this->rankkeywords = SQ_Classes_RemoteController::getRanks();
64
-
65
- SQ_Debug::dump($json);
66
-
67
- if (isset($json->keywords) && !empty($json->keywords)) {
68
- $this->keywords = $json->keywords;
69
- } else {
70
-
71
- $this->error = esc_html__("No keyword found.", _SQ_PLUGIN_NAME_);
72
-
73
- }
74
-
75
- if (isset($json->labels)) {
76
- $this->labels = $json->labels;
77
- }
78
-
79
- wp_enqueue_style('wp-color-picker');
80
- wp_enqueue_script('wp-color-picker');
81
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('briefcase');
82
-
83
- }
84
-
85
-
86
- /**
87
- * Called when action is triggered
88
- *
89
- * @return void
90
- */
91
- public function action() {
92
-
93
- parent::action();
94
- SQ_Classes_Helpers_Tools::setHeader('json');
95
-
96
- switch (SQ_Classes_Helpers_Tools::getValue('action')) {
97
-
98
- ///////////////////////////////////////////LIVE ASSISTANT SETTINGS
99
- case 'sq_settings_assistant':
100
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
101
- return;
102
- }
103
-
104
- //Save the settings
105
- if (!empty($_POST)) {
106
- SQ_Classes_ObjController::getClass('SQ_Models_Settings')->saveValues($_POST);
107
- }
108
-
109
- //show the saved message
110
- SQ_Classes_Error::setMessage(esc_html__("Saved", _SQ_PLUGIN_NAME_));
111
-
112
- break;
113
-
114
- case 'sq_ajax_assistant':
115
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippets')) {
116
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
117
- SQ_Classes_Helpers_Tools::setHeader('json');
118
- echo wp_json_encode($response);
119
- exit();
120
- }
121
-
122
- SQ_Classes_Helpers_Tools::setHeader('json');
123
-
124
- $input = SQ_Classes_Helpers_Tools::getValue('input', '');
125
- $value = (bool)SQ_Classes_Helpers_Tools::getValue('value', false);
126
- if ($input) {
127
- //unpack the input into expected variables
128
- list($category_name, $name, $option) = explode('|', $input);
129
- $dbtasks = json_decode(get_option(SQ_TASKS), true);
130
-
131
- if ($category_name <> '' && $name <> '') {
132
- if (!$option) $option = 'active';
133
- $dbtasks[$category_name][$name][$option] = $value;
134
- update_option(SQ_TASKS, wp_json_encode($dbtasks));
135
- }
136
-
137
- $response['data'] = SQ_Classes_Error::showNotices(esc_html__("Saved", _SQ_PLUGIN_NAME_), 'sq_success');
138
- echo wp_json_encode($response);
139
- exit;
140
- }
141
-
142
- $response['data'] = SQ_Classes_Error::showNotices(esc_html__("Error: Could not save the data.", _SQ_PLUGIN_NAME_), 'sq_error');
143
- echo wp_json_encode($response);
144
- exit();
145
-
146
-
147
- }
148
-
149
-
150
- }
151
- }
 
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ class SQ_Controllers_Assistant extends SQ_Classes_FrontController
5
+ {
6
+
7
+ /**
8
+ *
9
+ *
10
+ * @var object Checkin process
11
+ */
12
+ public $checkin;
13
+
14
+ function init()
15
+ {
16
+
17
+ $tab = preg_replace("/[^a-zA-Z0-9]/", "", SQ_Classes_Helpers_Tools::getValue('tab', 'assistant'));
18
+
19
+ if (method_exists($this, $tab)) {
20
+ call_user_func(array($this, $tab));
21
+ }
22
+
23
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap-reboot');
24
+ if(is_rtl()) {
25
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('popper');
26
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap.rtl');
27
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('rtl');
28
+ }else{
29
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap');
30
+ }
31
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap-select');
32
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('switchery');
33
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('datatables');
34
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('fontawesome');
35
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('global');
36
+
37
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('assistant');
38
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('navbar');
39
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('assistant');
40
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('chart');
41
+
42
+ //@ob_flush();
43
+ $this->show_view('Assistant/' . esc_attr(ucfirst($tab)));
44
+
45
+ //get the modal window for the assistant popup
46
+ echo SQ_Classes_ObjController::getClass('SQ_Models_Assistant')->getModal();
47
+ }
48
+
49
+ public function assistant()
50
+ {
51
+ //Checkin to API V2
52
+ $this->checkin = SQ_Classes_RemoteController::checkin();
53
+
54
+ add_action('sq_form_notices', array($this, 'getNotificationBar'));
55
+ }
56
+
57
+ public function settings()
58
+ {
59
+ $search = (string)SQ_Classes_Helpers_Tools::getValue('skeyword', '');
60
+ $labels = SQ_Classes_Helpers_Tools::getValue('slabel', false);
61
+
62
+ $args = array();
63
+ $args['search'] = $search;
64
+ if ($labels && !empty($labels)) {
65
+ $args['label'] = join(',', $labels);
66
+ }
67
+
68
+ $json = SQ_Classes_RemoteController::getBriefcase($args);
69
+
70
+ $this->rankkeywords = SQ_Classes_RemoteController::getRanks();
71
+
72
+ if (isset($json->keywords) && !empty($json->keywords)) {
73
+ $this->keywords = $json->keywords;
74
+ } else {
75
+
76
+ $this->error = esc_html__("No keyword found.", 'squirrly-seo');
77
+
78
+ }
79
+
80
+ if (isset($json->labels)) {
81
+ $this->labels = $json->labels;
82
+ }
83
+
84
+ wp_enqueue_style('wp-color-picker');
85
+ wp_enqueue_script('wp-color-picker');
86
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('briefcase');
87
+
88
+ }
89
+
90
+
91
+ /**
92
+ * Called when action is triggered
93
+ *
94
+ * @return void
95
+ */
96
+ public function action()
97
+ {
98
+
99
+ parent::action();
100
+ SQ_Classes_Helpers_Tools::setHeader('json');
101
+
102
+ switch (SQ_Classes_Helpers_Tools::getValue('action')) {
103
+
104
+ ///////////////////////////////////////////LIVE ASSISTANT SETTINGS
105
+ case 'sq_settings_assistant':
106
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
107
+ return;
108
+ }
109
+
110
+ //Save the settings
111
+ if (!empty($_POST)) {
112
+ SQ_Classes_ObjController::getClass('SQ_Models_Settings')->saveValues($_POST);
113
+ }
114
+
115
+ //show the saved message
116
+ SQ_Classes_Error::setMessage(esc_html__("Saved", 'squirrly-seo'));
117
+
118
+ break;
119
+
120
+ case 'sq_ajax_assistant':
121
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippets')) {
122
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
123
+ SQ_Classes_Helpers_Tools::setHeader('json');
124
+ echo wp_json_encode($response);
125
+ exit();
126
+ }
127
+
128
+ SQ_Classes_Helpers_Tools::setHeader('json');
129
+
130
+ $input = SQ_Classes_Helpers_Tools::getValue('input', '');
131
+ $value = (bool)SQ_Classes_Helpers_Tools::getValue('value', false);
132
+ if ($input) {
133
+ //unpack the input into expected variables
134
+ list($category_name, $name, $option) = explode('|', $input);
135
+ $dbtasks = json_decode(get_option(SQ_TASKS), true);
136
+
137
+ if ($category_name <> '' && $name <> '') {
138
+ if (!$option) $option = 'active';
139
+ $dbtasks[$category_name][$name][$option] = $value;
140
+ update_option(SQ_TASKS, wp_json_encode($dbtasks));
141
+ }
142
+
143
+ $response['data'] = SQ_Classes_Error::showNotices(esc_html__("Saved", 'squirrly-seo'), 'sq_success');
144
+ echo wp_json_encode($response);
145
+ exit;
146
+ }
147
+
148
+ $response['data'] = SQ_Classes_Error::showNotices(esc_html__("Error: Could not save the data.", 'squirrly-seo'), 'sq_error');
149
+ echo wp_json_encode($response);
150
+ exit();
151
+
152
+
153
+ }
154
+
155
+
156
+ }
157
+ }
controllers/Audits.php CHANGED
@@ -1,381 +1,411 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- class SQ_Controllers_Audits extends SQ_Classes_FrontController {
5
-
6
- /** @var object Checkin process */
7
- public $checkin;
8
-
9
- public $blogs;
10
- public $auditpage;
11
- public $audit;
12
- public $pages;
13
- public $audits;
14
- public $auditpages;
15
-
16
- /** @var int Audit history limit */
17
- public $limit = 10;
18
-
19
- function init() {
20
-
21
- if (SQ_Classes_Helpers_Tools::getOption('sq_api') == '') {
22
- echo $this->getView('Errors/Connect');
23
- return;
24
- }
25
-
26
- //Checkin to API V2
27
- $this->checkin = SQ_Classes_RemoteController::checkin();
28
-
29
- if (is_wp_error($this->checkin)) {
30
- if ($this->checkin->get_error_message() == 'no_data') {
31
- echo $this->getView('Errors/Error');
32
- return;
33
- } elseif ($this->checkin->get_error_message() == 'maintenance') {
34
- echo $this->getView('Errors/Maintenance');
35
- return;
36
- }
37
- }
38
-
39
- $tab = SQ_Classes_Helpers_Tools::getValue('tab', 'audits');
40
-
41
- if (method_exists($this, $tab)) {
42
- call_user_func(array($this, $tab));
43
- }
44
-
45
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap-reboot');
46
- if (is_rtl()) {
47
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('popper');
48
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap.rtl');
49
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('rtl');
50
- } else {
51
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap');
52
- }
53
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('switchery');
54
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('fontawesome');
55
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('global');
56
-
57
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('assistant');
58
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('navbar');
59
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('audits');
60
-
61
- //@ob_flush();
62
- echo $this->getView('Audits/' . ucfirst($tab));
63
-
64
- //get the modal window for the assistant popup
65
- echo SQ_Classes_ObjController::getClass('SQ_Models_Assistant')->getModal();
66
- }
67
-
68
- /**
69
- * Load for Add Audit Page menu tab
70
- */
71
- public function addpage() {
72
- $search = (string)SQ_Classes_Helpers_Tools::getValue('skeyword', '');
73
- $this->pages = SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->getPages($search);
74
-
75
- //get also the audit pages
76
- $this->auditpage = SQ_Classes_RemoteController::getAuditPages();
77
-
78
- if (is_wp_error($this->auditpage)) {
79
- $this->auditpage = false;
80
- }
81
-
82
- }
83
-
84
- public function compare() {
85
- $sids = SQ_Classes_Helpers_Tools::getValue('sid', false);
86
-
87
- //get all the ids
88
- if ($sids && !empty($sids)) {
89
- foreach ($sids as $sid) {
90
- $audit = SQ_Classes_RemoteController::getAudit(array('id' => $sid));
91
-
92
- //Don't add error audits
93
- if (!is_wp_error($audit)) {
94
- $this->audits[] = $this->model->prepareAudit($audit);
95
- }
96
- }
97
-
98
- }
99
-
100
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('audits');
101
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('knob');
102
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('scrolltotop');
103
-
104
- }
105
-
106
- public function audit() {
107
- $days_back = (int)SQ_Classes_Helpers_Tools::getValue('days_back', 30);
108
- $sid = (int)SQ_Classes_Helpers_Tools::getValue('sid', false);
109
-
110
- if ($sid) {
111
-
112
- $this->audit = SQ_Classes_RemoteController::getAudit(array('id' => $sid, 'days_back' => $days_back));
113
-
114
- if ($auditpages = SQ_Classes_RemoteController::getAuditPages()) {
115
-
116
- if (is_wp_error($auditpages)) {
117
- SQ_Classes_Error::setError('Could not load the Audit Pages.');
118
- } else {
119
-
120
- if (!empty($auditpages)) {
121
- foreach ($auditpages as $auditpage) {
122
-
123
- /** @var SQ_Models_Domain_FocusPage $auditpage */
124
- $auditpage = SQ_Classes_ObjController::getDomain('SQ_Models_Domain_AuditPage', $auditpage);
125
-
126
- //If there is a local page, then show focus
127
- if ($auditpage->getWppost()) {
128
- $this->auditpages[] = SQ_Classes_ObjController::getClass('SQ_Models_Audits')->parseAuditPage($auditpage)->getAuditPage();
129
- }
130
-
131
- }
132
- }
133
-
134
- if (!is_wp_error($this->audit)) {
135
- $this->audit = $this->model->prepareAudit($this->audit);
136
- }
137
- }
138
-
139
- }
140
-
141
- } else {
142
- SQ_Classes_Error::setError(esc_html__("The audit was not found. Please load another audit.", _SQ_PLUGIN_NAME_));
143
-
144
- }
145
-
146
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('audits');
147
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('knob');
148
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('scrolltotop');
149
- SQ_Classes_Error::clearErrors();
150
-
151
- }
152
-
153
- public function audits() {
154
- add_action('sq_form_notices', array($this, 'getNotificationBar'));
155
-
156
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('audits');
157
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('knob');
158
-
159
- $this->setAuditPages();
160
- }
161
-
162
- /**
163
- * Set the audit pages and populate them
164
- * @return mixed
165
- */
166
- public function setAuditPages() {
167
- $days_back = (int)SQ_Classes_Helpers_Tools::getValue('days_back', 30);
168
- $this->audit = SQ_Classes_RemoteController::getAudit(array('days_back' => $days_back));
169
-
170
- if (is_wp_error($this->audit)) {
171
- SQ_Classes_Error::setError(esc_html__("Could not load the Audit Page.", _SQ_PLUGIN_NAME_));
172
- } elseif ($auditpages = SQ_Classes_RemoteController::getAuditPages()) {
173
-
174
- if (is_wp_error($auditpages)) {
175
- SQ_Classes_Error::setError('Could not load the Audit Pages.');
176
- } else {
177
-
178
- if (!empty($auditpages)) {
179
- foreach ($auditpages as $auditpage) {
180
-
181
- /** @var SQ_Models_Domain_FocusPage $auditpage */
182
- $auditpage = SQ_Classes_ObjController::getDomain('SQ_Models_Domain_AuditPage', $auditpage);
183
-
184
- //If there is a local page, then show focus
185
- $this->auditpages[] = SQ_Classes_ObjController::getClass('SQ_Models_Audits')->parseAuditPage($auditpage)->getAuditPage();
186
- }
187
- }
188
- }
189
- }
190
-
191
- return $this->auditpages;
192
- }
193
-
194
- /**
195
- * Load the Google Chart
196
- * @return string
197
- */
198
- public function getScripts() {
199
- return '<script>
200
- function drawScoreChart(id, values, reverse) {
201
- var data = google.visualization.arrayToDataTable(values);
202
-
203
- var options = {
204
-
205
- title : "",
206
- chartArea:{width:"80%",height:"70%"},
207
- vAxis: {title: "",
208
- viewWindowMode:"explicit",
209
- viewWindow: {
210
- max:100,
211
- min:0
212
- }},
213
- hAxis: {title: ""},
214
- seriesType: "bars",
215
- series: {2: {type: "line"}},
216
- legend: {position: "bottom"},
217
- colors:["#589ee4","#17d1f3"]
218
- };
219
-
220
- var chart = new google.visualization.ComboChart(document.getElementById(id));
221
- chart.draw(data, options);
222
- return chart;
223
- }
224
- </script>';
225
- }
226
-
227
- /**
228
- * Called when action is triggered
229
- *
230
- * @return void
231
- */
232
- public function action() {
233
- parent::action();
234
-
235
- switch (SQ_Classes_Helpers_Tools::getValue('action')) {
236
- case 'sq_auditpages_getaudit':
237
-
238
- $json = array();
239
-
240
- //Set all audit pages
241
- $this->setAuditPages();
242
-
243
- $json['stats'] = $this->getView('Audits/AuditStats');
244
- $json['html'] = $this->getView('Audits/AuditPages');
245
-
246
- //Support for international languages
247
- if (function_exists('iconv') && SQ_Classes_Helpers_Tools::getOption('sq_non_utf8_support')) {
248
- if (strpos(get_bloginfo("language"), 'en') === false) {
249
- $json['html'] = iconv('UTF-8', 'UTF-8//IGNORE', $json['html']);
250
- }
251
- }
252
-
253
- if (SQ_Classes_Helpers_Tools::isAjax()) {
254
- SQ_Classes_Helpers_Tools::setHeader('json');
255
-
256
- if (SQ_Classes_Error::isError()) {
257
- $json['error'] = SQ_Classes_Error::getError();
258
- }
259
-
260
- if (SQ_Classes_Helpers_Tools::getValue('sq_debug') == 'on') {
261
- return;
262
- }
263
- echo wp_json_encode($json);
264
- exit();
265
- }
266
- break;
267
- case 'sq_audits_addnew':
268
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_focuspages')) {
269
- return;
270
- }
271
-
272
- $post_id = (int)SQ_Classes_Helpers_Tools::getValue('post_id', 0);
273
- $term_id = (int)SQ_Classes_Helpers_Tools::getValue('term_id', 0);
274
- $taxonomy = SQ_Classes_Helpers_Tools::getValue('taxonomy', '');
275
- $post_type = SQ_Classes_Helpers_Tools::getValue('type', '');
276
-
277
- if ($post = SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->getCurrentSnippet($post_id, $term_id, $taxonomy, $post_type)) {
278
-
279
- //Save the post data in DB with the hash
280
- SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->savePost($post);
281
-
282
- $args = array();
283
- $args['post_id'] = $post->ID;
284
- $args['hash'] = $post->hash;
285
- $args['permalink'] = $post->url;
286
- if ($auditpage = SQ_Classes_RemoteController::addAuditPage($args)) {
287
- if (!is_wp_error($auditpage)) {
288
- SQ_Classes_Error::setError(esc_html__("Audit page is added. The audit may take a while so please be patient.", _SQ_PLUGIN_NAME_) . " <br /> ", 'success');
289
- set_transient('sq_auditpage_all', time());
290
- } elseif ($auditpage->get_error_message() == 'limit_exceed') {
291
- SQ_Classes_Error::setError(esc_html__("You reached the maximum number of audit pages for your account.", _SQ_PLUGIN_NAME_) . " <br /> ");
292
- }
293
- } else {
294
- SQ_Classes_Error::setError(esc_html__("Error! Could not add the audit page.", _SQ_PLUGIN_NAME_) . " <br /> ");
295
- }
296
-
297
- } else {
298
- SQ_Classes_Error::setError(esc_html__("Error! Could not find the audit page in your website.", _SQ_PLUGIN_NAME_) . " <br /> ");
299
- }
300
- break;
301
- case 'sq_audits_page_update':
302
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_focuspages')) {
303
- return;
304
- }
305
-
306
- $post_id = (int)SQ_Classes_Helpers_Tools::getValue('post_id', 0);
307
-
308
- if ($post_id) {
309
- $args = array();
310
- $args['post_id'] = $post_id;
311
-
312
- if ($auditpage = SQ_Classes_RemoteController::updateAudit($args)) {
313
- if (!is_wp_error($auditpage)) {
314
- SQ_Classes_Error::setMessage(esc_html__("Audit page sent for recheck. It may take a while so please be patient.", _SQ_PLUGIN_NAME_) . " <br /> ");
315
- } elseif ($auditpage->get_error_message() == 'too_many_attempts') {
316
- SQ_Classes_Error::setError(esc_html__("You've made too many requests, you can request one page audit per hour.", _SQ_PLUGIN_NAME_) . " <br /> ");
317
- } else {
318
- SQ_Classes_Error::setError(esc_html__("The page could not be sent for reaudit.", _SQ_PLUGIN_NAME_) . " <br /> ");
319
- }
320
- } else {
321
- SQ_Classes_Error::setError(esc_html__("The page could not be sent for reaudit.", _SQ_PLUGIN_NAME_) . " <br /> ");
322
- }
323
- }
324
- break;
325
- case 'sq_audits_update':
326
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_focuspages')) {
327
- return;
328
- }
329
-
330
- if ($auditpage = SQ_Classes_RemoteController::updateAudit()) {
331
- if (!is_wp_error($auditpage)) {
332
- SQ_Classes_Error::setError(esc_html__("Audit page sent for recheck. It may take a while so please be patient.", _SQ_PLUGIN_NAME_) . " <br /> ", 'success');
333
- set_transient('sq_auditpage_all', time());
334
- } elseif ($auditpage->get_error_message() == 'too_many_attempts') {
335
- SQ_Classes_Error::setError(esc_html__("The audit for all pages can be made once an hour.", _SQ_PLUGIN_NAME_) . " <br /> ");
336
- }
337
- } else {
338
- SQ_Classes_Error::setError(esc_html__("The audit for all pages can be made once an hour.", _SQ_PLUGIN_NAME_) . " <br /> ");
339
- }
340
- break;
341
- case 'sq_audits_delete':
342
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_focuspages')) {
343
- return;
344
- }
345
-
346
- if ($post_id = SQ_Classes_Helpers_Tools::getValue('id', false)) {
347
- SQ_Classes_RemoteController::deleteAuditPage(array('user_post_id' => $post_id));
348
- SQ_Classes_Error::setError(esc_html__("The audit page is deleted.", _SQ_PLUGIN_NAME_) . " <br /> ", 'success');
349
- } else {
350
- SQ_Classes_Error::setError(esc_html__("Invalid params!", _SQ_PLUGIN_NAME_) . " <br /> ");
351
- }
352
-
353
- break;
354
- case 'sq_audits_settings':
355
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
356
- return;
357
- }
358
-
359
- $email = sanitize_email(SQ_Classes_Helpers_Tools::getValue('sq_audit_email'));
360
- SQ_Classes_Helpers_Tools::saveOptions('sq_audit_email', $email);
361
-
362
- if ($email <> '') {
363
-
364
- //Save the settings on API too
365
- $args = array();
366
- $args['audit_email'] = $email;
367
- SQ_Classes_RemoteController::saveSettings($args);
368
- ///////////////////////////////
369
-
370
- //show the saved message
371
- SQ_Classes_Error::setMessage(esc_html__("Saved", _SQ_PLUGIN_NAME_));
372
- } else {
373
- SQ_Classes_Error::setError(esc_html__("Not a valid email address.", _SQ_PLUGIN_NAME_));
374
-
375
- }
376
-
377
- break;
378
- }
379
-
380
- }
381
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ class SQ_Controllers_Audits extends SQ_Classes_FrontController
5
+ {
6
+
7
+ /**
8
+ *
9
+ *
10
+ * @var object Checkin process
11
+ */
12
+ public $checkin;
13
+
14
+ public $blogs;
15
+ public $auditpage;
16
+ public $audit;
17
+ public $pages;
18
+ public $audits;
19
+ public $auditpages;
20
+
21
+ /**
22
+ *
23
+ *
24
+ * @var int Audit history limit
25
+ */
26
+ public $limit = 10;
27
+
28
+ function init()
29
+ {
30
+
31
+ if (SQ_Classes_Helpers_Tools::getOption('sq_api') == '') {
32
+ $this->show_view('Errors/Connect');
33
+ return;
34
+ }
35
+
36
+ //Checkin to API V2
37
+ $this->checkin = SQ_Classes_RemoteController::checkin();
38
+
39
+ if (is_wp_error($this->checkin)) {
40
+ if ($this->checkin->get_error_message() == 'no_data') {
41
+ $this->show_view('Errors/Error');
42
+ return;
43
+ } elseif ($this->checkin->get_error_message() == 'maintenance') {
44
+ $this->show_view('Errors/Maintenance');
45
+ return;
46
+ }
47
+ }
48
+
49
+ $tab = preg_replace("/[^a-zA-Z0-9]/", "", SQ_Classes_Helpers_Tools::getValue('tab', 'audits'));
50
+
51
+ if (method_exists($this, $tab)) {
52
+ call_user_func(array($this, $tab));
53
+ }
54
+ if (method_exists($this, $tab)) {
55
+ call_user_func(array($this, $tab));
56
+ }
57
+
58
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap-reboot');
59
+ if (is_rtl()) {
60
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('popper');
61
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap.rtl');
62
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('rtl');
63
+ } else {
64
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap');
65
+ }
66
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('switchery');
67
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('fontawesome');
68
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('global');
69
+
70
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('assistant');
71
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('navbar');
72
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('audits');
73
+
74
+ //@ob_flush();
75
+ $this->show_view('Audits/' . esc_attr(ucfirst($tab)));
76
+
77
+ //get the modal window for the assistant popup
78
+ echo SQ_Classes_ObjController::getClass('SQ_Models_Assistant')->getModal();
79
+ }
80
+
81
+ /**
82
+ * Load for Add Audit Page menu tab
83
+ */
84
+ public function addpage()
85
+ {
86
+ $search = (string)SQ_Classes_Helpers_Tools::getValue('skeyword', '');
87
+ $this->pages = SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->getPages($search);
88
+
89
+ //get also the audit pages
90
+ $this->auditpage = SQ_Classes_RemoteController::getAuditPages();
91
+
92
+ if (is_wp_error($this->auditpage)) {
93
+ $this->auditpage = false;
94
+ }
95
+
96
+ }
97
+
98
+ public function compare()
99
+ {
100
+ $sids = SQ_Classes_Helpers_Tools::getValue('sid', false);
101
+
102
+ //get all the ids
103
+ if ($sids && !empty($sids)) {
104
+ foreach ($sids as $sid) {
105
+ $audit = SQ_Classes_RemoteController::getAudit(array('id' => $sid));
106
+
107
+ //Don't add error audits
108
+ if (!is_wp_error($audit)) {
109
+ $this->audits[] = $this->model->prepareAudit($audit);
110
+ }
111
+ }
112
+
113
+ }
114
+
115
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('audits');
116
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('knob');
117
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('scrolltotop');
118
+
119
+ }
120
+
121
+ public function audit()
122
+ {
123
+ $days_back = (int)SQ_Classes_Helpers_Tools::getValue('days_back', 30);
124
+ $sid = (int)SQ_Classes_Helpers_Tools::getValue('sid', false);
125
+
126
+ if ($sid) {
127
+
128
+ $this->audit = SQ_Classes_RemoteController::getAudit(array('id' => $sid, 'days_back' => $days_back));
129
+
130
+ if ($auditpages = SQ_Classes_RemoteController::getAuditPages()) {
131
+
132
+ if (is_wp_error($auditpages)) {
133
+ SQ_Classes_Error::setError('Could not load the Audit Pages.');
134
+ } else {
135
+
136
+ if (!empty($auditpages)) {
137
+ foreach ($auditpages as $auditpage) {
138
+
139
+ /**
140
+ *
141
+ *
142
+ * @var SQ_Models_Domain_FocusPage $auditpage
143
+ */
144
+ $auditpage = SQ_Classes_ObjController::getDomain('SQ_Models_Domain_AuditPage', $auditpage);
145
+
146
+ //If there is a local page, then show focus
147
+ if ($auditpage->getWppost()) {
148
+ $this->auditpages[] = SQ_Classes_ObjController::getClass('SQ_Models_Audits')->parseAuditPage($auditpage)->getAuditPage();
149
+ }
150
+
151
+ }
152
+ }
153
+
154
+ if (!is_wp_error($this->audit)) {
155
+ $this->audit = $this->model->prepareAudit($this->audit);
156
+ }
157
+ }
158
+
159
+ }
160
+
161
+ } else {
162
+ SQ_Classes_Error::setError(esc_html__("The audit was not found. Please load another audit.", 'squirrly-seo'));
163
+
164
+ }
165
+
166
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('audits');
167
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('knob');
168
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('scrolltotop');
169
+ SQ_Classes_Error::clearErrors();
170
+
171
+ }
172
+
173
+ public function audits()
174
+ {
175
+ add_action('sq_form_notices', array($this, 'getNotificationBar'));
176
+
177
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('audits');
178
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('knob');
179
+
180
+ $this->setAuditPages();
181
+ }
182
+
183
+ /**
184
+ * Set the audit pages and populate them
185
+ *
186
+ * @return mixed
187
+ */
188
+ public function setAuditPages()
189
+ {
190
+ $days_back = (int)SQ_Classes_Helpers_Tools::getValue('days_back', 30);
191
+ $this->audit = SQ_Classes_RemoteController::getAudit(array('days_back' => $days_back));
192
+
193
+ if (is_wp_error($this->audit)) {
194
+ SQ_Classes_Error::setError(esc_html__("Could not load the Audit Page.", 'squirrly-seo'));
195
+ } elseif ($auditpages = SQ_Classes_RemoteController::getAuditPages()) {
196
+
197
+ if (is_wp_error($auditpages)) {
198
+ SQ_Classes_Error::setError('Could not load the Audit Pages.');
199
+ } else {
200
+
201
+ if (!empty($auditpages)) {
202
+ foreach ($auditpages as $auditpage) {
203
+
204
+ /**
205
+ *
206
+ *
207
+ * @var SQ_Models_Domain_FocusPage $auditpage
208
+ */
209
+ $auditpage = SQ_Classes_ObjController::getDomain('SQ_Models_Domain_AuditPage', $auditpage);
210
+
211
+ //If there is a local page, then show focus
212
+ $this->auditpages[] = SQ_Classes_ObjController::getClass('SQ_Models_Audits')->parseAuditPage($auditpage)->getAuditPage();
213
+ }
214
+ }
215
+ }
216
+ }
217
+
218
+ return $this->auditpages;
219
+ }
220
+
221
+ /**
222
+ * Load the Google Chart
223
+ *
224
+ * @return string
225
+ */
226
+ public function loadScripts()
227
+ {
228
+ echo '<script>
229
+ function drawScoreChart(id, values, reverse) {
230
+ var data = google.visualization.arrayToDataTable(values);
231
+
232
+ var options = {
233
+
234
+ title : "",
235
+ chartArea:{width:"80%",height:"70%"},
236
+ vAxis: {title: "",
237
+ viewWindowMode:"explicit",
238
+ viewWindow: {
239
+ max:100,
240
+ min:0
241
+ }},
242
+ hAxis: {title: ""},
243
+ seriesType: "bars",
244
+ series: {2: {type: "line"}},
245
+ legend: {position: "bottom"},
246
+ colors:["#589ee4","#17d1f3"]
247
+ };
248
+
249
+ var chart = new google.visualization.ComboChart(document.getElementById(id));
250
+ chart.draw(data, options);
251
+ return chart;
252
+ }
253
+ </script>';
254
+ }
255
+
256
+ /**
257
+ * Called when action is triggered
258
+ *
259
+ * @return void
260
+ */
261
+ public function action()
262
+ {
263
+ parent::action();
264
+
265
+ switch (SQ_Classes_Helpers_Tools::getValue('action')) {
266
+ case 'sq_auditpages_getaudit':
267
+
268
+ $json = array();
269
+
270
+ //Set all audit pages
271
+ $this->setAuditPages();
272
+
273
+ $json['stats'] = $this->get_view('Audits/AuditStats');
274
+ $json['html'] = $this->get_view('Audits/AuditPages');
275
+
276
+ //Support for international languages
277
+ if (function_exists('iconv') && SQ_Classes_Helpers_Tools::getOption('sq_non_utf8_support')) {
278
+ if (strpos(get_bloginfo("language"), 'en') === false) {
279
+ $json['html'] = iconv('UTF-8', 'UTF-8//IGNORE', $json['html']);
280
+ }
281
+ }
282
+
283
+ if (SQ_Classes_Helpers_Tools::isAjax()) {
284
+ SQ_Classes_Helpers_Tools::setHeader('json');
285
+
286
+ if (SQ_Classes_Error::isError()) {
287
+ $json['error'] = SQ_Classes_Error::getError();
288
+ }
289
+
290
+ if (SQ_Classes_Helpers_Tools::getValue('sq_debug') == 'on') {
291
+ return;
292
+ }
293
+ echo wp_json_encode($json);
294
+ exit();
295
+ }
296
+ break;
297
+ case 'sq_audits_addnew':
298
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_focuspages')) {
299
+ return;
300
+ }
301
+
302
+ $post_id = (int)SQ_Classes_Helpers_Tools::getValue('post_id', 0);
303
+ $term_id = (int)SQ_Classes_Helpers_Tools::getValue('term_id', 0);
304
+ $taxonomy = SQ_Classes_Helpers_Tools::getValue('taxonomy', '');
305
+ $post_type = SQ_Classes_Helpers_Tools::getValue('type', '');
306
+
307
+ if ($post = SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->getCurrentSnippet($post_id, $term_id, $taxonomy, $post_type)) {
308
+
309
+ //Save the post data in DB with the hash
310
+ SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->savePost($post);
311
+
312
+ $args = array();
313
+ $args['post_id'] = $post->ID;
314
+ $args['hash'] = $post->hash;
315
+ $args['permalink'] = $post->url;
316
+ if ($auditpage = SQ_Classes_RemoteController::addAuditPage($args)) {
317
+ if (!is_wp_error($auditpage)) {
318
+ SQ_Classes_Error::setError(esc_html__("Audit page is added. The audit may take a while so please be patient.", 'squirrly-seo') . " <br /> ", 'success');
319
+ set_transient('sq_auditpage_all', time());
320
+ } elseif ($auditpage->get_error_message() == 'limit_exceed') {
321
+ SQ_Classes_Error::setError(esc_html__("You reached the maximum number of audit pages for your account.", 'squirrly-seo') . " <br /> ");
322
+ }
323
+ } else {
324
+ SQ_Classes_Error::setError(esc_html__("Error! Could not add the audit page.", 'squirrly-seo') . " <br /> ");
325
+ }
326
+
327
+ } else {
328
+ SQ_Classes_Error::setError(esc_html__("Error! Could not find the audit page in your website.", 'squirrly-seo') . " <br /> ");
329
+ }
330
+ break;
331
+ case 'sq_audits_page_update':
332
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_focuspages')) {
333
+ return;
334
+ }
335
+
336
+ $post_id = (int)SQ_Classes_Helpers_Tools::getValue('post_id', 0);
337
+
338
+ if ($post_id) {
339
+ $args = array();
340
+ $args['post_id'] = $post_id;
341
+
342
+ if ($auditpage = SQ_Classes_RemoteController::updateAudit($args)) {
343
+ if (!is_wp_error($auditpage)) {
344
+ SQ_Classes_Error::setMessage(esc_html__("Audit page sent for recheck. It may take a while so please be patient.", 'squirrly-seo') . " <br /> ");
345
+ } elseif ($auditpage->get_error_message() == 'too_many_attempts') {
346
+ SQ_Classes_Error::setError(esc_html__("You've made too many requests, you can request one page audit per hour.", 'squirrly-seo') . " <br /> ");
347
+ } else {
348
+ SQ_Classes_Error::setError(esc_html__("The page could not be sent for reaudit.", 'squirrly-seo') . " <br /> ");
349
+ }
350
+ } else {
351
+ SQ_Classes_Error::setError(esc_html__("The page could not be sent for reaudit.", 'squirrly-seo') . " <br /> ");
352
+ }
353
+ }
354
+ break;
355
+ case 'sq_audits_update':
356
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_focuspages')) {
357
+ return;
358
+ }
359
+
360
+ if ($auditpage = SQ_Classes_RemoteController::updateAudit()) {
361
+ if (!is_wp_error($auditpage)) {
362
+ SQ_Classes_Error::setError(esc_html__("Audit page sent for recheck. It may take a while so please be patient.", 'squirrly-seo') . " <br /> ", 'success');
363
+ set_transient('sq_auditpage_all', time());
364
+ } elseif ($auditpage->get_error_message() == 'too_many_attempts') {
365
+ SQ_Classes_Error::setError(esc_html__("The audit for all pages can be made once an hour.", 'squirrly-seo') . " <br /> ");
366
+ }
367
+ } else {
368
+ SQ_Classes_Error::setError(esc_html__("The audit for all pages can be made once an hour.", 'squirrly-seo') . " <br /> ");
369
+ }
370
+ break;
371
+ case 'sq_audits_delete':
372
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_focuspages')) {
373
+ return;
374
+ }
375
+
376
+ if ($post_id = SQ_Classes_Helpers_Tools::getValue('id', false)) {
377
+ SQ_Classes_RemoteController::deleteAuditPage(array('user_post_id' => $post_id));
378
+ SQ_Classes_Error::setError(esc_html__("The audit page is deleted.", 'squirrly-seo') . " <br /> ", 'success');
379
+ } else {
380
+ SQ_Classes_Error::setError(esc_html__("Invalid params!", 'squirrly-seo') . " <br /> ");
381
+ }
382
+
383
+ break;
384
+ case 'sq_audits_settings':
385
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
386
+ return;
387
+ }
388
+
389
+ $email = sanitize_email(SQ_Classes_Helpers_Tools::getValue('sq_audit_email'));
390
+ SQ_Classes_Helpers_Tools::saveOptions('sq_audit_email', $email);
391
+
392
+ if ($email <> '') {
393
+
394
+ //Save the settings on API too
395
+ $args = array();
396
+ $args['audit_email'] = $email;
397
+ SQ_Classes_RemoteController::saveSettings($args);
398
+ ///////////////////////////////
399
+
400
+ //show the saved message
401
+ SQ_Classes_Error::setMessage(esc_html__("Saved", 'squirrly-seo'));
402
+ } else {
403
+ SQ_Classes_Error::setError(esc_html__("Not a valid email address.", 'squirrly-seo'));
404
+
405
+ }
406
+
407
+ break;
408
+ }
409
+
410
+ }
411
+ }
controllers/BulkSeo.php CHANGED
@@ -1,111 +1,115 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- class SQ_Controllers_BulkSeo extends SQ_Classes_FrontController {
5
-
6
- public $pages = array();
7
-
8
- function init() {
9
-
10
- $tab = SQ_Classes_Helpers_Tools::getValue('tab', 'bulkseo');
11
-
12
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap-reboot');
13
- if(is_rtl()){
14
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('popper');
15
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap.rtl');
16
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('rtl');
17
- }else{
18
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap');
19
- }
20
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('switchery');
21
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('fontawesome');
22
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('global');
23
-
24
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('assistant');
25
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('navbar');
26
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('seosettings');
27
-
28
- if (method_exists($this, $tab)) {
29
- call_user_func(array($this, $tab));
30
- }
31
-
32
- if (function_exists('wp_enqueue_media')) {
33
- wp_enqueue_media();
34
- }
35
-
36
- //@ob_flush();
37
- echo $this->getView('BulkSeo/' . ucfirst($tab));
38
-
39
- //get the modal window for the assistant popup
40
- echo SQ_Classes_ObjController::getClass('SQ_Models_Assistant')->getModal();
41
- }
42
-
43
- public function bulkseo() {
44
- add_action('sq_form_notices', array($this,'getNotificationBar'));
45
-
46
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bulkseo');
47
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('labels');
48
-
49
- $search = (string)SQ_Classes_Helpers_Tools::getValue('skeyword', '');
50
- $this->pages = SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->getPages($search);
51
-
52
- if (!empty($labels) || count((array)$this->pages) > 1) {
53
- //Get the labels for view use
54
- $this->labels = SQ_Classes_ObjController::getClass('SQ_Models_BulkSeo')->getLabels();
55
- }
56
- }
57
-
58
- /**
59
- * Called when action is triggered
60
- *
61
- * @return void
62
- */
63
- public function action() {
64
- parent::action();
65
-
66
- switch (SQ_Classes_Helpers_Tools::getValue('action')) {
67
-
68
- case 'sq_ajax_assistant_bulkseo':
69
- SQ_Classes_Helpers_Tools::setHeader('json');
70
-
71
- $response = array();
72
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
73
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
74
- echo wp_json_encode($response);
75
- exit();
76
- }
77
-
78
- $post_id = (int)SQ_Classes_Helpers_Tools::getValue('post_id', 0);
79
- $term_id = (int)SQ_Classes_Helpers_Tools::getValue('term_id', 0);
80
- $taxonomy = SQ_Classes_Helpers_Tools::getValue('taxonomy', '');
81
- $post_type = SQ_Classes_Helpers_Tools::getValue('post_type', '');
82
-
83
- //Set the Labels and Categories
84
- SQ_Classes_ObjController::getClass('SQ_Models_BulkSeo')->init();
85
- if ($post = SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->getCurrentSnippet($post_id, $term_id, $taxonomy, $post_type)) {
86
- $this->post = SQ_Classes_ObjController::getClass('SQ_Models_BulkSeo')->parsePage($post)->getPage();
87
- }
88
-
89
- $json = array();
90
- $json['html'] = $this->getView('BulkSeo/BulkseoRow');
91
- $json['html_dest'] = "#sq_row_" . $this->post->hash;
92
-
93
- $json['assistant'] = '';
94
- $categories = apply_filters('sq_assistant_categories_page', $this->post->hash);
95
- if (!empty($categories)) {
96
- foreach ($categories as $index => $category) {
97
- if (isset($category->assistant)) {
98
- $json['assistant'] .= $category->assistant;
99
- }
100
- }
101
- }
102
- $json['assistant_dest'] = "#sq_assistant_" . $this->post->hash;
103
-
104
- echo wp_json_encode($json);
105
- exit();
106
-
107
- }
108
-
109
- }
110
-
111
- }
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ class SQ_Controllers_BulkSeo extends SQ_Classes_FrontController
5
+ {
6
+
7
+ public $pages = array();
8
+
9
+ function init()
10
+ {
11
+
12
+ $tab = preg_replace("/[^a-zA-Z0-9]/", "", SQ_Classes_Helpers_Tools::getValue('tab', 'bulkseo'));
13
+
14
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap-reboot');
15
+ if(is_rtl()) {
16
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('popper');
17
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap.rtl');
18
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('rtl');
19
+ }else{
20
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap');
21
+ }
22
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('switchery');
23
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('fontawesome');
24
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('global');
25
+
26
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('assistant');
27
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('navbar');
28
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('seosettings');
29
+
30
+ if (method_exists($this, $tab)) {
31
+ call_user_func(array($this, $tab));
32
+ }
33
+
34
+ if (function_exists('wp_enqueue_media')) {
35
+ wp_enqueue_media();
36
+ }
37
+
38
+ //@ob_flush();
39
+ $this->show_view('BulkSeo/' . esc_attr(ucfirst($tab)));
40
+
41
+ //get the modal window for the assistant popup
42
+ echo SQ_Classes_ObjController::getClass('SQ_Models_Assistant')->getModal();
43
+ }
44
+
45
+ public function bulkseo()
46
+ {
47
+ add_action('sq_form_notices', array($this,'getNotificationBar'));
48
+
49
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bulkseo');
50
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('labels');
51
+
52
+ $search = (string)SQ_Classes_Helpers_Tools::getValue('skeyword', '');
53
+ $this->pages = SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->getPages($search);
54
+
55
+ if (!empty($labels) || count((array)$this->pages) > 1) {
56
+ //Get the labels for view use
57
+ $this->labels = SQ_Classes_ObjController::getClass('SQ_Models_BulkSeo')->getLabels();
58
+ }
59
+ }
60
+
61
+ /**
62
+ * Called when action is triggered
63
+ *
64
+ * @return void
65
+ */
66
+ public function action()
67
+ {
68
+ parent::action();
69
+
70
+ switch (SQ_Classes_Helpers_Tools::getValue('action')) {
71
+
72
+ case 'sq_ajax_assistant_bulkseo':
73
+ SQ_Classes_Helpers_Tools::setHeader('json');
74
+
75
+ $response = array();
76
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
77
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
78
+ echo wp_json_encode($response);
79
+ exit();
80
+ }
81
+
82
+ $post_id = (int)SQ_Classes_Helpers_Tools::getValue('post_id', 0);
83
+ $term_id = (int)SQ_Classes_Helpers_Tools::getValue('term_id', 0);
84
+ $taxonomy = SQ_Classes_Helpers_Tools::getValue('taxonomy', '');
85
+ $post_type = SQ_Classes_Helpers_Tools::getValue('post_type', '');
86
+
87
+ //Set the Labels and Categories
88
+ SQ_Classes_ObjController::getClass('SQ_Models_BulkSeo')->init();
89
+ if ($post = SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->getCurrentSnippet($post_id, $term_id, $taxonomy, $post_type)) {
90
+ $this->post = SQ_Classes_ObjController::getClass('SQ_Models_BulkSeo')->parsePage($post)->getPage();
91
+ }
92
+
93
+ $json = array();
94
+ $json['html'] = $this->get_view('BulkSeo/BulkseoRow');
95
+ $json['html_dest'] = "#sq_row_" . $this->post->hash;
96
+
97
+ $json['assistant'] = '';
98
+ $categories = apply_filters('sq_assistant_categories_page', $this->post->hash);
99
+ if (!empty($categories)) {
100
+ foreach ($categories as $index => $category) {
101
+ if (isset($category->assistant)) {
102
+ $json['assistant'] .= $category->assistant;
103
+ }
104
+ }
105
+ }
106
+ $json['assistant_dest'] = "#sq_assistant_" . $this->post->hash;
107
+
108
+ echo wp_json_encode($json);
109
+ exit();
110
+
111
+ }
112
+
113
+ }
114
+
115
+ }
controllers/CheckSeo.php CHANGED
@@ -1,381 +1,392 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- class SQ_Controllers_CheckSeo extends SQ_Classes_FrontController {
5
- public $report;
6
- public $score = 100;
7
- public $congratulations;
8
- public $report_time;
9
-
10
- /**
11
- * Set a custom category name
12
- *
13
- * @param $category_name
14
- * @return $this
15
- */
16
- public function setCategory($category_name) {
17
- $this->model->category_name = $category_name;
18
- return $this;
19
- }
20
-
21
- /**
22
- * Call the init on Dashboard
23
- * @return mixed|void
24
- */
25
- public function init() {
26
-
27
- if (!isset($this->congratulations)) {
28
- $this->congratulations = $this->getCongratulations();
29
- }
30
-
31
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('checkseo');
32
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('knob');
33
-
34
- //get the modal window for the assistant popup
35
- echo SQ_Classes_ObjController::getClass('SQ_Models_Assistant')->getModal();
36
-
37
- echo $this->getView('Goals/CheckSeo');
38
- }
39
-
40
- /**
41
- * Get the notifications from database
42
- * @return mixed
43
- */
44
- public function getNotifications() {
45
-
46
- //Load the report
47
- $report = $this->model->getDbTasks();
48
- //Load the tasks from database and filter them
49
- $tasks = $this->model->getTasks();
50
-
51
- // $this->model->dbtasks['tasks_for_today'] = array();
52
- // $this->model->dbtasks['count_tasks_for_today'] = 300;
53
- if (!empty($report)) {
54
-
55
- if (!isset($this->model->dbtasks['count_tasks_for_today'])) {
56
- $this->model->dbtasks['count_tasks_for_today'] = 3; //Show 3 goals per day
57
- }
58
-
59
- $urgent_tasks = array();
60
- $tasks_for_today = isset($this->model->dbtasks['tasks_for_today']) ? $this->model->dbtasks['tasks_for_today'] : array();
61
- if (!isset($tasks_for_today[date('Y-m-d')]) || count($tasks_for_today[date('Y-m-d')]) < $this->model->dbtasks['count_tasks_for_today']) {
62
- //If the tasks for today are not yet set
63
- $tasks_for_today = array(date('Y-m-d') => array());
64
- } else {
65
- //update the report to todays tasks
66
- foreach ($report as $function => $row) {
67
- //Limit today tasks
68
- if (isset($tasks[$function]['priority']) && $tasks[$function]['priority'] == 1) {
69
- if (!isset($tasks[$function]['positive'])) $tasks[$function]['positive'] = false;
70
-
71
- if (!$tasks[$function]['positive'] && isset($row['completed']) && !$row['completed']) {
72
- $urgent_tasks[$function] = $row;
73
- }
74
- }
75
-
76
- if (isset($tasks_for_today[date('Y-m-d')][$function])) {
77
- $tasks_for_today[date('Y-m-d')][$function] = $row;
78
- }
79
- }
80
-
81
- //add the urgent tasks first in the todays tasks
82
- if (!empty($urgent_tasks)) {
83
- $tasks_for_today[date('Y-m-d')] = array_merge($urgent_tasks, $tasks_for_today[date('Y-m-d')]);
84
- }
85
-
86
- //get the report from todays tasks
87
- $report = $tasks_for_today[date('Y-m-d')];
88
- }
89
-
90
- foreach ($report as $function => &$row) {
91
-
92
- //Make sure the function is set in the task
93
- if (is_array($row) && isset($tasks[$function])) {
94
- if (!isset($tasks[$function]['positive'])) $tasks[$function]['positive'] = false;
95
-
96
- $row = array_merge(array('completed' => false, 'active' => true, 'done' => false), $row);
97
- $row['status'] = $row['active'] ? ($row['done'] ? 'done' : (($row['completed']) ? 'completed' : '')) : 'ignore';
98
-
99
- //if isn't a success task and is not completes
100
- if (!$tasks[$function]['positive'] && ($row['status'] == '' || !empty($tasks_for_today[date('Y-m-d')]))) {
101
- $row = array_merge($tasks[$function], $row);
102
-
103
- //set defaults for each task
104
- $default = array(
105
- 'completed' => false,
106
- 'warning' => '',
107
- 'message' => '',
108
- 'solution' => '',
109
- 'link' => '',
110
- 'color' => '#4f1440',
111
- 'bullet' => false,
112
- 'priority' => 0,
113
- 'ignore' => false
114
- );
115
- $row = array_merge($default, $row);
116
-
117
- //replace links
118
- $row['warning'] = preg_replace('/\[link\]([^\[]*)\[\/link\]/i', '<a href="$1" target="_blank">$1</a>', $row['warning']);
119
- $row['message'] = preg_replace('/\[link\]([^\[]*)\[\/link\]/i', '<a href="$1" target="_blank">$1</a>', $row['message']);
120
- $row['solution'] = preg_replace('/\[link\]([^\[]*)\[\/link\]/i', '<a href="$1" target="_blank">$1</a>', $row['solution']);
121
-
122
- //add links to all tools
123
- if (!empty($row['tools'])) {
124
- foreach ($row['tools'] as &$tool) {
125
- switch ($tool) {
126
- case 'On-Page SEO':
127
- $tool = '<a href="https://plugin.squirrly.co/bulk-seo-settings/" target="_blank"><strong class="text-info">' . $tool . '</strong></a>';
128
- break;
129
- case 'SEO Automation':
130
- $tool = '<a href="https://howto.squirrly.co/kb/seo-automation/" target="_blank"><strong class="text-info">' . $tool . '</strong></a>';
131
- break;
132
- case 'SEO Snippet':
133
- $tool = '<a href="https://plugin.squirrly.co/seo-snippet-tool/" target="_blank"><strong class="text-info">' . $tool . '</strong></a>';
134
- break;
135
- case 'Focus Pages':
136
- $tool = '<a href="https://plugin.squirrly.co/focus-pages/" target="_blank"><strong class="text-info">' . $tool . '</strong></a>';
137
- break;
138
- case 'Live Assistant':
139
- $tool = '<a href="https://plugin.squirrly.co/seo-virtual-assistant/" target="_blank"><strong class="text-info">' . $tool . '</strong></a>';
140
- break;
141
- case 'Multiple Keyword Optimization':
142
- $tool = '<a href="https://plugin.squirrly.co/seo-virtual-assistant/" target="_blank"><strong class="text-info">' . $tool . '</strong></a>';
143
- break;
144
- case 'Keyword Research':
145
- $tool = '<a href="https://plugin.squirrly.co/best-keyword-research-tool-for-seo/" target="_blank"><strong class="text-info">' . $tool . '</strong></a>';
146
- break;
147
- case 'Briefcase':
148
- $tool = '<a href="https://plugin.squirrly.co/briefcase-keyword-management-tool/" target="_blank"><strong class="text-info">' . $tool . '</strong></a>';
149
- break;
150
- case 'Rankings':
151
- $tool = '<a href="https://plugin.squirrly.co/google-serp-checker/" target="_blank"><strong class="text-info">' . $tool . '</strong></a>';
152
- break;
153
- case 'Audits':
154
- $tool = '<a href="https://plugin.squirrly.co/site-seo-audit-tool/" target="_blank"><strong class="text-info">' . $tool . '</strong></a>';
155
- break;
156
- }
157
- }
158
- }
159
-
160
-
161
- } else {
162
- //if task is complete, remove it
163
- unset($report[$function]);
164
- }
165
- } else {
166
- //if function doesn't exists, remove the task
167
- unset($report[$function]);
168
- }
169
- }
170
-
171
-
172
- //Set the todays tasks if empty
173
- if (empty($tasks_for_today[date('Y-m-d')])) {
174
- $count = 1;
175
- foreach ($report as $function => $task) {
176
- //Limit today tasks
177
- if ($count > $this->model->dbtasks['count_tasks_for_today'] && $task['priority'] > 1) {
178
- unset($report[$function]);
179
- } else {
180
- $tasks_for_today[date('Y-m-d')][$function] = $task;
181
- }
182
-
183
- $count++;
184
- }
185
- }
186
-
187
- //Verify the goals gor today completion and progress
188
- if (!empty($tasks_for_today[date('Y-m-d')])) {
189
-
190
- $countdone = 0;
191
- foreach ($tasks_for_today[date('Y-m-d')] as $function => $task) {
192
-
193
- if (!isset($report[$function])) { //in case the goal was removed from API
194
- //remove the daily goal and move on
195
- unset($tasks_for_today[date('Y-m-d')][$function]);
196
- continue;
197
- }
198
-
199
- //count the completed goals for today's progress
200
- if (in_array($report[$function]['status'], array('completed', 'done', 'ignore'))) {
201
- $countdone++;
202
- }
203
- }
204
-
205
- //Calculate today's progress
206
- if (count($tasks_for_today[date('Y-m-d')]) > 0) {
207
- $this->score = number_format((100 * $countdone) / count($tasks_for_today[date('Y-m-d')]), 0);
208
- }
209
-
210
- }
211
-
212
- $this->model->dbtasks['tasks_for_today'] = $tasks_for_today;
213
- $this->model->saveDbTasks();
214
-
215
- }
216
-
217
- //return the report
218
- return $report;
219
- }
220
-
221
- /**
222
- * Get the notifications from database
223
- * @return mixed
224
- */
225
- public function getCongratulations() {
226
-
227
- $report = $this->model->getDbTasks();
228
- $tasks = $this->model->getTasks();
229
-
230
- if (!empty($report)) {
231
- foreach ($report as $function => &$row) {
232
-
233
- if (is_array($row) && isset($tasks[$function])) {
234
- if (!isset($tasks[$function]['positive'])) $tasks[$function]['positive'] = false;
235
-
236
- $row = array_merge(array('completed' => false, 'active' => true, 'done' => false, 'positive' => false), $row);
237
- $row['status'] = $row['active'] ? (($row['completed'] || $row['done']) ? 'completed' : '') : 'ignore';
238
-
239
- if ($tasks[$function]['positive'] && in_array($row['status'], array('completed', 'ignore'))) {
240
- $row = array_merge($tasks[$function], $row);
241
- } else {
242
- unset($report[$function]);
243
- }
244
-
245
- } else {
246
- unset($report[$function]);
247
- }
248
- }
249
- }
250
-
251
- //return the report
252
- return $report;
253
- }
254
-
255
- /**
256
- * Return the number of SEO errors if exists
257
- * @return bool|int
258
- */
259
- public function getErrorsCount() {
260
-
261
- $errors = 0;
262
-
263
- if (!isset($this->report)) {
264
- $this->report = $this->getNotifications();
265
- }
266
-
267
- if(!empty($this->report)){
268
- foreach ($this->report as $row){
269
- if($row['active'] && !$row['positive'] && !$row['completed'] && !$row['done'] ){
270
- $errors ++;
271
- }
272
- }
273
- }
274
-
275
- return $errors;
276
- }
277
-
278
- /**
279
- * Check SEO Actions
280
- */
281
- public function action() {
282
- parent::action();
283
-
284
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippets')) {
285
- return;
286
- }
287
-
288
- switch (SQ_Classes_Helpers_Tools::getValue('action')) {
289
-
290
- case 'sq_checkseo':
291
- SQ_Classes_Error::setMessage(esc_html__("Done!", _SQ_PLUGIN_NAME_));
292
- //Check all the SEO
293
- //Process all the tasks and save the report
294
- $this->model->checkSEO();
295
-
296
- break;
297
- case 'sq_moretasks':
298
- $this->model->dbtasks['tasks_for_today'] = array();
299
- $this->model->saveDbTasks();
300
-
301
- SQ_Classes_Error::setMessage(esc_html__("Done!", _SQ_PLUGIN_NAME_));
302
- //Check all the SEO
303
- //Process all the tasks and save the report
304
- $this->model->checkSEO();
305
-
306
- break;
307
- case 'sq_fixsettings':
308
- $name = SQ_Classes_Helpers_Tools::getValue('name', false);
309
- $value = SQ_Classes_Helpers_Tools::getValue('value', false);
310
-
311
- if ($name) {
312
- if (in_array($name, array_keys(SQ_Classes_Helpers_Tools::$options))) {
313
- SQ_Classes_Helpers_Tools::saveOptions($name, (bool)$value);
314
-
315
- //Process all the tasks and save the report
316
- $this->model->checkSEO();
317
-
318
- SQ_Classes_Error::setMessage(esc_html__("Fixed!", _SQ_PLUGIN_NAME_));
319
- return;
320
- }
321
- }
322
-
323
- SQ_Classes_Error::setError(esc_html__("Could not fix it. You need to change it manually.", _SQ_PLUGIN_NAME_));
324
- break;
325
- case 'sq_donetask':
326
- $name = SQ_Classes_Helpers_Tools::getValue('name', false);
327
-
328
- $this->model->doneTask($name);
329
-
330
- SQ_Classes_Error::setMessage(esc_html__("Saved! Task marked as done.", _SQ_PLUGIN_NAME_));
331
- break;
332
- case 'sq_resetignored':
333
- //Remove ignored tasks
334
- $this->model->clearIgnoredTasks();
335
-
336
- SQ_Classes_Error::setMessage(esc_html__("Saved!", _SQ_PLUGIN_NAME_));
337
-
338
- break;
339
- case 'sq_ajax_checkseo':
340
- SQ_Classes_Helpers_Tools::setHeader('json');
341
- $json = array();
342
-
343
- //Check all the SEO
344
- //Process all the tasks and save the report
345
- $this->model->checkSEO();
346
-
347
- if (SQ_Classes_Error::isError()) {
348
- $json['error'] = SQ_Classes_Error::getError();
349
- }
350
-
351
- echo wp_json_encode($json);
352
- exit();
353
- case 'sq_ajax_getgoals':
354
- SQ_Classes_Helpers_Tools::setHeader('json');
355
- $json = array();
356
-
357
- if (!isset($this->report)) {
358
- $this->report = $this->getNotifications();
359
- }
360
-
361
- $json['html'] = $this->getView('Goals/Goals');
362
-
363
- //Support for international languages
364
- if (function_exists('iconv') && SQ_Classes_Helpers_Tools::getOption('sq_non_utf8_support')) {
365
- if (strpos(get_bloginfo("language"), 'en') === false) {
366
- $json['html'] = iconv('UTF-8', 'UTF-8//IGNORE', $json['html']);
367
- }
368
- }
369
-
370
- if (SQ_Classes_Error::isError()) {
371
- $json['error'] = SQ_Classes_Error::getError();
372
- }
373
-
374
- echo wp_json_encode($json);
375
- exit();
376
- }
377
-
378
-
379
- }
380
-
381
- }
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ class SQ_Controllers_CheckSeo extends SQ_Classes_FrontController
5
+ {
6
+ public $report;
7
+ public $score = 100;
8
+ public $congratulations;
9
+ public $report_time;
10
+
11
+ /**
12
+ * Set a custom category name
13
+ *
14
+ * @param $category_name
15
+ * @return $this
16
+ */
17
+ public function setCategory($category_name)
18
+ {
19
+ $this->model->category_name = $category_name;
20
+ return $this;
21
+ }
22
+
23
+ /**
24
+ * Call the init on Dashboard
25
+ *
26
+ * @return mixed|void
27
+ */
28
+ public function init()
29
+ {
30
+
31
+ if (!isset($this->congratulations)) {
32
+ $this->congratulations = $this->getCongratulations();
33
+ }
34
+
35
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('checkseo');
36
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('knob');
37
+
38
+ //get the modal window for the assistant popup
39
+ echo SQ_Classes_ObjController::getClass('SQ_Models_Assistant')->getModal();
40
+
41
+ $this->show_view('Goals/CheckSeo');
42
+ }
43
+
44
+ /**
45
+ * Get the notifications from database
46
+ *
47
+ * @return mixed
48
+ */
49
+ public function getNotifications()
50
+ {
51
+
52
+ //Load the report
53
+ $report = $this->model->getDbTasks();
54
+ //Load the tasks from database and filter them
55
+ $tasks = $this->model->getTasks();
56
+
57
+ // $this->model->dbtasks['tasks_for_today'] = array();
58
+ // $this->model->dbtasks['count_tasks_for_today'] = 300;
59
+ if (!empty($report)) {
60
+
61
+ if (!isset($this->model->dbtasks['count_tasks_for_today'])) {
62
+ $this->model->dbtasks['count_tasks_for_today'] = 3; //Show 3 goals per day
63
+ }
64
+
65
+ $urgent_tasks = array();
66
+ $tasks_for_today = isset($this->model->dbtasks['tasks_for_today']) ? $this->model->dbtasks['tasks_for_today'] : array();
67
+ if (!isset($tasks_for_today[date('Y-m-d')]) || count($tasks_for_today[date('Y-m-d')]) < $this->model->dbtasks['count_tasks_for_today']) {
68
+ //If the tasks for today are not yet set
69
+ $tasks_for_today = array(date('Y-m-d') => array());
70
+ } else {
71
+ //update the report to todays tasks
72
+ foreach ($report as $function => $row) {
73
+ //Limit today tasks
74
+ if (isset($tasks[$function]['priority']) && $tasks[$function]['priority'] == 1) {
75
+ if (!isset($tasks[$function]['positive'])) $tasks[$function]['positive'] = false;
76
+
77
+ if (!$tasks[$function]['positive'] && isset($row['completed']) && !$row['completed']) {
78
+ $urgent_tasks[$function] = $row;
79
+ }
80
+ }
81
+
82
+ if (isset($tasks_for_today[date('Y-m-d')][$function])) {
83
+ $tasks_for_today[date('Y-m-d')][$function] = $row;
84
+ }
85
+ }
86
+
87
+ //add the urgent tasks first in the todays tasks
88
+ if (!empty($urgent_tasks)) {
89
+ $tasks_for_today[date('Y-m-d')] = array_merge($urgent_tasks, $tasks_for_today[date('Y-m-d')]);
90
+ }
91
+
92
+ //get the report from todays tasks
93
+ $report = $tasks_for_today[date('Y-m-d')];
94
+ }
95
+
96
+ foreach ($report as $function => &$row) {
97
+
98
+ //Make sure the function is set in the task
99
+ if (is_array($row) && isset($tasks[$function])) {
100
+ if (!isset($tasks[$function]['positive'])) $tasks[$function]['positive'] = false;
101
+
102
+ $row = array_merge(array('completed' => false, 'active' => true, 'done' => false), $row);
103
+ $row['status'] = $row['active'] ? ($row['done'] ? 'done' : (($row['completed']) ? 'completed' : '')) : 'ignore';
104
+
105
+ //if isn't a success task and is not completes
106
+ if (!$tasks[$function]['positive'] && ($row['status'] == '' || !empty($tasks_for_today[date('Y-m-d')]))) {
107
+ $row = array_merge($tasks[$function], $row);
108
+
109
+ //set defaults for each task
110
+ $default = array(
111
+ 'completed' => false,
112
+ 'warning' => '',
113
+ 'message' => '',
114
+ 'solution' => '',
115
+ 'link' => '',
116
+ 'color' => '#4f1440',
117
+ 'bullet' => false,
118
+ 'priority' => 0,
119
+ 'ignore' => false
120
+ );
121
+ $row = array_merge($default, $row);
122
+
123
+ //replace links
124
+ $row['warning'] = preg_replace('/\[link\]([^\[]*)\[\/link\]/i', '<a href="$1" target="_blank">$1</a>', $row['warning']);
125
+ $row['message'] = preg_replace('/\[link\]([^\[]*)\[\/link\]/i', '<a href="$1" target="_blank">$1</a>', $row['message']);
126
+ $row['solution'] = preg_replace('/\[link\]([^\[]*)\[\/link\]/i', '<a href="$1" target="_blank">$1</a>', $row['solution']);
127
+
128
+ //add links to all tools
129
+ if (!empty($row['tools'])) {
130
+ foreach ($row['tools'] as &$tool) {
131
+ switch ($tool) {
132
+ case 'On-Page SEO':
133
+ $tool = '<a href="https://plugin.squirrly.co/bulk-seo-settings/" target="_blank"><strong class="text-info">' . $tool . '</strong></a>';
134
+ break;
135
+ case 'SEO Automation':
136
+ $tool = '<a href="https://howto.squirrly.co/kb/seo-automation/" target="_blank"><strong class="text-info">' . $tool . '</strong></a>';
137
+ break;
138
+ case 'SEO Snippet':
139
+ $tool = '<a href="https://plugin.squirrly.co/seo-snippet-tool/" target="_blank"><strong class="text-info">' . $tool . '</strong></a>';
140
+ break;
141
+ case 'Focus Pages':
142
+ $tool = '<a href="https://plugin.squirrly.co/focus-pages/" target="_blank"><strong class="text-info">' . $tool . '</strong></a>';
143
+ break;
144
+ case 'Live Assistant':
145
+ $tool = '<a href="https://plugin.squirrly.co/seo-virtual-assistant/" target="_blank"><strong class="text-info">' . $tool . '</strong></a>';
146
+ break;
147
+ case 'Multiple Keyword Optimization':
148
+ $tool = '<a href="https://plugin.squirrly.co/seo-virtual-assistant/" target="_blank"><strong class="text-info">' . $tool . '</strong></a>';
149
+ break;
150
+ case 'Keyword Research':
151
+ $tool = '<a href="https://plugin.squirrly.co/best-keyword-research-tool-for-seo/" target="_blank"><strong class="text-info">' . $tool . '</strong></a>';
152
+ break;
153
+ case 'Briefcase':
154
+ $tool = '<a href="https://plugin.squirrly.co/briefcase-keyword-management-tool/" target="_blank"><strong class="text-info">' . $tool . '</strong></a>';
155
+ break;
156
+ case 'Rankings':
157
+ $tool = '<a href="https://plugin.squirrly.co/google-serp-checker/" target="_blank"><strong class="text-info">' . $tool . '</strong></a>';
158
+ break;
159
+ case 'Audits':
160
+ $tool = '<a href="https://plugin.squirrly.co/site-seo-audit-tool/" target="_blank"><strong class="text-info">' . $tool . '</strong></a>';
161
+ break;
162
+ }
163
+ }
164
+ }
165
+
166
+
167
+ } else {
168
+ //if task is complete, remove it
169
+ unset($report[$function]);
170
+ }
171
+ } else {
172
+ //if function doesn't exists, remove the task
173
+ unset($report[$function]);
174
+ }
175
+ }
176
+
177
+
178
+ //Set the todays tasks if empty
179
+ if (empty($tasks_for_today[date('Y-m-d')])) {
180
+ $count = 1;
181
+ foreach ($report as $function => $task) {
182
+ //Limit today tasks
183
+ if ($count > $this->model->dbtasks['count_tasks_for_today'] && $task['priority'] > 1) {
184
+ unset($report[$function]);
185
+ } else {
186
+ $tasks_for_today[date('Y-m-d')][$function] = $task;
187
+ }
188
+
189
+ $count++;
190
+ }
191
+ }
192
+
193
+ //Verify the goals gor today completion and progress
194
+ if (!empty($tasks_for_today[date('Y-m-d')])) {
195
+
196
+ $countdone = 0;
197
+ foreach ($tasks_for_today[date('Y-m-d')] as $function => $task) {
198
+
199
+ if (!isset($report[$function])) { //in case the goal was removed from API
200
+ //remove the daily goal and move on
201
+ unset($tasks_for_today[date('Y-m-d')][$function]);
202
+ continue;
203
+ }
204
+
205
+ //count the completed goals for today's progress
206
+ if (in_array($report[$function]['status'], array('completed', 'done', 'ignore'))) {
207
+ $countdone++;
208
+ }
209
+ }
210
+
211
+ //Calculate today's progress
212
+ if (count($tasks_for_today[date('Y-m-d')]) > 0) {
213
+ $this->score = number_format((100 * $countdone) / count($tasks_for_today[date('Y-m-d')]), 0);
214
+ }
215
+
216
+ }
217
+
218
+ $this->model->dbtasks['tasks_for_today'] = $tasks_for_today;
219
+ $this->model->saveDbTasks();
220
+
221
+ }
222
+
223
+ //return the report
224
+ return $report;
225
+ }
226
+
227
+ /**
228
+ * Get the notifications from database
229
+ *
230
+ * @return mixed
231
+ */
232
+ public function getCongratulations()
233
+ {
234
+
235
+ $report = $this->model->getDbTasks();
236
+ $tasks = $this->model->getTasks();
237
+
238
+ if (!empty($report)) {
239
+ foreach ($report as $function => &$row) {
240
+
241
+ if (is_array($row) && isset($tasks[$function])) {
242
+ if (!isset($tasks[$function]['positive'])) $tasks[$function]['positive'] = false;
243
+
244
+ $row = array_merge(array('completed' => false, 'active' => true, 'done' => false, 'positive' => false), $row);
245
+ $row['status'] = $row['active'] ? (($row['completed'] || $row['done']) ? 'completed' : '') : 'ignore';
246
+
247
+ if ($tasks[$function]['positive'] && in_array($row['status'], array('completed', 'ignore'))) {
248
+ $row = array_merge($tasks[$function], $row);
249
+ } else {
250
+ unset($report[$function]);
251
+ }
252
+
253
+ } else {
254
+ unset($report[$function]);
255
+ }
256
+ }
257
+ }
258
+
259
+ //return the report
260
+ return $report;
261
+ }
262
+
263
+ /**
264
+ * Return the number of SEO errors if exists
265
+ *
266
+ * @return bool|int
267
+ */
268
+ public function getErrorsCount()
269
+ {
270
+
271
+ $errors = 0;
272
+
273
+ if (!isset($this->report)) {
274
+ $this->report = $this->getNotifications();
275
+ }
276
+
277
+ if(!empty($this->report)) {
278
+ foreach ($this->report as $row){
279
+ if($row['active'] && !$row['positive'] && !$row['completed'] && !$row['done'] ) {
280
+ $errors ++;
281
+ }
282
+ }
283
+ }
284
+
285
+ return $errors;
286
+ }
287
+
288
+ /**
289
+ * Check SEO Actions
290
+ */
291
+ public function action()
292
+ {
293
+ parent::action();
294
+
295
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippets')) {
296
+ return;
297
+ }
298
+
299
+ switch (SQ_Classes_Helpers_Tools::getValue('action')) {
300
+
301
+ case 'sq_checkseo':
302
+ SQ_Classes_Error::setMessage(esc_html__("Done!", 'squirrly-seo'));
303
+ //Check all the SEO
304
+ //Process all the tasks and save the report
305
+ $this->model->checkSEO();
306
+
307
+ break;
308
+ case 'sq_moretasks':
309
+ $this->model->dbtasks['tasks_for_today'] = array();
310
+ $this->model->saveDbTasks();
311
+
312
+ SQ_Classes_Error::setMessage(esc_html__("Done!", 'squirrly-seo'));
313
+ //Check all the SEO
314
+ //Process all the tasks and save the report
315
+ $this->model->checkSEO();
316
+
317
+ break;
318
+ case 'sq_fixsettings':
319
+ $name = SQ_Classes_Helpers_Tools::getValue('name', false);
320
+ $value = SQ_Classes_Helpers_Tools::getValue('value', false);
321
+
322
+ if ($name) {
323
+ if (in_array($name, array_keys(SQ_Classes_Helpers_Tools::$options))) {
324
+ SQ_Classes_Helpers_Tools::saveOptions($name, (bool)$value);
325
+
326
+ //Process all the tasks and save the report
327
+ $this->model->checkSEO();
328
+
329
+ SQ_Classes_Error::setMessage(esc_html__("Fixed!", 'squirrly-seo'));
330
+ return;
331
+ }
332
+ }
333
+
334
+ SQ_Classes_Error::setError(esc_html__("Could not fix it. You need to change it manually.", 'squirrly-seo'));
335
+ break;
336
+ case 'sq_donetask':
337
+ $name = SQ_Classes_Helpers_Tools::getValue('name', false);
338
+
339
+ $this->model->doneTask($name);
340
+
341
+ SQ_Classes_Error::setMessage(esc_html__("Saved! Task marked as done.", 'squirrly-seo'));
342
+ break;
343
+ case 'sq_resetignored':
344
+ //Remove ignored tasks
345
+ $this->model->clearIgnoredTasks();
346
+
347
+ SQ_Classes_Error::setMessage(esc_html__("Saved!", 'squirrly-seo'));
348
+
349
+ break;
350
+ case 'sq_ajax_checkseo':
351
+ SQ_Classes_Helpers_Tools::setHeader('json');
352
+ $json = array();
353
+
354
+ //Check all the SEO
355
+ //Process all the tasks and save the report
356
+ $this->model->checkSEO();
357
+
358
+ if (SQ_Classes_Error::isError()) {
359
+ $json['error'] = SQ_Classes_Error::getError();
360
+ }
361
+
362
+ echo wp_json_encode($json);
363
+ exit();
364
+ case 'sq_ajax_getgoals':
365
+ SQ_Classes_Helpers_Tools::setHeader('json');
366
+ $json = array();
367
+
368
+ if (!isset($this->report)) {
369
+ $this->report = $this->getNotifications();
370
+ }
371
+
372
+ $json['html'] = $this->get_view('Goals/Goals');
373
+
374
+ //Support for international languages
375
+ if (function_exists('iconv') && SQ_Classes_Helpers_Tools::getOption('sq_non_utf8_support')) {
376
+ if (strpos(get_bloginfo("language"), 'en') === false) {
377
+ $json['html'] = iconv('UTF-8', 'UTF-8//IGNORE', $json['html']);
378
+ }
379
+ }
380
+
381
+ if (SQ_Classes_Error::isError()) {
382
+ $json['error'] = SQ_Classes_Error::getError();
383
+ }
384
+
385
+ echo wp_json_encode($json);
386
+ exit();
387
+ }
388
+
389
+
390
+ }
391
+
392
+ }
controllers/Dashboard.php CHANGED
@@ -1,43 +1,46 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- /**
5
- * Show on the WordPress Dashboard
6
- * Class SQ_Controllers_Dashboard
7
- */
8
- class SQ_Controllers_Dashboard extends SQ_Classes_FrontController {
9
-
10
-
11
- public function dashboard() {
12
-
13
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('dashboard');
14
- if (is_rtl()) {
15
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('rtl');
16
- }
17
-
18
- add_action('sq_form_notices', array($this, 'getNotificationBar'));
19
-
20
- echo $this->getView('Blocks/Dashboard');
21
- }
22
-
23
- public function action() {
24
- parent::action();
25
-
26
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippets')) {
27
- return;
28
- }
29
-
30
- switch (SQ_Classes_Helpers_Tools::getValue('action')) {
31
- case 'sq_ajaxcheckseo':
32
- SQ_Classes_Helpers_Tools::setHeader('json');
33
-
34
- //Check all the SEO
35
- //Process all the tasks and save the report
36
- SQ_Classes_ObjController::getClass('SQ_Models_CheckSeo')->checkSEO();
37
-
38
- echo wp_json_encode(array('data' => $this->getView('Blocks/Dashboard')));
39
- exit();
40
-
41
- }
42
- }
43
- }
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ /**
5
+ * Show on the WordPress Dashboard
6
+ * Class SQ_Controllers_Dashboard
7
+ */
8
+ class SQ_Controllers_Dashboard extends SQ_Classes_FrontController
9
+ {
10
+
11
+
12
+ public function dashboard()
13
+ {
14
+
15
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('dashboard');
16
+ if (is_rtl()) {
17
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('rtl');
18
+ }
19
+
20
+ add_action('sq_form_notices', array($this, 'getNotificationBar'));
21
+
22
+ $this->show_view('Blocks/Dashboard');
23
+ }
24
+
25
+ public function action()
26
+ {
27
+ parent::action();
28
+
29
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippets')) {
30
+ return;
31
+ }
32
+
33
+ switch (SQ_Classes_Helpers_Tools::getValue('action')) {
34
+ case 'sq_ajaxcheckseo':
35
+ SQ_Classes_Helpers_Tools::setHeader('json');
36
+
37
+ //Check all the SEO
38
+ //Process all the tasks and save the report
39
+ SQ_Classes_ObjController::getClass('SQ_Models_CheckSeo')->checkSEO();
40
+
41
+ echo wp_json_encode(array('data' => $this->get_view('Blocks/Dashboard')));
42
+ exit();
43
+
44
+ }
45
+ }
46
+ }
controllers/Features.php CHANGED
@@ -1,32 +1,34 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- /**
5
- * Features
6
- */
7
- class SQ_Controllers_Features extends SQ_Classes_FrontController {
8
-
9
- public function init() {
10
-
11
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap-reboot');
12
- if (is_rtl()) {
13
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('popper');
14
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap.rtl');
15
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('rtl');
16
- } else {
17
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap');
18
- }
19
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('fontawesome');
20
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('switchery');
21
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('global');
22
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('research');
23
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('navbar');
24
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('dashboard');
25
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('account');
26
-
27
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('assistant');
28
-
29
- parent::init();
30
- }
31
-
32
- }
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ /**
5
+ * Features
6
+ */
7
+ class SQ_Controllers_Features extends SQ_Classes_FrontController
8
+ {
9
+
10
+ public function init()
11
+ {
12
+
13
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap-reboot');
14
+ if (is_rtl()) {
15
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('popper');
16
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap.rtl');
17
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('rtl');
18
+ } else {
19
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap');
20
+ }
21
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('fontawesome');
22
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('switchery');
23
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('global');
24
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('research');
25
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('navbar');
26
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('dashboard');
27
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('account');
28
+
29
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('assistant');
30
+
31
+ parent::init();
32
+ }
33
+
34
+ }
controllers/FocusPages.php CHANGED
@@ -1,430 +1,459 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- class SQ_Controllers_FocusPages extends SQ_Classes_FrontController {
5
-
6
- /** @var object Checkin process with Squirrly Cloud */
7
- public $checkin;
8
- /** @var array list of tasks labels */
9
- public $labels = array();
10
- /** @var array found pages in DB */
11
- public $pages = array();
12
- /** @var array of focus pages from API */
13
- public $focuspages = array();
14
-
15
- /**
16
- * Initiate the class if called from menu
17
- * @return mixed|void
18
- */
19
- function init() {
20
-
21
- if (SQ_Classes_Helpers_Tools::getOption('sq_api') == '') {
22
- echo $this->getView('Errors/Connect');
23
- return;
24
- }
25
-
26
- //Checkin to API V2
27
- $this->checkin = SQ_Classes_RemoteController::checkin();
28
-
29
- if (is_wp_error($this->checkin)) {
30
- if ($this->checkin->get_error_message() == 'no_data') {
31
- echo $this->getView('Errors/Error');
32
- return;
33
- } elseif ($this->checkin->get_error_message() == 'maintenance') {
34
- echo $this->getView('Errors/Maintenance');
35
- return;
36
- }
37
- }
38
-
39
- $tab = SQ_Classes_Helpers_Tools::getValue('tab', 'pagelist');
40
-
41
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap-reboot');
42
- if (is_rtl()) {
43
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('popper');
44
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap.rtl');
45
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('rtl');
46
- } else {
47
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap');
48
- }
49
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('switchery');
50
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('fontawesome');
51
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('global');
52
-
53
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('assistant');
54
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('navbar');
55
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('seosettings');
56
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('chart');
57
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('knob');
58
-
59
- if (method_exists($this, $tab)) {
60
- call_user_func(array($this, $tab));
61
- }
62
- echo $this->getView('FocusPages/' . ucfirst($tab));
63
-
64
- //get the modal window for the assistant popup
65
- echo SQ_Classes_ObjController::getClass('SQ_Models_Assistant')->getModal();
66
- }
67
-
68
- /**
69
- * Load for Add Focus Page menu tab
70
- */
71
- public function addpage() {
72
- $search = (string)SQ_Classes_Helpers_Tools::getValue('skeyword', '');
73
- $this->pages = SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->getPages($search);
74
-
75
- //get also the focus pages
76
- $this->focuspages = SQ_Classes_RemoteController::getFocusPages();
77
-
78
- if (!empty($this->focuspages)) {
79
- foreach ($this->focuspages as &$focuspage) {
80
- $focuspage = SQ_Classes_ObjController::getDomain('SQ_Models_Domain_FocusPage', $focuspage);
81
- }
82
- }
83
- }
84
-
85
- /**
86
- * Called for List of the Focus Pages
87
- */
88
- public function pagelist() {
89
- add_action('sq_form_notices', array($this, 'getNotificationBar'));
90
-
91
- //Set the Labels and Categories
92
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('focuspages');
93
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('labels');
94
-
95
- //Set the focus pages and labels
96
- $this->setFocusPages();
97
- }
98
-
99
- /**
100
- * Set the Focus Pages and Labels
101
- */
102
- public function setFocusPages() {
103
- $labels = SQ_Classes_Helpers_Tools::getValue('slabel', array());
104
- $days_back = (int)SQ_Classes_Helpers_Tools::getValue('days_back', 90);
105
- $sid = SQ_Classes_Helpers_Tools::getValue('sid', false);
106
-
107
- SQ_Classes_ObjController::getClass('SQ_Models_FocusPages')->init();
108
- $this->checkin = SQ_Classes_RemoteController::checkin();
109
-
110
- if ($focuspages = SQ_Classes_RemoteController::getFocusPages()) {
111
-
112
- if (is_wp_error($focuspages)) {
113
- SQ_Classes_Error::setError('Could not load the Focus Pages.');
114
- } else {
115
-
116
- //Get the audits for the focus pages
117
- $audits = SQ_Classes_RemoteController::getFocusAudits(array('post_id' => $sid, 'days_back' => $days_back));
118
-
119
- if (!empty($focuspages)) {
120
- foreach ($focuspages as $focuspage) {
121
-
122
- //Add the audit data if exists
123
- if (!is_wp_error($audits)) {
124
- if (isset($focuspage->user_post_id) && !empty($audits)) {
125
- foreach ($audits as $audit) {
126
- if ($focuspage->user_post_id == $audit->user_post_id) {
127
- if (isset($audit->audit)) $audit->audit = json_decode($audit->audit); //set the audit data
128
- if (isset($audit->stats)) $audit->stats = json_decode($audit->stats); //set the stats and progress data
129
- $focuspage = (object)array_merge((array)$focuspage, (array)$audit);
130
- break;
131
- }
132
- }
133
- }
134
- }
135
-
136
- /** @var SQ_Models_Domain_FocusPage $focuspage */
137
- $focuspage = SQ_Classes_ObjController::getDomain('SQ_Models_Domain_FocusPage', $focuspage);
138
-
139
- //set the connection info with GSC and GA
140
- $focuspage->audit->sq_analytics_gsc_connected = (isset($this->checkin->connection_gsc) ? $this->checkin->connection_gsc : 0);
141
- $focuspage->audit->sq_analytics_google_connected = (isset($this->checkin->connection_ga) ? $this->checkin->connection_ga : 0);
142
- $focuspage->audit->sq_subscription_serpcheck = (isset($this->checkin->subscription_serpcheck) ? $this->checkin->subscription_serpcheck : 0);
143
-
144
- //SQ_Debug::dump($focuspage, $focuspage->audit);
145
-
146
- //If there is a local page, then show focus
147
- if ($focuspage->getWppost()) {
148
- //if post_id is set, show only that focus page
149
- if ($sid && $focuspage->id <> $sid) {
150
- continue;
151
- }
152
-
153
- $this->focuspages[] = SQ_Classes_ObjController::getClass('SQ_Models_FocusPages')->parseFocusPage($focuspage, $labels)->getFocusPage();
154
-
155
- } elseif ($focuspage->user_post_id) {
156
- SQ_Classes_Error::setError(esc_html__("Focus Page does not exist or was deleted from your website.", _SQ_PLUGIN_NAME_));
157
- SQ_Classes_RemoteController::deleteFocusPage(array('user_post_id' => $focuspage->user_post_id));
158
- }
159
- }
160
- }
161
- }
162
- }
163
-
164
- //Remove the blank focus pages
165
- $this->focuspages = array_filter($this->focuspages);
166
-
167
- //Get the labels for view use
168
- if (!empty($labels) || count((array)$this->focuspages) > 1) {
169
- $this->labels = SQ_Classes_ObjController::getClass('SQ_Models_FocusPages')->getLabels();
170
- }
171
- }
172
-
173
- /**
174
- * Load the Google Chart
175
- * @return string
176
- */
177
- public function getScripts() {
178
- return '<script>
179
- function drawScoreChart(id, values, reverse) {
180
- var data = google.visualization.arrayToDataTable(values);
181
-
182
- var options = {
183
-
184
- title : "",
185
- chartArea:{width:"85%",height:"80%"},
186
- enableInteractivity: "true",
187
- tooltip: {trigger: "auto"},
188
- vAxis: {
189
- direction: ((reverse) ? -1 : 1),
190
- title: "",
191
- viewWindowMode:"explicit",
192
- viewWindow: {
193
- max:100,
194
- min:0
195
- }},
196
- hAxis: {
197
- title: "",
198
- baselineColor: "transparent",
199
- gridlineColor: "transparent",
200
- textPosition: "none"
201
- } ,
202
- seriesType: "bars",
203
- series: {2: {type: "line"}},
204
- legend: {position: "bottom"},
205
- colors:["#17c6ea"]
206
- };
207
-
208
- var chart = new google.visualization.ComboChart(document.getElementById(id));
209
- chart.draw(data, options);
210
- return chart;
211
- }
212
- function drawRankingChart(id, values, reverse) {
213
- var data = google.visualization.arrayToDataTable(values);
214
-
215
- var options = {
216
-
217
- curveType: "function",
218
- title: "",
219
- chartArea:{width:"100%",height:"100%"},
220
- enableInteractivity: "true",
221
- tooltip: {trigger: "auto"},
222
- pointSize: "2",
223
- colors: ["#55b2ca"],
224
- hAxis: {
225
- baselineColor: "transparent",
226
- gridlineColor: "transparent",
227
- textPosition: "none"
228
- } ,
229
- vAxis:{
230
- direction: ((reverse) ? -1 : 1),
231
- baselineColor: "transparent",
232
- gridlineColor: "transparent",
233
- textPosition: "none"
234
- }
235
- };
236
-
237
- var chart = new google.visualization.LineChart(document.getElementById(id));
238
- chart.draw(data, options);
239
- return chart;
240
- }
241
- function drawTrafficChart(id, values, reverse) {
242
- var data = google.visualization.arrayToDataTable(values);
243
-
244
- var options = {
245
-
246
- title : "",
247
- chartArea:{width:"85%",height:"80%"},
248
- enableInteractivity: "true",
249
- tooltip: {trigger: "auto"},
250
- vAxis: {
251
- direction: ((reverse) ? -1 : 1),
252
- title: "",
253
- viewWindowMode:"explicit"
254
- },
255
- hAxis: {
256
- title: "",
257
- baselineColor: "transparent",
258
- gridlineColor: "transparent",
259
- textPosition: "none"
260
- } ,
261
- seriesType: "bars",
262
- series: {2: {type: "line"}},
263
- legend: {position: "bottom"},
264
- colors:["#17c6ea"]
265
- };
266
-
267
- var chart = new google.visualization.ComboChart(document.getElementById(id));
268
- chart.draw(data, options);
269
- return chart;
270
- }
271
- </script>';
272
- }
273
-
274
- /**
275
- * Called when action is triggered
276
- *
277
- * @return void
278
- */
279
- public function action() {
280
-
281
- parent::action();
282
-
283
- switch (SQ_Classes_Helpers_Tools::getValue('action')) {
284
-
285
- case 'sq_focuspages_inspecturl':
286
- $json = array();
287
- SQ_Classes_Helpers_Tools::setHeader('json');
288
- $post_id = (int)SQ_Classes_Helpers_Tools::getValue('post_id', 0);
289
-
290
- //Set the focus pages and labels
291
- $args = array();
292
- $args['post_id'] = $post_id;
293
- if ($json['html'] = SQ_Classes_RemoteController::getInspectURL($args)) {
294
-
295
- //Support for international languages
296
- if (function_exists('iconv') && SQ_Classes_Helpers_Tools::getOption('sq_non_utf8_support')) {
297
- if (strpos(get_bloginfo("language"), 'en') === false) {
298
- $json['html'] = iconv('UTF-8', 'UTF-8//IGNORE', $json['html']);
299
- }
300
- }
301
- }
302
-
303
- if (SQ_Classes_Error::isError()) {
304
- $json['error'] = SQ_Classes_Error::getError();
305
- }
306
-
307
- echo wp_json_encode($json);
308
- exit();
309
- case 'sq_focuspages_getpage':
310
- $json = array();
311
- SQ_Classes_Helpers_Tools::setHeader('json');
312
-
313
-
314
- //Set the focus pages and labels
315
- $this->setFocusPages();
316
-
317
- $json['html'] = $this->getView('FocusPages/FocusPages');
318
-
319
- //Support for international languages
320
- if (function_exists('iconv') && SQ_Classes_Helpers_Tools::getOption('sq_non_utf8_support')) {
321
- if (strpos(get_bloginfo("language"), 'en') === false) {
322
- $json['html'] = iconv('UTF-8', 'UTF-8//IGNORE', $json['html']);
323
- }
324
- }
325
-
326
- if (SQ_Classes_Error::isError()) {
327
- $json['error'] = SQ_Classes_Error::getError();
328
- }
329
-
330
- echo wp_json_encode($json);
331
- exit();
332
- case 'sq_focuspages_addnew':
333
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_focuspages')) {
334
- return;
335
- }
336
-
337
- $term_id = (int)SQ_Classes_Helpers_Tools::getValue('term_id', 0);
338
- $taxonomy = SQ_Classes_Helpers_Tools::getValue('taxonomy', '');
339
- $post_type = SQ_Classes_Helpers_Tools::getValue('type', '');
340
-
341
- if ($post_id = (int)SQ_Classes_Helpers_Tools::getValue('post_id', 0)) {
342
- if ($post = SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->getCurrentSnippet($post_id, $term_id, $taxonomy, $post_type)) {
343
- //Save the post data in DB with the hash
344
- SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->savePost($post);
345
-
346
- if ($post->post_status == 'publish' && $post->ID == $post_id) {
347
- //send the post to API
348
- $args = array();
349
- $args['post_id'] = $post->ID;
350
- $args['hash'] = $post->hash;
351
- $args['permalink'] = $post->url;
352
- if ($focuspage = SQ_Classes_RemoteController::addFocusPage($args)) {
353
- if (!is_wp_error($focuspage)) {
354
- SQ_Classes_Error::setError(esc_html__("Focus page is added. The audit may take a while so please be patient.", _SQ_PLUGIN_NAME_) . " <br /> ", 'success');
355
- if (isset($focuspage->user_post_id)) {
356
- set_transient('sq_auditpage_' . $focuspage->user_post_id, time());
357
-
358
- SQ_Classes_Helpers_Tools::saveOptions('seoreport_time', false);
359
- }
360
- } elseif ($focuspage->get_error_message() == 'limit_exceed') {
361
- SQ_Classes_Error::setError(esc_html__("You reached the maximum number of focus pages for all your websites.", _SQ_PLUGIN_NAME_) . " <br /> ");
362
- }
363
- } else {
364
- SQ_Classes_Error::setError(esc_html__("Error! Could not add the focus page.", _SQ_PLUGIN_NAME_) . " <br /> ");
365
- }
366
- } else {
367
- SQ_Classes_Error::setError(esc_html__("Error! This focus page is not public.", _SQ_PLUGIN_NAME_) . " <br /> ");
368
- }
369
-
370
- } else {
371
- SQ_Classes_Error::setError(sprintf(esc_html__("Error! Could not find the focus page %d in your website.", _SQ_PLUGIN_NAME_), $post_id) . " <br /> ");
372
- }
373
- }
374
- break;
375
- case 'sq_focuspages_update':
376
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_focuspages')) {
377
- return;
378
- }
379
-
380
- $post_id = (int)SQ_Classes_Helpers_Tools::getValue('post_id', 0);
381
- $term_id = (int)SQ_Classes_Helpers_Tools::getValue('term_id', 0);
382
- $taxonomy = SQ_Classes_Helpers_Tools::getValue('taxonomy', '');
383
- $post_type = SQ_Classes_Helpers_Tools::getValue('type', '');
384
- if ($id = (int)SQ_Classes_Helpers_Tools::getValue('id', 0)) {
385
- if ($post = SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->getCurrentSnippet($post_id, $term_id, $taxonomy, $post_type)) {
386
-
387
- //Save the post data in DB with the hash
388
- SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->savePost($post);
389
-
390
- //send the post to API
391
- $args = array();
392
- $args['post_id'] = $id;
393
- $args['hash'] = $post->hash;
394
- $args['permalink'] = $post->url;
395
- if ($focuspage = SQ_Classes_RemoteController::updateFocusPage($args)) {
396
-
397
- if (!is_wp_error($focuspage)) {
398
- SQ_Classes_Error::setError(esc_html__("Focus page sent for recheck. It may take a while so please be patient.", _SQ_PLUGIN_NAME_) . " <br /> ", 'success');
399
- set_transient('sq_auditpage_' . $id, time());
400
- } elseif ($focuspage->get_error_message() == 'too_many_attempts') {
401
- SQ_Classes_Error::setError(esc_html__("You've made too many requests, please wait a few minutes.", _SQ_PLUGIN_NAME_) . " <br /> ");
402
- }
403
-
404
- } else {
405
- SQ_Classes_Error::setError(esc_html__("You've made too many requests, please wait a few minutes.", _SQ_PLUGIN_NAME_) . " <br /> ");
406
- set_transient('sq_auditpage_' . $id, time());
407
- }
408
-
409
- } else {
410
- SQ_Classes_Error::setError(sprintf(esc_html__("Error! Could not find the focus page %d in your website.", _SQ_PLUGIN_NAME_), $post_id) . " <br /> ");
411
- }
412
- }
413
- break;
414
- case 'sq_focuspages_delete':
415
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_focuspages')) {
416
- return;
417
- }
418
-
419
- if ($post_id = SQ_Classes_Helpers_Tools::getValue('id', false)) {
420
- SQ_Classes_RemoteController::deleteFocusPage(array('user_post_id' => $post_id));
421
- SQ_Classes_Error::setError(esc_html__("The focus page is deleted", _SQ_PLUGIN_NAME_) . " <br /> ", 'success');
422
- } else {
423
- SQ_Classes_Error::setError(esc_html__("Invalid params!", _SQ_PLUGIN_NAME_) . " <br /> ");
424
- }
425
-
426
- break;
427
- }
428
-
429
- }
430
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ class SQ_Controllers_FocusPages extends SQ_Classes_FrontController
5
+ {
6
+
7
+ /**
8
+ *
9
+ *
10
+ * @var object Checkin process with Squirrly Cloud
11
+ */
12
+ public $checkin;
13
+ /**
14
+ *
15
+ *
16
+ * @var array list of tasks labels
17
+ */
18
+ public $labels = array();
19
+ /**
20
+ *
21
+ *
22
+ * @var array found pages in DB
23
+ */
24
+ public $pages = array();
25
+ /**
26
+ *
27
+ *
28
+ * @var array of focus pages from API
29
+ */
30
+ public $focuspages = array();
31
+
32
+ /**
33
+ * Initiate the class if called from menu
34
+ *
35
+ * @return mixed|void
36
+ */
37
+ function init()
38
+ {
39
+
40
+ if (SQ_Classes_Helpers_Tools::getOption('sq_api') == '') {
41
+ $this->show_view('Errors/Connect');
42
+ return;
43
+ }
44
+
45
+ //Checkin to API V2
46
+ $this->checkin = SQ_Classes_RemoteController::checkin();
47
+
48
+ if (is_wp_error($this->checkin)) {
49
+ if ($this->checkin->get_error_message() == 'no_data') {
50
+ $this->show_view('Errors/Error');
51
+ return;
52
+ } elseif ($this->checkin->get_error_message() == 'maintenance') {
53
+ $this->show_view('Errors/Maintenance');
54
+ return;
55
+ }
56
+ }
57
+
58
+ $tab = preg_replace("/[^a-zA-Z0-9]/", "", SQ_Classes_Helpers_Tools::getValue('tab', 'pagelist'));
59
+
60
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap-reboot');
61
+ if (is_rtl()) {
62
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('popper');
63
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap.rtl');
64
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('rtl');
65
+ } else {
66
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap');
67
+ }
68
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('switchery');
69
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('fontawesome');
70
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('global');
71
+
72
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('assistant');
73
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('navbar');
74
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('seosettings');
75
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('chart');
76
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('knob');
77
+
78
+ if (method_exists($this, $tab)) {
79
+ call_user_func(array($this, $tab));
80
+ }
81
+ $this->show_view('FocusPages/' . esc_attr(ucfirst($tab)));
82
+
83
+ //get the modal window for the assistant popup
84
+ echo SQ_Classes_ObjController::getClass('SQ_Models_Assistant')->getModal();
85
+ }
86
+
87
+ /**
88
+ * Load for Add Focus Page menu tab
89
+ */
90
+ public function addpage()
91
+ {
92
+ $search = (string)SQ_Classes_Helpers_Tools::getValue('skeyword', '');
93
+ $this->pages = SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->getPages($search);
94
+
95
+ //get also the focus pages
96
+ $this->focuspages = SQ_Classes_RemoteController::getFocusPages();
97
+
98
+ if (!empty($this->focuspages)) {
99
+ foreach ($this->focuspages as &$focuspage) {
100
+ $focuspage = SQ_Classes_ObjController::getDomain('SQ_Models_Domain_FocusPage', $focuspage);
101
+ }
102
+ }
103
+ }
104
+
105
+ /**
106
+ * Called for List of the Focus Pages
107
+ */
108
+ public function pagelist()
109
+ {
110
+ add_action('sq_form_notices', array($this, 'getNotificationBar'));
111
+
112
+ //Set the Labels and Categories
113
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('focuspages');
114
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('labels');
115
+
116
+ //Set the focus pages and labels
117
+ $this->setFocusPages();
118
+ }
119
+
120
+ /**
121
+ * Set the Focus Pages and Labels
122
+ */
123
+ public function setFocusPages()
124
+ {
125
+ $labels = SQ_Classes_Helpers_Tools::getValue('slabel', array());
126
+ $days_back = (int)SQ_Classes_Helpers_Tools::getValue('days_back', 90);
127
+ $sid = SQ_Classes_Helpers_Tools::getValue('sid', false);
128
+
129
+ SQ_Classes_ObjController::getClass('SQ_Models_FocusPages')->init();
130
+ $this->checkin = SQ_Classes_RemoteController::checkin();
131
+
132
+ if ($focuspages = SQ_Classes_RemoteController::getFocusPages()) {
133
+
134
+ if (is_wp_error($focuspages)) {
135
+ SQ_Classes_Error::setError('Could not load the Focus Pages.');
136
+ } else {
137
+
138
+ //Get the audits for the focus pages
139
+ $audits = SQ_Classes_RemoteController::getFocusAudits(array('post_id' => $sid, 'days_back' => $days_back));
140
+
141
+ if (!empty($focuspages)) {
142
+ foreach ($focuspages as $focuspage) {
143
+
144
+ //Add the audit data if exists
145
+ if (!is_wp_error($audits)) {
146
+ if (isset($focuspage->user_post_id) && !empty($audits)) {
147
+ foreach ($audits as $audit) {
148
+ if ($focuspage->user_post_id == $audit->user_post_id) {
149
+ if (isset($audit->audit)) $audit->audit = json_decode($audit->audit); //set the audit data
150
+ if (isset($audit->stats)) $audit->stats = json_decode($audit->stats); //set the stats and progress data
151
+ $focuspage = (object)array_merge((array)$focuspage, (array)$audit);
152
+ break;
153
+ }
154
+ }
155
+ }
156
+ }
157
+
158
+ /**
159
+ *
160
+ *
161
+ * @var SQ_Models_Domain_FocusPage $focuspage
162
+ */
163
+ $focuspage = SQ_Classes_ObjController::getDomain('SQ_Models_Domain_FocusPage', $focuspage);
164
+
165
+ //set the connection info with GSC and GA
166
+ $focuspage->audit->sq_analytics_gsc_connected = (isset($this->checkin->connection_gsc) ? $this->checkin->connection_gsc : 0);
167
+ $focuspage->audit->sq_analytics_google_connected = (isset($this->checkin->connection_ga) ? $this->checkin->connection_ga : 0);
168
+ $focuspage->audit->sq_subscription_serpcheck = (isset($this->checkin->subscription_serpcheck) ? $this->checkin->subscription_serpcheck : 0);
169
+
170
+ //SQ_Debug::dump($focuspage, $focuspage->audit);
171
+
172
+ //If there is a local page, then show focus
173
+ if ($focuspage->getWppost()) {
174
+ //if post_id is set, show only that focus page
175
+ if ($sid && $focuspage->id <> $sid) {
176
+ continue;
177
+ }
178
+
179
+ $this->focuspages[] = SQ_Classes_ObjController::getClass('SQ_Models_FocusPages')->parseFocusPage($focuspage, $labels)->getFocusPage();
180
+
181
+ } elseif ($focuspage->user_post_id) {
182
+ SQ_Classes_Error::setError(esc_html__("Focus Page does not exist or was deleted from your website.", 'squirrly-seo'));
183
+ SQ_Classes_RemoteController::deleteFocusPage(array('user_post_id' => $focuspage->user_post_id));
184
+ }
185
+ }
186
+ }
187
+ }
188
+ }
189
+
190
+ //Remove the blank focus pages
191
+ $this->focuspages = array_filter($this->focuspages);
192
+
193
+ //Get the labels for view use
194
+ if (!empty($labels) || count((array)$this->focuspages) > 1) {
195
+ $this->labels = SQ_Classes_ObjController::getClass('SQ_Models_FocusPages')->getLabels();
196
+ }
197
+ }
198
+
199
+ /**
200
+ * Load the Google Chart
201
+ *
202
+ * @return string
203
+ */
204
+ public function loadScripts()
205
+ {
206
+ echo '<script>
207
+ function drawScoreChart(id, values, reverse) {
208
+ var data = google.visualization.arrayToDataTable(values);
209
+
210
+ var options = {
211
+
212
+ title : "",
213
+ chartArea:{width:"85%",height:"80%"},
214
+ enableInteractivity: "true",
215
+ tooltip: {trigger: "auto"},
216
+ vAxis: {
217
+ direction: ((reverse) ? -1 : 1),
218
+ title: "",
219
+ viewWindowMode:"explicit",
220
+ viewWindow: {
221
+ max:100,
222
+ min:0
223
+ }},
224
+ hAxis: {
225
+ title: "",
226
+ baselineColor: "transparent",
227
+ gridlineColor: "transparent",
228
+ textPosition: "none"
229
+ } ,
230
+ seriesType: "bars",
231
+ series: {2: {type: "line"}},
232
+ legend: {position: "bottom"},
233
+ colors:["#17c6ea"]
234
+ };
235
+
236
+ var chart = new google.visualization.ComboChart(document.getElementById(id));
237
+ chart.draw(data, options);
238
+ return chart;
239
+ }
240
+ function drawRankingChart(id, values, reverse) {
241
+ var data = google.visualization.arrayToDataTable(values);
242
+
243
+ var options = {
244
+
245
+ curveType: "function",
246
+ title: "",
247
+ chartArea:{width:"100%",height:"100%"},
248
+ enableInteractivity: "true",
249
+ tooltip: {trigger: "auto"},
250
+ pointSize: "2",
251
+ colors: ["#55b2ca"],
252
+ hAxis: {
253
+ baselineColor: "transparent",
254
+ gridlineColor: "transparent",
255
+ textPosition: "none"
256
+ } ,
257
+ vAxis:{
258
+ direction: ((reverse) ? -1 : 1),
259
+ baselineColor: "transparent",
260
+ gridlineColor: "transparent",
261
+ textPosition: "none"
262
+ }
263
+ };
264
+
265
+ var chart = new google.visualization.LineChart(document.getElementById(id));
266
+ chart.draw(data, options);
267
+ return chart;
268
+ }
269
+ function drawTrafficChart(id, values, reverse) {
270
+ var data = google.visualization.arrayToDataTable(values);
271
+
272
+ var options = {
273
+
274
+ title : "",
275
+ chartArea:{width:"85%",height:"80%"},
276
+ enableInteractivity: "true",
277
+ tooltip: {trigger: "auto"},
278
+ vAxis: {
279
+ direction: ((reverse) ? -1 : 1),
280
+ title: "",
281
+ viewWindowMode:"explicit"
282
+ },
283
+ hAxis: {
284
+ title: "",
285
+ baselineColor: "transparent",
286
+ gridlineColor: "transparent",
287
+ textPosition: "none"
288
+ } ,
289
+ seriesType: "bars",
290
+ series: {2: {type: "line"}},
291
+ legend: {position: "bottom"},
292
+ colors:["#17c6ea"]
293
+ };
294
+
295
+ var chart = new google.visualization.ComboChart(document.getElementById(id));
296
+ chart.draw(data, options);
297
+ return chart;
298
+ }
299
+ </script>';
300
+ }
301
+
302
+ /**
303
+ * Called when action is triggered
304
+ *
305
+ * @return void
306
+ */
307
+ public function action()
308
+ {
309
+
310
+ parent::action();
311
+
312
+ switch (SQ_Classes_Helpers_Tools::getValue('action')) {
313
+
314
+ case 'sq_focuspages_inspecturl':
315
+ $json = array();
316
+ SQ_Classes_Helpers_Tools::setHeader('json');
317
+ $post_id = (int)SQ_Classes_Helpers_Tools::getValue('post_id', 0);
318
+
319
+ //Set the focus pages and labels
320
+ $args = array();
321
+ $args['post_id'] = $post_id;
322
+ if ($json['html'] = SQ_Classes_RemoteController::getInspectURL($args)) {
323
+
324
+ //Support for international languages
325
+ if (function_exists('iconv') && SQ_Classes_Helpers_Tools::getOption('sq_non_utf8_support')) {
326
+ if (strpos(get_bloginfo("language"), 'en') === false) {
327
+ $json['html'] = iconv('UTF-8', 'UTF-8//IGNORE', $json['html']);
328
+ }
329
+ }
330
+ }
331
+
332
+ if (SQ_Classes_Error::isError()) {
333
+ $json['error'] = SQ_Classes_Error::getError();
334
+ }
335
+
336
+ echo wp_json_encode($json);
337
+ exit();
338
+ case 'sq_focuspages_getpage':
339
+ $json = array();
340
+ SQ_Classes_Helpers_Tools::setHeader('json');
341
+
342
+
343
+ //Set the focus pages and labels
344
+ $this->setFocusPages();
345
+
346
+ $json['html'] = $this->get_view('FocusPages/FocusPages');
347
+
348
+ //Support for international languages
349
+ if (function_exists('iconv') && SQ_Classes_Helpers_Tools::getOption('sq_non_utf8_support')) {
350
+ if (strpos(get_bloginfo("language"), 'en') === false) {
351
+ $json['html'] = iconv('UTF-8', 'UTF-8//IGNORE', $json['html']);
352
+ }
353
+ }
354
+
355
+ if (SQ_Classes_Error::isError()) {
356
+ $json['error'] = SQ_Classes_Error::getError();
357
+ }
358
+
359
+ echo wp_json_encode($json);
360
+ exit();
361
+ case 'sq_focuspages_addnew':
362
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_focuspages')) {
363
+ return;
364
+ }
365
+
366
+ $term_id = (int)SQ_Classes_Helpers_Tools::getValue('term_id', 0);
367
+ $taxonomy = SQ_Classes_Helpers_Tools::getValue('taxonomy', '');
368
+ $post_type = SQ_Classes_Helpers_Tools::getValue('type', '');
369
+
370
+ if ($post_id = (int)SQ_Classes_Helpers_Tools::getValue('post_id', 0)) {
371
+ if ($post = SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->getCurrentSnippet($post_id, $term_id, $taxonomy, $post_type)) {
372
+ //Save the post data in DB with the hash
373
+ SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->savePost($post);
374
+
375
+ if ($post->post_status == 'publish' && $post->ID == $post_id) {
376
+ //send the post to API
377
+ $args = array();
378
+ $args['post_id'] = $post->ID;
379
+ $args['hash'] = $post->hash;
380
+ $args['permalink'] = $post->url;
381
+ if ($focuspage = SQ_Classes_RemoteController::addFocusPage($args)) {
382
+ if (!is_wp_error($focuspage)) {
383
+ SQ_Classes_Error::setError(esc_html__("Focus page is added. The audit may take a while so please be patient.", 'squirrly-seo') . " <br /> ", 'success');
384
+ if (isset($focuspage->user_post_id)) {
385
+ set_transient('sq_auditpage_' . $focuspage->user_post_id, time());
386
+
387
+ SQ_Classes_Helpers_Tools::saveOptions('seoreport_time', false);
388
+ }
389
+ } elseif ($focuspage->get_error_message() == 'limit_exceed') {
390
+ SQ_Classes_Error::setError(esc_html__("You reached the maximum number of focus pages for all your websites.", 'squirrly-seo') . " <br /> ");
391
+ }
392
+ } else {
393
+ SQ_Classes_Error::setError(esc_html__("Error! Could not add the focus page.", 'squirrly-seo') . " <br /> ");
394
+ }
395
+ } else {
396
+ SQ_Classes_Error::setError(esc_html__("Error! This focus page is not public.", 'squirrly-seo') . " <br /> ");
397
+ }
398
+
399
+ } else {
400
+ SQ_Classes_Error::setError(sprintf(esc_html__("Error! Could not find the focus page %d in your website.", 'squirrly-seo'), $post_id) . " <br /> ");
401
+ }
402
+ }
403
+ break;
404
+ case 'sq_focuspages_update':
405
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_focuspages')) {
406
+ return;
407
+ }
408
+
409
+ $post_id = (int)SQ_Classes_Helpers_Tools::getValue('post_id', 0);
410
+ $term_id = (int)SQ_Classes_Helpers_Tools::getValue('term_id', 0);
411
+ $taxonomy = SQ_Classes_Helpers_Tools::getValue('taxonomy', '');
412
+ $post_type = SQ_Classes_Helpers_Tools::getValue('type', '');
413
+ if ($id = (int)SQ_Classes_Helpers_Tools::getValue('id', 0)) {
414
+ if ($post = SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->getCurrentSnippet($post_id, $term_id, $taxonomy, $post_type)) {
415
+
416
+ //Save the post data in DB with the hash
417
+ SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->savePost($post);
418
+
419
+ //send the post to API
420
+ $args = array();
421
+ $args['post_id'] = $id;
422
+ $args['hash'] = $post->hash;
423
+ $args['permalink'] = $post->url;
424
+ if ($focuspage = SQ_Classes_RemoteController::updateFocusPage($args)) {
425
+
426
+ if (!is_wp_error($focuspage)) {
427
+ SQ_Classes_Error::setError(esc_html__("Focus page sent for recheck. It may take a while so please be patient.", 'squirrly-seo') . " <br /> ", 'success');
428
+ set_transient('sq_auditpage_' . $id, time());
429
+ } elseif ($focuspage->get_error_message() == 'too_many_attempts') {
430
+ SQ_Classes_Error::setError(esc_html__("You've made too many requests, please wait a few minutes.", 'squirrly-seo') . " <br /> ");
431
+ }
432
+
433
+ } else {
434
+ SQ_Classes_Error::setError(esc_html__("You've made too many requests, please wait a few minutes.", 'squirrly-seo') . " <br /> ");
435
+ set_transient('sq_auditpage_' . $id, time());
436
+ }
437
+
438
+ } else {
439
+ SQ_Classes_Error::setError(sprintf(esc_html__("Error! Could not find the focus page %d in your website.", 'squirrly-seo'), $post_id) . " <br /> ");
440
+ }
441
+ }
442
+ break;
443
+ case 'sq_focuspages_delete':
444
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_focuspages')) {
445
+ return;
446
+ }
447
+
448
+ if ($post_id = SQ_Classes_Helpers_Tools::getValue('id', false)) {
449
+ SQ_Classes_RemoteController::deleteFocusPage(array('user_post_id' => $post_id));
450
+ SQ_Classes_Error::setError(esc_html__("The focus page is deleted", 'squirrly-seo') . " <br /> ", 'success');
451
+ } else {
452
+ SQ_Classes_Error::setError(esc_html__("Invalid params!", 'squirrly-seo') . " <br /> ");
453
+ }
454
+
455
+ break;
456
+ }
457
+
458
+ }
459
+ }
controllers/Frontend.php CHANGED
@@ -1,164 +1,177 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- class SQ_Controllers_Frontend extends SQ_Classes_FrontController {
5
-
6
- /** @var SQ_Models_Frontend */
7
- public $model;
8
-
9
- public function __construct() {
10
- if (is_admin() || is_network_admin() || SQ_Classes_Helpers_Tools::isAjax()) {
11
- return;
12
- }
13
-
14
- //load the hooks
15
- parent::__construct();
16
-
17
- //For favicon and Robots
18
- $this->hookCheckFiles();
19
-
20
- /* Check if sitemap is on and Load the Sitemap */
21
- if (SQ_Classes_Helpers_Tools::getOption('sq_auto_sitemap')) {
22
- add_filter('wp_sitemaps_enabled', '__return_false');
23
- SQ_Classes_ObjController::getClass('SQ_Controllers_Sitemaps');
24
- }
25
-
26
- //Check cache plugin compatibility
27
- SQ_Classes_ObjController::getClass('SQ_Models_Compatibility')->checkCompatibility();
28
-
29
- //Check if late loading is on
30
- if (!apply_filters('sq_lateloading', SQ_Classes_Helpers_Tools::getOption('sq_laterload'))) {
31
- //Hook the buffer on both actions in case one fails
32
- add_action('plugins_loaded', array($this, 'hookBuffer'), 9);
33
- }
34
-
35
- //In case plugins_loaded hook is disabled
36
- add_action('template_redirect', array($this, 'hookBuffer'), 1);
37
-
38
- //Set the post so that Squirrly will know which one to process
39
- add_action('template_redirect', array($this->model, 'setPost'), 9);
40
-
41
- if(SQ_Classes_Helpers_Tools::getOption('sq_auto_links')) {
42
-
43
- //Check if attachment to image redirect is needed
44
- if (SQ_Classes_Helpers_Tools::getOption('sq_attachment_redirect')) {
45
- add_action('template_redirect', array($this->model, 'redirectAttachments'), 10);
46
- }
47
-
48
- }
49
- }
50
-
51
- /**
52
- * HOOK THE BUFFER
53
- */
54
- public function hookBuffer() {
55
- //remove the action is already hocked in plugins_loaded
56
- if (!did_action('template_redirect')) {
57
- remove_action('template_redirect', array($this, 'hookBuffer'), 1);
58
- }
59
-
60
- //Check if there is an editor loading
61
- //Don't load Squirrly METAs while in frontend editors
62
- if(!SQ_Classes_ObjController::getClass('SQ_Models_Compatibility')->isBuilderEditor()) {
63
- $this->model->startBuffer();
64
- }
65
- }
66
-
67
- /**
68
- * Called after plugins are loaded
69
- */
70
- public function hookCheckFiles() {
71
- //Check for sitemap and robots
72
- if ($basename = $this->getFileName($_SERVER['REQUEST_URI'])) {
73
- if (SQ_Classes_Helpers_Tools::getOption('sq_auto_robots') == 1) {
74
- if ($basename == "robots.txt") {
75
- SQ_Classes_ObjController::getClass('SQ_Models_Services_Robots');
76
- apply_filters('sq_robots', false);
77
- exit();
78
- }
79
- }
80
-
81
- if (SQ_Classes_Helpers_Tools::getOption('sq_auto_favicon') && SQ_Classes_Helpers_Tools::getOption('favicon') <> '') {
82
- if ($basename == "favicon.icon") {
83
- SQ_Classes_Helpers_Tools::setHeader('ico');
84
- @readfile(_SQ_CACHE_DIR_ . SQ_Classes_Helpers_Tools::getOption('favicon'));
85
- exit();
86
- } elseif ($basename == "touch-icon.png") {
87
- SQ_Classes_Helpers_Tools::setHeader('png');
88
- @readfile(_SQ_CACHE_DIR_ . SQ_Classes_Helpers_Tools::getOption('favicon'));
89
- exit();
90
- } else {
91
- $appleSizes = preg_split('/[,]+/', _SQ_MOBILE_ICON_SIZES);
92
- foreach ($appleSizes as $appleSize) {
93
- if ($basename == "touch-icon$appleSize.png") {
94
- SQ_Classes_Helpers_Tools::setHeader('png');
95
- @readfile(_SQ_CACHE_DIR_ . SQ_Classes_Helpers_Tools::getOption('favicon') . $appleSize);
96
- exit();
97
- }
98
- }
99
- }
100
- }
101
-
102
- }
103
-
104
- }
105
-
106
- /**
107
- * Hook the Header load
108
- */
109
- public function hookFronthead() {
110
-
111
- if (is_admin() || (defined('SQ_NOCSS') && SQ_NOCSS)) {
112
- return;
113
- }
114
-
115
- if (SQ_Classes_Helpers_Tools::isPluginInstalled('elementor/elementor.php')) {
116
- if (SQ_Classes_Helpers_Tools::getValue('elementor-preview', false)) {
117
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('elementor');
118
- }
119
- }
120
-
121
- if(SQ_Classes_Helpers_Tools::getOption('sq_load_css')) {
122
- if (!SQ_Classes_Helpers_Tools::isAjax()) {
123
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('frontend');
124
- }
125
- }
126
- }
127
-
128
- /**
129
- * Hook the footer
130
- */
131
- public function hookFrontfooter() {
132
- echo $this->model->getFooter();
133
- }
134
-
135
- /**
136
- * Get the File Name if itțs a file in URL
137
- * @param null $url
138
- * @return bool|string|null
139
- */
140
- public function getFileName($url = null) {
141
- if (isset($url) && $url <> '') {
142
- $url = basename($url);
143
- if (strpos($url, '?') <> '') {
144
- $url = substr($url, 0, strpos($url, '?'));
145
- }
146
-
147
- $files = array('ico', 'icon', 'txt', 'jpg', 'jpeg', 'png', 'bmp', 'gif', 'webp',
148
- 'css', 'scss', 'js',
149
- 'pdf', 'doc', 'docx', 'csv', 'xls', 'xslx',
150
- 'mp4', 'mpeg',
151
- 'zip', 'rar');
152
-
153
- if (strrpos($url, '.') !== false) {
154
- $ext = substr($url, strrpos($url, '.') + 1);
155
- if (in_array($ext, $files)) {
156
- return $url;
157
- }
158
- }
159
- }
160
-
161
- return false;
162
-
163
- }
164
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ class SQ_Controllers_Frontend extends SQ_Classes_FrontController
5
+ {
6
+
7
+ /**
8
+ *
9
+ *
10
+ * @var SQ_Models_Frontend
11
+ */
12
+ public $model;
13
+
14
+ public function __construct()
15
+ {
16
+ if (is_admin() || is_network_admin() || SQ_Classes_Helpers_Tools::isAjax()) {
17
+ return;
18
+ }
19
+
20
+ //load the hooks
21
+ parent::__construct();
22
+
23
+ //For favicon and Robots
24
+ $this->hookCheckFiles();
25
+
26
+ /* Check if sitemap is on and Load the Sitemap */
27
+ if (SQ_Classes_Helpers_Tools::getOption('sq_auto_sitemap')) {
28
+ add_filter('wp_sitemaps_enabled', '__return_false');
29
+ SQ_Classes_ObjController::getClass('SQ_Controllers_Sitemaps');
30
+ }
31
+
32
+ //Check cache plugin compatibility
33
+ SQ_Classes_ObjController::getClass('SQ_Models_Compatibility')->checkCompatibility();
34
+
35
+ //Check if late loading is on
36
+ if (!apply_filters('sq_lateloading', SQ_Classes_Helpers_Tools::getOption('sq_laterload'))) {
37
+ //Hook the buffer on both actions in case one fails
38
+ add_action('plugins_loaded', array($this, 'hookBuffer'), 9);
39
+ }
40
+
41
+ //In case plugins_loaded hook is disabled
42
+ add_action('template_redirect', array($this, 'hookBuffer'), 1);
43
+
44
+ //Set the post so that Squirrly will know which one to process
45
+ add_action('template_redirect', array($this->model, 'setPost'), 9);
46
+
47
+ if(SQ_Classes_Helpers_Tools::getOption('sq_auto_links')) {
48
+
49
+ //Check if attachment to image redirect is needed
50
+ if (SQ_Classes_Helpers_Tools::getOption('sq_attachment_redirect')) {
51
+ add_action('template_redirect', array($this->model, 'redirectAttachments'), 10);
52
+ }
53
+
54
+ }
55
+ }
56
+
57
+ /**
58
+ * HOOK THE BUFFER
59
+ */
60
+ public function hookBuffer()
61
+ {
62
+ //remove the action is already hocked in plugins_loaded
63
+ if (!did_action('template_redirect')) {
64
+ remove_action('template_redirect', array($this, 'hookBuffer'), 1);
65
+ }
66
+
67
+ //Check if there is an editor loading
68
+ //Don't load Squirrly METAs while in frontend editors
69
+ if(!SQ_Classes_ObjController::getClass('SQ_Models_Compatibility')->isBuilderEditor()) {
70
+ $this->model->startBuffer();
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Called after plugins are loaded
76
+ */
77
+ public function hookCheckFiles()
78
+ {
79
+ //Check for sitemap and robots
80
+ if ($basename = $this->getFileName($_SERVER['REQUEST_URI'])) {
81
+ if (SQ_Classes_Helpers_Tools::getOption('sq_auto_robots') == 1) {
82
+ if ($basename == "robots.txt") {
83
+ SQ_Classes_ObjController::getClass('SQ_Models_Services_Robots');
84
+ apply_filters('sq_robots', false);
85
+ exit();
86
+ }
87
+ }
88
+
89
+ if (SQ_Classes_Helpers_Tools::getOption('sq_auto_favicon') && SQ_Classes_Helpers_Tools::getOption('favicon') <> '') {
90
+ if ($basename == "favicon.icon") {
91
+ SQ_Classes_Helpers_Tools::setHeader('ico');
92
+ @readfile(_SQ_CACHE_DIR_ . SQ_Classes_Helpers_Tools::getOption('favicon'));
93
+ exit();
94
+ } elseif ($basename == "touch-icon.png") {
95
+ SQ_Classes_Helpers_Tools::setHeader('png');
96
+ @readfile(_SQ_CACHE_DIR_ . SQ_Classes_Helpers_Tools::getOption('favicon'));
97
+ exit();
98
+ } else {
99
+ $appleSizes = preg_split('/[,]+/', _SQ_MOBILE_ICON_SIZES);
100
+ foreach ($appleSizes as $appleSize) {
101
+ if ($basename == "touch-icon$appleSize.png") {
102
+ SQ_Classes_Helpers_Tools::setHeader('png');
103
+ @readfile(_SQ_CACHE_DIR_ . SQ_Classes_Helpers_Tools::getOption('favicon') . $appleSize);
104
+ exit();
105
+ }
106
+ }
107
+ }
108
+ }
109
+
110
+ }
111
+
112
+ }
113
+
114
+ /**
115
+ * Hook the Header load
116
+ */
117
+ public function hookFronthead()
118
+ {
119
+
120
+ if (is_admin() || (defined('SQ_NOCSS') && SQ_NOCSS)) {
121
+ return;
122
+ }
123
+
124
+ if (SQ_Classes_Helpers_Tools::isPluginInstalled('elementor/elementor.php')) {
125
+ if (SQ_Classes_Helpers_Tools::getValue('elementor-preview', false)) {
126
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('elementor');
127
+ }
128
+ }
129
+
130
+ if(SQ_Classes_Helpers_Tools::getOption('sq_load_css')) {
131
+ if (!SQ_Classes_Helpers_Tools::isAjax()) {
132
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('frontend');
133
+ }
134
+ }
135
+ }
136
+
137
+ /**
138
+ * Hook the footer function
139
+ */
140
+ public function hookFrontfooter()
141
+ {
142
+ //Show the analytics code in footer
143
+ echo $this->model->getFooter();
144
+ }
145
+
146
+ /**
147
+ * Get the File Name if itțs a file in URL
148
+ *
149
+ * @param null $url
150
+ * @return bool|string|null
151
+ */
152
+ public function getFileName($url = null)
153
+ {
154
+ if (isset($url) && $url <> '') {
155
+ $url = basename($url);
156
+ if (strpos($url, '?') <> '') {
157
+ $url = substr($url, 0, strpos($url, '?'));
158
+ }
159
+
160
+ $files = array('ico', 'icon', 'txt', 'jpg', 'jpeg', 'png', 'bmp', 'gif', 'webp',
161
+ 'css', 'scss', 'js',
162
+ 'pdf', 'doc', 'docx', 'csv', 'xls', 'xslx',
163
+ 'mp4', 'mpeg',
164
+ 'zip', 'rar');
165
+
166
+ if (strrpos($url, '.') !== false) {
167
+ $ext = substr($url, strrpos($url, '.') + 1);
168
+ if (in_array($ext, $files)) {
169
+ return $url;
170
+ }
171
+ }
172
+ }
173
+
174
+ return false;
175
+
176
+ }
177
+ }
controllers/Menu.php CHANGED
@@ -1,483 +1,535 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- class SQ_Controllers_Menu extends SQ_Classes_FrontController {
5
-
6
- /** @var array snippet */
7
- public $post_type;
8
- /** @var array snippet */
9
- var $options = array();
10
-
11
- public function __construct() {
12
- parent::__construct();
13
-
14
- global $sq_fullscreen, $sq_setting_page;
15
-
16
- //Only on subsites
17
- if (!is_network_admin()) {
18
- $sq_fullscreen = $sq_setting_page = false;
19
-
20
- add_action('admin_bar_menu', array($this, 'hookTopmenuDashboard'), 10);
21
- add_action('admin_bar_menu', array($this, 'hookTopmenuSquirrly'), 91);
22
-
23
- add_action('do_meta_boxes', array($this, 'addMetabox'));
24
- add_filter('sq_cloudmenu', array($this, 'getCloudMenu'), 10, 2);
25
-
26
- //run compatibility check on Squirrly settings
27
- if (SQ_Classes_Helpers_Tools::getIsset('page')) {
28
-
29
- //Get all the Squirrly SEO menus
30
- $menus = $this->model->getMainMenu();
31
- //Get current accessed page
32
- $page = apply_filters('sq_page', SQ_Classes_Helpers_Tools::getValue('page'));
33
-
34
- if (in_array($page, array_keys($menus))) {
35
- //Set if it's a Squirrly SEO Page
36
- $sq_setting_page = true;
37
-
38
- //Check if the menu requires full screen window
39
- if (isset($menus[$page]['fullscreen']) && $menus[$page]['fullscreen']) {
40
- $sq_fullscreen = true;
41
- }
42
-
43
- //dequeue other css when on Squirrly Settings page
44
- add_action('admin_enqueue_scripts', array(SQ_Classes_ObjController::getClass('SQ_Models_Compatibility'), 'fixEnqueueErrors'), PHP_INT_MAX);
45
- add_action('admin_head', array($this, 'setViewport'), PHP_INT_MAX);
46
- }
47
- }
48
-
49
- //Hook the Frontend Editors
50
- $this->hookBuilders();
51
- }
52
-
53
- add_action('current_screen', function () {
54
- if (in_array(get_current_screen()->id, array('plugins', 'plugins-network'))) {
55
- SQ_Classes_ObjController::getClass('SQ_Controllers_Uninstall');
56
- }
57
- });
58
- }
59
-
60
- /**
61
- * Hook the Admin load
62
- */
63
- public function hookInit() {
64
-
65
- /* add the plugin menu in admin */
66
- if (SQ_Classes_Helpers_Tools::userCan('manage_options')) {
67
- try {
68
- //check if activated
69
- if (get_transient('sq_activate') == 1) {
70
- // Delete the redirect transient
71
- delete_transient('sq_activate');
72
-
73
- //Create Qss table if not exists
74
- SQ_Classes_ObjController::getClass('SQ_Models_Qss')->checkTableExists();
75
-
76
- //This option is use for custom Package installs
77
- //update text in case of devkit
78
- SQ_Classes_ObjController::getClass('SQ_Classes_Helpers_DevKit')->updatePluginData();
79
-
80
- if (SQ_Classes_Helpers_Tools::getOption('sq_api') == '') {
81
- wp_redirect(SQ_Classes_Helpers_Tools::getAdminUrl('sq_dashboard'));
82
- die();
83
- }
84
-
85
- //Connect to cloud with an unique Token for API access
86
- SQ_Classes_ObjController::getClass('SQ_Core_BlockConnect')->connectToCloud();
87
- }
88
-
89
- } catch (Exception $e) {
90
- SQ_Classes_Error::setMessage(sprintf(esc_html__("An error occurred during activation. If this error persists, please contact us at: %s", _SQ_PLUGIN_NAME_), _SQ_SUPPORT_URL_));
91
- }
92
-
93
- }
94
-
95
- //Add Squirrly SEO in Posts list
96
- SQ_Classes_ObjController::getClass('SQ_Controllers_PostsList')->init();
97
-
98
- //Hook the post save action
99
- SQ_Classes_ObjController::getClass('SQ_Controllers_Post')->hookPost();
100
-
101
- //Show Squirrly SEO in Dashboard if connected to Squirrly Cloud
102
- if (SQ_Classes_Helpers_Tools::getOption('sq_api') <> '') {
103
- add_action('wp_dashboard_setup', array($this, 'hookDashboardSetup'));
104
- }
105
-
106
- //Add the Squirrly Class in all Squirrly SEO Pages
107
- add_filter('admin_body_class', array($this, 'addSquirrlySettingsClass'));
108
-
109
- }
110
-
111
- /**
112
- * Show the Dashboard link when Full Screen
113
- * @param \WP_Admin_Bar $wp_admin_bar
114
- * @return mixed
115
- */
116
- public function hookTopmenuDashboard($wp_admin_bar) {
117
- global $sq_fullscreen;
118
-
119
- if (function_exists('is_user_logged_in') && is_user_logged_in()) {
120
- if (isset($sq_fullscreen) && $sq_fullscreen) {
121
- $wp_admin_bar->add_node(array(
122
- 'parent' => 'site-name',
123
- 'id' => 'dashboard',
124
- 'title' => esc_html__("Dashboard"),
125
- 'href' => admin_url(),
126
- ));
127
- }
128
- }
129
-
130
- return $wp_admin_bar;
131
- }
132
-
133
- /**
134
- * Show the Squirrly Menu in toolbar
135
- * @param \WP_Admin_Bar $wp_admin_bar
136
- *
137
- * @return \WP_Admin_Bar
138
- */
139
- public function hookTopmenuSquirrly($wp_admin_bar) {
140
- global $tag;
141
-
142
- if (!apply_filters('sq_load_snippet', true) || !SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
143
- return;
144
- }
145
-
146
- if (is_admin()) {
147
-
148
- if (SQ_Classes_Helpers_Tools::userCan('edit_posts')) {
149
- //Get count local SEO errors
150
- $errors = apply_filters('sq_seo_errors', 0);
151
-
152
- $wp_admin_bar->add_node(array(
153
- 'id' => 'sq_toolbar',
154
- 'title' => '<span class="sq_logo" style="margin-right: 2px"></span>' . apply_filters('sq_menu_name', _SQ_MENU_NAME_) . (($errors) ? '<span class="sq_errorcount">' . $errors . '</span>' : ''),
155
- 'href' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_dashboard'),
156
- 'parent' => false
157
- ));
158
-
159
- $mainmenu = $this->model->getMainMenu();
160
- if (!empty($mainmenu)) {
161
- foreach ($mainmenu as $menuid => $item) {
162
-
163
- //Check if the menu item is visible on the top
164
- if (isset($item['topmenu']) && !$item['topmenu']) {
165
- continue;
166
- }
167
-
168
- if ($menuid == 'sq_dashboard' && $errors) {
169
- if (is_rtl()) {
170
- $item['title'] = '<span class="sq_errorcount" style="margin: 6px 0 0 0 !important; float: left !important;">' . $errors . '</span>' . $item['title'];
171
- } else {
172
- $item['title'] = $item['title'] . '<span class="sq_errorcount" style="margin: 6px 35px 0 0 !important;">' . $errors . '</span>';
173
- }
174
- }
175
-
176
- //make sure the user has the capabilities
177
- if (SQ_Classes_Helpers_Tools::userCan($item['capability'])) {
178
- $wp_admin_bar->add_node(array(
179
- 'id' => $menuid,
180
- 'title' => $item['title'],
181
- 'href' => SQ_Classes_Helpers_Tools::getAdminUrl($menuid),
182
- 'parent' => 'sq_toolbar'
183
- ));
184
- $tabs = $this->model->getTabs($menuid);
185
- if (!empty($tabs)) {
186
- foreach ($tabs as $id => $tab) {
187
- $array_id = explode('/', $id);
188
- if (count((array)$array_id) == 2) {
189
- $wp_admin_bar->add_node(array(
190
- 'id' => $menuid . str_replace('/', '_', $id),
191
- 'title' => $tab['title'],
192
- 'href' => SQ_Classes_Helpers_Tools::getAdminUrl($array_id[0], $array_id[1]),
193
- 'parent' => $menuid
194
- ));
195
- }
196
- }
197
- }
198
- }
199
- }
200
- }
201
-
202
- }
203
-
204
- $current_screen = get_current_screen();
205
- $post = get_post();
206
- if ('post' == $current_screen->base
207
- && ($post_type_object = get_post_type_object($post->post_type))
208
- && (SQ_Classes_Helpers_Tools::userCan('edit_post', $post->ID) || SQ_Classes_Helpers_Tools::userCan('sq_manage_snippets'))
209
- && ($post_type_object->public)) {
210
- } elseif ('edit' == $current_screen->base
211
- && ($post_type_object = get_post_type_object($current_screen->post_type))
212
- && ($post_type_object->show_in_admin_bar)
213
- && !('edit-' . $current_screen->post_type === $current_screen->id)) {
214
- } elseif ('term' == $current_screen->base
215
- && isset($tag) && is_object($tag) && !is_wp_error($tag)
216
- && ($tax = get_taxonomy($tag->taxonomy))
217
- && $tax->public) {
218
- } else {
219
- return $wp_admin_bar;
220
- }
221
-
222
- $this->model->addMeta(array('sq_blocksnippet',
223
- esc_html__("SEO Snippet", _SQ_PLUGIN_NAME_),
224
- array(SQ_Classes_ObjController::getClass('SQ_Controllers_Snippet'), 'init'),
225
- null,
226
- 'normal',
227
- 'high'
228
- ));
229
-
230
- $wp_admin_bar->add_node(array(
231
- 'id' => 'sq_bar_menu',
232
- 'title' => '<span class="sq_logo"></span> ' . esc_html__("Custom SEO", _SQ_PLUGIN_NAME_),
233
- 'parent' => 'top-secondary',
234
- ));
235
-
236
-
237
- //Add snippet body
238
- $wp_admin_bar->add_menu(array(
239
- 'id' => 'sq_bar_submenu',
240
- 'parent' => 'sq_bar_menu',
241
- 'meta' => array(
242
- 'html' => SQ_Classes_ObjController::getClass('SQ_Controllers_Snippet')->init(),
243
- 'tabindex' => PHP_INT_MAX,
244
- ),
245
- ));
246
- }
247
-
248
- return $wp_admin_bar;
249
- }
250
-
251
- public function hookDashboardSetup() {
252
- wp_add_dashboard_widget(
253
- 'sq_dashboard_widget',
254
- esc_html__("Squirrly SEO", _SQ_PLUGIN_NAME_),
255
- array(SQ_Classes_ObjController::getClass('SQ_Controllers_Dashboard'), 'dashboard')
256
- );
257
-
258
- // Move our widget to top.
259
- global $wp_meta_boxes;
260
-
261
- $dashboard = $wp_meta_boxes['dashboard']['normal']['core'];
262
- $ours = array('sq_dashboard_widget' => $dashboard['sq_dashboard_widget']);
263
- $wp_meta_boxes['dashboard']['normal']['core'] = array_merge($ours, $dashboard);
264
- }
265
-
266
- public function hookNetworkMenu() {
267
- //Check the Dev Kit settings
268
- SQ_Classes_ObjController::getClass('SQ_Classes_Helpers_DevKit');
269
- }
270
-
271
- /**
272
- * Creates the Setting menu in Wordpress
273
- */
274
- public function hookMenu() {
275
- //Hook the SEO Errors from Squirrly SEO Check
276
- add_action('sq_seo_errors', array($this, 'getSEOErrors'));
277
-
278
- //Check the Dev Kit settings
279
- SQ_Classes_ObjController::getClass('SQ_Classes_Helpers_DevKit');
280
-
281
- //Get all the post types
282
- $this->post_type = SQ_Classes_Helpers_Tools::getOption('sq_post_types');
283
-
284
- //Get count local SEO errors
285
- $errors = apply_filters('sq_seo_errors', 0);
286
-
287
- ///////////////
288
- $this->model->addMenu(array(apply_filters('sq_menu_name', _SQ_MENU_NAME_),
289
- apply_filters('sq_menu_name', _SQ_MENU_NAME_) . (($errors) ? '<span class="sq_errorcount">' . $errors . '</span>' : ''),
290
- 'edit_posts',
291
- 'sq_dashboard',
292
- null,
293
- apply_filters('sq_logo', _SQ_ASSETS_URL_ . 'img/logos/menu_icon_16.png')
294
- ));
295
-
296
- //Load the Squirrly Menu
297
- $mainmenu = $this->model->getMainMenu();
298
- if (!empty($mainmenu)) {
299
- foreach ($mainmenu as $name => $item) {
300
-
301
- //Check if the menu is set to show in the left side
302
- if (isset($item['leftmenu'])) {
303
- if (is_bool($item['leftmenu'])) {
304
- if (!$item['leftmenu'] && SQ_Classes_Helpers_Tools::getValue('page', '') <> $name) {
305
- continue;
306
- }
307
- } else {
308
- $item['title'] = $item['leftmenu'];
309
- }
310
- }
311
-
312
- //Add the page
313
- $this->model->addSubmenu(array($item['parent'],
314
- $item['description'],
315
- $item['title'],
316
- $item['capability'],
317
- $name,
318
- $item['function'],
319
- ));
320
-
321
- }
322
-
323
- //Update the external links in the menu
324
- global $submenu;
325
- if (!empty($submenu['sq_dashboard'])) {
326
- foreach ($submenu['sq_dashboard'] as &$item) {
327
- if (isset($mainmenu[$item[2]]['href']) && $mainmenu[$item[2]]['href']) {
328
- if (parse_url($mainmenu[$item[2]]['href'], PHP_URL_HOST) !== parse_url(home_url(), PHP_URL_HOST)) {
329
- $item[0] .= '<i class="dashicons dashicons-external" style="font-size:12px;vertical-align:-2px;height:10px;"></i>';
330
- }
331
- $item[2] = $mainmenu[$item[2]]['href'];
332
- }
333
- }
334
- }
335
- }
336
- }
337
-
338
- /**
339
- * Add Post Editor Meta Box
340
- * Load Squirrly Live Assistant
341
- */
342
- public function addMetabox() {
343
- $types = get_post_types(array('public' => true));
344
-
345
- if (!apply_filters('sq_load_snippet', true) || !SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
346
- return;
347
- }
348
-
349
- //Exclude types for SLA
350
- $excludes = SQ_Classes_Helpers_Tools::getOption('sq_sla_exclude_post_types');
351
- if (!empty($types) && !empty($excludes)) {
352
- foreach ($excludes as $exclude) {
353
- if ($exclude) {
354
- if (in_array($exclude, $types)) {
355
- unset($types[$exclude]);
356
- }
357
- }
358
- }
359
- }
360
-
361
- //Add Live Assistant For Selected Post Types
362
- if (!empty($types)) {
363
- foreach ($types as $type) {
364
- if (is_string($type) && $type <> '' && $metabox = unserialize(SQ_Classes_Helpers_Tools::getUserMeta('meta-box-order_' . $type))) {
365
- extract($metabox);
366
-
367
- if (isset($side) && isset($normal)) {
368
- $side = explode(',', $side);
369
- $normal = explode(',', $normal);
370
- if (in_array('post' . _SQ_NAME_, $normal)) {
371
- $side = array_merge(array('post' . _SQ_NAME_), $side);
372
- $metabox['side'] = join(',', array_unique($side));
373
-
374
- $normal = array_diff($normal, array('post' . _SQ_NAME_));
375
- $metabox['normal'] = join(',', array_unique($normal));
376
- SQ_Classes_Helpers_Tools::saveUserMeta('meta-box-order_' . $type, $metabox);
377
- }
378
-
379
- if (in_array('sq_blocksnippet', $side)) {
380
- $normal = array_merge(array('sq_blocksnippet'), $normal);
381
- $metabox['normal'] = join(',', array_unique($normal));
382
-
383
- $side = array_diff($side, array('sq_blocksnippet'));
384
- $metabox['side'] = join(',', array_unique($side));
385
- SQ_Classes_Helpers_Tools::saveUserMeta('meta-box-order_' . $type, $metabox);
386
- }
387
- }
388
- }
389
-
390
- //Load the SLA in Post
391
- $this->model->addMeta(array('post' . _SQ_NAME_,
392
- ucfirst(_SQ_NAME_),
393
- array(SQ_Classes_ObjController::getClass('SQ_Controllers_Post'), 'init'),
394
- $type,
395
- 'side',
396
- 'high'
397
- ));
398
- }
399
-
400
- }
401
- }
402
-
403
- /**
404
- * Add the Squirrly Setttings Class in all Squirrly SEO Pages
405
- * Used for personal layout
406
- *
407
- * @param $classes
408
- * @return string
409
- */
410
- public function addSquirrlySettingsClass($classes) {
411
- global $sq_setting_page;
412
-
413
- if (isset($sq_setting_page) && $sq_setting_page) {
414
- $classes = "$classes squirrly-seo-settings";
415
- }
416
-
417
- return $classes;
418
- }
419
-
420
- /**
421
- * Hook the Head
422
- */
423
- public function hookHead() {
424
- global $sq_fullscreen, $sq_setting_page;
425
-
426
- //Load settings only in the Squirrly Menu
427
- if (isset($sq_setting_page) && $sq_setting_page) {
428
- echo '<script type="text/javascript" src="//www.google.com/jsapi"></script>';
429
- echo '<script>google.load("visualization", "1.0", {packages: ["corechart"]});</script>';
430
- if (isset($sq_fullscreen) && $sq_fullscreen) {
431
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('fullwidth', array('trigger' => true, 'media' => 'all'));
432
- }
433
- }
434
-
435
- //Load the Squirrly Logo on all Dashboard
436
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('logo');
437
-
438
- }
439
-
440
- /**
441
- * Set the viewport for a google Squirrly Settings layout
442
- */
443
- function setViewport() {
444
- $page = apply_filters('sq_page', SQ_Classes_Helpers_Tools::getValue('page', ''));
445
- if ($page == 'sq_dashboard') {
446
- echo '<meta name="viewport" content="width=900">';
447
- } else {
448
- echo '<meta name="viewport" content="width=1200">';
449
- }
450
- }
451
-
452
- /**
453
- * Hook the Elementor Builder
454
- */
455
- public function hookBuilders() {
456
- add_action('elementor/editor/footer', array(SQ_Classes_ObjController::getClass('SQ_Controllers_Post'), 'loadLiveAssistant'), 99);
457
- }
458
-
459
- /**
460
- * Count the SEO Errors from SEO Goals
461
- * @return mixed
462
- */
463
- public function getSEOErrors() {
464
- return SQ_Classes_ObjController::getClass('SQ_Controllers_CheckSeo')->setCategory('sq_dashboard')->getErrorsCount();
465
- }
466
-
467
-
468
- /**
469
- * Set the cloud.squirrly.co menu based on the client rights
470
- * @param $url
471
- * @param $path
472
- * @return string
473
- */
474
- public function getCloudMenu($url, $path) {
475
- if (function_exists('wp_get_current_user') && SQ_Classes_Helpers_Tools::getOption('sq_api')) {
476
- if (SQ_Classes_Helpers_Tools::getMenuVisible('show_panel') && SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
477
- $url .= 'login/?token=' . SQ_Classes_Helpers_Tools::getOption('sq_api') . '&user_url=' . apply_filters('sq_homeurl', get_bloginfo('url')) . '&redirect_to=' . _SQ_DASH_URL_ . 'user/' . $path;
478
- }
479
- }
480
-
481
- return $url;
482
- }
483
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ class SQ_Controllers_Menu extends SQ_Classes_FrontController
5
+ {
6
+
7
+ /**
8
+ *
9
+ *
10
+ * @var array snippet
11
+ */
12
+ public $post_type;
13
+ /**
14
+ *
15
+ *
16
+ * @var array snippet
17
+ */
18
+ var $options = array();
19
+
20
+ public function __construct()
21
+ {
22
+ parent::__construct();
23
+
24
+ global $sq_fullscreen, $sq_setting_page;
25
+
26
+ //Only on subsites
27
+ if (!is_network_admin()) {
28
+ $sq_fullscreen = $sq_setting_page = false;
29
+
30
+ add_action('admin_bar_menu', array($this, 'hookTopmenuDashboard'), 10);
31
+ add_action('admin_bar_menu', array($this, 'hookTopmenuSquirrly'), 91);
32
+
33
+ add_action('do_meta_boxes', array($this, 'addMetabox'));
34
+ add_filter('sq_cloudmenu', array($this, 'getCloudMenu'), 10, 2);
35
+
36
+ //run compatibility check on Squirrly settings
37
+ if (SQ_Classes_Helpers_Tools::getIsset('page')) {
38
+
39
+ //Get all the Squirrly SEO menus
40
+ $menus = $this->model->getMainMenu();
41
+ //Get current accessed page
42
+ $page = apply_filters('sq_page', SQ_Classes_Helpers_Tools::getValue('page'));
43
+
44
+ if (in_array($page, array_keys($menus))) {
45
+ //Set if it's a Squirrly SEO Page
46
+ $sq_setting_page = true;
47
+
48
+ //Check if the menu requires full screen window
49
+ if (isset($menus[$page]['fullscreen']) && $menus[$page]['fullscreen']) {
50
+ $sq_fullscreen = true;
51
+ }
52
+
53
+ //dequeue other css when on Squirrly Settings page
54
+ add_action('admin_enqueue_scripts', array(SQ_Classes_ObjController::getClass('SQ_Models_Compatibility'), 'fixEnqueueErrors'), PHP_INT_MAX);
55
+ add_action('admin_head', array($this, 'setViewport'), PHP_INT_MAX);
56
+ }
57
+ }
58
+
59
+ //Hook the Frontend Editors
60
+ $this->hookBuilders();
61
+ }
62
+
63
+ add_action(
64
+ 'current_screen', function () {
65
+ if (in_array(get_current_screen()->id, array('plugins', 'plugins-network'))) {
66
+ SQ_Classes_ObjController::getClass('SQ_Controllers_Uninstall');
67
+ }
68
+ }
69
+ );
70
+ }
71
+
72
+ /**
73
+ * Hook the Admin load
74
+ */
75
+ public function hookInit()
76
+ {
77
+
78
+ /* add the plugin menu in admin */
79
+ if (SQ_Classes_Helpers_Tools::userCan('manage_options')) {
80
+ try {
81
+ //check if activated
82
+ if (get_transient('sq_activate') == 1) {
83
+ // Delete the redirect transient
84
+ delete_transient('sq_activate');
85
+
86
+ //Create Qss table if not exists
87
+ SQ_Classes_ObjController::getClass('SQ_Models_Qss')->checkTableExists();
88
+
89
+ //This option is use for custom Package installs
90
+ //update text in case of devkit
91
+ SQ_Classes_ObjController::getClass('SQ_Classes_Helpers_DevKit')->updatePluginData();
92
+
93
+ if (SQ_Classes_Helpers_Tools::getOption('sq_api') == '') {
94
+ wp_redirect(SQ_Classes_Helpers_Tools::getAdminUrl('sq_dashboard'));
95
+ die();
96
+ }
97
+
98
+ //Connect to cloud with an unique Token for API access
99
+ SQ_Classes_ObjController::getClass('SQ_Core_BlockConnect')->connectToCloud();
100
+ }
101
+
102
+ } catch (Exception $e) {
103
+ SQ_Classes_Error::setMessage(sprintf(esc_html__("An error occurred during activation. If this error persists, please contact us at: %s", 'squirrly-seo'), _SQ_SUPPORT_URL_));
104
+ }
105
+
106
+ }
107
+
108
+ //Add Squirrly SEO in Posts list
109
+ SQ_Classes_ObjController::getClass('SQ_Controllers_PostsList')->init();
110
+
111
+ //Hook the post save action
112
+ SQ_Classes_ObjController::getClass('SQ_Controllers_Post')->hookPost();
113
+
114
+ //Show Squirrly SEO in Dashboard if connected to Squirrly Cloud
115
+ if (SQ_Classes_Helpers_Tools::getOption('sq_api') <> '') {
116
+ add_action('wp_dashboard_setup', array($this, 'hookDashboardSetup'));
117
+ }
118
+
119
+ //Add the Squirrly Class in all Squirrly SEO Pages
120
+ add_filter('admin_body_class', array($this, 'addSquirrlySettingsClass'));
121
+
122
+ }
123
+
124
+ /**
125
+ * Show the Dashboard link when Full Screen
126
+ *
127
+ * @param \WP_Admin_Bar $wp_admin_bar
128
+ * @return mixed
129
+ */
130
+ public function hookTopmenuDashboard($wp_admin_bar)
131
+ {
132
+ global $sq_fullscreen;
133
+
134
+ if (function_exists('is_user_logged_in') && is_user_logged_in()) {
135
+ if (isset($sq_fullscreen) && $sq_fullscreen) {
136
+ $wp_admin_bar->add_node(
137
+ array(
138
+ 'parent' => 'site-name',
139
+ 'id' => 'dashboard',
140
+ 'title' => esc_html__("Dashboard"),
141
+ 'href' => admin_url(),
142
+ )
143
+ );
144
+ }
145
+ }
146
+
147
+ return $wp_admin_bar;
148
+ }
149
+
150
+ /**
151
+ * Show the Squirrly Menu in toolbar
152
+ *
153
+ * @param \WP_Admin_Bar $wp_admin_bar
154
+ *
155
+ * @return \WP_Admin_Bar
156
+ */
157
+ public function hookTopmenuSquirrly($wp_admin_bar)
158
+ {
159
+ global $tag;
160
+
161
+ if (!apply_filters('sq_load_snippet', true) || !SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
162
+ return;
163
+ }
164
+
165
+ if (is_admin()) {
166
+
167
+ if (SQ_Classes_Helpers_Tools::userCan('edit_posts')) {
168
+ //Get count local SEO errors
169
+ $errors = apply_filters('sq_seo_errors', 0);
170
+
171
+ $wp_admin_bar->add_node(
172
+ array(
173
+ 'id' => 'sq_toolbar',
174
+ 'title' => '<span class="sq_logo" style="margin-right: 2px"></span>' . esc_html(apply_filters('sq_menu_name', _SQ_MENU_NAME_)) . (($errors) ? '<span class="sq_errorcount">' . esc_html($errors) . '</span>' : ''),
175
+ 'href' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_dashboard'),
176
+ 'parent' => false
177
+ )
178
+ );
179
+
180
+ $mainmenu = $this->model->getMainMenu();
181
+ if (!empty($mainmenu)) {
182
+ foreach ($mainmenu as $menuid => $item) {
183
+
184
+ //Check if the menu item is visible on the top
185
+ if (isset($item['topmenu']) && !$item['topmenu']) {
186
+ continue;
187
+ }
188
+
189
+ if ($menuid == 'sq_dashboard' && $errors) {
190
+ if (is_rtl()) {
191
+ $item['title'] = '<span class="sq_errorcount" style="margin: 6px 0 0 0 !important; float: left !important;">' . $errors . '</span>' . $item['title'];
192
+ } else {
193
+ $item['title'] = $item['title'] . '<span class="sq_errorcount" style="margin: 6px 35px 0 0 !important;">' . $errors . '</span>';
194
+ }
195
+ }
196
+
197
+ //make sure the user has the capabilities
198
+ if (SQ_Classes_Helpers_Tools::userCan($item['capability'])) {
199
+ $wp_admin_bar->add_node(
200
+ array(
201
+ 'id' => $menuid,
202
+ 'title' => $item['title'],
203
+ 'href' => SQ_Classes_Helpers_Tools::getAdminUrl($menuid),
204
+ 'parent' => 'sq_toolbar'
205
+ )
206
+ );
207
+ $tabs = $this->model->getTabs($menuid);
208
+ if (!empty($tabs)) {
209
+ foreach ($tabs as $id => $tab) {
210
+ $array_id = explode('/', $id);
211
+ if (count((array)$array_id) == 2) {
212
+ $wp_admin_bar->add_node(
213
+ array(
214
+ 'id' => $menuid . str_replace('/', '_', $id),
215
+ 'title' => $tab['title'],
216
+ 'href' => SQ_Classes_Helpers_Tools::getAdminUrl($array_id[0], $array_id[1]),
217
+ 'parent' => $menuid
218
+ )
219
+ );
220
+ }
221
+ }
222
+ }
223
+ }
224
+ }
225
+ }
226
+
227
+ }
228
+
229
+ $current_screen = get_current_screen();
230
+ $post = get_post();
231
+ if ('post' == $current_screen->base
232
+ && ($post_type_object = get_post_type_object($post->post_type))
233
+ && (SQ_Classes_Helpers_Tools::userCan('edit_post', $post->ID) || SQ_Classes_Helpers_Tools::userCan('sq_manage_snippets'))
234
+ && ($post_type_object->public)
235
+ ) {
236
+ } elseif ('edit' == $current_screen->base
237
+ && ($post_type_object = get_post_type_object($current_screen->post_type))
238
+ && ($post_type_object->show_in_admin_bar)
239
+ && !('edit-' . $current_screen->post_type === $current_screen->id)
240
+ ) {
241
+ } elseif ('term' == $current_screen->base
242
+ && isset($tag) && is_object($tag) && !is_wp_error($tag)
243
+ && ($tax = get_taxonomy($tag->taxonomy))
244
+ && $tax->public
245
+ ) {
246
+ } else {
247
+ return $wp_admin_bar;
248
+ }
249
+
250
+ $this->model->addMeta(
251
+ array('sq_blocksnippet',
252
+ esc_html__("SEO Snippet", 'squirrly-seo'),
253
+ array(SQ_Classes_ObjController::getClass('SQ_Controllers_Snippet'), 'init'),
254
+ null,
255
+ 'normal',
256
+ 'high'
257
+ )
258
+ );
259
+
260
+ $wp_admin_bar->add_node(
261
+ array(
262
+ 'id' => 'sq_bar_menu',
263
+ 'title' => '<span class="sq_logo"></span> ' . esc_html__("Custom SEO", 'squirrly-seo'),
264
+ 'parent' => 'top-secondary',
265
+ )
266
+ );
267
+
268
+
269
+ //Add snippet body
270
+ $wp_admin_bar->add_menu(
271
+ array(
272
+ 'id' => 'sq_bar_submenu',
273
+ 'parent' => 'sq_bar_menu',
274
+ 'meta' => array(
275
+ 'html' => SQ_Classes_ObjController::getClass('SQ_Controllers_Snippet')->init(),
276
+ 'tabindex' => PHP_INT_MAX,
277
+ ),
278
+ )
279
+ );
280
+ }
281
+
282
+ return $wp_admin_bar;
283
+ }
284
+
285
+ public function hookDashboardSetup()
286
+ {
287
+ wp_add_dashboard_widget(
288
+ 'sq_dashboard_widget',
289
+ esc_html__("Squirrly SEO", 'squirrly-seo'),
290
+ array(SQ_Classes_ObjController::getClass('SQ_Controllers_Dashboard'), 'dashboard')
291
+ );
292
+
293
+ // Move our widget to top.
294
+ global $wp_meta_boxes;
295
+
296
+ $dashboard = $wp_meta_boxes['dashboard']['normal']['core'];
297
+ $ours = array('sq_dashboard_widget' => $dashboard['sq_dashboard_widget']);
298
+ $wp_meta_boxes['dashboard']['normal']['core'] = array_merge($ours, $dashboard);
299
+ }
300
+
301
+ public function hookNetworkMenu()
302
+ {
303
+ //Check the Dev Kit settings
304
+ SQ_Classes_ObjController::getClass('SQ_Classes_Helpers_DevKit');
305
+ }
306
+
307
+ /**
308
+ * Creates the Setting menu in Wordpress
309
+ */
310
+ public function hookMenu()
311
+ {
312
+ //Hook the SEO Errors from Squirrly SEO Check
313
+ add_action('sq_seo_errors', array($this, 'getSEOErrors'));
314
+
315
+ //Check the Dev Kit settings
316
+ SQ_Classes_ObjController::getClass('SQ_Classes_Helpers_DevKit');
317
+
318
+ //Get all the post types
319
+ $this->post_type = SQ_Classes_Helpers_Tools::getOption('sq_post_types');
320
+
321
+ //Get count local SEO errors
322
+ $errors = apply_filters('sq_seo_errors', 0);
323
+
324
+ ///////////////
325
+ $this->model->addMenu(
326
+ array(apply_filters('sq_menu_name', _SQ_MENU_NAME_),
327
+ apply_filters('sq_menu_name', _SQ_MENU_NAME_) . (($errors) ? '<span class="sq_errorcount">' . $errors . '</span>' : ''),
328
+ 'edit_posts',
329
+ 'sq_dashboard',
330
+ null,
331
+ apply_filters('sq_logo', _SQ_ASSETS_URL_ . 'img/logos/menu_icon_16.png')
332
+ )
333
+ );
334
+
335
+ //Load the Squirrly Menu
336
+ $mainmenu = $this->model->getMainMenu();
337
+ if (!empty($mainmenu)) {
338
+ foreach ($mainmenu as $name => $item) {
339
+
340
+ //Check if the menu is set to show in the left side
341
+ if (isset($item['leftmenu'])) {
342
+ if (is_bool($item['leftmenu'])) {
343
+ if (!$item['leftmenu'] && SQ_Classes_Helpers_Tools::getValue('page', '') <> $name) {
344
+ continue;
345
+ }
346
+ } else {
347
+ $item['title'] = $item['leftmenu'];
348
+ }
349
+ }
350
+
351
+ //Add the page
352
+ $this->model->addSubmenu(
353
+ array($item['parent'],
354
+ $item['description'],
355
+ $item['title'],
356
+ $item['capability'],
357
+ $name,
358
+ $item['function'],
359
+ )
360
+ );
361
+
362
+ }
363
+
364
+ //Update the external links in the menu
365
+ global $submenu;
366
+ if (!empty($submenu['sq_dashboard'])) {
367
+ foreach ($submenu['sq_dashboard'] as &$item) {
368
+ if (isset($mainmenu[$item[2]]['href']) && $mainmenu[$item[2]]['href']) {
369
+ if (parse_url($mainmenu[$item[2]]['href'], PHP_URL_HOST) !== parse_url(home_url(), PHP_URL_HOST)) {
370
+ $item[0] .= '<i class="dashicons dashicons-external" style="font-size:12px;vertical-align:-2px;height:10px;"></i>';
371
+ }
372
+ $item[2] = $mainmenu[$item[2]]['href'];
373
+ }
374
+ }
375
+ }
376
+ }
377
+ }
378
+
379
+ /**
380
+ * Add Post Editor Meta Box
381
+ * Load Squirrly Live Assistant
382
+ */
383
+ public function addMetabox()
384
+ {
385
+ $types = get_post_types(array('public' => true));
386
+
387
+ if (!apply_filters('sq_load_snippet', true) || !SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
388
+ return;
389
+ }
390
+
391
+ //Exclude types for SLA
392
+ $excludes = SQ_Classes_Helpers_Tools::getOption('sq_sla_exclude_post_types');
393
+ if (!empty($types) && !empty($excludes)) {
394
+ foreach ($excludes as $exclude) {
395
+ if ($exclude) {
396
+ if (in_array($exclude, $types)) {
397
+ unset($types[$exclude]);
398
+ }
399
+ }
400
+ }
401
+ }
402
+
403
+ //Add Live Assistant For Selected Post Types
404
+ if (!empty($types)) {
405
+ foreach ($types as $type) {
406
+ if (is_string($type) && $type <> '' && $metabox = unserialize(SQ_Classes_Helpers_Tools::getUserMeta('meta-box-order_' . $type))) {
407
+ extract($metabox);
408
+
409
+ if (isset($side) && isset($normal) && is_string($side) && is_string($normal)) {
410
+ $side = explode(',', $side);
411
+ $normal = explode(',', $normal);
412
+ if (in_array('post' . _SQ_NAME_, $normal)) {
413
+ $side = array_merge(array('post' . _SQ_NAME_), $side);
414
+ $metabox['side'] = join(',', array_unique($side));
415
+
416
+ $normal = array_diff($normal, array('post' . _SQ_NAME_));
417
+ $metabox['normal'] = join(',', array_unique($normal));
418
+ SQ_Classes_Helpers_Tools::saveUserMeta('meta-box-order_' . $type, $metabox);
419
+ }
420
+
421
+ if (in_array('sq_blocksnippet', $side)) {
422
+ $normal = array_merge(array('sq_blocksnippet'), $normal);
423
+ $metabox['normal'] = join(',', array_unique($normal));
424
+
425
+ $side = array_diff($side, array('sq_blocksnippet'));
426
+ $metabox['side'] = join(',', array_unique($side));
427
+ SQ_Classes_Helpers_Tools::saveUserMeta('meta-box-order_' . $type, $metabox);
428
+ }
429
+ }
430
+ }
431
+
432
+ //Load the SLA in Post
433
+ $this->model->addMeta(
434
+ array('post' . _SQ_NAME_,
435
+ ucfirst(_SQ_NAME_),
436
+ array(SQ_Classes_ObjController::getClass('SQ_Controllers_Post'), 'init'),
437
+ $type,
438
+ 'side',
439
+ 'high'
440
+ )
441
+ );
442
+ }
443
+
444
+ }
445
+ }
446
+
447
+ /**
448
+ * Add the Squirrly Setttings Class in all Squirrly SEO Pages
449
+ * Used for personal layout
450
+ *
451
+ * @param $classes
452
+ * @return string
453
+ */
454
+ public function addSquirrlySettingsClass($classes)
455
+ {
456
+ global $sq_setting_page;
457
+
458
+ if (isset($sq_setting_page) && $sq_setting_page) {
459
+ $classes = "$classes squirrly-seo-settings";
460
+ }
461
+
462
+ return $classes;
463
+ }
464
+
465
+ /**
466
+ * Hook the Head
467
+ */
468
+ public function hookHead()
469
+ {
470
+ global $sq_fullscreen, $sq_setting_page;
471
+
472
+ //Load settings only in the Squirrly Menu
473
+ if (isset($sq_setting_page) && $sq_setting_page) {
474
+ echo '<script type="text/javascript" src="//www.google.com/jsapi"></script>';
475
+ echo '<script>google.load("visualization", "1.0", {packages: ["corechart"]});</script>';
476
+ if (isset($sq_fullscreen) && $sq_fullscreen) {
477
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('fullwidth', array('trigger' => true, 'media' => 'all'));
478
+ }
479
+ }
480
+
481
+ //Load the Squirrly Logo on all Dashboard
482
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('logo');
483
+
484
+ }
485
+
486
+ /**
487
+ * Set the viewport for a google Squirrly Settings layout
488
+ */
489
+ function setViewport()
490
+ {
491
+ $page = apply_filters('sq_page', SQ_Classes_Helpers_Tools::getValue('page', ''));
492
+ if ($page == 'sq_dashboard') {
493
+ echo '<meta name="viewport" content="width=900">';
494
+ } else {
495
+ echo '<meta name="viewport" content="width=1200">';
496
+ }
497
+ }
498
+
499
+ /**
500
+ * Hook the Elementor Builder
501
+ */
502
+ public function hookBuilders()
503
+ {
504
+ add_action('elementor/editor/footer', array(SQ_Classes_ObjController::getClass('SQ_Controllers_Post'), 'loadLiveAssistant'), 99);
505
+ }
506
+
507
+ /**
508
+ * Count the SEO Errors from SEO Goals
509
+ *
510
+ * @return mixed
511
+ */
512
+ public function getSEOErrors()
513
+ {
514
+ return SQ_Classes_ObjController::getClass('SQ_Controllers_CheckSeo')->setCategory('sq_dashboard')->getErrorsCount();
515
+ }
516
+
517
+
518
+ /**
519
+ * Set the cloud.squirrly.co menu based on the client rights
520
+ *
521
+ * @param $url
522
+ * @param $path
523
+ * @return string
524
+ */
525
+ public function getCloudMenu($url, $path)
526
+ {
527
+ if (function_exists('wp_get_current_user') && SQ_Classes_Helpers_Tools::getOption('sq_api')) {
528
+ if (SQ_Classes_Helpers_Tools::getMenuVisible('show_panel') && SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
529
+ $url .= 'login/?token=' . SQ_Classes_Helpers_Tools::getOption('sq_api') . '&user_url=' . apply_filters('sq_homeurl', get_bloginfo('url')) . '&redirect_to=' . _SQ_DASH_URL_ . 'user/' . $path;
530
+ }
531
+ }
532
+
533
+ return esc_url($url);
534
+ }
535
+ }
controllers/Onboarding.php CHANGED
@@ -1,95 +1,104 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- class SQ_Controllers_Onboarding extends SQ_Classes_FrontController {
5
-
6
- public $metas;
7
- public $platforms;
8
- public $active_plugins;
9
-
10
- /**
11
- * Call for Onboarding
12
- * @return mixed|void
13
- */
14
- public function init() {
15
-
16
- $tab = SQ_Classes_Helpers_Tools::getValue('tab', 'step1');
17
-
18
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap-reboot');
19
- if (is_rtl()) {
20
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('popper');
21
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap.rtl');
22
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('rtl');
23
- } else {
24
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap');
25
- }
26
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('switchery');
27
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('fontawesome');
28
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('global');
29
-
30
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('assistant');
31
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('navbar');
32
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('onboarding');
33
-
34
- if (method_exists($this, preg_replace("/[^a-zA-Z0-9]/", "", $tab))) {
35
- call_user_func(array($this, preg_replace("/[^a-zA-Z0-9]/", "", $tab)));
36
- }
37
-
38
- //Load the Themes and Plugins
39
- add_filter('sq_themes', array(SQ_Classes_ObjController::getClass('SQ_Models_ImportExport'), 'getAvailableThemes'));
40
- add_filter('sq_plugins', array(SQ_Classes_ObjController::getClass('SQ_Models_ImportExport'), 'getAvailablePlugins'));
41
- $this->platforms = apply_filters('sq_importList', false);
42
-
43
- //@ob_flush();
44
- echo $this->getView('Onboarding/' . ucfirst($tab));
45
- }
46
-
47
- public function step1() {
48
- //Set the onboarding version
49
- SQ_Classes_Helpers_Tools::saveOptions('sq_onboarding', SQ_VERSION);
50
- }
51
-
52
- /**
53
- * Check SEO Actions
54
- */
55
- public function action() {
56
- parent::action();
57
-
58
- switch (SQ_Classes_Helpers_Tools::getValue('action')) {
59
- case 'sq_onboading_checksite':
60
- /** @var SQ_Models_CheckSeo $seoCheck */
61
- $seoCheck = SQ_Classes_ObjController::getClass('SQ_Models_CheckSeo');
62
- $seoCheck->getSourceCode();
63
- $this->metas = $seoCheck->checkMetas();
64
-
65
- break;
66
-
67
- case 'sq_onboarding_settings':
68
- $sq_onboarding_data = SQ_Classes_Helpers_Tools::getValue('sq_onboarding_data');
69
- SQ_Classes_Helpers_Tools::saveOptions('sq_onboarding_data', $sq_onboarding_data);
70
-
71
- if (isset($sq_onboarding_data['seo_level'])) {
72
- SQ_Classes_Helpers_Tools::saveOptions('sq_seoexpert', ($sq_onboarding_data['seo_level'] == 'expert'));
73
- }
74
- if (isset($sq_onboarding_data['website_type'])) {
75
- if ($sq_onboarding_data['website_type'] == 'local') {
76
- SQ_Classes_Helpers_Tools::saveOptions('sq_auto_jsonld_local', 1);
77
- }
78
- if ($sq_onboarding_data['website_type'] == 'portofolio') {
79
- SQ_Classes_Helpers_Tools::saveOptions('sq_attachment_redirect', 0);
80
- }else{
81
- SQ_Classes_Helpers_Tools::saveOptions('sq_attachment_redirect', 1);
82
- }
83
- SQ_Classes_Helpers_Tools::saveOptions('sq_jsonld_type', ($sq_onboarding_data['website_type'] == 'personal' ? 'Person' : 'Organization'));
84
- }
85
-
86
- break;
87
- case 'sq_onboarding_commitment':
88
- SQ_Classes_Helpers_Tools::saveOptions('sq_seojourney', date('Y-m-d'));
89
-
90
- break;
91
-
92
- }
93
- }
94
-
95
- }
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ class SQ_Controllers_Onboarding extends SQ_Classes_FrontController
5
+ {
6
+
7
+ public $metas;
8
+ public $platforms;
9
+ public $active_plugins;
10
+
11
+ /**
12
+ * Call for Onboarding
13
+ *
14
+ * @return mixed|void
15
+ */
16
+ public function init()
17
+ {
18
+
19
+ $tab = preg_replace("/[^a-zA-Z0-9]/", "", SQ_Classes_Helpers_Tools::getValue('tab', 'step1'));
20
+
21
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap-reboot');
22
+ if (is_rtl()) {
23
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('popper');
24
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap.rtl');
25
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('rtl');
26
+ } else {
27
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap');
28
+ }
29
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('switchery');
30
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('fontawesome');
31
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('global');
32
+
33
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('assistant');
34
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('navbar');
35
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('onboarding');
36
+
37
+ if (method_exists($this, $tab)) {
38
+ call_user_func(array($this, $tab));
39
+ }
40
+
41
+ //Load the Themes and Plugins
42
+ add_filter('sq_themes', array(SQ_Classes_ObjController::getClass('SQ_Models_ImportExport'), 'getAvailableThemes'));
43
+ add_filter('sq_plugins', array(SQ_Classes_ObjController::getClass('SQ_Models_ImportExport'), 'getAvailablePlugins'));
44
+ $this->platforms = apply_filters('sq_importList', false);
45
+
46
+ //@ob_flush();
47
+ $this->show_view('Onboarding/' . esc_attr(ucfirst($tab)));
48
+ }
49
+
50
+ public function step1()
51
+ {
52
+ //Set the onboarding version
53
+ SQ_Classes_Helpers_Tools::saveOptions('sq_onboarding', SQ_VERSION);
54
+ }
55
+
56
+ /**
57
+ * Check SEO Actions
58
+ */
59
+ public function action()
60
+ {
61
+ parent::action();
62
+
63
+ switch (SQ_Classes_Helpers_Tools::getValue('action')) {
64
+ case 'sq_onboading_checksite':
65
+ /**
66
+ *
67
+ *
68
+ * @var SQ_Models_CheckSeo $seoCheck
69
+ */
70
+ $seoCheck = SQ_Classes_ObjController::getClass('SQ_Models_CheckSeo');
71
+ $seoCheck->getSourceCode();
72
+ $this->metas = $seoCheck->checkMetas();
73
+
74
+ break;
75
+
76
+ case 'sq_onboarding_settings':
77
+ $sq_onboarding_data = SQ_Classes_Helpers_Tools::getValue('sq_onboarding_data');
78
+ SQ_Classes_Helpers_Tools::saveOptions('sq_onboarding_data', $sq_onboarding_data);
79
+
80
+ if (isset($sq_onboarding_data['seo_level'])) {
81
+ SQ_Classes_Helpers_Tools::saveOptions('sq_seoexpert', ($sq_onboarding_data['seo_level'] == 'expert'));
82
+ }
83
+ if (isset($sq_onboarding_data['website_type'])) {
84
+ if ($sq_onboarding_data['website_type'] == 'local') {
85
+ SQ_Classes_Helpers_Tools::saveOptions('sq_auto_jsonld_local', 1);
86
+ }
87
+ if ($sq_onboarding_data['website_type'] == 'portofolio') {
88
+ SQ_Classes_Helpers_Tools::saveOptions('sq_attachment_redirect', 0);
89
+ }else{
90
+ SQ_Classes_Helpers_Tools::saveOptions('sq_attachment_redirect', 1);
91
+ }
92
+ SQ_Classes_Helpers_Tools::saveOptions('sq_jsonld_type', ($sq_onboarding_data['website_type'] == 'personal' ? 'Person' : 'Organization'));
93
+ }
94
+
95
+ break;
96
+ case 'sq_onboarding_commitment':
97
+ SQ_Classes_Helpers_Tools::saveOptions('sq_seojourney', date('Y-m-d'));
98
+
99
+ break;
100
+
101
+ }
102
+ }
103
+
104
+ }
controllers/Overview.php CHANGED
@@ -1,101 +1,109 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- /**
5
- * Overview
6
- */
7
- class SQ_Controllers_Overview extends SQ_Classes_FrontController {
8
- /** @var object Checkin process with Squirrly Cloud */
9
- public $checkin;
10
-
11
- public function init() {
12
-
13
- if (SQ_Classes_Helpers_Tools::getOption('sq_api') == '') {
14
- echo $this->getView('Errors/Connect');
15
- return;
16
- }
17
-
18
- //Checkin to API V2
19
- $this->checkin = SQ_Classes_RemoteController::checkin();
20
-
21
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap-reboot');
22
- if (is_rtl()) {
23
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('popper');
24
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap.rtl');
25
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('rtl');
26
- } else {
27
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap');
28
- }
29
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('fontawesome');
30
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('switchery');
31
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('global');
32
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('research');
33
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('navbar');
34
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('dashboard');
35
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('account');
36
-
37
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('assistant');
38
-
39
- add_action('sq_form_notices', array($this, 'getNotificationBar'));
40
- add_action('sq_form_notices', array($this, 'getNotificationCompatibility'));
41
-
42
- parent::init();
43
-
44
- }
45
-
46
- public function getJourneyNotification() {
47
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippets')) {
48
- return;
49
- }
50
-
51
- //Get the user name
52
- $username = '';
53
- if(get_current_user_id()) {
54
- $user_info = get_userdata(get_current_user_id());
55
- if(!$username = $user_info->first_name){
56
- $username = $user_info->user_login;
57
- }
58
- }
59
-
60
- if (!SQ_Classes_Helpers_Tools::getOption('sq_seojourney') && SQ_Classes_Helpers_Tools::getOption('sq_alert_journey')) {
61
- if ((time() - strtotime(SQ_Classes_Helpers_Tools::getOption('sq_installed'))) / (3600 * 24) > 4) { ?>
62
- <div class="alert alert-warning text-center m-0 mt-2 p-2">
63
- <form method="post" class="p-0 m-0">
64
- <?php SQ_Classes_Helpers_Tools::setNonce('sq_alerts_close', 'sq_nonce'); ?>
65
- <input type="hidden" name="action" value="sq_alerts_close"/>
66
- <input type="hidden" name="alert" value="sq_alert_journey"/>
67
- <button type="submit" class="btn float-right bg-transparent p-0 m-0">x</button>
68
- </form>
69
- <?php echo sprintf(esc_html__("%s, why don't you start a two weeks journey for better rankings? %sStart driving your most valuable pages to Better Rankings today with your current plan.%s", _SQ_PLUGIN_NAME_), '<strong>' . $username . '</strong>', '<br /><a href="' . SQ_Classes_Helpers_Tools::getAdminUrl('sq_onboarding', 'journey1') . '" style="font-weight: bold;" >', '</a>'); ?>
70
- </div>
71
- <?php
72
- }
73
- }
74
- }
75
-
76
-
77
- public function getNotificationCompatibility() {
78
- if (SQ_Classes_Helpers_Tools::getOption('sq_alert_overview') && SQ_Classes_Helpers_Tools::getOption('sq_api')) {
79
- add_filter('sq_plugins', array(SQ_Classes_ObjController::getClass('SQ_Models_ImportExport'), 'getActivePlugins'));
80
- $platforms = apply_filters('sq_importList', false);
81
- if ($platforms && count((array)$platforms) > 0) {
82
- foreach ($platforms as $platform => $data) {
83
- $plugin = SQ_Classes_ObjController::getClass('SQ_Models_ImportExport')->getName($platform);
84
- ?>
85
- <div class="sq_offer alert alert-warning text-center m-0 mt-2 p-2">
86
- <form method="post" class="p-0 m-0">
87
- <?php SQ_Classes_Helpers_Tools::setNonce('sq_alerts_close', 'sq_nonce'); ?>
88
- <input type="hidden" name="action" value="sq_alerts_close"/>
89
- <input type="hidden" name="alert" value="sq_alert_overview"/>
90
- <button type="submit" class="btn float-right bg-transparent p-0 m-0">x</button>
91
- </form>
92
- <?php echo sprintf(esc_html__("Detected %s: We encourage you to %sImport the Settings and SEO%s from %s and deactivate %s to increase the page loading speed for better Google ranking.", _SQ_PLUGIN_NAME_), '<strong>' . $plugin . '</strong>', '<a href="' . SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'backup') . '" style="font-weight: bold;" >', '</a>', $plugin, $plugin); ?>
93
- </div>
94
- <?php
95
- break;
96
- }
97
- }
98
- }
99
- }
100
-
101
- }
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ /**
5
+ * Overview
6
+ */
7
+ class SQ_Controllers_Overview extends SQ_Classes_FrontController
8
+ {
9
+ /**
10
+ *
11
+ *
12
+ * @var object Checkin process with Squirrly Cloud
13
+ */
14
+ public $checkin;
15
+
16
+ public function init()
17
+ {
18
+
19
+ if (SQ_Classes_Helpers_Tools::getOption('sq_api') == '') {
20
+ $this->show_view('Errors/Connect');
21
+ return;
22
+ }
23
+
24
+ //Checkin to API V2
25
+ $this->checkin = SQ_Classes_RemoteController::checkin();
26
+
27
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap-reboot');
28
+ if (is_rtl()) {
29
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('popper');
30
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap.rtl');
31
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('rtl');
32
+ } else {
33
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap');
34
+ }
35
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('fontawesome');
36
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('switchery');
37
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('global');
38
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('research');
39
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('navbar');
40
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('dashboard');
41
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('account');
42
+
43
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('assistant');
44
+
45
+ add_action('sq_form_notices', array($this, 'getNotificationBar'));
46
+ add_action('sq_form_notices', array($this, 'getNotificationCompatibility'));
47
+
48
+ parent::init();
49
+
50
+ }
51
+
52
+ public function getJourneyNotification()
53
+ {
54
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippets')) {
55
+ return;
56
+ }
57
+
58
+ //Get the user name
59
+ $username = '';
60
+ if(get_current_user_id()) {
61
+ $user_info = get_userdata(get_current_user_id());
62
+ if(!$username = $user_info->first_name) {
63
+ $username = $user_info->user_login;
64
+ }
65
+ }
66
+
67
+ if (!SQ_Classes_Helpers_Tools::getOption('sq_seojourney') && SQ_Classes_Helpers_Tools::getOption('sq_alert_journey')) {
68
+ if ((time() - strtotime(SQ_Classes_Helpers_Tools::getOption('sq_installed'))) / (3600 * 24) > 4) { ?>
69
+ <div class="alert alert-warning text-center m-0 mt-2 p-2">
70
+ <form method="post" class="p-0 m-0">
71
+ <?php SQ_Classes_Helpers_Tools::setNonce('sq_alerts_close', 'sq_nonce'); ?>
72
+ <input type="hidden" name="action" value="sq_alerts_close"/>
73
+ <input type="hidden" name="alert" value="sq_alert_journey"/>
74
+ <button type="submit" class="btn float-right bg-transparent p-0 m-0">x</button>
75
+ </form>
76
+ <?php echo sprintf(esc_html__("%s, why don't you start a two weeks journey for better rankings? %sStart driving your most valuable pages to Better Rankings today with your current plan.%s", 'squirrly-seo'), '<strong>' . esc_attr($username) . '</strong>', '<br /><a href="' . SQ_Classes_Helpers_Tools::getAdminUrl('sq_onboarding', 'journey1') . '" style="font-weight: bold;" >', '</a>'); ?>
77
+ </div>
78
+ <?php
79
+ }
80
+ }
81
+ }
82
+
83
+
84
+ public function getNotificationCompatibility()
85
+ {
86
+ if (SQ_Classes_Helpers_Tools::getOption('sq_alert_overview') && SQ_Classes_Helpers_Tools::getOption('sq_api')) {
87
+ add_filter('sq_plugins', array(SQ_Classes_ObjController::getClass('SQ_Models_ImportExport'), 'getActivePlugins'));
88
+ $platforms = apply_filters('sq_importList', false);
89
+ if ($platforms && count((array)$platforms) > 0) {
90
+ foreach ($platforms as $platform => $data) {
91
+ $plugin = SQ_Classes_ObjController::getClass('SQ_Models_ImportExport')->getName($platform);
92
+ ?>
93
+ <div class="sq_offer alert alert-warning text-center m-0 mt-2 p-2">
94
+ <form method="post" class="p-0 m-0">
95
+ <?php SQ_Classes_Helpers_Tools::setNonce('sq_alerts_close', 'sq_nonce'); ?>
96
+ <input type="hidden" name="action" value="sq_alerts_close"/>
97
+ <input type="hidden" name="alert" value="sq_alert_overview"/>
98
+ <button type="submit" class="btn float-right bg-transparent p-0 m-0">x</button>
99
+ </form>
100
+ <?php echo sprintf(esc_html__("Detected %s: We encourage you to %sImport the Settings and SEO%s from %s and deactivate %s to increase the page loading speed for better Google ranking.", 'squirrly-seo'), '<strong>' . esc_attr($plugin) . '</strong>', '<a href="' . SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'backup') . '" style="font-weight: bold;" >', '</a>', esc_attr($plugin), esc_attr($plugin)); ?>
101
+ </div>
102
+ <?php
103
+ break;
104
+ }
105
+ }
106
+ }
107
+ }
108
+
109
+ }
controllers/Patterns.php CHANGED
@@ -1,158 +1,168 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- class SQ_Controllers_Patterns extends SQ_Classes_FrontController {
5
-
6
- /** @var SQ_Models_Domain_Patterns $patterns */
7
- public $patterns;
8
-
9
- public function init() {
10
- if (is_rtl()) {
11
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('sqbootstrap.rtl', array('trigger' => true, 'media' => 'all'));
12
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('rtl', array('trigger' => true, 'media' => 'all'));
13
- } else {
14
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('sqbootstrap', array('trigger' => true, 'media' => 'all'));
15
- }
16
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('patterns', array('trigger' => true, 'media' => 'all'));
17
-
18
- echo '
19
- <script>
20
- jQuery.sq_patterns_list = jQuery.parseJSON("' . addslashes(SQ_ALL_PATTERNS) . '");
21
- var __sq_save_message = "' . esc_html__("Saved!", _SQ_PLUGIN_NAME_) . '";
22
- var __sq_save_message_preview = "' . esc_html__("Saved! This is how the preview looks like", _SQ_PLUGIN_NAME_) . '";
23
- </script>';
24
- }
25
-
26
- /**
27
- * Replace the patterns by each tags
28
- *
29
- * @param SQ_Models_Domain_Post $post
30
- * @return SQ_Models_Domain_Post | false
31
- */
32
- public function replacePatterns($post) {
33
- if ($post instanceof SQ_Models_Domain_Post) {
34
- //set the patterns based on the current post
35
- $this->patterns = SQ_Classes_ObjController::getDomain('SQ_Models_Domain_Patterns', $post->toArray());
36
-
37
- //set the current post for excerpt and description
38
- $this->patterns->currentpost = $post;
39
-
40
- //Foreach SQ, if has patterns, replace them
41
- if ($sq_array = $post->sq->toArray()) {
42
-
43
- //set the keywords from sq and not from post
44
- $this->patterns->keywords = $post->sq->keywords;
45
-
46
- $post->sq = $this->processPatterns($sq_array, $post->sq);
47
- }
48
- }
49
- return $post;
50
-
51
- }
52
-
53
- /**
54
- * Get all patterns to process and add them in the object
55
- * @param $values
56
- * @param $object
57
- * @return mixed
58
- */
59
- public function processPatterns($values, $object) {
60
-
61
- //Foreach SQ, if has patterns, replace them
62
- $sq_with_patterns = array();
63
- //Set the Separator from object automation
64
- //do not remove it from here
65
- $this->patterns->sep = $object->sep;
66
-
67
- if (!empty($values)) {
68
- foreach ($values as $name => $value) {
69
- if ($name <> '' && !is_array($value) && $value <> '') {
70
-
71
- if (strpos($value, '%%') !== false) { //in case there are still patterns from Yoast
72
- $value = preg_replace('/%%([^\%]+)%%/s', '{{$1}}', $value);
73
- $object->$name = preg_replace('/%%([^\%]+)%%/s', '{{$1}}', $object->$name);
74
- }
75
-
76
- if (strpos($value, '%') !== false) { //in case there are still patterns from Rank Math
77
- $value = preg_replace('/%([^\%]+)%/s', '{{$1}}', $value);
78
- $object->$name = preg_replace('/%([^\%]+)%/s', '{{$1}}', $object->$name);
79
- }
80
-
81
- if(is_string($value) && $value <> '') {
82
- if (strpos($value, '{{') !== false && strpos($value, '}}') !== false) {
83
- $sq_with_patterns[$name] = $value;
84
- }
85
- }
86
- }
87
- }
88
- if (!empty($sq_with_patterns)) {
89
- foreach ($this->patterns->getPatterns() as $key => $pattern) {
90
- foreach ($sq_with_patterns as $name => $value) {
91
- if ($name <> '' && is_string($value) && $value <> '' && $pattern <> '') {
92
- if (stripos($value, $pattern) !== false) {
93
- $object->$name = str_ireplace($pattern, $this->patterns->$key, $object->$name);
94
- }
95
- }
96
- }
97
- }
98
-
99
- }
100
- }
101
-
102
- return $object;
103
- }
104
-
105
- /**
106
- * Called when Post action is triggered
107
- *
108
- * @return void
109
- */
110
- public function action() {
111
- parent::action();
112
-
113
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
114
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
115
- SQ_Classes_Helpers_Tools::setHeader('json');
116
- echo wp_json_encode($response);
117
- exit();
118
- }
119
-
120
- switch (SQ_Classes_Helpers_Tools::getValue('action')) {
121
- case 'sq_getpatterns':
122
- $all_patterns = json_decode(SQ_ALL_PATTERNS, true);
123
- $patterns = false;
124
-
125
- $post_id = (int)SQ_Classes_Helpers_Tools::getValue('post_id', 0);
126
- $term_id = (int)SQ_Classes_Helpers_Tools::getValue('term_id', 0);
127
- $taxonomy = SQ_Classes_Helpers_Tools::getValue('taxonomy', 'category');
128
- $post_type = SQ_Classes_Helpers_Tools::getValue('post_type', 'post');
129
-
130
- if ($post = SQ_Classes_ObjController::getDomain('SQ_Models_Snippet')->getCurrentSnippet($post_id, $term_id, $taxonomy, $post_type)) {
131
-
132
- $patterns = SQ_Classes_ObjController::getDomain('SQ_Models_Domain_Patterns', $post->toArray());
133
- $patterns = $this->processPatterns(array_keys($all_patterns), $patterns);
134
-
135
- //Set the separator character from post sep
136
- $patterns->sep = $post->sq->sep;
137
-
138
- foreach ($all_patterns as $pattern => $title) {
139
- $name = preg_replace('/{{([^\}]+)}}/s', '$1', $pattern);
140
- $all_patterns[$pattern] = array('value' => $patterns->$name, 'details' => $all_patterns[$pattern]);
141
- }
142
- }
143
-
144
-
145
- if (SQ_Classes_Helpers_Tools::isAjax()) {
146
- //return json with the results
147
- SQ_Classes_Helpers_Tools::setHeader('json');
148
-
149
- echo wp_json_encode(array('json' => wp_json_encode($all_patterns)));
150
- exit();
151
- }
152
- break;
153
-
154
- }
155
- }
156
-
157
-
158
- }
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ class SQ_Controllers_Patterns extends SQ_Classes_FrontController
5
+ {
6
+
7
+ /**
8
+ *
9
+ *
10
+ * @var SQ_Models_Domain_Patterns $patterns
11
+ */
12
+ public $patterns;
13
+
14
+ public function init()
15
+ {
16
+ if (is_rtl()) {
17
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('sqbootstrap.rtl', array('trigger' => true, 'media' => 'all'));
18
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('rtl', array('trigger' => true, 'media' => 'all'));
19
+ } else {
20
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('sqbootstrap', array('trigger' => true, 'media' => 'all'));
21
+ }
22
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('patterns', array('trigger' => true, 'media' => 'all'));
23
+
24
+ echo '
25
+ <script>
26
+ jQuery.sq_patterns_list = jQuery.parseJSON("' . addslashes(SQ_ALL_PATTERNS) . '");
27
+ var __sq_save_message = "' . esc_html__("Saved!", 'squirrly-seo') . '";
28
+ var __sq_save_message_preview = "' . esc_html__("Saved! This is how the preview looks like", 'squirrly-seo') . '";
29
+ </script>';
30
+ }
31
+
32
+ /**
33
+ * Replace the patterns by each tags
34
+ *
35
+ * @param SQ_Models_Domain_Post $post
36
+ * @return SQ_Models_Domain_Post | false
37
+ */
38
+ public function replacePatterns($post)
39
+ {
40
+ if ($post instanceof SQ_Models_Domain_Post) {
41
+ //set the patterns based on the current post
42
+ $this->patterns = SQ_Classes_ObjController::getDomain('SQ_Models_Domain_Patterns', $post->toArray());
43
+
44
+ //set the current post for excerpt and description
45
+ $this->patterns->currentpost = $post;
46
+
47
+ //Foreach SQ, if has patterns, replace them
48
+ if ($sq_array = $post->sq->toArray()) {
49
+
50
+ //set the keywords from sq and not from post
51
+ $this->patterns->keywords = $post->sq->keywords;
52
+
53
+ $post->sq = $this->processPatterns($sq_array, $post->sq);
54
+ }
55
+ }
56
+ return $post;
57
+
58
+ }
59
+
60
+ /**
61
+ * Get all patterns to process and add them in the object
62
+ *
63
+ * @param $values
64
+ * @param $object
65
+ * @return mixed
66
+ */
67
+ public function processPatterns($values, $object)
68
+ {
69
+
70
+ //Foreach SQ, if has patterns, replace them
71
+ $sq_with_patterns = array();
72
+ //Set the Separator from object automation
73
+ //do not remove it from here
74
+ $this->patterns->sep = $object->sep;
75
+
76
+ if (!empty($values)) {
77
+ foreach ($values as $name => $value) {
78
+ if ($name <> '' && !is_array($value) && $value <> '') {
79
+
80
+ if (strpos($value, '%%') !== false) { //in case there are still patterns from Yoast
81
+ $value = preg_replace('/%%([^\%]+)%%/s', '{{$1}}', $value);
82
+ $object->$name = preg_replace('/%%([^\%]+)%%/s', '{{$1}}', $object->$name);
83
+ }
84
+
85
+ if (strpos($value, '%') !== false) { //in case there are still patterns from Rank Math
86
+ $value = preg_replace('/%([^\%]+)%/s', '{{$1}}', $value);
87
+ $object->$name = preg_replace('/%([^\%]+)%/s', '{{$1}}', $object->$name);
88
+ }
89
+
90
+ if(is_string($value) && $value <> '') {
91
+ if (strpos($value, '{{') !== false && strpos($value, '}}') !== false) {
92
+ $sq_with_patterns[$name] = $value;
93
+ }
94
+ }
95
+ }
96
+ }
97
+ if (!empty($sq_with_patterns)) {
98
+ foreach ($this->patterns->getPatterns() as $key => $pattern) {
99
+ foreach ($sq_with_patterns as $name => $value) {
100
+ if ($name <> '' && is_string($value) && $value <> '' && $pattern <> '') {
101
+ if (stripos($value, $pattern) !== false) {
102
+ $object->$name = str_ireplace($pattern, $this->patterns->$key, $object->$name);
103
+ }
104
+ }
105
+ }
106
+ }
107
+
108
+ }
109
+ }
110
+
111
+ return $object;
112
+ }
113
+
114
+ /**
115
+ * Called when Post action is triggered
116
+ *
117
+ * @return void
118
+ */
119
+ public function action()
120
+ {
121
+ parent::action();
122
+
123
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
124
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
125
+ SQ_Classes_Helpers_Tools::setHeader('json');
126
+ echo wp_json_encode($response);
127
+ exit();
128
+ }
129
+
130
+ switch (SQ_Classes_Helpers_Tools::getValue('action')) {
131
+ case 'sq_getpatterns':
132
+ $all_patterns = json_decode(SQ_ALL_PATTERNS, true);
133
+ $patterns = false;
134
+
135
+ $post_id = (int)SQ_Classes_Helpers_Tools::getValue('post_id', 0);
136
+ $term_id = (int)SQ_Classes_Helpers_Tools::getValue('term_id', 0);
137
+ $taxonomy = SQ_Classes_Helpers_Tools::getValue('taxonomy', 'category');
138
+ $post_type = SQ_Classes_Helpers_Tools::getValue('post_type', 'post');
139
+
140
+ if ($post = SQ_Classes_ObjController::getDomain('SQ_Models_Snippet')->getCurrentSnippet($post_id, $term_id, $taxonomy, $post_type)) {
141
+
142
+ $patterns = SQ_Classes_ObjController::getDomain('SQ_Models_Domain_Patterns', $post->toArray());
143
+ $patterns = $this->processPatterns(array_keys($all_patterns), $patterns);
144
+
145
+ //Set the separator character from post sep
146
+ $patterns->sep = $post->sq->sep;
147
+
148
+ foreach ($all_patterns as $pattern => $title) {
149
+ $name = preg_replace('/{{([^\}]+)}}/s', '$1', $pattern);
150
+ $all_patterns[$pattern] = array('value' => $patterns->$name, 'details' => $all_patterns[$pattern]);
151
+ }
152
+ }
153
+
154
+
155
+ if (SQ_Classes_Helpers_Tools::isAjax()) {
156
+ //return json with the results
157
+ SQ_Classes_Helpers_Tools::setHeader('json');
158
+
159
+ echo wp_json_encode(array('json' => wp_json_encode($all_patterns)));
160
+ exit();
161
+ }
162
+ break;
163
+
164
+ }
165
+ }
166
+
167
+
168
+ }
controllers/Post.php CHANGED
@@ -1,635 +1,658 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- class SQ_Controllers_Post extends SQ_Classes_FrontController {
5
-
6
- public $saved;
7
-
8
- public function init() {
9
- parent::init();
10
-
11
- if (is_rtl()) {
12
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('rtl');
13
- }
14
-
15
- //load the draggable script in post edit for the floating SLA
16
- wp_enqueue_script("jquery-ui-core");
17
- wp_enqueue_script("jquery-ui-draggable");
18
- }
19
-
20
- /**
21
- * Hook the post save
22
- */
23
- public function hookPost() {
24
- if (SQ_Classes_Helpers_Tools::getOption('sq_api') == '')
25
- return;
26
-
27
- //Hook and save the Snippet and Keywords for Attachment Pages
28
- add_action('wp_insert_attachment_data', array($this, 'hookAttachmentSave'), 12, 2);
29
-
30
- //if the option to save the images locally is activated
31
- if (SQ_Classes_Helpers_Tools::getOption('sq_local_images')) {
32
- add_filter('wp_insert_post_data', array($this, 'checkImage'), 13, 2);
33
- }
34
-
35
- //Remove the SLA highlight from post
36
- add_filter('wp_insert_post_data', array($this, 'removeHighlight'), 12, 2);
37
-
38
- //Hook the save post action
39
- add_action('save_post', array($this, 'hookSavePost'), 11, 2);
40
-
41
- //Hook the Move To Trash action
42
- add_action('wp_trash_post', array(SQ_Classes_ObjController::getClass('SQ_Models_PostsList'), 'hookUpdateStatus'));
43
-
44
- if (SQ_Classes_Helpers_Tools::getOption('sq_auto_sitemap')) {
45
- add_action('transition_post_status', array(SQ_Classes_ObjController::getClass('SQ_Controllers_Sitemaps'), 'refreshSitemap'), PHP_INT_MAX, 3);
46
- }
47
-
48
- //Check the compatibility with Woocommerce
49
- if (SQ_Classes_Helpers_Tools::getOption('sq_jsonld_product_custom')) {
50
- SQ_Classes_ObjController::getClass('SQ_Models_Compatibility')->checkWooCommerce();
51
- }
52
-
53
- //add compatibility for backend
54
- SQ_Classes_ObjController::getClass('SQ_Models_Compatibility')->hookPostEditorBackend();
55
-
56
- //Make sure the URL is local and not changed by other plugins
57
- add_filter('sq_homeurl', array($this, 'getHomeUrl'));
58
- }
59
-
60
- /**
61
- * Get the current Home URL
62
- * @param $url
63
- * @return mixed
64
- */
65
- public function getHomeUrl($url) {
66
- if (defined('WP_HOME')) {
67
- return WP_HOME;
68
- } else {
69
- return get_option('home');
70
- }
71
- }
72
-
73
- /**
74
- * Initialize the TinyMCE editor for the current use
75
- *
76
- * @return void
77
- */
78
- public function hookEditor() {
79
- $this->saved = array();
80
- }
81
-
82
- /**
83
- * Remove the Squirrly Highlights in case there are some left
84
- * @param array $post_data
85
- * @param array $postarr
86
- * @return array
87
- */
88
- public function removeHighlight($post_data, $postarr) {
89
-
90
- if (isset($post_data['post_type']) && $post_data['post_type'] <> '') {
91
- //Exclude types for SLA
92
- $excludes = SQ_Classes_Helpers_Tools::getOption('sq_sla_exclude_post_types');
93
- if (in_array($post_data['post_type'], $excludes)) {
94
- return $post_data;
95
- }
96
- }
97
-
98
- if (!isset($post_data['post_content']) || !isset($postarr['ID'])) {
99
- return $post_data;
100
- }
101
-
102
- if (strpos($post_data['post_content'], '<mark') !== false) {
103
- $post_data['post_content'] = preg_replace('/<mark[^>]*(data-markjs|mark_counter)[^>]*>([^<]*)<\/mark>/i', '$2', $post_data['post_content']);
104
- }
105
- return $post_data;
106
- }
107
-
108
- /**
109
- * Check if the image is a remote image and save it locally
110
- *
111
- * @param array $post_data
112
- * @param array $postarr
113
- * @return array
114
- */
115
- public function checkImage($post_data, $postarr) {
116
-
117
- if (!isset($post_data['post_content']) || !isset($postarr['ID'])) {
118
- return $post_data;
119
- }
120
-
121
- if (isset($post_data['post_type']) && $post_data['post_type'] <> '') {
122
- //Exclude types for SLA
123
- $excludes = SQ_Classes_Helpers_Tools::getOption('sq_sla_exclude_post_types');
124
- if (in_array($post_data['post_type'], $excludes)) {
125
- return $post_data;
126
- }
127
- }
128
-
129
- require_once(ABSPATH . 'wp-admin/includes/image.php');
130
-
131
- $urls = array();
132
- if (function_exists('preg_match_all')) {
133
- @preg_match_all('/<img[^>]*src=[\'"]([^\'"]+)[\'"][^>]*>/i', stripslashes($post_data['post_content']), $out);
134
-
135
- if (!empty($out)) {
136
- if (!is_array($out[1]) || count((array)$out[1]) == 0) {
137
- return $post_data;
138
- }
139
-
140
- if (get_bloginfo('wpurl') <> '') {
141
- $domain = parse_url(home_url(), PHP_URL_HOST);
142
-
143
- foreach ($out[1] as $row) {
144
- if (strpos($row, '//') !== false && strpos($row, $domain) === false) {
145
- if (!in_array($row, $urls)) {
146
- $urls[] = $row;
147
- }
148
- }
149
- }
150
- }
151
- }
152
- }
153
-
154
- if (!is_array($urls) || (is_array($urls) && count((array)$urls) == 0)) {
155
- return $post_data;
156
- }
157
-
158
- if (count((array)$urls) > 1) {
159
- $urls = array_unique($urls);
160
- }
161
-
162
- $time = microtime(true);
163
-
164
- //get the already downloaded images
165
- $images = get_post_meta((int)$postarr['ID'], '_sq_image_downloaded');
166
-
167
- foreach ($urls as $url) {
168
-
169
- //Set the title and filename
170
- $basename = md5(basename($url));
171
- $keyword = SQ_Classes_Helpers_Tools::getValue('sq_keyword', false);
172
- if ($keyword) {
173
- $title = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\[\]\\x80-\\xff ]|i', '', $keyword);
174
- $basename = preg_replace('|[^a-z0-9-_]|i', '', str_replace(' ', '-', strtolower($keyword)));
175
- }
176
-
177
- //check the images
178
- if (!empty($images)) {
179
- foreach ($images as $key => $local) {
180
- $local = json_decode($local, true);
181
- if ($local['url'] == md5($url)) {
182
-
183
- //replace the image in the content
184
- $post_data['post_content'] = str_replace($url, $local['file'], $post_data['post_content']);
185
-
186
- continue 2;
187
- }
188
- }
189
- }
190
-
191
- //Upload the image on server
192
- if ($file = $this->model->upload_image($url, $basename)) {
193
- if (!file_is_valid_image($file['file']))
194
- continue;
195
-
196
- $local_file = $file['url'];
197
- if ($local_file !== false) {
198
-
199
- //save as downloaded image to avoid duplicates
200
- add_post_meta((int)$postarr['ID'], '_sq_image_downloaded', wp_json_encode(array('url' => md5($url), 'file' => $local_file)));
201
-
202
- //replace the image in the content
203
- $post_data['post_content'] = str_replace($url, $local_file, $post_data['post_content']);
204
-
205
- //add the attachment image
206
- $attach_id = wp_insert_attachment(array(
207
- 'post_mime_type' => $file['type'],
208
- 'post_title' => $title,
209
- 'post_content' => '',
210
- 'post_status' => 'inherit',
211
- 'guid' => $local_file
212
- ), $file['file'], $postarr['ID']);
213
-
214
- $attach_data = wp_generate_attachment_metadata($attach_id, $file['file']);
215
- wp_update_attachment_metadata($attach_id, $attach_data);
216
-
217
- }
218
- }
219
-
220
- if (microtime(true) - $time >= 10) {
221
- break;
222
- }
223
-
224
- }
225
-
226
- return $post_data;
227
- }
228
-
229
- /**
230
- * Hook the Attachment save data
231
- * Don't use it for post save
232
- *
233
- * @param array $post_data
234
- * @param array $postarr
235
- * @return array
236
- */
237
- public function hookAttachmentSave($post_data, $postarr) {
238
-
239
- if (isset($postarr['ID']) && $post = get_post($postarr['ID'])) {
240
- //If the post is a new or edited post
241
- if (wp_is_post_autosave($post->ID) == '' &&
242
- get_post_status($post->ID) <> 'auto-draft' &&
243
- get_post_status($post->ID) <> 'inherit'
244
- ) {
245
-
246
- if ($post_data['post_type'] == 'attachment') {
247
- //Save the SEO
248
- SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->saveSEO($post->ID);
249
-
250
- //Send the optimization when attachment page
251
- $this->sendSeo($post);
252
- }
253
- }
254
- }
255
-
256
- return $post_data;
257
- }
258
-
259
- /**
260
- * Hook after save post to make sure the data is saved
261
- * @param $post_id
262
- */
263
- public function hookSavePost($post_id) {
264
-
265
- if ($post_id && $post = get_post($post_id)) {
266
- //If the post is a new or edited post
267
- if (wp_is_post_autosave($post->ID) == '' &&
268
- get_post_status($post->ID) <> 'auto-draft' &&
269
- get_post_status($post->ID) <> 'inherit'
270
- ) {
271
-
272
- //Update the SEO Keywords from Live Assistant and Permalink
273
- add_filter('sq_seo_before_save', array($this, 'addSeoKeywords'), 11, 1);
274
- //Update the redirect to old slugs
275
- add_filter('sq_url_before_save', array($this, 'checkOldSlugs'), 11, 2);
276
-
277
- //Save the SEO
278
- SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->saveSEO($post->ID);
279
-
280
- //Exclude types for SLA
281
- if (isset($post->post_type) && $post->post_type <> '') {
282
- $excludes = SQ_Classes_Helpers_Tools::getOption('sq_sla_exclude_post_types');
283
- if (in_array($post->post_type, $excludes)) {
284
- return;
285
- }
286
- }
287
-
288
- //Send the optimization when attachment page
289
- $this->sendSeo($post);
290
- }
291
- }
292
-
293
- }
294
-
295
- /**
296
- * Send the Post to Squirrly API
297
- * @param $post
298
- */
299
- public function sendSeo($post) {
300
- $args = array();
301
-
302
- $seo = SQ_Classes_Helpers_Tools::getValue('sq_seo', '');
303
-
304
- if (is_array($seo) && count((array)$seo) > 0) {
305
- $args['seo'] = implode(',', $seo);
306
- }
307
-
308
- $args['keyword'] = SQ_Classes_Helpers_Tools::getValue('sq_keyword', '');
309
- $args['status'] = $post->post_status;
310
- $args['permalink'] = get_permalink($post->ID);
311
- $args['author'] = $post->post_author;
312
- $args['post_id'] = $post->ID;
313
- $args['referer'] = 'edit';
314
-
315
- if ($args['permalink']) {
316
- SQ_Classes_RemoteController::savePost($args);
317
- }
318
-
319
- }
320
-
321
- /**
322
- * Called when Post action is triggered
323
- *
324
- * @return void
325
- */
326
- public function action() {
327
- parent::action();
328
- switch (SQ_Classes_Helpers_Tools::getValue('action')) {
329
- case 'sq_create_demo':
330
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
331
- SQ_Classes_Error::setError(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
332
- break;
333
- }
334
-
335
- $post_type = 'post';
336
- if (post_type_exists($post_type)) {
337
- $wp_filesystem = SQ_Classes_Helpers_Tools::initFilesystem();
338
-
339
- if ($wp_filesystem->exists(_SQ_ROOT_DIR_ . 'demo.json')) {
340
- $json = json_decode($wp_filesystem->get_contents(_SQ_ROOT_DIR_ . 'demo.json'));
341
-
342
- if (isset($json->demo->title) && isset($json->demo->content)) {
343
- $args = array();
344
- $args['s'] = '"' . addslashes($json->demo->title) . '"';
345
- $args['post_type'] = $post_type;
346
- //if the post doesn't exists already or is changed
347
- if (!$posts = SQ_Classes_ObjController::getClass('SQ_Models_Post')->searchPost($args)) {
348
-
349
- // Create post object
350
- $post = array(
351
- 'post_title' => $json->demo->title,
352
- 'post_content' => $json->demo->content,
353
- 'post_status' => 'draft',
354
- 'comment_status' => 'closed',
355
- 'ping_status' => 'closed',
356
- 'post_type' => $post_type,
357
- 'post_author' => get_current_user_id(),
358
- 'post_category' => array()
359
- );
360
-
361
- if ($post_id = wp_insert_post($post)) {
362
- if (!is_wp_error($post_id)) {
363
- wp_redirect(admin_url("post.php?post=" . $post_id . "&action=edit&post_type=" . $post_type . "&keyword=" . SQ_Classes_Helpers_Sanitize::escapeKeyword($json->demo->keyword, 'url')));
364
- exit();
365
-
366
- }
367
- }
368
- } else {
369
- foreach ($posts as $post) {
370
- wp_redirect(admin_url("post.php?post=" . $post->ID . "&action=edit&post_type=" . $post_type . "&keyword=" . SQ_Classes_Helpers_Sanitize::escapeKeyword($json->demo->keyword, 'url')));
371
- exit();
372
- }
373
- }
374
-
375
- }
376
- }
377
- }
378
- SQ_Classes_Error::setError(esc_html__("Could not add the demo post.", _SQ_PLUGIN_NAME_));
379
- break;
380
-
381
- /**************************** AJAX CALLS *************************/
382
- case 'sq_ajax_save_ogimage':
383
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
384
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
385
- SQ_Classes_Helpers_Tools::setHeader('json');
386
- echo wp_json_encode($response);
387
- exit();
388
- }
389
-
390
- if (!empty($_FILES['ogimage'])) {
391
- $return = $this->model->addImage($_FILES['ogimage']);
392
- }
393
- if (isset($return['file'])) {
394
- $return['filename'] = basename($return['file']);
395
- $local_file = str_replace($return['filename'], urlencode($return['filename']), $return['url']);
396
- $attach_id = wp_insert_attachment(array(
397
- 'post_mime_type' => $return['type'],
398
- 'post_title' => preg_replace('/\.[^.]+$/', '', $return['filename']),
399
- 'post_content' => '',
400
- 'post_status' => 'inherit',
401
- 'guid' => $local_file
402
- ), $return['file'], SQ_Classes_Helpers_Tools::getValue('post_id'));
403
-
404
- $attach_data = wp_generate_attachment_metadata($attach_id, $return['file']);
405
- wp_update_attachment_metadata($attach_id, $attach_data);
406
- }
407
- SQ_Classes_Helpers_Tools::setHeader('json');
408
-
409
- echo wp_json_encode($return);
410
- exit();
411
- case 'sq_ajax_save_post':
412
- SQ_Classes_Helpers_Tools::setHeader('json');
413
-
414
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
415
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
416
- echo wp_json_encode($response);
417
- exit();
418
- }
419
-
420
- $post_id = (int)SQ_Classes_Helpers_Tools::getValue('post_id');
421
- $referer = SQ_Classes_Helpers_Tools::getValue('referer', false);
422
-
423
- if ($post = SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->getCurrentSnippet($post_id)) {
424
-
425
- if (wp_is_post_autosave($post->ID) == '' &&
426
- get_post_status($post->ID) <> 'auto-draft' &&
427
- get_post_status($post->ID) <> 'inherit'
428
- ) {
429
-
430
- //Send the post optimization to Squirrly API
431
- $this->sendSeo($post);
432
-
433
- //save the reference for this post ID
434
- if ($referer) update_post_meta($post_id, '_sq_sla', $referer);
435
- }
436
-
437
- echo wp_json_encode($post->toArray());
438
- } else {
439
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("Can't get the post URL", _SQ_PLUGIN_NAME_), 'sq_error');
440
- SQ_Classes_Helpers_Tools::setHeader('json');
441
- echo wp_json_encode($response);
442
- }
443
-
444
- echo wp_json_encode(array());
445
- exit();
446
- case 'sq_ajax_get_post':
447
- SQ_Classes_Helpers_Tools::setHeader('json');
448
-
449
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
450
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
451
- echo wp_json_encode($response);
452
- exit();
453
- }
454
-
455
- $post_id = (int)SQ_Classes_Helpers_Tools::getValue('post_id');
456
-
457
- if ($post_id > 0) {
458
- if ($post = SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->getCurrentSnippet($post_id)) {
459
- if ($post->post_status <> 'publish') {
460
- $post->url = sanitize_title($post->post_title);
461
- }
462
- echo wp_json_encode($post->toArray());
463
- } else {
464
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("Can't get the post URL", _SQ_PLUGIN_NAME_), 'sq_error');
465
- SQ_Classes_Helpers_Tools::setHeader('json');
466
- echo wp_json_encode($response);
467
- }
468
- } else {
469
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("Invalid request", _SQ_PLUGIN_NAME_), 'sq_error');
470
- SQ_Classes_Helpers_Tools::setHeader('json');
471
- echo wp_json_encode($response);
472
- }
473
- exit();
474
- case 'sq_ajax_type_click':
475
- SQ_Classes_Helpers_Tools::saveOptions('sq_img_licence', SQ_Classes_Helpers_Tools::getValue('licence'));
476
- exit();
477
- case 'sq_ajax_search_blog':
478
- $args = array();
479
- $args['post_type'] = 'post';
480
- $args['post_status'] = 'publish';
481
-
482
- if (SQ_Classes_Helpers_Tools::getValue('exclude') && SQ_Classes_Helpers_Tools::getValue('exclude') <> 'undefined') {
483
- $args['post__not_in'] = array((int)SQ_Classes_Helpers_Tools::getValue('exclude'));
484
- }
485
- if (SQ_Classes_Helpers_Tools::getValue('start'))
486
- $args['start'] = array((int)SQ_Classes_Helpers_Tools::getValue('start'));
487
-
488
- if (SQ_Classes_Helpers_Tools::getValue('nrb'))
489
- $args['posts_per_page'] = (int)SQ_Classes_Helpers_Tools::getValue('nrb');
490
-
491
- if (SQ_Classes_Helpers_Tools::getValue('q') <> '')
492
- $args['s'] = SQ_Classes_Helpers_Tools::getValue('q');
493
-
494
- $responce = array();
495
- if ($posts = SQ_Classes_ObjController::getClass('SQ_Models_Post')->searchPost($args)) {
496
- foreach ($posts as $post) {
497
- $responce['results'][] = array('id' => $post->ID,
498
- 'url' => get_permalink($post->ID),
499
- 'title' => $post->post_title,
500
- 'content' => SQ_Classes_Helpers_Sanitize::truncate($post->post_content, 50),
501
- 'date' => $post->post_date_gmt);
502
- }
503
- }
504
-
505
- echo wp_json_encode($responce);
506
- exit();
507
- }
508
- }
509
-
510
- /**
511
- * Save the keywords from briefcase into the meta keywords if there are no keywords saved
512
- * @param SQ_Models_Domain_Sq $sq
513
- * @return SQ_Models_Domain_Sq
514
- */
515
- public function addSeoKeywords($sq) {
516
- if (empty($sq->keywords)) {
517
- $keywords = (array)SQ_Classes_Helpers_Tools::getValue('sq_briefcase_keyword', array());
518
-
519
- if (SQ_Classes_Helpers_Tools::getValue('sq_keyword', false)) {
520
- array_unshift($keywords, SQ_Classes_Helpers_Tools::getValue('sq_keyword'));
521
- }
522
-
523
- $keywords = array_filter($keywords);
524
- $keywords = array_unique($keywords);
525
- $sq->keywords = join(',', $keywords);
526
- }
527
-
528
- return $sq;
529
- }
530
-
531
- /**
532
- * Rewrite the function for pages and other post types
533
- *
534
- * @param string $url
535
- * @param string $sq_hash
536
- * @return string
537
- */
538
- public function checkOldSlugs($url, $sq_hash) {
539
-
540
- // Don't bother if it hasn't changed.
541
- $post = SQ_Classes_ObjController::getClass('SQ_Models_Qss')->getSqPost($sq_hash);
542
- $patterns = (array)SQ_Classes_Helpers_Tools::getOption('patterns');
543
-
544
- if (!isset($post->ID)) {
545
- return $url;
546
- }
547
-
548
- if (!empty($patterns) && $permalink = get_permalink($post->ID)) {
549
- if ($post->ID > 0 && get_post_status($post->ID) === 'publish' && $permalink <> $post->url) {
550
-
551
- //Get the Squirrly SEO Patterns
552
- foreach ($patterns as $pattern => $type) {
553
- if (get_post_type($post->ID) == $pattern) {
554
- if (isset($type['do_redirects']) && $type['do_redirects']) {
555
-
556
- //do_redirects
557
- $post_name = basename($post->url);
558
- $old_slugs = (array)get_post_meta($post->ID, '_sq_old_slug');
559
-
560
- // If we haven't added this old slug before, add it now.
561
- if (!empty($post_name) && !in_array($post_name, $old_slugs)) {
562
- add_post_meta($post->ID, '_sq_old_slug', $post_name);
563
- }
564
-
565
- // If the new slug was used previously, delete it from the list.
566
- if (in_array($post->post_name, $old_slugs)) {
567
- delete_post_meta($post->ID, '_sq_old_slug', $post->post_name);
568
- }
569
-
570
- }
571
- }
572
- }
573
-
574
- }
575
- }
576
-
577
- return get_permalink($post->ID);
578
- }
579
-
580
- /**
581
- * Load Squirrly Assistant in frontend
582
- */
583
- public function loadLiveAssistant() {
584
- //Load the Frontend Assistant for the current post
585
- if (SQ_Classes_Helpers_Tools::getOption('sq_sla_frontend')) {
586
-
587
- $elementor = (SQ_Classes_Helpers_Tools::getValue('action', false) == 'elementor');
588
-
589
- if (($elementor && is_admin())) {
590
- global $post;
591
-
592
- if (isset($post->ID) && isset($post->post_type)) {
593
- $types = get_post_types(array('public' => true));
594
-
595
- //Exclude types for SLA
596
- $excludes = SQ_Classes_Helpers_Tools::getOption('sq_sla_exclude_post_types');
597
- if (!empty($types) && !empty($excludes)) {
598
- foreach ($excludes as $exclude) {
599
- if (in_array($exclude, $types)) {
600
- unset($types[$exclude]);
601
- }
602
- }
603
- }
604
-
605
- if (in_array($post->post_type, (array)$types)) {
606
- //Load the assistant for frontend
607
- if (!wp_script_is('jquery')) {
608
- wp_enqueue_script('jquery');
609
- }
610
-
611
- SQ_Classes_ObjController::getClass('SQ_Classes_RemoteController');
612
- SQ_Classes_ObjController::getClass('SQ_Classes_ActionController')->hookHead();
613
-
614
- //Load post style in post edit
615
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('post');
616
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('fontawesome');
617
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('slaseo');
618
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('slasearch');
619
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('slaresearch');
620
-
621
- //load the draggable script in post edit for the floating SLA
622
- wp_enqueue_script("jquery-ui-core");
623
- wp_enqueue_script("jquery-ui-draggable");
624
-
625
- echo $this->getView('Frontend/Assistant');
626
- }
627
-
628
- }
629
- }
630
-
631
- }
632
- }
633
-
634
-
635
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ class SQ_Controllers_Post extends SQ_Classes_FrontController
5
+ {
6
+
7
+ public $saved;
8
+
9
+ public function init()
10
+ {
11
+ parent::init();
12
+
13
+ if (is_rtl()) {
14
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('rtl');
15
+ }
16
+
17
+ //load the draggable script in post edit for the floating SLA
18
+ wp_enqueue_script("jquery-ui-core");
19
+ wp_enqueue_script("jquery-ui-draggable");
20
+ }
21
+
22
+ /**
23
+ * Hook the post save
24
+ */
25
+ public function hookPost()
26
+ {
27
+ if (SQ_Classes_Helpers_Tools::getOption('sq_api') == '')
28
+ return;
29
+
30
+ //Hook and save the Snippet and Keywords for Attachment Pages
31
+ add_action('wp_insert_attachment_data', array($this, 'hookAttachmentSave'), 12, 2);
32
+
33
+ //if the option to save the images locally is activated
34
+ if (SQ_Classes_Helpers_Tools::getOption('sq_local_images')) {
35
+ add_filter('wp_insert_post_data', array($this, 'checkImage'), 13, 2);
36
+ }
37
+
38
+ //Remove the SLA highlight from post
39
+ add_filter('wp_insert_post_data', array($this, 'removeHighlight'), 12, 2);
40
+
41
+ //Hook the save post action
42
+ add_action('save_post', array($this, 'hookSavePost'), 11, 2);
43
+
44
+ //Hook the Move To Trash action
45
+ add_action('wp_trash_post', array(SQ_Classes_ObjController::getClass('SQ_Models_PostsList'), 'hookUpdateStatus'));
46
+
47
+ if (SQ_Classes_Helpers_Tools::getOption('sq_auto_sitemap')) {
48
+ add_action('transition_post_status', array(SQ_Classes_ObjController::getClass('SQ_Controllers_Sitemaps'), 'refreshSitemap'), PHP_INT_MAX, 3);
49
+ }
50
+
51
+ //Check the compatibility with Woocommerce
52
+ if (SQ_Classes_Helpers_Tools::getOption('sq_jsonld_product_custom')) {
53
+ SQ_Classes_ObjController::getClass('SQ_Models_Compatibility')->checkWooCommerce();
54
+ }
55
+
56
+ //add compatibility for backend
57
+ SQ_Classes_ObjController::getClass('SQ_Models_Compatibility')->hookPostEditorBackend();
58
+
59
+ //Make sure the URL is local and not changed by other plugins
60
+ add_filter('sq_homeurl', array($this, 'getHomeUrl'));
61
+ }
62
+
63
+ /**
64
+ * Get the current Home URL
65
+ *
66
+ * @param $url
67
+ * @return mixed
68
+ */
69
+ public function getHomeUrl($url)
70
+ {
71
+ if (defined('WP_HOME')) {
72
+ return WP_HOME;
73
+ } else {
74
+ return get_option('home');
75
+ }
76
+ }
77
+
78
+ /**
79
+ * Initialize the TinyMCE editor for the current use
80
+ *
81
+ * @return void
82
+ */
83
+ public function hookEditor()
84
+ {
85
+ $this->saved = array();
86
+ }
87
+
88
+ /**
89
+ * Remove the Squirrly Highlights in case there are some left
90
+ *
91
+ * @param array $post_data
92
+ * @param array $postarr
93
+ * @return array
94
+ */
95
+ public function removeHighlight($post_data, $postarr)
96
+ {
97
+
98
+ if (isset($post_data['post_type']) && $post_data['post_type'] <> '') {
99
+ //Exclude types for SLA
100
+ $excludes = SQ_Classes_Helpers_Tools::getOption('sq_sla_exclude_post_types');
101
+ if (in_array($post_data['post_type'], $excludes)) {
102
+ return $post_data;
103
+ }
104
+ }
105
+
106
+ if (!isset($post_data['post_content']) || !isset($postarr['ID'])) {
107
+ return $post_data;
108
+ }
109
+
110
+ if (strpos($post_data['post_content'], '<mark') !== false) {
111
+ $post_data['post_content'] = preg_replace('/<mark[^>]*(data-markjs|mark_counter)[^>]*>([^<]*)<\/mark>/i', '$2', $post_data['post_content']);
112
+ }
113
+ return $post_data;
114
+ }
115
+
116
+ /**
117
+ * Check if the image is a remote image and save it locally
118
+ *
119
+ * @param array $post_data
120
+ * @param array $postarr
121
+ * @return array
122
+ */
123
+ public function checkImage($post_data, $postarr)
124
+ {
125
+
126
+ if (!isset($post_data['post_content']) || !isset($postarr['ID'])) {
127
+ return $post_data;
128
+ }
129
+
130
+ if (isset($post_data['post_type']) && $post_data['post_type'] <> '') {
131
+ //Exclude types for SLA
132
+ $excludes = SQ_Classes_Helpers_Tools::getOption('sq_sla_exclude_post_types');
133
+ if (in_array($post_data['post_type'], $excludes)) {
134
+ return $post_data;
135
+ }
136
+ }
137
+
138
+ include_once ABSPATH . 'wp-admin/includes/image.php';
139
+
140
+ $urls = array();
141
+ if (function_exists('preg_match_all')) {
142
+ @preg_match_all('/<img[^>]*src=[\'"]([^\'"]+)[\'"][^>]*>/i', stripslashes($post_data['post_content']), $out);
143
+
144
+ if (!empty($out)) {
145
+ if (!is_array($out[1]) || count((array)$out[1]) == 0) {
146
+ return $post_data;
147
+ }
148
+
149
+ if (get_bloginfo('wpurl') <> '') {
150
+ $domain = parse_url(home_url(), PHP_URL_HOST);
151
+
152
+ foreach ($out[1] as $row) {
153
+ if (strpos($row, '//') !== false && strpos($row, $domain) === false) {
154
+ if (!in_array($row, $urls)) {
155
+ $urls[] = $row;
156
+ }
157
+ }
158
+ }
159
+ }
160
+ }
161
+ }
162
+
163
+ if (!is_array($urls) || (is_array($urls) && count((array)$urls) == 0)) {
164
+ return $post_data;
165
+ }
166
+
167
+ if (count((array)$urls) > 1) {
168
+ $urls = array_unique($urls);
169
+ }
170
+
171
+ $time = microtime(true);
172
+
173
+ //get the already downloaded images
174
+ $images = get_post_meta((int)$postarr['ID'], '_sq_image_downloaded');
175
+
176
+ foreach ($urls as $url) {
177
+
178
+ //Set the title and filename
179
+ $basename = md5(basename($url));
180
+ $keyword = SQ_Classes_Helpers_Tools::getValue('sq_keyword', false);
181
+ if ($keyword) {
182
+ $title = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\[\]\\x80-\\xff ]|i', '', $keyword);
183
+ $basename = preg_replace('|[^a-z0-9-_]|i', '', str_replace(' ', '-', strtolower($keyword)));
184
+ }
185
+
186
+ //check the images
187
+ if (!empty($images)) {
188
+ foreach ($images as $key => $local) {
189
+ $local = json_decode($local, true);
190
+ if ($local['url'] == md5($url)) {
191
+
192
+ //replace the image in the content
193
+ $post_data['post_content'] = str_replace($url, $local['file'], $post_data['post_content']);
194
+
195
+ continue 2;
196
+ }
197
+ }
198
+ }
199
+
200
+ //Upload the image on server
201
+ if ($file = $this->model->upload_image($url, $basename)) {
202
+ if (!file_is_valid_image($file['file']))
203
+ continue;
204
+
205
+ $local_file = $file['url'];
206
+ if ($local_file !== false) {
207
+
208
+ //save as downloaded image to avoid duplicates
209
+ add_post_meta((int)$postarr['ID'], '_sq_image_downloaded', wp_json_encode(array('url' => md5($url), 'file' => $local_file)));
210
+
211
+ //replace the image in the content
212
+ $post_data['post_content'] = str_replace($url, $local_file, $post_data['post_content']);
213
+
214
+ //add the attachment image
215
+ $attach_id = wp_insert_attachment(
216
+ array(
217
+ 'post_mime_type' => $file['type'],
218
+ 'post_title' => $title,
219
+ 'post_content' => '',
220
+ 'post_status' => 'inherit',
221
+ 'guid' => $local_file
222
+ ), $file['file'], $postarr['ID']
223
+ );
224
+
225
+ $attach_data = wp_generate_attachment_metadata($attach_id, $file['file']);
226
+ wp_update_attachment_metadata($attach_id, $attach_data);
227
+
228
+ }
229
+ }
230
+
231
+ if (microtime(true) - $time >= 10) {
232
+ break;
233
+ }
234
+
235
+ }
236
+
237
+ return $post_data;
238
+ }
239
+
240
+ /**
241
+ * Hook the Attachment save data
242
+ * Don't use it for post save
243
+ *
244
+ * @param array $post_data
245
+ * @param array $postarr
246
+ * @return array
247
+ */
248
+ public function hookAttachmentSave($post_data, $postarr)
249
+ {
250
+
251
+ if (isset($postarr['ID']) && $post = get_post($postarr['ID'])) {
252
+ //If the post is a new or edited post
253
+ if (wp_is_post_autosave($post->ID) == ''
254
+ && get_post_status($post->ID) <> 'auto-draft'
255
+ && get_post_status($post->ID) <> 'inherit'
256
+ ) {
257
+
258
+ if ($post_data['post_type'] == 'attachment') {
259
+ //Save the SEO
260
+ SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->saveSEO($post->ID);
261
+
262
+ //Send the optimization when attachment page
263
+ $this->sendSeo($post);
264
+ }
265
+ }
266
+ }
267
+
268
+ return $post_data;
269
+ }
270
+
271
+ /**
272
+ * Hook after save post to make sure the data is saved
273
+ *
274
+ * @param $post_id
275
+ */
276
+ public function hookSavePost($post_id)
277
+ {
278
+
279
+ if ($post_id && $post = get_post($post_id)) {
280
+ //If the post is a new or edited post
281
+ if (wp_is_post_autosave($post->ID) == ''
282
+ && get_post_status($post->ID) <> 'auto-draft'
283
+ && get_post_status($post->ID) <> 'inherit'
284
+ ) {
285
+
286
+ //Update the SEO Keywords from Live Assistant and Permalink
287
+ add_filter('sq_seo_before_save', array($this, 'addSeoKeywords'), 11, 1);
288
+ //Update the redirect to old slugs
289
+ add_filter('sq_url_before_save', array($this, 'checkOldSlugs'), 11, 2);
290
+
291
+ //Save the SEO
292
+ SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->saveSEO($post->ID);
293
+
294
+ //Exclude types for SLA
295
+ if (isset($post->post_type) && $post->post_type <> '') {
296
+ $excludes = SQ_Classes_Helpers_Tools::getOption('sq_sla_exclude_post_types');
297
+ if (in_array($post->post_type, $excludes)) {
298
+ return;
299
+ }
300
+ }
301
+
302
+ //Send the optimization when attachment page
303
+ $this->sendSeo($post);
304
+ }
305
+ }
306
+
307
+ }
308
+
309
+ /**
310
+ * Send the Post to Squirrly API
311
+ *
312
+ * @param $post
313
+ */
314
+ public function sendSeo($post)
315
+ {
316
+ $args = array();
317
+
318
+ $seo = SQ_Classes_Helpers_Tools::getValue('sq_seo', '');
319
+
320
+ if (is_array($seo) && count((array)$seo) > 0) {
321
+ $args['seo'] = implode(',', $seo);
322
+ }
323
+
324
+ $args['keyword'] = SQ_Classes_Helpers_Tools::getValue('sq_keyword', '');
325
+ $args['status'] = $post->post_status;
326
+ $args['permalink'] = get_permalink($post->ID);
327
+ $args['author'] = $post->post_author;
328
+ $args['post_id'] = $post->ID;
329
+ $args['referer'] = 'edit';
330
+
331
+ if ($args['permalink']) {
332
+ SQ_Classes_RemoteController::savePost($args);
333
+ }
334
+
335
+ }
336
+
337
+ /**
338
+ * Called when Post action is triggered
339
+ *
340
+ * @return void
341
+ */
342
+ public function action()
343
+ {
344
+ parent::action();
345
+ switch (SQ_Classes_Helpers_Tools::getValue('action')) {
346
+ case 'sq_create_demo':
347
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
348
+ SQ_Classes_Error::setError(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
349
+ break;
350
+ }
351
+
352
+ $post_type = 'post';
353
+ if (post_type_exists($post_type)) {
354
+ $wp_filesystem = SQ_Classes_Helpers_Tools::initFilesystem();
355
+
356
+ if ($wp_filesystem->exists(_SQ_ROOT_DIR_ . 'demo.json')) {
357
+ $json = json_decode($wp_filesystem->get_contents(_SQ_ROOT_DIR_ . 'demo.json'));
358
+
359
+ if (isset($json->demo->title) && isset($json->demo->content)) {
360
+ $args = array();
361
+ $args['s'] = '"' . addslashes($json->demo->title) . '"';
362
+ $args['post_type'] = $post_type;
363
+ //if the post doesn't exists already or is changed
364
+ if (!$posts = SQ_Classes_ObjController::getClass('SQ_Models_Post')->searchPost($args)) {
365
+
366
+ // Create post object
367
+ $post = array(
368
+ 'post_title' => $json->demo->title,
369
+ 'post_content' => $json->demo->content,
370
+ 'post_status' => 'draft',
371
+ 'comment_status' => 'closed',
372
+ 'ping_status' => 'closed',
373
+ 'post_type' => $post_type,
374
+ 'post_author' => get_current_user_id(),
375
+ 'post_category' => array()
376
+ );
377
+
378
+ if ($post_id = wp_insert_post($post)) {
379
+ if (!is_wp_error($post_id)) {
380
+ wp_redirect(admin_url("post.php?post=" . $post_id . "&action=edit&post_type=" . $post_type . "&keyword=" . SQ_Classes_Helpers_Sanitize::escapeKeyword($json->demo->keyword, 'url')));
381
+ exit();
382
+
383
+ }
384
+ }
385
+ } else {
386
+ foreach ($posts as $post) {
387
+ wp_redirect(admin_url("post.php?post=" . $post->ID . "&action=edit&post_type=" . $post_type . "&keyword=" . SQ_Classes_Helpers_Sanitize::escapeKeyword($json->demo->keyword, 'url')));
388
+ exit();
389
+ }
390
+ }
391
+
392
+ }
393
+ }
394
+ }
395
+ SQ_Classes_Error::setError(esc_html__("Could not add the demo post.", 'squirrly-seo'));
396
+ break;
397
+
398
+ /** AJAX CALLS ***/
399
+ case 'sq_ajax_save_ogimage':
400
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
401
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
402
+ SQ_Classes_Helpers_Tools::setHeader('json');
403
+ echo wp_json_encode($response);
404
+ exit();
405
+ }
406
+
407
+ if (!empty($_FILES['ogimage'])) {
408
+ $return = $this->model->addImage($_FILES['ogimage']);
409
+ }
410
+ if (isset($return['file'])) {
411
+ $return['filename'] = basename($return['file']);
412
+ $local_file = str_replace($return['filename'], urlencode($return['filename']), $return['url']);
413
+ $attach_id = wp_insert_attachment(
414
+ array(
415
+ 'post_mime_type' => $return['type'],
416
+ 'post_title' => preg_replace('/\.[^.]+$/', '', $return['filename']),
417
+ 'post_content' => '',
418
+ 'post_status' => 'inherit',
419
+ 'guid' => $local_file
420
+ ), $return['file'], SQ_Classes_Helpers_Tools::getValue('post_id')
421
+ );
422
+
423
+ $attach_data = wp_generate_attachment_metadata($attach_id, $return['file']);
424
+ wp_update_attachment_metadata($attach_id, $attach_data);
425
+ }
426
+ SQ_Classes_Helpers_Tools::setHeader('json');
427
+
428
+ echo wp_json_encode($return);
429
+ exit();
430
+ case 'sq_ajax_save_post':
431
+ SQ_Classes_Helpers_Tools::setHeader('json');
432
+
433
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
434
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
435
+ echo wp_json_encode($response);
436
+ exit();
437
+ }
438
+
439
+ $post_id = (int)SQ_Classes_Helpers_Tools::getValue('post_id');
440
+ $referer = SQ_Classes_Helpers_Tools::getValue('referer', false);
441
+
442
+ if ($post = SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->getCurrentSnippet($post_id)) {
443
+
444
+ if (wp_is_post_autosave($post->ID) == ''
445
+ && get_post_status($post->ID) <> 'auto-draft'
446
+ && get_post_status($post->ID) <> 'inherit'
447
+ ) {
448
+
449
+ //Send the post optimization to Squirrly API
450
+ $this->sendSeo($post);
451
+
452
+ //save the reference for this post ID
453
+ if ($referer) update_post_meta($post_id, '_sq_sla', $referer);
454
+ }
455
+
456
+ $response['data'] = array('data' => esc_html__("Saved", 'squirrly-seo'));
457
+ echo wp_json_encode($response);
458
+ } else {
459
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("Can't get the post URL", 'squirrly-seo'), 'sq_error');
460
+ SQ_Classes_Helpers_Tools::setHeader('json');
461
+ echo wp_json_encode($response);
462
+ }
463
+
464
+ exit();
465
+ case 'sq_ajax_get_post':
466
+ SQ_Classes_Helpers_Tools::setHeader('json');
467
+
468
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
469
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
470
+ echo wp_json_encode($response);
471
+ exit();
472
+ }
473
+
474
+ $post_id = (int)SQ_Classes_Helpers_Tools::getValue('post_id');
475
+
476
+ if ($post_id > 0) {
477
+ if ($post = SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->getCurrentSnippet($post_id)) {
478
+ if ($post->post_status <> 'publish') {
479
+ $post->url = sanitize_title($post->post_title);
480
+ }
481
+ echo wp_json_encode($post->toArray());
482
+ } else {
483
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("Can't get the post URL", 'squirrly-seo'), 'sq_error');
484
+ SQ_Classes_Helpers_Tools::setHeader('json');
485
+ echo wp_json_encode($response);
486
+ }
487
+ } else {
488
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("Invalid request", 'squirrly-seo'), 'sq_error');
489
+ SQ_Classes_Helpers_Tools::setHeader('json');
490
+ echo wp_json_encode($response);
491
+ }
492
+ exit();
493
+ case 'sq_ajax_type_click':
494
+ SQ_Classes_Helpers_Tools::saveOptions('sq_img_licence', SQ_Classes_Helpers_Tools::getValue('licence'));
495
+ exit();
496
+ case 'sq_ajax_search_blog':
497
+ $args = array();
498
+ $args['post_type'] = 'post';
499
+ $args['post_status'] = 'publish';
500
+
501
+ if (SQ_Classes_Helpers_Tools::getValue('exclude') && SQ_Classes_Helpers_Tools::getValue('exclude') <> 'undefined') {
502
+ $args['post__not_in'] = array((int)SQ_Classes_Helpers_Tools::getValue('exclude'));
503
+ }
504
+ if (SQ_Classes_Helpers_Tools::getValue('start'))
505
+ $args['start'] = array((int)SQ_Classes_Helpers_Tools::getValue('start'));
506
+
507
+ if (SQ_Classes_Helpers_Tools::getValue('nrb'))
508
+ $args['posts_per_page'] = (int)SQ_Classes_Helpers_Tools::getValue('nrb');
509
+
510
+ if (SQ_Classes_Helpers_Tools::getValue('q') <> '')
511
+ $args['s'] = SQ_Classes_Helpers_Tools::getValue('q');
512
+
513
+ $responce = array();
514
+ if ($posts = SQ_Classes_ObjController::getClass('SQ_Models_Post')->searchPost($args)) {
515
+ foreach ($posts as $post) {
516
+ $responce['results'][] = array('id' => $post->ID,
517
+ 'url' => get_permalink($post->ID),
518
+ 'title' => $post->post_title,
519
+ 'content' => SQ_Classes_Helpers_Sanitize::truncate($post->post_content, 50),
520
+ 'date' => $post->post_date_gmt);
521
+ }
522
+ }
523
+
524
+ echo wp_json_encode($responce);
525
+ exit();
526
+ }
527
+ }
528
+
529
+ /**
530
+ * Save the keywords from briefcase into the meta keywords if there are no keywords saved
531
+ *
532
+ * @param SQ_Models_Domain_Sq $sq
533
+ * @return SQ_Models_Domain_Sq
534
+ */
535
+ public function addSeoKeywords($sq)
536
+ {
537
+ if (empty($sq->keywords)) {
538
+ $keywords = (array)SQ_Classes_Helpers_Tools::getValue('sq_briefcase_keyword', array());
539
+
540
+ if (SQ_Classes_Helpers_Tools::getValue('sq_keyword', false)) {
541
+ array_unshift($keywords, SQ_Classes_Helpers_Tools::getValue('sq_keyword'));
542
+ }
543
+
544
+ $keywords = array_filter($keywords);
545
+ $keywords = array_unique($keywords);
546
+ $sq->keywords = join(',', $keywords);
547
+ }
548
+
549
+ return $sq;
550
+ }
551
+
552
+ /**
553
+ * Rewrite the function for pages and other post types
554
+ *
555
+ * @param string $url
556
+ * @param string $sq_hash
557
+ * @return string
558
+ */
559
+ public function checkOldSlugs($url, $sq_hash)
560
+ {
561
+
562
+ // Don't bother if it hasn't changed.
563
+ $post = SQ_Classes_ObjController::getClass('SQ_Models_Qss')->getSqPost($sq_hash);
564
+ $patterns = (array)SQ_Classes_Helpers_Tools::getOption('patterns');
565
+
566
+ if (!isset($post->ID)) {
567
+ return $url;
568
+ }
569
+
570
+ if (!empty($patterns) && $permalink = get_permalink($post->ID)) {
571
+ if ($post->ID > 0 && get_post_status($post->ID) === 'publish' && $permalink <> $post->url) {
572
+
573
+ //Get the Squirrly SEO Patterns
574
+ foreach ($patterns as $pattern => $type) {
575
+ if (get_post_type($post->ID) == $pattern) {
576
+ if (isset($type['do_redirects']) && $type['do_redirects']) {
577
+
578
+ //do_redirects
579
+ $post_name = basename($post->url);
580
+ $old_slugs = (array)get_post_meta($post->ID, '_sq_old_slug');
581
+
582
+ // If we haven't added this old slug before, add it now.
583
+ if (!empty($post_name) && !in_array($post_name, $old_slugs)) {
584
+ add_post_meta($post->ID, '_sq_old_slug', $post_name);
585
+ }
586
+
587
+ // If the new slug was used previously, delete it from the list.
588
+ if (in_array($post->post_name, $old_slugs)) {
589
+ delete_post_meta($post->ID, '_sq_old_slug', $post->post_name);
590
+ }
591
+
592
+ }
593
+ }
594
+ }
595
+
596
+ }
597
+ }
598
+
599
+ return get_permalink($post->ID);
600
+ }
601
+
602
+ /**
603
+ * Load Squirrly Assistant in frontend
604
+ */
605
+ public function loadLiveAssistant()
606
+ {
607
+ //Load the Frontend Assistant for the current post
608
+ if (SQ_Classes_Helpers_Tools::getOption('sq_sla_frontend')) {
609
+
610
+ $elementor = (SQ_Classes_Helpers_Tools::getValue('action', false) == 'elementor');
611
+
612
+ if (($elementor && is_admin())) {
613
+ global $post;
614
+
615
+ if (isset($post->ID) && isset($post->post_type)) {
616
+ $types = get_post_types(array('public' => true));
617
+
618
+ //Exclude types for SLA
619
+ $excludes = SQ_Classes_Helpers_Tools::getOption('sq_sla_exclude_post_types');
620
+ if (!empty($types) && !empty($excludes)) {
621
+ foreach ($excludes as $exclude) {
622
+ if (in_array($exclude, $types)) {
623
+ unset($types[$exclude]);
624
+ }
625
+ }
626
+ }
627
+
628
+ if (in_array($post->post_type, (array)$types)) {
629
+ //Load the assistant for frontend
630
+ if (!wp_script_is('jquery')) {
631
+ wp_enqueue_script('jquery');
632
+ }
633
+
634
+ SQ_Classes_ObjController::getClass('SQ_Classes_RemoteController');
635
+ SQ_Classes_ObjController::getClass('SQ_Classes_ActionController')->hookHead();
636
+
637
+ //Load post style in post edit
638
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('post');
639
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('fontawesome');
640
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('slaseo');
641
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('slasearch');
642
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('slaresearch');
643
+
644
+ //load the draggable script in post edit for the floating SLA
645
+ wp_enqueue_script("jquery-ui-core");
646
+ wp_enqueue_script("jquery-ui-draggable");
647
+
648
+ $this->show_view('Frontend/Assistant');
649
+ }
650
+
651
+ }
652
+ }
653
+
654
+ }
655
+ }
656
+
657
+
658
+ }
controllers/PostsList.php CHANGED
@@ -1,307 +1,333 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- class SQ_Controllers_PostsList extends SQ_Classes_FrontController {
5
-
6
- /** @var array Post Type in */
7
- private $_types = array();
8
- private $_taxonomies = array();
9
-
10
- /** @var integer Set the column index for Squirrly */
11
- private $_pos = 5;
12
-
13
- /** @var string Set the column name for Squirrly */
14
- private $_slacolumn_id = 'sq_slacolumn';
15
- private $_column_id = 'sq_column';
16
-
17
- /** @var array list of the posts to load the optimization for */
18
- public $posts = array();
19
-
20
-
21
- /**
22
- * Create the column and filter for the Posts List
23
- *
24
- */
25
- public function init() {
26
- $this->_types = get_post_types(array('public' => true));
27
- SQ_Classes_ObjController::getClass('SQ_Models_BulkSeo')->init();
28
-
29
- array_push($this->_types, 'posts');
30
- array_push($this->_types, 'pages');
31
- array_push($this->_types, 'media');
32
-
33
- //Exclude types for SLA
34
- $excludes = SQ_Classes_Helpers_Tools::getOption('sq_sla_exclude_post_types');
35
-
36
- if (!empty($this->_types) && !empty($excludes)) {
37
- foreach ($excludes as $exclude) {
38
- if ($exclude) {
39
- if (false !== $key = array_search($exclude, $this->_types)) {
40
- unset($this->_types[$key]);
41
- }
42
- if (false !== $key = array_search($exclude . 's', $this->_types)) {
43
- unset($this->_types[$key]);
44
- }
45
- }
46
- }
47
- }
48
-
49
- $this->_taxonomies = get_taxonomies(array('public' => true));
50
-
51
- if (SQ_Classes_Helpers_Tools::getOption('sq_api') == '') {
52
- return;
53
- }
54
-
55
- if (!apply_filters('sq_load_snippet', true) || !SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
56
- return;
57
- }
58
-
59
- foreach ($this->_types as $type) {
60
- add_filter('manage_' . $type . '_columns', array($this, 'add_post_column'), 10, 1);
61
- add_action('manage_' . $type . '_custom_column', array($this, 'add_post_row'), 10, 2);
62
- }
63
-
64
- foreach ($this->_taxonomies as $taxonomy) {
65
- add_filter('manage_edit-' . $taxonomy . '_columns', array($this, 'add_tax_column'), 10, 1);
66
- add_action('manage_' . $taxonomy . '_custom_column', array($this, 'add_tax_row'), 10, 3);
67
- }
68
-
69
- //Update post status on API
70
- add_action('before_delete_post', array($this->model, 'hookUpdateStatus'), 10, 1);
71
- add_action('untrashed_post', array($this->model, 'hookUpdateStatus'), 10, 1);
72
- add_action('trashed_post', array($this->model, 'hookUpdateStatus'), 10, 1);
73
-
74
- }
75
-
76
- /**
77
- * Hook the Wordpress header only on postslist header table
78
- */
79
- public function loadHead() {
80
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('postslist');
81
- }
82
-
83
- /**
84
- * Add the Squirrly column in the Post List
85
- *
86
- * @param array $columns
87
- * @return array
88
- */
89
- public function add_post_column($columns) {
90
- $this->loadHead(); //load the js only for post list
91
-
92
- $columns = $this->insert($columns, array($this->_column_id => esc_html__("SQ Snippet", _SQ_PLUGIN_NAME_)), $this->_pos);
93
- $columns = $this->insert($columns, array($this->_slacolumn_id => esc_html__("Optimized", _SQ_PLUGIN_NAME_)), $this->_pos);
94
-
95
- return $columns;
96
- }
97
-
98
- /**
99
- * Add row in Post list
100
- *
101
- * @param object $column
102
- * @param integer $post_id
103
- */
104
- public function add_post_row($column, $post_id) {
105
- if (!$post_type = get_post_type($post_id)) {
106
- $post_type = 'post';
107
- }
108
-
109
- if(!SQ_Classes_Helpers_Tools::userCan('edit_post', $post_id)){
110
- return;
111
- }
112
-
113
- if ($column == $this->_slacolumn_id) {
114
- $html = false;
115
- if (SQ_Classes_Helpers_Tools::isAjax()) {
116
- $args = array();
117
- $args['posts'] = $post_id;
118
-
119
- if ($json = SQ_Classes_RemoteController::getPostOptimization($args)) {
120
- if (!is_wp_error($json)) {
121
- $posts = $this->model->processPost($json, $post_type);
122
- $html = $posts[$post_id];
123
- }
124
- }
125
- } else {
126
- if (get_post_status($post_id) == 'publish')
127
- array_push($this->posts, $post_id);
128
- }
129
-
130
- echo '<div class="' . $this->_slacolumn_id . '_row" ref="' . $post_id . '">' . (($html) ? $html : 'loading ...') . '</div>';
131
- }
132
-
133
- if ($column == $this->_column_id) {
134
- echo '<div class="' . $this->_column_id . '_row">' . $this->model->getPostButton($post_id, $post_type) . '</div>';
135
- }
136
- }
137
-
138
- /**
139
- * Add the Squirrly column in the Post List
140
- *
141
- * @param array $columns
142
- * @return array
143
- */
144
- public function add_tax_column($columns) {
145
- $this->loadHead(); //load the js only for post list
146
-
147
- $columns = $this->insert($columns, array($this->_column_id => esc_html__("SQ Snippet", _SQ_PLUGIN_NAME_)), $this->_pos);
148
- return $columns;
149
- }
150
-
151
- /**
152
- * Add row in Categories and Tags
153
- *
154
- * @param string $html
155
- * @param object $column
156
- * @param integer $post_id
157
- */
158
- public function add_tax_row($html = '', $column = 0, $tax_id = 0) {
159
- if ((int)$tax_id > 0 && (int)$column > 0) {
160
- $term = get_term($tax_id);
161
-
162
- if (!is_wp_error($term) && $column == $this->_column_id) {
163
- return '<div class="' . $this->_column_id . '_row">' . $this->model->getTaxButton($term->term_id, 'tax-' . $term->taxonomy) . '</div>';
164
- }
165
- }
166
-
167
- return $html;
168
- }
169
-
170
- /**
171
- * Push the array to a specific index
172
- * @param array $src
173
- * @param array $in
174
- * @param integer $pos
175
- * @return array
176
- */
177
- public function insert($src, $in, $pos) {
178
- $array = array();
179
- if (is_int($pos))
180
- $array = array_merge(array_slice($src, 0, $pos), $in, array_slice($src, $pos));
181
- else {
182
- foreach ($src as $k => $v) {
183
- if ($k == $pos)
184
- $array = array_merge($array, $in);
185
- $array[$k] = $v;
186
- }
187
- }
188
- return $array;
189
- }
190
-
191
- /**
192
- * Hook Get/Post action
193
- * @return void
194
- */
195
- public function action() {
196
- switch (SQ_Classes_Helpers_Tools::getValue('action')) {
197
- case 'inline-save':
198
-
199
- if (isset($_POST['post_ID']) && ($post_id = (int)$_POST['post_ID']) && isset($_POST['_status']) && $_POST['_status'] == 'publish') {
200
-
201
- // Don't bother if it hasn't changed.
202
- $sq_hash = md5($post_id);
203
- $post = SQ_Classes_ObjController::getClass('SQ_Models_Qss')->getSqPost($sq_hash);
204
- $patterns = (array)SQ_Classes_Helpers_Tools::getOption('patterns');
205
- if (!empty($patterns) && $permalink = get_permalink($post->ID)) {
206
-
207
- if ($post->ID > 0 && $permalink <> $post->url) {
208
-
209
- //Get the Squirrly SEO Patterns
210
- foreach ($patterns as $pattern => $type) {
211
- if (get_post_type($post->ID) == $pattern) {
212
- if (isset($type['do_redirects']) && $type['do_redirects']) {
213
-
214
- //do_redirects
215
- $post_name = basename($post->url);
216
- $old_slugs = (array)get_post_meta($post->ID, '_sq_old_slug');
217
-
218
- // If we haven't added this old slug before, add it now.
219
- if (!empty($post_name) && !in_array($post_name, $old_slugs)) {
220
- add_post_meta($post->ID, '_sq_old_slug', $post_name);
221
- }
222
-
223
- // If the new slug was used previously, delete it from the list.
224
- if (in_array($post->post_name, $old_slugs)) {
225
- delete_post_meta($post->ID, '_sq_old_slug', $post->post_name);
226
- }
227
-
228
- //Update the permalink in QSS
229
- SQ_Classes_ObjController::getClass('SQ_Models_Qss')->savePermalink($permalink, $sq_hash);
230
-
231
- }
232
- }
233
- }
234
-
235
- }
236
- }
237
-
238
- }
239
- return;
240
- }
241
-
242
- parent::action();
243
- switch (SQ_Classes_Helpers_Tools::getValue('action')) {
244
- case 'sq_ajax_postslist':
245
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
246
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
247
- SQ_Classes_Helpers_Tools::setHeader('json');
248
- echo wp_json_encode($response);
249
- exit();
250
- }
251
-
252
- SQ_Classes_Helpers_Tools::setHeader('json');
253
- $args = array();
254
- $posts = SQ_Classes_Helpers_Tools::getValue('posts');
255
- if (is_array($posts) && !empty($posts)) {
256
- $post_type = SQ_Classes_Helpers_Tools::getValue('post_type', 'post');
257
- $args['posts'] = join(',', SQ_Classes_Helpers_Tools::getValue('posts', array()));
258
-
259
- if ($json = SQ_Classes_RemoteController::getPostOptimization($args)) {
260
- if (is_wp_error($json)) {
261
- $array = array();
262
- if ($json->get_error_message() == 'no_data') {
263
- foreach ($posts as $post_id) {
264
- $array[$post_id] = esc_html__("Network Error. Please Refresh.", _SQ_PLUGIN_NAME_);
265
- }
266
- } elseif ($json->get_error_message() == 'maintenance') {
267
- foreach ($posts as $post_id) {
268
- $array[$post_id] = sprintf(esc_html__("Maintenance. %sWe'll be back in a minute.", _SQ_PLUGIN_NAME_), '<br />');
269
- }
270
- }
271
-
272
- echo wp_json_encode(array('posts' => $array));
273
- } else {
274
- $posts = $this->model->processPost($json, $post_type);
275
- echo wp_json_encode(array('posts' => $posts));
276
- }
277
-
278
- exit();
279
- }
280
- }
281
- echo wp_json_encode(array('posts' => array()));
282
- exit();
283
- }
284
- }
285
-
286
- /**
287
- * Hook the Footer
288
- *
289
- */
290
- public function hookFooter() {
291
- $posts = '';
292
- foreach ($this->posts as $post) {
293
- $posts .= '"' . $post . '",';
294
- }
295
-
296
- if (strlen($posts) > 0) $posts = substr($posts, 0, strlen($posts) - 1);
297
-
298
- echo '<script>
299
- var __sq_ranknotpublic_text = "' . esc_html__("Not Public", _SQ_PLUGIN_NAME_) . '";
300
- var __sq_couldnotprocess_text = "' . esc_html__("Could not process", _SQ_PLUGIN_NAME_) . '";
301
- var __sq_subscriptionexpired_text = "' . esc_html__("The Squirrly subscription has expired!", _SQ_PLUGIN_NAME_) . '";
302
- var sq_posts = new Array(' . $posts . ');
303
- </script>';
304
-
305
- }
306
-
307
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ class SQ_Controllers_PostsList extends SQ_Classes_FrontController
5
+ {
6
+
7
+ /**
8
+ *
9
+ *
10
+ * @var array Post Type in
11
+ */
12
+ private $_types = array();
13
+ private $_taxonomies = array();
14
+
15
+ /**
16
+ *
17
+ *
18
+ * @var integer Set the column index for Squirrly
19
+ */
20
+ private $_pos = 5;
21
+
22
+ /**
23
+ *
24
+ *
25
+ * @var string Set the column name for Squirrly
26
+ */
27
+ private $_slacolumn_id = 'sq_slacolumn';
28
+ private $_column_id = 'sq_column';
29
+
30
+ /**
31
+ *
32
+ *
33
+ * @var array list of the posts to load the optimization for
34
+ */
35
+ public $posts = array();
36
+
37
+
38
+ /**
39
+ * Create the column and filter for the Posts List
40
+ */
41
+ public function init()
42
+ {
43
+ $this->_types = get_post_types(array('public' => true));
44
+ SQ_Classes_ObjController::getClass('SQ_Models_BulkSeo')->init();
45
+
46
+ array_push($this->_types, 'posts');
47
+ array_push($this->_types, 'pages');
48
+ array_push($this->_types, 'media');
49
+
50
+ //Exclude types for SLA
51
+ $excludes = SQ_Classes_Helpers_Tools::getOption('sq_sla_exclude_post_types');
52
+
53
+ if (!empty($this->_types) && !empty($excludes)) {
54
+ foreach ($excludes as $exclude) {
55
+ if ($exclude) {
56
+ if (false !== $key = array_search($exclude, $this->_types)) {
57
+ unset($this->_types[$key]);
58
+ }
59
+ if (false !== $key = array_search($exclude . 's', $this->_types)) {
60
+ unset($this->_types[$key]);
61
+ }
62
+ }
63
+ }
64
+ }
65
+
66
+ $this->_taxonomies = get_taxonomies(array('public' => true));
67
+
68
+ if (SQ_Classes_Helpers_Tools::getOption('sq_api') == '') {
69
+ return;
70
+ }
71
+
72
+ if (!apply_filters('sq_load_snippet', true) || !SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
73
+ return;
74
+ }
75
+
76
+ foreach ($this->_types as $type) {
77
+ add_filter('manage_' . $type . '_columns', array($this, 'add_post_column'), 10, 1);
78
+ add_action('manage_' . $type . '_custom_column', array($this, 'add_post_row'), 10, 2);
79
+ }
80
+
81
+ foreach ($this->_taxonomies as $taxonomy) {
82
+ add_filter('manage_edit-' . $taxonomy . '_columns', array($this, 'add_tax_column'), 10, 1);
83
+ add_action('manage_' . $taxonomy . '_custom_column', array($this, 'add_tax_row'), 10, 3);
84
+ }
85
+
86
+ //Update post status on API
87
+ add_action('before_delete_post', array($this->model, 'hookUpdateStatus'), 10, 1);
88
+ add_action('untrashed_post', array($this->model, 'hookUpdateStatus'), 10, 1);
89
+ add_action('trashed_post', array($this->model, 'hookUpdateStatus'), 10, 1);
90
+
91
+ }
92
+
93
+ /**
94
+ * Hook the Wordpress header only on postslist header table
95
+ */
96
+ public function loadHead()
97
+ {
98
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('postslist');
99
+ }
100
+
101
+ /**
102
+ * Add the Squirrly column in the Post List
103
+ *
104
+ * @param array $columns
105
+ * @return array
106
+ */
107
+ public function add_post_column($columns)
108
+ {
109
+ $this->loadHead(); //load the js only for post list
110
+
111
+ //$columns = $this->insert($columns, array($this->_column_id => esc_html__("SQ Snippet", 'squirrly-seo')), $this->_pos);
112
+ $columns = $this->insert($columns, array($this->_slacolumn_id => esc_html__("Optimized", 'squirrly-seo')), $this->_pos);
113
+
114
+ return $columns;
115
+ }
116
+
117
+ /**
118
+ * Add row in Post list
119
+ *
120
+ * @param object $column
121
+ * @param integer $post_id
122
+ */
123
+ public function add_post_row($column, $post_id)
124
+ {
125
+ if (!$post_type = get_post_type($post_id)) {
126
+ $post_type = 'post';
127
+ }
128
+
129
+ if(!SQ_Classes_Helpers_Tools::userCan('edit_post', $post_id)) {
130
+ return;
131
+ }
132
+
133
+ if ($column == $this->_slacolumn_id) {
134
+ $html = false;
135
+ if (SQ_Classes_Helpers_Tools::isAjax()) {
136
+ $args = array();
137
+ $args['posts'] = $post_id;
138
+
139
+ if ($json = SQ_Classes_RemoteController::getPostOptimization($args)) {
140
+ if (!is_wp_error($json)) {
141
+ $posts = $this->model->processPost($json, $post_type);
142
+ $html = $posts[$post_id];
143
+ }
144
+ }
145
+ } else {
146
+ if (get_post_status($post_id) == 'publish')
147
+ array_push($this->posts, $post_id);
148
+ }
149
+
150
+ echo '<div class="' . esc_attr($this->_slacolumn_id) . '_row" ref="' . esc_attr($post_id) . '">' . (($html) ? wp_kses_post($html) : 'loading ...') . '</div>';
151
+ }
152
+
153
+ // if ($column == $this->_column_id) {
154
+ // echo '<div class="' . (int)$this->_column_id . '_row">' . $this->model->getPostButton($post_id, $post_type) . '</div>';
155
+ // }
156
+ }
157
+
158
+ /**
159
+ * Add the Squirrly column in the Post List
160
+ *
161
+ * @param array $columns
162
+ * @return array
163
+ */
164
+ public function add_tax_column($columns)
165
+ {
166
+ $this->loadHead(); //load the js only for post list
167
+
168
+ $columns = $this->insert($columns, array($this->_column_id => esc_html__("SQ Snippet", 'squirrly-seo')), $this->_pos);
169
+ return $columns;
170
+ }
171
+
172
+ /**
173
+ * Add row in Categories and Tags
174
+ *
175
+ * @param string $html
176
+ * @param object $column
177
+ * @param integer $post_id
178
+ */
179
+ public function add_tax_row($html = '', $column = 0, $tax_id = 0)
180
+ {
181
+ if ((int)$tax_id > 0 && (int)$column > 0) {
182
+ $term = get_term($tax_id);
183
+
184
+ if (!is_wp_error($term) && $column == $this->_column_id) {
185
+ return '<div class="' . $this->_column_id . '_row">' . $this->model->getTaxButton($term->term_id, 'tax-' . $term->taxonomy) . '</div>';
186
+ }
187
+ }
188
+
189
+ return $html;
190
+ }
191
+
192
+ /**
193
+ * Push the array to a specific index
194
+ *
195
+ * @param array $src
196
+ * @param array $in
197
+ * @param integer $pos
198
+ * @return array
199
+ */
200
+ public function insert($src, $in, $pos)
201
+ {
202
+ $array = array();
203
+ if (is_int($pos))
204
+ $array = array_merge(array_slice($src, 0, $pos), $in, array_slice($src, $pos));
205
+ else {
206
+ foreach ($src as $k => $v) {
207
+ if ($k == $pos)
208
+ $array = array_merge($array, $in);
209
+ $array[$k] = $v;
210
+ }
211
+ }
212
+ return $array;
213
+ }
214
+
215
+ /**
216
+ * Hook Get/Post action
217
+ *
218
+ * @return void
219
+ */
220
+ public function action()
221
+ {
222
+ switch (SQ_Classes_Helpers_Tools::getValue('action')) {
223
+ case 'inline-save':
224
+
225
+ if (isset($_POST['post_ID']) && ($post_id = (int)$_POST['post_ID']) && isset($_POST['_status']) && $_POST['_status'] == 'publish') {
226
+
227
+ // Don't bother if it hasn't changed.
228
+ $sq_hash = md5($post_id);
229
+ $post = SQ_Classes_ObjController::getClass('SQ_Models_Qss')->getSqPost($sq_hash);
230
+ $patterns = (array)SQ_Classes_Helpers_Tools::getOption('patterns');
231
+ if (!empty($patterns) && $permalink = get_permalink($post->ID)) {
232
+
233
+ if ($post->ID > 0 && $permalink <> $post->url) {
234
+
235
+ //Get the Squirrly SEO Patterns
236
+ foreach ($patterns as $pattern => $type) {
237
+ if (get_post_type($post->ID) == $pattern) {
238
+ if (isset($type['do_redirects']) && $type['do_redirects']) {
239
+
240
+ //do_redirects
241
+ $post_name = basename($post->url);
242
+ $old_slugs = (array)get_post_meta($post->ID, '_sq_old_slug');
243
+
244
+ // If we haven't added this old slug before, add it now.
245
+ if (!empty($post_name) && !in_array($post_name, $old_slugs)) {
246
+ add_post_meta($post->ID, '_sq_old_slug', $post_name);
247
+ }
248
+
249
+ // If the new slug was used previously, delete it from the list.
250
+ if (in_array($post->post_name, $old_slugs)) {
251
+ delete_post_meta($post->ID, '_sq_old_slug', $post->post_name);
252
+ }
253
+
254
+ //Update the permalink in QSS
255
+ SQ_Classes_ObjController::getClass('SQ_Models_Qss')->savePermalink($permalink, $sq_hash);
256
+
257
+ }
258
+ }
259
+ }
260
+
261
+ }
262
+ }
263
+
264
+ }
265
+ return;
266
+ }
267
+
268
+ parent::action();
269
+ switch (SQ_Classes_Helpers_Tools::getValue('action')) {
270
+ case 'sq_ajax_postslist':
271
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
272
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
273
+ SQ_Classes_Helpers_Tools::setHeader('json');
274
+ echo wp_json_encode($response);
275
+ exit();
276
+ }
277
+
278
+ SQ_Classes_Helpers_Tools::setHeader('json');
279
+ $args = array();
280
+ $posts = SQ_Classes_Helpers_Tools::getValue('posts');
281
+ if (is_array($posts) && !empty($posts)) {
282
+ $post_type = SQ_Classes_Helpers_Tools::getValue('post_type', 'post');
283
+ $args['posts'] = join(',', SQ_Classes_Helpers_Tools::getValue('posts', array()));
284
+
285
+ if ($json = SQ_Classes_RemoteController::getPostOptimization($args)) {
286
+ if (is_wp_error($json)) {
287
+ $array = array();
288
+ if ($json->get_error_message() == 'no_data') {
289
+ foreach ($posts as $post_id) {
290
+ $array[$post_id] = esc_html__("Network Error. Please Refresh.", 'squirrly-seo');
291
+ }
292
+ } elseif ($json->get_error_message() == 'maintenance') {
293
+ foreach ($posts as $post_id) {
294
+ $array[$post_id] = sprintf(esc_html__("Maintenance. %sWe'll be back in a minute.", 'squirrly-seo'), '<br />');
295
+ }
296
+ }
297
+
298
+ echo wp_json_encode(array('posts' => $array));
299
+ } else {
300
+ $posts = $this->model->processPost($json, $post_type);
301
+ echo wp_json_encode(array('posts' => $posts));
302
+ }
303
+
304
+ exit();
305
+ }
306
+ }
307
+ echo wp_json_encode(array('posts' => array()));
308
+ exit();
309
+ }
310
+ }
311
+
312
+ /**
313
+ * Hook the Footer
314
+ */
315
+ public function hookFooter()
316
+ {
317
+ $posts = '';
318
+ foreach ($this->posts as $post) {
319
+ $posts .= '"' . $post . '",';
320
+ }
321
+
322
+ if (strlen($posts) > 0) $posts = substr($posts, 0, strlen($posts) - 1);
323
+
324
+ echo '<script>
325
+ var __sq_ranknotpublic_text = "' . esc_html__("Not Public", 'squirrly-seo') . '";
326
+ var __sq_couldnotprocess_text = "' . esc_html__("Could not process", 'squirrly-seo') . '";
327
+ var __sq_subscriptionexpired_text = "' . esc_html__("The Squirrly subscription has expired!", 'squirrly-seo') . '";
328
+ var sq_posts = new Array(' . $posts . ');
329
+ </script>';
330
+
331
+ }
332
+
333
+ }
controllers/Ranking.php CHANGED
@@ -1,253 +1,263 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- class SQ_Controllers_Ranking extends SQ_Classes_FrontController {
5
-
6
- public $info;
7
- public $ranks;
8
- public $serps;
9
- public $suggested;
10
-
11
- /** @var object Checkin process with Squirrly Cloud */
12
- public $checkin;
13
-
14
- function init() {
15
-
16
- if (SQ_Classes_Helpers_Tools::getOption('sq_api') == '') {
17
- echo $this->getView('Errors/Connect');
18
- return;
19
- }
20
-
21
- //Checkin to API V2
22
- $this->checkin = SQ_Classes_RemoteController::checkin();
23
-
24
- if (is_wp_error($this->checkin)) {
25
- if($this->checkin->get_error_message() == 'no_data') {
26
- echo $this->getView('Errors/Error');
27
- return;
28
- }elseif($this->checkin->get_error_message() == 'maintenance') {
29
- echo $this->getView('Errors/Maintenance');
30
- return;
31
- }
32
- }
33
-
34
- $tab = SQ_Classes_Helpers_Tools::getValue('tab', 'rankings');
35
-
36
- if (method_exists($this, $tab)) {
37
- call_user_func(array($this, $tab));
38
- }
39
-
40
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap-reboot');
41
- if(is_rtl()){
42
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('popper');
43
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap.rtl');
44
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('rtl');
45
- }else{
46
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap');
47
- }
48
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('switchery');
49
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('fontawesome');
50
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('datatables');
51
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('global');
52
-
53
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('assistant');
54
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('navbar');
55
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('rankings');
56
-
57
- //@ob_flush();
58
- echo $this->getView('Ranking/' . ucfirst($tab));
59
-
60
- //get the modal window for the assistant popup
61
- echo SQ_Classes_ObjController::getClass('SQ_Models_Assistant')->getModal();
62
-
63
- }
64
-
65
- /**
66
- * Call the rankings
67
- */
68
- public function rankings() {
69
- add_action('sq_form_notices', array($this,'getNotificationBar'));
70
-
71
- $days_back = (int)SQ_Classes_Helpers_Tools::getValue('days_back', 30);
72
-
73
- $args = array();
74
- $args['days_back'] = $days_back;
75
- $args['keyword'] = (string)SQ_Classes_Helpers_Tools::getValue('skeyword', '');
76
- $args['has_change'] = (string)SQ_Classes_Helpers_Tools::getValue('schanges', '');
77
- $args['has_ranks'] = (string)SQ_Classes_Helpers_Tools::getValue('ranked', '');
78
-
79
-
80
- if ($this->info = SQ_Classes_RemoteController::getRanksStats($args)) {
81
- if (is_wp_error($this->info)) {
82
- $this->info = array();
83
- }
84
- }
85
-
86
- if ($this->ranks = SQ_Classes_RemoteController::getRanks($args)) {
87
- if (is_wp_error($this->ranks)) {
88
- SQ_Classes_Error::setError(esc_html__("Could not load the Rankings.", _SQ_PLUGIN_NAME_));
89
- $this->ranks = array();
90
- }
91
- }
92
- }
93
-
94
- public function gscsync() {
95
-
96
- $this->suggested = array();
97
-
98
- if($this->checkin->connection_gsc) {
99
- $args = array();
100
- $args['max_results'] = '100';
101
- $args['max_position'] = '100';
102
- if ($this->suggested = SQ_Classes_RemoteController::syncGSC($args)) {
103
- if (is_wp_error($this->suggested)) {
104
- SQ_Classes_Error::setError(esc_html__("Could not load data.", _SQ_PLUGIN_NAME_));
105
-
106
- }
107
- }
108
- }
109
-
110
- //Get the briefcase keywords
111
- if ($briefcase = SQ_Classes_RemoteController::getBriefcase()) {
112
- if (!is_wp_error($briefcase)) {
113
- if (isset($briefcase->keywords)) {
114
- $this->keywords = $briefcase->keywords;
115
- }
116
- }
117
- }
118
- }
119
-
120
- /**
121
- * Called when action is triggered
122
- *
123
- * @return void
124
- */
125
- public function action() {
126
- parent::action();
127
-
128
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_focuspages')) {
129
- return;
130
- }
131
-
132
- switch (SQ_Classes_Helpers_Tools::getValue('action')) {
133
-
134
- case 'sq_ranking_settings':
135
- //Save the settings
136
- if (!empty($_POST)) {
137
- SQ_Classes_ObjController::getClass('SQ_Models_Settings')->saveValues($_POST);
138
- }
139
-
140
- //Save the settings on API too
141
- $args = array();
142
- $args['sq_google_country'] = SQ_Classes_Helpers_Tools::getValue('sq_google_country');
143
- $args['sq_google_language'] = SQ_Classes_Helpers_Tools::getValue('sq_google_language');
144
- $args['sq_google_device'] = SQ_Classes_Helpers_Tools::getValue('sq_google_device');
145
- SQ_Classes_RemoteController::saveSettings($args);
146
- ///////////////////////////////
147
-
148
- //show the saved message
149
- SQ_Classes_Error::setMessage(esc_html__("Saved", _SQ_PLUGIN_NAME_));
150
-
151
- break;
152
- case 'sq_serp_refresh_post':
153
- $keyword = SQ_Classes_Helpers_Tools::getValue('keyword', false);
154
- if ($keyword) {
155
- $args = array();
156
- $args['keyword'] = $keyword;
157
- if (SQ_Classes_RemoteController::checkPostRank($args) === false) {
158
- SQ_Classes_Error::setError(sprintf(esc_html__("Could not refresh the rank. Please check your SERP credits %shere%s", _SQ_PLUGIN_NAME_), '<a href="' . SQ_Classes_RemoteController::getMySquirrlyLink('account') . '">', '</a>'));
159
- } else {
160
- SQ_Classes_Error::setMessage(sprintf(esc_html__("%s is queued and the rank will be checked soon.", _SQ_PLUGIN_NAME_), '<strong>' . $keyword . '</strong>'));
161
- }
162
- }
163
-
164
- break;
165
- case 'sq_serp_delete_keyword':
166
- $keyword = SQ_Classes_Helpers_Tools::getValue('keyword', false);
167
-
168
- if ($keyword) {
169
- $response = SQ_Classes_RemoteController::deleteSerpKeyword(array('keyword' => $keyword));
170
- if (!is_wp_error($response)) {
171
- SQ_Classes_Error::setError(esc_html__("The keyword is deleted.", _SQ_PLUGIN_NAME_) . " <br /> ", 'success');
172
- } else {
173
- SQ_Classes_Error::setError(esc_html__("Could not delete the keyword!", _SQ_PLUGIN_NAME_) . " <br /> ");
174
- }
175
- } else {
176
- SQ_Classes_Error::setError(esc_html__("Invalid params!", _SQ_PLUGIN_NAME_) . " <br /> ");
177
- }
178
- break;
179
- case 'sq_ajax_rank_bulk_delete':
180
- SQ_Classes_Helpers_Tools::setHeader( 'json' );
181
- $inputs = SQ_Classes_Helpers_Tools::getValue( 'inputs', array() );
182
-
183
- if ( ! empty( $inputs ) ) {
184
- foreach ( $inputs as $keyword ) {
185
- if ( $keyword <> '' ) {
186
- $args = array();
187
- $args['keyword'] = $keyword;
188
- SQ_Classes_RemoteController::deleteSerpKeyword($args);
189
- }
190
- }
191
-
192
- echo wp_json_encode( array( 'message' => esc_html__( "Deleted!", _SQ_PLUGIN_NAME_ ) ) );
193
- } else {
194
- echo wp_json_encode( array( 'error' => esc_html__( "Invalid params!", _SQ_PLUGIN_NAME_ ) ) );
195
- }
196
- exit();
197
- case 'sq_ajax_rank_bulk_refresh':
198
- SQ_Classes_Helpers_Tools::setHeader( 'json' );
199
- $inputs = SQ_Classes_Helpers_Tools::getValue( 'inputs', array() );
200
-
201
- if ( ! empty( $inputs ) ) {
202
- foreach ( $inputs as $keyword ) {
203
- if ( $keyword <> '' ) {
204
- $args = array();
205
- $args['keyword'] = $keyword;
206
- SQ_Classes_RemoteController::checkPostRank($args);
207
- }
208
-
209
- echo wp_json_encode( array( 'message' => esc_html__( "Sent!", _SQ_PLUGIN_NAME_ ) ) );
210
- }
211
- } else {
212
- echo wp_json_encode( array( 'error' => esc_html__( "Invalid params!", _SQ_PLUGIN_NAME_ ) ) );
213
- }
214
- exit();
215
-
216
- }
217
- }
218
-
219
- public function getScripts() {
220
- return '<script type="text/javascript">
221
- function drawChart(id, values, reverse) {
222
- var data = google.visualization.arrayToDataTable(values);
223
-
224
- var options = {
225
-
226
- curveType: "function",
227
- title: "",
228
- chartArea:{width:"100%",height:"100%"},
229
- enableInteractivity: "true",
230
- tooltip: {trigger: "auto"},
231
- pointSize: "2",
232
- colors: ["#55b2ca"],
233
- hAxis: {
234
- baselineColor: "transparent",
235
- gridlineColor: "transparent",
236
- textPosition: "none"
237
- } ,
238
- vAxis:{
239
- direction: ((reverse) ? -1 : 1),
240
- baselineColor: "transparent",
241
- gridlineColor: "transparent",
242
- textPosition: "none"
243
- }
244
- };
245
-
246
- var chart = new google.visualization.LineChart(document.getElementById(id));
247
- chart.draw(data, options);
248
- return chart;
249
- }
250
- </script>';
251
- }
252
-
253
- }
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ class SQ_Controllers_Ranking extends SQ_Classes_FrontController
5
+ {
6
+
7
+ public $info;
8
+ public $ranks;
9
+ public $serps;
10
+ public $suggested;
11
+
12
+ /**
13
+ *
14
+ *
15
+ * @var object Checkin process with Squirrly Cloud
16
+ */
17
+ public $checkin;
18
+
19
+ function init()
20
+ {
21
+
22
+ if (SQ_Classes_Helpers_Tools::getOption('sq_api') == '') {
23
+ $this->show_view('Errors/Connect');
24
+ return;
25
+ }
26
+
27
+ //Checkin to API V2
28
+ $this->checkin = SQ_Classes_RemoteController::checkin();
29
+
30
+ if (is_wp_error($this->checkin)) {
31
+ if($this->checkin->get_error_message() == 'no_data') {
32
+ $this->show_view('Errors/Error');
33
+ return;
34
+ }elseif($this->checkin->get_error_message() == 'maintenance') {
35
+ $this->show_view('Errors/Maintenance');
36
+ return;
37
+ }
38
+ }
39
+
40
+ $tab = preg_replace("/[^a-zA-Z0-9]/", "", SQ_Classes_Helpers_Tools::getValue('tab', 'rankings'));
41
+
42
+ if (method_exists($this, $tab)) {
43
+ call_user_func(array($this, $tab));
44
+ }
45
+
46
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap-reboot');
47
+ if(is_rtl()) {
48
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('popper');
49
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap.rtl');
50
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('rtl');
51
+ }else{
52
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap');
53
+ }
54
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('switchery');
55
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('fontawesome');
56
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('datatables');
57
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('global');
58
+
59
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('assistant');
60
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('navbar');
61
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('rankings');
62
+
63
+ //@ob_flush();
64
+ $this->show_view('Ranking/' . esc_attr(ucfirst($tab)));
65
+
66
+ //get the modal window for the assistant popup
67
+ echo SQ_Classes_ObjController::getClass('SQ_Models_Assistant')->getModal();
68
+
69
+ }
70
+
71
+ /**
72
+ * Call the rankings
73
+ */
74
+ public function rankings()
75
+ {
76
+ add_action('sq_form_notices', array($this,'getNotificationBar'));
77
+
78
+ $days_back = (int)SQ_Classes_Helpers_Tools::getValue('days_back', 30);
79
+
80
+ $args = array();
81
+ $args['days_back'] = $days_back;
82
+ $args['keyword'] = (string)SQ_Classes_Helpers_Tools::getValue('skeyword', '');
83
+ $args['has_change'] = (string)SQ_Classes_Helpers_Tools::getValue('schanges', '');
84
+ $args['has_ranks'] = (string)SQ_Classes_Helpers_Tools::getValue('ranked', '');
85
+
86
+
87
+ if ($this->info = SQ_Classes_RemoteController::getRanksStats($args)) {
88
+ if (is_wp_error($this->info)) {
89
+ $this->info = array();
90
+ }
91
+ }
92
+
93
+ if ($this->ranks = SQ_Classes_RemoteController::getRanks($args)) {
94
+ if (is_wp_error($this->ranks)) {
95
+ SQ_Classes_Error::setError(esc_html__("Could not load the Rankings.", 'squirrly-seo'));
96
+ $this->ranks = array();
97
+ }
98
+ }
99
+ }
100
+
101
+ public function gscsync()
102
+ {
103
+
104
+ $this->suggested = array();
105
+
106
+ if($this->checkin->connection_gsc) {
107
+ $args = array();
108
+ $args['max_results'] = '100';
109
+ $args['max_position'] = '100';
110
+ if ($this->suggested = SQ_Classes_RemoteController::syncGSC($args)) {
111
+ if (is_wp_error($this->suggested)) {
112
+ SQ_Classes_Error::setError(esc_html__("Could not load data.", 'squirrly-seo'));
113
+
114
+ }
115
+ }
116
+ }
117
+
118
+ //Get the briefcase keywords
119
+ if ($briefcase = SQ_Classes_RemoteController::getBriefcase()) {
120
+ if (!is_wp_error($briefcase)) {
121
+ if (isset($briefcase->keywords)) {
122
+ $this->keywords = $briefcase->keywords;
123
+ }
124
+ }
125
+ }
126
+ }
127
+
128
+ /**
129
+ * Called when action is triggered
130
+ *
131
+ * @return void
132
+ */
133
+ public function action()
134
+ {
135
+ parent::action();
136
+
137
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_focuspages')) {
138
+ return;
139
+ }
140
+
141
+ switch (SQ_Classes_Helpers_Tools::getValue('action')) {
142
+
143
+ case 'sq_ranking_settings':
144
+ //Save the settings
145
+ if (!empty($_POST)) {
146
+ SQ_Classes_ObjController::getClass('SQ_Models_Settings')->saveValues($_POST);
147
+ }
148
+
149
+ //Save the settings on API too
150
+ $args = array();
151
+ $args['sq_google_country'] = SQ_Classes_Helpers_Tools::getValue('sq_google_country');
152
+ $args['sq_google_language'] = SQ_Classes_Helpers_Tools::getValue('sq_google_language');
153
+ $args['sq_google_device'] = SQ_Classes_Helpers_Tools::getValue('sq_google_device');
154
+ SQ_Classes_RemoteController::saveSettings($args);
155
+ ///////////////////////////////
156
+
157
+ //show the saved message
158
+ SQ_Classes_Error::setMessage(esc_html__("Saved", 'squirrly-seo'));
159
+
160
+ break;
161
+ case 'sq_serp_refresh_post':
162
+ $keyword = SQ_Classes_Helpers_Tools::getValue('keyword', false);
163
+ if ($keyword) {
164
+ $args = array();
165
+ $args['keyword'] = $keyword;
166
+ if (SQ_Classes_RemoteController::checkPostRank($args) === false) {
167
+ SQ_Classes_Error::setError(sprintf(esc_html__("Could not refresh the rank. Please check your SERP credits %shere%s", 'squirrly-seo'), '<a href="' . SQ_Classes_RemoteController::getMySquirrlyLink('account') . '">', '</a>'));
168
+ } else {
169
+ SQ_Classes_Error::setMessage(sprintf(esc_html__("%s is queued and the rank will be checked soon.", 'squirrly-seo'), '<strong>' . $keyword . '</strong>'));
170
+ }
171
+ }
172
+
173
+ break;
174
+ case 'sq_serp_delete_keyword':
175
+ $keyword = SQ_Classes_Helpers_Tools::getValue('keyword', false);
176
+
177
+ if ($keyword) {
178
+ $response = SQ_Classes_RemoteController::deleteSerpKeyword(array('keyword' => $keyword));
179
+ if (!is_wp_error($response)) {
180
+ SQ_Classes_Error::setError(esc_html__("The keyword is deleted.", 'squirrly-seo') . " <br /> ", 'success');
181
+ } else {
182
+ SQ_Classes_Error::setError(esc_html__("Could not delete the keyword!", 'squirrly-seo') . " <br /> ");
183
+ }
184
+ } else {
185
+ SQ_Classes_Error::setError(esc_html__("Invalid params!", 'squirrly-seo') . " <br /> ");
186
+ }
187
+ break;
188
+ case 'sq_ajax_rank_bulk_delete':
189
+ SQ_Classes_Helpers_Tools::setHeader('json');
190
+ $inputs = SQ_Classes_Helpers_Tools::getValue('inputs', array());
191
+
192
+ if (! empty($inputs) ) {
193
+ foreach ( $inputs as $keyword ) {
194
+ if ($keyword <> '' ) {
195
+ $args = array();
196
+ $args['keyword'] = $keyword;
197
+ SQ_Classes_RemoteController::deleteSerpKeyword($args);
198
+ }
199
+ }
200
+
201
+ echo wp_json_encode(array( 'message' => esc_html__("Deleted!", 'squirrly-seo') ));
202
+ } else {
203
+ echo wp_json_encode(array( 'error' => esc_html__("Invalid params!", 'squirrly-seo') ));
204
+ }
205
+ exit();
206
+ case 'sq_ajax_rank_bulk_refresh':
207
+ SQ_Classes_Helpers_Tools::setHeader('json');
208
+ $inputs = SQ_Classes_Helpers_Tools::getValue('inputs', array());
209
+
210
+ if (! empty($inputs) ) {
211
+ foreach ( $inputs as $keyword ) {
212
+ if ($keyword <> '' ) {
213
+ $args = array();
214
+ $args['keyword'] = $keyword;
215
+ SQ_Classes_RemoteController::checkPostRank($args);
216
+ }
217
+
218
+ echo wp_json_encode(array( 'message' => esc_html__("Sent!", 'squirrly-seo') ));
219
+ }
220
+ } else {
221
+ echo wp_json_encode(array( 'error' => esc_html__("Invalid params!", 'squirrly-seo') ));
222
+ }
223
+ exit();
224
+
225
+ }
226
+ }
227
+
228
+ public function loadScripts()
229
+ {
230
+ echo '<script type="text/javascript">
231
+ function drawChart(id, values, reverse) {
232
+ var data = google.visualization.arrayToDataTable(values);
233
+
234
+ var options = {
235
+
236
+ curveType: "function",
237
+ title: "",
238
+ chartArea:{width:"100%",height:"100%"},
239
+ enableInteractivity: "true",
240
+ tooltip: {trigger: "auto"},
241
+ pointSize: "2",
242
+ colors: ["#55b2ca"],
243
+ hAxis: {
244
+ baselineColor: "transparent",
245
+ gridlineColor: "transparent",
246
+ textPosition: "none"
247
+ } ,
248
+ vAxis:{
249
+ direction: ((reverse) ? -1 : 1),
250
+ baselineColor: "transparent",
251
+ gridlineColor: "transparent",
252
+ textPosition: "none"
253
+ }
254
+ };
255
+
256
+ var chart = new google.visualization.LineChart(document.getElementById(id));
257
+ chart.draw(data, options);
258
+ return chart;
259
+ }
260
+ </script>';
261
+ }
262
+
263
+ }
controllers/Research.php CHANGED
@@ -1,794 +1,813 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- class SQ_Controllers_Research extends SQ_Classes_FrontController {
5
-
6
- public $blogs;
7
- public $kr;
8
- //--
9
- public $keywords = array();
10
- public $suggested = array();
11
- public $rankkeywords = array();
12
- public $labels = array();
13
- public $countries = array();
14
- public $post_id = false;
15
- //--
16
- public $index;
17
- public $error;
18
- public $user;
19
-
20
- /** @var object Checkin process with Squirrly Cloud */
21
- public $checkin;
22
-
23
- function init() {
24
- if (SQ_Classes_Helpers_Tools::getOption('sq_api') == '') {
25
- echo $this->getView('Errors/Connect');
26
- return;
27
- }
28
-
29
- //Checkin to API V2
30
- $this->checkin = SQ_Classes_RemoteController::checkin();
31
-
32
- if (is_wp_error($this->checkin)) {
33
- if ($this->checkin->get_error_message() == 'no_data') {
34
- echo $this->getView('Errors/Error');
35
- return;
36
- } elseif ($this->checkin->get_error_message() == 'maintenance') {
37
- echo $this->getView('Errors/Maintenance');
38
- return;
39
- }
40
- }
41
-
42
- $tab = SQ_Classes_Helpers_Tools::getValue('tab', 'research');
43
-
44
-
45
- wp_enqueue_style('wp-color-picker');
46
- wp_enqueue_script('wp-color-picker');
47
-
48
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap-reboot');
49
- if (is_rtl()) {
50
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('popper');
51
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap.rtl');
52
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('rtl');
53
- } else {
54
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap');
55
- }
56
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('switchery');
57
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('datatables');
58
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('fontawesome');
59
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('global');
60
-
61
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('assistant');
62
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('navbar');
63
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('research');
64
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia($tab);
65
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('chart');
66
-
67
- if (method_exists($this, $tab)) {
68
- call_user_func(array($this, $tab));
69
- }
70
-
71
- echo $this->getView('Research/' . ucfirst($tab));
72
-
73
-
74
- //get the modal window for the assistant popup
75
- echo SQ_Classes_ObjController::getClass('SQ_Models_Assistant')->getModal();
76
- }
77
-
78
- public function research() {
79
- add_action('sq_form_notices', array($this, 'getNotificationBar'));
80
-
81
- $countries = SQ_Classes_RemoteController::getKrCountries();
82
-
83
- if (!is_wp_error($countries)) {
84
- $this->countries = $countries;
85
- } else {
86
- $this->error = $countries->get_error_message();
87
- }
88
- }
89
-
90
- public function briefcase() {
91
- add_action('sq_form_notices', array($this, 'getNotificationBar'));
92
-
93
- $search = (string)SQ_Classes_Helpers_Tools::getValue('skeyword', '');
94
- $labels = SQ_Classes_Helpers_Tools::getValue('slabel', false);
95
-
96
- $args = array();
97
- $args['search'] = $search;
98
- if ($labels && !empty($labels)) {
99
- $args['label'] = join(',', $labels);
100
- }
101
- SQ_Debug::dump($args);
102
-
103
- $briefcase = SQ_Classes_RemoteController::getBriefcase($args);
104
- $this->rankkeywords = SQ_Classes_RemoteController::getRanks();
105
-
106
- if (!is_wp_error($briefcase)) {
107
- if (isset($briefcase->keywords) && !empty($briefcase->keywords)) {
108
- $this->keywords = $briefcase->keywords;
109
- } else {
110
- $this->error = sprintf(esc_html__("No keyword found. %s Show all %s keywords from Briefcase.", _SQ_PLUGIN_NAME_), '<a href="' . SQ_Classes_Helpers_Tools::getAdminUrl('sq_research', 'briefcase') . '">', '</a>');
111
- }
112
-
113
- if (isset($briefcase->labels)) {
114
- $this->labels = $briefcase->labels;
115
- }
116
-
117
- }
118
-
119
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('briefcase');
120
-
121
- }
122
-
123
- public function labels() {
124
- add_action('sq_form_notices', array($this, 'getNotificationBar'));
125
-
126
- $args = array();
127
- if (!empty($labels)) {
128
- $args['label'] = join(',', $labels);
129
- }
130
-
131
- $briefcase = SQ_Classes_RemoteController::getBriefcase($args);
132
-
133
- if (!is_wp_error($briefcase)) {
134
- if (isset($briefcase->labels)) {
135
- $this->labels = $briefcase->labels;
136
- }
137
- }
138
-
139
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('briefcase');
140
-
141
- }
142
-
143
- public function suggested() {
144
- add_action('sq_form_notices', array($this, 'getNotificationBar'));
145
-
146
- //Get the briefcase keywords
147
- if ($briefcase = SQ_Classes_RemoteController::getBriefcase()) {
148
- if (!is_wp_error($briefcase)) {
149
- if (isset($briefcase->keywords)) {
150
- $this->keywords = $briefcase->keywords;
151
- }
152
- }
153
- }
154
-
155
- $this->suggested = SQ_Classes_RemoteController::getKrFound();
156
-
157
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('briefcase');
158
-
159
- }
160
-
161
- public function history() {
162
-
163
- $args = array();
164
- $args['limit'] = 100;
165
- $this->kr = SQ_Classes_RemoteController::getKRHistory($args);
166
-
167
- }
168
-
169
- /**
170
- * Return the text for the stats in details
171
- * @param $key
172
- * @param $index
173
- * @return string
174
- */
175
- public function getReasearchStatsText($key, $index) {
176
- $stats = array(
177
- 'tw' => array(esc_html__("very few", _SQ_PLUGIN_NAME_), esc_html__("few", _SQ_PLUGIN_NAME_), esc_html__("few", _SQ_PLUGIN_NAME_), esc_html__("few", _SQ_PLUGIN_NAME_), esc_html__("few", _SQ_PLUGIN_NAME_), esc_html__("some", _SQ_PLUGIN_NAME_), esc_html__("some", _SQ_PLUGIN_NAME_), esc_html__("some", _SQ_PLUGIN_NAME_), esc_html__("some", _SQ_PLUGIN_NAME_), esc_html__("many", _SQ_PLUGIN_NAME_), esc_html__("many", _SQ_PLUGIN_NAME_)),
178
- 'sc' => array(esc_html__("very low ranking chance", _SQ_PLUGIN_NAME_), esc_html__("very low ranking chance", _SQ_PLUGIN_NAME_), esc_html__("low ranking chance", _SQ_PLUGIN_NAME_), esc_html__("low ranking chance", _SQ_PLUGIN_NAME_), esc_html__("modest ranking chance", _SQ_PLUGIN_NAME_), esc_html__("modest ranking chance", _SQ_PLUGIN_NAME_), esc_html__("decent ranking chance", _SQ_PLUGIN_NAME_), esc_html__("decent ranking chance", _SQ_PLUGIN_NAME_), esc_html__("high ranking chance", _SQ_PLUGIN_NAME_), esc_html__("very high ranking chance", _SQ_PLUGIN_NAME_), esc_html__("very high ranking chance", _SQ_PLUGIN_NAME_)),
179
- );
180
-
181
- if(isset($stats[$key][$index])){
182
- return $stats[$key][$index];
183
- }
184
-
185
- return '';
186
- }
187
-
188
- /**
189
- * Called when action is triggered
190
- *
191
- * @return void
192
- */
193
- public function action() {
194
- parent::action();
195
-
196
- switch (SQ_Classes_Helpers_Tools::getValue('action')) {
197
-
198
- case 'sq_briefcase_addkeyword':
199
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
200
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
201
- SQ_Classes_Helpers_Tools::setHeader('json');
202
-
203
- if (SQ_Classes_Helpers_Tools::isAjax()) {
204
- echo wp_json_encode($response);
205
- exit();
206
- } else {
207
- SQ_Classes_Error::setError(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_));
208
- }
209
- }
210
-
211
- SQ_Classes_Helpers_Tools::setHeader('json');
212
- $keyword = (string)SQ_Classes_Helpers_Tools::getValue('keyword', '');
213
- $do_serp = (int)SQ_Classes_Helpers_Tools::getValue('doserp', 0);
214
- $is_hidden = (int)SQ_Classes_Helpers_Tools::getValue('hidden', 0);
215
-
216
- if ($keyword <> '') {
217
- //set ignore on API
218
- $args = array();
219
- $args['keyword'] = $keyword;
220
- $args['do_serp'] = $do_serp;
221
- $args['is_hidden'] = $is_hidden;
222
- SQ_Classes_RemoteController::addBriefcaseKeyword($args);
223
-
224
- if (SQ_Classes_Helpers_Tools::isAjax()) {
225
- if ($do_serp) {
226
- echo wp_json_encode(array('message' => esc_html__("Keyword Saved. The rank check will be ready in a minute.", _SQ_PLUGIN_NAME_)));
227
- } else {
228
- echo wp_json_encode(array('message' => esc_html__("Keyword Saved!", _SQ_PLUGIN_NAME_)));
229
- }
230
- exit();
231
- } else {
232
- SQ_Classes_Error::setMessage(esc_html__("Keyword Saved!", _SQ_PLUGIN_NAME_));
233
- }
234
- } else {
235
- if (SQ_Classes_Helpers_Tools::isAjax()) {
236
- echo wp_json_encode(array('error' => esc_html__("Invalid params!", _SQ_PLUGIN_NAME_)));
237
- exit();
238
- } else {
239
- SQ_Classes_Error::setError(esc_html__("Invalid params!", _SQ_PLUGIN_NAME_));
240
- }
241
- }
242
- break;
243
- case 'sq_briefcase_deletekeyword':
244
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
245
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
246
- SQ_Classes_Helpers_Tools::setHeader('json');
247
- echo wp_json_encode($response);
248
- exit();
249
- }
250
-
251
- SQ_Classes_Helpers_Tools::setHeader('json');
252
- $keyword = (string)SQ_Classes_Helpers_Tools::getValue('keyword', '');
253
-
254
- if ($keyword <> '') {
255
- //set ignore on API
256
- $args = array();
257
- $args['keyword'] = stripslashes($keyword);
258
- SQ_Classes_RemoteController::removeBriefcaseKeyword($args);
259
-
260
- echo wp_json_encode(array('message' => esc_html__("Deleted!", _SQ_PLUGIN_NAME_)));
261
- } else {
262
- echo wp_json_encode(array('error' => esc_html__("Invalid params!", _SQ_PLUGIN_NAME_)));
263
- }
264
- exit();
265
- case 'sq_briefcase_deletefound':
266
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
267
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
268
- SQ_Classes_Helpers_Tools::setHeader('json');
269
- echo wp_json_encode($response);
270
- exit();
271
- }
272
-
273
- SQ_Classes_Helpers_Tools::setHeader('json');
274
- $keyword = (string)SQ_Classes_Helpers_Tools::getValue('keyword', '');
275
-
276
- if ($keyword <> '') {
277
- //set ignore on API
278
- $args = array();
279
- $args['keyword'] = stripslashes($keyword);
280
- SQ_Classes_RemoteController::removeKrFound($args);
281
-
282
- echo wp_json_encode(array('message' => esc_html__("Deleted!", _SQ_PLUGIN_NAME_)));
283
- } else {
284
- echo wp_json_encode(array('error' => esc_html__("Invalid params!", _SQ_PLUGIN_NAME_)));
285
- }
286
- exit();
287
- /**********************************/
288
- case 'sq_briefcase_addlabel':
289
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
290
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
291
- SQ_Classes_Helpers_Tools::setHeader('json');
292
- echo wp_json_encode($response);
293
- exit();
294
- }
295
-
296
- SQ_Classes_Helpers_Tools::setHeader('json');
297
-
298
- $name = (string)SQ_Classes_Helpers_Tools::getValue('name', '');
299
- $color = (string)SQ_Classes_Helpers_Tools::getValue('color', '#ffffff');
300
-
301
- if ($name <> '' && $color <> '') {
302
- $args = array();
303
-
304
- $args['name'] = $name;
305
- $args['color'] = $color;
306
- $json = SQ_Classes_RemoteController::addBriefcaseLabel($args);
307
-
308
- if (!is_wp_error($json)) {
309
- echo wp_json_encode(array('saved' => esc_html__("Saved!", _SQ_PLUGIN_NAME_)));
310
- } else {
311
- echo wp_json_encode(array('error' => $json->get_error_message()));
312
- }
313
-
314
- } else {
315
- echo wp_json_encode(array('error' => esc_html__("Invalid Label or Color!", _SQ_PLUGIN_NAME_)));
316
- }
317
- exit();
318
- case 'sq_briefcase_editlabel':
319
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
320
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
321
- SQ_Classes_Helpers_Tools::setHeader('json');
322
- echo wp_json_encode($response);
323
- exit();
324
- }
325
-
326
- SQ_Classes_Helpers_Tools::setHeader('json');
327
-
328
- $id = (int)SQ_Classes_Helpers_Tools::getValue('id', 0);
329
- $name = (string)SQ_Classes_Helpers_Tools::getValue('name', 0);
330
- $color = (string)SQ_Classes_Helpers_Tools::getValue('color', '#ffffff');
331
-
332
- if ((int)$id > 0 && $name <> '' && $color <> '') {
333
- $args = array();
334
-
335
- $args['id'] = $id;
336
- $args['name'] = $name;
337
- $args['color'] = $color;
338
- SQ_Classes_RemoteController::saveBriefcaseLabel($args);
339
-
340
- echo wp_json_encode(array('saved' => esc_html__("Saved!", _SQ_PLUGIN_NAME_)));
341
- } else {
342
- echo wp_json_encode(array('error' => esc_html__("Invalid params!", _SQ_PLUGIN_NAME_)));
343
- }
344
- exit();
345
- case 'sq_briefcase_deletelabel':
346
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippets')) {
347
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
348
- SQ_Classes_Helpers_Tools::setHeader('json');
349
- echo wp_json_encode($response);
350
- exit();
351
- }
352
-
353
- SQ_Classes_Helpers_Tools::setHeader('json');
354
-
355
- $id = (int)SQ_Classes_Helpers_Tools::getValue('id', 0);
356
-
357
- if ($id > 0) {
358
- //set ignore on API
359
- $args = array();
360
-
361
- $args['id'] = $id;
362
- SQ_Classes_RemoteController::removeBriefcaseLabel($args);
363
-
364
- echo wp_json_encode(array('deleted' => esc_html__("Deleted!", _SQ_PLUGIN_NAME_)));
365
- } else {
366
- echo wp_json_encode(array('error' => esc_html__("Invalid params!", _SQ_PLUGIN_NAME_)));
367
- }
368
- exit();
369
- case 'sq_briefcase_keywordlabel':
370
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
371
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
372
- SQ_Classes_Helpers_Tools::setHeader('json');
373
- echo wp_json_encode($response);
374
- exit();
375
- }
376
-
377
- SQ_Classes_Helpers_Tools::setHeader('json');
378
-
379
- $keyword = (string)SQ_Classes_Helpers_Tools::getValue('keyword', '');
380
- $labels = SQ_Classes_Helpers_Tools::getValue('labels', array());
381
-
382
- if ($keyword <> '') {
383
- $args = array();
384
-
385
- $args['keyword'] = $keyword;
386
- $args['labels'] = '';
387
- if (is_array($labels) && !empty($labels)) {
388
- $args['labels'] = join(',', $labels);
389
- SQ_Classes_RemoteController::saveBriefcaseKeywordLabel($args);
390
- } else {
391
- SQ_Classes_RemoteController::saveBriefcaseKeywordLabel($args);
392
-
393
- }
394
- echo wp_json_encode(array('saved' => esc_html__("Saved!", _SQ_PLUGIN_NAME_)));
395
- } else {
396
- echo wp_json_encode(array('error' => esc_html__("Invalid Keyword!", _SQ_PLUGIN_NAME_)));
397
- }
398
- exit();
399
- case 'sq_briefcase_backup':
400
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
401
- SQ_Classes_Error::setError(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
402
- return;
403
- }
404
-
405
- $args = array();
406
- $args['limit'] = -1;
407
- $briefcase = SQ_Classes_RemoteController::getBriefcase($args);
408
-
409
- if(isset($briefcase->keywords) && !empty($briefcase->keywords)) {
410
- $fp = fopen(_SQ_CACHE_DIR_ . 'file.txt', 'w');
411
- foreach ($briefcase->keywords as $row) {
412
- fwrite($fp, $row->keyword . PHP_EOL);
413
- }
414
- fclose($fp);
415
-
416
- header("Content-type: text;");
417
- header("Content-Encoding: UTF-8");
418
- header("Content-Disposition: attachment; filename=squirrly-briefcase-" . gmdate('Y-m-d') . ".txt");
419
- header("Pragma: no-cache");
420
- header("Expires: 0");
421
- readfile(_SQ_CACHE_DIR_ . 'file.txt');
422
- }else{
423
- SQ_Classes_Error::setError(esc_html__("No keywords in Briefcase to backup", _SQ_PLUGIN_NAME_), 'sq_error');
424
- return;
425
- }
426
-
427
- exit();
428
- case 'sq_briefcase_restore':
429
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
430
- SQ_Classes_Error::setError(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
431
- return;
432
- }
433
-
434
- if (!empty($_FILES['sq_upload_file']) && $_FILES['sq_upload_file']['tmp_name'] <> '') {
435
- $fp = fopen($_FILES['sq_upload_file']['tmp_name'], 'rb');
436
-
437
- try {
438
- $data = '';
439
- $keywords = array();
440
-
441
- while (($line = fgets($fp)) !== false) {
442
- $data .= $line;
443
- }
444
-
445
- if ($data = json_decode($data)) {
446
- if (is_array($data) and !empty($data)) {
447
- foreach ($data as $row) {
448
- if (isset($row->keyword)) {
449
- $keywords[] = $row->keyword;
450
- }
451
- }
452
- }
453
- } else {
454
- //Get the data from CSV
455
- $fp = fopen($_FILES['sq_upload_file']['tmp_name'], 'rb');
456
-
457
- while (($data = fgetcsv($fp, 1000, ";")) !== FALSE) {
458
- if (!isset($data[0]) || $data[0] == '' || strlen($data[0]) > 255 || is_numeric($data[0])) {
459
- SQ_Classes_Error::setError(esc_html__("Error! The backup is not valid.", _SQ_PLUGIN_NAME_) . " <br /> ");
460
- break;
461
- }
462
-
463
- if (is_string($data[0]) && $data[0] <> '') {
464
- $keywords[] = strip_tags($data[0]);
465
- }
466
- }
467
-
468
- if (empty($keywords)) {
469
- $fp = fopen($_FILES['sq_upload_file']['tmp_name'], 'rb');
470
-
471
- while (($data = fgetcsv($fp, 1000, ",")) !== FALSE) {
472
- if (!isset($data[0]) || $data[0] == '' || strlen($data[0]) > 255 || is_numeric($data[0])) {
473
- SQ_Classes_Error::setError(esc_html__("Error! The backup is not valid.", _SQ_PLUGIN_NAME_) . " <br /> ");
474
- break;
475
- }
476
-
477
- if (is_string($data[0]) && $data[0] <> '') {
478
- $keywords[] = strip_tags($data[0]);
479
- }
480
- }
481
- }
482
-
483
-
484
- }
485
-
486
- if (!empty($keywords)) {
487
- $keywords = array_chunk($keywords, 100);
488
-
489
- foreach ($keywords as $chunk) {
490
- SQ_Classes_RemoteController::importBriefcaseKeywords(array('keywords' => json_encode($chunk)));
491
- }
492
-
493
- SQ_Classes_Error::setError(esc_html__("Great! The backup is restored.", _SQ_PLUGIN_NAME_) . " <br /> ", 'success');
494
- } else {
495
- SQ_Classes_Error::setError(esc_html__("Error! The backup is not valid.", _SQ_PLUGIN_NAME_) . " <br /> ");
496
- }
497
- } catch (Exception $e) {
498
- SQ_Classes_Error::setError(esc_html__("Error! The backup is not valid.", _SQ_PLUGIN_NAME_) . " <br /> ");
499
- }
500
- } else {
501
- SQ_Classes_Error::setError(esc_html__("Error! You have to enter a previously saved backup file.", _SQ_PLUGIN_NAME_) . " <br /> ");
502
- }
503
- break;
504
- case 'sq_briefcase_savemain':
505
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
506
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
507
- SQ_Classes_Helpers_Tools::setHeader('json');
508
- echo wp_json_encode($response);
509
- exit();
510
- }
511
-
512
- SQ_Classes_Helpers_Tools::setHeader('json');
513
-
514
- $post_id = (int)SQ_Classes_Helpers_Tools::getValue('post_id', 0);
515
- $keyword = (string)SQ_Classes_Helpers_Tools::getValue('keyword', '');
516
-
517
- if ((int)$post_id > 0 && $keyword <> '') {
518
- $args = array();
519
-
520
- $args['post_id'] = $post_id;
521
- $args['keyword'] = $keyword;
522
- SQ_Classes_RemoteController::saveBriefcaseMainKeyword($args);
523
-
524
- echo wp_json_encode(array('saved' => esc_html__("Saved!", _SQ_PLUGIN_NAME_)));
525
- } else {
526
- echo wp_json_encode(array('error' => esc_html__("Invalid params!", _SQ_PLUGIN_NAME_)));
527
- }
528
- exit();
529
- /************************************************* AJAX */
530
- case 'sq_ajax_briefcase_doserp':
531
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
532
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
533
- SQ_Classes_Helpers_Tools::setHeader('json');
534
- echo wp_json_encode($response);
535
- exit();
536
- }
537
-
538
- SQ_Classes_Helpers_Tools::setHeader('json');
539
-
540
- $json = array();
541
- $keyword = (string)SQ_Classes_Helpers_Tools::getValue('keyword', '');
542
-
543
- if ($keyword <> '') {
544
- $args = array();
545
- $args['keyword'] = $keyword;
546
- if (SQ_Classes_RemoteController::addSerpKeyword($args) === false) {
547
- $json['error'] = SQ_Classes_Error::showNotices(esc_html__("Could not add the keyword to SERP Check. Please try again.", _SQ_PLUGIN_NAME_), 'sq_error');
548
- } else {
549
- $json['message'] = SQ_Classes_Error::showNotices(esc_html__("The keyword is added to SERP Check.", _SQ_PLUGIN_NAME_), 'sq_success');
550
- }
551
- } else {
552
- $json['error'] = SQ_Classes_Error::showNotices(esc_html__("Invalid parameters.", _SQ_PLUGIN_NAME_), 'sq_error');
553
- }
554
-
555
- SQ_Classes_Helpers_Tools::setHeader('json');
556
- echo wp_json_encode($json);
557
- exit();
558
- case 'sq_ajax_research_others':
559
- SQ_Classes_Helpers_Tools::setHeader('json');
560
- $keyword = SQ_Classes_Helpers_Tools::getValue('keyword', false);
561
- $country = SQ_Classes_Helpers_Tools::getValue('country', 'com');
562
- $lang = SQ_Classes_Helpers_Tools::getValue('lang', 'en');
563
-
564
- if ($keyword) {
565
- $args = array();
566
- $args['keyword'] = $keyword;
567
- $args['country'] = $country;
568
- $args['lang'] = $lang;
569
- $json = SQ_Classes_RemoteController::getKROthers($args);
570
-
571
- if (!is_wp_error($json)) {
572
- if (isset($json->keywords)) {
573
- echo wp_json_encode(array('keywords' => $json->keywords));
574
- }
575
- } else {
576
- echo wp_json_encode(array('error' => $json->get_error_message()));
577
- }
578
- } else {
579
- echo wp_json_encode(array('error' => esc_html__("Invalid params!", _SQ_PLUGIN_NAME_)));
580
- }
581
-
582
- exit();
583
- case 'sq_ajax_research_process':
584
- SQ_Classes_Helpers_Tools::setHeader('json');
585
- $keywords = SQ_Classes_Helpers_Tools::getValue('keywords', false);
586
- $lang = SQ_Classes_Helpers_Tools::getValue('lang', 'en');
587
- $country = SQ_Classes_Helpers_Tools::getValue('country', 'com');
588
-
589
- $count = (int)SQ_Classes_Helpers_Tools::getValue('count', 10);
590
- $id = (int)SQ_Classes_Helpers_Tools::getValue('id', 0);
591
- $this->post_id = SQ_Classes_Helpers_Tools::getValue('post_id', false);
592
-
593
- if ($id > 0) {
594
- $args = array();
595
- $args['id'] = $id;
596
- $this->kr = SQ_Classes_RemoteController::getKRSuggestion($args);
597
-
598
- if (!is_wp_error($this->kr)) {
599
- if (!empty($this->kr)) {
600
- //Get the briefcase keywords
601
- if ($briefcase = SQ_Classes_RemoteController::getBriefcase()) {
602
- if (!is_wp_error($briefcase)) {
603
- if (isset($briefcase->keywords)) {
604
- $this->keywords = $briefcase->keywords;
605
- }
606
- }
607
- }
608
-
609
- //research ready, return the results
610
- echo wp_json_encode(array('done' => true, 'html' => $this->getView('Research/ResearchDetails')));
611
- } else {
612
- //still loading
613
- echo wp_json_encode(array('done' => false));
614
- }
615
- } else {
616
- //show the keywords in results to be able to add them to brifcase
617
- $keywords = explode(',', $keywords);
618
- if (!empty($keywords)) {
619
- foreach ($keywords as $keyword) {
620
- $this->kr[] = json_decode(wp_json_encode(array(
621
- 'keyword' => $keyword,
622
- )));
623
- }
624
- }
625
- echo wp_json_encode(array('done' => true, 'html' => $this->getView('Research/ResearchDetails')));
626
-
627
- }
628
- } elseif ($keywords) {
629
- $args = array();
630
- $args['q'] = $keywords;
631
- $args['country'] = $country;
632
- $args['lang'] = $lang;
633
- $args['count'] = $count;
634
- $process = SQ_Classes_RemoteController::setKRSuggestion($args);
635
-
636
- if (!is_wp_error($process)) {
637
- if (isset($process->id)) {
638
- //Get the briefcase keywords
639
- echo wp_json_encode(array('done' => false, 'id' => $process->id));
640
-
641
- }
642
- } else {
643
- if ($process->get_error_code() == 'limit_exceeded') {
644
- echo wp_json_encode(array('done' => true, 'error' => esc_html__("Keyword Research limit exceeded", _SQ_PLUGIN_NAME_)));
645
- } else {
646
- echo wp_json_encode(array('done' => true, 'error' => $process->get_error_message()));
647
- }
648
- }
649
- } else {
650
- echo wp_json_encode(array('done' => true, 'error' => esc_html__("Invalid params!", _SQ_PLUGIN_NAME_)));
651
- }
652
- exit();
653
- case 'sq_ajax_research_history':
654
- SQ_Classes_Helpers_Tools::setHeader('json');
655
- $id = (int)SQ_Classes_Helpers_Tools::getValue('id', 0);
656
-
657
- if ($id > 0) {
658
- $args = $this->kr = array();
659
- $args['id'] = $id;
660
- $krHistory = SQ_Classes_RemoteController::getKRHistory($args);
661
-
662
- if (!empty($krHistory)) { //get only the first report
663
- $this->kr = current($krHistory);
664
- }
665
-
666
- //Get the briefcase keywords
667
- if ($briefcase = SQ_Classes_RemoteController::getBriefcase()) {
668
- if (!is_wp_error($briefcase)) {
669
- if (isset($briefcase->keywords)) {
670
- $this->keywords = $briefcase->keywords;
671
- }
672
- }
673
- }
674
-
675
- echo wp_json_encode(array('html' => $this->getView('Research/HistoryDetails')));
676
- } else {
677
- echo wp_json_encode(array('error' => esc_html__("Invalid params!", _SQ_PLUGIN_NAME_)));
678
- }
679
- exit();
680
-
681
- case 'sq_ajax_briefcase_bulk_delete':
682
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
683
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
684
- SQ_Classes_Helpers_Tools::setHeader('json');
685
- echo wp_json_encode($response);
686
- exit();
687
- }
688
-
689
- SQ_Classes_Helpers_Tools::setHeader('json');
690
- $keywords = SQ_Classes_Helpers_Tools::getValue('inputs', array());
691
-
692
- if (!empty($keywords)) {
693
- foreach ($keywords as $keyword) {
694
- //set ignore on API
695
- $args = array();
696
- $args['keyword'] = stripslashes($keyword);
697
- SQ_Classes_RemoteController::removeBriefcaseKeyword($args);
698
- }
699
-
700
- echo wp_json_encode(array('message' => esc_html__("Deleted!", _SQ_PLUGIN_NAME_)));
701
- } else {
702
- echo wp_json_encode(array('error' => esc_html__("Invalid params!", _SQ_PLUGIN_NAME_)));
703
- }
704
- exit();
705
- case 'sq_ajax_briefcase_bulk_label':
706
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
707
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
708
- SQ_Classes_Helpers_Tools::setHeader('json');
709
- echo wp_json_encode($response);
710
- exit();
711
- }
712
-
713
- SQ_Classes_Helpers_Tools::setHeader('json');
714
-
715
- $keywords = SQ_Classes_Helpers_Tools::getValue('inputs', array());
716
- $labels = SQ_Classes_Helpers_Tools::getValue('labels', array());
717
-
718
- if (!empty($keywords)) {
719
- foreach ($keywords as $keyword) {
720
- $args = array();
721
-
722
- $args['keyword'] = $keyword;
723
- $args['labels'] = '';
724
- if (is_array($labels) && !empty($labels)) {
725
- $args['labels'] = join(',', $labels);
726
- SQ_Classes_RemoteController::saveBriefcaseKeywordLabel($args);
727
- } else {
728
- SQ_Classes_RemoteController::saveBriefcaseKeywordLabel($args);
729
-
730
- }
731
- }
732
-
733
- echo wp_json_encode(array('message' => esc_html__("Saved!", _SQ_PLUGIN_NAME_)));
734
- } else {
735
- echo wp_json_encode(array('error' => esc_html__("Invalid Keyword!", _SQ_PLUGIN_NAME_)));
736
- }
737
-
738
- exit();
739
- case 'sq_ajax_briefcase_bulk_doserp':
740
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
741
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
742
- SQ_Classes_Helpers_Tools::setHeader('json');
743
- echo wp_json_encode($response);
744
- exit();
745
- }
746
-
747
- SQ_Classes_Helpers_Tools::setHeader('json');
748
-
749
- $keywords = SQ_Classes_Helpers_Tools::getValue('inputs', array());
750
-
751
- if (!empty($keywords)) {
752
- foreach ($keywords as $keyword) {
753
- $args = array();
754
- $args['keyword'] = $keyword;
755
- SQ_Classes_RemoteController::addSerpKeyword($args);
756
-
757
- }
758
-
759
- echo wp_json_encode(array('message' => esc_html__("The keywords are added to SERP Check!", _SQ_PLUGIN_NAME_)));
760
- } else {
761
- echo wp_json_encode(array('error' => esc_html__("Invalid Keyword!", _SQ_PLUGIN_NAME_)));
762
- }
763
- exit();
764
-
765
- case 'sq_ajax_labels_bulk_delete':
766
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
767
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
768
- SQ_Classes_Helpers_Tools::setHeader('json');
769
- echo wp_json_encode($response);
770
- exit();
771
- }
772
-
773
- SQ_Classes_Helpers_Tools::setHeader('json');
774
- $inputs = SQ_Classes_Helpers_Tools::getValue('inputs', array());
775
-
776
- if (!empty($inputs)) {
777
- foreach ($inputs as $id) {
778
- if ($id > 0) {
779
- $args = array();
780
- $args['id'] = $id;
781
- SQ_Classes_RemoteController::removeBriefcaseLabel($args);
782
- }
783
- }
784
-
785
- echo wp_json_encode(array('message' => esc_html__("Deleted!", _SQ_PLUGIN_NAME_)));
786
- } else {
787
- echo wp_json_encode(array('error' => esc_html__("Invalid params!", _SQ_PLUGIN_NAME_)));
788
- }
789
- exit();
790
- }
791
-
792
-
793
- }
794
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ class SQ_Controllers_Research extends SQ_Classes_FrontController
5
+ {
6
+
7
+ public $blogs;
8
+ public $kr;
9
+ //--
10
+ public $keywords = array();
11
+ public $suggested = array();
12
+ public $rankkeywords = array();
13
+ public $labels = array();
14
+ public $countries = array();
15
+ public $post_id = false;
16
+ //--
17
+ public $index;
18
+ public $error;
19
+ public $user;
20
+
21
+ /**
22
+ *
23
+ *
24
+ * @var object Checkin process with Squirrly Cloud
25
+ */
26
+ public $checkin;
27
+
28
+ function init()
29
+ {
30
+ if (SQ_Classes_Helpers_Tools::getOption('sq_api') == '') {
31
+ $this->show_view('Errors/Connect');
32
+ return;
33
+ }
34
+
35
+ //Checkin to API V2
36
+ $this->checkin = SQ_Classes_RemoteController::checkin();
37
+
38
+ if (is_wp_error($this->checkin)) {
39
+ if ($this->checkin->get_error_message() == 'no_data') {
40
+ $this->show_view('Errors/Error');
41
+ return;
42
+ } elseif ($this->checkin->get_error_message() == 'maintenance') {
43
+ $this->show_view('Errors/Maintenance');
44
+ return;
45
+ }
46
+ }
47
+
48
+ $tab = preg_replace("/[^a-zA-Z0-9]/", "", SQ_Classes_Helpers_Tools::getValue('tab', 'research'));
49
+
50
+ wp_enqueue_style('wp-color-picker');
51
+ wp_enqueue_script('wp-color-picker');
52
+
53
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap-reboot');
54
+ if (is_rtl()) {
55
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('popper');
56
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap.rtl');
57
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('rtl');
58
+ } else {
59
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap');
60
+ }
61
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('switchery');
62
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('datatables');
63
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('fontawesome');
64
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('global');
65
+
66
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('assistant');
67
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('navbar');
68
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('research');
69
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia($tab);
70
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('chart');
71
+
72
+ if (method_exists($this, $tab)) {
73
+ call_user_func(array($this, $tab));
74
+ }
75
+
76
+ $this->show_view('Research/' . esc_attr(ucfirst($tab)));
77
+
78
+
79
+ //get the modal window for the assistant popup
80
+ echo SQ_Classes_ObjController::getClass('SQ_Models_Assistant')->getModal();
81
+ }
82
+
83
+ public function research()
84
+ {
85
+ add_action('sq_form_notices', array($this, 'getNotificationBar'));
86
+
87
+ $countries = SQ_Classes_RemoteController::getKrCountries();
88
+
89
+ if (!is_wp_error($countries)) {
90
+ $this->countries = $countries;
91
+ } else {
92
+ $this->error = $countries->get_error_message();
93
+ }
94
+ }
95
+
96
+ public function briefcase()
97
+ {
98
+ add_action('sq_form_notices', array($this, 'getNotificationBar'));
99
+
100
+ $search = (string)SQ_Classes_Helpers_Tools::getValue('skeyword', '');
101
+ $labels = SQ_Classes_Helpers_Tools::getValue('slabel', false);
102
+
103
+ $args = array();
104
+ $args['search'] = $search;
105
+ if ($labels && !empty($labels)) {
106
+ $args['label'] = join(',', $labels);
107
+ }
108
+
109
+ $briefcase = SQ_Classes_RemoteController::getBriefcase($args);
110
+ $this->rankkeywords = SQ_Classes_RemoteController::getRanks();
111
+
112
+ if (!is_wp_error($briefcase)) {
113
+ if (isset($briefcase->keywords) && !empty($briefcase->keywords)) {
114
+ $this->keywords = $briefcase->keywords;
115
+ } else {
116
+ $this->error = sprintf(esc_html__("No keyword found. %s Show all %s keywords from Briefcase.", 'squirrly-seo'), '<a href="' . SQ_Classes_Helpers_Tools::getAdminUrl('sq_research', 'briefcase') . '">', '</a>');
117
+ }
118
+
119
+ if (isset($briefcase->labels)) {
120
+ $this->labels = $briefcase->labels;
121
+ }
122
+
123
+ }
124
+
125
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('briefcase');
126
+
127
+ }
128
+
129
+ public function labels()
130
+ {
131
+ add_action('sq_form_notices', array($this, 'getNotificationBar'));
132
+
133
+ $args = array();
134
+ if (!empty($labels)) {
135
+ $args['label'] = join(',', $labels);
136
+ }
137
+
138
+ $briefcase = SQ_Classes_RemoteController::getBriefcase($args);
139
+
140
+ if (!is_wp_error($briefcase)) {
141
+ if (isset($briefcase->labels)) {
142
+ $this->labels = $briefcase->labels;
143
+ }
144
+ }
145
+
146
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('briefcase');
147
+
148
+ }
149
+
150
+ public function suggested()
151
+ {
152
+ add_action('sq_form_notices', array($this, 'getNotificationBar'));
153
+
154
+ //Get the briefcase keywords
155
+ if ($briefcase = SQ_Classes_RemoteController::getBriefcase()) {
156
+ if (!is_wp_error($briefcase)) {
157
+ if (isset($briefcase->keywords)) {
158
+ $this->keywords = $briefcase->keywords;
159
+ }
160
+ }
161
+ }
162
+
163
+ $this->suggested = SQ_Classes_RemoteController::getKrFound();
164
+
165
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('briefcase');
166
+
167
+ }
168
+
169
+ public function history()
170
+ {
171
+
172
+ $args = array();
173
+ $args['limit'] = 100;
174
+ $this->kr = SQ_Classes_RemoteController::getKRHistory($args);
175
+
176
+ }
177
+
178
+ /**
179
+ * Return the text for the stats in details
180
+ *
181
+ * @param $key
182
+ * @param $index
183
+ * @return string
184
+ */
185
+ public function getReasearchStatsText($key, $index)
186
+ {
187
+ $stats = array(
188
+ 'tw' => array(esc_html__("very few", 'squirrly-seo'), esc_html__("few", 'squirrly-seo'), esc_html__("few", 'squirrly-seo'), esc_html__("few", 'squirrly-seo'), esc_html__("few", 'squirrly-seo'), esc_html__("some", 'squirrly-seo'), esc_html__("some", 'squirrly-seo'), esc_html__("some", 'squirrly-seo'), esc_html__("some", 'squirrly-seo'), esc_html__("many", 'squirrly-seo'), esc_html__("many", 'squirrly-seo')),
189
+ 'sc' => array(esc_html__("very low ranking chance", 'squirrly-seo'), esc_html__("very low ranking chance", 'squirrly-seo'), esc_html__("low ranking chance", 'squirrly-seo'), esc_html__("low ranking chance", 'squirrly-seo'), esc_html__("modest ranking chance", 'squirrly-seo'), esc_html__("modest ranking chance", 'squirrly-seo'), esc_html__("decent ranking chance", 'squirrly-seo'), esc_html__("decent ranking chance", 'squirrly-seo'), esc_html__("high ranking chance", 'squirrly-seo'), esc_html__("very high ranking chance", 'squirrly-seo'), esc_html__("very high ranking chance", 'squirrly-seo')),
190
+ );
191
+
192
+ if(isset($stats[$key][$index])) {
193
+ return $stats[$key][$index];
194
+ }
195
+
196
+ return '';
197
+ }
198
+
199
+ /**
200
+ * Called when action is triggered
201
+ *
202
+ * @return void
203
+ */
204
+ public function action()
205
+ {
206
+ parent::action();
207
+
208
+ switch (SQ_Classes_Helpers_Tools::getValue('action')) {
209
+
210
+ case 'sq_briefcase_addkeyword':
211
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
212
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
213
+ SQ_Classes_Helpers_Tools::setHeader('json');
214
+
215
+ if (SQ_Classes_Helpers_Tools::isAjax()) {
216
+ echo wp_json_encode($response);
217
+ exit();
218
+ } else {
219
+ SQ_Classes_Error::setError(esc_html__("You do not have permission to perform this action", 'squirrly-seo'));
220
+ }
221
+ }
222
+
223
+ SQ_Classes_Helpers_Tools::setHeader('json');
224
+ $keyword = (string)SQ_Classes_Helpers_Tools::getValue('keyword', '');
225
+ $do_serp = (int)SQ_Classes_Helpers_Tools::getValue('doserp', 0);
226
+ $is_hidden = (int)SQ_Classes_Helpers_Tools::getValue('hidden', 0);
227
+
228
+ if ($keyword <> '') {
229
+ //set ignore on API
230
+ $args = array();
231
+ $args['keyword'] = $keyword;
232
+ $args['do_serp'] = $do_serp;
233
+ $args['is_hidden'] = $is_hidden;
234
+ SQ_Classes_RemoteController::addBriefcaseKeyword($args);
235
+
236
+ if (SQ_Classes_Helpers_Tools::isAjax()) {
237
+ if ($do_serp) {
238
+ echo wp_json_encode(array('message' => esc_html__("Keyword Saved. The rank check will be ready in a minute.", 'squirrly-seo')));
239
+ } else {
240
+ echo wp_json_encode(array('message' => esc_html__("Keyword Saved!", 'squirrly-seo')));
241
+ }
242
+ exit();
243
+ } else {
244
+ SQ_Classes_Error::setMessage(esc_html__("Keyword Saved!", 'squirrly-seo'));
245
+ }
246
+ } else {
247
+ if (SQ_Classes_Helpers_Tools::isAjax()) {
248
+ echo wp_json_encode(array('error' => esc_html__("Invalid params!", 'squirrly-seo')));
249
+ exit();
250
+ } else {
251
+ SQ_Classes_Error::setError(esc_html__("Invalid params!", 'squirrly-seo'));
252
+ }
253
+ }
254
+ break;
255
+ case 'sq_briefcase_deletekeyword':
256
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
257
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
258
+ SQ_Classes_Helpers_Tools::setHeader('json');
259
+ echo wp_json_encode($response);
260
+ exit();
261
+ }
262
+
263
+ SQ_Classes_Helpers_Tools::setHeader('json');
264
+ $keyword = (string)SQ_Classes_Helpers_Tools::getValue('keyword', '');
265
+
266
+ if ($keyword <> '') {
267
+ //set ignore on API
268
+ $args = array();
269
+ $args['keyword'] = stripslashes($keyword);
270
+ SQ_Classes_RemoteController::removeBriefcaseKeyword($args);
271
+
272
+ echo wp_json_encode(array('message' => esc_html__("Deleted!", 'squirrly-seo')));
273
+ } else {
274
+ echo wp_json_encode(array('error' => esc_html__("Invalid params!", 'squirrly-seo')));
275
+ }
276
+ exit();
277
+ case 'sq_briefcase_deletefound':
278
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
279
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
280
+ SQ_Classes_Helpers_Tools::setHeader('json');
281
+ echo wp_json_encode($response);
282
+ exit();
283
+ }
284
+
285
+ SQ_Classes_Helpers_Tools::setHeader('json');
286
+ $keyword = (string)SQ_Classes_Helpers_Tools::getValue('keyword', '');
287
+
288
+ if ($keyword <> '') {
289
+ //set ignore on API
290
+ $args = array();
291
+ $args['keyword'] = stripslashes($keyword);
292
+ SQ_Classes_RemoteController::removeKrFound($args);
293
+
294
+ echo wp_json_encode(array('message' => esc_html__("Deleted!", 'squirrly-seo')));
295
+ } else {
296
+ echo wp_json_encode(array('error' => esc_html__("Invalid params!", 'squirrly-seo')));
297
+ }
298
+ exit();
299
+ /**********************************/
300
+ case 'sq_briefcase_addlabel':
301
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
302
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
303
+ SQ_Classes_Helpers_Tools::setHeader('json');
304
+ echo wp_json_encode($response);
305
+ exit();
306
+ }
307
+
308
+ SQ_Classes_Helpers_Tools::setHeader('json');
309
+
310
+ $name = (string)SQ_Classes_Helpers_Tools::getValue('name', '');
311
+ $color = (string)SQ_Classes_Helpers_Tools::getValue('color', '#ffffff');
312
+
313
+ if ($name <> '' && $color <> '') {
314
+ $args = array();
315
+
316
+ $args['name'] = $name;
317
+ $args['color'] = $color;
318
+ $json = SQ_Classes_RemoteController::addBriefcaseLabel($args);
319
+
320
+ if (!is_wp_error($json)) {
321
+ echo wp_json_encode(array('saved' => esc_html__("Saved!", 'squirrly-seo')));
322
+ } else {
323
+ echo wp_json_encode(array('error' => $json->get_error_message()));
324
+ }
325
+
326
+ } else {
327
+ echo wp_json_encode(array('error' => esc_html__("Invalid Label or Color!", 'squirrly-seo')));
328
+ }
329
+ exit();
330
+ case 'sq_briefcase_editlabel':
331
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
332
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
333
+ SQ_Classes_Helpers_Tools::setHeader('json');
334
+ echo wp_json_encode($response);
335
+ exit();
336
+ }
337
+
338
+ SQ_Classes_Helpers_Tools::setHeader('json');
339
+
340
+ $id = (int)SQ_Classes_Helpers_Tools::getValue('id', 0);
341
+ $name = (string)SQ_Classes_Helpers_Tools::getValue('name', 0);
342
+ $color = (string)SQ_Classes_Helpers_Tools::getValue('color', '#ffffff');
343
+
344
+ if ((int)$id > 0 && $name <> '' && $color <> '') {
345
+ $args = array();
346
+
347
+ $args['id'] = $id;
348
+ $args['name'] = $name;
349
+ $args['color'] = $color;
350
+ SQ_Classes_RemoteController::saveBriefcaseLabel($args);
351
+
352
+ echo wp_json_encode(array('saved' => esc_html__("Saved!", 'squirrly-seo')));
353
+ } else {
354
+ echo wp_json_encode(array('error' => esc_html__("Invalid params!", 'squirrly-seo')));
355
+ }
356
+ exit();
357
+ case 'sq_briefcase_deletelabel':
358
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippets')) {
359
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
360
+ SQ_Classes_Helpers_Tools::setHeader('json');
361
+ echo wp_json_encode($response);
362
+ exit();
363
+ }
364
+
365
+ SQ_Classes_Helpers_Tools::setHeader('json');
366
+
367
+ $id = (int)SQ_Classes_Helpers_Tools::getValue('id', 0);
368
+
369
+ if ($id > 0) {
370
+ //set ignore on API
371
+ $args = array();
372
+
373
+ $args['id'] = $id;
374
+ SQ_Classes_RemoteController::removeBriefcaseLabel($args);
375
+
376
+ echo wp_json_encode(array('deleted' => esc_html__("Deleted!", 'squirrly-seo')));
377
+ } else {
378
+ echo wp_json_encode(array('error' => esc_html__("Invalid params!", 'squirrly-seo')));
379
+ }
380
+ exit();
381
+ case 'sq_briefcase_keywordlabel':
382
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
383
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
384
+ SQ_Classes_Helpers_Tools::setHeader('json');
385
+ echo wp_json_encode($response);
386
+ exit();
387
+ }
388
+
389
+ SQ_Classes_Helpers_Tools::setHeader('json');
390
+
391
+ $keyword = (string)SQ_Classes_Helpers_Tools::getValue('keyword', '');
392
+ $labels = SQ_Classes_Helpers_Tools::getValue('labels', array());
393
+
394
+ if ($keyword <> '') {
395
+ $args = array();
396
+
397
+ $args['keyword'] = $keyword;
398
+ $args['labels'] = '';
399
+ if (is_array($labels) && !empty($labels)) {
400
+ $args['labels'] = join(',', $labels);
401
+ SQ_Classes_RemoteController::saveBriefcaseKeywordLabel($args);
402
+ } else {
403
+ SQ_Classes_RemoteController::saveBriefcaseKeywordLabel($args);
404
+
405
+ }
406
+ echo wp_json_encode(array('saved' => esc_html__("Saved!", 'squirrly-seo')));
407
+ } else {
408
+ echo wp_json_encode(array('error' => esc_html__("Invalid Keyword!", 'squirrly-seo')));
409
+ }
410
+ exit();
411
+ case 'sq_briefcase_backup':
412
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
413
+ SQ_Classes_Error::setError(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
414
+ return;
415
+ }
416
+
417
+ $args = array();
418
+ $args['limit'] = -1;
419
+ $briefcase = SQ_Classes_RemoteController::getBriefcase($args);
420
+
421
+ if(isset($briefcase->keywords) && !empty($briefcase->keywords)) {
422
+ $fp = fopen(_SQ_CACHE_DIR_ . 'file.txt', 'w');
423
+ foreach ($briefcase->keywords as $row) {
424
+ fwrite($fp, $row->keyword . PHP_EOL);
425
+ }
426
+ fclose($fp);
427
+
428
+ header("Content-type: text;");
429
+ header("Content-Encoding: UTF-8");
430
+ header("Content-Disposition: attachment; filename=squirrly-briefcase-" . gmdate('Y-m-d') . ".txt");
431
+ header("Pragma: no-cache");
432
+ header("Expires: 0");
433
+ readfile(_SQ_CACHE_DIR_ . 'file.txt');
434
+ }else{
435
+ SQ_Classes_Error::setError(esc_html__("No keywords in Briefcase to backup", 'squirrly-seo'), 'sq_error');
436
+ return;
437
+ }
438
+
439
+ exit();
440
+ case 'sq_briefcase_restore':
441
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
442
+ SQ_Classes_Error::setError(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
443
+ return;
444
+ }
445
+
446
+ if (!empty($_FILES['sq_upload_file']) && $_FILES['sq_upload_file']['tmp_name'] <> '') {
447
+ $fp = fopen($_FILES['sq_upload_file']['tmp_name'], 'rb');
448
+
449
+ try {
450
+ $data = '';
451
+ $keywords = array();
452
+
453
+ while (($line = fgets($fp)) !== false) {
454
+ $data .= $line;
455
+ }
456
+
457
+ if ($data = json_decode($data)) {
458
+ if (is_array($data) and !empty($data)) {
459
+ foreach ($data as $row) {
460
+ if (isset($row->keyword)) {
461
+ $keywords[] = $row->keyword;
462
+ }
463
+ }
464
+ }
465
+ } else {
466
+ //Get the data from CSV
467
+ $fp = fopen($_FILES['sq_upload_file']['tmp_name'], 'rb');
468
+
469
+ while (($data = fgetcsv($fp, 1000, ";")) !== false) {
470
+ if (!isset($data[0]) || $data[0] == '' || strlen($data[0]) > 255 || is_numeric($data[0])) {
471
+ SQ_Classes_Error::setError(esc_html__("Error! The backup is not valid.", 'squirrly-seo') . " <br /> ");
472
+ break;
473
+ }
474
+
475
+ if (is_string($data[0]) && $data[0] <> '') {
476
+ $keywords[] = strip_tags($data[0]);
477
+ }
478
+ }
479
+
480
+ if (empty($keywords)) {
481
+ $fp = fopen($_FILES['sq_upload_file']['tmp_name'], 'rb');
482
+
483
+ while (($data = fgetcsv($fp, 1000, ",")) !== false) {
484
+ if (!isset($data[0]) || $data[0] == '' || strlen($data[0]) > 255 || is_numeric($data[0])) {
485
+ SQ_Classes_Error::setError(esc_html__("Error! The backup is not valid.", 'squirrly-seo') . " <br /> ");
486
+ break;
487
+ }
488
+
489
+ if (is_string($data[0]) && $data[0] <> '') {
490
+ $keywords[] = strip_tags($data[0]);
491
+ }
492
+ }
493
+ }
494
+
495
+
496
+ }
497
+
498
+ if (!empty($keywords)) {
499
+ $keywords = array_chunk($keywords, 100);
500
+
501
+ foreach ($keywords as $chunk) {
502
+ SQ_Classes_RemoteController::importBriefcaseKeywords(array('keywords' => json_encode($chunk)));
503
+ }
504
+
505
+ SQ_Classes_Error::setError(esc_html__("Great! The backup is restored.", 'squirrly-seo') . " <br /> ", 'success');
506
+ } else {
507
+ SQ_Classes_Error::setError(esc_html__("Error! The backup is not valid.", 'squirrly-seo') . " <br /> ");
508
+ }
509
+ } catch (Exception $e) {
510
+ SQ_Classes_Error::setError(esc_html__("Error! The backup is not valid.", 'squirrly-seo') . " <br /> ");
511
+ }
512
+ } else {
513
+ SQ_Classes_Error::setError(esc_html__("Error! You have to enter a previously saved backup file.", 'squirrly-seo') . " <br /> ");
514
+ }
515
+ break;
516
+ case 'sq_briefcase_savemain':
517
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
518
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
519
+ SQ_Classes_Helpers_Tools::setHeader('json');
520
+ echo wp_json_encode($response);
521
+ exit();
522
+ }
523
+
524
+ SQ_Classes_Helpers_Tools::setHeader('json');
525
+
526
+ $post_id = (int)SQ_Classes_Helpers_Tools::getValue('post_id', 0);
527
+ $keyword = (string)SQ_Classes_Helpers_Tools::getValue('keyword', '');
528
+
529
+ if ((int)$post_id > 0 && $keyword <> '') {
530
+ $args = array();
531
+
532
+ $args['post_id'] = $post_id;
533
+ $args['keyword'] = $keyword;
534
+ SQ_Classes_RemoteController::saveBriefcaseMainKeyword($args);
535
+
536
+ echo wp_json_encode(array('saved' => esc_html__("Saved!", 'squirrly-seo')));
537
+ } else {
538
+ echo wp_json_encode(array('error' => esc_html__("Invalid params!", 'squirrly-seo')));
539
+ }
540
+ exit();
541
+ /*************************************************
542
+ *
543
+ * AJAX
544
+ */
545
+ case 'sq_ajax_briefcase_doserp':
546
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
547
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
548
+ SQ_Classes_Helpers_Tools::setHeader('json');
549
+ echo wp_json_encode($response);
550
+ exit();
551
+ }
552
+
553
+ SQ_Classes_Helpers_Tools::setHeader('json');
554
+
555
+ $json = array();
556
+ $keyword = (string)SQ_Classes_Helpers_Tools::getValue('keyword', '');
557
+
558
+ if ($keyword <> '') {
559
+ $args = array();
560
+ $args['keyword'] = $keyword;
561
+ if (SQ_Classes_RemoteController::addSerpKeyword($args) === false) {
562
+ $json['error'] = SQ_Classes_Error::showNotices(esc_html__("Could not add the keyword to SERP Check. Please try again.", 'squirrly-seo'), 'sq_error');
563
+ } else {
564
+ $json['message'] = SQ_Classes_Error::showNotices(esc_html__("The keyword is added to SERP Check.", 'squirrly-seo'), 'sq_success');
565
+ }
566
+ } else {
567
+ $json['error'] = SQ_Classes_Error::showNotices(esc_html__("Invalid parameters.", 'squirrly-seo'), 'sq_error');
568
+ }
569
+
570
+ SQ_Classes_Helpers_Tools::setHeader('json');
571
+ echo wp_json_encode($json);
572
+ exit();
573
+ case 'sq_ajax_research_others':
574
+ SQ_Classes_Helpers_Tools::setHeader('json');
575
+ $keyword = SQ_Classes_Helpers_Tools::getValue('keyword', false);
576
+ $country = SQ_Classes_Helpers_Tools::getValue('country', 'com');
577
+ $lang = SQ_Classes_Helpers_Tools::getValue('lang', 'en');
578
+
579
+ if ($keyword) {
580
+ $args = array();
581
+ $args['keyword'] = $keyword;
582
+ $args['country'] = $country;
583
+ $args['lang'] = $lang;
584
+ $json = SQ_Classes_RemoteController::getKROthers($args);
585
+
586
+ if (!is_wp_error($json)) {
587
+ if (isset($json->keywords)) {
588
+ echo wp_json_encode(array('keywords' => $json->keywords));
589
+ }
590
+ } else {
591
+ echo wp_json_encode(array('error' => $json->get_error_message()));
592
+ }
593
+ } else {
594
+ echo wp_json_encode(array('error' => esc_html__("Invalid params!", 'squirrly-seo')));
595
+ }
596
+
597
+ exit();
598
+ case 'sq_ajax_research_process':
599
+ SQ_Classes_Helpers_Tools::setHeader('json');
600
+ $keywords = SQ_Classes_Helpers_Tools::getValue('keywords', false);
601
+ $lang = SQ_Classes_Helpers_Tools::getValue('lang', 'en');
602
+ $country = SQ_Classes_Helpers_Tools::getValue('country', 'com');
603
+
604
+ $count = (int)SQ_Classes_Helpers_Tools::getValue('count', 10);
605
+ $id = (int)SQ_Classes_Helpers_Tools::getValue('id', 0);
606
+ $this->post_id = SQ_Classes_Helpers_Tools::getValue('post_id', false);
607
+
608
+ if ($id > 0) {
609
+ $args = array();
610
+ $args['id'] = $id;
611
+ $this->kr = SQ_Classes_RemoteController::getKRSuggestion($args);
612
+
613
+ if (!is_wp_error($this->kr)) {
614
+ if (!empty($this->kr)) {
615
+ //Get the briefcase keywords
616
+ if ($briefcase = SQ_Classes_RemoteController::getBriefcase()) {
617
+ if (!is_wp_error($briefcase)) {
618
+ if (isset($briefcase->keywords)) {
619
+ $this->keywords = $briefcase->keywords;
620
+ }
621
+ }
622
+ }
623
+
624
+ //research ready, return the results
625
+ echo wp_json_encode(array('done' => true, 'html' => $this->get_view('Research/ResearchDetails')));
626
+ } else {
627
+ //still loading
628
+ echo wp_json_encode(array('done' => false));
629
+ }
630
+ } else {
631
+ //show the keywords in results to be able to add them to brifcase
632
+ $keywords = explode(',', $keywords);
633
+ if (!empty($keywords)) {
634
+ foreach ($keywords as $keyword) {
635
+ $this->kr[] = json_decode(
636
+ wp_json_encode(
637
+ array(
638
+ 'keyword' => $keyword,
639
+ )
640
+ )
641
+ );
642
+ }
643
+ }
644
+ echo wp_json_encode(array('done' => true, 'html' => $this->get_view('Research/ResearchDetails')));
645
+
646
+ }
647
+ } elseif ($keywords) {
648
+ $args = array();
649
+ $args['q'] = $keywords;
650
+ $args['country'] = $country;
651
+ $args['lang'] = $lang;
652
+ $args['count'] = $count;
653
+ $process = SQ_Classes_RemoteController::setKRSuggestion($args);
654
+
655
+ if (!is_wp_error($process)) {
656
+ if (isset($process->id)) {
657
+ //Get the briefcase keywords
658
+ echo wp_json_encode(array('done' => false, 'id' => $process->id));
659
+
660
+ }
661
+ } else {
662
+ if ($process->get_error_code() == 'limit_exceeded') {
663
+ echo wp_json_encode(array('done' => true, 'error' => esc_html__("Keyword Research limit exceeded", 'squirrly-seo')));
664
+ } else {
665
+ echo wp_json_encode(array('done' => true, 'error' => $process->get_error_message()));
666
+ }
667
+ }
668
+ } else {
669
+ echo wp_json_encode(array('done' => true, 'error' => esc_html__("Invalid params!", 'squirrly-seo')));
670
+ }
671
+ exit();
672
+ case 'sq_ajax_research_history':
673
+ SQ_Classes_Helpers_Tools::setHeader('json');
674
+ $id = (int)SQ_Classes_Helpers_Tools::getValue('id', 0);
675
+
676
+ if ($id > 0) {
677
+ $args = $this->kr = array();
678
+ $args['id'] = $id;
679
+ $krHistory = SQ_Classes_RemoteController::getKRHistory($args);
680
+
681
+ if (!empty($krHistory)) { //get only the first report
682
+ $this->kr = current($krHistory);
683
+ }
684
+
685
+ //Get the briefcase keywords
686
+ if ($briefcase = SQ_Classes_RemoteController::getBriefcase()) {
687
+ if (!is_wp_error($briefcase)) {
688
+ if (isset($briefcase->keywords)) {
689
+ $this->keywords = $briefcase->keywords;
690
+ }
691
+ }
692
+ }
693
+
694
+ echo wp_json_encode(array('html' => $this->get_view('Research/HistoryDetails')));
695
+ } else {
696
+ echo wp_json_encode(array('error' => esc_html__("Invalid params!", 'squirrly-seo')));
697
+ }
698
+ exit();
699
+
700
+ case 'sq_ajax_briefcase_bulk_delete':
701
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
702
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
703
+ SQ_Classes_Helpers_Tools::setHeader('json');
704
+ echo wp_json_encode($response);
705
+ exit();
706
+ }
707
+
708
+ SQ_Classes_Helpers_Tools::setHeader('json');
709
+ $keywords = SQ_Classes_Helpers_Tools::getValue('inputs', array());
710
+
711
+ if (!empty($keywords)) {
712
+ foreach ($keywords as $keyword) {
713
+ //set ignore on API
714
+ $args = array();
715
+ $args['keyword'] = stripslashes($keyword);
716
+ SQ_Classes_RemoteController::removeBriefcaseKeyword($args);
717
+ }
718
+
719
+ echo wp_json_encode(array('message' => esc_html__("Deleted!", 'squirrly-seo')));
720
+ } else {
721
+ echo wp_json_encode(array('error' => esc_html__("Invalid params!", 'squirrly-seo')));
722
+ }
723
+ exit();
724
+ case 'sq_ajax_briefcase_bulk_label':
725
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
726
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
727
+ SQ_Classes_Helpers_Tools::setHeader('json');
728
+ echo wp_json_encode($response);
729
+ exit();
730
+ }
731
+
732
+ SQ_Classes_Helpers_Tools::setHeader('json');
733
+
734
+ $keywords = SQ_Classes_Helpers_Tools::getValue('inputs', array());
735
+ $labels = SQ_Classes_Helpers_Tools::getValue('labels', array());
736
+
737
+ if (!empty($keywords)) {
738
+ foreach ($keywords as $keyword) {
739
+ $args = array();
740
+
741
+ $args['keyword'] = $keyword;
742
+ $args['labels'] = '';
743
+ if (is_array($labels) && !empty($labels)) {
744
+ $args['labels'] = join(',', $labels);
745
+ SQ_Classes_RemoteController::saveBriefcaseKeywordLabel($args);
746
+ } else {
747
+ SQ_Classes_RemoteController::saveBriefcaseKeywordLabel($args);
748
+
749
+ }
750
+ }
751
+
752
+ echo wp_json_encode(array('message' => esc_html__("Saved!", 'squirrly-seo')));
753
+ } else {
754
+ echo wp_json_encode(array('error' => esc_html__("Invalid Keyword!", 'squirrly-seo')));
755
+ }
756
+
757
+ exit();
758
+ case 'sq_ajax_briefcase_bulk_doserp':
759
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
760
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
761
+ SQ_Classes_Helpers_Tools::setHeader('json');
762
+ echo wp_json_encode($response);
763
+ exit();
764
+ }
765
+
766
+ SQ_Classes_Helpers_Tools::setHeader('json');
767
+
768
+ $keywords = SQ_Classes_Helpers_Tools::getValue('inputs', array());
769
+
770
+ if (!empty($keywords)) {
771
+ foreach ($keywords as $keyword) {
772
+ $args = array();
773
+ $args['keyword'] = $keyword;
774
+ SQ_Classes_RemoteController::addSerpKeyword($args);
775
+
776
+ }
777
+
778
+ echo wp_json_encode(array('message' => esc_html__("The keywords are added to SERP Check!", 'squirrly-seo')));
779
+ } else {
780
+ echo wp_json_encode(array('error' => esc_html__("Invalid Keyword!", 'squirrly-seo')));
781
+ }
782
+ exit();
783
+
784
+ case 'sq_ajax_labels_bulk_delete':
785
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
786
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
787
+ SQ_Classes_Helpers_Tools::setHeader('json');
788
+ echo wp_json_encode($response);
789
+ exit();
790
+ }
791
+
792
+ SQ_Classes_Helpers_Tools::setHeader('json');
793
+ $inputs = SQ_Classes_Helpers_Tools::getValue('inputs', array());
794
+
795
+ if (!empty($inputs)) {
796
+ foreach ($inputs as $id) {
797
+ if ($id > 0) {
798
+ $args = array();
799
+ $args['id'] = $id;
800
+ SQ_Classes_RemoteController::removeBriefcaseLabel($args);
801
+ }
802
+ }
803
+
804
+ echo wp_json_encode(array('message' => esc_html__("Deleted!", 'squirrly-seo')));
805
+ } else {
806
+ echo wp_json_encode(array('error' => esc_html__("Invalid params!", 'squirrly-seo')));
807
+ }
808
+ exit();
809
+ }
810
+
811
+
812
+ }
813
+ }
controllers/SeoSettings.php CHANGED
@@ -1,843 +1,878 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- class SQ_Controllers_SeoSettings extends SQ_Classes_FrontController {
5
-
6
- public $pages = array();
7
-
8
- function init() {
9
- $tab = SQ_Classes_Helpers_Tools::getValue('tab', 'automation');
10
-
11
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap-reboot');
12
- if (is_rtl()) {
13
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('popper');
14
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap.rtl');
15
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('rtl');
16
- } else {
17
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap');
18
- }
19
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap-select');
20
-
21
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('switchery');
22
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('fontawesome');
23
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('global');
24
-
25
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('assistant');
26
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('navbar');
27
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('seosettings');
28
-
29
- if (method_exists($this, $tab)) {
30
- call_user_func(array($this, $tab));
31
- }
32
-
33
- if (function_exists('wp_enqueue_media')) {
34
- wp_enqueue_media();
35
- wp_enqueue_style('media-views');
36
- }
37
-
38
- //@ob_flush();
39
- echo $this->getView('SeoSettings/' . ucfirst($tab));
40
-
41
- //get the modal window for the assistant popup
42
- echo SQ_Classes_ObjController::getClass('SQ_Models_Assistant')->getModal();
43
- }
44
-
45
- public function gotoImport() {
46
- $_GET['tab'] = 'backup';
47
- return $this->init();
48
- }
49
-
50
- public function automation() {
51
- add_action('sq_form_notices', array($this, 'getNotificationBar'));
52
-
53
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('highlight');
54
- SQ_Classes_ObjController::getClass('SQ_Controllers_Patterns')->init();
55
- }
56
-
57
- public function metas() {
58
- add_action('sq_form_notices', array($this, 'getNotificationBar'));
59
-
60
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('highlight');
61
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('snippet');
62
- }
63
-
64
- public function links() {
65
- add_action('sq_form_notices', array($this, 'getNotificationBar'));
66
-
67
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('highlight');
68
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('snippet');
69
- }
70
-
71
- public function jsonld() {
72
- add_action('sq_form_notices', array($this, 'getNotificationBar'));
73
- }
74
-
75
- public function social() {
76
- add_action('sq_form_notices', array($this, 'getNotificationBar'));
77
- }
78
-
79
- public function tracking() {
80
- add_action('sq_form_notices', array($this, 'getNotificationBar'));
81
- }
82
-
83
- public function webmaster() {
84
- add_action('sq_form_notices', array($this, 'getNotificationBar'));
85
- }
86
-
87
- public function sitemap() {
88
- add_action('sq_form_notices', array($this, 'getNotificationBar'));
89
- }
90
-
91
- public function robots() {
92
- add_action('sq_form_notices', array($this, 'getNotificationBar'));
93
- }
94
-
95
- public function favicon() {
96
- add_action('sq_form_notices', array($this, 'getNotificationBar'));
97
- }
98
-
99
- public function backup() {
100
- add_filter('sq_themes', array(SQ_Classes_ObjController::getClass('SQ_Models_ImportExport'), 'getAvailableThemes'), 10, 1);
101
- add_filter('sq_importList', array(SQ_Classes_ObjController::getClass('SQ_Models_ImportExport'), 'importList'));
102
- }
103
-
104
-
105
- public function hookFooter() {
106
- if (!SQ_Classes_Helpers_Tools::getOption('sq_seoexpert')) {
107
- echo "<script>jQuery('.sq_advanced').hide();</script>";
108
- } else {
109
- echo "<script>jQuery('.sq_advanced').show();</script>";
110
- }
111
- }
112
-
113
- /**
114
- * Called when action is triggered
115
- *
116
- * @return void
117
- */
118
- public function action() {
119
- parent::action();
120
-
121
- switch (SQ_Classes_Helpers_Tools::getValue('action')) {
122
-
123
- case 'sq_seosettings_links':
124
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
125
- return;
126
- }
127
-
128
- //Save the settings
129
- if (!empty($_POST)) {
130
- SQ_Classes_ObjController::getClass('SQ_Models_Settings')->saveValues($_POST);
131
- }
132
-
133
- //Save custom robots
134
- $links = SQ_Classes_Helpers_Tools::getValue('links_permission', '', true);
135
- $links = explode(PHP_EOL, $links);
136
- $links = str_replace("\r", "", $links);
137
-
138
- if (!empty($links)) {
139
- SQ_Classes_Helpers_Tools::$options['sq_external_exception'] = array_unique($links);
140
- }
141
-
142
- //save the options in database
143
- SQ_Classes_Helpers_Tools::saveOptions();
144
-
145
- //show the saved message
146
- if (!SQ_Classes_Error::isError()) SQ_Classes_Error::setMessage(esc_html__("Saved", _SQ_PLUGIN_NAME_));
147
-
148
- break;
149
-
150
- ///////////////////////////////////////////SEO SETTINGS METAS
151
- case 'sq_seosettings_metas':
152
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
153
- return;
154
- }
155
-
156
- //Save the settings
157
- if (!empty($_POST)) {
158
- SQ_Classes_ObjController::getClass('SQ_Models_Settings')->saveValues($_POST);
159
- }
160
-
161
- ///////////////////////////////////////////
162
- /////////////////////////////FIRST PAGE OPTIMIZATION
163
- $url = home_url();
164
- $post = SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->setHomePage();
165
-
166
- $post->sq->doseo = 1;
167
- $post->sq->title = urldecode(SQ_Classes_Helpers_Tools::getValue('sq_fp_title', false));
168
- $post->sq->description = urldecode(SQ_Classes_Helpers_Tools::getValue('sq_fp_description', false));
169
- $post->sq->keywords = SQ_Classes_Helpers_Tools::getValue('sq_fp_keywords', false);
170
-
171
- if (SQ_Classes_Helpers_Tools::getIsset('sq_fp_ogimage')) {
172
- $post->sq->og_media = SQ_Classes_Helpers_Tools::getValue('sq_fp_ogimage', '');
173
- }
174
-
175
- SQ_Classes_ObjController::getClass('SQ_Models_Qss')->saveSqSEO(
176
- $url,
177
- md5('wp_homepage'),
178
- maybe_serialize(array(
179
- 'ID' => 0,
180
- 'post_type' => 'home',
181
- 'term_id' => 0,
182
- 'taxonomy' => '',
183
- )),
184
- maybe_serialize($post->sq->toArray()),
185
- gmdate('Y-m-d H:i:s')
186
- );
187
-
188
- //reset the report time
189
- SQ_Classes_Helpers_Tools::saveOptions('seoreport_time', false);
190
-
191
- //show the saved message
192
- if (!SQ_Classes_Error::isError()) SQ_Classes_Error::setMessage(esc_html__("Saved", _SQ_PLUGIN_NAME_));
193
-
194
- break;
195
-
196
- ///////////////////////////////////////////SEO SETTINGS AUTOMATION
197
- case 'sq_seosettings_automation':
198
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
199
- return;
200
- }
201
-
202
- //Save the settings
203
- if (!empty($_POST)) {
204
- SQ_Classes_ObjController::getClass('SQ_Models_Settings')->saveValues($_POST);
205
- }
206
-
207
-
208
- //show the saved message
209
- if (!SQ_Classes_Error::isError()) SQ_Classes_Error::setMessage(esc_html__("Saved", _SQ_PLUGIN_NAME_));
210
-
211
- break;
212
- ///////////////////////////////////////////SEO SETTINGS METAS
213
- case 'sq_seosettings_social':
214
- case 'sq_seosettings_tracking':
215
- case 'sq_seosettings_webmaster':
216
- case 'sq_seosettings_advanced':
217
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
218
- return;
219
- }
220
-
221
- //Save the settings
222
- if (!empty($_POST)) {
223
- SQ_Classes_ObjController::getClass('SQ_Models_Settings')->saveValues($_POST);
224
- }
225
-
226
- //save the options in database
227
- SQ_Classes_Helpers_Tools::saveOptions();
228
-
229
- //reset the report time
230
- SQ_Classes_Helpers_Tools::saveOptions('seoreport_time', false);
231
-
232
- //show the saved message
233
- if (!SQ_Classes_Error::isError()) SQ_Classes_Error::setMessage(esc_html__("Saved", _SQ_PLUGIN_NAME_));
234
-
235
-
236
- break;
237
-
238
- ///////////////////////////////////////////SEO SETTINGS METAS
239
- case 'sq_seosettings_sitemap':
240
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
241
- return;
242
- }
243
-
244
- //Save the settings
245
- if (!empty($_POST)) {
246
- SQ_Classes_ObjController::getClass('SQ_Models_Settings')->saveValues($_POST);
247
- }
248
-
249
- //Make sure we get the Sitemap data from the form
250
- if ($sitemap = SQ_Classes_Helpers_Tools::getValue('sitemap', false)) {
251
- foreach (SQ_Classes_Helpers_Tools::$options['sq_sitemap'] as $key => $value) {
252
- if (isset($sitemap[$key])) {
253
- SQ_Classes_Helpers_Tools::$options['sq_sitemap'][$key][1] = (int)$sitemap[$key];
254
- } elseif ($key <> 'sitemap') {
255
- SQ_Classes_Helpers_Tools::$options['sq_sitemap'][$key][1] = 0;
256
- }
257
- }
258
- }
259
-
260
- //save the options in database
261
- SQ_Classes_Helpers_Tools::saveOptions();
262
-
263
- //delete other sitemap xml files from root
264
- if (SQ_Classes_Helpers_Tools::getOption('sq_auto_sitemap') && file_exists(ABSPATH . "/" . 'sitemap.xml')) {
265
- @rename(ABSPATH . "/" . 'sitemap.xml', ABSPATH . "/" . 'sitemap_ren' . time() . '.xml');
266
- }
267
-
268
- //reset the report time
269
- SQ_Classes_Helpers_Tools::saveOptions('seoreport_time', false);
270
-
271
- //show the saved message
272
- if (!SQ_Classes_Error::isError()) SQ_Classes_Error::setMessage(esc_html__("Saved", _SQ_PLUGIN_NAME_));
273
-
274
- break;
275
-
276
- //Save the JSON-LD page from SEO Settings
277
- case 'sq_seosettings_jsonld':
278
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
279
- return;
280
- }
281
-
282
- //Save the settings
283
- if (!empty($_POST)) {
284
- SQ_Classes_ObjController::getClass('SQ_Models_Settings')->saveValues($_POST);
285
- }
286
-
287
- if (SQ_Classes_Helpers_Tools::$options['sq_jsonld']['Person']['telephone'] <> '') {
288
- SQ_Classes_Helpers_Tools::$options['sq_jsonld']['Person']['telephone'] = '+' . ltrim(SQ_Classes_Helpers_Tools::$options['sq_jsonld']['Person']['telephone'], '+');
289
- }
290
- if (SQ_Classes_Helpers_Tools::$options['sq_jsonld']['Organization']['contactPoint']['telephone'] <> '') {
291
- SQ_Classes_Helpers_Tools::$options['sq_jsonld']['Organization']['contactPoint']['telephone'] = '+' . ltrim(SQ_Classes_Helpers_Tools::$options['sq_jsonld']['Organization']['contactPoint']['telephone'], '+');
292
- }
293
-
294
- //save the options in database
295
- SQ_Classes_Helpers_Tools::saveOptions();
296
-
297
- //reset the report time
298
- SQ_Classes_Helpers_Tools::saveOptions('seoreport_time', false);
299
-
300
- //show the saved message
301
- if (!SQ_Classes_Error::isError()) SQ_Classes_Error::setMessage(esc_html__("Saved", _SQ_PLUGIN_NAME_));
302
-
303
- break;
304
-
305
- //Save the Robots permissions
306
- case 'sq_seosettings_robots':
307
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
308
- return;
309
- }
310
-
311
- //Save the settings
312
- if (!empty($_POST)) {
313
- SQ_Classes_ObjController::getClass('SQ_Models_Settings')->saveValues($_POST);
314
- }
315
-
316
- //Save custom robots
317
- $robots = SQ_Classes_Helpers_Tools::getValue('robots_permission', '', true);
318
- $robots = explode(PHP_EOL, $robots);
319
- $robots = str_replace("\r", "", $robots);
320
-
321
- if (!empty($robots)) {
322
- SQ_Classes_Helpers_Tools::$options['sq_robots_permission'] = array_unique($robots);
323
- }
324
-
325
- //save the options in database
326
- SQ_Classes_Helpers_Tools::saveOptions();
327
-
328
- //reset the report time
329
- SQ_Classes_Helpers_Tools::saveOptions('seoreport_time', false);
330
-
331
- //show the saved message
332
- if (!SQ_Classes_Error::isError()) SQ_Classes_Error::setMessage(esc_html__("Saved", _SQ_PLUGIN_NAME_));
333
-
334
-
335
- break;
336
-
337
- //Save the Favicon image
338
- case 'sq_seosettings_favicon':
339
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
340
- return;
341
- }
342
-
343
- //If the favicon is turned off delete the favicon image created
344
- if (!SQ_Classes_Helpers_Tools::getValue('sq_auto_favicon') &&
345
- SQ_Classes_Helpers_Tools::getOption('sq_auto_favicon') &&
346
- SQ_Classes_Helpers_Tools::getOption('favicon') <> '' &&
347
- file_exists(ABSPATH . "/" . 'favicon.ico')) {
348
- @rename(ABSPATH . "/" . 'favicon.ico', ABSPATH . "/" . 'favicon_ren' . time() . '.ico');
349
- }
350
-
351
- //Save the settings
352
- if (!empty($_POST)) {
353
- SQ_Classes_ObjController::getClass('SQ_Models_Settings')->saveValues($_POST);
354
- }
355
-
356
- /* if there is an icon to upload */
357
- if (!empty($_FILES['favicon'])) {
358
- if ($return = SQ_Classes_ObjController::getClass('SQ_Models_Ico')->addFavicon($_FILES['favicon'])) {
359
- if ($return['favicon'] <> '') {
360
- SQ_Classes_Helpers_Tools::saveOptions('favicon', strtolower(basename($return['favicon'])));
361
- }
362
- }
363
- }
364
-
365
-
366
- break;
367
- case 'sq_seosettings_ga_revoke':
368
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
369
- return;
370
- }
371
-
372
- //remove connection with Google Analytics
373
- $response = SQ_Classes_RemoteController::revokeGaConnection();
374
- if (!is_wp_error($response)) {
375
- SQ_Classes_Error::setError(esc_html__("Google Analytics account is disconnected.", _SQ_PLUGIN_NAME_) . " <br /> ", 'success');
376
- } else {
377
- SQ_Classes_Error::setError(esc_html__("Error! Could not disconnect the account.", _SQ_PLUGIN_NAME_) . " <br /> ");
378
- }
379
- break;
380
- case 'sq_seosettings_gsc_revoke':
381
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
382
- return;
383
- }
384
-
385
- //remove connection with Google Search Console
386
- $response = SQ_Classes_RemoteController::revokeGscConnection();
387
- if (!is_wp_error($response)) {
388
- SQ_Classes_Error::setError(esc_html__("Google Search Console account is disconnected.", _SQ_PLUGIN_NAME_) . " <br /> ", 'success');
389
- } else {
390
- SQ_Classes_Error::setError(esc_html__("Error! Could not disconnect the account.", _SQ_PLUGIN_NAME_) . " <br /> ");
391
- }
392
- break;
393
- case 'sq_seosettings_ga_check':
394
- case 'sq_seosettings_gsc_check':
395
- case 'sq_seosettings_clear_cache':
396
-
397
- //Refresh the checkin on login
398
- delete_transient('sq_checkin');
399
-
400
- break;
401
- case 'sq_seosettings_ga_save':
402
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
403
- return;
404
- }
405
-
406
- $property_id = SQ_Classes_Helpers_Tools::getValue('property_id', false);
407
-
408
- if ($property_id) {
409
- $args = array();
410
- $args['property_id'] = $property_id;
411
- SQ_Classes_RemoteController::saveGAProperties($args);
412
- }
413
-
414
- SQ_Classes_Error::setMessage(esc_html__("Saved", _SQ_PLUGIN_NAME_));
415
- break;
416
- case 'sq_seosettings_backupsettings':
417
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
418
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
419
- SQ_Classes_Helpers_Tools::setHeader('json');
420
- echo wp_json_encode($response);
421
- exit();
422
- }
423
-
424
- SQ_Classes_Helpers_Tools::setHeader('text');
425
- header("Content-Disposition: attachment; filename=squirrly-settings-" . gmdate('Y-m-d') . ".txt");
426
-
427
- if (function_exists('base64_encode')) {
428
- echo base64_encode(wp_json_encode(SQ_Classes_Helpers_Tools::$options));
429
- } else {
430
- echo wp_json_encode(SQ_Classes_Helpers_Tools::$options);
431
- }
432
- exit();
433
- case 'sq_seosettings_restoresettings':
434
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
435
- return;
436
- }
437
-
438
- if (!empty($_FILES['sq_options']) && $_FILES['sq_options']['tmp_name'] <> '') {
439
- $fp = fopen($_FILES['sq_options']['tmp_name'], 'rb');
440
- $options = '';
441
- while (($line = fgets($fp)) !== false) {
442
- $options .= $line;
443
- }
444
- try {
445
- if (function_exists('base64_encode') && base64_decode($options) <> '') {
446
- $options = @base64_decode($options);
447
- }
448
- $options = json_decode($options, true);
449
- if (is_array($options) && isset($options['sq_api'])) {
450
- if (SQ_Classes_Helpers_Tools::getOption('sq_api') <> '') {
451
- $options['sq_api'] = SQ_Classes_Helpers_Tools::getOption('sq_api');
452
- }
453
- if (SQ_Classes_Helpers_Tools::getOption('sq_seojourney') <> '') {
454
- $options['sq_seojourney'] = SQ_Classes_Helpers_Tools::getOption('sq_seojourney');
455
- }
456
- SQ_Classes_Helpers_Tools::$options = $options;
457
- SQ_Classes_Helpers_Tools::saveOptions();
458
-
459
- //Check if there is an old backup from Squirrly
460
- SQ_Classes_Helpers_Tools::getOptions();
461
-
462
- //reset the report time
463
- SQ_Classes_Helpers_Tools::saveOptions('seoreport_time', false);
464
-
465
- SQ_Classes_Error::setError(esc_html__("Great! The backup is restored.", _SQ_PLUGIN_NAME_) . " <br /> ", 'success');
466
- } else {
467
- SQ_Classes_Error::setError(esc_html__("Error! The backup is not valid.", _SQ_PLUGIN_NAME_) . " <br /> ");
468
- }
469
- } catch (Exception $e) {
470
- SQ_Classes_Error::setError(esc_html__("Error! The backup is not valid.", _SQ_PLUGIN_NAME_) . " <br /> ");
471
- }
472
- } else {
473
- SQ_Classes_Error::setError(esc_html__("Error! You have to enter a previously saved backup file.", _SQ_PLUGIN_NAME_) . " <br /> ");
474
- }
475
- break;
476
- case 'sq_seosettings_backupseo':
477
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
478
- return;
479
- }
480
-
481
- header('Content-Type: application/octet-stream');
482
- header("Content-Transfer-Encoding: Binary");
483
- header("Content-Disposition: attachment; filename=squirrly-seo-" . gmdate('Y-m-d') . ".sql");
484
-
485
- if (function_exists('base64_encode')) {
486
- echo base64_encode(SQ_Classes_ObjController::getClass('SQ_Models_ImportExport')->createTableBackup());
487
- } else {
488
- echo SQ_Classes_ObjController::getClass('SQ_Models_ImportExport')->createTableBackup();
489
- }
490
- exit();
491
- case 'sq_seosettings_restoreseo':
492
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
493
- return;
494
- }
495
-
496
- if (!empty($_FILES['sq_sql']) && $_FILES['sq_sql']['tmp_name'] <> '') {
497
- $fp = fopen($_FILES['sq_sql']['tmp_name'], 'rb');
498
- $sql_file = '';
499
- while (($line = fgets($fp)) !== false) {
500
- $sql_file .= $line;
501
- }
502
-
503
- if (function_exists('base64_encode')) {
504
- $sql_file = @base64_decode($sql_file);
505
- }
506
-
507
- if ($sql_file <> '' && strpos($sql_file, 'INSERT INTO') !== false) {
508
- try {
509
-
510
- $queries = explode("INSERT INTO", $sql_file);
511
- SQ_Classes_ObjController::getClass('SQ_Models_ImportExport')->executeSql($queries);
512
- SQ_Classes_Error::setError(esc_html__("Great! The SEO backup is restored.", _SQ_PLUGIN_NAME_) . " <br /> ", 'success');
513
-
514
- } catch (Exception $e) {
515
- SQ_Classes_Error::setError(esc_html__("Error! The backup is not valid.", _SQ_PLUGIN_NAME_) . " <br /> ");
516
- }
517
- } else {
518
- SQ_Classes_Error::setError(esc_html__("Error! The backup is not valid.", _SQ_PLUGIN_NAME_) . " <br /> ");
519
- }
520
- } else {
521
- SQ_Classes_Error::setError(esc_html__("Error! You have to enter a previously saved backup file.", _SQ_PLUGIN_NAME_) . " <br /> ");
522
- }
523
- break;
524
- case 'sq_seosettings_importall':
525
- $platform = SQ_Classes_Helpers_Tools::getValue('sq_import_platform', '');
526
- if ($platform <> '') {
527
- try {
528
- SQ_Classes_ObjController::getClass('SQ_Models_ImportExport')->importDBSettings($platform);
529
- $seo = SQ_Classes_ObjController::getClass('SQ_Models_ImportExport')->importDBSeo($platform);
530
- if (!empty($seo)) {
531
- //Check if the Squirrly Table Exists
532
- SQ_Classes_ObjController::getClass('SQ_Models_Qss')->checkTableExists();
533
-
534
- foreach ($seo as $sq_hash => $metas) {
535
- SQ_Classes_ObjController::getClass('SQ_Models_Qss')->saveSqSEO(
536
- (isset($metas['url']) ? $metas['url'] : ''),
537
- $sq_hash,
538
- maybe_serialize(array(
539
- 'ID' => (isset($metas['post_id']) ? (int)$metas['post_id'] : 0),
540
- 'post_type' => (isset($metas['post_type']) ? $metas['post_type'] : ''),
541
- 'term_id' => (isset($metas['term_id']) ? (int)$metas['term_id'] : 0),
542
- 'taxonomy' => (isset($metas['taxonomy']) ? $metas['taxonomy'] : ''),
543
- )),
544
- maybe_serialize($metas),
545
- gmdate('Y-m-d H:i:s'));
546
- }
547
- }
548
-
549
- SQ_Classes_Error::setMessage(sprintf(esc_html__("Success! The import from %s was completed successfully and your SEO is safe!", _SQ_PLUGIN_NAME_), SQ_Classes_ObjController::getClass('SQ_Models_ImportExport')->getName($platform)));
550
- } catch (Exception $e) {
551
- SQ_Classes_Error::setMessage(esc_html__("Error! An error occured while import. Please try again.", _SQ_PLUGIN_NAME_));
552
- }
553
- }
554
- break;
555
- case 'sq_seosettings_importsettings':
556
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
557
- return;
558
- }
559
-
560
- $platform = SQ_Classes_Helpers_Tools::getValue('sq_import_platform', '');
561
- if ($platform <> '') {
562
- if (SQ_Classes_ObjController::getClass('SQ_Models_ImportExport')->importDBSettings($platform)) {
563
- SQ_Classes_Error::setMessage(esc_html__("All the Plugin settings were imported successfuly!", _SQ_PLUGIN_NAME_));
564
- } else {
565
- SQ_Classes_Error::setMessage(esc_html__("No settings found for this plugin/theme.", _SQ_PLUGIN_NAME_));
566
- }
567
- }
568
- break;
569
- case 'sq_seosettings_importseo':
570
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
571
- return;
572
- }
573
-
574
- $platform = SQ_Classes_Helpers_Tools::getValue('sq_import_platform', '');
575
- $overwrite = SQ_Classes_Helpers_Tools::getValue('sq_import_overwrite', false);
576
-
577
- if ($platform <> '') {
578
- $seo = SQ_Classes_ObjController::getClass('SQ_Models_ImportExport')->importDBSeo($platform);
579
-
580
- if (!empty($seo)) {
581
- foreach ($seo as $sq_hash => $metas) {
582
- $sq = SQ_Classes_ObjController::getClass('SQ_Models_Qss')->getSqSeo($sq_hash);
583
-
584
- if ($overwrite || !($sq->title && $sq->description)) {
585
-
586
- SQ_Classes_ObjController::getClass('SQ_Models_Qss')->saveSqSEO(
587
- (isset($metas['url']) ? $metas['url'] : ''),
588
- $sq_hash,
589
- maybe_serialize(array(
590
- 'ID' => (isset($metas['post_id']) ? (int)$metas['post_id'] : 0),
591
- 'post_type' => (isset($metas['post_type']) ? $metas['post_type'] : ''),
592
- 'term_id' => (isset($metas['term_id']) ? (int)$metas['term_id'] : 0),
593
- 'taxonomy' => (isset($metas['taxonomy']) ? $metas['taxonomy'] : ''),
594
- )),
595
- maybe_serialize($metas),
596
- gmdate('Y-m-d H:i:s'));
597
-
598
- }
599
- }
600
- }
601
-
602
- SQ_Classes_Error::setMessage(sprintf(esc_html__("Success! The import from %s was completed successfully and your SEO is safe!", _SQ_PLUGIN_NAME_), SQ_Classes_ObjController::getClass('SQ_Models_ImportExport')->getName($platform)));
603
- }
604
- break;
605
- case 'sq_rollback':
606
- SQ_Classes_Helpers_Tools::setHeader('html');
607
- $plugin_slug = basename(_SQ_PLUGIN_NAME_, '.php');
608
-
609
-
610
- $rollback = SQ_Classes_ObjController::getClass('SQ_Models_Rollback');
611
-
612
- $rollback->set_plugin(array(
613
- 'version' => SQ_STABLE_VERSION,
614
- 'plugin_name' => _SQ_ROOT_DIR_,
615
- 'plugin_slug' => $plugin_slug,
616
- 'package_url' => sprintf('https://downloads.wordpress.org/plugin/%s.%s.zip', $plugin_slug, SQ_STABLE_VERSION),
617
- ));
618
-
619
- $rollback->run();
620
-
621
- wp_die(
622
- '', esc_html__("Rollback to Previous Version", _SQ_PLUGIN_NAME_), [
623
- 'response' => 200,
624
- ]
625
- );
626
- exit();
627
- case 'sq_reinstall':
628
- SQ_Classes_Helpers_Tools::setHeader('html');
629
- $plugin_slug = basename(_SQ_PLUGIN_NAME_, '.php');
630
-
631
-
632
- $rollback = SQ_Classes_ObjController::getClass('SQ_Models_Rollback');
633
-
634
- $rollback->set_plugin(array(
635
- 'version' => SQ_VERSION,
636
- 'plugin_name' => _SQ_ROOT_DIR_,
637
- 'plugin_slug' => $plugin_slug,
638
- 'package_url' => sprintf('https://downloads.wordpress.org/plugin/%s.%s.zip', $plugin_slug, SQ_VERSION),
639
- ));
640
-
641
- $rollback->run();
642
-
643
- wp_die(
644
- '', esc_html__("Reinstall Current Version", _SQ_PLUGIN_NAME_), [
645
- 'response' => 200,
646
- ]
647
- );
648
- exit();
649
- case 'sq_alerts_close':
650
- //remove the specified alert from showing again
651
- if ($alert = SQ_Classes_Helpers_Tools::getValue('alert', false)) {
652
- if (in_array($alert, array('sq_alert_overview', 'sq_alert_journey'))) {
653
- SQ_Classes_Helpers_Tools::saveOptions($alert, false);
654
- }
655
- }
656
- break;
657
- /**************************** Ajax *******************************************************/
658
- case 'sq_ajax_seosettings_save':
659
- SQ_Classes_Helpers_Tools::setHeader('json');
660
- $response = array();
661
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
662
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
663
- echo wp_json_encode($response);
664
- exit();
665
- }
666
-
667
-
668
- $name = SQ_Classes_Helpers_Tools::getValue('input', false);
669
- $value = SQ_Classes_Helpers_Tools::getValue('value', false);
670
-
671
- if (isset(SQ_Classes_Helpers_Tools::$options[$name])) {
672
- SQ_Classes_Helpers_Tools::saveOptions($name, $value);
673
- $response['data'] = SQ_Classes_Error::showNotices(esc_html__("Saved", _SQ_PLUGIN_NAME_), 'sq_success');
674
- } else {
675
- $response['data'] = SQ_Classes_Error::showNotices(esc_html__("Could not save the changes", _SQ_PLUGIN_NAME_), 'sq_error');
676
-
677
- }
678
-
679
- echo wp_json_encode($response);
680
- exit();
681
- case 'sq_ajax_sla_sticky':
682
- SQ_Classes_Helpers_Tools::setHeader('json');
683
-
684
- $response = array();
685
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
686
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
687
- echo wp_json_encode($response);
688
- exit();
689
- }
690
-
691
- SQ_Classes_Helpers_Tools::saveUserMeta('sq_auto_sticky', (int)SQ_Classes_Helpers_Tools::getValue('sq_auto_sticky'));
692
- echo wp_json_encode(array());
693
- exit();
694
- case 'sq_ajax_gsc_code':
695
- SQ_Classes_Helpers_Tools::setHeader('json');
696
-
697
- $response = array();
698
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
699
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
700
- echo wp_json_encode($response);
701
- exit();
702
- }
703
-
704
- //remove connection with Google Analytics
705
- $code = SQ_Classes_RemoteController::getGSCToken();
706
-
707
- if (!is_wp_error($code) && $code) {
708
- $response['code'] = SQ_Classes_Helpers_Sanitize::checkGoogleWTCode($code);
709
- } else {
710
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("Error! Could not get the code. Connect to Google Search Console and validate the connection.", _SQ_PLUGIN_NAME_), 'sq_error');
711
- }
712
-
713
- echo wp_json_encode($response);
714
- exit();
715
- case 'sq_ajax_ga_code':
716
- SQ_Classes_Helpers_Tools::setHeader('json');
717
-
718
- $response = array();
719
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
720
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
721
- echo wp_json_encode($response);
722
- exit();
723
- }
724
-
725
- //remove connection with Google Analytics
726
- $code = SQ_Classes_RemoteController::getGAToken();
727
- if (!is_wp_error($code) && $code) {
728
- $response['code'] = $code;
729
- } else {
730
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("Error! Could not get the tracking code. Connect to Google Analytics and get the website tracking code from Admin area.", _SQ_PLUGIN_NAME_), 'sq_error');
731
- }
732
- echo wp_json_encode($response);
733
- exit();
734
- case 'sq_ajax_connection_check':
735
- SQ_Classes_Helpers_Tools::setHeader('json');
736
-
737
- $response = array();
738
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
739
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
740
- echo wp_json_encode($response);
741
- exit();
742
- }
743
-
744
- //delete local checking cache
745
- delete_transient('sq_checkin');
746
- //check the connection again
747
- SQ_Classes_RemoteController::checkin();
748
-
749
- echo wp_json_encode(array());
750
- exit();
751
-
752
-
753
- /************************ Automation ********************************************************/
754
- case 'sq_ajax_automation_addpostype':
755
- SQ_Classes_Helpers_Tools::setHeader('json');
756
- $response = array();
757
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
758
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
759
- echo wp_json_encode($response);
760
- exit();
761
- }
762
-
763
- //Get the new post type
764
- $posttype = SQ_Classes_Helpers_Tools::getValue('value', false);
765
- $filter = array('public' => true, '_builtin' => false);
766
- $types = get_post_types($filter);
767
- foreach ($types as $pattern => $type) {
768
- if($post_type_obj = get_post_type_object( $pattern )){
769
- if($post_type_obj->has_archive) {
770
- $types['archive-' . $pattern] = 'archive-' . $pattern;
771
- }
772
- }
773
- }
774
-
775
- $filter = array('public' => true,);
776
- $taxonomies = get_taxonomies($filter);
777
- foreach ($taxonomies as $pattern => $type) {
778
- $types['tax-' . $pattern] = 'tax-' . $pattern;
779
- }
780
-
781
- //If the post type is in the list of types
782
- if ($posttype && in_array($posttype, $types)) {
783
- $patterns = SQ_Classes_Helpers_Tools::getOption('patterns');
784
- //if the post type does not already exists
785
- if (!isset($patterns[$posttype])) {
786
- //add the custom rights to the new post type
787
- $patterns[$posttype] = $patterns['custom'];
788
- $patterns[$posttype]['protected'] = 0;
789
- //save the options in database
790
- SQ_Classes_Helpers_Tools::saveOptions('patterns', $patterns);
791
-
792
- $response['data'] = SQ_Classes_Error::showNotices(esc_html__("Saved", _SQ_PLUGIN_NAME_), 'sq_success');
793
- echo wp_json_encode($response);
794
- exit();
795
- }
796
- }
797
-
798
-
799
- //Return error in case the post is not saved
800
- $response['data'] = SQ_Classes_Error::showNotices(esc_html__("Could not add the post type.", _SQ_PLUGIN_NAME_), 'sq_error');
801
- echo wp_json_encode($response);
802
- exit();
803
- case 'sq_ajax_automation_deletepostype':
804
- SQ_Classes_Helpers_Tools::setHeader('json');
805
- $response = array();
806
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
807
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
808
- echo wp_json_encode($response);
809
- exit();
810
- }
811
-
812
-
813
- //Get the new post type
814
- $posttype = SQ_Classes_Helpers_Tools::getValue('value', false);
815
-
816
- //If the post type is in the list of types
817
- if ($posttype && $posttype <> '') {
818
- $patterns = SQ_Classes_Helpers_Tools::getOption('patterns');
819
- //if the post type exists in the patterns
820
- if (isset($patterns[$posttype])) {
821
- //add the custom rights to the new post type
822
- unset($patterns[$posttype]);
823
-
824
- //save the options in database
825
- SQ_Classes_Helpers_Tools::saveOptions('patterns', $patterns);
826
-
827
- $response['data'] = SQ_Classes_Error::showNotices(esc_html__("Saved", _SQ_PLUGIN_NAME_), 'sq_success');
828
- echo wp_json_encode($response);
829
- exit();
830
- }
831
- }
832
-
833
-
834
- //Return error in case the post is not saved
835
- $response['data'] = SQ_Classes_Error::showNotices(esc_html__("Could not add the post type.", _SQ_PLUGIN_NAME_), 'sq_error');
836
- echo wp_json_encode($response);
837
- exit();
838
-
839
- }
840
-
841
- }
842
-
843
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ class SQ_Controllers_SeoSettings extends SQ_Classes_FrontController
5
+ {
6
+
7
+ public $pages = array();
8
+
9
+ function init()
10
+ {
11
+ $tab = preg_replace("/[^a-zA-Z0-9]/", "", SQ_Classes_Helpers_Tools::getValue('tab', 'automation'));
12
+
13
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap-reboot');
14
+ if (is_rtl()) {
15
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('popper');
16
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap.rtl');
17
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('rtl');
18
+ } else {
19
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap');
20
+ }
21
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('bootstrap-select');
22
+
23
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('switchery');
24
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('fontawesome');
25
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('global');
26
+
27
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('assistant');
28
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('navbar');
29
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('seosettings');
30
+
31
+ if (method_exists($this, $tab)) {
32
+ call_user_func(array($this, $tab));
33
+ }
34
+
35
+ if (function_exists('wp_enqueue_media')) {
36
+ wp_enqueue_media();
37
+ wp_enqueue_style('media-views');
38
+ }
39
+
40
+ //@ob_flush();
41
+ $this->show_view('SeoSettings/' . esc_attr(ucfirst($tab)));
42
+
43
+ //get the modal window for the assistant popup
44
+ echo SQ_Classes_ObjController::getClass('SQ_Models_Assistant')->getModal();
45
+ }
46
+
47
+ public function gotoImport()
48
+ {
49
+ $_GET['tab'] = 'backup';
50
+ return $this->init();
51
+ }
52
+
53
+ public function automation()
54
+ {
55
+ add_action('sq_form_notices', array($this, 'getNotificationBar'));
56
+
57
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('highlight');
58
+ SQ_Classes_ObjController::getClass('SQ_Controllers_Patterns')->init();
59
+ }
60
+
61
+ public function metas()
62
+ {
63
+ add_action('sq_form_notices', array($this, 'getNotificationBar'));
64
+
65
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('highlight');
66
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('snippet');
67
+ }
68
+
69
+ public function links()
70
+ {
71
+ add_action('sq_form_notices', array($this, 'getNotificationBar'));
72
+
73
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('highlight');
74
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('snippet');
75
+ }
76
+
77
+ public function jsonld()
78
+ {
79
+ add_action('sq_form_notices', array($this, 'getNotificationBar'));
80
+ }
81
+
82
+ public function social()
83
+ {
84
+ add_action('sq_form_notices', array($this, 'getNotificationBar'));
85
+ }
86
+
87
+ public function tracking()
88
+ {
89
+ add_action('sq_form_notices', array($this, 'getNotificationBar'));
90
+ }
91
+
92
+ public function webmaster()
93
+ {
94
+ add_action('sq_form_notices', array($this, 'getNotificationBar'));
95
+ }
96
+
97
+ public function sitemap()
98
+ {
99
+ add_action('sq_form_notices', array($this, 'getNotificationBar'));
100
+ }
101
+
102
+ public function robots()
103
+ {
104
+ add_action('sq_form_notices', array($this, 'getNotificationBar'));
105
+ }
106
+
107
+ public function favicon()
108
+ {
109
+ add_action('sq_form_notices', array($this, 'getNotificationBar'));
110
+ }
111
+
112
+ public function backup()
113
+ {
114
+ add_filter('sq_themes', array(SQ_Classes_ObjController::getClass('SQ_Models_ImportExport'), 'getAvailableThemes'), 10, 1);
115
+ add_filter('sq_importList', array(SQ_Classes_ObjController::getClass('SQ_Models_ImportExport'), 'importList'));
116
+ }
117
+
118
+
119
+ public function hookFooter()
120
+ {
121
+ if (!SQ_Classes_Helpers_Tools::getOption('sq_seoexpert')) {
122
+ echo "<script>jQuery('.sq_advanced').hide();</script>";
123
+ } else {
124
+ echo "<script>jQuery('.sq_advanced').show();</script>";
125
+ }
126
+ }
127
+
128
+ /**
129
+ * Called when action is triggered
130
+ *
131
+ * @return void
132
+ */
133
+ public function action()
134
+ {
135
+ parent::action();
136
+
137
+ switch (SQ_Classes_Helpers_Tools::getValue('action')) {
138
+
139
+ case 'sq_seosettings_links':
140
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
141
+ return;
142
+ }
143
+
144
+ //Save the settings
145
+ if (!empty($_POST)) {
146
+ SQ_Classes_ObjController::getClass('SQ_Models_Settings')->saveValues($_POST);
147
+ }
148
+
149
+ //Save custom robots
150
+ $links = SQ_Classes_Helpers_Tools::getValue('links_permission', '', true);
151
+ $links = explode(PHP_EOL, $links);
152
+ $links = str_replace("\r", "", $links);
153
+
154
+ if (!empty($links)) {
155
+ SQ_Classes_Helpers_Tools::$options['sq_external_exception'] = array_unique($links);
156
+ }
157
+
158
+ //save the options in database
159
+ SQ_Classes_Helpers_Tools::saveOptions();
160
+
161
+ //show the saved message
162
+ if (!SQ_Classes_Error::isError()) SQ_Classes_Error::setMessage(esc_html__("Saved", 'squirrly-seo'));
163
+
164
+ break;
165
+
166
+ ///////////////////////////////////////////SEO SETTINGS METAS
167
+ case 'sq_seosettings_metas':
168
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
169
+ return;
170
+ }
171
+
172
+ //Save the settings
173
+ if (!empty($_POST)) {
174
+ SQ_Classes_ObjController::getClass('SQ_Models_Settings')->saveValues($_POST);
175
+ }
176
+
177
+ ///////////////////////////////////////////
178
+ /////////////////////////////FIRST PAGE OPTIMIZATION
179
+ $url = home_url();
180
+ $post = SQ_Classes_ObjController::getClass('SQ_Models_Snippet')->setHomePage();
181
+
182
+ $post->sq->doseo = 1;
183
+ $post->sq->title = urldecode(SQ_Classes_Helpers_Tools::getValue('sq_fp_title', false));
184
+ $post->sq->description = urldecode(SQ_Classes_Helpers_Tools::getValue('sq_fp_description', false));
185
+ $post->sq->keywords = SQ_Classes_Helpers_Tools::getValue('sq_fp_keywords', false);
186
+
187
+ if (SQ_Classes_Helpers_Tools::getIsset('sq_fp_ogimage')) {
188
+ $post->sq->og_media = SQ_Classes_Helpers_Tools::getValue('sq_fp_ogimage', '');
189
+ }
190
+
191
+ SQ_Classes_ObjController::getClass('SQ_Models_Qss')->saveSqSEO(
192
+ $url,
193
+ md5('wp_homepage'),
194
+ maybe_serialize(
195
+ array(
196
+ 'ID' => 0,
197
+ 'post_type' => 'home',
198
+ 'term_id' => 0,
199
+ 'taxonomy' => '',
200
+ )
201
+ ),
202
+ maybe_serialize($post->sq->toArray()),
203
+ gmdate('Y-m-d H:i:s')
204
+ );
205
+
206
+ //reset the report time
207
+ SQ_Classes_Helpers_Tools::saveOptions('seoreport_time', false);
208
+
209
+ //show the saved message
210
+ if (!SQ_Classes_Error::isError()) SQ_Classes_Error::setMessage(esc_html__("Saved", 'squirrly-seo'));
211
+
212
+ break;
213
+
214
+ ///////////////////////////////////////////SEO SETTINGS AUTOMATION
215
+ case 'sq_seosettings_automation':
216
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
217
+ return;
218
+ }
219
+
220
+ //Save the settings
221
+ if (!empty($_POST)) {
222
+ SQ_Classes_ObjController::getClass('SQ_Models_Settings')->saveValues($_POST);
223
+ }
224
+
225
+
226
+ //show the saved message
227
+ if (!SQ_Classes_Error::isError()) SQ_Classes_Error::setMessage(esc_html__("Saved", 'squirrly-seo'));
228
+
229
+ break;
230
+ ///////////////////////////////////////////SEO SETTINGS METAS
231
+ case 'sq_seosettings_social':
232
+ case 'sq_seosettings_tracking':
233
+ case 'sq_seosettings_webmaster':
234
+ case 'sq_seosettings_advanced':
235
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
236
+ return;
237
+ }
238
+
239
+ //Save the settings
240
+ if (!empty($_POST)) {
241
+ SQ_Classes_ObjController::getClass('SQ_Models_Settings')->saveValues($_POST);
242
+ }
243
+
244
+ //save the options in database
245
+ SQ_Classes_Helpers_Tools::saveOptions();
246
+
247
+ //reset the report time
248
+ SQ_Classes_Helpers_Tools::saveOptions('seoreport_time', false);
249
+
250
+ //show the saved message
251
+ if (!SQ_Classes_Error::isError()) SQ_Classes_Error::setMessage(esc_html__("Saved", 'squirrly-seo'));
252
+
253
+
254
+ break;
255
+
256
+ ///////////////////////////////////////////SEO SETTINGS METAS
257
+ case 'sq_seosettings_sitemap':
258
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
259
+ return;
260
+ }
261
+
262
+ //Save the settings
263
+ if (!empty($_POST)) {
264
+ SQ_Classes_ObjController::getClass('SQ_Models_Settings')->saveValues($_POST);
265
+ }
266
+
267
+ //Make sure we get the Sitemap data from the form
268
+ if ($sitemap = SQ_Classes_Helpers_Tools::getValue('sitemap', false)) {
269
+ foreach (SQ_Classes_Helpers_Tools::$options['sq_sitemap'] as $key => $value) {
270
+ if (isset($sitemap[$key])) {
271
+ SQ_Classes_Helpers_Tools::$options['sq_sitemap'][$key][1] = (int)$sitemap[$key];
272
+ } elseif ($key <> 'sitemap') {
273
+ SQ_Classes_Helpers_Tools::$options['sq_sitemap'][$key][1] = 0;
274
+ }
275
+ }
276
+ }
277
+
278
+ //save the options in database
279
+ SQ_Classes_Helpers_Tools::saveOptions();
280
+
281
+ //delete other sitemap xml files from root
282
+ if (SQ_Classes_Helpers_Tools::getOption('sq_auto_sitemap') && file_exists(ABSPATH . "/" . 'sitemap.xml')) {
283
+ @rename(ABSPATH . "/" . 'sitemap.xml', ABSPATH . "/" . 'sitemap_ren' . time() . '.xml');
284
+ }
285
+
286
+ //reset the report time
287
+ SQ_Classes_Helpers_Tools::saveOptions('seoreport_time', false);
288
+
289
+ //show the saved message
290
+ if (!SQ_Classes_Error::isError()) SQ_Classes_Error::setMessage(esc_html__("Saved", 'squirrly-seo'));
291
+
292
+ break;
293
+
294
+ //Save the JSON-LD page from SEO Settings
295
+ case 'sq_seosettings_jsonld':
296
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
297
+ return;
298
+ }
299
+
300
+ //Save the settings
301
+ if (!empty($_POST)) {
302
+ SQ_Classes_ObjController::getClass('SQ_Models_Settings')->saveValues($_POST);
303
+ }
304
+
305
+ if (SQ_Classes_Helpers_Tools::$options['sq_jsonld']['Person']['telephone'] <> '') {
306
+ SQ_Classes_Helpers_Tools::$options['sq_jsonld']['Person']['telephone'] = '+' . ltrim(SQ_Classes_Helpers_Tools::$options['sq_jsonld']['Person']['telephone'], '+');
307
+ }
308
+ if (SQ_Classes_Helpers_Tools::$options['sq_jsonld']['Organization']['contactPoint']['telephone'] <> '') {
309
+ SQ_Classes_Helpers_Tools::$options['sq_jsonld']['Organization']['contactPoint']['telephone'] = '+' . ltrim(SQ_Classes_Helpers_Tools::$options['sq_jsonld']['Organization']['contactPoint']['telephone'], '+');
310
+ }
311
+
312
+ //save the options in database
313
+ SQ_Classes_Helpers_Tools::saveOptions();
314
+
315
+ //reset the report time
316
+ SQ_Classes_Helpers_Tools::saveOptions('seoreport_time', false);
317
+
318
+ //show the saved message
319
+ if (!SQ_Classes_Error::isError()) SQ_Classes_Error::setMessage(esc_html__("Saved", 'squirrly-seo'));
320
+
321
+ break;
322
+
323
+ //Save the Robots permissions
324
+ case 'sq_seosettings_robots':
325
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
326
+ return;
327
+ }
328
+
329
+ //Save the settings
330
+ if (!empty($_POST)) {
331
+ SQ_Classes_ObjController::getClass('SQ_Models_Settings')->saveValues($_POST);
332
+ }
333
+
334
+ //Save custom robots
335
+ $robots = SQ_Classes_Helpers_Tools::getValue('robots_permission', '', true);
336
+ $robots = explode(PHP_EOL, $robots);
337
+ $robots = str_replace("\r", "", $robots);
338
+
339
+ if (!empty($robots)) {
340
+ SQ_Classes_Helpers_Tools::$options['sq_robots_permission'] = array_unique($robots);
341
+ }
342
+
343
+ //save the options in database
344
+ SQ_Classes_Helpers_Tools::saveOptions();
345
+
346
+ //reset the report time
347
+ SQ_Classes_Helpers_Tools::saveOptions('seoreport_time', false);
348
+
349
+ //show the saved message
350
+ if (!SQ_Classes_Error::isError()) SQ_Classes_Error::setMessage(esc_html__("Saved", 'squirrly-seo'));
351
+
352
+
353
+ break;
354
+
355
+ //Save the Favicon image
356
+ case 'sq_seosettings_favicon':
357
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
358
+ return;
359
+ }
360
+
361
+ //If the favicon is turned off delete the favicon image created
362
+ if (!SQ_Classes_Helpers_Tools::getValue('sq_auto_favicon')
363
+ && SQ_Classes_Helpers_Tools::getOption('sq_auto_favicon')
364
+ && SQ_Classes_Helpers_Tools::getOption('favicon') <> ''
365
+ && file_exists(ABSPATH . "/" . 'favicon.ico')
366
+ ) {
367
+ @rename(ABSPATH . "/" . 'favicon.ico', ABSPATH . "/" . 'favicon_ren' . time() . '.ico');
368
+ }
369
+
370
+ //Save the settings
371
+ if (!empty($_POST)) {
372
+ SQ_Classes_ObjController::getClass('SQ_Models_Settings')->saveValues($_POST);
373
+ }
374
+
375
+ /* if there is an icon to upload */
376
+ if (!empty($_FILES['favicon'])) {
377
+ if ($return = SQ_Classes_ObjController::getClass('SQ_Models_Ico')->addFavicon($_FILES['favicon'])) {
378
+ if ($return['favicon'] <> '') {
379
+ SQ_Classes_Helpers_Tools::saveOptions('favicon', strtolower(basename($return['favicon'])));
380
+ }
381
+ }
382
+ }
383
+
384
+
385
+ break;
386
+ case 'sq_seosettings_ga_revoke':
387
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
388
+ return;
389
+ }
390
+
391
+ //remove connection with Google Analytics
392
+ $response = SQ_Classes_RemoteController::revokeGaConnection();
393
+ if (!is_wp_error($response)) {
394
+ SQ_Classes_Error::setError(esc_html__("Google Analytics account is disconnected.", 'squirrly-seo') . " <br /> ", 'success');
395
+ } else {
396
+ SQ_Classes_Error::setError(esc_html__("Error! Could not disconnect the account.", 'squirrly-seo') . " <br /> ");
397
+ }
398
+ break;
399
+ case 'sq_seosettings_gsc_revoke':
400
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
401
+ return;
402
+ }
403
+
404
+ //remove connection with Google Search Console
405
+ $response = SQ_Classes_RemoteController::revokeGscConnection();
406
+ if (!is_wp_error($response)) {
407
+ SQ_Classes_Error::setError(esc_html__("Google Search Console account is disconnected.", 'squirrly-seo') . " <br /> ", 'success');
408
+ } else {
409
+ SQ_Classes_Error::setError(esc_html__("Error! Could not disconnect the account.", 'squirrly-seo') . " <br /> ");
410
+ }
411
+ break;
412
+ case 'sq_seosettings_ga_check':
413
+ case 'sq_seosettings_gsc_check':
414
+ case 'sq_seosettings_clear_cache':
415
+
416
+ //Refresh the checkin on login
417
+ delete_transient('sq_checkin');
418
+
419
+ break;
420
+ case 'sq_seosettings_ga_save':
421
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
422
+ return;
423
+ }
424
+
425
+ $property_id = SQ_Classes_Helpers_Tools::getValue('property_id', false);
426
+
427
+ if ($property_id) {
428
+ $args = array();
429
+ $args['property_id'] = $property_id;
430
+ SQ_Classes_RemoteController::saveGAProperties($args);
431
+ }
432
+
433
+ SQ_Classes_Error::setMessage(esc_html__("Saved", 'squirrly-seo'));
434
+ break;
435
+ case 'sq_seosettings_backupsettings':
436
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
437
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
438
+ SQ_Classes_Helpers_Tools::setHeader('json');
439
+ echo wp_json_encode($response);
440
+ exit();
441
+ }
442
+
443
+ SQ_Classes_Helpers_Tools::setHeader('text');
444
+ header("Content-Disposition: attachment; filename=squirrly-settings-" . gmdate('Y-m-d') . ".txt");
445
+
446
+ if (function_exists('base64_encode')) {
447
+ echo base64_encode(wp_json_encode(SQ_Classes_Helpers_Tools::$options));
448
+ } else {
449
+ echo wp_json_encode(SQ_Classes_Helpers_Tools::$options);
450
+ }
451
+ exit();
452
+ case 'sq_seosettings_restoresettings':
453
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
454
+ return;
455
+ }
456
+
457
+ if (!empty($_FILES['sq_options']) && $_FILES['sq_options']['tmp_name'] <> '') {
458
+ $fp = fopen($_FILES['sq_options']['tmp_name'], 'rb');
459
+ $options = '';
460
+ while (($line = fgets($fp)) !== false) {
461
+ $options .= $line;
462
+ }
463
+ try {
464
+ if (function_exists('base64_encode') && base64_decode($options) <> '') {
465
+ $options = @base64_decode($options);
466
+ }
467
+ $options = json_decode($options, true);
468
+ if (is_array($options) && isset($options['sq_api'])) {
469
+ if (SQ_Classes_Helpers_Tools::getOption('sq_api') <> '') {
470
+ $options['sq_api'] = SQ_Classes_Helpers_Tools::getOption('sq_api');
471
+ }
472
+ if (SQ_Classes_Helpers_Tools::getOption('sq_seojourney') <> '') {
473
+ $options['sq_seojourney'] = SQ_Classes_Helpers_Tools::getOption('sq_seojourney');
474
+ }
475
+ SQ_Classes_Helpers_Tools::$options = $options;
476
+ SQ_Classes_Helpers_Tools::saveOptions();
477
+
478
+ //Check if there is an old backup from Squirrly
479
+ SQ_Classes_Helpers_Tools::getOptions();
480
+
481
+ //reset the report time
482
+ SQ_Classes_Helpers_Tools::saveOptions('seoreport_time', false);
483
+
484
+ SQ_Classes_Error::setError(esc_html__("Great! The backup is restored.", 'squirrly-seo') . " <br /> ", 'success');
485
+ } else {
486
+ SQ_Classes_Error::setError(esc_html__("Error! The backup is not valid.", 'squirrly-seo') . " <br /> ");
487
+ }
488
+ } catch (Exception $e) {
489
+ SQ_Classes_Error::setError(esc_html__("Error! The backup is not valid.", 'squirrly-seo') . " <br /> ");
490
+ }
491
+ } else {
492
+ SQ_Classes_Error::setError(esc_html__("Error! You have to enter a previously saved backup file.", 'squirrly-seo') . " <br /> ");
493
+ }
494
+ break;
495
+ case 'sq_seosettings_backupseo':
496
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
497
+ return;
498
+ }
499
+
500
+ header('Content-Type: application/octet-stream');
501
+ header("Content-Transfer-Encoding: Binary");
502
+ header("Content-Disposition: attachment; filename=squirrly-seo-" . gmdate('Y-m-d') . ".sql");
503
+
504
+ if (function_exists('base64_encode')) {
505
+ echo base64_encode(SQ_Classes_ObjController::getClass('SQ_Models_ImportExport')->createTableBackup());
506
+ } else {
507
+ echo SQ_Classes_ObjController::getClass('SQ_Models_ImportExport')->createTableBackup();
508
+ }
509
+ exit();
510
+ case 'sq_seosettings_restoreseo':
511
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
512
+ return;
513
+ }
514
+
515
+ if (!empty($_FILES['sq_sql']) && $_FILES['sq_sql']['tmp_name'] <> '') {
516
+ $fp = fopen($_FILES['sq_sql']['tmp_name'], 'rb');
517
+ $sql_file = '';
518
+ while (($line = fgets($fp)) !== false) {
519
+ $sql_file .= $line;
520
+ }
521
+
522
+ if (function_exists('base64_encode')) {
523
+ $sql_file = @base64_decode($sql_file);
524
+ }
525
+
526
+ if ($sql_file <> '' && strpos($sql_file, 'INSERT INTO') !== false) {
527
+ try {
528
+
529
+ $queries = explode("INSERT INTO", $sql_file);
530
+ SQ_Classes_ObjController::getClass('SQ_Models_ImportExport')->executeSql($queries);
531
+ SQ_Classes_Error::setError(esc_html__("Great! The SEO backup is restored.", 'squirrly-seo') . " <br /> ", 'success');
532
+
533
+ } catch (Exception $e) {
534
+ SQ_Classes_Error::setError(esc_html__("Error! The backup is not valid.", 'squirrly-seo') . " <br /> ");
535
+ }
536
+ } else {
537
+ SQ_Classes_Error::setError(esc_html__("Error! The backup is not valid.", 'squirrly-seo') . " <br /> ");
538
+ }
539
+ } else {
540
+ SQ_Classes_Error::setError(esc_html__("Error! You have to enter a previously saved backup file.", 'squirrly-seo') . " <br /> ");
541
+ }
542
+ break;
543
+ case 'sq_seosettings_importall':
544
+ $platform = SQ_Classes_Helpers_Tools::getValue('sq_import_platform', '');
545
+ if ($platform <> '') {
546
+ try {
547
+ SQ_Classes_ObjController::getClass('SQ_Models_ImportExport')->importDBSettings($platform);
548
+ $seo = SQ_Classes_ObjController::getClass('SQ_Models_ImportExport')->importDBSeo($platform);
549
+ if (!empty($seo)) {
550
+ //Check if the Squirrly Table Exists
551
+ SQ_Classes_ObjController::getClass('SQ_Models_Qss')->checkTableExists();
552
+
553
+ foreach ($seo as $sq_hash => $metas) {
554
+ SQ_Classes_ObjController::getClass('SQ_Models_Qss')->saveSqSEO(
555
+ (isset($metas['url']) ? $metas['url'] : ''),
556
+ $sq_hash,
557
+ maybe_serialize(
558
+ array(
559
+ 'ID' => (isset($metas['post_id']) ? (int)$metas['post_id'] : 0),
560
+ 'post_type' => (isset($metas['post_type']) ? $metas['post_type'] : ''),
561
+ 'term_id' => (isset($metas['term_id']) ? (int)$metas['term_id'] : 0),
562
+ 'taxonomy' => (isset($metas['taxonomy']) ? $metas['taxonomy'] : ''),
563
+ )
564
+ ),
565
+ maybe_serialize($metas),
566
+ gmdate('Y-m-d H:i:s')
567
+ );
568
+ }
569
+ }
570
+
571
+ SQ_Classes_Error::setMessage(sprintf(esc_html__("Success! The import from %s was completed successfully and your SEO is safe!", 'squirrly-seo'), SQ_Classes_ObjController::getClass('SQ_Models_ImportExport')->getName($platform)));
572
+ } catch (Exception $e) {
573
+ SQ_Classes_Error::setMessage(esc_html__("Error! An error occured while import. Please try again.", 'squirrly-seo'));
574
+ }
575
+ }
576
+ break;
577
+ case 'sq_seosettings_importsettings':
578
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
579
+ return;
580
+ }
581
+
582
+ $platform = SQ_Classes_Helpers_Tools::getValue('sq_import_platform', '');
583
+ if ($platform <> '') {
584
+ if (SQ_Classes_ObjController::getClass('SQ_Models_ImportExport')->importDBSettings($platform)) {
585
+ SQ_Classes_Error::setMessage(esc_html__("All the Plugin settings were imported successfuly!", 'squirrly-seo'));
586
+ } else {
587
+ SQ_Classes_Error::setMessage(esc_html__("No settings found for this plugin/theme.", 'squirrly-seo'));
588
+ }
589
+ }
590
+ break;
591
+ case 'sq_seosettings_importseo':
592
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
593
+ return;
594
+ }
595
+
596
+ $platform = SQ_Classes_Helpers_Tools::getValue('sq_import_platform', '');
597
+ $overwrite = SQ_Classes_Helpers_Tools::getValue('sq_import_overwrite', false);
598
+
599
+ if ($platform <> '') {
600
+ $seo = SQ_Classes_ObjController::getClass('SQ_Models_ImportExport')->importDBSeo($platform);
601
+
602
+ if (!empty($seo)) {
603
+ foreach ($seo as $sq_hash => $metas) {
604
+ $sq = SQ_Classes_ObjController::getClass('SQ_Models_Qss')->getSqSeo($sq_hash);
605
+
606
+ if ($overwrite || !($sq->title && $sq->description)) {
607
+
608
+ SQ_Classes_ObjController::getClass('SQ_Models_Qss')->saveSqSEO(
609
+ (isset($metas['url']) ? $metas['url'] : ''),
610
+ $sq_hash,
611
+ maybe_serialize(
612
+ array(
613
+ 'ID' => (isset($metas['post_id']) ? (int)$metas['post_id'] : 0),
614
+ 'post_type' => (isset($metas['post_type']) ? $metas['post_type'] : ''),
615
+ 'term_id' => (isset($metas['term_id']) ? (int)$metas['term_id'] : 0),
616
+ 'taxonomy' => (isset($metas['taxonomy']) ? $metas['taxonomy'] : ''),
617
+ )
618
+ ),
619
+ maybe_serialize($metas),
620
+ gmdate('Y-m-d H:i:s')
621
+ );
622
+
623
+ }
624
+ }
625
+ }
626
+
627
+ SQ_Classes_Error::setMessage(sprintf(esc_html__("Success! The import from %s was completed successfully and your SEO is safe!", 'squirrly-seo'), SQ_Classes_ObjController::getClass('SQ_Models_ImportExport')->getName($platform)));
628
+ }
629
+ break;
630
+ case 'sq_rollback':
631
+ SQ_Classes_Helpers_Tools::setHeader('html');
632
+ $plugin_slug = basename(_SQ_PLUGIN_NAME_, '.php');
633
+
634
+
635
+ $rollback = SQ_Classes_ObjController::getClass('SQ_Models_Rollback');
636
+
637
+ $rollback->set_plugin(
638
+ array(
639
+ 'version' => SQ_STABLE_VERSION,
640
+ 'plugin_name' => _SQ_ROOT_DIR_,
641
+ 'plugin_slug' => $plugin_slug,
642
+ 'package_url' => sprintf('https://downloads.wordpress.org/plugin/%s.%s.zip', $plugin_slug, SQ_STABLE_VERSION),
643
+ )
644
+ );
645
+
646
+ $rollback->run();
647
+
648
+ wp_die(
649
+ '', esc_html__("Rollback to Previous Version", 'squirrly-seo'), [
650
+ 'response' => 200,
651
+ ]
652
+ );
653
+ exit();
654
+ case 'sq_reinstall':
655
+ SQ_Classes_Helpers_Tools::setHeader('html');
656
+ $plugin_slug = basename(_SQ_PLUGIN_NAME_, '.php');
657
+
658
+
659
+ $rollback = SQ_Classes_ObjController::getClass('SQ_Models_Rollback');
660
+
661
+ $rollback->set_plugin(
662
+ array(
663
+ 'version' => SQ_VERSION,
664
+ 'plugin_name' => _SQ_ROOT_DIR_,
665
+ 'plugin_slug' => $plugin_slug,
666
+ 'package_url' => sprintf('https://downloads.wordpress.org/plugin/%s.%s.zip', $plugin_slug, SQ_VERSION),
667
+ )
668
+ );
669
+
670
+ $rollback->run();
671
+
672
+ wp_die(
673
+ '', esc_html__("Reinstall Current Version", 'squirrly-seo'), [
674
+ 'response' => 200,
675
+ ]
676
+ );
677
+ exit();
678
+ case 'sq_alerts_close':
679
+ //remove the specified alert from showing again
680
+ if ($alert = SQ_Classes_Helpers_Tools::getValue('alert', false)) {
681
+ if (in_array($alert, array('sq_alert_overview', 'sq_alert_journey'))) {
682
+ SQ_Classes_Helpers_Tools::saveOptions($alert, false);
683
+ }
684
+ }
685
+ break;
686
+ /****************************
687
+ *
688
+ * Ajax
689
+ *******************************************************/
690
+ case 'sq_ajax_seosettings_save':
691
+ SQ_Classes_Helpers_Tools::setHeader('json');
692
+ $response = array();
693
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
694
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
695
+ echo wp_json_encode($response);
696
+ exit();
697
+ }
698
+
699
+
700
+ $name = SQ_Classes_Helpers_Tools::getValue('input', false);
701
+ $value = SQ_Classes_Helpers_Tools::getValue('value', false);
702
+
703
+ if (isset(SQ_Classes_Helpers_Tools::$options[$name])) {
704
+ SQ_Classes_Helpers_Tools::saveOptions($name, $value);
705
+ $response['data'] = SQ_Classes_Error::showNotices(esc_html__("Saved", 'squirrly-seo'), 'sq_success');
706
+ } else {
707
+ $response['data'] = SQ_Classes_Error::showNotices(esc_html__("Could not save the changes", 'squirrly-seo'), 'sq_error');
708
+
709
+ }
710
+
711
+ echo wp_json_encode($response);
712
+ exit();
713
+ case 'sq_ajax_sla_sticky':
714
+ SQ_Classes_Helpers_Tools::setHeader('json');
715
+
716
+ $response = array();
717
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
718
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
719
+ echo wp_json_encode($response);
720
+ exit();
721
+ }
722
+
723
+ SQ_Classes_Helpers_Tools::saveUserMeta('sq_auto_sticky', (int)SQ_Classes_Helpers_Tools::getValue('sq_auto_sticky'));
724
+ echo wp_json_encode(array());
725
+ exit();
726
+ case 'sq_ajax_gsc_code':
727
+ SQ_Classes_Helpers_Tools::setHeader('json');
728
+
729
+ $response = array();
730
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
731
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
732
+ echo wp_json_encode($response);
733
+ exit();
734
+ }
735
+
736
+ //remove connection with Google Analytics
737
+ $code = SQ_Classes_RemoteController::getGSCToken();
738
+
739
+ if (!is_wp_error($code) && $code) {
740
+ $response['code'] = SQ_Classes_Helpers_Sanitize::checkGoogleWTCode($code);
741
+ } else {
742
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("Error! Could not get the code. Connect to Google Search Console and validate the connection.", 'squirrly-seo'), 'sq_error');
743
+ }
744
+
745
+ echo wp_json_encode($response);
746
+ exit();
747
+ case 'sq_ajax_ga_code':
748
+ SQ_Classes_Helpers_Tools::setHeader('json');
749
+
750
+ $response = array();
751
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
752
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
753
+ echo wp_json_encode($response);
754
+ exit();
755
+ }
756
+
757
+ //remove connection with Google Analytics
758
+ $code = SQ_Classes_RemoteController::getGAToken();
759
+ if (!is_wp_error($code) && $code) {
760
+ $response['code'] = $code;
761
+ } else {
762
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("Error! Could not get the tracking code. Connect to Google Analytics and get the website tracking code from Admin area.", 'squirrly-seo'), 'sq_error');
763
+ }
764
+ echo wp_json_encode($response);
765
+ exit();
766
+ case 'sq_ajax_connection_check':
767
+ SQ_Classes_Helpers_Tools::setHeader('json');
768
+
769
+ $response = array();
770
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
771
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
772
+ echo wp_json_encode($response);
773
+ exit();
774
+ }
775
+
776
+ //delete local checking cache
777
+ delete_transient('sq_checkin');
778
+ //check the connection again
779
+ SQ_Classes_RemoteController::checkin();
780
+
781
+ echo wp_json_encode(array());
782
+ exit();
783
+
784
+
785
+ /************************
786
+ *
787
+ * Automation
788
+ ********************************************************/
789
+ case 'sq_ajax_automation_addpostype':
790
+ SQ_Classes_Helpers_Tools::setHeader('json');
791
+ $response = array();
792
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
793
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
794
+ echo wp_json_encode($response);
795
+ exit();
796
+ }
797
+
798
+ //Get the new post type
799
+ $posttype = SQ_Classes_Helpers_Tools::getValue('value', false);
800
+ $filter = array('public' => true, '_builtin' => false);
801
+ $types = get_post_types($filter);
802
+ foreach ($types as $pattern => $type) {
803
+ if($post_type_obj = get_post_type_object($pattern)) {
804
+ if($post_type_obj->has_archive) {
805
+ $types['archive-' . $pattern] = 'archive-' . $pattern;
806
+ }
807
+ }
808
+ }
809
+
810
+ $filter = array('public' => true,);
811
+ $taxonomies = get_taxonomies($filter);
812
+ foreach ($taxonomies as $pattern => $type) {
813
+ $types['tax-' . $pattern] = 'tax-' . $pattern;
814
+ }
815
+
816
+ //If the post type is in the list of types
817
+ if ($posttype && in_array($posttype, $types)) {
818
+ $patterns = SQ_Classes_Helpers_Tools::getOption('patterns');
819
+ //if the post type does not already exists
820
+ if (!isset($patterns[$posttype])) {
821
+ //add the custom rights to the new post type
822
+ $patterns[$posttype] = $patterns['custom'];
823
+ $patterns[$posttype]['protected'] = 0;
824
+ //save the options in database
825
+ SQ_Classes_Helpers_Tools::saveOptions('patterns', $patterns);
826
+
827
+ $response['data'] = SQ_Classes_Error::showNotices(esc_html__("Saved", 'squirrly-seo'), 'sq_success');
828
+ echo wp_json_encode($response);
829
+ exit();
830
+ }
831
+ }
832
+
833
+
834
+ //Return error in case the post is not saved
835
+ $response['data'] = SQ_Classes_Error::showNotices(esc_html__("Could not add the post type.", 'squirrly-seo'), 'sq_error');
836
+ echo wp_json_encode($response);
837
+ exit();
838
+ case 'sq_ajax_automation_deletepostype':
839
+ SQ_Classes_Helpers_Tools::setHeader('json');
840
+ $response = array();
841
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_settings')) {
842
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
843
+ echo wp_json_encode($response);
844
+ exit();
845
+ }
846
+
847
+
848
+ //Get the new post type
849
+ $posttype = SQ_Classes_Helpers_Tools::getValue('value', false);
850
+
851
+ //If the post type is in the list of types
852
+ if ($posttype && $posttype <> '') {
853
+ $patterns = SQ_Classes_Helpers_Tools::getOption('patterns');
854
+ //if the post type exists in the patterns
855
+ if (isset($patterns[$posttype])) {
856
+ //add the custom rights to the new post type
857
+ unset($patterns[$posttype]);
858
+
859
+ //save the options in database
860
+ SQ_Classes_Helpers_Tools::saveOptions('patterns', $patterns);
861
+
862
+ $response['data'] = SQ_Classes_Error::showNotices(esc_html__("Saved", 'squirrly-seo'), 'sq_success');
863
+ echo wp_json_encode($response);
864
+ exit();
865
+ }
866
+ }
867
+
868
+
869
+ //Return error in case the post is not saved
870
+ $response['data'] = SQ_Classes_Error::showNotices(esc_html__("Could not add the post type.", 'squirrly-seo'), 'sq_error');
871
+ echo wp_json_encode($response);
872
+ exit();
873
+
874
+ }
875
+
876
+ }
877
+
878
+ }
controllers/Sitemaps.php CHANGED
@@ -1,727 +1,780 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- /**
5
- * Class for Sitemap Generator
6
- */
7
- class SQ_Controllers_Sitemaps extends SQ_Classes_FrontController {
8
- /* @var string root name */
9
- var $root = 'sitemap';
10
-
11
- /* @var string post limit */
12
- var $posts_limit;
13
- var $news_limit;
14
-
15
- public function __construct() {
16
- parent::__construct();
17
- $this->posts_limit = SQ_Classes_Helpers_Tools::getOption('sq_sitemap_perpage');
18
- $this->news_limit = SQ_Classes_Helpers_Tools::getOption('sq_sitemap_perpage');
19
- add_filter('sq_sitemap_style', array($this, 'getSquirrlyHeader'));
20
- add_action('wp', array($this, 'hookPreventRedirect'), 9);
21
-
22
- add_filter('user_trailingslashit', array($this, 'untrailingslashit'));
23
-
24
- //Process the cron if created
25
- add_action('sq_processPing', array($this, 'processCron'));
26
-
27
- }
28
-
29
- public function hookPreventRedirect() {
30
- global $wp_query;
31
-
32
- if (isset($_SERVER['REQUEST_URI'])) {
33
- if (isset($_SERVER['QUERY_STRING']) && strpos($_SERVER['QUERY_STRING'], 'sq_feed') !== false) {
34
- parse_str($_SERVER['QUERY_STRING'], $query);
35
- $sitemap = 'sitemap';
36
- $page = 0;
37
-
38
- if (isset($query['sq_feed'])) {
39
- $sitemap = $query['sq_feed'];
40
- $page = (isset($query['page']) ? $query['page'] : 0);
41
- }
42
-
43
- $wp_query->is_404 = false;
44
- $wp_query->is_feed = true;
45
-
46
- $this->feedRequest($sitemap, $page);
47
- apply_filters('sq_sitemapxml', $this->showSitemap());
48
- die();
49
-
50
- } elseif (strpos($_SERVER['REQUEST_URI'], '.xml') !== false) {
51
- $parseurl = parse_url($_SERVER['REQUEST_URI']);
52
- $stemaplist = SQ_Classes_Helpers_Tools::getOption('sq_sitemap');
53
- $page = 0;
54
-
55
- foreach ($stemaplist as $request => $sitemap) {
56
- if (isset($sitemap[0]) && $sitemap[1] && substr($parseurl['path'], (strrpos($parseurl['path'], '/') + 1)) == $sitemap[0]) {
57
-
58
- $wp_query->is_404 = false;
59
- $wp_query->is_feed = true;
60
-
61
- if (isset($parseurl['query'])) {
62
- parse_str($parseurl['query'], $query);
63
- $page = (isset($query['page']) ? $query['page'] : 0);
64
- }
65
-
66
- $this->feedRequest($request, $page);
67
- apply_filters('sq_sitemapxml', $this->showSitemap());
68
- die();
69
- }
70
- }
71
- } elseif (strpos($_SERVER['REQUEST_URI'], 'locations.kml') !== false) {
72
- if (SQ_Classes_Helpers_Tools::getOption('sq_jsonld_type') == 'Organization') {
73
- $wp_query->is_404 = false;
74
- $wp_query->is_feed = true;
75
- $this->model->type = 'locations';
76
- apply_filters('sq_sitemapxml', $this->showSitemap());
77
- die();
78
- }
79
- }
80
- }
81
- }
82
-
83
- /**
84
- * Send the sitemap to Search Engines only if a page is freshly posted
85
- *
86
- * @param $new_status
87
- * @param $old_status
88
- * @param $post
89
- */
90
- public function refreshSitemap($new_status, $old_status, $post) {
91
- if ($old_status <> $new_status && $new_status = 'publish') {
92
- if (SQ_Classes_Helpers_Tools::getOption('sq_sitemap_ping')) {
93
- wp_schedule_single_event(time() + 5, 'sq_processPing');
94
- }
95
- }
96
- }
97
-
98
- /**
99
- * Listen the feed call from wordpress
100
- * @param string $request
101
- * @param integer $page
102
- */
103
- public function feedRequest($request = null, $page = 1) {
104
- global $sq_query;
105
- $sq_query = array();
106
-
107
- if (!isset($request)) {
108
- return;
109
- }
110
-
111
- $this->model->type = $request;
112
-
113
- if (strpos($request, 'sitemap') !== false) {
114
- $sq_sitemap = SQ_Classes_Helpers_Tools::getOption('sq_sitemap');
115
-
116
- //reset the previous query
117
- wp_reset_query();
118
-
119
- //Set Current Language
120
- $this->model->setCurrentLanguage();
121
-
122
- if ($request == 'sitemap') { //if sitemapindex, return
123
- return;
124
- }
125
-
126
- if ($this->model->type == 'sitemap-news') {
127
- $this->posts_limit = $this->news_limit;
128
- }
129
-
130
- remove_all_actions('pre_get_posts');
131
- remove_all_actions('parse_query');
132
- remove_all_actions('posts_where');
133
-
134
- //init the query
135
- $sq_query = array(
136
- 'post_type' => array('post'),
137
- 'tax_query' => array(),
138
- 'post_status' => 'publish',
139
- 'posts_per_page' => 1000,
140
- 'paged' => $page,
141
- 'orderby' => 'date',
142
- 'order' => 'DESC',
143
- );
144
-
145
- if ($this->model->language <> '') {
146
- if (!SQ_Classes_Helpers_Tools::getOption('sq_sitemap_combinelangs')) {
147
- $sq_query['lang'] = apply_filters('sq_sitemap_language', $this->model->language);
148
- }
149
- }
150
-
151
-
152
-
153
- //show products
154
- if ($this->model->type == 'sitemap-product') {
155
- if (SQ_Classes_Helpers_Tools::isEcommerce() && $sq_sitemap[$this->model->type][1] == 2) {
156
- $sq_sitemap[$this->model->type][1] = 1;
157
- }
158
- }
159
-
160
- if (isset($sq_sitemap[$this->model->type]) && $sq_sitemap[$this->model->type][1]) {
161
-
162
- //PREPARE CUSTOM QUERIES
163
- switch ($this->model->type) {
164
- case 'sitemap-news':
165
- case 'sitemap-post':
166
- $sq_query['posts_per_page'] = $this->posts_limit;
167
- break;
168
- case 'sitemap-category':
169
- case 'sitemap-post_tag':
170
- case 'sitemap-custom-tax':
171
- remove_all_filters('terms_clauses'); //prevent language filters
172
- add_filter('get_terms_fields', array($this, 'customTaxFilter'), 5, 2);
173
- break;
174
- case 'sitemap-page':
175
- $sq_query['post_type'] = array('page');
176
- $sq_query['posts_per_page'] = $this->posts_limit;
177
- break;
178
- case 'sitemap-attachment':
179
- $sq_query['post_type'] = array('attachment');
180
- $sq_query['post_status'] = array('publish', 'inherit');
181
- break;
182
- case 'sitemap-author':
183
- add_filter('sq-sitemap-authors', array($this, 'authorFilter'), 5);
184
- break;
185
- case 'sitemap-custom-post':
186
- $types = get_post_types(array('public' => true));
187
- foreach (array('post', 'page', 'attachment', 'revision', 'nav_menu_item', 'product', 'wpsc-product', 'ngg_tag') as $exclude) {
188
- if (in_array($exclude, $types)) {
189
- unset($types[$exclude]);
190
- }
191
- }
192
-
193
- foreach ($types as $type) {
194
- $type_data = get_post_type_object($type);
195
- if ((isset($type_data->rewrite['publicly_queryable']) && $type_data->rewrite['publicly_queryable'] == 1) || (isset($type_data->publicly_queryable) && $type_data->publicly_queryable == 1)) {
196
- continue;
197
- }
198
- unset($types[$type]);
199
- }
200
-
201
- if (empty($types)) {
202
- array_push($types, 'custom-post');
203
- }
204
-
205
- $sq_query['post_type'] = $types;
206
- break;
207
- case 'sitemap-product':
208
- if (SQ_Classes_Helpers_Tools::isEcommerce()) {
209
- $types = array('product', 'wpsc-product');
210
- } else {
211
- $types = array('custom-post');
212
- }
213
- $sq_query['post_type'] = $types;
214
- $sq_query['posts_per_page'] = $this->posts_limit;
215
-
216
- break;
217
- case 'sitemap-archive':
218
- add_filter('sq-sitemap-archive', array($this, 'archiveFilter'), 5);
219
- break;
220
- }
221
-
222
- //add custom filter
223
- do_action('do_feed_' . $this->model->type);
224
- }
225
- }
226
-
227
- }
228
-
229
- public function getSquirrlyHeader($header) {
230
- if ($this->model->type <> 'locations') {
231
- $header = '<?xml-stylesheet type="text/xsl" href="/' . _SQ_ASSETS_RELATIVE_URL_ . 'css/sitemap' . ($this->model->type == 'sitemap' ? 'index' : '') . '.xsl"?>' . "\n";
232
- $header .= '<!-- generated-on="' . date('Y-m-d\TH:i:s+00:00') . '" -->' . "\n";
233
- $header .= '<!-- generator="Squirrly SEO Sitemap" -->' . "\n";
234
- $header .= '<!-- generator-url="https://wordpress.org/plugins/squirrly-seo/" -->' . "\n";
235
- $header .= '<!-- generator-version="' . SQ_VERSION . '" -->' . "\n";
236
- }
237
-
238
- return $header;
239
- }
240
-
241
- /**
242
- * Show the Sitemap Header
243
- * @param array $include Include schema
244
- */
245
- public function showSitemapHeader($include = array()) {
246
- @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
247
-
248
- header('Status: 200 OK', true, 200);
249
- header('Content-Type: text/xml; charset=' . get_bloginfo('charset'), true);
250
- //Generate header
251
- echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?>' . "\n";
252
- echo apply_filters('sq_sitemap_style', false);
253
-
254
- echo '' . "\n";
255
-
256
- $schema = array(
257
- 'image' => 'xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"',
258
- 'video' => 'xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"',
259
- 'news' => 'xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"',
260
- 'mobile' => 'xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0"',
261
- );
262
-
263
- if (!empty($include))
264
- $include = array_unique($include);
265
-
266
- switch ($this->model->type) {
267
- case 'locations':
268
- echo '<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">' . "\n";
269
- echo '<Document>' . "\n";
270
- break;
271
- case 'sitemap':
272
- echo '<sitemapindex xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
273
- . 'xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd" '
274
- . 'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"';
275
- foreach ($include as $value) {
276
- echo ' ' . $schema[$value] . "\n";
277
- }
278
- echo '>' . "\n";
279
- break;
280
- case 'sitemap-news':
281
- array_push($include, 'news');
282
- $include = array_unique($include);
283
- default:
284
- echo '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
285
- . 'xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" '
286
- . 'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"';
287
- if (!empty($include))
288
- foreach ($include as $value) {
289
- echo " " . $schema[$value] . " ";
290
- }
291
- echo '>' . "\n";
292
- break;
293
- }
294
- }
295
-
296
- /**
297
- * Show the Sitemap Footer
298
- */
299
- private function showSitemapFooter() {
300
- switch ($this->model->type) {
301
- case 'locations':
302
- echo '</Document>' . "\n";
303
- echo '</kml>' . "\n";
304
- break;
305
- case 'sitemap':
306
- echo '</sitemapindex>' . "\n";
307
- break;
308
- default :
309
- echo '</urlset>' . "\n";
310
- break;
311
- }
312
- }
313
-
314
- /**
315
- * Create the XML sitemap
316
- * @return string
317
- */
318
- public function showSitemap() {
319
- switch ($this->model->type) {
320
- case 'sitemap':
321
- $this->showSitemapHeader();
322
- $sq_sitemap = SQ_Classes_Helpers_Tools::getOption('sq_sitemap');
323
- $patterns = SQ_Classes_Helpers_Tools::getOption('patterns');
324
-
325
- if (!empty($sq_sitemap))
326
- foreach ($sq_sitemap as $name => $value) {
327
-
328
- //check if available from SEO Automation
329
- $pname = str_replace(array('sitemap-', 'post_'), '', $name);
330
- if (isset($patterns[$pname]['do_sitemap']) && !$patterns[$pname]['do_sitemap']) {
331
- continue;
332
- }
333
-
334
- //force to show products if not preset
335
- if ($name == 'sitemap-product' && !SQ_Classes_Helpers_Tools::isEcommerce()) {
336
- continue;
337
- }
338
-
339
- if ($name !== 'sitemap' && ($value[1] == 1 || $value[1] == 2)) {
340
- echo "\t" . '<sitemap>' . "\n";
341
- echo "\t" . '<loc>' . $this->getXmlUrl($name) . '</loc>' . "\n";
342
- echo "\t" . '<lastmod>' . mysql2date('Y-m-d\TH:i:s+00:00', get_lastpostmodified('gmt'), false) . '</lastmod>' . "\n";
343
- echo "\t" . '</sitemap>' . "\n";
344
-
345
-
346
- if ($name == 'sitemap-post' && $count_posts = wp_count_posts()) {
347
- if (isset($count_posts->publish) && $count_posts->publish > 0 && $count_posts->publish > $this->posts_limit) {
348
- $pages = ceil($count_posts->publish / $this->posts_limit);
349
- for ($page = 2; $page <= $pages; $page++) {
350
- echo "\t" . '<sitemap>' . "\n";
351
- echo "\t" . '<loc>' . $this->getXmlUrl($name, $page) . '</loc>' . "\n";
352
- echo "\t" . '<lastmod>' . mysql2date('Y-m-d\TH:i:s+00:00', get_lastpostmodified('gmt'), false) . '</lastmod>' . "\n";
353
- echo "\t" . '</sitemap>' . "\n";
354
- }
355
- }
356
- }
357
- if ($name == 'sitemap-page' && $count_posts = wp_count_posts('page')) {
358
- if (isset($count_posts->publish) && $count_posts->publish > 0 && $count_posts->publish > $this->posts_limit) {
359
- $pages = ceil($count_posts->publish / $this->posts_limit);
360
- for ($page = 2; $page <= $pages; $page++) {
361
- echo "\t" . '<sitemap>' . "\n";
362
- echo "\t" . '<loc>' . $this->getXmlUrl($name, $page) . '</loc>' . "\n";
363
- echo "\t" . '<lastmod>' . mysql2date('Y-m-d\TH:i:s+00:00', get_lastpostmodified('gmt'), false) . '</lastmod>' . "\n";
364
- echo "\t" . '</sitemap>' . "\n";
365
- }
366
- }
367
- }
368
- if ($name == 'sitemap-product' && $count_posts = wp_count_posts('product')) {
369
- if (isset($count_posts->publish) && $count_posts->publish > 0 && $count_posts->publish > $this->posts_limit) {
370
- $pages = ceil($count_posts->publish / $this->posts_limit);
371
- for ($page = 2; $page <= $pages; $page++) {
372
- echo "\t" . '<sitemap>' . "\n";
373
- echo "\t" . '<loc>' . $this->getXmlUrl($name, $page) . '</loc>' . "\n";
374
- echo "\t" . '<lastmod>' . mysql2date('Y-m-d\TH:i:s+00:00', get_lastpostmodified('gmt'), false) . '</lastmod>' . "\n";
375
- echo "\t" . '</sitemap>' . "\n";
376
- }
377
- }
378
- }
379
-
380
- }
381
- }
382
- $this->showSitemapFooter();
383
- break;
384
- case 'sitemap-home':
385
- $this->showPackXml($this->model->getHomeLink());
386
- break;
387
- case 'sitemap-news':
388
- $this->showPackXml($this->model->getListNews());
389
- break;
390
- case 'sitemap-category':
391
- case 'sitemap-post_tag':
392
- case 'sitemap-custom-tax':
393
- $this->showPackXml($this->model->getListTerms());
394
- break;
395
- case 'sitemap-author':
396
- $this->showPackXml($this->model->getListAuthors());
397
- break;
398
- case 'sitemap-archive':
399
- $this->showPackXml($this->model->getListArchive());
400
- break;
401
- case 'sitemap-attachment':
402
- $this->showPackXml($this->model->getListAttachments());
403
- break;
404
- case 'locations':
405
- $this->showPackKml($this->model->getKmlXML());
406
- break;
407
- default:
408
- $this->showPackXml($this->model->getListPosts());
409
- break;
410
- }
411
- }
412
-
413
- /**
414
- * Pach the XML for each sitemap
415
- * @param array $xml
416
- * @return void
417
- */
418
- public function showPackXml($xml = array()) {
419
- if (empty($xml)) {
420
- $xml['contains'] = '';
421
- }
422
- if (!isset($xml['contains'])) {
423
- $xml['contains'] = '';
424
- }
425
- $this->showSitemapHeader($xml['contains']);
426
-
427
- unset($xml['contains']);
428
- foreach ($xml as $row) {
429
- echo "\t" . '<url>' . "\n";
430
-
431
- if (is_array($row)) {
432
- echo $this->getRecursiveXml($row);
433
- }
434
- echo "\t" . '</url>' . "\n";
435
- }
436
- $this->showSitemapFooter();
437
- unset($xml);
438
- }
439
-
440
- /**
441
- * Pach the XML for each sitemap
442
- * @param array $kml
443
- * @return void
444
- */
445
- public function showPackKml($kml = array()) {
446
-
447
- $this->showSitemapHeader();
448
- header('Content-Type: application/vnd.google-earth.kml+xml; charset=' . get_bloginfo('charset'), true);
449
- echo $this->getRecursiveXml($kml);
450
- $this->showSitemapFooter();
451
-
452
- unset($kml);
453
- }
454
-
455
- public function getRecursiveXml($xml, $pkey = '', $level = 2) {
456
- $str = '';
457
- $tab = str_repeat("\t", $level);
458
- if (is_array($xml)) {
459
- $cnt = 0;
460
- foreach ($xml as $key => $data) {
461
- if ($data === false) {
462
- $str .= $tab . '<' . $key . '>' . "\n";
463
- } elseif (!is_array($data) && $data <> '') {
464
- $str .= $tab . '<' . $key . ($key == 'video:player_loc' ? ' allow_embed="yes"' : '') . '>' . $data . ((strpos($data, '?') == false && $key == 'video:player_loc') ? '' : '') . '</' . $key . '>' . "\n";
465
- } else {
466
- if ($this->getRecursiveXml($data) <> '') {
467
- if (!$this->_ckeckIntergerArray($data)) {
468
- $str .= $tab . '<' . (!is_numeric($key) ? $key : $pkey) . '>' . "\n";
469
- }
470
- $str .= $this->getRecursiveXml($data, $key, ($this->_ckeckIntergerArray($data) ? $level : $level + 1));
471
- if (!$this->_ckeckIntergerArray($data)) {
472
- $str .= $tab . '</' . (!is_numeric($key) ? $key : $pkey) . '>' . "\n";
473
- }
474
- }
475
- }
476
- $cnt++;
477
- }
478
- }
479
- return $str;
480
- }
481
-
482
- private function _ckeckIntergerArray($data) {
483
- foreach ($data as $key => $value) {
484
- if (is_numeric($key)) {
485
- return true;
486
- }
487
- break;
488
- }
489
- return false;
490
- }
491
-
492
- /**
493
- * Set the query limit
494
- * @param integer $limits
495
- * @return string
496
- */
497
- public function setLimits($limits) {
498
- if (isset($this->posts_limit) && $this->posts_limit > 0) {
499
- return 'LIMIT 0, ' . $this->posts_limit;
500
- }
501
-
502
- return '';
503
- }
504
-
505
- /**
506
- * Get the url for each sitemap
507
- * @param string $sitemap
508
- * @param integer $page
509
- * @return string
510
- */
511
- public function getXmlUrl($sitemap, $page = null) {
512
- $sq_sitemap = SQ_Classes_Helpers_Tools::getOption('sq_sitemap');
513
-
514
- if (!get_option('permalink_structure')) {
515
- $sitemap = '?sq_feed=' . str_replace('.xml', '', $sitemap) . (isset($page) ? '&amp;page=' . $page : '');
516
- } else {
517
- if (isset($sq_sitemap[$sitemap])) {
518
- $sitemap = $sq_sitemap[$sitemap][0] . (isset($page) ? '?page=' . $page : '');
519
- }
520
-
521
- if (strpos($sitemap, '.xml') === false) {
522
- $sitemap .= '.xml';
523
- }
524
- }
525
-
526
- if ($this->model->language <> '') {
527
- if(function_exists('pll_home_url')) {
528
- return pll_home_url($this->model->language) . $sitemap;
529
- }elseif (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] <> ''){
530
- if(strpos($this->model->language, '_') !== false) {
531
- $language = substr($this->model->language, 0, strpos($this->model->language, '_'));
532
- if(preg_match("/\/$language\//", $_SERVER['REQUEST_URI'])) {
533
- return esc_url(trailingslashit(home_url())) . $language . '/' . $sitemap;
534
- }
535
- }
536
- }
537
- }
538
-
539
- return esc_url(trailingslashit(home_url())) . $sitemap;
540
- }
541
-
542
- public function getKmlUrl($sitemap, $page = null) {
543
- $sq_sitemap = SQ_Classes_Helpers_Tools::getOption('sq_sitemap');
544
-
545
- if (!get_option('permalink_structure')) {
546
- $sitemap = '?sq_feed=' . str_replace('.kml', '', $sitemap) . (isset($page) ? '&amp;page=' . $page : '');
547
- } else {
548
- if (isset($sq_sitemap[$sitemap])) {
549
- $sitemap = $sq_sitemap[$sitemap][0] . (isset($page) ? '?page=' . $page : '');
550
- }
551
-
552
- if (strpos($sitemap, '.kml') === false) {
553
- $sitemap .= '.kml';
554
- }
555
- }
556
-
557
- return esc_url(trailingslashit(home_url())) . $sitemap;
558
- }
559
-
560
-
561
- /**
562
- * Process the on-time cron if called
563
- */
564
- public function processCron() {
565
- SQ_Classes_ObjController::getClass('SQ_Classes_Helpers_Tools');
566
-
567
- $sq_sitemap = SQ_Classes_Helpers_Tools::getOption('sq_sitemap');
568
- if (!empty($sq_sitemap)) {
569
- foreach ($sq_sitemap as $name => $sitemap) {
570
- if ($sitemap[1] == 1) { //is the default sitemap
571
- $this->SendPing($this->getXmlUrl($name));
572
- }
573
- }
574
- }
575
- }
576
-
577
- /**
578
- * Ping the sitemap to Google and Bing
579
- * @param string $sitemapUrl
580
- * @return boolean
581
- */
582
- protected function SendPing($sitemapUrl) {
583
- $success = true;
584
- $urls = array(
585
- "https://www.google.com/ping?sitemap=%s",
586
- "http://www.bing.com/ping?sitemap=%s",
587
- );
588
-
589
- $options = array(
590
- 'method' => 'get',
591
- 'sslverify' => false,
592
- 'timeout' => 10
593
- );
594
-
595
- foreach ($urls as $url) {
596
- if ($responce = SQ_Classes_ObjController::getClass('SQ_Classes_RemoteController')->sq_wpcall(sprintf($url, $sitemapUrl), $options)) {
597
- $success = true;
598
- }
599
- }
600
-
601
- return $success;
602
- }
603
-
604
- /**
605
- * Delete the fizical file if exists
606
- * @return boolean
607
- */
608
- public function deleteSitemapFile() {
609
- $sq_sitemap = SQ_Classes_Helpers_Tools::getOption('sq_sitemap');
610
- if (isset($sq_sitemap[$this->root])) {
611
- if (file_exists(ABSPATH . $sq_sitemap[$this->root])) {
612
- @unlink(ABSPATH . $sq_sitemap[$this->root]);
613
- return true;
614
- }
615
- }
616
- return false;
617
- }
618
-
619
- /**
620
- * Remove the trailing slash from permalinks that have an extension,
621
- * such as /sitemap.xml
622
- *
623
- * @param $request
624
- * @return string
625
- */
626
- public function untrailingslashit($request) {
627
- if (pathinfo($request, PATHINFO_EXTENSION)) {
628
- return untrailingslashit($request);
629
- }
630
- return $request; // trailingslashit($request);
631
- }
632
-
633
- public function postFilter(&$query) {
634
- $query->set('tax_query', array());
635
- }
636
-
637
- /**
638
- * Filter the Custom Taxonomy
639
- * @param $query
640
- * @param $args
641
- * @return array
642
- */
643
- public function customTaxFilter($query, $args) {
644
- global $wpdb;
645
- $query[] = $wpdb->prepare("(SELECT
646
- UNIX_TIMESTAMP(MAX(p.post_date_gmt)) as _mod_date
647
- FROM `$wpdb->posts` p, `$wpdb->term_relationships` r
648
- WHERE p.ID = r.object_id
649
- AND p.post_status = %s
650
- AND p.post_password = ''
651
- AND r.term_taxonomy_id = tt.term_taxonomy_id
652
- ) as lastmod", 'publish');
653
-
654
-
655
- return $query;
656
- }
657
-
658
- public function pageFilter(&$query) {
659
- $query->set('post_type', array('page'));
660
- $query->set('tax_query', array());
661
- }
662
-
663
- public function authorFilter() {
664
- //get only the author with posts
665
- add_filter('pre_user_query', array($this, 'userFilter'));
666
- return get_users();
667
- }
668
-
669
- public function userFilter($query) {
670
- global $wpdb;
671
-
672
- $query->query_fields .= ',p.lastmod';
673
- $query->query_from .= ' LEFT OUTER JOIN (
674
- SELECT MAX(post_modified) as lastmod, post_author, COUNT(*) as post_count
675
- FROM `' . $wpdb->posts . '`
676
- WHERE post_type = "post" AND post_status = "publish"
677
- GROUP BY post_author
678
- ) p ON (wp_users.ID = p.post_author)';
679
- $query->query_where .= ' AND post_count > 0 ';
680
- }
681
-
682
- public function customPostFilter(&$query) {
683
- $types = get_post_types(array('public' => true));
684
- foreach (array('post', 'page', 'attachment', 'revision', 'nav_menu_item', 'product', 'wpsc-product') as $exclude) {
685
- if (in_array($exclude, $types)) {
686
- unset($types[$exclude]);
687
- }
688
- }
689
-
690
- foreach ($types as $type) {
691
- $type_data = get_post_type_object($type);
692
- if ((isset($type_data->rewrite['feeds']) && $type_data->rewrite['feeds'] == 1) || (isset($type_data->feeds) && $type_data->feeds == 1)) {
693
- continue;
694
- }
695
- unset($types[$type]);
696
- }
697
-
698
- if (empty($types)) {
699
- array_push($types, 'custom-post');
700
- }
701
-
702
- $query->set('post_type', $types); // id of page or post
703
- $query->set('tax_query', array());
704
- }
705
-
706
- public function productFilter(&$query) {
707
-
708
- if (!$types = SQ_Classes_Helpers_Tools::isEcommerce()) {
709
- $types = array('custom-post');
710
- }
711
- $query->set('post_type', $types); // id of page or post
712
- $query->set('tax_query', array());
713
- }
714
-
715
- public function archiveFilter() {
716
- global $wpdb;
717
- $archives = $wpdb->get_results($wpdb->prepare("
718
- SELECT DISTINCT YEAR(post_date_gmt) as `year`, MONTH(post_date_gmt) as `month`, max(post_date_gmt) as lastmod, count(ID) as posts
719
- FROM `$wpdb->posts`
720
- WHERE post_date_gmt < NOW() AND post_status = %s AND post_type = %s
721
- GROUP BY YEAR(post_date_gmt), MONTH(post_date_gmt)
722
- ORDER BY post_date_gmt DESC
723
- ", 'publish', 'post'));
724
- return $archives;
725
- }
726
-
727
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ /**
5
+ * Class for Sitemap Generator
6
+ */
7
+ class SQ_Controllers_Sitemaps extends SQ_Classes_FrontController
8
+ {
9
+ /* @var string root name */
10
+ var $root = 'sitemap';
11
+
12
+ /* @var string post limit */
13
+ var $posts_limit;
14
+ var $news_limit;
15
+
16
+ public function __construct()
17
+ {
18
+ parent::__construct();
19
+ $this->posts_limit = SQ_Classes_Helpers_Tools::getOption('sq_sitemap_perpage');
20
+ $this->news_limit = SQ_Classes_Helpers_Tools::getOption('sq_sitemap_perpage');
21
+ add_filter('sq_sitemap_style', array($this, 'getSquirrlyHeader'));
22
+ add_action('wp', array($this, 'hookPreventRedirect'), 9);
23
+
24
+ add_filter('user_trailingslashit', array($this, 'untrailingslashit'));
25
+
26
+ //Process the cron if created
27
+ add_action('sq_processPing', array($this, 'processCron'));
28
+
29
+ }
30
+
31
+ public function hookPreventRedirect()
32
+ {
33
+ global $wp_query;
34
+
35
+ if (isset($_SERVER['REQUEST_URI'])) {
36
+ if (isset($_SERVER['QUERY_STRING']) && strpos($_SERVER['QUERY_STRING'], 'sq_feed') !== false) {
37
+ parse_str($_SERVER['QUERY_STRING'], $query);
38
+ $sitemap = 'sitemap';
39
+ $page = 0;
40
+
41
+ if (isset($query['sq_feed'])) {
42
+ $sitemap = $query['sq_feed'];
43
+ $page = (isset($query['page']) ? $query['page'] : 0);
44
+ }
45
+
46
+ $wp_query->is_404 = false;
47
+ $wp_query->is_feed = true;
48
+
49
+ $this->feedRequest($sitemap, $page);
50
+ apply_filters('sq_sitemapxml', $this->showSitemap());
51
+ die();
52
+
53
+ } elseif (strpos($_SERVER['REQUEST_URI'], '.xml') !== false) {
54
+ $parseurl = parse_url($_SERVER['REQUEST_URI']);
55
+ $stemaplist = SQ_Classes_Helpers_Tools::getOption('sq_sitemap');
56
+ $page = 0;
57
+
58
+ foreach ($stemaplist as $request => $sitemap) {
59
+ if (isset($sitemap[0]) && $sitemap[1] && substr($parseurl['path'], (strrpos($parseurl['path'], '/') + 1)) == $sitemap[0]) {
60
+
61
+ $wp_query->is_404 = false;
62
+ $wp_query->is_feed = true;
63
+
64
+ if (isset($parseurl['query'])) {
65
+ parse_str($parseurl['query'], $query);
66
+ $page = (isset($query['page']) ? $query['page'] : 0);
67
+ }
68
+
69
+ $this->feedRequest($request, $page);
70
+ apply_filters('sq_sitemapxml', $this->showSitemap());
71
+ die();
72
+ }
73
+ }
74
+ } elseif (strpos($_SERVER['REQUEST_URI'], 'locations.kml') !== false) {
75
+ if (SQ_Classes_Helpers_Tools::getOption('sq_jsonld_type') == 'Organization') {
76
+ $wp_query->is_404 = false;
77
+ $wp_query->is_feed = true;
78
+ $this->model->type = 'locations';
79
+ apply_filters('sq_sitemapxml', $this->showSitemap());
80
+ die();
81
+ }
82
+ }
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Send the sitemap to Search Engines only if a page is freshly posted
88
+ *
89
+ * @param $new_status
90
+ * @param $old_status
91
+ * @param $post
92
+ */
93
+ public function refreshSitemap($new_status, $old_status, $post)
94
+ {
95
+ if ($old_status <> $new_status && $new_status = 'publish') {
96
+ if (SQ_Classes_Helpers_Tools::getOption('sq_sitemap_ping')) {
97
+ wp_schedule_single_event(time() + 5, 'sq_processPing');
98
+ }
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Listen the feed call from wordpress
104
+ *
105
+ * @param string $request
106
+ * @param integer $page
107
+ */
108
+ public function feedRequest($request = null, $page = 1)
109
+ {
110
+ global $sq_query;
111
+ $sq_query = array();
112
+
113
+ if (!isset($request)) {
114
+ return;
115
+ }
116
+
117
+ $this->model->type = $request;
118
+
119
+ if (strpos($request, 'sitemap') !== false) {
120
+ $sq_sitemap = SQ_Classes_Helpers_Tools::getOption('sq_sitemap');
121
+
122
+ //reset the previous query
123
+ wp_reset_query();
124
+
125
+ //Set Current Language
126
+ $this->model->setCurrentLanguage();
127
+
128
+ if ($request == 'sitemap') { //if sitemapindex, return
129
+ return;
130
+ }
131
+
132
+ if ($this->model->type == 'sitemap-news') {
133
+ $this->posts_limit = $this->news_limit;
134
+ }
135
+
136
+ remove_all_actions('pre_get_posts');
137
+ remove_all_actions('parse_query');
138
+ remove_all_actions('posts_where');
139
+
140
+ //init the query
141
+ $sq_query = array(
142
+ 'post_type' => array('post'),
143
+ 'tax_query' => array(),
144
+ 'post_status' => 'publish',
145
+ 'posts_per_page' => 1000,
146
+ 'paged' => $page,
147
+ 'orderby' => 'date',
148
+ 'order' => 'DESC',
149
+ );
150
+
151
+ if ($this->model->language <> '') {
152
+ if (!SQ_Classes_Helpers_Tools::getOption('sq_sitemap_combinelangs')) {
153
+ $sq_query['lang'] = apply_filters('sq_sitemap_language', $this->model->language);
154
+ }
155
+ }
156
+
157
+
158
+
159
+ //show products
160
+ if ($this->model->type == 'sitemap-product') {
161
+ if (SQ_Classes_Helpers_Tools::isEcommerce() && $sq_sitemap[$this->model->type][1] == 2) {
162
+ $sq_sitemap[$this->model->type][1] = 1;
163
+ }
164
+ }
165
+
166
+ if (isset($sq_sitemap[$this->model->type]) && $sq_sitemap[$this->model->type][1]) {
167
+
168
+ //PREPARE CUSTOM QUERIES
169
+ switch ($this->model->type) {
170
+ case 'sitemap-news':
171
+ case 'sitemap-post':
172
+ $sq_query['posts_per_page'] = $this->posts_limit;
173
+ break;
174
+ case 'sitemap-category':
175
+ case 'sitemap-post_tag':
176
+ case 'sitemap-custom-tax':
177
+ remove_all_filters('terms_clauses'); //prevent language filters
178
+ add_filter('get_terms_fields', array($this, 'customTaxFilter'), 5, 2);
179
+ break;
180
+ case 'sitemap-page':
181
+ $sq_query['post_type'] = array('page');
182
+ $sq_query['posts_per_page'] = $this->posts_limit;
183
+ break;
184
+ case 'sitemap-attachment':
185
+ $sq_query['post_type'] = array('attachment');
186
+ $sq_query['post_status'] = array('publish', 'inherit');
187
+ break;
188
+ case 'sitemap-author':
189
+ add_filter('sq-sitemap-authors', array($this, 'authorFilter'), 5);
190
+ break;
191
+ case 'sitemap-custom-post':
192
+ $types = get_post_types(array('public' => true));
193
+ foreach (array('post', 'page', 'attachment', 'revision', 'nav_menu_item', 'product', 'wpsc-product', 'ngg_tag') as $exclude) {
194
+ if (in_array($exclude, $types)) {
195
+ unset($types[$exclude]);
196
+ }
197
+ }
198
+
199
+ foreach ($types as $type) {
200
+ $type_data = get_post_type_object($type);
201
+ if ((isset($type_data->rewrite['publicly_queryable']) && $type_data->rewrite['publicly_queryable'] == 1) || (isset($type_data->publicly_queryable) && $type_data->publicly_queryable == 1)) {
202
+ continue;
203
+ }
204
+ unset($types[$type]);
205
+ }
206
+
207
+ if (empty($types)) {
208
+ array_push($types, 'custom-post');
209
+ }
210
+
211
+ $sq_query['post_type'] = $types;
212
+ break;
213
+ case 'sitemap-product':
214
+ if (SQ_Classes_Helpers_Tools::isEcommerce()) {
215
+ $types = array('product', 'wpsc-product');
216
+ } else {
217
+ $types = array('custom-post');
218
+ }
219
+ $sq_query['post_type'] = $types;
220
+ $sq_query['posts_per_page'] = $this->posts_limit;
221
+
222
+ break;
223
+ case 'sitemap-archive':
224
+ add_filter('sq-sitemap-archive', array($this, 'archiveFilter'), 5);
225
+ break;
226
+ }
227
+
228
+ //add custom filter
229
+ do_action('do_feed_' . $this->model->type);
230
+ }
231
+ }
232
+
233
+ }
234
+
235
+ public function getSquirrlyHeader($header)
236
+ {
237
+ if ($this->model->type <> 'locations') {
238
+ $header = '<?xml-stylesheet type="text/xsl" href="/' . _SQ_ASSETS_RELATIVE_URL_ . 'css/sitemap' . ($this->model->type == 'sitemap' ? 'index' : '') . '.xsl"?>' . "\n";
239
+ $header .= '<!-- generated-on="' . date('Y-m-d\TH:i:s+00:00') . '" -->' . "\n";
240
+ $header .= '<!-- generator="Squirrly SEO Sitemap" -->' . "\n";
241
+ $header .= '<!-- generator-url="https://wordpress.org/plugins/squirrly-seo/" -->' . "\n";
242
+ $header .= '<!-- generator-version="' . esc_attr(SQ_VERSION) . '" -->' . "\n";
243
+ }
244
+
245
+ return $header;
246
+ }
247
+
248
+ /**
249
+ * Show the Sitemap Header
250
+ *
251
+ * @param array $include Include schema
252
+ */
253
+ public function showSitemapHeader($include = array())
254
+ {
255
+ @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
256
+
257
+ header('Status: 200 OK', true, 200);
258
+ header('Content-Type: text/xml; charset=' . get_bloginfo('charset'), true);
259
+ //Generate header
260
+ echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?>' . "\n";
261
+ echo apply_filters('sq_sitemap_style', false);
262
+
263
+ echo '' . "\n";
264
+
265
+ $schema = array(
266
+ 'image' => 'xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"',
267
+ 'video' => 'xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"',
268
+ 'news' => 'xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"',
269
+ 'mobile' => 'xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0"',
270
+ );
271
+
272
+ if (!empty($include))
273
+ $include = array_unique($include);
274
+
275
+ switch ($this->model->type) {
276
+ case 'locations':
277
+ echo '<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">' . "\n";
278
+ echo '<Document>' . "\n";
279
+ break;
280
+ case 'sitemap':
281
+ echo '<sitemapindex xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
282
+ . 'xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd" '
283
+ . 'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"';
284
+ foreach ($include as $value) {
285
+ //echo the xmlns for the current sitemap type
286
+ echo ' ' . $schema[$value] . "\n";
287
+ }
288
+ echo '>' . "\n";
289
+ break;
290
+ case 'sitemap-news':
291
+ array_push($include, 'news');
292
+ $include = array_unique($include);
293
+ default:
294
+ echo '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
295
+ . 'xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" '
296
+ . 'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"';
297
+ if (!empty($include))
298
+ foreach ($include as $value) {
299
+ //echo the xmlns for the current sitemap type
300
+ echo " " . $schema[$value] . " ";
301
+ }
302
+ echo '>' . "\n";
303
+ break;
304
+ }
305
+ }
306
+
307
+ /**
308
+ * Show the Sitemap Footer
309
+ */
310
+ private function showSitemapFooter()
311
+ {
312
+ switch ($this->model->type) {
313
+ case 'locations':
314
+ echo '</Document>' . "\n";
315
+ echo '</kml>' . "\n";
316
+ break;
317
+ case 'sitemap':
318
+ echo '</sitemapindex>' . "\n";
319
+ break;
320
+ default :
321
+ echo '</urlset>' . "\n";
322
+ break;
323
+ }
324
+ }
325
+
326
+ /**
327
+ * Create the XML sitemap
328
+ *
329
+ * @return string
330
+ */
331
+ public function showSitemap()
332
+ {
333
+ switch ($this->model->type) {
334
+ case 'sitemap':
335
+ $this->showSitemapHeader();
336
+ $sq_sitemap = SQ_Classes_Helpers_Tools::getOption('sq_sitemap');
337
+ $patterns = SQ_Classes_Helpers_Tools::getOption('patterns');
338
+
339
+ if (!empty($sq_sitemap))
340
+ foreach ($sq_sitemap as $name => $value) {
341
+
342
+ //check if available from SEO Automation
343
+ $pname = str_replace(array('sitemap-', 'post_'), '', $name);
344
+ if (isset($patterns[$pname]['do_sitemap']) && !$patterns[$pname]['do_sitemap']) {
345
+ continue;
346
+ }
347
+
348
+ //force to show products if not preset
349
+ if ($name == 'sitemap-product' && !SQ_Classes_Helpers_Tools::isEcommerce()) {
350
+ continue;
351
+ }
352
+
353
+ if ($name !== 'sitemap' && ($value[1] == 1 || $value[1] == 2)) {
354
+ echo "\t" . '<sitemap>' . "\n";
355
+ echo "\t" . '<loc>' . esc_url($this->getXmlUrl($name)) . '</loc>' . "\n";
356
+ echo "\t" . '<lastmod>' . mysql2date('Y-m-d\TH:i:s+00:00', get_lastpostmodified('gmt'), false) . '</lastmod>' . "\n";
357
+ echo "\t" . '</sitemap>' . "\n";
358
+
359
+
360
+ if ($name == 'sitemap-post' && $count_posts = wp_count_posts()) {
361
+ if (isset($count_posts->publish) && (int)$count_posts->publish > 0 && (int)$count_posts->publish > (int)$this->posts_limit) {
362
+ $pages = ceil((int)$count_posts->publish / (int)$this->posts_limit);
363
+ for ($page = 2; $page <= $pages; $page++) {
364
+ echo "\t" . '<sitemap>' . "\n";
365
+ echo "\t" . '<loc>' . esc_url($this->getXmlUrl($name, $page)) . '</loc>' . "\n";
366
+ echo "\t" . '<lastmod>' . mysql2date('Y-m-d\TH:i:s+00:00', get_lastpostmodified('gmt'), false) . '</lastmod>' . "\n";
367
+ echo "\t" . '</sitemap>' . "\n";
368
+ }
369
+ }
370
+ }
371
+ if ($name == 'sitemap-page' && $count_posts = wp_count_posts('page')) {
372
+ if (isset($count_posts->publish) && (int)$count_posts->publish > 0 && (int)$count_posts->publish > (int)$this->posts_limit) {
373
+ $pages = ceil((int)$count_posts->publish / (int)$this->posts_limit);
374
+ for ($page = 2; $page <= $pages; $page++) {
375
+ echo "\t" . '<sitemap>' . "\n";
376
+ echo "\t" . '<loc>' . esc_url($this->getXmlUrl($name, $page)) . '</loc>' . "\n";
377
+ echo "\t" . '<lastmod>' . mysql2date('Y-m-d\TH:i:s+00:00', get_lastpostmodified('gmt'), false) . '</lastmod>' . "\n";
378
+ echo "\t" . '</sitemap>' . "\n";
379
+ }
380
+ }
381
+ }
382
+ if ($name == 'sitemap-product' && $count_posts = wp_count_posts('product')) {
383
+ if (isset($count_posts->publish) && (int)$count_posts->publish > 0 && (int)$count_posts->publish > (int)$this->posts_limit) {
384
+ $pages = ceil((int)$count_posts->publish / (int)$this->posts_limit);
385
+ for ($page = 2; $page <= $pages; $page++) {
386
+ echo "\t" . '<sitemap>' . "\n";
387
+ echo "\t" . '<loc>' . esc_url($this->getXmlUrl($name, $page)) . '</loc>' . "\n";
388
+ echo "\t" . '<lastmod>' . mysql2date('Y-m-d\TH:i:s+00:00', get_lastpostmodified('gmt'), false) . '</lastmod>' . "\n";
389
+ echo "\t" . '</sitemap>' . "\n";
390
+ }
391
+ }
392
+ }
393
+
394
+ }
395
+ }
396
+ $this->showSitemapFooter();
397
+ break;
398
+ case 'sitemap-home':
399
+ $this->showPackXml($this->model->getHomeLink());
400
+ break;
401
+ case 'sitemap-news':
402
+ $this->showPackXml($this->model->getListNews());
403
+ break;
404
+ case 'sitemap-category':
405
+ case 'sitemap-post_tag':
406
+ case 'sitemap-custom-tax':
407
+ $this->showPackXml($this->model->getListTerms());
408
+ break;
409
+ case 'sitemap-author':
410
+ $this->showPackXml($this->model->getListAuthors());
411
+ break;
412
+ case 'sitemap-archive':
413
+ $this->showPackXml($this->model->getListArchive());
414
+ break;
415
+ case 'sitemap-attachment':
416
+ $this->showPackXml($this->model->getListAttachments());
417
+ break;
418
+ case 'locations':
419
+ $this->showPackKml($this->model->getKmlXML());
420
+ break;
421
+ default:
422
+ $this->showPackXml($this->model->getListPosts());
423
+ break;
424
+ }
425
+ }
426
+
427
+ /**
428
+ * Pach the XML for each sitemap
429
+ *
430
+ * @param array $xml
431
+ * @return void
432
+ */
433
+ public function showPackXml($xml = array())
434
+ {
435
+ if (empty($xml)) {
436
+ $xml['contains'] = '';
437
+ }
438
+ if (!isset($xml['contains'])) {
439
+ $xml['contains'] = '';
440
+ }
441
+ $this->showSitemapHeader($xml['contains']);
442
+
443
+ unset($xml['contains']);
444
+ foreach ($xml as $row) {
445
+ echo "\t" . '<url>' . "\n";
446
+
447
+ if (is_array($row)) {
448
+ echo $this->getRecursiveXml($row);
449
+ }
450
+ echo "\t" . '</url>' . "\n";
451
+ }
452
+ $this->showSitemapFooter();
453
+ unset($xml);
454
+ }
455
+
456
+ /**
457
+ * Pach the XML for each sitemap
458
+ *
459
+ * @param array $kml
460
+ * @return void
461
+ */
462
+ public function showPackKml($kml = array())
463
+ {
464
+
465
+ $this->showSitemapHeader();
466
+ header('Content-Type: application/vnd.google-earth.kml+xml; charset=' . get_bloginfo('charset'), true);
467
+ echo $this->getRecursiveXml($kml);
468
+ $this->showSitemapFooter();
469
+
470
+ unset($kml);
471
+ }
472
+
473
+ /**
474
+ * Return XML Structure for the Sitemap
475
+ * @param $xml
476
+ * @param string $pkey
477
+ * @param int $level
478
+ * @return string XML
479
+ */
480
+ public function getRecursiveXml($xml, $pkey = '', $level = 2)
481
+ {
482
+ $str = '';
483
+ $tab = str_repeat("\t", $level);
484
+ if (is_array($xml)) {
485
+ $cnt = 0;
486
+ foreach ($xml as $key => $data) {
487
+ if ($data === false) {
488
+ $str .= $tab . '<' . $key . '>' . "\n";
489
+ } elseif (!is_array($data) && $data <> '') {
490
+ $str .= $tab . '<' . $key . ($key == 'video:player_loc' ? ' allow_embed="yes"' : '') . '>' . $data . ((strpos($data, '?') == false && $key == 'video:player_loc') ? '' : '') . '</' . $key . '>' . "\n";
491
+ } else {
492
+ if ($this->getRecursiveXml($data) <> '') {
493
+ if (!$this->_ckeckIntergerArray($data)) {
494
+ $str .= $tab . '<' . (!is_numeric($key) ? $key : $pkey) . '>' . "\n";
495
+ }
496
+ $str .= $this->getRecursiveXml($data, $key, ($this->_ckeckIntergerArray($data) ? $level : $level + 1));
497
+ if (!$this->_ckeckIntergerArray($data)) {
498
+ $str .= $tab . '</' . (!is_numeric($key) ? $key : $pkey) . '>' . "\n";
499
+ }
500
+ }
501
+ }
502
+ $cnt++;
503
+ }
504
+ }
505
+ return $str;
506
+ }
507
+
508
+ private function _ckeckIntergerArray($data)
509
+ {
510
+ foreach ($data as $key => $value) {
511
+ if (is_numeric($key)) {
512
+ return true;
513
+ }
514
+ break;
515
+ }
516
+ return false;
517
+ }
518
+
519
+ /**
520
+ * Set the query limit
521
+ *
522
+ * @param integer $limits
523
+ * @return string
524
+ */
525
+ public function setLimits($limits)
526
+ {
527
+ if (isset($this->posts_limit) && $this->posts_limit > 0) {
528
+ return 'LIMIT 0, ' . $this->posts_limit;
529
+ }
530
+
531
+ return '';
532
+ }
533
+
534
+ /**
535
+ * Get the url for each sitemap
536
+ *
537
+ * @param string $sitemap
538
+ * @param integer $page
539
+ * @return string
540
+ */
541
+ public function getXmlUrl($sitemap, $page = null)
542
+ {
543
+ $sq_sitemap = SQ_Classes_Helpers_Tools::getOption('sq_sitemap');
544
+
545
+ if (!get_option('permalink_structure')) {
546
+ $sitemap = '?sq_feed=' . str_replace('.xml', '', $sitemap) . (isset($page) ? '&amp;page=' . $page : '');
547
+ } else {
548
+ if (isset($sq_sitemap[$sitemap])) {
549
+ $sitemap = $sq_sitemap[$sitemap][0] . (isset($page) ? '?page=' . $page : '');
550
+ }
551
+
552
+ if (strpos($sitemap, '.xml') === false) {
553
+ $sitemap .= '.xml';
554
+ }
555
+ }
556
+
557
+ if ($this->model->language <> '') {
558
+ if(function_exists('pll_home_url')) {
559
+ return pll_home_url($this->model->language) . $sitemap;
560
+ }elseif (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] <> '') {
561
+ if(strpos($this->model->language, '_') !== false) {
562
+ $language = substr($this->model->language, 0, strpos($this->model->language, '_'));
563
+ if(preg_match("/\/$language\//", $_SERVER['REQUEST_URI'])) {
564
+ return esc_url(trailingslashit(home_url())) . $language . '/' . $sitemap;
565
+ }
566
+ }
567
+ }
568
+ }
569
+
570
+ return esc_url(trailingslashit(home_url())) . $sitemap;
571
+ }
572
+
573
+ public function getKmlUrl($sitemap, $page = null)
574
+ {
575
+ $sq_sitemap = SQ_Classes_Helpers_Tools::getOption('sq_sitemap');
576
+
577
+ if (!get_option('permalink_structure')) {
578
+ $sitemap = '?sq_feed=' . str_replace('.kml', '', $sitemap) . (isset($page) ? '&amp;page=' . $page : '');
579
+ } else {
580
+ if (isset($sq_sitemap[$sitemap])) {
581
+ $sitemap = $sq_sitemap[$sitemap][0] . (isset($page) ? '?page=' . $page : '');
582
+ }
583
+
584
+ if (strpos($sitemap, '.kml') === false) {
585
+ $sitemap .= '.kml';
586
+ }
587
+ }
588
+
589
+ return esc_url(trailingslashit(home_url())) . $sitemap;
590
+ }
591
+
592
+
593
+ /**
594
+ * Process the on-time cron if called
595
+ */
596
+ public function processCron()
597
+ {
598
+ SQ_Classes_ObjController::getClass('SQ_Classes_Helpers_Tools');
599
+
600
+ $sq_sitemap = SQ_Classes_Helpers_Tools::getOption('sq_sitemap');
601
+ if (!empty($sq_sitemap)) {
602
+ foreach ($sq_sitemap as $name => $sitemap) {
603
+ if ($sitemap[1] == 1) { //is the default sitemap
604
+ $this->SendPing($this->getXmlUrl($name));
605
+ }
606
+ }
607
+ }
608
+ }
609
+
610
+ /**
611
+ * Ping the sitemap to Google and Bing
612
+ *
613
+ * @param string $sitemapUrl
614
+ * @return boolean
615
+ */
616
+ protected function SendPing($sitemapUrl)
617
+ {
618
+ $success = true;
619
+ $urls = array(
620
+ "https://www.google.com/ping?sitemap=%s",
621
+ "http://www.bing.com/ping?sitemap=%s",
622
+ );
623
+
624
+ $options = array(
625
+ 'method' => 'get',
626
+ 'sslverify' => false,
627
+ 'timeout' => 10
628
+ );
629
+
630
+ foreach ($urls as $url) {
631
+ if ($responce = SQ_Classes_ObjController::getClass('SQ_Classes_RemoteController')->sq_wpcall(sprintf($url, $sitemapUrl), $options)) {
632
+ $success = true;
633
+ }
634
+ }
635
+
636
+ return $success;
637
+ }
638
+
639
+ /**
640
+ * Delete the fizical file if exists
641
+ *
642
+ * @return boolean
643
+ */
644
+ public function deleteSitemapFile()
645
+ {
646
+ $sq_sitemap = SQ_Classes_Helpers_Tools::getOption('sq_sitemap');
647
+ if (isset($sq_sitemap[$this->root])) {
648
+ if (file_exists(ABSPATH . $sq_sitemap[$this->root])) {
649
+ @unlink(ABSPATH . $sq_sitemap[$this->root]);
650
+ return true;
651
+ }
652
+ }
653
+ return false;
654
+ }
655
+
656
+ /**
657
+ * Remove the trailing slash from permalinks that have an extension,
658
+ * such as /sitemap.xml
659
+ *
660
+ * @param $request
661
+ * @return string
662
+ */
663
+ public function untrailingslashit($request)
664
+ {
665
+ if (pathinfo($request, PATHINFO_EXTENSION)) {
666
+ return untrailingslashit($request);
667
+ }
668
+ return $request; // trailingslashit($request);
669
+ }
670
+
671
+ public function postFilter(&$query)
672
+ {
673
+ $query->set('tax_query', array());
674
+ }
675
+
676
+ /**
677
+ * Filter the Custom Taxonomy
678
+ *
679
+ * @param $query
680
+ * @param $args
681
+ * @return array
682
+ */
683
+ public function customTaxFilter($query, $args)
684
+ {
685
+ global $wpdb;
686
+ $query[] = $wpdb->prepare(
687
+ "(SELECT
688
+ UNIX_TIMESTAMP(MAX(p.post_date_gmt)) as _mod_date
689
+ FROM `$wpdb->posts` p, `$wpdb->term_relationships` r
690
+ WHERE p.ID = r.object_id
691
+ AND p.post_status = %s
692
+ AND p.post_password = ''
693
+ AND r.term_taxonomy_id = tt.term_taxonomy_id
694
+ ) as lastmod", 'publish'
695
+ );
696
+
697
+
698
+ return $query;
699
+ }
700
+
701
+ public function pageFilter(&$query)
702
+ {
703
+ $query->set('post_type', array('page'));
704
+ $query->set('tax_query', array());
705
+ }
706
+
707
+ public function authorFilter()
708
+ {
709
+ //get only the author with posts
710
+ add_filter('pre_user_query', array($this, 'userFilter'));
711
+ return get_users();
712
+ }
713
+
714
+ public function userFilter($query)
715
+ {
716
+ global $wpdb;
717
+
718
+ $query->query_fields .= ',p.lastmod';
719
+ $query->query_from .= ' LEFT OUTER JOIN (
720
+ SELECT MAX(post_modified) as lastmod, post_author, COUNT(*) as post_count
721
+ FROM `' . $wpdb->posts . '`
722
+ WHERE post_type = "post" AND post_status = "publish"
723
+ GROUP BY post_author
724
+ ) p ON (wp_users.ID = p.post_author)';
725
+ $query->query_where .= ' AND post_count > 0 ';
726
+ }
727
+
728
+ public function customPostFilter(&$query)
729
+ {
730
+ $types = get_post_types(array('public' => true));
731
+ foreach (array('post', 'page', 'attachment', 'revision', 'nav_menu_item', 'product', 'wpsc-product') as $exclude) {
732
+ if (in_array($exclude, $types)) {
733
+ unset($types[$exclude]);
734
+ }
735
+ }
736
+
737
+ foreach ($types as $type) {
738
+ $type_data = get_post_type_object($type);
739
+ if ((isset($type_data->rewrite['feeds']) && $type_data->rewrite['feeds'] == 1) || (isset($type_data->feeds) && $type_data->feeds == 1)) {
740
+ continue;
741
+ }
742
+ unset($types[$type]);
743
+ }
744
+
745
+ if (empty($types)) {
746
+ array_push($types, 'custom-post');
747
+ }
748
+
749
+ $query->set('post_type', $types); // id of page or post
750
+ $query->set('tax_query', array());
751
+ }
752
+
753
+ public function productFilter(&$query)
754
+ {
755
+
756
+ if (!$types = SQ_Classes_Helpers_Tools::isEcommerce()) {
757
+ $types = array('custom-post');
758
+ }
759
+ $query->set('post_type', $types); // id of page or post
760
+ $query->set('tax_query', array());
761
+ }
762
+
763
+ public function archiveFilter()
764
+ {
765
+ global $wpdb;
766
+ $archives = $wpdb->get_results(
767
+ $wpdb->prepare(
768
+ "
769
+ SELECT DISTINCT YEAR(post_date_gmt) as `year`, MONTH(post_date_gmt) as `month`, max(post_date_gmt) as lastmod, count(ID) as posts
770
+ FROM `$wpdb->posts`
771
+ WHERE post_date_gmt < NOW() AND post_status = %s AND post_type = %s
772
+ GROUP BY YEAR(post_date_gmt), MONTH(post_date_gmt)
773
+ ORDER BY post_date_gmt DESC
774
+ ", 'publish', 'post'
775
+ )
776
+ );
777
+ return $archives;
778
+ }
779
+
780
+ }
controllers/Snippet.php CHANGED
@@ -1,281 +1,302 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- class SQ_Controllers_Snippet extends SQ_Classes_FrontController {
5
-
6
- /** @var array Post Type in */
7
- private $_types = array();
8
- public $post;
9
-
10
- public function __construct() {
11
- parent::__construct();
12
- add_action('admin_bar_menu', array($this, 'hookTopmenuFrontend'), 11);
13
-
14
- if (is_admin()) {
15
- add_action('category_add_form_fields', array($this, 'hookTermsPage'), 10);
16
-
17
- $taxonomies = get_taxonomies(array('public' => true));
18
- if (!empty($taxonomies)) {
19
- foreach ($taxonomies as $taxonomy) {
20
- if (is_string($taxonomy) && $taxonomy <> '') {
21
- add_filter($taxonomy . '_edit_form', array($this, 'hookTermsPage'), 10);
22
- }
23
- }
24
- }
25
- }
26
- }
27
-
28
- /**
29
- * Init Snippet and return the view for Admin Bar
30
- * @return mixed
31
- */
32
- public function init() {
33
- if (is_rtl()) {
34
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('sqbootstrap.rtl', array('trigger' => true, 'media' => 'all'));
35
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('rtl', array('trigger' => true, 'media' => 'all'));
36
- } else {
37
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('sqbootstrap', array('trigger' => true, 'media' => 'all'));
38
- }
39
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('fontawesome', array('trigger' => true, 'media' => 'all'));
40
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('highlight', array('trigger' => true, 'media' => 'all'));
41
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('patterns', array('trigger' => true, 'media' => 'all'));
42
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('snippet', array('trigger' => true, 'media' => 'all'));
43
-
44
-
45
- if(is_admin()) {
46
- global $post;
47
-
48
- //Set the current post in admin panel
49
- if (isset($post->ID) && $post->ID > 0) {
50
- $this->post = SQ_Classes_ObjController::getClass('SQ_Models_Frontend')->setPost($post)->getPost();
51
- }
52
- }
53
-
54
- return $this->getView('Blocks/Snippet');
55
- }
56
-
57
- /**
58
- * Hook the Head sequence in frontend when user is logged in
59
- */
60
- public function hookFronthead() {
61
- if (SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
62
- //prevent some compatibility errors with other plugins
63
- remove_all_actions('print_media_templates');
64
-
65
- //loade the media library
66
- @wp_enqueue_media();
67
-
68
- //Set the current post domain with all the data
69
- $this->post = SQ_Classes_ObjController::getClass('SQ_Models_Frontend')->getPost();
70
- }
71
- }
72
-
73
-
74
- /**
75
- * Set the post in SEO Snippet for Bulk SEO
76
- * @param $post
77
- * @return $this
78
- */
79
- public function setPost($post) {
80
- $this->post = $post;
81
-
82
- return $this;
83
- }
84
-
85
- /**
86
- * Hook pages like Terms and Categories
87
- */
88
- public function hookTermsPage() {
89
- echo $this->getSnippetDiv(SQ_Classes_ObjController::getClass('SQ_Controllers_Snippet')->init());
90
- }
91
-
92
- /**
93
- * Get the Snippet div for different pages
94
- *
95
- * @param $content
96
- * @param string $attributes
97
- * @return string
98
- */
99
- public function getSnippetDiv($content, $attributes = '') {
100
-
101
- if (!apply_filters('sq_load_snippet', true) || !SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
102
- return false;
103
- }
104
-
105
- return '<div id="sq_blocksnippet" ' . $attributes . ' class="sq_blocksnippet sq-shadow-sm sq-border-bottom sq-mb-4"><h2 class="hndle"><span class="sq_logo" style="margin-right: 5px;width: 30px !important;height: 30px !important;"></span>' . esc_html__("Squirrly SEO Snippet", _SQ_PLUGIN_NAME_) . '</span></h2><div class="inside">' . $content . '</div></div>';
106
-
107
- }
108
-
109
- /**
110
- * Add a menu in Frontend Admin Bar
111
- *
112
- * @param WP_Admin_Bar $wp_admin_bar
113
- */
114
- public function hookTopmenuFrontend($wp_admin_bar) {
115
- global $wp_the_query;
116
-
117
- if (is_admin() || !function_exists('is_user_logged_in') || !is_user_logged_in()) {
118
- return;
119
- }
120
-
121
- //If user set not to load Squirrly in frontend
122
- if (!SQ_Classes_Helpers_Tools::getOption('sq_use_frontend')) {
123
- return;
124
- }
125
-
126
- if (!$wp_the_query || !method_exists($wp_the_query, 'get_queried_object') || !function_exists('current_user_can')) {
127
- return;
128
- }
129
-
130
- if (!apply_filters('sq_load_snippet', true) || !SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
131
- return;
132
- }
133
-
134
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippets')) {
135
- $current_object = $wp_the_query->get_queried_object();
136
-
137
- if (empty($current_object))
138
- return;
139
-
140
- if (!empty($current_object->post_type)
141
- && ($post_type_object = get_post_type_object($current_object->post_type))
142
- && SQ_Classes_Helpers_Tools::userCan('edit_post', $current_object->ID)
143
- && $post_type_object->show_in_admin_bar
144
- && $edit_post_link = get_edit_post_link($current_object->ID)) {
145
- } elseif (!empty($current_object->taxonomy)
146
- && ($tax = get_taxonomy($current_object->taxonomy))
147
- && SQ_Classes_Helpers_Tools::userCan('edit_term', $current_object->term_id)
148
- && $edit_term_link = get_edit_term_link($current_object->term_id, $current_object->taxonomy)) {
149
- } else {
150
- return;
151
- }
152
- }
153
-
154
- try {
155
-
156
- //Dev Kit
157
- $style = '';
158
- if (SQ_Classes_Helpers_Tools::getOption('sq_devkit_logo')) {
159
- $style = '<style>.sq_logo{background-image:url("' . SQ_Classes_Helpers_Tools::getOption('sq_devkit_logo') . '") !important;background-size: 100%; background-repeat: no-repeat; background-position: center;}</style>';
160
- }
161
-
162
- $wp_admin_bar->add_node(array(
163
- 'id' => 'sq_bar_menu',
164
- 'title' => $style . '<span class="sq_logo"></span> ' . esc_html__("Custom SEO", _SQ_PLUGIN_NAME_),
165
- 'parent' => 'top-secondary',
166
- ));
167
-
168
-
169
- $wp_admin_bar->add_menu(array(
170
- 'id' => 'sq_bar_submenu',
171
- 'parent' => 'sq_bar_menu',
172
- 'meta' => array(
173
- 'html' => $this->getSnippetDiv(SQ_Classes_ObjController::getClass('SQ_Controllers_Snippet')->init(), 'data-snippet="topmenu"'),
174
- 'tabindex' => PHP_INT_MAX,
175
- ),
176
- ));
177
- } catch (Exception $e) {
178
-
179
- }
180
-
181
- }
182
-
183
- /**
184
- * Called when Post action is triggered
185
- *
186
- * @return void
187
- */
188
- public function action() {
189
- parent::action();
190
-
191
- $response = array();
192
- if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
193
- $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", _SQ_PLUGIN_NAME_), 'sq_error');
194
- SQ_Classes_Helpers_Tools::setHeader('json');
195
- echo wp_json_encode($response);
196
- exit();
197
- }
198
-
199
- switch (SQ_Classes_Helpers_Tools::getValue('action')) {
200
- case 'sq_saveseo':
201
- $sq_hash = SQ_Classes_Helpers_Tools::getValue('sq_hash', false);
202
- $post_id = (int)SQ_Classes_Helpers_Tools::getValue('post_id', 0);
203
- $term_id = (int)SQ_Classes_Helpers_Tools::getValue('term_id', 0);
204
- $taxonomy = SQ_Classes_Helpers_Tools::getValue('taxonomy', '');
205
- $post_type = SQ_Classes_Helpers_Tools::getValue('post_type', '');
206
-
207
- //Save the SEO settings
208
- if ($this->model->saveSEO($post_id, $term_id, $taxonomy, $post_type)) {
209
- $json['saved'] = $sq_hash;
210
- } else {
211
- global $wpdb;
212
- $json['error'] = sprintf(esc_html__("Could not save the snippet. Please check the database table %s integrity.", _SQ_PLUGIN_NAME_), '<strong>' . $wpdb->prefix . _SQ_DB_ . '</strong>');
213
- }
214
-
215
- if ($this->post = $this->model->getCurrentSnippet($post_id, $term_id, $taxonomy, $post_type)) {
216
- $json['html'] = $this->getView('Blocks/Snippet');
217
- }
218
- if (SQ_Classes_Helpers_Tools::isAjax()) {
219
- SQ_Classes_Helpers_Tools::setHeader('json');
220
- SQ_Classes_Helpers_Tools::emptyCache();
221
-
222
- echo wp_json_encode($json);
223
- exit();
224
- }
225
- break;
226
-
227
- case 'sq_getsnippet':
228
- SQ_Classes_Helpers_Tools::setHeader('json');
229
-
230
- $json = array();
231
- $post_id = (int)SQ_Classes_Helpers_Tools::getValue('post_id', 0);
232
- $term_id = (int)SQ_Classes_Helpers_Tools::getValue('term_id', 0);
233
- $taxonomy = SQ_Classes_Helpers_Tools::getValue('taxonomy', 'category');
234
- $post_type = SQ_Classes_Helpers_Tools::getValue('post_type', 'post');
235
-
236
- if ($this->post = $this->model->getCurrentSnippet($post_id, $term_id, $taxonomy, $post_type)) {
237
- $json['html'] = $this->getView('Blocks/Snippet');
238
-
239
- //Support for international languages
240
- if (function_exists('iconv') && SQ_Classes_Helpers_Tools::getOption('sq_non_utf8_support')) {
241
- if (strpos(get_bloginfo("language"), 'en') === false) {
242
- $json['html'] = iconv('UTF-8', 'UTF-8//IGNORE', $json['html']);
243
- }
244
- }
245
-
246
- if (SQ_Classes_Error::isError()) {
247
- $json['error'] = SQ_Classes_Error::getError();
248
- }
249
-
250
- } else {
251
- $json['error'] = 'Not found!';
252
- }
253
-
254
- echo wp_json_encode($json);
255
- exit();
256
- case 'sq_previewsnippet':
257
-
258
- $snippet = array();
259
- try {
260
-
261
- if (SQ_Classes_Helpers_Tools::getValue('url') <> '') {
262
- $url = SQ_Classes_Helpers_Tools::getValue('url');
263
- } else {
264
- $url = get_bloginfo('url');
265
- }
266
-
267
- $snippet = SQ_Classes_RemoteController::getSnippet($url);
268
-
269
- } catch (Exception $e) {
270
- }
271
-
272
- if (SQ_Classes_Helpers_Tools::isAjax()) {
273
- SQ_Classes_Helpers_Tools::setHeader('json');
274
- echo wp_json_encode($snippet);
275
- exit();
276
- }
277
- }
278
- }
279
-
280
-
281
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ class SQ_Controllers_Snippet extends SQ_Classes_FrontController
5
+ {
6
+
7
+ /**
8
+ *
9
+ *
10
+ * @var array Post Type in
11
+ */
12
+ private $_types = array();
13
+ public $post;
14
+
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+ add_action('admin_bar_menu', array($this, 'hookTopmenuFrontend'), 11);
19
+
20
+ if (is_admin()) {
21
+ add_action('category_add_form_fields', array($this, 'hookTermsPage'), 10);
22
+
23
+ $taxonomies = get_taxonomies(array('public' => true));
24
+ if (!empty($taxonomies)) {
25
+ foreach ($taxonomies as $taxonomy) {
26
+ if (is_string($taxonomy) && $taxonomy <> '') {
27
+ add_filter($taxonomy . '_edit_form', array($this, 'hookTermsPage'), 10);
28
+ }
29
+ }
30
+ }
31
+ }
32
+ }
33
+
34
+ /**
35
+ * Init Snippet and return the view for Admin Bar
36
+ *
37
+ * @return mixed
38
+ */
39
+ public function init()
40
+ {
41
+ if (is_rtl()) {
42
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('sqbootstrap.rtl', array('trigger' => true, 'media' => 'all'));
43
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('rtl', array('trigger' => true, 'media' => 'all'));
44
+ } else {
45
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('sqbootstrap', array('trigger' => true, 'media' => 'all'));
46
+ }
47
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('fontawesome', array('trigger' => true, 'media' => 'all'));
48
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('highlight', array('trigger' => true, 'media' => 'all'));
49
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('patterns', array('trigger' => true, 'media' => 'all'));
50
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('snippet', array('trigger' => true, 'media' => 'all'));
51
+
52
+
53
+ if(is_admin()) {
54
+ global $post;
55
+
56
+ //Set the current post in admin panel
57
+ if (isset($post->ID) && $post->ID > 0) {
58
+ $this->post = SQ_Classes_ObjController::getClass('SQ_Models_Frontend')->setPost($post)->getPost();
59
+ }
60
+ }
61
+
62
+ return $this->get_view('Blocks/Snippet');
63
+ }
64
+
65
+ /**
66
+ * Hook the Head sequence in frontend when user is logged in
67
+ */
68
+ public function hookFronthead()
69
+ {
70
+ if (SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
71
+ //prevent some compatibility errors with other plugins
72
+ remove_all_actions('print_media_templates');
73
+
74
+ //loade the media library
75
+ @wp_enqueue_media();
76
+
77
+ //Set the current post domain with all the data
78
+ $this->post = SQ_Classes_ObjController::getClass('SQ_Models_Frontend')->getPost();
79
+ }
80
+ }
81
+
82
+
83
+ /**
84
+ * Set the post in SEO Snippet for Bulk SEO
85
+ *
86
+ * @param $post
87
+ * @return $this
88
+ */
89
+ public function setPost($post)
90
+ {
91
+ $this->post = $post;
92
+
93
+ return $this;
94
+ }
95
+
96
+ /**
97
+ * Hook pages like Terms and Categories
98
+ */
99
+ public function hookTermsPage()
100
+ {
101
+ echo $this->getSnippetDiv(SQ_Classes_ObjController::getClass('SQ_Controllers_Snippet')->init());
102
+ }
103
+
104
+ /**
105
+ * Get the Snippet div for different pages
106
+ *
107
+ * @param $content
108
+ * @param string $attributes
109
+ * @return string
110
+ */
111
+ public function getSnippetDiv($content, $attributes = '')
112
+ {
113
+
114
+ if (!apply_filters('sq_load_snippet', true) || !SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
115
+ return false;
116
+ }
117
+
118
+ return '<div id="sq_blocksnippet" ' . $attributes . ' class="sq_blocksnippet sq-shadow-sm sq-border-bottom sq-mb-4"><h2 class="hndle"><span class="sq_logo" style="margin-right: 5px;width: 30px !important;height: 30px !important;"></span>' . esc_html__("Squirrly SEO Snippet", 'squirrly-seo') . '</span></h2><div class="inside">' . $content . '</div></div>';
119
+
120
+ }
121
+
122
+ /**
123
+ * Add a menu in Frontend Admin Bar
124
+ *
125
+ * @param WP_Admin_Bar $wp_admin_bar
126
+ */
127
+ public function hookTopmenuFrontend($wp_admin_bar)
128
+ {
129
+ global $wp_the_query;
130
+
131
+ if (is_admin() || !function_exists('is_user_logged_in') || !is_user_logged_in()) {
132
+ return;
133
+ }
134
+
135
+ //If user set not to load Squirrly in frontend
136
+ if (!SQ_Classes_Helpers_Tools::getOption('sq_use_frontend')) {
137
+ return;
138
+ }
139
+
140
+ if (!$wp_the_query || !method_exists($wp_the_query, 'get_queried_object') || !function_exists('current_user_can')) {
141
+ return;
142
+ }
143
+
144
+ if (!apply_filters('sq_load_snippet', true) || !SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
145
+ return;
146
+ }
147
+
148
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippets')) {
149
+ $current_object = $wp_the_query->get_queried_object();
150
+
151
+ if (empty($current_object))
152
+ return;
153
+
154
+ if (!empty($current_object->post_type)
155
+ && ($post_type_object = get_post_type_object($current_object->post_type))
156
+ && SQ_Classes_Helpers_Tools::userCan('edit_post', $current_object->ID)
157
+ && $post_type_object->show_in_admin_bar
158
+ && $edit_post_link = get_edit_post_link($current_object->ID)
159
+ ) {
160
+ } elseif (!empty($current_object->taxonomy)
161
+ && ($tax = get_taxonomy($current_object->taxonomy))
162
+ && SQ_Classes_Helpers_Tools::userCan('edit_term', $current_object->term_id)
163
+ && $edit_term_link = get_edit_term_link($current_object->term_id, $current_object->taxonomy)
164
+ ) {
165
+ } else {
166
+ return;
167
+ }
168
+ }
169
+
170
+ try {
171
+
172
+ //Dev Kit
173
+ $style = '';
174
+ if (SQ_Classes_Helpers_Tools::getOption('sq_devkit_logo')) {
175
+ $style = '<style>.sq_logo{background-image:url("' . SQ_Classes_Helpers_Tools::getOption('sq_devkit_logo') . '") !important;background-size: 100%; background-repeat: no-repeat; background-position: center;}</style>';
176
+ }
177
+
178
+ $wp_admin_bar->add_node(
179
+ array(
180
+ 'id' => 'sq_bar_menu',
181
+ 'title' => $style . '<span class="sq_logo"></span> ' . esc_html__("Custom SEO", 'squirrly-seo'),
182
+ 'parent' => 'top-secondary',
183
+ )
184
+ );
185
+
186
+
187
+ $wp_admin_bar->add_menu(
188
+ array(
189
+ 'id' => 'sq_bar_submenu',
190
+ 'parent' => 'sq_bar_menu',
191
+ 'meta' => array(
192
+ 'html' => $this->getSnippetDiv(SQ_Classes_ObjController::getClass('SQ_Controllers_Snippet')->init(), 'data-snippet="topmenu"'),
193
+ 'tabindex' => PHP_INT_MAX,
194
+ ),
195
+ )
196
+ );
197
+ } catch (Exception $e) {
198
+
199
+ }
200
+
201
+ }
202
+
203
+ /**
204
+ * Called when Post action is triggered
205
+ *
206
+ * @return void
207
+ */
208
+ public function action()
209
+ {
210
+ parent::action();
211
+
212
+ $response = array();
213
+ if (!SQ_Classes_Helpers_Tools::userCan('sq_manage_snippet')) {
214
+ $response['error'] = SQ_Classes_Error::showNotices(esc_html__("You do not have permission to perform this action", 'squirrly-seo'), 'sq_error');
215
+ SQ_Classes_Helpers_Tools::setHeader('json');
216
+ echo wp_json_encode($response);
217
+ exit();
218
+ }
219
+
220
+ switch (SQ_Classes_Helpers_Tools::getValue('action')) {
221
+ case 'sq_saveseo':
222
+ $sq_hash = SQ_Classes_Helpers_Tools::getValue('sq_hash', false);
223
+ $post_id = (int)SQ_Classes_Helpers_Tools::getValue('post_id', 0);
224
+ $term_id = (int)SQ_Classes_Helpers_Tools::getValue('term_id', 0);
225
+ $taxonomy = SQ_Classes_Helpers_Tools::getValue('taxonomy', '');
226
+ $post_type = SQ_Classes_Helpers_Tools::getValue('post_type', '');
227
+
228
+ //Save the SEO settings
229
+ if ($this->model->saveSEO($post_id, $term_id, $taxonomy, $post_type)) {
230
+ $json['saved'] = $sq_hash;
231
+ } else {
232
+ global $wpdb;
233
+ $json['error'] = sprintf(esc_html__("Could not save the snippet. Please check the database table %s integrity.", 'squirrly-seo'), '<strong>' . $wpdb->prefix . _SQ_DB_ . '</strong>');
234
+ }
235
+
236
+ if ($this->post = $this->model->getCurrentSnippet($post_id, $term_id, $taxonomy, $post_type)) {
237
+ $json['html'] = $this->get_view('Blocks/Snippet');
238
+ }
239
+ if (SQ_Classes_Helpers_Tools::isAjax()) {
240
+ SQ_Classes_Helpers_Tools::setHeader('json');
241
+ SQ_Classes_Helpers_Tools::emptyCache();
242
+
243
+ echo wp_json_encode($json);
244
+ exit();
245
+ }
246
+ break;
247
+
248
+ case 'sq_getsnippet':
249
+ SQ_Classes_Helpers_Tools::setHeader('json');
250
+
251
+ $json = array();
252
+ $post_id = (int)SQ_Classes_Helpers_Tools::getValue('post_id', 0);
253
+ $term_id = (int)SQ_Classes_Helpers_Tools::getValue('term_id', 0);
254
+ $taxonomy = SQ_Classes_Helpers_Tools::getValue('taxonomy', 'category');
255
+ $post_type = SQ_Classes_Helpers_Tools::getValue('post_type', 'post');
256
+
257
+ if ($this->post = $this->model->getCurrentSnippet($post_id, $term_id, $taxonomy, $post_type)) {
258
+ $json['html'] = $this->get_view('Blocks/Snippet');
259
+
260
+ //Support for international languages
261
+ if (function_exists('iconv') && SQ_Classes_Helpers_Tools::getOption('sq_non_utf8_support')) {
262
+ if (strpos(get_bloginfo("language"), 'en') === false) {
263
+ $json['html'] = iconv('UTF-8', 'UTF-8//IGNORE', $json['html']);
264
+ }
265
+ }
266
+
267
+ if (SQ_Classes_Error::isError()) {
268
+ $json['error'] = SQ_Classes_Error::getError();
269
+ }
270
+
271
+ } else {
272
+ $json['error'] = 'Not found!';
273
+ }
274
+
275
+ echo wp_json_encode($json);
276
+ exit();
277
+ case 'sq_previewsnippet':
278
+
279
+ $snippet = array();
280
+ try {
281
+
282
+ if (SQ_Classes_Helpers_Tools::getValue('url') <> '') {
283
+ $url = SQ_Classes_Helpers_Tools::getValue('url');
284
+ } else {
285
+ $url = get_bloginfo('url');
286
+ }
287
+
288
+ $snippet = SQ_Classes_RemoteController::getSnippet($url);
289
+
290
+ } catch (Exception $e) {
291
+ }
292
+
293
+ if (SQ_Classes_Helpers_Tools::isAjax()) {
294
+ SQ_Classes_Helpers_Tools::setHeader('json');
295
+ echo wp_json_encode($snippet);
296
+ exit();
297
+ }
298
+ }
299
+ }
300
+
301
+
302
+ }
controllers/Uninstall.php CHANGED
@@ -1,16 +1,19 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- /**
5
- * Uninstall Options
6
- */
7
- class SQ_Controllers_Uninstall extends SQ_Classes_FrontController {
8
-
9
- public function hookHead() {
10
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('uninstall');
11
- }
12
-
13
- public function hookFooter() {
14
- echo $this->getView('Blocks/Uninstall');
15
- }
16
- }
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ /**
5
+ * Uninstall Options
6
+ */
7
+ class SQ_Controllers_Uninstall extends SQ_Classes_FrontController
8
+ {
9
+
10
+ public function hookHead()
11
+ {
12
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('uninstall');
13
+ }
14
+
15
+ public function hookFooter()
16
+ {
17
+ $this->show_view('Blocks/Uninstall');
18
+ }
19
+ }
core/BlockAssistant.php CHANGED
@@ -1,9 +1,11 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- class SQ_Core_BlockAssistant extends SQ_Classes_BlockController {
5
-
6
- public function init(){
7
- echo $this->getView('Blocks/Assistant');
8
- }
9
- }
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ class SQ_Core_BlockAssistant extends SQ_Classes_BlockController
5
+ {
6
+
7
+ public function init()
8
+ {
9
+ $this->show_view('Blocks/Assistant');
10
+ }
11
+ }
core/BlockConnect.php CHANGED
@@ -1,55 +1,60 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- class SQ_Core_BlockConnect extends SQ_Classes_BlockController {
5
-
6
- public $message;
7
-
8
- public function init() {
9
- /* If logged in, then return */
10
- if (SQ_Classes_Helpers_Tools::getOption('sq_api') == '') {
11
- return;
12
- }
13
-
14
- echo $this->getView('Blocks/Connect');
15
- }
16
-
17
- /**
18
- * Called for sq_login on Post action
19
- * Login or register a user
20
- */
21
- public function action() {
22
- switch (SQ_Classes_Helpers_Tools::getValue('action')) {
23
- //sign-up action
24
- case 'sq_cloud_connect':
25
- $this->connectToCloud();
26
- break;
27
-
28
- case 'sq_cloud_disconnect':
29
- $this->disconnectFromCloud();
30
- break;
31
- }
32
- }
33
-
34
- public function connectToCloud() {
35
- if(function_exists('rest_get_url_prefix')){
36
- $apiUrl = trim(rest_get_url_prefix(),'/');
37
- }elseif(function_exists('rest_url')){
38
- $apiUrl = trim(parse_url(rest_url(),PHP_URL_PATH),'/');
39
- }
40
-
41
- //Make sure the website exists on the Cloud
42
- SQ_Classes_RemoteController::connect();
43
-
44
- if ($token = SQ_Classes_RemoteController::getCloudToken(array('wp-json' => $apiUrl))) {
45
- if(isset($token->token) && $token->token <> '') {
46
- SQ_Classes_Helpers_Tools::saveOptions('sq_cloud_token', $token->token);
47
- SQ_Classes_Helpers_Tools::saveOptions('sq_cloud_connect', 1);
48
- }
49
- }
50
- }
51
-
52
- public function disconnectFromCloud() {
53
- SQ_Classes_Helpers_Tools::saveOptions('sq_cloud_connect', 0);
54
- }
55
- }
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ class SQ_Core_BlockConnect extends SQ_Classes_BlockController
5
+ {
6
+
7
+ public $message;
8
+
9
+ public function init()
10
+ {
11
+ /* If logged in, then return */
12
+ if (SQ_Classes_Helpers_Tools::getOption('sq_api') == '') {
13
+ return;
14
+ }
15
+
16
+ $this->show_view('Blocks/Connect');
17
+ }
18
+
19
+ /**
20
+ * Called for sq_login on Post action
21
+ * Login or register a user
22
+ */
23
+ public function action()
24
+ {
25
+ switch (SQ_Classes_Helpers_Tools::getValue('action')) {
26
+ //sign-up action
27
+ case 'sq_cloud_connect':
28
+ $this->connectToCloud();
29
+ break;
30
+
31
+ case 'sq_cloud_disconnect':
32
+ $this->disconnectFromCloud();
33
+ break;
34
+ }
35
+ }
36
+
37
+ public function connectToCloud()
38
+ {
39
+ if(function_exists('rest_get_url_prefix')) {
40
+ $apiUrl = trim(rest_get_url_prefix(), '/');
41
+ }elseif(function_exists('rest_url')) {
42
+ $apiUrl = trim(parse_url(rest_url(), PHP_URL_PATH), '/');
43
+ }
44
+
45
+ //Make sure the website exists on the Cloud
46
+ SQ_Classes_RemoteController::connect();
47
+
48
+ if ($token = SQ_Classes_RemoteController::getCloudToken(array('wp-json' => $apiUrl))) {
49
+ if(isset($token->token) && $token->token <> '') {
50
+ SQ_Classes_Helpers_Tools::saveOptions('sq_cloud_token', $token->token);
51
+ SQ_Classes_Helpers_Tools::saveOptions('sq_cloud_connect', 1);
52
+ }
53
+ }
54
+ }
55
+
56
+ public function disconnectFromCloud()
57
+ {
58
+ SQ_Classes_Helpers_Tools::saveOptions('sq_cloud_connect', 0);
59
+ }
60
+ }
core/BlockFeatures.php CHANGED
@@ -1,661 +1,664 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- class SQ_Core_BlockFeatures extends SQ_Classes_BlockController {
5
-
6
- public function init() {
7
- echo $this->getView('Blocks/Features');
8
- }
9
-
10
- public function getFeatures() {
11
- $connect = SQ_Classes_Helpers_Tools::getOption('connect');
12
- $sitemap = SQ_Classes_Helpers_Tools::getOption('sq_sitemap');
13
- $features = array(
14
- array(
15
- 'title' => "Squirrly Cloud App",
16
- 'description' => "Many Squirrly features work from <bold>cloud.squirrly.co</bold> and helps you optimize the content and manage the keywords, audits and rankings.",
17
- 'mode' => "Free",
18
- 'option' => false,
19
- 'active' => true,
20
- 'optional' => false,
21
- 'connection' => true,
22
- 'logo' => 'squirrly.png',
23
- 'link' => SQ_Classes_RemoteController::getMySquirrlyLink('dashboard'),
24
- 'details' => 'https://howto.squirrly.co/kb/squirrly-cloud-app/',
25
- 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_panel'),
26
- ), //Squirrly Cloud
27
- array(
28
- 'title' => "14 Days Journey Course",
29
- 'description' => "<strong>Improve your Online Presence</strong> by knowing how your website is performing. All you need now is to start driving One of your most valuable pages to <strong>Better Rankings</strong>.",
30
- 'mode' => "Free",
31
- 'option' => false,
32
- 'active' => SQ_Classes_Helpers_Tools::getOption('sq_seojourney'),
33
- 'optional' => false,
34
- 'connection' => true,
35
- 'logo' => 'journey_92.png',
36
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_onboarding', 'journey1'),
37
- 'details' => 'https://howto.squirrly.co/kb/install-squirrly-seo-plugin/#journey',
38
- 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_journey'),
39
- ), //14 Days Journey Course
40
- array(
41
- 'title' => "Next SEO Goals",
42
- 'description' => "The AI SEO Consultant with <strong>over 100+ signals</strong> that prepares your goals to take you closer to the first page of Google.",
43
- 'mode' => "Free",
44
- 'option' => false,
45
- 'active' => true,
46
- 'optional' => false,
47
- 'connection' => true,
48
- 'logo' => 'goals_92.png',
49
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_dashboard', '', array('#tasks')),
50
- 'details' => 'https://howto.squirrly.co/kb/next-seo-goals/',
51
- 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_seogoals'),
52
- ),//Next SEO Goals
53
- array(
54
- 'title' => "Progress & Achievements",
55
- 'description' => "Displays <strong>Success Messages</strong> and <strong>Progress & Achievements</strong> for SEO Goals, Focus Pages, Audits, and Rankings",
56
- 'mode' => "Free",
57
- 'option' => false,
58
- 'active' => true,
59
- 'optional' => false,
60
- 'connection' => true,
61
- 'logo' => 'progress_92.png',
62
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_dashboard', '', array('#tasks')),
63
- 'details' => 'https://howto.squirrly.co/kb/squirrly-seo-goals/',
64
- 'show' => true,
65
- ),//Progress
66
- array(
67
- 'title' => "Focus Pages",
68
- 'description' => "Brings you clear methods to take your pages <strong>from never found to always found on Google</strong>. Rank your pages by influencing the right ranking factors.",
69
- 'mode' => "Free",
70
- 'option' => false,
71
- 'active' => true,
72
- 'optional' => false,
73
- 'connection' => true,
74
- 'logo' => 'focuspages_92.png',
75
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_focuspages', 'pagelist'),
76
- 'details' => 'https://howto.squirrly.co/kb/focus-pages-page-audits/',
77
- 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_focuspages'),
78
- ), //Focus Pages
79
- array(
80
- 'title' => "Chances of Ranking",
81
- 'description' => "Get information about <strong>Chances of Ranking for each Focus Page</strong> based on our <strong>Machine Learning Algorithms and Ranking Vision A.I.</strong>",
82
- 'mode' => "Free",
83
- 'option' => false,
84
- 'active' => true,
85
- 'optional' => false,
86
- 'connection' => true,
87
- 'logo' => 'focuspages_92.png',
88
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_focuspages', 'pagelist'),
89
- 'details' => 'https://howto.squirrly.co/kb/focus-pages-page-audits/#chance_to_rank',
90
- 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_focuspages'),
91
- ), //Chances of Ranking
92
- array(
93
- 'title' => "Keyword Research",
94
- 'description' => "Find the <strong>Best Keywords</strong> that your own website can rank for and get <strong>personalized competition data</strong> for each keyword. Provides info on Region that was used for Keyword Research.",
95
- 'mode' => "Free",
96
- 'option' => false ,
97
- 'active' => true,
98
- 'optional' => false,
99
- 'connection' => true,
100
- 'logo' => 'kr_92.png',
101
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_research', 'research'),
102
- 'details' => 'https://howto.squirrly.co/kb/keyword-research-and-seo-strategy/',
103
- 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_research'),
104
- ), //Keyword Research
105
- array(
106
- 'title' => "Google Search & Trends",
107
- 'description' => "Keyword Research uses tird-party services like <strong>Google Search API and Google Trends API</strong> to get live research data for each keyword. The research algorithm processes <strong>more than 100 processes</strong> for each keyword you selected.",
108
- 'mode' => "Free",
109
- 'option' => false,
110
- 'active' => true,
111
- 'optional' => false,
112
- 'connection' => true,
113
- 'logo' => 'kr_92.png',
114
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_research', 'research'),
115
- 'details' => 'https://howto.squirrly.co/kb/keyword-research-and-seo-strategy/',
116
- 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_research'),
117
- ), //Keyword Research
118
- array(
119
- 'title' => "Briefcase",
120
- 'description' => "Add keywords in your portfolio based on your current Campaigns, Trends, Performance <strong>for a successful SEO strategy</strong>.",
121
- 'mode' => "Free",
122
- 'option' => false,
123
- 'active' => true,
124
- 'optional' => false,
125
- 'connection' => true,
126
- 'logo' => 'briefcase_92.png',
127
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_research', 'briefcase'),
128
- 'details' => 'https://howto.squirrly.co/kb/keyword-research-and-seo-strategy/#briefcase',
129
- 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_research'),
130
- ),//SEO Briefcase
131
- array(
132
- 'title' => "Live Assistant",
133
- 'description' => "Publish <strong>content that is fully optimized</strong> for BOTH Search Engines and Humans – every single time!",
134
- 'mode' => "Free",
135
- 'option' => false,
136
- 'active' => true,
137
- 'optional' => false,
138
- 'connection' => true,
139
- 'logo' => 'sla_92.png',
140
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_assistant'),
141
- 'details' => 'https://howto.squirrly.co/kb/squirrly-live-assistant/',
142
- 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_assistant'),
143
- ),//Live Assistant
144
- array(
145
- 'title' => "Keywords Optimization",
146
- 'description' => "Optimize for <strong>Multiple Keywords at once in a Single Page</strong>. Automatically Calculates Optimization Scores for all secondary keywords and displays them to you as you’re typing your page.",
147
- 'mode' => "Free",
148
- 'option' => false,
149
- 'active' => true,
150
- 'optional' => false,
151
- 'connection' => true,
152
- 'logo' => 'briefcase_92.png',
153
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_assistant'),
154
- 'details' => 'https://howto.squirrly.co/kb/squirrly-live-assistant/#add_keyword',
155
- 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_assistant'),
156
- ),//Keywords Optimization
157
- array(
158
- 'title' => "Elementor Website Builder",
159
- 'description' => "The SEO Live Assistant <strong>works on the front-end of Elementor</strong>, just as you're creating or editing your Elementor page.",
160
- 'mode' => "Free",
161
- 'option' => 'sq_sla_frontend',
162
- 'active' => SQ_Classes_Helpers_Tools::getOption('sq_sla_frontend'),
163
- 'optional' => true,
164
- 'connection' => false,
165
- 'logo' => 'sla_92.png',
166
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_assistant', 'settings'),
167
- 'details' => 'https://howto.squirrly.co/kb/squirrly-live-assistant/#elementor',
168
- 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_assistant'),
169
- ),//Live Assistant Elementor
170
- array(
171
- 'title' => "Google Rankings with GSC",
172
- 'description' => "Get <strong>Google Search Console (GSC)</strong> average <strong>positions, clicks and impressions</strong> for organic keywords.",
173
- 'mode' => "Free",
174
- 'option' => false,
175
- 'active' => true,
176
- 'optional' => false,
177
- 'connection' => true,
178
- 'logo' => 'ranking_92.png',
179
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_rankings', 'rankings'),
180
- 'details' => 'https://howto.squirrly.co/kb/ranking-serp-checker/',
181
- 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_rankings'),
182
- ),//Google SERP with GSC
183
- array(
184
- 'title' => "SEO Automation",
185
- 'description' => "Configure the <strong>SEO in 2 minutes</strong> for the entire website without writing a line of code.",
186
- 'mode' => "Free",
187
- 'option' => 'sq_auto_pattern',
188
- 'active' => SQ_Classes_Helpers_Tools::getOption('sq_auto_pattern'),
189
- 'optional' => true,
190
- 'connection' => false,
191
- 'logo' => 'automation_92.png',
192
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'automation'),
193
- 'details' => 'https://howto.squirrly.co/kb/seo-automation/',
194
- 'show' => true,
195
- ),//SEO Automation
196
- array(
197
- 'title' => "Bulk SEO & Snippets",
198
- 'description' => "Simplify the SEO process to <strong>Optimize all the SEO Snippets</strong> in just minutes. Edit Snippets in BULK for all post types directly from All Snippets",
199
- 'mode' => "Free",
200
- 'option' => false,
201
- 'active' => true,
202
- 'optional' => false,
203
- 'connection' => false,
204
- 'logo' => 'bulkseo_92.png',
205
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_bulkseo', 'bulkseo'),
206
- 'details' => 'https://howto.squirrly.co/kb/bulk-seo/',
207
- 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_bulkseo'),
208
- ),//Bulk SEO
209
- array(
210
- 'title' => "Frontend SEO Snippet",
211
- 'description' => "Optimize each page by loading the <strong>SEO Snippet directly on the front-end</strong> of your site. You have <strong>Custom SEO</strong> directly in the WP Admin Toolbar.",
212
- 'mode' => "Free",
213
- 'option' => 'sq_use_frontend',
214
- 'active' => SQ_Classes_Helpers_Tools::getOption('sq_use_frontend'),
215
- 'optional' => true,
216
- 'connection' => false,
217
- 'logo' => 'bulkseo_92.png',
218
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'metas'),
219
- 'details' => 'https://howto.squirrly.co/kb/seo-metas/#Add-Snippet-in-Frontend',
220
- 'show' => true,
221
- ),//Frontend SEO Snippet
222
- array(
223
- 'title' => "Open Graph Optimization",
224
- 'description' => "Add Social Open Graph protocol so that <strong>your Facebook Shares look awesome</strong>.",
225
- 'mode' => "Free",
226
- 'option' => 'sq_auto_facebook',
227
- 'active' => SQ_Classes_Helpers_Tools::getOption('sq_auto_facebook'),
228
- 'optional' => true,
229
- 'connection' => false,
230
- 'logo' => 'social_92.png',
231
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'social'),
232
- 'details' => 'https://howto.squirrly.co/kb/social-media-settings/#opengraph',
233
- 'show' => true,
234
- ),//Open Graph Optimization
235
- array(
236
- 'title' => "Twitter Card Optimization",
237
- 'description' => "Add Twitter Card in your tweets so that your <strong>Twitter Shares look awesome</strong>.",
238
- 'mode' => "Free",
239
- 'option' => 'sq_auto_twitter',
240
- 'active' => SQ_Classes_Helpers_Tools::getOption('sq_auto_twitter'),
241
- 'optional' => true,
242
- 'connection' => false,
243
- 'logo' => 'social_92.png',
244
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'social'),
245
- 'details' => 'https://howto.squirrly.co/kb/social-media-settings/#twittercard',
246
- 'show' => true,
247
- ),//Twitter Card Optimization
248
- array(
249
- 'title' => "Sitemap XML",
250
- 'description' => "Use Sitemap Generator to <strong>help your website get crawled</strong> and indexed by Search Engines. Add Sitemap Support for News, Posts, Pages, Products, Tags, Categories, Taxonomies, Images, Videos, etc.",
251
- 'mode' => "Free",
252
- 'option' => 'sq_auto_sitemap',
253
- 'active' => SQ_Classes_Helpers_Tools::getOption('sq_auto_sitemap'),
254
- 'optional' => true,
255
- 'connection' => false,
256
- 'logo' => 'sitemap_92.png',
257
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'sitemap'),
258
- 'details' => 'https://howto.squirrly.co/kb/sitemap-xml-settings/',
259
- 'show' => true,
260
- ), //XML Sitemap
261
- array(
262
- 'title' => "Google News",
263
- 'description' => "For a news website it's really important to have a Google News Sitemap. This way you will have <strong>all your News Posts instantly on Google News</strong>.",
264
- 'mode' => "Free",
265
- 'option' => false,
266
- 'active' => ($sitemap['sitemap-news'][1] == 1),
267
- 'optional' => false,
268
- 'connection' => false,
269
- 'logo' => 'news_92.png',
270
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'sitemap'),
271
- 'details' => 'https://howto.squirrly.co/kb/sitemap-xml-settings/#news_sitemap',
272
- 'show' => true,
273
- ), //Sitemap Instant Indexing
274
- array(
275
- 'title' => "JSON-LD Structured Data",
276
- 'description' => "Edit your website's JSON-LD Schema with Squirrly's powerful <strong>semantic SEO Markup Solution</strong>. Use the built-in Structured Data or add your custom Schema code.",
277
- 'mode' => "Free",
278
- 'option' => 'sq_auto_jsonld',
279
- 'active' => SQ_Classes_Helpers_Tools::getOption('sq_auto_jsonld'),
280
- 'optional' => true,
281
- 'connection' => false,
282
- 'logo' => 'jsonld_92.png',
283
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'jsonld'),
284
- 'details' => 'https://howto.squirrly.co/kb/json-ld-structured-data/',
285
- 'show' => true,
286
- ), //JSON-LD Optimizaition
287
- array(
288
- 'title' => "ACF Integration",
289
- 'description' => "Use <strong>Advanced Custom Fields (ACF)</strong> plugin to add advanced and custom JSON-LD Schema code on your pages.",
290
- 'mode' => "Free",
291
- 'option' => false,
292
- 'active' => true,
293
- 'optional' => false,
294
- 'connection' => false,
295
- 'logo' => 'jsonld_92.png',
296
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'jsonld'),
297
- 'details' => 'https://howto.squirrly.co/kb/json-ld-structured-data/#ACF',
298
- 'show' => true,
299
- ), //Advanced Custom Fields
300
- array(
301
- 'title' => "Google Analytics Tracking",
302
- 'description' => "Add the <strong>Google Analytics</strong> and <strong>Google Tag Manager</strong> tracking on your website.",
303
- 'mode' => "Free",
304
- 'option' => 'sq_auto_tracking',
305
- 'active' => SQ_Classes_Helpers_Tools::getOption('sq_auto_tracking'),
306
- 'optional' => true,
307
- 'connection' => false,
308
- 'logo' => 'traffic_92.png',
309
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'tracking'),
310
- 'details' => 'https://howto.squirrly.co/kb/google-analytics-tracking-tool/#google_analytics',
311
- 'show' => true,
312
- ), //Google Analytics Tracking
313
- array(
314
- 'title' => "AMP Support",
315
- 'description' => sprintf("Automatically load the <strong>Accelerate Mobile Pages (AMP)</strong> support for plugins like %sAMP for WP%s or %sAMP%s.", '<a href="https://wordpress.org/plugins/accelerated-mobile-pages/" target="_blank">', '</a>', '<a href="https://wordpress.org/plugins/amp/" target="_blank">', '</a>'),
316
- 'mode' => "Free",
317
- 'option' => 'sq_auto_amp',
318
- 'active' => SQ_Classes_Helpers_Tools::getOption('sq_auto_amp'),
319
- 'optional' => true,
320
- 'connection' => false,
321
- 'logo' => 'amp_92.png',
322
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'tracking'),
323
- 'details' => 'https://howto.squirrly.co/kb/google-analytics-tracking-tool/#amp_support',
324
- 'show' => true,
325
- ), //
326
- array(
327
- 'title' => "Facebook Pixel Tracking",
328
- 'description' => "Track visitors with <strong>website and e-commerce events</strong> for better Retargeting Campaigns. <strong>Integrated with Woocommerce</strong> plugin with events like Add to Cart, Initiate Checkout, Payment, and more.",
329
- 'mode' => "Free",
330
- 'option' => 'sq_auto_pixels',
331
- 'active' => SQ_Classes_Helpers_Tools::getOption('sq_auto_pixels'),
332
- 'optional' => true,
333
- 'connection' => false,
334
- 'logo' => 'traffic_92.png',
335
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'tracking'),
336
- 'details' => 'https://howto.squirrly.co/kb/google-analytics-tracking-tool/#facebook_pixel',
337
- 'show' => true,
338
- ), //Facebook Pixel Tracking
339
- array(
340
- 'title' => "Webmaster Tools",
341
- 'description' => "Connect your website with the popular webmasters like <strong>Google Search Console (GSC), Bing, Baidu, Yandex, Alexa</strong>.",
342
- 'mode' => "Free",
343
- 'option' => 'sq_auto_webmasters',
344
- 'active' => SQ_Classes_Helpers_Tools::getOption('sq_auto_webmasters'),
345
- 'optional' => true,
346
- 'connection' => false,
347
- 'logo' => 'websites_92.png',
348
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'webmaster'),
349
- 'details' => 'https://howto.squirrly.co/kb/webmaster-tools-settings/',
350
- 'show' => true,
351
- ), //Webmaster Tools
352
- array(
353
- 'title' => "Google Search Console (GSC)",
354
- 'description' => "Connect your website with <strong>Google Search Console</strong> and get insights based on <strong>organic searched keywords</strong>.",
355
- 'mode' => "Free",
356
- 'option' => 'sq_auto_webmasters',
357
- 'active' => (isset($connect['google_search_console']) ? $connect['google_search_console'] : true),
358
- 'optional' => false,
359
- 'connection' => true,
360
- 'logo' => 'websites_92.png',
361
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_rankings', 'settings'),
362
- 'details' => 'https://howto.squirrly.co/kb/ranking-serp-checker/#google_search_console',
363
- 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_rankings'),
364
- ), //Google Search Console
365
- array(
366
- 'title' => "Robots.txt File",
367
- 'description' => "Tell search engine crawlers which pages or files the crawler can or can't request from your site.",
368
- 'mode' => "Free",
369
- 'option' => 'sq_auto_robots',
370
- 'active' => SQ_Classes_Helpers_Tools::getOption('sq_auto_robots'),
371
- 'optional' => true,
372
- 'connection' => false,
373
- 'logo' => 'robots_92.png',
374
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'robots'),
375
- 'details' => false,
376
- 'show' => true,
377
- ), //Robots.txt File
378
- array(
379
- 'title' => "Favicon Site Icon",
380
- 'description' => "Add your <strong>website icon</strong> in the browser tabs and on other devices like <strong>iPhone, iPad and Android phones</strong>.",
381
- 'mode' => "Free",
382
- 'option' => 'sq_auto_favicon',
383
- 'active' => SQ_Classes_Helpers_Tools::getOption('sq_auto_favicon'),
384
- 'optional' => true,
385
- 'connection' => false,
386
- 'logo' => 'favicon_92.png',
387
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'favicon'),
388
- 'details' => 'https://howto.squirrly.co/kb/website-favicon-settings/',
389
- 'show' => true,
390
- ), //Favicon Site Icon
391
- array(
392
- 'title' => "SEO Links",
393
- 'description' => "Increase the <strong>website authority</strong> by correctly managing all the external links on your website. Instantly add <strong>nofollow</strong> to all external links.",
394
- 'mode' => "Free",
395
- 'option' => 'sq_auto_links',
396
- 'active' => (bool)SQ_Classes_Helpers_Tools::getOption('sq_auto_links'),
397
- 'optional' => true,
398
- 'connection' => false,
399
- 'logo' => 'links_92.png',
400
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'links'),
401
- 'details' => 'https://howto.squirrly.co/kb/seo-links/',
402
- 'show' => true,
403
- ), //SEO Links
404
- array(
405
- 'title' => "On-Page SEO METAs",
406
- 'description' => "Add all the required Search Engine METAs like <strong>Title Meta, Description, Canonical Link, Dublin Core, Robots Meta</strong> and more.",
407
- 'mode' => "Free",
408
- 'option' => 'sq_auto_metas',
409
- 'active' => SQ_Classes_Helpers_Tools::getOption('sq_auto_metas'),
410
- 'optional' => true,
411
- 'connection' => false,
412
- 'logo' => 'metas_92.png',
413
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'metas'),
414
- 'details' => 'https://howto.squirrly.co/kb/seo-metas/',
415
- 'show' => true,
416
- ), //On-Page SEO METAs
417
- array(
418
- 'title' => "Remove META Duplicate",
419
- 'description' => "Fix Duplicate Title, Description, Canonical, Dublin Core, Robots and more without writing a line of code.",
420
- 'mode' => "Free",
421
- 'option' => false,
422
- 'active' => true,
423
- 'optional' => false,
424
- 'connection' => false,
425
- 'logo' => 'metas_92.png',
426
- 'link' => false,
427
- 'details' => 'https://howto.squirrly.co/kb/seo-metas/#remove_duplicates',
428
- 'show' => true,
429
- ), //Remove META Duplicate
430
- array(
431
- 'title' => "404 URLs Redirects",
432
- 'description' => "Automatically <strong>redirect 404 URLs</strong> to the new URLs and keep the post authority. You can manage the <strong>Redirect Broken URLs</strong> for each post type.",
433
- 'mode' => "Free",
434
- 'option' => false,
435
- 'active' => true,
436
- 'optional' => false,
437
- 'connection' => false,
438
- 'logo' => 'redirect_92.png',
439
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'automation', array('#tab=nav-post')),
440
- 'details' => 'https://howto.squirrly.co/kb/seo-automation/#redirect_broken_urls',
441
- 'show' => true,
442
- ), //404 Redirects
443
- array(
444
- 'title' => "SEO Audit",
445
- 'description' => "Improve your Online Presence by knowing how your website is performing online. <strong>Generate and Compare SEO Audits</strong> and follow the Assistant to optimize the website.",
446
- 'mode' => "Free",
447
- 'option' => false,
448
- 'active' => true,
449
- 'optional' => false,
450
- 'connection' => true,
451
- 'logo' => 'audit_92.png',
452
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_audits', 'audits'),
453
- 'details' => 'https://howto.squirrly.co/kb/seo-audit/',
454
- 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_audit'),
455
- ), //SEO Audit
456
- array(
457
- 'title' => "Moz",
458
- 'description' => "Receive information about <strong>Backlinks and Authority from Moz.com</strong> directly in your SEO Audit report.",
459
- 'mode' => "Free",
460
- 'option' => false,
461
- 'active' => true,
462
- 'optional' => false,
463
- 'connection' => true,
464
- 'logo' => 'audit_92.png',
465
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_audits', 'audits'),
466
- 'details' => 'https://howto.squirrly.co/kb/seo-audit/#moz',
467
- 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_audit'),
468
- ), //SEO Audit Moz
469
- array(
470
- 'title' => "Majestic",
471
- 'description' => "Receive information about <strong>Backlinks from Majestic.com</strong> directly in your SEO Audit report.",
472
- 'mode' => "Free",
473
- 'option' => false,
474
- 'active' => true,
475
- 'optional' => false,
476
- 'connection' => true,
477
- 'logo' => 'audit_92.png',
478
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_audits', 'audits'),
479
- 'details' => 'https://howto.squirrly.co/kb/seo-audit/#majestic',
480
- 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_audit'),
481
- ), //SEO Audit Majestic
482
- array(
483
- 'title' => "Alexa",
484
- 'description' => "Receive <strong>Alexa Score and Backlinks</strong> information directly in your SEO Audit report.",
485
- 'mode' => "Free",
486
- 'option' => false,
487
- 'active' => true,
488
- 'optional' => false,
489
- 'connection' => true,
490
- 'logo' => 'audit_92.png',
491
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_audits', 'audits'),
492
- 'details' => 'https://howto.squirrly.co/kb/seo-audit/#alexa',
493
- 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_audit'),
494
- ), //SEO Audit Alexa
495
- array(
496
- 'title' => "Google PageSpeed Insights",
497
- 'description' => "Get precise information about the <strong>Average Loading Time</strong> of your website using Google PageSpeed Insights in your SEO Audit report.",
498
- 'mode' => "Free",
499
- 'option' => false,
500
- 'active' => true,
501
- 'optional' => false,
502
- 'connection' => true,
503
- 'logo' => 'audit_92.png',
504
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_audits', 'audits'),
505
- 'details' => 'https://howto.squirrly.co/kb/seo-audit/#google_pagespeed',
506
- 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_audit'),
507
- ), //SEO Audit Google PageSpeed
508
- array(
509
- 'title' => "Blogging Assistant",
510
- 'description' => "Add relevant <strong>Copyright-Free images, Tweets, Wikis, Blog Excerpts</strong> in your posts.",
511
- 'mode' => "Pro",
512
- 'option' => false,
513
- 'active' => true,
514
- 'optional' => false,
515
- 'connection' => true,
516
- 'logo' => 'sla_92.png',
517
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_assistant'),
518
- 'details' => 'https://howto.squirrly.co/kb/squirrly-live-assistant/#live_assistant_box',
519
- 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_assistant'),
520
- ), //Blogging Assistant
521
- array(
522
- 'title' => "Google SERP Checker",
523
- 'description' => "Accurately track your <strong>Google Rankings every day</strong> with Squirrly's user-friendly Google SERP Checker.",
524
- 'mode' => "Business",
525
- 'option' => false,
526
- 'active' => true,
527
- 'optional' => false,
528
- 'connection' => true,
529
- 'logo' => 'ranking_92.png',
530
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_rankings', 'rankings'),
531
- 'details' => 'https://howto.squirrly.co/kb/ranking-serp-checker/',
532
- 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_rankings'),
533
- ), //Google SERP Checker
534
- array(
535
- 'title' => "Copyright Free Images",
536
- 'description' => "Search <strong>Copyright Free Images</strong> in Squirrly Live Assistant and import them directly on your content.",
537
- 'mode' => "free",
538
- 'option' => false,
539
- 'active' => true,
540
- 'optional' => false,
541
- 'connection' => true,
542
- 'logo' => 'image_92.png',
543
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_assistant'),
544
- 'details' => 'https://howto.squirrly.co/kb/squirrly-live-assistant/#copyright_free_images',
545
- 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_assistant'),
546
- ), //Blogging Assistant
547
- array(
548
- 'title' => "WooCommerce SEO",
549
- 'description' => "<strong>Optimize all WooCommerce Products</strong> with Squirrly Live Assistant for better ranking. Add the required Metas, Google Tracking, Facebook Pixel Events and JSON-LD Schema. Useful for loading Rich Snippets on Google search results.",
550
- 'mode' => "Free",
551
- 'option' => false,
552
- 'active' => true,
553
- 'optional' => false,
554
- 'connection' => false,
555
- 'logo' => 'shop_92.png',
556
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_bulkseo', 'bulkseo', array('stype=product')),
557
- 'details' => 'https://howto.squirrly.co/kb/json-ld-structured-data/#woocommerce',
558
- 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_bulkseo'),
559
- ), //
560
- array(
561
- 'title' => "Polylang",
562
- 'description' => "<strong>Multilingual Support</strong> with Polylang plugin for fast multilingual optimization. Load Squirrly Live Assistant, SEO Snippets and Sitemap XML based on Polylang language.",
563
- 'mode' => "Free",
564
- 'option' => false,
565
- 'active' => true,
566
- 'optional' => false,
567
- 'connection' => false,
568
- 'logo' => 'multilingual_92.png',
569
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_bulkseo', 'bulkseo'),
570
- 'details' => 'https://howto.squirrly.co/wordpress-seo/compatibility-with-polylang-plugin/',
571
- 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_bulkseo'),
572
- ), //
573
- array(
574
- 'title' => "Local SEO",
575
- 'description' => "Optimize the website for <strong>local audience</strong> to have a huge advantage in front of your competitors.",
576
- 'mode' => "Free",
577
- 'option' => 'sq_auto_jsonld_local',
578
- 'active' => SQ_Classes_Helpers_Tools::getOption('sq_auto_jsonld_local'),
579
- 'optional' => true,
580
- 'connection' => false,
581
- 'logo' => 'local_92.png',
582
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'jsonld', array('#localseo')),
583
- 'details' => 'https://howto.squirrly.co/kb/json-ld-structured-data/#local_seo',
584
- 'show' => true,
585
- ), //
586
- array(
587
- 'title' => "Settings Assistant",
588
- 'description' => "With many of the Assistant panels in all Squirrly Setting pages, all a user needs to do is <strong>turn Red dots into Green dots</strong>.",
589
- 'mode' => "Free",
590
- 'option' => false,
591
- 'active' => true,
592
- 'optional' => false,
593
- 'connection' => false,
594
- 'logo' => 'audit_92.png',
595
- 'link' => false,
596
- 'details' => 'https://howto.squirrly.co/kb/squirrly-settings-assistant/',
597
- 'show' => true,
598
- ),//Live Assistant Elementor
599
- array(
600
- 'title' => "Fetch SEO Snippet",
601
- 'description' => sprintf("Automatically <strong>fetch the Squirrly Snippet</strong> on %sFacebook Sharing Debugger%s every time you update the content on a page.", '<a href="https://developers.facebook.com/tools/debug/" target="_blank">', '</a>'),
602
- 'mode' => "Free",
603
- 'option' => 'sq_sla_social_fetch',
604
- 'active' => SQ_Classes_Helpers_Tools::getOption('sq_sla_social_fetch'),
605
- 'optional' => true,
606
- 'connection' => true,
607
- 'logo' => 'social_92.png',
608
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_assistant', 'settings'),
609
- 'details' => 'https://howto.squirrly.co/kb/squirrly-live-assistant/#fetch_social',
610
- 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_assistant'),
611
- ), //
612
- array(
613
- 'title' => "SEO Images",
614
- 'description' => "Automatically <strong>downloads image and adds image alt tag</strong> for you, if you searched for images using your focus keyword <strong>inside the Blogging Assistant</strong>.",
615
- 'mode' => "Free",
616
- 'option' => 'sq_local_images',
617
- 'active' => SQ_Classes_Helpers_Tools::getOption('sq_local_images'),
618
- 'optional' => true,
619
- 'connection' => false,
620
- 'logo' => 'image_92.png',
621
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_assistant', 'settings'),
622
- 'details' => 'https://howto.squirrly.co/kb/squirrly-live-assistant/#seo_image',
623
- 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_assistant'),
624
- ), //
625
-
626
- array(
627
- 'title' => "Plugins Integration",
628
- 'description' => "Squirrly SEO works with all websites types and popular plugins like <strong>E-commerce plugins, Page Builder plugins, Cache plugins, SEO plugins, Multilingual plugins, and more</strong>.",
629
- 'mode' => "Free",
630
- 'option' => false,
631
- 'active' => true,
632
- 'optional' => false,
633
- 'connection' => false,
634
- 'logo' => 'settings_92.png',
635
- 'link' => false,
636
- 'details' => 'https://howto.squirrly.co/',
637
- 'show' => true,
638
- ), //
639
- array(
640
- 'title' => "Import SEO & Settings",
641
- 'description' => "Import the settings and SEO from other plugins so you can use only Squirrly SEO for on-page SEO.",
642
- 'mode' => "Free",
643
- 'option' => false,
644
- 'active' => true,
645
- 'optional' => false,
646
- 'connection' => false,
647
- 'logo' => 'settings_92.png',
648
- 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'backup'),
649
- 'details' => 'https://howto.squirrly.co/kb/import-export-seo-settings/',
650
- 'show' => true,
651
- ), //Import SEO & Settings
652
-
653
-
654
- );
655
-
656
- //for PHP 7.3.1 version
657
- $features = array_filter($features);
658
-
659
- return apply_filters('sq_features', $features);
660
- }
661
- }
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ class SQ_Core_BlockFeatures extends SQ_Classes_BlockController
5
+ {
6
+
7
+ public function init()
8
+ {
9
+ $this->show_view('Blocks/Features');
10
+ }
11
+
12
+ public function getFeatures()
13
+ {
14
+ $connect = SQ_Classes_Helpers_Tools::getOption('connect');
15
+ $sitemap = SQ_Classes_Helpers_Tools::getOption('sq_sitemap');
16
+ $features = array(
17
+ array(
18
+ 'title' => "Squirrly Cloud App",
19
+ 'description' => "Many Squirrly features work from <bold>cloud.squirrly.co</bold> and helps you optimize the content and manage the keywords, audits and rankings.",
20
+ 'mode' => "Free",
21
+ 'option' => false,
22
+ 'active' => true,
23
+ 'optional' => false,
24
+ 'connection' => true,
25
+ 'logo' => 'squirrly.png',
26
+ 'link' => SQ_Classes_RemoteController::getMySquirrlyLink('dashboard'),
27
+ 'details' => 'https://howto.squirrly.co/kb/squirrly-cloud-app/',
28
+ 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_panel'),
29
+ ), //Squirrly Cloud
30
+ array(
31
+ 'title' => "14 Days Journey Course",
32
+ 'description' => "<strong>Improve your Online Presence</strong> by knowing how your website is performing. All you need now is to start driving One of your most valuable pages to <strong>Better Rankings</strong>.",
33
+ 'mode' => "Free",
34
+ 'option' => false,
35
+ 'active' => SQ_Classes_Helpers_Tools::getOption('sq_seojourney'),
36
+ 'optional' => false,
37
+ 'connection' => true,
38
+ 'logo' => 'journey_92.png',
39
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_onboarding', 'journey1'),
40
+ 'details' => 'https://howto.squirrly.co/kb/install-squirrly-seo-plugin/#journey',
41
+ 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_journey'),
42
+ ), //14 Days Journey Course
43
+ array(
44
+ 'title' => "Next SEO Goals",
45
+ 'description' => "The AI SEO Consultant with <strong>over 100+ signals</strong> that prepares your goals to take you closer to the first page of Google.",
46
+ 'mode' => "Free",
47
+ 'option' => false,
48
+ 'active' => true,
49
+ 'optional' => false,
50
+ 'connection' => true,
51
+ 'logo' => 'goals_92.png',
52
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_dashboard', '', array('#tasks')),
53
+ 'details' => 'https://howto.squirrly.co/kb/next-seo-goals/',
54
+ 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_seogoals'),
55
+ ),//Next SEO Goals
56
+ array(
57
+ 'title' => "Progress & Achievements",
58
+ 'description' => "Displays <strong>Success Messages</strong> and <strong>Progress & Achievements</strong> for SEO Goals, Focus Pages, Audits, and Rankings",
59
+ 'mode' => "Free",
60
+ 'option' => false,
61
+ 'active' => true,
62
+ 'optional' => false,
63
+ 'connection' => true,
64
+ 'logo' => 'progress_92.png',
65
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_dashboard', '', array('#tasks')),
66
+ 'details' => 'https://howto.squirrly.co/kb/squirrly-seo-goals/',
67
+ 'show' => true,
68
+ ),//Progress
69
+ array(
70
+ 'title' => "Focus Pages",
71
+ 'description' => "Brings you clear methods to take your pages <strong>from never found to always found on Google</strong>. Rank your pages by influencing the right ranking factors.",
72
+ 'mode' => "Free",
73
+ 'option' => false,
74
+ 'active' => true,
75
+ 'optional' => false,
76
+ 'connection' => true,
77
+ 'logo' => 'focuspages_92.png',
78
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_focuspages', 'pagelist'),
79
+ 'details' => 'https://howto.squirrly.co/kb/focus-pages-page-audits/',
80
+ 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_focuspages'),
81
+ ), //Focus Pages
82
+ array(
83
+ 'title' => "Chances of Ranking",
84
+ 'description' => "Get information about <strong>Chances of Ranking for each Focus Page</strong> based on our <strong>Machine Learning Algorithms and Ranking Vision A.I.</strong>",
85
+ 'mode' => "Free",
86
+ 'option' => false,
87
+ 'active' => true,
88
+ 'optional' => false,
89
+ 'connection' => true,
90
+ 'logo' => 'focuspages_92.png',
91
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_focuspages', 'pagelist'),
92
+ 'details' => 'https://howto.squirrly.co/kb/focus-pages-page-audits/#chance_to_rank',
93
+ 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_focuspages'),
94
+ ), //Chances of Ranking
95
+ array(
96
+ 'title' => "Keyword Research",
97
+ 'description' => "Find the <strong>Best Keywords</strong> that your own website can rank for and get <strong>personalized competition data</strong> for each keyword. Provides info on Region that was used for Keyword Research.",
98
+ 'mode' => "Free",
99
+ 'option' => false ,
100
+ 'active' => true,
101
+ 'optional' => false,
102
+ 'connection' => true,
103
+ 'logo' => 'kr_92.png',
104
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_research', 'research'),
105
+ 'details' => 'https://howto.squirrly.co/kb/keyword-research-and-seo-strategy/',
106
+ 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_research'),
107
+ ), //Keyword Research
108
+ array(
109
+ 'title' => "Google Search & Trends",
110
+ 'description' => "Keyword Research uses tird-party services like <strong>Google Search API and Google Trends API</strong> to get live research data for each keyword. The research algorithm processes <strong>more than 100 processes</strong> for each keyword you selected.",
111
+ 'mode' => "Free",
112
+ 'option' => false,
113
+ 'active' => true,
114
+ 'optional' => false,
115
+ 'connection' => true,
116
+ 'logo' => 'kr_92.png',
117
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_research', 'research'),
118
+ 'details' => 'https://howto.squirrly.co/kb/keyword-research-and-seo-strategy/',
119
+ 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_research'),
120
+ ), //Keyword Research
121
+ array(
122
+ 'title' => "Briefcase",
123
+ 'description' => "Add keywords in your portfolio based on your current Campaigns, Trends, Performance <strong>for a successful SEO strategy</strong>.",
124
+ 'mode' => "Free",
125
+ 'option' => false,
126
+ 'active' => true,
127
+ 'optional' => false,
128
+ 'connection' => true,
129
+ 'logo' => 'briefcase_92.png',
130
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_research', 'briefcase'),
131
+ 'details' => 'https://howto.squirrly.co/kb/keyword-research-and-seo-strategy/#briefcase',
132
+ 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_research'),
133
+ ),//SEO Briefcase
134
+ array(
135
+ 'title' => "Live Assistant",
136
+ 'description' => "Publish <strong>content that is fully optimized</strong> for BOTH Search Engines and Humans – every single time!",
137
+ 'mode' => "Free",
138
+ 'option' => false,
139
+ 'active' => true,
140
+ 'optional' => false,
141
+ 'connection' => true,
142
+ 'logo' => 'sla_92.png',
143
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_assistant'),
144
+ 'details' => 'https://howto.squirrly.co/kb/squirrly-live-assistant/',
145
+ 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_assistant'),
146
+ ),//Live Assistant
147
+ array(
148
+ 'title' => "Keywords Optimization",
149
+ 'description' => "Optimize for <strong>Multiple Keywords at once in a Single Page</strong>. Automatically Calculates Optimization Scores for all secondary keywords and displays them to you as you’re typing your page.",
150
+ 'mode' => "Free",
151
+ 'option' => false,
152
+ 'active' => true,
153
+ 'optional' => false,
154
+ 'connection' => true,
155
+ 'logo' => 'briefcase_92.png',
156
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_assistant'),
157
+ 'details' => 'https://howto.squirrly.co/kb/squirrly-live-assistant/#add_keyword',
158
+ 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_assistant'),
159
+ ),//Keywords Optimization
160
+ array(
161
+ 'title' => "Elementor Website Builder",
162
+ 'description' => "The SEO Live Assistant <strong>works on the front-end of Elementor</strong>, just as you're creating or editing your Elementor page.",
163
+ 'mode' => "Free",
164
+ 'option' => 'sq_sla_frontend',
165
+ 'active' => SQ_Classes_Helpers_Tools::getOption('sq_sla_frontend'),
166
+ 'optional' => true,
167
+ 'connection' => false,
168
+ 'logo' => 'sla_92.png',
169
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_assistant', 'settings'),
170
+ 'details' => 'https://howto.squirrly.co/kb/squirrly-live-assistant/#elementor',
171
+ 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_assistant'),
172
+ ),//Live Assistant Elementor
173
+ array(
174
+ 'title' => "Google Rankings with GSC",
175
+ 'description' => "Get <strong>Google Search Console (GSC)</strong> average <strong>positions, clicks and impressions</strong> for organic keywords.",
176
+ 'mode' => "Free",
177
+ 'option' => false,
178
+ 'active' => true,
179
+ 'optional' => false,
180
+ 'connection' => true,
181
+ 'logo' => 'ranking_92.png',
182
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_rankings', 'rankings'),
183
+ 'details' => 'https://howto.squirrly.co/kb/ranking-serp-checker/',
184
+ 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_rankings'),
185
+ ),//Google SERP with GSC
186
+ array(
187
+ 'title' => "SEO Automation",
188
+ 'description' => "Configure the <strong>SEO in 2 minutes</strong> for the entire website without writing a line of code.",
189
+ 'mode' => "Free",
190
+ 'option' => 'sq_auto_pattern',
191
+ 'active' => SQ_Classes_Helpers_Tools::getOption('sq_auto_pattern'),
192
+ 'optional' => true,
193
+ 'connection' => false,
194
+ 'logo' => 'automation_92.png',
195
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'automation'),
196
+ 'details' => 'https://howto.squirrly.co/kb/seo-automation/',
197
+ 'show' => true,
198
+ ),//SEO Automation
199
+ array(
200
+ 'title' => "Bulk SEO & Snippets",
201
+ 'description' => "Simplify the SEO process to <strong>Optimize all the SEO Snippets</strong> in just minutes. Edit Snippets in BULK for all post types directly from All Snippets",
202
+ 'mode' => "Free",
203
+ 'option' => false,
204
+ 'active' => true,
205
+ 'optional' => false,
206
+ 'connection' => false,
207
+ 'logo' => 'bulkseo_92.png',
208
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_bulkseo', 'bulkseo'),
209
+ 'details' => 'https://howto.squirrly.co/kb/bulk-seo/',
210
+ 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_bulkseo'),
211
+ ),//Bulk SEO
212
+ array(
213
+ 'title' => "Frontend SEO Snippet",
214
+ 'description' => "Optimize each page by loading the <strong>SEO Snippet directly on the front-end</strong> of your site. You have <strong>Custom SEO</strong> directly in the WP Admin Toolbar.",
215
+ 'mode' => "Free",
216
+ 'option' => 'sq_use_frontend',
217
+ 'active' => SQ_Classes_Helpers_Tools::getOption('sq_use_frontend'),
218
+ 'optional' => true,
219
+ 'connection' => false,
220
+ 'logo' => 'bulkseo_92.png',
221
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'metas'),
222
+ 'details' => 'https://howto.squirrly.co/kb/seo-metas/#Add-Snippet-in-Frontend',
223
+ 'show' => true,
224
+ ),//Frontend SEO Snippet
225
+ array(
226
+ 'title' => "Open Graph Optimization",
227
+ 'description' => "Add Social Open Graph protocol so that <strong>your Facebook Shares look awesome</strong>.",
228
+ 'mode' => "Free",
229
+ 'option' => 'sq_auto_facebook',
230
+ 'active' => SQ_Classes_Helpers_Tools::getOption('sq_auto_facebook'),
231
+ 'optional' => true,
232
+ 'connection' => false,
233
+ 'logo' => 'social_92.png',
234
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'social'),
235
+ 'details' => 'https://howto.squirrly.co/kb/social-media-settings/#opengraph',
236
+ 'show' => true,
237
+ ),//Open Graph Optimization
238
+ array(
239
+ 'title' => "Twitter Card Optimization",
240
+ 'description' => "Add Twitter Card in your tweets so that your <strong>Twitter Shares look awesome</strong>.",
241
+ 'mode' => "Free",
242
+ 'option' => 'sq_auto_twitter',
243
+ 'active' => SQ_Classes_Helpers_Tools::getOption('sq_auto_twitter'),
244
+ 'optional' => true,
245
+ 'connection' => false,
246
+ 'logo' => 'social_92.png',
247
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'social'),
248
+ 'details' => 'https://howto.squirrly.co/kb/social-media-settings/#twittercard',
249
+ 'show' => true,
250
+ ),//Twitter Card Optimization
251
+ array(
252
+ 'title' => "Sitemap XML",
253
+ 'description' => "Use Sitemap Generator to <strong>help your website get crawled</strong> and indexed by Search Engines. Add Sitemap Support for News, Posts, Pages, Products, Tags, Categories, Taxonomies, Images, Videos, etc.",
254
+ 'mode' => "Free",
255
+ 'option' => 'sq_auto_sitemap',
256
+ 'active' => SQ_Classes_Helpers_Tools::getOption('sq_auto_sitemap'),
257
+ 'optional' => true,
258
+ 'connection' => false,
259
+ 'logo' => 'sitemap_92.png',
260
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'sitemap'),
261
+ 'details' => 'https://howto.squirrly.co/kb/sitemap-xml-settings/',
262
+ 'show' => true,
263
+ ), //XML Sitemap
264
+ array(
265
+ 'title' => "Google News",
266
+ 'description' => "For a news website it's really important to have a Google News Sitemap. This way you will have <strong>all your News Posts instantly on Google News</strong>.",
267
+ 'mode' => "Free",
268
+ 'option' => false,
269
+ 'active' => ($sitemap['sitemap-news'][1] == 1),
270
+ 'optional' => false,
271
+ 'connection' => false,
272
+ 'logo' => 'news_92.png',
273
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'sitemap'),
274
+ 'details' => 'https://howto.squirrly.co/kb/sitemap-xml-settings/#news_sitemap',
275
+ 'show' => true,
276
+ ), //Sitemap Instant Indexing
277
+ array(
278
+ 'title' => "JSON-LD Structured Data",
279
+ 'description' => "Edit your website's JSON-LD Schema with Squirrly's powerful <strong>semantic SEO Markup Solution</strong>. Use the built-in Structured Data or add your custom Schema code.",
280
+ 'mode' => "Free",
281
+ 'option' => 'sq_auto_jsonld',
282
+ 'active' => SQ_Classes_Helpers_Tools::getOption('sq_auto_jsonld'),
283
+ 'optional' => true,
284
+ 'connection' => false,
285
+ 'logo' => 'jsonld_92.png',
286
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'jsonld'),
287
+ 'details' => 'https://howto.squirrly.co/kb/json-ld-structured-data/',
288
+ 'show' => true,
289
+ ), //JSON-LD Optimizaition
290
+ array(
291
+ 'title' => "ACF Integration",
292
+ 'description' => "Use <strong>Advanced Custom Fields (ACF)</strong> plugin to add advanced and custom JSON-LD Schema code on your pages.",
293
+ 'mode' => "Free",
294
+ 'option' => false,
295
+ 'active' => true,
296
+ 'optional' => false,
297
+ 'connection' => false,
298
+ 'logo' => 'jsonld_92.png',
299
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'jsonld'),
300
+ 'details' => 'https://howto.squirrly.co/kb/json-ld-structured-data/#ACF',
301
+ 'show' => true,
302
+ ), //Advanced Custom Fields
303
+ array(
304
+ 'title' => "Google Analytics Tracking",
305
+ 'description' => "Add the <strong>Google Analytics</strong> and <strong>Google Tag Manager</strong> tracking on your website.",
306
+ 'mode' => "Free",
307
+ 'option' => 'sq_auto_tracking',
308
+ 'active' => SQ_Classes_Helpers_Tools::getOption('sq_auto_tracking'),
309
+ 'optional' => true,
310
+ 'connection' => false,
311
+ 'logo' => 'traffic_92.png',
312
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'tracking'),
313
+ 'details' => 'https://howto.squirrly.co/kb/google-analytics-tracking-tool/#google_analytics',
314
+ 'show' => true,
315
+ ), //Google Analytics Tracking
316
+ array(
317
+ 'title' => "AMP Support",
318
+ 'description' => sprintf("Automatically load the <strong>Accelerate Mobile Pages (AMP)</strong> support for plugins like %sAMP for WP%s or %sAMP%s.", '<a href="https://wordpress.org/plugins/accelerated-mobile-pages/" target="_blank">', '</a>', '<a href="https://wordpress.org/plugins/amp/" target="_blank">', '</a>'),
319
+ 'mode' => "Free",
320
+ 'option' => 'sq_auto_amp',
321
+ 'active' => SQ_Classes_Helpers_Tools::getOption('sq_auto_amp'),
322
+ 'optional' => true,
323
+ 'connection' => false,
324
+ 'logo' => 'amp_92.png',
325
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'tracking'),
326
+ 'details' => 'https://howto.squirrly.co/kb/google-analytics-tracking-tool/#amp_support',
327
+ 'show' => true,
328
+ ), //
329
+ array(
330
+ 'title' => "Facebook Pixel Tracking",
331
+ 'description' => "Track visitors with <strong>website and e-commerce events</strong> for better Retargeting Campaigns. <strong>Integrated with Woocommerce</strong> plugin with events like Add to Cart, Initiate Checkout, Payment, and more.",
332
+ 'mode' => "Free",
333
+ 'option' => 'sq_auto_pixels',
334
+ 'active' => SQ_Classes_Helpers_Tools::getOption('sq_auto_pixels'),
335
+ 'optional' => true,
336
+ 'connection' => false,
337
+ 'logo' => 'traffic_92.png',
338
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'tracking'),
339
+ 'details' => 'https://howto.squirrly.co/kb/google-analytics-tracking-tool/#facebook_pixel',
340
+ 'show' => true,
341
+ ), //Facebook Pixel Tracking
342
+ array(
343
+ 'title' => "Webmaster Tools",
344
+ 'description' => "Connect your website with the popular webmasters like <strong>Google Search Console (GSC), Bing, Baidu, Yandex, Alexa</strong>.",
345
+ 'mode' => "Free",
346
+ 'option' => 'sq_auto_webmasters',
347
+ 'active' => SQ_Classes_Helpers_Tools::getOption('sq_auto_webmasters'),
348
+ 'optional' => true,
349
+ 'connection' => false,
350
+ 'logo' => 'websites_92.png',
351
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'webmaster'),
352
+ 'details' => 'https://howto.squirrly.co/kb/webmaster-tools-settings/',
353
+ 'show' => true,
354
+ ), //Webmaster Tools
355
+ array(
356
+ 'title' => "Google Search Console (GSC)",
357
+ 'description' => "Connect your website with <strong>Google Search Console</strong> and get insights based on <strong>organic searched keywords</strong>.",
358
+ 'mode' => "Free",
359
+ 'option' => 'sq_auto_webmasters',
360
+ 'active' => (isset($connect['google_search_console']) ? $connect['google_search_console'] : true),
361
+ 'optional' => false,
362
+ 'connection' => true,
363
+ 'logo' => 'websites_92.png',
364
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_rankings', 'settings'),
365
+ 'details' => 'https://howto.squirrly.co/kb/ranking-serp-checker/#google_search_console',
366
+ 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_rankings'),
367
+ ), //Google Search Console
368
+ array(
369
+ 'title' => "Robots.txt File",
370
+ 'description' => "Tell search engine crawlers which pages or files the crawler can or can't request from your site.",
371
+ 'mode' => "Free",
372
+ 'option' => 'sq_auto_robots',
373
+ 'active' => SQ_Classes_Helpers_Tools::getOption('sq_auto_robots'),
374
+ 'optional' => true,
375
+ 'connection' => false,
376
+ 'logo' => 'robots_92.png',
377
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'robots'),
378
+ 'details' => false,
379
+ 'show' => true,
380
+ ), //Robots.txt File
381
+ array(
382
+ 'title' => "Favicon Site Icon",
383
+ 'description' => "Add your <strong>website icon</strong> in the browser tabs and on other devices like <strong>iPhone, iPad and Android phones</strong>.",
384
+ 'mode' => "Free",
385
+ 'option' => 'sq_auto_favicon',
386
+ 'active' => SQ_Classes_Helpers_Tools::getOption('sq_auto_favicon'),
387
+ 'optional' => true,
388
+ 'connection' => false,
389
+ 'logo' => 'favicon_92.png',
390
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'favicon'),
391
+ 'details' => 'https://howto.squirrly.co/kb/website-favicon-settings/',
392
+ 'show' => true,
393
+ ), //Favicon Site Icon
394
+ array(
395
+ 'title' => "SEO Links",
396
+ 'description' => "Increase the <strong>website authority</strong> by correctly managing all the external links on your website. Instantly add <strong>nofollow</strong> to all external links.",
397
+ 'mode' => "Free",
398
+ 'option' => 'sq_auto_links',
399
+ 'active' => (bool)SQ_Classes_Helpers_Tools::getOption('sq_auto_links'),
400
+ 'optional' => true,
401
+ 'connection' => false,
402
+ 'logo' => 'links_92.png',
403
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'links'),
404
+ 'details' => 'https://howto.squirrly.co/kb/seo-links/',
405
+ 'show' => true,
406
+ ), //SEO Links
407
+ array(
408
+ 'title' => "On-Page SEO METAs",
409
+ 'description' => "Add all the required Search Engine METAs like <strong>Title Meta, Description, Canonical Link, Dublin Core, Robots Meta</strong> and more.",
410
+ 'mode' => "Free",
411
+ 'option' => 'sq_auto_metas',
412
+ 'active' => SQ_Classes_Helpers_Tools::getOption('sq_auto_metas'),
413
+ 'optional' => true,
414
+ 'connection' => false,
415
+ 'logo' => 'metas_92.png',
416
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'metas'),
417
+ 'details' => 'https://howto.squirrly.co/kb/seo-metas/',
418
+ 'show' => true,
419
+ ), //On-Page SEO METAs
420
+ array(
421
+ 'title' => "Remove META Duplicate",
422
+ 'description' => "Fix Duplicate Title, Description, Canonical, Dublin Core, Robots and more without writing a line of code.",
423
+ 'mode' => "Free",
424
+ 'option' => false,
425
+ 'active' => true,
426
+ 'optional' => false,
427
+ 'connection' => false,
428
+ 'logo' => 'metas_92.png',
429
+ 'link' => false,
430
+ 'details' => 'https://howto.squirrly.co/kb/seo-metas/#remove_duplicates',
431
+ 'show' => true,
432
+ ), //Remove META Duplicate
433
+ array(
434
+ 'title' => "404 URLs Redirects",
435
+ 'description' => "Automatically <strong>redirect 404 URLs</strong> to the new URLs and keep the post authority. You can manage the <strong>Redirect Broken URLs</strong> for each post type.",
436
+ 'mode' => "Free",
437
+ 'option' => false,
438
+ 'active' => true,
439
+ 'optional' => false,
440
+ 'connection' => false,
441
+ 'logo' => 'redirect_92.png',
442
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'automation', array('#tab=nav-post')),
443
+ 'details' => 'https://howto.squirrly.co/kb/seo-automation/#redirect_broken_urls',
444
+ 'show' => true,
445
+ ), //404 Redirects
446
+ array(
447
+ 'title' => "SEO Audit",
448
+ 'description' => "Improve your Online Presence by knowing how your website is performing online. <strong>Generate and Compare SEO Audits</strong> and follow the Assistant to optimize the website.",
449
+ 'mode' => "Free",
450
+ 'option' => false,
451
+ 'active' => true,
452
+ 'optional' => false,
453
+ 'connection' => true,
454
+ 'logo' => 'audit_92.png',
455
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_audits', 'audits'),
456
+ 'details' => 'https://howto.squirrly.co/kb/seo-audit/',
457
+ 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_audit'),
458
+ ), //SEO Audit
459
+ array(
460
+ 'title' => "Moz",
461
+ 'description' => "Receive information about <strong>Backlinks and Authority from Moz.com</strong> directly in your SEO Audit report.",
462
+ 'mode' => "Free",
463
+ 'option' => false,
464
+ 'active' => true,
465
+ 'optional' => false,
466
+ 'connection' => true,
467
+ 'logo' => 'audit_92.png',
468
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_audits', 'audits'),
469
+ 'details' => 'https://howto.squirrly.co/kb/seo-audit/#moz',
470
+ 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_audit'),
471
+ ), //SEO Audit Moz
472
+ array(
473
+ 'title' => "Majestic",
474
+ 'description' => "Receive information about <strong>Backlinks from Majestic.com</strong> directly in your SEO Audit report.",
475
+ 'mode' => "Free",
476
+ 'option' => false,
477
+ 'active' => true,
478
+ 'optional' => false,
479
+ 'connection' => true,
480
+ 'logo' => 'audit_92.png',
481
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_audits', 'audits'),
482
+ 'details' => 'https://howto.squirrly.co/kb/seo-audit/#majestic',
483
+ 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_audit'),
484
+ ), //SEO Audit Majestic
485
+ array(
486
+ 'title' => "Alexa",
487
+ 'description' => "Receive <strong>Alexa Score and Backlinks</strong> information directly in your SEO Audit report.",
488
+ 'mode' => "Free",
489
+ 'option' => false,
490
+ 'active' => true,
491
+ 'optional' => false,
492
+ 'connection' => true,
493
+ 'logo' => 'audit_92.png',
494
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_audits', 'audits'),
495
+ 'details' => 'https://howto.squirrly.co/kb/seo-audit/#alexa',
496
+ 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_audit'),
497
+ ), //SEO Audit Alexa
498
+ array(
499
+ 'title' => "Google PageSpeed Insights",
500
+ 'description' => "Get precise information about the <strong>Average Loading Time</strong> of your website using Google PageSpeed Insights in your SEO Audit report.",
501
+ 'mode' => "Free",
502
+ 'option' => false,
503
+ 'active' => true,
504
+ 'optional' => false,
505
+ 'connection' => true,
506
+ 'logo' => 'audit_92.png',
507
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_audits', 'audits'),
508
+ 'details' => 'https://howto.squirrly.co/kb/seo-audit/#google_pagespeed',
509
+ 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_audit'),
510
+ ), //SEO Audit Google PageSpeed
511
+ array(
512
+ 'title' => "Blogging Assistant",
513
+ 'description' => "Add relevant <strong>Copyright-Free images, Tweets, Wikis, Blog Excerpts</strong> in your posts.",
514
+ 'mode' => "Pro",
515
+ 'option' => false,
516
+ 'active' => true,
517
+ 'optional' => false,
518
+ 'connection' => true,
519
+ 'logo' => 'sla_92.png',
520
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_assistant'),
521
+ 'details' => 'https://howto.squirrly.co/kb/squirrly-live-assistant/#live_assistant_box',
522
+ 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_assistant'),
523
+ ), //Blogging Assistant
524
+ array(
525
+ 'title' => "Google SERP Checker",
526
+ 'description' => "Accurately track your <strong>Google Rankings every day</strong> with Squirrly's user-friendly Google SERP Checker.",
527
+ 'mode' => "Business",
528
+ 'option' => false,
529
+ 'active' => true,
530
+ 'optional' => false,
531
+ 'connection' => true,
532
+ 'logo' => 'ranking_92.png',
533
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_rankings', 'rankings'),
534
+ 'details' => 'https://howto.squirrly.co/kb/ranking-serp-checker/',
535
+ 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_rankings'),
536
+ ), //Google SERP Checker
537
+ array(
538
+ 'title' => "Copyright Free Images",
539
+ 'description' => "Search <strong>Copyright Free Images</strong> in Squirrly Live Assistant and import them directly on your content.",
540
+ 'mode' => "free",
541
+ 'option' => false,
542
+ 'active' => true,
543
+ 'optional' => false,
544
+ 'connection' => true,
545
+ 'logo' => 'image_92.png',
546
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_assistant'),
547
+ 'details' => 'https://howto.squirrly.co/kb/squirrly-live-assistant/#copyright_free_images',
548
+ 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_assistant'),
549
+ ), //Blogging Assistant
550
+ array(
551
+ 'title' => "WooCommerce SEO",
552
+ 'description' => "<strong>Optimize all WooCommerce Products</strong> with Squirrly Live Assistant for better ranking. Add the required Metas, Google Tracking, Facebook Pixel Events and JSON-LD Schema. Useful for loading Rich Snippets on Google search results.",
553
+ 'mode' => "Free",
554
+ 'option' => false,
555
+ 'active' => true,
556
+ 'optional' => false,
557
+ 'connection' => false,
558
+ 'logo' => 'shop_92.png',
559
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_bulkseo', 'bulkseo', array('stype=product')),
560
+ 'details' => 'https://howto.squirrly.co/kb/json-ld-structured-data/#woocommerce',
561
+ 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_bulkseo'),
562
+ ), //
563
+ array(
564
+ 'title' => "Polylang",
565
+ 'description' => "<strong>Multilingual Support</strong> with Polylang plugin for fast multilingual optimization. Load Squirrly Live Assistant, SEO Snippets and Sitemap XML based on Polylang language.",
566
+ 'mode' => "Free",
567
+ 'option' => false,
568
+ 'active' => true,
569
+ 'optional' => false,
570
+ 'connection' => false,
571
+ 'logo' => 'multilingual_92.png',
572
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_bulkseo', 'bulkseo'),
573
+ 'details' => 'https://howto.squirrly.co/wordpress-seo/compatibility-with-polylang-plugin/',
574
+ 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_bulkseo'),
575
+ ), //
576
+ array(
577
+ 'title' => "Local SEO",
578
+ 'description' => "Optimize the website for <strong>local audience</strong> to have a huge advantage in front of your competitors.",
579
+ 'mode' => "Free",
580
+ 'option' => 'sq_auto_jsonld_local',
581
+ 'active' => SQ_Classes_Helpers_Tools::getOption('sq_auto_jsonld_local'),
582
+ 'optional' => true,
583
+ 'connection' => false,
584
+ 'logo' => 'local_92.png',
585
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'jsonld', array('#localseo')),
586
+ 'details' => 'https://howto.squirrly.co/kb/json-ld-structured-data/#local_seo',
587
+ 'show' => true,
588
+ ), //
589
+ array(
590
+ 'title' => "Settings Assistant",
591
+ 'description' => "With many of the Assistant panels in all Squirrly Setting pages, all a user needs to do is <strong>turn Red dots into Green dots</strong>.",
592
+ 'mode' => "Free",
593
+ 'option' => false,
594
+ 'active' => true,
595
+ 'optional' => false,
596
+ 'connection' => false,
597
+ 'logo' => 'audit_92.png',
598
+ 'link' => false,
599
+ 'details' => 'https://howto.squirrly.co/kb/squirrly-settings-assistant/',
600
+ 'show' => true,
601
+ ),//Live Assistant Elementor
602
+ array(
603
+ 'title' => "Fetch SEO Snippet",
604
+ 'description' => sprintf("Automatically <strong>fetch the Squirrly Snippet</strong> on %sFacebook Sharing Debugger%s every time you update the content on a page.", '<a href="https://developers.facebook.com/tools/debug/" target="_blank">', '</a>'),
605
+ 'mode' => "Free",
606
+ 'option' => 'sq_sla_social_fetch',
607
+ 'active' => SQ_Classes_Helpers_Tools::getOption('sq_sla_social_fetch'),
608
+ 'optional' => true,
609
+ 'connection' => true,
610
+ 'logo' => 'social_92.png',
611
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_assistant', 'settings'),
612
+ 'details' => 'https://howto.squirrly.co/kb/squirrly-live-assistant/#fetch_social',
613
+ 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_assistant'),
614
+ ), //
615
+ array(
616
+ 'title' => "SEO Images",
617
+ 'description' => "Automatically <strong>downloads image and adds image alt tag</strong> for you, if you searched for images using your focus keyword <strong>inside the Blogging Assistant</strong>.",
618
+ 'mode' => "Free",
619
+ 'option' => 'sq_local_images',
620
+ 'active' => SQ_Classes_Helpers_Tools::getOption('sq_local_images'),
621
+ 'optional' => true,
622
+ 'connection' => false,
623
+ 'logo' => 'image_92.png',
624
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_assistant', 'settings'),
625
+ 'details' => 'https://howto.squirrly.co/kb/squirrly-live-assistant/#seo_image',
626
+ 'show' => SQ_Classes_Helpers_Tools::getMenuVisible('show_assistant'),
627
+ ), //
628
+
629
+ array(
630
+ 'title' => "Plugins Integration",
631
+ 'description' => "Squirrly SEO works with all websites types and popular plugins like <strong>E-commerce plugins, Page Builder plugins, Cache plugins, SEO plugins, Multilingual plugins, and more</strong>.",
632
+ 'mode' => "Free",
633
+ 'option' => false,
634
+ 'active' => true,
635
+ 'optional' => false,
636
+ 'connection' => false,
637
+ 'logo' => 'settings_92.png',
638
+ 'link' => false,
639
+ 'details' => 'https://howto.squirrly.co/',
640
+ 'show' => true,
641
+ ), //
642
+ array(
643
+ 'title' => "Import SEO & Settings",
644
+ 'description' => "Import the settings and SEO from other plugins so you can use only Squirrly SEO for on-page SEO.",
645
+ 'mode' => "Free",
646
+ 'option' => false,
647
+ 'active' => true,
648
+ 'optional' => false,
649
+ 'connection' => false,
650
+ 'logo' => 'settings_92.png',
651
+ 'link' => SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'backup'),
652
+ 'details' => 'https://howto.squirrly.co/kb/import-export-seo-settings/',
653
+ 'show' => true,
654
+ ), //Import SEO & Settings
655
+
656
+
657
+ );
658
+
659
+ //for PHP 7.3.1 version
660
+ $features = array_filter($features);
661
+
662
+ return apply_filters('sq_features', $features);
663
+ }
664
+ }
core/BlockJorney.php CHANGED
@@ -1,48 +1,52 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- class SQ_Core_BlockJorney extends SQ_Classes_BlockController {
5
-
6
- public $days = false;
7
-
8
- public function init() {
9
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('jorney');
10
-
11
- if (!$seojorney = SQ_Classes_Helpers_Tools::getOption('sq_seojourney')) {
12
- echo $this->getView('Blocks/Jorney');
13
- }else {
14
-
15
- if (!SQ_Classes_Helpers_Tools::getOption('sq_seojourney_congrats')) {
16
- return false;
17
- }
18
-
19
- $days = 1;
20
- $seconds = strtotime(date('Y-m-d')) - strtotime($seojorney);
21
-
22
- if ($seconds > 0) {
23
- $days = $seconds / (3600 * 24);
24
- $days = (int)$days + 1;
25
- }
26
-
27
- $this->days = $days;
28
- echo $this->getView('Blocks/Jorney');
29
- }
30
- }
31
-
32
- public function getJourneyDays() {
33
- return $this->days;
34
- }
35
-
36
- /**
37
- * 14 days journey action
38
- */
39
- public function action() {
40
- switch (SQ_Classes_Helpers_Tools::getValue('action')) {
41
- //login action
42
- case 'sq_journey_close':
43
- SQ_Classes_Helpers_Tools::saveOptions('sq_seojourney_congrats', 0);
44
- break;
45
-
46
- }
47
- }
48
- }
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ class SQ_Core_BlockJorney extends SQ_Classes_BlockController
5
+ {
6
+
7
+ public $days = false;
8
+
9
+ public function init()
10
+ {
11
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('jorney');
12
+
13
+ if (!$seojorney = SQ_Classes_Helpers_Tools::getOption('sq_seojourney')) {
14
+ $this->show_view('Blocks/Jorney');
15
+ }else {
16
+
17
+ if (!SQ_Classes_Helpers_Tools::getOption('sq_seojourney_congrats')) {
18
+ return false;
19
+ }
20
+
21
+ $days = 1;
22
+ $seconds = strtotime(date('Y-m-d')) - strtotime($seojorney);
23
+
24
+ if ($seconds > 0) {
25
+ $days = $seconds / (3600 * 24);
26
+ $days = (int)$days + 1;
27
+ }
28
+
29
+ $this->days = $days;
30
+ $this->show_view('Blocks/Jorney');
31
+ }
32
+ }
33
+
34
+ public function getJourneyDays()
35
+ {
36
+ return $this->days;
37
+ }
38
+
39
+ /**
40
+ * 14 days journey action
41
+ */
42
+ public function action()
43
+ {
44
+ switch (SQ_Classes_Helpers_Tools::getValue('action')) {
45
+ //login action
46
+ case 'sq_journey_close':
47
+ SQ_Classes_Helpers_Tools::saveOptions('sq_seojourney_congrats', 0);
48
+ break;
49
+
50
+ }
51
+ }
52
+ }
core/BlockKnowledgeBase.php CHANGED
@@ -1,9 +1,11 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- class SQ_Core_BlockKnowledgeBase extends SQ_Classes_BlockController {
5
-
6
- public function init(){
7
- echo $this->getView('Blocks/KnowledgeBase');
8
- }
9
- }
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ class SQ_Core_BlockKnowledgeBase extends SQ_Classes_BlockController
5
+ {
6
+
7
+ public function init()
8
+ {
9
+ $this->show_view('Blocks/KnowledgeBase');
10
+ }
11
+ }
core/BlockSearch.php CHANGED
@@ -1,36 +1,39 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- class SQ_Core_BlockSearch extends SQ_Classes_BlockController {
5
-
6
- public function init() {
7
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('search');
8
-
9
- echo $this->getView('Blocks/Search');
10
- }
11
-
12
- public function action() {
13
- switch (SQ_Classes_Helpers_Tools::getValue('action')) {
14
- case 'sq_ajax_search':
15
-
16
- //SQ_Classes_Helpers_Tools::setHeader('json');
17
- $search_query = SQ_Classes_Helpers_Tools::getValue('search_query', '');
18
-
19
- $args = array();
20
- $args['action'] = 'lsvr-lore-ajax-search';
21
- $args['nonce'] = 'plugin_search';
22
- $args['search_query'] = $search_query;
23
-
24
- $parameters = "";
25
- foreach ($args as $key => $value) {
26
- if ($value <> '') {
27
- $parameters .= ($parameters == "" ? "" : "&") . $key . "=" . urlencode($value);
28
- }
29
- }
30
- $url = 'https://howto.squirrly.co/wp-admin/admin-ajax.php' . "?" . $parameters;
31
- echo SQ_Classes_RemoteController::sq_wpcall($url, array('sslverify' => false, 'timeout' => 10));
32
- exit();
33
- }
34
- }
35
-
36
- }
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ class SQ_Core_BlockSearch extends SQ_Classes_BlockController
5
+ {
6
+
7
+ public function init()
8
+ {
9
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('search');
10
+
11
+ $this->show_view('Blocks/Search');
12
+ }
13
+
14
+ public function action()
15
+ {
16
+ switch (SQ_Classes_Helpers_Tools::getValue('action')) {
17
+ case 'sq_ajax_search':
18
+
19
+ //SQ_Classes_Helpers_Tools::setHeader('json');
20
+ $search_query = SQ_Classes_Helpers_Tools::getValue('search_query', '');
21
+
22
+ $args = array();
23
+ $args['action'] = 'lsvr-lore-ajax-search';
24
+ $args['nonce'] = 'plugin_search';
25
+ $args['search_query'] = $search_query;
26
+
27
+ $parameters = "";
28
+ foreach ($args as $key => $value) {
29
+ if ($value <> '') {
30
+ $parameters .= ($parameters == "" ? "" : "&") . $key . "=" . urlencode($value);
31
+ }
32
+ }
33
+ $url = 'https://howto.squirrly.co/wp-admin/admin-ajax.php' . "?" . $parameters;
34
+ echo SQ_Classes_RemoteController::sq_wpcall($url, array('sslverify' => false, 'timeout' => 10));
35
+ exit();
36
+ }
37
+ }
38
+
39
+ }
core/BlockStats.php CHANGED
@@ -1,21 +1,23 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- class SQ_Core_BlockStats extends SQ_Classes_BlockController {
5
- var $stats = array();
6
-
7
- function init() {
8
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('global');
9
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('stats');
10
-
11
- parent::init();
12
-
13
- $dbtasks = json_decode(get_option(SQ_TASKS), true);
14
- if(isset($dbtasks['sq_stats'])) {
15
- $this->stats = $dbtasks['sq_stats'];
16
-
17
- echo $this->getView('Blocks/Stats');
18
- }
19
- }
20
-
21
- }
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ class SQ_Core_BlockStats extends SQ_Classes_BlockController
5
+ {
6
+ var $stats = array();
7
+
8
+ function init()
9
+ {
10
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('global');
11
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('stats');
12
+
13
+ parent::init();
14
+
15
+ $dbtasks = json_decode(get_option(SQ_TASKS), true);
16
+ if(isset($dbtasks['sq_stats'])) {
17
+ $this->stats = $dbtasks['sq_stats'];
18
+
19
+ $this->show_view('Blocks/Stats');
20
+ }
21
+ }
22
+
23
+ }
core/BlockSupport.php CHANGED
@@ -1,63 +1,66 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- class SQ_Core_BlockSupport extends SQ_Classes_BlockController {
5
-
6
- public function init() {
7
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('support');
8
-
9
- echo $this->getView('Blocks/Support');
10
- }
11
-
12
- /**
13
- * Called when Post action is triggered
14
- *
15
- * @return void
16
- */
17
- public function action() {
18
- switch (SQ_Classes_Helpers_Tools::getValue('action')) {
19
- case 'sq_feedback':
20
- $return = array();
21
-
22
- $feedback = SQ_Classes_Helpers_Tools::getValue('feedback', false);
23
-
24
- if ($feedback) {
25
- SQ_Classes_Helpers_Tools::saveOptions('sq_feedback', 1);
26
-
27
- $args['action'] = 'feedback';
28
- $args['value'] = $feedback;
29
- SQ_Classes_RemoteController::saveFeedback($args);
30
-
31
- $return['message'] = esc_html__("Thank you for your feedback.", _SQ_PLUGIN_NAME_);
32
- $return['success'] = true;
33
-
34
- } else {
35
- $return['message'] = esc_html__("No message.", _SQ_PLUGIN_NAME_);
36
- $return['error'] = true;
37
- }
38
-
39
- SQ_Classes_Helpers_Tools::setHeader('json');
40
- echo wp_json_encode($return);
41
- exit();
42
-
43
- case 'sq_uninstall_feedback':
44
- $reason['select'] = SQ_Classes_Helpers_Tools::getValue('reason_key', false);
45
- $reason['plugin'] = SQ_Classes_Helpers_Tools::getValue('reason_found_a_better_plugin', false);
46
- $reason['other'] = SQ_Classes_Helpers_Tools::getValue('reason_other', false);
47
-
48
- $args['action'] = 'deactivate';
49
- $args['value'] = json_encode($reason);
50
- SQ_Classes_RemoteController::saveFeedback($args);
51
-
52
- if (SQ_Classes_Helpers_Tools::getValue('option_remove_records', false)) {
53
- SQ_Classes_Helpers_Tools::saveOptions('sq_api', false);
54
- }
55
-
56
- SQ_Classes_Helpers_Tools::setHeader('json');
57
- echo wp_json_encode(array());
58
- exit();
59
- }
60
- exit();
61
- }
62
-
63
- }
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ class SQ_Core_BlockSupport extends SQ_Classes_BlockController
5
+ {
6
+
7
+ public function init()
8
+ {
9
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('support');
10
+
11
+ $this->show_view('Blocks/Support');
12
+ }
13
+
14
+ /**
15
+ * Called when Post action is triggered
16
+ *
17
+ * @return void
18
+ */
19
+ public function action()
20
+ {
21
+ switch (SQ_Classes_Helpers_Tools::getValue('action')) {
22
+ case 'sq_feedback':
23
+ $return = array();
24
+
25
+ $feedback = SQ_Classes_Helpers_Tools::getValue('feedback', false);
26
+
27
+ if ($feedback) {
28
+ SQ_Classes_Helpers_Tools::saveOptions('sq_feedback', 1);
29
+
30
+ $args['action'] = 'feedback';
31
+ $args['value'] = $feedback;
32
+ SQ_Classes_RemoteController::saveFeedback($args);
33
+
34
+ $return['message'] = esc_html__("Thank you for your feedback.", 'squirrly-seo');
35
+ $return['success'] = true;
36
+
37
+ } else {
38
+ $return['message'] = esc_html__("No message.", 'squirrly-seo');
39
+ $return['error'] = true;
40
+ }
41
+
42
+ SQ_Classes_Helpers_Tools::setHeader('json');
43
+ echo wp_json_encode($return);
44
+ exit();
45
+
46
+ case 'sq_uninstall_feedback':
47
+ $reason['select'] = SQ_Classes_Helpers_Tools::getValue('reason_key', false);
48
+ $reason['plugin'] = SQ_Classes_Helpers_Tools::getValue('reason_found_a_better_plugin', false);
49
+ $reason['other'] = SQ_Classes_Helpers_Tools::getValue('reason_other', false);
50
+
51
+ $args['action'] = 'deactivate';
52
+ $args['value'] = json_encode($reason);
53
+ SQ_Classes_RemoteController::saveFeedback($args);
54
+
55
+ if (SQ_Classes_Helpers_Tools::getValue('option_remove_records', false)) {
56
+ SQ_Classes_Helpers_Tools::saveOptions('sq_api', false);
57
+ }
58
+
59
+ SQ_Classes_Helpers_Tools::setHeader('json');
60
+ echo wp_json_encode(array());
61
+ exit();
62
+ }
63
+ exit();
64
+ }
65
+
66
+ }
core/BlockToolbar.php CHANGED
@@ -1,10 +1,12 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- class SQ_Core_BlockToolbar extends SQ_Classes_BlockController {
5
-
6
- function init() {
7
- echo $this->getView('Blocks/Toolbar');
8
- }
9
-
10
- }
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ class SQ_Core_BlockToolbar extends SQ_Classes_BlockController
5
+ {
6
+
7
+ function init()
8
+ {
9
+ $this->show_view('Blocks/Toolbar');
10
+ }
11
+
12
+ }
core/Blocklogin.php CHANGED
@@ -1,149 +1,159 @@
1
- <?php
2
- defined('ABSPATH') || die('Cheatin\' uh?');
3
-
4
- class SQ_Core_Blocklogin extends SQ_Classes_BlockController {
5
-
6
- public $message;
7
-
8
- public function init() {
9
- /* If logged in, then return */
10
- if (SQ_Classes_Helpers_Tools::getOption('sq_api') <> '') {
11
- return;
12
- }
13
-
14
- SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('login');
15
- SQ_Classes_Error::hookNotices();
16
- echo $this->getView('Blocks/Login');
17
- }
18
-
19
- /**
20
- * Called for sq_login on Post action
21
- * Login or register a user
22
- */
23
- public function action() {
24
- switch (SQ_Classes_Helpers_Tools::getValue('action')) {
25
- //login action
26
- case 'sq_login':
27
- $this->squirrlyLogin();
28
- break;
29
-
30
- //sign-up action
31
- case 'sq_register':
32
- $this->squirrlyRegister();
33
- break;
34
- }
35
- }
36
-
37
- /**
38
- * Register a new user to Squirrly and get the token
39
- * @global string $current_user
40
- */
41
- public function squirrlyRegister() {
42
- //if email is set
43
- if (SQ_Classes_Helpers_Tools::getIsset('email')) {
44
- //post arguments
45
- $args = array();
46
- $args['name'] = '';
47
- $args['user'] = SQ_Classes_Helpers_Tools::getValue('email');
48
-
49
- //create an object from json responce
50
- $responce = SQ_Classes_RemoteController::register($args);
51
- if (is_wp_error($responce)) {
52
- switch ($responce->get_error_message()) {
53
- case 'alreadyregistered':
54
- SQ_Classes_Error::setError(sprintf(esc_html__("We found your email, so it means you already have a Squirrly.co account. %sClick %sI already have an account%s and login. If you forgot your password, click %shere%s", _SQ_PLUGIN_NAME_), '<br />', '<a href="' . SQ_Classes_Helpers_Tools::getAdminUrl('sq_dashboard', 'login') . '" style="color:yellow">', '</a>', '<a href="' . _SQ_DASH_URL_ . '/login?action=lostpassword" target="_blank" style="color:yellow">', '</a>'));
55
- break;
56
- case 'invalidemail':
57
- SQ_Classes_Error::setError(esc_html__("Your email is not valid. Please enter a valid email.", _SQ_PLUGIN_NAME_));
58
- break;
59
- default:
60
- if (!SQ_Classes_Error::isError()) {
61
- SQ_Classes_Error::setError(esc_html__("We could not create your account. Please enter a valid email.", _SQ_PLUGIN_NAME_));
62
- }
63
- break;
64
- }
65
-
66
- } elseif (isset($responce->token)) { //check if token is set and save it
67
- SQ_Classes_Helpers_Tools::saveOptions('sq_api', $responce->token);
68
-
69
- //Connect to cloud with an unique blog Token for API access
70
- SQ_Classes_ObjController::getClass('SQ_Core_BlockConnect')->connectToCloud();
71
-
72
- //redirect users to onboarding if necessary
73
- if (!$onboarding = SQ_Classes_Helpers_Tools::getOption('sq_onboarding')) {
74
- wp_redirect(SQ_Classes_Helpers_Tools::getAdminUrl('sq_onboarding'));
75
- die();
76
- } else {
77
- wp_redirect(SQ_Classes_Helpers_Tools::getAdminUrl('sq_dashboard'));
78
- die();
79
- }
80
-
81
- } elseif (!SQ_Classes_Error::isError()) {
82
- //if unknown error
83
- SQ_Classes_Error::setError(sprintf(esc_html__("Error: Couldn't connect to host :( . Please contact your site's webhost (or webmaster) and request them to add %s to their IP whitelist.", _SQ_PLUGIN_NAME_), _SQ_APIV2_URL_));
84
- }
85
- } else {
86
- SQ_Classes_Error::setError(esc_html__("Your email is not set. Please enter a valid email.", _SQ_PLUGIN_NAME_));
87
- }
88
- }
89
-
90
- /**
91
- * Login a user to Squirrly and get the token
92
- */
93
- public function squirrlyLogin() {
94
- //if email is set
95
- if (SQ_Classes_Helpers_Tools::getIsset('email') && SQ_Classes_Helpers_Tools::getIsset('password') && isset($_POST['password'])) {
96
- //get the user and password
97
- $args['user'] = SQ_Classes_Helpers_Tools::getValue('email');
98
- $args['password'] = $_POST['password'];
99
-
100
- //get the responce from server on login call
101
- /** @var bool|WP_Error $responce */
102
- $responce = SQ_Classes_RemoteController::login($args);
103
-
104
- /** */
105
- if (is_wp_error($responce)) {
106
- switch ($responce->get_error_message()) {
107
- case 'badlogin':
108
- SQ_Classes_Error::setError(esc_html__("Wrong email or password!", _SQ_PLUGIN_NAME_));
109
- break;
110
- case 'multisite':
111
- SQ_Classes_Error::setError(esc_html__("You can only use this account for the URL you registered first!", _SQ_PLUGIN_NAME_));
112
- break;
113
- case 'disconnected':
114
- SQ_Classes_Error::setError(esc_html__("You disconnected your website from", _SQ_PLUGIN_NAME_) . ' ' . _SQ_DASH_URL_);
115
- break;
116
- default:
117
- if (!SQ_Classes_Error::isError()) {
118
- SQ_Classes_Error::setError(esc_html__("An error occured.", _SQ_PLUGIN_NAME_) . ':' . $responce->get_error_message());
119
- }
120
- break;
121
- }
122
-
123
- } elseif (isset($responce->token)) { //check if token is set and save it
124
- SQ_Classes_Helpers_Tools::saveOptions('sq_api', $responce->token);
125
-
126
- //Connect to cloud with an unique blog Token for API access
127
- SQ_Classes_ObjController::getClass('SQ_Core_BlockConnect')->connectToCloud();
128
-
129
- //redirect users to onboarding if necessary
130
- if (!$onboarding = SQ_Classes_Helpers_Tools::getOption('sq_onboarding')) {
131
- wp_redirect(SQ_Classes_Helpers_Tools::getAdminUrl('sq_onboarding'));
132
- die();
133
- } else {
134
- wp_redirect(SQ_Classes_Helpers_Tools::getAdminUrl('sq_dashboard'));
135
- die();
136
- }
137
-
138
- } elseif (!SQ_Classes_Error::isError()) {
139
- //if unknown error
140
- SQ_Classes_Error::setError(sprintf(esc_html__("Error: Couldn't connect to host :( . Please contact your site's webhost (or webmaster) and request them to add %s to their IP whitelist.", _SQ_PLUGIN_NAME_), _SQ_APIV2_URL_));
141
- }
142
-
143
- } else {
144
- SQ_Classes_Error::setError(esc_html__("Both fields are required.", _SQ_PLUGIN_NAME_));
145
- }
146
-
147
- }
148
-
149
- }
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || die('Cheatin\' uh?');
3
+
4
+ class SQ_Core_Blocklogin extends SQ_Classes_BlockController
5
+ {
6
+
7
+ public $message;
8
+
9
+ public function init()
10
+ {
11
+ /* If logged in, then return */
12
+ if (SQ_Classes_Helpers_Tools::getOption('sq_api') <> '') {
13
+ return;
14
+ }
15
+
16
+ SQ_Classes_ObjController::getClass('SQ_Classes_DisplayController')->loadMedia('login');
17
+ SQ_Classes_Error::hookNotices();
18
+ $this->show_view('Blocks/Login');
19
+ }
20
+
21
+ /**
22
+ * Called for sq_login on Post action
23
+ * Login or register a user
24
+ */
25
+ public function action()
26
+ {
27
+ switch (SQ_Classes_Helpers_Tools::getValue('action')) {
28
+ //login action
29
+ case 'sq_login':
30
+ $this->squirrlyLogin();
31
+ break;
32
+
33
+ //sign-up action
34
+ case 'sq_register':
35
+ $this->squirrlyRegister();
36
+ break;
37
+ }
38
+ }
39
+
40
+ /**
41
+ * Register a new user to Squirrly and get the token
42
+ *
43
+ * @global string $current_user
44
+ */
45
+ public function squirrlyRegister()
46
+ {
47
+ //if email is set
48
+ if (SQ_Classes_Helpers_Tools::getIsset('email')) {
49
+ //post arguments
50
+ $args = array();
51
+ $args['name'] = '';
52
+ $args['user'] = SQ_Classes_Helpers_Tools::getValue('email');
53
+
54
+ //create an object from json responce
55
+ $responce = SQ_Classes_RemoteController::register($args);
56
+ if (is_wp_error($responce)) {
57
+ switch ($responce->get_error_message()) {
58
+ case 'alreadyregistered':
59
+ SQ_Classes_Error::setError(sprintf(esc_html__("We found your email, so it means you already have a Squirrly.co account. %sClick %sI already have an account%s and login. If you forgot your password, click %shere%s", 'squirrly-seo'), '<br />', '<a href="' . SQ_Classes_Helpers_Tools::getAdminUrl('sq_dashboard', 'login') . '" style="color:yellow">', '</a>', '<a href="' . _SQ_DASH_URL_ . '/login?action=lostpassword" target="_blank" style="color:yellow">', '</a>'));
60
+ break;
61
+ case 'invalidemail':
62
+ SQ_Classes_Error::setError(esc_html__("Your email is not valid. Please enter a valid email.", 'squirrly-seo'));
63
+ break;
64
+ default:
65
+ if (!SQ_Classes_Error::isError()) {
66
+ SQ_Classes_Error::setError(esc_html__("We could not create your account. Please enter a valid email.", 'squirrly-seo'));
67
+ }
68
+ break;
69
+ }
70
+
71
+ } elseif (isset($responce->token)) { //check if token is set and save it
72
+ SQ_Classes_Helpers_Tools::saveOptions('sq_api', $responce->token);
73
+
74
+ //Connect to cloud with an unique blog Token for API access
75
+ SQ_Classes_ObjController::getClass('SQ_Core_BlockConnect')->connectToCloud();
76
+
77
+ //redirect users to onboarding if necessary
78
+ if (!$onboarding = SQ_Classes_Helpers_Tools::getOption('sq_onboarding')) {
79
+ wp_redirect(SQ_Classes_Helpers_Tools::getAdminUrl('sq_onboarding'));
80
+ die();
81
+ } else {
82
+ wp_redirect(SQ_Classes_Helpers_Tools::getAdminUrl('sq_dashboard'));
83
+ die();
84
+ }
85
+
86
+ } elseif (!SQ_Classes_Error::isError()) {
87
+ //if unknown error
88
+ SQ_Classes_Error::setError(sprintf(esc_html__("Error: Couldn't connect to host :( . Please contact your site's webhost (or webmaster) and request them to add %s to their IP whitelist.", 'squirrly-seo'), _SQ_APIV2_URL_));
89
+ }
90
+ } else {
91
+ SQ_Classes_Error::setError(esc_html__("Your email is not set. Please enter a valid email.", 'squirrly-seo'));
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Login a user to Squirrly and get the token
97
+ */
98
+ public function squirrlyLogin()
99
+ {
100
+ //if email is set
101
+ if (SQ_Classes_Helpers_Tools::getIsset('email') && SQ_Classes_Helpers_Tools::getIsset('password') && isset($_POST['password'])) {
102
+ //get the user and password
103
+ $args['user'] = SQ_Classes_Helpers_Tools::getValue('email');
104
+ $args['password'] = $_POST['password'];
105
+
106
+ //get the responce from server on login call
107
+ /**
108
+ *
109
+ *
110
+ * @var bool|WP_Error $responce
111
+ */
112
+ $responce = SQ_Classes_RemoteController::login($args);
113
+
114
+ /** */
115
+ if (is_wp_error($responce)) {
116
+ switch ($responce->get_error_message()) {
117
+ case 'badlogin':
118
+ SQ_Classes_Error::setError(esc_html__("Wrong email or password!", 'squirrly-seo'));
119
+ break;
120
+ case 'multisite':
121
+ SQ_Classes_Error::setError(esc_html__("You can only use this account for the URL you registered first!", 'squirrly-seo'));
122
+ break;
123
+ case 'disconnected':
124
+ SQ_Classes_Error::setError(esc_html__("You disconnected your website from", 'squirrly-seo') . ' ' . _SQ_DASH_URL_);
125
+ break;
126
+ default:
127
+ if (!SQ_Classes_Error::isError()) {
128
+ SQ_Classes_Error::setError(esc_html__("An error occured.", 'squirrly-seo') . ':' . $responce->get_error_message());
129
+ }
130
+ break;
131
+ }
132
+
133
+ } elseif (isset($responce->token)) { //check if token is set and save it
134
+ SQ_Classes_Helpers_Tools::saveOptions('sq_api', $responce->token);
135
+
136
+ //Connect to cloud with an unique blog Token for API access
137
+ SQ_Classes_ObjController::getClass('SQ_Core_BlockConnect')->connectToCloud();
138
+
139
+ //redirect users to onboarding if necessary
140
+ if (!$onboarding = SQ_Classes_Helpers_Tools::getOption('sq_onboarding')) {
141
+ wp_redirect(SQ_Classes_Helpers_Tools::getAdminUrl('sq_onboarding'));
142
+ die();
143
+ } else {
144
+ wp_redirect(SQ_Classes_Helpers_Tools::getAdminUrl('sq_dashboard'));
145
+ die();
146
+ }
147
+
148
+ } elseif (!SQ_Classes_Error::isError()) {
149
+ //if unknown error
150
+ SQ_Classes_Error::setError(sprintf(esc_html__("Error: Couldn't connect to host :( . Please contact your site's webhost (or webmaster) and request them to add %s to their IP whitelist.", 'squirrly-seo'), _SQ_APIV2_URL_));
151
+ }
152
+
153
+ } else {
154
+ SQ_Classes_Error::setError(esc_html__("Both fields are required.", 'squirrly-seo'));
155
+ }
156
+
157
+ }
158
+
159
+ }
debug/index.php CHANGED
@@ -1,230 +1,96 @@
1
- <?php
2
- defined( 'ABSPATH' ) || die( 'Cheatin\' uh?' );
3
-
4
- class SQ_Debug {
5
-
6
- /** @var array */
7
- private static $debug;
8
-
9
- public function logQueries($query) {
10
- self::dump($query);
11
- return $query;
12
- }
13
-
14
- public function _isAjax() {
15
- if (defined('DOING_AJAX') && DOING_AJAX) {
16
- return true;
17
- }
18
- return false;
19
- }
20
-
21
- /**
22
- * Get a value from $_POST / $_GET
23
- * if unavailable, take a default value
24
- *
25
- * @param string $key Value key
26
- * @param mixed $defaultValue (optional)
27
- * @return mixed Value
28
- */
29
- public static function getValue($key, $defaultValue = false) {
30
- if (!isset($key) OR empty($key) OR !is_string($key))
31
- return false;
32
- $ret = (isset($_POST[$key]) ? $_POST[$key] : (isset($_GET[$key]) ? $_GET[$key] : $defaultValue));
33
-
34
- if (is_string($ret) === true)
35
- $ret = urldecode(preg_replace('/((\%5C0+)|(\%00+))/i', '', urlencode($ret)));
36
- return !is_string($ret) ? $ret : stripslashes($ret);
37
- }
38
-
39
- public static function setValue($key, $value) {
40
- $_POST[$key] = $value;
41
- $_GET[$key] = $value;
42
- }
43
-
44
- /**
45
- * Check if the parameter is set
46
- *
47
- * @param string $key
48
- * @return boolean
49
- */
50
- public static function getIsset($key) {
51
- if (!isset($key) OR empty($key) OR !is_string($key))
52
- return false;
53
- return isset($_POST[$key]) ? true : (isset($_GET[$key]) ? true : false);
54
- }
55
-
56
- /**
57
- * Check if debug is called
58
- */
59
- public static function checkDebug() {
60
- //if debug is called
61
- if (self::getIsset('sq_debug')) {
62
- if (self::getValue('sq_debug') === 'on' && SQ_DEBUG) {
63
- error_reporting(E_ALL);
64
- @ini_set('display_errors', true);
65
- if (function_exists('register_shutdown_function')) {
66
- register_shutdown_function(array(new SQ_Debug(), 'showDebug'));
67
- }
68
- echo '<script>var SQ_DEBUG = true;</script>';
69
- }
70
- }
71
- }
72
-
73
- /**
74
- * Get the debug buffer
75
- * @param $buffer
76
- * @return mixed
77
- */
78
- public function getBuffer($buffer) {
79
- if (SQ_Classes_Helpers_Tools::isAjax()) {
80
- return $buffer;
81
- }
82
- if (!$this->getIsset('sq_debug')) {
83
- return $buffer;
84
- }
85
-
86
- return false;
87
- }
88
-
89
- /**
90
- * Store the debug for a later view
91
- *
92
- * @return bool|void
93
- */
94
- public static function dump() {
95
- if (SQ_DEBUG) {
96
- if (self::getValue('sq_debug') !== 'on') {
97
- return;
98
- }
99
-
100
- $output = '';
101
- $callee = array('file' => '', 'line' => '');
102
- if (function_exists('func_get_args')) {
103
- $arguments = func_get_args();
104
- $total_arguments = count($arguments);
105
- } else
106
- $arguments = array();
107
-
108
-
109
- $run_time = number_format(microtime(true) - SQ_REQUEST_TIME, 3);
110
- if (function_exists('debug_backtrace'))
111
- list($callee) = debug_backtrace();
112
-
113
- $output .= '<fieldset style="background: #FFFFFF; border: 1px #CCCCCC solid; padding: 5px; font-size: 9pt; margin: 0;">';
114
- $output .= '<legend style="background: #EEEEEE; padding: 2px; font-size: 8pt;">' . $callee['file'] . ' Time: ' . $run_time . ' @ line: ' . $callee['line']
115
- . '</legend><pre style="margin: 0; font-size: 8pt; text-align: left;">';
116
-
117
- $i = 0;
118
- foreach ($arguments as $argument) {
119
- if (count($arguments) > 1)
120
- $output .= "\n" . '<strong>#' . (++$i) . ' of ' . $total_arguments . '</strong>: ';
121
-
122
- // if argument is boolean, false value does not display, so ...
123
- if (is_bool($argument))
124
- $argument = ($argument) ? 'TRUE' : 'FALSE';
125
- else
126
- if (is_object($argument) && function_exists('array_reverse') && function_exists('class_parents'))
127
- $output .= implode("\n" . '|' . "\n", array_reverse(class_parents($argument))) . "\n" . '|' . "\n";
128
-
129
- $output .= htmlspecialchars(print_r($argument, TRUE))
130
- . ((is_object($argument) && function_exists('spl_object_hash')) ? spl_object_hash($argument) : '');
131
- }
132
- $output .= "</pre>";
133
- $output .= "</fieldset>";
134
-
135
- self::$debug[] = $output;
136
- }
137
- }
138
-
139
- /**
140
- * Show the debug dump
141
- */
142
- public static function showDebug() {
143
- SQ_Classes_Helpers_Tools::setHeader('html');
144
- error_get_last();
145
- echo "Debug result: <br />" . '<div id="wpcontent">' . '<br />' . implode('<br />', (array)self::$debug) . '<div>';
146
-
147
- $run_time = number_format(microtime(true) - SQ_REQUEST_TIME, 3);
148
- $pps = number_format(1 / $run_time, 0);
149
- $memory_avail = ini_get('memory_limit');
150
- $memory_used = number_format(memory_get_usage(true) / (1024 * 1024), 2);
151
- $memory_peak = number_format(memory_get_peak_usage(true) / (1024 * 1024), 2);
152
-
153
- if (PHP_SAPI == 'cli') {
154
- // if run for command line, display some info
155
- $debug = PHP_EOL
156
- . "=======================