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