mirror of
https://github.com/kokororin/typecho-plugin-Access.git
synced 2024-12-26 21:00:17 +08:00
feat: add fuzzy match to filter
This commit is contained in:
parent
45c1d9fd1c
commit
020bfec514
@ -66,6 +66,7 @@ class Access_Core
|
||||
{
|
||||
$type = $this->request->get('type', 1);
|
||||
$filter = $this->request->get('filter', 'all');
|
||||
$fuzzy = $this->request->get('fuzzy', '');
|
||||
$pagenum = $this->request->get('page', 1);
|
||||
$offset = (max(intval($pagenum), 1) - 1) * $this->config->pageSize;
|
||||
$query = $this->db->select()->from('table.access_logs')
|
||||
@ -87,18 +88,33 @@ class Access_Core
|
||||
switch ($filter) {
|
||||
case 'ip':
|
||||
$ip = $this->request->get('ip', '');
|
||||
$query->where('ip = ?', $ip);
|
||||
$qcount->where('ip = ?', $ip);
|
||||
if ($fuzzy == '1') {
|
||||
$query->where('ip LIKE ?', $ip);
|
||||
$qcount->where('ip LIKE ?', $ip);
|
||||
} else {
|
||||
$query->where('ip = ?', $ip);
|
||||
$qcount->where('ip = ?', $ip);
|
||||
}
|
||||
break;
|
||||
case 'post':
|
||||
$cid = $this->request->get('cid', '');
|
||||
$query->where('content_id = ?', $cid);
|
||||
$qcount->where('content_id = ?', $cid);
|
||||
if ($fuzzy == '1') {
|
||||
$query->where('content_id LIKE ?', $cid);
|
||||
$qcount->where('content_id LIKE ?', $cid);
|
||||
} else {
|
||||
$query->where('content_id = ?', $cid);
|
||||
$qcount->where('content_id = ?', $cid);
|
||||
}
|
||||
break;
|
||||
case 'path':
|
||||
$path = $this->request->get('path', '');
|
||||
$query->where('path = ?', $path);
|
||||
$qcount->where('path = ?', $path);
|
||||
if ($fuzzy == '1') {
|
||||
$query->where('path LIKE ?', $path);
|
||||
$qcount->where('path LIKE ?', $path);
|
||||
} else {
|
||||
$query->where('path = ?', $path);
|
||||
$qcount->where('path = ?', $path);
|
||||
}
|
||||
break;
|
||||
}
|
||||
$list = $this->db->fetchAll($query);
|
||||
|
@ -49,6 +49,10 @@ $access = new Access_Core();
|
||||
<option <?php if($request->filter == 'post'): ?> selected="true"<?php endif; ?>value="post"><?php _e('按文章'); ?></option>
|
||||
<option <?php if($request->filter == 'path'): ?> selected="true"<?php endif; ?>value="path"><?php _e('按路由'); ?></option>
|
||||
</select>
|
||||
<select style="<?php if(!in_array($request->get('filter', 'all'), ['ip', 'path'])): ?>display: none<?php endif; ?>" name="fuzzy">
|
||||
<option <?php if($request->fuzzy != '1'): ?> selected="true"<?php endif; ?>value=""><?php _e('精确匹配'); ?></option>
|
||||
<option <?php if($request->fuzzy == '1'): ?> selected="true"<?php endif; ?>value="1"><?php _e('模糊匹配'); ?></option>
|
||||
</select>
|
||||
<input style="<?php if($request->get('filter', 'all') != 'ip'): ?>display: none<?php endif; ?>" type="text" class="text-s" placeholder="" value="<?= htmlspecialchars($request->ip); ?>" name="ip" />
|
||||
<select style="<?php if($request->get('filter', 'all') != 'post'): ?>display: none<?php endif; ?>" name="cid">
|
||||
<?php foreach ($access->logs['cidList'] as $content):?>
|
||||
@ -363,25 +367,39 @@ $(document).ready(function() {
|
||||
var $cidSelect = $form.find('select[name="cid"]');
|
||||
var $pathInput = $form.find('input[name="path"]');
|
||||
var $filterSelect = $form.find('select[name="filter"]');
|
||||
var $fuzzySelect = $form.find('select[name="fuzzy"]');
|
||||
|
||||
$filterSelect.on('change', function() {
|
||||
$ipInput.removeAttr('placeholder').val('').hide();
|
||||
$cidSelect.hide();
|
||||
$pathInput.removeAttr('placeholder').val('').hide();
|
||||
$fuzzySelect.hide();
|
||||
|
||||
switch ($filterSelect.val()) {
|
||||
case 'ip':
|
||||
$ipInput.attr('placeholder', '输入ip').show();
|
||||
$fuzzySelect.show();
|
||||
break;
|
||||
case 'post':
|
||||
$cidSelect.show();
|
||||
break;
|
||||
case 'path':
|
||||
$pathInput.attr('placeholder', '输入路由').show();
|
||||
$fuzzySelect.show();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
$fuzzySelect.on('change', function(e) {
|
||||
if (e.target.value === '1') {
|
||||
$ipInput.val($ipInput.val().replace(/%/u, '\\%'));
|
||||
$pathInput.val($ipInput.val().replace(/%/u, '\\%'));
|
||||
} else {
|
||||
$ipInput.val($ipInput.val().replace(/\\%/u, '%'));
|
||||
$pathInput.val($ipInput.val().replace(/\\%/u, '%'));
|
||||
}
|
||||
})
|
||||
|
||||
$form.find('button[type="button"]').on('click', function() {
|
||||
$form.submit();
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user