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