Skip to content
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

Use a Custom Web Protocol for following #262

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions feed-parsers/class-feed-parser-activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public function __construct( Feed $friends_feed ) {
\add_filter( 'friends_reblog', array( $this, 'reblog' ), 20, 2 );
\add_filter( 'friends_unreblog', array( $this, 'unreblog' ), 20, 2 );
\add_filter( 'friends_reblog', array( $this, 'maybe_unqueue_friends_reblog_post' ), 9, 2 );
\add_filter( 'friends_reblogged_author', array( $this, 'reblogged_author' ), 10, 2 );

\add_filter( 'pre_get_remote_metadata_by_actor', array( $this, 'disable_webfinger_for_example_domains' ), 9, 2 );

Expand Down Expand Up @@ -1580,6 +1581,18 @@ public function maybe_unqueue_friends_reblog_post( $ret, $post ) {
return $ret;
}

public function reblogged_author( $url, $post_id ) {
if ( User_Feed::get_parser_for_post_id( $post_id ) !== 'activitypub' ) {
return $url;
}

$meta = get_post_meta( $post_id, self::SLUG, true );
if ( isset( $meta['attributedTo']['id'] ) ) {
return $meta['attributedTo']['id'];
}
return $url;
}

public function reblog( $ret, $post ) {
$post = get_post( $post );
if ( ! $post ) {
Expand Down
7 changes: 5 additions & 2 deletions includes/class-feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -755,8 +755,11 @@ public function friends_add_friend_redirect() {
if ( ! isset( $_GET['add-friend'] ) || isset( $_GET['page'] ) ) {
return;
}

wp_safe_redirect( add_query_arg( 'url', $_GET['add-friend'], self_admin_url( 'admin.php?page=add-friend' ) ) );
$add_friend = $_GET['add-friend'];
if ( 'web+follow' === substr( $add_friend, 0, 10 ) ) {
$add_friend = substr( $add_friend, 13 );
}
wp_safe_redirect( add_query_arg( 'url', $add_friend, self_admin_url( 'admin.php?page=add-friend' ) ) );
exit;
}

Expand Down
1 change: 1 addition & 0 deletions includes/class-frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ private function register_hooks() {
add_filter( 'body_class', array( $this, 'add_body_class' ) );

add_filter( 'friends_override_author_name', array( $this, 'override_author_name' ), 10, 3 );
add_filter( 'friends_boosted_author', array( $this, 'boosted_author' ), 10, 2 );
}

/**
Expand Down
5 changes: 5 additions & 0 deletions templates/frontend/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php wp_head(); ?>
<script>
if (typeof navigator.registerProtocolHandler === "function") {
navigator.registerProtocolHandler( 'web+follow', '<?php echo esc_js( add_query_arg( 'add-friend', '%s', home_url() ) ); ?>', 'Follow' );
}
</script>
</head>

<body <?php body_class( 'off-canvas off-canvas-sidebar-show' ); ?>>
Expand Down
5 changes: 5 additions & 0 deletions templates/frontend/parts/header-status.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* ```
*/
$override_author_name = apply_filters( 'friends_override_author_name', '', $author_name, get_the_id() );
$reblogged_author = apply_filters( 'friends_reblogged_author', false, get_the_id() );
?><header class="entry-header card-header columns">
<div class="avatar col-auto mr-2">
<?php if ( in_array( get_post_type(), apply_filters( 'friends_frontend_post_types', array() ), true ) ) : ?>
Expand All @@ -49,6 +50,10 @@
– <?php echo esc_html( $override_author_name ); ?>
<?php endif; ?>
</a>
<?php if ( $reblogged_author ) : ?>
[<a href="web+follow://<?php echo esc_attr( $reblogged_author ); ?>"><?php esc_html_e( 'Follow', 'friends' ); ?></a>]
<?php endif; ?>

<?php else : ?>
<a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>">
<strong><?php the_author(); ?></strong>
Expand Down