Hypolite Petovan
2627b54349
- 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
61 lines
1.4 KiB
PHP
61 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Friendica\Directory\Models;
|
|
|
|
/**
|
|
* @author Hypolite Petovan <hypolite@mrpetovan.com>
|
|
*/
|
|
class Server extends \Friendica\Directory\Model
|
|
{
|
|
/**
|
|
* @param string $server_url
|
|
* @return array|null
|
|
*/
|
|
public function getByUrlAlias(string $server_url): ?array
|
|
{
|
|
$server_alias = str_replace(['http://', 'https://'], ['', ''], $server_url);
|
|
|
|
$server = $this->atlas->fetchOne('SELECT s.* FROM `server` s JOIN `server_alias` sa ON sa.`server_id` = s.`id` WHERE sa.`alias` = :alias',
|
|
['alias' => $server_alias]
|
|
);
|
|
|
|
return $server;
|
|
}
|
|
|
|
/**
|
|
* @param string $server_url
|
|
*/
|
|
public function addAliasToServer(int $server_id, string $server_url): void
|
|
{
|
|
$server_alias = str_replace(['http://', 'https://'], ['', ''], $server_url);
|
|
|
|
$this->atlas->perform('INSERT INTO `server_alias`
|
|
SET `server_id` = :server_id,
|
|
`alias` = :alias,
|
|
`timestamp` = NOW()
|
|
ON DUPLICATE KEY UPDATE
|
|
`server_id` = :server_id,
|
|
`timestamp` = NOW()',
|
|
[
|
|
'server_id' => $server_id,
|
|
'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;
|
|
}
|
|
}
|