| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FireBox |
| 4 |
* @version 3.1.5 Free |
| 5 |
* |
| 6 |
* @author FirePlugins <info@fireplugins.com> |
| 7 |
* @link https://www.fireplugins.com |
| 8 |
* @copyright Copyright © 2026 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 Media |
| 20 |
{ |
| 21 |
public function __construct() |
| 22 |
{ |
| 23 |
if (!is_admin()) |
| 24 |
{ |
| 25 |
return; |
| 26 |
} |
| 27 |
|
| 28 |
add_action('enqueue_block_editor_assets', [$this, 'block_editor_only_assets']); |
| 29 |
|
| 30 |
add_action('enqueue_block_assets', [$this, 'enqueue_block_assets']); |
| 31 |
} |
| 32 |
|
| 33 |
public function block_editor_only_assets() |
| 34 |
{ |
| 35 |
if (!is_admin()) |
| 36 |
{ |
| 37 |
return; |
| 38 |
} |
| 39 |
|
| 40 |
// Enqueue block editor script only in Gutenberg editor |
| 41 |
if (function_exists('get_current_screen')) |
| 42 |
{ |
| 43 |
$screen = get_current_screen(); |
| 44 |
if ($screen->is_block_editor) |
| 45 |
{ |
| 46 |
wp_enqueue_script( |
| 47 |
'firebox-gutenberg-store', |
| 48 |
FBOX_MEDIA_ADMIN_URL . 'js/blocks/gutenberg_store.js', |
| 49 |
['wp-data'], |
| 50 |
FBOX_VERSION, |
| 51 |
true |
| 52 |
); |
| 53 |
|
| 54 |
// Required for ProOnlyButton hover icon swap (closed/open lock) across plans. |
| 55 |
wp_enqueue_style( |
| 56 |
'firebox-editor-free', |
| 57 |
FBOX_MEDIA_ADMIN_URL . 'css/editor-free.css', |
| 58 |
[], |
| 59 |
FBOX_VERSION |
| 60 |
); |
| 61 |
|
| 62 |
if ($this->shouldLoadFreeUpgradeModalsScript()) |
| 63 |
{ |
| 64 |
wp_enqueue_script( |
| 65 |
'firebox-plugins-free-modals', |
| 66 |
FBOX_MEDIA_ADMIN_URL . 'js/blocks/plugins/free-modals.js', |
| 67 |
[], |
| 68 |
FBOX_VERSION, |
| 69 |
true |
| 70 |
); |
| 71 |
} |
| 72 |
|
| 73 |
if (FBOX_LICENSE_TYPE === 'lite') |
| 74 |
{ |
| 75 |
wp_enqueue_script('firebox-blocks-free', FBOX_MEDIA_ADMIN_URL . 'js/blocks/blocks-free.js', [], FBOX_VERSION, true); |
| 76 |
} |
| 77 |
else if (FBOX_LICENSE_TYPE === 'pro') |
| 78 |
{ |
| 79 |
wp_enqueue_script('firebox-blocks-pro', FBOX_MEDIA_ADMIN_URL . 'js/blocks/blocks-pro.js', [], FBOX_VERSION, true); |
| 80 |
} |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Loads Gutenberg editor assets |
| 87 |
* |
| 88 |
* @return void |
| 89 |
*/ |
| 90 |
public function enqueue_block_assets() |
| 91 |
{ |
| 92 |
if (!is_admin()) |
| 93 |
{ |
| 94 |
return; |
| 95 |
} |
| 96 |
|
| 97 |
// Enqueue block editor script only in Gutenberg editor |
| 98 |
if (function_exists('get_current_screen')) |
| 99 |
{ |
| 100 |
$screen = get_current_screen(); |
| 101 |
if ($screen->is_block_editor) |
| 102 |
{ |
| 103 |
wp_enqueue_code_editor(['type' => 'text/css']); |
| 104 |
wp_enqueue_code_editor(['type' => 'javascript']); |
| 105 |
|
| 106 |
// Add the block editor styling for our blocks |
| 107 |
wp_enqueue_style( |
| 108 |
'firebox-blocks-editor-styles', |
| 109 |
FBOX_MEDIA_ADMIN_URL . 'css/admin/blocks.css', |
| 110 |
[], |
| 111 |
FBOX_VERSION |
| 112 |
); |
| 113 |
|
| 114 |
// Add the FireBox block editor script only to FireBox post type |
| 115 |
if (get_post_type() === 'firebox') |
| 116 |
{ |
| 117 |
wp_enqueue_script( |
| 118 |
'firebox-gutenberg-store', |
| 119 |
FBOX_MEDIA_ADMIN_URL . 'js/blocks/gutenberg_store.js', |
| 120 |
['wp-data'], |
| 121 |
FBOX_VERSION, |
| 122 |
true |
| 123 |
); |
| 124 |
|
| 125 |
// FireBox main CSS file |
| 126 |
wp_enqueue_style( |
| 127 |
'firebox', |
| 128 |
FBOX_MEDIA_PUBLIC_URL . 'css/firebox.css', |
| 129 |
[], |
| 130 |
FBOX_VERSION |
| 131 |
); |
| 132 |
|
| 133 |
wp_enqueue_style( |
| 134 |
'firebox-animations', |
| 135 |
FBOX_MEDIA_PUBLIC_URL . 'css/vendor/animate.min.css', |
| 136 |
[], |
| 137 |
FBOX_VERSION |
| 138 |
); |
| 139 |
|
| 140 |
wp_enqueue_style( |
| 141 |
'firebox-block-editor', |
| 142 |
FBOX_MEDIA_ADMIN_URL . 'css/block-editor.css', |
| 143 |
[], |
| 144 |
FBOX_VERSION |
| 145 |
); |
| 146 |
|
| 147 |
wp_enqueue_script( |
| 148 |
'firebox-editor', |
| 149 |
FBOX_MEDIA_ADMIN_URL . 'js/blocks/editor.js', |
| 150 |
['wp-edit-post'], |
| 151 |
FBOX_VERSION, |
| 152 |
true |
| 153 |
); |
| 154 |
|
| 155 |
wp_enqueue_script( |
| 156 |
'firebox-slotfills-general', |
| 157 |
FBOX_MEDIA_ADMIN_URL . 'js/blocks/slotfills/general.js', |
| 158 |
[], |
| 159 |
FBOX_VERSION, |
| 160 |
true |
| 161 |
); |
| 162 |
|
| 163 |
// Required for ProOnlyButton hover icon swap (closed/open lock) across plans. |
| 164 |
wp_enqueue_style( |
| 165 |
'firebox-editor-free', |
| 166 |
FBOX_MEDIA_ADMIN_URL . 'css/editor-free.css', |
| 167 |
[], |
| 168 |
FBOX_VERSION |
| 169 |
); |
| 170 |
|
| 171 |
if ($this->shouldLoadFreeUpgradeModalsScript()) |
| 172 |
{ |
| 173 |
wp_enqueue_script( |
| 174 |
'firebox-plugins-free-modals', |
| 175 |
FBOX_MEDIA_ADMIN_URL . 'js/blocks/plugins/free-modals.js', |
| 176 |
[], |
| 177 |
FBOX_VERSION, |
| 178 |
true |
| 179 |
); |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
if (FBOX_LICENSE_TYPE === 'lite') |
| 184 |
{ |
| 185 |
wp_enqueue_script( |
| 186 |
'firebox-slotfills-free', |
| 187 |
FBOX_MEDIA_ADMIN_URL . 'js/blocks/slotfills/free.js', |
| 188 |
[], |
| 189 |
FBOX_VERSION, |
| 190 |
true |
| 191 |
); |
| 192 |
} |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
$integrations_registry = \FireBox\Core\Helpers\Integrations::getFormEditorIntegrationsRegistry(); |
| 201 |
$integration_connections = []; |
| 202 |
foreach ($integrations_registry as $integration) |
| 203 |
{ |
| 204 |
if (!is_array($integration) || empty($integration['slug'])) |
| 205 |
{ |
| 206 |
continue; |
| 207 |
} |
| 208 |
|
| 209 |
$integration_connections[$integration['slug']] = !empty($integration['connected']); |
| 210 |
} |
| 211 |
|
| 212 |
$data = [ |
| 213 |
'google_fonts' => \FPFramework\Libs\GoogleFonts::getFonts(), |
| 214 |
'google_fonts_names' => \FPFramework\Libs\GoogleFonts::getFontsNames(), |
| 215 |
'icons' => \FireBox\Core\Libs\Icons::getAll(), |
| 216 |
'turnstile_site_key' => \FireBox\Core\Helpers\Captcha\Turnstile::getSiteKey(), |
| 217 |
'turnstile_secret_key' => \FireBox\Core\Helpers\Captcha\Turnstile::getSecretKey(), |
| 218 |
'hcaptcha_site_key' => \FireBox\Core\Helpers\Captcha\HCaptcha::getSiteKey(), |
| 219 |
'hcaptcha_secret_key' => \FireBox\Core\Helpers\Captcha\HCaptcha::getSecretKey(), |
| 220 |
'settings_url' => admin_url('admin.php?page=firebox-settings'), |
| 221 |
'integrations_registry' => $integrations_registry, |
| 222 |
'integration_connections' => $integration_connections, |
| 223 |
'license_type' => defined('FBOX_LICENSE_TYPE') ? FBOX_LICENSE_TYPE : '', |
| 224 |
'license_plan' => defined('FBOX_LICENSE_PLAN') ? FBOX_LICENSE_PLAN : '', |
| 225 |
'media_url' => FBOX_MEDIA_URL, |
| 226 |
|
| 227 |
]; |
| 228 |
|
| 229 |
wp_register_script('firebox-block-editor-script', false); |
| 230 |
wp_enqueue_script('firebox-block-editor-script'); |
| 231 |
wp_localize_script('firebox-block-editor-script', 'fbox_block_editor_object', $data); |
| 232 |
} |
| 233 |
} |
| 234 |
} |
| 235 |
|
| 236 |
private function shouldLoadFreeUpgradeModalsScript() |
| 237 |
{ |
| 238 |
$license_type = defined('FBOX_LICENSE_TYPE') ? strtolower(trim((string) FBOX_LICENSE_TYPE)) : ''; |
| 239 |
$license_plan = defined('FBOX_LICENSE_PLAN') ? strtolower(trim((string) FBOX_LICENSE_PLAN)) : ''; |
| 240 |
|
| 241 |
return $license_type === 'lite' || in_array($license_plan, ['free', 'basic'], true); |
| 242 |
} |
| 243 |
} |
| 244 |
|