From e68b68110b84a75f33ce582f21827dafb5619180 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 27 Sep 2020 15:22:43 -0400 Subject: [PATCH 1/3] Create new popular server languages widget - Rename popular profile widget class and template --- src/classes/Controllers/Web/Directory.php | 4 +- ...guages.php => PopularProfileLanguages.php} | 4 +- .../Views/Widget/PopularServerLanguages.php | 44 +++++++++++++++++++ ...es.phtml => popularprofilelanguages.phtml} | 0 .../widget/popularserverlanguages.phtml | 13 ++++++ 5 files changed, 61 insertions(+), 4 deletions(-) rename src/classes/Views/Widget/{PopularLanguages.php => PopularProfileLanguages.php} (87%) create mode 100644 src/classes/Views/Widget/PopularServerLanguages.php rename src/templates/widget/{popularlanguages.phtml => popularprofilelanguages.phtml} (100%) create mode 100644 src/templates/widget/popularserverlanguages.phtml diff --git a/src/classes/Controllers/Web/Directory.php b/src/classes/Controllers/Web/Directory.php index f56ed20..f4aaaec 100644 --- a/src/classes/Controllers/Web/Directory.php +++ b/src/classes/Controllers/Web/Directory.php @@ -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); diff --git a/src/classes/Views/Widget/PopularLanguages.php b/src/classes/Views/Widget/PopularProfileLanguages.php similarity index 87% rename from src/classes/Views/Widget/PopularLanguages.php rename to src/classes/Views/Widget/PopularProfileLanguages.php index f82e2f4..3b3ea92 100644 --- a/src/classes/Views/Widget/PopularLanguages.php +++ b/src/classes/Views/Widget/PopularProfileLanguages.php @@ -5,7 +5,7 @@ namespace Friendica\Directory\Views\Widget; /** * @author Hypolite Petovan */ -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); } } diff --git a/src/classes/Views/Widget/PopularServerLanguages.php b/src/classes/Views/Widget/PopularServerLanguages.php new file mode 100644 index 0000000..50dcb9e --- /dev/null +++ b/src/classes/Views/Widget/PopularServerLanguages.php @@ -0,0 +1,44 @@ + + */ +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); + } +} diff --git a/src/templates/widget/popularlanguages.phtml b/src/templates/widget/popularprofilelanguages.phtml similarity index 100% rename from src/templates/widget/popularlanguages.phtml rename to src/templates/widget/popularprofilelanguages.phtml diff --git a/src/templates/widget/popularserverlanguages.phtml b/src/templates/widget/popularserverlanguages.phtml new file mode 100644 index 0000000..84d5d45 --- /dev/null +++ b/src/templates/widget/popularserverlanguages.phtml @@ -0,0 +1,13 @@ +
+

__('Filter by language')?>

+ +
From 16d19623240c70f71f657c72d2f928f59306d600 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 27 Sep 2020 15:35:23 -0400 Subject: [PATCH 2/3] Add language filter to server list --- src/classes/Controllers/Web/Servers.php | 26 +++++++++++++++++++++---- src/routes.php | 2 +- src/templates/servers.phtml | 7 ++++++- src/templates/sub/server.phtml | 4 ++-- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/classes/Controllers/Web/Servers.php b/src/classes/Controllers/Web/Servers.php index 29d505c..a4c1d78 100644 --- a/src/classes/Controllers/Web/Servers.php +++ b/src/classes/Controllers/Web/Servers.php @@ -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); diff --git a/src/routes.php b/src/routes.php index a3ed395..9dc2010 100644 --- a/src/routes.php +++ b/src/routes.php @@ -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') { diff --git a/src/templates/servers.phtml b/src/templates/servers.phtml index 5f0de89..6bc4ec4 100644 --- a/src/templates/servers.phtml +++ b/src/templates/servers.phtml @@ -1,4 +1,9 @@ -

e($title) ?>

+

e($title) ?> (e($total)?>)

+ +

__('Filtered by language:')?> e(\Friendica\Directory\Utils\L10n::localeToLanguageString($language)) ?> __('Clear language filter')?>

+ + + diff --git a/src/templates/sub/server.phtml b/src/templates/sub/server.phtml index a8d67f2..f1cf79d 100644 --- a/src/templates/sub/server.phtml +++ b/src/templates/sub/server.phtml @@ -41,10 +41,10 @@ $base_url_display = substr($base_url, strpos($base_url, '/') + 2); - + e(Friendica\Directory\Utils\L10n::localeToLanguageString($server['language'])) ?> - + From cb0bfae1ab1f59da851e352a4c3592d254045197 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 27 Sep 2020 15:37:13 -0400 Subject: [PATCH 3/3] [Composer] Add expected ext-pdo dependency --- composer.json | 1 + composer.lock | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 9f4de41..df85fd1 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/composer.lock b/composer.lock index 884f061..5854ef7 100644 --- a/composer.lock +++ b/composer.lock @@ -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" }