| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* To change this license header, choose License Headers in Project Properties. |
| 5 |
* To change this template file, choose Tools | Templates |
| 6 |
* and open the template in the editor. |
| 7 |
*/ |
| 8 |
|
| 9 |
|
| 10 |
/** |
| 11 |
* Description of class-wpstream-player |
| 12 |
* |
| 13 |
* @author cretu |
| 14 |
*/ |
| 15 |
class Wpstream_Player{ |
| 16 |
public function __construct($plugin_main) { |
| 17 |
$this->main = $plugin_main; |
| 18 |
|
| 19 |
add_filter( 'the_content',array($this, 'wpstream_filter_the_title') ); |
| 20 |
add_action( 'woocommerce_before_single_product', array($this,'wpstream_user_logged_in_product_already_bought') ); |
| 21 |
|
| 22 |
add_action( 'wp_ajax_wpstream_player_check_status', array($this,'wpstream_player_check_status') ); |
| 23 |
add_action('wp_ajax_nopriv_wpstream_player_check_status', array($this,'wpstream_player_check_status')); |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
/** |
| 37 |
* |
| 38 |
* edited 4.0 |
| 39 |
* |
| 40 |
* check player status |
| 41 |
* |
| 42 |
* @author cretu |
| 43 |
*/ |
| 44 |
|
| 45 |
public function wpstream_player_check_status(){ |
| 46 |
$channel_id = intval($_POST['channel_id']); |
| 47 |
|
| 48 |
|
| 49 |
$transient_name = 'event_data_to_return_'. $channel_id; |
| 50 |
$event_data_for_transient = get_transient( $transient_name ); |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
if ( false === $event_data_for_transient || $event_data_for_transient=='' ) { //ws || $hls_to_return=='' |
| 55 |
$notes = 'wpstream_player_check_status_note_from_js'; |
| 56 |
$event_status = $this->main->wpstream_live_connection-> wpstream_check_event_status_api_call($channel_id,$notes); |
| 57 |
$event_data_for_transient = $event_status; |
| 58 |
|
| 59 |
set_transient($transient_name,$event_data_for_transient,45); |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
if( isset($event_data_for_transient['hls_playback_url']) && $event_data_for_transient['hls_playback_url']!=''){ |
| 64 |
echo json_encode( array( |
| 65 |
|
| 66 |
'started' => 'yes', |
| 67 |
'channel_id' => $channel_id, |
| 68 |
'event_uri' => $event_data_for_transient['hls_playback_url'], |
| 69 |
'live_conect_views' => $event_data_for_transient['stats_url'], |
| 70 |
'chat_url' => $event_data_for_transient['chat_url'], |
| 71 |
'$event_data_for_transient'=>$event_data_for_transient |
| 72 |
|
| 73 |
|
| 74 |
)); |
| 75 |
update_post_meta($channel_id,'stream_name',$event_data_for_transient['stream_name']); |
| 76 |
update_post_meta($channel_id,'hls_key_retrieval_url',$event_data_for_transient['hls_key_retrieval_url']); |
| 77 |
delete_transient( 'free_event_streamName_'.$event_data_for_transient['stream_name']); |
| 78 |
|
| 79 |
}else{ |
| 80 |
echo json_encode( array( |
| 81 |
'started' => 'no', |
| 82 |
'server_id' => '', |
| 83 |
'channel_id' => $channel_id, |
| 84 |
'event_uri' => '', |
| 85 |
'live_conect_views' => '', |
| 86 |
'chat_url' => '', |
| 87 |
|
| 88 |
)); |
| 89 |
|
| 90 |
} |
| 91 |
|
| 92 |
die(); |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
/** |
| 98 |
* Insert player in page |
| 99 |
* |
| 100 |
* @author cretu |
| 101 |
*/ |
| 102 |
public function wpstream_filter_the_title( $content ) { |
| 103 |
if(function_exists('remove_wpstream_filter')){ |
| 104 |
return $content; |
| 105 |
} |
| 106 |
|
| 107 |
if( is_singular('wpstream_product') || is_singular('wpstream_product_vod') ){ |
| 108 |
global $post; |
| 109 |
$args=array('id'=>$post->ID); |
| 110 |
$custom_content = $this->wpstream_insert_player_inpage($args); |
| 111 |
$content = '<div class="wpestream_inserted_player">'.$custom_content.'</div>'.$content; |
| 112 |
return $content; |
| 113 |
}else{ |
| 114 |
return $content; |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* Insert player in page |
| 120 |
* |
| 121 |
* @author cretu |
| 122 |
*/ |
| 123 |
|
| 124 |
public function wpstream_insert_player_inpage($attributes, $content = null){ |
| 125 |
$product_id = ''; |
| 126 |
$return_string = ''; |
| 127 |
$attributes = shortcode_atts( |
| 128 |
array( |
| 129 |
'id' => 0, |
| 130 |
), $attributes) ; |
| 131 |
|
| 132 |
|
| 133 |
if ( isset($attributes['id']) ){ |
| 134 |
$product_id=$attributes['id']; |
| 135 |
} |
| 136 |
|
| 137 |
if(intval($product_id)==0){ |
| 138 |
$product_id= $this->wpstream_player_retrive_first_id(); |
| 139 |
} |
| 140 |
|
| 141 |
ob_start(); |
| 142 |
|
| 143 |
$this->wpstream_video_player_shortcode($product_id); |
| 144 |
$return_string= ob_get_contents(); |
| 145 |
ob_end_clean(); |
| 146 |
|
| 147 |
return $return_string; |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
/** |
| 154 |
* Video Player shortcode |
| 155 |
* |
| 156 |
* @author cretu |
| 157 |
*/ |
| 158 |
|
| 159 |
public function wpstream_video_player_shortcode($from_sh_id='') { |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
if ( is_user_logged_in() ) { |
| 164 |
global $product; |
| 165 |
$current_user = wp_get_current_user(); |
| 166 |
$product_id = intval($from_sh_id); |
| 167 |
$term_list = wp_get_post_terms($product_id, 'product_type'); |
| 168 |
$possible_bundle = get_post_meta($product_id, 'wpstream_part_of_bundle', true); |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
if ( |
| 174 |
|
| 175 |
( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) && wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product_id) ) || |
| 176 |
( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) && (intval($possible_bundle)!=0) && wc_customer_bought_product( $current_user->user_email, $current_user->ID, $possible_bundle) ) || |
| 177 |
get_post_type($product_id)=='wpstream_product' || |
| 178 |
get_post_type($product_id)=='wpstream_product_vod' ){ |
| 179 |
global $product; |
| 180 |
echo '<div class="wpstream_player_wrapper wpstream_player_shortcode"><div class="wpstream_player_container">'; |
| 181 |
|
| 182 |
|
| 183 |
if( get_post_type($product_id) == 'wpstream_product' ){ |
| 184 |
$this->wpstream_live_event_player($product_id); |
| 185 |
}else if( get_post_type($product_id) == 'wpstream_product_vod' ){ |
| 186 |
$this->wpstream_video_on_demand_player($product_id); |
| 187 |
}else{ |
| 188 |
|
| 189 |
$is_subscription_live_event = esc_html(get_post_meta($product_id,'_subscript_live_event',true)); |
| 190 |
|
| 191 |
if( $term_list[0]->name=='live_stream' || ( $term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){ |
| 192 |
$this->wpstream_live_event_player($product_id); |
| 193 |
}else if( $term_list[0]->name=='video_on_demand' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='no' ) ){ |
| 194 |
$this->wpstream_video_on_demand_player($product_id); |
| 195 |
} |
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
echo '</div></div>'; |
| 200 |
}else{ |
| 201 |
|
| 202 |
if( get_post_type($product_id) == 'product' ){ |
| 203 |
echo '<div class="wpstream_player_wrapper wpstream_player_shortcode no_buy"><div class="wpstream_player_container">'; |
| 204 |
$message =esc_html( get_option('wpstream_product_not_bought','You did not yet purchase this item.')) ; |
| 205 |
echo '<div class="wpstream_notice" style="background:#e16767;">'.esc_html($message).'</div>'; |
| 206 |
echo '</div></div>'; |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
|
| 211 |
}else{ |
| 212 |
|
| 213 |
$product_id = intval($from_sh_id); |
| 214 |
$term_list = wp_get_post_terms($product_id, 'product_type'); |
| 215 |
|
| 216 |
if( get_post_type($product_id) == 'product' && ($term_list[0]->name=='live_stream' || $term_list[0]->name=='video_on_demand') ){ |
| 217 |
|
| 218 |
echo '<div class="wpstream_player_wrapper wpstream_player_shortcode no_buy"><div class="wpstream_player_container">'; |
| 219 |
$message= esc_html( get_option('wpstream_product_not_login','You must be logged in to watch this video.')) ; |
| 220 |
|
| 221 |
|
| 222 |
echo '<div class="wpstream_notice" style="background:#e16767;">'.esc_html($message).'</div>'; |
| 223 |
echo '</div></div>'; |
| 224 |
}elseif( get_post_type($product_id) == 'wpstream_product' ){ |
| 225 |
$this->wpstream_live_event_player($product_id); |
| 226 |
} else if( get_post_type($product_id) == 'wpstream_product_vod' ){ |
| 227 |
$this->wpstream_video_on_demand_player($product_id); |
| 228 |
} |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
/** |
| 235 |
* Video Player shortcode - low latency |
| 236 |
* |
| 237 |
* @author cretu |
| 238 |
*/ |
| 239 |
|
| 240 |
public function wpstream_video_player_shortcode_low_latency($from_sh_id='') { |
| 241 |
|
| 242 |
if ( is_user_logged_in() ) { |
| 243 |
global $product; |
| 244 |
$current_user = wp_get_current_user(); |
| 245 |
$product_id = intval($from_sh_id); |
| 246 |
|
| 247 |
|
| 248 |
if ( ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) && wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product_id) ) || get_post_type($product_id)=='wpstream_product' ){ |
| 249 |
global $product; |
| 250 |
echo '<div class="wpstream_player_wrapper wpstream_player_shortcode"><div class="wpstream_player_container">'; |
| 251 |
|
| 252 |
|
| 253 |
if( get_post_type($product_id) == 'wpstream_product' ){ |
| 254 |
$this->wpstream_live_event_player_low_latency($product_id); |
| 255 |
}else{ |
| 256 |
$term_list = wp_get_post_terms($product_id, 'product_type'); |
| 257 |
$is_subscription_live_event = esc_html(get_post_meta($product_id,'_subscript_live_event',true)); |
| 258 |
|
| 259 |
if( $term_list[0]->name=='live_stream' || ( $term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){ |
| 260 |
$this->wpstream_live_event_player_low_latency($product_id); |
| 261 |
} |
| 262 |
} |
| 263 |
|
| 264 |
|
| 265 |
echo '</div></div>'; |
| 266 |
}else{ |
| 267 |
|
| 268 |
if( get_post_type($product_id) == 'product' ){ |
| 269 |
echo '<div class="wpstream_player_wrapper wpstream_player_shortcode no_buy"><div class="wpstream_player_container">'; |
| 270 |
|
| 271 |
$message =esc_html( get_option('wpstream_product_not_bought','You did not yet purchase this item.')) ; |
| 272 |
echo '<div class="wpstream_notice" style="background:#e16767;">'.$message.'</div>'; |
| 273 |
echo '</div></div>'; |
| 274 |
} |
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
}else{ |
| 279 |
$product_id = intval($from_sh_id); |
| 280 |
if( get_post_type($product_id) == 'wpstream_product' ){ |
| 281 |
$this->wpstream_live_event_player_low_latency($product_id); |
| 282 |
} |
| 283 |
} |
| 284 |
} |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
/** |
| 291 |
* Live Event Player |
| 292 |
* |
| 293 |
* @author cretu |
| 294 |
*/ |
| 295 |
function remove_http($url) { |
| 296 |
$disallowed = array('http://', 'https://'); |
| 297 |
foreach($disallowed as $d) { |
| 298 |
if(strpos($url, $d) === 0) { |
| 299 |
return str_replace($d, '', $url); |
| 300 |
} |
| 301 |
} |
| 302 |
return $url; |
| 303 |
} |
| 304 |
|
| 305 |
/** |
| 306 |
* Get event settings |
| 307 |
* |
| 308 |
* @author cretu |
| 309 |
*/ |
| 310 |
|
| 311 |
function wpestream_return_event_settings($product_id){ |
| 312 |
|
| 313 |
$local_event_options = get_post_meta($product_id,'local_event_options',true); |
| 314 |
if(!is_array($local_event_options)){ |
| 315 |
$local_event_options = get_option('wpstream_user_streaming_global_channel_options') ; |
| 316 |
} |
| 317 |
|
| 318 |
return $local_event_options; |
| 319 |
} |
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
/** |
| 324 |
* edited in 4.0 |
| 325 |
* |
| 326 |
* Live Event Player |
| 327 |
* |
| 328 |
* @author cretu |
| 329 |
*/ |
| 330 |
|
| 331 |
function wpstream_live_event_player($channel_id,$poster_show='',$use_chat=''){ |
| 332 |
|
| 333 |
$now = time().rand(0,1000000); |
| 334 |
$thumb_id = get_post_thumbnail_id($channel_id); |
| 335 |
$thumb = wp_get_attachment_image_src($thumb_id,'small'); |
| 336 |
$usernamestream = esc_html ( get_option('wpstream_api_username','') ); |
| 337 |
$autoplay = true; |
| 338 |
|
| 339 |
$event_settings = $this->wpestream_return_event_settings($channel_id); |
| 340 |
$notes = 'wpstream_live_event_player_note'; |
| 341 |
$event_status = $this->main->wpstream_live_connection-> wpstream_check_event_status_api_call($channel_id,$notes); |
| 342 |
$hls_playback_url = ''; |
| 343 |
$live_conect_views = ''; |
| 344 |
|
| 345 |
if(isset($event_status['status']) && $event_status['status']=='active'){ |
| 346 |
//live event |
| 347 |
if(isset($event_status['hls_playback_url'])){ |
| 348 |
$hls_playback_url = $event_status['hls_playback_url']; |
| 349 |
|
| 350 |
update_post_meta($channel_id,'stream_name',$event_status['stream_name']); |
| 351 |
update_post_meta($channel_id,'hls_key_retrieval_url',$event_status['hls_key_retrieval_url']); |
| 352 |
delete_transient( 'free_event_streamName_'.$event_status['stream_name']); |
| 353 |
|
| 354 |
$live_conect_array = explode('live.streamer.wpstream.net',$hls_playback_url); |
| 355 |
$live_conect_views = $live_conect_array[0].'live.streamer.wpstream.net'; |
| 356 |
$live_conect_views = $this->remove_http($live_conect_views); |
| 357 |
|
| 358 |
} |
| 359 |
if(isset($event_status['chat_url'])){ |
| 360 |
$chat_url = $event_status['chat_url']; |
| 361 |
} |
| 362 |
|
| 363 |
}else{ |
| 364 |
// event not live |
| 365 |
} |
| 366 |
|
| 367 |
if(isset($event_settings['autoplay']) && intval($event_settings['autoplay'])==0){ |
| 368 |
$autoplay=false; |
| 369 |
} |
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
echo '<div class="wpstream_live_player_wrapper function_wpstream_live_event_player" data-now="'.$now.'" data-me="'.esc_attr($usernamestream).'" data-product-id="'.$channel_id.'" id="wpstream_live_player_wrapper'.$now.'" > '; |
| 374 |
|
| 375 |
if( ( isset($event_settings['view_count'] ) && intval($event_settings['view_count'])==1 ) || !isset($event_settings['view_count']) ){ |
| 376 |
echo '<div id="wpestream_live_counting" class="wpestream_live_counting"></div>'; |
| 377 |
} |
| 378 |
|
| 379 |
$show_wpstream_not_live_mess=' style="display:none;" '; |
| 380 |
if(trim($hls_playback_url) ==''){ |
| 381 |
|
| 382 |
$show_wpstream_not_live_mess=''; |
| 383 |
} |
| 384 |
|
| 385 |
$message_show= esc_html( get_option('wpstream_you_are_not_live','We are not live at this moment')) ; |
| 386 |
print '<div class="wpstream_not_live_mess" '.$show_wpstream_not_live_mess.'><div class="wpstream_not_live_mess_back"></div><div class="wpstream_not_live_mess_mess">'.esc_html($message_show).'</div></div>'; |
| 387 |
|
| 388 |
$poster_data=''; |
| 389 |
if(isset($thumb[0])){ |
| 390 |
$poster_data=' poster="'.$thumb[0].'" '; |
| 391 |
} |
| 392 |
if($poster_show=='no'){ |
| 393 |
$poster_data=''; |
| 394 |
} |
| 395 |
|
| 396 |
$is_muted=false; |
| 397 |
if( isset($event_settings['mute']) && intval($event_settings['mute'])==1){ |
| 398 |
$is_muted=true; |
| 399 |
} |
| 400 |
// override $is_muted and $autoplay here - for testing |
| 401 |
// $autoplay = true; |
| 402 |
// $is_muted = false; |
| 403 |
|
| 404 |
$autoplay_str = $autoplay ? 'autoplay' : ''; |
| 405 |
$is_muted_str = $is_muted ? 'muted' : ''; |
| 406 |
|
| 407 |
// TODO (crerem) - setup trailer url here based on meta etc |
| 408 |
// override trailer url here - for testing |
| 409 |
$video_trailer = ''; |
| 410 |
// $video_trailer = '/wp-content/uploads/2023/10/production-ID_4608975.mp4'; |
| 411 |
// $video_trailer = '/wp-content/uploads/2023/10/ultrawide.mp4'; |
| 412 |
|
| 413 |
if ($video_trailer){ |
| 414 |
print '<div id="wpstream_live_video_play_trailer_btn_' . $now . '" style="display: none;" class="dummy">'.esc_html('Play Teaser').'</div>'; |
| 415 |
} |
| 416 |
echo' |
| 417 |
<video id="wpstream-video'.$now.'" '.$poster_data.' class="video-js vjs-default-skin vjs-fluid vjs-wpstream" playsinline="true" '.$is_muted_str." ".$autoplay_str.'> |
| 418 |
|
| 419 |
</video>'; |
| 420 |
|
| 421 |
print '<script type="text/javascript"> |
| 422 |
//<![CDATA[ |
| 423 |
jQuery(document).ready(function(){ |
| 424 |
wpstream_player_initialize({ |
| 425 |
videoElementId: "'.$now.'", |
| 426 |
trailerUrl: "'.$video_trailer.'", |
| 427 |
contentUrl: "'.$hls_playback_url.'", |
| 428 |
statsUri: "'.$live_conect_views.'", |
| 429 |
autoplay: '.var_export($autoplay, true).', |
| 430 |
muted: '.var_export($is_muted, true).', |
| 431 |
playTrailerButtonElementId: "wpstream_live_video_play_trailer_btn_'.$now.'", |
| 432 |
}); |
| 433 |
}); |
| 434 |
//]]> |
| 435 |
</script>'; |
| 436 |
print '</div>'; |
| 437 |
|
| 438 |
|
| 439 |
if(trim($hls_playback_url) ==''){ |
| 440 |
// $show_wpstream_not_live_mess=''; |
| 441 |
}else{ |
| 442 |
print '<script type="text/javascript"> |
| 443 |
//<![CDATA[ |
| 444 |
jQuery(document).ready(function(){ |
| 445 |
var player_wrapper = jQuery(".wpstream_live_player_wrapper"); |
| 446 |
wpstream_read_websocket_info("'.$channel_id.'","wpstream_live_player_wrapper'.$now.'", player_wrapper ,"'.$chat_url.'", "'.$hls_playback_url.'"); |
| 447 |
}); |
| 448 |
//]]> |
| 449 |
</script>'; |
| 450 |
} |
| 451 |
|
| 452 |
|
| 453 |
if($use_chat=="yes"){ |
| 454 |
$this->wpstream_connect_to_chat($channel_id); |
| 455 |
} |
| 456 |
|
| 457 |
usleep (10000); |
| 458 |
|
| 459 |
} |
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
/** |
| 464 |
* |
| 465 |
* Edited in 4.0 |
| 466 |
* |
| 467 |
* |
| 468 |
* Live Event Player |
| 469 |
* |
| 470 |
* @author cretu |
| 471 |
*/ |
| 472 |
|
| 473 |
function wpstream_live_event_player_low_latency($channel_id,$poster_show='',$use_chat=''){ |
| 474 |
$usernamestream = esc_html ( get_option('wpstream_api_username','') ); |
| 475 |
$thumb_id = get_post_thumbnail_id($channel_id); |
| 476 |
$thumb = wp_get_attachment_image_src($thumb_id,'small'); |
| 477 |
|
| 478 |
$event_settings = $this->wpestream_return_event_settings($channel_id); |
| 479 |
$notes = 'wpstream_live_event_player_low_latency_note'; |
| 480 |
$event_status = $this->main->wpstream_live_connection-> wpstream_check_event_status_api_call($channel_id,$notes); |
| 481 |
$hls_playback_url = ''; |
| 482 |
$live_conect_views = ''; |
| 483 |
$now = time().rand(0,10); |
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
if(isset($event_status['status']) && $event_status['status']=='active'){ |
| 488 |
//live event |
| 489 |
if(isset($event_status['sldp_playback_url'])){ |
| 490 |
$hls_playback_url = $event_status['sldp_playback_url']; |
| 491 |
|
| 492 |
$live_conect_array = explode('live.streamer.wpstream.net',$hls_playback_url); |
| 493 |
$live_conect_views = $live_conect_array[0].'live.streamer.wpstream.net'; |
| 494 |
$live_conect_views = $this->remove_http($live_conect_views); |
| 495 |
|
| 496 |
} |
| 497 |
if(isset($event_status['chat_url'])){ |
| 498 |
$chat_url =$event_status['chat_url']; |
| 499 |
} |
| 500 |
|
| 501 |
}else{ |
| 502 |
// event not live |
| 503 |
} |
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
echo '<div class="wpstream_live_player_wrapper function_wpstream_live_event_player_low_latency wpstream_low_latency" data-now="'.$now.'" data-me="'.esc_attr($usernamestream).'" data-product-id="'.$channel_id.'" id="wpstream_live_player_wrapper'.$now.'" > '; |
| 509 |
|
| 510 |
|
| 511 |
if( ( isset($event_settings['view_count'] ) && intval($event_settings['view_count'])==1 ) || !isset($event_settings['view_count']) ){ |
| 512 |
echo '<div id="wpestream_live_counting" class="wpestream_live_counting"></div>'; |
| 513 |
} |
| 514 |
|
| 515 |
$show_wpstream_not_live_mess=' style="display:none;" '; |
| 516 |
if(trim($hls_playback_url) ==''){ |
| 517 |
$show_wpstream_not_live_mess=''; |
| 518 |
} |
| 519 |
|
| 520 |
$message_show= esc_html( get_option('wpstream_you_are_not_live','We are not live at this moment')) ; |
| 521 |
print '<div class="wpstream_not_live_mess " '.$show_wpstream_not_live_mess.' ><div class="wpstream_not_live_mess_back"></div><div class="wpstream_not_live_mess_mess">'. $message_show.'</div></div>'; |
| 522 |
|
| 523 |
|
| 524 |
$poster_data=' poster="'.$thumb[0].'" '; |
| 525 |
if($poster_show=='no'){ |
| 526 |
$poster_data=''; |
| 527 |
} |
| 528 |
|
| 529 |
|
| 530 |
$is_muted=''; |
| 531 |
if( isset($event_settings['mute']) && intval($event_settings['mute'])==1){ |
| 532 |
$is_muted=' muted '; |
| 533 |
} |
| 534 |
|
| 535 |
|
| 536 |
$autoplay='autoplay'; |
| 537 |
if(isset($event_settings['autoplay']) && intval($event_settings['autoplay'])==0){ |
| 538 |
$autoplay=''; |
| 539 |
} |
| 540 |
|
| 541 |
echo' |
| 542 |
<div iccd="player" id="wpstream-video'.$now.'" '.$poster_data.' '.$is_muted.' class="" > |
| 543 |
</div>'; |
| 544 |
|
| 545 |
print '<script type="text/javascript"> |
| 546 |
//<![CDATA[ |
| 547 |
jQuery(document).ready(function(){ |
| 548 |
var low_latencyid="wpstream-video'.$now.'"; |
| 549 |
document.addEventListener("DOMContentLoaded", initPlayer(low_latencyid, "'.$hls_playback_url.'","'.$is_muted.'","'.$autoplay.'" ) ); '; |
| 550 |
print'}); |
| 551 |
//]]> |
| 552 |
</script>'; |
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
if(trim($hls_playback_url) ==''){ |
| 557 |
// $show_wpstream_not_live_mess=''; |
| 558 |
}else{ |
| 559 |
print '<script type="text/javascript"> |
| 560 |
//<![CDATA[ |
| 561 |
jQuery(document).ready(function(){ |
| 562 |
var player_wrapper = jQuery(".wpstream_live_player_wrapper"); |
| 563 |
wpstream_read_websocket_info("'.$channel_id.'","wpstream_live_player_wrapper'.$now.'", player_wrapper ,"'.$chat_url.'", "'.$hls_playback_url.'"); |
| 564 |
}); |
| 565 |
//]]> |
| 566 |
</script>'; |
| 567 |
} |
| 568 |
|
| 569 |
|
| 570 |
if($use_chat=="yes"){ |
| 571 |
$this->wpstream_connect_to_chat($channel_id); |
| 572 |
} |
| 573 |
|
| 574 |
usleep (10000); |
| 575 |
|
| 576 |
} |
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
/* |
| 583 |
* |
| 584 |
* Request HLS player |
| 585 |
* |
| 586 |
* |
| 587 |
* |
| 588 |
*/ |
| 589 |
public function wpstream_request_video_on_demand_hls_player($video_name,$product_id){ |
| 590 |
if($video_name==''){ |
| 591 |
return ''; |
| 592 |
} |
| 593 |
|
| 594 |
$transient_name = 'wpstream_video_on_demand_'.$video_name; |
| 595 |
$hls_to_return = get_transient( $transient_name ); |
| 596 |
$hls_to_return = false; |
| 597 |
|
| 598 |
|
| 599 |
if($hls_to_return==false){ |
| 600 |
|
| 601 |
$access_token = $this->main->wpstream_live_connection->wpstream_get_token(); |
| 602 |
$url = 'video/info'; |
| 603 |
|
| 604 |
//corsorigin de check |
| 605 |
$local_event_options = get_option('wpstream_user_streaming_global_channel_options') ; |
| 606 |
$domain = parse_url ( get_site_url() ); |
| 607 |
$domain_scheme = 'http'; |
| 608 |
if(is_ssl()){ |
| 609 |
$domain_scheme='https'; |
| 610 |
} |
| 611 |
|
| 612 |
$corsorigin=''; |
| 613 |
if( isset($local_event_options['vod_domain_lock']) ){ |
| 614 |
if (intval( $local_event_options['vod_domain_lock']) ==0 ){ |
| 615 |
$corsorigin='*'; |
| 616 |
} |
| 617 |
}else{ |
| 618 |
$corsorigin='*'; |
| 619 |
} |
| 620 |
|
| 621 |
if($corsorigin!='*'){ |
| 622 |
$corsorigin=$domain_scheme.'://'.$domain['host']; |
| 623 |
} |
| 624 |
|
| 625 |
$is_encrypt="false"; |
| 626 |
if( isset($local_event_options['vod_encrypt']) && intval( $local_event_options['vod_encrypt']) ==1 ){ |
| 627 |
$is_encrypt="true"; |
| 628 |
} |
| 629 |
|
| 630 |
$hlsKeysUrlPrefix = get_site_url().'?wpstream_voddrm='; |
| 631 |
$encrypt = $is_encrypt; |
| 632 |
$debugDrm = false; |
| 633 |
|
| 634 |
$curl_post_fields=array( |
| 635 |
'access_token' => $access_token, |
| 636 |
'name' => $video_name, |
| 637 |
'corsOrigin' => $corsorigin, |
| 638 |
'encryptHls' => $encrypt, |
| 639 |
'hlsKeysUrlPrefix' => $hlsKeysUrlPrefix, |
| 640 |
'debugDrm' => $debugDrm, |
| 641 |
); |
| 642 |
|
| 643 |
|
| 644 |
$curl_response = $this->main->wpstream_live_connection->wpstream_baker_do_curl_base($url,$curl_post_fields); |
| 645 |
$curl_response_decoded = json_decode($curl_response,JSON_OBJECT_AS_ARRAY); |
| 646 |
|
| 647 |
if($curl_response_decoded['success']){ |
| 648 |
set_transient( $transient_name, $curl_response_decoded['hlsUrl'] ,300); |
| 649 |
$hls_to_return = $curl_response_decoded['hlsUrl']; |
| 650 |
if( isset($curl_response_decoded['hlsDecryptionKey']) && isset($curl_response_decoded['hlsDecryptionKeyIndex']) ){ |
| 651 |
update_post_meta($product_id,'hlsDecryptionKey',$curl_response_decoded['hlsDecryptionKey']); |
| 652 |
update_post_meta($product_id,'hlsDecryptionKeyIndex',$curl_response_decoded['hlsDecryptionKeyIndex']); |
| 653 |
}else{ |
| 654 |
delete_post_meta($product_id,'hlsDecryptionKey'); |
| 655 |
delete_post_meta($product_id,'hlsDecryptionKeyIndex'); |
| 656 |
} |
| 657 |
|
| 658 |
}else{ |
| 659 |
return ''; |
| 660 |
} |
| 661 |
|
| 662 |
} |
| 663 |
|
| 664 |
return $hls_to_return; |
| 665 |
|
| 666 |
} |
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
/** |
| 672 |
* VODPlayer uri details |
| 673 |
* |
| 674 |
* @author cretu |
| 675 |
*/ |
| 676 |
public function wpstream_video_on_demand_player_uri_request($product_id){ |
| 677 |
|
| 678 |
$wpstream_data_setup = ' data-setup="{}" '; |
| 679 |
|
| 680 |
/* free_video_type |
| 681 |
* 1 - free live channel |
| 682 |
* 2 - free video encrypted |
| 683 |
* 3 - free video -not encrypted |
| 684 |
*/ |
| 685 |
|
| 686 |
$post_type = get_post_type($product_id); |
| 687 |
$free_video_type = intval( get_post_meta($product_id, 'wpstream_product_type', true)); |
| 688 |
if( ( $post_type =='wpstream_product_vod' && $free_video_type==2 ) || get_post_type($product_id)=='product' ){ |
| 689 |
|
| 690 |
/* |
| 691 |
* IF vide is encrypted- readed from vod,streaner |
| 692 |
* |
| 693 |
*/ |
| 694 |
|
| 695 |
|
| 696 |
$video_type = 'application/x-mpegURL'; |
| 697 |
$video_path = get_post_meta($product_id,'_movie_url',true); |
| 698 |
if(get_post_type($product_id)=='wpstream_product_vod'){ |
| 699 |
$video_path = esc_html(get_post_meta($product_id, 'wpstream_free_video', true)); |
| 700 |
} |
| 701 |
$video_path_final = $this->wpstream_request_video_on_demand_hls_player($video_path,$product_id); |
| 702 |
|
| 703 |
|
| 704 |
}else if( $post_type =='wpstream_product_vod' && $free_video_type==3 ){ |
| 705 |
|
| 706 |
/* Video is unecrypted - read from local or youtube / vimeo |
| 707 |
*/ |
| 708 |
|
| 709 |
$video_type = 'video/mp4'; |
| 710 |
$video_path_final=esc_html(get_post_meta($product_id, 'wpstream_free_video_external', true)); |
| 711 |
|
| 712 |
if (strpos($video_path_final, 'www.youtube') !== false) { |
| 713 |
$wpstream_data_setup= ' data-setup=\'{ "techOrder": ["youtube"], "sources": [{ "type": "video/youtube", "src": "'.$video_path_final.'"}] }\' '; |
| 714 |
$video_path_final=''; |
| 715 |
} |
| 716 |
/* disabled due to old lib |
| 717 |
if (strpos($video_path_final, 'vimeo.com') !== false) { |
| 718 |
$wpstream_data_setup= ' data-setup=\'{"techOrder": ["vimeo"], "sources": [{ "type": "video/vimeo", "src": "'.$video_path_final.'"}], "vimeo": { "color": "#fbc51b"} }\' '; |
| 719 |
$video_path_final=''; |
| 720 |
}*/ |
| 721 |
|
| 722 |
} |
| 723 |
|
| 724 |
$return_array = array(); |
| 725 |
$return_array['video_path_final'] = $video_path_final; |
| 726 |
$return_array['wpstream_data_setup']= $wpstream_data_setup; |
| 727 |
$return_array['video_type'] = $video_type; |
| 728 |
$return_array['free_video_type'] = $free_video_type; |
| 729 |
$return_array['post_type'] = $post_type ; |
| 730 |
return $return_array; |
| 731 |
} |
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
/** |
| 736 |
* VODPlayer url |
| 737 |
* |
| 738 |
* @author cretu |
| 739 |
*/ |
| 740 |
|
| 741 |
public function wpstream_video_on_demand_player($product_id){ |
| 742 |
|
| 743 |
$uri_details = $this->wpstream_video_on_demand_player_uri_request($product_id); |
| 744 |
$video_path_final = $uri_details['video_path_final']; |
| 745 |
$wpstream_data_setup = $uri_details['wpstream_data_setup']; |
| 746 |
$video_type = $uri_details['video_type']; |
| 747 |
$now = time().rand(0,1000000); |
| 748 |
|
| 749 |
$thumb_id = get_post_thumbnail_id($product_id); |
| 750 |
$thumb = wp_get_attachment_image_src($thumb_id,'small'); |
| 751 |
$usernamestream = esc_html ( get_option('wpstream_api_username','') ); |
| 752 |
|
| 753 |
$poster_thumb = ''; |
| 754 |
if(isset($thumb[0])){ |
| 755 |
$poster_thumb=$thumb[0]; |
| 756 |
} |
| 757 |
|
| 758 |
$hlsDecryptionKey = get_post_meta($product_id,'hlsDecryptionKey',true); |
| 759 |
$hlsDecryptionKeyIndex = get_post_meta($product_id,'hlsDecryptionKeyIndex',true); |
| 760 |
|
| 761 |
|
| 762 |
$pack = $this->main->wpstream_live_connection->wpstream_request_pack_data_per_user(); |
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
$trailer_attachment_id = intval (get_post_meta( $product_id, 'video_trailer', true )); |
| 767 |
$video_trailer = ''; |
| 768 |
$video_trailer_type = ''; |
| 769 |
if($trailer_attachment_id!=0) { |
| 770 |
$video_trailer = wp_get_attachment_url( $trailer_attachment_id ); |
| 771 |
$attachment_metadata = wp_get_attachment_metadata($trailer_attachment_id); |
| 772 |
$video_trailer_type = $attachment_metadata['mime_type']; |
| 773 |
} |
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
if(isset($pack['available_data_mb']) && $pack['available_data_mb']>0){ |
| 779 |
|
| 780 |
if($video_path_final==''){ |
| 781 |
if( $uri_details['post_type']=='wpstream_product_vod' && $uri_details['free_video_type']==3 ){ |
| 782 |
}else{ |
| 783 |
print '<div class="wpstream_vod_notice">This video does not exist or it has been deleted!</div>'; |
| 784 |
} |
| 785 |
|
| 786 |
} |
| 787 |
|
| 788 |
// TODO (crerem) populate these from VOD settings |
| 789 |
$autoplay = true; |
| 790 |
$muted = false; |
| 791 |
|
| 792 |
echo '<video id="wpstream-video-vod-'.$now.'" class="video-js vjs-default-skin vjs-fluid kuk wpstream_video_on_demand vjs-wpstream" data-me="'.esc_attr($usernamestream).'" data-product-id="'.$product_id.'" playsinline preload="auto" |
| 793 |
poster="'.esc_url($poster_thumb).'" '.$wpstream_data_setup.'> |
| 794 |
<p class="vjs-no-js"> |
| 795 |
To view this video please enable JavaScript, and consider upgrading to a web browser that |
| 796 |
<a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a> |
| 797 |
</p> |
| 798 |
</video>'; |
| 799 |
|
| 800 |
if($trailer_attachment_id !=0){ |
| 801 |
print '<div id="wpstream_video_on_demand_play_trailer_btn_' . $now . '" class="wpstream_video_on_demand_play_video">'.esc_html('play trailer').'</div>'; |
| 802 |
print '<div id="wpstream_video_on_demand_play_video_btn_' . $now . '" class="wpstream_video_on_demand_play_video">'.esc_html('play real video').'</div>'; |
| 803 |
print '<script type="text/javascript"> |
| 804 |
//<![CDATA[ |
| 805 |
jQuery(document).ready(function(){ |
| 806 |
wpstream_player_initialize_vod({ |
| 807 |
videoElementId: "wpstream-video-vod-'.$now.'", |
| 808 |
trailerUrl: "'.$video_trailer.'", |
| 809 |
videoUrl: "'.$video_path_final.'", |
| 810 |
autoplay: '.var_export($autoplay, true).', |
| 811 |
muted: '.var_export($muted, true).', |
| 812 |
playTrailerButtonElementId: "wpstream_video_on_demand_play_trailer_btn_'.$now.'", |
| 813 |
playVideoButtonElementId: "wpstream_video_on_demand_play_video_btn_'.$now.'", |
| 814 |
}); |
| 815 |
}); |
| 816 |
//]]> |
| 817 |
</script>'; |
| 818 |
} |
| 819 |
else { |
| 820 |
print '<script type="text/javascript"> |
| 821 |
//<![CDATA[ |
| 822 |
jQuery(document).ready(function(){ |
| 823 |
wpstream_player_initialize_vod({ |
| 824 |
videoElementId: "wpstream-video-vod-'.$now.'", |
| 825 |
videoUrl: "'.$video_path_final.'", |
| 826 |
autoplay: '.var_export($autoplay, true).', |
| 827 |
muted: '.var_export($muted, true).', |
| 828 |
}); |
| 829 |
}); |
| 830 |
//]]> |
| 831 |
</script>'; |
| 832 |
} |
| 833 |
}else{ |
| 834 |
print esc_html_e('Insufficient resources to stream this title','wpstream'); |
| 835 |
} |
| 836 |
|
| 837 |
} |
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
/** |
| 845 |
* |
| 846 |
* edited 4.0 |
| 847 |
* |
| 848 |
* Retreive username for vod path |
| 849 |
* |
| 850 |
* @author cretu |
| 851 |
*/ |
| 852 |
private function wpstream_retrive_username(){ |
| 853 |
|
| 854 |
return get_option('wpstream_api_username_from_token'); |
| 855 |
} |
| 856 |
|
| 857 |
/** |
| 858 |
* check if the we can add display the player |
| 859 |
* |
| 860 |
* @since 3.12 |
| 861 |
* returns html of the player |
| 862 |
*/ |
| 863 |
|
| 864 |
public function wpstream_check_if_player_can_dsplay($product_id){ |
| 865 |
if ( is_user_logged_in() ) { |
| 866 |
|
| 867 |
$term_list = wp_get_post_terms($product_id, 'product_type'); |
| 868 |
$current_user = wp_get_current_user(); |
| 869 |
$subscription_model = intval( get_option('wpstream_global_sub','')) ; |
| 870 |
|
| 871 |
$product = wc_get_product($product_id); |
| 872 |
$product_type = $product->get_type(); |
| 873 |
|
| 874 |
|
| 875 |
if($subscription_model==1){ // if we have Neflix mode |
| 876 |
if( $product_type=='subscription' ){ // if the product loaded is a subscription and we are on netflix mode |
| 877 |
return false; |
| 878 |
} |
| 879 |
if($this->wpstream_in_plugin_check_global_subscription_model($product_id)){ |
| 880 |
return true; |
| 881 |
} |
| 882 |
}else{ |
| 883 |
// ppv mode |
| 884 |
|
| 885 |
if( $product_type=='subscription' ){ |
| 886 |
|
| 887 |
// $user_subscriptions = wcs_get_users_subscriptions($current_user->ID ); |
| 888 |
// foreach ($user_subscriptions as $subscription) { |
| 889 |
// $subscription_status = $subscription->get_status(); |
| 890 |
// echo "</br>*** Subscription ID $subscription->ID for User ID $current_user->ID has status: $subscription_status"; |
| 891 |
// } |
| 892 |
|
| 893 |
|
| 894 |
if( wcs_user_has_subscription( $current_user->ID, $product_id ,'active') ) { |
| 895 |
// user has active subcription |
| 896 |
return true; |
| 897 |
} |
| 898 |
|
| 899 |
}else{ |
| 900 |
if( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product_id)){ |
| 901 |
return true; |
| 902 |
} |
| 903 |
} |
| 904 |
|
| 905 |
|
| 906 |
} |
| 907 |
return false; |
| 908 |
|
| 909 |
} |
| 910 |
return false; |
| 911 |
|
| 912 |
} |
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
/** |
| 917 |
* check if the we can add display the player - theme variant |
| 918 |
* |
| 919 |
* @since 3.12 |
| 920 |
* returns html of the player |
| 921 |
*/ |
| 922 |
public function wpstream_check_if_player_can_dsplay_theme($product_id){ |
| 923 |
|
| 924 |
$post_type= get_post_type($product_id); |
| 925 |
|
| 926 |
|
| 927 |
print '------- post type: '.$post_type.'</br>'; |
| 928 |
if($post_type=='wpstream_product_vod' || $post_type=='wpstream_product'){ |
| 929 |
return true; // if we have free vod or live |
| 930 |
} |
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
if ( is_user_logged_in() && $post_type==='product' ) { |
| 935 |
|
| 936 |
$product = wc_get_product( $product_id ); |
| 937 |
$product_type = $product->get_type(); |
| 938 |
$possible_bundle = get_post_meta($product_id, 'wpstream_part_of_bundle',true); |
| 939 |
print '----------'.$product_type.'-----------</br>'; |
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
$current_user = wp_get_current_user(); |
| 945 |
$subscription_model = intval( get_option('wpstream_global_sub','')) ; |
| 946 |
print 'subscription model '.$subscription_model.'</br>'; |
| 947 |
|
| 948 |
if($subscription_model==1){ // if we have Neflix mode |
| 949 |
if( $product_type=='subscription' ){ // if the product loaded is a subscription and we are on netflix mode |
| 950 |
return false; |
| 951 |
} |
| 952 |
if($this->wpstream_in_plugin_check_global_subscription_model($product_id)){ |
| 953 |
return true; |
| 954 |
} |
| 955 |
}else{ |
| 956 |
// ppv mode |
| 957 |
if ( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product_id) ){ |
| 958 |
return true; //simple product bought |
| 959 |
}else if (function_exists('wcs_user_has_subscription') && wcs_user_has_subscription( $current_user->ID, $product_id ,'active') ){ |
| 960 |
return true; // subscription boght |
| 961 |
}else if( get_post_type($product_id) =='product' && |
| 962 |
intval($possible_bundle )!=0 && |
| 963 |
wc_customer_bought_product( $current_user->user_email, $current_user->ID, $possible_bundle) |
| 964 |
){ |
| 965 |
return true; // part of a boght bundle |
| 966 |
} |
| 967 |
} |
| 968 |
print ' fac return false </br>'; |
| 969 |
return false; |
| 970 |
|
| 971 |
} |
| 972 |
return false; |
| 973 |
|
| 974 |
} |
| 975 |
|
| 976 |
|
| 977 |
/** |
| 978 |
* in plugin - check if global subscription model is enabled |
| 979 |
* |
| 980 |
* @since 3.12 |
| 981 |
* |
| 982 |
*/ |
| 983 |
public function wpstream_in_plugin_check_global_subscription_model($product_id) { |
| 984 |
|
| 985 |
// $selected_sub= get_post_meta($post->ID,'_wpstream_parent_sub',true); |
| 986 |
if( is_user_logged_in() && function_exists('wcs_user_has_subscription') ){ |
| 987 |
|
| 988 |
global $woocommerce; |
| 989 |
$current_user = wp_get_current_user(); |
| 990 |
|
| 991 |
$subscription_model = intval( get_option('wpstream_global_sub','')) ; |
| 992 |
$main_subscription = intval( get_option('wpstream_global_sub_id','')); |
| 993 |
|
| 994 |
if($subscription_model==1){ |
| 995 |
$selected_sub= get_post_meta($product_id,'_wpstream_parent_sub',true) ; |
| 996 |
|
| 997 |
if( is_array($selected_sub) ){ |
| 998 |
|
| 999 |
// we have per product sub |
| 1000 |
foreach($selected_sub as $key=>$subscrition_id ): |
| 1001 |
if( wcs_user_has_subscription( $current_user->ID, $subscrition_id ,'active') ) { |
| 1002 |
return true; |
| 1003 |
} |
| 1004 |
endforeach; |
| 1005 |
|
| 1006 |
} else if($main_subscription!=0){ |
| 1007 |
|
| 1008 |
// if we have one main subscription |
| 1009 |
if( wcs_user_has_subscription( $current_user->ID, $main_subscription ,'active') ) { |
| 1010 |
return true; |
| 1011 |
} |
| 1012 |
} |
| 1013 |
|
| 1014 |
|
| 1015 |
} |
| 1016 |
return false; |
| 1017 |
|
| 1018 |
} |
| 1019 |
// there is no woo subscription or user not logged in |
| 1020 |
return false; |
| 1021 |
} |
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
/** |
| 1032 |
* |
| 1033 |
* |
| 1034 |
* |
| 1035 |
* |
| 1036 |
* check if the user bought the product and display the player - TO REDo |
| 1037 |
* |
| 1038 |
* @since 3.0.1 |
| 1039 |
* returns html of the player |
| 1040 |
* |
| 1041 |
* |
| 1042 |
* |
| 1043 |
* |
| 1044 |
* |
| 1045 |
*/ |
| 1046 |
public function wpstream_user_logged_in_product_already_bought($from_sh_id='') { |
| 1047 |
if(function_exists('remove_wpstream_filter')){ |
| 1048 |
return; |
| 1049 |
} |
| 1050 |
global $product; |
| 1051 |
$product_id = $product->get_id(); |
| 1052 |
$current_user = wp_get_current_user(); |
| 1053 |
|
| 1054 |
if ( is_user_logged_in() ) { |
| 1055 |
|
| 1056 |
|
| 1057 |
if($this->wpstream_check_if_player_can_dsplay($product_id) ){ |
| 1058 |
|
| 1059 |
echo '<div class="wpstream_player_wrapper "><div class="wpstream_player_container">'; |
| 1060 |
|
| 1061 |
$is_subscription_live_event = esc_html(get_post_meta($product_id,'_subscript_live_event',true)); |
| 1062 |
$term_list = wp_get_post_terms($product_id, 'product_type'); |
| 1063 |
|
| 1064 |
|
| 1065 |
if( $term_list[0]->name=='live_stream' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){ |
| 1066 |
$this->wpstream_live_event_player($product_id); |
| 1067 |
}else if( $term_list[0]->name=='video_on_demand' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='no' ) ){ |
| 1068 |
$this->wpstream_video_on_demand_player($product_id); |
| 1069 |
} |
| 1070 |
echo '</div></div>'; |
| 1071 |
}else{ |
| 1072 |
|
| 1073 |
|
| 1074 |
$term_list = wp_get_post_terms($product_id, 'product_type'); |
| 1075 |
|
| 1076 |
if( $term_list[0]->name=='subscription' ){ |
| 1077 |
|
| 1078 |
if( !wcs_user_has_subscription( $current_user->ID, $product_id ,'active') ) { |
| 1079 |
$this->wpstream_display_no_buy_message('nobuy',$product_id); |
| 1080 |
} |
| 1081 |
|
| 1082 |
}else{ |
| 1083 |
$this->wpstream_display_no_buy_message('nobuy',$product_id); |
| 1084 |
} |
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
} |
| 1089 |
|
| 1090 |
|
| 1091 |
}else{ |
| 1092 |
|
| 1093 |
$this->wpstream_display_no_buy_message('nolog',$product_id); |
| 1094 |
} |
| 1095 |
} |
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
/** |
| 1102 |
* |
| 1103 |
* |
| 1104 |
* check if the user bought the product and display the player - TO REDo |
| 1105 |
* |
| 1106 |
* @since 3.0.1 |
| 1107 |
* returns html of the player |
| 1108 |
*/ |
| 1109 |
|
| 1110 |
public function wpstream_chat_wrapper($product_id){ |
| 1111 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/templates/wpstream_chat_template.php'; |
| 1112 |
} |
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
/** |
| 1122 |
* coonect to chat |
| 1123 |
* |
| 1124 |
* @since 1.12.2 |
| 1125 |
* |
| 1126 |
*/ |
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
public function wpstream_connect_to_chat($product_id){ |
| 1131 |
$current_user = wp_get_current_user(); |
| 1132 |
$userID = $current_user->ID; |
| 1133 |
$user_login = $current_user->user_login; |
| 1134 |
|
| 1135 |
$key=''; |
| 1136 |
|
| 1137 |
$chat_url = get_post_meta($product_id,'chat_url',true); |
| 1138 |
|
| 1139 |
|
| 1140 |
wp_enqueue_script( 'sockjs-0.3.min' ); |
| 1141 |
wp_enqueue_script( 'emojione.min.js' ); |
| 1142 |
wp_enqueue_script( "jquery-effects-core"); |
| 1143 |
wp_enqueue_script( 'jquery.linkify.min.js'); |
| 1144 |
wp_enqueue_script( 'ripples.min.js'); |
| 1145 |
wp_enqueue_script( 'material.min.js'); |
| 1146 |
wp_enqueue_script( 'chat.js'); |
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
wp_enqueue_style( 'chat.css'); |
| 1151 |
wp_enqueue_style( 'ripples.css'); |
| 1152 |
wp_enqueue_style( 'emojione.min.css'); |
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
if(!is_user_logged_in()){ |
| 1158 |
$user_login=''; |
| 1159 |
$chat_url=''; |
| 1160 |
} |
| 1161 |
|
| 1162 |
|
| 1163 |
print '<script type="text/javascript"> |
| 1164 |
//<![CDATA[ |
| 1165 |
jQuery(document).ready(function(){ |
| 1166 |
username = "'.$user_login.'"; |
| 1167 |
key="'.$key.'"; |
| 1168 |
|
| 1169 |
}); |
| 1170 |
//]]> |
| 1171 |
</script>'; |
| 1172 |
|
| 1173 |
} |
| 1174 |
|
| 1175 |
|
| 1176 |
/** |
| 1177 |
* display no buy Message |
| 1178 |
* |
| 1179 |
* @since 3.12.2 |
| 1180 |
* |
| 1181 |
*/ |
| 1182 |
public function wpstream_display_no_buy_message($log,$product_id) { |
| 1183 |
|
| 1184 |
if($log=='sub_active'){ |
| 1185 |
$message= esc_html( get_option('wpstream_subscription_active','Your Subscription is Active.')) ; |
| 1186 |
echo '<div class="wpstream_player_wrapper no_buy"><div class="wpstream_player_container">'; |
| 1187 |
echo '<div class="wpstream_notice"> '.$message.'</div>'; |
| 1188 |
echo '</div></div>'; |
| 1189 |
return; |
| 1190 |
|
| 1191 |
}else if($log=='nolog'){ |
| 1192 |
$message= esc_html( get_option('wpstream_product_not_login','You must be logged in to watch this video.')) ; |
| 1193 |
}else{ |
| 1194 |
$message =esc_html( get_option('wpstream_product_not_bought','You did not yet purchase this item.')) ; |
| 1195 |
} |
| 1196 |
$subscription_model = intval( get_option('wpstream_global_sub','')) ; |
| 1197 |
if($subscription_model==1){ |
| 1198 |
$message =esc_html( get_option('wpstream_product_not_subscribe','You did not yet subscribe to this item.')); |
| 1199 |
} |
| 1200 |
|
| 1201 |
|
| 1202 |
if( get_post_type($product_id) == 'product' && $subscription_model==0 ){ |
| 1203 |
$product = wc_get_product($product_id); |
| 1204 |
$term_list = wp_get_post_terms($product_id, 'product_type'); |
| 1205 |
$product_type = $product->get_type(); |
| 1206 |
$is_subscription_live_event = esc_html(get_post_meta($product_id,'_subscript_live_event',true)); |
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
if( $term_list[0]->name=='video_on_demand' || $term_list[0]->name=='live_stream' || $product_type=='subscription'){ |
| 1211 |
|
| 1212 |
echo '<div class="wpstream_player_wrapper no_buy"><div class="wpstream_player_container">'; |
| 1213 |
echo '<div class="wpstream_notice">'.$message.'</div>'; |
| 1214 |
echo '</div></div>'; |
| 1215 |
|
| 1216 |
} |
| 1217 |
|
| 1218 |
}else if( get_post_type($product_id) == 'product' && $subscription_model==1 ){ |
| 1219 |
$term_list = wp_get_post_terms($product_id, 'product_type'); |
| 1220 |
if( $term_list[0]->name!=='simple'){ |
| 1221 |
echo '<div class="wpstream_player_wrapper no_buy"><div class="wpstream_player_container">'; |
| 1222 |
echo '<div class="wpstream_notice"> '.$message.'</div>'; |
| 1223 |
echo '</div></div>'; |
| 1224 |
} |
| 1225 |
} |
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
} |
| 1233 |
|
| 1234 |
|
| 1235 |
} |