Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/changelog/content-parser
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Add rich content support for standard.site documents using the Markpub format.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
},
"autoload": {
"classmap": [
"includes/",
"integrations/"
"includes/"
]
},
"scripts": {
Expand Down
44 changes: 41 additions & 3 deletions includes/class-atmosphere.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Atmosphere\Transformer\Document;
use Atmosphere\Transformer\Publication;
use Atmosphere\Transformer\TID;
use Atmosphere\Integrations\Load;
use Atmosphere\WP_Admin\Admin;

/**
Expand Down Expand Up @@ -41,8 +40,8 @@ public function init(): void {
\add_action( 'init', array( $this, 'register_wellknown_rewrite' ) );
\add_action( 'template_redirect', array( $this, 'serve_wellknown_publication' ) );

// Plugin integrations.
Load::init();
// JSON preview for AT Protocol records.
\add_action( 'template_redirect', array( $this, 'preview' ) );

// Post lifecycle hooks.
\add_action( 'transition_post_status', array( $this, 'on_status_change' ), 10, 3 );
Expand Down Expand Up @@ -145,6 +144,45 @@ public function serve_wellknown_publication(): void {
exit;
}

/**
* Serve a JSON preview of the AT Protocol record for a post.
*
* Append ?atproto to a singular post URL to see the document
* record JSON. Optionally pass ?atproto={parser} to preview
* with a specific content parser (requires the parser to be
* registered via the atmosphere_content_parser filter).
*/
public function preview(): void {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( ! isset( $_GET['atproto'] ) || ! \is_singular() ) {
return;
}

if ( ! \current_user_can( 'edit_posts' ) ) {
return;
}

$post = \get_queried_object();

if ( ! $post instanceof \WP_Post ) {
return;
}

if ( ! \in_array( $post->post_type, Backfill::syncable_post_types(), true ) ) {
\status_header( 404 );
exit;
}

$transformer = new Document( $post );
$record = $transformer->transform();

\status_header( 200 );
\header( 'Content-Type: application/json; charset=utf-8' );
// phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode
echo \wp_json_encode( $record, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
exit;
}

/**
* Handle post status transitions.
*
Expand Down
Loading