diff --git a/includes/class-admin.php b/includes/class-admin.php index 23ad567..1efc6d2 100644 --- a/includes/class-admin.php +++ b/includes/class-admin.php @@ -15,9 +15,7 @@ class Admin { \add_action( 'admin_init', array( '\Activitypub\Admin', 'register_settings' ) ); \add_action( 'admin_init', array( '\Activitypub\Admin', 'version_check' ), 1 ); \add_action( 'show_user_profile', array( '\Activitypub\Admin', 'add_fediverse_profile' ) ); - \add_action( 'wp_ajax_migrate_post', array( '\Activitypub\Admin', 'migrate_post_action' ) ); \add_filter( 'comment_row_actions', array( '\Activitypub\Admin', 'reply_comments_actions' ), 10, 2 ); - \add_filter( 'views_tools_page_activitypub_tools', array( '\Activitypub\Table\Migrate_List', 'get_activitypub_tools_views' ), 10 ); \add_action( 'admin_enqueue_scripts', array( '\Activitypub\Admin', 'enqueue_scripts' ) ); } @@ -39,7 +37,6 @@ class Admin { \add_action( 'load-' . $followers_list_page, array( '\Activitypub\Admin', 'add_followers_list_help_tab' ) ); - \add_management_page( \__( 'ActivityPub Management', 'activitypub' ), \__( 'ActivityPub Tools', 'activitypub' ), 'manage_options', 'activitypub_tools', array( '\Activitypub\Admin', 'migrate_tools_page' ) ); } /** @@ -78,13 +75,6 @@ class Admin { \load_template( \dirname( __FILE__ ) . '/../templates/followers-list.php' ); } - /** - * Load ActivityPub Tools page - */ - public static function migrate_tools_page() { - \load_template( \dirname( __FILE__ ) . '/../templates/tools-page.php' ); - } - /** * Register ActivityPub settings */ @@ -157,27 +147,6 @@ class Admin { ); } - /** - * Update ActivityPub plugin - */ - public static function version_check() { - if ( ! function_exists( 'get_plugin_data' ) ) { - require_once ABSPATH . 'wp-admin/includes/plugin.php'; - } - $plugin_data = \get_plugin_data( ACTIVITYPUB_PLUGIN ); - $activitypub_db_version = \get_option( 'activitypub_version' ); - - if ( empty( $activitypub_db_version ) || \version_compare( $plugin_data['Version'], $activitypub_db_version, '>' ) ) { - // Check for specific migrations - - if ( version_compare( '0.13.4', $activitypub_db_version, '>' ) ) { - \Activitypub\Tools\Posts::mark_posts_to_migrate(); - } - } - \update_option( 'activitypub_version', $plugin_data['Version'] ); - //\delete_option( 'activitypub_version' ); - } - public static function add_settings_help_tab() { require_once \dirname( __FILE__ ) . '/help.php'; } @@ -193,20 +162,6 @@ class Admin { \Activitypub\get_identifier_settings( $user->ID ); } - /** - * Migrate post (Ajax) - */ - public static function migrate_post_action() { - if ( wp_verify_nonce( $_POST['nonce'], 'activitypub_migrate_actions' ) ) { - \Activitypub\Tools\Posts::migrate_post( rawurldecode( $_POST['post_url'] ), absint( $_POST['post_author'] ) ); - \delete_post_meta( \url_to_postid( $_POST['post_url'] ), '_activitypub_permalink_compat' ); - } else { - $error = new WP_Error( 'nonce_failure', __( 'Unauthorized', 'activitypub' ) ); - wp_send_json_error( $error ); - } - wp_die(); - } - /** * hook comment_row_actions * Reply to ActivityPub Comments from the edit-comments.php screen diff --git a/includes/class-tools.php b/includes/class-tools.php deleted file mode 100644 index e0191bc..0000000 --- a/includes/class-tools.php +++ /dev/null @@ -1,100 +0,0 @@ - -1, - 'post_type' => $post_types, - 'order' => 'ASC', - ); - $posts_to_migrate = \get_posts( $args ); - foreach ( $posts_to_migrate as $post ) { - $permalink = \get_permalink( $post->ID ); - \update_post_meta( $post->ID, '_activitypub_permalink_compat', $permalink ); - } - } - - public static function get_posts_to_migrate() { - $post_types = \get_option( 'activitypub_support_post_types', array( 'post', 'page' ) ); - $args = array( - 'numberposts' => -1, - 'post_type' => $post_types, - 'meta_key' => '_activitypub_permalink_compat', - 'order' => 'ASC', - ); - return \get_posts( $args ); - } - - public static function get_posts_with_activitypub_comments() { - $args = array( - 'comment_type' => 'activitypub', - 'status' => 'all', - ); - $activitypub_comments = \get_comments( $args ); - $activitypub_comments_posts = array(); - foreach ( $activitypub_comments as $comment ) { - $meta = \get_post_meta( $comment->comment_post_ID, '_activitypub_permalink_compat', true ); - if ( ! $meta ) { - continue; - } - $activitypub_comments_posts[] = $comment->comment_post_ID; - } - return ( empty( \array_unique( $activitypub_comments_posts ) ) ? $activitypub_comments_posts : \get_posts( \array_unique( $activitypub_comments_posts ) ) ); - } - - public static function count_posts_to_migrate() { - $posts = self::get_posts_to_migrate(); - return \count( $posts ); - } - - public static function count_posts_with_comments_to_migrate() { - $posts = self::get_posts_with_activitypub_comments(); - return \count( $posts ); - } - - /** - * migrate_post - * Federate Delete - * Federate Announce - * - * @param str post_url (_activitypub_permalink_compat) - * @param str post_author (user_id) - */ - public static function migrate_post( $post_url, $post_author ) { - self::delete_url( $post_url, $post_author ); - self::announce_url( $post_url, $post_author ); - } - - /** - * announce_url - * send Announce (obj) - * - * @param str post_url (post_id) - * @param int user_id - */ - public static function announce_url( $post_url, $user_id ) { - \wp_schedule_single_event( \time(), 'activitypub_send_announce_activity', array( $post_url, $user_id ) ); - } - - /** - * delete_url - * Send a Delete activity to the Fediverse - * - * @param str post_url (_activitypub_permalink_compat) - * @param str post_author (user_id) - */ - public static function delete_url( $post_url, $post_author ) { - \wp_schedule_single_event( \time(), 'activitypub_send_delete_url_activity', array( $post_url, $post_author ) ); - } -} diff --git a/includes/table/migrate-list.php b/includes/table/migrate-list.php deleted file mode 100644 index 701aaa1..0000000 --- a/includes/table/migrate-list.php +++ /dev/null @@ -1,207 +0,0 @@ - '', - 'post_author' => \__( 'Post Author (user_id)', 'activitypub' ), - 'title' => \__( 'Post', 'activitypub' ), - 'comments' => \__( 'Comments', 'activitypub' ), - 'date' => \__( 'Publication Date', 'activitypub' ), - 'migrate' => \__( 'Migrate', 'activitypub' ), - ); - } - - public function get_sortable_columns() { - return array(); - } - - public function get_bulk_actions() { - $actions = array( - 'delete' => 'Remove backwards compatibility', - ); - return $actions; - } - - public static function get_activitypub_tools_views() { - $posts_count = \Activitypub\Tools\Posts::count_posts_to_migrate(); - $comments_posts_count = \Activitypub\Tools\Posts::count_posts_with_comments_to_migrate(); - $activitypub_tools_page = 'tools.php?page=activitypub_tools'; - $view_slugs = array( - array( 'all', null, __( 'All', 'activitypub' ), $posts_count ), - array( 'comments', 'activitypub', __( 'Posts with Comments', 'activitypub' ), $comments_posts_count ), - ); - $post_status_var = get_query_var( 'comments' ); - $view_count = count( $view_slugs ); - for ( $x = 0; $x < $view_count; $x++ ) { - $class = ( $post_status_var === $view_slugs[ $x ][1] ) ? ' class="current"' : ''; - $post_status_temp = $view_slugs[ $x ][1]; - if ( ! empty( $post_status_temp ) ) { - $post_status_temp = '&comments=' . $view_slugs[ $x ][1]; - } - $views[ $view_slugs[ $x ][0] ] = sprintf( - '' . $view_slugs[ $x ][2] . ' (%s)', - $view_slugs[ $x ][3] - ); - } - return $views; - } - - public function prepare_items() { - $columns = $this->get_columns(); - $hidden = array( 'post_author', 'migrate' ); - $sortable = $this->get_sortable_columns(); - $this->_column_headers = array( $columns, $hidden, $sortable ); - - $items = array(); - $this->process_action(); - if ( 'activitypub_tools' === $_REQUEST['page'] ) { - if ( isset( $_REQUEST['comments'] ) && 'activitypub' === $_REQUEST['comments'] ) { - foreach ( \Activitypub\Tools\Posts::get_posts_with_activitypub_comments() as $ap_post ) { - $items[] = array( - 'post_author' => $ap_post->post_author, - 'title' => \sprintf( - '%2s', - \get_permalink( $ap_post->ID ), - $ap_post->post_title - ), - 'comments' => $ap_post->comment_count, - 'date' => $ap_post->post_date, - 'migrate' => \get_post_meta( $ap_post->ID, '_activitypub_permalink_compat', true ), - ); - } - } else { - foreach ( \Activitypub\Tools\Posts::get_posts_to_migrate() as $post ) { - $items[] = array( - 'post_author' => $post->post_author, - 'title' => \sprintf( - '%2s', - \get_permalink( $post->ID ), - $post->post_title - ), - 'comments' => $post->comment_count, - 'date' => $post->post_date, - 'migrate' => \get_post_meta( $post->ID, '_activitypub_permalink_compat', true ), - ); - } - } - } - - // pagination - $per_page = $this->get_items_per_page( 'elements_per_page', 10 ); - $current_page = $this->get_pagenum(); - $total_items = count( $items ); - $table_data = array_slice( $items, ( ( $current_page - 1 ) * $per_page ), $per_page ); - $this->set_pagination_args( - array( - 'total_items' => $total_items, - 'per_page' => $per_page, - 'total_pages' => ceil( $total_items / $per_page ), - ) - ); - $this->items = $table_data; - - // actions - if ( isset( $_REQUEST['_wpnonce'] ) ) { - $nonce = \esc_attr( $_REQUEST['_wpnonce'] ); - } - // delete - if ( isset( $_REQUEST['action'] ) && 'activitypub_tools' === $_REQUEST['page'] && 'delete_notice' === $_REQUEST['action'] ) { - if ( wp_verify_nonce( $nonce, 'activitypub_migrate_actions' ) ) { - \Activitypub\Tools\Posts::delete_url( rawurldecode( $_REQUEST['post_url'] ), absint( $_REQUEST['post_author'] ) ); - \delete_post_meta( \url_to_postid( $_REQUEST['post_url'] ), '_activitypub_permalink_compat' ); - } - } - // delete and announce - if ( isset( $_REQUEST['action'] ) && 'activitypub_tools' === $_REQUEST['page'] && 'delete' === $_REQUEST['action'] ) { - if ( wp_verify_nonce( $nonce, 'activitypub_migrate_actions' ) ) { - \Activitypub\Tools\Posts::migrate_post( rawurldecode( $_REQUEST['post_url'] ), absint( $_REQUEST['post_author'] ) ); - \delete_post_meta( \url_to_postid( $_REQUEST['post_url'] ), '_activitypub_permalink_compat' ); - } - } - } - - public function single_row( $item ) { - $inline_styles = ( $item['comments'] > 0 ) ? 'warning' : ''; ?> -
- Migration here means updating the Activity ID by federating a Delete activity removing the original post from the fediverse, and then Sharing the new post ID with an Announce activity.
- Posts with comments should be treated with care, existing interactions in the fediverse will be lost.', 'activitypub' ),
- \esc_attr( \Activitypub\Tools\Posts::count_posts_to_migrate() )
- ); ?>