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

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