use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Module\Register;
-use Friendica\Network\CurlResult;
+use Friendica\Network\IHTTPResult;
use Friendica\Protocol\Diaspora;
-use Friendica\Protocol\PortableContact;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
use Friendica\Util\Strings;
public static function reachable(string $profile, string $server = '', string $network = '', bool $force = false)
{
if ($server == '') {
- $server = GContact::getBasepath($profile);
+ $contact = Contact::getByURL($profile, null, ['baseurl']);
+ if (!empty($contact['baseurl'])) {
+ $server = $contact['baseurl'];
+ }
}
if ($server == '') {
// When the base path doesn't seem to contain a social network we try the complete path.
// Most detectable system have to be installed in the root directory.
// We checked the base to avoid false positives.
- $curlResult = Network::curl($url, false, ['timeout' => $xrd_timeout]);
+ $curlResult = DI::httpRequest()->get($url, false, ['timeout' => $xrd_timeout]);
if ($curlResult->isSuccess()) {
$urldata = self::analyseRootHeader($curlResult, $serverdata);
$urldata = self::analyseRootBody($curlResult, $urldata, $url);
}
if (!empty($serverdata['network']) && !empty($id) && ($serverdata['network'] != Protocol::PHANTOM)) {
- $gcontacts = DBA::count('gcontact', ['gsid' => $id]);
$apcontacts = DBA::count('apcontact', ['gsid' => $id]);
$contacts = DBA::count('contact', ['uid' => 0, 'gsid' => $id]);
- $max_users = max($gcontacts, $apcontacts, $contacts, $registeredUsers);
+ $max_users = max($apcontacts, $contacts, $registeredUsers);
if ($max_users > $registeredUsers) {
Logger::info('Update registered users', ['id' => $id, 'url' => $serverdata['nurl'], 'registered-users' => $max_users]);
DBA::update('gserver', ['registered-users' => $max_users], ['id' => $id]);
/**
* Detect server type by using the nodeinfo data
*
- * @param string $url address of the server
- * @param CurlResult $curlResult
+ * @param string $url address of the server
+ * @param IHTTPResult $httpResult
+ *
* @return array Server data
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- private static function fetchNodeinfo(string $url, CurlResult $curlResult)
+ private static function fetchNodeinfo(string $url, IHTTPResult $httpResult)
{
- if (!$curlResult->isSuccess()) {
+ if (!$httpResult->isSuccess()) {
return [];
}
- $nodeinfo = json_decode($curlResult->getBody(), true);
+ $nodeinfo = json_decode($httpResult->getBody(), true);
if (!is_array($nodeinfo) || empty($nodeinfo['links'])) {
return [];
{
$contacts = [];
- $gcontacts = DBA::select('gcontact', ['url', 'nurl'], ['server_url' => [$url, $serverdata['nurl']]]);
- while ($gcontact = DBA::fetch($gcontacts)) {
- $contacts[$gcontact['nurl']] = $gcontact['url'];
- }
- DBA::close($gcontacts);
-
$apcontacts = DBA::select('apcontact', ['url'], ['baseurl' => [$url, $serverdata['nurl']]]);
while ($apcontact = DBA::fetch($apcontacts)) {
$contacts[Strings::normaliseLink($apcontact['url'])] = $apcontact['url'];
return !strpos($body, '>');
}
- /**
- * Update the user directory of a given gserver record
- *
- * @param array $gserver gserver record
- */
- public static function updateDirectory(array $gserver)
- {
- /// @todo Add Mastodon API directory
-
- if (!empty($gserver['poco'])) {
- PortableContact::discoverSingleServer($gserver['id']);
- }
- }
-
/**
* Update GServer entries
*/
$last_update = date('c', time() - (60 * 60 * 24 * $requery_days));
- $gservers = DBA::p("SELECT `id`, `url`, `nurl`, `network`, `poco`
+ $gservers = DBA::p("SELECT `id`, `url`, `nurl`, `network`, `poco`, `directory-type`
FROM `gserver`
WHERE NOT `failed`
- AND `poco` != ''
+ AND `directory-type` != ?
AND `last_poco_query` < ?
- ORDER BY RAND()", $last_update
+ ORDER BY RAND()", self::DT_NONE, $last_update
);
while ($gserver = DBA::fetch($gservers)) {
continue;
}
+ Logger::info('Update peer list', ['server' => $gserver['url'], 'id' => $gserver['id']]);
+ Worker::add(PRIORITY_LOW, 'UpdateServerPeers', $gserver['url']);
+
Logger::info('Update directory', ['server' => $gserver['url'], 'id' => $gserver['id']]);
Worker::add(PRIORITY_LOW, 'UpdateServerDirectory', $gserver);
+ $fields = ['last_poco_query' => DateTimeFormat::utcNow()];
+ DBA::update('gserver', $fields, ['nurl' => $gserver['nurl']]);
+
if (--$no_of_queries == 0) {
break;
}