PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 2.1.39
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v2.1.39
3.1.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 All 123 releases
← All changes | Inc/Framework/Inc/Admin/Library/Library.php +261 -124 1.0.7 → 2.1.39 View file →
@@ -1,12 +1,12 @@
1 1 <?php
2 2 /**
3 3 * @package FirePlugins Framework
4 - * @version 1.0.16
4 + * @version 1.1.132
5 5 *
6 6 * @author FirePlugins <[email protected]>
7 7 * @link https://www.fireplugins.com
8 - * @copyright Copyright © 2021 FirePlugins All Rights Reserved
8 + * @copyright Copyright © 2025 FirePlugins All Rights Reserved
9 9 * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
10 10 */
11 11
12 12 namespace FPFramework\Admin\Library;
@@ -15,20 +15,104 @@
15 15 {
16 16 exit; // Exit if accessed directly.
17 17 }
18 18
19 -class Library extends Templates
19 +class Library
20 20 {
21 + use Favorites;
22 + use Templates;
23 +
24 + /**
25 + * Library item info popup.
26 + *
27 + * @var string
28 + */
29 + private $info_modal_id = 'fpf-library-item-info-popup';
30 +
31 + /**
32 + * Library preview popup.
33 + *
34 + * @var string
35 + */
36 + private $preview_modal_id = 'fpf-library-preview-popup';
37 +
38 + /**
39 + * The library settings
40 + *
41 + * @var array
42 + */
43 + protected $library_settings = [];
44 +
45 + public function __construct($library_settings = [])
46 + {
47 + $this->library_settings = $library_settings;
48 +
49 + $this->favorites_init();
50 + $this->templates_init();
51 + }
52 +
21 53 public function init()
22 54 {
23 - // enqueue media
55 + $this->prepare();
56 +
57 + // Enqueue media
24 58 add_action('admin_enqueue_scripts', [$this, 'register_media']);
25 59
26 - // add the library popup
27 - add_action('admin_footer', [$this, 'add_library_popup'], 12);
60 + $this->customizePopups();
61 + $this->addPopups();
28 62 }
29 63
30 64 /**
65 + * Prepares the Library.
66 + *
67 + * @return void
68 + */
69 + private function prepare()
70 + {
71 + $this->library_settings['preview_url'] = FPF_TEMPLATES_SITE_URL . '?template_preview_id=TEMPLATE_ID&plugin=' . $this->library_settings['plugin'];
72 + }
73 +
74 + /**
75 + * Setup ajax requests
76 + *
77 + * @return void
78 + *
79 + * @deprecated 1.1.0 Used only for backwards compatibility
80 + */
81 + public function setupAjax()
82 + {
83 + $this->templates_init();
84 + }
85 +
86 + /**
87 + * Customize popups sections.
88 + *
89 + * @return void
90 + */
91 + private function customizePopups()
92 + {
93 + // Main Templates Library Popup
94 + add_action('fpframework/modal/' . $this->library_settings['id'] . '/header/prepend_actions', [$this, 'templates_library_set_modal_actions']);
95 + add_action('fpframework/modal/' . $this->library_settings['id'] . '/header/middle', [$this, 'templates_library_set_modal_header_middle']);
96 +
97 + // Templates Library Preview
98 + add_action('fpframework/modal/' . $this->preview_modal_id . '/header/before_title', [$this, 'library_preview_before_title']);
99 + add_action('fpframework/modal/' . $this->preview_modal_id . '/header/middle', [$this, 'library_preview_header_middle']);
100 + }
101 +
102 + /**
103 + * Add required popups to the page.
104 + *
105 + * @return void
106 + */
107 + private function addPopups()
108 + {
109 + add_action('admin_footer', [$this, 'add_library_popup']);
110 + add_action('admin_footer', [$this, 'add_library_preview_template_popup']);
111 + add_action('admin_footer', [$this, 'add_library_item_info_popup']);
112 + }
113 +
114 + /**
31 115 * Adds admin media
32 116 *
33 117 * @return void
34 118 */
@@ -33,180 +117,233 @@
33 117 * @return void
34 118 */
35 119 public function register_media()
36 120 {
121 + // Templates Library CSS
122 + wp_enqueue_style(
123 + 'fpf-templates-library',
124 + FPF_MEDIA_URL . 'admin/css/fpf_templates_library.css',
125 + [],
126 + FPF_VERSION,
127 + false
128 + );
129 +
130 + // Templates Library JS
37 131 wp_enqueue_script(
38 - 'fpf-templates',
39 - FPF_MEDIA_URL . 'admin/js/fpf_templates.js',
132 + 'fpf-templates-library',
133 + FPF_MEDIA_URL . 'admin/js/fpf_templates_library.js',
40 134 [],
41 135 FPF_VERSION,
42 - false
136 + true
43 137 );
138 +
139 + $data = [
140 + 'plugin_name' => $this->library_settings['plugin_name'],
141 + 'pro' => fpframework()->_('FPF_PRO'),
142 + 'lite' => fpframework()->_('FPF_LITE'),
143 + 'wordpress' => fpframework()->_('FPF_WORDPRESS'),
144 + 'install_plugin' => fpframework()->_('FPF_INSTALL_PLUGIN'),
145 + 'activate_plugin' => fpframework()->_('FPF_ACTIVATE_PLUGIN'),
146 + 'update_plugin' => fpframework()->_('FPF_UPDATE_PLUGIN'),
147 + 'license_key' => fpframework()->_('FPF_LICENSE_KEY'),
148 + 'license' => isset($this->library_settings['license_key']) ? $this->library_settings['license_key'] : ''
149 + ];
150 + wp_localize_script('fpf-templates-library', 'fpf_templates_library_js_object', $data);
44 151 }
45 152
46 153 /**
47 - * Adds the popup at the footer of the page. Appears when you click the "New" / "Add New" button
154 + * Adds the popup at the footer of the page. Appears when you click the "New" / "Add New" button.
48 155 *
49 - * @param string $text
50 - *
51 156 * @return void
52 157 */
53 158 public function add_library_popup()
54 159 {
55 - // get library layout
56 - $content = fpframework()->renderer->admin->render('library/tmpl', $this->library_settings, true);
57 -
58 160 $payload = [
59 - 'id' => $this->modal_id,
161 + 'id' => $this->library_settings['id'],
60 162 'title' => $this->library_settings['title'],
61 - 'content' => $content,
163 + 'class' => ['fpf-templates-library'],
164 + 'overlay_click' => false,
165 + 'content' => fpframework()->renderer->admin->render('library/tmpl', $this->library_settings, true),
62 166 'width' => 70,
63 - 'height' => 70
167 + 'height' => 100
64 168 ];
65 169
66 - // render a modal with the library layout and return it
67 170 \FPFramework\Helpers\HTML::renderModal($payload);
68 171 }
69 172
70 173 /**
71 - * Setup ajax requests
174 + * Adds the popup at that allows us to preview a template.
72 175 *
73 176 * @return void
74 177 */
75 - public function setupAjax()
178 + public function add_library_preview_template_popup()
76 179 {
77 - // Get Templates Layout AJAX
78 - add_action('wp_ajax_fpf_library_get_templates', [$this, 'fpf_library_get_templates']);
180 + $payload = [
181 + 'id' => $this->preview_modal_id,
182 + 'class' => ['fpf-templates-library-popup-preview'],
183 + 'overlay_click' => false,
184 + 'content' => fpframework()->renderer->admin->render('library/preview', [], true),
185 + 'width' => 100,
186 + 'height' => 100
187 + ];
79 188
80 - // Refresh Templates from Remote and return Layout - AJAX
81 - add_action('wp_ajax_fpf_library_refresh_templates', [$this, 'fpf_library_refresh_templates']);
82 -
83 - // Favorites AJAX
84 - add_action('wp_ajax_fpf_library_favorites_toggle', [$this, 'fpf_library_favorites_toggle']);
189 + \FPFramework\Helpers\HTML::renderModal($payload);
85 190 }
86 191
87 192 /**
88 - * Checks whether we have the template locally and retrives its layout.
89 - * If no local template is found, then retrieves it from remote and returns its layout.
193 + * Adds the popup that displays the info for each template.
90 194 *
91 - * @return string
195 + * @return void
92 196 */
93 - public function fpf_library_get_templates()
197 + public function add_library_item_info_popup()
94 198 {
95 - if (!current_user_can('manage_options'))
96 - {
97 - return false;
98 - }
199 + $popup_payload = [
200 + 'category_label' => isset($this->library_settings['main_category_label']) ? $this->library_settings['main_category_label'] : '',
201 + 'plugin_name' => $this->library_settings['plugin_name']
202 + ];
99 203
100 - $nonce = isset($_POST['nonce']) ? sanitize_text_field($_POST['nonce']) : '';
204 + $payload = [
205 + 'id' => $this->info_modal_id,
206 + 'title' => 'Template Title Goes Here',
207 + 'class' => ['fpf-templates-library-item-info'],
208 + 'content' => fpframework()->renderer->admin->render('library/info_popup', $popup_payload, true),
209 + 'width' => '600px'
210 + ];
101 211
102 - // verify nonce
103 - if (!$verify = wp_verify_nonce($nonce, 'fpf_js_nonce'))
104 - {
105 - return false;
106 - }
212 + \FPFramework\Helpers\HTML::renderModal($payload);
213 + }
107 214
108 - $this->get_templates($this->getList());
215 + /**
216 + * Renders any other actions in the modal header.
217 + *
218 + * @return void
219 + */
220 + public function templates_library_set_modal_actions()
221 + {
222 + ?>
223 + <li>
224 + <a href="<?PHP echo esc_url($this->library_settings['create_new_template_link']); ?>" title="<?php echo esc_attr(fpframework()->_('FPF_START_FROM_SCRATCH')); ?>">
225 + <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
226 + <circle cx="12" cy="12" r="8" stroke="currentColor"/>
227 + <line x1="11.9277" y1="8.5" x2="11.9277" y2="15.5" stroke="currentColor" stroke-linecap="round"/>
228 + <line x1="15.5" y1="11.9285" x2="8.5" y2="11.9285" stroke="currentColor" stroke-linecap="round"/>
229 + </svg>
230 + </a>
231 + </li>
232 + <li>
233 + <a href="#" class="fpf-templates-refresh-btn" title="<?php echo esc_attr(fpframework()->_('FPF_REFRESH_TEMPLATES')); ?>">
234 + <svg class="checkmark" width="18" height="18" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 52">
235 + <circle class="checkmark__circle" cx="26" cy="26" r="25" fill="none" />
236 + <path class="checkmark__check" fill="none" d="M14.1 27.2l7.1 7.2 16.7-16.8" stroke-width="5" />
237 + </svg>
238 + <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
239 + <path d="M20 12C20 7.58172 16.4183 4 12 4C7.58172 4 4 7.58172 4 12C4 16.4183 7.58172 20 12 20C14.2879 20 16.3514 19.0396 17.8095 17.5" stroke="currentColor" stroke-linecap="round"/>
240 + <path class="tip" d="M22.25 9.99999L20 12.25L17.75 9.99999" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
241 + </svg>
242 + </a>
243 + </li>
244 + <li>
245 + <a href="<?php echo esc_url(FPF_SUPPORT_URL . '?topic=Feature Request'); ?>" title="<?php echo esc_attr(fpframework()->_('FPF_REQUEST_TEMPLATE')); ?>" target="_blank">
246 + <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
247 + <path d="M8.8 16H9.3C9.3 15.7239 9.07614 15.5 8.8 15.5V16ZM8.8 20H8.3C8.3 20.1905 8.40823 20.3644 8.57912 20.4486C8.75002 20.5327 8.95387 20.5125 9.10486 20.3963L8.8 20ZM13.7304 16.2074L14.0353 16.6037L13.7304 16.2074ZM5 4.5H19V3.5H5V4.5ZM19.5 5V15H20.5V5H19.5ZM4.5 15V5H3.5V15H4.5ZM8.8 15.5H5V16.5H8.8V15.5ZM9.3 20V16H8.3V20H9.3ZM19 15.5H14.3401V16.5H19V15.5ZM13.4256 15.8111L8.49514 19.6037L9.10486 20.3963L14.0353 16.6037L13.4256 15.8111ZM3.5 15C3.5 15.8284 4.17157 16.5 5 16.5V15.5C4.72386 15.5 4.5 15.2761 4.5 15H3.5ZM19.5 15C19.5 15.2761 19.2761 15.5 19 15.5V16.5C19.8284 16.5 20.5 15.8284 20.5 15H19.5ZM14.3401 15.5C14.0093 15.5 13.6878 15.6094 13.4256 15.8111L14.0353 16.6037C14.1227 16.5365 14.2299 16.5 14.3401 16.5V15.5ZM19 4.5C19.2761 4.5 19.5 4.72386 19.5 5H20.5C20.5 4.17157 19.8284 3.5 19 3.5V4.5ZM5 3.5C4.17157 3.5 3.5 4.17157 3.5 5H4.5C4.5 4.72386 4.72386 4.5 5 4.5V3.5Z" fill="currentColor"/>
248 + </svg>
249 + </a>
250 + </li>
251 + <li>
252 + <a href="#" class="fpf-templates-library-toggle-fullscreen">
253 + <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
254 + <path d="M9 2H14V7" stroke="currentColor" stroke-width="1"/>
255 + <path d="M7 14L2 14L2 9" stroke="currentColor" stroke-width="1"/>
256 + </svg>
257 + <svg class="on-fullscreen" width="16" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
258 + <path d="M14 5L9 5L9 3.97232e-08" stroke="currentColor" stroke-width="1"/>
259 + <path d="M0 9H5L5 14" stroke="currentColor" stroke-width="1"/>
260 + </svg>
261 + </a>
262 + </li>
263 + <?php
109 264 }
110 265
111 266 /**
112 - * Returns all available templates
267 + * Renders actions in the middle of the header.
268 + *
269 + * @return void
113 270 */
114 - private function get_templates($templates)
271 + public function templates_library_set_modal_header_middle()
115 272 {
116 - if (isset($templates->code) || \is_wp_error($templates))
273 + if (!isset($this->library_settings['plugin_license_type']))
117 274 {
118 - echo json_encode($templates);
119 - wp_die();
275 + return;
120 276 }
121 -
122 - $license_type = isset($this->library_settings['license_type']) ? $this->library_settings['license_type'] : 'free';
123 -
124 - $layouts = [];
125 -
126 - // main templates and favorites data
127 - $free_layouts_payload = [
128 - 'plugin' => $this->library_settings['plugin'],
129 - 'template_use_url' => $this->library_settings['template_use_url'],
130 - 'templates' => $templates,
131 - 'favorites' => $this->getFavorites()
132 - ];
133 - // Add the license type only if we are a free user, otherwise show all templates
134 - if ($license_type != 'pro')
277 +
278 + if ($this->library_settings['plugin_license_type'] === 'lite')
135 279 {
136 - $free_layouts_payload['license_type'] = 'free';
280 + ?>
281 + <a href="#" class="fpf-button outline red fpf-modal-opener" data-fpf-modal-item="<?php echo esc_attr(fpframework()->_('FPF_PRO_TEMPLATES')); ?>" data-fpf-modal="#fpfUpgradeToPro" data-fpf-plugin="<?php echo esc_attr($this->library_settings['plugin_name']); ?>">
282 + <svg class="icon" width="16" height="14" viewBox="0 0 16 14" fill="none" xmlns="http://www.w3.org/2000/svg">
283 + <path d="M7.5 10C7.5 10.2761 7.72386 10.5 8 10.5C8.27614 10.5 8.5 10.2761 8.5 10L7.5 10ZM8.35355 3.64645C8.15829 3.45118 7.84171 3.45118 7.64645 3.64645L4.46447 6.82843C4.2692 7.02369 4.2692 7.34027 4.46447 7.53553C4.65973 7.7308 4.97631 7.7308 5.17157 7.53553L8 4.70711L10.8284 7.53553C11.0237 7.7308 11.3403 7.7308 11.5355 7.53553C11.7308 7.34027 11.7308 7.02369 11.5355 6.82843L8.35355 3.64645ZM8.5 10L8.5 4L7.5 4L7.5 10L8.5 10Z" fill="currentColor"/>
284 + <path d="M14 7C14 10.3137 11.3137 13 8 13C4.68629 13 2 10.3137 2 7C2 3.68629 4.68629 1 8 1C11.3137 1 14 3.68629 14 7Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
285 + </svg>
286 + <?php echo esc_html(fpframework()->_('FPF_UPGRADE_TO_PRO')); ?>
287 + </a>
288 + <?php
137 289 }
138 - $layouts['main'] = fpframework()->renderer->admin->render('library/items_list', $free_layouts_payload, true);
139 -
140 - // If we are a free user, also load the pro templates separately
141 - if ($license_type == 'free')
142 - {
143 - // pro templates and favorites data
144 - $layouts['pro'] = fpframework()->renderer->admin->render('library/items_list', [
145 - 'plugin' => $this->library_settings['plugin'],
146 - 'template_use_url' => $this->library_settings['template_use_url'],
147 - 'templates' => $templates,
148 - 'favorites' => $this->getFavorites(),
149 - 'license_type' => 'pro'
150 - ], true);
151 - }
152 -
153 - echo json_encode($layouts);
154 - wp_die();
155 290 }
156 291
157 292 /**
158 - * Retrieve remote templates, store them locally and return new layout.
293 + * Adds back and refresh buttons to the Preview Library Item popup.
159 294 *
160 - * @return string
295 + * @return void
161 296 */
162 - public function fpf_library_refresh_templates()
297 + public function library_preview_before_title()
163 298 {
164 - if (!current_user_can('manage_options'))
165 - {
166 - return false;
167 - }
168 -
169 - $nonce = isset($_POST['nonce']) ? sanitize_text_field($_POST['nonce']) : '';
170 -
171 - // verify nonce
172 - if (!$verify = wp_verify_nonce($nonce, 'fpf_js_nonce'))
173 - {
174 - return false;
175 - }
176 -
177 - $this->get_templates($this->getRemoteTemplatesAndStore());
299 + ?>
300 + <a href="#" class="fpf-modal-close fpf-templates-library-preview-go-back">
301 + <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
302 + <path d="M16 4L8 12L16 20" stroke="currentColor" stroke-linecap="round"/>
303 + </svg>
304 + <div class="text"><?php echo esc_html(fpframework()->_('FPF_BACK')); ?></div>
305 + </a>
306 + <a href="#" class="fpf-templates-library-refresh-demo">
307 + <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
308 + <path d="M20 12C20 7.58172 16.4183 4 12 4C7.58172 4 4 7.58172 4 12C4 16.4183 7.58172 20 12 20C14.2879 20 16.3514 19.0396 17.8095 17.5" stroke="currentColor" stroke-linecap="round"/>
309 + <path d="M22.25 9.99999L20 12.25L17.75 9.99999" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
310 + </svg>
311 + </a>
312 + <?php
178 313 }
179 314
180 315 /**
181 - * Handles AJAX Library favorite toggle
316 + * Adds responsive devices to Preview Library Item popup.
182 317 *
183 - * @return string
318 + * @return void
184 319 */
185 - public function fpf_library_favorites_toggle()
320 + public function library_preview_header_middle()
186 321 {
187 - if (!current_user_can('manage_options'))
188 - {
189 - return false;
190 - }
191 -
192 - $nonce = isset($_POST['nonce']) ? sanitize_text_field($_POST['nonce']) : '';
193 -
194 - // verify nonce
195 - if (!$verify = wp_verify_nonce($nonce, 'fpf_js_nonce'))
196 - {
197 - return false;
198 - }
199 -
200 - $template_id = isset($_POST['template_id']) ? sanitize_text_field($_POST['template_id']) : '';
322 + ?>
323 + <div class="fpf-templates-library-preview-responsive-devices">
324 + <svg class="fpf-templates-library-preview-responsive-device active" data-device="desktop" width="35" height="24" viewBox="0 0 35 24" fill="none" xmlns="http://www.w3.org/2000/svg">
325 + <rect x="1" y="1" width="33" height="19" rx="2" stroke="currentColor" stroke-width="2"/>
326 + <path d="M16 21.5V21C16 20.4477 16.4477 20 17 20H19C19.5523 20 20 20.4477 20 21V21.5C20 22.0523 20.4477 22.5 21 22.5H23.25C23.6642 22.5 24 22.8358 24 23.25C24 23.6642 23.6642 24 23.25 24H12.75C12.3358 24 12 23.6642 12 23.25C12 22.8358 12.3358 22.5 12.75 22.5H15C15.5523 22.5 16 22.0523 16 21.5Z" fill="currentColor"/>
327 + </svg>
328 + <svg class="fpf-templates-library-preview-responsive-device" data-device="tablet" width="19" height="24" viewBox="0 0 19 24" fill="none" xmlns="http://www.w3.org/2000/svg">
329 + <rect x="1" y="1" width="17" height="22" rx="2" stroke="currentColor" stroke-width="2"/>
330 + <circle cx="9.5" cy="19.5" r="1.5" fill="currentColor"/>
331 + </svg>
332 + <svg class="fpf-templates-library-preview-responsive-device" data-device="mobile" width="15" height="24" viewBox="0 0 15 24" fill="none" xmlns="http://www.w3.org/2000/svg">
333 + <rect x="1" y="1" width="13" height="22" rx="2" stroke="currentColor" stroke-width="2"/>
334 + <line x1="5" y1="2" x2="10" y2="2" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
335 + </svg>
336 + </div>
337 + <?php
338 + }
201 339
202 - if (empty($template_id))
203 - {
204 - return false;
205 - }
206 -
207 - $this->addOrRemoveFavorite($template_id);
208 -
209 - echo json_encode($this->getFavorites());
210 - wp_die();
211 - }
340 + /**
341 + * Return templates folder path
342 + *
343 + * @return string
344 + */
345 + protected function getTemplatesPath()
346 + {
347 + return \FPFramework\Helpers\WPHelper::getPluginUploadsDirectory($this->library_settings['plugin'], 'templates');
348 + }
212 349 }