diff --git a/api/v1/database/mastodon/accounts/search/index.php b/api/v1/database/mastodon/accounts/search/index.php index 37fc581..eba17e2 100644 --- a/api/v1/database/mastodon/accounts/search/index.php +++ b/api/v1/database/mastodon/accounts/search/index.php @@ -71,9 +71,20 @@ $all_accounts = $pg->fetch_all($sql_all, $cache); if (isset($_GET['profile']) && trim($_GET['profile']) != '') { - $q = strtolower(trim($_GET['profile'])); - if ($q === '') $q = ''; - $q = normalize_for_search($q); + $q = trim($_GET['profile']); + $q = base64_decode($q); + $qt = null; + if ($q === '') { + $q = ''; + $qt = 'empty'; + } else if (preg_match('/^expr:.*/', $q)) { + $q = trim(preg_replace('/^expr:/','',$q)); + $q = parse_search_expression($q); + $qt = 'expr'; + } else { + $q = normalize_for_search($q); + $qt = 'simple'; + } $ai = -1; foreach ($all_accounts as $account) diff --git a/base.php b/base.php index 7deb71a..85c0320 100644 --- a/base.php +++ b/base.php @@ -279,6 +279,11 @@ function normalize_for_search($str) { return trim(implode(' ', $newwords)); } +function parse_search_expression($q) { + var_dump($q); + die; +} + function content_cache__exists($key) { $cache_dir = $GLOBALS['appconf']['data_dir'].'/cache'; if (!file_exists($cache_dir)) { diff --git a/js/templates/instance/filter-users.html b/js/templates/instance/filter-users.html index 103875b..3de6e3f 100644 --- a/js/templates/instance/filter-users.html +++ b/js/templates/instance/filter-users.html @@ -46,6 +46,7 @@
diff --git a/views/instance.php b/views/instance.php index 44e535c..d0a0970 100644 --- a/views/instance.php +++ b/views/instance.php @@ -34,6 +34,69 @@ window.view.instance = { }); }, }, + filter_users: { + get_current_filter: function() { + var data = {}; + var preset = E.element('#filters-current input[name="preset_name"]').value.trim(); + if (preset !== '' && preset.toLowerCase() !== 'undefined') + data.preset_name = E.element('#filters-current input[name="preset_name"]').value; + data.user_filter = E.element('#filters-current input[name=user_filter]:checked').value; + var prof_stype = E.element("#filters-current input[name=profile_search_type]:checked").value; + var profile = E.element("#filters-current textarea[name=profile]").value; + if (prof_stype === 'empty') + profile = ''; + else if (prof_stype === 'expr') + profile = 'expr: '+profile; + data.profile = btoa(profile); + const obj_noavatar = E.element('*[name=no_avatar]:checked'); + if (obj_noavatar !== null) + data.no_avatar = ''; + const obj_nostatuses = E.element('*[name=no_statuses]:checked'); + if (obj_nostatuses !== null) + data.no_statuses = ''; + const obj_nofollows = E.element('*[name=no_follows]:checked'); + if (obj_nofollows !== null) + data.no_follows = ''; + return data; + }, + set_current_filter: function(data) { + const _process = function(d) { + if (d.preset_name === undefined) + d.preset_name = 'Undefined'; + E.element('#filters-current input[name="preset_name"]').value = d.preset_name; + E.element('#filters-current input[name=user_filter][value='+d.user_filter+']').click(); + d.profile = atob(d.profile); + if (d.profile === '') + E.element('#filters-current #profile-search-type-empty').click(); + else if (d.profile.startsWith('expr:')) { + d.profile = d.profile.replace(/^expr:/,'').trim(); + E.element('#filters-current #profile-search-type-expr').click(); + E.element("#filters-current textarea[name=profile]").value = d.profile; + } + E.elements('#filters-current input[type=checkbox]').forEach(function(it){ it.checked = false }); + if (d.no_avatar !== undefined) E.element('#filters-current input[name=no_avatar]').click(); + if (d.no_statuses !== undefined) E.element('#filters-current input[name=no_statuses]').click(); + if (d.no_follows !== undefined) E.element('#filters-current input[name=no_follows]').click(); + console.log(d); + }; + if (typeof data === 'object') + _process(data); + //else // TODO: load the filter by API + }, + execute: function() { + const btn = E.elemid('btncollapse-filters-current'); + if (btn.innerText.trim() === 'hide') + btn.click(); + const data = window.view.instance.do.filter_users.get_current_filter(); + const hargs = get_hash_arguments(); + var payload = data; + payload.instance = hargs.instance; + payload = JSON_to_URLEncoded(payload); + http.get(`api/v1/database/${hargs.software}/accounts/search?${payload}`, data, function(js) { + console.log(js); + }); + }, + }, }, load: { new_accounts: function() { @@ -64,20 +127,22 @@ window.view.instance = { E.element('#window-instance #container').innerHTML = html; E.elemid('profile-search-type-simple').onchange = function(e) { if (e.target.checked) { - E.element('textarea[name="profile"]').setAttribute('placeholder', 'Input your text here'); - E.element('textarea[name="profile"]').removeAttribute('disabled'); + E.element('#filters-current textarea[name=profile]').setAttribute('placeholder', 'Input your text here'); + E.element('#filters-current textarea[name=profile]').removeAttribute('disabled'); } }; E.elemid('profile-search-type-expr').onchange = function(e) { if (e.target.checked) { - E.element('textarea[name="profile"]').setAttribute('placeholder', '(words "apple banana" AND contains "i like apples") OR words "pineapple strawberry"'); - E.element('textarea[name="profile"]').removeAttribute('disabled'); + E.element('#filters-current textarea[name=profile]').setAttribute('placeholder', + '(words "apple,banana" AND contains "i like apples") OR words "pineapple,strawberry"'); + E.element('#filters-current textarea[name=profile]').removeAttribute('disabled'); } }; E.elemid('profile-search-type-empty').onchange = function(e) { if (e.target.checked) { - E.element('textarea[name="profile"]').setAttribute('placeholder', ''); - E.element('textarea[name="profile"]').setAttribute('disabled', 'disabled'); + E.element('#filters-current textarea[name=profile]').setAttribute('placeholder', ''); + E.element('#filters-current textarea[name=profile]').setAttribute('disabled', 'disabled'); + E.element("#filters-current textarea[name=profile]").value = ''; } } E.custom.btncollapse_render();