| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FireBox |
| 4 |
* @version 3.0.1 Free |
| 5 |
* |
| 6 |
* @author FirePlugins <info@fireplugins.com> |
| 7 |
* @link https://www.fireplugins.com |
| 8 |
* @copyright Copyright © 2025 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 |
class Frontend |
| 20 |
{ |
| 21 |
public function __construct() |
| 22 |
{ |
| 23 |
// ensure we run only on front-end |
| 24 |
if (is_admin()) |
| 25 |
{ |
| 26 |
return; |
| 27 |
} |
| 28 |
|
| 29 |
// Prepare Gutenberg Blocks that contain attributes by FireBox |
| 30 |
new \FireBox\Core\FB\BoxBlocksParser(); |
| 31 |
|
| 32 |
/** |
| 33 |
* Event that runs before any rendering of popups. |
| 34 |
*/ |
| 35 |
do_action('firebox/boxes/before_render'); |
| 36 |
|
| 37 |
// Run Actions |
| 38 |
\FireBox\Core\Helpers\Actions::run(); |
| 39 |
|
| 40 |
add_action('template_redirect', [$this, 'render']); |
| 41 |
|
| 42 |
/** |
| 43 |
* Event that runs after popups have been rendered. |
| 44 |
*/ |
| 45 |
do_action('firebox/boxes/after_render'); |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Renders all boxes on front-end |
| 50 |
* |
| 51 |
* @return void |
| 52 |
*/ |
| 53 |
public function render() |
| 54 |
{ |
| 55 |
if ($this->checkForBoxPreview()) |
| 56 |
{ |
| 57 |
return; |
| 58 |
} |
| 59 |
|
| 60 |
// Don't render the popup if previewing with third party page builders |
| 61 |
if (!$this->canRenderInEditors()) |
| 62 |
{ |
| 63 |
return; |
| 64 |
} |
| 65 |
|
| 66 |
// increment session counter |
| 67 |
\FPFramework\Libs\Functions::incrementSession(); |
| 68 |
|
| 69 |
/** |
| 70 |
* Adds all boxes at the end of page. |
| 71 |
*/ |
| 72 |
firebox()->boxes->render(); |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Don't render when previewing with third party page builders. |
| 77 |
* |
| 78 |
* @return boolean |
| 79 |
*/ |
| 80 |
private function canRenderInEditors() |
| 81 |
{ |
| 82 |
// Don't render the popup if previewing with Elementor |
| 83 |
if (class_exists('\Elementor\Plugin') && \Elementor\Plugin::$instance->preview->is_preview_mode()) |
| 84 |
{ |
| 85 |
return; |
| 86 |
} |
| 87 |
|
| 88 |
// Don't render the popup if previewing with Beaver Builder |
| 89 |
if (class_exists('\FLBuilderModel') && method_exists('\FLBuilderModel', 'is_builder_active') && \FLBuilderModel::is_builder_active()) |
| 90 |
{ |
| 91 |
return; |
| 92 |
} |
| 93 |
|
| 94 |
return true; |
| 95 |
} |
| 96 |
|
| 97 |
/** |
| 98 |
* Check if we are previewing a box and do not show other boxes. |
| 99 |
* |
| 100 |
* @return boolean |
| 101 |
*/ |
| 102 |
private function checkForBoxPreview() |
| 103 |
{ |
| 104 |
$previewer = new Previewer(); |
| 105 |
return $previewer->init(); |
| 106 |
} |
| 107 |
} |