pterotype/inc/inbox.php

80 lines
1.9 KiB
PHP
Raw Normal View History

2018-08-21 13:17:07 +00:00
<?php
2018-08-22 12:33:21 +00:00
/*
When an Activity is received (i.e. POSTed) to an Actor's inbox, the server must:
2018-08-21 13:17:07 +00:00
2018-08-22 12:33:21 +00:00
1. Forward the Activity as necessary
See (https://www.w3.org/TR/activitypub/#x7-1-2-forwarding-from-inbox).
2. Perform the side effects of receiving the Activity
2018-09-15 21:47:13 +00:00
3. Persist the activity in the actor's inbox (and the attached object, if necessary)
To persist an activity or object:
1. Check if the activity or object already exists in the DB
2. If yes, do nothing
3. If no, add it to the DB
2018-08-22 12:33:21 +00:00
*/
2018-09-15 21:47:13 +00:00
namespace inbox;
function handle_activity( $actor, $activity ) {
if ( !array_key_exists( 'type', $activity ) ) {
return new \WP_Error(
'invalid_activity',
2018-09-19 15:16:41 +00:00
__( 'Activity must have a type', 'pterotype' ),
2018-09-15 21:47:13 +00:00
array( 'status' => 400 )
);
}
forward_activity( $activity );
switch ( $activity['type'] ) {
case 'Create':
break;
case 'Update':
break;
case 'Delete':
break;
case 'Follow':
break;
case 'Accept':
break;
case 'Reject':
break;
case 'Add':
break;
case 'Remove':
break;
case 'Announce':
break;
case 'Undo':
break;
}
if ( is_wp_error( $activity ) ) {
return $activity;
}
persist_activity( $activity );
return new \WP_REST_Response();
}
function forward_activity( $activity ) {
}
function persist_activity( $activity ) {
global $wpdb;
2018-09-15 21:47:13 +00:00
}
function create_inbox_table() {
global $wpdb;
$wpdb->query(
"
2018-09-19 21:33:20 +00:00
CREATE TABLE IF NOT EXISTS pterotype_inbox(
2018-09-15 21:47:13 +00:00
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
actor_id UNSIGNED INT NOT NULL,
activity_id INT UNSIGNED NOT NULL,
2018-09-19 12:54:07 +00:00
FOREIGN KEY inbox_activity_fk(activity_id)
2018-09-19 21:33:20 +00:00
REFERENCES pterotype_activities(id)
2018-09-19 12:54:07 +00:00
)
ENGINE=InnoDB DEFAULT CHARSET=utf8;
2018-09-15 21:47:13 +00:00
"
);
}
2018-08-21 13:17:07 +00:00
?>