transformer: make get_supported_post_types static and refactor
Some checks failed
Unit Testing / phpunit (7.3) (push) Waiting to run
Unit Testing / phpunit (7.4) (push) Waiting to run
Unit Testing / phpunit (8.0) (push) Waiting to run
Unit Testing / phpunit (8.1) (push) Waiting to run
Unit Testing / phpunit (8.2) (push) Waiting to run
Unit Testing / phpunit (latest) (push) Waiting to run
PHP_CodeSniffer / phpcs (push) Successful in 4m0s
Unit Testing / phpunit (5.6, 6.2) (push) Failing after 4m25s
Unit Testing / phpunit (7.0) (push) Failing after 4m43s
Unit Testing / phpunit (7.2) (push) Has been cancelled
Some checks failed
Unit Testing / phpunit (7.3) (push) Waiting to run
Unit Testing / phpunit (7.4) (push) Waiting to run
Unit Testing / phpunit (8.0) (push) Waiting to run
Unit Testing / phpunit (8.1) (push) Waiting to run
Unit Testing / phpunit (8.2) (push) Waiting to run
Unit Testing / phpunit (latest) (push) Waiting to run
PHP_CodeSniffer / phpcs (push) Successful in 4m0s
Unit Testing / phpunit (5.6, 6.2) (push) Failing after 4m25s
Unit Testing / phpunit (7.0) (push) Failing after 4m43s
Unit Testing / phpunit (7.2) (push) Has been cancelled
This commit is contained in:
parent
56939d3c2e
commit
5addca1aff
1 changed files with 49 additions and 46 deletions
|
@ -19,6 +19,11 @@ use function Activitypub\site_supports_blocks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class to implement WordPress to ActivityPub transformers.
|
* Base class to implement WordPress to ActivityPub transformers.
|
||||||
|
*
|
||||||
|
* All have to be extended from this one. It provides some WordPress typical
|
||||||
|
* getter functions, that you might want to use:
|
||||||
|
*
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
abstract class Base {
|
abstract class Base {
|
||||||
/**
|
/**
|
||||||
|
@ -28,6 +33,41 @@ abstract class Base {
|
||||||
*/
|
*/
|
||||||
protected $wp_post;
|
protected $wp_post;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the name used for registering the transformer with the ActivityPub plugin.
|
||||||
|
*
|
||||||
|
* @since version_number_transformer_management_placeholder
|
||||||
|
* @return string name
|
||||||
|
*/
|
||||||
|
abstract public function get_name();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the display name for the ActivityPub transformer.
|
||||||
|
*
|
||||||
|
* @since version_number_transformer_management_placeholder
|
||||||
|
* @return string display name
|
||||||
|
*/
|
||||||
|
abstract public function get_label();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the ActivityStreams 2.0 Object-Type for a Post.
|
||||||
|
*
|
||||||
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#activity-types
|
||||||
|
*
|
||||||
|
* @return string The Object-Type.
|
||||||
|
*/
|
||||||
|
abstract protected function get_object_type();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transforms the WP_Post object to an ActivityPub Object
|
||||||
|
*
|
||||||
|
* @see \Activitypub\Activity\Base_Object
|
||||||
|
* @param WP_Post $wp_post The WordPress Post
|
||||||
|
*
|
||||||
|
* @return \Activitypub\Activity\Base_Object The ActivityPub Object
|
||||||
|
*/
|
||||||
|
abstract public function transform();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getter function for this wp_post.
|
* Getter function for this wp_post.
|
||||||
*
|
*
|
||||||
|
@ -67,7 +107,7 @@ abstract class Base {
|
||||||
* @since version_number_transformer_management_placeholder
|
* @since version_number_transformer_management_placeholder
|
||||||
* @return string[] An array containing all the supported post types.
|
* @return string[] An array containing all the supported post types.
|
||||||
*/
|
*/
|
||||||
public function get_supported_post_types() {
|
public static function get_supported_post_types() {
|
||||||
return \get_post_types( array( 'public' => true ), 'names' );
|
return \get_post_types( array( 'public' => true ), 'names' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +118,7 @@ abstract class Base {
|
||||||
* @since version_number_transformer_management_placeholder
|
* @since version_number_transformer_management_placeholder
|
||||||
* @return string Plugin name
|
* @return string Plugin name
|
||||||
*/
|
*/
|
||||||
private function get_plugin_name_from_transformer_instance( $transformer ) {
|
final private function get_plugin_name_from_transformer_instance( $transformer ) {
|
||||||
$class_reflection = new \ReflectionClass( $transformer );
|
$class_reflection = new \ReflectionClass( $transformer );
|
||||||
|
|
||||||
$plugin_basename = plugin_basename( $class_reflection->getFileName() );
|
$plugin_basename = plugin_basename( $class_reflection->getFileName() );
|
||||||
|
@ -105,31 +145,6 @@ abstract class Base {
|
||||||
return in_array( $post_type, $this->get_supported_post_types(), true );
|
return in_array( $post_type, $this->get_supported_post_types(), true );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the name used for registering the transformer with the ActivityPub plugin.
|
|
||||||
*
|
|
||||||
* @since version_number_transformer_management_placeholder
|
|
||||||
* @return string name
|
|
||||||
*/
|
|
||||||
abstract public function get_name();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the display name for the ActivityPub transformer.
|
|
||||||
*
|
|
||||||
* @since version_number_transformer_management_placeholder
|
|
||||||
* @return string display name
|
|
||||||
*/
|
|
||||||
abstract public function get_label();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the ActivityStreams 2.0 Object-Type for a Post.
|
|
||||||
*
|
|
||||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#activity-types
|
|
||||||
*
|
|
||||||
* @return string The Object-Type.
|
|
||||||
*/
|
|
||||||
abstract protected function get_object_type();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the content for the ActivityPub Item.
|
* Returns the content for the ActivityPub Item.
|
||||||
*
|
*
|
||||||
|
@ -481,7 +496,6 @@ abstract class Base {
|
||||||
return $image;
|
return $image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function to get the @-Mentions from the post content.
|
* Helper function to get the @-Mentions from the post content.
|
||||||
*
|
*
|
||||||
|
@ -548,7 +562,6 @@ abstract class Base {
|
||||||
return $tags;
|
return $tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the locale of the post.
|
* Returns the locale of the post.
|
||||||
*
|
*
|
||||||
|
@ -582,14 +595,4 @@ abstract class Base {
|
||||||
$this->get_locale() => $this->get_content(),
|
$this->get_locale() => $this->get_content(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Transforms the WP_Post object to an ActivityPub Object
|
|
||||||
*
|
|
||||||
* @see \Activitypub\Activity\Base_Object
|
|
||||||
* @param WP_Post $wp_post The WordPress Post
|
|
||||||
*
|
|
||||||
* @return \Activitypub\Activity\Base_Object The ActivityPub Object
|
|
||||||
*/
|
|
||||||
abstract public function transform();
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue