PluginProbe
StreamCast – bring live radio to your site with a sleek player / 2.4.2
StreamCast – bring live radio to your site with a sleek player v2.4.2
2.4.5 2.4.4 trunk 1.0 1.1 2.0.0 2.1.10 2.1.2 2.1.4 2.1.5 2.1.8 2.2.1 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 All 29 releases
streamcast / inc / class-streamcast-main.php

class-streamcast-main.php in StreamCast – bring live radio to your site with a sleek player 2.4.2, at inc/class-streamcast-main.php

139 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace StreamCast;
3
4 if (!defined('ABSPATH')) {
5 exit;
6 }
7
8 class STREAMCAST_Main {
9
10 public function __construct() {
11 // Include the Composer autoloader if it exists
12 if ( file_exists( STREAMCAST_PLUGIN_PATH . 'vendor/autoload.php' ) ) {
13 require_once STREAMCAST_PLUGIN_PATH . 'vendor/autoload.php';
14 }
15
16 // Require remaining procedural files (not classes/namespaces)
17 require_once STREAMCAST_PLUGIN_PATH . 'mimes/enable-mime-type.php';
18 require_once STREAMCAST_PLUGIN_PATH . 'inc/class-streamcast-functions.php'; // Registers global helper streamcast_get_meta()
19
20 if (!class_exists('STREAMCAST_STREAMCAST_CSF')) {
21 require_once STREAMCAST_PLUGIN_PATH . 'vendor/codestar-framework/codestar-framework.php';
22 }
23
24 add_action('streamcast_csf_init', function () {
25 require_once STREAMCAST_PLUGIN_PATH . 'inc/class-streamcast-metabox.php';
26 });
27
28 // Instantiate autoloaded classes
29 new \StreamCast\STREAMCAST_Admin();
30 new \StreamCast\STREAMCAST_Block();
31 new \StreamCast\STREAMCAST_Shortcode();
32 new \StreamCast\AJAX();
33
34 do_action('streamcast_csf_init');
35 add_action('admin_enqueue_scripts', [__CLASS__, 'enqueue_admin_assets']);
36 add_action('admin_menu', [__CLASS__, 'add_help_pages']);
37 add_shortcode('stream', [__CLASS__, 'stream_shortcode']);
38 add_filter('plugin_action_links_' . plugin_basename(STREAMCAST_PLUGIN_FILE), [$this, 'add_action_links']);
39 }
40
41 public static function load_metabox() {
42 if(class_exists('STREAMCAST_STREAMCAST_CSF')) {
43 require_once STREAMCAST_PLUGIN_PATH . 'inc/class-streamcast-metabox.php';
44 }
45 }
46
47
48
49 public static function enqueue_admin_assets($hook) {
50 global $typenow;
51 if ('streamcast' === $typenow) {
52 wp_enqueue_script('streamcast-admin-post-js', STREAMCAST_PLUGIN_DIR . 'build/admin-post.js', [], STREAMCAST_PLUGIN_VERSION, true);
53 wp_enqueue_style('streamcast-admin-post-css', STREAMCAST_PLUGIN_DIR . 'build/admin-post.css', [], STREAMCAST_PLUGIN_VERSION);
54 wp_enqueue_style('streamcast-admin-css', STREAMCAST_PLUGIN_DIR . 'assets/admin.css', [], STREAMCAST_PLUGIN_VERSION);
55 wp_enqueue_script('streamcast-admin-js', STREAMCAST_PLUGIN_DIR . 'assets/admin.js', [], STREAMCAST_PLUGIN_VERSION, true);
56 }
57
58 if ('streamcast_page_streamcast' === $hook) {
59 wp_enqueue_style('streamcast-dashboard-css', STREAMCAST_PLUGIN_DIR . 'build/admin-dashboard.css', [], STREAMCAST_PLUGIN_VERSION);
60
61 $asset_file = include STREAMCAST_PLUGIN_PATH . 'build/admin-dashboard.asset.php';
62 wp_enqueue_script('apb-admin-dashboard', STREAMCAST_PLUGIN_DIR . 'build/admin-dashboard.js', array_merge($asset_file['dependencies'], ['wp-util']), STREAMCAST_PLUGIN_VERSION, true);
63 }
64 }
65
66 public static function add_help_pages()
67 {
68 add_submenu_page(
69 'edit.php?post_type=streamcast',
70 'Demo & Help',
71 'Demo & Help',
72 'manage_options',
73 'streamcast',
74 [__CLASS__, 'render_dashboard']
75 );
76 }
77
78 public static function render_dashboard() {
79 ?>
80 <div id="streamcastAdminDashboardWrapper" data-info='<?php echo esc_attr(wp_json_encode([
81 'version' => STREAMCAST_PLUGIN_VERSION,
82 'isPremium' => false,
83 'hasPro' => false,
84 'licenseActiveNonce' => wp_create_nonce('bPlLicenseActivation')
85 ])); ?>'></div>
86 <?php
87 }
88
89 public static function stream_shortcode($atts) {
90 $atts = shortcode_atts(
91 [
92 'url' => null,
93 'background' => null,
94 ],
95 $atts
96 );
97
98 $url = esc_url($atts['url']);
99 $background = sanitize_hex_color($atts['background']) ?: 'transparent';
100
101 ob_start();
102 ?>
103 <div style="width:200px;">
104 <audio id="player" controls>
105 <source src="<?php echo esc_url($url); ?>" type="audio/mp3" />
106 </audio>
107 </div>
108
109 <style>
110 .plyr__control {
111 margin-right: 0 !important;
112 }
113
114 .plyr--audio .plyr__controls {
115 background:
116 <?php echo esc_attr($background); ?>
117 !important;
118 border-radius: 3px !important;
119 }
120 </style>
121
122 <script>
123 const player = new Plyr('#player', {
124 controls: ['play', 'mute', 'volume']
125 });
126 </script>
127 <?php
128 return ob_get_clean();
129 }
130
131 public function add_action_links($links) {
132 $help_link = '<a href="' . admin_url('edit.php?post_type=streamcast&page=streamcast') . '"><span style="color: #f18500; font-weight: 600;">' . __('Help & Demo\'s', 'streamcast') . '</span></a>';
133 array_unshift($links, $help_link);
134 return $links;
135 }
136
137 }
138
139