PluginProbe
WpStream – Live Streaming, Video on Demand, Pay Per View / 4.4.5
WpStream – Live Streaming, Video on Demand, Pay Per View v4.4.5
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.4.5, at includes/class-wpstream.php

934 lines 35.9 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 $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
215 $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
216 $this->loader->add_action( 'admin_menu', $plugin_admin, 'wpstream_manage_admin_menu',999);
217
218 $plugin_post_types = new Wpstream_Product();
219 $this->loader->add_action( 'init', $plugin_post_types, 'create_custom_post_type', 999 );
220
221 // save and render metaboxed
222 $this->loader->add_action( 'admin_init', $plugin_admin, 'add_wpstream_product_metaboxes' );
223 $this->loader->add_action( 'save_post', $plugin_admin, 'wpstream_free_product_update_post',1,2 );
224 $this->loader->add_action( 'publish_wpstream_product', $plugin_admin, 'wpstream_publish_wpstream_product',1,2 );
225
226
227
228 // make product virtual
229 $this->loader->add_action( 'save_post', $plugin_admin, 'wpstream_make_product_virtual', 99999, 2 );
230
231
232
233 // show streaming controls on sidebar
234 $this->loader->add_action('add_meta_boxes', $plugin_admin, 'wpstream_startstreaming_sidebar_meta');
235
236 // on boarding actions
237 $this->loader->add_action('admin_footer',$plugin_admin, 'wpstream_admin_footer_onboarding');
238 $this->loader->add_action( 'wp_ajax_wpstream_on_board_create_channel', $plugin_admin,'wpstream_on_board_create_channel' );
239 $this->loader->add_action( 'wp_ajax_wpstream_on_board_create_channel_ppv', $plugin_admin,'wpstream_on_board_create_channel_ppv' );
240 $this->loader->add_action( 'wp_ajax_wpstream_on_board_create_free_vod', $plugin_admin,'wpstream_on_board_create_free_vod' );
241 $this->loader->add_action( 'wp_ajax_wpstream_on_board_create_ppv_vod', $plugin_admin,'wpstream_on_board_create_ppv_vod' );
242
243
244 $this->loader->add_action( 'wp_ajax_wpstream_on_board_login', $plugin_admin,'wpstream_on_board_login' );
245 $this->loader->add_action( 'wp_ajax_wpstream_on_board_register', $plugin_admin,'wpstream_on_board_register' );
246
247
248 $this->loader->add_action( 'admin_notices', $plugin_admin,'wpstream_admin_notice' );
249 $this->loader->add_action( 'wp_ajax_wpstream_update_cache_notice', $plugin_admin,'wpstream_update_cache_notice' );
250
251
252
253
254 // add and save category extra fields
255 $this->loader->add_action( 'category_edit_form_fields', $plugin_post_types, 'wpstream_category_callback_function', 10, 2);
256 $this->loader->add_action( 'category_add_form_fields', $plugin_post_types, 'wpstream_category_callback_add_function', 10, 2 );
257 $this->loader->add_action( 'created_category', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2);
258 $this->loader->add_action( 'edited_category', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2);
259
260 $this->loader->add_action( 'product_cat_edit_form_fields', $plugin_post_types, 'wpstream_category_callback_function', 10, 2);
261 $this->loader->add_action( 'product_cat_add_form_fields', $plugin_post_types, 'wpstream_category_callback_add_function', 10, 2 );
262 $this->loader->add_action( 'created_product_cat', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2);
263 $this->loader->add_action( 'edited_product_cat', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2);
264
265
266 $this->loader->add_action( 'wpstream_category_edit_form_fields', $plugin_post_types, 'wpstream_category_callback_function', 10, 2);
267 $this->loader->add_action( 'wpstream_category_add_form_fields', $plugin_post_types, 'wpstream_category_callback_add_function', 10, 2 );
268 $this->loader->add_action( 'created_wpstream_category', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2);
269 $this->loader->add_action( 'edited_wpstream_category', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2);
270
271
272 $this->loader->add_action( 'wpstream_actors_edit_form_fields', $plugin_post_types, 'wpstream_category_callback_function', 10, 2);
273 $this->loader->add_action( 'wpstream_actors_add_form_fields', $plugin_post_types, 'wpstream_category_callback_add_function', 10, 2 );
274 $this->loader->add_action( 'created_wpstream_actors', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2);
275 $this->loader->add_action( 'edited_wpstream_actors', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2);
276
277 $this->loader->add_action( 'wpstream_movie_rating_edit_form_fields', $plugin_post_types, 'wpstream_category_callback_function', 10, 2);
278 $this->loader->add_action( 'wpstream_movie_rating_add_form_fields', $plugin_post_types, 'wpstream_category_callback_add_function', 10, 2 );
279 $this->loader->add_action( 'created_wpstream_movie_rating', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2);
280 $this->loader->add_action( 'edited_wpstream_movie_rating', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2);
281
282
283
284
285 if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
286
287 $this->loader->add_filter( 'product_type_selector', $plugin_admin, 'wpstream_add_products' );
288 $this->loader->add_action( 'admin_footer', $plugin_admin, 'wpstream_products_custom_js' );
289 $this->loader->add_filter( 'woocommerce_product_data_tabs', $plugin_admin, 'wpstream_hide_attributes_data_panel',10,1 );
290 $this->loader->add_filter( 'woocommerce_is_purchasable', $plugin_admin, 'wpstream_hide_buy_now_subscription_mode',10,2);
291
292 $this->loader->add_filter( 'woocommerce_product_options_general_product_data',$plugin_admin, 'wpstream_add_custom_general_fields', 10,1);
293 $this->loader->add_filter( 'woocommerce_process_product_meta',$plugin_admin, 'wpstream_add_custom_general_fields_save',10,1 );
294 $this->loader->add_action( 'woocommerce_live_stream_add_to_cart', $plugin_admin, 'wpstream_add_to_cart',10,1);
295 $this->loader->add_action( 'woocommerce_video_on_demand_add_to_cart', $plugin_admin, 'wpstream_add_to_cart',10,1);
296 $this->loader->add_filter( 'woocommerce_loop_add_to_cart_link', $plugin_admin,'replacing_add_to_cart_button', 10, 2 );
297 }
298
299
300
301
302
303
304 }
305
306
307
308
309
310 /**
311 * Register all of the hooks related to the public-facing functionality
312 * of the plugin.
313 *
314 * @since 3.0.1
315 * @access private
316 */
317 private function define_public_hooks() {
318
319 $plugin_public = new Wpstream_Public( $this->get_plugin_name(), $this->get_version(), $this->main );
320
321 $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
322 $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
323
324 $this->loader->add_action( 'init', $plugin_public,'wpstream_my_custom_endpoints' );
325 $this->loader->add_filter( 'query_vars',$plugin_public, 'wpstream_my_custom_query_vars', 0 );
326
327 //live stream action
328 $this->loader->add_action('init',$plugin_public,'wpstream_set_cookies',0);
329 $this->loader->add_action('init',$plugin_public,'wpstream_live_streaming_key');
330 $this->loader->add_action('init',$plugin_public,'wpstream_live_streaming_key_for_3rdparty');
331 $this->loader->add_action('init',$plugin_public,'wpstream_live_streaming_key_vod',10);
332 // woo action
333
334 $this->loader->add_action( 'woocommerce_before_single_product', $plugin_public,'wpstream_non_image_content_wrapper_start', 20 );
335 $this->loader->add_action( 'woocommerce_after_single_product', $plugin_public,'wpstream_non_image_content_wrapper_end', 20 );
336 $this->loader->add_action( 'woocommerce_thankyou_order_received_text', $plugin_public,'wpstream_thankyou_extra', 20,2 );
337 $this->loader->add_action( 'woocommerce_email_order_details', $plugin_public,'wpstream_email_order_details', 20,4 );
338
339 $this->loader->add_filter( 'woocommerce_account_menu_items', $plugin_public,'wpstream_custom_my_account_menu_items' );
340 $this->loader->add_action( 'woocommerce_account_event-list_endpoint', $plugin_public,'wpstream_custom_endpoint_content_event_list' );
341 $this->loader->add_action( 'woocommerce_account_video-list_endpoint', $plugin_public,'wpstream_custom_endpoint_video_list' );
342
343
344 $this->loader->add_action( 'after_switch_theme', $plugin_public,'wpstream_custom_flush_rewrite_rules' );
345 $this->loader->add_action('init', $plugin_public,'wpstream_shortcodes');
346 $this->loader->add_action('vc_before_init', $plugin_public,'wpstream_bakery_shortcodes');
347
348
349 $this->loader->add_action('wo_before_api', 'wpstream_cors_check_and_response',10,1);
350
351
352
353 }
354
355 /**
356 * Run the loader to execute all of the hooks with WordPress.
357 *
358 * @since 3.0.1
359 */
360 public function run() {
361 $this->loader->run();
362 }
363
364 /**
365 * The name of the plugin used to uniquely identify it within the context of
366 * WordPress and to define internationalization functionality.
367 *
368 * @since 3.0.1
369 * @return string The name of the plugin.
370 */
371 public function get_plugin_name() {
372 return $this->plugin_name;
373 }
374
375 /**
376 * The reference to the class that orchestrates the hooks with the plugin.
377 *
378 * @since 3.0.1
379 * @return Wpstream_Loader Orchestrates the hooks of the plugin.
380 */
381 public function get_loader() {
382 return $this->loader;
383 }
384
385 /**
386 * Retrieve the version number of the plugin.
387 *
388 * @since 3.0.1
389 * @return string The version number of the plugin.
390 */
391 public function get_version() {
392 return $this->version;
393 }
394
395
396
397 public function show_user_data($pack_details){
398 if( isset($pack_details['available_data_mb']) && isset( $pack_details['available_storage_mb']) ){
399 $wpstream_convert_band = $this->wpstream_convert_band($pack_details['available_data_mb']);
400 if($wpstream_convert_band<0)$wpstream_convert_band=0;
401 // print_r($pack_details);
402 $wpstream_convert_storage = $this->wpstream_convert_band($pack_details['available_storage_mb']);
403 if($wpstream_convert_storage<0)$wpstream_convert_storage=0;
404
405 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 recording storage','wpstream');
406 print '<a href="https://wpstream.net/pricing/" class="wpstream_upgrade_topbar" target="_blank">'.esc_html__('Upgrade Subscription','wpstream').'</a>';
407 print '</div>';
408 print'<input type="hidden" id="wpstream_band" value="'.$pack_details['available_data_mb'].'">';
409 print'<input type="hidden" id="wpstream_storage" value="'.$pack_details['available_storage_mb'].'">';
410
411 }
412 }
413
414
415 /**
416 * help function for media list elementor widget
417 *
418 * @since 3.0.1
419 * @return string
420 */
421
422 public function wpstream_media_list_elementor_function($attributes, $content = null){
423
424
425
426 ob_start();
427
428 $media_number=3;
429 if ( isset($attributes['media_number']) ){
430 $media_number=$attributes['media_number'];
431 }
432
433 // check if is vod or live stream
434 $meta_query = array();
435 $tax_query_array= array();
436 $tax_query = array();
437
438 // check if the media is paid or free
439 $event_types = array();
440 $product_type_free_paid = 0;
441 if ( isset($attributes['product_type_free_paid']) ){
442 $product_type_free_paid=$attributes['product_type_free_paid'];
443
444 if($product_type_free_paid==0){
445 $event_types=array('wpstream_product');
446
447 if ( isset($attributes['product_type']) && intval($attributes['product_type'])==2){
448 $event_types=array('wpstream_product_vod');
449
450
451
452 }
453
454
455
456 }else{
457 $event_types=array('product');
458 if ( isset($attributes['product_type']) ){
459 $product_type = $attributes['product_type'];
460 $product_type_slug = 'video_on_demand';
461 if($product_type==1){
462 $product_type_slug ='live_stream';
463 }
464
465 $tax_query_array = array(
466 'taxonomy' => 'product_type',
467 'field' => 'slug',
468 'terms' => $product_type_slug
469 );
470
471 $tax_query= array(
472 'relation' => 'AND',
473 $tax_query_array
474 );
475
476 }
477 }
478
479 }
480 $see_product='';
481 if(isset($attributes['free_label'])){
482 $see_product=$attributes['free_label'];
483 }
484
485 // pagination
486 $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
487 if( is_front_page() ){
488 $paged= (get_query_var('page')) ? get_query_var('page') : 1;
489 }
490
491
492 //order
493 $orderby='ID';
494 $order ='ASC';
495 if ( isset($attributes['order_by']) ){
496 $order_by=intval($attributes['order_by']);
497 switch ($order_by) {
498 case 0:
499 $orderby='ID';
500 $order ='ASC';
501 break;
502 case 1:
503 $orderby='ID';
504 $order ='DESC';
505 break;
506 case 2:
507 $orderby='title';
508 $order ='ASC';
509 break;
510 case 3:
511 $orderby='title';
512 $order ='DESC';
513 break;
514 }
515 }
516
517 // building wp_query arg array
518 $args = array(
519 'post_type' => $event_types,
520 'post_status' => 'publish',
521 'meta_query' => $meta_query,
522 'posts_per_page' => $media_number,
523 'paged' => $paged,
524 'orderby' => $orderby,
525 'order' => $order,
526 'tax_query' => $tax_query
527 );
528
529
530
531 // show live events
532 if ( isset($attributes['product_show_live']) && $attributes['product_show_live']=='yes'){
533 $live_event_for_user = $this->main->wpstream_live_connection->api20_wpstream_request_live_stream_for_user_for_shortcode('shortcode');
534
535
536 if( is_array($live_event_for_user) ){
537 $live_event_for_user[]=0;
538
539 $args['post__in']=$live_event_for_user;
540 }
541 }
542
543
544
545
546 $media_list= new WP_Query($args);
547 if($media_list->have_posts()){
548 print '<ul class="wpstream_media_list_wrapper products columns-3" >';
549 while($media_list->have_posts()):$media_list->the_post();
550 if($product_type_free_paid==0 ){
551
552 $thumb=wp_get_attachment_image_src(get_post_thumbnail_id(),'medium');
553
554 $thumb_src='';
555 if( isset($thumb[0]) ){
556 $thumb_src=$thumb[0];
557 }
558
559 if(($thumb_src)==''){
560 $thumb_src= plugin_dir_url( dirname( __FILE__ ) ). 'img/default_300.png';
561 }
562 print '<li class="wpstream_product_unit">'
563 .'<a href="'.get_permalink().'" class="product_title" ><div class="product_image" style="background-image:url('.esc_url($thumb_src).')"></div></a>'
564 .'<a href="'.get_permalink().'" class="product_title" >'.get_the_title().'</a>';
565
566 if($see_product!=''){
567 print '<a href="'.get_permalink().'"class="see_product">'.$see_product.'</a>';
568 }
569 print '</li>';
570 }else{
571 wc_get_template_part( 'content', 'product' );
572 }
573 endwhile;
574 print '</ul>';
575 }else{
576 print esc_html__('No media found! ','wpstream');
577 }
578
579
580 wp_reset_query();
581 wp_reset_postdata();
582
583 $this->wpstream_pagination($media_list->max_num_pages,$range=2);
584 $return_string= ob_get_contents();
585 ob_end_clean();
586
587 return $return_string;
588 }
589
590
591
592
593
594
595 /*
596 *
597 *
598 * Pagination for media lista
599 *
600 *
601 *
602 */
603
604
605
606
607 function wpstream_pagination($pages = '', $range = 2){
608
609 $showitems = ($range * 2)+1;
610 global $paged;
611 if(empty($paged)) $paged = 1;
612
613
614 if($pages == ''){
615 global $wp_query;
616 $pages = $wp_query->max_num_pages;
617 if(!$pages)
618 {
619 $pages = 1;
620 }
621 }
622
623 if(1 != $pages){
624 print '<ul class="wpstream_pagination ">';
625 print '<li class="roundleft"><a href="'.get_pagenum_link($paged - 1).'"> < </a></li>';
626
627 for ($i=1; $i <= $pages; $i++)
628 {
629 if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
630 {
631 if ($paged == $i){
632 print '<li class="active"><a href="'.esc_url(get_pagenum_link($i)).'" >'.$i.'</a><li>';
633 }else{
634 print '<li><a href="'.esc_url(get_pagenum_link($i)).'" >'.$i.'</a><li>';
635 }
636 }
637 }
638
639 $prev_page= get_pagenum_link($paged + 1);
640 if ( ($paged +1) > $pages){
641 $prev_page= get_pagenum_link($paged );
642 }else{
643 $prev_page= get_pagenum_link($paged + 1);
644 }
645
646
647 print '<li class="roundright"><a href="'.$prev_page.'"> > </a><li>';
648 print '</ul>';
649 }
650 }
651
652
653
654
655
656
657
658
659
660
661
662
663
664 /**
665 * help function for player elementr widget
666 *
667 * @since 3.0.1
668 * @return string
669 */
670
671 public function wpstream_insert_player_elementor($attributes, $content = null){
672 $product_id = '';
673 $return_string = '';
674 $attributes = shortcode_atts(
675 array(
676 'id' => 0,
677 'user_id' => 0,
678 ), $attributes) ;
679
680
681 if ( isset($attributes['id']) ){
682 $product_id=$attributes['id'];
683 }
684 if ( isset($attributes['user_id']) ){
685 $user_id = intval( $attributes['user_id'] );
686 }
687
688 if(intval($product_id)==0 && $user_id!=0 ){
689 $product_id= $this->wpstream_player_retrive_first_id($user_id);
690 }
691
692
693
694
695 ob_start();
696 $this->main->wpstream_player->wpstream_video_player_shortcode($product_id);
697 $return_string= ob_get_contents();
698 ob_end_clean();
699
700 return $return_string;
701 }
702
703 /**
704 * help function for player low latency elementor widget
705 *
706 * @since 3.0.1
707 * @return string
708 */
709
710 public function wpstream_insert_player__low_latency_elementor($attributes, $content = null){
711 $product_id = '';
712 $return_string = '';
713 $attributes = shortcode_atts(
714 array(
715 'id' => 0,
716 'user_id' => 0,
717 ), $attributes) ;
718
719
720 if ( isset($attributes['id']) ){
721 $product_id=$attributes['id'];
722 }
723
724 if ( isset($attributes['user_id']) ){
725 $user_id = intval( $attributes['user_id'] );
726 }
727
728 if(intval($product_id)==0 && $user_id!=0){
729 $product_id= $this->wpstream_player_retrive_first_id($user_id);
730 }
731
732
733 ob_start();
734 $this->main->wpstream_player->wpstream_video_player_shortcode_low_latency($product_id);
735 $return_string= ob_get_contents();
736 ob_end_clean();
737
738 return $return_string;
739 }
740
741
742
743 public function wpstream_player_retrive_first_id($received_user_id=''){
744 $channel_type = get_option ('wpstream_user_streaming_channel_type');
745 $product_id = $this->wpstream_get_current_event_per_author($received_user_id,$channel_type);
746 return $product_id;
747 }
748
749
750
751 /**
752 * help function for chat elementor widget
753 *
754 * @since 3.0.1
755 * @return string
756 */
757
758 public function wpstream_insert_chat_elementor($attributes, $content = null){
759 $product_id = '';
760 $return_string = '';
761 $attributes = shortcode_atts(
762 array(
763 'id' => 0,
764 ), $attributes) ;
765
766
767 if ( isset($attributes['id']) ){
768 $product_id=$attributes['id'];
769 }
770
771 $return_string.= '<div class="wpstream_plugin_chat_wrapper">';
772 ob_start();
773 $this->main->wpstream_player->wpstream_chat_wrapper($product_id);
774 $return_string.= ob_get_contents();
775 ob_end_clean();
776 $return_string.='</div>';
777 $this->main->wpstream_player->wpstream_connect_to_chat($product_id);
778
779 return $return_string;
780 }
781
782
783 /**
784 * edited 4.0
785 *
786 * Check if user is allowed to stream
787 *
788 * @since 3.7
789 */
790
791 public function wpstream_check_user_can_stream(){
792 $current_user = wp_get_current_user();
793
794 if( !is_user_logged_in() ){
795 return false;
796 exit('user not logged in');
797 }
798
799 if(current_user_can('administrator')){
800 // admins can always brodcast
801 return true;
802 }
803
804 $extra_roles = get_option( 'wpstream_stream_role', true );
805 $user_role = $current_user->roles[0];
806
807 if (is_array($extra_roles) && in_array($user_role, $extra_roles)){
808 return true;
809 }
810
811 if(function_exists('wpstream_get_option') && intval(wpstream_get_option('allow_streaming_regular_users',''))==1 ){
812 return true;
813 }
814
815 return false;
816 }
817
818
819 /**
820 * Start Streaming wrapper
821 *
822 * @since 3.7
823 */
824
825 public function wpstream_live_stream_unit_wrapper($item_id,$type){
826 $item_id = intval($item_id);
827
828 if($item_id == 0){
829 //retrive or create channel for front end streamers
830 $item_id=$this->wpstream_retrive_front_end_channel();
831 }
832 print'</div><div class="wpstream_modal_background"></div>';
833 print '<div class="wpstream_error_modal_notification"><div class="wpstream_error_content">er2</div>
834 <div class="wpstream_error_ok wpstream_button" type="button">'.esc_html__('Close','wpstream').'</div>
835 </div>';
836 $this->admin->wpstream_live_stream_unit( $item_id,$type );
837 }
838
839
840
841
842
843 /**
844 * retrive channel for front end streaming
845 *
846 * @since 3.7
847 */
848 public function wpstream_retrive_front_end_channel(){
849
850 $current_user = wp_get_current_user();
851 $channel_type = get_option ('wpstream_user_streaming_channel_type');
852 $channel_price = floatval( get_option ('wpstream_user_streaming_default_price') );
853
854 $front_end_streamin_channel = $this->wpstream_get_current_event_per_author($current_user->ID,$channel_type);
855
856 if(intval($front_end_streamin_channel) == 0){
857 $front_end_streamin_channel= $this->wpstrea_create_front_end_event($current_user->ID,$current_user->user_login ,$channel_type,$channel_price);
858 }
859 return $front_end_streamin_channel;
860
861 }
862
863 /**
864 * create the event from front end
865 *
866 * @since 3.7
867 */
868
869 public function wpstrea_create_front_end_event($userID,$userLogin,$channel_type,$channel_price){
870
871 if( !$this->wpstream_check_user_can_stream() ){
872 return;
873 }
874
875 $post_type='wpstream_product';
876 if($channel_type=='paid'){
877 $post_type='product';
878 }
879
880 $post = array(
881 'post_title' => sprintf( esc_html__('%s Channel','wpstream'),$userLogin),
882 'post_content' => '',
883 'post_type' => $post_type ,
884 'post_author' => $userID,
885 'post_status' => 'publish',
886 );
887 $post_id = wp_insert_post($post );
888 if($channel_type=='paid'){
889 $product = wc_get_product($post_id);
890 $price = wc_format_decimal($channel_price);
891
892 $product = wc_get_product( $post_id );
893 // Set the product active price (regular)
894 $product->set_price( $price );
895 $product->set_regular_price( $price ); // To be sure
896 $product->save();
897 update_post_meta ($post_id,'event_passed',0);
898 wp_set_object_terms( $post_id, 'live_stream', 'product_type' );
899 }
900 update_post_meta($post_id,'wpstream_product_type',1);
901
902 return $post_id;
903 }
904
905
906 public function wpstream_get_current_event_per_author($userID,$channel_type){
907
908 $post_type='wpstream_product';
909 if($channel_type=='paid'){
910 $post_type='product';
911 }
912
913 $args = array(
914
915 'post_type' => $post_type,
916 'author' => $userID,
917 'posts_per_page' => 1,
918 'fields' => 'ids'
919 )
920 ;
921 $author_posts = new WP_Query( $args );
922 if( $author_posts->have_posts() ) {
923 $author_posts->the_post();
924 return get_the_ID();
925 }else{
926 return 0;
927 }
928
929 wp_reset_query();
930 wp_reset_postdata();
931 }
932
933 }
934