PluginProbe
WpStream – Live Streaming, Video on Demand, Pay Per View / 3.1.8
WpStream – Live Streaming, Video on Demand, Pay Per View v3.1.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 +163 -789 4.4.5 → 3.1.8 View file →
@@ -17,83 +17,13 @@
17 17 $this->main = $plugin_main;
18 18
19 19 add_filter( 'the_content',array($this, 'wpstream_filter_the_title') );
20 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 21 }
30 22
31 23
32 -
33 -
34 24
35 -
36 - /**
37 - *
38 - * edited 4.0
39 - *
40 - * check player status
41 - *
42 - * @author cretu
43 - */
44 25
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 26 /**
97 27 * Insert player in page
98 28 *
99 29 * @author cretu
@@ -98,9 +28,9 @@
98 28 *
99 29 * @author cretu
100 30 */
101 31 public function wpstream_filter_the_title( $content ) {
102 - if( is_singular('wpstream_product') || is_singular('wpstream_product_vod') ){
32 + if( is_singular('wpstream_product')){
103 33 global $post;
104 34 $args=array('id'=>$post->ID);
105 35 $custom_content = $this->wpstream_insert_player_inpage($args);
106 36 $content = '<div class="wpestream_inserted_player">'.$custom_content.'</div>'.$content;
@@ -127,16 +57,11 @@
127 57
128 58 if ( isset($attributes['id']) ){
129 59 $product_id=$attributes['id'];
130 60 }
131 -
132 - if(intval($product_id)==0){
133 - $product_id= $this->wpstream_player_retrive_first_id();
134 - }
135 61
136 62 ob_start();
137 -
138 - $this->wpstream_video_player_shortcode($product_id);
63 + $this->wpstream_video_player_shortcode($product_id);
139 64 $return_string= ob_get_contents();
140 65 ob_end_clean();
141 66
142 67 return $return_string;
@@ -152,32 +77,30 @@
152 77 */
153 78
154 79 public function wpstream_video_player_shortcode($from_sh_id='') {
155 80
156 -
157 -
158 81 if ( is_user_logged_in() ) {
159 82 global $product;
160 83 $current_user = wp_get_current_user();
161 84 $product_id = intval($from_sh_id);
162 - $term_list = wp_get_post_terms($product_id, 'product_type');
163 -
164 -
165 85
166 86
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' ){
87 + 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' ){
170 88 global $product;
171 89 echo '<div class="wpstream_player_wrapper wpstream_player_shortcode"><div class="wpstream_player_container">';
172 90
173 91
174 92 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);
93 +
94 + $wpstream_product_type = esc_html(get_post_meta($product_id, 'wpstream_product_type', true));
95 + if($wpstream_product_type==1){
96 + $this->wpstream_live_event_player($product_id);
97 + } else if($wpstream_product_type==2 || $wpstream_product_type==3){
98 + $this->wpstream_video_on_demand_player($product_id);
99 + }
100 +
178 101 }else{
179 -
102 + $term_list = wp_get_post_terms($product_id, 'product_type');
180 103 $is_subscription_live_event = esc_html(get_post_meta($product_id,'_subscript_live_event',true));
181 104
182 105 if( $term_list[0]->name=='live_stream' || ( $term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){
183 106 $this->wpstream_live_event_player($product_id);
@@ -186,79 +109,31 @@
186 109 }
187 110 }
188 111
189 112
190 - echo '</div></div>';
113 +
191 114 }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 - }
115 + $thumb_id = get_post_thumbnail_id($product_id);
116 + $thumb = wp_get_attachment_image_src($thumb_id,'medium_large');
117 +
118 + echo '<div class="wpstream_player_wrapper wpstream_player_shortcode no_buy"><div class="wpstream_player_container">';
119 + echo '<div class="wpstream_notice">'.__('You did not buy this product!','wpstream').
120 + '</div><img src="'.$thumb[0].'" alt="product_thumb">';
198 121 }
199 122
200 -
123 + echo '</div></div>';
201 124 }else{
202 -
203 125 $product_id = intval($from_sh_id);
204 126 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 127
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);
128 + $wpstream_product_type = esc_html(get_post_meta($product_id, 'wpstream_product_type', true));
129 + if($wpstream_product_type==1){
130 + $this->wpstream_live_event_player($product_id);
131 + } else if($wpstream_product_type==2 || $wpstream_product_type==3){
132 + $this->wpstream_video_on_demand_player($product_id);
241 133 }
242 - }
243 134
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 135 }
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 136 }
262 137 }
263 138
264 139
@@ -264,8 +139,9 @@
264 139
265 140
266 141
267 142
143 +
268 144 /**
269 145 * Live Event Player
270 146 *
271 147 * @author cretu
@@ -278,114 +154,47 @@
278 154 }
279 155 }
280 156 return $url;
281 157 }
282 -
283 - /**
284 - * Get event settings
285 - *
286 - * @author cretu
287 - */
288 158
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 159
299 -
300 -
301 160 /**
302 - * edited in 4.0
303 - *
304 161 * Live Event Player
305 162 *
306 163 * @author cretu
307 164 */
308 165
309 - function wpstream_live_event_player($channel_id,$poster_show='',$use_chat=''){
166 + function wpstream_live_event_player($product_id){
167 + $live_event_uri = get_post_meta($product_id,'live_event_uri',true);
168 + $thumb_id = get_post_thumbnail_id($product_id);
169 + $thumb = wp_get_attachment_image_src($thumb_id,'small');
170 + $live_event_uri_final = $this->wpstream_request_hls_player($product_id);
171 + $now = time().rand(0,10);
172 + $live_conect_array = explode('live.streamer.wpstream.net',$live_event_uri_final);
173 + $live_conect_views = $live_conect_array[0].'live.streamer.wpstream.net';
174 + $live_conect_views = $this->remove_http($live_conect_views);
310 175
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 176
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 = '';
177 + echo '
178 +
179 + <div class="wpstream_live_player_wrapper" id="wpstream_live_player_wrapper'.$now.'" > <div id="wpestream_live_counting" class="wpestream_live_counting"></div>';
180 +
181 + if(trim($live_event_uri_final)==''){
182 + print '<div class="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>';
183 + }else{
184 + print '<script type="text/javascript">
185 + //<![CDATA[
186 + jQuery(document).ready(function(){
187 + wpstream_count_connect_plugin("wpstream_live_player_wrapper'.$now.'" ,"'.$live_conect_views.'");
188 + });
189 + //]]>
190 + </script>';
191 + }
321 192
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 193 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.'>
194 + <video id="wpstream-video'.$now.'" poster="'.$thumb[0].'" class="video-js vjs-default-skin vjs-16-9" controls>
386 195 <source
387 - src="'.$hls_playback_url.'"
196 + src="'.$live_event_uri_final.'"
388 197 type="application/x-mpegURL">
389 198 </video>';
390 199
391 200 print '<script type="text/javascript">
@@ -390,33 +199,14 @@
390 199
391 200 print '<script type="text/javascript">
392 201 //<![CDATA[
393 202 jQuery(document).ready(function(){
394 - wpstream_player_initialize("'.$now.'","'.$hls_playback_url.'","'.$live_conect_views.'","'.$autoplay.'");';
395 - print'});
203 + wpstream_player_initialize("'.$now.'","'.$live_event_uri_final.'","'.$live_conect_views.'");
204 + });
396 205 //]]>
397 206 </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 -
207 +
208 + print '</div>';
419 209 usleep (10000);
420 210
421 211 }
422 212
@@ -421,222 +211,68 @@
421 211 }
422 212
423 213
424 214
425 - /**
426 - *
427 - * Edited in 4.0
428 - *
429 - *
430 - * Live Event Player
431 - *
432 - * @author cretu
433 - */
215 + /**
216 + * HLS PLAYER
217 + *
218 + * @author cretu
219 + */
434 220
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 221
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);
222 + public function wpstream_request_hls_player($product_id){
456 223
457 - }
458 - if(isset($event_status['chat_url'])){
459 - $chat_url =$event_status['chat_url'];
460 - }
461 -
462 - }else{
463 - // event not live
464 - }
224 + $transient_name = 'hls_to_return_'.$product_id;
225 + $hls_to_return = get_transient( $transient_name );
465 226
227 + if ( false === $hls_to_return ) {
466 228
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>';
229 + $show_id = intval($product_id);
230 + $token = $this->main->wpstream_live_connection->wpstream_get_token();
231 + $values_array = array();
232 + $values_array['show_id'] = $show_id;
505 233
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);
234 + $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/get_player_hls/?access_token=".$token;
536 235
537 - }
538 236
237 + $arguments = array(
238 + 'method' => 'GET',
239 + 'timeout' => 45,
240 + 'redirection' => 5,
241 + 'httpversion' => '1.0',
242 + 'blocking' => true,
243 + 'headers' => array(),
244 + 'body' => $values_array,
245 + 'cookies' => array()
246 + );
247 + $response = wp_remote_post($url,$arguments);
248 + $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
539 249
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 '';
250 + if( isset($response['response']['code']) && $response['response']['code']=='200'){
251 + $hls_to_return = trim($received_data);
252 + set_transient( $transient_name, $hls_to_return, 120 );
253 + return $hls_to_return = trim($received_data);
254 + }else{
255 + return 'failed connection';
256 + }
257 + exit();
258 + }else{
259 + return $hls_to_return;
553 260 }
554 -
555 - $transient_name = 'wpstream_video_on_demand_'.$video_name;
556 - $hls_to_return = get_transient( $transient_name );
557 - $hls_to_return = false;
558 261
559 -
560 - if($hls_to_return==false){
561 -
562 - $access_token = $this->main->wpstream_live_connection->wpstream_get_token();
563 - $url = 'video/info';
262 + }
564 263
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 264
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 265
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 266 /**
633 - * VODPlayer uri details
267 + * VODPlayer
634 268 *
635 269 * @author cretu
636 270 */
637 - public function wpstream_video_on_demand_player_uri_request($product_id){
638 -
271 +
272 + public function wpstream_video_on_demand_player($product_id){
273 + $thumb_id = get_post_thumbnail_id($product_id);
274 + $thumb = wp_get_attachment_image_src($thumb_id,'small');
639 275 $wpstream_data_setup = ' data-setup="{}" ';
640 276
641 277 /* free_video_type
642 278 * 1 - free live channel
@@ -642,28 +278,38 @@
642 278 * 1 - free live channel
643 279 * 2 - free video encrypted
644 280 * 3 - free video -not encrypted
645 281 */
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' ){
282 + $free_video_type = intval( get_post_meta($product_id, 'wpstream_product_type', true));
283 +
284 +
285 + if($free_video_type==2 || get_post_type($product_id)=='product' ){
650 286
651 - /*
652 - * IF vide is encrypted- readed from vod,streaner
653 - *
654 - */
655 -
287 + /* IF vide is encrypted- readed from vod,streaner
288 + */
656 289
657 290 $video_type = 'application/x-mpegURL';
658 291 $video_path = get_post_meta($product_id,'_movie_url',true);
659 - if(get_post_type($product_id)=='wpstream_product_vod'){
292 + if(get_post_type($product_id)=='wpstream_product'){
660 293 $video_path = esc_html(get_post_meta($product_id, 'wpstream_free_video', true));
661 294 }
662 - $video_path_final = $this->wpstream_request_video_on_demand_hls_player($video_path,$product_id);
663 295
296 + $username = esc_html ( get_option('wpstream_api_username','') );
297 + if (filter_var($username, FILTER_VALIDATE_EMAIL)) {
298 + $username = $this->wpstream_retrive_username();
299 + }
300 +
301 + if(strpos($username,'@')!=false){
302 + $username_array= explode('@', $username);
303 + $username=$username_array[0];
304 + }
305 +
306 + $video_path_final = 'https://vod.streamer.wpstream.net/'.$username.'/'.$video_path.'/index.m3u8?'.get_site_url();
307 + if(!is_ssl()){
308 + $video_path_final = 'http://vod.streamer.wpstream.net/'.$username.'/'.$video_path.'/index.m3u8?'.get_site_url();
309 + }
664 310
665 - }else if( is_singular('wpstream_product_vod') && $free_video_type==3 ){
311 + }else if($free_video_type==3){
666 312
667 313 /* Video is unecrypted - read from local or youtube / vimeo
668 314 */
669 315
@@ -679,203 +325,74 @@
679 325 $video_path_final='';
680 326 }
681 327
682 328 }
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 329
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 - }
330 + echo '<video id="wpstream-video'.time().'" class="video-js vjs-default-skin vjs-16-9 kuk wpstream_video_on_demand" controls preload="auto"
331 + poster="'.$thumb[0].'" '.$wpstream_data_setup.'>
714 332
715 - $hlsDecryptionKey = get_post_meta($product_id,'hlsDecryptionKey',true);
716 - $hlsDecryptionKeyIndex = get_post_meta($product_id,'hlsDecryptionKeyIndex',true);
717 -
333 + <source src="'.trim($video_path_final).'" type="'.$video_type.'">
334 + <p class="vjs-no-js">
335 + To view this video please enable JavaScript, and consider upgrading to a web browser that
336 + <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a>
337 + </p>
338 + </video>';
718 339
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 340 }
742 341
743 342
744 343
745 -
746 -
747 -
748 344 /**
749 - *
750 - * edited 4.0
751 - *
752 345 * Retreive username for vod path
753 346 *
754 347 * @author cretu
755 348 */
756 349 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 - }
350 + $token = $this->main->wpstream_live_connection->wpstream_get_token();
351 +
352 + $url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/return_login/?access_token=".$token;
353 + $arguments = array(
354 + 'method' => 'GET',
355 + 'timeout' => 45,
356 + 'redirection' => 5,
357 + 'httpversion' => '1.0',
358 + 'blocking' => true,
359 + 'headers' => array(),
360 + 'cookies' => array()
361 + );
362 + $response = wp_remote_post($url,$arguments);
363 + $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
364 + if( isset($response['response']['code']) && $response['response']['code']=='200'){
365 + return ($received_data); die();
366 + }else{
367 + print 'Failed to conbect media server';
368 + die();
789 369 }
790 - return false;
791 -
792 - }
793 - return false;
794 -
795 370 }
796 371
797 372
798 373
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 374
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 375
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 - *
376 + /**
858 377 * check if the user bought the product and display the player - TO REDo
859 378 *
860 379 * @since 3.0.1
861 380 * returns html of the player
862 - *
863 - *
864 - *
865 - *
866 - *
867 381 */
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();
382 + public function wpstream_user_logged_in_product_already_bought($from_sh_id='') {
383 +
872 384 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">';
385 + global $product;
386 + $current_user = wp_get_current_user();
387 + $product_id = $product->get_id();
877 388
389 +
390 + 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') ) ){
391 +
392 +
393 + echo '<div class="wpstream_player_wrapper"><div class="wpstream_player_container">';
394 +
878 395 $is_subscription_live_event = esc_html(get_post_meta($product_id,'_subscript_live_event',true));
879 396 $term_list = wp_get_post_terms($product_id, 'product_type');
880 397
881 398
@@ -883,158 +400,15 @@
883 400 $this->wpstream_live_event_player($product_id);
884 401 }else if( $term_list[0]->name=='video_on_demand' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='no' ) ){
885 402 $this->wpstream_video_on_demand_player($product_id);
886 403 }
887 - echo '</div></div>';
404 +
888 405 }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 -
406 + echo '<div class="wpstream_player_wrapper no_buy"><div class="wpstream_player_container">';
407 + echo '<div class="wpstream_notice">'.__('You did not buy this product!','wpstream').'</div>';
901 408 }
902 409
903 -
904 - }else{
905 -
906 - $this->wpstream_display_no_buy_message('nolog',$product_id);
410 + echo '</div></div>';
907 411 }
908 412 }
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 413
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 414 }