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