PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 1.0.7
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v1.0.7
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 / FB / Boxes.php

Boxes.php in FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment 1.0.7, at Inc/Core/FB/Boxes.php

140 lines 2.4 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.7 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\FB;
13
14 if (!defined('ABSPATH'))
15 {
16 exit; // Exit if accessed directly.
17 }
18
19 use FPFramework\Libs\Registry;
20 use FireBox\Core\Helpers\BoxHelper;
21
22 class Boxes
23 {
24 /**
25 * A box instance
26 *
27 * @var Box
28 */
29 protected $box;
30
31 /**
32 * Factory
33 *
34 * @var Factory
35 */
36 protected $factory;
37
38 public function __construct($box = null, $factory = null)
39 {
40 if (!$factory)
41 {
42 $factory = new \FPFramework\Base\Factory();
43 }
44 $this->factory = $factory;
45 }
46
47 /**
48 * Render boxes
49 *
50 * @return string
51 */
52 public function render()
53 {
54 if (!$boxes_query = BoxHelper::getAllBoxesWPQuery())
55 {
56 return;
57 }
58
59 if (!method_exists($boxes_query, 'have_posts') || (method_exists($boxes_query, 'have_posts') && !$boxes_query->have_posts()))
60 {
61 return;
62 }
63
64 return $this->renderAll($boxes_query);
65 }
66
67 /**
68 * Renders all boxes
69 *
70 * @param array $boxes
71 *
72 * @return string
73 */
74 public function renderAll($boxes)
75 {
76 $html = '';
77
78 // handle WP_Query boxes loop
79 if (isset($boxes->posts))
80 {
81 foreach ($boxes->posts as $box)
82 {
83 $boxes->the_post();
84
85 $this->prepare($box);
86
87 $html .= $this->get_output($box);
88 }
89 wp_reset_query();
90 }
91 else
92 // handle boxes array
93 {
94 foreach ($boxes as $box)
95 {
96 $this->prepare($box);
97
98 $html .= $this->get_output($box);
99 }
100 }
101
102 return $html;
103 }
104
105 /**
106 * Prepares the box by setting its meta settings.
107 *
108 * @param object $box
109 *
110 * @return void
111 */
112 private function prepare(&$box)
113 {
114 // get meta options for box
115 $meta = get_post_meta($box->ID, 'fpframework_meta_settings', true);
116 $box->params = new Registry($meta);
117 }
118
119 /**
120 * Returns the box output
121 *
122 * @param object $box
123 *
124 * @return string
125 */
126 private function get_output($box)
127 {
128 $logged_and_admin = (is_user_logged_in() && current_user_can('manage_options'));
129
130 $testmode = $box->params->get('testmode', false);
131
132 // if box is in test mode only logged-in admin users can see it.
133 if ($testmode == '1' && !$logged_and_admin)
134 {
135 return '';
136 }
137
138 return firebox()->box->render($box);
139 }
140 }