coding standards

This commit is contained in:
Django Doucet 2022-04-15 01:17:00 -06:00
parent 73e6be9782
commit 51643142aa
8 changed files with 187 additions and 198 deletions

View file

@ -167,8 +167,7 @@ class Activitypub {
//Admin users comments bypass transition_comment_status (auto approved)
if ( $commentdata['comment_type'] === 'activitypub' ) {
if (
( $comment_approved === 1 ) &&
if ( ( $comment_approved === 1 ) &&
! empty( $commentdata['user_id'] ) &&
( $user = get_userdata( $commentdata['user_id'] ) ) && // get the user data
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 registered
// 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 ) {
//TODO Test with non-admin user
\wp_schedule_single_event( \time(), 'activitypub_send_update_comment_activity', array( $activitypub_comment->comment_ID ) );
} else {
//error_log( 'schedule_update_comment_activity: else?:' );
}
} else { }
}
/**

View file

@ -58,7 +58,7 @@ function safe_remote_post( $url, $body, $user_id ) {
$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;
}
@ -355,7 +355,6 @@ function url_to_authorid( $url ) {
/**
* Verify if in_replyto_url is a local comment,
* Or if it is a previously received remote comment
*
* return int comment_id
*/
function url_to_commentid( $in_replyto_url ) {
@ -366,7 +365,7 @@ function url_to_commentid( $in_replyto_url ) {
//rewrite for activitypub object id simplification
$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
\parse_str( $url_maybe_id['query'], $reply_query );
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(
'key' => 'source_url', //$object['object']['id']
'value' => $in_replyto_url,
)
)
),
),
);
$comments_query = new \WP_Comment_Query;
$comments_query = new \WP_Comment_Query();
$comments = $comments_query->query( $comment_args );
$found_comment_ids = array();
if ( $comments ) {
@ -404,7 +403,6 @@ function url_to_commentid( $in_replyto_url ) {
/**
* Verify if url is a wp_ap_comment,
* Or if it is a previously received remote comment
*
* return int comment_id
*/
function is_ap_comment() {
@ -421,14 +419,12 @@ function is_ap_comment() {
/**
* Verify if url is a /replies endoint,
*
* return int true
*/
function is_ap_replies() {
global $wp;
$replies = get_query_var( 'replies' );
//$page = get_query_var( 'collection_page' );
if( ( $replies ) ) {
if ( $replies ) {
return $replies;
}
return null;
@ -438,7 +434,6 @@ function is_ap_replies() {
* Get tagged users from received AP object meta
* @param string $object_id a comment_id to search
* @param boolean $post defaults to searching a comment_id
*
* @return array of tagged users
*/
function get_recipients( $object_id, $post = null ) {
@ -522,7 +517,7 @@ function tag_user( $recipient ) {
* @return array of all matched webfinger
*/
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;
}

View file

@ -236,27 +236,33 @@ class Comment {
$children = \get_comments( $args );
$replies = null;
if ( $children ) {
$items = [];
$items = array();
foreach ( $children as $child_comment ) {
$comment_url = \add_query_arg(
array(
'p' => $child_comment->comment_post_ID,
'ap_comment_id' => $child_comment->comment_ID
'ap_comment_id' => $child_comment->comment_ID,
),
trailingslashit( site_url() )
);
$items[] = $comment_url;
}
$replies = (object) [
$replies = (object) array(
'type' => 'Collection',
'id' => \add_query_arg( array( 'replies' => '' ), $this->id ),
'first' => (object) [
'first' => (object) array(
'type' => 'CollectionPage',
'partOf' => \add_query_arg( array( 'replies' => '' ), $this->id ),
'next' => \add_query_arg( array( 'replies' => '', 'page' => 1 ), $this->id ),
'items' => $items
],
];
'next' => \add_query_arg(
array(
'replies' => '',
'page' => 1,
),
$this->id
),
'items' => $items,
),
);
}
return $replies;
}

View file

@ -188,7 +188,7 @@ class Post {
'status' => 'approve',
);
$comments = \get_comments( $args );
$items = [];
$items = array();
foreach ( $comments as $comment ) {
// include self replies
@ -197,7 +197,7 @@ class Post {
$comment_url = \add_query_arg( //
array(
'p' => $this->post->ID,
'ap_comment_id' => $comment->comment_ID
'ap_comment_id' => $comment->comment_ID,
),
trailingslashit( site_url() )
);
@ -206,16 +206,22 @@ class Post {
}
}
//\error_log( 'generate_replies: $comments' . print_r( $comments, true ) );
$replies = (object) [
$replies = (object) array(
'type' => 'Collection',
'id' => \add_query_arg( array( 'replies' => '' ), $this->id ),
'first' => (object) [
'first' => (object) array(
'type' => 'CollectionPage',
'partOf' => \add_query_arg( array( 'replies' => '' ), $this->id ),
'next' => \add_query_arg( array( 'replies' => '', 'page' => 1 ), $this->id ),
'items' => $items
],
];
'next' => \add_query_arg(
array(
'replies' => '',
'page' => 1,
),
$this->id
),
'items' => $items,
),
);
}
return $replies;
}