| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FireBox |
| 4 |
* @version 3.1.13 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 |
| 13 |
{ |
| 14 |
if (!defined('ABSPATH')) |
| 15 |
{ |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
use FPFramework\Framework; |
| 20 |
use FPFramework\Base\Renderer; |
| 21 |
|
| 22 |
use FireBox\Core\Admin\Admin; |
| 23 |
use FireBox\Core\Admin\Includes\Library; |
| 24 |
use FireBox\Core\Admin\Includes\Cpts\Cpts; |
| 25 |
use FireBox\Core\Admin\Menu\PluginMenu; |
| 26 |
use FireBox\Core\FB\Box; |
| 27 |
use FireBox\Core\FB\Boxes; |
| 28 |
use FireBox\Core\FB\Log; |
| 29 |
use FireBox\Core\FB\Track; |
| 30 |
use FireBox\Core\Shortcodes\Shortcodes; |
| 31 |
use FireBox\Core\Libs\Translations; |
| 32 |
|
| 33 |
/** |
| 34 |
* This class is responsible for initializing FireBox. |
| 35 |
* |
| 36 |
* It registers all required components needed for the plugin to run. |
| 37 |
*/ |
| 38 |
final class Plugin |
| 39 |
{ |
| 40 |
/** |
| 41 |
* Holds the admin plugin. |
| 42 |
* |
| 43 |
* @var Admin |
| 44 |
*/ |
| 45 |
public $admin; |
| 46 |
|
| 47 |
/** |
| 48 |
* Library |
| 49 |
* |
| 50 |
* @var Library |
| 51 |
*/ |
| 52 |
public $library; |
| 53 |
|
| 54 |
/** |
| 55 |
* Tables |
| 56 |
* |
| 57 |
* @var Tables |
| 58 |
*/ |
| 59 |
public $tables; |
| 60 |
|
| 61 |
/** |
| 62 |
* Custom Post Types |
| 63 |
* |
| 64 |
* @var CPTS |
| 65 |
*/ |
| 66 |
public $cpts; |
| 67 |
|
| 68 |
/** |
| 69 |
* Renderer |
| 70 |
* |
| 71 |
* @var Renderer |
| 72 |
*/ |
| 73 |
public $renderer; |
| 74 |
|
| 75 |
/** |
| 76 |
* Box |
| 77 |
* |
| 78 |
* @var Box |
| 79 |
*/ |
| 80 |
public $box; |
| 81 |
|
| 82 |
/** |
| 83 |
* Boxes |
| 84 |
* |
| 85 |
* @var Boxes |
| 86 |
*/ |
| 87 |
public $boxes; |
| 88 |
|
| 89 |
/** |
| 90 |
* The WP Admin Menu of the Plugin |
| 91 |
* |
| 92 |
* @var Menu |
| 93 |
*/ |
| 94 |
public $menu; |
| 95 |
|
| 96 |
/** |
| 97 |
* Helper Classes |
| 98 |
* |
| 99 |
* @var HelperMiddleware |
| 100 |
*/ |
| 101 |
public $helper; |
| 102 |
|
| 103 |
/** |
| 104 |
* Gutenberg blocks |
| 105 |
* |
| 106 |
* @var Blocks |
| 107 |
*/ |
| 108 |
public $blocks; |
| 109 |
|
| 110 |
/** |
| 111 |
* Shortcodes |
| 112 |
* |
| 113 |
* @var Shortcodes |
| 114 |
*/ |
| 115 |
public $shortcodes; |
| 116 |
|
| 117 |
/** |
| 118 |
* Track |
| 119 |
* |
| 120 |
* @var Track |
| 121 |
*/ |
| 122 |
public $track; |
| 123 |
|
| 124 |
/** |
| 125 |
* log |
| 126 |
* |
| 127 |
* @var Log |
| 128 |
*/ |
| 129 |
public $log; |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
/** |
| 134 |
* Translations cache |
| 135 |
* |
| 136 |
* @var Libs\Translations |
| 137 |
*/ |
| 138 |
private $translations_cache; |
| 139 |
|
| 140 |
/** |
| 141 |
* Tables used by Hook |
| 142 |
* |
| 143 |
* @var array |
| 144 |
*/ |
| 145 |
public $hook_data = [ |
| 146 |
'tables' => [ 'firebox_logs', 'firebox_logs_details', 'firebox_submissions', 'firebox_submission_meta' ], |
| 147 |
'activation' => FBOX_PLUGIN_DIR . 'Inc/Core/Admin/sql/firebox.sql', |
| 148 |
'uninstall' => FBOX_PLUGIN_DIR . 'Inc/Core/Admin/sql/uninstall.firebox.sql' |
| 149 |
]; |
| 150 |
|
| 151 |
/** |
| 152 |
* The plugin name |
| 153 |
* |
| 154 |
* @var String |
| 155 |
*/ |
| 156 |
public $plugin_name = 'FireBox'; |
| 157 |
|
| 158 |
/** |
| 159 |
* The plugin slug |
| 160 |
* |
| 161 |
* @var String |
| 162 |
*/ |
| 163 |
public $plugin_slug = 'firebox'; |
| 164 |
|
| 165 |
/** |
| 166 |
* Holds the plugin instance |
| 167 |
* |
| 168 |
* @var Plugin $instance |
| 169 |
*/ |
| 170 |
public static $instance = null; |
| 171 |
|
| 172 |
private function __construct() |
| 173 |
{ |
| 174 |
$this->preFlight(); |
| 175 |
|
| 176 |
// run init |
| 177 |
add_action('fpf_init', [$this, 'init']); |
| 178 |
|
| 179 |
// admin init |
| 180 |
add_action('fpf_admin_init', [$this, 'admin_init']); |
| 181 |
|
| 182 |
// admin menu |
| 183 |
add_action('admin_menu', [$this, 'admin_menu']); |
| 184 |
} |
| 185 |
|
| 186 |
/** |
| 187 |
* Admin Menu |
| 188 |
* |
| 189 |
* @return void |
| 190 |
*/ |
| 191 |
public function admin_menu() |
| 192 |
{ |
| 193 |
$this->menu = new PluginMenu(); |
| 194 |
$this->menu->init(); |
| 195 |
} |
| 196 |
|
| 197 |
/** |
| 198 |
* Admin Init |
| 199 |
* |
| 200 |
* @return void |
| 201 |
*/ |
| 202 |
public function admin_init() |
| 203 |
{ |
| 204 |
new \FPFramework\Admin\Includes\UpgradeProModal($this->plugin_slug, $this->plugin_name); |
| 205 |
|
| 206 |
|
| 207 |
new \FireBox\Core\Admin\Includes\UpgradeToPlanModal(); |
| 208 |
|
| 209 |
|
| 210 |
// Admin |
| 211 |
$this->admin = new Admin(); |
| 212 |
|
| 213 |
// Library |
| 214 |
$this->library = new Library(); |
| 215 |
} |
| 216 |
|
| 217 |
/** |
| 218 |
* Runs at the start of the Plugin |
| 219 |
* |
| 220 |
* @return void |
| 221 |
*/ |
| 222 |
public function preFlight() |
| 223 |
{ |
| 224 |
// loads text domain |
| 225 |
add_action('plugins_loaded', [$this, 'loadTextdomain'], 10); |
| 226 |
|
| 227 |
|
| 228 |
} |
| 229 |
|
| 230 |
/** |
| 231 |
* Ensures only one instance of the plugin class is loaded or can be loaded |
| 232 |
* |
| 233 |
* @return Plugin An instance of the class. |
| 234 |
*/ |
| 235 |
public static function instance() |
| 236 |
{ |
| 237 |
if (is_null(self::$instance)) |
| 238 |
{ |
| 239 |
self::$instance = new self(); |
| 240 |
} |
| 241 |
|
| 242 |
return self::$instance; |
| 243 |
} |
| 244 |
|
| 245 |
/** |
| 246 |
* Loads the textdomain |
| 247 |
* |
| 248 |
* @return void |
| 249 |
*/ |
| 250 |
public function loadTextdomain() |
| 251 |
{ |
| 252 |
load_plugin_textdomain('firebox', false, FBOX_PLUGIN_DIR . 'languages/'); |
| 253 |
} |
| 254 |
|
| 255 |
/** |
| 256 |
* Initializes all Common components used by front-end and back-end. |
| 257 |
* |
| 258 |
* @return void |
| 259 |
*/ |
| 260 |
private function initCommons() |
| 261 |
{ |
| 262 |
new AdminBarMenu(); |
| 263 |
|
| 264 |
// Tables |
| 265 |
$this->tables = new Tables(); |
| 266 |
|
| 267 |
// Shortcodes |
| 268 |
$this->shortcodes = new Shortcodes(); |
| 269 |
|
| 270 |
// Log |
| 271 |
$this->log = new Log(); |
| 272 |
|
| 273 |
new API\API(); |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
// Register Custom Post Type |
| 278 |
new \FireBox\Core\Admin\Includes\Cpts\Firebox(); |
| 279 |
|
| 280 |
// Keep the campaign-derived caches (box list, "session conditions in use" |
| 281 |
// flag) in sync with campaign writes |
| 282 |
\FireBox\Core\Helpers\BoxHelper::registerCacheInvalidation(); |
| 283 |
|
| 284 |
// Renderer |
| 285 |
$this->renderer = new Renderer(FBOX_LAYOUTS_DIR); |
| 286 |
|
| 287 |
// Box |
| 288 |
$this->box = new Box(); |
| 289 |
|
| 290 |
// Boxes |
| 291 |
$this->boxes = new Boxes(); |
| 292 |
|
| 293 |
// Helper |
| 294 |
$this->helper = new HelperMiddleware(); |
| 295 |
|
| 296 |
// Gutenberg Blocks |
| 297 |
$this->blocks = new Blocks(); |
| 298 |
|
| 299 |
// Forms AJAX |
| 300 |
new \FireBox\Core\Form\Ajax(); |
| 301 |
|
| 302 |
// Analytics AJAX |
| 303 |
new \FireBox\Core\Analytics\Ajax(); |
| 304 |
|
| 305 |
// Track |
| 306 |
$this->track = new Track(); |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
// Usage Tracking |
| 311 |
$usageTracking = new \FireBox\Core\UsageTracking\SendUsage(); |
| 312 |
$usageTracking->maybeStart(); |
| 313 |
|
| 314 |
new FB\Meta(); |
| 315 |
} |
| 316 |
|
| 317 |
/** |
| 318 |
* Initializes FireBox Plugin with the required components |
| 319 |
* |
| 320 |
* @return void |
| 321 |
*/ |
| 322 |
public function init() |
| 323 |
{ |
| 324 |
// init framework |
| 325 |
\FPFramework\Framework::getInstance($this->plugin_slug); |
| 326 |
|
| 327 |
// common classes (both front/back end) |
| 328 |
$this->initCommons(); |
| 329 |
|
| 330 |
// Load front-end |
| 331 |
new Frontend(); |
| 332 |
} |
| 333 |
|
| 334 |
/** |
| 335 |
* Retrieves the translation of $text |
| 336 |
* |
| 337 |
* @param string $text |
| 338 |
* @param string $fallback |
| 339 |
* |
| 340 |
* @return string |
| 341 |
*/ |
| 342 |
public function _($text, $fallback = null) |
| 343 |
{ |
| 344 |
// check if translations instance exists |
| 345 |
if (!isset($this->translations_cache)) |
| 346 |
{ |
| 347 |
// set translations |
| 348 |
$this->translations_cache = new Libs\Translations(); |
| 349 |
} |
| 350 |
|
| 351 |
return $this->translations_cache->_($text, $fallback); |
| 352 |
} |
| 353 |
} |
| 354 |
} |
| 355 |
|
| 356 |
namespace { |
| 357 |
/** |
| 358 |
* The function which returns the one and only FireBox instance. |
| 359 |
* |
| 360 |
* @return Plugin |
| 361 |
*/ |
| 362 |
function firebox() |
| 363 |
{ |
| 364 |
return FireBox\Core\Plugin::instance(); |
| 365 |
} |
| 366 |
} |