Overlays refresh themselves after updates; media URLs versioned; frameless (transparent) alerts
Test and Release / test (push) Successful in 1m17s
Test and Release / release (push) Successful in 5s

- Overlay\Build id (plugin version + admin epoch) in X-SG-Build; overlay.js reloads once on mismatch (loop-guarded); 'Refresh all overlays now'
- Media URLs carry ?v=<mtime>
- Alert option 'Frameless' (schema v5): no box so transparent PNG/GIF/WebP and VP9-alpha WebM show through; admin preview with checkerboard and ffmpeg help

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
shadowdaoandClaude Sonnet 5.5 committed 2026-11-15 13:41:18 -08:00
1 parent 9249b80cb6
commit afa768fa42
21 files changed
+287 -16

No files matched your search

+1 -1
View File
@@ -20,7 +20,7 @@ interface AlertMediaSource {
/**
* Server-side attachment lookup (the only place media URLs come from). Null when it is gone.
*
* @return array{url:string,mime:string}|null
* @return array{url:string,mime:string,v?:int,modified?:string}|null (v = file mtime, modified = post_modified_gmt; used only for the ?v= cache-bust suffix)
*/
public function attachment( int $id ): ?array;
}
+44
View File
@@ -0,0 +1,44 @@
<?php
declare( strict_types=1 );
namespace StreamGoals\Overlay;
/**
* Overlay build id: plugin version + a manual "epoch". The overlay page embeds it, every overlay REST response
* repeats it in a header, and a page that sees a different value reloads itself (OBS never does that on its own).
*/
final class Build {
public const HEADER = 'X-SG-Build';
public const OPTION = 'sg_overlay_epoch';
/** Pure: the build id string for a version and epoch. Only [A-Za-z0-9._-] survive, so it is header- and attribute-safe. */
public static function id( string $version, mixed $epoch ): string {
$v = preg_replace( '/[^A-Za-z0-9._-]/', '', $version ) ?? '';
return ( '' === $v ? '0' : $v ) . '-' . self::epochInt( $epoch );
}
/** Pure: stored option value (anything) to a non-negative integer. */
public static function epochInt( mixed $raw ): int {
return ( is_int( $raw ) || ( is_string( $raw ) && ctype_digit( $raw ) && strlen( $raw ) < 15 ) ) ? max( 0, (int) $raw ) : 0;
}
/** Pure: the epoch after a bump. Strictly increasing, never lower than the clock so a deleted option cannot repeat an old value. */
public static function nextEpoch( mixed $current, int $now ): int {
return max( self::epochInt( $current ) + 1, $now );
}
/** Pure: response headers carrying the build id (merged into the existing ones; ETag semantics untouched). */
public static function headers( string $build ): array {
return array( self::HEADER => $build );
}
public static function current(): string {
return self::id( defined( 'STREAMGOALS_VERSION' ) ? (string) STREAMGOALS_VERSION : '', get_option( self::OPTION, 0 ) );
}
/** Reloads every open overlay at its next poll. */
public static function bump(): void {
update_option( self::OPTION, self::nextEpoch( get_option( self::OPTION, 0 ), time() ), false );
}
}
+1 -1
View File
@@ -74,7 +74,7 @@ final class Router {
<title>StreamGoals overlay</title>
<link rel="stylesheet" href="<?php echo $asset( 'overlay.css' ); // phpcs:ignore WordPress.Security.EscapeOutput ?>">
</head>
<body class="sg-theme-<?php echo esc_attr( $style['theme'] ); ?> sg-w-<?php echo esc_attr( $widget ); ?>" data-widget="<?php echo esc_attr( $widget ); ?>" data-endpoint="<?php echo esc_url( $endpoint ); ?>" data-poll="2500">
<body class="sg-theme-<?php echo esc_attr( $style['theme'] ); ?> sg-w-<?php echo esc_attr( $widget ); ?>" data-widget="<?php echo esc_attr( $widget ); ?>" data-endpoint="<?php echo esc_url( $endpoint ); ?>" data-poll="2500" data-build="<?php echo esc_attr( Build::current() ); ?>">
<main id="sg-root" aria-live="polite"></main>
<script src="<?php echo $asset( 'overlay.js' ); // phpcs:ignore WordPress.Security.EscapeOutput ?>"></script>
</body>
+4 -2
View File
@@ -6,7 +6,7 @@ namespace StreamGoals\Overlay;
/** $wpdb adapter reading sg_goals, sg_donations, sg_state, sg_rules directly. */
final class WpdbDataSource implements OverlayDataSource, RecentDonationsSource, ActionsSource, AlertMediaSource, TiersSource {
/** @var array<int,?array{url:string,mime:string}> */
/** @var array<int,?array{url:string,mime:string,v:int,modified:string}> */
private array $attachments = array();
private function t( string $name ): string {
@@ -160,7 +160,9 @@ final class WpdbDataSource implements OverlayDataSource, RecentDonationsSource,
$mime = (string) get_post_mime_type( $id );
$url = wp_get_attachment_url( $id );
if ( \StreamGoals\Alerts\Media::isAllowed( $mime ) && is_string( $url ) && '' !== $url ) {
$out = array( 'url' => $url, 'mime' => $mime );
$path = get_attached_file( $id );
$mtime = ( is_string( $path ) && is_file( $path ) ) ? (int) @filemtime( $path ) : 0;
$out = array( 'url' => $url, 'mime' => $mime, 'v' => $mtime, 'modified' => (string) get_post_field( 'post_modified_gmt', $id ) );
}
}
return $this->attachments[ $id ] = $out;