| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FireBox |
| 4 |
* @version 2.1.10 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 |
| 13 |
{ |
| 14 |
if (!defined('ABSPATH')) |
| 15 |
{ |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
use FPFramework\Framework; |
| 20 |
use FPFramework\Admin\Includes\MetaboxManager; |
| 21 |
use FPFramework\Base\Renderer; |
| 22 |
|
| 23 |
use FireBox\Core\Admin\Admin; |
| 24 |
use FireBox\Core\Admin\Includes\Library; |
| 25 |
use FireBox\Core\Admin\Includes\Metaboxes as PluginMetaboxes; |
| 26 |
use FireBox\Core\Admin\Includes\Cpts\Cpts; |
| 27 |
use FireBox\Core\Admin\Menu\PluginMenu; |
| 28 |
use FireBox\Core\FB\Box; |
| 29 |
use FireBox\Core\FB\Boxes; |
| 30 |
use FireBox\Core\FB\Log; |
| 31 |
use FireBox\Core\FB\Track; |
| 32 |
use FireBox\Core\Shortcodes\Shortcodes; |
| 33 |
use FireBox\Core\Libs\Translations; |
| 34 |
|
| 35 |
/** |
| 36 |
* This class is responsible for initializing FireBox. |
| 37 |
* |
| 38 |
* It registers all required components needed for the plugin to run. |
| 39 |
*/ |
| 40 |
final class Plugin |
| 41 |
{ |
| 42 |
/** |
| 43 |
* Holds the admin plugin. |
| 44 |
* |
| 45 |
* @var Admin |
| 46 |
*/ |
| 47 |
public $admin; |
| 48 |
|
| 49 |
/** |
| 50 |
* Library |
| 51 |
* |
| 52 |
* @var Library |
| 53 |
*/ |
| 54 |
public $library; |
| 55 |
|
| 56 |
/** |
| 57 |
* Tables |
| 58 |
* |
| 59 |
* @var Tables |
| 60 |
*/ |
| 61 |
public $tables; |
| 62 |
|
| 63 |
/** |
| 64 |
* Custom Post Types |
| 65 |
* |
| 66 |
* @var CPTS |
| 67 |
*/ |
| 68 |
public $cpts; |
| 69 |
|
| 70 |
/** |
| 71 |
* Renderer |
| 72 |
* |
| 73 |
* @var Renderer |
| 74 |
*/ |
| 75 |
public $renderer; |
| 76 |
|
| 77 |
/** |
| 78 |
* Plugin Metaboxes |
| 79 |
* |
| 80 |
* @var Metaboxes |
| 81 |
*/ |
| 82 |
public $plugin_metaboxes; |
| 83 |
|
| 84 |
/** |
| 85 |
* Metaboxes Manager |
| 86 |
* |
| 87 |
* @var MetaboxManager |
| 88 |
*/ |
| 89 |
public $metaboxes_manager; |
| 90 |
|
| 91 |
/** |
| 92 |
* Box |
| 93 |
* |
| 94 |
* @var Box |
| 95 |
*/ |
| 96 |
public $box; |
| 97 |
|
| 98 |
/** |
| 99 |
* Boxes |
| 100 |
* |
| 101 |
* @var Boxes |
| 102 |
*/ |
| 103 |
public $boxes; |
| 104 |
|
| 105 |
/** |
| 106 |
* The WP Admin Menu of the Plugin |
| 107 |
* |
| 108 |
* @var Menu |
| 109 |
*/ |
| 110 |
public $menu; |
| 111 |
|
| 112 |
/** |
| 113 |
* Helper Classes |
| 114 |
* |
| 115 |
* @var HelperMiddleware |
| 116 |
*/ |
| 117 |
public $helper; |
| 118 |
|
| 119 |
/** |
| 120 |
* Gutenberg blocks |
| 121 |
* |
| 122 |
* @var Blocks |
| 123 |
*/ |
| 124 |
public $blocks; |
| 125 |
|
| 126 |
/** |
| 127 |
* Widgets |
| 128 |
* |
| 129 |
* @var Widgets |
| 130 |
*/ |
| 131 |
public $widgets; |
| 132 |
|
| 133 |
/** |
| 134 |
* Shortcodes |
| 135 |
* |
| 136 |
* @var Shortcodes |
| 137 |
*/ |
| 138 |
public $shortcodes; |
| 139 |
|
| 140 |
/** |
| 141 |
* Track |
| 142 |
* |
| 143 |
* @var Track |
| 144 |
*/ |
| 145 |
public $track; |
| 146 |
|
| 147 |
/** |
| 148 |
* log |
| 149 |
* |
| 150 |
* @var Log |
| 151 |
*/ |
| 152 |
public $log; |
| 153 |
|
| 154 |
/** |
| 155 |
* PHP Scripts |
| 156 |
* |
| 157 |
* @var PHPScripts |
| 158 |
*/ |
| 159 |
public $phpscripts; |
| 160 |
#PRO-END |
| 161 |
|
| 162 |
/** |
| 163 |
* Translations |
| 164 |
* |
| 165 |
* @var Translations |
| 166 |
*/ |
| 167 |
public $translations; |
| 168 |
|
| 169 |
/** |
| 170 |
* Tables used by Hook |
| 171 |
* |
| 172 |
* @var array |
| 173 |
*/ |
| 174 |
public $hook_data = [ |
| 175 |
'tables' => [ 'firebox_logs', 'firebox_logs_details', 'firebox_submissions', 'firebox_submission_meta' ], |
| 176 |
'activation' => FBOX_PLUGIN_DIR . 'Inc/Core/Admin/sql/firebox.sql', |
| 177 |
'uninstall' => FBOX_PLUGIN_DIR . 'Inc/Core/Admin/sql/uninstall.firebox.sql' |
| 178 |
]; |
| 179 |
|
| 180 |
/** |
| 181 |
* The plugin name |
| 182 |
* |
| 183 |
* @var String |
| 184 |
*/ |
| 185 |
public $plugin_name = 'FireBox'; |
| 186 |
|
| 187 |
/** |
| 188 |
* The plugin slug |
| 189 |
* |
| 190 |
* @var String |
| 191 |
*/ |
| 192 |
public $plugin_slug = 'firebox'; |
| 193 |
|
| 194 |
/** |
| 195 |
* Holds the plugin instance |
| 196 |
* |
| 197 |
* @var Plugin $instance |
| 198 |
*/ |
| 199 |
public static $instance = null; |
| 200 |
|
| 201 |
private function __construct() |
| 202 |
{ |
| 203 |
$this->preFlight(); |
| 204 |
|
| 205 |
// run init |
| 206 |
add_action('fpf_init', [$this, 'init']); |
| 207 |
|
| 208 |
// admin init |
| 209 |
add_action('fpf_admin_init', [$this, 'admin_init']); |
| 210 |
|
| 211 |
// admin menu |
| 212 |
add_action('admin_menu', [$this, 'admin_menu']); |
| 213 |
} |
| 214 |
|
| 215 |
/** |
| 216 |
* Admin Menu |
| 217 |
* |
| 218 |
* @return void |
| 219 |
*/ |
| 220 |
public function admin_menu() |
| 221 |
{ |
| 222 |
$this->menu = new PluginMenu(); |
| 223 |
$this->menu->init(); |
| 224 |
} |
| 225 |
|
| 226 |
/** |
| 227 |
* Admin Init |
| 228 |
* |
| 229 |
* @return void |
| 230 |
*/ |
| 231 |
public function admin_init() |
| 232 |
{ |
| 233 |
|
| 234 |
new \FPFramework\Admin\Includes\UpgradeProModal($this->plugin_slug, $this->plugin_name); |
| 235 |
|
| 236 |
|
| 237 |
// Admin |
| 238 |
$this->admin = new Admin(); |
| 239 |
|
| 240 |
// Library |
| 241 |
$this->library = new Library(); |
| 242 |
|
| 243 |
// Metaboxes |
| 244 |
$this->metaboxes_manager = new MetaboxManager(); |
| 245 |
$this->plugin_metaboxes = new PluginMetaboxes(); |
| 246 |
$this->metaboxes_manager->init(); |
| 247 |
} |
| 248 |
|
| 249 |
/** |
| 250 |
* Runs at the start of the Plugin |
| 251 |
* |
| 252 |
* @return void |
| 253 |
*/ |
| 254 |
public function preFlight() |
| 255 |
{ |
| 256 |
// set translations |
| 257 |
$this->translations = new Libs\Translations(); |
| 258 |
|
| 259 |
// loads text domain |
| 260 |
add_action('plugins_loaded', [$this, 'loadTextdomain'], 10); |
| 261 |
|
| 262 |
// show rate reminder after user has activated the plugin |
| 263 |
add_action('activated_plugin', [$this, 'set_rate_reminder']); |
| 264 |
|
| 265 |
// Widgets |
| 266 |
$this->widgets = new Widgets(); |
| 267 |
} |
| 268 |
|
| 269 |
/** |
| 270 |
* Set rate reminder transient on plugin activation. |
| 271 |
* |
| 272 |
* @return void |
| 273 |
*/ |
| 274 |
public function set_rate_reminder() |
| 275 |
{ |
| 276 |
if( get_transient( 'fpf_firebox_rate_reminder_deleted' ) || get_transient( 'fpf_firebox_rate_reminder' ) ) |
| 277 |
{ |
| 278 |
return; |
| 279 |
} |
| 280 |
|
| 281 |
// make rate reminder appear 2 days after the plugin has been activated. |
| 282 |
$date = new \DateTime(); |
| 283 |
$date->add( new \DateInterval( 'P2D' ) ); |
| 284 |
set_transient( 'fpf_firebox_rate_reminder', $date->format( 'Y-m-d' ) ); |
| 285 |
} |
| 286 |
|
| 287 |
/** |
| 288 |
* Ensures only one instance of the plugin class is loaded or can be loaded |
| 289 |
* |
| 290 |
* @return Plugin An instance of the class. |
| 291 |
*/ |
| 292 |
public static function instance() |
| 293 |
{ |
| 294 |
if (is_null(self::$instance)) |
| 295 |
{ |
| 296 |
self::$instance = new self(); |
| 297 |
} |
| 298 |
|
| 299 |
return self::$instance; |
| 300 |
} |
| 301 |
|
| 302 |
/** |
| 303 |
* Loads the textdomain |
| 304 |
* |
| 305 |
* @return void |
| 306 |
*/ |
| 307 |
public function loadTextdomain() |
| 308 |
{ |
| 309 |
load_plugin_textdomain('firebox', false, FBOX_PLUGIN_DIR . 'languages/'); |
| 310 |
} |
| 311 |
|
| 312 |
/** |
| 313 |
* Initializes all Common components used by front-end and back-end. |
| 314 |
* |
| 315 |
* @return void |
| 316 |
*/ |
| 317 |
private function initCommons() |
| 318 |
{ |
| 319 |
new AdminBarMenu(); |
| 320 |
|
| 321 |
// Tables |
| 322 |
$this->tables = new Tables(); |
| 323 |
|
| 324 |
// Shortcodes |
| 325 |
$this->shortcodes = new Shortcodes(); |
| 326 |
|
| 327 |
// Log |
| 328 |
$this->log = new Log(); |
| 329 |
|
| 330 |
// REST API |
| 331 |
new RESTAPI(); |
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
// Custom Post Types |
| 336 |
$this->cpts = new Cpts(); |
| 337 |
$this->cpts->init(); |
| 338 |
|
| 339 |
// Renderer |
| 340 |
$this->renderer = new Renderer(FBOX_LAYOUTS_DIR); |
| 341 |
|
| 342 |
// Box |
| 343 |
$this->box = new Box(); |
| 344 |
|
| 345 |
// Boxes |
| 346 |
$this->boxes = new Boxes(); |
| 347 |
|
| 348 |
// Helper |
| 349 |
$this->helper = new HelperMiddleware(); |
| 350 |
|
| 351 |
// Gutenberg Blocks |
| 352 |
$this->blocks = new Blocks(); |
| 353 |
|
| 354 |
// Forms AJAX |
| 355 |
new \FireBox\Core\Form\Ajax(); |
| 356 |
|
| 357 |
// Analytics AJAX |
| 358 |
new \FireBox\Core\Analytics\Ajax(); |
| 359 |
|
| 360 |
// Track |
| 361 |
$this->track = new Track(); |
| 362 |
} |
| 363 |
|
| 364 |
/** |
| 365 |
* Initializes FireBox Plugin with the required components |
| 366 |
* |
| 367 |
* @return void |
| 368 |
*/ |
| 369 |
public function init() |
| 370 |
{ |
| 371 |
// init framework |
| 372 |
\FPFramework\Framework::getInstance($this->plugin_slug); |
| 373 |
|
| 374 |
// common classes (both front/back end) |
| 375 |
$this->initCommons(); |
| 376 |
|
| 377 |
// Load front-end |
| 378 |
new Frontend(); |
| 379 |
} |
| 380 |
|
| 381 |
/** |
| 382 |
* Append our Plugin translation class to the set of translation classes of the Framework |
| 383 |
* |
| 384 |
* @param array |
| 385 |
* |
| 386 |
* @return array |
| 387 |
*/ |
| 388 |
public function setTranslationsPaths($paths) |
| 389 |
{ |
| 390 |
if (isset($paths['firebox'])) |
| 391 |
{ |
| 392 |
return $paths; |
| 393 |
} |
| 394 |
|
| 395 |
$paths['firebox'] = [ |
| 396 |
'prefix' => 'FB_' |
| 397 |
]; |
| 398 |
|
| 399 |
return $paths; |
| 400 |
} |
| 401 |
|
| 402 |
/** |
| 403 |
* Retrieves the translation of $text |
| 404 |
* |
| 405 |
* @param string $text |
| 406 |
* @param string $fallback |
| 407 |
* |
| 408 |
* @return string |
| 409 |
*/ |
| 410 |
public function _($text, $fallback = null) |
| 411 |
{ |
| 412 |
return $this->translations->_($text, $fallback); |
| 413 |
} |
| 414 |
} |
| 415 |
} |
| 416 |
|
| 417 |
namespace { |
| 418 |
/** |
| 419 |
* The function which returns the one and only FireBox instance. |
| 420 |
* |
| 421 |
* @return Plugin |
| 422 |
*/ |
| 423 |
function firebox() |
| 424 |
{ |
| 425 |
return FireBox\Core\Plugin::instance(); |
| 426 |
} |
| 427 |
} |