PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / trunk
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment vtrunk
3.1.13 3.1.12 3.1.11 3.1.10 3.1.9 3.1.8 3.1.7 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 All 122 releases
firebox / Inc / Core / Previewer.php

Previewer.php in FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment trunk, at Inc/Core/Previewer.php

234 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package FireBox
4 * @version 3.1.13 Free
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2026 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 Previewer
20 {
21 /**
22 * FireBox data.
23 *
24 * @var array
25 */
26 public $box_data;
27
28 protected $embed_html = '';
29
30 /**
31 * Inits Previewer
32 *
33 * @return void
34 */
35 public function init()
36 {
37 if (!$this->is_preview_page())
38 {
39 return false;
40 }
41
42 $this->hooks();
43 return true;
44 }
45
46 /**
47 * Check if current page request meets requirements for firebox preview page.
48 *
49 * @return boolean
50 */
51 public function is_preview_page()
52 {
53 global $post;
54 $post_type = isset($_GET['post_type']) ? sanitize_key($_GET['post_type']) : false; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
55 $post_id = isset($_GET['p']) ? \absint($_GET['p']) : false; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
56
57 if (!$post_type && !$post_id && $post)
58 {
59 $post_type = $post->post_type;
60 $post_id = $post->ID;
61 }
62
63 // Only proceed if we have a item to preview
64 if (empty($post_type))
65 {
66 return false;
67 }
68
69 if ($post_type != 'firebox')
70 {
71 return false;
72 }
73
74 if (empty($post_id))
75 {
76 return false;
77 }
78
79 if (empty($_GET['preview'])) //phpcs:ignore WordPress.Security.NonceVerification.Recommended
80 {
81 return false;
82 }
83
84 if (!sanitize_key(wp_unslash($_GET['preview']))) //phpcs:ignore WordPress.Security.NonceVerification.Recommended
85 {
86 return false;
87 }
88
89 // Check for logged in user.
90 if (!\is_user_logged_in())
91 {
92 return false;
93 }
94
95 if (!\current_user_can('read_firebox', $post_id))
96 {
97 return false;
98 }
99
100 if (!$this->box_data = firebox()->box->get($post_id))
101 {
102 return false;
103 }
104
105 return true;
106 }
107
108 /**
109 * Hooks
110 *
111 * @return void
112 */
113 public function hooks()
114 {
115 if ($this->box_data->params->get('mode') !== 'embed')
116 {
117 // Set to trigger on Page Load
118 $this->box_data->params->set('triggermethod', 'pageload');
119 }
120
121 // Remove Impressions
122 $this->box_data->params->set('assign_impressions_param_type', 'always');
123 // Remove Assignments
124 $this->box_data->params->remove('assignments');
125 // Remove Rules
126 $this->box_data->params->remove('rules');
127 // Enable Test Mode to prevent cookies
128 $this->box_data->params->set('testmode', true);
129 // Disable Statistics to prevent impressions from being tracked into the database
130 $this->box_data->params->set('stats', 0);
131
132 \FireBox\Core\Helpers\Actions::run();
133
134 if ($this->box_data->params->get('mode') !== 'embed')
135 {
136 firebox()->box->setBox($this->box_data)->render();
137 }
138 else
139 {
140 global $post;
141 $this->embed_html = \FireBox\Core\Helpers\Embed::renderCampaign($post->ID, ['draft']);
142 }
143
144 \add_filter('the_title', [$this, 'the_title'], 100, 1);
145
146 \add_filter('the_content', [$this, 'the_content'], 999);
147
148 \add_filter('get_the_excerpt', [$this, 'the_content'], 999);
149 }
150
151 public function the_content()
152 {
153 if (!isset($this->box_data->ID))
154 {
155 return '';
156 }
157
158 if (!current_user_can('read_firebox', $this->box_data->ID))
159 {
160 return '';
161 }
162
163 $links = [];
164
165 $links[] = [
166 'url' => esc_url(
167 add_query_arg(
168 [
169 'post' => absint($this->box_data->ID),
170 'action' => 'edit',
171 ],
172 admin_url('post.php')
173 )
174 ),
175 'text' => esc_html(firebox()->_('FB_EDIT_CAMPAIGN')),
176 ];
177
178 $links[] = [
179 'url' => esc_url(
180 add_query_arg(
181 [
182 'post_type' => 'firebox',
183 ],
184 admin_url('edit.php')
185 )
186 ),
187 'text' => esc_html(firebox()->_('FB_VIEW_CAMPAIGNS')),
188 ];
189
190 $content = '<div style="padding: 15px; background: #ededed;">';
191 $content .= '<p>';
192 $content .= esc_html(firebox()->_('FB_FIREBOX_PREVIEW_DESC'));
193 $content .= '<br>';
194 foreach ($links as $key => $link)
195 {
196 $content .= '<a href="' . esc_url($link['url']) . '">' . esc_html($link['text']) . '</a>';
197 $l = array_keys($links);
198 if (end($l) !== $key)
199 {
200 $content .= ' <span style="display:inline-block;margin:0 6px;opacity: 0.5">|</span> ';
201 }
202 }
203 $content .= '</p>';
204 $content .= '</div>';
205
206 // Add embed campaign to preview page
207 if ($this->box_data->params->get('mode') === 'embed')
208 {
209 $content .= '<div style="margin: 30px auto; display: flex; justify-content: center;">' . $this->embed_html . '</div>';
210 }
211
212 return $content;
213 }
214
215 /**
216 * Customize firebox popup preview page title.
217 *
218 * @param string $title
219 *
220 * @return string
221 */
222 public function the_title($title)
223 {
224 if (in_the_loop())
225 {
226 $title = sprintf(
227 esc_html('%s'),
228 ! empty($this->box_data->post_title) ? sanitize_text_field($this->box_data->post_title) . ' ' . firebox()->_('FB_PREVIEW') : esc_html(firebox()->_('FB_FIREBOX_CAMPAIGN_PREVIEW'))
229 );
230 }
231
232 return $title;
233 }
234 }