| 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 |
add_action( 'wp_ajax_wpstream_force_clear_transient', array($this,'wpstream_force_clear_transient') ); |
| 27 |
add_action('wp_ajax_nopriv_wpstream_force_clear_transient', array($this,'wpstream_force_clear_transient')); |
| 28 |
|
| 29 |
|
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
/** |
| 35 |
* clear status transients |
| 36 |
* |
| 37 |
* @author cretu |
| 38 |
*/ |
| 39 |
|
| 40 |
|
| 41 |
public function wpstream_force_clear_transient($event_id){ |
| 42 |
|
| 43 |
$transient_name = 'event_data_to_return_'.$event_id; |
| 44 |
delete_transient($transient_name); |
| 45 |
update_post_meta($event_id,'statsUrl',''); |
| 46 |
update_post_meta($event_id,'chatUrl',''); |
| 47 |
|
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
/** |
| 53 |
* check player status |
| 54 |
* |
| 55 |
* @author cretu |
| 56 |
*/ |
| 57 |
|
| 58 |
public function wpstream_player_check_status(){ |
| 59 |
$event_id = intval($_POST['event_id']); |
| 60 |
$transient_name = 'event_data_to_return_'.$event_id; |
| 61 |
$event_data_for_transient = get_transient( $transient_name ); |
| 62 |
|
| 63 |
if ( false === $event_data_for_transient || $event_data_for_transient=='' ) { //ws || $hls_to_return=='' |
| 64 |
|
| 65 |
$this->wpstream_request_hls_player_dynamic_data('',$event_id); |
| 66 |
$chatUrl = get_post_meta($event_id,'chatUrl',true); |
| 67 |
$statsUrl = get_post_meta($event_id,'statsUrl',true); |
| 68 |
$live_event_uri_final = get_post_meta($event_id,'hlsPlaybackUrl',true); |
| 69 |
$server_id = get_post_meta($event_id,'server_id', true ); |
| 70 |
|
| 71 |
$event_data_for_transient = array( |
| 72 |
'statsUrl' => $statsUrl, |
| 73 |
'chatUrl' => $chatUrl, |
| 74 |
'live_event_uri_final' => $live_event_uri_final, |
| 75 |
'server_id' => $server_id, |
| 76 |
); |
| 77 |
|
| 78 |
set_transient($transient_name,$event_data_for_transient,45); |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
// 1==2 && |
| 84 |
|
| 85 |
if( $event_data_for_transient['live_event_uri_final']!=''){ |
| 86 |
echo json_encode( array( |
| 87 |
'new'=>'2213', |
| 88 |
'started' => 'yes', |
| 89 |
'server_id' => $event_data_for_transient['server_id'], |
| 90 |
'event_id' => $event_id, |
| 91 |
'event_uri' => $event_data_for_transient['live_event_uri_final'], |
| 92 |
'live_conect_views' => $event_data_for_transient['statsUrl'], |
| 93 |
'chat_url' => $event_data_for_transient['chatUrl'], |
| 94 |
|
| 95 |
)); |
| 96 |
}else{ |
| 97 |
echo json_encode( array( |
| 98 |
'new'=>$event_data_for_transient, |
| 99 |
'started' => 'no', |
| 100 |
'server_id' => $event_data_for_transient['server_id'], |
| 101 |
'event_id' => $event_id, |
| 102 |
'event_uri' => '', |
| 103 |
'live_conect_views' => '', |
| 104 |
'chat_url' => '', |
| 105 |
|
| 106 |
)); |
| 107 |
$this->wpstream_force_clear_transient($event_id); |
| 108 |
} |
| 109 |
die(); |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
/** |
| 115 |
* Insert player in page |
| 116 |
* |
| 117 |
* @author cretu |
| 118 |
*/ |
| 119 |
public function wpstream_filter_the_title( $content ) { |
| 120 |
if( is_singular('wpstream_product')){ |
| 121 |
global $post; |
| 122 |
$args=array('id'=>$post->ID); |
| 123 |
$custom_content = $this->wpstream_insert_player_inpage($args); |
| 124 |
$content = '<div class="wpestream_inserted_player">'.$custom_content.'</div>'.$content; |
| 125 |
return $content; |
| 126 |
}else{ |
| 127 |
return $content; |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
/** |
| 132 |
* Insert player in page |
| 133 |
* |
| 134 |
* @author cretu |
| 135 |
*/ |
| 136 |
|
| 137 |
public function wpstream_insert_player_inpage($attributes, $content = null){ |
| 138 |
$product_id = ''; |
| 139 |
$return_string = ''; |
| 140 |
$attributes = shortcode_atts( |
| 141 |
array( |
| 142 |
'id' => 0, |
| 143 |
), $attributes) ; |
| 144 |
|
| 145 |
|
| 146 |
if ( isset($attributes['id']) ){ |
| 147 |
$product_id=$attributes['id']; |
| 148 |
} |
| 149 |
|
| 150 |
ob_start(); |
| 151 |
$this->wpstream_video_player_shortcode($product_id); |
| 152 |
$return_string= ob_get_contents(); |
| 153 |
ob_end_clean(); |
| 154 |
|
| 155 |
return $return_string; |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
/** |
| 162 |
* Video Player shortcode |
| 163 |
* |
| 164 |
* @author cretu |
| 165 |
*/ |
| 166 |
|
| 167 |
public function wpstream_video_player_shortcode($from_sh_id='') { |
| 168 |
|
| 169 |
if ( is_user_logged_in() ) { |
| 170 |
global $product; |
| 171 |
$current_user = wp_get_current_user(); |
| 172 |
$product_id = intval($from_sh_id); |
| 173 |
|
| 174 |
|
| 175 |
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' ){ |
| 176 |
global $product; |
| 177 |
echo '<div class="wpstream_player_wrapper wpstream_player_shortcode"><div class="wpstream_player_container">'; |
| 178 |
|
| 179 |
|
| 180 |
if( get_post_type($product_id) == 'wpstream_product' ){ |
| 181 |
|
| 182 |
$wpstream_product_type = esc_html(get_post_meta($product_id, 'wpstream_product_type', true)); |
| 183 |
if($wpstream_product_type==1){ |
| 184 |
$this->wpstream_live_event_player($product_id); |
| 185 |
} else if($wpstream_product_type==2 || $wpstream_product_type==3){ |
| 186 |
$this->wpstream_video_on_demand_player($product_id); |
| 187 |
} |
| 188 |
|
| 189 |
}else{ |
| 190 |
$term_list = wp_get_post_terms($product_id, 'product_type'); |
| 191 |
$is_subscription_live_event = esc_html(get_post_meta($product_id,'_subscript_live_event',true)); |
| 192 |
|
| 193 |
if( $term_list[0]->name=='live_stream' || ( $term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){ |
| 194 |
$this->wpstream_live_event_player($product_id); |
| 195 |
}else if( $term_list[0]->name=='video_on_demand' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='no' ) ){ |
| 196 |
$this->wpstream_video_on_demand_player($product_id); |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
}else{ |
| 203 |
$thumb_id = get_post_thumbnail_id($product_id); |
| 204 |
$thumb = wp_get_attachment_image_src($thumb_id,'medium_large'); |
| 205 |
|
| 206 |
echo '<div class="wpstream_player_wrapper wpstream_player_shortcode no_buy"><div class="wpstream_player_container">'; |
| 207 |
echo '<div class="wpstream_notice">'.__('You did not buy this product!','wpstream'). |
| 208 |
'</div><img src="'.$thumb[0].'" alt="product_thumb">'; |
| 209 |
} |
| 210 |
|
| 211 |
echo '</div></div>'; |
| 212 |
}else{ |
| 213 |
$product_id = intval($from_sh_id); |
| 214 |
if( get_post_type($product_id) == 'wpstream_product' ){ |
| 215 |
|
| 216 |
$wpstream_product_type = esc_html(get_post_meta($product_id, 'wpstream_product_type', true)); |
| 217 |
if($wpstream_product_type==1){ |
| 218 |
$this->wpstream_live_event_player($product_id); |
| 219 |
} else if($wpstream_product_type==2 || $wpstream_product_type==3){ |
| 220 |
$this->wpstream_video_on_demand_player($product_id); |
| 221 |
} |
| 222 |
|
| 223 |
} |
| 224 |
} |
| 225 |
} |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
/** |
| 233 |
* Live Event Player |
| 234 |
* |
| 235 |
* @author cretu |
| 236 |
*/ |
| 237 |
function remove_http($url) { |
| 238 |
$disallowed = array('http://', 'https://'); |
| 239 |
foreach($disallowed as $d) { |
| 240 |
if(strpos($url, $d) === 0) { |
| 241 |
return str_replace($d, '', $url); |
| 242 |
} |
| 243 |
} |
| 244 |
return $url; |
| 245 |
} |
| 246 |
|
| 247 |
|
| 248 |
/** |
| 249 |
* Live Event Player |
| 250 |
* |
| 251 |
* @author cretu |
| 252 |
*/ |
| 253 |
|
| 254 |
function wpstream_live_event_player($product_id){ |
| 255 |
$live_event_uri = get_post_meta($product_id,'live_event_uri',true); |
| 256 |
$api20_event_id = get_post_meta($product_id,'server_id',true); |
| 257 |
|
| 258 |
$thumb_id = get_post_thumbnail_id($product_id); |
| 259 |
$thumb = wp_get_attachment_image_src($thumb_id,'small'); |
| 260 |
|
| 261 |
$chatUrl= get_post_meta($product_id,'statsUrl',true); |
| 262 |
|
| 263 |
|
| 264 |
$live_event_uri_final = $this->wpstream_request_hls_player_dynamic('',$product_id);// buleala lu Gabi |
| 265 |
$now = time().rand(0,10); |
| 266 |
$live_conect_array = explode('live.streamer.wpstream.net',$live_event_uri_final); |
| 267 |
$live_conect_views = $live_conect_array[0].'live.streamer.wpstream.net'; |
| 268 |
$live_conect_views = $this->remove_http($live_conect_views); |
| 269 |
|
| 270 |
|
| 271 |
echo '<div class="wpstream_live_player_wrapper" data-now="'.$now.'" data-product-id="'.$product_id.'" id="wpstream_live_player_wrapper'.$now.'" > ' |
| 272 |
. '<div id="wpestream_live_counting" class="wpestream_live_counting"></div>'; |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
$show_wpstream_not_live_mess=' style="display:none;" '; |
| 278 |
if(trim($live_event_uri_final) ==''){ |
| 279 |
$show_wpstream_not_live_mess=''; |
| 280 |
}else{ |
| 281 |
print '<script type="text/javascript"> |
| 282 |
//<![CDATA[ |
| 283 |
jQuery(document).ready(function(){ |
| 284 |
wpstream_count_connect_plugin("wpstream_live_player_wrapper'.$now.'" ,"'.$chatUrl.'"); |
| 285 |
}); |
| 286 |
//]]> |
| 287 |
</script>'; |
| 288 |
} |
| 289 |
|
| 290 |
|
| 291 |
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>'; |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
echo' |
| 296 |
<video id="wpstream-video'.$now.'" poster="'.$thumb[0].'" class="video-js vjs-default-skin vjs-16-9" controls> |
| 297 |
<source |
| 298 |
src="'.$live_event_uri_final.'" |
| 299 |
type="application/x-mpegURL"> |
| 300 |
</video>'; |
| 301 |
|
| 302 |
print '<script type="text/javascript"> |
| 303 |
//<![CDATA[ |
| 304 |
jQuery(document).ready(function(){ |
| 305 |
wpstream_player_initialize("'.$now.'","'.$live_event_uri_final.'","'.$live_conect_views.'");'; |
| 306 |
|
| 307 |
if(trim($live_event_uri_final) !==''){ |
| 308 |
print 'wpstream_player_play("'.$now.'","'.$live_event_uri_final.'","'.$live_conect_views.'");'; |
| 309 |
} |
| 310 |
|
| 311 |
print' }); |
| 312 |
//]]> |
| 313 |
</script>'; |
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
print '</div>'; |
| 318 |
usleep (10000); |
| 319 |
|
| 320 |
} |
| 321 |
|
| 322 |
|
| 323 |
/** |
| 324 |
* Request dynamic data |
| 325 |
* |
| 326 |
* @author cretu |
| 327 |
*/ |
| 328 |
|
| 329 |
public function wpstream_request_hls_player_dynamic_data($server_id,$product_id){ |
| 330 |
|
| 331 |
$transient_name = 'event_data_to_return_'.$product_id; |
| 332 |
$event_data_to_return = get_transient( $transient_name ); |
| 333 |
|
| 334 |
if ( false === $event_data_to_return || $event_data_to_return=='' ) { //ws || $hls_to_return=='' |
| 335 |
$this->main->wpstream_live_connection->wpstream_check_event_status_front_player($product_id,$server_id); |
| 336 |
set_transient( $transient_name, 'something', 45 ); |
| 337 |
return; |
| 338 |
}else{ |
| 339 |
return ''; |
| 340 |
} |
| 341 |
|
| 342 |
} |
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
/** |
| 347 |
* HLS PLAYER |
| 348 |
* |
| 349 |
* @author cretu |
| 350 |
*/ |
| 351 |
public function wpstream_request_hls_player_dynamic($server_id,$product_id){ |
| 352 |
|
| 353 |
$transient_name = 'hls_to_return_'.$product_id; |
| 354 |
$hls_to_return = get_transient( $transient_name ); |
| 355 |
|
| 356 |
if ( false === $hls_to_return || $hls_to_return=='' ) { //ws || $hls_to_return=='' |
| 357 |
|
| 358 |
$token = $this->main->wpstream_live_connection->wpstream_get_token(); |
| 359 |
$values_array = array(); |
| 360 |
$values_array['server_id'] = $server_id; |
| 361 |
|
| 362 |
if($server_id==''){ |
| 363 |
$this->main->wpstream_live_connection->wpstream_check_event_status_front_player($product_id,$server_id); |
| 364 |
$server_id = get_post_meta($product_id,'server_id', true ); |
| 365 |
$values_array['server_id'] = $server_id; |
| 366 |
} |
| 367 |
|
| 368 |
|
| 369 |
if($server_id==''){ |
| 370 |
delete_transient($transient_name); |
| 371 |
return '';exit(); |
| 372 |
} |
| 373 |
|
| 374 |
$url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/api20-livestrem/ap20_get_player_hls_dynamic/?access_token=".$token; |
| 375 |
|
| 376 |
|
| 377 |
$arguments = array( |
| 378 |
'method' => 'GET', |
| 379 |
'timeout' => 45, |
| 380 |
'redirection' => 5, |
| 381 |
'httpversion' => '1.0', |
| 382 |
'blocking' => true, |
| 383 |
'headers' => array(), |
| 384 |
'body' => $values_array, |
| 385 |
'cookies' => array() |
| 386 |
); |
| 387 |
$response = wp_remote_post($url,$arguments); |
| 388 |
|
| 389 |
$received_data = json_decode( wp_remote_retrieve_body($response) ,true); |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
if( isset($response['response']['code']) && $response['response']['code']=='200'){ |
| 395 |
$hls_to_return = trim($received_data); |
| 396 |
|
| 397 |
|
| 398 |
set_transient( $transient_name, $hls_to_return, 60 ); |
| 399 |
return $hls_to_return; |
| 400 |
}else{ |
| 401 |
return 'failed connection'; |
| 402 |
} |
| 403 |
exit(); |
| 404 |
}else{ |
| 405 |
return $hls_to_return; |
| 406 |
} |
| 407 |
|
| 408 |
} |
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
/** |
| 413 |
* HLS PLAYER |
| 414 |
* |
| 415 |
* @author cretu |
| 416 |
*/ |
| 417 |
|
| 418 |
|
| 419 |
public function wpstream_request_hls_player($product_id){ |
| 420 |
|
| 421 |
$transient_name = 'hls_to_return_'.$product_id; |
| 422 |
$hls_to_return = get_transient( $transient_name ); |
| 423 |
|
| 424 |
if ( false === $hls_to_return || $hls_to_return=='' ) { |
| 425 |
|
| 426 |
$show_id = intval($product_id); |
| 427 |
$token = $this->main->wpstream_live_connection->wpstream_get_token(); |
| 428 |
$values_array = array(); |
| 429 |
$values_array['show_id'] = $show_id; |
| 430 |
|
| 431 |
$url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/ap20_get_player_hls/?access_token=".$token; |
| 432 |
|
| 433 |
|
| 434 |
$arguments = array( |
| 435 |
'method' => 'GET', |
| 436 |
'timeout' => 45, |
| 437 |
'redirection' => 5, |
| 438 |
'httpversion' => '1.0', |
| 439 |
'blocking' => true, |
| 440 |
'headers' => array(), |
| 441 |
'body' => $values_array, |
| 442 |
'cookies' => array() |
| 443 |
); |
| 444 |
$response = wp_remote_post($url,$arguments); |
| 445 |
|
| 446 |
$received_data = json_decode( wp_remote_retrieve_body($response) ,true); |
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
if( isset($response['response']['code']) && $response['response']['code']=='200'){ |
| 451 |
$hls_to_return = trim($received_data); |
| 452 |
set_transient( $transient_name, $hls_to_return, 60 ); |
| 453 |
return $hls_to_return = trim($received_data); |
| 454 |
}else{ |
| 455 |
return 'failed connection'; |
| 456 |
} |
| 457 |
exit(); |
| 458 |
}else{ |
| 459 |
return $hls_to_return; |
| 460 |
} |
| 461 |
|
| 462 |
} |
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
/** |
| 467 |
* VODPlayer uri details |
| 468 |
* |
| 469 |
* @author cretu |
| 470 |
*/ |
| 471 |
public function wpstream_video_on_demand_player_uri_request($product_id){ |
| 472 |
|
| 473 |
$wpstream_data_setup = ' data-setup="{}" '; |
| 474 |
|
| 475 |
/* free_video_type |
| 476 |
* 1 - free live channel |
| 477 |
* 2 - free video encrypted |
| 478 |
* 3 - free video -not encrypted |
| 479 |
*/ |
| 480 |
$free_video_type = intval( get_post_meta($product_id, 'wpstream_product_type', true)); |
| 481 |
|
| 482 |
|
| 483 |
if($free_video_type==2 || get_post_type($product_id)=='product' ){ |
| 484 |
|
| 485 |
/* IF vide is encrypted- readed from vod,streaner |
| 486 |
*/ |
| 487 |
|
| 488 |
$video_type = 'application/x-mpegURL'; |
| 489 |
$video_path = get_post_meta($product_id,'_movie_url',true); |
| 490 |
if(get_post_type($product_id)=='wpstream_product'){ |
| 491 |
$video_path = esc_html(get_post_meta($product_id, 'wpstream_free_video', true)); |
| 492 |
} |
| 493 |
|
| 494 |
$username = esc_html ( get_option('wpstream_api_username','') ); |
| 495 |
if (filter_var($username, FILTER_VALIDATE_EMAIL)) { |
| 496 |
$username = $this->wpstream_retrive_username(); |
| 497 |
} |
| 498 |
|
| 499 |
if(strpos($username,'@')!=false){ |
| 500 |
$username_array= explode('@', $username); |
| 501 |
$username=$username_array[0]; |
| 502 |
} |
| 503 |
|
| 504 |
$video_path_final = 'https://vod.streamer.wpstream.net/'.$username.'/'.$video_path.'/index.m3u8?'.get_site_url(); |
| 505 |
if(!is_ssl()){ |
| 506 |
$video_path_final = 'http://vod.streamer.wpstream.net/'.$username.'/'.$video_path.'/index.m3u8?'.get_site_url(); |
| 507 |
} |
| 508 |
|
| 509 |
}else if($free_video_type==3){ |
| 510 |
|
| 511 |
/* Video is unecrypted - read from local or youtube / vimeo |
| 512 |
*/ |
| 513 |
|
| 514 |
$video_type = 'video/mp4'; |
| 515 |
$video_path_final=esc_html(get_post_meta($product_id, 'wpstream_free_video_external', true)); |
| 516 |
|
| 517 |
if (strpos($video_path_final, 'www.youtube') !== false) { |
| 518 |
$wpstream_data_setup= ' data-setup=\'{ "techOrder": ["youtube"], "sources": [{ "type": "video/youtube", "src": "'.$video_path_final.'"}] }\' '; |
| 519 |
$video_path_final=''; |
| 520 |
} |
| 521 |
if (strpos($video_path_final, 'vimeo.com') !== false) { |
| 522 |
$wpstream_data_setup= ' data-setup=\'{"techOrder": ["vimeo"], "sources": [{ "type": "video/vimeo", "src": "'.$video_path_final.'"}], "vimeo": { "color": "#fbc51b"} }\' '; |
| 523 |
$video_path_final=''; |
| 524 |
} |
| 525 |
|
| 526 |
} |
| 527 |
|
| 528 |
$return_array=array(); |
| 529 |
$return_array['video_path_final'] = $video_path_final; |
| 530 |
$return_array['wpstream_data_setup']= $wpstream_data_setup; |
| 531 |
$return_array['video_type'] = $video_type; |
| 532 |
return $return_array; |
| 533 |
} |
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
/** |
| 538 |
* VODPlayer url |
| 539 |
* |
| 540 |
* @author cretu |
| 541 |
*/ |
| 542 |
|
| 543 |
public function wpstream_video_on_demand_player($product_id){ |
| 544 |
|
| 545 |
$uri_details = $this->wpstream_video_on_demand_player_uri_request($product_id); |
| 546 |
$video_path_final = $uri_details['video_path_final']; |
| 547 |
$wpstream_data_setup = $uri_details['wpstream_data_setup']; |
| 548 |
$video_type = $uri_details['video_type']; |
| 549 |
|
| 550 |
$thumb_id = get_post_thumbnail_id($product_id); |
| 551 |
$thumb = wp_get_attachment_image_src($thumb_id,'small'); |
| 552 |
|
| 553 |
echo '<video id="wpstream-video'.time().'" class="video-js vjs-default-skin vjs-16-9 kuk wpstream_video_on_demand" controls preload="auto" |
| 554 |
poster="'.$thumb[0].'" '.$wpstream_data_setup.'> |
| 555 |
|
| 556 |
<source src="'.trim($video_path_final).'" type="'.$video_type.'"> |
| 557 |
<p class="vjs-no-js"> |
| 558 |
To view this video please enable JavaScript, and consider upgrading to a web browser that |
| 559 |
<a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a> |
| 560 |
</p> |
| 561 |
</video>'; |
| 562 |
|
| 563 |
} |
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
/** |
| 571 |
* Retreive username for vod path |
| 572 |
* |
| 573 |
* @author cretu |
| 574 |
*/ |
| 575 |
private function wpstream_retrive_username(){ |
| 576 |
$token = $this->main->wpstream_live_connection->wpstream_get_token(); |
| 577 |
|
| 578 |
$url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/return_login/?access_token=".$token; |
| 579 |
$arguments = array( |
| 580 |
'method' => 'GET', |
| 581 |
'timeout' => 45, |
| 582 |
'redirection' => 5, |
| 583 |
'httpversion' => '1.0', |
| 584 |
'blocking' => true, |
| 585 |
'headers' => array(), |
| 586 |
'cookies' => array() |
| 587 |
); |
| 588 |
$response = wp_remote_post($url,$arguments); |
| 589 |
$received_data = json_decode( wp_remote_retrieve_body($response) ,true); |
| 590 |
if( isset($response['response']['code']) && $response['response']['code']=='200'){ |
| 591 |
return ($received_data); die(); |
| 592 |
}else{ |
| 593 |
print 'Failed to conbect media server'; |
| 594 |
die(); |
| 595 |
} |
| 596 |
} |
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
/** |
| 603 |
* check if the user bought the product and display the player - TO REDo |
| 604 |
* |
| 605 |
* @since 3.0.1 |
| 606 |
* returns html of the player |
| 607 |
*/ |
| 608 |
public function wpstream_user_logged_in_product_already_bought($from_sh_id='') { |
| 609 |
|
| 610 |
if ( is_user_logged_in() ) { |
| 611 |
global $product; |
| 612 |
$current_user = wp_get_current_user(); |
| 613 |
$product_id = $product->get_id(); |
| 614 |
|
| 615 |
|
| 616 |
if ( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product_id) || ( function_exists('wcs_user_has_subscription') && wcs_user_has_subscription( $current_user->ID, $product_id ,'active') ) ){ |
| 617 |
|
| 618 |
|
| 619 |
echo '<div class="wpstream_player_wrapper"><div class="wpstream_player_container">'; |
| 620 |
|
| 621 |
$is_subscription_live_event = esc_html(get_post_meta($product_id,'_subscript_live_event',true)); |
| 622 |
$term_list = wp_get_post_terms($product_id, 'product_type'); |
| 623 |
|
| 624 |
|
| 625 |
if( $term_list[0]->name=='live_stream' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){ |
| 626 |
$this->wpstream_live_event_player($product_id); |
| 627 |
}else if( $term_list[0]->name=='video_on_demand' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='no' ) ){ |
| 628 |
$this->wpstream_video_on_demand_player($product_id); |
| 629 |
} |
| 630 |
|
| 631 |
}else{ |
| 632 |
echo '<div class="wpstream_player_wrapper no_buy"><div class="wpstream_player_container">'; |
| 633 |
echo '<div class="wpstream_notice">'.__('You did not buy this product!','wpstream').'</div>'; |
| 634 |
} |
| 635 |
|
| 636 |
echo '</div></div>'; |
| 637 |
} |
| 638 |
} |
| 639 |
|
| 640 |
/** |
| 641 |
* check if the user bought the product and display the player - TO REDo |
| 642 |
* |
| 643 |
* @since 3.0.1 |
| 644 |
* returns html of the player |
| 645 |
*/ |
| 646 |
|
| 647 |
public function wpstream_chat_wrapper($product_id){ |
| 648 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/templates/wpstream_chat_template.php'; |
| 649 |
} |
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
public function wpstream_connect_to_chat($product_id){ |
| 654 |
$current_user = wp_get_current_user(); |
| 655 |
$userID = $current_user->ID; |
| 656 |
$user_login = $current_user->user_login; |
| 657 |
|
| 658 |
// |
| 659 |
// if(current_user_can('administrator')){ |
| 660 |
// $key = "3vjajxVV4B4Ylx259Z6u"; |
| 661 |
// }else{ |
| 662 |
// $key = "3vjajxVV4B4YIx259Z6u"; |
| 663 |
// } |
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
$chatUrl = get_post_meta($product_id,'chatUrl',true); |
| 668 |
|
| 669 |
|
| 670 |
wp_enqueue_script( 'sockjs-0.3.min' ); |
| 671 |
wp_enqueue_script( 'emojione.min.js' ); |
| 672 |
wp_enqueue_script( "jquery-effects-core"); |
| 673 |
wp_enqueue_script( 'jquery.linkify.min.js'); |
| 674 |
wp_enqueue_script( 'ripples.min.js'); |
| 675 |
wp_enqueue_script( 'material.min.js'); |
| 676 |
wp_enqueue_script( 'chat.js'); |
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
wp_enqueue_style( 'chat.css'); |
| 681 |
wp_enqueue_style( 'ripples.css'); |
| 682 |
wp_enqueue_style( 'emojione.min.css'); |
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
if(!is_user_logged_in()){ |
| 688 |
$user_login=''; |
| 689 |
$chatUrl=''; |
| 690 |
} |
| 691 |
// |
| 692 |
// wp_localize_script('chat.js', 'chat_vars', |
| 693 |
// array( |
| 694 |
// 'link'=>esc_html($chatUrl) |
| 695 |
// ) |
| 696 |
// ); |
| 697 |
|
| 698 |
|
| 699 |
print '<script type="text/javascript"> |
| 700 |
//<![CDATA[ |
| 701 |
jQuery(document).ready(function(){ |
| 702 |
username = "'.$user_login.'"; |
| 703 |
key="'.$key.'"; |
| 704 |
connect("'.$chatUrl.'"); |
| 705 |
}); |
| 706 |
//]]> |
| 707 |
</script>'; |
| 708 |
|
| 709 |
} |
| 710 |
} |
| 711 |
|