Add language filter to server list #68
|
@ -16,6 +16,7 @@
|
|||
"ext-curl": "*",
|
||||
"ext-gd": "*",
|
||||
"ext-json": "*",
|
||||
"ext-pdo": "*",
|
||||
"asika/simple-console": "^1.0",
|
||||
"atlas/pdo": "^1.1",
|
||||
"boronczyk/localization-middleware": "^1.4",
|
||||
|
|
23
composer.lock
generated
23
composer.lock
generated
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "32addc73d4c20158a63877c57d3654dc",
|
||||
"content-hash": "a8bc1750aa6136e10ea28799a0974f6b",
|
||||
"packages": [
|
||||
{
|
||||
"name": "asika/simple-console",
|
||||
|
@ -1773,6 +1773,7 @@
|
|||
"keywords": [
|
||||
"tokenizer"
|
||||
],
|
||||
"abandoned": true,
|
||||
"time": "2017-12-04T08:55:13+00:00"
|
||||
},
|
||||
{
|
||||
|
@ -3056,6 +3057,20 @@
|
|||
"Xdebug",
|
||||
"performance"
|
||||
],
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://packagist.com",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/composer",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/composer/composer",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2020-06-04T11:16:35+00:00"
|
||||
},
|
||||
{
|
||||
|
@ -3750,10 +3765,12 @@
|
|||
"php": ">=7.1.0",
|
||||
"ext-curl": "*",
|
||||
"ext-gd": "*",
|
||||
"ext-json": "*"
|
||||
"ext-json": "*",
|
||||
"ext-pdo": "*"
|
||||
},
|
||||
"platform-dev": [],
|
||||
"platform-overrides": {
|
||||
"php": "7.1.0"
|
||||
}
|
||||
},
|
||||
"plugin-api-version": "1.1.0"
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace Friendica\Directory\Controllers\Web;
|
|||
|
||||
use Friendica\Directory\Content\Pager;
|
||||
use Friendica\Directory\Views\Widget\PopularCountries;
|
||||
use Friendica\Directory\Views\Widget\PopularLanguages;
|
||||
use Friendica\Directory\Views\Widget\PopularProfileLanguages;
|
||||
use Friendica\Directory\Views\Widget\PopularTags;
|
||||
use Slim\Http\Request;
|
||||
use Slim\Http\Response;
|
||||
|
@ -54,7 +54,7 @@ class Directory extends BaseController
|
|||
{
|
||||
$popularTags = new PopularTags($this->atlas, $this->renderer);
|
||||
$popularCountries = new PopularCountries($this->atlas, $this->renderer);
|
||||
$popularLanguages = new PopularLanguages($this->atlas, $this->renderer);
|
||||
$popularLanguages = new PopularProfileLanguages($this->atlas, $this->renderer);
|
||||
|
||||
$pager = new Pager($this->l10n, $request, 20);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace Friendica\Directory\Views\Widget;
|
|||
/**
|
||||
* @author Hypolite Petovan <hypolite@mrpetovan.com>
|
||||
*/
|
||||
class PopularLanguages
|
||||
class PopularProfileLanguages
|
||||
{
|
||||
/**
|
||||
* @var \Atlas\Pdo\Connection
|
||||
|
@ -36,6 +36,6 @@ class PopularLanguages
|
|||
'languages' => $languages
|
||||
];
|
||||
|
||||
return $this->renderer->fetch('widget/popularlanguages.phtml', $vars);
|
||||
return $this->renderer->fetch('widget/popularprofilelanguages.phtml', $vars);
|
||||
}
|
||||
}
|
44
src/classes/Views/Widget/PopularServerLanguages.php
Normal file
44
src/classes/Views/Widget/PopularServerLanguages.php
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Directory\Views\Widget;
|
||||
|
||||
/**
|
||||
* @author Hypolite Petovan <hypolite@mrpetovan.com>
|
||||
*/
|
||||
class PopularServerLanguages
|
||||
{
|
||||
/**
|
||||
* @var \Atlas\Pdo\Connection
|
||||
*/
|
||||
private $connection;
|
||||
/**
|
||||
* @var \Friendica\Directory\Views\PhpRenderer
|
||||
*/
|
||||
private $renderer;
|
||||
|
||||
public function __construct(\Atlas\Pdo\Connection $connection, \Friendica\Directory\Views\PhpRenderer $renderer)
|
||||
{
|
||||
$this->connection = $connection;
|
||||
$this->renderer = $renderer;
|
||||
}
|
||||
|
||||
public function render(): string
|
||||
{
|
||||
$stmt = 'SELECT LEFT(`language`, 2) AS `language`, COUNT(*) AS `total`
|
||||
FROM `server`
|
||||
WHERE `reg_policy` != "REGISTER_CLOSED"
|
||||
AND `available`
|
||||
AND NOT `hidden`
|
||||
AND `language` IS NOT NULL
|
||||
GROUP BY LEFT(`language`, 2)
|
||||
ORDER BY `total` DESC
|
||||
LIMIT 10';
|
||||
$languages = $this->connection->fetchAll($stmt);
|
||||
|
||||
$vars = [
|
||||
'languages' => $languages
|
||||
];
|
||||
|
||||
return $this->renderer->fetch('widget/popularserverlanguages.phtml', $vars);
|
||||
}
|
||||
}
|
|
@ -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') {
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
13
src/templates/widget/popularserverlanguages.phtml
Normal file
13
src/templates/widget/popularserverlanguages.phtml
Normal file
|
@ -0,0 +1,13 @@
|
|||
<div>
|
||||
<h3><?php echo $this->__('Filter by language')?></h3>
|
||||
<ul>
|
||||
<?php foreach ($languages as $language): ?>
|
||||
<li>
|
||||
<a href="<?php echo $this->escapeHtmlAttr($this->r('servers', ['language' => $language['language']])) ?>">
|
||||
<?php echo $this->e(Friendica\Directory\Utils\L10n::localeToLanguageString($language['language'])) ?>
|
||||
(<?php echo $this->e($language['total'])?>)
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
Loading…
Reference in a new issue