Add comments view, warnings to migrate page

This commit is contained in:
Django Doucet 2022-10-31 14:43:14 -06:00
parent 8707387ab8
commit 055c22e9c3
5 changed files with 99 additions and 24 deletions

View file

@ -5,12 +5,10 @@
if ( $('body').hasClass('edit-comments-php') ) {
//Insert Mentions into comment content on reply
$( '.comment-inline.button-link' ).on( 'click', function( event ) {
// Summary/ContentWarning Syntax [CW]
var summary = $(this).attr('data-summary') ? '[' + $(this).attr('data-summary') + '] ' : '';
var recipients = $(this).attr('data-recipients') ? $(this).attr('data-recipients') + ' ' : '';
setTimeout(function() {
if ( summary || recipients ){
$('#replycontent').val( summary + recipients )
if ( recipients ){
$('#replycontent').val( recipients )
}
}, 100);
})

View file

@ -18,7 +18,7 @@ class Admin {
\add_action( 'admin_enqueue_scripts', array( '\Activitypub\Admin', 'enqueue_script_actions' ), 10, 2 );
\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 );
}
/**
@ -213,6 +213,10 @@ class Admin {
wp_die();
}
/**
* hook comment_row_actions
* Reply to ActivityPub Comments from the edit-comments.php screen
*/
public static function reply_comments_actions( $actions, $comment ) {
$recipients = \Activitypub\get_recipients( $comment->comment_ID );
$summary = \Activitypub\get_summary( $comment->comment_ID );

View file

@ -39,13 +39,18 @@ class Posts {
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 \get_posts( \array_unique( $activitypub_comments_posts ) );
return ( empty( \array_unique( $activitypub_comments_posts ) ) ? $activitypub_comments_posts : \get_posts( \array_unique( $activitypub_comments_posts ) ) );
}
public static function count_posts_to_migrate() {
@ -53,6 +58,11 @@ class Posts {
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

View file

@ -21,27 +21,80 @@ class Migrate_List extends \WP_List_Table {
public function get_sortable_columns() {
return array();
}
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($post_status_temp != '') {
$post_status_temp = '&comments='.$view_slugs[$x][1];
}
$views[$view_slugs[$x][0]] = sprintf(__('<a href="' .
$activitypub_tools_page .
$post_status_temp . '"' .
$class .
' >' .
$view_slugs[$x][2] .
' <span class="count">(%d)</span></a>'),
$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->process_action();
$this->_column_headers = array( $columns, $hidden, $sortable );
foreach ( \Activitypub\Tools\Posts::get_posts_to_migrate() as $post ) {
$this->items[] = array(
'post_author' => $post->post_author,
'title' => \sprintf(
'<a href="%1s">%2s</a>',
\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 ),
);
$this->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 ) {
$this->items[] = array(
'post_author' => $ap_post->post_author,
'title' => \sprintf(
'<a href="%1s">%2s</a>',
\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 ) {
$this->items[] = array(
'post_author' => $post->post_author,
'title' => \sprintf(
'<a href="%1s">%2s</a>',
\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
@ -64,7 +117,7 @@ class Migrate_List extends \WP_List_Table {
// 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'] ) );
\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' );
}
}

View file

@ -9,6 +9,15 @@ if ( isset( $_REQUEST['post_url'] ) && $_REQUEST['page'] == "activitypub_tools"
}
}
?>
<style>
#the-list tr.warning {
background-color: #fcf9e8;
box-shadow: inset 0 -1px 0 rgba(0,0,0,.1);
}
#the-list tr.warning th.check-column {
border-left: 4px solid #d63638;
}
</style>
<div class="wrap">
<h1><?php \esc_html_e( 'Manage ActivityPub posts (Fediverse)', 'activitypub' ); ?></h1>
@ -24,15 +33,16 @@ if ( isset( $_REQUEST['post_url'] ) && $_REQUEST['page'] == "activitypub_tools"
</div>
<p><?php \printf(
\__( 'You currently have %s posts to migrate.', 'activitypub' ),
\__( 'You currently have %s posts marked for review.', 'activitypub' ),
\esc_attr( \Activitypub\Tools\Posts::count_posts_to_migrate() )
); ?></p>
<?php $token_table = new \Activitypub\Table\Migrate_List(); ?>
<form method="POST" id="table">
<?php
$token_table->prepare_items();
$token_table->display();
$token_table->views();
$token_table->prepare_items();
$token_table->display();
?>
</form>
<?php endif; ?>