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

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

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