wordpress-activitypub/includes/collection/class-follow-requests.php
André Menrath 03b6a8e598
Some checks failed
PHP_CodeSniffer / phpcs (push) Has been cancelled
Unit Testing / phpunit (5.6, 6.2) (push) Has been cancelled
Unit Testing / phpunit (7.0) (push) Has been cancelled
Unit Testing / phpunit (7.2) (push) Has been cancelled
Unit Testing / phpunit (7.3) (push) Has been cancelled
Unit Testing / phpunit (7.4) (push) Has been cancelled
Unit Testing / phpunit (8.0) (push) Has been cancelled
Unit Testing / phpunit (8.1) (push) Has been cancelled
Unit Testing / phpunit (8.2) (push) Has been cancelled
Unit Testing / phpunit (latest) (push) Has been cancelled
draft for managing follow requests
- the application actor is managed manually by default
- no admin-options are included yet
- the old new follower table only is used hardcoded by the application actor
- no admin notifications are send yet
- todo: a lot more
2023-12-25 22:35:04 +01:00

53 lines
1.8 KiB
PHP

<?php
namespace Activitypub\Collection;
use WP_Error;
use WP_Query;
use Activitypub\Http;
use Activitypub\Webfinger;
use Activitypub\Activity\Base_Object;
use Activitypub\Model\Follower;
use function Activitypub\is_tombstone;
use function Activitypub\get_remote_metadata_by_actor;
/**
* ActivityPub Follow Requests Collection
*
* @author André Menrath
*/
class Follow_Requests {
/**
* Get a follow request together with information from the follower.
*
* @param int $user_id The ID of the WordPress User
* @param int $follower_id The follower ID
*
* @return \Activitypub\Model\Follow|null The Follower object or null
*/
public static function get_follow_requests_for_user( $user_id, $per_page, $page, $args ) {
$order = isset($args['order']) && strtolower($args['order']) === 'asc' ? 'ASC' : 'DESC';
$orderby = isset($args['orderby']) ? sanitize_text_field($args['orderby']) : 'published';
global $wpdb;
$follow_requests = $wpdb->get_results(
$wpdb->prepare(
"SELECT SQL_CALC_FOUND_ROWS follow_request.ID AS id, follow_request.post_date AS published, follow_request.guid, follow_request.post_status AS 'status', follower.post_title AS 'post_title', follower.guid AS follower_guid, follower.id AS follower_id, follower.post_modified AS follower_modified
FROM {$wpdb->posts} AS follow_request
LEFT JOIN {$wpdb->posts} AS follower ON follow_request.post_parent = follower.ID
LEFT JOIN {$wpdb->postmeta} AS meta ON follow_request.ID = meta.post_id
WHERE follow_request.post_type = 'ap_follow_request'
AND meta.meta_key = 'activitypub_user_id'
AND meta.meta_value = %s
ORDER BY {$orderby} {$order}
LIMIT %d OFFSET %d",
$user_id,
$per_page,
0
)
);
$total_items = $wpdb->get_var("SELECT FOUND_ROWS()");
return compact( 'follow_requests', 'total_items' );
}
}