PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 2.1.23
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v2.1.23
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.23, at Inc/Core/Admin/Admin.php

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