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

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