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 +79 -76 3.1.163.2.18 View file →
@@ -5,8 +5,9 @@
5 5 use WP_Post;
6 6
7 7 class Box {
8 8
9 +
9 10 /**
10 11 * @var int
11 12 */
12 13 public $ID;
@@ -30,12 +31,12 @@
30 31 * @var bool
31 32 */
32 33 public $enabled = false;
33 34
34 - /**
35 - * @var WP_Post
36 - */
37 - private $post;
35 + /**
36 + * @var WP_Post
37 + */
38 + private $post;
38 39
39 40 /**
40 41 * @param WP_Post|int $post
41 42 */
@@ -41,9 +42,9 @@
41 42 */
42 43 public function __construct( $post ) {
43 44
44 45 // fetch post if it hasn't been fetched yet
45 - if( ! $post instanceof WP_Post ) {
46 + if ( ! $post instanceof WP_Post ) {
46 47 $post = get_post( $post );
47 48 }
48 49
49 50 // store ref to post
@@ -70,50 +71,48 @@
70 71 **
71 72 * @return array Array of box options
72 73 */
73 74 protected function load_options() {
74 -
75 - static $defaults = array(
76 - 'css' => array(
75 + $defaults = array(
76 + 'css' => array(
77 77 'background_color' => '',
78 - 'color' => '',
79 - 'width' => '',
80 - 'border_color' => '',
81 - 'border_width' => '',
82 - 'border_style' => '',
83 - 'position' => 'bottom-right',
78 + 'color' => '',
79 + 'width' => '',
80 + 'border_color' => '',
81 + 'border_width' => '',
82 + 'border_style' => '',
83 + 'position' => 'bottom-right',
84 84 ),
85 - 'rules' => array(
85 + 'rules' => array(
86 86 0 => array(
87 87 'condition' => '',
88 - 'value' => '',
88 + 'value' => '',
89 89 ),
90 90 ),
91 - 'rules_comparision' => 'any',
92 - 'cookie' => array(
91 + 'rules_comparision' => 'any',
92 + 'cookie' => array(
93 93 'triggered' => 0,
94 94 'dismissed' => 0,
95 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,
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 109 );
110 - $box = $this;
110 + $box = $this;
111 111
112 112 $options = get_post_meta( $this->ID, 'boxzilla_options', true );
113 113 $options = is_array( $options ) ? $options : array();
114 114
115 -
116 115 // merge options with default options
117 116 $options = array_replace_recursive( $defaults, $options );
118 117
119 118 // allow others to filter the final array of options
@@ -149,14 +148,13 @@
149 148 *
150 149 * @return string
151 150 */
152 151 public function get_close_icon() {
152 + if ( ! $this->options['show_close_icon'] ) {
153 + return '';
154 + }
153 155
154 - if( ! $this->options['show_close_icon'] ) {
155 - return '';
156 - }
157 -
158 - $box = $this;
156 + $box = $this;
159 157 $html = '×';
160 158
161 159 /**
162 160 * Filters the HTML for the close icon.
@@ -175,17 +173,23 @@
175 173 * @return string
176 174 */
177 175 public function get_content() {
178 176 $content = $this->content;
179 - $box = $this;
177 + $box = $this;
180 178
181 179 // replace boxzilla specific shortcodes
182 - $close_link = sprintf('<a href="javascript:Boxzilla.dismiss(%d);">', $this->ID );
183 - $content = str_replace( '[boxzilla-close]', $close_link, $content );
184 - $content = str_replace( '[/boxzilla-close]', '</a>', $content );
180 + $close_link = sprintf( '<a href="javascript:Boxzilla.dismiss(%d);">', $this->ID );
185 181
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 + );
186 188
187 - /**
189 + $content = str_replace( array_keys( $replacements ), array_values( $replacements ), $content );
190 +
191 + /**
188 192 * Filters the HTML for the box content
189 193 *
190 194 * @param string $content
191 195 * @param Box $box
@@ -193,23 +197,23 @@
193 197 $content = apply_filters( 'boxzilla_box_content', $content, $box );
194 198 return $content;
195 199 }
196 200
197 - /**
198 - * Get options object for JS script.
199 - *
200 - * @return array
201 - */
201 + /**
202 + * Get options object for JS script.
203 + *
204 + * @return array
205 + */
202 206 public function get_client_options() {
203 207 $box = $this;
204 208
205 209 $trigger = false;
206 - if( $box->options['trigger'] ) {
210 + if ( $box->options['trigger'] ) {
207 211 $trigger = array(
208 - 'method' => $this->options['trigger']
209 - );
212 + 'method' => $this->options['trigger'],
213 + );
210 214
211 - if( isset( $this->options[ 'trigger_' . $this->options['trigger'] ] ) ) {
215 + if ( isset( $this->options[ 'trigger_' . $this->options['trigger'] ] ) ) {
212 216 $trigger['value'] = $this->options[ 'trigger_' . $this->options['trigger'] ];
213 217 }
214 218 }
215 219
@@ -214,35 +218,35 @@
214 218 }
215 219
216 220 // build screenWidthCondition object (or null)
217 221 $screen_width_condition = null;
218 - if( $box->options['screen_size_condition']['value'] > 0 ) {
219 - $screen_width_condition = array(
220 - 'condition' => $box->options['screen_size_condition']['condition'],
221 - 'value' => intval( $box->options['screen_size_condition']['value'] ),
222 - );
223 - }
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 + }
224 228
225 229 $client_options = array(
226 - 'id' => $box->ID,
227 - 'icon' => $box->get_close_icon(),
228 - 'content' => $box->get_content(),
229 - 'css' => array_filter( $box->options['css'] ),
230 - 'trigger' => $trigger,
231 - 'animation' => $box->options['animation'],
232 - 'cookie' => 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(
233 237 'triggered' => absint( $box->options['cookie']['triggered'] ),
234 238 'dismissed' => absint( $box->options['cookie']['dismissed'] ),
235 239 ),
236 - 'rehide' => (bool) $box->options['auto_hide'],
237 - 'position' => $box->options['css']['position'],
238 - 'screenWidthCondition' => $screen_width_condition,
239 - 'closable' => !!$box->options['closable'],
240 - 'post' => array(
241 - 'id' => $this->post->ID,
242 - 'title' => $this->post->post_title,
243 - 'slug' => $this->post->post_name,
244 - ),
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 + ),
245 249 );
246 250
247 251 /**
248 252 * Filter the final options for the JS Boxzilla client.
@@ -253,6 +257,5 @@
253 257 $client_options = apply_filters( 'boxzilla_box_client_options', $client_options, $box );
254 258
255 259 return $client_options;
256 260 }
257 -
258 -}
261 +}