block-all-options-controls.php
7.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
if (!defined('WORDFENCE_VERSION')) { exit; }
/**
* Presents the top controls on the All Options page.
*
* Expects $indexOptions. $suppressControls may be defined to hide the options-saving controls. If not truthy, $restoreDefaultsSection and $restoreDefaultsMessage must also be defined.
*
* @var array $indexOptions An array of the index options to allow searching. The key should be the element ID to scroll to and the value is the name of the option.
* @var string $restoreDefaultsMessage The message shown in the restore defaults prompt
*/
if (isset($backLabel) && !isset($backLabelHTML)) {
$backLabelHTML = esc_html($backLabel);
}
?>
<div class="wf-block wf-block-transparent wf-active">
<div class="wf-block-content">
<ul class="wf-block-left-right wf-block-left-right-nowrap wf-hidden-xs">
<li class="wf-left">
<ul class="wf-flex-horizontal">
<?php if (isset($showIcon) && $showIcon): ?>
<li><div class="wordfence-lock-icon wordfence-icon32 wf-no-top wf-no-right wf-hidden-xs"></div></li>
<?php endif; ?>
<li id="wf-all-options-search"<?php if (isset($showIcon) && $showIcon): ?> class="wf-padding-add-left"<?php endif; ?>>
<select class="wf-options-searcher" multiple>
<?php
foreach ($indexOptions as $element => $label):
?>
<option value="<?php echo esc_attr($element); ?>"><?php echo esc_html($label); ?></option>
<?php
endforeach;
?>
</select>
</li>
</ul>
</li>
<?php if (!isset($suppressControls) || !$suppressControls): ?>
<li class="wf-right">
<a id="wf-restore-defaults" class="wf-btn wf-btn-default wf-btn-callout-subtle" href="#" data-restore-defaults-section="<?php echo esc_attr($restoreDefaultsSection); ?>" role="button"><?php echo wp_kses(/* translators: word order may be reversed as long as HTML remains around "Restore" */ __('<span class="wf-hidden-xs">Restore </span>Defaults', 'wordfence'), array('span'=>array('class'=>array()))); ?></a> <a id="wf-cancel-changes" class="wf-btn wf-btn-default wf-btn-callout-subtle wf-disabled" href="#" role="button"><?php echo wp_kses(/* translators: word order may be reversed as long as HTML remains around "Changes" */ __('Cancel<span class="wf-hidden-xs wf-hidden-sm"> Changes</span>', 'wordfence'), array('span'=>array('class'=>array()))); ?></a> <a id="wf-save-changes" class="wf-btn wf-btn-primary wf-btn-callout-subtle wf-disabled" href="#" role="button"><?php echo wp_kses(/* translators: word order may be reversed as long as HTML remains around "Changes" */ __('Save<span class="wf-hidden-xs wf-hidden-sm"> Changes</span>', 'wordfence'), array('span'=>array('class'=>array()))); ?></a>
</li>
<?php endif; ?>
</ul>
<ul class="wf-block-left-center-right wf-hidden-sm wf-hidden-md wf-hidden-lg">
<li class="wf-left">
<?php if (!isset($suppressLogo) || !$suppressLogo): ?>
<div class="wordfence-lock-icon wordfence-icon32"></div>
<?php endif; ?>
</li>
<li class="wf-center">
<select class="wf-options-searcher" multiple>
<?php
foreach ($indexOptions as $element => $label):
?>
<option value="<?php echo esc_attr($element); ?>"><?php echo esc_html($label); ?></option>
<?php
endforeach;
?>
</select>
</li>
<?php if (!isset($suppressControls) || !$suppressControls): ?>
<li class="wf-right">
<a id="wf-mobile-controls" href="#" data-restore-defaults-section="<?php echo esc_attr($restoreDefaultsSection); ?>" role="button">•••</a>
</li>
<?php endif; ?>
</ul>
</div>
</div>
<?php if (!isset($suppressControls) || !$suppressControls): ?>
<script type="application/javascript">
(function($) {
$('.wf-options-searcher').css('display', 'none');
$(function() {
var initialTop = parseInt($('.wf-options-controls').css('top'));
$(window).bind("scroll", function() {
if (window.matchMedia("only screen and (max-width: 615px)").matches) {
$(this).scrollTop() > initialTop ? $('.wf-options-controls').css('top', '0px').css('position', 'fixed').css('left', '0px') : $('.wf-options-controls').css('top', initialTop + 'px').css('position', 'absolute').css('left', '-10px');
}
});
$('.wf-options-searcher').wfselect2({
tags: true,
tokenSeparators: [','],
placeholder: <?php echo json_encode(__('Search All Options', 'wordfence')) ?>,
minimumResultsForSearch: -1,
minimumInputLength: 2,
selectOnClose: false,
width: (WFAD.screenSize(WFAD.SCREEN_MD) ? '250px' : '500px'),
createTag: function (params) {
return null; //No custom tags
}
}).on('change', function () {
var selection = $(this).val();
if (Array.isArray(selection)) {
if (selection.length > 0) {
selection = selection[0];
}
else {
selection = false;
}
}
else if (typeof selection !== 'string') {
selection = false;
}
if (selection !== false) {
var el = $('#' + selection);
if (el.is(':visible')) {
$('html, body').animate({
scrollTop: el.offset().top - 100
}, 750);
}
else if (el.is('input[type="hidden"]')) {
$('html, body').animate({
scrollTop: el.parent().offset().top - 100
}, 750);
}
else {
var block = el.closest('.wf-block[data-persistence-key]');
if (!block.hasClass('wf-active') && !block.hasClass('wf-always-active')) {
block.find('.wf-block-content').slideDown({
always: function() {
block.addClass('wf-active');
$('html, body').animate({
scrollTop: el.offset().top - 100
}, 750);
}
});
WFAD.ajax('wordfence_saveDisclosureState', {name: block.data('persistenceKey'), state: true}, function() {}, function() {}, true);
}
}
$('.wf-options-searcher').val('').change();
}
});
if ($('.wf-options-searcher').length > 0) {
$('.wf-options-searcher').data('wfselect2').$container.addClass('wf-select2-placeholder-fix wf-select2-hide-tags');
}
$(window).on('resize', function(e) {
$('.wf-options-searcher').wfselect2({
tags: true,
tokenSeparators: [','],
placeholder: <?php echo json_encode(__('Search All Options', 'wordfence')) ?>,
minimumResultsForSearch: -1,
minimumInputLength: 2,
selectOnClose: false,
width: (WFAD.screenSize(WFAD.SCREEN_MD) ? '250px' : '500px'),
createTag: function (params) {
return null; //No custom tags
}
});
});
});
})(jQuery);
</script>
<script type="text/x-jquery-template" id="wfTmpl_restoreDefaultsPrompt">
<?php
echo wfView::create('common/modal-prompt', array(
'title' => __('Confirm Restore Defaults', 'wordfence'),
'message' => $restoreDefaultsMessage,
'primaryButton' => array('id' => 'wf-restore-defaults-prompt-cancel', 'label' => __('Cancel', 'wordfence'), 'link' => '#'),
'secondaryButtons' => array(array('id' => 'wf-restore-defaults-prompt-confirm', 'labelHTML' => wp_kses(/* translators: word order may be reversed as long as HTML remains around "Defaults" */ __('Restore<span class="wf-hidden-xs"> Defaults</span>', 'wordfence'), array('span'=>array('class'=>array()))), 'link' => '#')),
))->render();
?>
</script>
<?php endif; ?>