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
wpstream / public / class-wpstream-public.php

class-wpstream-public.php in WpStream – Live Streaming, Video on Demand, Pay Per View 3.8, at public/class-wpstream-public.php

1,156 lines 42.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The public-facing functionality of the plugin.
5 *
6 * @link http://wpstream.net
7 * @since 3.0.1
8 *
9 * @package Wpstream
10 * @subpackage Wpstream/public
11 */
12
13 /**
14 * The public-facing functionality of the plugin.
15 *
16 * Defines the plugin name, version, and two examples hooks for how to
17 * enqueue the public-facing stylesheet and JavaScript.
18 *
19 * @package Wpstream
20 * @subpackage Wpstream/public
21 * @author wpstream <office@wpstream.net>
22 */
23 class Wpstream_Public {
24
25
26
27 /**
28 * Store plugin main class to allow public access.
29 *
30 * @since 20180622
31 * @var object The main class.
32 */
33 public $main;
34 /**
35 * The ID of this plugin.
36 *
37 * @since 3.0.1
38 * @access private
39 * @var string $plugin_name The ID of this plugin.
40 */
41 private $plugin_name;
42
43 /**
44 * The version of this plugin.
45 *
46 * @since 3.0.1
47 * @access private
48 * @var string $version The current version of this plugin.
49 */
50 private $version;
51
52 /**
53 * Initialize the class and set its properties.
54 *
55 * @since 3.0.1
56 * @param string $plugin_name The name of the plugin.
57 * @param string $version The version of this plugin.
58 */
59 public function __construct( $plugin_name, $version ,$plugin_main) {
60 $this->main = $plugin_main;
61 $this->plugin_name = $plugin_name;
62 $this->version = $version;
63
64 }
65
66 /**
67 * Register the stylesheets for the public-facing side of the site.
68 *
69 * @since 3.0.1
70 */
71 public function enqueue_styles() {
72
73 wp_enqueue_style('wpstream-style', plugin_dir_url( __FILE__ ) .'/css/wpstream_style.css',array(), WPSTREAM_PLUGIN_VERSION, 'all' );
74 wp_enqueue_style('video-js.min', plugin_dir_url( __FILE__ ).'/css/video-js.min.css', array(), WPSTREAM_PLUGIN_VERSION, 'all');
75 wp_enqueue_style('videojs-wpstream-player', plugin_dir_url( __FILE__ ).'/css/videojs-wpstream.css', array(), WPSTREAM_PLUGIN_VERSION, 'all');
76 }
77
78 /**
79 * Register the JavaScript for the public-facing side of the site.
80 *
81 * @since 3.0.1
82 */
83 public function enqueue_scripts() {
84
85
86 wp_enqueue_script('video.min', 'https://vjs.zencdn.net/7.8.4/video.js', WPSTREAM_PLUGIN_VERSION, false);
87 wp_enqueue_script('youtube.min', plugin_dir_url( __FILE__ ).'js/youtube.min.js',array('video.min'), WPSTREAM_PLUGIN_VERSION, false);
88 wp_enqueue_script('videojs-vimeo.min', plugin_dir_url( __FILE__ ).'js/videojs-vimeo.min.js',array('video.min'), WPSTREAM_PLUGIN_VERSION, false);
89 wp_enqueue_script('wpstream-player', plugin_dir_url( __FILE__ ).'js/wpstream-player.js',array('video.min'), WPSTREAM_PLUGIN_VERSION, false);
90 wp_enqueue_script('sldp-v2.12.1.min', plugin_dir_url( __FILE__ ).'js/sldp-v2.12.1.min.js',array(), WPSTREAM_PLUGIN_VERSION, false);
91
92 wp_localize_script('wpstream-player', 'wpstream_player_vars',
93 array(
94 'admin_url' => get_admin_url(),
95 'chat_not_connected' => esc_html__('Inactive Channel - Chat is disabled.','wpstream'),
96 'server_up' => esc_html__('The live stream is paused and may resume shortly.','wpstream')
97 )
98 );
99
100 wp_enqueue_script( 'jquery-ui-autocomplete' );
101 wp_enqueue_script( "jquery-effects-core");
102
103 wp_register_script( 'sockjs-0.3.min', plugin_dir_url( __FILE__ ) . '/chat_lib/sockjs-0.3.min.js', array('jquery'), true );
104 wp_register_script( 'emojione.min.js',plugin_dir_url( __FILE__ ). '/chat_lib/emojione.min.js', array('jquery'), true );
105
106 wp_register_script( 'jquery.linkify.min.js', plugin_dir_url( __FILE__ ). '/chat_lib/jquery.linkify.min.js', array('jquery'), true );
107 wp_register_script( 'ripples.min.js',plugin_dir_url( __FILE__ ). '/chat_lib/ripples.min.js', array('jquery'), true );
108 wp_register_script( 'material.min.js"', plugin_dir_url( __FILE__ ). '/chat_lib/material.min.js', array('jquery'), true );
109 wp_register_script( 'chat.js', plugin_dir_url( __FILE__ ). '/chat_lib/chat.js', array('jquery'), true );
110
111
112
113 wp_register_style( 'chat.css',plugin_dir_url( __FILE__ ).'/chat_lib/css/chat.css', array(), '1.0', 'all');
114 wp_register_style( 'ripples.css',plugin_dir_url( __FILE__ ).'/chat_lib/css/ripples.css', array(), '1.0', 'all');
115 wp_register_style( 'emojione.min.css',plugin_dir_url( __FILE__ ).'/chat_lib/css/emojione.min.css', array(), '1.0', 'all');
116
117
118
119 wp_enqueue_script('wpstream-start-streaming', plugin_dir_url( __FILE__ ) .'js/start_streaming.js',array(), WPSTREAM_PLUGIN_VERSION, true);
120 wp_localize_script('wpstream-start-streaming', 'wpstream_start_streaming_vars',
121 array(
122 'admin_url' => get_admin_url(),
123 'loading_url' => WPSTREAM_PLUGIN_DIR_URL.'/img/loading.gif',
124 'download_mess' => esc_html__('Click to download!','wpstream'),
125 'uploading' => esc_html('We are uploading your file.Do not close this window!','wpstream'),
126 'upload_complete2' => esc_html('Upload Complete! You can upload another file!','wpstream'),
127 'not_accepted' => esc_html('The file is not an accepted video format','wpstream'),
128 'upload_complete' => esc_html('Upload Complete!','wpstream'),
129 'no_band' => esc_html('Not enough bandwidth.','wpsteam'),
130 'no_band_no_store' => esc_html('Not enough bandwidth or storage.','wpsteam')
131
132 ));
133
134
135 wp_enqueue_style( 'wpstream_front_style', plugin_dir_url( __DIR__ ) . 'admin/css/wpstream-admin.css', array(), WPSTREAM_PLUGIN_VERSION, 'all' );
136
137 }
138
139
140
141 /**
142 * add custom end points for woocomerce
143 *
144 * @since 3.0.1
145 * @return nothing
146 */
147 public function wpstream_my_custom_endpoints() {
148 add_rewrite_endpoint( 'video-list', EP_ROOT | EP_PAGES );
149 add_rewrite_endpoint( 'event-list', EP_ROOT | EP_PAGES );
150 }
151
152 /**
153 * add custom query vars
154 *
155 * @since 3.0.1
156 * @return nothing
157 */
158 public function wpstream_my_custom_query_vars( $vars ) {
159 $vars[] = 'video-list';
160 $vars[] = 'event-list';
161 return $vars;
162 }
163
164
165 /**
166 * Hust flush rewrite rules
167 *
168 * @since 3.0.1
169 *
170 */
171 public function wpstream_custom_flush_rewrite_rules() {
172 flush_rewrite_rules();
173 }
174
175
176 /**
177 * Add new sections in woocomerce account
178 *
179 * @since 3.0.1
180 */
181 public function wpstream_custom_my_account_menu_items( $items ) {
182 if(function_exists('wpstream_is_global_subscription') && wpstream_is_global_subscription()){
183 $items = array(
184 'dashboard' => __( 'Dashboard', 'woocommerce' ),
185 'orders' => __( 'Orders', 'woocommerce' ),
186 'edit-address' => __( 'Addresses', 'woocommerce' ),
187 'edit-account' => __( 'Edit Account', 'woocommerce' ),
188 'customer-logout' => __( 'Logout', 'woocommerce' ),
189 );
190 }else{
191 $items = array(
192 'dashboard' => __( 'Dashboard', 'woocommerce' ),
193 'orders' => __( 'Orders', 'woocommerce' ),
194 'edit-address' => __( 'Addresses', 'woocommerce' ),
195 'edit-account' => __( 'Edit Account', 'woocommerce' ),
196 'event-list' => __( 'Events', 'wpstream' ),
197 'video-list' => __( 'Videos', 'wpstream' ),
198 'customer-logout' => __( 'Logout', 'woocommerce' ),
199 );
200 }
201 return $items;
202 }
203
204
205
206 /**
207 * Add new endpoint
208 *
209 * @since 3.0.1
210 */
211 public function wpstream_custom_endpoint_content_event_list() {
212 include plugin_dir_path( __DIR__ ).'woocommerce/myaccount/event_list.php';
213 }
214
215
216 /**
217 * Add new endpoint
218 *
219 * @since 3.0.1
220 */
221 public function wpstream_custom_endpoint_video_list() {
222 include plugin_dir_path( __DIR__ ).'woocommerce/myaccount/video_list.php';
223 }
224
225
226
227
228
229
230 /**
231 * register shortcodes
232 *
233 * @since 3.0.1
234 *
235 */
236 public function wpstream_shortcodes(){
237 add_shortcode('wpstream_player', array($this,'wpstream_insert_player_inpage_local') );
238 add_shortcode('wpstream_list_products', array($this,'wpstream_list_products_function') );
239 add_shortcode('wpstream_chat', array($this,'wpstream_chat_function') );
240 add_shortcode('wpstream_player_low_latency', array($this,'wpstream_insert_player_inpage_low_latency') );
241 add_shortcode('wpstream_go_live', array($this,'wpstream_start_streaming_shortocde') );
242
243
244 // register shortcodes for visual composer
245 if( function_exists('vc_map') ):
246
247 vc_map(
248 array(
249 "name" => esc_html__( "WpStream Start Streaming Button","wpestate"),
250 "base" => "wpstream_go_live",
251 "class" => "",
252 "category" => esc_html__( 'WpStream','wpstream'),
253 'admin_enqueue_js' => array(get_template_directory_uri().'/vc_extend/bartag.js'),
254 'admin_enqueue_css' => array(get_template_directory_uri().'/vc_extend/bartag.css'),
255 'weight'=>100,
256 'icon' =>'',
257 'description'=>esc_html__( 'Insert WpStream Start Streaming Button','wpstream'),
258 "params" => array(
259 array(
260 "type" => "textfield",
261 "holder" => "div",
262 "class" => "",
263 "heading" => esc_html__( "Product/Free Product Id","wpestate"),
264 "param_name" => "id",
265 "value" => "",
266 "description" => esc_html__( "If you leave this option blank we will stream on the first free/paid channel for this user","wpestate")
267 ),
268
269
270 )
271 )
272 );
273
274
275
276 vc_map(
277 array(
278 "name" => esc_html__( "WpStream Chat - Beta Version","wpestate"),
279 "base" => "wpstream_chat",
280 "class" => "",
281 "category" => esc_html__( 'WpStream','wpstream'),
282 'admin_enqueue_js' => array(get_template_directory_uri().'/vc_extend/bartag.js'),
283 'admin_enqueue_css' => array(get_template_directory_uri().'/vc_extend/bartag.css'),
284 'weight'=>100,
285 'icon' =>'',
286 'description'=>esc_html__( 'Insert WpStream Chat','wpstream'),
287 "params" => array(
288 array(
289 "type" => "textfield",
290 "holder" => "div",
291 "class" => "",
292 "heading" => esc_html__( "Live Stream Id","wpestate"),
293 "param_name" => "id",
294 "value" => "0",
295 "description" => esc_html__( "Add here the live stream id","wpestate")
296 ),
297
298 )
299 )
300 );
301
302
303
304 vc_map(
305 array(
306 "name" => esc_html__( "WpStream Player","wpestate"),
307 "base" => "wpstream_player",
308 "class" => "",
309 "category" => esc_html__( 'WpStream','wpstream'),
310 'admin_enqueue_js' => array(get_template_directory_uri().'/vc_extend/bartag.js'),
311 'admin_enqueue_css' => array(get_template_directory_uri().'/vc_extend/bartag.css'),
312 'weight'=>100,
313 'icon' =>'',
314 'description'=>esc_html__( 'Insert WpStream Player','wpstream'),
315 "params" => array(
316 array(
317 "type" => "textfield",
318 "holder" => "div",
319 "class" => "",
320 "heading" => esc_html__( "Product/Free Product Id","wpestate"),
321 "param_name" => "id",
322 "value" => "0",
323 "description" => esc_html__( "Add here the live stream id or the video id","wpestate")
324 ),
325 array(
326 "type" => "textfield",
327 "holder" => "div",
328 "class" => "",
329 "heading" => esc_html__( "User Id","wpestate"),
330 "param_name" => "user_id",
331 "value" => "",
332 "description" => esc_html__( "We will use the first channel of this user id(product id will be ignored.).","wpestate")
333 ),
334
335 )
336 )
337 );
338
339
340 vc_map(
341 array(
342 "name" => esc_html__( "WpStream Player - Low Latency - Private Beta / Requires Approval","wpestate"),
343 "base" => "wpstream_player_low_latency",
344 "class" => "",
345 "category" => esc_html__( 'WpStream','wpstream'),
346 'admin_enqueue_js' => array(get_template_directory_uri().'/vc_extend/bartag.js'),
347 'admin_enqueue_css' => array(get_template_directory_uri().'/vc_extend/bartag.css'),
348 'weight'=>100,
349 'icon' =>'',
350 'description'=>esc_html__( 'Insert WpStream Player','wpstream'),
351 "params" => array(
352 array(
353 "type" => "textfield",
354 "holder" => "div",
355 "class" => "",
356 "heading" => esc_html__( "Product/Free Product Id","wpestate"),
357 "param_name" => "id",
358 "value" => "0",
359 "description" => esc_html__( "Add here the live stream id or the video id","wpestate")
360 ),
361 array(
362 "type" => "textfield",
363 "holder" => "div",
364 "class" => "",
365 "heading" => esc_html__( "User Id","wpestate"),
366 "param_name" => "user_id",
367 "value" => "",
368 "description" => esc_html__( "We will use the first channel of this user id(product id will be ignored.).","wpestate")
369 ),
370
371 )
372 )
373 );
374
375
376 $product_type=array(
377 '1' => __('Free Live Channel','wpstream'),
378 '2' => __('Free Video','wpstream')
379 );
380
381 vc_map(
382 array(
383 "name" => esc_html__( "WpStream Products List","wpestate"),
384 "base" => "wpstream_list_products",
385 "class" => "",
386 "category" => esc_html__( 'WpStream','wpstream'),
387 'admin_enqueue_js' => array(get_template_directory_uri().'/vc_extend/bartag.js'),
388 'admin_enqueue_css' => array(get_template_directory_uri().'/vc_extend/bartag.css'),
389 'weight'=>100,
390 'icon' =>'',
391 'description'=>esc_html__( ' List wpstream products','wpstream'),
392 "params" => array(
393 array(
394 "type" => "textfield",
395 "holder" => "div",
396 "class" => "",
397 "heading" => esc_html__( "Media number","wpestate"),
398 "param_name" => "media_number",
399 "value" => "",
400 "description" => esc_html__( "No of media ","wpestate")
401 ),
402
403 array(
404 "type" => "dropdown",
405 "holder" => "div",
406 "class" => "",
407 "heading" => esc_html__( "Product type","wpestate"),
408 "param_name" => "product_type",
409 "value" => $product_type,
410 "description" => esc_html__( "What type of products ","wpestate")
411 ),
412
413 )
414 )
415 );
416 endif;
417
418
419 // add shorcotes to editor interface
420 if (!current_user_can('edit_posts') && !current_user_can('edit_pages')) {
421 return;
422 }
423
424 if (get_user_option('rich_editing') == 'true') {
425 add_filter('mce_external_plugins', array( $this,'wpstream_add_plugin') );
426 add_filter('mce_buttons_2', array($this,'wpstream_register_button') );
427 }
428 }
429
430
431 /**
432 * shortocode player
433 *
434 * @since 3.0.1
435 *
436 */
437 public function wpstream_chat_function($attributes, $content = null){
438 $product_id = '';
439 $return_string = '';
440 $attributes = shortcode_atts(
441 array(
442 'id' => 0,
443 ), $attributes) ;
444
445
446 if ( isset($attributes['id']) ){
447 $product_id=$attributes['id'];
448 }
449
450
451 $return_string.= '<div class="wpstream_plugin_chat_wrapper">';
452 ob_start();
453 $this->main->wpstream_player->wpstream_chat_wrapper($product_id);
454 $return_string.= ob_get_contents();
455 ob_end_clean();
456 $return_string.='</div>';
457 $this->main->wpstream_player->wpstream_connect_to_chat($product_id);
458
459 return $return_string;
460 }
461
462
463
464
465 /**
466 * shortocode player
467 *
468 * @since 3.0.1
469 *
470 */
471
472
473 public function wpstream_insert_player_inpage_local($attributes, $content = null){
474 $product_id = '';
475 $return_string = '';
476 $attributes = shortcode_atts(
477 array(
478 'id' => 0,
479 'user_id' => 0,
480 ), $attributes) ;
481
482
483 if ( isset($attributes['id']) ){
484 $product_id = intval( $attributes['id'] );
485 }
486
487 if ( isset($attributes['user_id']) ){
488 $user_id = intval( $attributes['user_id'] );
489 }
490
491 if(intval($product_id)==0 && $user_id!=0 ){
492 $product_id= $this->main->wpstream_player_retrive_first_id($user_id);
493 }
494
495 ob_start();
496 $this->main->wpstream_player->wpstream_video_player_shortcode($product_id);
497 $return_string= ob_get_contents();
498 ob_end_clean();
499
500 return $return_string;
501 }
502
503
504 /**
505 * shortocode function for start streaming
506 *
507 * @since 3.7
508 *
509 */
510
511
512 public function wpstream_start_streaming_shortocde($attributes, $content = null){
513 $product_id = '';
514 $return_string = '';
515 $attributes = shortcode_atts(
516 array(
517 'id' => 0,
518 ), $attributes) ;
519
520
521 if ( isset($attributes['id']) ){
522 $product_id=intval($attributes['id']);
523 }
524
525
526 ob_start();
527 global $wpstream_plugin;
528 $wpstream_plugin->wpstream_live_stream_unit_wrapper( $product_id,'front' );
529 $return_string= ob_get_contents();
530 ob_end_clean();
531
532 return $return_string;
533 }
534
535
536
537 /**
538 * shortocode player low latency
539 *
540 * @since 3.0.1
541 *
542 */
543
544
545 public function wpstream_insert_player_inpage_low_latency($attributes, $content = null){
546 $product_id = '';
547 $return_string = '';
548 $attributes = shortcode_atts(
549 array(
550 'id' => 0,
551 'user_id' => 0,
552 ), $attributes) ;
553
554
555 if ( isset($attributes['id']) ){
556 $product_id=$attributes['id'];
557 }
558
559
560 if ( isset($attributes['user_id']) ){
561 $user_id = intval( $attributes['user_id'] );
562 }
563
564
565 if(intval($product_id)==0 && $user_id!=0){
566 $product_id= $this->main->wpstream_player_retrive_first_id($user_id);
567 }
568
569 ob_start();
570 $this->main->wpstream_player->wpstream_video_player_shortcode_low_latency($product_id);
571 $return_string= ob_get_contents();
572 ob_end_clean();
573
574 return $return_string;
575 }
576
577
578
579
580
581 /**
582 * list products - shortcode function
583 *
584 * @since 3.0.1
585 *
586 */
587
588 public function wpstream_list_products_function($atts, $content=null){
589
590 $media_number = "";
591 $product_type = "";
592 $attributes = shortcode_atts(
593 array(
594 'media_number' => '4',
595 'product_type' => __('Free Live Channel','wpstream'),
596
597 ), $atts);
598
599 if ( isset($attributes['media_number']) ){
600 $media_number=$attributes['media_number'];
601 }
602
603 if ( isset($attributes['product_type']) ){
604 $product_type=$attributes['product_type'];
605 }
606
607 if($product_type== __('Free Live Channel','wpstream') ){
608 $product_type=1;
609 }else{
610 $product_type=2;
611 }
612
613 $return_string="";
614
615
616
617 $args = array(
618 'post_type' => 'wpstream_product',
619 'post_status' => 'publish',
620 'meta_query' =>array(
621 array(
622 'key' => 'wpstream_product_type',
623 'value' => $product_type,
624 'compare' => '=',
625 ),
626 ),
627 'posts_per_page' =>$media_number,
628 'page' => 1
629 );
630
631
632 $media_list= new WP_Query($args);
633
634 if($product_type==1){
635 $see_product= __('See Free Live Chanel','wpstream');
636 }else{
637 $see_product =_('See Free Video','wpstream');
638 }
639
640
641
642 while($media_list->have_posts()):$media_list->the_post();
643 $return_string.='<div class="wpstream_product_unit">'
644 .'<div class="product_image" style="background-image:url('.wp_get_attachment_thumb_url(get_post_thumbnail_id()).')"></div>'
645 .'<a href="'.get_permalink().'" class="product_title" >'.get_the_title().'</a>'
646 .'<a href="'.get_permalink().'"class="see_product">'.$see_product.'</a>'
647 .'</div>';
648 endwhile;
649
650 wp_reset_postdata();
651 wp_reset_query();
652
653
654 return '<div class="shortcode_list_wrapper">'.$return_string.'</div>';
655
656 }
657
658
659
660 /**
661 * register shortcodes - add buttons in js
662 *
663 * @since 3.0.1
664 *
665 */
666
667 public function wpstream_add_plugin($plugin_array) {
668 $plugin_array['wpstream_player'] = plugin_dir_url( __FILE__ ). '/js/shortcodes.js';
669 $plugin_array['wpstream_list_products'] = plugin_dir_url( __FILE__ ). '/js/shortcodes.js';
670 return $plugin_array;
671 }
672
673 /**
674 * register shortcodes - add buttons
675 *
676 * @since 3.0.1
677 *
678 */
679 public function wpstream_register_button($buttons) {
680 array_push($buttons, "|", "wpstream_player");
681 array_push($buttons, "|", "wpstream_list_products");
682 return $buttons;
683 }
684
685
686
687 /**
688 * wpstream cors
689 *
690 * @since 3.0.1
691 *
692 */
693
694 public function wpstream_cors_check_and_response(){
695 if ($_SERVER['REQUEST_METHOD'] == "OPTIONS") {
696 header('Access-Control-Allow-Methods: POST, GET');
697 header('Access-Control-Allow-Headers: Authorization');
698 header('Access-Control-Max-Age: 1'); //1728000
699 header("Content-Length: 0");
700 header("Content-Type: text/plain charset=UTF-8");
701 exit(0);
702 }
703 }
704
705 /**
706 * set user cookie
707 *
708 * @since 3.0.1
709 *
710 */
711
712 public function wpstream_set_cookies(){
713 if( !isset( $_REQUEST[ 'keys' ]) && !isset( $_REQUEST[ 'keys2' ]) ) {
714 $cookie=uniqid ();
715 setcookie("WpstreamNonLogCookie3", $cookie);
716 }
717 }
718
719 /**
720 * get key for live stream
721 *
722 * @since 3.0.1
723 *
724 */
725
726
727 public function wpstream_live_streaming_key(){
728
729 if( isset( $_REQUEST[ 'keys' ]) && $_REQUEST[ 'keys' ]!='' ) {
730
731 $streamname_received = esc_html($_REQUEST[ 'keys' ]);
732 $stream_key_array = explode('-', $streamname_received);
733
734 $streamname = $stream_key_array[0];
735 $current_user = wp_get_current_user();
736
737
738 $args_free = array(
739 'posts_per_page' => -1,
740 'post_type' => 'wpstream_product',
741 'post_status' => 'publish',
742 'meta_query' => array(
743 array(
744 'key' => 'streamName',
745 'value' => $streamname,
746 'compare' => '=',
747 )
748 ),
749
750
751 );
752 $event_list_free = new WP_Query($args_free);
753
754
755 if ($event_list_free->have_posts() ){
756 ////////////////////////////////////////////////////////////
757 // when we have a free event
758 ////////////////////////////////////////////////////////////
759
760 $event_list_free->the_post();
761 $the_id = get_the_ID();
762 $show_id = $the_id;
763 $get_key = $this->wpstream_get_encryption_key_remonting($show_id,$streamname_received);
764 print $get_key;
765 die();
766
767
768 }else{
769 ////////////////////////////////////////////////////////////
770 // this is for paid products
771 ////////////////////////////////////////////////////////////
772
773 if ( is_user_logged_in() && intval($current_user->ID)!=0 ) {
774
775 $args = array(
776 'posts_per_page' => -1,
777 'post_type' => 'product',
778 'post_status' => 'publish',
779 'meta_query' => array(
780 array(
781 'key' => 'streamName',
782 'value' => $streamname,
783 'compare' => '=',
784 ),
785 ),
786 'tax_query' => array(
787 'relation' => 'AND',
788 array(
789 'taxonomy' => 'product_type',
790 'field' => 'slug',
791 'terms' => array('live_stream','subscription')
792 )
793 ),
794 );
795
796
797 $event_list = new WP_Query($args);
798
799 if ($event_list->have_posts() ){
800 while ( $event_list->have_posts() ):
801 $event_list->the_post();
802 $the_id = get_the_ID();
803 $show_id = $the_id;
804
805 endwhile;
806
807 $is_valid_subscription=0;
808 if(class_exists ('WC_Subscription')){
809 $is_valid_subscription = wcs_user_has_subscription( $current_user->ID, $show_id ,'active');
810 }
811
812
813 if(function_exists('wpstream_check_global_subscription_model')){
814 if( wpstream_check_global_subscription_model() ){
815 $is_valid_subscription=1;// this is global subscription
816 }
817 }
818
819
820 if( wc_customer_bought_product( $current_user->email, $current_user->ID, $show_id) || $is_valid_subscription==1 ){
821 $get_key = $this->wpstream_get_encryption_key_remonting($show_id,$streamname_received);
822 print $get_key;
823 die();
824
825 }else{
826 exit('live - no ticket ');
827 }
828
829 } else{
830 exit('live - no event');
831 }
832
833 }else{
834 exit('live - user not log or awserr');
835 }
836
837 }
838 exit('no free or paid event');
839
840 }else{
841 return;
842 }
843
844 }
845
846
847
848
849 /**
850 * get remote key for live
851 *
852 * @since 3.0.1
853 *
854 */
855
856 public function wpstream_get_encryption_key_remonting ($show_id,$streamname_received){
857
858 if ( false === ( $get_key = get_transient( $show_id.'_api20_streamName' ) ) ) {
859
860 $url = get_post_meta($show_id,'hlsKeyRetrievalUrl',true).'/'.$streamname_received;
861
862 $get= wp_remote_get( $url );
863
864 if(is_array($get)){
865 $get_key = $get['body'];
866 }else{
867 $get_key='';
868 }
869
870 set_transient( $show_id.'_api20_streamName', $get_key, 30 );
871 }
872 return $get_key;
873 }
874
875
876
877 /**
878 * get key for 3rdparty
879 *
880 * @since 3.0.1
881 *
882 */
883
884
885 public function wpstream_live_streaming_key_for_3rdparty(){
886
887 if( isset( $_REQUEST[ 'thirdkeys' ]) && $_REQUEST[ 'thirdkeys' ]!='' ) {
888
889 $thirdkeys = esc_html($_REQUEST[ 'thirdkeys' ]);
890
891 //live_event_carnat2
892
893 $args = array(
894 'post_type' => array('product','wpstream_product'),
895 'post_status' => 'publish',
896 'meta_query' =>array(
897 array(
898 'key' => 'live_event_carnat2',
899 'value' => $thirdkeys,
900 'compare' => '=',
901 ),
902 ),
903
904
905 );
906
907
908 $media_list= new WP_Query($args);
909 if($media_list->have_posts()){
910 while($media_list->have_posts()):$media_list->the_post();
911
912 $media_id = get_the_ID();
913 $replay_array = array(
914 // '', // fb will be here
915 stripslashes( get_post_meta($media_id,'wpstream_youtube_rtmp',true )),
916 stripslashes( get_post_meta($media_id,'wpstream_twich_rtmp',true) ),
917 );
918
919 $reply_final=array('rtmp_urls'=>$replay_array);
920 header('Content-Type: application/json;charset=utf-8');
921 print json_encode($reply_final,JSON_UNESCAPED_SLASHES);
922 die();
923
924
925 endwhile;
926 }else{
927 print'{}';
928 die('');
929 }
930
931 }
932
933 }
934
935
936
937 /**
938 * get key for vod
939 *
940 * @since 3.0.1
941 *
942 */
943
944
945 public function wpstream_live_streaming_key_vod(){
946
947 if( isset( $_REQUEST[ 'keys2' ]) && $_REQUEST[ 'keys2' ]!='' ) {
948 global $wp_query;
949 $current_user = wp_get_current_user();
950
951
952 $keys2 = esc_html($_REQUEST[ 'keys2' ]);
953
954
955 $keys2= ltrim($keys2,"/");
956 $keys2= rtrim($keys2,"/");
957 $keys2_array=explode('/',$keys2);
958
959
960 $folder=$keys2_array[0];
961 $movie=$keys2_array[1];
962
963
964 $free_args = array(
965 'posts_per_page' => -1,
966 'post_type' => 'wpstream_product',
967 'meta_query' => array(
968 array(
969 'key' => 'wpstream_free_video',
970 'value' => $movie,
971 'compare' => '=',
972 ),
973 )
974 );
975
976
977 $free_video_list = new WP_Query($free_args);
978
979 if ($free_video_list->have_posts() ){
980 $get_key = $this->wpstream_get_vod_key($folder.'/'.$movie);
981 echo ($get_key);
982 die();
983 }else{
984 if ( is_user_logged_in() && intval($current_user->ID)!=0 ) {
985
986 $args = array(
987 'posts_per_page' => -1,
988 'post_type' => 'product',
989 'meta_query' => array(
990 array(
991 'key' => '_movie_url',
992 'value' => $movie,
993 'compare' => '=',
994 ),
995 ),
996 'tax_query' => array(
997 'relation' => 'AND',
998 array(
999 'taxonomy' => 'product_type',
1000 'field' => 'slug',
1001 'terms' => array('video_on_demand','subscription')
1002 )
1003 ),
1004
1005 );
1006
1007
1008 $video_list = new WP_Query($args);
1009
1010 $video_id =0;
1011 $ticket_flag=0;
1012 if ($video_list->have_posts() ){
1013 while ( $video_list->have_posts() ):
1014 $video_list->the_post();
1015 $video_id = get_the_ID();
1016
1017 $show_id='';
1018 $is_valid_subscription=0;
1019 if(class_exists ('WC_Subscription')){
1020
1021 $is_valid_subscription = wcs_user_has_subscription( $current_user->ID, $show_id ,'active');
1022 }
1023
1024 if(function_exists('wpstream_check_global_subscription_model')){
1025 if( wpstream_check_global_subscription_model() ){
1026 $is_valid_subscription=1;// this is global subscription
1027 }
1028 }
1029
1030
1031 if( wc_customer_bought_product( $current_user->email, $current_user->ID, $video_id) ||
1032 $is_valid_subscription==1 ){
1033
1034 $get_key = $this->wpstream_get_vod_key($folder.'/'.$movie);
1035 echo ($get_key);
1036 exit();
1037 }else{
1038 $ticket_flag=1;
1039 exit('no ticket loop'.$current_user->ID.'/'.$video_id.'/'.$is_valid_subscription );
1040 }
1041 endwhile;
1042
1043 if($ticket_flag==0){
1044 exit($current_user->email.'no ticket ukpt'.$current_user->ID.'.'.$video_id);
1045 }
1046
1047 }else{
1048 exit('no video found :'.$movie);
1049 }
1050
1051 }else{
1052 exit('user not log');
1053 }
1054
1055 }
1056
1057 }
1058
1059 }
1060
1061
1062
1063 /**
1064 * request key for vod from wpstream
1065 *
1066 * @since 3.0.1
1067 *
1068 */
1069
1070
1071 public function wpstream_get_vod_key($filename){
1072 global $wpstream_plugin;
1073 $vod_key = get_transient("vod_key".$filename);
1074 if(false===$vod_key){
1075 $token = $wpstream_plugin->wpstream_live_connection->wpstream_get_token();
1076 $domain = parse_url ( get_site_url() );
1077
1078 $values_array=array(
1079 "filename" => $filename,
1080 );
1081 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/uservodkey/get/?access_token=".$token;
1082
1083
1084 $arguments = array(
1085 'method' => 'GET',
1086 'timeout' => 45,
1087 'redirection' => 5,
1088 'httpversion' => '1.0',
1089 'blocking' => true,
1090 'headers' => array(),
1091 'body' => $values_array,
1092 'cookies' => array()
1093 );
1094 $response = wp_remote_post($url,$arguments);
1095 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
1096
1097
1098 if( isset($response['response']['code']) && $response['response']['code']=='200'){
1099 set_transient("vod_key".$filename,$received_data,120);
1100 return ($received_data);
1101 }else{
1102 return 'failed connection';
1103 }
1104 }else{
1105 return $vod_key;
1106 }
1107
1108 }
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118 /**
1119 * wrapper start around woo
1120 *
1121 * @since 3.0.1
1122 *
1123 */
1124
1125
1126 public function wpstream_non_image_content_wrapper_start() {
1127 if ( is_user_logged_in() ) {
1128 global $product;
1129 $current_user = wp_get_current_user();
1130 $product = wc_get_product();
1131
1132 if($product){
1133 $product_id = $product->get_id();
1134 if ( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product_id) ){
1135 echo '<div id="wpstream_product_wrap">';
1136 }else{
1137 echo '<div id="wpstream_product_wrap_no_buy">';
1138 }
1139 }
1140 }
1141
1142 }
1143
1144 /**
1145 * wrapper end around woo
1146 *
1147 * @since 3.0.1
1148 *
1149 */
1150
1151
1152 function wpstream_non_image_content_wrapper_end() {
1153 // echo '</div>';
1154 }
1155 }
1156