| 1 |
<?php |
| 2 |
|
| 3 |
defined('ABSPATH') or exit; |
| 4 |
|
| 5 |
/** @var \Boxzilla\Box $box */ |
| 6 |
/** @var array $opts */ |
| 7 |
/** @var array $global_opts */ |
| 8 |
|
| 9 |
/** @var array $rule_options */ |
| 10 |
$rule_options = [ |
| 11 |
'everywhere' => esc_html__('everywhere', 'boxzilla'), |
| 12 |
'is_page' => esc_html__('if page', 'boxzilla'), |
| 13 |
'is_single' => esc_html__('if post', 'boxzilla'), |
| 14 |
'is_post_with_tag' => esc_html__('if post tag', 'boxzilla'), |
| 15 |
'is_post_in_category' => esc_html__('if post category', 'boxzilla'), |
| 16 |
'is_post_type' => esc_html__('if post type', 'boxzilla'), |
| 17 |
'is_url' => esc_html__('if URL', 'boxzilla'), |
| 18 |
'is_referer' => esc_html__('if referer', 'boxzilla'), |
| 19 |
'is_user_logged_in' => esc_html__('if user', 'boxzilla'), |
| 20 |
]; |
| 21 |
|
| 22 |
$rule_options = apply_filters('boxzilla_rules_options', $rule_options); |
| 23 |
|
| 24 |
?> |
| 25 |
<table class="form-table"> |
| 26 |
<?php |
| 27 |
do_action('boxzilla_before_box_option_controls', $box, $opts); |
| 28 |
?> |
| 29 |
<tr> |
| 30 |
<th><?php esc_html_e('Load this box if', 'boxzilla'); ?></th> |
| 31 |
<td> |
| 32 |
<label> |
| 33 |
<?php esc_html_e('Request matches', 'boxzilla'); ?> |
| 34 |
<select name="boxzilla_box[rules_comparision]" id="boxzilla-rule-comparison"> |
| 35 |
<option value="any" <?php selected($opts['rules_comparision'], 'any'); ?>><?php esc_html_e('any', 'boxzilla'); ?></option> |
| 36 |
<option value="all" <?php selected($opts['rules_comparision'], 'all'); ?>><?php esc_html_e('all', 'boxzilla'); ?></option> |
| 37 |
</select> |
| 38 |
<?php esc_html_e('of the following conditions.', 'boxzilla'); ?> |
| 39 |
</label> |
| 40 |
</td> |
| 41 |
</tr> |
| 42 |
<tbody id="boxzilla-box-rules"> |
| 43 |
<?php |
| 44 |
$key = 0; |
| 45 |
foreach ($opts['rules'] as $rule) { |
| 46 |
// skip invalid looking rules |
| 47 |
if (! isset($rule['condition'])) { |
| 48 |
continue; |
| 49 |
} |
| 50 |
|
| 51 |
// output row showing "and" or "or" between rules |
| 52 |
if ($key > 0) { |
| 53 |
$or = esc_html__('or', 'boxzilla'); |
| 54 |
$and = esc_html__('and', 'boxzilla'); |
| 55 |
$text = $opts['rules_comparision'] === 'any' ? $or : $and; |
| 56 |
|
| 57 |
echo '<tr>'; |
| 58 |
echo '<th class="boxzilla-no-vpadding"></th>'; |
| 59 |
echo '<td class="boxzilla-no-vpadding"><span class="boxzilla-andor boxzilla-muted">', esc_html($text), '</span></td>'; |
| 60 |
echo '</tr>'; |
| 61 |
} |
| 62 |
?> |
| 63 |
<tr valign="top" class="boxzilla-rule-row boxzilla-rule-row-<?php echo (int) $key; ?>"> |
| 64 |
<th style="text-align: right; font-weight: normal;"> |
| 65 |
<span class="boxzilla-close boxzilla-remove-rule" title="<?php esc_attr_e('Remove rule', 'boxzilla'); ?>"><span class="dashicons dashicons-dismiss"></span></span> |
| 66 |
</th> |
| 67 |
<td> |
| 68 |
<select class="boxzilla-rule-condition" name="boxzilla_box[rules][<?php echo (int) $key; ?>][condition]"> |
| 69 |
<?php |
| 70 |
foreach ($rule_options as $value => $label) { |
| 71 |
echo '<option value="' . esc_attr($value) . '" ' . selected($rule['condition'], $value, false) . '>' . esc_html($label) . '</option>'; |
| 72 |
} |
| 73 |
?> |
| 74 |
</select> |
| 75 |
|
| 76 |
<select class="boxzilla-rule-qualifier" name="boxzilla_box[rules][<?php echo (int) $key; ?>][qualifier]" style="min-width: 135px;"> |
| 77 |
<option value="1" <?php selected(! isset($rule['qualifier']) || $rule['qualifier']); ?>><?php esc_html_e('is', 'boxzilla'); ?></option> |
| 78 |
<option value="0" <?php selected(isset($rule['qualifier']) && ! $rule['qualifier']); ?>><?php esc_html_e('is not', 'boxzilla'); ?></option> |
| 79 |
<option value="contains" <?php selected(isset($rule['qualifier']) && $rule['qualifier'] === 'contains'); ?> style="display: none;"><?php esc_html_e('contains', 'boxzilla'); ?></option> |
| 80 |
<option value="not_contains" <?php selected(isset($rule['qualifier']) && $rule['qualifier'] === 'not_contains'); ?> style="display: none;"><?php esc_html_e('does not contain', 'boxzilla'); ?></option> |
| 81 |
</select> |
| 82 |
|
| 83 |
<input class="boxzilla-rule-value regular-text" name="boxzilla_box[rules][<?php echo (int) $key; ?>][value]" type="text" value="<?php echo esc_attr($rule['value']); ?>" placeholder="<?php esc_attr_e('Leave empty for any or enter (comma-separated) names or ID\'s', 'boxzilla'); ?>" <?php echo in_array($rule['condition'], [ '', 'everywhere' ], true) ? 'style="display: none;"' : ''; ?> /> |
| 84 |
</td> |
| 85 |
</tr> |
| 86 |
<?php |
| 87 |
$key++; |
| 88 |
} |
| 89 |
?> |
| 90 |
</tbody> |
| 91 |
<tr> |
| 92 |
<th></th> |
| 93 |
<td><button type="button" class="button boxzilla-add-rule"><?php esc_html_e('Add another rule', 'boxzilla'); ?></button></td> |
| 94 |
</tr> |
| 95 |
<tr valign="top"> |
| 96 |
<th><label><?php esc_html_e('Box Position', 'boxzilla'); ?></label></th> |
| 97 |
<td> |
| 98 |
<table class="window-positions"> |
| 99 |
<tr> |
| 100 |
<td> |
| 101 |
<?php |
| 102 |
$value = 'top-left'; |
| 103 |
$label = esc_html__('Top Left', 'boxzilla'); |
| 104 |
printf('<label><input type="radio" name="boxzilla_box[css][position]" value="%s" %s> %s</label>', esc_attr($value), checked($opts['css']['position'], $value, false), esc_html($label)); |
| 105 |
?> |
| 106 |
</td> |
| 107 |
<td></td> |
| 108 |
<td> |
| 109 |
<?php |
| 110 |
$value = 'top-right'; |
| 111 |
$label = esc_html__('Top Right', 'boxzilla'); |
| 112 |
printf('<label><input type="radio" name="boxzilla_box[css][position]" value="%s" %s> %s</label>', esc_attr($value), checked($opts['css']['position'], $value, false), esc_html($label)); |
| 113 |
?> |
| 114 |
</td> |
| 115 |
</tr> |
| 116 |
<tr> |
| 117 |
<td></td> |
| 118 |
<td> |
| 119 |
<?php |
| 120 |
$value = 'center'; |
| 121 |
$label = esc_html__('Center', 'boxzilla'); |
| 122 |
printf('<label><input type="radio" name="boxzilla_box[css][position]" value="%s" %s> %s</label>', esc_attr($value), checked($opts['css']['position'], $value, false), esc_html($label)); |
| 123 |
?> |
| 124 |
</td> |
| 125 |
<td></td> |
| 126 |
</tr> |
| 127 |
<tr> |
| 128 |
<td> |
| 129 |
<?php |
| 130 |
$value = 'bottom-left'; |
| 131 |
$label = esc_html__('Bottom Left', 'boxzilla'); |
| 132 |
printf('<label><input type="radio" name="boxzilla_box[css][position]" value="%s" %s> %s</label>', esc_attr($value), checked($opts['css']['position'], $value, false), esc_html($label)); |
| 133 |
?> |
| 134 |
</td> |
| 135 |
<td></td> |
| 136 |
<td> |
| 137 |
<?php |
| 138 |
$value = 'bottom-right'; |
| 139 |
$label = esc_html__('Bottom Right', 'boxzilla'); |
| 140 |
printf('<label><input type="radio" name="boxzilla_box[css][position]" value="%s" %s> %s</label>', esc_attr($value), checked($opts['css']['position'], $value, false), esc_html($label)); |
| 141 |
?> |
| 142 |
</td> |
| 143 |
</tr> |
| 144 |
</table> |
| 145 |
</td> |
| 146 |
</tr> |
| 147 |
<tr valign="top"> |
| 148 |
<th><label><?php esc_html_e('Animation', 'boxzilla'); ?></label></th> |
| 149 |
<td> |
| 150 |
<label style="margin-right: 1rem;"><input type="radio" name="boxzilla_box[animation]" value="fade" <?php checked($opts['animation'], 'fade'); ?> /> <?php esc_html_e('Fade In', 'boxzilla'); ?></label> |
| 151 |
<label style="margin-right: 1rem;"><input type="radio" name="boxzilla_box[animation]" value="slide" <?php checked($opts['animation'], 'slide'); ?> /> <?php esc_html_e('Slide In', 'boxzilla'); ?></label> |
| 152 |
<label><input type="radio" name="boxzilla_box[animation]" value="shake" <?php checked($opts['animation'], 'shake'); ?> /> <?php esc_html_e('Shake', 'boxzilla'); ?></label> |
| 153 |
|
| 154 |
<p class="help" style="margin-top: 1rem;"><?php esc_html_e('Which animation type should be used to show the box when triggered?', 'boxzilla'); ?></p> |
| 155 |
</td> |
| 156 |
</tr> |
| 157 |
<tr valign="top"> |
| 158 |
<th><label><?php esc_html_e('Auto-show box?', 'boxzilla'); ?></label></th> |
| 159 |
<td> |
| 160 |
<label style="display: block;"><input type="radio" class="boxzilla-auto-show-trigger" name="boxzilla_box[trigger]" value="" <?php checked($opts['trigger'], ''); ?> /> <?php esc_html_e('Never', 'boxzilla'); ?></label><br /> |
| 161 |
<?php /* translators: %s: Number input field for seconds on page. */ ?> |
| 162 |
<label style="display: block;"><input type="radio" class="boxzilla-auto-show-trigger" name="boxzilla_box[trigger]" value="time_on_page" <?php checked($opts['trigger'], 'time_on_page'); ?> /> <?php printf(esc_html__('Yes, after %s seconds on the page.', 'boxzilla'), '<input type="number" name="boxzilla_box[trigger_time_on_page]" min="0" value="' . esc_attr($opts['trigger_time_on_page']) . '" />'); ?></label><br /> |
| 163 |
<?php /* translators: %s: Number input field for page scroll percentage. */ ?> |
| 164 |
<label style="display: block;"><input type="radio" class="boxzilla-auto-show-trigger" name="boxzilla_box[trigger]" value="percentage" <?php checked($opts['trigger'], 'percentage'); ?> /> <?php printf(esc_html__('Yes, when at %s of page height', 'boxzilla'), '<input type="number" name="boxzilla_box[trigger_percentage]" min="0" max="100" value="' . esc_attr($opts['trigger_percentage']) . '" />%'); ?></label><br /> |
| 165 |
<?php /* translators: %s: Text input field for the CSS selector to trigger on. */ ?> |
| 166 |
<label><input type="radio" class="boxzilla-auto-show-trigger" name="boxzilla_box[trigger]" value="element" <?php checked($opts['trigger'], 'element'); ?> /> <?php printf(esc_html__('Yes, when at element %s', 'boxzilla'), '<input type="text" name="boxzilla_box[trigger_element]" value="' . esc_attr($opts['trigger_element']) . '" placeholder="' . esc_attr__('Example: #comments', 'boxzilla') . '" />'); ?></label><br /> |
| 167 |
<?php do_action('boxzilla_output_auto_show_trigger_options', $opts); ?> |
| 168 |
</td> |
| 169 |
</tr> |
| 170 |
<tbody class="boxzilla-trigger-options" style="display: <?php echo ( $opts['trigger'] === '' ) ? 'none' : 'table-row-group'; ?>;"> |
| 171 |
<tr valign="top"> |
| 172 |
<th><label><?php esc_html_e('Cookie expiration', 'boxzilla'); ?></label></th> |
| 173 |
<td> |
| 174 |
<div style="display: inline-block; margin-right: 20px;"> |
| 175 |
<label for="boxzilla_cookie_triggered" style="font-weight: bold; display: block; margin-bottom: 4px;"><?php esc_html_e('Triggered', 'boxzilla'); ?></label> |
| 176 |
<input type="number" id="boxzilla_cookie_triggered" name="boxzilla_box[cookie][triggered]" min="0" step="1" value="<?php echo esc_attr($opts['cookie']['triggered']); ?>" /> |
| 177 |
<small><?php esc_html_e('hours', 'boxzilla'); ?></small> |
| 178 |
</div> |
| 179 |
<div style="display: inline-block;"> |
| 180 |
<label for="boxzilla_cookie_dismissed" style="font-weight: bold; display: block; margin-bottom: 4px;"><?php esc_html_e('Dismissed', 'boxzilla'); ?></label> |
| 181 |
<input type="number" id="boxzilla_cookie_dismissed" name="boxzilla_box[cookie][dismissed]" min="0" step="1" value="<?php echo esc_attr($opts['cookie']['dismissed']); ?>" /> |
| 182 |
<small><?php esc_html_e('hours', 'boxzilla'); ?></small> |
| 183 |
</div> |
| 184 |
<p class="help" style="margin-top: 1rem;"><?php esc_html_e('After this box is triggered or dismissed, how many hours should it stay hidden?', 'boxzilla'); ?></p> |
| 185 |
</td> |
| 186 |
</tr> |
| 187 |
<tr valign="top"> |
| 188 |
<th><label><?php esc_html_e('Screen width', 'boxzilla'); ?></label></th> |
| 189 |
<td> |
| 190 |
<?php |
| 191 |
$condition_type = $opts['screen_size_condition']['condition']; |
| 192 |
$condition_value = $opts['screen_size_condition']['value']; |
| 193 |
$condition_select = sprintf( |
| 194 |
'<select name="boxzilla_box[screen_size_condition][condition]"><option value="larger" %1$s>%2$s</option><option value="smaller" %3$s>%4$s</option></select>', |
| 195 |
selected($condition_type, 'larger', false), |
| 196 |
esc_html__('larger', 'boxzilla'), |
| 197 |
selected($condition_type, 'smaller', false), |
| 198 |
esc_html__('smaller', 'boxzilla') |
| 199 |
); |
| 200 |
?> |
| 201 |
<?php /* translators: 1: Comparison selector (larger/smaller), 2: Number input field with px suffix. */ ?> |
| 202 |
<p><?php printf(esc_html__('Only show on screens %1$s than %2$s.', 'boxzilla'), wp_kses($condition_select, [ 'select' => [ 'name' => true ], 'option' => [ 'value' => true, 'selected' => true ] ]), '<input type="number" min="0" name="boxzilla_box[screen_size_condition][value]" value="' . esc_attr($condition_value) . '" style="max-width: 70px;" />px'); ?></p> |
| 203 |
<p class="help"><?php esc_html_e('Leave empty if you want to show the box on all screen sizes.', 'boxzilla'); ?></p> |
| 204 |
</td> |
| 205 |
|
| 206 |
</tr> |
| 207 |
<?php if (in_array($opts['trigger'], [ 'element', 'percentage' ])) { ?> |
| 208 |
<tr valign="top"> |
| 209 |
<th><label><?php esc_html_e('Auto-hide?', 'boxzilla'); ?></label></th> |
| 210 |
<td> |
| 211 |
<label><input type="radio" name="boxzilla_box[auto_hide]" value="1" <?php checked($opts['auto_hide'], 1); ?> /> <?php esc_html_e('Yes', 'boxzilla'); ?></label> |
| 212 |
<label><input type="radio" name="boxzilla_box[auto_hide]" value="0" <?php checked($opts['auto_hide'], 0); ?> /> <?php esc_html_e('No', 'boxzilla'); ?></label> |
| 213 |
<p class="help"><?php esc_html_e('Hide box again when visitors scroll back up?', 'boxzilla'); ?></p> |
| 214 |
</td> |
| 215 |
</tr> |
| 216 |
<?php } // end if ?> |
| 217 |
</tbody> |
| 218 |
<tbody> |
| 219 |
<tr valign="top"> |
| 220 |
<th><label><?php esc_html_e('Show close icon?', 'boxzilla'); ?></label></th> |
| 221 |
<td> |
| 222 |
<label><input type="radio" id="boxzilla_closable_1" name="boxzilla_box[show_close_icon]" value="1" <?php checked($opts['show_close_icon'], 1); ?> /> <?php esc_html_e('Yes', 'boxzilla'); ?></label> |
| 223 |
<label><input type="radio" id="boxzilla_closable_0" name="boxzilla_box[show_close_icon]" value="0" <?php checked($opts['show_close_icon'], 0); ?> /> <?php esc_html_e('No', 'boxzilla'); ?></label> |
| 224 |
<p class="help"> |
| 225 |
<?php esc_html_e('If you decide to hide the close icon, make sure to offer an alternative way to close the box.', 'boxzilla'); ?><br /> |
| 226 |
<?php esc_html_e('Example: ', 'boxzilla'); ?> <code>[boxzilla-close]No, thanks![/boxzilla-close]</code> |
| 227 |
</p> |
| 228 |
</td> |
| 229 |
</tr> |
| 230 |
<tr valign="top"> |
| 231 |
<th><label><?php esc_html_e('Enable test mode?', 'boxzilla'); ?></label></th> |
| 232 |
<td> |
| 233 |
<label><input type="radio" id="boxzilla_test_mode_1" name="boxzilla_global_settings[test_mode]" value="1" <?php checked($global_opts['test_mode'], 1); ?> /> <?php esc_html_e('Yes', 'boxzilla'); ?></label> |
| 234 |
<label><input type="radio" id="boxzilla_test_mode_0" name="boxzilla_global_settings[test_mode]" value="0" <?php checked($global_opts['test_mode'], 0); ?> /> <?php esc_html_e('No', 'boxzilla'); ?></label> |
| 235 |
<p class="help"><?php esc_html_e('If test mode is enabled, all boxes will show up regardless of whether a cookie has been set.', 'boxzilla'); ?></p> |
| 236 |
</td> |
| 237 |
</tr> |
| 238 |
<?php |
| 239 |
do_action('boxzilla_after_box_option_controls', $box, $opts); |
| 240 |
?> |
| 241 |
</tbody> |
| 242 |
</table> |
| 243 |
|
| 244 |
|
| 245 |
<script type="text/html" id="tmpl-rule-row-template"> |
| 246 |
<tr> |
| 247 |
<th class="boxzilla-no-vpadding"></th> |
| 248 |
<td class="boxzilla-no-vpadding"><span class="boxzilla-andor boxzilla-muted">{{data.andor}}</span></td> |
| 249 |
</tr> |
| 250 |
<tr valign="top" class="boxzilla-rule-row boxzilla-rule-row-{{{data.key}}}"> |
| 251 |
<th style="text-align: right; font-weight: normal;"> |
| 252 |
<span class="boxzilla-close boxzilla-remove-rule" title="<?php esc_attr_e('Remove rule', 'boxzilla'); ?>"><span class="dashicons dashicons-dismiss"></span></span> |
| 253 |
</th> |
| 254 |
<td class="boxzilla-sm"> |
| 255 |
<select class="boxzilla-rule-condition" name="boxzilla_box[rules][{{{data.key}}}][condition]"> |
| 256 |
<?php |
| 257 |
foreach ($rule_options as $value => $label) { |
| 258 |
echo '<option value="' . esc_attr($value) . '" ' . disabled($value, '', false) . '>' . esc_html($label) . '</option>'; |
| 259 |
} |
| 260 |
?> |
| 261 |
</select> |
| 262 |
<select class="boxzilla-rule-qualifier" name="boxzilla_box[rules][{{{data.key}}}][qualifier]" style="display: none; min-width: 135px;" > |
| 263 |
<option value="1" selected><?php esc_html_e('is', 'boxzilla'); ?></option> |
| 264 |
<option value="0"><?php esc_html_e('is not', 'boxzilla'); ?></option> |
| 265 |
<option value="contains" style="display: none;"><?php esc_html_e('contains', 'boxzilla'); ?></option> |
| 266 |
<option value="not_contains" style="display: none;"><?php esc_html_e('does not contain', 'boxzilla'); ?></option> |
| 267 |
</select> |
| 268 |
|
| 269 |
<input class="boxzilla-rule-value regular-text" name="boxzilla_box[rules][{{{data.key}}}][value]" type="text" value="" placeholder="<?php esc_attr_e('Leave empty for any or enter (comma-separated) names or ID\'s', 'boxzilla'); ?>" style="display: none;" /> |
| 270 |
</td> |
| 271 |
</tr> |
| 272 |
</script> |
| 273 |
|