kind. Everything else (svg, html, ...) is rejected. */ public const MIMES = array( 'image/png' => 'image', 'image/jpeg' => 'image', 'image/gif' => 'image', 'image/webp' => 'image', 'video/mp4' => 'video', 'video/webm' => 'video', 'audio/mpeg' => 'audio', 'audio/ogg' => 'audio', 'audio/wav' => 'audio', ); public const WARN_BYTES = 26214400; // 25 MB public const MIN_DURATION_MS = 1000; public const MAX_DURATION_MS = 60000; public const DEFAULT_MS = 6000; public const VIDEO_CAP_MS = 30000; /** 'image' | 'video' | 'audio' for an allowed MIME, else null. Strict: no parameters, no case games. */ public static function kind( mixed $mime ): ?string { if ( ! is_string( $mime ) ) { return null; } return self::MIMES[ strtolower( $mime ) ] ?? null; } public static function isAllowed( mixed $mime ): bool { return null !== self::kind( $mime ); } /** 'image' | 'video' for a visual attachment MIME, else null (audio is not a visual). */ public static function visualType( mixed $mime ): ?string { $k = self::kind( $mime ); return 'image' === $k || 'video' === $k ? $k : null; } public static function isSound( mixed $mime ): bool { return 'audio' === self::kind( $mime ); } public static function clampDurationMs( mixed $ms, int $default = self::DEFAULT_MS ): int { if ( ! is_numeric( $ms ) ) { return $default; } return max( self::MIN_DURATION_MS, min( self::MAX_DURATION_MS, (int) $ms ) ); } /** Whole seconds (1-60) to clamped milliseconds; null when the input is not a number. */ public static function secondsToMs( mixed $s ): ?int { if ( ! is_scalar( $s ) || ! preg_match( '/^\s*\d{1,4}(\.\d+)?\s*$/', (string) $s ) ) { return null; } return self::clampDurationMs( (int) round( (float) $s * 1000 ) ); } public static function clampVolume( mixed $v, int $default = 80 ): int { return is_numeric( $v ) ? max( 0, min( 100, (int) $v ) ) : $default; } /** Only plain http(s) URLs are ever handed to the overlay. */ public static function safeUrl( mixed $url ): ?string { if ( ! is_string( $url ) || '' === $url || strlen( $url ) > 2000 || preg_match( '/[\x00-\x20\x7F"\'<>\\\\]/', $url ) ) { return null; } return preg_match( '#^https?://[^/]#i', $url ) ? $url : null; } }