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 +89 -58 3.13.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;
@@ -31,17 +32,25 @@
31 32 */
32 33 public $enabled = false;
33 34
34 35 /**
36 + * @var WP_Post
37 + */
38 + private $post;
39 +
40 + /**
35 41 * @param WP_Post|int $post
36 42 */
37 43 public function __construct( $post ) {
38 44
39 45 // fetch post if it hasn't been fetched yet
40 - if( ! $post instanceof WP_Post ) {
46 + if ( ! $post instanceof WP_Post ) {
41 47 $post = get_post( $post );
42 48 }
43 49
50 + // store ref to post
51 + $this->post = $post;
52 +
44 53 // store ID in property for quick access
45 54 $this->ID = $post->ID;
46 55
47 56 // store title in property
@@ -50,9 +59,9 @@
50 59 // store content in property
51 60 $this->content = $post->post_content;
52 61
53 62 // is this box enabled?
54 - $this->enabled = ( $post->post_status === 'publish' );
63 + $this->enabled = $post->post_status === 'publish';
55 64
56 65 // load and store options in property
57 66 $this->options = $this->load_options();
58 67 }
@@ -62,41 +71,44 @@
62 71 **
63 72 * @return array Array of box options
64 73 */
65 74 protected function load_options() {
66 -
67 - static $defaults = array(
68 - 'css' => array(
75 + $defaults = array(
76 + 'css' => array(
69 77 'background_color' => '',
70 - 'color' => '',
71 - 'width' => '',
72 - 'border_color' => '',
73 - 'border_width' => '',
74 - 'border_style' => '',
75 - 'position' => 'bottom-right',
78 + 'color' => '',
79 + 'width' => '',
80 + 'border_color' => '',
81 + 'border_width' => '',
82 + 'border_style' => '',
83 + 'position' => 'bottom-right',
76 84 ),
77 - 'rules' => array(
85 + 'rules' => array(
78 86 0 => array(
79 87 'condition' => '',
80 - 'value' => '',
88 + 'value' => '',
81 89 ),
82 90 ),
83 - 'rules_comparision' => 'any',
84 - 'cookie' => array(
91 + 'rules_comparision' => 'any',
92 + 'cookie' => array(
85 93 'triggered' => 0,
86 94 'dismissed' => 0,
87 95 ),
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,
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,
97 109 );
98 - $box = $this;
110 + $box = $this;
99 111
100 112 $options = get_post_meta( $this->ID, 'boxzilla_options', true );
101 113 $options = is_array( $options ) ? $options : array();
102 114
@@ -136,10 +148,13 @@
136 148 *
137 149 * @return string
138 150 */
139 151 public function get_close_icon() {
152 + if ( ! $this->options['show_close_icon'] ) {
153 + return '';
154 + }
140 155
141 - $box = $this;
156 + $box = $this;
142 157 $html = '×';
143 158
144 159 /**
145 160 * Filters the HTML for the close icon.
@@ -154,14 +169,26 @@
154 169
155 170 /**
156 171 * Get the content of this box
157 172 *
158 - * @return mixed|void
173 + * @return string
159 174 */
160 175 public function get_content() {
161 176 $content = $this->content;
162 - $box = $this;
177 + $box = $this;
163 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 +
164 191 /**
165 192 * Filters the HTML for the box content
166 193 *
167 194 * @param string $content
@@ -171,51 +198,56 @@
171 198 return $content;
172 199 }
173 200
174 201 /**
175 - * Get the minimum allowed screen size for this box
202 + * Get options object for JS script.
176 203 *
177 - * @return int
204 + * @return array
178 205 */
179 - public function get_minimum_screen_size() {
180 -
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 - }
186 -
187 - return $minimum_screen_size;
188 - }
189 -
190 206 public function get_client_options() {
191 207 $box = $this;
192 208
193 209 $trigger = false;
194 - if( $box->options['trigger'] ) {
210 + if ( $box->options['trigger'] ) {
211 + $trigger = array(
212 + 'method' => $this->options['trigger'],
213 + );
195 214
196 - $trigger = array( 'method' => $this->options['trigger'] );
197 -
198 - if( isset( $this->options[ 'trigger_' . $this->options['trigger'] ] ) ) {
215 + if ( isset( $this->options[ 'trigger_' . $this->options['trigger'] ] ) ) {
199 216 $trigger['value'] = $this->options[ 'trigger_' . $this->options['trigger'] ];
200 217 }
201 218 }
202 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;
203 230 $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(
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(
211 238 'triggered' => absint( $box->options['cookie']['triggered'] ),
212 239 'dismissed' => absint( $box->options['cookie']['dismissed'] ),
213 240 ),
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'],
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 + ),
218 250 );
219 251
220 252 /**
221 253 * Filter the final options for the JS Boxzilla client.
@@ -226,6 +258,5 @@
226 258 $client_options = apply_filters( 'boxzilla_box_client_options', $client_options, $box );
227 259
228 260 return $client_options;
229 261 }
230 -
231 -}
262 +}