| 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 . 'inc/enable-mime-type.php'; |
| 18 |
require_once STREAMCAST_PLUGIN_PATH . 'inc/class-streamcast-functions.php'; // Registers global helper streamcast_get_meta() |
| 19 |
require_once STREAMCAST_PLUGIN_PATH . 'inc/class-streamcast-sidebox.php'; |
| 20 |
|
| 21 |
if (!class_exists('STREAMCAST_STREAMCAST_CSF')) { |
| 22 |
require_once STREAMCAST_PLUGIN_PATH . 'vendor/codestar-framework/codestar-framework.php'; |
| 23 |
} |
| 24 |
|
| 25 |
add_action('streamcast_csf_init', function () { |
| 26 |
require_once STREAMCAST_PLUGIN_PATH . 'inc/class-streamcast-metabox.php'; |
| 27 |
}); |
| 28 |
|
| 29 |
// Instantiate autoloaded classes |
| 30 |
new \StreamCast\STREAMCAST_Admin(); |
| 31 |
new \StreamCast\STREAMCAST_Block(); |
| 32 |
new \StreamCast\STREAMCAST_Shortcode(); |
| 33 |
new \StreamCast\AJAX(); |
| 34 |
|
| 35 |
$sidebox = new \StreamCast\STREAMCAST_SideBox(); |
| 36 |
$sidebox->register(); |
| 37 |
|
| 38 |
add_action('init', function () { |
| 39 |
do_action('streamcast_csf_init'); |
| 40 |
}, 5); |
| 41 |
add_action('admin_enqueue_scripts', [__CLASS__, 'enqueue_admin_assets']); |
| 42 |
add_action('admin_menu', [__CLASS__, 'add_help_pages']); |
| 43 |
add_shortcode('stream', [__CLASS__, 'stream_shortcode']); |
| 44 |
add_filter('plugin_action_links_' . plugin_basename(STREAMCAST_PLUGIN_FILE), [$this, 'add_action_links']); |
| 45 |
} |
| 46 |
|
| 47 |
public static function load_metabox() { |
| 48 |
if(class_exists('STREAMCAST_STREAMCAST_CSF')) { |
| 49 |
require_once STREAMCAST_PLUGIN_PATH . 'inc/class-streamcast-metabox.php'; |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
public static function enqueue_admin_assets($hook) { |
| 56 |
global $typenow; |
| 57 |
if ('streamcast' === $typenow) { |
| 58 |
wp_enqueue_script('streamcast-admin-post-js', STREAMCAST_PLUGIN_DIR . 'build/admin-post.js', [], STREAMCAST_PLUGIN_VERSION, true); |
| 59 |
wp_enqueue_style('streamcast-admin-post-css', STREAMCAST_PLUGIN_DIR . 'build/admin-post.css', [], STREAMCAST_PLUGIN_VERSION); |
| 60 |
wp_enqueue_style('streamcast-admin-css', STREAMCAST_PLUGIN_DIR . 'assets/admin.css', [], STREAMCAST_PLUGIN_VERSION); |
| 61 |
wp_enqueue_script('streamcast-admin-js', STREAMCAST_PLUGIN_DIR . 'assets/admin.js', ['jquery'], STREAMCAST_PLUGIN_VERSION, true); |
| 62 |
} |
| 63 |
|
| 64 |
if ('streamcast_page_streamcast' === $hook) { |
| 65 |
wp_enqueue_style('streamcast-dashboard-css', STREAMCAST_PLUGIN_DIR . 'build/admin-dashboard.css', [], STREAMCAST_PLUGIN_VERSION); |
| 66 |
|
| 67 |
$asset_file = include STREAMCAST_PLUGIN_PATH . 'build/admin-dashboard.asset.php'; |
| 68 |
wp_enqueue_script('apb-admin-dashboard', STREAMCAST_PLUGIN_DIR . 'build/admin-dashboard.js', array_merge($asset_file['dependencies'], ['wp-util']), STREAMCAST_PLUGIN_VERSION, true); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
public static function add_help_pages() |
| 73 |
{ |
| 74 |
add_submenu_page( |
| 75 |
'edit.php?post_type=streamcast', |
| 76 |
'Demo & Help', |
| 77 |
'Demo & Help', |
| 78 |
'manage_options', |
| 79 |
'streamcast', |
| 80 |
[__CLASS__, 'render_dashboard'] |
| 81 |
); |
| 82 |
} |
| 83 |
|
| 84 |
public static function render_dashboard() { |
| 85 |
?> |
| 86 |
<div id="streamcastAdminDashboardWrapper" data-info='<?php echo esc_attr(wp_json_encode([ |
| 87 |
'version' => STREAMCAST_PLUGIN_VERSION, |
| 88 |
'isPremium' => false, |
| 89 |
'hasPro' => false, |
| 90 |
'adminUrl' => admin_url(), |
| 91 |
'pluginUrl' => STREAMCAST_PLUGIN_DIR, |
| 92 |
'licenseActiveNonce' => wp_create_nonce('bPlLicenseActivation') |
| 93 |
])); ?>'></div> |
| 94 |
<?php |
| 95 |
} |
| 96 |
|
| 97 |
public static function stream_shortcode($atts) { |
| 98 |
$atts = shortcode_atts( |
| 99 |
[ |
| 100 |
'url' => null, |
| 101 |
'background' => null, |
| 102 |
], |
| 103 |
$atts |
| 104 |
); |
| 105 |
|
| 106 |
$url = esc_url($atts['url']); |
| 107 |
$background = sanitize_hex_color($atts['background']) ?: 'transparent'; |
| 108 |
|
| 109 |
ob_start(); |
| 110 |
?> |
| 111 |
<div style="width:200px;"> |
| 112 |
<audio id="player" controls> |
| 113 |
<source src="<?php echo esc_url($url); ?>" type="audio/mp3" /> |
| 114 |
</audio> |
| 115 |
</div> |
| 116 |
|
| 117 |
<style> |
| 118 |
.plyr__control { |
| 119 |
margin-right: 0 !important; |
| 120 |
} |
| 121 |
|
| 122 |
.plyr--audio .plyr__controls { |
| 123 |
background: |
| 124 |
<?php echo esc_attr($background); ?> |
| 125 |
!important; |
| 126 |
border-radius: 3px !important; |
| 127 |
} |
| 128 |
</style> |
| 129 |
|
| 130 |
<script> |
| 131 |
const player = new Plyr('#player', { |
| 132 |
controls: ['play', 'mute', 'volume'] |
| 133 |
}); |
| 134 |
</script> |
| 135 |
<?php |
| 136 |
return ob_get_clean(); |
| 137 |
} |
| 138 |
|
| 139 |
public function add_action_links($links) { |
| 140 |
$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>'; |
| 141 |
array_unshift($links, $help_link); |
| 142 |
return $links; |
| 143 |
} |
| 144 |
|
| 145 |
} |
| 146 |
|
| 147 |
|