updated plugin ActivityPub
version 3.3.3
This commit is contained in:
@ -1,15 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* Base Transformer Class file.
|
||||
*
|
||||
* @package Activitypub
|
||||
*/
|
||||
|
||||
namespace Activitypub\Transformer;
|
||||
|
||||
use WP_Error;
|
||||
use WP_Post;
|
||||
use WP_Comment;
|
||||
|
||||
use Activitypub\Activity\Activity;
|
||||
use Activitypub\Activity\Base_Object;
|
||||
use Activitypub\Collection\Replies;
|
||||
|
||||
/**
|
||||
* WordPress Base Transformer
|
||||
* WordPress Base Transformer.
|
||||
*
|
||||
* Transformers are responsible for transforming a WordPress objects into different ActivityPub
|
||||
* Object-Types or Activities.
|
||||
@ -29,18 +35,18 @@ abstract class Base {
|
||||
*
|
||||
* This helps to chain the output of the Transformer.
|
||||
*
|
||||
* @param WP_Post|WP_Comment $wp_object The WordPress object
|
||||
* @param WP_Post|WP_Comment $wp_object The WordPress object.
|
||||
*
|
||||
* @return Base
|
||||
*/
|
||||
public static function transform( $object ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.objectFound
|
||||
return new static( $object );
|
||||
public static function transform( $wp_object ) {
|
||||
return new static( $wp_object );
|
||||
}
|
||||
|
||||
/**
|
||||
* Base constructor.
|
||||
*
|
||||
* @param WP_Post|WP_Comment $wp_object The WordPress object
|
||||
* @param WP_Post|WP_Comment $wp_object The WordPress object.
|
||||
*/
|
||||
public function __construct( $wp_object ) {
|
||||
$this->wp_object = $wp_object;
|
||||
@ -49,9 +55,9 @@ abstract class Base {
|
||||
/**
|
||||
* Transform all properties with available get(ter) functions.
|
||||
*
|
||||
* @param Base_Object|object $object
|
||||
* @param Base_Object|object $activitypub_object The ActivityPub Object.
|
||||
*
|
||||
* @return Base_Object|object $object
|
||||
* @return Base_Object|object
|
||||
*/
|
||||
protected function transform_object_properties( $activitypub_object ) {
|
||||
$vars = $activitypub_object->get_object_var_keys();
|
||||
@ -75,13 +81,12 @@ abstract class Base {
|
||||
/**
|
||||
* Transform the WordPress Object into an ActivityPub Object.
|
||||
*
|
||||
* @return Activitypub\Activity\Base_Object
|
||||
* @return Base_Object|object The ActivityPub Object.
|
||||
*/
|
||||
public function to_object() {
|
||||
$activitypub_object = new Base_Object();
|
||||
$activitypub_object = $this->transform_object_properties( $activitypub_object );
|
||||
|
||||
return $activitypub_object;
|
||||
return $this->transform_object_properties( $activitypub_object );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -89,7 +94,7 @@ abstract class Base {
|
||||
*
|
||||
* @param string $type The Activity-Type.
|
||||
*
|
||||
* @return \Activitypub\Activity\Activity The Activity.
|
||||
* @return Activity The Activity.
|
||||
*/
|
||||
public function to_activity( $type ) {
|
||||
$object = $this->to_object();
|
||||
@ -100,7 +105,7 @@ abstract class Base {
|
||||
// Pre-fill the Activity with data (for example cc and to).
|
||||
$activity->set_object( $object );
|
||||
|
||||
// Use simple Object (only ID-URI) for Like and Announce
|
||||
// Use simple Object (only ID-URI) for Like and Announce.
|
||||
if ( in_array( $type, array( 'Like', 'Announce' ), true ) ) {
|
||||
$activity->set_object( $object->get_id() );
|
||||
}
|
||||
@ -108,17 +113,27 @@ abstract class Base {
|
||||
return $activity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ID of the WordPress Object.
|
||||
*/
|
||||
abstract protected function get_id();
|
||||
|
||||
/**
|
||||
* Get the replies Collection.
|
||||
*/
|
||||
public function get_replies() {
|
||||
return Replies::get_collection( $this->wp_object );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID of the WordPress Object.
|
||||
*
|
||||
* @return int The ID of the WordPress Object
|
||||
*/
|
||||
abstract public function get_wp_user_id();
|
||||
|
||||
/**
|
||||
* Change the User-ID of the WordPress Post.
|
||||
*
|
||||
* @return int The User-ID of the WordPress Post
|
||||
* @param int $user_id The new user ID.
|
||||
*/
|
||||
abstract public function change_wp_user_id( $user_id );
|
||||
}
|
||||
|
Reference in New Issue
Block a user