coding standards
This commit is contained in:
parent
73e6be9782
commit
51643142aa
8 changed files with 187 additions and 198 deletions
|
@ -167,8 +167,7 @@ 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
|
||||||
|
@ -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'] );
|
|
||||||
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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?:' );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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,7 +365,7 @@ 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'] ) ) {
|
||||||
|
@ -385,10 +384,10 @@ function url_to_commentid( $in_replyto_url ) {
|
||||||
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,7 +403,6 @@ 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() {
|
||||||
|
@ -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 ) {
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -236,27 +236,33 @@ class Comment {
|
||||||
$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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,7 +188,7 @@ class Post {
|
||||||
'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
|
||||||
|
@ -197,7 +197,7 @@ class Post {
|
||||||
$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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue