init follower update scheduler

This commit is contained in:
Matthias Pfefferle 2023-05-04 15:17:05 +02:00
parent e489a04880
commit cec4ed2e3f
2 changed files with 120 additions and 65 deletions

View file

@ -29,67 +29,66 @@ function init() {
\define( 'ACTIVITYPUB_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); \define( 'ACTIVITYPUB_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
\define( 'ACTIVITYPUB_PLUGIN_FILE', plugin_dir_path( __FILE__ ) . '/' . basename( __FILE__ ) ); \define( 'ACTIVITYPUB_PLUGIN_FILE', plugin_dir_path( __FILE__ ) . '/' . basename( __FILE__ ) );
require_once \dirname( __FILE__ ) . '/includes/table/followers-list.php'; \define( 'ACTIVITYPUB_OBJECT', 'ACTIVITYPUB_OBJECT' );
require_once \dirname( __FILE__ ) . '/includes/class-signature.php';
require_once \dirname( __FILE__ ) . '/includes/class-webfinger.php';
require_once \dirname( __FILE__ ) . '/includes/peer/class-followers.php';
require_once \dirname( __FILE__ ) . '/includes/functions.php';
require_once \dirname( __FILE__ ) . '/includes/model/class-activity.php'; Migration::init();
require_once \dirname( __FILE__ ) . '/includes/model/class-post.php';
require_once \dirname( __FILE__ ) . '/includes/class-activity-dispatcher.php';
Activity_Dispatcher::init(); Activity_Dispatcher::init();
require_once \dirname( __FILE__ ) . '/includes/class-activitypub.php';
Activitypub::init(); Activitypub::init();
Collection\Followers::init();
// Configure the REST API route // Configure the REST API route
require_once \dirname( __FILE__ ) . '/includes/rest/class-outbox.php';
Rest\Outbox::init(); Rest\Outbox::init();
require_once \dirname( __FILE__ ) . '/includes/rest/class-inbox.php';
Rest\Inbox::init(); Rest\Inbox::init();
require_once \dirname( __FILE__ ) . '/includes/rest/class-followers.php';
Rest\Followers::init(); Rest\Followers::init();
require_once \dirname( __FILE__ ) . '/includes/rest/class-following.php';
Rest\Following::init(); Rest\Following::init();
require_once \dirname( __FILE__ ) . '/includes/rest/class-webfinger.php';
Rest\Webfinger::init(); Rest\Webfinger::init();
// load NodeInfo endpoints only if blog is public
if ( true === (bool) \get_option( 'blog_public', 1 ) ) {
require_once \dirname( __FILE__ ) . '/includes/rest/class-nodeinfo.php';
Rest\NodeInfo::init();
}
require_once \dirname( __FILE__ ) . '/includes/class-admin.php';
Admin::init(); Admin::init();
require_once \dirname( __FILE__ ) . '/includes/class-hashtag.php';
Hashtag::init(); Hashtag::init();
require_once \dirname( __FILE__ ) . '/includes/class-shortcodes.php';
Shortcodes::init(); Shortcodes::init();
require_once \dirname( __FILE__ ) . '/includes/class-mention.php';
Mention::init(); Mention::init();
require_once \dirname( __FILE__ ) . '/includes/class-debug.php';
Debug::init(); Debug::init();
require_once \dirname( __FILE__ ) . '/includes/class-health-check.php';
Health_Check::init(); Health_Check::init();
if ( \WP_DEBUG ) {
require_once \dirname( __FILE__ ) . '/includes/debug.php';
}
} }
\add_action( 'plugins_loaded', '\Activitypub\init' ); \add_action( 'plugins_loaded', '\Activitypub\init' );
spl_autoload_register(
function ( $class ) {
$base_dir = trailingslashit( __DIR__ ) . 'includes' . DIRECTORY_SEPARATOR;
$base = 'activitypub';
$class = strtolower( $class );
if ( strncmp( $class, $base, strlen( $base ) ) === 0 ) {
$class = str_replace( 'activitypub\\', '', $class );
if ( strpos( $class, '\\' ) ) {
list( $sub_dir, $class ) = explode( '\\', $class );
$base_dir = $base_dir . $sub_dir . DIRECTORY_SEPARATOR;
}
$filename = 'class-' . str_replace( '_', '-', $class );
$file = $base_dir . $filename . '.php';
if ( file_exists( $file ) ) {
require_once $file;
}
}
}
);
require_once \dirname( __FILE__ ) . '/includes/functions.php';
// load NodeInfo endpoints only if blog is public
if ( true === (bool) \get_option( 'blog_public', 1 ) ) {
require_once \dirname( __FILE__ ) . '/includes/rest/class-nodeinfo.php';
Rest\NodeInfo::init();
}
if ( \WP_DEBUG ) {
require_once \dirname( __FILE__ ) . '/includes/debug.php';
}
/** /**
* Add plugin settings link * Add plugin settings link
*/ */
@ -102,34 +101,32 @@ function plugin_settings_link( $actions ) {
return \array_merge( $settings_link, $actions ); return \array_merge( $settings_link, $actions );
} }
\add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), '\Activitypub\plugin_settings_link' ); \add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), __NAMESPACE__ . '\plugin_settings_link' );
/** \register_activation_hook(
* Add rewrite rules __FILE__,
*/ array(
function add_rewrite_rules() { __NAMESPACE__ . '\Activitypub',
if ( ! \class_exists( 'Webfinger' ) ) { 'activate',
\add_rewrite_rule( '^.well-known/webfinger', 'index.php?rest_route=/activitypub/1.0/webfinger', 'top' ); )
} );
if ( ! \class_exists( 'Nodeinfo' ) || ! (bool) \get_option( 'blog_public', 1 ) ) { \register_deactivation_hook(
\add_rewrite_rule( '^.well-known/nodeinfo', 'index.php?rest_route=/activitypub/1.0/nodeinfo/discovery', 'top' ); __FILE__,
\add_rewrite_rule( '^.well-known/x-nodeinfo2', 'index.php?rest_route=/activitypub/1.0/nodeinfo2', 'top' ); array(
} __NAMESPACE__ . '\Activitypub',
'deactivate',
)
);
\add_rewrite_endpoint( 'activitypub', EP_AUTHORS | EP_PERMALINK | EP_PAGES ); register_uninstall_hook(
} __FILE__,
\add_action( 'init', '\Activitypub\add_rewrite_rules', 1 ); array(
__NAMESPACE__ . '\Activitypub',
'uninstall',
)
);
/**
* Flush rewrite rules;
*/
function flush_rewrite_rules() {
\Activitypub\add_rewrite_rules();
\flush_rewrite_rules();
}
\register_activation_hook( __FILE__, '\Activitypub\flush_rewrite_rules' );
\register_deactivation_hook( __FILE__, '\flush_rewrite_rules' );
/** /**
* Only load code that needs BuddyPress to run once BP is loaded and initialized. * Only load code that needs BuddyPress to run once BP is loaded and initialized.

View file

@ -25,6 +25,40 @@ class Activitypub {
\add_action( 'transition_post_status', array( self::class, 'schedule_post_activity' ), 33, 3 ); \add_action( 'transition_post_status', array( self::class, 'schedule_post_activity' ), 33, 3 );
\add_action( 'wp_trash_post', array( self::class, 'trash_post' ), 1 ); \add_action( 'wp_trash_post', array( self::class, 'trash_post' ), 1 );
\add_action( 'untrash_post', array( self::class, 'untrash_post' ), 1 ); \add_action( 'untrash_post', array( self::class, 'untrash_post' ), 1 );
\add_action( 'init', array( self::class, 'add_rewrite_rules' ) );
}
/**
* Activation Hook
*
* @return void
*/
public static function activate() {
self::flush_rewrite_rules();
if ( ! \wp_next_scheduled( 'activitypub_update_followers' ) ) {
\wp_schedule_event( time(), 'hourly', 'activitypub_update_followers' );
}
}
/**
* Deactivation Hook
*
* @return void
*/
public static function deactivate() {
self::flush_rewrite_rules();
wp_unschedule_hook( 'activitypub_update_followers' );
}
/**
* Uninstall Hook
*
* @return void
*/
public static function uninstall() {
} }
/** /**
@ -204,4 +238,28 @@ class Activitypub {
public static function untrash_post( $post_id ) { public static function untrash_post( $post_id ) {
\delete_post_meta( $post_id, 'activitypub_canonical_url' ); \delete_post_meta( $post_id, 'activitypub_canonical_url' );
} }
/**
* Add rewrite rules
*/
public static function add_rewrite_rules() {
if ( ! \class_exists( 'Webfinger' ) ) {
\add_rewrite_rule( '^.well-known/webfinger', 'index.php?rest_route=/activitypub/1.0/webfinger', 'top' );
}
if ( ! \class_exists( 'Nodeinfo' ) || (bool) \get_option( 'blog_public', 1 ) ) {
\add_rewrite_rule( '^.well-known/nodeinfo', 'index.php?rest_route=/activitypub/1.0/nodeinfo/discovery', 'top' );
\add_rewrite_rule( '^.well-known/x-nodeinfo2', 'index.php?rest_route=/activitypub/1.0/nodeinfo2', 'top' );
}
\add_rewrite_endpoint( 'activitypub', EP_AUTHORS | EP_PERMALINK | EP_PAGES );
}
/**
* Flush rewrite rules;
*/
public static function flush_rewrite_rules() {
self::add_rewrite_rules();
\flush_rewrite_rules();
}
} }