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