forked from grumpydevelop/federator
152 lines
4.1 KiB
PHP
152 lines
4.1 KiB
PHP
<?php
|
|
/**
|
|
* SPDX-FileCopyrightText: 2024 Sascha Nitsch (grumpydeveloper) https://contentnation.net/@grumpydevelop
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
* @author Author: Sascha Nitsch (grumpydeveloper)
|
|
**/
|
|
|
|
namespace Federator\Connector;
|
|
|
|
/**
|
|
* dummy connector that always return the same permission
|
|
*/
|
|
class DummyConnector implements Connector
|
|
{
|
|
/**
|
|
* constructor
|
|
*/
|
|
public function __construct()
|
|
{
|
|
}
|
|
|
|
/**
|
|
* get followers of given user
|
|
*
|
|
* @param string $userId user id @unused-param
|
|
* @return \Federator\Data\FedUser[]|false
|
|
*/
|
|
public function getRemoteFollowersOfUser($userId)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* get following of given user
|
|
*
|
|
* @param string $id user id @unused-param
|
|
|
|
* @return \Federator\Data\FedUser[]|false
|
|
*/
|
|
public function getRemoteFollowingForUser($id)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* get posts by given user
|
|
*
|
|
* @param string $id user id @unused-param
|
|
* @param int $min min timestamp @unused-param
|
|
* @param int $max max timestamp @unused-param
|
|
* @param int $limit limit number of results @unused-param
|
|
* @return \Federator\Data\ActivityPub\Common\Activity[]|false
|
|
*/
|
|
public function getRemotePostsByUser($id, $min, $max, $limit)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* get statistics from remote system
|
|
*
|
|
* @return \Federator\Data\Stats|false
|
|
*/
|
|
public function getRemoteStats()
|
|
{
|
|
$stats = new \Federator\Data\Stats();
|
|
$stats->userCount = 9;
|
|
$stats->postCount = 11;
|
|
$stats->commentCount = 13;
|
|
return $stats;
|
|
}
|
|
|
|
/**
|
|
* Convert jsonData to Activity format
|
|
*
|
|
* @param array<string, mixed> $jsonData the json data from our platfrom @unused-param
|
|
* @param string $articleId the original id of the article (if applicable)
|
|
* (used to identify the article in the remote system) @unused-param
|
|
* @return \Federator\Data\ActivityPub\Common\Activity|false
|
|
*/
|
|
public function jsonToActivity(array $jsonData, &$articleId) {
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* get remote user by name
|
|
* @param string $_name user or profile name
|
|
* @return \Federator\Data\User | false
|
|
*/
|
|
public function getRemoteUserByName(string $_name)
|
|
{
|
|
// validate $_session and $user
|
|
$user = new \Federator\Data\User();
|
|
$user->externalid = $_name;
|
|
return $user;
|
|
}
|
|
|
|
/**
|
|
* get remote user by given session
|
|
* @param string $_session session id
|
|
* @param string $_user user or profile name
|
|
* @return \Federator\Data\User | false
|
|
*/
|
|
public function getRemoteUserBySession(string $_session, string $_user)
|
|
{
|
|
// validate $_session and $user
|
|
$user = new \Federator\Data\User();
|
|
$user->externalid = $_user;
|
|
$user->permissions = ['publish'];
|
|
$user->session = $_session;
|
|
return $user;
|
|
}
|
|
|
|
/**
|
|
* send target-friendly json from ActivityPub activity
|
|
*
|
|
* @param \Federator\Data\FedUser $sender the user of the sender @unused-param
|
|
* @param \Federator\Data\ActivityPub\Common\Activity $activity the activity @unused-param
|
|
* @return boolean did we successfully send the activity?
|
|
*/
|
|
public function sendActivity($sender, $activity)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* check if the headers include a valid signature
|
|
*
|
|
* @param string[] $headers the headers @unused-param
|
|
* @throws \Federator\Exceptions\PermissionDenied
|
|
* @return string|\Federator\Exceptions\PermissionDenied
|
|
*/
|
|
public function checkSignature($headers)
|
|
{
|
|
return new \Federator\Exceptions\PermissionDenied("Dummy connector: no signature check");
|
|
}
|
|
}
|
|
|
|
namespace Federator;
|
|
|
|
/**
|
|
* Function to initialize plugin
|
|
*
|
|
* @param \Federator\Main $main main instance
|
|
* @return void
|
|
*/
|
|
function dummy_load($main)
|
|
{
|
|
$dummy = new Connector\DummyConnector();
|
|
# echo "dummyconnector::dummy_load Loaded new connector, adding to main\n"; // TODO change to proper log
|
|
$main->setConnector($dummy);
|
|
}
|