modified file plugins
This commit is contained in:
wp-content/upgrade-temp-backup/plugins
activitypub
.distignoreLICENSEactivitypub.php
assets
build
follow-me
followers
remote-reply
includes
activity
class-activity-dispatcher.phpclass-activitypub.phpclass-admin.phpclass-blocks.phpclass-comment.phpclass-debug.phpclass-handler.phpclass-hashtag.phpclass-health-check.phpclass-http.phpclass-mention.phpclass-migration.phpclass-scheduler.phpclass-shortcodes.phpclass-signature.phpclass-webfinger.phpcollection
compat.phpdebug.phpfunctions.phphandler
help.phpmodel
rest
class-collection.phpclass-comment.phpclass-followers.phpclass-following.phpclass-inbox.phpclass-nodeinfo.phpclass-outbox.phpclass-server.phpclass-users.phpclass-webfinger.php
table
transformer
integration
readme.txttemplates
simple-local-avatars
two-factor
LICENSE.md
assets
banner-1544x500.pngbanner-772x250.pngicon-128x128.pngicon-256x256.pngicon.svgscreenshot-1.pngscreenshot-2.pngscreenshot-3.png
class-two-factor-compat.phpclass-two-factor-core.phpincludes
providers
class-two-factor-backup-codes.phpclass-two-factor-dummy.phpclass-two-factor-email.phpclass-two-factor-fido-u2f-admin-list-table.phpclass-two-factor-fido-u2f-admin.phpclass-two-factor-fido-u2f.phpclass-two-factor-provider.phpclass-two-factor-totp.php
readme.txttwo-factor.phpuser-edit.csscss
js
109
wp-content/upgrade-temp-backup/plugins/activitypub/includes/handler/class-follow.php
Normal file
109
wp-content/upgrade-temp-backup/plugins/activitypub/includes/handler/class-follow.php
Normal file
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
namespace Activitypub\Handler;
|
||||
|
||||
use Activitypub\Http;
|
||||
use Activitypub\Activity\Activity;
|
||||
use Activitypub\Collection\Users;
|
||||
use Activitypub\Collection\Followers;
|
||||
|
||||
/**
|
||||
* Handle Follow requests
|
||||
*/
|
||||
class Follow {
|
||||
/**
|
||||
* Initialize the class, registering WordPress hooks
|
||||
*/
|
||||
public static function init() {
|
||||
\add_action(
|
||||
'activitypub_inbox_follow',
|
||||
array( self::class, 'handle_follow' )
|
||||
);
|
||||
|
||||
\add_action(
|
||||
'activitypub_followers_post_follow',
|
||||
array( self::class, 'send_follow_response' ),
|
||||
10,
|
||||
4
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle "Follow" requests
|
||||
*
|
||||
* @param array $activity The activity object
|
||||
* @param int $user_id The user ID
|
||||
*/
|
||||
public static function handle_follow( $activity ) {
|
||||
$user = Users::get_by_resource( $activity['object'] );
|
||||
|
||||
if ( ! $user || is_wp_error( $user ) ) {
|
||||
// If we can not find a user,
|
||||
// we can not initiate a follow process
|
||||
return;
|
||||
}
|
||||
|
||||
$user_id = $user->get__id();
|
||||
|
||||
// save follower
|
||||
$follower = Followers::add_follower(
|
||||
$user_id,
|
||||
$activity['actor']
|
||||
);
|
||||
|
||||
do_action(
|
||||
'activitypub_followers_post_follow',
|
||||
$activity['actor'],
|
||||
$activity,
|
||||
$user_id,
|
||||
$follower
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Accept response
|
||||
*
|
||||
* @param string $actor The Actor URL
|
||||
* @param array $object The Activity object
|
||||
* @param int $user_id The ID of the WordPress User
|
||||
* @param Activitypub\Model\Follower $follower The Follower object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function send_follow_response( $actor, $object, $user_id, $follower ) {
|
||||
if ( \is_wp_error( $follower ) ) {
|
||||
// it is not even possible to send a "Reject" because
|
||||
// we can not get the Remote-Inbox
|
||||
return;
|
||||
}
|
||||
|
||||
// only send minimal data
|
||||
$object = array_intersect_key(
|
||||
$object,
|
||||
array_flip(
|
||||
array(
|
||||
'id',
|
||||
'type',
|
||||
'actor',
|
||||
'object',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$user = Users::get_by_id( $user_id );
|
||||
|
||||
// get inbox
|
||||
$inbox = $follower->get_shared_inbox();
|
||||
|
||||
// send "Accept" activity
|
||||
$activity = new Activity();
|
||||
$activity->set_type( 'Accept' );
|
||||
$activity->set_object( $object );
|
||||
$activity->set_actor( $user->get_id() );
|
||||
$activity->set_to( $actor );
|
||||
$activity->set_id( $user->get_id() . '#follow-' . \preg_replace( '~^https?://~', '', $actor ) . '-' . \time() );
|
||||
|
||||
$activity = $activity->to_json();
|
||||
|
||||
Http::post( $inbox, $activity, $user_id );
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user