Skip to content

Commit

Permalink
Merge branch 'master' into add/query-as-id
Browse files Browse the repository at this point in the history
  • Loading branch information
pfefferle authored Sep 24, 2024
2 parents 105d4f1 + d361a69 commit 6f2c91e
Show file tree
Hide file tree
Showing 25 changed files with 374 additions and 90 deletions.
Binary file added .wordpress-org/screenshot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .wordpress-org/screenshot-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .wordpress-org/screenshot-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .wordpress-org/screenshot-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .wordpress-org/screenshot-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ The followers of a user can be found in the menu under "Users" -> "Followers" or

For reasons of data protection, it is not possible to see the followers of other users.

## Screenshots ##

1. The "Follow me"-Block in the Block-Editor
2. The "Followers"-Block in the Block-Editor
3. The "Federated Reply"-Block in the Block-Editor
4. A "Federated Reply" in a Post

## Changelog ##

### 3.2.5 ###
Expand Down
2 changes: 1 addition & 1 deletion build/follow-me/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'f33252a2026002ddb56c');
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '1ec66c1edf3d9b0b6678');
4 changes: 2 additions & 2 deletions build/follow-me/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/follow-me/view.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-dom-ready', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'ab8c0dad126bb0a61ed6');
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-dom-ready', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'bc272e3d4aaa7992f4c7');
2 changes: 1 addition & 1 deletion build/follow-me/view.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/remote-reply/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-dom-ready', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'ab787305c7ed07812b96');
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-dom-ready', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '45f08e094782c24c4c34');
2 changes: 1 addition & 1 deletion build/remote-reply/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/reply/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '9eb1d863fcf6d209ef29');
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '808c98599517db815fc5');
2 changes: 1 addition & 1 deletion build/reply/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion includes/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ public static function admin_notices() {
if ( 'edit' === $current_screen->base && Extra_Fields::is_extra_fields_post_type( $current_screen->post_type ) ) {
?>
<div class="notice" style="margin: 0; background: none; border: none; box-shadow: none; padding: 15px 0 0 0; font-size: 14px;">
<?php esc_html_e( 'These are extra fields that are used for your ActivityPub profile. You can use your homepage, social profiles, pronouns, age, anything you want.', 'activitypub' ); ?>
<?php
esc_html_e( 'These are extra fields that are used for your ActivityPub profile. You can use your homepage, social profiles, pronouns, age, anything you want.', 'activitypub' );
?>
</div>
<?php
}
Expand Down
5 changes: 0 additions & 5 deletions includes/class-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,6 @@ public static function render_follow_me_block( $attrs ) {
array( 'icon', 'name', 'webfinger' )
);

// add `@` prefix if it's missing
if ( '@' !== substr( $attrs['profileData']['webfinger'], 0, 1 ) ) {
$attrs['profileData']['webfinger'] = '@' . $attrs['profileData']['webfinger'];
}

$wrapper_attributes = get_block_wrapper_attributes(
array(
'aria-label' => __( 'Follow me on the Fediverse', 'activitypub' ),
Expand Down
42 changes: 28 additions & 14 deletions includes/collection/class-extra-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use WP_Query;
use Activitypub\Collection\Users;

use function Activitypub\site_supports_blocks;

class Extra_Fields {

const USER_POST_TYPE = 'ap_extrafield';
Expand Down Expand Up @@ -37,6 +39,23 @@ public static function get_actor_fields( $user_id ) {
return apply_filters( 'activitypub_get_actor_extra_fields', $fields, $user_id );
}

public static function get_formatted_content( $post ) {
$content = \get_the_content( null, false, $post );
$content = Link::the_content( $content, true );
if ( site_supports_blocks() ) {
$content = \do_blocks( $content );
}
$content = \wptexturize( $content );
$content = \wp_filter_content_tags( $content );
// replace script and style elements
$content = \preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $content );
$content = \strip_shortcodes( $content );
$content = \trim( \preg_replace( '/[\n\r\t]/', '', $content ) );
$content = \apply_filters( 'activitypub_extra_field_content', $content, $post );

return $content;
}

/**
* Transforms the Extra Fields (Cutom Post Types) to ActivityPub Actor-Attachments.
*
Expand All @@ -56,16 +75,7 @@ function( $rel ) {
);

foreach ( $fields as $post ) {
$content = \get_the_content( null, false, $post );
$content = \do_blocks( $content );
$content = \wptexturize( $content );
$content = \wp_filter_content_tags( $content );
// replace script and style elements
$content = \preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $content );
$content = \strip_shortcodes( $content );
$content = \trim( \preg_replace( '/[\n\r\t]/', '', $content ) );
$content = \apply_filters( 'activitypub_extra_field_content', $content, $post );

$content = self::get_formatted_content( $post );
$attachments[] = array(
'type' => 'PropertyValue',
'name' => \get_the_title( $post ),
Expand Down Expand Up @@ -211,10 +221,7 @@ function( $rel ) {
'post_title' => $title,
'post_status' => 'publish',
'post_author' => $user_id,
'post_content' => sprintf(
'<!-- wp:paragraph --><p>%s</p><!-- /wp:paragraph -->',
Link::the_content( $url )
),
'post_content' => self::make_paragraph_block( Link::the_content( $url ) ),
'comment_status' => 'closed',
'menu_order' => $menu_order,
);
Expand All @@ -231,6 +238,13 @@ function( $rel ) {
return $extra_fields;
}

public static function make_paragraph_block( $content ) {
if ( ! site_supports_blocks() ) {
return $content;
}
return '<!-- wp:paragraph --><p>' . $content . '</p><!-- /wp:paragraph -->';
}

/**
* Checks if the user is the blog user.
* @param int $user_id The user ID.
Expand Down
54 changes: 50 additions & 4 deletions includes/model/class-blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ public function get_preferred_username() {
* @return array The User-Icon.
*/
public function get_icon() {
// try site icon first
$icon_id = get_option( 'site_icon' );
// try site_logo, falling back to site_icon, first
$icon_id = get_option( 'site_logo', get_option( 'site_icon' ) );

// try custom logo second
if ( ! $icon_id ) {
Expand Down Expand Up @@ -394,11 +394,57 @@ public function get_indexable() {
}

/**
* Get the User-Hashtags.
* Update the User-Name.
*
* @param mixed $value The new value.
* @return bool True if the attribute was updated, false otherwise.
*/
public function update_name( $value ) {
return \update_option( 'blogname', $value );
}

/**
* Update the User-Description.
*
* @param mixed $value The new value.
* @return bool True if the attribute was updated, false otherwise.
*/
public function update_summary( $value ) {
return \update_option( 'blogdescription', $value );
}

/**
* Update the User-Icon.
*
* @param mixed $value The new value.
* @return bool True if the attribute was updated, false otherwise.
*/
public function update_icon( $value ) {
if ( ! wp_attachment_is_image( $value ) ) {
return false;
}
return \update_option( 'site_logo', $value ) && \update_option( 'site_icon', $value );
}

/**
* Update the User-Header-Image.
*
* @param mixed $value The new value.
* @return bool True if the attribute was updated, false otherwise.
*/
public function update_header( $value ) {
if ( ! wp_attachment_is_image( $value ) ) {
return false;
}
return \update_option( 'activitypub_header_image', $value );
}

/**
* Get the User - Hashtags .
*
* @see https://docs.joinmastodon.org/spec/activitypub/#Hashtag
*
* @return array The User-Hashtags.
* @return array The User - Hashtags .
*/
public function get_tag() {
$hashtags = array();
Expand Down
64 changes: 60 additions & 4 deletions includes/model/class-user.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ public function get_preferred_username() {
}

public function get_icon() {
$icon = \get_user_option( 'activitypub_icon', $this->_id );
if ( wp_attachment_is_image( $icon ) ) {
return array(
'type' => 'Image',
'url' => esc_url( wp_get_attachment_url( $icon ) ),
);
}

$icon = \esc_url(
\get_avatar_url(
$this->_id,
Expand All @@ -158,12 +166,12 @@ public function get_image() {
$header_image = get_user_option( 'activitypub_header_image', $this->_id );
$image_url = null;

if ( $header_image ) {
$image_url = \wp_get_attachment_url( $header_image );
if ( ! $header_image && \has_header_image() ) {
$image_url = \get_header_image();
}

if ( ! $image_url && \has_header_image() ) {
$image_url = \get_header_image();
if ( $header_image ) {
$image_url = \wp_get_attachment_url( $header_image );
}

if ( $image_url ) {
Expand Down Expand Up @@ -283,4 +291,52 @@ public function get_indexable() {
return false;
}
}


/**
* Update the User-Name.
*
* @param mixed $value The new value.
* @return bool True if the attribute was updated, false otherwise.
*/
public function update_name( $value ) {
$userdata = [ 'ID' => $this->_id, 'display_name' => $value ];
return \wp_update_user( $userdata );
}

/**
* Update the User-Description.
*
* @param mixed $value The new value.
* @return bool True if the attribute was updated, false otherwise.
*/
public function update_summary( $value ) {
return \update_user_option( $this->_id, 'activitypub_description', $value );
}

/**
* Update the User-Icon.
*
* @param mixed $value The new value. Should be an attachment ID.
* @return bool True if the attribute was updated, false otherwise.
*/
public function update_icon( $value ) {
if ( ! wp_attachment_is_image( $value ) ) {
return false;
}
return update_user_option( $this->_id, 'activitypub_icon', $value );
}

/**
* Update the User-Header-Image.
*
* @param mixed $value The new value. Should be an attachment ID.
* @return bool True if the attribute was updated, false otherwise.
*/
public function update_header( $value ) {
if ( ! wp_attachment_is_image( $value ) ) {
return false;
}
return \update_user_option( $this->_id, 'activitypub_header_image', $value );
}
}
Loading

0 comments on commit 6f2c91e

Please sign in to comment.