forked from grumpydevelop/federator
		
	
		
			
				
	
	
		
			80 lines
		
	
	
	
		
			1.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			80 lines
		
	
	
	
		
			1.9 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 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;
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * 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;
 | 
						|
        $user->permissions = [];
 | 
						|
        $user->session = '';
 | 
						|
        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;
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
namespace Federator;
 | 
						|
 | 
						|
/**
 | 
						|
 * Function to initialize plugin
 | 
						|
 *
 | 
						|
 * @param  \Federator\Main $main main instance
 | 
						|
 * @return void
 | 
						|
 */
 | 
						|
function dummy_load($main)
 | 
						|
{
 | 
						|
    $dummy = new Connector\DummyConnector();
 | 
						|
    $main->setConnector($dummy);
 | 
						|
}
 |