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

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