| 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 |
$event_status = $this->main->wpstream_live_connection-> wpstream_check_event_status_api_call($channel_id); |
| 56 |
$event_data_for_transient = $event_status; |
| 57 |
|
| 58 |
set_transient($transient_name,$event_data_for_transient,45); |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
if( isset($event_data_for_transient['hls_playback_url']) && $event_data_for_transient['hls_playback_url']!=''){ |
| 63 |
echo json_encode( array( |
| 64 |
|
| 65 |
'started' => 'yes', |
| 66 |
'channel_id' => $channel_id, |
| 67 |
'event_uri' => $event_data_for_transient['hls_playback_url'], |
| 68 |
'live_conect_views' => $event_data_for_transient['stats_url'], |
| 69 |
'chat_url' => $event_data_for_transient['chat_url'], |
| 70 |
'$event_data_for_transient'=>$event_data_for_transient |
| 71 |
|
| 72 |
|
| 73 |
)); |
| 74 |
update_post_meta($channel_id,'stream_name',$event_data_for_transient['stream_name']); |
| 75 |
update_post_meta($channel_id,'hls_key_retrieval_url',$event_data_for_transient['hls_key_retrieval_url']); |
| 76 |
delete_transient( 'free_event_streamName_'.$event_data_for_transient['stream_name']); |
| 77 |
|
| 78 |
}else{ |
| 79 |
echo json_encode( array( |
| 80 |
'started' => 'no', |
| 81 |
'server_id' => '', |
| 82 |
'channel_id' => $channel_id, |
| 83 |
'event_uri' => '', |
| 84 |
'live_conect_views' => '', |
| 85 |
'chat_url' => '', |
| 86 |
|
| 87 |
)); |
| 88 |
|
| 89 |
} |
| 90 |
|
| 91 |
die(); |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
/** |
| 97 |
* Insert player in page |
| 98 |
* |
| 99 |
* @author cretu |
| 100 |
*/ |
| 101 |
public function wpstream_filter_the_title( $content ) { |
| 102 |
if( is_singular('wpstream_product') || is_singular('wpstream_product_vod') ){ |
| 103 |
global $post; |
| 104 |
$args=array('id'=>$post->ID); |
| 105 |
$custom_content = $this->wpstream_insert_player_inpage($args); |
| 106 |
$content = '<div class="wpestream_inserted_player">'.$custom_content.'</div>'.$content; |
| 107 |
return $content; |
| 108 |
}else{ |
| 109 |
return $content; |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* Insert player in page |
| 115 |
* |
| 116 |
* @author cretu |
| 117 |
*/ |
| 118 |
|
| 119 |
public function wpstream_insert_player_inpage($attributes, $content = null){ |
| 120 |
$product_id = ''; |
| 121 |
$return_string = ''; |
| 122 |
$attributes = shortcode_atts( |
| 123 |
array( |
| 124 |
'id' => 0, |
| 125 |
), $attributes) ; |
| 126 |
|
| 127 |
|
| 128 |
if ( isset($attributes['id']) ){ |
| 129 |
$product_id=$attributes['id']; |
| 130 |
} |
| 131 |
|
| 132 |
if(intval($product_id)==0){ |
| 133 |
$product_id= $this->wpstream_player_retrive_first_id(); |
| 134 |
} |
| 135 |
|
| 136 |
ob_start(); |
| 137 |
|
| 138 |
$this->wpstream_video_player_shortcode($product_id); |
| 139 |
$return_string= ob_get_contents(); |
| 140 |
ob_end_clean(); |
| 141 |
|
| 142 |
return $return_string; |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
/** |
| 149 |
* Video Player shortcode |
| 150 |
* |
| 151 |
* @author cretu |
| 152 |
*/ |
| 153 |
|
| 154 |
public function wpstream_video_player_shortcode($from_sh_id='') { |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
if ( is_user_logged_in() ) { |
| 159 |
global $product; |
| 160 |
$current_user = wp_get_current_user(); |
| 161 |
$product_id = intval($from_sh_id); |
| 162 |
$term_list = wp_get_post_terms($product_id, 'product_type'); |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
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) ) |
| 169 |
|| get_post_type($product_id)=='wpstream_product' || get_post_type($product_id)=='wpstream_product_vod' ){ |
| 170 |
global $product; |
| 171 |
echo '<div class="wpstream_player_wrapper wpstream_player_shortcode"><div class="wpstream_player_container">'; |
| 172 |
|
| 173 |
|
| 174 |
if( get_post_type($product_id) == 'wpstream_product' ){ |
| 175 |
$this->wpstream_live_event_player($product_id); |
| 176 |
}else if( get_post_type($product_id) == 'wpstream_product_vod' ){ |
| 177 |
$this->wpstream_video_on_demand_player($product_id); |
| 178 |
}else{ |
| 179 |
|
| 180 |
$is_subscription_live_event = esc_html(get_post_meta($product_id,'_subscript_live_event',true)); |
| 181 |
|
| 182 |
if( $term_list[0]->name=='live_stream' || ( $term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){ |
| 183 |
$this->wpstream_live_event_player($product_id); |
| 184 |
}else if( $term_list[0]->name=='video_on_demand' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='no' ) ){ |
| 185 |
$this->wpstream_video_on_demand_player($product_id); |
| 186 |
} |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
echo '</div></div>'; |
| 191 |
}else{ |
| 192 |
|
| 193 |
if( get_post_type($product_id) == 'product' ){ |
| 194 |
echo '<div class="wpstream_player_wrapper wpstream_player_shortcode no_buy"><div class="wpstream_player_container">'; |
| 195 |
echo '<div class="wpstream_notice" style="background:#e16767;">'.esc_html__('You did not buy this product!','wpstream').'</div>'; |
| 196 |
echo '</div></div>'; |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
}else{ |
| 202 |
|
| 203 |
$product_id = intval($from_sh_id); |
| 204 |
if( get_post_type($product_id) == 'wpstream_product' ){ |
| 205 |
$this->wpstream_live_event_player($product_id); |
| 206 |
} else if( get_post_type($product_id) == 'wpstream_product_vod' ){ |
| 207 |
$this->wpstream_video_on_demand_player($product_id); |
| 208 |
} |
| 209 |
} |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
/** |
| 215 |
* Video Player shortcode - low latency |
| 216 |
* |
| 217 |
* @author cretu |
| 218 |
*/ |
| 219 |
|
| 220 |
public function wpstream_video_player_shortcode_low_latency($from_sh_id='') { |
| 221 |
|
| 222 |
if ( is_user_logged_in() ) { |
| 223 |
global $product; |
| 224 |
$current_user = wp_get_current_user(); |
| 225 |
$product_id = intval($from_sh_id); |
| 226 |
|
| 227 |
|
| 228 |
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' ){ |
| 229 |
global $product; |
| 230 |
echo '<div class="wpstream_player_wrapper wpstream_player_shortcode"><div class="wpstream_player_container">'; |
| 231 |
|
| 232 |
|
| 233 |
if( get_post_type($product_id) == 'wpstream_product' ){ |
| 234 |
$this->wpstream_live_event_player_low_latency($product_id); |
| 235 |
}else{ |
| 236 |
$term_list = wp_get_post_terms($product_id, 'product_type'); |
| 237 |
$is_subscription_live_event = esc_html(get_post_meta($product_id,'_subscript_live_event',true)); |
| 238 |
|
| 239 |
if( $term_list[0]->name=='live_stream' || ( $term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){ |
| 240 |
$this->wpstream_live_event_player_low_latency($product_id); |
| 241 |
} |
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
echo '</div></div>'; |
| 246 |
}else{ |
| 247 |
|
| 248 |
if( get_post_type($product_id) == 'product' ){ |
| 249 |
echo '<div class="wpstream_player_wrapper wpstream_player_shortcode no_buy"><div class="wpstream_player_container">'; |
| 250 |
echo '<div class="wpstream_notice" style="background:#e16767;">'.esc_html__('You did not buy this product!','wpstream').'</div>'; |
| 251 |
echo '</div></div>'; |
| 252 |
} |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
}else{ |
| 257 |
$product_id = intval($from_sh_id); |
| 258 |
if( get_post_type($product_id) == 'wpstream_product' ){ |
| 259 |
$this->wpstream_live_event_player_low_latency($product_id); |
| 260 |
} |
| 261 |
} |
| 262 |
} |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
/** |
| 269 |
* Live Event Player |
| 270 |
* |
| 271 |
* @author cretu |
| 272 |
*/ |
| 273 |
function remove_http($url) { |
| 274 |
$disallowed = array('http://', 'https://'); |
| 275 |
foreach($disallowed as $d) { |
| 276 |
if(strpos($url, $d) === 0) { |
| 277 |
return str_replace($d, '', $url); |
| 278 |
} |
| 279 |
} |
| 280 |
return $url; |
| 281 |
} |
| 282 |
|
| 283 |
/** |
| 284 |
* Get event settings |
| 285 |
* |
| 286 |
* @author cretu |
| 287 |
*/ |
| 288 |
|
| 289 |
function wpestream_return_event_settings($product_id){ |
| 290 |
|
| 291 |
$local_event_options = get_post_meta($product_id,'local_event_options',true); |
| 292 |
if(!is_array($local_event_options)){ |
| 293 |
$local_event_options = get_option('wpstream_user_streaming_global_channel_options') ; |
| 294 |
} |
| 295 |
|
| 296 |
return $local_event_options; |
| 297 |
} |
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
/** |
| 302 |
* edited in 4.0 |
| 303 |
* |
| 304 |
* Live Event Player |
| 305 |
* |
| 306 |
* @author cretu |
| 307 |
*/ |
| 308 |
|
| 309 |
function wpstream_live_event_player($channel_id,$poster_show='',$use_chat=''){ |
| 310 |
|
| 311 |
$now = time().rand(0,1000000); |
| 312 |
$thumb_id = get_post_thumbnail_id($channel_id); |
| 313 |
$thumb = wp_get_attachment_image_src($thumb_id,'small'); |
| 314 |
$usernamestream = esc_html ( get_option('wpstream_api_username','') ); |
| 315 |
$autoplay = 'autoplay'; |
| 316 |
|
| 317 |
$event_settings = $this->wpestream_return_event_settings($channel_id); |
| 318 |
$event_status = $this->main->wpstream_live_connection-> wpstream_check_event_status_api_call($channel_id); |
| 319 |
$hls_playback_url = ''; |
| 320 |
$live_conect_views = ''; |
| 321 |
|
| 322 |
if(isset($event_status['status']) && $event_status['status']=='active'){ |
| 323 |
//live event |
| 324 |
if(isset($event_status['hls_playback_url'])){ |
| 325 |
$hls_playback_url = $event_status['hls_playback_url']; |
| 326 |
|
| 327 |
update_post_meta($channel_id,'stream_name',$event_status['stream_name']); |
| 328 |
update_post_meta($channel_id,'hls_key_retrieval_url',$event_status['hls_key_retrieval_url']); |
| 329 |
delete_transient( 'free_event_streamName_'.$event_status['stream_name']); |
| 330 |
|
| 331 |
$live_conect_array = explode('live.streamer.wpstream.net',$hls_playback_url); |
| 332 |
$live_conect_views = $live_conect_array[0].'live.streamer.wpstream.net'; |
| 333 |
$live_conect_views = $this->remove_http($live_conect_views); |
| 334 |
|
| 335 |
} |
| 336 |
if(isset($event_status['chat_url'])){ |
| 337 |
$chat_url = $event_status['chat_url']; |
| 338 |
} |
| 339 |
|
| 340 |
}else{ |
| 341 |
// event not live |
| 342 |
} |
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
if(isset($event_settings['autoplay']) && intval($event_settings['autoplay'])==0){ |
| 351 |
$autoplay='no_autoplay'; |
| 352 |
} |
| 353 |
|
| 354 |
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.'" > '; |
| 355 |
|
| 356 |
if( ( isset($event_settings['view_count'] ) && intval($event_settings['view_count'])==1 ) || !isset($event_settings['view_count']) ){ |
| 357 |
echo '<div id="wpestream_live_counting" class="wpestream_live_counting"></div>'; |
| 358 |
} |
| 359 |
|
| 360 |
$show_wpstream_not_live_mess=' style="display:none;" '; |
| 361 |
if(trim($hls_playback_url) ==''){ |
| 362 |
|
| 363 |
$show_wpstream_not_live_mess=''; |
| 364 |
} |
| 365 |
|
| 366 |
|
| 367 |
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__('We are not live at this moment. Please check back later.','wpstream').'</div></div>'; |
| 368 |
|
| 369 |
$poster_data=''; |
| 370 |
if(isset($thumb[0])){ |
| 371 |
$poster_data=' poster="'.$thumb[0].'" '; |
| 372 |
} |
| 373 |
if($poster_show=='no'){ |
| 374 |
$poster_data=''; |
| 375 |
} |
| 376 |
|
| 377 |
$is_muted=''; |
| 378 |
if( isset($event_settings['mute']) && intval($event_settings['mute'])==1){ |
| 379 |
$is_muted=' muted '; |
| 380 |
} |
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
echo' |
| 385 |
<video id="wpstream-video'.$now.'" '.$poster_data.' class="video-js vjs-default-skin vjs-16-9 vjs-wpstream" playsinline="true" '.$is_muted.' controls data-autoplay='.$autoplay.'> |
| 386 |
<source |
| 387 |
src="'.$hls_playback_url.'" |
| 388 |
type="application/x-mpegURL"> |
| 389 |
</video>'; |
| 390 |
|
| 391 |
print '<script type="text/javascript"> |
| 392 |
//<![CDATA[ |
| 393 |
jQuery(document).ready(function(){ |
| 394 |
wpstream_player_initialize("'.$now.'","'.$hls_playback_url.'","'.$live_conect_views.'","'.$autoplay.'");'; |
| 395 |
print'}); |
| 396 |
//]]> |
| 397 |
</script>'; |
| 398 |
print '</div>'; |
| 399 |
|
| 400 |
|
| 401 |
if(trim($hls_playback_url) ==''){ |
| 402 |
// $show_wpstream_not_live_mess=''; |
| 403 |
}else{ |
| 404 |
print '<script type="text/javascript"> |
| 405 |
//<![CDATA[ |
| 406 |
jQuery(document).ready(function(){ |
| 407 |
var player_wrapper = jQuery(".wpstream_live_player_wrapper"); |
| 408 |
wpstream_read_websocket_info("'.$channel_id.'","wpstream_live_player_wrapper'.$now.'", player_wrapper ,"'.$chat_url.'", "'.$hls_playback_url.'"); |
| 409 |
}); |
| 410 |
//]]> |
| 411 |
</script>'; |
| 412 |
} |
| 413 |
|
| 414 |
|
| 415 |
if($use_chat=="yes"){ |
| 416 |
$this->wpstream_connect_to_chat($channel_id); |
| 417 |
} |
| 418 |
|
| 419 |
usleep (10000); |
| 420 |
|
| 421 |
} |
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
/** |
| 426 |
* |
| 427 |
* Edited in 4.0 |
| 428 |
* |
| 429 |
* |
| 430 |
* Live Event Player |
| 431 |
* |
| 432 |
* @author cretu |
| 433 |
*/ |
| 434 |
|
| 435 |
function wpstream_live_event_player_low_latency($channel_id,$poster_show='',$use_chat=''){ |
| 436 |
$usernamestream = esc_html ( get_option('wpstream_api_username','') ); |
| 437 |
$thumb_id = get_post_thumbnail_id($channel_id); |
| 438 |
$thumb = wp_get_attachment_image_src($thumb_id,'small'); |
| 439 |
|
| 440 |
$event_settings = $this->wpestream_return_event_settings($channel_id); |
| 441 |
$event_status = $this->main->wpstream_live_connection-> wpstream_check_event_status_api_call($channel_id); |
| 442 |
$hls_playback_url = ''; |
| 443 |
$live_conect_views = ''; |
| 444 |
$now = time().rand(0,10); |
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
if(isset($event_status['status']) && $event_status['status']=='active'){ |
| 449 |
//live event |
| 450 |
if(isset($event_status['sldp_playback_url'])){ |
| 451 |
$hls_playback_url = $event_status['sldp_playback_url']; |
| 452 |
|
| 453 |
$live_conect_array = explode('live.streamer.wpstream.net',$hls_playback_url); |
| 454 |
$live_conect_views = $live_conect_array[0].'live.streamer.wpstream.net'; |
| 455 |
$live_conect_views = $this->remove_http($live_conect_views); |
| 456 |
|
| 457 |
} |
| 458 |
if(isset($event_status['chat_url'])){ |
| 459 |
$chat_url =$event_status['chat_url']; |
| 460 |
} |
| 461 |
|
| 462 |
}else{ |
| 463 |
// event not live |
| 464 |
} |
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
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.'" > '; |
| 470 |
|
| 471 |
|
| 472 |
if( ( isset($event_settings['view_count'] ) && intval($event_settings['view_count'])==1 ) || !isset($event_settings['view_count']) ){ |
| 473 |
echo '<div id="wpestream_live_counting" class="wpestream_live_counting"></div>'; |
| 474 |
} |
| 475 |
|
| 476 |
$show_wpstream_not_live_mess=' style="display:none;" '; |
| 477 |
if(trim($hls_playback_url) ==''){ |
| 478 |
$show_wpstream_not_live_mess=''; |
| 479 |
} |
| 480 |
|
| 481 |
|
| 482 |
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__('We are not live at this moment. Please check back later.','wpstream').'</div></div>'; |
| 483 |
|
| 484 |
|
| 485 |
$poster_data=' poster="'.$thumb[0].'" '; |
| 486 |
if($poster_show=='no'){ |
| 487 |
$poster_data=''; |
| 488 |
} |
| 489 |
|
| 490 |
|
| 491 |
$is_muted=''; |
| 492 |
if( isset($event_settings['mute']) && intval($event_settings['mute'])==1){ |
| 493 |
$is_muted=' muted '; |
| 494 |
} |
| 495 |
|
| 496 |
|
| 497 |
$autoplay='autoplay'; |
| 498 |
if(isset($event_settings['autoplay']) && intval($event_settings['autoplay'])==0){ |
| 499 |
$autoplay='no_autoplay'; |
| 500 |
} |
| 501 |
|
| 502 |
echo' |
| 503 |
<div iccd="player" id="wpstream-video'.$now.'" '.$poster_data.' '.$is_muted.' class="" > |
| 504 |
</div>'; |
| 505 |
|
| 506 |
print '<script type="text/javascript"> |
| 507 |
//<![CDATA[ |
| 508 |
jQuery(document).ready(function(){ |
| 509 |
var low_latencyid="wpstream-video'.$now.'"; |
| 510 |
document.addEventListener("DOMContentLoaded", initPlayer(low_latencyid, "'.$hls_playback_url.'","'.$is_muted.'","'.$autoplay.'" ) ); '; |
| 511 |
print'}); |
| 512 |
//]]> |
| 513 |
</script>'; |
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
if(trim($hls_playback_url) ==''){ |
| 518 |
// $show_wpstream_not_live_mess=''; |
| 519 |
}else{ |
| 520 |
print '<script type="text/javascript"> |
| 521 |
//<![CDATA[ |
| 522 |
jQuery(document).ready(function(){ |
| 523 |
var player_wrapper = jQuery(".wpstream_live_player_wrapper"); |
| 524 |
wpstream_read_websocket_info("'.$channel_id.'","wpstream_live_player_wrapper'.$now.'", player_wrapper ,"'.$chat_url.'", "'.$hls_playback_url.'"); |
| 525 |
}); |
| 526 |
//]]> |
| 527 |
</script>'; |
| 528 |
} |
| 529 |
|
| 530 |
|
| 531 |
if($use_chat=="yes"){ |
| 532 |
$this->wpstream_connect_to_chat($channel_id); |
| 533 |
} |
| 534 |
|
| 535 |
usleep (10000); |
| 536 |
|
| 537 |
} |
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
/* |
| 544 |
* |
| 545 |
* Request HLS player |
| 546 |
* |
| 547 |
* |
| 548 |
* |
| 549 |
*/ |
| 550 |
public function wpstream_request_video_on_demand_hls_player($video_name,$product_id){ |
| 551 |
if($video_name==''){ |
| 552 |
return ''; |
| 553 |
} |
| 554 |
|
| 555 |
$transient_name = 'wpstream_video_on_demand_'.$video_name; |
| 556 |
$hls_to_return = get_transient( $transient_name ); |
| 557 |
$hls_to_return = false; |
| 558 |
|
| 559 |
|
| 560 |
if($hls_to_return==false){ |
| 561 |
|
| 562 |
$access_token = $this->main->wpstream_live_connection->wpstream_get_token(); |
| 563 |
$url = 'video/info'; |
| 564 |
|
| 565 |
//corsorigin de check |
| 566 |
$local_event_options = get_option('wpstream_user_streaming_global_channel_options') ; |
| 567 |
$domain = parse_url ( get_site_url() ); |
| 568 |
$domain_scheme = 'http'; |
| 569 |
if(is_ssl()){ |
| 570 |
$domain_scheme='https'; |
| 571 |
} |
| 572 |
|
| 573 |
$corsorigin=''; |
| 574 |
if( isset($local_event_options['vod_domain_lock']) ){ |
| 575 |
if (intval( $local_event_options['vod_domain_lock']) ==0 ){ |
| 576 |
$corsorigin='*'; |
| 577 |
} |
| 578 |
}else{ |
| 579 |
$corsorigin='*'; |
| 580 |
} |
| 581 |
|
| 582 |
if($corsorigin!='*'){ |
| 583 |
$corsorigin=$domain_scheme.'://'.$domain['host']; |
| 584 |
} |
| 585 |
|
| 586 |
$is_encrypt="false"; |
| 587 |
if( isset($local_event_options['vod_encrypt']) && intval( $local_event_options['vod_encrypt']) ==1 ){ |
| 588 |
$is_encrypt="true"; |
| 589 |
} |
| 590 |
|
| 591 |
$hlsKeysUrlPrefix = get_site_url().'?wpstream_voddrm='; |
| 592 |
$encrypt = $is_encrypt; |
| 593 |
$debugDrm = false; |
| 594 |
|
| 595 |
$curl_post_fields=array( |
| 596 |
'access_token' => $access_token, |
| 597 |
'name' => $video_name, |
| 598 |
'corsOrigin' => $corsorigin, |
| 599 |
'encryptHls' => $encrypt, |
| 600 |
'hlsKeysUrlPrefix' => $hlsKeysUrlPrefix, |
| 601 |
'debugDrm' => $debugDrm, |
| 602 |
); |
| 603 |
|
| 604 |
|
| 605 |
$curl_response = $this->main->wpstream_live_connection->wpstream_baker_do_curl_base($url,$curl_post_fields); |
| 606 |
$curl_response_decoded = json_decode($curl_response,JSON_OBJECT_AS_ARRAY); |
| 607 |
|
| 608 |
if($curl_response_decoded['success']){ |
| 609 |
set_transient( $transient_name, $curl_response_decoded['hlsUrl'] ,300); |
| 610 |
$hls_to_return = $curl_response_decoded['hlsUrl']; |
| 611 |
if( isset($curl_response_decoded['hlsDecryptionKey']) && isset($curl_response_decoded['hlsDecryptionKeyIndex']) ){ |
| 612 |
update_post_meta($product_id,'hlsDecryptionKey',$curl_response_decoded['hlsDecryptionKey']); |
| 613 |
update_post_meta($product_id,'hlsDecryptionKeyIndex',$curl_response_decoded['hlsDecryptionKeyIndex']); |
| 614 |
}else{ |
| 615 |
delete_post_meta($product_id,'hlsDecryptionKey'); |
| 616 |
delete_post_meta($product_id,'hlsDecryptionKeyIndex'); |
| 617 |
} |
| 618 |
|
| 619 |
}else{ |
| 620 |
return ''; |
| 621 |
} |
| 622 |
|
| 623 |
} |
| 624 |
|
| 625 |
return $hls_to_return; |
| 626 |
|
| 627 |
} |
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
/** |
| 633 |
* VODPlayer uri details |
| 634 |
* |
| 635 |
* @author cretu |
| 636 |
*/ |
| 637 |
public function wpstream_video_on_demand_player_uri_request($product_id){ |
| 638 |
|
| 639 |
$wpstream_data_setup = ' data-setup="{}" '; |
| 640 |
|
| 641 |
/* free_video_type |
| 642 |
* 1 - free live channel |
| 643 |
* 2 - free video encrypted |
| 644 |
* 3 - free video -not encrypted |
| 645 |
*/ |
| 646 |
|
| 647 |
|
| 648 |
$free_video_type = intval( get_post_meta($product_id, 'wpstream_product_type', true)); |
| 649 |
if( ( is_singular('wpstream_product_vod') && $free_video_type==2 ) || get_post_type($product_id)=='product' ){ |
| 650 |
|
| 651 |
/* |
| 652 |
* IF vide is encrypted- readed from vod,streaner |
| 653 |
* |
| 654 |
*/ |
| 655 |
|
| 656 |
|
| 657 |
$video_type = 'application/x-mpegURL'; |
| 658 |
$video_path = get_post_meta($product_id,'_movie_url',true); |
| 659 |
if(get_post_type($product_id)=='wpstream_product_vod'){ |
| 660 |
$video_path = esc_html(get_post_meta($product_id, 'wpstream_free_video', true)); |
| 661 |
} |
| 662 |
$video_path_final = $this->wpstream_request_video_on_demand_hls_player($video_path,$product_id); |
| 663 |
|
| 664 |
|
| 665 |
}else if( is_singular('wpstream_product_vod') && $free_video_type==3 ){ |
| 666 |
|
| 667 |
/* Video is unecrypted - read from local or youtube / vimeo |
| 668 |
*/ |
| 669 |
|
| 670 |
$video_type = 'video/mp4'; |
| 671 |
$video_path_final=esc_html(get_post_meta($product_id, 'wpstream_free_video_external', true)); |
| 672 |
|
| 673 |
if (strpos($video_path_final, 'www.youtube') !== false) { |
| 674 |
$wpstream_data_setup= ' data-setup=\'{ "techOrder": ["youtube"], "sources": [{ "type": "video/youtube", "src": "'.$video_path_final.'"}] }\' '; |
| 675 |
$video_path_final=''; |
| 676 |
} |
| 677 |
if (strpos($video_path_final, 'vimeo.com') !== false) { |
| 678 |
$wpstream_data_setup= ' data-setup=\'{"techOrder": ["vimeo"], "sources": [{ "type": "video/vimeo", "src": "'.$video_path_final.'"}], "vimeo": { "color": "#fbc51b"} }\' '; |
| 679 |
$video_path_final=''; |
| 680 |
} |
| 681 |
|
| 682 |
} |
| 683 |
|
| 684 |
$return_array=array(); |
| 685 |
$return_array['video_path_final'] = $video_path_final; |
| 686 |
$return_array['wpstream_data_setup']= $wpstream_data_setup; |
| 687 |
$return_array['video_type'] = $video_type; |
| 688 |
return $return_array; |
| 689 |
} |
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
/** |
| 694 |
* VODPlayer url |
| 695 |
* |
| 696 |
* @author cretu |
| 697 |
*/ |
| 698 |
|
| 699 |
public function wpstream_video_on_demand_player($product_id){ |
| 700 |
|
| 701 |
$uri_details = $this->wpstream_video_on_demand_player_uri_request($product_id); |
| 702 |
$video_path_final = $uri_details['video_path_final']; |
| 703 |
$wpstream_data_setup = $uri_details['wpstream_data_setup']; |
| 704 |
$video_type = $uri_details['video_type']; |
| 705 |
|
| 706 |
$thumb_id = get_post_thumbnail_id($product_id); |
| 707 |
$thumb = wp_get_attachment_image_src($thumb_id,'small'); |
| 708 |
$usernamestream = esc_html ( get_option('wpstream_api_username','') ); |
| 709 |
|
| 710 |
$poster_thumb = ''; |
| 711 |
if(isset($thumb[0])){ |
| 712 |
$poster_thumb=$thumb[0]; |
| 713 |
} |
| 714 |
|
| 715 |
$hlsDecryptionKey = get_post_meta($product_id,'hlsDecryptionKey',true); |
| 716 |
$hlsDecryptionKeyIndex = get_post_meta($product_id,'hlsDecryptionKeyIndex',true); |
| 717 |
|
| 718 |
|
| 719 |
$pack = $this->main->wpstream_live_connection->wpstream_request_pack_data_per_user(); |
| 720 |
|
| 721 |
|
| 722 |
if(isset($pack['available_data_mb']) && $pack['available_data_mb']>0){ |
| 723 |
|
| 724 |
if($video_path_final==''){ |
| 725 |
print '<div class="wpstream_vod_notice">This video does not exist or it has been deleted!</div>'; |
| 726 |
} |
| 727 |
|
| 728 |
echo '<video id="wpstream-video'.time().'" class="video-js vjs-default-skin vjs-16-9 kuk wpstream_video_on_demand vjs-wpstream" data-me="'.esc_attr($usernamestream).'" data-product-id="'.$product_id.'" controls preload="auto" |
| 729 |
poster="'.esc_url($poster_thumb).'" '.$wpstream_data_setup.'> |
| 730 |
|
| 731 |
<source src="'.trim($video_path_final).'" type="'.$video_type.'"> |
| 732 |
<p class="vjs-no-js"> |
| 733 |
To view this video please enable JavaScript, and consider upgrading to a web browser that |
| 734 |
<a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a> |
| 735 |
</p> |
| 736 |
</video>'; |
| 737 |
}else{ |
| 738 |
print esc_html_e('Insufficient resources to stream this title','wpstream'); |
| 739 |
} |
| 740 |
|
| 741 |
} |
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
/** |
| 749 |
* |
| 750 |
* edited 4.0 |
| 751 |
* |
| 752 |
* Retreive username for vod path |
| 753 |
* |
| 754 |
* @author cretu |
| 755 |
*/ |
| 756 |
private function wpstream_retrive_username(){ |
| 757 |
|
| 758 |
return get_option('wpstream_api_username_from_token'); |
| 759 |
} |
| 760 |
|
| 761 |
/** |
| 762 |
* check if the we can add display the player |
| 763 |
* |
| 764 |
* @since 3.12 |
| 765 |
* returns html of the player |
| 766 |
*/ |
| 767 |
|
| 768 |
public function wpstream_check_if_player_can_dsplay($product_id){ |
| 769 |
if ( is_user_logged_in() ) { |
| 770 |
|
| 771 |
$term_list = wp_get_post_terms($product_id, 'product_type'); |
| 772 |
$current_user = wp_get_current_user(); |
| 773 |
$subscription_model = esc_html( get_option('wpstream_global_sub','')) ; |
| 774 |
|
| 775 |
|
| 776 |
if($subscription_model==1){ // if we have Neflix mode |
| 777 |
if( $term_list[0]->name=='subscription' ){ // if the product loaded is a subscription and we are on netflix mode |
| 778 |
return false; |
| 779 |
} |
| 780 |
if($this->wpstream_in_plugin_check_global_subscription_model($product_id)){ |
| 781 |
return true; |
| 782 |
} |
| 783 |
}else{ |
| 784 |
// ppv mode |
| 785 |
if ( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product_id) || |
| 786 |
( function_exists('wcs_user_has_subscription') && wcs_user_has_subscription( $current_user->ID, $product_id ,'active') ) ){ |
| 787 |
return true; |
| 788 |
} |
| 789 |
} |
| 790 |
return false; |
| 791 |
|
| 792 |
} |
| 793 |
return false; |
| 794 |
|
| 795 |
} |
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
/** |
| 800 |
* in plugin - check if global subscription model is enabled |
| 801 |
* |
| 802 |
* @since 3.12 |
| 803 |
* |
| 804 |
*/ |
| 805 |
public function wpstream_in_plugin_check_global_subscription_model($product_id) { |
| 806 |
|
| 807 |
// $selected_sub= get_post_meta($post->ID,'_wpstream_parent_sub',true); |
| 808 |
if( is_user_logged_in() && function_exists('wcs_user_has_subscription') ){ |
| 809 |
|
| 810 |
global $woocommerce; |
| 811 |
$current_user = wp_get_current_user(); |
| 812 |
|
| 813 |
$subscription_model = esc_html( get_option('wpstream_global_sub','')) ; |
| 814 |
$main_subscription = intval( get_option('wpstream_global_sub_id','')); |
| 815 |
|
| 816 |
if($subscription_model==1){ |
| 817 |
$selected_sub= get_post_meta($product_id,'_wpstream_parent_sub',true) ; |
| 818 |
|
| 819 |
if( is_array($selected_sub) ){ |
| 820 |
|
| 821 |
// we have per product sub |
| 822 |
foreach($selected_sub as $key=>$subscrition_id ): |
| 823 |
if( wcs_user_has_subscription( $current_user->ID, $subscrition_id ,'active') ) { |
| 824 |
return true; |
| 825 |
} |
| 826 |
endforeach; |
| 827 |
|
| 828 |
} else if($main_subscription!=0){ |
| 829 |
|
| 830 |
// if we have one main subscription |
| 831 |
if( wcs_user_has_subscription( $current_user->ID, $main_subscription ,'active') ) { |
| 832 |
return true; |
| 833 |
} |
| 834 |
} |
| 835 |
|
| 836 |
|
| 837 |
} |
| 838 |
return false; |
| 839 |
|
| 840 |
} |
| 841 |
// there is no woo subscription or user not logged in |
| 842 |
return false; |
| 843 |
} |
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
/** |
| 854 |
* |
| 855 |
* |
| 856 |
* |
| 857 |
* |
| 858 |
* check if the user bought the product and display the player - TO REDo |
| 859 |
* |
| 860 |
* @since 3.0.1 |
| 861 |
* returns html of the player |
| 862 |
* |
| 863 |
* |
| 864 |
* |
| 865 |
* |
| 866 |
* |
| 867 |
*/ |
| 868 |
public function wpstream_user_logged_in_product_already_bought($from_sh_id='') { |
| 869 |
global $product; |
| 870 |
$product_id = $product->get_id(); |
| 871 |
$current_user = wp_get_current_user(); |
| 872 |
if ( is_user_logged_in() ) { |
| 873 |
|
| 874 |
if($this->wpstream_check_if_player_can_dsplay($product_id) ){ |
| 875 |
|
| 876 |
echo '<div class="wpstream_player_wrapper "><div class="wpstream_player_container">'; |
| 877 |
|
| 878 |
$is_subscription_live_event = esc_html(get_post_meta($product_id,'_subscript_live_event',true)); |
| 879 |
$term_list = wp_get_post_terms($product_id, 'product_type'); |
| 880 |
|
| 881 |
|
| 882 |
if( $term_list[0]->name=='live_stream' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){ |
| 883 |
$this->wpstream_live_event_player($product_id); |
| 884 |
}else if( $term_list[0]->name=='video_on_demand' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='no' ) ){ |
| 885 |
$this->wpstream_video_on_demand_player($product_id); |
| 886 |
} |
| 887 |
echo '</div></div>'; |
| 888 |
}else{ |
| 889 |
|
| 890 |
|
| 891 |
$term_list = wp_get_post_terms($product_id, 'product_type'); |
| 892 |
if( $term_list[0]->name=='subscription' ){ |
| 893 |
if( !wcs_user_has_subscription( $current_user->ID, $product_id ,'active') ) { |
| 894 |
$this->wpstream_display_no_buy_message('nobuy',$product_id); |
| 895 |
} |
| 896 |
|
| 897 |
} |
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
} |
| 902 |
|
| 903 |
|
| 904 |
}else{ |
| 905 |
|
| 906 |
$this->wpstream_display_no_buy_message('nolog',$product_id); |
| 907 |
} |
| 908 |
} |
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
/** |
| 915 |
* |
| 916 |
* |
| 917 |
* check if the user bought the product and display the player - TO REDo |
| 918 |
* |
| 919 |
* @since 3.0.1 |
| 920 |
* returns html of the player |
| 921 |
*/ |
| 922 |
|
| 923 |
public function wpstream_chat_wrapper($product_id){ |
| 924 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/templates/wpstream_chat_template.php'; |
| 925 |
} |
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
/** |
| 935 |
* coonect to chat |
| 936 |
* |
| 937 |
* @since 1.12.2 |
| 938 |
* |
| 939 |
*/ |
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
public function wpstream_connect_to_chat($product_id){ |
| 944 |
$current_user = wp_get_current_user(); |
| 945 |
$userID = $current_user->ID; |
| 946 |
$user_login = $current_user->user_login; |
| 947 |
|
| 948 |
$key=''; |
| 949 |
|
| 950 |
$chat_url = get_post_meta($product_id,'chat_url',true); |
| 951 |
|
| 952 |
|
| 953 |
wp_enqueue_script( 'sockjs-0.3.min' ); |
| 954 |
wp_enqueue_script( 'emojione.min.js' ); |
| 955 |
wp_enqueue_script( "jquery-effects-core"); |
| 956 |
wp_enqueue_script( 'jquery.linkify.min.js'); |
| 957 |
wp_enqueue_script( 'ripples.min.js'); |
| 958 |
wp_enqueue_script( 'material.min.js'); |
| 959 |
wp_enqueue_script( 'chat.js'); |
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
wp_enqueue_style( 'chat.css'); |
| 964 |
wp_enqueue_style( 'ripples.css'); |
| 965 |
wp_enqueue_style( 'emojione.min.css'); |
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
if(!is_user_logged_in()){ |
| 971 |
$user_login=''; |
| 972 |
$chat_url=''; |
| 973 |
} |
| 974 |
|
| 975 |
|
| 976 |
print '<script type="text/javascript"> |
| 977 |
//<![CDATA[ |
| 978 |
jQuery(document).ready(function(){ |
| 979 |
username = "'.$user_login.'"; |
| 980 |
key="'.$key.'"; |
| 981 |
|
| 982 |
}); |
| 983 |
//]]> |
| 984 |
</script>'; |
| 985 |
|
| 986 |
} |
| 987 |
|
| 988 |
|
| 989 |
/** |
| 990 |
* display no buy Message |
| 991 |
* |
| 992 |
* @since 3.12.2 |
| 993 |
* |
| 994 |
*/ |
| 995 |
public function wpstream_display_no_buy_message($log,$product_id) { |
| 996 |
|
| 997 |
if($log=='sub_active'){ |
| 998 |
$message= esc_html( get_option('wpstream_subscription_active','Your Subscription is Active.')) ; |
| 999 |
echo '<div class="wpstream_player_wrapper no_buy"><div class="wpstream_player_container">'; |
| 1000 |
echo '<div class="wpstream_notice"> '.$message.'</div>'; |
| 1001 |
echo '</div></div>'; |
| 1002 |
return; |
| 1003 |
|
| 1004 |
}else if($log=='nolog'){ |
| 1005 |
$message= esc_html( get_option('wpstream_product_not_login','You must be logged in to watch this video.')) ; |
| 1006 |
}else{ |
| 1007 |
$message =esc_html( get_option('wpstream_product_not_bought','You did not yet purchase this item.')) ; |
| 1008 |
} |
| 1009 |
$subscription_model = esc_html( get_option('wpstream_global_sub','')) ; |
| 1010 |
if($subscription_model==1){ |
| 1011 |
$message =esc_html( get_option('wpstream_product_not_subscribe','You did not yet subscribe to this item.')); |
| 1012 |
} |
| 1013 |
|
| 1014 |
|
| 1015 |
if( get_post_type($product_id) == 'product' && $subscription_model==0 ){ |
| 1016 |
|
| 1017 |
$term_list = wp_get_post_terms($product_id, 'product_type'); |
| 1018 |
if( $term_list[0]->name=='video_on_demand' || $term_list[0]->name=='live_stream'){ |
| 1019 |
|
| 1020 |
echo '<div class="wpstream_player_wrapper no_buy"><div class="wpstream_player_container">'; |
| 1021 |
echo '<div class="wpstream_notice">'.$message.'</div>'; |
| 1022 |
echo '</div></div>'; |
| 1023 |
|
| 1024 |
} |
| 1025 |
|
| 1026 |
}else if( get_post_type($product_id) == 'product' && $subscription_model==1 ){ |
| 1027 |
echo '<div class="wpstream_player_wrapper no_buy"><div class="wpstream_player_container">'; |
| 1028 |
echo '<div class="wpstream_notice"> '.$message.'</div>'; |
| 1029 |
echo '</div></div>'; |
| 1030 |
} |
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
} |
| 1038 |
|
| 1039 |
|
| 1040 |
} |
| 1041 |
|