PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 2.1.10
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v2.1.10
3.1.13 3.1.12 3.1.11 3.1.10 3.1.9 3.1.8 3.1.7 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 All 122 releases
firebox / Inc / Core / Admin / Admin.php

Admin.php in FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment 2.1.10, at Inc/Core/Admin/Admin.php

495 lines 13.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package FireBox
4 * @version 2.1.10 Free
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2024 FirePlugins All Rights Reserved
9 * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
10 */
11
12 namespace FireBox\Core\Admin;
13
14 if (!defined('ABSPATH'))
15 {
16 exit; // Exit if accessed directly.
17 }
18
19 class Admin
20 {
21 /**
22 * Admin Page Settings
23 *
24 * @var AdminPageSettings
25 */
26 private $pageSettings;
27
28 /**
29 * Library
30 *
31 * @var Library
32 */
33 public $library;
34
35 /**
36 * Admin constructor
37 */
38 public function __construct()
39 {
40
41 add_action('admin_enqueue_scripts', [$this, 'global_backend_assets'], 20);
42
43
44 add_action('enqueue_block_editor_assets', [$this, 'block_editor_assets'], -100);
45
46 add_action('current_screen', [$this, 'current_screen']);
47
48 // init dependencies
49 $this->initDependencies();
50
51 // Admin Page Settings
52 $this->pageSettings = new AdminPageSettings();
53
54 // run actions
55 $this->handleActions();
56
57 // run filters
58 $this->handleFilters();
59 }
60
61 public function block_editor_assets()
62 {
63 wp_register_script(
64 'firebox-store',
65 FBOX_MEDIA_ADMIN_URL . 'js/helpers/store.js',
66 [],
67 FBOX_VERSION,
68 false
69 );
70 }
71
72
73 public function global_backend_assets()
74 {
75 wp_register_style(
76 'firebox-admin-lite',
77 FBOX_MEDIA_ADMIN_URL . 'css/lite.css',
78 [],
79 FBOX_VERSION,
80 false
81 );
82 wp_enqueue_style('firebox-admin-lite');
83 }
84
85
86 public function current_screen($screen)
87 {
88 add_action('admin_enqueue_scripts', [$this, 'registerEditorMedia'], 11);
89
90 $allowed_pages = [
91 'toplevel_page_firebox',
92 'firebox_page_firebox-campaigns',
93 'firebox_page_firebox-analytics',
94 'firebox_page_firebox-submissions',
95 'firebox_page_firebox-settings',
96 'firebox_page_firebox-import'
97 ];
98
99 if (isset($screen->id) && in_array($screen->id, $allowed_pages))
100 {
101 add_action('admin_enqueue_scripts', [$this, 'registerMediaAdminPages'], 20);
102
103 add_filter('admin_footer_text', [$this, 'admin_footer_text']);
104 }
105 }
106
107 public function registerEditorMedia()
108 {
109 wp_register_script('firebox-admin-editor', false);
110 wp_enqueue_script('firebox-admin-editor');
111
112 $data = [
113 'media_url' => FBOX_MEDIA_URL,
114 'timezone' => $this->getTimezone()
115 ];
116
117 wp_localize_script('firebox-admin-editor', 'fbox_admin_editor_js_object', $data);
118
119 }
120
121 public function admin_footer_text()
122 {
123 return;
124 }
125
126 /**
127 * Load admin dependencies.
128 *
129 * @return void
130 */
131 private function initDependencies()
132 {
133 new Media();
134
135 $this->library = firebox()->library;
136
137 // Update Notice
138 $valid_pages = [
139 'firebox',
140 'firebox-campaigns',
141 'firebox-analytics',
142 'firebox-import',
143 'firebox-submissions',
144 'firebox-settings'
145 ];
146 $updateNotice = new \FPFramework\Admin\Includes\UpdateNotice(
147 firebox()->plugin_slug,
148 firebox()->plugin_name,
149 FBOX_VERSION,
150 $valid_pages
151 );
152 $updateNotice->init();
153
154 // Review Reminder
155 new \FPFramework\Admin\Includes\ReviewReminder(
156 firebox()->plugin_slug,
157 firebox()->plugin_name,
158 FBOX_MEDIA_ADMIN_URL
159 );
160 }
161
162 /**
163 * Runs all Admin Actions
164 *
165 * @return void
166 */
167 private function handleActions()
168 {
169 add_action('admin_enqueue_scripts', [$this, 'registerGlobalMedia'], 20);
170
171
172 add_action('plugin_action_links_' . plugin_basename(FBOX_PLUGIN_BASE_FILE), [$this, 'plugin_action_links']);
173
174 }
175
176 public function registerGlobalMedia()
177 {
178 wp_register_style('firebox-global-admin', false);
179 wp_enqueue_style('firebox-global-admin');
180 $css = '
181 #adminmenu li.toplevel_page_firebox img {
182 max-height: 22px;
183 padding-top: 6px;
184 }
185 ';
186 wp_add_inline_style('firebox-global-admin', $css);
187 }
188
189
190 /**
191 * Adds extra links to the Plugins page in the free version.
192 * - Upgrade to Pro button
193 *
194 * @param array $links
195 *
196 * @return array
197 */
198 public function plugin_action_links($links)
199 {
200 $links = array_merge( $links, array(
201 '<a href="' . FBOX_GO_PRO_URL . '" class="firebox-go-pro-link" title="' . fpframework()->_('FPF_UNLOCK_MORE_FEATURES_WITH_PRO_READ_MORE') . '">' . firebox()->_('FB_UPGRADE_20_OFF') . '</a>'
202 ) );
203
204 return $links;
205 }
206
207
208 /**
209 * Runs all Admin Filters
210 *
211 * @return void
212 */
213 private function handleFilters()
214 {
215 add_filter('admin_body_class', [$this, 'setPluginPageBodyClass']);
216 add_filter('plugin_row_meta' , [$this, 'addPluginMetaLinks'], 10, 4);
217 }
218
219 /**
220 * Adds extra links to the plugins page.
221 *
222 * @param array $links
223 * @param string $file
224 * @param array $plugin_data
225 * @param string $status
226 *
227 * @return array
228 */
229 public function addPluginMetaLinks($links, $file, $plugin_data, $status)
230 {
231 if ($file === FBOX_PLUGIN_BASENAME)
232 {
233 $links['rate'] = '<a href="https://wordpress.org/support/plugin/firebox/reviews/?filter=5#new-post" aria-label="' . esc_attr__(firebox()->_('FB_RATE_FIREBOX')) . '" target="_blank">' . esc_html__(firebox()->_('FB_RATE_FIREBOX')) . '</a>';
234 $links['support'] = '<a href="https://www.fireplugins.com/contact/" aria-label="' . esc_attr__(fpframework()->_('FPF_SUPPORT')) . '" target="_blank">' . esc_html__(fpframework()->_('FPF_SUPPORT')) . '</a>';
235 }
236
237 return $links;
238 }
239
240 /**
241 * Sets a class to the body of the FireBox Admin Pages
242 *
243 * @return string
244 */
245 public function setPluginPageBodyClass($classes)
246 {
247 if (!$this->isPluginPage())
248 {
249 return $classes;
250 }
251
252 $classes .= ' fpf-admin-page fpf-firebox-page';
253
254 if ($this->isControllerPage())
255 {
256 $classes .= ' fpf-controller-page';
257 }
258
259 // Set admin template theme class
260 $fireplugins_theme = isset($_COOKIE['fireplugins_theme']) ? sanitize_key($_COOKIE['fireplugins_theme']) : 'light';
261 $classes .= ' ' . $fireplugins_theme;
262
263 // Set admin template sidebar toggle class
264 $sidebar_state = isset($_COOKIE['fireplugins_sidebar_state']) ? $_COOKIE['fireplugins_sidebar_state'] : 'expand';
265 $classes .= ' ' . ($sidebar_state === 'expand' ? 'fpf-admin-sidebar-expand' : 'fpf-admin-sidebar-shrink');
266
267 return $classes;
268 }
269
270 /**
271 * Checks if we are in a plugin page
272 *
273 * @return boolean
274 */
275 private function isPluginPage()
276 {
277 if (in_array($this->getPageNow(), ['edit.php', 'post-new.php']) && isset($_GET['post_type']) && $_GET['post_type'] == 'firebox') //phpcs:ignore WordPress.Security.NonceVerification.Recommended
278 {
279 return true;
280 }
281
282 if ($this->getPageNow() == 'post.php')
283 {
284 return true;
285 }
286
287 if ($this->isControllerPage())
288 {
289 return true;
290 }
291
292 return false;
293 }
294
295 /**
296 * Whether we are browsing a plugin page from the plugin's menu
297 *
298 * @return boolean
299 */
300 private function isControllerPage()
301 {
302 if (!firebox()->menu)
303 {
304 return false;
305 }
306
307 $current_plugin_page = fpframework()->getPluginPage();
308 $plugin_menu_items = firebox()->menu->getPluginMenuItems();
309
310 // Only set the class to the plugin pages
311 return $this->getPageNow() == 'admin.php' && in_array($current_plugin_page, $plugin_menu_items);
312 }
313
314 /**
315 * Returns page now
316 *
317 * @return string
318 */
319 protected function getPageNow()
320 {
321 global $pagenow;
322 return $pagenow;
323 }
324
325 /**
326 * Registers CSS and JS files
327 *
328 * @return void
329 */
330 public function registerMediaAdminPages()
331 {
332 $this->registerStyles();
333 $this->registerScripts();
334 }
335
336 /**
337 * Register admin styles.
338 *
339 * @return void
340 */
341 public function registerStyles()
342 {
343 // load dashicons
344 wp_enqueue_style('dashicons');
345
346 // firebox main admin css
347 wp_register_style(
348 'firebox-admin',
349 FBOX_MEDIA_ADMIN_URL . 'css/firebox.css',
350 [],
351 FBOX_VERSION,
352 false
353 );
354 wp_enqueue_style('firebox-admin');
355
356 // firebox admin design
357 wp_register_style(
358 'firebox-design-admin',
359 FBOX_MEDIA_ADMIN_URL . 'css/firebox_design.css',
360 [],
361 FBOX_VERSION,
362 false
363 );
364 wp_enqueue_style('firebox-design-admin');
365
366 $css = '
367 :root {
368 --fpf-templates-library-header-logo: url(' . FBOX_MEDIA_ADMIN_URL . 'images/logo.svg);
369 }
370 ';
371 wp_add_inline_style('firebox-admin', $css);
372 }
373
374 /**
375 * Registers admin scripts.
376 *
377 * @return void
378 */
379 public function registerScripts()
380 {
381 wp_register_script('firebox-admin', false);
382 wp_enqueue_script('firebox-admin');
383
384 $data = array(
385 'campaigns_item_new_url' => admin_url('post-new.php?post_type=firebox'),
386 'campaigns_list_url' => admin_url('admin.php?page=firebox-campaigns'),
387 'campaigns_item_edit_url' => admin_url('post.php?post={{ID}}&action=edit'),
388 'campaigns_item_analytics_url' => admin_url('admin.php?page=firebox-analytics&campaign={{ID}}'),
389 'campaigns_analytics_url' => admin_url('admin.php?page=firebox-analytics'),
390 'submissions_page' => admin_url('admin.php?page=firebox-submissions'),
391 'flags_url' => FBOX_PLUGIN_URL . 'Inc/Framework/media/admin/images/flags/{{FLAG}}.png',
392 'langs' => [
393 'CAMPAIGN_INFO' => firebox()->_('FB_CAMPAIGN_INFO'),
394 'EDIT_CAMPAIGN' => firebox()->_('FB_EDIT_CAMPAIGN'),
395 'STATUS' => fpframework()->_('FPF_STATUS'),
396 'CREATED' => fpframework()->_('FPF_CREATED'),
397 'LAST_VIEWED' => firebox()->_('FB_LAST_VIEWED'),
398 'ACTIVE' => firebox()->_('FB_ACTIVE'),
399 'DISABLED' => fpframework()->_('FPF_DISABLED'),
400 'ID' => fpframework()->_('FPF_ID'),
401 'CAMPAIGN' => firebox()->_('FB_CAMPAIGN'),
402 'VIEWS' => firebox()->_('FB_VIEWS'),
403 'ACTIONS' => firebox()->_('FB_ACTIONS'),
404 'CONVERSIONS' => firebox()->_('FB_CONVERSIONS'),
405 'CONVERSION_RATE' => firebox()->_('FB_CONVERSION_RATE'),
406 'NO_DATA_AVAILABLE' => firebox()->_('FB_NO_DATA_AVAILABLE'),
407 'COUNTRIES' => fpframework()->_('FPF_COUNTRIES'),
408 'FLAG' => fpframework()->_('FPF_FLAG'),
409 'DEVICES' => fpframework()->_('FPF_DEVICES'),
410 'EVENTS' => fpframework()->_('FPF_EVENTS'),
411 'PERCENTAGE_DIFFERENCE_AGAINST_PREVIOUS_PERIOD' => firebox()->_('FB_PERCENTAGE_DIFFERENCE_AGAINST_PREVIOUS_PERIOD'),
412 'NO_CAMPAIGN_DATA_FOUND' => firebox()->_('FB_NO_CAMPAIGN_DATA_FOUND'),
413 'MOST_POPULAR_CAMPAIGNS' => firebox()->_('FB_MOST_POPULAR_CAMPAIGNS'),
414 'TOP_CAMPAIGNS' => firebox()->_('FB_TOP_CAMPAIGNS'),
415 'N/A' => fpframework()->_('FPF_N/A'),
416 'ALL_DAYS' => firebox()->_('FB_ALL_DAYS'),
417 'MONDAY' => firebox()->_('FB_MONDAY'),
418 'TUESDAY' => firebox()->_('FB_TUESDAY'),
419 'WEDNESDAY' => firebox()->_('FB_WEDNESDAY'),
420 'THURSDAY' => firebox()->_('FB_THURSDAY'),
421 'FRIDAY' => firebox()->_('FB_FRIDAY'),
422 'SATURDAY' => firebox()->_('FB_SATURDAY'),
423 'SUNDAY' => firebox()->_('FB_SUNDAY'),
424 'VIEW_HOURS' => firebox()->_('FB_VIEW_HOURS'),
425 'PATHS' => fpframework()->_('FPF_PATHS'),
426 'REFERRERS' => fpframework()->_('FPF_REFERRERS'),
427 'S' => fpframework()->_('FPF_S'),
428 'VIEW_CAMPAIGN_ANALYTICS' => firebox()->_('FB_VIEW_CAMPAIGN_ANALYTICS'),
429 'ACTIVATE' => fpframework()->_('FPF_ACTIVATE'),
430 'DEACTIVATE' => fpframework()->_('FPF_DEACTIVATE'),
431 'EDIT' => fpframework()->_('FPF_EDIT'),
432 'DELETE' => fpframework()->_('FPF_DELETE'),
433 'DUPLICATE' => fpframework()->_('FPF_DUPLICATE'),
434 'ARE_YOU_SURE_YOU_WANT_TO_DELETE_THIS_CAMPAIGN' => firebox()->_('FB_ARE_YOU_SURE_YOU_WANT_TO_DELETE_THIS_CAMPAIGN'),
435 'RECENT_CAMPAIGNS' => firebox()->_('FB_RECENT_CAMPAIGNS'),
436 'VIEW_ALL' => firebox()->_('FB_VIEW_ALL'),
437 'YOU_HAVENT_CREATED_ANY_CAMPAIGNS_YET' => firebox()->_('FB_YOU_HAVENT_CREATED_ANY_CAMPAIGNS_YET'),
438 'NEW_CAMPAIGN' => firebox()->_('FB_NEW_CAMPAIGN'),
439 'NUMBER_OF_VIEWS_IN_THE_LAST_30_DAYS' => firebox()->_('FB_NUMBER_OF_VIEWS_IN_THE_LAST_30_DAYS'),
440 'NUMBER_OF_CONVERSIONS_IN_THE_LAST_30_DAYS' => firebox()->_('FB_NUMBER_OF_CONVERSIONS_IN_THE_LAST_30_DAYS'),
441 'CONVERSION_RATE_IN_THE_LAST_30_DAYS' => firebox()->_('FB_CONVERSION_RATE_IN_THE_LAST_30_DAYS'),
442 'LOADING_CAMPAIGNS' => firebox()->_('FB_LOADING_CAMPAIGNS'),
443 'NO_CAMPAIGNS_FOUND' => firebox()->_('FB_NO_CAMPAIGNS_FOUND'),
444 'SEARCH_DOTS' => firebox()->_('FB_SEARCH_DOTS'),
445 'TODAY' => firebox()->_('FB_TODAY'),
446 'YESTERDAY' => firebox()->_('FB_YESTERDAY'),
447 'LAST_7_DAYS' => firebox()->_('FB_LAST_7_DAYS'),
448 'LAST_30_DAYS' => firebox()->_('FB_LAST_30_DAYS'),
449 'LAST_WEEK' => firebox()->_('FB_LAST_WEEK'),
450 'LAST_MONTH' => firebox()->_('FB_LAST_MONTH'),
451 'CUSTOM' => firebox()->_('FB_CUSTOM'),
452 'AVG_TIME_OPEN_TOOLTIP_DESC' => firebox()->_('FB_AVG_TIME_OPEN_TOOLTIP_DESC'),
453 'READ_MORE' => firebox()->_('FB_READ_MORE'),
454 'AVG_TIME_OPEN' => firebox()->_('FB_AVG_TIME_OPEN'),
455 'CONVERSION_RATE_TOOLTIP_DESC' => firebox()->_('FB_CONVERSION_RATE_TOOLTIP_DESC'),
456 'CONVERSIONS_TOOLTIP_DESC' => firebox()->_('FB_CONVERSIONS_TOOLTIP_DESC'),
457 'VS_PREVIOUS_PERIOD' => firebox()->_('FB_VS_PREVIOUS_PERIOD'),
458 'VIEWS_TOOLTIP_DESC' => firebox()->_('FB_VIEWS_TOOLTIP_DESC'),
459 'NO' => firebox()->_('FB_NO'),
460 'DATA_AVAILABLE' => firebox()->_('FB_DATA_AVAILABLE'),
461 'PERFORMANCE' => firebox()->_('FB_PERFORMANCE'),
462 'TRENDING_TEMPLATES' => firebox()->_('FB_TRENDING_TEMPLATES'),
463 'THERE_ARE_NO_TRENDING_TEMPLATES_TO_SHOW' => firebox()->_('FB_THERE_ARE_NO_TRENDING_TEMPLATES_TO_SHOW'),
464 'INSERT_TEMPLATE' => firebox()->_('FB_INSERT_TEMPLATE'),
465 'INSERT' => firebox()->_('FB_INSERT'),
466 'VIEW_ALL_ANALYTICS' => firebox()->_('FB_VIEW_ALL_ANALYTICS'),
467 'DAILY' => firebox()->_('FB_DAILY'),
468 'WEEKLY' => firebox()->_('FB_WEEKLY'),
469 'MONTHLY' => firebox()->_('FB_MONTHLY'),
470 'UPGRADE_TO_PRO' => fpframework()->_('FPF_UPGRADE_TO_PRO'),
471 'ALL_CAMPAIGNS' => firebox()->_('FB_ALL_CAMPAIGNS'),
472 'OVERVIEW' => fpframework()->_('FPF_OVERVIEW'),
473 'TO' => fpframework()->_('FPF_TO'),
474 'SHOWING_TOP_30_RESULTS' => firebox()->_('FB_SHOWING_TOP_30_RESULTS'),
475 'DAY_OF_THE_WEEK' => firebox()->_('FB_DAY_OF_THE_WEEK'),
476 'ANALYTICS' => fpframework()->_('FPF_ANALYTICS')
477 ]
478 );
479
480 wp_localize_script('firebox-admin', 'fbox_admin_js_object', $data);
481 }
482
483 /**
484 * Returns the timezone in format: +-XX:XX
485 *
486 * @return string
487 */
488 private function getTimezone()
489 {
490 $offset = get_option('gmt_offset');
491 $hours = (int) $offset;
492 $minutes = abs(($offset - (int) $offset) * 60);
493 return sprintf('%+03d:%02d', $hours, $minutes);
494 }
495 }