| 1 |
<?php |
| 2 |
namespace StreamCast; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 5 |
|
| 6 |
if (!class_exists('STREAMCAST_Block')) { |
| 7 |
class STREAMCAST_Block { |
| 8 |
public function __construct() { |
| 9 |
add_action('init', [__CLASS__, 'onInit']); |
| 10 |
add_action('enqueue_block_assets', [__CLASS__, 'scb_enqueue_block_assets']); |
| 11 |
} |
| 12 |
public static function onInit() { |
| 13 |
register_block_type(STREAMCAST_PLUGIN_PATH . '/build'); |
| 14 |
|
| 15 |
// Register external Muses player script. |
| 16 |
wp_register_script('muses-player', STREAMCAST_PLUGIN_DIR . 'assets/vendor/muses-player/mrp.js', [], '1.0', false); |
| 17 |
} |
| 18 |
|
| 19 |
public static function scb_enqueue_block_assets() { |
| 20 |
wp_enqueue_style('scb-style', STREAMCAST_PLUGIN_DIR . 'public/css/radio.css', array(), STREAMCAST_PLUGIN_VERSION, 'all'); |
| 21 |
wp_enqueue_style('scb-player-style', STREAMCAST_PLUGIN_DIR . 'public/css/styles.css', array(), STREAMCAST_PLUGIN_VERSION, 'all'); |
| 22 |
wp_enqueue_script('scb-script', STREAMCAST_PLUGIN_DIR . 'public/js/streamcast-final.js', array('jquery'), STREAMCAST_PLUGIN_VERSION, true); |
| 23 |
|
| 24 |
// Enqueue Muses player script. |
| 25 |
wp_enqueue_script('muses-player'); |
| 26 |
|
| 27 |
$data = array( |
| 28 |
'iframePath' => STREAMCAST_PLUGIN_DIR . 'iframe.html', |
| 29 |
'ajaxUrl' => admin_url('admin-ajax.php'), |
| 30 |
'plyrSvg' => STREAMCAST_PLUGIN_DIR . 'assets/vendor/plyr/plyr.svg', |
| 31 |
'plyrBlankVideo' => STREAMCAST_PLUGIN_DIR . 'assets/vendor/plyr/blank.mp4', |
| 32 |
'nonce' => wp_create_nonce('streamcast_fetch_nonce'), |
| 33 |
); |
| 34 |
|
| 35 |
// Pass data to JavaScript. |
| 36 |
wp_localize_script('scb-streamcast-block-editor-script', 'streamcastData', $data); |
| 37 |
wp_localize_script('scb-streamcast-block-view-script', 'streamcastData', $data); |
| 38 |
wp_localize_script('scb-script', 'streamcastData', $data); |
| 39 |
} |
| 40 |
|
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
|