| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FireBox |
| 4 |
* @version 1.0.10 Free |
| 5 |
* |
| 6 |
* @author FirePlugins <info@fireplugins.com> |
| 7 |
* @link https://www.fireplugins.com |
| 8 |
* @copyright Copyright © 2022 FirePlugins All Rights Reserved |
| 9 |
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace FireBox\Core { |
| 13 |
if (!defined('ABSPATH')) |
| 14 |
{ |
| 15 |
exit; // Exit if accessed directly. |
| 16 |
} |
| 17 |
|
| 18 |
use FPFramework\Framework; |
| 19 |
use FPFramework\Admin\Includes\MetaboxManager; |
| 20 |
use FPFramework\Libs\FPGeoIP; |
| 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\Menu\PluginMenu; |
| 30 |
use FireBox\Core\Admin\Maintenance; |
| 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 |
* Maintenance |
| 96 |
* |
| 97 |
* @var Maintenance |
| 98 |
*/ |
| 99 |
public $maintenance; |
| 100 |
|
| 101 |
/** |
| 102 |
* Box |
| 103 |
* |
| 104 |
* @var Box |
| 105 |
*/ |
| 106 |
public $box; |
| 107 |
|
| 108 |
/** |
| 109 |
* Boxes |
| 110 |
* |
| 111 |
* @var Boxes |
| 112 |
*/ |
| 113 |
public $boxes; |
| 114 |
|
| 115 |
/** |
| 116 |
* The WP Admin Menu of the Plugin |
| 117 |
* |
| 118 |
* @var Menu |
| 119 |
*/ |
| 120 |
public $menu; |
| 121 |
|
| 122 |
/** |
| 123 |
* The geolocation class |
| 124 |
* |
| 125 |
* @var GeoIP |
| 126 |
*/ |
| 127 |
public $fpgeoip; |
| 128 |
|
| 129 |
/** |
| 130 |
* The REST API. |
| 131 |
* |
| 132 |
* @var RESTAPI |
| 133 |
*/ |
| 134 |
public $api; |
| 135 |
|
| 136 |
/** |
| 137 |
* Helper Classes |
| 138 |
* |
| 139 |
* @var HelperMiddleware |
| 140 |
*/ |
| 141 |
public $helper; |
| 142 |
|
| 143 |
/** |
| 144 |
* Gutenberg blocks |
| 145 |
* |
| 146 |
* @var Blocks |
| 147 |
*/ |
| 148 |
public $blocks; |
| 149 |
|
| 150 |
/** |
| 151 |
* Widgets |
| 152 |
* |
| 153 |
* @var Widgets |
| 154 |
*/ |
| 155 |
public $widgets; |
| 156 |
|
| 157 |
/** |
| 158 |
* Shortcodes |
| 159 |
* |
| 160 |
* @var Shortcodes |
| 161 |
*/ |
| 162 |
public $shortcodes; |
| 163 |
|
| 164 |
/** |
| 165 |
* Track |
| 166 |
* |
| 167 |
* @var Track |
| 168 |
*/ |
| 169 |
public $track; |
| 170 |
|
| 171 |
/** |
| 172 |
* log |
| 173 |
* |
| 174 |
* @var Log |
| 175 |
*/ |
| 176 |
public $log; |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
/** |
| 181 |
* Translations |
| 182 |
* |
| 183 |
* @var Translations |
| 184 |
*/ |
| 185 |
public $translations; |
| 186 |
|
| 187 |
/** |
| 188 |
* Tables used by Hook |
| 189 |
* |
| 190 |
* @var array |
| 191 |
*/ |
| 192 |
private $hook_data = [ |
| 193 |
'tables' => [ 'firebox_logs' ], |
| 194 |
'activation' => FBOX_PLUGIN_DIR . 'Inc/Core/Admin/sql/firebox.sql', |
| 195 |
'uninstall' => FBOX_PLUGIN_DIR . 'Inc/Core/Admin/sql/uninstall.firebox.sql' |
| 196 |
]; |
| 197 |
|
| 198 |
/** |
| 199 |
* The plugin name |
| 200 |
* |
| 201 |
* @var String |
| 202 |
*/ |
| 203 |
public $plugin_name = 'FireBox'; |
| 204 |
|
| 205 |
/** |
| 206 |
* The plugin slug |
| 207 |
* |
| 208 |
* @var String |
| 209 |
*/ |
| 210 |
public $plugin_slug = 'firebox'; |
| 211 |
|
| 212 |
/** |
| 213 |
* Holds the plugin instance |
| 214 |
* |
| 215 |
* @var Plugin $instance |
| 216 |
*/ |
| 217 |
public static $instance = null; |
| 218 |
|
| 219 |
private function __construct() |
| 220 |
{ |
| 221 |
$this->preFlight(); |
| 222 |
|
| 223 |
// run init |
| 224 |
add_action('fpf_init', [$this, 'init']); |
| 225 |
|
| 226 |
// admin init |
| 227 |
add_action('fpf_admin_init', [$this, 'admin_init']); |
| 228 |
|
| 229 |
// admin menu |
| 230 |
add_action('admin_menu', [$this, 'admin_menu']); |
| 231 |
} |
| 232 |
|
| 233 |
/** |
| 234 |
* Admin Menu |
| 235 |
* |
| 236 |
* @return void |
| 237 |
*/ |
| 238 |
public function admin_menu() |
| 239 |
{ |
| 240 |
$this->menu = new PluginMenu(); |
| 241 |
$this->menu->init(); |
| 242 |
} |
| 243 |
|
| 244 |
/** |
| 245 |
* Admin Init |
| 246 |
* |
| 247 |
* @return void |
| 248 |
*/ |
| 249 |
public function admin_init() |
| 250 |
{ |
| 251 |
|
| 252 |
new \FPFramework\Admin\Includes\UpgradeProModal($this->plugin_slug, $this->plugin_name); |
| 253 |
|
| 254 |
|
| 255 |
// Admin |
| 256 |
$this->admin = new Admin(); |
| 257 |
|
| 258 |
// Metaboxes |
| 259 |
$this->metaboxes_manager = new MetaboxManager(); |
| 260 |
$this->plugin_metaboxes = new PluginMetaboxes(); |
| 261 |
$this->metaboxes_manager->init(); |
| 262 |
} |
| 263 |
|
| 264 |
/** |
| 265 |
* Runs at the start of the Plugin |
| 266 |
* |
| 267 |
* @return void |
| 268 |
*/ |
| 269 |
public function preFlight() |
| 270 |
{ |
| 271 |
// set translations |
| 272 |
$this->translations = new Libs\Translations(); |
| 273 |
|
| 274 |
// loads text domain |
| 275 |
add_action('plugins_loaded', [$this, 'loadTextdomain'], 10); |
| 276 |
|
| 277 |
// show rate reminder after user has activated the plugin |
| 278 |
add_action('activated_plugin', [$this, 'set_rate_reminder']); |
| 279 |
|
| 280 |
// adds plugin translation class to the framework set of translate classes |
| 281 |
add_filter('fpframework/set_translation_paths', [$this, 'setTranslationsPaths']); |
| 282 |
|
| 283 |
// Widgets |
| 284 |
$this->widgets = new Widgets(); |
| 285 |
|
| 286 |
if (is_admin()) |
| 287 |
{ |
| 288 |
// Run Activation/Deactivation procedures |
| 289 |
$this->maintenance = new Maintenance($this->hook_data); |
| 290 |
$this->maintenance->init(); |
| 291 |
} |
| 292 |
} |
| 293 |
|
| 294 |
/** |
| 295 |
* Set rate reminder transient on plugin activation. |
| 296 |
* |
| 297 |
* @return void |
| 298 |
*/ |
| 299 |
public function set_rate_reminder() |
| 300 |
{ |
| 301 |
if( get_transient( 'fpf_firebox_rate_reminder_deleted' ) || get_transient( 'fpf_firebox_rate_reminder' ) ) |
| 302 |
{ |
| 303 |
return; |
| 304 |
} |
| 305 |
|
| 306 |
// make rate reminder appear 2 days after the plugin has been activated. |
| 307 |
$date = new \DateTime(); |
| 308 |
$date->add( new \DateInterval( 'P2D' ) ); |
| 309 |
set_transient( 'fpf_firebox_rate_reminder', $date->format( 'Y-m-d' ) ); |
| 310 |
} |
| 311 |
|
| 312 |
/** |
| 313 |
* Ensures only one instance of the plugin class is loaded or can be loaded |
| 314 |
* |
| 315 |
* @return Plugin An instance of the class. |
| 316 |
*/ |
| 317 |
public static function instance() |
| 318 |
{ |
| 319 |
if (is_null(self::$instance)) |
| 320 |
{ |
| 321 |
self::$instance = new self(); |
| 322 |
} |
| 323 |
|
| 324 |
return self::$instance; |
| 325 |
} |
| 326 |
|
| 327 |
/** |
| 328 |
* Loads the textdomain |
| 329 |
* |
| 330 |
* @return void |
| 331 |
*/ |
| 332 |
public function loadTextdomain() |
| 333 |
{ |
| 334 |
load_plugin_textdomain('firebox', false, FBOX_PLUGIN_DIR . 'languages/'); |
| 335 |
} |
| 336 |
|
| 337 |
/** |
| 338 |
* Initializes all Common components used by front-end and back-end. |
| 339 |
* |
| 340 |
* @return void |
| 341 |
*/ |
| 342 |
private function initCommons() |
| 343 |
{ |
| 344 |
new AdminBarMenu(); |
| 345 |
|
| 346 |
// Library |
| 347 |
$this->library = new Library(); |
| 348 |
|
| 349 |
// Tables |
| 350 |
$this->tables = new Tables(); |
| 351 |
|
| 352 |
// Shortcodes |
| 353 |
$this->shortcodes = new Shortcodes(); |
| 354 |
|
| 355 |
// Log |
| 356 |
$this->log = new Log(); |
| 357 |
|
| 358 |
// REST API |
| 359 |
$this->api = new RESTAPI(); |
| 360 |
|
| 361 |
// Custom Post Types |
| 362 |
$this->cpts = new Cpts(); |
| 363 |
$this->cpts->init(); |
| 364 |
|
| 365 |
// Renderer |
| 366 |
$this->renderer = new Renderer(FBOX_LAYOUTS_DIR); |
| 367 |
|
| 368 |
// Box |
| 369 |
$this->box = new Box(); |
| 370 |
|
| 371 |
// Boxes |
| 372 |
$this->boxes = new Boxes(); |
| 373 |
|
| 374 |
// FPGeo IP |
| 375 |
$this->fpgeoip = new FPGeoIP(); |
| 376 |
|
| 377 |
// Helper |
| 378 |
$this->helper = new HelperMiddleware(); |
| 379 |
|
| 380 |
// Gutenberg Blocks |
| 381 |
$this->blocks = new Blocks(); |
| 382 |
|
| 383 |
// Track |
| 384 |
$this->track = new Track(); |
| 385 |
|
| 386 |
// Initialize Analytics |
| 387 |
global $wpdb; |
| 388 |
$analytics_configuration = [ |
| 389 |
'boxes_table' => $wpdb->prefix . 'posts', |
| 390 |
'logs_table' => firebox()->tables->boxlog->getFullTableName(), |
| 391 |
'logs_details_table' => firebox()->tables->boxlogdetails->getFullTableName(), |
| 392 |
'nonce_value' => wp_create_nonce('fb-analytics-nonce'), |
| 393 |
]; |
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
// Initialize Analytics Overview |
| 398 |
$this->analytics_overview = new AnalyticsOverview($analytics_configuration); |
| 399 |
} |
| 400 |
|
| 401 |
/** |
| 402 |
* Initializes FireBox Plugin with the required components |
| 403 |
* |
| 404 |
* @return void |
| 405 |
*/ |
| 406 |
public function init() |
| 407 |
{ |
| 408 |
// init framework |
| 409 |
\FPFramework\Framework::getInstance($this->plugin_slug); |
| 410 |
|
| 411 |
// common classes (both front/back end) |
| 412 |
$this->initCommons(); |
| 413 |
|
| 414 |
// Load front-end |
| 415 |
new Frontend(); |
| 416 |
} |
| 417 |
|
| 418 |
/** |
| 419 |
* Append our Plugin translation class to the set of translation classes of the Framework |
| 420 |
* |
| 421 |
* @param array |
| 422 |
* |
| 423 |
* @return array |
| 424 |
*/ |
| 425 |
public function setTranslationsPaths($paths) |
| 426 |
{ |
| 427 |
if (isset($paths['firebox'])) |
| 428 |
{ |
| 429 |
return $paths; |
| 430 |
} |
| 431 |
|
| 432 |
$paths['firebox'] = [ |
| 433 |
'prefix' => 'FB_' |
| 434 |
]; |
| 435 |
|
| 436 |
return $paths; |
| 437 |
} |
| 438 |
|
| 439 |
/** |
| 440 |
* Retrieves the translation of $text |
| 441 |
* |
| 442 |
* @param string $text |
| 443 |
* @param string $fallback |
| 444 |
* |
| 445 |
* @return string |
| 446 |
*/ |
| 447 |
public function _($text, $fallback = null) |
| 448 |
{ |
| 449 |
return $this->translations->_($text, $fallback); |
| 450 |
} |
| 451 |
} |
| 452 |
} |
| 453 |
|
| 454 |
namespace { |
| 455 |
/** |
| 456 |
* The function which returns the one and only FireBox instance. |
| 457 |
* |
| 458 |
* @return Plugin |
| 459 |
*/ |
| 460 |
function firebox() |
| 461 |
{ |
| 462 |
return FireBox\Core\Plugin::instance(); |
| 463 |
} |
| 464 |
} |