PluginProbe
Boxzilla – WordPress Popup Builder / 3.1.3
Boxzilla – WordPress Popup Builder v3.1.3
3.4.11 3.4.10 3.4.9 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 trunk 3.0 3.0.1 3.0.2 3.0.3 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 All 72 releases
← All changes | src/class-box.php +189 -226 3.4.33.1.3 View file →
@@ -3,266 +3,229 @@
3 3 namespace Boxzilla;
4 4
5 5 use WP_Post;
6 6
7 -class Box
8 -{
9 - /**
10 - * @var int
11 - */
12 - public $ID;
7 +class Box {
13 8
14 - /**
15 - * @var array
16 - */
17 - public $options = [];
9 + /**
10 + * @var int
11 + */
12 + public $ID;
18 13
19 - /**
20 - * @var string
21 - */
22 - public $title = '';
14 + /**
15 + * @var array
16 + */
17 + public $options = array();
23 18
24 - /**
25 - * @var string
26 - */
27 - protected $content = '';
19 + /**
20 + * @var string
21 + */
22 + public $title = '';
28 23
29 - /**
30 - * @var bool
31 - */
32 - public $enabled = false;
24 + /**
25 + * @var string
26 + */
27 + protected $content = '';
33 28
34 - /**
35 - * @var WP_Post
36 - */
37 - private $post;
29 + /**
30 + * @var bool
31 + */
32 + public $enabled = false;
38 33
39 - /**
40 - * @param WP_Post|int $post
41 - */
42 - public function __construct($post)
43 - {
34 + /**
35 + * @param WP_Post|int $post
36 + */
37 + public function __construct( $post ) {
44 38
45 - // fetch post if it hasn't been fetched yet
46 - if (! $post instanceof WP_Post) {
47 - $post = get_post($post);
48 - }
39 + // fetch post if it hasn't been fetched yet
40 + if( ! $post instanceof WP_Post ) {
41 + $post = get_post( $post );
42 + }
49 43
50 - // store ref to post
51 - $this->post = $post;
44 + // store ID in property for quick access
45 + $this->ID = $post->ID;
52 46
53 - // store ID in property for quick access
54 - $this->ID = $post->ID;
47 + // store title in property
48 + $this->title = $post->post_title;
55 49
56 - // store title in property
57 - $this->title = $post->post_title;
50 + // store content in property
51 + $this->content = $post->post_content;
58 52
59 - // store content in property
60 - $this->content = $post->post_content;
53 + // is this box enabled?
54 + $this->enabled = ( $post->post_status === 'publish' );
61 55
62 - // is this box enabled?
63 - $this->enabled = $post->post_status === 'publish';
56 + // load and store options in property
57 + $this->options = $this->load_options();
58 + }
64 59
65 - // load and store options in property
66 - $this->options = $this->load_options();
67 - }
60 + /**
61 + * Get the options for this box.
62 + **
63 + * @return array Array of box options
64 + */
65 + protected function load_options() {
68 66
69 - /**
70 - * Get the options for this box.
71 - **
72 - * @return array Array of box options
73 - */
74 - protected function load_options()
75 - {
76 - $defaults = [
77 - 'css' => [
78 - 'background_color' => '',
79 - 'color' => '',
80 - 'width' => '',
81 - 'border_color' => '',
82 - 'border_width' => '',
83 - 'border_style' => '',
84 - 'position' => 'bottom-right',
85 - ],
86 - 'rules' => [
87 - 0 => [
88 - 'condition' => '',
89 - 'value' => '',
90 - ],
91 - ],
92 - 'rules_comparision' => 'any',
93 - 'cookie' => [
94 - 'triggered' => 0,
95 - 'dismissed' => 0,
96 - ],
97 - 'trigger' => 'percentage',
98 - 'trigger_percentage' => 65,
99 - 'trigger_element' => '',
100 - 'trigger_time_on_site' => 0,
101 - 'trigger_time_on_page' => 0,
102 - 'animation' => 'fade',
103 - 'auto_hide' => 0,
104 - 'screen_size_condition' => [
105 - 'condition' => 'larger',
106 - 'value' => 0,
107 - ],
108 - 'closable' => 1,
109 - 'show_close_icon' => 1,
110 - ];
111 - $box = $this;
67 + static $defaults = array(
68 + 'css' => array(
69 + 'background_color' => '',
70 + 'color' => '',
71 + 'width' => '',
72 + 'border_color' => '',
73 + 'border_width' => '',
74 + 'border_style' => '',
75 + 'position' => 'bottom-right',
76 + ),
77 + 'rules' => array(
78 + 0 => array(
79 + 'condition' => '',
80 + 'value' => '',
81 + ),
82 + ),
83 + 'rules_comparision' => 'any',
84 + 'cookie' => array(
85 + 'triggered' => 0,
86 + 'dismissed' => 0,
87 + ),
88 + 'trigger' => 'percentage',
89 + 'trigger_percentage' => 65,
90 + 'trigger_element' => '',
91 + 'trigger_time_on_site' => 0,
92 + 'trigger_time_on_page' => 0,
93 + 'animation' => 'fade',
94 + 'auto_hide' => 0,
95 + 'hide_on_screen_size' => '',
96 + 'closable' => true,
97 + );
98 + $box = $this;
112 99
113 - $options = get_post_meta($this->ID, 'boxzilla_options', true);
114 - $options = is_array($options) ? $options : [];
100 + $options = get_post_meta( $this->ID, 'boxzilla_options', true );
101 + $options = is_array( $options ) ? $options : array();
115 102
116 - // merge options with default options
117 - $options = array_replace_recursive($defaults, $options);
103 + // merge options with default options
104 + $options = array_replace_recursive( $defaults, $options );
118 105
119 - // allow others to filter the final array of options
120 - /**
121 - * Filter the options for a given box
122 - *
123 - * @param array $options
124 - * @param Box $box
125 - */
126 - $options = apply_filters('boxzilla_box_options', $options, $box);
106 + // allow others to filter the final array of options
107 + /**
108 + * Filter the options for a given box
109 + *
110 + * @param array $options
111 + * @param Box $box
112 + */
113 + $options = apply_filters( 'boxzilla_box_options', $options, $box );
127 114
128 - return $options;
129 - }
115 + return $options;
116 + }
130 117
131 - /**
132 - * @return bool
133 - */
134 - public function is_enabled()
135 - {
136 - return $this->enabled;
137 - }
118 + /**
119 + * @return bool
120 + */
121 + public function is_enabled() {
122 + return $this->enabled;
123 + }
138 124
139 - /**
140 - * Get the options for this box
141 - *
142 - * @return array
143 - */
144 - public function get_options()
145 - {
146 - return $this->options;
147 - }
125 + /**
126 + * Get the options for this box
127 + *
128 + * @return array
129 + */
130 + public function get_options() {
131 + return $this->options;
132 + }
148 133
149 - /**
150 - * Get the close / hide icon for this box
151 - *
152 - * @return string
153 - */
154 - public function get_close_icon()
155 - {
156 - if (! $this->options['show_close_icon']) {
157 - return '';
158 - }
134 + /**
135 + * Get the close / hide icon for this box
136 + *
137 + * @return string
138 + */
139 + public function get_close_icon() {
159 140
160 - $box = $this;
161 - $html = '×';
141 + $box = $this;
142 + $html = '×';
162 143
163 - /**
164 - * Filters the HTML for the close icon.
165 - *
166 - * @param string $html
167 - * @param Box $box
168 - */
169 - $close_icon = (string) apply_filters('boxzilla_box_close_icon', $html, $box);
144 + /**
145 + * Filters the HTML for the close icon.
146 + *
147 + * @param string $html
148 + * @param Box $box
149 + */
150 + $close_icon = (string) apply_filters( 'boxzilla_box_close_icon', $html, $box );
170 151
171 - return $close_icon;
172 - }
152 + return $close_icon;
153 + }
173 154
174 - /**
175 - * Get the content of this box
176 - *
177 - * @return string
178 - */
179 - public function get_content()
180 - {
181 - $content = $this->content;
182 - $box = $this;
155 + /**
156 + * Get the content of this box
157 + *
158 + * @return mixed|void
159 + */
160 + public function get_content() {
161 + $content = $this->content;
162 + $box = $this;
183 163
184 - // replace boxzilla specific shortcodes
185 - $close_link = "<a href=\"javascript:Boxzilla.dismiss({$this->ID});\">";
164 + /**
165 + * Filters the HTML for the box content
166 + *
167 + * @param string $content
168 + * @param Box $box
169 + */
170 + $content = apply_filters( 'boxzilla_box_content', $content, $box );
171 + return $content;
172 + }
186 173
187 - $replacements = [
188 - '[boxzilla_close]' => $close_link, // accept underscore and dash here for consistency with other shortcode
189 - '[boxzilla-close]' => $close_link,
190 - '[/boxzilla_close]' => '</a>',
191 - '[/boxzilla-close]' => '</a>',
192 - ];
174 + /**
175 + * Get the minimum allowed screen size for this box
176 + *
177 + * @return int
178 + */
179 + public function get_minimum_screen_size() {
193 180
194 - $content = str_replace(array_keys($replacements), array_values($replacements), $content);
181 + if( $this->options['hide_on_screen_size'] > 0 ) {
182 + $minimum_screen_size = absint( $this->options['hide_on_screen_size'] );
183 + } else {
184 + $minimum_screen_size = 0;
185 + }
195 186
196 - /**
197 - * Filters the HTML for the box content
198 - *
199 - * @param string $content
200 - * @param Box $box
201 - */
202 - $content = apply_filters('boxzilla_box_content', $content, $box);
203 - return $content;
204 - }
187 + return $minimum_screen_size;
188 + }
205 189
206 - /**
207 - * Get options object for JS script.
208 - *
209 - * @return array
210 - */
211 - public function get_client_options()
212 - {
213 - $box = $this;
190 + public function get_client_options() {
191 + $box = $this;
214 192
215 - $trigger = false;
216 - if ($box->options['trigger']) {
217 - $trigger = [
218 - 'method' => $this->options['trigger'],
219 - ];
193 + $trigger = false;
194 + if( $box->options['trigger'] ) {
220 195
221 - if (isset($this->options[ 'trigger_' . $this->options['trigger'] ])) {
222 - $trigger['value'] = $this->options[ 'trigger_' . $this->options['trigger'] ];
223 - }
224 - }
196 + $trigger = array( 'method' => $this->options['trigger'] );
225 197
226 - // build screenWidthCondition object (or null)
227 - $screen_width_condition = null;
228 - if ($box->options['screen_size_condition']['value'] > 0) {
229 - $screen_width_condition = [
230 - 'condition' => $box->options['screen_size_condition']['condition'],
231 - 'value' => intval($box->options['screen_size_condition']['value']),
232 - ];
233 - }
198 + if( isset( $this->options[ 'trigger_' . $this->options['trigger'] ] ) ) {
199 + $trigger['value'] = $this->options[ 'trigger_' . $this->options['trigger'] ];
200 + }
201 + }
234 202
235 - $post = $this->post;
236 - $client_options = [
237 - 'id' => $box->ID,
238 - 'icon' => $box->get_close_icon(),
239 - 'content' => '', // we grab this later from an HTML element
240 - 'css' => array_filter($box->options['css']),
241 - 'trigger' => $trigger,
242 - 'animation' => $box->options['animation'],
243 - 'cookie' => [
244 - 'triggered' => absint($box->options['cookie']['triggered']),
245 - 'dismissed' => absint($box->options['cookie']['dismissed']),
246 - ],
247 - 'rehide' => (bool) $box->options['auto_hide'],
248 - 'position' => $box->options['css']['position'],
249 - 'screenWidthCondition' => $screen_width_condition,
250 - 'closable' => ! ! $box->options['closable'],
251 - 'post' => [
252 - 'id' => $post->ID,
253 - 'title' => $post->post_title,
254 - 'slug' => $post->post_name,
255 - ],
256 - ];
203 + $client_options = array(
204 + 'id' => $box->ID,
205 + 'icon' => $box->get_close_icon(),
206 + 'content' => $box->get_content(),
207 + 'css' => array_filter( $box->options['css'] ),
208 + 'trigger' => $trigger,
209 + 'animation' => $box->options['animation'],
210 + 'cookie' => array(
211 + 'triggered' => absint( $box->options['cookie']['triggered'] ),
212 + 'dismissed' => absint( $box->options['cookie']['dismissed'] ),
213 + ),
214 + 'rehide' => (bool) $box->options['auto_hide'],
215 + 'position' => $box->options['css']['position'],
216 + 'minimumScreenWidth' => $box->get_minimum_screen_size(),
217 + 'closable' => $box->options['closable'],
218 + );
257 219
258 - /**
259 - * Filter the final options for the JS Boxzilla client.
260 - *
261 - * @param array $client_options
262 - * @param Box $box
263 - */
264 - $client_options = apply_filters('boxzilla_box_client_options', $client_options, $box);
220 + /**
221 + * Filter the final options for the JS Boxzilla client.
222 + *
223 + * @param array $client_options
224 + * @param Box $box
225 + */
226 + $client_options = apply_filters( 'boxzilla_box_client_options', $client_options, $box );
265 227
266 - return $client_options;
267 - }
268 -}
228 + return $client_options;
229 + }
230 +
231 +}