PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 2.1.4
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v2.1.4
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 2.1.4, at Inc/Core/Previewer.php

217 lines 4.3 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 2.1.4 Free
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2024 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 /**
29 * Inits Previewer
30 *
31 * @return void
32 */
33 public function init()
34 {
35 if (!$this->is_preview_page())
36 {
37 return false;
38 }
39
40 $this->hooks();
41 return true;
42 }
43
44 /**
45 * Check if current page request meets requirements for firebox preview page.
46 *
47 * @return boolean
48 */
49 public function is_preview_page()
50 {
51 global $post;
52 $post_type = isset($_GET['post_type']) ? sanitize_key($_GET['post_type']) : false;
53 $post_id = isset($_GET['p']) ? \absint($_GET['p']) : false;
54
55 if (!$post_type && !$post_id && $post)
56 {
57 $post_type = $post->post_type;
58 $post_id = $post->ID;
59 }
60
61 // Only proceed if we have a item to preview
62 if (empty($post_type))
63 {
64 return false;
65 }
66
67 if ($post_type != 'firebox')
68 {
69 return false;
70 }
71
72 if (empty($post_id))
73 {
74 return false;
75 }
76
77 if (empty($_GET['preview']))
78 {
79 return false;
80 }
81
82 if (!$_GET['preview'])
83 {
84 return false;
85 }
86
87 // Check for logged in user.
88 if (!\is_user_logged_in())
89 {
90 return false;
91 }
92
93 if (!\current_user_can('manage_options'))
94 {
95 return false;
96 }
97
98 if (!$this->box_data = firebox()->box->get($post_id))
99 {
100 return false;
101 }
102
103 return true;
104 }
105
106 /**
107 * Hooks
108 *
109 * @return void
110 */
111 public function hooks()
112 {
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();
127
128 firebox()->box->setBox($this->box_data)->render();
129
130 \add_filter('the_title', [$this, 'the_title'], 100, 1);
131
132 \add_filter('the_content', [$this, 'the_content'], 999);
133
134 \add_filter('get_the_excerpt', [$this, 'the_content'], 999);
135 }
136
137 public function the_content()
138 {
139 if (!isset($this->box_data->ID))
140 {
141 return '';
142 }
143
144 if (!current_user_can('manage_options'))
145 {
146 return '';
147 }
148
149 $links = [];
150
151 $links[] = [
152 'url' => esc_url(
153 add_query_arg(
154 [
155 'post' => absint($this->box_data->ID),
156 'action' => 'edit',
157 ],
158 admin_url('post.php')
159 )
160 ),
161 'text' => esc_html(firebox()->_('FB_EDIT_FIREBOX')),
162 ];
163
164 $links[] = [
165 'url' => esc_url(
166 add_query_arg(
167 [
168 'post_type' => 'firebox',
169 ],
170 admin_url('edit.php')
171 )
172 ),
173 'text' => esc_html(firebox()->_('FB_VIEW_FIREBOX_ITEMS')),
174 ];
175
176 $content = '<div style="padding: 15px; background: #ededed;">';
177 $content .= '<p>';
178 $content .= esc_html(firebox()->_('FB_FIREBOX_PREVIEW_DESC'));
179 if (!empty($links))
180 {
181 $content .= '<br>';
182 foreach ($links as $key => $link)
183 {
184 $content .= '<a href="' . esc_url($link['url']) . '">' . esc_html($link['text']) . '</a>';
185 $l = array_keys($links);
186 if (end($l) !== $key)
187 {
188 $content .= ' <span style="display:inline-block;margin:0 6px;opacity: 0.5">|</span> ';
189 }
190 }
191 }
192 $content .= '</p>';
193 $content .= '</div>';
194
195 return $content;
196 }
197
198 /**
199 * Customize firebox popup preview page title.
200 *
201 * @param string $title
202 *
203 * @return string
204 */
205 public function the_title($title)
206 {
207 if (in_the_loop())
208 {
209 $title = sprintf(
210 esc_html('%s'),
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'))
212 );
213 }
214
215 return $title;
216 }
217 }