*/
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'),home_url() ),
'defaults' => 'yes',
),
'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',
),
);
}
/**
* 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' );
}
/**
* 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')
));
}
/**
* Add Plugin Administation menu
*
* @since 3.0.1
*/
public function wpstream_manage_admin_menu() {
add_menu_page( __('WpStream','wpestream'), __('WpStream ','wpstream'), 'administrator', 'wpstream_plugin_options', array($this,'wpstream_set_wpstream_credentials') );
add_submenu_page( 'wpstream_plugin_options', __('WpStream Credentials','wpestream'), __('Credentials','wpestream'), 'administrator', 'wpstream_plugin_options', array($this,'wpstream_set_wpstream_credentials') );
add_submenu_page( 'wpstream_plugin_options', __('WpStream Channels','wpestream'), __('Channels','wpestream'), 'administrator', 'wpstream_new_general_set', array( $this,'wpstream_new_general_set'));
add_submenu_page( 'wpstream_plugin_options', __('WpStream Media Management','wpestream'), __('Media Management','wpestream'), 'administrator', 'wpstream_media_management', array($this,'wpstream_media_management'));
add_submenu_page( 'wpstream_plugin_options', __('WpStream Settings','wpestream'), __('Settings','wpestream'), 'administrator', 'wpstream_settings', array($this,'wpstream_settings'));
}
/**
* 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 '
'.
sprintf(esc_html__('Use %s on your Windows or Mac computer, or the Larix Broadcaster app on your %s or %s smartphone/tablet. Various other Apps and devices are compatible. See %s for more details.','wpstream'),'OBS Studio',' iOS','Android','this page').'
';
print 'Some Facebook Settings for event '.$the_id;
print '
';
print '
';
print '';
print '';
print '
';
print '
';
print '';
print '';
print '
';
print '
';
}
print '
';
print '
';
}
public function wpstream_show_settings_per_event(){
}
/**
* 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=''){
foreach($this->global_event_options as $key=>$option){
if( $local != $key){
print '
'.esc_html__('You can choose a video from your computer or use the url from external source or use the url of a YouTube Video or use the url from a Vimeo video.','wpstream').'
';
}
/**
* Add new product types to Woocommerce select product type
*
* @since 3.0.1
*/
public function wpstream_add_products( $types ){
$types[ 'live_stream' ] = __( 'Live Channel','wpestream' );
$types[ 'video_on_demand' ] = __( 'Video On Demand','wpestream' );
return $types;
}
/**
* Js action to do when user pick live stream or video on demand
*
* @since 3.0.1
*/
public function wpstream_products_custom_js() {
if ( 'product' != get_post_type() ) :
return;
endif;
?>
get_id();
$term_list = wp_get_post_terms($product_id, 'product_type');
$subscription_model = esc_html( get_option('wpstream_global_sub','')) ;
if($subscription_model==1){ // if we have Neflix mode
if( $term_list[0]->name=='live_stream' || $term_list[0]->name=='video_on_demand' ){
return false;
}
}
return $purchaseable_product_wpblog;
}
/**
* Add custom fields to custom product types
*
* @since 3.0.1
*/
public function wpstream_add_custom_general_fields() {
global $woocommerce, $post;
if(function_exists('wcs_user_has_subscription')){
echo '
';
woocommerce_wp_select(
array(
'id' => '_subscript_live_event',
'label' => __( 'Is a subscription based live channel ?', 'woocommerce' ),
'options' => array("yes"=>"yes","no"=>"no")
)
);
echo '
'.__( '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' ).'
'.esc_html__('New! We just released WpStream WordPress Theme - a turn key solution for video delivery & live streaming. This theme is built around WpStream plugin and is the perfect solution for video streaming or rentals platform. ','wpstream').''.esc_html__('Download Theme','wpstream').'
//
';
// }
//
$ajax_nonce = wp_create_nonce( "wpstream_notice_nonce" );
print '';
}
/**
* Admin notices
*
* @since 3.0.1
*/
public function wpstream_update_cache_notice(){
//check_ajax_referer( 'wpstream_notice_nonce', 'security' );
$notice_type = esc_html($_POST['notice_type']);
$notices = get_option('wp_stream_notices');
if(! is_array($notices) ){
$notices=array();
}
$notices[$notice_type]='yes';
update_option('wpstream_notices',$notices);
die();
}
/**
* Activate metaboxes for Streaming controls on sidebar
*
* @since 3.0.1
*/
public function wpstream_startstreaming_sidebar_meta() {
global $post;
$term_list = wp_get_post_terms($post->ID, 'product_type');
if( get_post_meta($post->ID, 'wpstream_product_type', true)==1 ){
add_meta_box('wpstream-sidebar-meta', esc_html__('Live Streaming', 'wpstream'), array($this,'wpstream_start_stream_meta'), 'wpstream_product', 'side', 'high');
}
$is_subscription_live_event = esc_html(get_post_meta($post->ID,'_subscript_live_event',true));
if(!is_wp_error( $term_list )){
if( isset($term_list[0]->name) ){
if( $term_list[0]->name=='live_stream' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){
add_meta_box('wpstream-sidebar-meta', esc_html__('Live Streaming', 'wpstream'), array($this,'wpstream_start_stream_meta'), 'product', 'side', 'high');
}
}
}
}
/**
* edited 4.0
*
* Show Streaming controls on sidebar
*
* @since 3.0.1
*/
public function wpstream_start_stream_meta(){
global $live_event_for_user;
$live_event_for_user = $this->main->wpstream_live_connection->wpstream_get_live_event_for_user();
// was - i think for front tend
// $live_event_for_user = $this->main->wpstream_live_connection->api20_wpstream_request_live_stream_for_user();
global $post;
$ajax_nonce = wp_create_nonce( "wpstream_start_event_nonce" );
print '';
$this->wpstream_live_stream_unit($post->ID);
}
}