Add "languages" field in filter-users to filter by most-used language

This commit is contained in:
Bofh 2022-12-28 23:49:34 +01:00
parent c398b2b1d6
commit 5eae25fec6
3 changed files with 27 additions and 1 deletions

View File

@ -291,11 +291,27 @@ $sile_file = 'silenced_accounts,'.$GLOBALS['ap_software'].','.$GLOBALS['ap_insta
if (filedb_exists('cache', $sile_file)) if (filedb_exists('cache', $sile_file))
$silenced_users = unserialize(filedb_get('cache', $sile_file)); $silenced_users = unserialize(filedb_get('cache', $sile_file));
$nlanguages = [];
$languages = arg('get.languages', null);
if ($languages !== null) {
$languages = explode(',', strtolower($languages));
$nlanguages = [];
foreach ($languages as $l)
if (preg_match('/^[a-z]{2}$/', trim($l)))
$nlanguages []= trim($l);
}
$result_accounts = []; $result_accounts = [];
foreach ($filtered_accounts as $id) { foreach ($filtered_accounts as $id) {
$newacc = []; $newacc = [];
$account = $all_accounts[$filtered_accounts_index[$id]]; $account = $all_accounts[$filtered_accounts_index[$id]];
if (count($nlanguages) > 0) {
$lang = $pg->fetch("SELECT language, COUNT(language) FROM statuses WHERE account_id = $id AND NOT language IS NULL GROUP BY language ORDER BY count DESC LIMIT 1");
if ($lang === false || !in_array($lang['language'], $nlanguages))
continue;
}
$following = $pg->fetch('SELECT count(1) FROM follows WHERE account_id = \''.$id.'\''); $following = $pg->fetch('SELECT count(1) FROM follows WHERE account_id = \''.$id.'\'');
$followers = $pg->fetch('SELECT count(1) FROM follows WHERE target_account_id = \''.$id.'\''); $followers = $pg->fetch('SELECT count(1) FROM follows WHERE target_account_id = \''.$id.'\'');
if (isset($_GET['no_follows']) && (intval($following['count']) > 0 || intval($followers['count']) > 0)) if (isset($_GET['no_follows']) && (intval($following['count']) > 0 || intval($followers['count']) > 0))

View File

@ -49,6 +49,12 @@
<textarea name="instances" placeholder="instance1.org, server2.com" <textarea name="instances" placeholder="instance1.org, server2.com"
style="width: 100%; min-width: 24em; min-height: 4em"></textarea> style="width: 100%; min-width: 24em; min-height: 4em"></textarea>
</div> </div>
<div class="input">
<label for="languages">Languages:</label>
<br class="sep"/>
<textarea name="languages" placeholder="es, en, de"
style="width: 100%; min-width: 24em; min-height: 4em"></textarea>
</div>
<div class="input"> <div class="input">
<label for="user_filter">Account type:</label> <label for="user_filter">Account type:</label>
<br class="sep"/> <br class="sep"/>
@ -185,7 +191,7 @@
</div> </div>
</div> </div>
</div> </div>
<div class="only mastodon disable-able">{mastodon:fields}</div> <div class="only mastodon">{mastodon:fields}</div>
<div class="note">{note}</div> <div class="note">{note}</div>
<div style="margin-top: 1em; text-align: right;"> <div style="margin-top: 1em; text-align: right;">

View File

@ -192,6 +192,9 @@ window.view.instance = {
data.instances = instances; data.instances = instances;
data.user_filter = 'remote'; data.user_filter = 'remote';
} }
var languages = E.element('#filters-current textarea[name=languages]').value.trim();
if (languages !== '')
data.languages = languages;
const obj_noavatar = E.element('*[name=no_avatar]:checked'); const obj_noavatar = E.element('*[name=no_avatar]:checked');
if (obj_noavatar !== null) if (obj_noavatar !== null)
data.no_avatar = ''; data.no_avatar = '';
@ -254,6 +257,7 @@ window.view.instance = {
E.element("#filters-current textarea[name=profile]").value = d.profile; E.element("#filters-current textarea[name=profile]").value = d.profile;
} }
E.element('#filters-current textarea[name=instances]').value = d.instances !== undefined ? d.instances : ''; E.element('#filters-current textarea[name=instances]').value = d.instances !== undefined ? d.instances : '';
E.element('#filters-current textarea[name=languages]').value = d.languages !== undefined ? d.languages : '';
E.elements('#filters-current input[type=checkbox]').forEach(function(it){ it.checked = false }); 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_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_statuses !== undefined) E.element('#filters-current input[name=no_statuses]').click();