| @@ -99,10 +99,14 @@ | ||
| 99 | 99 | 'trigger_time_on_site' => 0, |
| 100 | 100 | 'trigger_time_on_page' => 0, |
| 101 | 101 | 'animation' => 'fade', |
| 102 | 102 | 'auto_hide' => 0, |
| 103 | - 'hide_on_screen_size' => '', | |
| 104 | - 'closable' => true, | |
| 103 | + 'screen_size_condition' => array( | |
| 104 | + 'condition' => 'larger', | |
| 105 | + 'value' => 0, | |
| 106 | + ), | |
| 107 | + 'closable' => 1, | |
| 108 | + 'show_close_icon' => 1, | |
| 105 | 109 | ); |
| 106 | 110 | $box = $this; |
| 107 | 111 | |
| 108 | 112 | $options = get_post_meta( $this->ID, 'boxzilla_options', true ); |
| @@ -107,8 +111,9 @@ | ||
| 107 | 111 | |
| 108 | 112 | $options = get_post_meta( $this->ID, 'boxzilla_options', true ); |
| 109 | 113 | $options = is_array( $options ) ? $options : array(); |
| 110 | 114 | |
| 115 | + | |
| 111 | 116 | // merge options with default options |
| 112 | 117 | $options = array_replace_recursive( $defaults, $options ); |
| 113 | 118 | |
| 114 | 119 | // allow others to filter the final array of options |
| @@ -145,8 +150,12 @@ | ||
| 145 | 150 | * @return string |
| 146 | 151 | */ |
| 147 | 152 | public function get_close_icon() { |
| 148 | 153 | |
| 154 | + if( ! $this->options['show_close_icon'] ) { | |
| 155 | + return ''; | |
| 156 | + } | |
| 157 | + | |
| 149 | 158 | $box = $this; |
| 150 | 159 | $html = '×'; |
| 151 | 160 | |
| 152 | 161 | /** |
| @@ -162,15 +171,27 @@ | ||
| 162 | 171 | |
| 163 | 172 | /** |
| 164 | 173 | * Get the content of this box |
| 165 | 174 | * |
| 166 | - * @return mixed|void | |
| 175 | + * @return string | |
| 167 | 176 | */ |
| 168 | 177 | public function get_content() { |
| 169 | 178 | $content = $this->content; |
| 170 | 179 | $box = $this; |
| 171 | 180 | |
| 172 | - /** | |
| 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 | + /** | |
| 173 | 194 | * Filters the HTML for the box content |
| 174 | 195 | * |
| 175 | 196 | * @param string $content |
| 176 | 197 | * @param Box $box |
| @@ -178,24 +199,8 @@ | ||
| 178 | 199 | $content = apply_filters( 'boxzilla_box_content', $content, $box ); |
| 179 | 200 | return $content; |
| 180 | 201 | } |
| 181 | 202 | |
| 182 | - /** | |
| 183 | - * Get the minimum allowed screen size for this box | |
| 184 | - * | |
| 185 | - * @return int | |
| 186 | - */ | |
| 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 | 203 | /** |
| 199 | 204 | * Get options object for JS script. |
| 200 | 205 | * |
| 201 | 206 | * @return array |
| @@ -213,8 +218,17 @@ | ||
| 213 | 218 | $trigger['value'] = $this->options[ 'trigger_' . $this->options['trigger'] ]; |
| 214 | 219 | } |
| 215 | 220 | } |
| 216 | 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 | + | |
| 217 | 231 | $client_options = array( |
| 218 | 232 | 'id' => $box->ID, |
| 219 | 233 | 'icon' => $box->get_close_icon(), |
| 220 | 234 | 'content' => $box->get_content(), |
| @@ -226,10 +240,10 @@ | ||
| 226 | 240 | 'dismissed' => absint( $box->options['cookie']['dismissed'] ), |
| 227 | 241 | ), |
| 228 | 242 | 'rehide' => (bool) $box->options['auto_hide'], |
| 229 | 243 | 'position' => $box->options['css']['position'], |
| 230 | - 'minimumScreenWidth' => $box->get_minimum_screen_size(), | |
| 231 | - 'closable' => $box->options['closable'], | |
| 244 | + 'screenWidthCondition' => $screen_width_condition, | |
| 245 | + 'closable' => !!$box->options['closable'], | |
| 232 | 246 | 'post' => array( |
| 233 | 247 | 'id' => $this->post->ID, |
| 234 | 248 | 'title' => $this->post->post_title, |
| 235 | 249 | 'slug' => $this->post->post_name, |