wip
This commit is contained in:
parent
23dfd11d39
commit
2bd6130eb1
4 changed files with 137 additions and 42 deletions
|
@ -1,28 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Inspired by the PHP ActivityPub Library by @Landrok
|
||||
*
|
||||
* @link https://github.com/landrok/activitypub
|
||||
*/
|
||||
|
||||
namespace Activitypub\Activity;
|
||||
|
||||
use WP_Error;
|
||||
use ReflectionClass;
|
||||
|
||||
use function Activitypub\camel_to_snake_case;
|
||||
use function Activitypub\snake_to_camel_case;
|
||||
|
||||
/**
|
||||
* Base_Object is an implementation of one of the
|
||||
* Activity Streams Core Types.
|
||||
*
|
||||
* The Object is the primary base type for the Activity Streams
|
||||
* vocabulary.
|
||||
*
|
||||
* Note: Object is a reserved keyword in PHP. It has been suffixed with
|
||||
* 'Base_' for this reason.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-core/#object
|
||||
*/
|
||||
class Base_Object {
|
44
includes/base/class-transformer-base.php
Normal file
44
includes/base/class-transformer-base.php
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
/**
|
||||
* Inspired by the PHP ActivityPub Library by @Landrok
|
||||
*
|
||||
* @link https://github.com/landrok/activitypub
|
||||
*/
|
||||
|
||||
namespace Activitypub\Activity;
|
||||
|
||||
use WP_Error;
|
||||
use ReflectionClass;
|
||||
|
||||
use function Activitypub\camel_to_snake_case;
|
||||
use function Activitypub\snake_to_camel_case;
|
||||
|
||||
/**
|
||||
* Base class to implement WordPress to ActivityPub transformers.
|
||||
*/
|
||||
abstract class Transformer_Base {
|
||||
/**
|
||||
* Get the supported WP post_types that the transformer can use as an input.
|
||||
*
|
||||
* By default all post types are supported.
|
||||
*
|
||||
* @since version_number_transformer_management_placeholder
|
||||
*/
|
||||
public function get_supported_post_types() {
|
||||
return \get_post_types( array(), 'names');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name used for registering the transformer with the ActivityPub plugin.
|
||||
*
|
||||
* @since version_number_transformer_management_placeholder
|
||||
*/
|
||||
abstract public function get_name();
|
||||
|
||||
/**
|
||||
* Get the display name for the ActivityPub transformer.
|
||||
*
|
||||
* @since version_number_transformer_management_placeholder
|
||||
*/
|
||||
abstract public function get_title();
|
||||
}
|
|
@ -3,6 +3,7 @@ namespace Activitypub;
|
|||
|
||||
use WP_User_Query;
|
||||
use Activitypub\Model\Blog_User;
|
||||
use Activitypub\Base\Transformer_Base;
|
||||
|
||||
/**
|
||||
* ActivityPub Admin Class
|
||||
|
@ -22,6 +23,10 @@ class Admin {
|
|||
if ( ! is_user_disabled( get_current_user_id() ) ) {
|
||||
\add_action( 'show_user_profile', array( self::class, 'add_profile' ) );
|
||||
}
|
||||
|
||||
add_filter( 'activitypub/transformers/is_transformer_enabled', function( $should_register, Transformer_Base $widget_instance ) {
|
||||
return ! Options::is_element_disabled( $widget_instance->get_name() );
|
||||
}, 10, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,14 +24,14 @@ class Transformers_Manager {
|
|||
/**
|
||||
* Transformers.
|
||||
*
|
||||
* Holds the list of all the transformers. Default is `null`.
|
||||
* Holds the list of all the ActivityPub transformers. Default is `null`.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
*
|
||||
* @var Base_Control[]
|
||||
* @var \ActivityPub\Transformer_Base[]
|
||||
*/
|
||||
private $controls = null;
|
||||
private $transformers = array();
|
||||
|
||||
/**
|
||||
* Transformers manager constructor.
|
||||
|
@ -43,8 +43,18 @@ class Transformers_Manager {
|
|||
*/
|
||||
public function __construct() {
|
||||
$this->require_files();
|
||||
}
|
||||
|
||||
add_action( 'elementor/ajax/register_actions', [ $this, 'register_ajax_actions' ] );
|
||||
/**
|
||||
* Require files.
|
||||
*
|
||||
* Require ActivityPub transformer base class.
|
||||
*
|
||||
* @since version_number_transformer_management_placeholder
|
||||
* @access private
|
||||
*/
|
||||
private function require_files() {
|
||||
require ACTIVITYPUB_PLUGIN_DIR . 'includes/base/class-transformer-base.php';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,22 +63,86 @@ class Transformers_Manager {
|
|||
* @since version_number_transformer_management_placeholder
|
||||
* @access public
|
||||
*
|
||||
* @param \ActivityPub\Base_Transformer $transformer_instance ActivityPub Transformer.
|
||||
* @param \ActivityPub\Transformer_Base $transformer_instance ActivityPub Transformer.
|
||||
*
|
||||
* @return bool True if the transformer was registered.
|
||||
* @return bool True if the ActivityPub transformer was registered.
|
||||
*/
|
||||
public function register( Base_Transformer $control_instance, $control_id = null ) {
|
||||
public function register( Transformer_Base $transformer_instance) {
|
||||
|
||||
// TODO: For BC. Remove in the future.
|
||||
if ( $control_id ) {
|
||||
Plugin::instance()->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_argument(
|
||||
'$control_id', '3.5.0'
|
||||
if ( ! $transformer_instance instanceof Transformer_Base ) {
|
||||
_doing_it_wrong(
|
||||
__METHOD__,
|
||||
__( 'ActivityPub transformer instance must be a implementation of the \ActivityPub\Transformer_Base class.' ),
|
||||
'version_number_transformer_management_placeholder'
|
||||
);
|
||||
} else {
|
||||
$control_id = $control_instance->get_type();
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->controls[ $control_id ] = $control_instance;
|
||||
$transformer_name = $transformer_instance->name;
|
||||
if ( preg_match( '/[A-Z]+/', $transformer_name ) ) {
|
||||
_doing_it_wrong(
|
||||
__METHOD__,
|
||||
__( 'ActivityPub transformer names must not contain uppercase characters.' ),
|
||||
'version_number_transformer_management_placeholder'
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
$name_matcher = '/^[a-z0-9-]+\/[a-z0-9-]+$/';
|
||||
if ( ! preg_match( $name_matcher, $transformer_name ) ) {
|
||||
_doing_it_wrong(
|
||||
__METHOD__,
|
||||
__( 'ActivityPub transformer names must contain a namespace prefix. Example: my-plugin/my-custom-transformer' ),
|
||||
'version_number_transformer_management_placeholder'
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $this->is_registered( $transformer_name ) ) {
|
||||
_doing_it_wrong(
|
||||
__METHOD__,
|
||||
/* translators: %s: Block name. */
|
||||
sprintf( __( 'ActivityPub transformer with name "%s" is already registered.' ), $transformer_name ),
|
||||
'version_number_transformer_management_placeholder'
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the ActivityPub transformer be registered.
|
||||
*
|
||||
* @since version_number_transformer_management_placeholder
|
||||
*
|
||||
* @param bool $should_register Should the ActivityPub transformer be registered. Default is `true`.
|
||||
* @param \ActivityPub\Transformer_Base $transformer_instance Widget instance.
|
||||
*/
|
||||
$should_register = apply_filters( 'activitypub/transformers/is_transformer_enabled', true, $transformer_instance );
|
||||
|
||||
if ( ! $should_register ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->_transformers[ $transformer_name ] = $transformer_instance;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register controls.
|
||||
*
|
||||
* This method creates a list of all the supported controls by requiring the
|
||||
* control files and initializing each one of them.
|
||||
*
|
||||
* The list of supported controls includes the regular controls and the group
|
||||
* controls.
|
||||
*
|
||||
* External developers can register new controls by hooking to the
|
||||
* `elementor/controls/controls_registered` action.
|
||||
*
|
||||
* @since 3.1.0
|
||||
* @access private
|
||||
*/
|
||||
private function register_controls() {
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue