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