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

202 lines 3.9 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.8 Free
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2021 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 assignments
107 $this->box_data->params->remove('assignments');
108 // Enable Test Mode to prevent cookies
109 $this->box_data->params->set('testmode', true);
110 // Disable Statistics to prevent impressions from being tracked into the database
111 $this->box_data->params->set('stats', 0);
112
113 firebox()->box->render($this->box_data);
114
115 \add_filter('the_title', [$this, 'the_title'], 100, 1);
116
117 \add_filter('the_content', [$this, 'the_content'], 999);
118
119 \add_filter('get_the_excerpt', [$this, 'the_content'], 999);
120 }
121
122 public function the_content()
123 {
124 if (!isset($this->box_data->ID))
125 {
126 return '';
127 }
128
129 if (!current_user_can('manage_options'))
130 {
131 return '';
132 }
133
134 $links = [];
135
136 $links[] = [
137 'url' => esc_url(
138 add_query_arg(
139 [
140 'post' => absint($this->box_data->ID),
141 'action' => 'edit',
142 ],
143 admin_url('post.php')
144 )
145 ),
146 'text' => esc_html(firebox()->_('FB_EDIT_FIREBOX')),
147 ];
148
149 $links[] = [
150 'url' => esc_url(
151 add_query_arg(
152 [
153 'post_type' => 'firebox',
154 ],
155 admin_url('edit.php')
156 )
157 ),
158 'text' => esc_html(firebox()->_('FB_VIEW_FIREBOX_ITEMS')),
159 ];
160
161 $content = '<div style="padding: 15px; background: #ededed;">';
162 $content .= '<p>';
163 $content .= esc_html(firebox()->_('FB_FIREBOX_PREVIEW_DESC'));
164 if (!empty($links))
165 {
166 $content .= '<br>';
167 foreach ($links as $key => $link)
168 {
169 $content .= '<a href="' . esc_url($link['url']) . '">' . esc_html($link['text']) . '</a>';
170 $l = array_keys($links);
171 if (end($l) !== $key)
172 {
173 $content .= ' <span style="display:inline-block;margin:0 6px;opacity: 0.5">|</span> ';
174 }
175 }
176 }
177 $content .= '</p>';
178 $content .= '</div>';
179
180 return $content;
181 }
182
183 /**
184 * Customize firebox popup preview page title.
185 *
186 * @param string $title
187 *
188 * @return string
189 */
190 public function the_title($title)
191 {
192 if (in_the_loop())
193 {
194 $title = sprintf(
195 esc_html('%s'),
196 ! empty($this->box_data->post_title) ? sanitize_text_field($this->box_data->post_title) . ' ' . firebox()->_('FB_PREVIEW') : esc_html(firebox()->_('FB_FIREBOX_POPUP_PREVIEW'))
197 );
198 }
199
200 return $title;
201 }
202 }