coding standards
This commit is contained in:
parent
73e6be9782
commit
51643142aa
8 changed files with 187 additions and 198 deletions
|
@ -50,7 +50,7 @@ class Activity_Dispatcher {
|
||||||
*/
|
*/
|
||||||
public static function send_update_activity( $activitypub_post ) {
|
public static function send_update_activity( $activitypub_post ) {
|
||||||
// save permalink for delete
|
// save permalink for delete
|
||||||
$post_id = \url_to_postid( $activitypub_post->get_id() );
|
$post_id = \url_to_postid( $activitypub_post->get_id() );
|
||||||
//shouldn't this go in schedule_*_activity? yeah
|
//shouldn't this go in schedule_*_activity? yeah
|
||||||
\update_post_meta( $post_id, '_ap_deleted_slug', $activitypub_post->get_id() );
|
\update_post_meta( $post_id, '_ap_deleted_slug', $activitypub_post->get_id() );
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ class Activity_Dispatcher {
|
||||||
public static function send_comment_activity( $activitypub_comment_id ) {
|
public static function send_comment_activity( $activitypub_comment_id ) {
|
||||||
//ONLY FOR LOCAL USERS ?
|
//ONLY FOR LOCAL USERS ?
|
||||||
$activitypub_comment = \get_comment( $activitypub_comment_id );
|
$activitypub_comment = \get_comment( $activitypub_comment_id );
|
||||||
$user_id = $activitypub_comment->user_id;
|
$user_id = $activitypub_comment->user_id;
|
||||||
$replyto = get_comment_meta( $activitypub_comment->comment_parent, 'comment_author_url', true );// must include in replyto
|
$replyto = get_comment_meta( $activitypub_comment->comment_parent, 'comment_author_url', true );// must include in replyto
|
||||||
$mentions = get_comment_meta( $activitypub_comment_id, 'mentions', true );//might be tagged
|
$mentions = get_comment_meta( $activitypub_comment_id, 'mentions', true );//might be tagged
|
||||||
|
|
||||||
|
@ -121,8 +121,8 @@ class Activity_Dispatcher {
|
||||||
$activity = $activitypub_activity->to_json(); // phpcs:ignore
|
$activity = $activitypub_activity->to_json(); // phpcs:ignore
|
||||||
|
|
||||||
// Send reply to followers, skip if replying to followers (avoid duplicate replies)
|
// Send reply to followers, skip if replying to followers (avoid duplicate replies)
|
||||||
if( in_array( $cc, $replyto ) || in_array( $cc, $mentions ) ) {
|
if ( in_array( $cc, $replyto ) || in_array( $cc, $mentions ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
\Activitypub\safe_remote_post( $inbox, $activity, $user_id );
|
\Activitypub\safe_remote_post( $inbox, $activity, $user_id );
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,7 @@ class Activity_Dispatcher {
|
||||||
//will be forwarded to the parent_comment->author or post_author followers collection
|
//will be forwarded to the parent_comment->author or post_author followers collection
|
||||||
//TODO verify that ... what?
|
//TODO verify that ... what?
|
||||||
$parent_comment = \get_comment( $activitypub_comment->comment_parent );
|
$parent_comment = \get_comment( $activitypub_comment->comment_parent );
|
||||||
if ( !is_null( $parent_comment ) ) {
|
if ( ! is_null( $parent_comment ) ) {
|
||||||
$user_id = $parent_comment->user_id;
|
$user_id = $parent_comment->user_id;
|
||||||
} else {
|
} else {
|
||||||
$original_post = \get_post( $activitypub_comment->comment_post_ID );
|
$original_post = \get_post( $activitypub_comment->comment_post_ID );
|
||||||
|
@ -151,12 +151,12 @@ class Activity_Dispatcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
//remove user_id from $activitypub_comment
|
//remove user_id from $activitypub_comment
|
||||||
unset($activitypub_activity['user_id']);
|
unset( $activitypub_activity['user_id'] );
|
||||||
|
|
||||||
foreach ( \Activitypub\get_follower_inboxes( $user_id ) as $inbox => $to ) {
|
foreach ( \Activitypub\get_follower_inboxes( $user_id ) as $inbox => $to ) {
|
||||||
|
|
||||||
//Forward reply to followers, skip sender
|
//Forward reply to followers, skip sender
|
||||||
if( in_array( $to, $replyto ) || ( $replyto == $to ) ) {
|
if ( in_array( $to, $replyto ) || ( $replyto == $to ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,8 @@ class Activitypub {
|
||||||
|
|
||||||
\add_action( 'transition_post_status', array( '\Activitypub\Activitypub', 'schedule_post_activity' ), 10, 3 );
|
\add_action( 'transition_post_status', array( '\Activitypub\Activitypub', 'schedule_post_activity' ), 10, 3 );
|
||||||
|
|
||||||
\add_filter( 'preprocess_comment' , array( '\Activitypub\Activitypub', 'preprocess_comment' ) );
|
\add_filter( 'preprocess_comment', array( '\Activitypub\Activitypub', 'preprocess_comment' ) );
|
||||||
\add_filter( 'comment_post' , array( '\Activitypub\Activitypub', 'postprocess_comment' ), 10, 3 );
|
\add_filter( 'comment_post', array( '\Activitypub\Activitypub', 'postprocess_comment' ), 10, 3 );
|
||||||
\add_filter( 'wp_update_comment_data', array( '\Activitypub\Activitypub', 'comment_updated_published' ), 20, 3 );
|
\add_filter( 'wp_update_comment_data', array( '\Activitypub\Activitypub', 'comment_updated_published' ), 20, 3 );
|
||||||
\add_action( 'transition_comment_status', array( '\Activitypub\Activitypub', 'schedule_comment_activity' ), 20, 3 );
|
\add_action( 'transition_comment_status', array( '\Activitypub\Activitypub', 'schedule_comment_activity' ), 20, 3 );
|
||||||
\add_action( 'edit_comment', array( '\Activitypub\Activitypub', 'edit_comment' ), 20, 2 );//schedule_admin_comment_activity
|
\add_action( 'edit_comment', array( '\Activitypub\Activitypub', 'edit_comment' ), 20, 2 );//schedule_admin_comment_activity
|
||||||
|
@ -149,7 +149,7 @@ class Activitypub {
|
||||||
*/
|
*/
|
||||||
public static function preprocess_comment( $commentdata ) {
|
public static function preprocess_comment( $commentdata ) {
|
||||||
// only process replies from local actors
|
// only process replies from local actors
|
||||||
if ( !empty( $commentdata['user_id'] ) ) {
|
if ( ! empty( $commentdata['user_id'] ) ) {
|
||||||
$commentdata['comment_type'] = 'activitypub';
|
$commentdata['comment_type'] = 'activitypub';
|
||||||
// transform webfinger mentions to links and add @mentions to cc
|
// transform webfinger mentions to links and add @mentions to cc
|
||||||
$tagged_content = \Activitypub\transform_tags( $commentdata['comment_content'] );
|
$tagged_content = \Activitypub\transform_tags( $commentdata['comment_content'] );
|
||||||
|
@ -167,12 +167,11 @@ class Activitypub {
|
||||||
//Admin users comments bypass transition_comment_status (auto approved)
|
//Admin users comments bypass transition_comment_status (auto approved)
|
||||||
|
|
||||||
if ( $commentdata['comment_type'] === 'activitypub' ) {
|
if ( $commentdata['comment_type'] === 'activitypub' ) {
|
||||||
if (
|
if ( ( $comment_approved === 1 ) &&
|
||||||
( $comment_approved === 1 ) &&
|
|
||||||
! empty( $commentdata['user_id'] ) &&
|
! empty( $commentdata['user_id'] ) &&
|
||||||
( $user = get_userdata( $commentdata['user_id'] ) ) && // get the user data
|
( $user = get_userdata( $commentdata['user_id'] ) ) && // get the user data
|
||||||
in_array( 'administrator', $user->roles ) // check the roles
|
in_array( 'administrator', $user->roles ) // check the roles
|
||||||
) {
|
) {
|
||||||
// Only for Admins?
|
// Only for Admins?
|
||||||
$mentions = \get_comment_meta( $comment_id, 'mentions', true );
|
$mentions = \get_comment_meta( $comment_id, 'mentions', true );
|
||||||
//\ActivityPub\Activity_Dispatcher::send_comment_activity( $comment_id ); // performance > followers collection
|
//\ActivityPub\Activity_Dispatcher::send_comment_activity( $comment_id ); // performance > followers collection
|
||||||
|
@ -183,21 +182,6 @@ class Activitypub {
|
||||||
// TODO comment test as anon / no auth_url, no fetchable status?
|
// TODO comment test as anon / no auth_url, no fetchable status?
|
||||||
// TODO comment test as registered
|
// TODO comment test as registered
|
||||||
// TODO comment test as anyother site settings
|
// TODO comment test as anyother site settings
|
||||||
|
|
||||||
|
|
||||||
// $replyto = get_comment_meta( $comment_id, 'replyto', true );
|
|
||||||
|
|
||||||
//inbox forward prep
|
|
||||||
// if ( !empty( $ap_object ) ) {
|
|
||||||
// //if is remote user (has ap_object)
|
|
||||||
// //error_log( print_r( $ap_object, true ) );
|
|
||||||
// // TODO verify that deduplication check happens at object create.
|
|
||||||
|
|
||||||
// //if to/cc/audience contains local followers collection
|
|
||||||
// //$local_user = \get_comment_author_url( $comment_id );
|
|
||||||
// //$is_local_user = \Activitypub\url_to_authorid( $commentdata['comment_author_url'] );
|
|
||||||
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -232,14 +216,14 @@ class Activitypub {
|
||||||
\wp_schedule_single_event( \time(), 'activitypub_send_comment_activity', array( $activitypub_comment->comment_ID ) );
|
\wp_schedule_single_event( \time(), 'activitypub_send_comment_activity', array( $activitypub_comment->comment_ID ) );
|
||||||
} else {
|
} else {
|
||||||
$local_user = \get_author_posts_url( $ap_object['user_id'] );
|
$local_user = \get_author_posts_url( $ap_object['user_id'] );
|
||||||
if ( !is_null( $local_user ) ) {
|
if ( ! is_null( $local_user ) ) {
|
||||||
if ( in_array( $local_user, $ap_object['to'] )
|
if ( in_array( $local_user, $ap_object['to'] )
|
||||||
|| in_array( $local_user, $ap_object['cc'] )
|
|| in_array( $local_user, $ap_object['cc'] )
|
||||||
|| in_array( $local_user, $ap_object['audience'] )
|
|| in_array( $local_user, $ap_object['audience'] )
|
||||||
|| in_array( $local_user, $ap_object['tag'] )
|
|| in_array( $local_user, $ap_object['tag'] )
|
||||||
) {
|
) {
|
||||||
//if inReplyTo, object, target and/or tag are (local-wp) objects
|
//if inReplyTo, object, target and/or tag are (local-wp) objects
|
||||||
\wp_schedule_single_event( \time(), 'activitypub_inbox_forward_activity', array( $activitypub_comment->comment_ID ) );
|
\wp_schedule_single_event( \time(), 'activitypub_inbox_forward_activity', array( $activitypub_comment->comment_ID ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -248,9 +232,7 @@ class Activitypub {
|
||||||
} elseif ( $old_status === $new_status ) {
|
} elseif ( $old_status === $new_status ) {
|
||||||
//TODO Test with non-admin user
|
//TODO Test with non-admin user
|
||||||
\wp_schedule_single_event( \time(), 'activitypub_send_update_comment_activity', array( $activitypub_comment->comment_ID ) );
|
\wp_schedule_single_event( \time(), 'activitypub_send_update_comment_activity', array( $activitypub_comment->comment_ID ) );
|
||||||
} else {
|
} else { }
|
||||||
//error_log( 'schedule_update_comment_activity: else?:' );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -261,7 +243,7 @@ class Activitypub {
|
||||||
public static function comment_append_edit_datetime( $comment_text, $comment, $args ) {
|
public static function comment_append_edit_datetime( $comment_text, $comment, $args ) {
|
||||||
if ( 'activitypub' === $comment->comment_type ) {
|
if ( 'activitypub' === $comment->comment_type ) {
|
||||||
$updated = \wp_date( 'Y-m-d H:i:s', \strtotime( \get_comment_meta( $comment->comment_ID, 'ap_last_modified', true ) ) );
|
$updated = \wp_date( 'Y-m-d H:i:s', \strtotime( \get_comment_meta( $comment->comment_ID, 'ap_last_modified', true ) ) );
|
||||||
if( $updated ) {
|
if ( $updated ) {
|
||||||
$append_updated = "<div>(Last edited on <time class='modified' datetime='{$updated}'>$updated</time>)</div>";
|
$append_updated = "<div>(Last edited on <time class='modified' datetime='{$updated}'>$updated</time>)</div>";
|
||||||
$comment_text .= $append_updated;
|
$comment_text .= $append_updated;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Activitypub;
|
namespace Activitypub;
|
||||||
|
|
||||||
define('AS_PUBLIC', 'https://www.w3.org/ns/activitystreams#Public');
|
define( 'AS_PUBLIC', 'https://www.w3.org/ns/activitystreams#Public' );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the ActivityPub default JSON-context
|
* Returns the ActivityPub default JSON-context
|
||||||
|
@ -58,7 +58,7 @@ function safe_remote_post( $url, $body, $user_id ) {
|
||||||
|
|
||||||
$response = \wp_safe_remote_post( $url, $args );
|
$response = \wp_safe_remote_post( $url, $args );
|
||||||
|
|
||||||
//\do_action( 'activitypub_safe_remote_post_response', $response, $url, $body, $user_id );
|
\do_action( 'activitypub_safe_remote_post_response', $response, $url, $body, $user_id );
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
@ -355,7 +355,6 @@ function url_to_authorid( $url ) {
|
||||||
/**
|
/**
|
||||||
* Verify if in_replyto_url is a local comment,
|
* Verify if in_replyto_url is a local comment,
|
||||||
* Or if it is a previously received remote comment
|
* Or if it is a previously received remote comment
|
||||||
*
|
|
||||||
* return int comment_id
|
* return int comment_id
|
||||||
*/
|
*/
|
||||||
function url_to_commentid( $in_replyto_url ) {
|
function url_to_commentid( $in_replyto_url ) {
|
||||||
|
@ -366,10 +365,10 @@ function url_to_commentid( $in_replyto_url ) {
|
||||||
//rewrite for activitypub object id simplification
|
//rewrite for activitypub object id simplification
|
||||||
$url_maybe_id = \wp_parse_url( $in_replyto_url );
|
$url_maybe_id = \wp_parse_url( $in_replyto_url );
|
||||||
|
|
||||||
if ( $url_maybe_id['scheme'] . '://' . $url_maybe_id['host'] == site_url() ) {
|
if ( site_url() === $url_maybe_id['scheme'] . '://' . $url_maybe_id['host'] ) {
|
||||||
//is local post or comment
|
//is local post or comment
|
||||||
\parse_str( $url_maybe_id['query'], $reply_query );
|
\parse_str( $url_maybe_id['query'], $reply_query );
|
||||||
if (isset( $reply_query['ap_comment_id'] ) && is_int( $reply_query['ap_comment_id'] ) ){
|
if ( isset( $reply_query['ap_comment_id'] ) && is_int( $reply_query['ap_comment_id'] ) ) {
|
||||||
//is local comment
|
//is local comment
|
||||||
return $reply_query['ap_comment_id'];
|
return $reply_query['ap_comment_id'];
|
||||||
} else {
|
} else {
|
||||||
|
@ -383,12 +382,12 @@ function url_to_commentid( $in_replyto_url ) {
|
||||||
'type' => 'activitypub',
|
'type' => 'activitypub',
|
||||||
'meta_query' => array(
|
'meta_query' => array(
|
||||||
array(
|
array(
|
||||||
'key' => 'source_url',//$object['object']['id']
|
'key' => 'source_url', //$object['object']['id']
|
||||||
'value' => $in_replyto_url,
|
'value' => $in_replyto_url,
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
$comments_query = new \WP_Comment_Query;
|
$comments_query = new \WP_Comment_Query();
|
||||||
$comments = $comments_query->query( $comment_args );
|
$comments = $comments_query->query( $comment_args );
|
||||||
$found_comment_ids = array();
|
$found_comment_ids = array();
|
||||||
if ( $comments ) {
|
if ( $comments ) {
|
||||||
|
@ -404,15 +403,14 @@ function url_to_commentid( $in_replyto_url ) {
|
||||||
/**
|
/**
|
||||||
* Verify if url is a wp_ap_comment,
|
* Verify if url is a wp_ap_comment,
|
||||||
* Or if it is a previously received remote comment
|
* Or if it is a previously received remote comment
|
||||||
*
|
|
||||||
* return int comment_id
|
* return int comment_id
|
||||||
*/
|
*/
|
||||||
function is_ap_comment() {
|
function is_ap_comment() {
|
||||||
$comment_id = get_query_var( 'ap_comment_id', null );
|
$comment_id = get_query_var( 'ap_comment_id', null );
|
||||||
if( ! is_null( $comment_id ) ) {
|
if ( ! is_null( $comment_id ) ) {
|
||||||
$comment = \get_comment( $comment_id );
|
$comment = \get_comment( $comment_id );
|
||||||
// Only return local origin comments
|
// Only return local origin comments
|
||||||
if( $comment->user_id ) {
|
if ( $comment->user_id ) {
|
||||||
return $comment_id;
|
return $comment_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -421,14 +419,12 @@ function is_ap_comment() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify if url is a /replies endoint,
|
* Verify if url is a /replies endoint,
|
||||||
*
|
|
||||||
* return int true
|
* return int true
|
||||||
*/
|
*/
|
||||||
function is_ap_replies() {
|
function is_ap_replies() {
|
||||||
global $wp;
|
global $wp;
|
||||||
$replies = get_query_var( 'replies' );
|
$replies = get_query_var( 'replies' );
|
||||||
//$page = get_query_var( 'collection_page' );
|
if ( $replies ) {
|
||||||
if( ( $replies ) ) {
|
|
||||||
return $replies;
|
return $replies;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -438,7 +434,6 @@ function is_ap_replies() {
|
||||||
* Get tagged users from received AP object meta
|
* Get tagged users from received AP object meta
|
||||||
* @param string $object_id a comment_id to search
|
* @param string $object_id a comment_id to search
|
||||||
* @param boolean $post defaults to searching a comment_id
|
* @param boolean $post defaults to searching a comment_id
|
||||||
*
|
|
||||||
* @return array of tagged users
|
* @return array of tagged users
|
||||||
*/
|
*/
|
||||||
function get_recipients( $object_id, $post = null ) {
|
function get_recipients( $object_id, $post = null ) {
|
||||||
|
@ -451,9 +446,9 @@ function get_recipients( $object_id, $post = null ) {
|
||||||
$ap_object = \unserialize( \get_comment_meta( $object_id, 'ap_object', true ) );
|
$ap_object = \unserialize( \get_comment_meta( $object_id, 'ap_object', true ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !empty( $ap_object ) ) {
|
if ( ! empty( $ap_object ) ) {
|
||||||
$tagged_users_name[] = \Activitypub\url_to_webfinger( $ap_object['actor'] );
|
$tagged_users_name[] = \Activitypub\url_to_webfinger( $ap_object['actor'] );
|
||||||
if ( !empty( $ap_object['object']['tag'] ) ) {
|
if ( ! empty( $ap_object['object']['tag'] ) ) {
|
||||||
$author_post_url = \get_author_posts_url( $ap_object['user_id'] );
|
$author_post_url = \get_author_posts_url( $ap_object['user_id'] );
|
||||||
foreach ( $ap_object['object']['tag'] as $tag ) {
|
foreach ( $ap_object['object']['tag'] as $tag ) {
|
||||||
if ( $author_post_url == $tag['href'] ) {
|
if ( $author_post_url == $tag['href'] ) {
|
||||||
|
@ -473,8 +468,8 @@ function get_recipients( $object_id, $post = null ) {
|
||||||
*/
|
*/
|
||||||
function get_summary( $comment_id ) {
|
function get_summary( $comment_id ) {
|
||||||
$ap_object = \unserialize( \get_comment_meta( $comment_id, 'ap_object', true ) );
|
$ap_object = \unserialize( \get_comment_meta( $comment_id, 'ap_object', true ) );
|
||||||
if ( !empty( $ap_object ) ) {
|
if ( ! empty( $ap_object ) ) {
|
||||||
if ( !empty( $ap_object['object']['summary'] ) ) {
|
if ( ! empty( $ap_object['object']['summary'] ) ) {
|
||||||
return \esc_attr( $ap_object['object']['summary'] );
|
return \esc_attr( $ap_object['object']['summary'] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -490,7 +485,7 @@ function transform_tags( $content ) {
|
||||||
//@Mentions
|
//@Mentions
|
||||||
$mentions = null;
|
$mentions = null;
|
||||||
$webfinger_tags = \Activitypub\webfinger_extract( $content );
|
$webfinger_tags = \Activitypub\webfinger_extract( $content );
|
||||||
if ( !empty( $webfinger_tags) ) {
|
if ( ! empty( $webfinger_tags ) ) {
|
||||||
foreach ( $webfinger_tags[0] as $webfinger_tag ) {
|
foreach ( $webfinger_tags[0] as $webfinger_tag ) {
|
||||||
$ap_profile = \Activitypub\Rest\Webfinger::webfinger_lookup( $webfinger_tag );
|
$ap_profile = \Activitypub\Rest\Webfinger::webfinger_lookup( $webfinger_tag );
|
||||||
if ( ! empty( $ap_profile ) ) {
|
if ( ! empty( $ap_profile ) ) {
|
||||||
|
@ -522,7 +517,7 @@ function tag_user( $recipient ) {
|
||||||
* @return array of all matched webfinger
|
* @return array of all matched webfinger
|
||||||
*/
|
*/
|
||||||
function webfinger_extract( $string ) {
|
function webfinger_extract( $string ) {
|
||||||
preg_match_all("/@[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $string, $matches);
|
preg_match_all( '/@[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i', $string, $matches );
|
||||||
return $matches;
|
return $matches;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -543,7 +538,7 @@ function url_to_webfinger( $user_url ) {
|
||||||
$user_url = \untrailingslashit( $user_url );
|
$user_url = \untrailingslashit( $user_url );
|
||||||
$user_url_array = explode( '/', $user_url );
|
$user_url_array = explode( '/', $user_url );
|
||||||
$user_name = end( $user_url_array );
|
$user_name = end( $user_url_array );
|
||||||
$url_host = parse_url( $user_url , PHP_URL_HOST );
|
$url_host = parse_url( $user_url, PHP_URL_HOST );
|
||||||
$webfinger = '@' . $user_name . '@' . $url_host;
|
$webfinger = '@' . $user_name . '@' . $url_host;
|
||||||
return $webfinger;
|
return $webfinger;
|
||||||
}
|
}
|
||||||
|
@ -574,13 +569,13 @@ function set_ap_comment_id( $comment ) {
|
||||||
$ap_comment_id = add_query_arg(
|
$ap_comment_id = add_query_arg(
|
||||||
array(
|
array(
|
||||||
'p' => $comment->comment_post_ID,
|
'p' => $comment->comment_post_ID,
|
||||||
'ap_comment_id' => $comment->comment_ID,//should probably rename to ap_comment or something
|
'ap_comment_id' => $comment->comment_ID, //should probably rename to ap_comment or something
|
||||||
),
|
),
|
||||||
trailingslashit( site_url() )
|
trailingslashit( site_url() )
|
||||||
);
|
);
|
||||||
return $ap_comment_id;
|
return $ap_comment_id;
|
||||||
}
|
}
|
||||||
/* comment_id_to_url( $comment_id ) {
|
/* comment_id_to_url( $comment_id ) {
|
||||||
//get remote from post_id from comment meta
|
//get remote from post_id from comment meta
|
||||||
//get local normalized comment_link
|
//get local normalized comment_link
|
||||||
}
|
}
|
||||||
|
@ -598,7 +593,7 @@ function get_audience( $object ) {
|
||||||
if ( in_array( AS_PUBLIC, $object['cc'] ) ) {
|
if ( in_array( AS_PUBLIC, $object['cc'] ) ) {
|
||||||
return 'unlisted';//is unlisted even relevant?
|
return 'unlisted';//is unlisted even relevant?
|
||||||
}
|
}
|
||||||
if ( !in_array( AS_PUBLIC, $object['to'] ) && !in_array( AS_PUBLIC, $object['cc'] ) ) {
|
if ( ! in_array( AS_PUBLIC, $object['to'] ) && ! in_array( AS_PUBLIC, $object['cc'] ) ) {
|
||||||
$author_post_url = get_author_posts_url( $object['user_id'] );
|
$author_post_url = get_author_posts_url( $object['user_id'] );
|
||||||
if ( in_array( $author_post_url, $object['cc'] ) ) {
|
if ( in_array( $author_post_url, $object['cc'] ) ) {
|
||||||
return 'followers_only';
|
return 'followers_only';
|
||||||
|
|
|
@ -76,7 +76,7 @@ class Activity {
|
||||||
if ( $this->trash ) {
|
if ( $this->trash ) {
|
||||||
$this->deleted = $timestamp['deleted'];
|
$this->deleted = $timestamp['deleted'];
|
||||||
}
|
}
|
||||||
if ( $this->updated) {
|
if ( $this->updated ) {
|
||||||
$this->updated = $timestamp['updated'];
|
$this->updated = $timestamp['updated'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,8 +58,8 @@ class Comment {
|
||||||
),
|
),
|
||||||
'context' => $this->context,
|
'context' => $this->context,
|
||||||
//'source' => \get_comment_link( $comment ), //non-conforming, see https://www.w3.org/TR/activitypub/#source-property
|
//'source' => \get_comment_link( $comment ), //non-conforming, see https://www.w3.org/TR/activitypub/#source-property
|
||||||
'url' => \get_comment_link( $comment ),//link for mastodon
|
'url' => \get_comment_link( $comment ), //link for mastodon
|
||||||
'to' => array( 'https://www.w3.org/ns/activitystreams#Public' ),//audience logic
|
'to' => array( 'https://www.w3.org/ns/activitystreams#Public' ), //audience logic
|
||||||
'cc' => $this->cc_recipients,
|
'cc' => $this->cc_recipients,
|
||||||
'tag' => $this->tags,
|
'tag' => $this->tags,
|
||||||
);
|
);
|
||||||
|
@ -171,9 +171,9 @@ class Comment {
|
||||||
//TODO Add audience logic get parent audience
|
//TODO Add audience logic get parent audience
|
||||||
//TODO shouldn't mentions go in 'to'?
|
//TODO shouldn't mentions go in 'to'?
|
||||||
$recipients = array( AS_PUBLIC );
|
$recipients = array( AS_PUBLIC );
|
||||||
$mentions = \get_comment_meta( $this->comment->comment_ID, 'mentions', true ) ;
|
$mentions = \get_comment_meta( $this->comment->comment_ID, 'mentions', true );
|
||||||
if ( !empty( $mentions ) ) {
|
if ( ! empty( $mentions ) ) {
|
||||||
foreach ($mentions as $mention) {
|
foreach ( $mentions as $mention ) {
|
||||||
$recipients[] = $mention['href'];
|
$recipients[] = $mention['href'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -184,9 +184,9 @@ class Comment {
|
||||||
* Mention user being replied to
|
* Mention user being replied to
|
||||||
*/
|
*/
|
||||||
public function generate_tags() {
|
public function generate_tags() {
|
||||||
$mentions = \get_comment_meta( $this->comment->comment_ID, 'mentions', true ) ;
|
$mentions = \get_comment_meta( $this->comment->comment_ID, 'mentions', true );
|
||||||
if ( !empty( $mentions ) ) {
|
if ( ! empty( $mentions ) ) {
|
||||||
foreach ($mentions as $mention) {
|
foreach ( $mentions as $mention ) {
|
||||||
$mention_tags[] = array(
|
$mention_tags[] = array(
|
||||||
'type' => 'Mention',
|
'type' => 'Mention',
|
||||||
'href' => $mention['href'],
|
'href' => $mention['href'],
|
||||||
|
@ -227,36 +227,42 @@ class Comment {
|
||||||
public function generate_replies() {
|
public function generate_replies() {
|
||||||
$comment = $this->comment;
|
$comment = $this->comment;
|
||||||
$args = array(
|
$args = array(
|
||||||
'post_id' => $comment->comment_post_ID,
|
'post_id' => $comment->comment_post_ID,
|
||||||
'parent' => $comment->comment_ID,
|
'parent' => $comment->comment_ID,
|
||||||
'author__in' => $comment->user_id,
|
'author__in' => $comment->user_id,
|
||||||
'status' => 'approve',
|
'status' => 'approve',
|
||||||
'hierarchical' => false,
|
'hierarchical' => false,
|
||||||
);
|
);
|
||||||
$children = \get_comments( $args );
|
$children = \get_comments( $args );
|
||||||
$replies = null;
|
$replies = null;
|
||||||
if ( $children ) {
|
if ( $children ) {
|
||||||
$items = [];
|
$items = array();
|
||||||
foreach ( $children as $child_comment ){
|
foreach ( $children as $child_comment ) {
|
||||||
$comment_url = \add_query_arg(
|
$comment_url = \add_query_arg(
|
||||||
array(
|
array(
|
||||||
'p' => $child_comment->comment_post_ID,
|
'p' => $child_comment->comment_post_ID,
|
||||||
'ap_comment_id' => $child_comment->comment_ID
|
'ap_comment_id' => $child_comment->comment_ID,
|
||||||
),
|
),
|
||||||
trailingslashit( site_url() )
|
trailingslashit( site_url() )
|
||||||
);
|
);
|
||||||
$items[] = $comment_url;
|
$items[] = $comment_url;
|
||||||
}
|
}
|
||||||
$replies = (object) [
|
$replies = (object) array(
|
||||||
'type' => 'Collection',
|
'type' => 'Collection',
|
||||||
'id' => \add_query_arg( array( 'replies' => '' ), $this->id ),
|
'id' => \add_query_arg( array( 'replies' => '' ), $this->id ),
|
||||||
'first' => (object) [
|
'first' => (object) array(
|
||||||
'type' => 'CollectionPage',
|
'type' => 'CollectionPage',
|
||||||
'partOf'=> \add_query_arg( array( 'replies' => '' ), $this->id ),
|
'partOf' => \add_query_arg( array( 'replies' => '' ), $this->id ),
|
||||||
'next' => \add_query_arg( array( 'replies' => '', 'page' => 1 ), $this->id ),
|
'next' => \add_query_arg(
|
||||||
'items' => $items
|
array(
|
||||||
],
|
'replies' => '',
|
||||||
];
|
'page' => 1,
|
||||||
|
),
|
||||||
|
$this->id
|
||||||
|
),
|
||||||
|
'items' => $items,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return $replies;
|
return $replies;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,11 +29,11 @@ class Post {
|
||||||
$this->attachments = $this->generate_attachments();
|
$this->attachments = $this->generate_attachments();
|
||||||
$this->tags = $this->generate_tags();
|
$this->tags = $this->generate_tags();
|
||||||
$this->object_type = $this->generate_object_type();
|
$this->object_type = $this->generate_object_type();
|
||||||
$this->replies = $this->generate_replies();
|
$this->replies = $this->generate_replies();
|
||||||
//$this->updated = $this->generate_updated();
|
//$this->updated = $this->generate_updated();
|
||||||
$this->slug = \get_permalink( $this->id );
|
$this->slug = \get_permalink( $this->id );
|
||||||
$this->updated = null;
|
$this->updated = null;
|
||||||
$this->delete = $this->get_deleted();
|
$this->delete = $this->get_deleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __call( $method, $params ) {
|
public function __call( $method, $params ) {
|
||||||
|
@ -185,19 +185,19 @@ class Post {
|
||||||
$args = array(
|
$args = array(
|
||||||
'post_id' => $this->post->ID, // Use post_id, not post_ID
|
'post_id' => $this->post->ID, // Use post_id, not post_ID
|
||||||
'hierarchical' => false,
|
'hierarchical' => false,
|
||||||
'status' => 'approve',
|
'status' => 'approve',
|
||||||
);
|
);
|
||||||
$comments = \get_comments( $args );
|
$comments = \get_comments( $args );
|
||||||
$items = [];
|
$items = array();
|
||||||
|
|
||||||
foreach ( $comments as $comment ){
|
foreach ( $comments as $comment ) {
|
||||||
// include self replies
|
// include self replies
|
||||||
if ( $this->post->post_author === $comment->user_id ) {
|
if ( $this->post->post_author === $comment->user_id ) {
|
||||||
//$comment_url = $comment->comment_ID;
|
//$comment_url = $comment->comment_ID;
|
||||||
$comment_url = \add_query_arg( //
|
$comment_url = \add_query_arg( //
|
||||||
array(
|
array(
|
||||||
'p' => $this->post->ID,
|
'p' => $this->post->ID,
|
||||||
'ap_comment_id' => $comment->comment_ID
|
'ap_comment_id' => $comment->comment_ID,
|
||||||
),
|
),
|
||||||
trailingslashit( site_url() )
|
trailingslashit( site_url() )
|
||||||
);
|
);
|
||||||
|
@ -206,16 +206,22 @@ class Post {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//\error_log( 'generate_replies: $comments' . print_r( $comments, true ) );
|
//\error_log( 'generate_replies: $comments' . print_r( $comments, true ) );
|
||||||
$replies = (object) [
|
$replies = (object) array(
|
||||||
'type' => 'Collection',
|
'type' => 'Collection',
|
||||||
'id' => \add_query_arg( array( 'replies' => '' ), $this->id ),
|
'id' => \add_query_arg( array( 'replies' => '' ), $this->id ),
|
||||||
'first' => (object) [
|
'first' => (object) array(
|
||||||
'type' => 'CollectionPage',
|
'type' => 'CollectionPage',
|
||||||
'partOf'=> \add_query_arg( array( 'replies' => '' ), $this->id ),
|
'partOf' => \add_query_arg( array( 'replies' => '' ), $this->id ),
|
||||||
'next' => \add_query_arg( array( 'replies' => '', 'page' => 1 ), $this->id ),
|
'next' => \add_query_arg(
|
||||||
'items' => $items
|
array(
|
||||||
],
|
'replies' => '',
|
||||||
];
|
'page' => 1,
|
||||||
|
),
|
||||||
|
$this->id
|
||||||
|
),
|
||||||
|
'items' => $items,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return $replies;
|
return $replies;
|
||||||
}
|
}
|
||||||
|
|
|
@ -417,7 +417,7 @@ class Inbox {
|
||||||
|
|
||||||
$comment_parent_ID = \Activitypub\url_to_commentid( \esc_url_raw( $object['object']['inReplyTo'] ) );
|
$comment_parent_ID = \Activitypub\url_to_commentid( \esc_url_raw( $object['object']['inReplyTo'] ) );
|
||||||
|
|
||||||
if ( !is_null( $comment_parent_ID ) ) {
|
if ( ! is_null( $comment_parent_ID ) ) {
|
||||||
//inReplyTo a known local comment
|
//inReplyTo a known local comment
|
||||||
$comment_parent = \get_comment( $comment_parent_ID );
|
$comment_parent = \get_comment( $comment_parent_ID );
|
||||||
$comment_post_ID = $comment_parent->comment_post_ID;
|
$comment_post_ID = $comment_parent->comment_post_ID;
|
||||||
|
@ -435,21 +435,21 @@ class Inbox {
|
||||||
}
|
}
|
||||||
|
|
||||||
// if no name is set use peer username
|
// if no name is set use peer username
|
||||||
if ( !empty( $meta['name'] ) ) {
|
if ( ! empty( $meta['name'] ) ) {
|
||||||
$name = \esc_attr( $meta['name'] );
|
$name = \esc_attr( $meta['name'] );
|
||||||
} else {
|
} else {
|
||||||
$name = \esc_attr( $meta['preferredUsername'] );
|
$name = \esc_attr( $meta['preferredUsername'] );
|
||||||
}
|
}
|
||||||
// if avatar is set
|
// if avatar is set
|
||||||
if ( !empty( $meta['icon']['url'] ) ) {
|
if ( ! empty( $meta['icon']['url'] ) ) {
|
||||||
$avatar_url = \esc_attr( $meta['icon']['url'] );
|
$avatar_url = \esc_attr( $meta['icon']['url'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
//Only create WP_Comment for public replies to local posts
|
//Only create WP_Comment for public replies to local posts
|
||||||
if ( ( in_array( AS_PUBLIC, $object['to'] )
|
if ( ( in_array( AS_PUBLIC, $object['to'] )
|
||||||
|| in_array( AS_PUBLIC, $object['cc'] ) )
|
|| in_array( AS_PUBLIC, $object['cc'] ) )
|
||||||
&& ( !empty( $comment_post_ID )
|
&& ( ! empty( $comment_post_ID )
|
||||||
|| !empty ( $comment_parent )
|
|| ! empty( $comment_parent )
|
||||||
) ) {
|
) ) {
|
||||||
|
|
||||||
$commentdata = array(
|
$commentdata = array(
|
||||||
|
@ -463,7 +463,7 @@ class Inbox {
|
||||||
'comment_meta' => array(
|
'comment_meta' => array(
|
||||||
'ap_object' => \serialize( $object ),
|
'ap_object' => \serialize( $object ),
|
||||||
'source_url' => $source_url,
|
'source_url' => $source_url,
|
||||||
'avatar_url' => $avatar_url,
|
'avatar_url' => $avatar_url,
|
||||||
'protocol' => 'activitypub',
|
'protocol' => 'activitypub',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -497,7 +497,7 @@ class Inbox {
|
||||||
|
|
||||||
//Determine comment_ID
|
//Determine comment_ID
|
||||||
$object_comment_ID = \Activitypub\url_to_commentid( \esc_url_raw( $object['object']['id'] ) );
|
$object_comment_ID = \Activitypub\url_to_commentid( \esc_url_raw( $object['object']['id'] ) );
|
||||||
if ( !is_null( $object_comment_ID ) ) {
|
if ( ! is_null( $object_comment_ID ) ) {
|
||||||
|
|
||||||
//found a local comment id
|
//found a local comment id
|
||||||
$commentdata = \get_comment( $object_comment_ID, ARRAY_A );
|
$commentdata = \get_comment( $object_comment_ID, ARRAY_A );
|
||||||
|
@ -510,7 +510,7 @@ class Inbox {
|
||||||
|
|
||||||
//apply_filters( 'wp_update_comment_data', $data, $comment, $commentarr );
|
//apply_filters( 'wp_update_comment_data', $data, $comment, $commentarr );
|
||||||
|
|
||||||
// disable flood control
|
// disable flood control
|
||||||
\remove_action( 'check_comment_flood', 'check_comment_flood_db', 10 );
|
\remove_action( 'check_comment_flood', 'check_comment_flood_db', 10 );
|
||||||
|
|
||||||
// do not require email for AP entries
|
// do not require email for AP entries
|
||||||
|
@ -541,12 +541,12 @@ class Inbox {
|
||||||
}
|
}
|
||||||
//Determine comment_ID
|
//Determine comment_ID
|
||||||
$object_comment_ID = \Activitypub\url_to_commentid( \esc_url_raw( $object['object']['id'] ) );
|
$object_comment_ID = \Activitypub\url_to_commentid( \esc_url_raw( $object['object']['id'] ) );
|
||||||
if ( !is_null( $object_comment_ID ) ) {
|
if ( ! is_null( $object_comment_ID ) ) {
|
||||||
|
|
||||||
//found a local comment id
|
//found a local comment id
|
||||||
$commentdata = \get_comment( $object_comment_ID, ARRAY_A );
|
$commentdata = \get_comment( $object_comment_ID, ARRAY_A );
|
||||||
|
|
||||||
// disable flood control
|
// disable flood control
|
||||||
\remove_action( 'check_comment_flood', 'check_comment_flood_db', 10 );
|
\remove_action( 'check_comment_flood', 'check_comment_flood_db', 10 );
|
||||||
|
|
||||||
// do not require email for AP entries
|
// do not require email for AP entries
|
||||||
|
|
|
@ -129,7 +129,7 @@ class Webfinger {
|
||||||
*/
|
*/
|
||||||
public static function webfinger_lookup( $webfinger ) {
|
public static function webfinger_lookup( $webfinger ) {
|
||||||
$activity_profile = null;
|
$activity_profile = null;
|
||||||
if ( \substr($webfinger, 0, 1) === '@' ) {
|
if ( \substr( $webfinger, 0, 1 ) === '@' ) {
|
||||||
$webfinger = substr( $webfinger, 1 );
|
$webfinger = substr( $webfinger, 1 );
|
||||||
}
|
}
|
||||||
$url_host = \explode( '@', $webfinger );
|
$url_host = \explode( '@', $webfinger );
|
||||||
|
@ -140,7 +140,7 @@ class Webfinger {
|
||||||
$ap_link = json_decode( $response['body'] );
|
$ap_link = json_decode( $response['body'] );
|
||||||
if ( isset( $ap_link->links ) ) {
|
if ( isset( $ap_link->links ) ) {
|
||||||
foreach ( $ap_link->links as $link ) {
|
foreach ( $ap_link->links as $link ) {
|
||||||
if ( !property_exists( $link, 'type' ) ) {
|
if ( ! property_exists( $link, 'type' ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ( isset( $link->type ) && $link->type === 'application/activity+json' ) {
|
if ( isset( $link->type ) && $link->type === 'application/activity+json' ) {
|
||||||
|
|
Loading…
Reference in a new issue