Overlays refresh themselves after updates; media URLs versioned; frameless (transparent) alerts
- 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:
1 parent
9249b80cb6
commit
afa768fa42
21 files changed
+287
-16
No files matched your search
@@ -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 );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user