Add language filter to server list #68

Merged
MrPetovan merged 3 commits from task/3-add-server-language-filter into stable 2020-09-27 21:45:42 +02:00
4 changed files with 31 additions and 8 deletions
Showing only changes of commit 16d1962324 - Show all commits

View file

@ -2,7 +2,8 @@
namespace Friendica\Directory\Controllers\Web;
use \Friendica\Directory\Content\Pager;
use Friendica\Directory\Content\Pager;
use Friendica\Directory\Views\Widget\PopularServerLanguages;
use PDO;
use Slim\Http\Request;
use Slim\Http\Response;
@ -58,19 +59,32 @@ class Servers extends BaseController
$rc_version = str_replace('-dev', '-rc', $dev_version);
$popularLanguages = new PopularServerLanguages($this->atlas, $this->renderer);
$pager = new Pager($this->l10n, $request, 20);
$sql_where = '';
$values = [];
if ($args['language']) {
$sql_where .= '
AND LEFT(`language`, 2) = LEFT(:language, 2)';
$values['language'] = $args['language'];
}
$stmt = 'SELECT *
FROM `server` s
WHERE `reg_policy` != "REGISTER_CLOSED"
AND `available`
AND NOT `hidden`
' . $sql_where . '
ORDER BY `health_score` DESC, `ssl_state` DESC, `info` != "" DESC, `last_seen` DESC
LIMIT :start, :limit';
$servers = $this->atlas->fetchAll($stmt, [
$listValues = array_merge($values, [
'start' => [$pager->getStart(), PDO::PARAM_INT],
'limit' => [$pager->getItemsPerPage(), PDO::PARAM_INT]
]);
$servers = $this->atlas->fetchAll($stmt, $listValues);
foreach ($servers as $key => $server) {
$servers[$key]['user_count'] = $this->atlas->fetchValue(
@ -83,16 +97,20 @@ LIMIT :start, :limit';
FROM `server` s
WHERE `reg_policy` != "REGISTER_CLOSED"
AND `available`
AND NOT `hidden`';
$count = $this->atlas->fetchValue($stmt);
AND NOT `hidden`
' . $sql_where;
$count = $this->atlas->fetchValue($stmt, $values);
$vars = [
'title' => $this->l10n->gettext('Public Servers'),
'total' => $count,
'language' => $args['language'],
'servers' => $servers,
'pager' => $pager->renderFull($count),
'stable_version' => $stable_version,
'rc_version' => $rc_version,
'dev_version' => $dev_version,
'popularLanguages' => $popularLanguages->render(),
];
$content = $this->renderer->fetch('servers.phtml', $vars);

View file

@ -10,7 +10,7 @@ use Slim\Http\Response;
*/
$app->get('/servers/surprise', \Friendica\Directory\Routes\Http\Surprise::class);
$app->get('/servers', \Friendica\Directory\Routes\Web\Servers::class)->setName('servers');
$app->get('/servers[/{language}]', \Friendica\Directory\Routes\Web\Servers::class)->setName('servers');
$app->get('/search[/{account_type}]', function (Request $request, Response $response, $args) {
if ($request->getAttribute('negotiation')->getMediaType() == 'application/json') {

View file

@ -1,4 +1,9 @@
<h1><?php echo $this->e($title) ?></h1>
<h1><?php echo $this->e($title) ?> (<?php echo $this->e($total)?>)</h1>
<?php if ($language):?>
<p><?php echo $this->__('Filtered by language:')?> <span class="badge badge-secondary"><?php echo $this->e(\Friendica\Directory\Utils\L10n::localeToLanguageString($language)) ?></span> <a href="<?php echo $this->r('servers')?>"><?php echo $this->__('Clear language filter')?></a></p>
<?php else:?>
<?php echo $popularLanguages?>
<?php endif;?>
<nav aria-label="<?php echo $this->__('Top servers pagination')?>">
<?php echo $this->fetch('sub/pager_full.phtml', $pager) ?>
</nav>

View file

@ -41,10 +41,10 @@ $base_url_display = substr($base_url, strpos($base_url, '/') + 2);
<i class="fa fa-heartbeat"></i> <?php echo $server['health_score'] ?>
</span>
<?php if ($server['language']):?>
<span class="badge badge-secondary" title="<?php echo $this->__('Default Language')?>">
<a href="<?php echo $this->r('servers', ['language' => $server['language']])?>" class="badge badge-secondary" title="<?php echo $this->__('Default Language')?>">
<i class="fa fa-language" alt="<?php echo $this->__('Default Language')?>"></i>
<?php echo $this->e(Friendica\Directory\Utils\L10n::localeToLanguageString($server['language'])) ?>
</span>
</a>
<?php endif;?>
<span class="badge badge-secondary" title="<?php echo $this->__('Known Users')?>">
<i class="fa fa-user"></i>