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

1,090 lines 44.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The file that defines the core plugin class
4 *
5 * A class definition that includes attributes and functions used across both the
6 * public-facing side of the site and the admin area.
7 *
8 * @link http://wpstream.net
9 * @since 3.0.1
10 *
11 * @package Wpstream
12 * @subpackage Wpstream/includes
13 */
14
15 /**
16 * The core plugin class.
17 *
18 * This is used to define internationalization, admin-specific hooks, and
19 * public-facing site hooks.
20 *
21 * Also maintains the unique identifier of this plugin as well as the current
22 * version of the plugin.
23 *
24 * @since 3.0.1
25 * @package Wpstream
26 * @subpackage Wpstream/includes
27 * @author wpstream <office@wpstream.net>
28 */
29 class Wpstream {
30
31 /**
32 * Store plugin main class to allow public access.
33 *
34 * @since 3.0.1
35 * @var object The main class.
36 */
37 public $main;
38 public $admin;
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 $quota_manager;
81 public $user_quota_service;
82 public $xtest;
83 public $plugin_admin;
84
85 public function __construct() {
86 $this->main = $this;
87
88 if ( defined( 'WPSTREAM_PLUGIN_VERSION' ) ) {
89 $this->version = WPSTREAM_PLUGIN_VERSION;
90 } else {
91 $this->version = '3.0.1';
92 }
93
94 $this->plugin_name = 'wpstream';
95
96 $this->load_dependencies();
97 $this->define_admin_hooks();
98 $this->define_public_hooks();
99 $this->define_ajax_hooks();
100 $this->wpstream_load_page_templates();
101 $this->wpstream_load_theme_notice();
102
103 $this->wpstream_conection();
104 $this->wpstream_player();
105 $this->wpstream_init_quota_manager();
106
107 }
108
109
110
111
112
113 public function wpstream_convert_band($megabits){
114 $gigabit = $megabits * 0.001;
115 return floatval( sprintf( '%.1f', $gigabit ) );
116 }
117
118 /**
119 * Floor a number to a given number of decimal places.
120 *
121 * @param float $value The number to floor.
122 * @param int $decimals Number of decimal places.
123 * @return float
124 */
125 public function wpstream_floor_decimals( $value, $decimals = 2 ) {
126 $decimals = max( 0, (int) $decimals );
127 $factor = pow( 10, $decimals );
128
129 return floatval( sprintf( '%.' . $decimals . 'f', floor( (float) $value * $factor ) / $factor ) );
130 }
131
132
133 public $wpstream_ajax;
134
135 private function define_ajax_hooks() {
136 require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-wpstream-ajax.php';
137 $this->wpstream_ajax = new WpStream_Ajax( $this->main );
138 }
139
140
141 private function wpstream_conection(){
142 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpstream-live-api-connection.php';
143 $this->wpstream_live_connection = new Wpstream_Live_Api_Connection();
144 $this->user_quota_service = $this->wpstream_live_connection->get_user_quota_service();
145 }
146
147
148 private function wpstream_player(){
149 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpstream-player.php';
150 $this->wpstream_player = new Wpstream_Player($this->main);
151 }
152
153 private function wpstream_init_quota_manager() {
154 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpstream-quota-manager.php';
155 $this->quota_manager = new Wpstream_Quota_Manager( $this );
156 }
157
158
159 private function wpstream_load_page_templates() {
160 require_once WPSTREAM_PLUGIN_PATH . 'includes/class-wpstream-templates.php';
161 new WpStream_Template_Loader();
162 }
163
164 private function wpstream_load_theme_notice() {
165 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpstream-theme-notice.php';
166 new WPStream_Theme_Notice();
167 }
168
169
170 /**
171 * Load the required dependencies for this plugin.
172 *
173 * Include the following files that make up the plugin:
174 *
175 * - Wpstream_Loader. Orchestrates the hooks of the plugin.
176 * - Wpstream_i18n. Defines internationalization functionality.
177 * - Wpstream_Admin. Defines all hooks for the admin area.
178 * - Wpstream_Public. Defines all hooks for the public side of the site.
179 *
180 * Create an instance of the loader which will be used to register the hooks
181 * with WordPress.
182 *
183 * @since 3.0.1
184 * @access private
185 */
186 private function load_dependencies() {
187
188 /**
189 * The class responsible for orchestrating the actions and filters of the
190 * core plugin.
191 */
192 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpstream-loader.php';
193
194 /**
195 * The class responsible for defining internationalization functionality
196 * of the plugin.
197 */
198 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpstream-i18n.php';
199
200 /**
201 * The class responsible for defining all actions that occur in the admin area.
202 */
203 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wpstream-admin.php';
204
205 /**
206 * The class responsible for defining all actions that occur in the public-facing
207 * side of the site.
208 */
209 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wpstream-public.php';
210 /**
211 * The class responsible for custom post type
212
213 */
214 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpstream_product.php';
215 if( class_exists( 'WooCommerce' ) ){
216 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wc_product_live_stream.php';
217 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wc_product_video_on_demand.php';
218 }
219
220 require_once plugin_dir_path(__FILE__) . 'Helpers/class-wpstream-log-entry.php';
221 require_once plugin_dir_path(__FILE__) . 'Logger/class-wpstream-logger.php';
222
223 $this->loader = new Wpstream_Loader();
224
225 }
226
227 /**
228 * Define the locale for this plugin for internationalization.
229 *
230 * Uses the Wpstream_i18n class in order to set the domain and to register the hook
231 * with WordPress.
232 *
233 * @since 3.0.1
234 * @access private
235 */
236 private function set_locale() {
237
238 $plugin_i18n = new Wpstream_i18n();
239
240 $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain', 1 );
241
242 }
243
244 /**
245 * Register all of the hooks related to the admin area functionality
246 * of the plugin.
247 *
248 * @since 3.0.1
249 * @access private
250 */
251 private function define_admin_hooks() {
252
253 $plugin_admin = new Wpstream_Admin( $this->get_plugin_name(), $this->get_version(), $this->main );
254
255 $this->admin = $plugin_admin;
256
257 $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
258 $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
259 $this->loader->add_action( 'admin_menu', $plugin_admin, 'wpstream_manage_admin_menu',999);
260
261 $plugin_post_types = new Wpstream_Product();
262 $this->loader->add_action( 'init', $plugin_post_types, 'create_custom_post_type', 999 );
263
264 // save and render metaboxed
265 $this->loader->add_action( 'add_meta_boxes', $plugin_admin, 'add_wpstream_product_metaboxes' );
266 $this->loader->add_action( 'save_post', $plugin_admin, 'wpstream_free_product_update_post',1,2 );
267 $this->loader->add_action( 'publish_wpstream_product', $plugin_admin, 'wpstream_publish_wpstream_product',1,2 );
268
269
270
271 // make product virtual
272 $this->loader->add_action( 'save_post', $plugin_admin, 'wpstream_make_product_virtual', 99999, 2 );
273
274
275
276 // show streaming controls on sidebar
277 $this->loader->add_action('add_meta_boxes', $plugin_admin, 'wpstream_startstreaming_sidebar_meta');
278
279 // on boarding actions
280 $this->loader->add_action('admin_footer',$plugin_admin, 'wpstream_admin_footer_onboarding');
281 $this->loader->add_action( 'wp_ajax_wpstream_on_board_create_channel', $plugin_admin,'wpstream_on_board_create_channel' );
282 $this->loader->add_action( 'wp_ajax_wpstream_on_board_create_channel_ppv', $plugin_admin,'wpstream_on_board_create_channel_ppv' );
283 $this->loader->add_action( 'wp_ajax_wpstream_on_board_create_free_vod', $plugin_admin,'wpstream_on_board_create_free_vod' );
284 $this->loader->add_action( 'wp_ajax_wpstream_on_board_create_ppv_vod', $plugin_admin,'wpstream_on_board_create_ppv_vod' );
285
286
287 $this->loader->add_action( 'wp_ajax_wpstream_on_board_login', $plugin_admin,'wpstream_on_board_login' );
288 $this->loader->add_action( 'wp_ajax_wpstream_on_board_register', $plugin_admin,'wpstream_on_board_register' );
289 $this->loader->add_action( 'wp_ajax_wpstream_get_captcha_challenge', $plugin_admin, 'wpstream_get_captcha_challenge' );
290 $this->loader->add_action( 'wp_ajax_nopriv_wpstream_get_captcha_challenge', $plugin_admin, 'wpstream_get_captcha_challenge' );
291
292 // Register AJAX actions for multipart uploads
293 $this->loader->add_action( 'wp_ajax_wpstream_initiate_multipart_upload', $plugin_admin, 'handle_initiate_multipart_upload' );
294 $this->loader->add_action( 'wp_ajax_wpstream_complete_multipart_upload', $plugin_admin, 'handle_complete_multipart_upload' );
295
296 $this->loader->add_action( 'admin_notices', $plugin_admin,'wpstream_admin_notice' );
297 $this->loader->add_action( 'admin_notices', $plugin_admin,'wpstream_plugin_update_available_notice' );
298
299 $this->loader->add_action( 'wp_ajax_wpstream_update_cache_notice', $plugin_admin,'wpstream_update_cache_notice' );
300 // $this->loader->add_action( 'wp_ajax_wpstream_get_videos_list', $plugin_admin,'wpstream_get_videos_list' );
301
302
303 $this->loader->add_action( 'wp_ajax_wpstream_settings_tab_update_plugin', $plugin_admin, 'wpstream_settings_tab_update_plugin' );
304
305 // add and save category extra fields
306 $this->loader->add_action( 'category_edit_form_fields', $plugin_post_types, 'wpstream_category_callback_function', 10, 2);
307 $this->loader->add_action( 'category_add_form_fields', $plugin_post_types, 'wpstream_category_callback_add_function' );
308 $this->loader->add_action( 'created_category', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2);
309 $this->loader->add_action( 'edited_category', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2);
310
311 $this->loader->add_action( 'product_cat_edit_form_fields', $plugin_post_types, 'wpstream_category_callback_function', 10, 2);
312 $this->loader->add_action( 'product_cat_add_form_fields', $plugin_post_types, 'wpstream_category_callback_add_function' );
313 $this->loader->add_action( 'created_product_cat', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2);
314 $this->loader->add_action( 'edited_product_cat', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2);
315
316
317 $this->loader->add_action( 'wpstream_category_edit_form_fields', $plugin_post_types, 'wpstream_category_callback_function', 10, 2);
318 $this->loader->add_action( 'wpstream_category_add_form_fields', $plugin_post_types, 'wpstream_category_callback_add_function' );
319 $this->loader->add_action( 'created_wpstream_category', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2);
320 $this->loader->add_action( 'edited_wpstream_category', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2);
321
322
323 $this->loader->add_action( 'wpstream_actors_edit_form_fields', $plugin_post_types, 'wpstream_category_callback_function', 10, 2);
324 $this->loader->add_action( 'wpstream_actors_add_form_fields', $plugin_post_types, 'wpstream_category_callback_add_function' );
325 $this->loader->add_action( 'created_wpstream_actors', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2);
326 $this->loader->add_action( 'edited_wpstream_actors', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2);
327
328 $this->loader->add_action( 'wpstream_movie_rating_edit_form_fields', $plugin_post_types, 'wpstream_category_callback_function', 10, 2);
329 $this->loader->add_action( 'wpstream_movie_rating_add_form_fields', $plugin_post_types, 'wpstream_category_callback_add_function' );
330 $this->loader->add_action( 'created_wpstream_movie_rating', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2);
331 $this->loader->add_action( 'edited_wpstream_movie_rating', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2);
332
333
334 if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
335
336 $this->loader->add_action( 'init', $plugin_admin, 'wpstream_add_custom_wc_products' );
337 $this->loader->add_filter( 'product_type_selector', $plugin_admin, 'wpstream_add_products' );
338 $this->loader->add_filter( 'woocommerce_product_class', $plugin_admin, 'wpstream_add_products_class', 10, 2 );
339 $this->loader->add_action( 'admin_footer', $plugin_admin, 'wpstream_products_custom_js' );
340 $this->loader->add_filter( 'woocommerce_product_data_tabs', $plugin_admin, 'wpstream_hide_attributes_data_panel',10,1 );
341 $this->loader->add_filter( 'woocommerce_is_purchasable', $plugin_admin, 'wpstream_hide_buy_now_subscription_mode',10,2);
342
343 $this->loader->add_action( 'woocommerce_product_options_general_product_data', $plugin_admin, 'wpstream_add_custom_general_fields', 20 );
344 $this->loader->add_filter( 'woocommerce_process_product_meta',$plugin_admin, 'wpstream_add_custom_general_fields_save',10,1 );
345 $this->loader->add_action( 'woocommerce_live_stream_add_to_cart', $plugin_admin, 'wpstream_add_to_cart',10,1);
346 $this->loader->add_action( 'woocommerce_video_on_demand_add_to_cart', $plugin_admin, 'wpstream_add_to_cart',10,1);
347 $this->loader->add_filter( 'woocommerce_loop_add_to_cart_link', $plugin_admin,'replacing_add_to_cart_button', 10, 2 );
348 }
349 }
350
351
352
353
354
355 /**
356 * Register all of the hooks related to the public-facing functionality
357 * of the plugin.
358 *
359 * @since 3.0.1
360 * @access private
361 */
362 private function define_public_hooks() {
363
364 $plugin_public = new Wpstream_Public( $this->get_plugin_name(), $this->get_version(), $this->main );
365
366 $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
367 // Registered on `wp` (not `wp_enqueue_scripts`/`wp_head`) because block themes render
368 // the Post Content block - and thus our `the_content` filter that enqueues/localizes
369 // these scripts - before `wp_head` ever fires, leaving the handles unregistered.
370 $this->loader->add_action( 'wp', $plugin_public, 'enqueue_scripts' );
371
372 $this->loader->add_action( 'init', $plugin_public,'wpstream_my_custom_endpoints' );
373 $this->loader->add_filter( 'query_vars',$plugin_public, 'wpstream_my_custom_query_vars', 0 );
374
375 //live stream action
376 $this->loader->add_action('init',$plugin_public,'wpstream_set_cookies',0);
377 $this->loader->add_action('init',$plugin_public,'wpstream_live_streaming_key');
378 $this->loader->add_action('init',$plugin_public,'wpstream_live_streaming_key_for_3rdparty');
379 $this->loader->add_action('init',$plugin_public,'wpstream_live_streaming_key_vod',10);
380
381 // woo action
382 $this->loader->add_action( 'woocommerce_before_single_product', $plugin_public,'wpstream_non_image_content_wrapper_start', 20 );
383 $this->loader->add_action( 'woocommerce_after_single_product', $plugin_public,'wpstream_non_image_content_wrapper_end', 20 );
384 $this->loader->add_action( 'woocommerce_thankyou_order_received_text', $plugin_public,'wpstream_thankyou_extra', 20,2 );
385 $this->loader->add_action( 'woocommerce_email_order_details', $plugin_public,'wpstream_email_order_details', 20,4 );
386
387 $this->loader->add_filter( 'woocommerce_account_menu_items', $plugin_public,'wpstream_custom_my_account_menu_items' );
388 $this->loader->add_action( 'woocommerce_account_event-list_endpoint', $plugin_public,'wpstream_custom_endpoint_content_event_list' );
389 $this->loader->add_action( 'woocommerce_account_video-list_endpoint', $plugin_public,'wpstream_custom_endpoint_video_list' );
390
391 $this->loader->add_action( 'after_switch_theme', $plugin_public,'wpstream_custom_flush_rewrite_rules' );
392 $this->loader->add_action('init', $plugin_public,'wpstream_shortcodes');
393 $this->loader->add_action('vc_before_init', $plugin_public,'wpstream_bakery_shortcodes');
394
395 $this->loader->add_action('wo_before_api', 'wpstream_cors_check_and_response',10,1);
396
397 $this->loader->add_filter( 'wpstream_search_template_item_post_type', $plugin_public, 'wpstream_search_template_add_item_post_type' );
398 $this->loader->add_filter( 'wpstream_sidebar_id_by_post_type', $plugin_public, 'wpstream_sidebar_id_by_post_type' );
399 $this->loader->add_filter( 'wpstream_header_search_values', $plugin_public, 'wpstream_header_search_values' );
400 $this->loader->add_filter( 'wpstream_extend_category_archive_query_filter', $plugin_public, 'wpstream_extend_category_archive_query_filter_callback' );
401 $this->loader->add_filter( 'wpstream_archives_lists_taxonomy_labels', $plugin_public, 'wpstream_archives_lists_taxonomy_labels_callback' );
402 $this->loader->add_filter( 'wpstream_author_archive_list_taxonomy_labels', $plugin_public, 'wpstream_author_archive_list_taxonomy_labels_callback' );
403 $this->loader->add_action( 'wpstream_vod_attached_to_channel', $plugin_public, 'wpstream_vod_attached_to_channel' );
404 $this->loader->add_action( 'wpstream_additional_content_post_type', $plugin_public, 'wpstream_additional_content_post_type_callback' );
405 $this->loader->add_action( 'wpstream_post_author_content_post_type_list', $plugin_public, 'wpstream_post_author_content_post_type_list_callback' );
406 $this->loader->add_action( 'wpstream_author_content_simple_post_type_message', $plugin_public, 'wpstream_author_content_simple_post_type_message_callback', 10, 2 );
407 $this->loader->add_action( 'wpstream_author_content_post_type_message', $plugin_public, 'wpstream_author_content_post_type_message_callback', 10, 2 );
408 $this->loader->add_action( 'wpstream_show_sidebar_for_post_type', $plugin_public, 'wpstream_show_sidebar_for_post_type_callback', 10, 2 );
409 $this->loader->add_action( 'wpstream_video_episodes_post_type', $plugin_public, 'wpstream_video_episodes_post_type_callback' );
410 $this->loader->add_action( 'wpstream_video_past_broadcast_post_type', $plugin_public, 'wpstream_video_past_broadcast_post_type_callback' );
411 $this->loader->add_action( 'wpstream_additional_content_post_type_label', $plugin_public, 'wpstream_additional_content_post_type_label_callback', 10, 2 );
412 }
413
414 /**
415 * Run the loader to execute all of the hooks with WordPress.
416 *
417 * @since 3.0.1
418 */
419 public function run() {
420 $this->loader->run();
421 }
422
423 /**
424 * The name of the plugin used to uniquely identify it within the context of
425 * WordPress and to define internationalization functionality.
426 *
427 * @since 3.0.1
428 * @return string The name of the plugin.
429 */
430 public function get_plugin_name() {
431 return $this->plugin_name;
432 }
433
434 /**
435 * The reference to the class that orchestrates the hooks with the plugin.
436 *
437 * @since 3.0.1
438 * @return Wpstream_Loader Orchestrates the hooks of the plugin.
439 */
440 public function get_loader() {
441 return $this->loader;
442 }
443
444 /**
445 * Retrieve the version number of the plugin.
446 *
447 * @since 3.0.1
448 * @return string The version number of the plugin.
449 */
450 public function get_version() {
451 return $this->version;
452 }
453
454 public function is_plugin_outdated(){
455 $update_data = get_site_transient('update_plugins');
456 $plugin_path = 'wpstream/wpstream.php';
457
458 if (isset($update_data->response[$plugin_path])) {
459 return true;
460 }
461
462 return false;
463 }
464
465
466
467 public function show_user_data($pack_details){
468 if ( ! isset( $pack_details['use_streaming_hours'] ) || $pack_details['use_streaming_hours'] !== true ) {
469 if ( isset( $pack_details['available_data_mb'] ) && isset( $pack_details['available_storage_mb'] ) ) {
470 $wpstream_convert_band = $this->wpstream_convert_band( $pack_details['available_data_mb'] );
471 if ( $wpstream_convert_band < 0 ) {
472 $wpstream_convert_band = 0;
473 }
474
475 $wpstream_convert_storage = $this->wpstream_convert_band( $pack_details['available_storage_mb'] );
476 if ( $wpstream_convert_storage < 0 ) {
477 $wpstream_convert_storage = 0;
478 }
479
480 print '<div class="pack_details_wrapper">'
481 . '<strong>' . __( 'Your account information: ', 'wpstream' ) . '</strong> '
482 . __( 'You have ', 'wpstream' ) . '<strong id="wpstream_available_data">' . abs( $wpstream_convert_band ) . ' GB</strong> '
483 . __( 'available cloud data and ', 'wpstream' )
484 . '<strong id="wpstream_available_storage">' . abs( $wpstream_convert_storage ) . ' GB</strong> '
485 . __( 'available cloud storage', 'wpstream' ) . '.';
486
487 print '<a href="https://wpstream.net/pricing/" class="wpstream_upgrade_topbar" target="_blank">' . esc_html__( 'Upgrade Plan', 'wpstream' ) . '</a>';
488 print '</div>';
489 print '<input type="hidden" id="wpstream_band" value="' . esc_attr( $pack_details['available_data_mb'] ) . '">';
490 print '<input type="hidden" id="wpstream_storage" value="' . esc_attr( $pack_details['available_storage_mb'] ) . '">';
491 }
492 } else {
493 if ( isset( $pack_details['available_viewer_hours'] ) && isset( $pack_details['available_broadcast_hours'] ) && isset( $pack_details['available_storage_hours'] ) ) {
494 $available_viewer_hours = floatval( $pack_details['available_viewer_hours'] );
495 if ( $available_viewer_hours < 0 ) {
496 $available_viewer_hours = 0;
497 }
498
499 $available_broadcast_hours = floatval( $pack_details['available_broadcast_hours'] );
500 if ( $available_broadcast_hours < 0 ) {
501 $available_broadcast_hours = 0;
502 }
503
504 $available_storage_hours = floatval( $pack_details['available_storage_hours'] );
505 if ( $available_storage_hours < 0 ) {
506 $available_storage_hours = 0;
507 }
508
509 $formatted_viewer_hours = $this->wpstream_floor_decimals( $available_viewer_hours, 2 );
510 $formatted_broadcast_hours = $this->wpstream_floor_decimals( $available_broadcast_hours, 2 );
511 $formatted_storage_hours = $this->wpstream_floor_decimals( $available_storage_hours, 2 );
512
513 print '<div class="pack_details_wrapper">'
514 . '<strong>' . __( 'Your account information: ', 'wpstream' ) . '</strong> '
515 . __( 'You have ', 'wpstream' ) . '<strong id="wpstream_available_viewer_hours">' . abs( $formatted_viewer_hours ) . ' hours</strong> '
516 . __( 'available viewer time, ', 'wpstream' )
517 . '<strong id="wpstream_available_broadcast_hours">' . abs( $formatted_broadcast_hours ) . ' hours</strong> '
518 . __( 'available broadcast time, and ', 'wpstream' )
519 . '<strong id="wpstream_available_storage_hours">' . $formatted_storage_hours . ' hours</strong> '
520 . __( 'available storage time', 'wpstream' ) . '.';
521
522 print '<a href="https://wpstream.net/pricing/" class="wpstream_upgrade_topbar" target="_blank">' . esc_html__( 'Upgrade Plan', 'wpstream' ) . '</a>';
523 print '</div>';
524 print '<input type="hidden" id="wpstream_viewer_hours" value="' . esc_attr( $pack_details['available_viewer_hours'] ) . '">';
525 print '<input type="hidden" id="wpstream_broadcast_hours" value="' . esc_attr( $pack_details['available_broadcast_hours'] ) . '">';
526 print '<input type="hidden" id="wpstream_storage_hours" value="' . esc_attr( $pack_details['available_storage_hours'] ) . '">';
527 }
528 }
529 }
530
531
532 /**
533 * help function for media list elementor widget
534 *
535 * @since 3.0.1
536 * @return string
537 */
538
539 public function wpstream_media_list_elementor_function($attributes, $content = null){
540
541
542 $media_number=3;
543 if ( isset($attributes['media_number']) ){
544 $media_number=$attributes['media_number'];
545 }
546
547
548 $row_number=3;
549 if ( isset($attributes['row_number']) ){
550 $row_number=$attributes['row_number'];
551 }
552 if($row_number>4){
553 $row_number=4;
554 }
555
556
557 ob_start();
558
559 // check if is vod or live stream
560 $meta_query = array();
561 $tax_query_array= array();
562 $tax_query = array();
563
564 // check if the media is paid or free
565 $event_types = array();
566 $product_type_free_paid = 0;
567 if ( isset($attributes['product_type_free_paid']) ){
568 $product_type_free_paid=$attributes['product_type_free_paid'];
569
570 if($product_type_free_paid==0){
571 $event_types=array('wpstream_product');
572
573 if ( isset($attributes['product_type']) && intval($attributes['product_type'])==2){
574 $event_types=array('wpstream_product_vod');
575 }
576
577 }else{
578 $event_types=array('product');
579 if ( isset($attributes['product_type']) ){
580 $product_type = $attributes['product_type'];
581 $product_type_slug = 'video_on_demand';
582 if($product_type==1){
583 $product_type_slug ='live_stream';
584 }
585
586 $tax_query_array = array(
587 'taxonomy' => 'product_type',
588 'field' => 'slug',
589 'terms' => $product_type_slug
590 );
591
592 $tax_query= array(
593 'relation' => 'AND',
594 $tax_query_array
595 );
596
597 }
598 }
599
600 }
601 $see_product='';
602 if(isset($attributes['free_label'])){
603 $see_product=$attributes['free_label'];
604 }
605
606 // pagination
607 $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
608 if( is_front_page() ){
609 $paged= (get_query_var('page')) ? get_query_var('page') : 1;
610 }
611
612
613 //order
614 $orderby='ID';
615 $order ='ASC';
616 if ( isset($attributes['order_by']) ){
617 $order_by=intval($attributes['order_by']);
618 switch ($order_by) {
619 case 0:
620 $orderby='ID';
621 $order ='ASC';
622 break;
623 case 1:
624 $orderby='ID';
625 $order ='DESC';
626 break;
627 case 2:
628 $orderby='title';
629 $order ='ASC';
630 break;
631 case 3:
632 $orderby='title';
633 $order ='DESC';
634 break;
635 }
636 }
637
638 // building wp_query arg array
639 $args = array(
640 'post_type' => $event_types,
641 'post_status' => 'publish',
642 'meta_query' => $meta_query,
643 'posts_per_page' => $media_number,
644 'paged' => $paged,
645 'orderby' => $orderby,
646 'order' => $order,
647 'tax_query' => $tax_query
648 );
649
650
651
652 // show live events
653 if ( isset($attributes['product_show_live']) && $attributes['product_show_live']=='yes'){
654 $live_event_for_user = $this->main->wpstream_live_connection->api20_wpstream_request_live_stream_for_user_for_shortcode('shortcode');
655
656
657 if( is_array($live_event_for_user) ){
658 $live_event_for_user[]=0;
659
660 $args['post__in']=$live_event_for_user;
661 }
662 }
663
664
665
666
667 $media_list= new WP_Query($args);
668 if($media_list->have_posts()){
669 print '<ul class="wpstream_media_list_wrapper products columns-'.esc_attr($row_number).'" >';
670 while($media_list->have_posts()):$media_list->the_post();
671 if($product_type_free_paid==0 ){
672
673 $thumb=wp_get_attachment_image_src(get_post_thumbnail_id(),'medium');
674
675 $thumb_src='';
676 if( isset($thumb[0]) ){
677 $thumb_src=$thumb[0];
678 }
679
680 if(($thumb_src)==''){
681 $thumb_src= plugin_dir_url( dirname( __FILE__ ) ). 'img/default_300.png';
682 }
683 print '<li class="wpstream_product_unit">'
684 .'<a href="'.get_permalink().'" class="product_title" ><div class="product_image" style="background-image:url('.esc_url($thumb_src).')"></div></a>'
685 .'<a href="'.get_permalink().'" class="product_title" >'.get_the_title().'</a>';
686
687 if($see_product!=''){
688 print '<a href="'.get_permalink().'"class="see_product">'.$see_product.'</a>';
689 }
690 print '</li>';
691 }else{
692 wc_get_template_part( 'content', 'product' );
693 }
694 endwhile;
695 print '</ul>';
696 }else{
697 print esc_html__('No media found! ','wpstream');
698 }
699
700
701 wp_reset_query();
702 wp_reset_postdata();
703
704 $this->wpstream_pagination($media_list->max_num_pages,$range=2);
705 $return_string= ob_get_contents();
706 ob_end_clean();
707
708 return $return_string;
709 }
710
711
712
713
714
715
716 /*
717 *
718 *
719 * Pagination for media lista
720 *
721 *
722 *
723 */
724
725
726
727
728 function wpstream_pagination($pages = '', $range = 2){
729
730 $showitems = ($range * 2)+1;
731 global $paged;
732 if(empty($paged)) $paged = 1;
733
734
735 if($pages == ''){
736 global $wp_query;
737 $pages = $wp_query->max_num_pages;
738 if(!$pages)
739 {
740 $pages = 1;
741 }
742 }
743
744 if(1 != $pages){
745 print '<ul class="wpstream_pagination ">';
746 print '<li class="roundleft"><a href="'.get_pagenum_link($paged - 1).'"> < </a></li>';
747
748 for ($i=1; $i <= $pages; $i++)
749 {
750 if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
751 {
752 if ($paged == $i){
753 print '<li class="active"><a href="'.esc_url(get_pagenum_link($i)).'" >'.$i.'</a><li>';
754 }else{
755 print '<li><a href="'.esc_url(get_pagenum_link($i)).'" >'.$i.'</a><li>';
756 }
757 }
758 }
759
760 $prev_page= get_pagenum_link($paged + 1);
761 if ( ($paged +1) > $pages){
762 $prev_page= get_pagenum_link($paged );
763 }else{
764 $prev_page= get_pagenum_link($paged + 1);
765 }
766
767
768 print '<li class="roundright"><a href="'.$prev_page.'"> > </a><li>';
769 print '</ul>';
770 }
771 }
772
773
774
775
776
777
778
779
780
781
782
783
784
785 /**
786 * help function for player elementr widget
787 *
788 * @since 3.0.1
789 * @return string
790 */
791
792 public function wpstream_insert_player_elementor($attributes, $content = null){
793 $product_id = '';
794 $return_string = '';
795 $attributes = shortcode_atts(
796 array(
797 'id' => 0,
798 'user_id' => 0,
799 ), $attributes) ;
800
801
802 if ( isset($attributes['id']) ){
803 $product_id=$attributes['id'];
804 }
805 if ( isset($attributes['user_id']) ){
806 $user_id = intval( $attributes['user_id'] );
807 }
808
809 if(intval($product_id)==0 && $user_id!=0 ){
810 $product_id= $this->wpstream_player_retrive_first_id($user_id);
811 }
812
813
814
815
816 ob_start();
817 ?>
818 <div class="wpstream_insert_player_elementor_wrapper">
819 <?php
820 $this->main->wpstream_player->wpstream_video_player_shortcode($product_id);
821 ?>
822 </div>
823 <?php
824 $return_string= ob_get_contents();
825 ob_end_clean();
826
827 return $return_string;
828 }
829
830 /**
831 * help function for player low latency elementor widget
832 *
833 * @since 3.0.1
834 * @return string
835 */
836
837 public function wpstream_insert_player__low_latency_elementor($attributes, $content = null){
838 $product_id = '';
839 $return_string = '';
840 $attributes = shortcode_atts(
841 array(
842 'id' => 0,
843 'user_id' => 0,
844 ), $attributes) ;
845
846
847 if ( isset($attributes['id']) ){
848 $product_id=$attributes['id'];
849 }
850
851 if ( isset($attributes['user_id']) ){
852 $user_id = intval( $attributes['user_id'] );
853 }
854
855 if(intval($product_id)==0 && $user_id!=0){
856 $product_id= $this->wpstream_player_retrive_first_id($user_id);
857 }
858
859
860 ob_start();
861 $this->main->wpstream_player->wpstream_video_player_shortcode_low_latency($product_id);
862 $return_string= ob_get_contents();
863 ob_end_clean();
864
865 return $return_string;
866 }
867
868
869
870 public function wpstream_player_retrive_first_id($received_user_id=''){
871 $channel_type = get_option ('wpstream_user_streaming_channel_type');
872 $product_id = $this->wpstream_get_current_event_per_author($received_user_id,$channel_type);
873 return $product_id;
874 }
875
876
877
878 /**
879 * help function for chat elementor widget
880 *
881 * @since 3.0.1
882 * @return string
883 */
884
885 public function wpstream_insert_chat_elementor($attributes, $content = null){
886 $product_id = '';
887 $return_string = '';
888 $attributes = shortcode_atts(
889 array(
890 'id' => 0,
891 ), $attributes) ;
892
893
894 if ( isset($attributes['id']) ){
895 $product_id=$attributes['id'];
896 }
897
898 $return_string.= '<div class="wpstream_plugin_chat_wrapper">';
899 ob_start();
900 $this->main->wpstream_player->wpstream_chat_wrapper($product_id);
901 $return_string.= ob_get_contents();
902 ob_end_clean();
903 $return_string.='</div>';
904 $this->main->wpstream_player->wpstream_connect_to_chat($product_id);
905
906 return $return_string;
907 }
908
909
910 /**
911 * edited 4.0
912 *
913 * Check if user is allowed to stream
914 *
915 * @since 3.7
916 */
917
918 public function wpstream_check_user_can_stream(){
919 $current_user = wp_get_current_user();
920
921 if( !is_user_logged_in() ){
922 return false;
923 exit('user not logged in');
924 }
925
926 if(current_user_can('administrator')){
927 // admins can always brodcast
928 return true;
929 }
930
931 $extra_roles = get_option( 'wpstream_stream_role', true );
932 $user_role = '';
933 if( is_array( $current_user->roles) && count( $current_user->roles ) > 0 ){
934 $user_role = $current_user->roles[0];
935 }
936
937 if ( is_array($extra_roles) && in_array( $user_role, $extra_roles ) ) {
938 return true;
939 }
940
941 if(function_exists('wpstream_get_option') && intval(wpstream_get_option('allow_streaming_regular_users',''))==1 ){
942 return true;
943 }
944
945 return false;
946 }
947
948
949 /**
950 * Start Streaming wrapper
951 *
952 * @since 3.7
953 */
954
955 public function wpstream_live_stream_unit_wrapper($item_id,$type){
956 $item_id = intval($item_id);
957
958 if($item_id == 0){
959 //retrive or create channel for front end streamers
960 $item_id=$this->wpstream_retrive_front_end_channel();
961 }
962 print'<div class="wpstream_modal_background"></div>';
963 print '<div class="wpstream_error_modal_notification"><div class="wpstream_error_content">er2</div>
964 <div class="wpstream_error_ok wpstream_button" type="button">'.esc_html__('Close','wpstream').'</div>
965 </div>';
966 $this->admin->wpstream_live_stream_unit( $item_id,$type );
967 }
968
969
970 /**
971 * Start Streaming wrapper for wpstream theme
972 *
973 * @since 3.7
974 */
975
976 public function wpstream_live_stream_unit_wrapper_for_theme($item_id,$type){
977 $item_id = intval($item_id);
978
979 if($item_id == 0){
980 //retrive or create channel for front end streamers
981 $item_id=$this->wpstream_retrive_front_end_channel();
982 }
983 print'<div class="wpstream_modal_background"></div>';
984 print '<div class="wpstream_error_modal_notification"><div class="wpstream_error_content">er2</div>
985 <div class="wpstream_error_ok wpstream_button" type="button">'.esc_html__('Close','wpstream').'</div>
986 </div>';
987 $this->admin->wpstream_live_stream_unit_for_theme( $item_id,$type );
988 }
989
990
991 /**
992 * retrive channel for front end streaming
993 *
994 * @since 3.7
995 */
996 public function wpstream_retrive_front_end_channel(){
997
998 $current_user = wp_get_current_user();
999 $channel_type = get_option ('wpstream_user_streaming_channel_type');
1000 $channel_price = floatval( get_option ('wpstream_user_streaming_default_price') );
1001
1002 $front_end_streamin_channel = $this->wpstream_get_current_event_per_author($current_user->ID,$channel_type);
1003
1004 if(intval($front_end_streamin_channel) == 0){
1005 $front_end_streamin_channel= $this->wpstrea_create_front_end_event($current_user->ID,$current_user->user_login ,$channel_type,$channel_price);
1006 }
1007 return $front_end_streamin_channel;
1008
1009 }
1010
1011 /**
1012 * create the event from front end
1013 *
1014 * @since 3.7
1015 */
1016
1017 public function wpstrea_create_front_end_event($userID,$userLogin,$channel_type,$channel_price){
1018
1019 if( !$this->wpstream_check_user_can_stream() ){
1020 return;
1021 }
1022
1023 $post_type='wpstream_product';
1024 if($channel_type=='paid'){
1025 $post_type='product';
1026 }
1027
1028 $post = array(
1029 'post_title' => sprintf( esc_html__('%s Channel','wpstream'),$userLogin),
1030 'post_content' => '',
1031 'post_type' => $post_type ,
1032 'post_author' => $userID,
1033 'post_status' => 'publish',
1034 );
1035 $post_id = wp_insert_post($post );
1036 if($channel_type=='paid'){
1037 $product = wc_get_product($post_id);
1038 $price = wc_format_decimal($channel_price);
1039
1040 $product = wc_get_product( $post_id );
1041 // Set the product active price (regular)
1042 $product->set_price( $price );
1043 $product->set_regular_price( $price ); // To be sure
1044 $product->save();
1045 update_post_meta ($post_id,'event_passed',0);
1046 wp_set_object_terms( $post_id, 'live_stream', 'product_type' );
1047 }
1048 update_post_meta($post_id,'wpstream_product_type',1);
1049
1050 return $post_id;
1051 }
1052
1053
1054 public function wpstream_get_current_event_per_author($userID,$channel_type){
1055
1056 $post_type='wpstream_product';
1057 if($channel_type=='paid'){
1058 $post_type='product';
1059 }
1060
1061 $args = array(
1062
1063 'post_type' => $post_type,
1064 'author' => $userID,
1065 'posts_per_page' => 1,
1066 'fields' => 'ids'
1067 )
1068 ;
1069 $author_posts = new WP_Query( $args );
1070 if( $author_posts->have_posts() ) {
1071 $author_posts->the_post();
1072 $the_id= get_the_ID();
1073 }else{
1074 $the_id= 0;
1075 }
1076
1077 wp_reset_query();
1078 wp_reset_postdata();
1079 return $the_id;
1080 }
1081
1082 /**
1083 * Cleanup old logs
1084 */
1085 public function cleanup_logs() {
1086 $logger = new WPStream_Logger();
1087 $logger->clear_old_logs();
1088 }
1089 }
1090