Rename Server class to Application
This commit is contained in:
parent
f101daf719
commit
ae04ffe71a
2 changed files with 82 additions and 34 deletions
82
includes/class-application.php
Normal file
82
includes/class-application.php
Normal file
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
namespace Activitypub;
|
||||
|
||||
use WP_Comment_Query;
|
||||
use Activitypub\Collection\Followers;
|
||||
use Activitypub\Collection\Users;
|
||||
use Activitypub\Scheduler;
|
||||
|
||||
use function Activitypub\is_user_disabled;
|
||||
|
||||
/**
|
||||
* ActivityPub Application Class
|
||||
*
|
||||
* @author Django Doucet
|
||||
*/
|
||||
class Application {
|
||||
|
||||
public static function known_inboxes() {
|
||||
$authors = get_users(
|
||||
array(
|
||||
'capability' => 'publish_posts',
|
||||
)
|
||||
);
|
||||
$follower_inboxes_all = [];
|
||||
foreach ( $authors as $user ) {
|
||||
$follower_inboxes = Followers::get_inboxes( $user->ID );
|
||||
$follower_inboxes_all = array_merge( $follower_inboxes, $follower_inboxes_all );
|
||||
}
|
||||
if ( ! is_user_disabled( Users::BLOG_USER_ID ) ) {
|
||||
$follower_inboxes = Followers::get_inboxes( Users::BLOG_USER_ID );
|
||||
$follower_inboxes_all = array_merge( $follower_inboxes, $follower_inboxes_all );
|
||||
}
|
||||
return array_unique( array_filter( $follower_inboxes_all ) );
|
||||
}
|
||||
|
||||
public static function known_users() {
|
||||
// at this point we just need known_commenters
|
||||
// this could get expensive though, eventually it would make sense
|
||||
// to schedule an add comment_author_url on Follow to a known_users site option
|
||||
$args = array(
|
||||
'user_id' => 0,
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'key' => 'protocol',
|
||||
'value' => 'activitypub',
|
||||
'compare' => '='
|
||||
),
|
||||
)
|
||||
);
|
||||
$comment_query = new WP_Comment_Query( $args );
|
||||
$known_users_all = [];
|
||||
foreach ( $comment_query->comments as $user ) {
|
||||
$known_users_all[] = $user->comment_author_url;
|
||||
}
|
||||
return array_unique( array_filter( $known_users_all ) );
|
||||
}
|
||||
|
||||
public static function is_actor_delete_request( $request ) {
|
||||
$json = $request->get_params( 'JSON' );
|
||||
if ( 'delete' === $json['type'] && $json['actor'] === $json['object'] ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function is_known_actor( $request ) {
|
||||
$json = $request->get_params( 'JSON' );
|
||||
if ( in_array( $json['actor'], self::known_users() ) ) {
|
||||
return $json['actor'];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function delete_remote_actor_comments( $actor ) {
|
||||
\wp_schedule_single_event(
|
||||
\time(),
|
||||
'activitypub_delete_remote_actor_comments',
|
||||
array( $actor )
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Activitypub;
|
||||
|
||||
use Activitypub\Collection\Followers;
|
||||
use Activitypub\Collection\Users;
|
||||
|
||||
use function Activitypub\is_user_disabled;
|
||||
|
||||
/**
|
||||
* ActivityPub Server Class
|
||||
*
|
||||
* @author Django Doucet
|
||||
*/
|
||||
class Server {
|
||||
|
||||
public static function known_inboxes() {
|
||||
$authors = get_users(
|
||||
array(
|
||||
'capability' => 'publish_posts',
|
||||
)
|
||||
);
|
||||
$follower_inboxes_all = [];
|
||||
foreach ( $authors as $user ) {
|
||||
$follower_inboxes = Followers::get_inboxes( $user->ID );
|
||||
$follower_inboxes_all = array_merge( $follower_inboxes, $follower_inboxes_all );
|
||||
}
|
||||
if ( ! is_user_disabled( Users::BLOG_USER_ID ) ) {
|
||||
$follower_inboxes = Followers::get_inboxes( Users::BLOG_USER_ID );
|
||||
$follower_inboxes_all = array_merge( $follower_inboxes, $follower_inboxes_all );
|
||||
}
|
||||
return array_unique( array_filter( $follower_inboxes_all ) );
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue