PluginProbe
StreamCast – bring live radio to your site with a sleek player / 2.3.4
StreamCast – bring live radio to your site with a sleek player v2.3.4
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.php

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

175 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class StreamCast {
4 public static $_instance = null;
5
6 public static function instance() {
7 if ( is_null( self::$_instance ) ) {
8 self::$_instance = new self();
9 }
10 return self::$_instance;
11 }
12
13 public function __construct() {
14 add_action( 'init', [$this, 'init'], 0 );
15 add_action( 'plugins_loaded', [$this, 'plugins_loaded'] );
16 add_action( 'plugins_loaded', [__CLASS__, 'load_textdomain'] );
17 add_action( 'admin_enqueue_scripts', [__CLASS__, 'enqueue_admin_assets'] );
18 add_action( 'admin_menu', [__CLASS__, 'add_help_pages'] );
19 add_filter( 'admin_footer_text', [__CLASS__, 'admin_footer'] );
20 add_shortcode( 'stream', [__CLASS__, 'stream_shortcode'] );
21 }
22
23 public static function init() {
24 if ( !class_exists( 'CSF' ) ) {
25 require_once STP_PLUGIN_PATH . 'frameworks/codestar-framework/codestar-framework.php';
26 }
27 if ( str_fs()->can_use_premium_code__premium_only() && file_exists( STP_PLUGIN_PATH . 'premium-files/metabox-pro.php' ) ) {
28 require_once STP_PLUGIN_PATH . 'premium-files/metabox-pro.php';
29 }
30 if ( str_fs()->is_free_plan() && file_exists( STP_PLUGIN_PATH . 'inc/metabox-free.php' ) ) {
31 require_once STP_PLUGIN_PATH . 'inc/metabox-free.php';
32 }
33 }
34
35 public function plugins_loaded() {
36 self::load_dependencies();
37 }
38
39 private static function load_dependencies() {
40 require_once STP_PLUGIN_PATH . 'mimes/enable-mime-type.php';
41 require_once STP_PLUGIN_PATH . 'inc/Streamcast_Admin.php';
42 require_once STP_PLUGIN_PATH . 'inc/functions.php';
43 // For All Nessesary Functions
44 require_once STP_PLUGIN_PATH . 'streamcast-block.php';
45 if ( str_fs()->is_free_plan() ) {
46 require_once STP_PLUGIN_PATH . 'public/shortcode-free.php';
47 }
48 if ( str_fs()->can_use_premium_code__premium_only() && !file_exists( STP_PLUGIN_PATH . 'premium-files/shortcode-pro.php' ) ) {
49 require_once STP_PLUGIN_PATH . 'public/shortcode-free.php';
50 }
51 }
52
53 public static function load_textdomain() {
54 load_plugin_textdomain( 'streamcast', false, dirname( __FILE__ ) . "/../languages" );
55 }
56
57 public static function enqueue_admin_assets( $hook ) {
58 global $typenow;
59 if ( 'streamcast' === $typenow ) {
60 wp_enqueue_script(
61 'stp-admin-post-js',
62 STP_PLUGIN_DIR . 'build/admin-post.js',
63 [],
64 STP_PLUGIN_VERSION,
65 true
66 );
67 wp_enqueue_style(
68 'stp-admin-post-css',
69 STP_PLUGIN_DIR . 'build/admin-post.css',
70 [],
71 STP_PLUGIN_VERSION
72 );
73 }
74 if ( 'streamcast_page_streamcast' === $hook ) {
75 wp_enqueue_script(
76 'stp-dashboard-js',
77 STP_PLUGIN_DIR . 'build/admin-dashboard.js',
78 ['react', 'react-dom'],
79 STP_PLUGIN_VERSION,
80 true
81 );
82 wp_enqueue_style(
83 'tlgb-dashboard-css',
84 STP_PLUGIN_DIR . 'build/admin-dashboard.css',
85 [],
86 STP_PLUGIN_VERSION
87 );
88 }
89 }
90
91 public static function add_help_pages() {
92 add_submenu_page(
93 'edit.php?post_type=streamcast',
94 'Demo & Help',
95 'Demo & Help',
96 'manage_options',
97 'streamcast',
98 [__CLASS__, 'render_dashboard']
99 );
100 }
101
102 public static function render_dashboard() {
103 ?>
104 <style>#wpcontent { padding-left: 0 !important; }</style>
105 <div id="stpAdminDashboardWrapper"
106 data-info='<?php
107 echo esc_attr( wp_json_encode( [
108 'version' => STP_PLUGIN_VERSION,
109 'isPremium' => esc_attr( stpIsPremium() ),
110 'adminUrl' => admin_url(),
111 ] ) );
112 ?>'>
113 </div>
114 <?php
115 }
116
117 public static function admin_footer( $text ) {
118 if ( 'streamcast' === get_post_type() ) {
119 $url = 'https://wordpress.org/support/plugin/streamcast/reviews/?filter=5#new-post';
120 return sprintf( __( 'If you like <strong>StreamCast Radio Player</strong> plugin, please leave us a <a href="%s" target="_blank">&#9733;&#9733;&#9733;&#9733;&#9733;</a> rating.', 'streamcast' ), $url );
121 }
122 return $text;
123 }
124
125 public static function stream_shortcode( $atts ) {
126 extract( shortcode_atts( [
127 'url' => null,
128 'background' => null,
129 ], $atts ) );
130 ob_start();
131 ?>
132 <div style="width:200px;">
133 <audio id="player" controls>
134 <source src="<?php
135 echo esc_url( $url );
136 ?>" type="audio/mp3" />
137 </audio>
138 </div>
139
140 <style>
141 .plyr__control {
142 margin-right: 0 !important;
143 }
144
145 .plyr--audio .plyr__controls {
146 <?php
147 echo 'background:' . esc_html( $background ?? 'transparent' ) . '!important; border-radius:3px !important;';
148 ?>
149 }
150 </style>
151
152 <script>
153 const player = new Plyr('#player', {
154 controls: ['play', 'mute', 'volume']
155 });
156 </script>
157 <?php
158 return ob_get_clean();
159 }
160
161 public static function activation_redirect() {
162 add_option( 'stp_do_activation_redirect', true );
163 }
164
165 // public static function do_redirect_to_dashboard() {
166 // if (get_option('stp_do_activation_redirect')) {
167 // delete_option('stp_do_activation_redirect');
168 // if (!is_network_admin() && !isset($_GET['activate-multi'])) {
169 // wp_safe_redirect(admin_url('edit.php?post_type=streamcast&page=streamcast#/dashboard'));
170 // exit;
171 // }
172 // }
173 // }
174 }
175