Rebrand to Pterotype

This commit is contained in:
Jeremy Dormitzer 2018-09-19 11:16:41 -04:00
parent e81a9b4bb0
commit d92d99f1fc
No known key found for this signature in database
GPG Key ID: 04F17C0F5A32C320
12 changed files with 89 additions and 86 deletions

View File

@ -1,12 +1,12 @@
<?php
/*
Plugin Name: ActivityPub
Plugin Name: Pterotype
*/
require_once plugin_dir_path( __FILE__ ) . 'inc/init.php';
function activitypub_init() {
do_action( 'activitypub_init' );
function pterotype_init() {
do_action( 'pterotype_init' );
}
register_activation_hook( __FILE__, 'activitypub_init');
register_activation_hook( __FILE__, 'pterotype_init');
?>

View File

@ -4,11 +4,11 @@ namespace activities;
function get_activity( $id ) {
global $wpdb;
$activity_json = $wpdb->get_var( $wpdb->prepare(
'SELECT activity FROM activitypub_activities WHERE id = %d', $id
'SELECT activity FROM pterotype_activitypub_activities WHERE id = %d', $id
) );
if ( is_null( $activity_json ) ) {
return new \WP_Error(
'not_found', __( 'Activity not found', 'activitypub' ), array( 'status' => 404 )
'not_found', __( 'Activity not found', 'pterotype' ), array( 'status' => 404 )
);
}
$activity = json_decode( $activity_json, true );
@ -18,11 +18,11 @@ function get_activity( $id ) {
function get_activity_by_activitypub_id( $activitypub_id ) {
global $wpdb;
$activity_json = $wpdb->get_var( $wpdb->prepare(
'SELECT activity FROM activitypub_activities WHERE id = %s', $activitypub_id
'SELECT activity FROM pterotype_activitypub_activities WHERE id = %s', $activitypub_id
) );
if ( is_null( $activity_json ) ) {
return new \WP_Error(
'not_found', __( 'Activity not found', 'activitypub' ), array( 'status' => 404 )
'not_found', __( 'Activity not found', 'pterotype' ), array( 'status' => 404 )
);
}
$activity = json_decode( $activity_json, true );
@ -44,12 +44,12 @@ function persist_activity( $activity ) {
if ( !array_key_exists( 'id', $activity ) ) {
return new \WP_Error(
'invalid_activity',
__( 'Activity must have an "id" field', 'activitypub' ),
__( 'Activity must have an "id" field', 'pterotype' ),
array( 'status' => 400 )
);
}
$activitypub_id = $activity['id'];
$wpdb->insert( 'activitypub_activities', array(
$wpdb->insert( 'pterotype_activitypub_activities', array(
'activitypub_id' => $activitypub_id,
'activity' => wp_json_encode( $activity )
) );
@ -58,19 +58,19 @@ function persist_activity( $activity ) {
function create_local_activity( $activity ) {
global $wpdb;
$res = $wpdb->insert( 'activitypub_activities', array(
$res = $wpdb->insert( 'pterotype_activitypub_activities', array(
'activity' => wp_json_encode( $activity )
) );
if ( !$res ) {
return new \WP_Error(
'db_error', __( 'Failed to insert activity row', 'activitypub' )
'db_error', __( 'Failed to insert activity row', 'pterotype' )
);
}
$activity_id = $wpdb->insert_id;
$activity_url = get_rest_url( null, sprintf( '/activitypub/v1/activity/%d', $id ) );
$activity_url = get_rest_url( null, sprintf( '/pterotype/v1/activity/%d', $id ) );
$activity['id'] = $activity_url;
$res = $wpdb->replace(
'activitypub_activities',
'pterotype_activitypub_activities',
array(
'id' => $activity_id,
'activitypub_id' => $activity_url,
@ -80,7 +80,7 @@ function create_local_activity( $activity ) {
);
if ( !$res ) {
return new \WP_Error(
'db_error', __( 'Failed to hydrate activity id', 'activitypub' )
'db_error', __( 'Failed to hydrate activity id', 'pterotype' )
);
}
return $activity;
@ -90,7 +90,7 @@ function create_activities_table() {
global $wpdb;
$wpdb->query(
"
CREATE TABLE IF NOT EXISTS activitypub_activities (
CREATE TABLE IF NOT EXISTS pterotype_activitypub_activities (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
activitypub_id VARCHAR(255) UNIQUE NOT NULL,
activity TEXT NOT NULL
@ -100,8 +100,8 @@ function create_activities_table() {
);
$wpdb->query(
"
CREATE UNIQUE INDEX ACTIVITYPUB_ID_INDEX
ON activitypub_activities (activitypub_id);
CREATE UNIQUE INDEX ACTIVITIES_ACTIVITYPUB_ID_INDEX
ON pterotype_activitypub_activities (activitypub_id);
"
);
}

View File

@ -4,7 +4,7 @@ namespace actors;
function get_actor( $id ) {
global $wpdb;
$row = $wpdb->get_row( $wpdb->prepare(
'SELECT * FROM activitypub_actors WHERE id = %d', $id
'SELECT * FROM pterotype_activitypub_actors WHERE id = %d', $id
) );
return get_user_from_row( $row );
}
@ -12,7 +12,7 @@ function get_actor( $id ) {
function get_actor_by_slug ( $slug ) {
global $wpdb;
$row = $wpdb->get_row( $wpdb->prepare(
'SELECT * FROM activitypub_actors WHERE slug = %s', $slug
'SELECT * FROM pterotype_activitypub_actors WHERE slug = %s', $slug
) );
return get_actor_from_row( $row );
}
@ -20,7 +20,7 @@ function get_actor_by_slug ( $slug ) {
function get_actor_id( $slug ) {
global $wpdb;
return $wpdb->get_var( $wpdb->prepare(
"SELECT slug FROM activitypub_actors WHERE slug = %s", $slug
"SELECT slug FROM pterotype_activitypub_actors WHERE slug = %s", $slug
) );
}
@ -41,17 +41,17 @@ function get_user_actor( $user ) {
$actor = array(
"@context" => array( "https://www.w3.org/ns/activitystreams" ),
"type" => "Person",
"id" => get_rest_url( null, sprintf( '/activitypub/v1/actor/%s', $handle ) ),
"id" => get_rest_url( null, sprintf( '/pterotype/v1/actor/%s', $handle ) ),
"following" => get_rest_url(
null, sprintf( '/activitypub/v1/actor/%s/following', $handle ) ),
null, sprintf( '/pterotype/v1/actor/%s/following', $handle ) ),
"followers" => get_rest_url(
null, sprintf( '/activitypub/v1/actor/%s/followers', $handle ) ),
null, sprintf( '/pterotype/v1/actor/%s/followers', $handle ) ),
"liked" => get_rest_url(
null, sprintf( '/activitypub/v1/actor/%s/liked', $handle ) ),
null, sprintf( '/pterotype/v1/actor/%s/liked', $handle ) ),
"inbox" => get_rest_url(
null, sprintf( '/activitypub/v1/actor/%s/inbox', $handle ) ),
null, sprintf( '/pterotype/v1/actor/%s/inbox', $handle ) ),
"outbox" => get_rest_url(
null, sprintf( '/activitypub/v1/actor/%s/outbox', $handle ) ),
null, sprintf( '/pterotype/v1/actor/%s/outbox', $handle ) ),
"preferredUsername" => $handle,
"name" => get_the_author_meta( 'display_name', $user->get('ID') ),
"summary" => get_the_author_meta( 'description', $user->get('ID') ),
@ -65,7 +65,7 @@ function create_actors_table() {
global $wpdb;
$wpdb->query(
"
CREATE TABLE IF NOT EXISTS activitypub_actors(
CREATE TABLE IF NOT EXISTS pterotype_activitypub_actors(
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
slug VARCHAR(64) UNIQUE NOT NULL,
type VARCHAR(64) NOT NULL
@ -92,7 +92,7 @@ function initialize_user_actors() {
function create_actor_from_user( $user_slug ) {
global $wpdb;
$wpdb->query( $wpdb->prepare(
"INSERT IGNORE INTO activitypub_actors(slug, type) VALUES(%s, 'user')", $user_slug
"INSERT IGNORE INTO pterotype_activitypub_actors(slug, type) VALUES(%s, 'user')", $user_slug
) );
}
?>

View File

@ -33,23 +33,23 @@ function get_activity( $request ) {
}
function register_routes() {
register_rest_route( 'activitypub/v1', '/actor/(?P<actor>[a-zA-Z0-9-]+)/outbox', array(
register_rest_route( 'pterotype/v1', '/actor/(?P<actor>[a-zA-Z0-9-]+)/outbox', array(
'methods' => 'POST',
'callback' => __NAMESPACE__ . '\post_to_outbox',
) );
register_rest_route( 'activitypub/v1', '/actor/(?P<actor>[a-zA-Z0-9-]+/outbox', array(
register_rest_route( 'pterotype/v1', '/actor/(?P<actor>[a-zA-Z0-9-]+/outbox', array(
'methods' => 'POST',
'callback' => __NAMESPACE__ . '\get_outbox',
) );
register_rest_route( 'activitypub/v1', '/actor/(?P<actor>[a-zA-Z0-9-]+)', array(
register_rest_route( 'pterotype/v1', '/actor/(?P<actor>[a-zA-Z0-9-]+)', array(
'methods' => 'GET',
'callback' => __NAMESPACE__ . '\get_actor',
) );
register_rest_route( 'activitypub/v1', '/object/(?P<id>[0-9]+)', array(
register_rest_route( 'pterotype/v1', '/object/(?P<id>[0-9]+)', array(
'methods' => 'GET',
'callback' => __NAMESPACE__ . '\get_object',
) );
register_rest_route( 'activitypub/v1', '/activity/(?P<id>[0-9]+)', array(
register_rest_route( 'pterotype/v1', '/activity/(?P<id>[0-9]+)', array(
'methods' => 'GET',
'callback' => __NAMESPACE__ . '\get_activity',
) );

View File

@ -10,11 +10,11 @@ get ignored
function create_block( $actor_id, $blocked_actor_url ) {
global $wpdb;
$res = $wpdb->insert(
'activitypub_blocks',
'pterotype_activitypub_blocks',
array( 'actor_id' => $actor_id, 'blocked_actor_url' => $blocked_actor_url )
);
if ( !$res ) {
return new \WP_Error( 'db_error', __( 'Error inserting block row', 'activitypub' ) );
return new \WP_Error( 'db_error', __( 'Error inserting block row', 'pterotype' ) );
}
}
@ -22,11 +22,11 @@ function create_blocks_table() {
global $wpdb;
$wpdb->query(
"
CREATE TABLE IF NOT EXISTS activitypub_blocks(
CREATE TABLE IF NOT EXISTS pterotype_activitypub_blocks(
actor_id INT UNSIGNED NOT NULL,
blocked_actor_url TEXT NOT NULL,
FOREIGN KEY blocks_actor_fk(actor_id)
REFERENCES activitypub_actors(id)
REFERENCES pterotype_activitypub_actors(id)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8;
"

View File

@ -46,7 +46,7 @@ function retrieve_recipients( $url ) {
// - collection
if ( !array_key_exists( 'type', $response_body ) ) {
return new \WP_Error(
'invalid_object', __( 'Expected an object type', 'activitypub' )
'invalid_object', __( 'Expected an object type', 'pterotype' )
);
}
switch ( $response_body['type'] ) {

View File

@ -7,7 +7,7 @@ $FOLLOWING = 'FOLLOWING';
function request_follow( $actor_id, $object_id ) {
global $wpdb;
return $wpdb->insert(
'activitypub_following',
'pterotype_activitypub_following',
array( 'actor_id' => $actor_id,
'object_id' => wp_json_encode( $object ),
'state' => $PENDING
@ -19,15 +19,15 @@ function create_following_table() {
global $wpdb;
$wpdb->query(
"
CREATE TABLE IF NOT EXISTS activitypub_following(
CREATE TABLE IF NOT EXISTS pterotype_activitypub_following(
actor_id INT UNSIGNED NOT NULL,
object_id INT UNSIGNED NOT NULL,
state VARCHAR(64) NOT NULL,
PRIMARY KEY (actor_id, object_id),
FOREIGN KEY following_actor_fk(actor_id)
REFERENCES activitypub_actors(id),
REFERENCES pterotype_activitypub_actors(id),
FOREIGN KEY following_object_fk(object_id)
REFERENCES activitypub_objects(id)
REFERENCES pterotype_activitypub_objects(id)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8;
"

View File

@ -18,7 +18,7 @@ function handle_activity( $actor, $activity ) {
if ( !array_key_exists( 'type', $activity ) ) {
return new \WP_Error(
'invalid_activity',
__( 'Activity must have a type', 'activitypub' ),
__( 'Activity must have a type', 'pterotype' ),
array( 'status' => 400 )
);
}
@ -65,12 +65,12 @@ function create_inbox_table() {
global $wpdb;
$wpdb->query(
"
CREATE TABLE IF NOT EXISTS activitypub_inbox(
CREATE TABLE IF NOT EXISTS pterotype_activitypub_inbox(
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
actor_id UNSIGNED INT NOT NULL,
activity_id INT UNSIGNED NOT NULL,
FOREIGN KEY inbox_activity_fk(activity_id)
REFERENCES activitypub_activities(id)
REFERENCES pterotype_activitypub_activities(id)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8;
"

View File

@ -19,7 +19,7 @@ add_action( 'user_register', function( $user_id ) {
\actors\create_actor_from_user( $slug );
} );
add_action( 'activitypub_init', function() {
add_action( 'pterotype_init', function() {
\activities\create_activities_table();
\objects\create_object_table();
\outbox\create_outbox_table();

View File

@ -4,7 +4,7 @@ namespace likes;
function create_like( $actor_id, $object_id ) {
global $wpdb;
return $wpdb->insert(
'activitypub_likes', array( 'actor_id' => $actor_id, 'object_id' => $object_id )
'pterotype_activitypub_likes', array( 'actor_id' => $actor_id, 'object_id' => $object_id )
);
}
@ -12,14 +12,14 @@ function create_likes_table() {
global $wpdb;
$wpdb->query(
"
CREATE TABLE IF NOT EXISTS activitypub_likes (
CREATE TABLE IF NOT EXISTS pterotype_activitypub_likes (
actor_id INT UNSIGNED NOT NULL,
object_id INT UNSIGNED NOT NULL,
PRIMARY KEY (actor_id, object_id),
FOREIGN KEY likes_actor_fk(actor_id)
REFERENCES activitypub_actors(id),
REFERENCES pterotype_activitypub_actors(id),
FOREIGN KEY likes_object_fk(object_id)
REFERENCES activitypub_objects(id)
REFERENCES pterotype_activitypub_objects(id)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8;
"

View File

@ -6,19 +6,19 @@ namespace objects;
function create_local_object( $object ) {
global $wpdb;
$res = $wpdb->insert( 'activitypub_objects', array(
$res = $wpdb->insert( 'pterotype_activitypub_objects', array(
'object' => wp_json_encode( $object )
) );
if ( !$res ) {
return new \WP_Error(
'db_error', __( 'Failed to insert object row', 'activitypub' )
'db_error', __( 'Failed to insert object row', 'pterotype' )
);
}
$object_id = $wpdb->insert_id;
$object_url = get_rest_url( null, sprintf( '/activitypub/v1/object/%d', $object_id ) );
$object_url = get_rest_url( null, sprintf( '/pterotype/v1/object/%d', $object_id ) );
$object['id'] = $object_url;
$res = $wpdb->replace(
'activitypub_objects',
'pterotype_activitypub_objects',
array (
'id' => $object_id,
'activitypub_id' => $object_url,
@ -28,7 +28,7 @@ function create_local_object( $object ) {
);
if ( !$res ) {
return new \WP_Error(
'db_error', __( 'Failed to hydrate object id', 'activitypub' )
'db_error', __( 'Failed to hydrate object id', 'pterotype' )
);
}
return $object;
@ -39,17 +39,17 @@ function upsert_object( $object ) {
if ( !array_key_exists( 'id', $object ) ) {
return new \WP_Error(
'invalid_object',
__( 'Objects must have an "id" field', 'activitypub' ),
__( 'Objects must have an "id" field', 'pterotype' ),
array( 'status' => 400 )
);
}
$row = $wpdb->get_row( $wpdb->prepare(
'SELECT * FROM activitypub_objects WHERE activitypub_url = %s', $object['id']
'SELECT * FROM pterotype_activitypub_objects WHERE activitypub_url = %s', $object['id']
) );
$res = true;
if ( $row === null ) {
$res = $wpdb->insert(
'activitypub_objects',
'pterotype_activitypub_objects',
array(
'activitypub_id' => $object['id'],
'object' => wp_json_encode( $object )
@ -57,7 +57,7 @@ function upsert_object( $object ) {
);
} else {
$res = $wpdb->replace(
'activitypub_objects',
'pterotype_activitypub_objects',
array(
'id' => $row->id,
'activitypub_id' => $object['id'],
@ -70,7 +70,7 @@ function upsert_object( $object ) {
}
if ( !$res ) {
return new \WP_Error(
'db_error', __( 'Failed to upsert object row', 'activitypub' )
'db_error', __( 'Failed to upsert object row', 'pterotype' )
);
}
$row->object = $object;
@ -82,7 +82,7 @@ function update_object( $object ) {
if ( !array_key_exists( 'id', $object ) ) {
return new \WP_Error(
'invalid_object',
__( 'Object must have an "id" field', 'activitypub' ),
__( 'Object must have an "id" field', 'pterotype' ),
array( 'status' => 400 )
);
}
@ -94,7 +94,7 @@ function update_object( $object ) {
'%s', '%d' );
if ( !$res ) {
return new \WP_Error(
'db_error', __( 'Failed to update object row', 'activitypub' )
'db_error', __( 'Failed to update object row', 'pterotype' )
);
}
return $object;
@ -103,11 +103,11 @@ function update_object( $object ) {
function get_object( $id ) {
global $wpdb;
$object_json = $wpdb->get_var( $wpdb->prepare(
'SELECT object FROM activitypub_objects WHERE id = %d', $id
'SELECT object FROM pterotype_activitypub_objects WHERE id = %d', $id
) );
if ( is_null( $object_json ) ) {
return new \WP_Error(
'not_found', __( 'Object not found', 'activitypub' ), array( 'status' => 404 )
'not_found', __( 'Object not found', 'pterotype' ), array( 'status' => 404 )
);
}
return json_decode( $object_json, true );
@ -116,11 +116,11 @@ function get_object( $id ) {
function get_object_by_activitypub_id( $activitypub_id ) {
global $wpdb;
$object_json = $wpdb->get_var( $wpdb->prepare(
'SELECT object FROM activitypub_objects WHERE activitypub_id = %s', $activitypub_id
'SELECT object FROM pterotype_activitypub_objects WHERE activitypub_id = %s', $activitypub_id
) );
if ( is_null( $object_json ) ) {
return new \WP_Error(
'not_found', __( 'Object not found', 'activitypub' ), array( 'status' => 404 )
'not_found', __( 'Object not found', 'pterotype' ), array( 'status' => 404 )
);
}
return json_decode( $object_json, true );
@ -131,14 +131,14 @@ function delete_object( $object ) {
if ( !array_key_exists( 'id', $object ) ) {
return new \WP_Error(
'invalid_object',
__( 'Object must have an "id" field', 'activitypub' ),
__( 'Object must have an "id" field', 'pterotype' ),
array( 'status' => 400 )
);
}
$activitypub_id = $object['id'];
$res = $wpdb->delete( 'activitypub_objects', array( 'activitypub_id' => $id ), '%s' );
$res = $wpdb->delete( 'pterotype_activitypub_objects', array( 'activitypub_id' => $id ), '%s' );
if ( !$res ) {
return new \WP_Error( 'db_error', __( 'Error deleting object', 'activitypub' ) );
return new \WP_Error( 'db_error', __( 'Error deleting object', 'pterotype' ) );
}
return $res;
}
@ -147,7 +147,7 @@ function create_object_table() {
global $wpdb;
$wpdb->query(
"
CREATE TABLE IF NOT EXISTS activitypub_objects (
CREATE TABLE IF NOT EXISTS pterotype_activitypub_objects (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
activitypub_id VARCHAR(255) UNIQUE NOT NULL,
object TEXT NOT NULL
@ -157,8 +157,8 @@ function create_object_table() {
);
$wpdb->query(
"
CREATE UNIQUE INDEX ACTIVITYPUB_ID_INDEX
ON activitypub_objects (activitypub_id);
CREATE UNIQUE INDEX OBJECT_ACTIVITYPUB_ID_INDEX
ON pterotype_activitypub_objects (activitypub_id);
"
);
}

View File

@ -27,7 +27,7 @@ function handle_activity( $actor_slug, $activity ) {
if ( !array_key_exists( 'type', $activity ) ) {
return new \WP_Error(
'invalid_activity',
__( 'Invalid activity', 'activitypub' ),
__( 'Invalid activity', 'pterotype' ),
array( 'status' => 400 )
);
}
@ -47,14 +47,14 @@ function handle_activity( $actor_slug, $activity ) {
case 'Add':
return new \WP_Error(
'not_implemented',
__( 'The Add activity has not been implemented', 'activitypub' ),
__( 'The Add activity has not been implemented', 'pterotype' ),
array( 'status' => 501 )
);
break;
case 'Remove':
return new \WP_Error(
'not_implemented',
__( 'The Remove activity has not been implemented', 'activitypub' ),
__( 'The Remove activity has not been implemented', 'pterotype' ),
array( 'status' => 501 )
);
break;
@ -67,7 +67,7 @@ function handle_activity( $actor_slug, $activity ) {
case 'Undo':
return new \WP_Error(
'not_implemented',
__( 'The Undo activity has not been implemented', 'activitypub' ),
__( 'The Undo activity has not been implemented', 'pterotype' ),
array( 'status' => 501 )
);
break;
@ -91,12 +91,15 @@ function get_outbox( $actor_slug ) {
// TODO what sort of joins should these be?
$results = $wpdb->get_results( $wpdb->prepare(
"
SELECT activitypub_activities.activity FROM activitypub_outbox
JOIN activitypub_actors
ON activitypub_actors.id = activitypub_outbox.actor_id
JOIN activitypub_activities
ON activitypub_activities.id = activitypub_outbox.activity_id
WHERE activitypub_outbox.actor_id = %d
SELECT pterotype_activitypub_activities.activity
FROM pterotype_activitypub_outbox
JOIN pterotype_activitypub_actors
ON pterotype_activitypub_actors.id
= pterotype_activitypub_outbox.actor_id
JOIN pterotype_activitypub_activities
ON pterotype_activitypub_activities.id
= pterotype_activitypub_outbox.activity_id
WHERE pterotype_pterotype_activitypub_outbox.actor_id = %d
",
$actor_id
) );
@ -120,7 +123,7 @@ function persist_activity( $actor_slug, $activity ) {
$activity = \activities\create_local_activity( $activity );
$activity_id = $wpdb->insert_id;
$actor_id = \actors\get_actor_id( $actor_slug );
$wpdb->insert( 'activitypub_outbox', array(
$wpdb->insert( 'pterotype_activitypub_outbox', array(
'actor_id' => $actor_id,
'activity_id' => $activity_id,
) );
@ -148,12 +151,12 @@ function create_outbox_table() {
global $wpdb;
$wpdb->query(
"
CREATE TABLE IF NOT EXISTS activitypub_outbox (
CREATE TABLE IF NOT EXISTS pterotype_activitypub_outbox (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
actor_id INT UNSIGNED NOT NULL,
activity_id INT UNSIGNED NOT NULL,
FOREIGN KEY outbox_activity_fk(activity_id)
REFERENCES activitypub_activities(id)
REFERENCES pterotype_activitypub_activities(id)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8;
"