function renaming

This commit is contained in:
Sascha Nitsch 2025-07-20 17:34:04 +02:00
parent f23a2b01e0
commit 6df40c1946
8 changed files with 42 additions and 47 deletions

View file

@ -43,7 +43,6 @@ class Following implements \Federator\Api\FedUsers\FedUsersInterface
$dbh = $this->main->getDatabase();
$cache = $this->main->getCache();
$connector = $this->main->getConnector();
// get user
$user = \Federator\DIO\User::getUserByName(
$dbh,
@ -56,7 +55,7 @@ class Following implements \Federator\Api\FedUsers\FedUsersInterface
}
$following = new \Federator\Data\ActivityPub\Common\Following();
$followingItems = \Federator\DIO\Followers::getFollowingForUser($dbh, $user->id, $connector, $cache);
$followingItems = \Federator\DIO\Followers::getFollowingByUser($dbh, $user->id, $connector, $cache);
$config = $this->main->getConfig();
$protocol = $config['generic']['protocol'];

View file

@ -20,7 +20,7 @@ interface Cache extends \Federator\Connector\Connector
* @param \Federator\Data\FedUser[]|false $followers user followers
* @return void
*/
public function saveRemoteFollowersOfUser($user, $followers);
public function saveFollowersByUser($user, $followers);
/**
* save remote following for user
@ -29,7 +29,7 @@ interface Cache extends \Federator\Connector\Connector
* @param \Federator\Data\FedUser[]|false $following user following
* @return void
*/
public function saveRemoteFollowingForUser($user, $following);
public function saveFollowingByUser($user, $following);
/**
* save remote posts by user

View file

@ -17,19 +17,17 @@ interface Connector
* get followers of given user
*
* @param string $id user id
* @return \Federator\Data\FedUser[]|false
*/
public function getRemoteFollowersOfUser($id);
public function getFollowersByUser($id);
/**
* get following of given user
*
* @param string $id user id
* @return \Federator\Data\FedUser[]|false
*/
public function getRemoteFollowingForUser($id);
public function getFollowingByUser($id);
/**
* get posts by given user
@ -38,7 +36,6 @@ interface Connector
* @param int $min min value
* @param int $max max value
* @param int $limit maximum number of results
* @return \Federator\Data\ActivityPub\Common\Activity[]|false
*/
public function getRemotePostsByUser($id, $min, $max, $limit);

View file

@ -49,7 +49,7 @@ class Article
*/
public static function conditionalConvertToNote($article, $targetUrl)
{
$supportFile = file_get_contents(PROJECT_ROOT . '/formatsupport.json');
$supportFile = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '../formatsupport.json');
if ($supportFile === false) {
error_log("Article::conditionalConvertToNote Failed to read support file for article conversion.");
return $article; // Fallback to original article if file read fails

View file

@ -30,7 +30,7 @@ class Followers
{
// ask cache
if ($cache !== null) {
$followers = $cache->getRemoteFollowersOfUser($id);
$followers = $cache->getFollowersByUser($id);
if ($followers !== false) {
return $followers;
}
@ -41,7 +41,7 @@ class Followers
if ($stmt === false) {
throw new \Federator\Exceptions\ServerError('Followers::getFollowersByUser Failed to prepare statement');
}
$stmt->bind_param("s", $id);
$stmt->bind_param('s', $id);
$stmt->execute();
$followerIds = [];
$stmt->bind_result($sourceUser);
@ -67,14 +67,14 @@ class Followers
if ($followers === []) {
// ask connector for user-id
$followers = $connector->getRemoteFollowersOfUser($id);
$followers = $connector->getFollowersByUser($id);
if ($followers === false) {
$followers = [];
}
}
// save followers to cache
if ($cache !== null) {
$cache->saveRemoteFollowersOfUser($id, $followers);
$cache->saveFollowersByUser($id, $followers);
}
return $followers;
}
@ -91,12 +91,11 @@ class Followers
* optional caching service
* @return \Federator\Data\FedUser[]
*/
public static function getFollowingForUser($dbh, $id, $connector, $cache)
public static function getFollowingByUser($dbh, $id, $connector, $cache)
{
// ask cache
if ($cache !== null) {
$following = $cache->getRemoteFollowingForUser($id);
$following = $cache->getFollowingByUser($id);
if ($following !== false) {
return $following;
}
@ -107,7 +106,7 @@ class Followers
if ($stmt === false) {
throw new \Federator\Exceptions\ServerError('Followers::getFollowingForUser Failed to prepare statement');
}
$stmt->bind_param("s", $id);
$stmt->bind_param('s', $id);
$stmt->execute();
$followingIds = [];
$stmt->bind_result($sourceUser);
@ -123,7 +122,7 @@ class Followers
$cache,
);
} catch (\Throwable $e) {
error_log('Followers::getFollowingForUser Exception: ' . $e->getMessage());
error_log('Followers::getFollowingByUser Exception: ' . $e->getMessage());
continue; // Skip this user if an exception occurs
}
if ($user !== false && $user->id !== null) {
@ -133,14 +132,14 @@ class Followers
if ($following === []) {
// ask connector for user-id
$following = $connector->getRemoteFollowingForUser($id);
$following = $connector->getFollowingByUser($id);
if ($following === false) {
$following = [];
}
}
// save posts to DB
if ($cache !== null) {
$cache->saveRemoteFollowingForUser($id, $following);
$cache->saveFollowingByUser($id, $following);
}
return $following;
}

View file

@ -53,27 +53,28 @@ class ContentNation implements Connector
/**
* get followers of given user
*
* @param string $userId user id
* @param string $userId user id @unused-param
* @return \Federator\Data\FedUser[]|false
*/
public function getRemoteFollowersOfUser($userId)
public function getFollowersByUser($userId)
{
// todo implement queue for this
// ContentNation does not export followers
/*
if (preg_match("#^([^@]+)@([^/]+)#", $userId, $matches) == 1) {
$userId = $matches[1];
}
$remoteURL = $this->service . '/api/profile/' . urlencode($userId) . '/followers';
$remoteURL = $this->service . '/api/profile/' . urlencode($userId);# . '/followers';
[$response, $info] = \Federator\Main::getFromRemote($remoteURL, []);
if ($info['http_code'] != 200) {
error_log("ContentNation::getRemoteFollowersOfUser error retrieving followers for userId: $userId . Error: "
error_log("ContentNation::getFollowersByUser error retrieving followers for userId: $userId . Error: "
. json_encode($info));
return false;
}
$r = json_decode($response, true);
if ($r === false || $r === null || !is_array($r)) {
return false;
}
}*/
$followers = [];
return $followers;
}
@ -81,13 +82,13 @@ class ContentNation implements Connector
/**
* get following of given user
*
* @param string $userId user id
* @param string $userId user id @unused-param
* @return \Federator\Data\FedUser[]|false
*/
public function getRemoteFollowingForUser($userId)
public function getFollowingByUser($userId)
{
// todo implement queue for this
// ContentNation does not export Following for user
/*
if (preg_match("#^([^@]+)@([^/]+)#", $userId, $matches) == 1) {
$userId = $matches[1];
}
@ -102,9 +103,9 @@ class ContentNation implements Connector
$r = json_decode($response, true);
if ($r === false || $r === null || !is_array($r)) {
return false;
}
$followers = [];
return $followers;
}*/
$following = [];
return $following;
}
/**
@ -722,7 +723,7 @@ class ContentNation implements Connector
"date: {$date}\n" .
"digest: {$digest}";
$pKeyPath = PROJECT_ROOT . '/' . $this->main->getConfig()['keys']['federatorPrivateKeyPath'];
$pKeyPath = $_SERVER['DOCUMENT_ROOT'] . '../' . $this->main->getConfig()['keys']['federatorPrivateKeyPath'];
$privateKeyPem = file_get_contents($pKeyPath);
if ($privateKeyPem === false) {
http_response_code(500);
@ -1070,7 +1071,7 @@ class ContentNation implements Connector
$signature = base64_decode($signatureParts['signature']);
$signedHeaders = explode(' ', $signatureParts['headers']);
$pKeyPath = PROJECT_ROOT . '/' . $this->config['keys']['publicKeyPath'];
$pKeyPath = $_SERVER['DOCUMENT_ROOT'] . '../' . $this->config['keys']['publicKeyPath'];
$publicKeyPem = file_get_contents($pKeyPath);
if ($publicKeyPem === false) {
http_response_code(500);

View file

@ -25,7 +25,7 @@ class DummyConnector implements Connector
* @param string $userId user id @unused-param
* @return \Federator\Data\FedUser[]|false
*/
public function getRemoteFollowersOfUser($userId)
public function getFollowersByUser($userId)
{
return false;
}
@ -34,10 +34,9 @@ class DummyConnector implements Connector
* get following of given user
*
* @param string $id user id @unused-param
* @return \Federator\Data\FedUser[]|false
*/
public function getRemoteFollowingForUser($id)
public function getFollowingByUser($id)
{
return false;
}

View file

@ -103,9 +103,9 @@ class RedisCache implements Cache
* @return \Federator\Data\FedUser[]|false
*/
public function getRemoteFollowersOfUser($id)
public function getFollowersByUser($id)
{
error_log("rediscache::getRemoteFollowersOfUser not implemented");
error_log("rediscache::getFollowersByUser not implemented");
return false;
}
@ -116,9 +116,9 @@ class RedisCache implements Cache
* @return \Federator\Data\FedUser[]|false
*/
public function getRemoteFollowingForUser($id)
public function getFollowingByUser($id)
{
error_log("rediscache::getRemoteFollowingForUser not implemented");
error_log("rediscache::getFollowingByUser not implemented");
return false;
}
@ -254,9 +254,9 @@ class RedisCache implements Cache
* @param \Federator\Data\FedUser[]|false $followers user followers @unused-param
* @return void
*/
public function saveRemoteFollowersOfUser($user, $followers)
public function saveFollowersByUser($user, $followers)
{
error_log("rediscache::saveRemoteFollowersOfUser not implemented");
error_log("rediscache::saveFollowersByUser not implemented");
}
/**
@ -266,9 +266,9 @@ class RedisCache implements Cache
* @param \Federator\Data\FedUser[]|false $following user following @unused-param
* @return void
*/
public function saveRemoteFollowingForUser($user, $following)
public function saveFollowingByUser($user, $following)
{
error_log("rediscache::saveRemoteFollowingForUser not implemented");
error_log("rediscache::saveFollowingByUser not implemented");
}
/**