PluginProbe
WpStream – Live Streaming, Video on Demand, Pay Per View / 4.2
WpStream – Live Streaming, Video on Demand, Pay Per View v4.2
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 4.5.12 All 180 releases
wpstream / includes / class-wpstream.php

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

913 lines 34.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The file that defines the core plugin class
5 *
6 * A class definition that includes attributes and functions used across both the
7 * public-facing side of the site and the admin area.
8 *
9 * @link http://wpstream.net
10 * @since 3.0.1
11 *
12 * @package Wpstream
13 * @subpackage Wpstream/includes
14 */
15
16 /**
17 * The core plugin class.
18 *
19 * This is used to define internationalization, admin-specific hooks, and
20 * public-facing site hooks.
21 *
22 * Also maintains the unique identifier of this plugin as well as the current
23 * version of the plugin.
24 *
25 * @since 3.0.1
26 * @package Wpstream
27 * @subpackage Wpstream/includes
28 * @author wpstream <office@wpstream.net>
29 */
30 class Wpstream {
31
32 /**
33 * Store plugin main class to allow public access.
34 *
35 * @since 3.0.1
36 * @var object The main class.
37 */
38 public $main;
39
40 /**
41 * The loader that's responsible for maintaining and registering all hooks that power
42 * the plugin.
43 *
44 * @since 3.0.1
45 * @access protected
46 * @var Wpstream_Loader $loader Maintains and registers all hooks for the plugin.
47 */
48 protected $loader;
49
50 /**
51 * The unique identifier of this plugin.
52 *
53 * @since 3.0.1
54 * @access protected
55 * @var string $plugin_name The string used to uniquely identify this plugin.
56 */
57 protected $plugin_name;
58
59 /**
60 * The current version of the plugin.
61 *
62 * @since 3.0.1
63 * @access protected
64 * @var string $version The current version of the plugin.
65 */
66 protected $version;
67
68 /**
69 * Define the core functionality of the plugin.
70 *
71 * Set the plugin name and the plugin version that can be used throughout the plugin.
72 * Load the dependencies, define the locale, and set the hooks for the admin area and
73 * the public-facing side of the site.
74 *
75 * @since 3.0.1
76 */
77
78 public $wpstream_live_connection;
79 public $wpstream_player;
80 public $xtest;
81 public $plugin_admin;
82
83 public function __construct() {
84 $this->main = $this;
85 if ( defined( 'WPSTREAM_PLUGIN_VERSION' ) ) {
86 $this->version = WPSTREAM_PLUGIN_VERSION;
87 } else {
88 $this->version = '3.0.1';
89 }
90 $this->plugin_name = 'wpstream';
91
92 $this->load_dependencies();
93 $this->set_locale();
94 $this->define_admin_hooks();
95 $this->define_public_hooks();
96
97
98 $this->wpstream_conection();
99 $this->wpstream_player();
100
101 }
102
103
104
105
106
107 public function wpstream_convert_band($megabits){
108 $gigabit = $megabits * 0.001;
109 $gigabit = number_format($gigabit,2);
110 return $gigabit;
111 }
112
113
114
115
116
117 private function wpstream_conection(){
118 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpstream-live-api-connection.php';
119 $this->wpstream_live_connection = new Wpstream_Live_Api_Connection();
120 }
121
122
123 private function wpstream_player(){
124 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpstream-player.php';
125 $this->wpstream_player = new Wpstream_Player($this->main);
126 }
127
128
129
130
131 /**
132 * Load the required dependencies for this plugin.
133 *
134 * Include the following files that make up the plugin:
135 *
136 * - Wpstream_Loader. Orchestrates the hooks of the plugin.
137 * - Wpstream_i18n. Defines internationalization functionality.
138 * - Wpstream_Admin. Defines all hooks for the admin area.
139 * - Wpstream_Public. Defines all hooks for the public side of the site.
140 *
141 * Create an instance of the loader which will be used to register the hooks
142 * with WordPress.
143 *
144 * @since 3.0.1
145 * @access private
146 */
147 private function load_dependencies() {
148
149 /**
150 * The class responsible for orchestrating the actions and filters of the
151 * core plugin.
152 */
153 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpstream-loader.php';
154
155 /**
156 * The class responsible for defining internationalization functionality
157 * of the plugin.
158 */
159 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpstream-i18n.php';
160
161 /**
162 * The class responsible for defining all actions that occur in the admin area.
163 */
164 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wpstream-admin.php';
165
166 /**
167 * The class responsible for defining all actions that occur in the public-facing
168 * side of the site.
169 */
170 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wpstream-public.php';
171
172 /**
173 * The class responsible for custom post type
174
175 */
176 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpstream_product.php';
177 if( class_exists( 'WooCommerce' ) ){
178 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wc_product_live_stream.php';
179 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wc_product_video_on_demand.php';
180 }
181
182 $this->loader = new Wpstream_Loader();
183
184 }
185
186 /**
187 * Define the locale for this plugin for internationalization.
188 *
189 * Uses the Wpstream_i18n class in order to set the domain and to register the hook
190 * with WordPress.
191 *
192 * @since 3.0.1
193 * @access private
194 */
195 private function set_locale() {
196
197 $plugin_i18n = new Wpstream_i18n();
198
199 $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
200
201 }
202
203 /**
204 * Register all of the hooks related to the admin area functionality
205 * of the plugin.
206 *
207 * @since 3.0.1
208 * @access private
209 */
210 private function define_admin_hooks() {
211
212 $this->admin= $plugin_admin = new Wpstream_Admin( $this->get_plugin_name(), $this->get_version(), $this->main );
213
214
215
216 $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
217 $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
218 $this->loader->add_action( 'admin_menu', $plugin_admin, 'wpstream_manage_admin_menu',999);
219
220 $plugin_post_types = new Wpstream_Product();
221 $this->loader->add_action( 'init', $plugin_post_types, 'create_custom_post_type', 999 );
222
223 // save and render metaboxed
224 $this->loader->add_action( 'admin_init', $plugin_admin, 'add_wpstream_product_metaboxes' );
225 $this->loader->add_action( 'save_post', $plugin_admin, 'wpstream_free_product_update_post',1,2 );
226
227 // make product virtual
228 $this->loader->add_action( 'save_post', $plugin_admin, 'wpstream_make_product_virtual', 99999, 2 );
229
230
231
232 // show streaming controls on sidebar
233 $this->loader->add_action('add_meta_boxes', $plugin_admin, 'wpstream_startstreaming_sidebar_meta');
234
235
236 $this->loader->add_action( 'admin_notices', $plugin_admin,'wpstream_admin_notice' );
237 $this->loader->add_action( 'wp_ajax_wpstream_update_cache_notice', $plugin_admin,'wpstream_update_cache_notice' );
238
239 // add and save category extra fields
240 $this->loader->add_action( 'category_edit_form_fields', $plugin_post_types, 'wpstream_category_callback_function', 10, 2);
241 $this->loader->add_action( 'category_add_form_fields', $plugin_post_types, 'wpstream_category_callback_add_function', 10, 2 );
242 $this->loader->add_action( 'created_category', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2);
243 $this->loader->add_action( 'edited_category', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2);
244
245 $this->loader->add_action( 'product_cat_edit_form_fields', $plugin_post_types, 'wpstream_category_callback_function', 10, 2);
246 $this->loader->add_action( 'product_cat_add_form_fields', $plugin_post_types, 'wpstream_category_callback_add_function', 10, 2 );
247 $this->loader->add_action( 'created_product_cat', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2);
248 $this->loader->add_action( 'edited_product_cat', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2);
249
250
251 $this->loader->add_action( 'wpstream_category_edit_form_fields', $plugin_post_types, 'wpstream_category_callback_function', 10, 2);
252 $this->loader->add_action( 'wpstream_category_add_form_fields', $plugin_post_types, 'wpstream_category_callback_add_function', 10, 2 );
253 $this->loader->add_action( 'created_wpstream_category', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2);
254 $this->loader->add_action( 'edited_wpstream_category', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2);
255
256
257 $this->loader->add_action( 'wpstream_actors_edit_form_fields', $plugin_post_types, 'wpstream_category_callback_function', 10, 2);
258 $this->loader->add_action( 'wpstream_actors_add_form_fields', $plugin_post_types, 'wpstream_category_callback_add_function', 10, 2 );
259 $this->loader->add_action( 'created_wpstream_actors', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2);
260 $this->loader->add_action( 'edited_wpstream_actors', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2);
261
262 $this->loader->add_action( 'wpstream_movie_rating_edit_form_fields', $plugin_post_types, 'wpstream_category_callback_function', 10, 2);
263 $this->loader->add_action( 'wpstream_movie_rating_add_form_fields', $plugin_post_types, 'wpstream_category_callback_add_function', 10, 2 );
264 $this->loader->add_action( 'created_wpstream_movie_rating', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2);
265 $this->loader->add_action( 'edited_wpstream_movie_rating', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2);
266
267
268
269
270 if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
271
272 $this->loader->add_filter( 'product_type_selector', $plugin_admin, 'wpstream_add_products' );
273 $this->loader->add_action( 'admin_footer', $plugin_admin, 'wpstream_products_custom_js' );
274 $this->loader->add_filter( 'woocommerce_product_data_tabs', $plugin_admin, 'wpstream_hide_attributes_data_panel',10,1 );
275 $this->loader->add_filter( 'woocommerce_is_purchasable', $plugin_admin, 'wpstream_hide_buy_now_subscription_mode',10,2);
276
277 $this->loader->add_filter( 'woocommerce_product_options_general_product_data',$plugin_admin, 'wpstream_add_custom_general_fields', 10,1);
278 $this->loader->add_filter( 'woocommerce_process_product_meta',$plugin_admin, 'wpstream_add_custom_general_fields_save',10,1 );
279 $this->loader->add_action( 'woocommerce_live_stream_add_to_cart', $plugin_admin, 'wpstream_add_to_cart',10,1);
280 $this->loader->add_action( 'woocommerce_video_on_demand_add_to_cart', $plugin_admin, 'wpstream_add_to_cart',10,1);
281 $this->loader->add_filter( 'woocommerce_loop_add_to_cart_link', $plugin_admin,'replacing_add_to_cart_button', 10, 2 );
282 }
283
284
285
286
287
288
289 }
290
291 /**
292 * Register all of the hooks related to the public-facing functionality
293 * of the plugin.
294 *
295 * @since 3.0.1
296 * @access private
297 */
298 private function define_public_hooks() {
299
300 $plugin_public = new Wpstream_Public( $this->get_plugin_name(), $this->get_version(), $this->main );
301
302 $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
303 $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
304
305 $this->loader->add_action( 'init', $plugin_public,'wpstream_my_custom_endpoints' );
306 $this->loader->add_filter( 'query_vars',$plugin_public, 'wpstream_my_custom_query_vars', 0 );
307
308 //live stream action
309 $this->loader->add_action('init',$plugin_public,'wpstream_set_cookies',0);
310 $this->loader->add_action('init',$plugin_public,'wpstream_live_streaming_key');
311 $this->loader->add_action('init',$plugin_public,'wpstream_live_streaming_key_for_3rdparty');
312 $this->loader->add_action('init',$plugin_public,'wpstream_live_streaming_key_vod');
313 // woo action
314
315 $this->loader->add_action( 'woocommerce_before_single_product', $plugin_public,'wpstream_non_image_content_wrapper_start', 20 );
316 $this->loader->add_action( 'woocommerce_after_single_product', $plugin_public,'wpstream_non_image_content_wrapper_end', 20 );
317 $this->loader->add_action( 'woocommerce_thankyou_order_received_text', $plugin_public,'wpstream_thankyou_extra', 20,2 );
318 $this->loader->add_action( 'woocommerce_email_order_details', $plugin_public,'wpstream_email_order_details', 20,4 );
319
320 $this->loader->add_filter( 'woocommerce_account_menu_items', $plugin_public,'wpstream_custom_my_account_menu_items' );
321 $this->loader->add_action( 'woocommerce_account_event-list_endpoint', $plugin_public,'wpstream_custom_endpoint_content_event_list' );
322 $this->loader->add_action( 'woocommerce_account_video-list_endpoint', $plugin_public,'wpstream_custom_endpoint_video_list' );
323
324
325 $this->loader->add_action( 'after_switch_theme', $plugin_public,'wpstream_custom_flush_rewrite_rules' );
326 $this->loader->add_action('init', $plugin_public,'wpstream_shortcodes');
327 $this->loader->add_action('vc_before_init', $plugin_public,'wpstream_bakery_shortcodes');
328
329
330 $this->loader->add_action('wo_before_api', 'wpstream_cors_check_and_response',10,1);
331
332
333
334 }
335
336 /**
337 * Run the loader to execute all of the hooks with WordPress.
338 *
339 * @since 3.0.1
340 */
341 public function run() {
342 $this->loader->run();
343 }
344
345 /**
346 * The name of the plugin used to uniquely identify it within the context of
347 * WordPress and to define internationalization functionality.
348 *
349 * @since 3.0.1
350 * @return string The name of the plugin.
351 */
352 public function get_plugin_name() {
353 return $this->plugin_name;
354 }
355
356 /**
357 * The reference to the class that orchestrates the hooks with the plugin.
358 *
359 * @since 3.0.1
360 * @return Wpstream_Loader Orchestrates the hooks of the plugin.
361 */
362 public function get_loader() {
363 return $this->loader;
364 }
365
366 /**
367 * Retrieve the version number of the plugin.
368 *
369 * @since 3.0.1
370 * @return string The version number of the plugin.
371 */
372 public function get_version() {
373 return $this->version;
374 }
375
376
377
378 public function show_user_data($pack_details){
379 if( isset($pack_details['available_data_mb']) && isset( $pack_details['available_storage_mb']) ){
380 $wpstream_convert_band = $this->wpstream_convert_band($pack_details['available_data_mb']);
381 if($wpstream_convert_band<0)$wpstream_convert_band=0;
382 // print_r($pack_details);
383 $wpstream_convert_storage = $this->wpstream_convert_band($pack_details['available_storage_mb']);
384 if($wpstream_convert_storage<0)$wpstream_convert_storage=0;
385
386 print '<div class="pack_details_wrapper"><strong>'.__('Your account information: ','wpstream').'</strong> '.__('You have','wpstream').'<strong> '.$wpstream_convert_band.' Gb</strong> '.__('available streaming data and','wpstream').' <strong>'.$wpstream_convert_storage.' Gb</strong> '.__('available media storage','wpstream').'.</div>';
387 print'<input type="hidden" id="wpstream_band" value="'.$pack_details['available_data_mb'].'">';
388 print'<input type="hidden" id="wpstream_storage" value="'.$pack_details['available_storage_mb'].'">';
389
390 }
391 }
392
393
394 /**
395 * help function for media list elementor widget
396 *
397 * @since 3.0.1
398 * @return string
399 */
400
401 public function wpstream_media_list_elementor_function($attributes, $content = null){
402
403
404
405 ob_start();
406
407 $media_number=3;
408 if ( isset($attributes['media_number']) ){
409 $media_number=$attributes['media_number'];
410 }
411
412 // check if is vod or live stream
413 $meta_query = array();
414 $tax_query_array= array();
415 $tax_query = array();
416
417 // check if the media is paid or free
418 $event_types = array();
419 $product_type_free_paid = 0;
420 if ( isset($attributes['product_type_free_paid']) ){
421 $product_type_free_paid=$attributes['product_type_free_paid'];
422
423 if($product_type_free_paid==0){
424 $event_types=array('wpstream_product');
425
426 if ( isset($attributes['product_type']) && intval($attributes['product_type'])==2){
427 $event_types=array('wpstream_product_vod');
428
429
430
431 }
432
433
434
435 }else{
436 $event_types=array('product');
437 if ( isset($attributes['product_type']) ){
438 $product_type = $attributes['product_type'];
439 $product_type_slug = 'video_on_demand';
440 if($product_type==1){
441 $product_type_slug ='live_stream';
442 }
443
444 $tax_query_array = array(
445 'taxonomy' => 'product_type',
446 'field' => 'slug',
447 'terms' => $product_type_slug
448 );
449
450 $tax_query= array(
451 'relation' => 'AND',
452 $tax_query_array
453 );
454
455 }
456 }
457
458 }
459 $see_product='';
460 if(isset($attributes['free_label'])){
461 $see_product=$attributes['free_label'];
462 }
463
464 // pagination
465 $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
466 if( is_front_page() ){
467 $paged= (get_query_var('page')) ? get_query_var('page') : 1;
468 }
469
470
471 //order
472 $orderby='ID';
473 $order ='ASC';
474 if ( isset($attributes['order_by']) ){
475 $order_by=intval($attributes['order_by']);
476 switch ($order_by) {
477 case 0:
478 $orderby='ID';
479 $order ='ASC';
480 break;
481 case 1:
482 $orderby='ID';
483 $order ='DESC';
484 break;
485 case 2:
486 $orderby='title';
487 $order ='ASC';
488 break;
489 case 3:
490 $orderby='title';
491 $order ='DESC';
492 break;
493 }
494 }
495
496 // building wp_query arg array
497 $args = array(
498 'post_type' => $event_types,
499 'post_status' => 'publish',
500 'meta_query' => $meta_query,
501 'posts_per_page' => $media_number,
502 'paged' => $paged,
503 'orderby' => $orderby,
504 'order' => $order,
505 'tax_query' => $tax_query
506 );
507
508
509
510 // show live events
511 if ( isset($attributes['product_show_live']) && $attributes['product_show_live']=='yes'){
512 $live_event_for_user = $this->main->wpstream_live_connection->api20_wpstream_request_live_stream_for_user_for_shortcode('shortcode');
513
514
515 if( is_array($live_event_for_user) ){
516 $live_event_for_user[]=0;
517
518 $args['post__in']=$live_event_for_user;
519 }
520 }
521
522
523
524
525 $media_list= new WP_Query($args);
526 if($media_list->have_posts()){
527 print '<ul class="wpstream_media_list_wrapper products columns-3" >';
528 while($media_list->have_posts()):$media_list->the_post();
529 if($product_type_free_paid==0 ){
530
531 $thumb=wp_get_attachment_image_src(get_post_thumbnail_id(),'medium');
532
533 $thumb_src='';
534 if( isset($thumb[0]) ){
535 $thumb_src=$thumb[0];
536 }
537
538 if(($thumb_src)==''){
539 $thumb_src= plugin_dir_url( dirname( __FILE__ ) ). 'img/default_300.png';
540 }
541 print '<li class="wpstream_product_unit">'
542 .'<a href="'.get_permalink().'" class="product_title" ><div class="product_image" style="background-image:url('.esc_url($thumb_src).')"></div></a>'
543 .'<a href="'.get_permalink().'" class="product_title" >'.get_the_title().'</a>';
544
545 if($see_product!=''){
546 print '<a href="'.get_permalink().'"class="see_product">'.$see_product.'</a>';
547 }
548 print '</li>';
549 }else{
550 wc_get_template_part( 'content', 'product' );
551 }
552 endwhile;
553 print '</ul>';
554 }else{
555 print esc_html__('No media found! ','wpstream');
556 }
557
558
559 wp_reset_query();
560 wp_reset_postdata();
561
562 $this->wpstream_pagination($media_list->max_num_pages,$range=2);
563 $return_string= ob_get_contents();
564 ob_end_clean();
565
566 return $return_string;
567 }
568
569
570
571
572
573
574 /*
575 *
576 *
577 * Pagination for media lista
578 *
579 *
580 *
581 */
582
583
584
585
586 function wpstream_pagination($pages = '', $range = 2){
587
588 $showitems = ($range * 2)+1;
589 global $paged;
590 if(empty($paged)) $paged = 1;
591
592
593 if($pages == ''){
594 global $wp_query;
595 $pages = $wp_query->max_num_pages;
596 if(!$pages)
597 {
598 $pages = 1;
599 }
600 }
601
602 if(1 != $pages){
603 print '<ul class="wpstream_pagination ">';
604 print '<li class="roundleft"><a href="'.get_pagenum_link($paged - 1).'"> < </a></li>';
605
606 for ($i=1; $i <= $pages; $i++)
607 {
608 if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
609 {
610 if ($paged == $i){
611 print '<li class="active"><a href="'.esc_url(get_pagenum_link($i)).'" >'.$i.'</a><li>';
612 }else{
613 print '<li><a href="'.esc_url(get_pagenum_link($i)).'" >'.$i.'</a><li>';
614 }
615 }
616 }
617
618 $prev_page= get_pagenum_link($paged + 1);
619 if ( ($paged +1) > $pages){
620 $prev_page= get_pagenum_link($paged );
621 }else{
622 $prev_page= get_pagenum_link($paged + 1);
623 }
624
625
626 print '<li class="roundright"><a href="'.$prev_page.'"> > </a><li>';
627 print '</ul>';
628 }
629 }
630
631
632
633
634
635
636
637
638
639
640
641
642
643 /**
644 * help function for player elementr widget
645 *
646 * @since 3.0.1
647 * @return string
648 */
649
650 public function wpstream_insert_player_elementor($attributes, $content = null){
651 $product_id = '';
652 $return_string = '';
653 $attributes = shortcode_atts(
654 array(
655 'id' => 0,
656 'user_id' => 0,
657 ), $attributes) ;
658
659
660 if ( isset($attributes['id']) ){
661 $product_id=$attributes['id'];
662 }
663 if ( isset($attributes['user_id']) ){
664 $user_id = intval( $attributes['user_id'] );
665 }
666
667 if(intval($product_id)==0 && $user_id!=0 ){
668 $product_id= $this->wpstream_player_retrive_first_id($user_id);
669 }
670
671
672
673
674 ob_start();
675 $this->main->wpstream_player->wpstream_video_player_shortcode($product_id);
676 $return_string= ob_get_contents();
677 ob_end_clean();
678
679 return $return_string;
680 }
681
682 /**
683 * help function for player low latency elementor widget
684 *
685 * @since 3.0.1
686 * @return string
687 */
688
689 public function wpstream_insert_player__low_latency_elementor($attributes, $content = null){
690 $product_id = '';
691 $return_string = '';
692 $attributes = shortcode_atts(
693 array(
694 'id' => 0,
695 'user_id' => 0,
696 ), $attributes) ;
697
698
699 if ( isset($attributes['id']) ){
700 $product_id=$attributes['id'];
701 }
702
703 if ( isset($attributes['user_id']) ){
704 $user_id = intval( $attributes['user_id'] );
705 }
706
707 if(intval($product_id)==0 && $user_id!=0){
708 $product_id= $this->wpstream_player_retrive_first_id($user_id);
709 }
710
711
712 ob_start();
713 $this->main->wpstream_player->wpstream_video_player_shortcode_low_latency($product_id);
714 $return_string= ob_get_contents();
715 ob_end_clean();
716
717 return $return_string;
718 }
719
720
721
722 public function wpstream_player_retrive_first_id($received_user_id=''){
723 $channel_type = get_option ('wpstream_user_streaming_channel_type');
724 $product_id = $this->wpstream_get_current_event_per_author($received_user_id,$channel_type);
725 return $product_id;
726 }
727
728
729
730 /**
731 * help function for chat elementor widget
732 *
733 * @since 3.0.1
734 * @return string
735 */
736
737 public function wpstream_insert_chat_elementor($attributes, $content = null){
738 $product_id = '';
739 $return_string = '';
740 $attributes = shortcode_atts(
741 array(
742 'id' => 0,
743 ), $attributes) ;
744
745
746 if ( isset($attributes['id']) ){
747 $product_id=$attributes['id'];
748 }
749
750 $return_string.= '<div class="wpstream_plugin_chat_wrapper">';
751 ob_start();
752 $this->main->wpstream_player->wpstream_chat_wrapper($product_id);
753 $return_string.= ob_get_contents();
754 ob_end_clean();
755 $return_string.='</div>';
756 $this->main->wpstream_player->wpstream_connect_to_chat($product_id);
757
758 return $return_string;
759 }
760
761
762 /**
763 * edited 4.0
764 *
765 * Check if user is allowed to stream
766 *
767 * @since 3.7
768 */
769
770 public function wpstream_check_user_can_stream(){
771 $current_user = wp_get_current_user();
772
773 if( !is_user_logged_in() ){
774 return false;
775 exit('user not logged in');
776 }
777
778 if(current_user_can('administrator')){
779 // admins can always brodcast
780 return true;
781 }
782
783 $extra_roles = get_option( 'wpstream_stream_role', true );
784 $user_role = $current_user->roles[0];
785
786 if (is_array($extra_roles) && in_array($user_role, $extra_roles)){
787 return true;
788 }
789
790 if(function_exists('wpstream_get_option') && intval(wpstream_get_option('allow_streaming_regular_users',''))==1 ){
791 return true;
792 }
793
794 return false;
795 }
796
797
798 /**
799 * Start Streaming wrapper
800 *
801 * @since 3.7
802 */
803
804 public function wpstream_live_stream_unit_wrapper($item_id,$type){
805 $item_id = intval($item_id);
806
807 if($item_id == 0){
808 //retrive or create channel for front end streamers
809 $item_id=$this->wpstream_retrive_front_end_channel();
810 }
811 print'</div><div class="wpstream_modal_background"></div>';
812 print '<div class="wpstream_error_modal_notification"><div class="wpstream_error_content">er2</div>
813 <div class="wpstream_error_ok wpstream_button" type="button">'.esc_html__('Close','wpstream').'</div>
814 </div>';
815 $this->admin->wpstream_live_stream_unit( $item_id,$type );
816 }
817
818
819
820
821
822 /**
823 * retrive channel for front end streaming
824 *
825 * @since 3.7
826 */
827 public function wpstream_retrive_front_end_channel(){
828
829 $current_user = wp_get_current_user();
830 $channel_type = get_option ('wpstream_user_streaming_channel_type');
831 $channel_price = floatval( get_option ('wpstream_user_streaming_default_price') );
832
833 $front_end_streamin_channel = $this->wpstream_get_current_event_per_author($current_user->ID,$channel_type);
834
835 if(intval($front_end_streamin_channel) == 0){
836 $front_end_streamin_channel= $this->wpstrea_create_front_end_event($current_user->ID,$current_user->user_login ,$channel_type,$channel_price);
837 }
838 return $front_end_streamin_channel;
839
840 }
841
842 /**
843 * create the event from front end
844 *
845 * @since 3.7
846 */
847
848 public function wpstrea_create_front_end_event($userID,$userLogin,$channel_type,$channel_price){
849
850 if( !$this->wpstream_check_user_can_stream() ){
851 return;
852 }
853
854 $post_type='wpstream_product';
855 if($channel_type=='paid'){
856 $post_type='product';
857 }
858
859 $post = array(
860 'post_title' => sprintf( esc_html__('%s Channel','wpstream'),$userLogin),
861 'post_content' => '',
862 'post_type' => $post_type ,
863 'post_author' => $userID,
864 'post_status' => 'publish',
865 );
866 $post_id = wp_insert_post($post );
867 if($channel_type=='paid'){
868 $product = wc_get_product($post_id);
869 $price = wc_format_decimal($channel_price);
870
871 $product = wc_get_product( $post_id );
872 // Set the product active price (regular)
873 $product->set_price( $price );
874 $product->set_regular_price( $price ); // To be sure
875 $product->save();
876 update_post_meta ($post_id,'event_passed',0);
877 wp_set_object_terms( $post_id, 'live_stream', 'product_type' );
878 }
879 update_post_meta($post_id,'wpstream_product_type',1);
880
881 return $post_id;
882 }
883
884
885 public function wpstream_get_current_event_per_author($userID,$channel_type){
886
887 $post_type='wpstream_product';
888 if($channel_type=='paid'){
889 $post_type='product';
890 }
891
892 $args = array(
893
894 'post_type' => $post_type,
895 'author' => $userID,
896 'posts_per_page' => 1,
897 'fields' => 'ids'
898 )
899 ;
900 $author_posts = new WP_Query( $args );
901 if( $author_posts->have_posts() ) {
902 $author_posts->the_post();
903 return get_the_ID();
904 }else{
905 return 0;
906 }
907
908 wp_reset_query();
909 wp_reset_postdata();
910 }
911
912 }
913