Merge pull request 'Rename "forum" to "group"' (#94) from MrPetovan/friendica-directory:task/rename-forum-to-group into stable

Reviewed-on: friendica/friendica-directory#94
This commit is contained in:
Tobias Diekershoff 2023-06-05 06:37:27 +02:00
commit 8bd1cb11ae
5 changed files with 73 additions and 45 deletions

View file

@ -16,7 +16,7 @@ Accept: application/json
``` ```
URI Parameter: URI Parameter:
- `account_type` (optional): An arbitrary account type string. Expected values are `all`, `people`, `news`, `organization` and `forum`. Default is `all`. - `account_type` (optional): An arbitrary account type string. Expected values are `all`, `people`, `news`, `organization` and `group`. Default is `all`.
Query parameters: Query parameters:
- `q`: The search query. - `q`: The search query.
- `page` (optional): The page number, default is 1. - `page` (optional): The page number, default is 1.

View file

@ -7,6 +7,13 @@ namespace Friendica\Directory\Models;
*/ */
class Profile extends \Friendica\Directory\Model class Profile extends \Friendica\Directory\Model
{ {
const ACCOUNT_TYPE_PERSON = 0;
const ACCOUNT_TYPE_ORGANISATION = 1;
const ACCOUNT_TYPE_NEWS = 2;
const ACCOUNT_TYPE_COMMUNITY = 3;
const ACCOUNT_TYPE_RELAY = 4;
const ACCOUNT_TYPE_DELETED = 127;
public function deleteById(int $profile_id): bool public function deleteById(int $profile_id): bool
{ {
$this->atlas->perform('DELETE FROM `photo` WHERE `profile_id` = :profile_id', $this->atlas->perform('DELETE FROM `photo` WHERE `profile_id` = :profile_id',

View file

@ -2,6 +2,8 @@
namespace Friendica\Directory\Pollers; namespace Friendica\Directory\Pollers;
use Friendica\Directory\Models;
use Friendica\Directory\Utils;
use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Exception\RequestException;
/** /**
@ -24,12 +26,12 @@ class Profile
private $http; private $http;
/** /**
* @var \Friendica\Directory\Models\Server * @var Models\Server
*/ */
private $serverModel; private $serverModel;
/** /**
* @var \Friendica\Directory\Models\Profile * @var Models\Profile
*/ */
private $profileModel; private $profileModel;
@ -49,8 +51,8 @@ class Profile
public function __construct( public function __construct(
\Atlas\Pdo\Connection $atlas, \Atlas\Pdo\Connection $atlas,
\GuzzleHttp\ClientInterface $http, \GuzzleHttp\ClientInterface $http,
\Friendica\Directory\Models\Server $serverModel, Models\Server $serverModel,
\Friendica\Directory\Models\Profile $profileModel, Models\Profile $profileModel,
\Psr\Log\LoggerInterface $logger, \Psr\Log\LoggerInterface $logger,
array $settings array $settings
) )
@ -81,12 +83,12 @@ class Profile
return false; return false;
} }
if (!\Friendica\Directory\Utils\Network::isPublicHost($host)) { if (!Utils\Network::isPublicHost($host)) {
$this->logger->warning('Private/reserved IP in polled profile URL: ' . $profile_uri); $this->logger->warning('Private/reserved IP in polled profile URL: ' . $profile_uri);
return false; return false;
} }
$profileUriInfo = \Friendica\Directory\Models\Profile::extractInfoFromProfileUrl($profile_uri); $profileUriInfo = Models\Profile::extractInfoFromProfileUrl($profile_uri);
if (!$profileUriInfo) { if (!$profileUriInfo) {
$this->logger->warning('Profile URI invalid'); $this->logger->warning('Profile URI invalid');
return false; return false;
@ -137,7 +139,7 @@ class Profile
if ($server['noscrape_url']) { if ($server['noscrape_url']) {
$this->logger->debug('Calling ' . $server['noscrape_url'] . '/' . $username); $this->logger->debug('Calling ' . $server['noscrape_url'] . '/' . $username);
try { try {
$params = \Friendica\Directory\Utils\Scrape::retrieveNoScrapeData($this->http, $server['noscrape_url'] . '/' . $username); $params = Utils\Scrape::retrieveNoScrapeData($this->http, $server['noscrape_url'] . '/' . $username);
} catch (RequestException $e) { } catch (RequestException $e) {
$this->logger->info('Request failed with error code ' . $e->getCode()); $this->logger->info('Request failed with error code ' . $e->getCode());
} catch (\Throwable $e) { } catch (\Throwable $e) {
@ -151,7 +153,7 @@ class Profile
if (!$available) { if (!$available) {
$this->logger->info('Parsing profile page ' . $profile_uri); $this->logger->info('Parsing profile page ' . $profile_uri);
try { try {
$params = \Friendica\Directory\Utils\Scrape::retrieveProfileData($this->http, $profile_uri); $params = Utils\Scrape::retrieveProfileData($this->http, $profile_uri);
} catch (RequestException $e) { } catch (RequestException $e) {
$this->logger->info('Request failed with error code ' . $e->getCode()); $this->logger->info('Request failed with error code ' . $e->getCode());
} catch (\Throwable $e) { } catch (\Throwable $e) {
@ -209,16 +211,22 @@ class Profile
return false; return false;
} }
switch ($params['account-type'] ?? 0) { switch ($params['account-type'] ?? Models\Profile::ACCOUNT_TYPE_PERSON) {
case 1: $account_type = 'News'; break; case Models\Profile::ACCOUNT_TYPE_ORGANISATION: $account_type = 'Organization'; break;
case 2: $account_type = 'Organization'; break; case Models\Profile::ACCOUNT_TYPE_NEWS : $account_type = 'News'; break;
case 3: $account_type = 'Forum'; break; case Models\Profile::ACCOUNT_TYPE_COMMUNITY : $account_type = 'Group'; break;
case 0: case Models\Profile::ACCOUNT_TYPE_RELAY : $account_type = 'Relay'; break;
default: case Models\Profile::ACCOUNT_TYPE_DELETED : $account_type = 'Deleted'; break;
case Models\Profile::ACCOUNT_TYPE_PERSON: {
$account_type = 'People'; $account_type = 'People';
if (!empty($params['comm'])) { if (!empty($params['comm'])) {
$account_type = 'Forum'; $account_type = 'Group';
} }
break;
}
default: $account_type = 'Unknown'; break;
} }
$tags = []; $tags = [];
@ -323,7 +331,7 @@ class Profile
if ($profile_id) { if ($profile_id) {
try { try {
$img_str = $this->http->get($params['photo'])->getBody()->getContents(); $img_str = $this->http->get($params['photo'])->getBody()->getContents();
$img = new \Friendica\Directory\Utils\Photo($img_str); $img = new Utils\Photo($img_str);
if ($img->getImage()) { if ($img->getImage()) {
$img->scaleImageSquare(80); $img->scaleImageSquare(80);

View file

@ -56,7 +56,9 @@ class AccountTypeTabs
case 'People' : $title = $this->renderer->np__('account-type', 'People (%d)' , 'People (%d)' , $account_type['count']); break; case 'People' : $title = $this->renderer->np__('account-type', 'People (%d)' , 'People (%d)' , $account_type['count']); break;
case 'News' : $title = $this->renderer->np__('account-type', 'News (%d)' , 'News (%d)' , $account_type['count']); break; case 'News' : $title = $this->renderer->np__('account-type', 'News (%d)' , 'News (%d)' , $account_type['count']); break;
case 'Organization': $title = $this->renderer->np__('account-type', 'Organization (%d)', 'Organizations (%d)', $account_type['count']); break; case 'Organization': $title = $this->renderer->np__('account-type', 'Organization (%d)', 'Organizations (%d)', $account_type['count']); break;
case 'Forum' : $title = $this->renderer->np__('account-type', 'Forum (%d)' , 'Forums (%d)' , $account_type['count']); break; // Kept for backward compatibility
case 'Forum' :
case 'Group' : $title = $this->renderer->np__('account-type', 'Group (%d)' , 'Groups (%d)' , $account_type['count']); break;
default: $title = $this->renderer->np__('account-type', $account_type['account_type']. ' (%d)', $account_type['account_type']. ' (%d)', $account_type['count']); default: $title = $this->renderer->np__('account-type', $account_type['account_type']. ' (%d)', $account_type['account_type']. ' (%d)', $account_type['count']);
} }

View file

@ -31,31 +31,31 @@ msgstr ""
msgid "Last" msgid "Last"
msgstr "" msgstr ""
#: src\classes\Controllers\Web\Directory.php:73 #: src\classes\Controllers\Web\Directory.php:85
msgid "People" msgid "People"
msgstr "" msgstr ""
#: src\classes\Controllers\Web\Search.php:64 #: src\classes\Controllers\Web\Search.php:72
msgctxt "field" msgctxt "field"
msgid "Language" msgid "Language"
msgstr "" msgstr ""
#: src\classes\Controllers\Web\Search.php:65 #: src\classes\Controllers\Web\Search.php:73
msgctxt "field" msgctxt "field"
msgid "Locality" msgid "Locality"
msgstr "" msgstr ""
#: src\classes\Controllers\Web\Search.php:66 #: src\classes\Controllers\Web\Search.php:74
msgctxt "field" msgctxt "field"
msgid "Region" msgid "Region"
msgstr "" msgstr ""
#: src\classes\Controllers\Web\Search.php:67 #: src\classes\Controllers\Web\Search.php:75
msgctxt "field" msgctxt "field"
msgid "Country" msgid "Country"
msgstr "" msgstr ""
#: src\classes\Controllers\Web\Servers.php:90 #: src\classes\Controllers\Web\Servers.php:105
msgid "Public Servers" msgid "Public Servers"
msgstr "" msgstr ""
@ -105,11 +105,11 @@ msgid_plural "%d results for \"%s\""
msgstr[0] "" msgstr[0] ""
msgstr[1] "" msgstr[1] ""
#: src\templates\servers.phtml:2 #: src\templates\servers.phtml:7
msgid "Top servers pagination" msgid "Top servers pagination"
msgstr "" msgstr ""
#: src\templates\servers.phtml:12 #: src\templates\servers.phtml:17
msgid "Bottom servers pagination" msgid "Bottom servers pagination"
msgstr "" msgstr ""
@ -126,24 +126,27 @@ msgid "Filter by country"
msgstr "" msgstr ""
#: src\templates\sub\profile.phtml:31 #: src\templates\sub\profile.phtml:31
#: src\templates\sub\profile.phtml:35
#: src\templates\sub\profile.phtml:39
msgctxt "verb" msgctxt "verb"
msgid "Follow" msgid "Follow"
msgstr "" msgstr ""
#: src\templates\layout.phtml:65 #: src\templates\layout.phtml:65
#: src\templates\sub\profile.phtml:47 #: src\templates\sub\profile.phtml:57
msgid "Language" msgid "Language"
msgstr "" msgstr ""
#: src\templates\sub\profile.phtml:50 #: src\templates\sub\profile.phtml:60
#: src\templates\widget\popularserverlanguages.phtml:2
msgid "Filter by language" msgid "Filter by language"
msgstr "" msgstr ""
#: src\templates\sub\profile.phtml:56 #: src\templates\sub\profile.phtml:66
msgid "Location" msgid "Location"
msgstr "" msgstr ""
#: src\templates\sub\profile.phtml:69 #: src\templates\sub\profile.phtml:79
msgid "Search Tag" msgid "Search Tag"
msgstr "" msgstr ""
@ -175,15 +178,15 @@ msgstr ""
msgid "Outdated Version" msgid "Outdated Version"
msgstr "" msgstr ""
#: src\templates\sub\server.phtml:72 #: src\templates\sub\server.phtml:69
msgid "Admin" msgid "Admin"
msgstr "" msgstr ""
#: src\templates\sub\server.phtml:79 #: src\templates\sub\server.phtml:76
msgid "No description provided" msgid "No description provided"
msgstr "" msgstr ""
#: src\templates\sub\server.phtml:82 #: src\templates\sub\server.phtml:79
msgid "Visit Server" msgid "Visit Server"
msgstr "" msgstr ""
@ -191,7 +194,7 @@ msgstr ""
msgid "Popular Countries" msgid "Popular Countries"
msgstr "" msgstr ""
#: src\templates\widget\popularlanguages.phtml:2 #: src\templates\widget\popularprofilelanguages.phtml:2
msgid "Popular Languages" msgid "Popular Languages"
msgstr "" msgstr ""
@ -220,13 +223,6 @@ msgid_plural "People (%d)"
msgstr[0] "" msgstr[0] ""
msgstr[1] "" msgstr[1] ""
#: src\classes\Views\Widget\AccountTypeTabs.php:59
msgctxt "account-type"
msgid "Forum (%d)"
msgid_plural "Forums (%d)"
msgstr[0] ""
msgstr[1] ""
#: src\templates\layout.phtml:97 #: src\templates\layout.phtml:97
msgid "Stats" msgid "Stats"
msgstr "" msgstr ""
@ -332,15 +328,30 @@ msgstr[1] ""
msgid "None" msgid "None"
msgstr "" msgstr ""
#: src\templates\sub\server.phtml:59 #: src\templates\sub\server.phtml:58
#: src\templates\sub\server.phtml:63 #: src\templates\sub\server.phtml:62
msgid "Registration Policy" msgid "Registration Policy"
msgstr "" msgstr ""
#: src\templates\sub\server.phtml:60 #: src\templates\sub\server.phtml:59
msgid "By Approval" msgid "By Approval"
msgstr "" msgstr ""
#: src\templates\sub\server.phtml:64 #: src\templates\sub\server.phtml:63
msgid "Open" msgid "Open"
msgstr "" msgstr ""
#: src\classes\Views\Widget\AccountTypeTabs.php:61
msgctxt "account-type"
msgid "Group (%d)"
msgid_plural "Groups (%d)"
msgstr[0] ""
msgstr[1] ""
#: src\templates\servers.phtml:3
msgid "Filtered by language:"
msgstr ""
#: src\templates\servers.phtml:3
msgid "Clear language filter"
msgstr ""