PluginProbe
Boxzilla – WordPress Popup Builder / 3.2.4
Boxzilla – WordPress Popup Builder v3.2.4
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 +71 -29 3.0.33.2.4 View file →
@@ -30,8 +30,13 @@
30 30 * @var bool
31 31 */
32 32 public $enabled = false;
33 33
34 + /**
35 + * @var WP_Post
36 + */
37 + private $post;
38 +
34 39 /**
35 40 * @param WP_Post|int $post
36 41 */
37 42 public function __construct( $post ) {
@@ -40,8 +45,11 @@
40 45 if( ! $post instanceof WP_Post ) {
41 46 $post = get_post( $post );
42 47 }
43 48
49 + // store ref to post
50 + $this->post = $post;
51 +
44 52 // store ID in property for quick access
45 53 $this->ID = $post->ID;
46 54
47 55 // store title in property
@@ -74,12 +82,18 @@
74 82 'border_style' => '',
75 83 'position' => 'bottom-right',
76 84 ),
77 85 'rules' => array(
78 - 0 => array('condition' => '', 'value' => '')
86 + 0 => array(
87 + 'condition' => '',
88 + 'value' => '',
89 + ),
79 90 ),
80 91 'rules_comparision' => 'any',
81 - 'cookie' => 0,
92 + 'cookie' => array(
93 + 'triggered' => 0,
94 + 'dismissed' => 0,
95 + ),
82 96 'trigger' => 'percentage',
83 97 'trigger_percentage' => 65,
84 98 'trigger_element' => '',
85 99 'trigger_time_on_site' => 0,
@@ -85,10 +99,14 @@
85 99 'trigger_time_on_site' => 0,
86 100 'trigger_time_on_page' => 0,
87 101 'animation' => 'fade',
88 102 'auto_hide' => 0,
89 - 'hide_on_screen_size' => '',
90 - 'closable' => true,
103 + 'screen_size_condition' => array(
104 + 'condition' => 'larger',
105 + 'value' => 0,
106 + ),
107 + 'closable' => 1,
108 + 'show_close_icon' => 1,
91 109 );
92 110 $box = $this;
93 111
94 112 $options = get_post_meta( $this->ID, 'boxzilla_options', true );
@@ -93,8 +111,9 @@
93 111
94 112 $options = get_post_meta( $this->ID, 'boxzilla_options', true );
95 113 $options = is_array( $options ) ? $options : array();
96 114
115 +
97 116 // merge options with default options
98 117 $options = array_replace_recursive( $defaults, $options );
99 118
100 119 // allow others to filter the final array of options
@@ -131,8 +150,12 @@
131 150 * @return string
132 151 */
133 152 public function get_close_icon() {
134 153
154 + if( ! $this->options['show_close_icon'] ) {
155 + return '';
156 + }
157 +
135 158 $box = $this;
136 159 $html = '×';
137 160
138 161 /**
@@ -148,15 +171,27 @@
148 171
149 172 /**
150 173 * Get the content of this box
151 174 *
152 - * @return mixed|void
175 + * @return string
153 176 */
154 177 public function get_content() {
155 178 $content = $this->content;
156 179 $box = $this;
157 180
158 - /**
181 + // replace boxzilla specific shortcodes
182 + $close_link = sprintf('<a href="javascript:Boxzilla.dismiss(%d);">', $this->ID );
183 +
184 + $replacements = array(
185 + '[boxzilla_close]' => $close_link, // accept underscore and dash here for consistency with other shortcode
186 + '[boxzilla-close]' => $close_link,
187 + '[/boxzilla_close]' => '</a>',
188 + '[/boxzilla-close]' => '</a>',
189 + );
190 +
191 + $content = str_replace( array_keys( $replacements ), array_values( $replacements ), $content );
192 +
193 + /**
159 194 * Filters the HTML for the box content
160 195 *
161 196 * @param string $content
162 197 * @param Box $box
@@ -164,49 +199,56 @@
164 199 $content = apply_filters( 'boxzilla_box_content', $content, $box );
165 200 return $content;
166 201 }
167 202
168 - /**
169 - * Get the minimum allowed screen size for this box
170 - *
171 - * @return int
172 - */
173 - public function get_minimum_screen_size() {
174 -
175 - if( $this->options['hide_on_screen_size'] > 0 ) {
176 - $minimum_screen_size = absint( $this->options['hide_on_screen_size'] );
177 - } else {
178 - $minimum_screen_size = 0;
179 - }
180 -
181 - return $minimum_screen_size;
182 - }
183 -
203 + /**
204 + * Get options object for JS script.
205 + *
206 + * @return array
207 + */
184 208 public function get_client_options() {
185 209 $box = $this;
186 210
187 211 $trigger = false;
188 212 if( $box->options['trigger'] ) {
213 + $trigger = array(
214 + 'method' => $this->options['trigger']
215 + );
189 216
190 - $trigger = array( 'method' => $this->options['trigger'] );
191 -
192 217 if( isset( $this->options[ 'trigger_' . $this->options['trigger'] ] ) ) {
193 218 $trigger['value'] = $this->options[ 'trigger_' . $this->options['trigger'] ];
194 219 }
195 220 }
196 221
222 + // build screenWidthCondition object (or null)
223 + $screen_width_condition = null;
224 + if( $box->options['screen_size_condition']['value'] > 0 ) {
225 + $screen_width_condition = array(
226 + 'condition' => $box->options['screen_size_condition']['condition'],
227 + 'value' => intval( $box->options['screen_size_condition']['value'] ),
228 + );
229 + }
230 +
197 231 $client_options = array(
198 232 'id' => $box->ID,
199 233 'icon' => $box->get_close_icon(),
200 - 'content' => $box->get_content(),
234 + 'content' => '', // we grab this later from an HTML element
201 235 'css' => array_filter( $box->options['css'] ),
202 236 'trigger' => $trigger,
203 237 'animation' => $box->options['animation'],
204 - 'cookieTime' => absint( $box->options['cookie'] ),
238 + 'cookie' => array(
239 + 'triggered' => absint( $box->options['cookie']['triggered'] ),
240 + 'dismissed' => absint( $box->options['cookie']['dismissed'] ),
241 + ),
205 242 'rehide' => (bool) $box->options['auto_hide'],
206 243 'position' => $box->options['css']['position'],
207 - 'minimumScreenWidth' => $box->get_minimum_screen_size(),
208 - 'closable' => $box->options['closable'],
244 + 'screenWidthCondition' => $screen_width_condition,
245 + 'closable' => !!$box->options['closable'],
246 + 'post' => array(
247 + 'id' => $this->post->ID,
248 + 'title' => $this->post->post_title,
249 + 'slug' => $this->post->post_name,
250 + ),
209 251 );
210 252
211 253 /**
212 254 * Filter the final options for the JS Boxzilla client.
@@ -218,5 +260,5 @@
218 260
219 261 return $client_options;
220 262 }
221 263
222 -}
264 +}