Add language filter to server list
This commit is contained in:
parent
e68b68110b
commit
16d1962324
4 changed files with 31 additions and 8 deletions
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
namespace Friendica\Directory\Controllers\Web;
|
namespace Friendica\Directory\Controllers\Web;
|
||||||
|
|
||||||
use \Friendica\Directory\Content\Pager;
|
use Friendica\Directory\Content\Pager;
|
||||||
|
use Friendica\Directory\Views\Widget\PopularServerLanguages;
|
||||||
use PDO;
|
use PDO;
|
||||||
use Slim\Http\Request;
|
use Slim\Http\Request;
|
||||||
use Slim\Http\Response;
|
use Slim\Http\Response;
|
||||||
|
@ -58,19 +59,32 @@ class Servers extends BaseController
|
||||||
|
|
||||||
$rc_version = str_replace('-dev', '-rc', $dev_version);
|
$rc_version = str_replace('-dev', '-rc', $dev_version);
|
||||||
|
|
||||||
|
$popularLanguages = new PopularServerLanguages($this->atlas, $this->renderer);
|
||||||
|
|
||||||
$pager = new Pager($this->l10n, $request, 20);
|
$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 *
|
$stmt = 'SELECT *
|
||||||
FROM `server` s
|
FROM `server` s
|
||||||
WHERE `reg_policy` != "REGISTER_CLOSED"
|
WHERE `reg_policy` != "REGISTER_CLOSED"
|
||||||
AND `available`
|
AND `available`
|
||||||
AND NOT `hidden`
|
AND NOT `hidden`
|
||||||
|
' . $sql_where . '
|
||||||
ORDER BY `health_score` DESC, `ssl_state` DESC, `info` != "" DESC, `last_seen` DESC
|
ORDER BY `health_score` DESC, `ssl_state` DESC, `info` != "" DESC, `last_seen` DESC
|
||||||
LIMIT :start, :limit';
|
LIMIT :start, :limit';
|
||||||
$servers = $this->atlas->fetchAll($stmt, [
|
$listValues = array_merge($values, [
|
||||||
'start' => [$pager->getStart(), PDO::PARAM_INT],
|
'start' => [$pager->getStart(), PDO::PARAM_INT],
|
||||||
'limit' => [$pager->getItemsPerPage(), PDO::PARAM_INT]
|
'limit' => [$pager->getItemsPerPage(), PDO::PARAM_INT]
|
||||||
]);
|
]);
|
||||||
|
$servers = $this->atlas->fetchAll($stmt, $listValues);
|
||||||
|
|
||||||
foreach ($servers as $key => $server) {
|
foreach ($servers as $key => $server) {
|
||||||
$servers[$key]['user_count'] = $this->atlas->fetchValue(
|
$servers[$key]['user_count'] = $this->atlas->fetchValue(
|
||||||
|
@ -83,16 +97,20 @@ LIMIT :start, :limit';
|
||||||
FROM `server` s
|
FROM `server` s
|
||||||
WHERE `reg_policy` != "REGISTER_CLOSED"
|
WHERE `reg_policy` != "REGISTER_CLOSED"
|
||||||
AND `available`
|
AND `available`
|
||||||
AND NOT `hidden`';
|
AND NOT `hidden`
|
||||||
$count = $this->atlas->fetchValue($stmt);
|
' . $sql_where;
|
||||||
|
$count = $this->atlas->fetchValue($stmt, $values);
|
||||||
|
|
||||||
$vars = [
|
$vars = [
|
||||||
'title' => $this->l10n->gettext('Public Servers'),
|
'title' => $this->l10n->gettext('Public Servers'),
|
||||||
|
'total' => $count,
|
||||||
|
'language' => $args['language'],
|
||||||
'servers' => $servers,
|
'servers' => $servers,
|
||||||
'pager' => $pager->renderFull($count),
|
'pager' => $pager->renderFull($count),
|
||||||
'stable_version' => $stable_version,
|
'stable_version' => $stable_version,
|
||||||
'rc_version' => $rc_version,
|
'rc_version' => $rc_version,
|
||||||
'dev_version' => $dev_version,
|
'dev_version' => $dev_version,
|
||||||
|
'popularLanguages' => $popularLanguages->render(),
|
||||||
];
|
];
|
||||||
|
|
||||||
$content = $this->renderer->fetch('servers.phtml', $vars);
|
$content = $this->renderer->fetch('servers.phtml', $vars);
|
||||||
|
|
|
@ -10,7 +10,7 @@ use Slim\Http\Response;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$app->get('/servers/surprise', \Friendica\Directory\Routes\Http\Surprise::class);
|
$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) {
|
$app->get('/search[/{account_type}]', function (Request $request, Response $response, $args) {
|
||||||
if ($request->getAttribute('negotiation')->getMediaType() == 'application/json') {
|
if ($request->getAttribute('negotiation')->getMediaType() == 'application/json') {
|
||||||
|
|
|
@ -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')?>">
|
<nav aria-label="<?php echo $this->__('Top servers pagination')?>">
|
||||||
<?php echo $this->fetch('sub/pager_full.phtml', $pager) ?>
|
<?php echo $this->fetch('sub/pager_full.phtml', $pager) ?>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
|
@ -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'] ?>
|
<i class="fa fa-heartbeat"></i> <?php echo $server['health_score'] ?>
|
||||||
</span>
|
</span>
|
||||||
<?php if ($server['language']):?>
|
<?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>
|
<i class="fa fa-language" alt="<?php echo $this->__('Default Language')?>"></i>
|
||||||
<?php echo $this->e(Friendica\Directory\Utils\L10n::localeToLanguageString($server['language'])) ?>
|
<?php echo $this->e(Friendica\Directory\Utils\L10n::localeToLanguageString($server['language'])) ?>
|
||||||
</span>
|
</a>
|
||||||
<?php endif;?>
|
<?php endif;?>
|
||||||
<span class="badge badge-secondary" title="<?php echo $this->__('Known Users')?>">
|
<span class="badge badge-secondary" title="<?php echo $this->__('Known Users')?>">
|
||||||
<i class="fa fa-user"></i>
|
<i class="fa fa-user"></i>
|
||||||
|
|
Loading…
Reference in a new issue