2018-08-28 23:26:18 +00:00
|
|
|
<?php
|
|
|
|
namespace objects;
|
|
|
|
|
|
|
|
function persist_object( $object ) {
|
|
|
|
global $wpdb;
|
|
|
|
$wpdb->insert( 'activitypub_objects', array( 'object' => wp_json_encode( $object ) ) );
|
2018-08-29 20:38:10 +00:00
|
|
|
$object['id'] = get_object_url( $wpdb->insert_id );
|
2018-08-28 23:26:18 +00:00
|
|
|
return $object;
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_object( $id ) {
|
|
|
|
global $wpdb;
|
2018-08-29 20:38:10 +00:00
|
|
|
$object_json = $wpdb->get_var( sprintf(
|
2018-08-28 23:26:18 +00:00
|
|
|
'SELECT object FROM activitypub_objects WHERE id = %d', $id
|
2018-08-29 20:38:10 +00:00
|
|
|
) );
|
|
|
|
if ( is_null( $object_json ) ) {
|
|
|
|
return new \WP_Error(
|
|
|
|
404, __( 'Object not found', 'activitypub' ), array ( 'status' => 404 )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$object = json_decode( $object_json );
|
|
|
|
$object['id'] = get_object_url( $id );
|
2018-08-28 23:26:18 +00:00
|
|
|
return $object;
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_object_url( $id ) {
|
2018-08-29 20:38:10 +00:00
|
|
|
return get_rest_url( null, sprintf( '/activitypub/v1/object/%d', $id ) );
|
2018-08-28 23:26:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function create_object_table() {
|
|
|
|
global $wpdb;
|
|
|
|
$wpdb->query(
|
|
|
|
"
|
|
|
|
CREATE TABLE IF NOT EXISTS activitypub_objects (
|
|
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
object TEXT NOT NULL
|
|
|
|
);
|
|
|
|
"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
?>
|