PluginProbe
Boxzilla – WordPress Popup Builder / 3.4.0
Boxzilla – WordPress Popup Builder v3.4.0
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 +84 -72 3.1.103.4.0 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
@@ -58,9 +59,9 @@
58 59 // store content in property
59 60 $this->content = $post->post_content;
60 61
61 62 // is this box enabled?
62 - $this->enabled = ( $post->post_status === 'publish' );
63 + $this->enabled = $post->post_status === 'publish';
63 64
64 65 // load and store options in property
65 66 $this->options = $this->load_options();
66 67 }
@@ -70,41 +71,44 @@
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 - 'hide_on_screen_size' => '',
104 - 'closable' => true,
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,
105 109 );
106 - $box = $this;
110 + $box = $this;
107 111
108 112 $options = get_post_meta( $this->ID, 'boxzilla_options', true );
109 113 $options = is_array( $options ) ? $options : array();
110 114
@@ -144,10 +148,13 @@
144 148 *
145 149 * @return string
146 150 */
147 151 public function get_close_icon() {
152 + if ( ! $this->options['show_close_icon'] ) {
153 + return '';
154 + }
148 155
149 - $box = $this;
156 + $box = $this;
150 157 $html = '×';
151 158
152 159 /**
153 160 * Filters the HTML for the close icon.
@@ -162,14 +169,26 @@
162 169
163 170 /**
164 171 * Get the content of this box
165 172 *
166 - * @return mixed|void
173 + * @return string
167 174 */
168 175 public function get_content() {
169 176 $content = $this->content;
170 - $box = $this;
177 + $box = $this;
171 178
179 + // replace boxzilla specific shortcodes
180 + $close_link = "<a href=\"javascript:Boxzilla.dismiss({$this->ID});\">";
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 + );
188 +
189 + $content = str_replace( array_keys( $replacements ), array_values( $replacements ), $content );
190 +
172 191 /**
173 192 * Filters the HTML for the box content
174 193 *
175 194 * @param string $content
@@ -179,62 +198,56 @@
179 198 return $content;
180 199 }
181 200
182 201 /**
183 - * Get the minimum allowed screen size for this box
202 + * Get options object for JS script.
184 203 *
185 - * @return int
204 + * @return array
186 205 */
187 - public function get_minimum_screen_size() {
188 -
189 - if( $this->options['hide_on_screen_size'] > 0 ) {
190 - $minimum_screen_size = absint( $this->options['hide_on_screen_size'] );
191 - } else {
192 - $minimum_screen_size = 0;
193 - }
194 -
195 - return $minimum_screen_size;
196 - }
197 -
198 - /**
199 - * Get options object for JS script.
200 - *
201 - * @return array
202 - */
203 206 public function get_client_options() {
204 207 $box = $this;
205 208
206 209 $trigger = false;
207 - if( $box->options['trigger'] ) {
210 + if ( $box->options['trigger'] ) {
208 211 $trigger = array(
209 - 'method' => $this->options['trigger']
210 - );
212 + 'method' => $this->options['trigger'],
213 + );
211 214
212 - if( isset( $this->options[ 'trigger_' . $this->options['trigger'] ] ) ) {
215 + if ( isset( $this->options[ 'trigger_' . $this->options['trigger'] ] ) ) {
213 216 $trigger['value'] = $this->options[ 'trigger_' . $this->options['trigger'] ];
214 217 }
215 218 }
216 219
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 + }
228 +
229 + $post = $this->post;
217 230 $client_options = array(
218 - 'id' => $box->ID,
219 - 'icon' => $box->get_close_icon(),
220 - 'content' => $box->get_content(),
221 - 'css' => array_filter( $box->options['css'] ),
222 - 'trigger' => $trigger,
223 - 'animation' => $box->options['animation'],
224 - 'cookie' => array(
231 + 'id' => $box->ID,
232 + 'icon' => $box->get_close_icon(),
233 + 'content' => '', // we grab this later from an HTML element
234 + 'css' => array_filter( $box->options['css'] ),
235 + 'trigger' => $trigger,
236 + 'animation' => $box->options['animation'],
237 + 'cookie' => array(
225 238 'triggered' => absint( $box->options['cookie']['triggered'] ),
226 239 'dismissed' => absint( $box->options['cookie']['dismissed'] ),
227 240 ),
228 - 'rehide' => (bool) $box->options['auto_hide'],
229 - 'position' => $box->options['css']['position'],
230 - 'minimumScreenWidth' => $box->get_minimum_screen_size(),
231 - 'closable' => $box->options['closable'],
232 - 'post' => array(
233 - 'id' => $this->post->ID,
234 - 'title' => $this->post->post_title,
235 - 'slug' => $this->post->post_name,
236 - ),
241 + 'rehide' => (bool) $box->options['auto_hide'],
242 + 'position' => $box->options['css']['position'],
243 + 'screenWidthCondition' => $screen_width_condition,
244 + 'closable' => ! ! $box->options['closable'],
245 + 'post' => array(
246 + 'id' => $post->ID,
247 + 'title' => $post->post_title,
248 + 'slug' => $post->post_name,
249 + ),
237 250 );
238 251
239 252 /**
240 253 * Filter the final options for the JS Boxzilla client.
@@ -245,6 +258,5 @@
245 258 $client_options = apply_filters( 'boxzilla_box_client_options', $client_options, $box );
246 259
247 260 return $client_options;
248 261 }
249 -
250 -}
262 +}