pterotype/inc/objects.php

42 lines
1.0 KiB
PHP
Raw Normal View History

<?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 );
return $object;
}
function get_object( $id ) {
global $wpdb;
2018-08-29 20:38:10 +00:00
$object_json = $wpdb->get_var( sprintf(
'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 );
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 ) );
}
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
);
"
);
}
?>