| 1 |
<?php |
| 2 |
namespace StreamCast; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 5 |
|
| 6 |
if (!class_exists('STREAMCAST_Shortcode')) { |
| 7 |
class STREAMCAST_Shortcode { |
| 8 |
public function __construct() { |
| 9 |
add_shortcode('radio_player', [__CLASS__, 'radio_player_callback']); |
| 10 |
} |
| 11 |
|
| 12 |
public static function radio_player_callback($atts) { |
| 13 |
extract( |
| 14 |
shortcode_atts( |
| 15 |
[ |
| 16 |
'id' => null, |
| 17 |
'url' => null, |
| 18 |
'background' => null, |
| 19 |
], |
| 20 |
$atts |
| 21 |
) |
| 22 |
); |
| 23 |
|
| 24 |
$post_type = get_post_type($id); |
| 25 |
if ($id && 'streamcast' !== $post_type) { |
| 26 |
return false; |
| 27 |
} |
| 28 |
|
| 29 |
$player_type = streamcast_get_meta($id, 'opt-radio', 'minimal'); |
| 30 |
|
| 31 |
// 1. Determine dynamic values based on player type and metabox. |
| 32 |
$streamURL = $url ? esc_url($url) : esc_url(streamcast_get_meta($id, 'stream_url', 'https://media-ssl.musicradio.com/HeartLondon')); |
| 33 |
$stationName = esc_html(streamcast_get_meta($id, 'station_name', __('Station Name', 'streamcast'))); |
| 34 |
$welcomeMsg = esc_html(streamcast_get_meta($id, 'welcome_msgs', __('Welcome Message', 'streamcast'))); |
| 35 |
$artWork = ''; // Default from block.json. |
| 36 |
$backgroundColor = $background ? esc_attr($background) : esc_attr(streamcast_get_meta($id, 'background', '#f09f8b')); |
| 37 |
$playerWidth = esc_attr(streamcast_get_meta($id, 'playerWidth', '100%')); |
| 38 |
|
| 39 |
if ('ultimate' === $player_type) { |
| 40 |
$stationName = esc_html(streamcast_get_meta($id, 'radioName', __('Station Name', 'streamcast'))); |
| 41 |
$streamURL = $url ? esc_url($url) : esc_url(streamcast_get_meta($id, 'streamURL', 'http://s5-webradio.antenne.de/antenne?icy=https')); |
| 42 |
$artWork = 'https://templates.bplugins.com/wp-content/uploads/2025/02/streamcast-demo-ultimate-1.png'; |
| 43 |
} elseif (in_array($player_type, ['auroraPlay', 'echoStream', 'wooden'], true)) { |
| 44 |
$stationName = esc_html(streamcast_get_meta($id, 'station_name_echoXauroraXwooden', __('Hello London', 'streamcast'))); |
| 45 |
$welcomeMsg = esc_html(streamcast_get_meta($id, 'welcomeMsg_echoXaurora', '106.2')); |
| 46 |
$streamURL = $url ? esc_url($url) : esc_url(streamcast_get_meta($id, 'stream_url_echoXaurora', 'https://media-ssl.musicradio.com/HeartLondon')); |
| 47 |
if ('auroraPlay' === $player_type) { |
| 48 |
$artWork = 'https://templates.bplugins.com/wp-content/uploads/2026/05/radio.jpg'; |
| 49 |
$playerWidth = esc_attr(streamcast_get_meta($id, 'widthXaurora', '100%')); |
| 50 |
$backgroundColor = $background ? esc_attr($background) : esc_attr(streamcast_get_meta($id, 'bgXaurora', '#000000')); |
| 51 |
} elseif ('wooden' === $player_type) { |
| 52 |
$playerWidth = esc_attr(streamcast_get_meta($id, 'widthXaurora', '100%')); |
| 53 |
$backgroundColor = $background ? esc_attr($background) : esc_attr(streamcast_get_meta($id, 'bgXwooden', '#693328')); |
| 54 |
} else { |
| 55 |
$playerWidth = esc_attr(streamcast_get_meta($id, 'widthXecho', '450px')); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
// 2. Construct the block array with attrs matching block.json structure. |
| 60 |
$block = [ |
| 61 |
'blockName' => 'scb/streamcast-block', |
| 62 |
'attrs' => [ |
| 63 |
'radioPlayer' => [ |
| 64 |
'playerType' => $player_type === 'plyr' ? 'minimal' : $player_type, |
| 65 |
'streamURL' => $streamURL, |
| 66 |
'streamProvider' => esc_attr(streamcast_get_meta($id, 'streamProvider', 'shout-cast')), |
| 67 |
'streamPort' => (int) streamcast_get_meta($id, 'streamPort', 8000), |
| 68 |
'streamMountPoint' => esc_attr(streamcast_get_meta($id, 'streamMountPoint', '')), |
| 69 |
'fetchNameFromUrl' => false, |
| 70 |
'stationName' => $stationName, |
| 71 |
'welcomeMessage' => $welcomeMsg, |
| 72 |
'artWork' => $artWork, |
| 73 |
'autoPlay' => false, |
| 74 |
'showTime' => true, |
| 75 |
'playerPosition' => 'center', |
| 76 |
'skin' => [ |
| 77 |
'name' => esc_attr(streamcast_get_meta($id, 'player_skin', 'mcclean')), |
| 78 |
'width' => 180, |
| 79 |
'height' => 60, |
| 80 |
], |
| 81 |
'initialVolume' => 65, |
| 82 |
], |
| 83 |
'radioStyles' => [ |
| 84 |
'playerWidth' => $playerWidth, |
| 85 |
'ultimate' => [ |
| 86 |
'playerColors' => 'theme', |
| 87 |
'playerTheme' => 'dodgerBlue', |
| 88 |
'playerOverlayColor' => 'rgba(15,17,21,0.5)', |
| 89 |
'thumbnailBorderColor' => 'rgba(255, 255, 255, 0.2)', |
| 90 |
'contentColor' => esc_attr(streamcast_get_meta($id, 'contentColor', '#fff')), |
| 91 |
'buttonHoverColor' => 'orangered', |
| 92 |
'progressActiveColor' => 'orangered', |
| 93 |
'visualizerColor' => 'orangered', |
| 94 |
'playerBackgroundImg' => '', |
| 95 |
'posterImg' => [ |
| 96 |
'url' => 'https://templates.bplugins.com/wp-content/uploads/2025/02/streamcast-demo-ultimate-1.png', |
| 97 |
], |
| 98 |
], |
| 99 |
'echoStream' => [ |
| 100 |
'bgImg' => [ |
| 101 |
'url' => 'https://templates.bplugins.com/wp-content/uploads/2026/05/radio.jpg', |
| 102 |
], |
| 103 |
'blur' => (int) streamcast_get_meta($id, 'blur_effect', 7), |
| 104 |
], |
| 105 |
'backgroundColor' => $backgroundColor, |
| 106 |
'stationName' => [ |
| 107 |
'color' => '#fff', |
| 108 |
'hoverColor' => '', |
| 109 |
'typo' => [ |
| 110 |
'fontSize' => ['desktop' => 18], |
| 111 |
'fontFamily' => 'Default', |
| 112 |
], |
| 113 |
'bgColor' => '#50241b', |
| 114 |
'hoverBgColor' => '', |
| 115 |
], |
| 116 |
'artistFmName' => [ |
| 117 |
'color' => '#fff', |
| 118 |
'typo' => [ |
| 119 |
'fontSize' => ['desktop' => 15], |
| 120 |
'fontFamily' => 'Default', |
| 121 |
], |
| 122 |
], |
| 123 |
'contentColor' => esc_attr(streamcast_get_meta($id, 'contentColorEchoXauroraXwooden', '#fff')), |
| 124 |
'playBtnColor' => 'red', |
| 125 |
'timeStamp' => [ |
| 126 |
'color' => '#fff', |
| 127 |
'hoverColor' => '', |
| 128 |
'typo' => [ |
| 129 |
'fontSize' => ['desktop' => 18], |
| 130 |
'fontFamily' => 'Default', |
| 131 |
], |
| 132 |
'bgColor' => '#50241b', |
| 133 |
'hoverBgColor' => '', |
| 134 |
], |
| 135 |
], |
| 136 |
'css' => wp_strip_all_tags((string) streamcast_get_meta($id, 'custom_css', '/* Your Custom CSS here */')), |
| 137 |
], |
| 138 |
'innerBlocks' => [], |
| 139 |
'innerHTML' => '', |
| 140 |
'innerContent' => [], |
| 141 |
]; |
| 142 |
|
| 143 |
return render_block($block); |
| 144 |
} |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
|