goal id => title */ private static function goalTitles(): array { $out = array(); foreach ( Store::goals()->all() as $g ) { $out[ (int) $g['id'] ] = (string) $g['title']; } return $out; } /** Attachment lookup for validation: mime + size, null when missing. */ public static function attachmentInfo( int $id ): ?array { if ( $id <= 0 || 'attachment' !== get_post_type( $id ) ) { return null; } $path = get_attached_file( $id ); return array( 'mime' => (string) get_post_mime_type( $id ), 'size' => ( is_string( $path ) && is_file( $path ) ) ? (int) filesize( $path ) : 0, ); } /* ---------------------------------------------------------------- render */ public static function render(): void { Admin::open( 'Alerts' ); $edit = Admin::get_int( 'edit' ); if ( 'new' === Admin::get_str( 'view' ) || $edit ) { self::renderForm( $edit ); } else { self::renderHelp(); self::renderList(); } Admin::close(); } private static function renderHelp(): void { echo '
An alert is the pop-up on your stream when someone donates. Here you can give it a picture, a GIF or a video, and a sound. Pick the donation size (or a reward) that should trigger it.
'; echo '| Name | Plays when | Applies to | Media | Order | Actions |
|---|---|---|---|---|---|
| ' . esc_html( $d['title'] ) . ' | '; echo '' . esc_html( $when ) . ' | '; echo '' . esc_html( 0 === $d['goal_id'] ? 'All goals' : ( $goals[ $d['goal_id'] ] ?? 'Goal #' . $d['goal_id'] ) ) . ' | '; echo '' . esc_html( $media ? implode( ', ', $media ) : 'Text only' ) . ' | '; echo '' . (int) $d['sort'] . ' | '; echo 'Edit '; Admin::form( 'sg_alert_toggle', array( 'alert_id' => $id, 'enabled' => $d['enabled'] ? 0 : 1 ), 'sg-inline' ); echo ' '; Admin::form( 'sg_alert_delete', array( 'alert_id' => $id ), 'sg-inline sg-confirm' ); echo ''; echo ' |
' . esc_html( $help ) . '
That alert no longer exists. Back to alerts
'; return; } $cur = Admin::currency(); $goals = self::goalTitles(); $val = static fn( string $k, $default = '' ) => $d[ $k ] ?? $default; $trigger = (string) $val( 'trigger_type', 'amount' ); $rewards = array(); foreach ( ( new ActionRepository() )->all() as $a ) { if ( $a['enabled'] || (int) $a['id'] === (int) $val( 'action_id', 0 ) ) { $rewards[] = array( 'id' => $a['id'], 'title' => $a['title'], 'enabled' => (bool) $a['enabled'] ); } } $data = array( 'currency' => $cur, 'exp' => Money::exponent( $cur ), 'rewards' => $rewards, 'videoCap' => Media::VIDEO_CAP_MS, 'warnBytes' => Media::WARN_BYTES, 'allowed' => Media::MIMES, ); echo 'Only you see this, for example "Big donation fireworks". | |
| Plays when | ';
echo '';
echo ' At least ' . esc_html( Format::money( self::minMinor(), $cur ) ) . ' (your minimum donation). If several amount alerts match, the one with the highest amount wins. '; echo 'A reward alert beats an amount alert. Only rewards that are turned on can be picked. |
| % | |
| seconds 1 to 60. Videos play to the end instead, for at most 30 seconds. | |
Optional. Use {name}, {amount} and {reward}, for example "{name} just sent {amount}!". Leave empty for the normal text ("Name donated $5.00"). | |
Lower numbers win when two alerts are otherwise equal. Leave empty to put it last. |
This is how the alert will look on stream. Press the button to play it (browsers only allow sound after you click).
'; echo ''; echo ''; echo '