code cleanup
This commit is contained in:
parent
be9b74478d
commit
aa1b54462e
3 changed files with 51 additions and 44 deletions
|
@ -128,7 +128,12 @@ class Activity_Dispatcher {
|
||||||
$activitypub_activity = new \Activitypub\Model\Activity( 'Delete', \Activitypub\Model\Activity::TYPE_SIMPLE );
|
$activitypub_activity = new \Activitypub\Model\Activity( 'Delete', \Activitypub\Model\Activity::TYPE_SIMPLE );
|
||||||
$activitypub_activity->set_id( $activitypub_url . '#delete' );
|
$activitypub_activity->set_id( $activitypub_url . '#delete' );
|
||||||
$activitypub_activity->set_actor( $actor );
|
$activitypub_activity->set_actor( $actor );
|
||||||
$activitypub_activity->set_object( array( "id" => $activitypub_url, "type" => "Tombstone" ) );
|
$activitypub_activity->set_object(
|
||||||
|
array(
|
||||||
|
'id' => $activitypub_url,
|
||||||
|
'type' => 'Tombstone',
|
||||||
|
)
|
||||||
|
);
|
||||||
$activitypub_activity->set_deleted( $deleted );
|
$activitypub_activity->set_deleted( $deleted );
|
||||||
|
|
||||||
foreach ( \Activitypub\get_follower_inboxes( $user_id ) as $inbox => $to ) {
|
foreach ( \Activitypub\get_follower_inboxes( $user_id ) as $inbox => $to ) {
|
||||||
|
|
|
@ -143,15 +143,15 @@ class Admin {
|
||||||
}
|
}
|
||||||
$plugin_data = \get_plugin_data( ACTIVITYPUB_PLUGIN );
|
$plugin_data = \get_plugin_data( ACTIVITYPUB_PLUGIN );
|
||||||
$activitypub_db_version = \get_option( 'activitypub_version' );
|
$activitypub_db_version = \get_option( 'activitypub_version' );
|
||||||
|
|
||||||
// Needs update
|
// Needs update
|
||||||
if ( empty( $activitypub_db_version ) || $plugin_data['Version'] > $activitypub_db_version ) {
|
if ( empty( $activitypub_db_version ) || $plugin_data['Version'] > $activitypub_db_version ) {
|
||||||
// Check for specific migrations
|
// Check for specific migrations
|
||||||
|
|
||||||
if ( '0.13.5' > $activitypub_db_version ) {
|
if ( '0.13.5' > $activitypub_db_version ) {
|
||||||
// This updates post_meta with _activitypub_permalink_compat.
|
// This updates post_meta with _activitypub_permalink_compat.
|
||||||
// Posts that have this meta will be backwards compatible with their permalink based ActivityPub ID (URI)
|
// Posts that have this meta will be backwards compatible with their permalink based ActivityPub ID (URI)
|
||||||
|
|
||||||
// This may create false positives, where the permalink has changed (slug, permalink structure) since federation,
|
// This may create false positives, where the permalink has changed (slug, permalink structure) since federation,
|
||||||
// for those cases a delete_url will allow for federating a delete based on the federated object ID (the old permalink)
|
// for those cases a delete_url will allow for federating a delete based on the federated object ID (the old permalink)
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ class Migrate_List extends \WP_List_Table {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_sortable_columns() {
|
public function get_sortable_columns() {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function prepare_items() {
|
public function prepare_items() {
|
||||||
|
@ -31,10 +31,10 @@ class Migrate_List extends \WP_List_Table {
|
||||||
foreach ( \Activitypub\Migrate\Posts::get_posts() as $post ) {
|
foreach ( \Activitypub\Migrate\Posts::get_posts() as $post ) {
|
||||||
$this->items[] = array(
|
$this->items[] = array(
|
||||||
'post_author' => $post->post_author,
|
'post_author' => $post->post_author,
|
||||||
'title' => \sprintf(
|
'title' => \sprintf(
|
||||||
'<a href="%1s">%2s</a>',
|
'<a href="%1s">%2s</a>',
|
||||||
\get_permalink( $post->ID ),
|
\get_permalink( $post->ID ),
|
||||||
$post->post_title
|
$post->post_title
|
||||||
),
|
),
|
||||||
'date' => $post->post_date,
|
'date' => $post->post_date,
|
||||||
'comments' => $post->comment_count,
|
'comments' => $post->comment_count,
|
||||||
|
@ -42,34 +42,34 @@ class Migrate_List extends \WP_List_Table {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* pagination */
|
// pagination
|
||||||
$per_page = $this->get_items_per_page('elements_per_page', 10);
|
$per_page = $this->get_items_per_page( 'elements_per_page', 10 );
|
||||||
$current_page = $this->get_pagenum();
|
$current_page = $this->get_pagenum();
|
||||||
$total_items = count($this->items);
|
$total_items = count( $this->items );
|
||||||
$table_data = array_slice( $this->items, ( ( $current_page - 1 ) * $per_page ), $per_page );
|
$table_data = array_slice( $this->items, ( ( $current_page - 1 ) * $per_page ), $per_page );
|
||||||
$this->set_pagination_args(
|
$this->set_pagination_args(
|
||||||
array(
|
array(
|
||||||
'total_items' => $total_items,
|
'total_items' => $total_items,
|
||||||
'per_page' => $per_page,
|
'per_page' => $per_page,
|
||||||
'total_pages' => ceil( $total_items / $per_page )
|
'total_pages' => ceil( $total_items / $per_page ),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
/* actions */
|
// actions
|
||||||
if ( isset( $_REQUEST['_wpnonce'] ) ) {
|
if ( isset( $_REQUEST['_wpnonce'] ) ) {
|
||||||
$nonce = \esc_attr( $_REQUEST['_wpnonce'] );
|
$nonce = \esc_attr( $_REQUEST['_wpnonce'] );
|
||||||
}
|
}
|
||||||
// delete
|
// delete
|
||||||
if (isset($_REQUEST['action']) && $_REQUEST['page'] == "activitypub_tools" && $_REQUEST['action'] == "delete") {
|
if ( isset( $_REQUEST['action'] ) && 'activitypub_tools' === $_REQUEST['page'] && 'delete' === $_REQUEST['action'] ) {
|
||||||
if ( wp_verify_nonce( $nonce, 'activitypub_delete_post' ) ) {
|
if ( wp_verify_nonce( $nonce, 'activitypub_delete_post' ) ) {
|
||||||
\Activitypub\Migrate\Posts::delete_url( rawurldecode( $_REQUEST['post_url'] ), absint( $_REQUEST['post_author'] ) );
|
\Activitypub\Migrate\Posts::delete_url( rawurldecode( $_REQUEST['post_url'] ), absint( $_REQUEST['post_author'] ) );
|
||||||
\delete_post_meta( \url_to_postid( $_REQUEST['post_url'] ), '_activitypub_permalink_compat' );
|
\delete_post_meta( \url_to_postid( $_REQUEST['post_url'] ), '_activitypub_permalink_compat' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// delete and announce
|
// delete and announce
|
||||||
if (isset($_REQUEST['action']) && $_REQUEST['page'] == "activitypub_tools" && $_REQUEST['action'] == "delete_and_boost") {
|
if ( isset( $_REQUEST['action'] ) && 'activitypub_tools' === $_REQUEST['page'] && 'delete_announce' === $_REQUEST['action'] ) {
|
||||||
if ( wp_verify_nonce( $nonce, 'activitypub_delete_announce_post' ) ) {
|
if ( wp_verify_nonce( $nonce, 'activitypub_delete_announce_post' ) ) {
|
||||||
\Activitypub\Migrate\Posts::migrate_post( rawurldecode( $_REQUEST['post_url'] ), absint( $_REQUEST['post_author'] ) );
|
\Activitypub\Migrate\Posts::migrate_post( rawurldecode( $_REQUEST['post_url'] ), absint( $_REQUEST['post_author'] ) );
|
||||||
\delete_post_meta( \url_to_postid( $_REQUEST['post_url'] ), '_activitypub_permalink_compat' );
|
\delete_post_meta( \url_to_postid( $_REQUEST['post_url'] ), '_activitypub_permalink_compat' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,32 +92,34 @@ class Migrate_List extends \WP_List_Table {
|
||||||
case 'migrate':
|
case 'migrate':
|
||||||
return $item[ $column_name ];
|
return $item[ $column_name ];
|
||||||
default:
|
default:
|
||||||
return print_r( $item, true ); //Show the whole array for troubleshooting purposes
|
return print_r( $item, true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function column_title( $item ) {
|
public function column_title( $item ) {
|
||||||
$delete_announce_nonce = wp_create_nonce( 'activitypub_delete_announce_post' );
|
$delete_announce_nonce = wp_create_nonce( 'activitypub_delete_announce_post' );
|
||||||
$delete_nonce = wp_create_nonce( 'activitypub_delete_post' );
|
$delete_nonce = wp_create_nonce( 'activitypub_delete_post' );
|
||||||
|
|
||||||
$actions = array(
|
$actions = array(
|
||||||
'delete_boost' => sprintf('<a href="?page=%s&action=%s&post_author=%s&post_url=%s&_wpnonce=%s">%s</a>',
|
'delete_announce' => sprintf(
|
||||||
esc_attr($_REQUEST['page']),
|
'<a href="?page=%s&action=%s&post_author=%s&post_url=%s&_wpnonce=%s">%s</a>',
|
||||||
'delete_and_boost',
|
esc_attr( $_REQUEST['page'] ),
|
||||||
$item['post_author'],
|
'delete_announce',
|
||||||
\rawurlencode( $item['migrate'] ),
|
$item['post_author'],
|
||||||
$delete_announce_nonce,
|
\rawurlencode( $item['migrate'] ),
|
||||||
__( 'Delete & Announce', 'activitypub' )
|
$delete_announce_nonce,
|
||||||
),
|
__( 'Delete & Announce', 'activitypub' )
|
||||||
'delete' => sprintf('<a href="?page=%s&action=%s&post_author=%s&post_url=%s&_wpnonce=%s">%s</a>',
|
),
|
||||||
esc_attr($_REQUEST['page']),
|
'delete' => sprintf(
|
||||||
'delete',
|
'<a href="?page=%s&action=%s&post_author=%s&post_url=%s&_wpnonce=%s">%s</a>',
|
||||||
$item['post_author'],
|
esc_attr( $_REQUEST['page'] ),
|
||||||
\rawurlencode( $item['migrate'] ),
|
'delete',
|
||||||
$delete_nonce,
|
$item['post_author'],
|
||||||
__( 'Delete', 'activitypub' )
|
\rawurlencode( $item['migrate'] ),
|
||||||
),
|
$delete_nonce,
|
||||||
);
|
__( 'Delete', 'activitypub' )
|
||||||
return sprintf('%1$s %2$s', $item['title'], $this->row_actions($actions, true) );
|
),
|
||||||
|
);
|
||||||
|
return sprintf( '%1$s %2$s', $item['title'], $this->row_actions( $actions, true ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue