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

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