*/
class Wpstream_Admin {
/**
* Store plugin main class to allow public access.
*
* @since 20180622
* @var object The main class.
*/
public $main;
/**
* The ID of this plugin.
*
* @since 3.0.1
* @access private
* @var string $plugin_name The ID of this plugin.
*/
private $plugin_name;
/**
* The version of this plugin.
*
* @since 3.0.1
* @access private
* @var string $version The current version of this plugin.
*/
private $version;
/**
* Initialize the class and set its properties.
*
* @since 3.0.1
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
*/
public $global_event_options ;
public function __construct( $plugin_name, $version,$plugin_main ) {
$this->plugin_name = $plugin_name;
$this->version = $version;
$this->main = $plugin_main;
$this->global_event_options = array(
'record' =>array(
'name' => esc_html__('Record Live Stream','wpstream'),
'details' => esc_html__('If enabled, live streams will be recorded and saved to your library.','wpstream'),
'defaults' => 'no',
),
'view_count' =>array(
'name' => esc_html__('Display Viewer Count','wpstream'),
'details' => esc_html__('If enabled, the live viewer count will show up in the player.','wpstream'),
'defaults' => 'yes',
),
'domain_lock'=>array(
'name' => esc_html__('Lock To Website','wpstream'),
'details' => sprintf ( esc_html__('If enabled, live video will only display on %1$s, otherwise it can show up on any website.','wpstream'),get_bloginfo('wpurl') ),
'defaults' => 'no',
),
'autoplay' =>array(
'name' => esc_html__('Autoplay','wpstream'),
'details' => esc_html__('If enabled, live video will attempt to start playing automatically. This is only achievable in some browsers.','wpstream'),
'defaults' => 'yes',
),
'mute' =>array(
'name' => esc_html__('Start Muted','wpstream'),
'details' => esc_html__('If enabled, live video will start muted. This may increase the rate of autoplay in some browsers. ','wpstream'),
'defaults' => 'no',
),
'encrypt' =>array(
'name' => esc_html__('Encrypt Live Stream','wpstream'),
'details' => esc_html__('If enabled, video data will be encrypted. Enabling encryption may lead to reduced website performance under certain configurations. Encrypted video may not display in all browsers.','wpstream'),
'defaults' => 'no',
),
'ses_encrypt'=>array(
'name' => esc_html__('Use Sessions with Encryption','wpstream'),
'details' => esc_html__('If enabled, encryption key distribution will be checked against valid user sessions. Setting may malfunction or lead to reduced website performance under certain configurations. ','wpstream'),
'defaults' => 'no',
),
'autostart' =>array(
'name' => esc_html__('Auto TURN ON','wpstream'),
'details' => esc_html__('If enabled, channel will TURN ON automatically when broadcasting with an External Streaming App (RTMP Encoder/Broadcaster)','wpstream'),
'defaults' => 'no',
),
'vod_domain_lock' =>array(
'name' => esc_html__('Video On Demand - Lock To Website','wpstream'),
'details' => sprintf ( esc_html__('If enabled, VODS will only display on %1$s, otherwise they can show up on any website.','wpstream'),get_bloginfo('wpurl') ),
'defaults' => 'no',
),
'vod_encrypt' =>array(
'name' => esc_html__('Encrypt Video on Demand','wpstream'),
'details' => esc_html__('If enabled, video data will be encrypted. Enabling encryption may lead to reduced website performance under certain configurations. Encrypted video may not display in all browsers.','wpstream'),
'defaults' => 'no',
),
);
}
/**
* Register the stylesheets for the admin area.
*
* @since 3.0.1
*/
public function enqueue_styles() {
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Wpstream_Loader as all of the hooks are defined
* in that particular class.
*
* The Wpstream_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_style( 'wpstream-roboto', "https://fonts.googleapis.com/css?family=Roboto:300,400,500,600,700,900&display=swap&subset=latin-ext" );
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wpstream-admin.css', array(), WPSTREAM_PLUGIN_VERSION, 'all' );
wp_enqueue_style( 'wpstream-on-boarding-css', plugin_dir_url( __FILE__ ) . 'css/wpstream-admin-onboarding.css', array(), rand(1,999999999999), 'all' );
}
/**
* Register the JavaScript for the admin area.
*
* @since 3.0.1
*/
public function enqueue_scripts() {
wp_enqueue_script("jquery-ui-slider");
wp_enqueue_script("jquery-ui-datepicker");
wp_enqueue_script('jquery.fileupload', plugin_dir_url( __FILE__ ) .'js/jquery.fileupload.js?v='.time(),array(), WPSTREAM_PLUGIN_VERSION, true);
wp_enqueue_script('wpstream-admin-control', plugin_dir_url( __FILE__ ) .'js/admin_control.js?v='.time(),array(), WPSTREAM_PLUGIN_VERSION, true);
wp_localize_script('wpstream-admin-control', 'wpstream_admin_control_vars',
array(
'admin_url' => get_admin_url(),
'loading_url' => WPSTREAM_PLUGIN_DIR_URL.'/img/loading.gif',
'download_mess' => esc_html__('Click to download!','wpstream'),
'uploading' => esc_html('We are uploading your file.Do not close this window!','wpstream'),
'upload_complete2' => esc_html('Upload Complete! You can upload another file!','wpstream'),
'not_accepted' => esc_html('The file is not an accepted video format','wpstream'),
'upload_complete' => esc_html('Upload Complete!','wpstream'),
'no_band' => esc_html('Not enough streaming data.','wpsteam'),
'no_band_no_store' => esc_html('Not enough streaming data or storage.','wpsteam')
));
wp_enqueue_script('wpstream-start-streaming_admin', plugin_dir_url( __DIR__ ) .'/public/js/start_streaming.js?v='.time(),array(), WPSTREAM_PLUGIN_VERSION, true);
wp_localize_script('wpstream-start-streaming_admin', 'wpstream_start_streaming_vars',
array(
'admin_url' => get_admin_url(),
'loading_url' => WPSTREAM_PLUGIN_DIR_URL.'/img/loading.gif',
'download_mess' => esc_html__('Click to download!','wpstream'),
'uploading' => esc_html('We are uploading your file.Do not close this window!','wpstream'),
'upload_complete2' => esc_html('Upload Complete! You can upload another file!','wpstream'),
'not_accepted' => esc_html('The file is not an accepted video format','wpstream'),
'upload_complete' => esc_html('Upload Complete!','wpstream'),
'no_band' => esc_html('Not enough streaming data.','wpsteam'),
'no_band_no_store' => esc_html('Not enough streaming data or storage.','wpsteam'),
'start_streaming_action'=> esc_html__('TURNING ON','wpstream'),
'stop_streaming_action' => esc_html__('TURNING OFF','wpstream'),
'start_streaming' => esc_html__('TURN ON','wpstream'),
'stop_streaming' => esc_html__('TURN OFF','wpstream'),
'turned_on_tooltip' => esc_html__('Channel is now OFF. Click to turn ON.','wpstream'),
'turned_off_tooltip' => esc_html__('Click to turn channel off. This will interrupt any ongoing broadcast.','wpstream'),
'turning_on_tooltip' => esc_html__('Turning a channel on may take 1-2 minutes or more. Please be patient.','wpstream'),
'turning_off_tooltip' => esc_html__('This may take a few minutes.','wpstream'),
'error1' => esc_html__('You don\'t have enough data to start a new event!','wpstream'),
'failed_event_creation' => esc_html__('Failed to start the channel. Please try again in a few minutes.','wpstream'),
'channel_turning_on' => esc_html__('Channel is turning on','wpstream'),
'channel_turning_off' => esc_html__('Channel is turning off','wpstream'),
'channel_on' => esc_html__('Channel is ON','wpstream'),
'channel_off' => esc_html__('Channel is OFF','wpstream'),
'turn_off_confirm' => esc_html__('ARE YOU SURE you\'d like to TURN OFF the channel now? '.PHP_EOL.PHP_EOL.'Channels TURN OFF automatically after 1 hour of inactivity (no active broadcast).'.PHP_EOL.PHP_EOL.'Manual TURN OFF is only useful if you require to change the channel settings immediately.'.PHP_EOL.PHP_EOL.'Statistics may be unavailable or incomplete for up to an hour.'.PHP_EOL.PHP_EOL.'If your channel is configured with Auto TURN ON, it will turn back on as soon as there is a broadcast.','wpstream')
));
wp_enqueue_script('wpstream-on-boarding-js', plugin_dir_url( __DIR__ ) .'/admin/js/wpstream-onboarding2.js?v='.time(),array(), WPSTREAM_PLUGIN_VERSION, true);
wp_localize_script('wpstream-on-boarding-js', 'wpstreamonboarding_js_vars',
array(
'admin_url' => get_admin_url(),
'plugin_url' => get_dashboard_url().'/plugins.php',
'upload_url' => get_dashboard_url().'admin.php?page=wpstream_recordings'
));
}
/**
* Add Plugin Administation menu
*
* @since 3.0.1
*/
public function wpstream_manage_admin_menu() {
add_menu_page( __('WpStream','wpestream'), __('WpStream ','wpstream'), 'administrator', 'wpstream_credentials', array($this,'wpstream_set_wpstream_credentials'), WPSTREAM_PLUGIN_DIR_URL.'img/wpstream-icon-menu_2.png',20 );
add_submenu_page( 'wpstream_credentials', __('WpStream Credentials','wpestream'), __('Credentials','wpestream'), 'administrator', 'wpstream_credentials', array($this,'wpstream_set_wpstream_credentials') );
add_submenu_page( 'wpstream_credentials', __('WpStream Live Channels','wpestream'), __('All Channels','wpestream'), 'administrator', 'wpstream_live_channels', array( $this,'wpstream_new_general_set'));
add_submenu_page( 'wpstream_credentials', __('WpStream Recordings','wpestream'), __('Recordings','wpestream'), 'administrator', 'wpstream_recordings', array($this,'wpstream_media_management'));
add_submenu_page( 'wpstream_credentials', __('WpStream Settings','wpestream'), __('Settings','wpestream'), 'administrator', 'wpstream_settings', array($this,'wpstream_settings'));
add_submenu_page( 'wpstream_credentials', __('WpStream Quick Start','wpestream'), __('WpStream Quick Start','wpestream'), 'administrator', 'wpstream_onboard', array($this,'wpstream_pre_onboard_display'));
}
/**
* Shows events wpstream
*
* @since 3.0.1
*/
public function wpstream_new_general_set() {
$no_channel=1;
if(class_exists ('WC_Subscription')){
}
//event_passed
$args = array(
'posts_per_page' => -1,
'post_type' => 'product',
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'event_passed',
'value' => 1,
'compare' => '!=',
)
),
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_type',
'field' => 'slug',
'terms' => array('live_stream','subscription')
)
),
);
$event_list = new WP_Query($args);
global $live_event_for_user;
$live_event_for_user = $this->main->wpstream_live_connection->wpstream_get_live_event_for_user();
$pack_details = $this->main->wpstream_live_connection->wpstream_request_pack_data_per_user();
$this->main->show_user_data($pack_details);
if( $event_list->have_posts()){
print '
';
}
/*
*
* Display Wmix settings
*
*/
public function wpstream_wmix_settings($obs_uri,$obs_stream){
print '
';
print '
';
print '
'.esc_html__('URL:').' ';
print '
' . $obs_uri.'
'.__('copy','wpstream').'
';
print '
'.__('Stream Key:').'
'. $obs_stream.'
'.__('copy','wpstream').'
';
print '
';
print'
';
print '
';
print '
1. Click on the gear icon near the stream button on the bottom.
2. Choose a custom RTMP Server in destination.
3. In the URL box, type/paste your URL.
4. In the Stream key, type/paste your Stream key.
5. Save changes. You can start streaming by clicking on the stream button at the bottom of the dashboard.
';
print '
';
print '
';
}
/*
* Set Settings
*
*
*/
public function wpstream_settings(){
if($_SERVER['REQUEST_METHOD'] === 'POST'){
$allowed_html = array();
$exclude_array = array();
$allowed_html = array();
if( isset($_POST['user_streaming_channel_type_hidden']) && intval($_POST['user_streaming_channel_type_hidden'])==1 && !isset($_POST['stream_role']) ){
update_option( sanitize_key('wpstream_stream_role'), '' );
}
foreach($_POST as $variable=>$value){
if ($variable!='submit'){
if (!in_array($variable, $exclude_array) ){
update_option( sanitize_key('wpstream_'.$variable), sanitize_text_field ($value) );
}
if($variable=='stream_role'){
update_option( sanitize_key('wpstream_stream_role'), $value );
}
}
}
if( isset($_GET['tab']) && $_GET['tab']=='default_options' ){
$event_settings=array();
foreach($this->global_event_options as $key=>$option){
$event_settings[$key]='';
if(isset($_POST['wpstream_event_set_'.$key]) && $_POST['wpstream_event_set_'.$key]=='on'){
$event_settings[$key]=1;
}else{
$event_settings[$key]=0;
}
}
update_option('wpstream_user_streaming_global_channel_options',$event_settings);
}
// reset permalinkgs
global $wp_rewrite;
update_option( "rewrite_rules", FALSE );
$wp_rewrite->flush_rules( true );
}
$wpstream_settings_array =array(
1 => array(
'tab' => 'general_options',
'label' => esc_html__('Slug for free video/channel pages ','wpstream'),
'name' => 'free_media_slug',
'type' => 'text',
'details' => esc_html__('This will replace the default "wpstream" of all your free video/channel urls. Special characters like "&" are not permitted. To have your new slug show up you need to re-save the "Permalinks Settings" under Settings -> Permalinks, even if not making any changes.','wpstream'),
),
2 => array(
'tab' => 'general_options',
'label' => esc_html__('Non-Admin User Roles Allowed to Broadcast','wpstream'),
'name' => 'stream_role',
'type' => 'user_roles',
'details' => esc_html__('These types of users can stream via frontend shortcodes / blocks. Single individual channels are automaticlally created for streaming by non-admins.','wpstream'),
),
3 => array(
'tab' => 'general_options',
'label' => esc_html__('Non Admin Streamers Channel Type.','wpstream'),
'name' => 'user_streaming_channel_type',
'type' => 'select',
'select_values'=>array(
'free' => esc_html__('Free Live Channel','wpstream'),
'paid' => esc_html__('Pay-Per-View','wpstream')
),
'details' => esc_html__('Choose whether the channels assigned to non-admins are free-for-all or pay-per-view (WooCommerce product).','wpstream'),
),
4 => array(
'tab' => 'general_options',
'label' => esc_html__('Default Pay-Per-View Price','wpstream'),
'name' => 'user_streaming_default_price',
'type' => 'text',
'details' => esc_html__('Default price of pay-per-view channels assigned to non-admins.','wpstream'),
),
6 => array(
'tab' => 'subscription_options',
'label' => esc_html__('Use Global Subscription Mode','wpstream'),
'name' => 'global_sub',
'type' => 'slidertoogle',
'details' => esc_html__('If enabled, a client can access all the media products (live and VOD) by purchasing a single subscription. The "WooCommerce Subscriptions" plugin is required.','wpstream'),
),
7 => array(
'tab' => 'subscription_options',
'label' => esc_html__('Subscription ID for Global Subscription Mode','wpstream'),
'name' => 'global_sub_id',
'type' => 'text',
'details' => esc_html__('ID of the subscription product to be purchased for global access to media. All non-subscription video products that are not already attached to a subscription will be accessible to users that have purchased it.','wpstream'),
),
8 => array(
'tab' => 'messages_options',
'label' => esc_html__('PPV not logged in message','wpstream'),
'name' => 'product_not_login',
'type' => 'text',
'details' => esc_html__('This message will be displayed on top of the media player for pay-per-view items when user is not logged in.','wpstream'),
'default' => esc_html__('You must be logged in to watch this video.','wpstream'),
),
9 => array(
'tab' => 'messages_options',
'label' => esc_html__('PPV not purchased message','wpstream'),
'name' => 'product_not_bought',
'type' => 'text',
'details' => esc_html__('This message will be displayed on top of the media player for common pay-per-view items that have not been purchased.','wpstream'),
'default' => esc_html__('You did not yet purchase this item.','wpstream'),
),
10 => array(
'tab' => 'messages_options',
'label' => esc_html__('Subscription not purchased message','wpstream'),
'name' => 'product_not_subscribe',
'type' => 'text',
'details' => esc_html__('This message will be displayed on top of the media player for subscription-type pay-per-view items that have not been purchased.','wpstream'),
'default' => esc_html__(' You did not yet subscribe to this item.','wpstream'),
),
11 => array(
'tab' => 'messages_options',
'label' => esc_html__('Thank you message','wpstream'),
'name' => 'product_thankyou',
'type' => 'text',
'details' => esc_html__('This message will be displayed on the thank you page (after purchase) and the confirmation email.','wpstream'),
'default' => esc_html__('Thanks for your purchase. You can access your item at any time by visiting the following page: {item_link}','wpstream'),
),
12 => array(
'tab' => 'messages_options',
'label' => esc_html__('Thank you message','wpstream'),
'name' => 'subscription_active',
'type' => 'text',
'details' => esc_html__('This message will be displayed on subscription product page.','wpstream'),
'default' => esc_html__('Your Subscription is Active','wpstream'),
),
99 => array(
'tab' => 'default_options',
'label' => esc_html__('Events Options ','wpstream'),
'name' => 'user_streaming_global_channel_options',
'type' => 'user_streaming_global_channel_options',
'details' => esc_html__('Global Options for live events.','wpstream'),
),
);
$active_tab = 'general_options';
if( isset( $_GET[ 'tab' ] ) ) {
$active_tab = $_GET[ 'tab' ];
}
print '
'.__('WpStream Settings','wpstream').'
';
print '
';
}
/**
* Set user roles
*
* @since 3.0.1
*/
public function user_streaming_global_channel_options($name,$value,$local_array=''){
foreach($this->global_event_options as $key=>$option){
if( is_array($local_array) && !in_array($key,$local_array)){
print '
'.__( 'WpStream Pay-Per-View Live Streaming and VOD only works with WooCommerce - Please enable and activate the WooCommerce plugin if you want to monetize your Live Events or Recorded Videos', 'wpstream' ).'
'.__( 'The php CURL library is not enabled on your server. WpStream plugin needs this library in order to work. Please address this issue with your hosting provider.', 'wpstream' ).'
';
}else{
esc_html_e('To Go Live, please publish your channel first !','wpstream');
}
}
/**
*
*
*
*/
public function add_dashboard_page() {
add_dashboard_page( '', '', 'administrator', 'wpstream-onboarding', '' );
}
public function wpstream_load_onboarding_wizard() {
// Check for wizard-specific parameter
// Allow plugins to disable the onboarding wizard
// Check if current user is allowed to save settings.
// Don't load the interface if doing an ajax call.
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
return;
}
set_current_screen();
// Remove an action in the Gutenberg plugin ( not core Gutenberg ) which throws an error.
remove_action( 'admin_print_styles', 'gutenberg_block_editor_admin_print_styles' );
$this->actual_load_onboarding_wizard();
}
/*
* Add on boarding to footer
*/
public function wpstream_admin_footer_onboarding(){
if( isset($_GET['page']) && $_GET['page']==='wpstream_onboard') {
$this->wpstream_onboard_display();
}
}
/*
* On Board Display
*
*/
public function wpstream_pre_onboard_display(){
$pack_details = $this->main->wpstream_live_connection->wpstream_request_pack_data_per_user();
$this->main->show_user_data($pack_details);
$thumb= plugin_dir_url( dirname( __FILE__ ) ). 'img/logo_onboarding.svg';
?>
'.esc_html__('Quick Start','wpstream').'';?>
'.esc_html__('The quick start guide is not working on mobile devices','wpstream').'';
} ?>
'.esc_html__('Choose Recording','wpstream').'
';
}
/*
*
*
*
*/
public function wpstream_obboarding_file_warning(){
print '
'.esc_html__('A recording is needed to create a VOD from. There are no recordings under your account. You can create new recordings by recording a live channel or uploading video files directly.','wpstream').'