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

209 lines 4.1 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.0.10 Free
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2023 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 // Only proceed if we have a item to preview
52 if (empty($_GET['post_type']))
53 {
54 return false;
55 }
56
57 if ($_GET['post_type'] != 'firebox')
58 {
59 return false;
60 }
61
62 if (empty($_GET['p']))
63 {
64 return false;
65 }
66
67 if (empty($_GET['preview']))
68 {
69 return false;
70 }
71
72 if (!$_GET['preview'])
73 {
74 return false;
75 }
76
77 // Check for logged in user.
78 if (!\is_user_logged_in())
79 {
80 return false;
81 }
82
83 if (!\current_user_can('manage_options'))
84 {
85 return false;
86 }
87
88 $box_id = \absint($_GET['p']);
89
90 if (!$this->box_data = firebox()->box->get($box_id))
91 {
92 return false;
93 }
94
95 return true;
96 }
97
98 /**
99 * Hooks
100 *
101 * @return void
102 */
103 public function hooks()
104 {
105 // Set to trigger on Page Load
106 $this->box_data->params->set('triggermethod', 'pageload');
107 // Remove Impressions
108 $this->box_data->params->set('assign_impressions_param_type', 'always');
109 // Remove Assignments
110 $this->box_data->params->remove('assignments');
111 // Remove Rules
112 $this->box_data->params->remove('rules');
113 // Enable Test Mode to prevent cookies
114 $this->box_data->params->set('testmode', true);
115 // Disable Statistics to prevent impressions from being tracked into the database
116 $this->box_data->params->set('stats', 0);
117
118 \FireBox\Core\Helpers\Actions::run();
119
120 firebox()->box->setBox($this->box_data)->render();
121
122 \add_filter('the_title', [$this, 'the_title'], 100, 1);
123
124 \add_filter('the_content', [$this, 'the_content'], 999);
125
126 \add_filter('get_the_excerpt', [$this, 'the_content'], 999);
127 }
128
129 public function the_content()
130 {
131 if (!isset($this->box_data->ID))
132 {
133 return '';
134 }
135
136 if (!current_user_can('manage_options'))
137 {
138 return '';
139 }
140
141 $links = [];
142
143 $links[] = [
144 'url' => esc_url(
145 add_query_arg(
146 [
147 'post' => absint($this->box_data->ID),
148 'action' => 'edit',
149 ],
150 admin_url('post.php')
151 )
152 ),
153 'text' => esc_html(firebox()->_('FB_EDIT_FIREBOX')),
154 ];
155
156 $links[] = [
157 'url' => esc_url(
158 add_query_arg(
159 [
160 'post_type' => 'firebox',
161 ],
162 admin_url('edit.php')
163 )
164 ),
165 'text' => esc_html(firebox()->_('FB_VIEW_FIREBOX_ITEMS')),
166 ];
167
168 $content = '<div style="padding: 15px; background: #ededed;">';
169 $content .= '<p>';
170 $content .= esc_html(firebox()->_('FB_FIREBOX_PREVIEW_DESC'));
171 if (!empty($links))
172 {
173 $content .= '<br>';
174 foreach ($links as $key => $link)
175 {
176 $content .= '<a href="' . esc_url($link['url']) . '">' . esc_html($link['text']) . '</a>';
177 $l = array_keys($links);
178 if (end($l) !== $key)
179 {
180 $content .= ' <span style="display:inline-block;margin:0 6px;opacity: 0.5">|</span> ';
181 }
182 }
183 }
184 $content .= '</p>';
185 $content .= '</div>';
186
187 return $content;
188 }
189
190 /**
191 * Customize firebox popup preview page title.
192 *
193 * @param string $title
194 *
195 * @return string
196 */
197 public function the_title($title)
198 {
199 if (in_the_loop())
200 {
201 $title = sprintf(
202 esc_html('%s'),
203 ! empty($this->box_data->post_title) ? sanitize_text_field($this->box_data->post_title) . ' ' . firebox()->_('FB_PREVIEW') : esc_html(firebox()->_('FB_FIREBOX_POPUP_PREVIEW'))
204 );
205 }
206
207 return $title;
208 }
209 }