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

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