| @@ -30,13 +30,8 @@ | ||
| 30 | 30 | * @var bool |
| 31 | 31 | */ |
| 32 | 32 | public $enabled = false; |
| 33 | 33 | |
| 34 | - /** | |
| 35 | - * @var WP_Post | |
| 36 | - */ | |
| 37 | - private $post; | |
| 38 | - | |
| 39 | 34 | /** |
| 40 | 35 | * @param WP_Post|int $post |
| 41 | 36 | */ |
| 42 | 37 | public function __construct( $post ) { |
| @@ -45,11 +40,8 @@ | ||
| 45 | 40 | if( ! $post instanceof WP_Post ) { |
| 46 | 41 | $post = get_post( $post ); |
| 47 | 42 | } |
| 48 | 43 | |
| 49 | - // store ref to post | |
| 50 | - $this->post = $post; | |
| 51 | - | |
| 52 | 44 | // store ID in property for quick access |
| 53 | 45 | $this->ID = $post->ID; |
| 54 | 46 | |
| 55 | 47 | // store title in property |
| @@ -99,14 +91,10 @@ | ||
| 99 | 91 | 'trigger_time_on_site' => 0, |
| 100 | 92 | 'trigger_time_on_page' => 0, |
| 101 | 93 | 'animation' => 'fade', |
| 102 | 94 | 'auto_hide' => 0, |
| 103 | - 'screen_size_condition' => array( | |
| 104 | - 'condition' => 'larger', | |
| 105 | - 'value' => 0, | |
| 106 | - ), | |
| 107 | - 'closable' => 1, | |
| 108 | - 'show_close_icon' => 1, | |
| 95 | + 'hide_on_screen_size' => '', | |
| 96 | + 'closable' => true, | |
| 109 | 97 | ); |
| 110 | 98 | $box = $this; |
| 111 | 99 | |
| 112 | 100 | $options = get_post_meta( $this->ID, 'boxzilla_options', true ); |
| @@ -111,9 +99,8 @@ | ||
| 111 | 99 | |
| 112 | 100 | $options = get_post_meta( $this->ID, 'boxzilla_options', true ); |
| 113 | 101 | $options = is_array( $options ) ? $options : array(); |
| 114 | 102 | |
| 115 | - | |
| 116 | 103 | // merge options with default options |
| 117 | 104 | $options = array_replace_recursive( $defaults, $options ); |
| 118 | 105 | |
| 119 | 106 | // allow others to filter the final array of options |
| @@ -150,12 +137,8 @@ | ||
| 150 | 137 | * @return string |
| 151 | 138 | */ |
| 152 | 139 | public function get_close_icon() { |
| 153 | 140 | |
| 154 | - if( ! $this->options['show_close_icon'] ) { | |
| 155 | - return ''; | |
| 156 | - } | |
| 157 | - | |
| 158 | 141 | $box = $this; |
| 159 | 142 | $html = '×'; |
| 160 | 143 | |
| 161 | 144 | /** |
| @@ -171,27 +154,15 @@ | ||
| 171 | 154 | |
| 172 | 155 | /** |
| 173 | 156 | * Get the content of this box |
| 174 | 157 | * |
| 175 | - * @return string | |
| 158 | + * @return mixed|void | |
| 176 | 159 | */ |
| 177 | 160 | public function get_content() { |
| 178 | 161 | $content = $this->content; |
| 179 | 162 | $box = $this; |
| 180 | 163 | |
| 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 | - /** | |
| 164 | + /** | |
| 194 | 165 | * Filters the HTML for the box content |
| 195 | 166 | * |
| 196 | 167 | * @param string $content |
| 197 | 168 | * @param Box $box |
| @@ -199,36 +170,37 @@ | ||
| 199 | 170 | $content = apply_filters( 'boxzilla_box_content', $content, $box ); |
| 200 | 171 | return $content; |
| 201 | 172 | } |
| 202 | 173 | |
| 203 | - /** | |
| 204 | - * Get options object for JS script. | |
| 205 | - * | |
| 206 | - * @return array | |
| 207 | - */ | |
| 174 | + /** | |
| 175 | + * Get the minimum allowed screen size for this box | |
| 176 | + * | |
| 177 | + * @return int | |
| 178 | + */ | |
| 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 | + | |
| 208 | 190 | public function get_client_options() { |
| 209 | 191 | $box = $this; |
| 210 | 192 | |
| 211 | 193 | $trigger = false; |
| 212 | 194 | if( $box->options['trigger'] ) { |
| 213 | - $trigger = array( | |
| 214 | - 'method' => $this->options['trigger'] | |
| 215 | - ); | |
| 216 | 195 | |
| 196 | + $trigger = array( 'method' => $this->options['trigger'] ); | |
| 197 | + | |
| 217 | 198 | if( isset( $this->options[ 'trigger_' . $this->options['trigger'] ] ) ) { |
| 218 | 199 | $trigger['value'] = $this->options[ 'trigger_' . $this->options['trigger'] ]; |
| 219 | 200 | } |
| 220 | 201 | } |
| 221 | 202 | |
| 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 | - | |
| 231 | 203 | $client_options = array( |
| 232 | 204 | 'id' => $box->ID, |
| 233 | 205 | 'icon' => $box->get_close_icon(), |
| 234 | 206 | 'content' => $box->get_content(), |
| @@ -240,15 +212,10 @@ | ||
| 240 | 212 | 'dismissed' => absint( $box->options['cookie']['dismissed'] ), |
| 241 | 213 | ), |
| 242 | 214 | 'rehide' => (bool) $box->options['auto_hide'], |
| 243 | 215 | 'position' => $box->options['css']['position'], |
| 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 | - ), | |
| 216 | + 'minimumScreenWidth' => $box->get_minimum_screen_size(), | |
| 217 | + 'closable' => $box->options['closable'], | |
| 251 | 218 | ); |
| 252 | 219 | |
| 253 | 220 | /** |
| 254 | 221 | * Filter the final options for the JS Boxzilla client. |