| @@ -1,12 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package FireBox |
| 4 | - * @version 1.0.0 Free | |
| 4 | + * @version 2.1.14 Free | |
| 5 | 5 | * |
| 6 | 6 | * @author FirePlugins <info@fireplugins.com> |
| 7 | 7 | * @link https://www.fireplugins.com |
| 8 | - * @copyright Copyright © 2021 FirePlugins All Rights Reserved | |
| 8 | + * @copyright Copyright © 2024 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; |
| @@ -15,11 +15,10 @@ | ||
| 15 | 15 | { |
| 16 | 16 | exit; // Exit if accessed directly. |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | -use \FPFramework\Libs\Registry; | |
| 20 | - | |
| 21 | -class Previewer { | |
| 19 | +class Previewer | |
| 20 | +{ | |
| 22 | 21 | /** |
| 23 | 22 | * FireBox data. |
| 24 | 23 | * |
| 25 | 24 | * @var array |
| @@ -48,30 +47,40 @@ | ||
| 48 | 47 | * @return boolean |
| 49 | 48 | */ |
| 50 | 49 | public function is_preview_page() |
| 51 | 50 | { |
| 51 | + global $post; | |
| 52 | + $post_type = isset($_GET['post_type']) ? sanitize_key($_GET['post_type']) : false; //phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 53 | + $post_id = isset($_GET['p']) ? \absint($_GET['p']) : false; //phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 54 | + | |
| 55 | + if (!$post_type && !$post_id && $post) | |
| 56 | + { | |
| 57 | + $post_type = $post->post_type; | |
| 58 | + $post_id = $post->ID; | |
| 59 | + } | |
| 60 | + | |
| 52 | 61 | // Only proceed if we have a item to preview |
| 53 | - if (empty($_GET['post_type'])) | |
| 62 | + if (empty($post_type)) | |
| 54 | 63 | { |
| 55 | 64 | return false; |
| 56 | 65 | } |
| 57 | 66 | |
| 58 | - if ($_GET['post_type'] != 'firebox') | |
| 67 | + if ($post_type != 'firebox') | |
| 59 | 68 | { |
| 60 | 69 | return false; |
| 61 | 70 | } |
| 62 | 71 | |
| 63 | - if (empty($_GET['p'])) | |
| 72 | + if (empty($post_id)) | |
| 64 | 73 | { |
| 65 | 74 | return false; |
| 66 | 75 | } |
| 67 | 76 | |
| 68 | - if (empty($_GET['preview'])) | |
| 77 | + if (empty($_GET['preview'])) //phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 69 | 78 | { |
| 70 | 79 | return false; |
| 71 | 80 | } |
| 72 | 81 | |
| 73 | - if (!$_GET['preview']) | |
| 82 | + if (!$_GET['preview']) //phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 74 | 83 | { |
| 75 | 84 | return false; |
| 76 | 85 | } |
| 77 | 86 | |
| @@ -85,11 +94,9 @@ | ||
| 85 | 94 | { |
| 86 | 95 | return false; |
| 87 | 96 | } |
| 88 | 97 | |
| 89 | - $box_id = \absint($_GET['p']); // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 90 | - | |
| 91 | - if (!$this->box_data = firebox()->boxes->getBox()->get($box_id, null)) | |
| 98 | + if (!$this->box_data = firebox()->box->get($post_id)) | |
| 92 | 99 | { |
| 93 | 100 | return false; |
| 94 | 101 | } |
| 95 | 102 | |
| @@ -102,10 +109,25 @@ | ||
| 102 | 109 | * @return void |
| 103 | 110 | */ |
| 104 | 111 | public function hooks() |
| 105 | 112 | { |
| 106 | - firebox()->boxes->getBox()->render($this->box_data); | |
| 113 | + // Set to trigger on Page Load | |
| 114 | + $this->box_data->params->set('triggermethod', 'pageload'); | |
| 115 | + // Remove Impressions | |
| 116 | + $this->box_data->params->set('assign_impressions_param_type', 'always'); | |
| 117 | + // Remove Assignments | |
| 118 | + $this->box_data->params->remove('assignments'); | |
| 119 | + // Remove Rules | |
| 120 | + $this->box_data->params->remove('rules'); | |
| 121 | + // Enable Test Mode to prevent cookies | |
| 122 | + $this->box_data->params->set('testmode', true); | |
| 123 | + // Disable Statistics to prevent impressions from being tracked into the database | |
| 124 | + $this->box_data->params->set('stats', 0); | |
| 125 | + | |
| 126 | + \FireBox\Core\Helpers\Actions::run(); | |
| 107 | 127 | |
| 128 | + firebox()->box->setBox($this->box_data)->render(); | |
| 129 | + | |
| 108 | 130 | \add_filter('the_title', [$this, 'the_title'], 100, 1); |
| 109 | 131 | |
| 110 | 132 | \add_filter('the_content', [$this, 'the_content'], 999); |
| 111 | 133 | |
| @@ -122,9 +144,9 @@ | ||
| 122 | 144 | if (!current_user_can('manage_options')) |
| 123 | 145 | { |
| 124 | 146 | return ''; |
| 125 | 147 | } |
| 126 | - | |
| 148 | + | |
| 127 | 149 | $links = []; |
| 128 | 150 | |
| 129 | 151 | $links[] = [ |
| 130 | 152 | 'url' => esc_url( |
| @@ -158,9 +180,9 @@ | ||
| 158 | 180 | { |
| 159 | 181 | $content .= '<br>'; |
| 160 | 182 | foreach ($links as $key => $link) |
| 161 | 183 | { |
| 162 | - $content .= '<a href="' . $link['url'] . '">' . $link['text'] . '</a>'; | |
| 184 | + $content .= '<a href="' . esc_url($link['url']) . '">' . esc_html($link['text']) . '</a>'; | |
| 163 | 185 | $l = array_keys($links); |
| 164 | 186 | if (end($l) !== $key) |
| 165 | 187 | { |
| 166 | 188 | $content .= ' <span style="display:inline-block;margin:0 6px;opacity: 0.5">|</span> '; |
| @@ -185,9 +207,9 @@ | ||
| 185 | 207 | if (in_the_loop()) |
| 186 | 208 | { |
| 187 | 209 | $title = sprintf( |
| 188 | 210 | esc_html('%s'), |
| 189 | - ! empty($this->box_data->post_title) ? sanitize_text_field($this->box_data->post_title) . ' ' . firebox()->_('FB_PREVIEW') : esc_html(firebox()->_('FB_FIREBOX_POPUP_PREVIEW')) | |
| 211 | + ! empty($this->box_data->post_title) ? sanitize_text_field($this->box_data->post_title) . ' ' . firebox()->_('FB_PREVIEW') : esc_html(firebox()->_('FB_FIREBOX_CAMPAIGN_PREVIEW')) | |
| 190 | 212 | ); |
| 191 | 213 | } |
| 192 | 214 | |
| 193 | 215 | return $title; |