-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add/extendable transformers #569
Closed
Closed
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
38be586
initial draft: add/extendable-transformers
Menrath 3ae71bb
fix the wrongs calld of the get_transformer
Menrath 6d40ebf
Automatically set the wp_post when returning a transformer instance f…
Menrath 0ccb6c9
fix: add missing self prefix of class constant
Menrath 246600b
add: untestet draft of the migration for the activated post type setting
Menrath 2113d3e
update phpdocs
Menrath 0501fc5
Merge remote-tracking branch 'origin/master' into add/extendable-tran…
Menrath 3a5b530
Merge branch 'master' into add/extendable-transformers
pfefferle 369b32b
transformer: move all related code to \Activitypub\Transformer namespace
Menrath c857eee
transformer: move all related code to \Activitypub\Transformer namespace
Menrath 0bd6ecc
typo
Menrath 804cb0a
fix phpcs errors
Menrath ed1b6b7
change hook name for registering transformers
Menrath 75f1da1
Merge branch 'master' into add/extendable-transformers
pfefferle 2a79297
Merge branch 'add/extendable-transformers' of ssh://code.event-federa…
Menrath 81f971b
fix creation of new transformer instance
Menrath 8338ea4
fix: make in_array comparison strict
Menrath 47b7d84
cleanup: remove function get_post_content_template that is now presen…
Menrath d25a5c2
fix: forgotten merge conflict
Menrath 82928fb
fix phpdocs
Menrath 9c20c8f
fix init of new transformer instance
Menrath 768d190
move transofmrer function get_post_content_template to base class
Menrath e5d19f2
fix phpdocs and some readability
Menrath c7ff99e
fix phpcs via phpcbf
Menrath File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,23 @@ | ||||||
<?php | ||||||
/** | ||||||
* Inspired by the PHP ActivityPub Library by @Landrok | ||||||
* | ||||||
* @link https://github.com/landrok/activitypub | ||||||
*/ | ||||||
|
||||||
namespace Activitypub\Activity; | ||||||
|
||||||
use Activitypub\Activity\Base_Object; | ||||||
|
||||||
/** | ||||||
* Event is an implementation of one of the | ||||||
* Activity Streams Event object type | ||||||
* | ||||||
* The Object is the primary base type for the Activity Streams | ||||||
* vocabulary. | ||||||
* | ||||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-event | ||||||
*/ | ||||||
class Note extends Base_Object { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
protected $type = 'Event'; | ||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
/** | ||
* Inspired by the PHP ActivityPub Library by @Landrok | ||
* | ||
* @link https://github.com/landrok/activitypub | ||
*/ | ||
|
||
namespace Activitypub\Activity; | ||
|
||
use Activitypub\Activity\Base_Object; | ||
|
||
/** | ||
* Note is an implementation of one of the | ||
* Activity Streams Note object type | ||
* | ||
* The Object is the primary base type for the Activity Streams | ||
* vocabulary. | ||
* | ||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-note | ||
*/ | ||
class Note extends Base_Object { | ||
protected $type = 'Note'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,7 +5,7 @@ | |||||
use WP_Error; | ||||||
use WP_REST_Server; | ||||||
use WP_REST_Response; | ||||||
use Activitypub\Transformer\Post; | ||||||
use Activitypub\Transformer\Transformers_Manager; | ||||||
use Activitypub\Activity\Activity; | ||||||
use Activitypub\Collection\Users as User_Collection; | ||||||
|
||||||
|
@@ -59,7 +59,7 @@ public static function user_outbox_get( $request ) { | |||||
return $user; | ||||||
} | ||||||
|
||||||
$post_types = \get_option( 'activitypub_support_post_types', array( 'post', 'page' ) ); | ||||||
$post_types = array_keys( \get_option( 'activitypub_transformer_mapping', array( 'post' => 'activitypub/default', 'page' => 'activitypub/default' ) ) ); | ||||||
|
||||||
$page = $request->get_param( 'page', 1 ); | ||||||
|
||||||
|
@@ -105,7 +105,8 @@ public static function user_outbox_get( $request ) { | |||||
); | ||||||
|
||||||
foreach ( $posts as $post ) { | ||||||
$post = Post::transform( $post )->to_object(); | ||||||
$transformer = \Activitypub\Transformer\Transformers_Manager::instance()->get_transformer( $post ); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
you do not have to use the full path (with namespaces) when using |
||||||
$post = $transformer->to_object(); | ||||||
$activity = new Activity(); | ||||||
$activity->set_type( 'Create' ); | ||||||
$activity->set_context( null ); | ||||||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why these classes? I tried to avoid them, because otherwise we also have to map all other types https://github.com/Automattic/wordpress-activitypub/blob/master/includes/transformer/class-post.php#L398
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are still evaluating all pros and cons. At the moment we have only tried to get an idea of what the consequences would be. As is often the case: the deeper I dig into this repository, the more I can understand certain design decisions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, but there are things that are simply legacy decisions! Be aware that this project started as a spare time thing and still has some crappy code everywhere. So do not try to understand everything and feel free to challenge us, that's what I also try here ;)
I discuss to understand, not to win :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, for offering help, even at our Drafting Stage. I gladly accept this invitation for discussions :)
One of my goals is, that it is very easy an straight forward, for feature developers adding their own transformers to their plugins. Very likely they will have to extend the Base_Object class anyway, especially if they want to add any custom fields that are not defined yet in our Base_Objet class, which until now is consistent with the Activitystreams Vocabulary Standard, e.g., Mobilizon makes usage of PeerTubes
commentsEnabled
feature within itsEvent
object which is a object type available in the ActivityPub standard.Other developers might have a look how thinks are done in this project, and might get confused if the activitypub plugin itself does things a bit differently than the future documentation for how to add proper activitiypub support for my custom post type might advice them to do.
Another related issue is, that when adding a custom field, one also has to add the appropriate json-ld context.
Though the filter
activitypub_json_context
is available, editing the array directly seemed kind of rough to me and applying the filter within the transformer code leaded to a runtime issue, so I had to apply this filter in a different part of the code, which is not ideal in my opinion: doing one "thing" on two different places.I will share our repository with some example transformers registering to the ActivityPub-plugin hopefully today, after doing some renaming and initial documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be perfect!
I agree with your point, but I am not sure if the "extensions" (Event-Activity) should be part of this repo or part of yours. I agree, that it has to be as easy as possible and maybe we have to change the current context implementation for that.
You can maybe have a look what I did to extend the base object(s) for the Follower (https://github.com/Automattic/wordpress-activitypub/blob/master/includes/model/class-follower.php) or internal User mapping (https://github.com/Automattic/wordpress-activitypub/blob/master/includes/model/class-user.php).