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

Don't add domain for mentions #465

Merged
merged 1 commit into from
Feb 7, 2025
Merged
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
52 changes: 0 additions & 52 deletions feed-parsers/class-feed-parser-activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -1731,29 +1731,6 @@ public function check_url_to_postid( $post_id, $url ) {
}

public function the_content( $the_content ) {
$protected_tags = array();
foreach ( array(
'#<a.*?href=[^>]+>.*?</a>#i', // leave the inside of links alone.
'#<script[^>]*>.*?</script>#i', // leave the inside of scripts alone.
'#<style[^>]*>.*?</script>#i', // leave the inside of styles alone.
'#<[^>]+>#i', // leave the inside of any tags alone.
) as $regex ) {
$the_content = preg_replace_callback(
$regex,
function ( $m ) use ( &$protected_tags ) {
$c = count( $protected_tags );
$protect = '!#!#PROTECT' . $c . '#!#!';
$protected_tags[ $protect ] = $m[0];
return $protect;
},
$the_content
);
}

$the_content = \preg_replace_callback( '/@(?:[a-zA-Z0-9_-]+)/', array( $this, 'replace_with_links' ), $the_content );

$the_content = str_replace( array_keys( $protected_tags ), array_values( $protected_tags ), $the_content );

// replace all links in <a href="mention hashtag"> with /friends/tag/tagname using the WP_HTML_Tag_Processor.
$processor = new \WP_HTML_Tag_Processor( $the_content );
while ( $processor->next_tag( array( 'tag_name' => 'a' ) ) ) {
Expand All @@ -1778,35 +1755,6 @@ function ( $m ) use ( &$protected_tags ) {
return $the_content;
}

/**
* Replace the mention with a link to the user.
*
* @param array $result The matched username.
*
* @return string The replaced username.
*/
public function replace_with_links( array $result ) {
$users = self::get_possible_mentions();
if ( ! isset( $users[ $result[0] ] ) ) {
return $result[0];
}

$metadata = $this->get_metadata( $users[ $result[0] ] );
if ( is_wp_error( $metadata ) || empty( $metadata['url'] ) ) {
return $result[0];
}

$username = ltrim( $users[ $result[0] ], '@' );
if ( ! empty( $metadata['name'] ) ) {
$username = $metadata['name'];
}
if ( ! empty( $metadata['preferredUsername'] ) ) {
$username = $metadata['preferredUsername'];
}
$username = '@<span>' . $username . '</span>';
return \sprintf( '<a rel="mention" class="u-url mention" href="%s">%s</a>', $metadata['url'], $username );
}

public function activitypub_save_settings( User $friend ) {
if ( ! isset( $_POST['_wpnonce'] ) || wp_verify_nonce( sanitize_key( $_POST['_wpnonce'] ), 'edit-friend-feeds-' . $friend->user_login ) ) {
return;
Expand Down