array( 'Goal bar', 800, 120, 'Progress bar towards your active goal.' ), 'timer' => array( 'Subathon timer', 400, 120, 'Countdown that grows with donations (needs an "Add time" rule).' ), 'counter' => array( 'Counter', 400, 120, 'A running count (needs a "Counter" rule).' ), 'alerts' => array( 'Donation alerts', 600, 300, 'Pop-up alert for each new donation.' ), 'actions' => array( 'Rewards menu', 500, 400, 'Lists your donation actions (e.g. "$5: Eat a bean") for the active goal. Shows nothing if you have none.' ), ); /** @return array{url:string,base:string,sep:string} */ public static function widgetUrl( string $widget ): array { $token = OverlayController::ensure_token(); if ( get_option( 'permalink_structure' ) ) { $base = home_url( '/streamgoals-overlay/' . rawurlencode( $token ) . '/' . rawurlencode( $widget ) . '/' ); return array( 'url' => $base, 'base' => $base, 'sep' => '?' ); } $base = add_query_arg( array( 'sg_overlay_token' => $token, 'sg_overlay_widget' => $widget ), home_url( '/' ) ); return array( 'url' => $base, 'base' => $base, 'sep' => '&' ); } /** Used by the wizard and this screen: one copy-able link per widget. */ public static function urlList( bool $withPreview = false ): void { foreach ( self::WIDGETS as $w => [ $label, $width, $height, $desc ] ) { $u = self::widgetUrl( $w ); echo '
'; echo '

' . esc_html( $label ) . '

' . esc_html( $desc ) . ' OBS size: ' . (int) $width . ' x ' . (int) $height . '

'; echo '
'; if ( $withPreview ) { echo '

'; echo ''; } echo '
'; } if ( ! get_option( 'permalink_structure' ) ) { echo '

Your site uses "Plain" permalinks, so the links use the longer form. They work the same.

'; } } public static function render(): void { Admin::open( 'Overlays' ); $fonts = array( 'sans' => 'Clean sans-serif', 'serif' => 'Serif', 'mono' => 'Monospace', 'rounded' => 'Rounded', 'condensed' => 'Condensed' ); echo '

Paste these links into OBS as Browser Sources. Use the style builder to change how they look: all links update as you go.

'; echo '

Style

'; echo ''; echo ''; echo ''; echo ''; foreach ( array( 'color' => 'Text color', 'accent' => 'Accent color', 'accent2' => 'Second accent', 'track' => 'Bar background', 'bg' => 'Panel background' ) as $k => $l ) { echo ''; } echo '

Tick a box to override that color; unticked colors come from the theme.

'; echo '

Links

'; self::urlList( true ); echo '
'; echo '

Refresh overlays

'; Admin::form( 'sg_refresh_overlays', array(), 'sg-inline' ); echo ''; echo '

Reloads every open OBS source. Done automatically after a plugin update.

'; echo '

Send a test donation

'; echo '

Shows a fake donation on the Donation alerts overlay so you can check your OBS setup. Open the alerts preview above (or have OBS running) first, then press the button; the alert appears within a few seconds.

'; echo '

How tests are kept out of your numbers: test donations are not attached to any goal, so they never count towards raised totals, timers or counters. They are excluded from the CSV export, and marked TEST in the Donations list. Test donations are kept in the database until you delete them below.

'; Admin::form( 'sg_test_donation', array(), 'sg-inline' ); echo ' '; echo ' '; Admin::form( 'sg_delete_tests', array(), 'sg-inline' ); echo '
'; echo '

Security

The links contain a secret token. If a link was shown on stream or shared by mistake, make new links. The old ones stop working immediately and you will need to paste the new ones into OBS.

'; Admin::form( 'sg_regen_token', array(), 'sg-confirm' ); echo '
'; Admin::close(); } public static function handleTestDonation(): void { Admin::guard( 'sg_test_donation' ); $cur = Admin::currency(); $amt = Input::amountToMinor( Admin::post_str( 'amount', 30 ), $cur ); if ( null === $amt || $amt <= 0 || $amt > 99999999 ) { Admin::redirect( Admin::url( 'streamgoals-overlays' ), 'error', 'Please enter a valid test amount, for example 5.00.' ); } $id = Store::insertTestDonation( $amt, $cur ); Admin::redirect( Admin::url( 'streamgoals-overlays' ), $id ? 'success' : 'error', $id ? 'Test donation sent. Watch your alerts overlay.' : 'The test donation could not be saved.' ); } public static function handleDeleteTests(): void { Admin::guard( 'sg_delete_tests' ); $n = Store::deleteTestDonations(); Admin::redirect( Admin::url( 'streamgoals-overlays' ), 'success', $n . ' test donation(s) deleted.' ); } public static function handleRefreshAll(): void { Admin::guard( 'sg_refresh_overlays' ); Build::bump(); Admin::redirect( Admin::url( 'streamgoals-overlays' ), 'success', 'All open overlays will reload within a few seconds.' ); } public static function handleRegenerate(): void { Admin::guard( 'sg_regen_token' ); Settings::update( array( 'overlay_token' => bin2hex( random_bytes( 16 ) ) ) ); Admin::redirect( Admin::url( 'streamgoals-overlays' ), 'success', 'New overlay links created. Update them in OBS.' ); } }