PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.1.4
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.1.4
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
acymailing / WpInit / Router.php

Router.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 10.1.4, at WpInit/Router.php

271 lines 8.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AcyMailing\WpInit;
4
5 use AcyMailing\Classes\PluginClass;
6
7 class Router
8 {
9 var $activation;
10
11 public function __construct()
12 {
13 add_action('wp_ajax_acymailing_router', [$this, 'router']);
14 if (!acym_isAdmin()) {
15 add_action('wp_loaded', [$this, 'frontRouter']);
16 }
17
18 $pages = [
19 'automation',
20 'bounces',
21 'campaigns',
22 'configuration',
23 'dashboard',
24 'dynamics',
25 'fields',
26 'file',
27 'followups',
28 'forms',
29 'language',
30 'lists',
31 'mails',
32 'override',
33 'queue',
34 'segments',
35 'stats',
36 'users',
37 ];
38 $headerPages = [
39 'automation',
40 'bounces',
41 'campaigns',
42 'configuration',
43 'dashboard',
44 'fields',
45 'followups',
46 'forms',
47 'lists',
48 'mails',
49 'override',
50 'queue',
51 'segments',
52 'stats',
53 'users',
54 ];
55 foreach ($pages as $page) {
56 if (in_array($page, $headerPages)) {
57 add_action('load-acymailing_page_acymailing_'.$page, [$this, 'waitHeaders']);
58 }
59 add_action('admin_print_scripts-acymailing_page_acymailing_'.$page, [$this, 'disableJsBreakingPages']);
60 add_action('admin_print_styles-acymailing_page_acymailing_'.$page, [$this, 'removeCssBreakingPages']);
61 }
62 add_action('admin_print_scripts-toplevel_page_acymailing_dashboard', [$this, 'disableJsBreakingPages']);
63 add_action('admin_print_styles-toplevel_page_acymailing_dashboard', [$this, 'removeCssBreakingPages']);
64 add_action('wp_enqueue_media', [$this, 'protectAcyMailingPages'], 100);
65 add_action('init', [$this, 'autologin']);
66 }
67
68 public function protectAcyMailingPages()
69 {
70 $page = isset($_REQUEST['page']) ? sanitize_text_field(wp_unslash($_REQUEST['page'])) : '';
71 if (empty($page) || strpos($page, 'acymailing_') === false) return;
72
73 wp_dequeue_script('responsive-lightbox-admin-select2');
74 wp_dequeue_style('responsive-lightbox-admin-select2');
75
76 wp_dequeue_script('dsm-select-two');
77 wp_dequeue_style('dsm-select-two');
78 }
79
80 public function waitHeaders()
81 {
82 ob_start();
83 }
84
85 public function disableJsBreakingPages()
86 {
87 remove_action('admin_print_scripts', 'print_emoji_detection_script');
88
89 remove_action('wp_enqueue_media', '\\Slideshowck\\Tinymce\\register_scripts_styles');
90
91 remove_action('wp_enqueue_media', '\\Sgdg\\Admin\\TinyMCE\\register_scripts_styles');
92
93 wp_dequeue_script('select2.js');
94
95 wp_dequeue_script('checkout_fields_js');
96
97 wp_dequeue_script('wp-optimize-minify-admin-purge');
98
99 wp_dequeue_script('happy-elementor-addons-select2');
100 wp_dequeue_script('select2');
101 }
102
103 public function removeCssBreakingPages()
104 {
105 wp_dequeue_style('saswp-main-css');
106 wp_dequeue_style('WP REST API Controller');
107 wp_dequeue_style('wpml-select-2');
108 wp_dequeue_style('swcfpc_admin_css');
109
110 wp_dequeue_style('happy-elementor-addons-select2');
111 wp_dequeue_style('select2');
112
113 wp_dequeue_style('qlwapp-admin-menu');
114 }
115
116 public function frontRouter()
117 {
118 $page = acym_getVar('string', 'page');
119 if (empty($page) || $page !== ACYM_COMPONENT.'_front') return;
120
121 $this->router(true);
122 }
123
124 public function router($front = false)
125 {
126 displayFreeTrialMessage();
127
128
129 if (!$front) auth_redirect();
130
131 $acyActivation = new Activation();
132 if (is_multisite()) {
133 $currentBlog = get_current_blog_id();
134 $sites = function_exists('get_sites') ? get_sites() : wp_get_sites();
135
136 foreach ($sites as $site) {
137 if (is_object($site)) {
138 $site = get_object_vars($site);
139 }
140 switch_to_blog($site['blog_id']);
141 acym_config(true);
142 $acyActivation->updateAcym();
143 }
144
145 switch_to_blog($currentBlog);
146 } else {
147 $acyActivation->updateAcym();
148 }
149
150 if (file_exists(ACYM_FOLDER.'update.php')) {
151 unlink(ACYM_FOLDER.'update.php');
152 }
153
154 $config = acym_config(true);
155
156 $ctrl = acym_getVar('cmd', 'ctrl', '');
157 $task = acym_getVar('cmd', 'task', '');
158
159 if (!$front && acym_isAdmin() && file_exists(ACYM_NEW_FEATURES_SPLASHSCREEN_JSON) && is_writable(ACYM_NEW_FEATURES_SPLASHSCREEN_JSON)) {
160 $ctrl = 'dashboard';
161 $task = 'features';
162 acym_setVar('ctrl', $ctrl);
163 acym_setVar('task', $task);
164 }
165
166 $needToMigrate = $config->get('migration') == 0 && acym_existsAcyMailing59() && acym_getVar('string', 'task') !== 'migrationDone';
167 $forceDashboard = !$front && ($needToMigrate || $config->get('walk_through', 0) == 1) && !(defined('DOING_AJAX') && DOING_AJAX) && 'dynamics' !== $ctrl;
168 if ($forceDashboard) {
169 $ctrl = 'dashboard';
170 acym_setVar('ctrl', $ctrl);
171 }
172
173 if (empty($ctrl)) {
174 $ctrl = str_replace(ACYM_COMPONENT.'_', '', acym_getVar('cmd', 'page', ''));
175
176 if (empty($ctrl)) {
177 echo acym_translation('ACYM_PAGE_NOT_FOUND');
178
179 $noCache = acym_getVar('int', 'nocache', 0);
180 if (!empty($noCache)) {
181 acym_redirect(acym_rootURI());
182 }
183
184 return;
185 }
186
187 acym_setVar('ctrl', $ctrl);
188 }
189
190 $this->deactivateHookAdminFooter();
191 $subNamespace = $front ? 'Front' : '';
192 $controllerNamespace = 'AcyMailing\\'.$subNamespace.'Controllers\\'.ucfirst($ctrl).'Controller';
193
194 if (!class_exists($controllerNamespace)) {
195 echo acym_translation('ACYM_PAGE_NOT_FOUND').': '.$ctrl;
196
197 return;
198 }
199
200 if (!$front && acym_isAdmin() && $task != 'edit' && !(defined('DOING_AJAX') && DOING_AJAX)) {
201 $pluginClass = new PluginClass();
202 $installedPlugins = $pluginClass->getAll('title');
203 $newPlugins = json_decode(ACYM_AVAILABLE_PLUGINS);
204 foreach ($newPlugins as $onePlugin) {
205 if (empty($installedPlugins[$onePlugin->name])) continue;
206 if ($installedPlugins[$onePlugin->name]->type !== 'ADDON') continue;
207
208 acym_enqueueMessage(
209 acym_translationSprintf(
210 'ACYM_NEW_PLUGIN_FORMAT',
211 $onePlugin->name,
212 '<a target="_blank" style="color: #00a5ff;" href="'.$onePlugin->downloadlink.'">'.acym_translation('ACYM_CLICK_HERE').'</a>'
213 ),
214 'error'
215 );
216 }
217 }
218
219 $controller = new $controllerNamespace();
220 if (empty($task)) {
221 $task = acym_getVar('cmd', 'defaulttask', $controller->defaulttask);
222 }
223
224 if ($forceDashboard && !method_exists($controller, $task)) {
225 $task = 'listing';
226 acym_setVar('task', $task);
227 }
228
229 $controller->call($task);
230 }
231
232 public function autologin()
233 {
234 $subId = acym_getVar('int', 'autoSubId');
235 $subKey = acym_getVar('string', 'subKey');
236
237 if (empty($subId) || empty($subKey)) {
238 return;
239 }
240
241 $currentUrl = acym_currentURL();
242 $cleanedUrl = acym_cleanUrl($currentUrl, ['autoSubId', 'subKey']);
243
244 $config = acym_config();
245 if ($config->get('autologin_urls', 0) == 0) {
246 acym_redirect($cleanedUrl);
247 }
248
249 $cmsId = acym_loadResult('SELECT `cms_id` FROM #__acym_user WHERE `id` = '.intval($subId).' AND `key` = '.acym_escapeDB($subKey));
250 if (empty($cmsId) || $cmsId === acym_currentUserId()) {
251 acym_redirect($cleanedUrl);
252 }
253
254 $user = get_user_by('id', $cmsId);
255
256 if (!is_wp_error($user)) {
257 wp_clear_auth_cookie();
258 wp_set_current_user($user->ID);
259 wp_set_auth_cookie($user->ID);
260
261 acym_redirect($cleanedUrl);
262 }
263 }
264
265 private function deactivateHookAdminFooter()
266 {
267 remove_action('admin_footer', 'Freemius::_enrich_ajax_url');
268 remove_action('admin_footer', 'Freemius::_open_support_forum_in_new_page');
269 }
270 }
271