PluginProbe
WpStream – Live Streaming, Video on Demand, Pay Per View / 4.7.2
WpStream – Live Streaming, Video on Demand, Pay Per View v4.7.2
4.14.0 4.13.2 4.13.1 4.13 4.12.5 4.12.4 4.12.3 4.12.2 4.12.1 4.12 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5 4.5.1 4.5.11 4.5.11.1 4.5.11.2 4.5.11.4 4.5.11.5 4.5.11.6 4.5.12 All 180 releases
wpstream / includes / class-wpstream.php

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

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