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 -52
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