| @@ -1,12 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package FireBox |
| 4 | - * @version 1.0.11 Free | |
| 4 | + * @version 2.0.12 Free | |
| 5 | 5 | * |
| 6 | 6 | * @author FirePlugins <info@fireplugins.com> |
| 7 | 7 | * @link https://www.fireplugins.com |
| 8 | - * @copyright Copyright © 2022 FirePlugins All Rights Reserved | |
| 8 | + * @copyright Copyright © 2023 FirePlugins All Rights Reserved | |
| 9 | 9 | * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | namespace FireBox\Core; |
| @@ -27,40 +27,49 @@ | ||
| 27 | 27 | { |
| 28 | 28 | return; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - $this->init_dependencies(); | |
| 31 | + // Prepare Gutenberg Blocks that contain attributes by FireBox | |
| 32 | + new \FireBox\Core\FB\BoxBlocksParser(); | |
| 32 | 33 | |
| 33 | - $this->render(); | |
| 34 | - } | |
| 35 | - | |
| 36 | - /** | |
| 37 | - * Initializes the dependencies | |
| 38 | - * | |
| 39 | - * @return void | |
| 40 | - */ | |
| 41 | - private function init_dependencies() | |
| 42 | - { | |
| 34 | + $this->prepare(); | |
| 35 | + | |
| 43 | 36 | /** |
| 44 | 37 | * Event that runs before any rendering of popups. |
| 45 | 38 | */ |
| 46 | 39 | do_action('firebox/boxes/before_render'); |
| 47 | 40 | |
| 48 | - $actions = []; | |
| 49 | - | |
| 50 | - | |
| 41 | + add_action('template_redirect', [$this, 'render']); | |
| 51 | 42 | |
| 52 | - // Initialize Sounds | |
| 53 | - $actions[] = new \FireBox\Core\FB\Actions\Sounds(); | |
| 54 | - | |
| 55 | - // Make actions filterable | |
| 56 | - $actions = apply_filters('firebox/actions/box/edit', $actions); | |
| 43 | + \FireBox\Core\Helpers\Actions::run(); | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * Event that runs after popups have been rendered. | |
| 47 | + */ | |
| 48 | + do_action('firebox/boxes/after_render'); | |
| 49 | + } | |
| 50 | + | |
| 51 | + private function prepare() | |
| 52 | + { | |
| 53 | + add_filter('the_content', [$this, 'prepareContent'], 0); | |
| 54 | + } | |
| 55 | + | |
| 56 | + public function prepareContent($content) | |
| 57 | + { | |
| 58 | + global $post; | |
| 59 | + | |
| 60 | + if (!$post instanceof \WP_Post) | |
| 61 | + { | |
| 62 | + return $content; | |
| 63 | + } | |
| 64 | + | |
| 65 | + // Check if the current post type is 'firebox' | |
| 66 | + if ($post->post_type === 'firebox') | |
| 67 | + { | |
| 68 | + remove_filter('the_content', 'wptexturize'); | |
| 69 | + } | |
| 57 | 70 | |
| 58 | - // Run actions | |
| 59 | - new \FireBox\Core\FB\Actions\ActionsBase($actions); | |
| 60 | - | |
| 61 | - // Prepare Gutenberg Blocks that contain attributes by FireBox | |
| 62 | - new \FireBox\Core\FB\BoxBlocksParser(); | |
| 71 | + return $content; | |
| 63 | 72 | } |
| 64 | 73 | |
| 65 | 74 | /** |
| 66 | 75 | * Renders all boxes on front-end |
| @@ -66,9 +75,9 @@ | ||
| 66 | 75 | * Renders all boxes on front-end |
| 67 | 76 | * |
| 68 | 77 | * @return void |
| 69 | 78 | */ |
| 70 | - private function render() | |
| 79 | + public function render() | |
| 71 | 80 | { |
| 72 | 81 | if ($this->checkForBoxPreview()) |
| 73 | 82 | { |
| 74 | 83 | return; |
| @@ -73,13 +82,8 @@ | ||
| 73 | 82 | { |
| 74 | 83 | return; |
| 75 | 84 | } |
| 76 | 85 | |
| 77 | - if ($this->checkForBoxTemplatePreview()) | |
| 78 | - { | |
| 79 | - return; | |
| 80 | - } | |
| 81 | - | |
| 82 | 86 | // increment session counter |
| 83 | 87 | \FPFramework\Libs\Functions::incrementSession(); |
| 84 | 88 | |
| 85 | 89 | /** |
| @@ -84,16 +88,9 @@ | ||
| 84 | 88 | |
| 85 | 89 | /** |
| 86 | 90 | * Adds all boxes at the end of page. |
| 87 | 91 | */ |
| 88 | - add_action('wp', function() { | |
| 89 | - firebox()->boxes->render(); | |
| 90 | - }); | |
| 91 | - | |
| 92 | - /** | |
| 93 | - * Event that runs after popups have been rendered. | |
| 94 | - */ | |
| 95 | - do_action('firebox/boxes/after_render'); | |
| 92 | + firebox()->boxes->render(); | |
| 96 | 93 | } |
| 97 | 94 | |
| 98 | 95 | /** |
| 99 | 96 | * Check if we are previewing a box and do not show other boxes. |
| @@ -103,75 +100,6 @@ | ||
| 103 | 100 | private function checkForBoxPreview() |
| 104 | 101 | { |
| 105 | 102 | $previewer = new Previewer(); |
| 106 | 103 | return $previewer->init(); |
| 107 | - } | |
| 108 | - | |
| 109 | - /** | |
| 110 | - * Check if we are previewing a box template and do not show other boxes. | |
| 111 | - * | |
| 112 | - * @return boolean | |
| 113 | - */ | |
| 114 | - private function checkForBoxTemplatePreview() | |
| 115 | - { | |
| 116 | - // Preview a box template | |
| 117 | - if (!isset($_GET['firebox_preview_template'])) | |
| 118 | - { | |
| 119 | - return false; | |
| 120 | - } | |
| 121 | - | |
| 122 | - $preview_box = sanitize_text_field($_GET['firebox_preview_template']); | |
| 123 | - $this->render_template(base64_decode($preview_box)); | |
| 124 | - return true; | |
| 125 | - } | |
| 126 | - | |
| 127 | - /** | |
| 128 | - * Render template content | |
| 129 | - * | |
| 130 | - * @param string $template_alias | |
| 131 | - * | |
| 132 | - * @return void | |
| 133 | - */ | |
| 134 | - private function render_template($template_alias) | |
| 135 | - { | |
| 136 | - $templates = firebox()->library; | |
| 137 | - | |
| 138 | - if (!$box = $templates->find($template_alias)) | |
| 139 | - { | |
| 140 | - return; | |
| 141 | - } | |
| 142 | - | |
| 143 | - $box->params = new Registry($box->params); | |
| 144 | - | |
| 145 | - // Remove Publishing Assignments | |
| 146 | - foreach ($box->params as $key => $value) | |
| 147 | - { | |
| 148 | - if (strpos($key, 'assign') !== false) | |
| 149 | - { | |
| 150 | - $box->params->remove($key); | |
| 151 | - } | |
| 152 | - } | |
| 153 | - $box->params->remove('assignments'); | |
| 154 | - | |
| 155 | - // Set id to 999999 for making front-end script happy | |
| 156 | - $box->ID = 999999; | |
| 157 | - | |
| 158 | - // Enable Test Mode to prevent cookies | |
| 159 | - $box->params->set('testmode', true); | |
| 160 | - | |
| 161 | - /** | |
| 162 | - * Some popups may require a trigger method override for the Template preview. | |
| 163 | - * | |
| 164 | - * i.e. AdBlock popups should not require an AdBlocker for the Template preview | |
| 165 | - * to display the popup. | |
| 166 | - */ | |
| 167 | - if (isset($box->custom_fields->override_trigger_method) && $box->custom_fields->override_trigger_method !== 'inherit') | |
| 168 | - { | |
| 169 | - $box->params->set('triggermethod', $box->custom_fields->override_trigger_method); | |
| 170 | - } | |
| 171 | - | |
| 172 | - // Disable Statistics to prevent impressions from being tracked into the database | |
| 173 | - $box->stats = 0; | |
| 174 | - | |
| 175 | - return firebox()->box->render($box); | |
| 176 | 104 | } |
| 177 | 105 | } |