Compare commits

...

43 Commits

Author SHA1 Message Date
Hypolite Petovan cfff03f6e2 [v2.4.2] Bump version number for release 2024-03-07 14:18:49 -05:00
Tobias Diekershoff 4524ad166b Merge pull request 'Move Visit server link to server name' (#103) from MrPetovan/friendica-directory:enhancement/100-move-visit-server-link into stable
Reviewed-on: #103
2024-03-07 15:48:26 +01:00
Hypolite Petovan 2ffb047736 Move Visit server link to server name 2024-03-07 09:42:45 -05:00
heluecht f4bff37432 Merge pull request 'Update source code link to point to Friendica's Forgejo' (#101) from MrPetovan/friendica-directory:enhancement/97-source-code-link into stable
Reviewed-on: #101
2024-03-07 15:36:49 +01:00
heluecht 62c6c0f1cc Merge pull request 'Change icon for Approval registration policy from dungeon door to stamp' (#102) from MrPetovan/friendica-directory:enhancement/99-unstable-version-icon into stable
Reviewed-on: #102
2024-03-07 15:35:43 +01:00
Hypolite Petovan 5f79768a6b Change icon for unstable version from poop to bug 2024-03-07 09:23:51 -05:00
Hypolite Petovan 08950be588 Change icon for Approval registration policy from dungeon door to stamp 2024-03-07 09:23:36 -05:00
Hypolite Petovan 9d77067e79 Update source code link to point to Friendica's Forgejo 2024-03-07 09:21:03 -05:00
Tobias Diekershoff 13b95e22da Merge pull request '[Composer] Change gofabian/negotiation-middleware dependency requirement to support PHP 8.2' (#96) from MrPetovan/friendica-directory:bug/php-8 into stable
Reviewed-on: #96
2023-08-09 07:01:21 +02:00
Hypolite Petovan 9d296b9f5d [Composer] Change gofabian/negotiation-middleware dependency requirement to support PHP 8
- Add now-explicit laminas/laminas-zendframework-bridge dependency
- Bump PHP version requirement to 7.3.0
- Updating willdurand/negotiation (v2.3.1 => 3.1.0) (PHP 8 compatibility)
- Updating psr/http-message (1.0.1 => 1.1)
- Removing gofabian/negotiation-middleware (v0.1.3)
- Installing gofabian/negotiation-middleware (dev-master 4d3cda5)
- Updating gettext/languages (2.9.0 => 2.10.0)
- Updating gettext/gettext (v4.8.6 => v4.8.8)
- Updating guzzlehttp/psr7 (1.8.5 => 1.9.1)
- Updating guzzlehttp/promises (1.5.1 => 1.5.3)
- Updating symfony/polyfill-php72 (v1.26.0 => v1.27.0)
- Updating symfony/polyfill-intl-normalizer (v1.26.0 => v1.27.0)
- Updating symfony/polyfill-intl-idn (v1.26.0 => v1.27.0)
- Updating guzzlehttp/guzzle (6.5.6 => 6.5.8)
- Updating laminas/laminas-escaper (2.6.1 => 2.9.0)
- Updating laminas/laminas-zendframework-bridge (1.1.1 => 1.4.1)
- Updating masterminds/html5 (2.7.5 => 2.8.0)
- Updating monolog/monolog (1.26.1 => 1.27.1)
- Updating psr/container (1.0.0 => 1.1.1)
- Updating pimple/pimple (v3.2.3 => v3.5.0)
- Updating slim/slim (3.12.3 => 3.12.5)
- Updating pear/pear-core-minimal (v1.10.11 => v1.10.13)
2023-07-31 01:24:50 +02:00
Hypolite Petovan bf85c8f986 Catch rare exception receiving line folding characters in header value of redirected request 2023-07-31 01:17:33 +02:00
Hypolite Petovan 064fd922e7 Add default profile picture path dependency
- Update default profile picture
2023-07-31 01:11:33 +02:00
Hypolite Petovan 95ffadb19f Fix ternary operator ambiguity deprecation in Utils\L10n 2023-07-31 01:10:37 +02:00
Tobias Diekershoff 8bd1cb11ae Merge pull request 'Rename "forum" to "group"' (#94) from MrPetovan/friendica-directory:task/rename-forum-to-group into stable
Reviewed-on: #94
2023-06-05 06:37:27 +02:00
Hypolite Petovan aade2ec534 Rename "forum" to "group"
- This reflects a change in Friendica Core
2023-06-04 00:16:38 -04:00
Hypolite Petovan f854d7d5f7 Fix several PHP messages
- Add logging for exceptions
2023-03-12 17:49:44 -04:00
Tobias Diekershoff 230f17ef36 Merge pull request 'Normalize HTTP client user agent' (#90) from MrPetovan/friendica-directory:task/89-normalize-user-agent into stable
Reviewed-on: #90
2022-06-07 05:40:29 +00:00
Hypolite Petovan 30f6e6f5de [Composer] Remove unused dependency byjg/webrequest 2022-06-06 02:23:57 -04:00
Hypolite Petovan d1a72232b3 Replace ByJG\WebRequest by GuzzleHttp\ClientInterface 2022-06-06 02:22:56 -04:00
Hypolite Petovan 9ff681a460 Fix database error with false bolean value in profile table 2022-06-06 02:22:39 -04:00
Hypolite Petovan 0ee5bf55b1 Replace direct curl uses with Guzzle HTTP client
- Add http dependency with custom User Agent
- Simplify profile poll to remove the second profile call to check availability
- Remove obsolete Network::fetchURL and Network::testURL
2022-06-06 02:22:37 -04:00
Hypolite Petovan 5829108c0e [Composer] Require guzzlehttp/guzzle:^6.5 2022-06-06 01:32:00 -04:00
Hypolite Petovan 91aa66ed77 [v2.4.1] Bump version number for release 2022-05-12 14:18:43 -04:00
Hypolite Petovan 7fdbaa3678 Don't encode the zrl parameter in external links
- Fix a "Forbidden" issue with /remote_follow links
2022-05-12 14:18:19 -04:00
Hypolite Petovan df660b66c9 [v2.4.0] Bump version number for release 2022-05-12 09:15:19 -04:00
heluecht 3f38b3adea Merge pull request 'Remove obsolete profile.dfrn_request field' (#87) from MrPetovan/friendica-directory:task/86-remove-dfrn_request into stable
Reviewed-on: #87
2022-05-11 04:17:41 +00:00
Hypolite Petovan e65bb660ce [Database v0010] Drop unused column profile.dfrn_request 2022-05-07 16:10:43 -04:00
Hypolite Petovan a5700cb2c9 Remove references to dfrn_request 2022-05-07 16:10:43 -04:00
Hypolite Petovan 2627b54349 Replace dfrn_request by subscribe URL when available for the follow link
- Falls back to the `/remote_follow` module available since Friendica version 2020.03
- Falls back to the profile URL
- Remove unused atlas dependency in a couple API controllers
2022-05-07 16:10:42 -04:00
Hypolite Petovan 8988ad9f9d Add subscribe URL retrieval to server poll 2022-05-07 16:09:30 -04:00
Hypolite Petovan 7d5012e72e [Database v0009] Add server.subscribe_url field 2022-05-07 16:09:30 -04:00
Hypolite Petovan b0142f6ab2 Add optional version parameter to console updatedb 2022-05-07 16:09:29 -04:00
Hypolite Petovan cd809f7646 Remove mention of non-existent console parameters in Install and UpdateDb 2022-05-07 16:09:29 -04:00
Hypolite Petovan 2aba91d42c Add HTML link to profile to account name
- Normalize white space in HTML
2022-05-07 16:09:27 -04:00
Hypolite Petovan 2e84f5aa7b Merge pull request 'added DA DK translation THX atjn' (#88) from tobias/friendica-directory:20220501-daDK into stable
Reviewed-on: #88
2022-05-04 21:45:51 +00:00
Tobias Diekershoff 1ebddb042f
PL translation updated THX strebski 2022-05-03 09:17:55 +02:00
Tobias Diekershoff 0344c77336
added DA DK translation THX atjn 2022-05-01 20:17:13 +02:00
Hypolite Petovan 5a16bcb57c Merge pull request 'PL translation updated THX strebski' (#85) from tobias/friendica-directory:20220318-pl into stable
Reviewed-on: #85
2022-04-25 11:27:41 +00:00
Tobias Diekershoff 146d4e6374
PL translation updated THX strebski 2022-03-18 17:41:59 +01:00
Hypolite Petovan ef91f43be0 [v2.3.5] Bump version number for release 2022-01-23 06:13:16 -05:00
Hypolite Petovan a3a5bd8ab4 Merge pull request 'added SV translation THX Kristoffer Grundström' (#84) from tobias/friendica-directory:20220122-sv into stable
Reviewed-on: #84
2022-01-23 01:27:15 +00:00
Tobias Diekershoff c34fcd11f8 added Swedish to the languages array 2022-01-22 19:09:24 +01:00
Tobias Diekershoff 1356001334 added SV translation THX Kristoffer Grundström 2022-01-22 19:08:37 +01:00
60 changed files with 3813 additions and 1854 deletions

View File

@ -1 +1 @@
2.3.4
2.4.2

View File

@ -22,10 +22,11 @@
"boronczyk/localization-middleware": "^1.4",
"byjg/migration": "^4.0",
"byjg/uri": "^1.0.4",
"byjg/webrequest": "^1.0",
"gettext/gettext": "^4.6",
"gofabian/negotiation-middleware": "^0.1.3",
"gofabian/negotiation-middleware": "dev-master",
"guzzlehttp/guzzle": "^6.5",
"laminas/laminas-escaper": "^2.6",
"laminas/laminas-zendframework-bridge": "^1.4",
"masterminds/html5": "^2.3",
"monolog/monolog": "^1.17",
"mrpetovan/net_ping": "^1.2",
@ -55,7 +56,7 @@
},
"config": {
"platform": {
"php": "7.1.0"
"php": "7.3.0"
},
"process-timeout" : 0,
"autoloader-suffix": "FriendicaDirectory",

1079
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -16,7 +16,7 @@ Accept: application/json
```
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:
- `q`: The search query.
- `page` (optional): The page number, default is 1.
@ -44,10 +44,11 @@ Example:
"region": "New York",
"country": "USA",
"profile_url": "https://friendica.mrpetovan.com/profile/hypolite",
"dfrn_request": "https://friendica.mrpetovan.com/dfrn_request/hypolite",
"photo": "https://friendica.mrpetovan.com/photo/27330388315ae4ed2b03e3c116980490-4.jpg?ts=1541567135",
"tags": "videogame gaming boardgame politics philosophy development programming php",
"last_activity": "2018-45"
"last_activity": "2018-45",
"remote_follow": "https://friendica.mrpetovan.com/remote_follow/hypolite",
"subscribe": null
},
...
]

Binary file not shown.

Before

Width:  |  Height:  |  Size: 325 B

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

@ -11,10 +11,6 @@ use Psr\Http\Message\ServerRequestInterface;
*/
class MatchSearch
{
/**
* @var \Atlas\Pdo\Connection
*/
private $atlas;
/**
* @var \Friendica\Directory\Models\Profile
*/
@ -25,12 +21,10 @@ class MatchSearch
private $l10n;
public function __construct(
\Atlas\Pdo\Connection $atlas,
\Friendica\Directory\Models\Profile $profileModel,
\Gettext\TranslatorInterface $l10n
)
{
$this->atlas = $atlas;
$this->profileModel = $profileModel;
$this->l10n = $l10n;
}
@ -53,7 +47,13 @@ class MatchSearch
$values = ['query' => $query];
$profiles = $this->profileModel->getListForDisplay($pager->getItemsPerPage(), $pager->getStart(), $sql_where, $values);
$profiles = $this->profileModel->getListForDisplay(
null,
$pager->getItemsPerPage(),
$pager->getStart(),
$sql_where,
$values,
);
$results = [];
foreach ($profiles as $profile) {

View File

@ -14,12 +14,18 @@ class Photo
* @var \Atlas\Pdo\Connection
*/
private $atlas;
/**
* @var string
*/
private $defaultProfilePictureSmallPath;
public function __construct(
\Atlas\Pdo\Connection $atlas
\Atlas\Pdo\Connection $atlas,
string $defaultProfilePictureSmallPath
)
{
$this->atlas = $atlas;
$this->defaultProfilePictureSmallPath = $defaultProfilePictureSmallPath;
}
public function render(Request $request, Response $response, array $args): Response
@ -30,7 +36,7 @@ class Photo
);
if (!$data) {
$data = file_get_contents('public/images/default-profile-sm.jpg');
$data = file_get_contents($this->defaultProfilePictureSmallPath);
}
//Try and cache our result.

View File

@ -11,10 +11,6 @@ use Psr\Http\Message\ServerRequestInterface;
*/
class Search
{
/**
* @var \Atlas\Pdo\Connection
*/
private $atlas;
/**
* @var \Friendica\Directory\Models\Profile
*/
@ -25,12 +21,10 @@ class Search
private $l10n;
public function __construct(
\Atlas\Pdo\Connection $atlas,
\Friendica\Directory\Models\Profile $profileModel,
\Gettext\TranslatorInterface $l10n
)
{
$this->atlas = $atlas;
$this->profileModel = $profileModel;
$this->l10n = $l10n;
}
@ -64,7 +58,13 @@ AND `account_type` = :account_type';
$values['account_type'] = $account_type;
}
$profiles = $this->profileModel->getListForDisplay($pager->getItemsPerPage(), $pager->getStart(), $sql_where, $values);
$profiles = $this->profileModel->getListForDisplay(
null,
$pager->getItemsPerPage(),
$pager->getStart(),
$sql_where,
$values,
);
$count = $this->profileModel->getCountForDisplay($sql_where, $values);

View File

@ -31,9 +31,9 @@ class Install extends \Asika\SimpleConsole\Console
protected function getHelp()
{
$help = <<<HELP
console install - Install directory
console install - Install wizard
Usage
bin/console install <server_url> [-h|--help|-?] [-v]
bin/console install [-h|--help|-?] [-v]
Description
Install directory

View File

@ -37,12 +37,14 @@ class UpdateDb extends \Asika\SimpleConsole\Console
$help = <<<HELP
console updatedb - Update database schema
Usage
bin/console updatedb <server_url> [-h|--help|-?] [-v]
bin/console updatedb [<version>] [-h|--help|-?] [-v]
Description
Update database schema
Options
<version> Optional target version number, default is the latest version.
Do not use this parameter if you're not sure what you're doing, it will result in data loss!
-h|--help|-? Show help information
-v Show more debug information.
HELP;
@ -56,16 +58,38 @@ HELP;
return 0;
}
if (count($this->args) > 1) {
if (count($this->args) > 2) {
throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
}
$this->out('Updating database schema to latest version...');
$currentVersion = $this->migration->getCurrentVersion()['version'];
$this->migration->up();
$this->out('Database schema currently in version ' . $currentVersion);
$this->out('Database schema migrated to version ' . $this->migration->getCurrentVersion()['version']);
if (count($this->args) == 1) {
$this->out('Updating database schema to latest version...');
$this->migration->up();
$this->out('Database schema migrated to version ' . $this->migration->getCurrentVersion()['version']);
return 0;
}
$target = $this->getArgument(1);
if ($target > $currentVersion) {
$this->out('Updating database schema to version ' . $target);
$this->migration->up($target);
$this->out('Database schema migrated up to version ' . $this->migration->getCurrentVersion()['version']);
return 0;
}
if ($target < $currentVersion) {
$this->out('Downgrading database schema to version ' . $target);
$this->migration->down($target);
$this->out('Database schema migrated down to version ' . $this->migration->getCurrentVersion()['version']);
return 0;
}
$this->out('Target version equal to current version, exiting.');
return 0;
}
}

View File

@ -18,6 +18,10 @@ class Directory extends BaseController
* @var \Atlas\Pdo\Connection
*/
private $atlas;
/**
* @var \Friendica\Directory\Models\Server
*/
private $serverModel;
/**
* @var \Friendica\Directory\Models\Profile
*/
@ -37,6 +41,7 @@ class Directory extends BaseController
public function __construct(
\Atlas\Pdo\Connection $atlas,
\Friendica\Directory\Models\Server $serverModel,
\Friendica\Directory\Models\Profile $profileModel,
\Friendica\Directory\Views\Widget\AccountTypeTabs $accountTypeTabs,
\Friendica\Directory\Views\PhpRenderer $renderer,
@ -44,6 +49,7 @@ class Directory extends BaseController
)
{
$this->atlas = $atlas;
$this->serverModel = $serverModel;
$this->profileModel = $profileModel;
$this->accountTypeTabs = $accountTypeTabs;
$this->renderer = $renderer;
@ -58,16 +64,22 @@ class Directory extends BaseController
$pager = new Pager($this->l10n, $request, 20);
$condition = '';
$sql_where = '';
$values = [];
if (!empty($args['account_type'])) {
$condition = '`account_type` = :account_type';
$sql_where = '`account_type` = :account_type';
$values = ['account_type' => $args['account_type']];
}
$profiles = $this->profileModel->getListForDisplay($pager->getItemsPerPage(), $pager->getStart(), $condition, $values);
$profiles = $this->profileModel->getListForDisplay(
$this->serverModel->getSubscribeUrlByProfile($request->getQueryParam('zrl', '')),
$pager->getItemsPerPage(),
$pager->getStart(),
$sql_where,
$values,
);
$count = $this->profileModel->getCountForDisplay($condition, $values);
$count = $this->profileModel->getCountForDisplay($sql_where, $values);
$vars = [
'title' => $this->l10n->gettext('People'),
@ -82,7 +94,6 @@ class Directory extends BaseController
$content = $this->renderer->fetch('directory.phtml', $vars);
// Render index view
return ['content' => $content];
}
}

View File

@ -13,6 +13,10 @@ class Search extends BaseController
* @var \Atlas\Pdo\Connection
*/
private $atlas;
/**
* @var \Friendica\Directory\Models\Server
*/
private $serverModel;
/**
* @var \Friendica\Directory\Models\Profile
*/
@ -32,6 +36,7 @@ class Search extends BaseController
public function __construct(
\Atlas\Pdo\Connection $atlas,
\Friendica\Directory\Models\Server $serverModel,
\Friendica\Directory\Models\Profile $profileModel,
\Friendica\Directory\Views\Widget\AccountTypeTabs $accountTypeTabs,
\Friendica\Directory\Views\PhpRenderer $renderer,
@ -39,6 +44,7 @@ class Search extends BaseController
)
{
$this->atlas = $atlas;
$this->serverModel = $serverModel;
$this->profileModel = $profileModel;
$this->accountTypeTabs = $accountTypeTabs;
$this->renderer = $renderer;
@ -89,7 +95,13 @@ AND `account_type` = :account_type';
$values['account_type'] = $account_type;
}
$profiles = $this->profileModel->getListForDisplay($pager->getItemsPerPage(), $pager->getStart(), $sql_where, $values);
$profiles = $this->profileModel->getListForDisplay(
$this->serverModel->getSubscribeUrlByProfile($request->getQueryParam('zrl', '')),
$pager->getItemsPerPage(),
$pager->getStart(),
$sql_where,
$values,
);
$count = $this->profileModel->getCountForDisplay($sql_where, $values);
@ -106,7 +118,6 @@ AND `account_type` = :account_type';
$content = $this->renderer->fetch('search.phtml', $vars);
// Render index view
return ['content' => $content, 'noNavSearch' => true];
}
}

View File

@ -66,7 +66,7 @@ class Servers extends BaseController
$sql_where = '';
$values = [];
if ($args['language']) {
if (!empty($args['language'])) {
$sql_where .= '
AND LEFT(`language`, 2) = LEFT(:language, 2)';
$values['language'] = $args['language'];
@ -104,7 +104,7 @@ AND NOT `hidden`
$vars = [
'title' => $this->l10n->gettext('Public Servers'),
'total' => $count,
'language' => $args['language'],
'language' => $args['language'] ?? null,
'servers' => $servers,
'pager' => $pager->renderFull($count),
'stable_version' => $stable_version,

View File

@ -7,6 +7,13 @@ namespace Friendica\Directory\Models;
*/
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
{
$this->atlas->perform('DELETE FROM `photo` WHERE `profile_id` = :profile_id',
@ -74,7 +81,7 @@ class Profile extends \Friendica\Directory\Model
];
}
public function getListForDisplay(int $limit = 30, int $start = 0, string $condition = '', array $values = []): array
public function getListForDisplay(string $subscribeUrl = null, int $limit = 30, int $start = 0, string $condition = '', array $values = []): array
{
if ($condition) {
$condition = 'AND ' . $condition;
@ -86,8 +93,8 @@ class Profile extends \Friendica\Directory\Model
]);
$stmt = 'SELECT p.`id`, p.`name`, p.`username`, p.`addr`, p.`account_type`, p.`language`,
p.`pdesc`, p.`locality`, p.`region`, p.`country`, p.`profile_url`, p.`dfrn_request`,
p.`photo`, p.`tags`, p.`last_activity`
p.`pdesc`, p.`locality`, p.`region`, p.`country`, p.`profile_url`,
p.`photo`, p.`tags`, p.`last_activity`, s.`version`
FROM `profile` p
JOIN `server` s ON s.`id` = p.`server_id` AND s.`available` AND NOT s.`hidden`
WHERE p.`available`
@ -98,6 +105,12 @@ class Profile extends \Friendica\Directory\Model
LIMIT :start, :limit';
$profiles = $this->atlas->fetchAll($stmt, $values);
array_walk($profiles, function (array &$profile) use ($subscribeUrl) {
$profile['remote_follow'] = version_compare($profile['version'], '2020.03', '>=') ? str_replace('/profile/', '/remote_follow/', $profile['profile_url']) : null;
$profile['subscribe'] = $subscribeUrl ? str_replace('{uri}', urlencode($profile['profile_url']), $subscribeUrl): null;
unset($profile['version']);
});
return $profiles;
}

View File

@ -41,4 +41,20 @@ class Server extends \Friendica\Directory\Model
'alias' => strtolower($server_alias)
]);
}
/**
* Returns the complete subscribe URL of the given profile URL if we have it for the related server
*
* @param string $profile_url
* @return mixed|null
*/
public function getSubscribeUrlByProfile(string $profile_url)
{
if (preg_match('#^(.+)/profile/#', $profile_url, $matches)) {
$server = $this->getByUrlAlias($matches[1]);
return $server['subscribe_url'] ?? null;
}
return null;
}
}

View File

@ -10,9 +10,9 @@ use Friendica\Directory\Utils\Network;
class Directory
{
/**
* @var \Atlas\Pdo\Connection
* @var \GuzzleHttp\ClientInterface
*/
private $atlas;
private $http;
/**
* @var \Friendica\Directory\Models\ProfilePollQueue
*/
@ -30,12 +30,12 @@ class Directory
];
public function __construct(
\Atlas\Pdo\Connection $atlas,
\GuzzleHttp\ClientInterface $http,
\Friendica\Directory\Models\ProfilePollQueue $profilePollQueueModel,
\Psr\Log\LoggerInterface $logger,
array $settings)
{
$this->atlas = $atlas;
$this->http = $http;
$this->profilePollQueueModel = $profilePollQueueModel;
$this->logger = $logger;
$this->settings = array_merge($this->settings, $settings);
@ -82,35 +82,7 @@ class Directory
$path = '/sync/pull/since/' . $last_polled;
}
//Prepare the CURL call.
$handle = curl_init();
$options = array(
//Timeouts
CURLOPT_TIMEOUT => max($this->settings['probe_timeout'], 1), //Minimum of 1 second timeout.
CURLOPT_CONNECTTIMEOUT => 1,
//Redirecting
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 8,
//SSL
CURLOPT_SSL_VERIFYPEER => true,
// CURLOPT_VERBOSE => true,
// CURLOPT_CERTINFO => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_PROTOCOLS => CURLPROTO_HTTP | CURLPROTO_HTTPS,
//Basic request
CURLOPT_USERAGENT => Network::USER_AGENT,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => $directory_url . $path
);
curl_setopt_array($handle, $options);
$this->logger->info('Pulling profiles from directory URL: ' . $directory_url . $path);
//Probe the site.
$pull_data = curl_exec($handle);
//Done with CURL now.
curl_close($handle);
$pull_data = $this->http->get($directory_url . $path, ['timeout' => max($this->settings['probe_timeout'], 1)])->getBody()->getContents();
$data = json_decode($pull_data, true);

View File

@ -2,14 +2,15 @@
namespace Friendica\Directory\Pollers;
use Friendica\Directory\Utils\Network;
use Friendica\Directory\Models;
use Friendica\Directory\Utils;
use GuzzleHttp\Exception\RequestException;
/**
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class Profile
{
const PROFILE_MISSING_REQUEST = 1;
const PROFILE_MISSING_CONFIRM = 2;
const PROFILE_MISSING_NOTIFY = 4;
const PROFILE_MISSING_POLL = 8;
@ -20,12 +21,17 @@ class Profile
private $atlas;
/**
* @var \Friendica\Directory\Models\Server
* @var \GuzzleHttp\ClientInterface
*/
private $http;
/**
* @var Models\Server
*/
private $serverModel;
/**
* @var \Friendica\Directory\Models\Profile
* @var Models\Profile
*/
private $profileModel;
@ -44,13 +50,15 @@ class Profile
public function __construct(
\Atlas\Pdo\Connection $atlas,
\Friendica\Directory\Models\Server $serverModel,
\Friendica\Directory\Models\Profile $profileModel,
\GuzzleHttp\ClientInterface $http,
Models\Server $serverModel,
Models\Profile $profileModel,
\Psr\Log\LoggerInterface $logger,
array $settings
)
{
$this->atlas = $atlas;
$this->http = $http;
$this->serverModel = $serverModel;
$this->profileModel = $profileModel;
$this->logger = $logger;
@ -75,12 +83,12 @@ class Profile
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);
return false;
}
$profileUriInfo = \Friendica\Directory\Models\Profile::extractInfoFromProfileUrl($profile_uri);
$profileUriInfo = Models\Profile::extractInfoFromProfileUrl($profile_uri);
if (!$profileUriInfo) {
$this->logger->warning('Profile URI invalid');
return false;
@ -123,25 +131,38 @@ class Profile
);
}
//Skip the profile scrape?
$noscrape = $server['noscrape_url'];
$available = false;
$params = [];
if ($noscrape) {
//Skip the profile scrape?
if ($server['noscrape_url']) {
$this->logger->debug('Calling ' . $server['noscrape_url'] . '/' . $username);
$params = \Friendica\Directory\Utils\Scrape::retrieveNoScrapeData($server['noscrape_url'] . '/' . $username);
$noscrape = !!$params; //If the result was false, do a scrape after all.
try {
$params = Utils\Scrape::retrieveNoScrapeData($this->http, $server['noscrape_url'] . '/' . $username);
} catch (RequestException $e) {
$this->logger->info('Request failed with error code ' . $e->getCode());
} catch (\Throwable $e) {
$this->logger->warning('Request failed with exception ' . get_class($e));
$this->logger->warning(var_export($e, true));
}
$available = !!$params; //If the result was false, do a scrape after all.
}
$available = true;
if ($noscrape) {
$available = Network::testURL($profile_uri);
$this->logger->debug('Testing ' . $profile_uri . ': ' . ($available?'Success':'Failure'));
} else {
$this->logger->notice('Parsing profile page ' . $profile_uri);
$params = \Friendica\Directory\Utils\Scrape::retrieveProfileData($profile_uri);
if (!$available) {
$this->logger->info('Parsing profile page ' . $profile_uri);
try {
$params = Utils\Scrape::retrieveProfileData($this->http, $profile_uri);
} catch (RequestException $e) {
$this->logger->info('Request failed with error code ' . $e->getCode());
} catch (\Throwable $e) {
$this->logger->warning('Request failed with exception ' . get_class($e));
$this->logger->warning(var_export($e, true));
}
$params['language'] = $server['language'];
$available = !empty($params['fn']);
}
// Empty result is due to an offline site.
@ -177,9 +198,6 @@ class Profile
// This is most likely a problem with the site configuration. Ignore.
if ($error = self::validateParams($params)) {
$this->logger->warning('Poll aborted, parameters invalid.', ['params' => $params]);
if ($error & Profile::PROFILE_MISSING_REQUEST) {
$this->logger->notice('dfrn-request parameter is empty.');
}
if ($error & Profile::PROFILE_MISSING_CONFIRM) {
$this->logger->notice('dfrn-confirm parameter is empty.');
}
@ -193,16 +211,22 @@ class Profile
return false;
}
switch ($params['account-type'] ?? 0) {
case 1: $account_type = 'News'; break;
case 2: $account_type = 'Organization'; break;
case 3: $account_type = 'Forum'; break;
case 0:
default:
switch ($params['account-type'] ?? Models\Profile::ACCOUNT_TYPE_PERSON) {
case Models\Profile::ACCOUNT_TYPE_ORGANISATION: $account_type = 'Organization'; break;
case Models\Profile::ACCOUNT_TYPE_NEWS : $account_type = 'News'; break;
case Models\Profile::ACCOUNT_TYPE_COMMUNITY : $account_type = 'Group'; break;
case Models\Profile::ACCOUNT_TYPE_RELAY : $account_type = 'Relay'; break;
case Models\Profile::ACCOUNT_TYPE_DELETED : $account_type = 'Deleted'; break;
case Models\Profile::ACCOUNT_TYPE_PERSON: {
$account_type = 'People';
if (!empty($params['comm'])) {
$account_type = 'Forum';
$account_type = 'Group';
}
break;
}
default: $account_type = 'Unknown'; break;
}
$tags = [];
@ -232,7 +256,6 @@ class Profile
'region' => $params['region'] ?? '',
'country' => $params['country-name'] ?? '',
'profile_url' => $profile_uri,
'dfrn_request' => $params['dfrn-request'] ?? null,
'photo' => $params['photo'],
'tags' => implode(' ', $tags),
'addr' => $addr,
@ -240,7 +263,7 @@ class Profile
'language' => $params['language'] ?? null,
'filled_fields'=> $filled_fields,
'last_activity'=> $params['last-activity'] ?? null,
'available' => $available,
'available' => [$available, \PDO::PARAM_BOOL],
];
$this->logger->debug(var_export($values, true));
@ -254,7 +277,6 @@ class Profile
`region` = :region,
`country` = :country,
`profile_url` = :profile_url,
`dfrn_request` = :dfrn_request,
`photo` = :photo,
`tags` = :tags,
`addr` = :addr,
@ -274,7 +296,6 @@ class Profile
`region` = :region,
`country` = :country,
`profile_url` = :profile_url,
`dfrn_request` = :dfrn_request,
`photo` = :photo,
`tags` = :tags,
`addr` = :addr,
@ -308,23 +329,27 @@ class Profile
$status = false;
if ($profile_id) {
$img_str = \Friendica\Directory\Utils\Network::fetchURL($params['photo'], true);
$img = new \Friendica\Directory\Utils\Photo($img_str);
if ($img->getImage()) {
$img->scaleImageSquare(80);
try {
$img_str = $this->http->get($params['photo'])->getBody()->getContents();
$img = new Utils\Photo($img_str);
if ($img->getImage()) {
$img->scaleImageSquare(80);
$this->atlas->perform('INSERT INTO `photo` SET
`profile_id` = :profile_id,
`data` = :data
ON DUPLICATE KEY UPDATE
`data` = :data',
[
'profile_id' => $profile_id,
'data' => $img->imageString()
]
);
$this->atlas->perform('INSERT INTO `photo` SET
`profile_id` = :profile_id,
`data` = :data
ON DUPLICATE KEY UPDATE
`data` = :data',
[
'profile_id' => $profile_id,
'data' => $img->imageString()
]
);
}
$status = true;
} catch (RequestException $e) {
$this->logger->info('Photo retrieval unsuccessful', ['url' => $params['photo'], 'code' => $e->getCode()]);
}
$status = true;
}
$submit_end = microtime(true);
@ -361,9 +386,6 @@ class Profile
private static function validateParams(array $params): int
{
$errors = 0;
if (empty($params['dfrn-request'])) {
$errors &= self::PROFILE_MISSING_REQUEST;
}
if (empty($params['dfrn-confirm'])) {
$errors &= self::PROFILE_MISSING_CONFIRM;
}

View File

@ -2,8 +2,9 @@
namespace Friendica\Directory\Pollers;
use ByJG\Util\WebRequest;
use Friendica\Directory\Utils\Network;
use GuzzleHttp\Psr7\Uri;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\TransferStats;
/**
* @author Hypolite Petovan <hypolite@mrpetovan.com>
@ -14,6 +15,10 @@ class Server
* @var \Atlas\Pdo\Connection
*/
private $atlas;
/**
* @var \GuzzleHttp\ClientInterface
*/
private $http;
/**
* @var \Friendica\Directory\Models\ProfilePollQueue
*/
@ -41,6 +46,7 @@ class Server
public function __construct(
\Atlas\Pdo\Connection $atlas,
\GuzzleHttp\ClientInterface $http,
\Friendica\Directory\Models\ProfilePollQueue $profilePollQueueModel,
\Friendica\Directory\Models\Server $serverModel,
\Psr\SimpleCache\CacheInterface $simplecache,
@ -48,6 +54,7 @@ class Server
array $settings)
{
$this->atlas = $atlas;
$this->http = $http;
$this->profilePollQueueModel = $profilePollQueueModel;
$this->serverModel = $serverModel;
$this->simplecache = $simplecache;
@ -147,6 +154,10 @@ class Server
$addons = $probe_result['data']['plugins'];
}
if (!empty($probe_result['data']['admin']['profile'])) {
$subscribe = $this->getSubscribeUrl($probe_result['data']['url'], $probe_result['data']['admin']['profile']);
}
$this->atlas->perform(
'UPDATE `server`
SET `available` = 1,
@ -161,20 +172,22 @@ class Server
`admin_name` = :admin_name,
`admin_profile` = :admin_profile,
`noscrape_url` = :noscrape_url,
`subscribe_url` = :subscribe_url,
`ssl_state` = :ssl_state
WHERE `id` = :server_id',
[
'server_id' => $server['id'],
'base_url' => strtolower($probe_result['data']['url']),
'name' => $probe_result['data']['site_name'],
'name' => substr($probe_result['data']['site_name'], 0, 255),
'language' => $probe_result['data']['language'] ?? null,
'version' => $probe_result['data']['version'],
'addons' => implode(',', $addons),
'reg_policy' => $probe_result['data']['register_policy'],
'info' => $probe_result['data']['info'],
'admin_name' => $probe_result['data']['admin']['name'],
'admin_profile' => $probe_result['data']['admin']['profile'],
'admin_name' => $probe_result['data']['admin']['name'] ?? null,
'admin_profile' => $probe_result['data']['admin']['profile'] ?? null,
'noscrape_url' => $probe_result['data']['no_scrape_url'] ?? null,
'subscribe_url' => $subscribe ?? null,
'ssl_state' => $probe_result['ssl_state']
]
);
@ -241,65 +254,50 @@ class Server
private function getProbeResult(string $base_url): array
{
//Prepare the CURL call.
$handle = curl_init();
$options = array(
//Timeouts
CURLOPT_TIMEOUT => max($this->settings['probe_timeout'], 1), //Minimum of 1 second timeout.
CURLOPT_CONNECTTIMEOUT => 1,
//Redirecting
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 8,
//SSL
CURLOPT_SSL_VERIFYPEER => true,
// CURLOPT_VERBOSE => true,
// CURLOPT_CERTINFO => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_PROTOCOLS => CURLPROTO_HTTP | CURLPROTO_HTTPS,
//Basic request
CURLOPT_USERAGENT => Network::USER_AGENT,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => $base_url . '/friendica/json'
);
curl_setopt_array($handle, $options);
$curl_info = null;
$options = [
'timeout' => max($this->settings['probe_timeout'], 1),
'on_stats' => function (TransferStats $transferStats) use (&$curl_info) {
$curl_info = $transferStats->getHandlerStats();
}
];
$sslcert_issues = false;
//Probe the site.
$probe_start = microtime(true);
$probe_data = curl_exec($handle);
$probe_end = microtime(true);
$probe_data = null;
try {
//Probe the site.
$probe_data = $this->http->get($base_url . '/friendica/json', $options)->getBody()->getContents();
} catch (RequestException $e) {
if (in_array($e->getHandlerContext()['errno'] ?? 0, [
60, //Could not authenticate certificate with known CA's
83 //Issuer check failed
])) {
$sslcert_issues = true;
//Check for SSL problems.
$curl_statuscode = curl_errno($handle);
$sslcert_issues = in_array($curl_statuscode, array(
60, //Could not authenticate certificate with known CA's
83 //Issuer check failed
));
//When it's the certificate that doesn't work, we probe again without strict SSL.
$options['verify'] = false;
//When it's the certificate that doesn't work.
if ($sslcert_issues) {
//Probe again, without strict SSL.
$options[CURLOPT_SSL_VERIFYPEER] = false;
//Replace the handle.
curl_close($handle);
$handle = curl_init();
curl_setopt_array($handle, $options);
//Probe.
$probe_start = microtime(true);
$probe_data = curl_exec($handle);
$probe_end = microtime(true);
//Store new status.
$curl_statuscode = curl_errno($handle);
$probe_start = microtime(true);
try {
$probe_data = $this->http->get($base_url . '/friendica/json', $options)->getBody()->getContents();
} catch(RequestException $e) {
// Collects 404, 500 errors
$this->logger->info('SSL-non-verified URL probe failed with error code: ' . $e->getCode());
}
} else {
$this->logger->info('SSL-verified URL probe failed with error code: ' . $e->getCode());
}
} catch (\InvalidArgumentException $e) {
$this->logger->error('Invalid argument provided to HTTP client', ['base_url' => $base_url, 'exception' => $e]);
return ['data' => false, 'time' => 0, 'curl_info' => [], 'ssl_state' => null];
}
//Gather more meta.
$time = round(($probe_end - $probe_start) * 1000);
$curl_info = curl_getinfo($handle);
$probe_end = microtime(true);
//Done with CURL now.
curl_close($handle);
$time = round(($probe_end - $probe_start) * 1000);
try {
$data = json_decode($probe_data, true);
@ -413,27 +411,24 @@ class Server
function discoverPoco($base_url): void
{
$pocoUrl = $base_url . '/poco';
$uri = Uri::withQueryValues(new Uri($base_url . '/poco'), ['fields' => 'urls', 'count' => 1000]);
$webrequest = new WebRequest($pocoUrl);
$pocoJsonData = $webrequest->get(['fields' => 'urls', 'count' => 1000]);
$this->logger->debug('WebRequest: ' . $webrequest->getLastFetchedUrl() . ' Status: ' . $webrequest->getLastStatus());
if ($webrequest->getLastStatus() != 200) {
$this->logger->info('Unsuccessful poco request: ' . $webrequest->getLastFetchedUrl());
try {
$response = $this->http->request('GET', $uri);
} catch (RequestException $e) {
$this->logger->info('Unsuccessful poco request: ' . $uri);
return;
}
try {
$pocoFetchData = json_decode($pocoJsonData);
$pocoFetchData = json_decode($response->getBody()->getContents());
} catch (\Throwable $e) {
$this->logger->notice('Invalid JSON string for PoCo URL: ' . $webrequest->getLastFetchedUrl());
$this->logger->notice('Invalid JSON string for PoCo URL: ' . $uri);
return;
}
if (!isset($pocoFetchData->entry)) {
$this->logger->notice('Invalid JSON structure for PoCo URL: ' . $webrequest->getLastFetchedUrl());
$this->logger->notice('Invalid JSON structure for PoCo URL: ' . $uri);
return;
}
@ -452,4 +447,45 @@ class Server
}
}
}
public function getSubscribeUrl($base_url, $profile)
{
$uri = Uri::withQueryValues(new Uri($base_url . '/xrd'), ['uri' => $profile]);
try {
$response = $this->http->request('GET', $uri, ['headers' => ['Accept' => 'application/jrd+json']]);
} catch (RequestException $e) {
$this->logger->info('Unsuccessful xrd request: ' . $uri);
return null;
}
$xrdJsonData = $response->getBody()->getContents();
$this->logger->debug('WebRequest: ' . $uri . ' Status: ' . $response->getStatusCode());
if ($response->getStatusCode() != 200) {
$this->logger->info('Unsuccessful XRD request: ' . $uri);
return null;
}
try {
$xrdData = json_decode($xrdJsonData);
} catch (\Throwable $e) {
$this->logger->notice('Invalid JSON string for XRD URL: ' . $uri);
return null;
}
if (!isset($xrdData->links)) {
$this->logger->notice('Invalid JSON structure for XRD URL: ' . $uri);
return null;
}
foreach ($xrdData->links as $link) {
if ($link->rel == 'http://ostatus.org/schema/1.0/subscribe') {
return $link->template ?? null;
}
}
return null;
}
}

View File

@ -10,7 +10,6 @@ class MatchSearch extends BaseRoute
public function __invoke(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args): \Slim\Http\Response
{
return (new \Friendica\Directory\Controllers\Api\MatchSearch(
$this->container->atlas,
$this->container->get(\Friendica\Directory\Models\Profile::class),
$this->container->l10n
))->render($request, $response, $args);

View File

@ -10,7 +10,8 @@ class Photo extends BaseRoute
public function __invoke(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args): \Slim\Http\Response
{
return (new \Friendica\Directory\Controllers\Api\Photo(
$this->container->atlas
$this->container->atlas,
$this->container->get('defaultProfilePictureSmallPath')
))->render($request, $response, $args);
}
}

View File

@ -10,7 +10,6 @@ class Search extends BaseRoute
public function __invoke(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args): \Slim\Http\Response
{
return (new \Friendica\Directory\Controllers\Api\Search(
$this->container->atlas,
$this->container->get(\Friendica\Directory\Models\Profile::class),
$this->container->l10n
))->render($request, $response, $args);

View File

@ -13,6 +13,7 @@ class Directory extends BaseRoute
$this->controller = new \Friendica\Directory\Controllers\Web\Directory(
$this->container->atlas,
$this->container->get(\Friendica\Directory\Models\Server::class),
$this->container->get(\Friendica\Directory\Models\Profile::class),
$this->container->get(\Friendica\Directory\Views\Widget\AccountTypeTabs::class),
$this->container->renderer,

View File

@ -13,6 +13,7 @@ class Search extends BaseRoute
$this->controller = new \Friendica\Directory\Controllers\Web\Search(
$this->container->atlas,
$this->container->get(\Friendica\Directory\Models\Server::class),
$this->container->get(\Friendica\Directory\Models\Profile::class),
$this->container->get(\Friendica\Directory\Views\Widget\AccountTypeTabs::class),
$this->container->renderer,

View File

@ -165,12 +165,12 @@ class L10n
$foundLang = $language;
}
if (strtolower($key) == strtolower(str_replace('-', '_', $locale))) {
$foundLocale = true;
$foundLocale = $language;
break;
}
}
return $foundLocale ? $language : $foundLang ?: $locale;
return $foundLocale ?: $foundLang ?: $locale;
}
/**

View File

@ -15,56 +15,6 @@ namespace Friendica\Directory\Utils;
*/
class Network
{
const USER_AGENT = 'friendica-directory-probe-1.0';
public static function fetchURL(string $url, bool $binary = false, int $timeout = 20): string
{
$ch = curl_init($url);
if (!$ch) {
return false;
}
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, max($timeout, 1)); //Minimum of 1 second timeout.
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 8);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, self::USER_AGENT);
if ($binary) {
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
}
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$s = curl_exec($ch);
curl_close($ch);
return $s;
}
public static function testURL(string $url, int $timeout = 20): bool
{