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

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

1,974 lines 78.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The public-facing functionality of the plugin.
5 *
6 * @link http://wpstream.net
7 * @since 3.0.1
8 *
9 * @package Wpstream
10 * @subpackage Wpstream/public
11 */
12
13 /**
14 * The public-facing functionality of the plugin.
15 *
16 * Defines the plugin name, version, and two examples hooks for how to
17 * enqueue the public-facing stylesheet and JavaScript.
18 *
19 * @package Wpstream
20 * @subpackage Wpstream/public
21 * @author wpstream <office@wpstream.net>
22 */
23 class Wpstream_Public {
24
25
26
27 /**
28 * Store plugin main class to allow public access.
29 *
30 * @since 20180622
31 * @var object The main class.
32 */
33 public $main;
34 /**
35 * The ID of this plugin.
36 *
37 * @since 3.0.1
38 * @access private
39 * @var string $plugin_name The ID of this plugin.
40 */
41 private $plugin_name;
42
43 /**
44 * The version of this plugin.
45 *
46 * @since 3.0.1
47 * @access private
48 * @var string $version The current version of this plugin.
49 */
50 private $version;
51
52 /**
53 * Initialize the class and set its properties.
54 *
55 * @since 3.0.1
56 * @param string $plugin_name The name of the plugin.
57 * @param string $version The version of this plugin.
58 */
59 public function __construct( $plugin_name, $version ,$plugin_main) {
60 $this->main = $plugin_main;
61 $this->plugin_name = $plugin_name;
62 $this->version = $version;
63
64 }
65
66 /**
67 * Register the stylesheets for the public-facing side of the site.
68 *
69 * @since 3.0.1
70 */
71 public function enqueue_styles() {
72
73 wp_enqueue_style('wpstream-style', plugin_dir_url( __FILE__ ) .'/css/wpstream_style.css',array(), WPSTREAM_PLUGIN_VERSION, 'all' );
74 wp_enqueue_style('video-js.min', plugin_dir_url( __FILE__ ).'css/video-js.css', array(), WPSTREAM_PLUGIN_VERSION, 'all');
75 wp_enqueue_style(
76 'videojs-wpstream-player',
77 plugin_dir_url( __FILE__ ).'css/videojs-wpstream.css',
78 array(),
79 WPSTREAM_PLUGIN_VERSION . '.' . filemtime( plugin_dir_path(__FILE__) . 'css/videojs-wpstream.css' ),
80 'all'
81 );
82 wp_enqueue_style('wpstream-integrations', plugin_dir_url( __DIR__ ) .'integrations/css/integrations.css',array(), WPSTREAM_PLUGIN_VERSION, 'all' );
83
84 }
85
86 /**
87 * Register the JavaScript for the public-facing side of the site.
88 *
89 * @since 3.0.1
90 */
91 public function enqueue_scripts() {
92
93 // Register the VideoJS script
94 // Enqueuing is happing directly wherever is used
95 wp_register_script('video.min', 'https://vjs.zencdn.net/8.20.0/video.min.js', WPSTREAM_PLUGIN_VERSION, true);
96
97 // Quality selector dependency (Video.js plugin)
98 wp_register_script(
99 'videojs-contrib-quality-levels',
100 'https://cdn.jsdelivr.net/npm/videojs-contrib-quality-levels@4.0.0/dist/videojs-contrib-quality-levels.min.js',
101 array('video.min'),
102 '4.0.0',
103 true
104 );
105
106 // WpStream quality selector (Video.js 8 compatible)
107 wp_register_script(
108 'wpstream-quality-selector',
109 plugin_dir_url( __FILE__ ) . 'js/wpstream-quality-selector.js',
110 array('video.min', 'videojs-contrib-quality-levels'),
111 WPSTREAM_PLUGIN_VERSION . '.' . filemtime(plugin_dir_path(__FILE__) . 'js/wpstream-quality-selector.js'),
112 true
113 );
114
115 // Enqueue the VideoJS Logo plugin script
116 wp_enqueue_script(
117 'videojs-logo',
118 'https://cdn.jsdelivr.net/npm/videojs-logo@latest/dist/videojs-logo.min.js',
119 array('video.min'),
120 '3.0.0',
121 true
122 );
123
124 // Ensure quality selector scripts are available wherever wpstream-player runs
125 wp_enqueue_script('videojs-contrib-quality-levels');
126 wp_enqueue_script('wpstream-quality-selector');
127
128 wp_register_script('youtube.min',
129 plugin_dir_url( __FILE__ ).'js/youtube.min.js',
130 array('video.min'),
131 WPSTREAM_PLUGIN_VERSION, true);
132
133 wp_register_script(
134 'wpstream-player',
135 plugin_dir_url( __FILE__ ).'js/wpstream-player.js',
136 array('video.min','wpstream-quality-selector'),
137 WPSTREAM_PLUGIN_VERSION . '.' . filemtime(plugin_dir_path(__FILE__) . 'js/wpstream-player.js'),
138 true
139 );
140
141 $abr_enabled = false;
142 $post_meta = get_post_meta( get_the_ID(), 'local_event_options', true );
143 if ( !empty($post_meta) && isset($post_meta['adaptive_bitrate']) && $post_meta['adaptive_bitrate'] == 1 ) {
144 $abr_enabled = true;
145 }
146 wp_localize_script('wpstream-player', 'wpstream_player_vars',
147 array(
148 'admin_url' => get_admin_url(),
149 'chat_not_connected' => esc_html__('Inactive Channel - Chat is disabled.','wpstream'),
150 'server_up' => esc_html__('The live stream is paused and may resume shortly.','wpstream'),
151 'wpstream_player_state_stopped_msg' => esc_html__(get_option('wpstream_you_are_not_live','We are not live at this moment'),'wpstream'),
152 'wpstream_player_state_init_msg' => esc_html__('The live stream has not yet started','wpstream'),
153 'wpstream_player_state_startup_msg' => esc_html__('The live stream is starting...','wpstream'),
154 'wpstream_player_state_paused_msg' => esc_html__('The live stream is paused','wpstream'),
155 'wpstream_player_state_ended_msg' => esc_html__('The live stream has ended','wpstream'),
156 'wpstream_player_state_error_msg' => esc_html__('Something went wrong','wpstream'),
157 'wpstream_player_theme' => get_option('wpstream_video_player_theme'),
158 'playerLogoSettings' => array(
159 'imageUrl' => $this->main->wpstream_player->wpstream_get_video_player_logo( get_the_ID() ),
160 'position' => get_option( 'wpstream_player_logo_position', 'top-left' ),
161 'opacity' => get_option('wpstream_player_logo_opacity', '100'),
162 ),
163 'wpstream_is_streamify_user' => $this->main->wpstream_player->wpstream_is_streamify_user( get_the_ID() ),
164 'player_check_status_nonce' => wp_create_nonce( 'wpstream_player_check_status_nonce'),
165 'is_abr_enabled' => $abr_enabled,
166 )
167 );
168
169 wp_enqueue_script( 'jquery-ui-autocomplete' );
170 wp_enqueue_script( "jquery-effects-core");
171
172 wp_register_script( 'sockjs-0.3.min', plugin_dir_url( __FILE__ ) . '/chat_lib/sockjs-0.3.min.js', array('jquery'), true );
173 wp_register_script( 'emojione.min.js',plugin_dir_url( __FILE__ ). '/chat_lib/emojione.min.js', array('jquery'), true );
174
175 wp_register_script( 'jquery.linkify.min.js', plugin_dir_url( __FILE__ ). '/chat_lib/jquery.linkify.min.js', array('jquery'), true );
176 wp_register_script( 'ripples.min.js',plugin_dir_url( __FILE__ ). '/chat_lib/ripples.min.js', array('jquery'), true );
177 wp_register_script( 'material.min.js"', plugin_dir_url( __FILE__ ). '/chat_lib/material.min.js', array('jquery'), true );
178 wp_register_script( 'chat.js', plugin_dir_url( __FILE__ ). '/chat_lib/chat.js', array('jquery'), true );
179
180 wp_localize_script('chat.js', 'chat-js-vars',
181 array(
182 'we_are_not_live' => esc_html( get_option('wpstream_you_are_not_live','We are not live at this moment')),
183 ));
184
185 wp_register_style( 'chat.css',plugin_dir_url( __FILE__ ).'/chat_lib/css/chat.css', array(), '1.0', 'all');
186 wp_register_style( 'ripples.css',plugin_dir_url( __FILE__ ).'/chat_lib/css/ripples.css', array(), '1.0', 'all');
187 wp_register_style( 'emojione.min.css',plugin_dir_url( __FILE__ ).'/chat_lib/css/emojione.min.css', array(), '1.0', 'all');
188
189
190 $modified_start_streaming_file_time = gmdate( 'YmdHi', filemtime( WPSTREAM_PLUGIN_PATH . 'public/js/start_streaming.js' ) );
191 wp_enqueue_script('wpstream-start-streaming', plugin_dir_url( __FILE__ ) .'js/start_streaming.js',array(), $modified_start_streaming_file_time, true);
192 wp_localize_script('wpstream-start-streaming', 'wpstream_start_streaming_vars',
193 array(
194 'admin_url' => get_admin_url(),
195 'loading_url' => WPSTREAM_PLUGIN_DIR_URL.'/img/loading.gif',
196 'download_mess' => esc_html__('Click to download!','wpstream'),
197 'uploading' => esc_html__('We are uploading your file.Do not close this window!','wpstream'),
198 'upload_complete2' => esc_html__('Upload Complete! You can upload another file!','wpstream'),
199 'not_accepted' => esc_html__('The file is not an accepted video format','wpstream'),
200 'upload_complete' => esc_html__('Upload Complete!','wpstream'),
201 'upload_failed' => esc_html__('Upload Failed!','wpstream'),
202 'upload_failed2' => esc_html__('Upload Failed! Please Try again!','wpstream'),
203 'no_band' => esc_html__('Not enough streaming data.','wpsteam'),
204 'no_band_no_store' => esc_html__('Not enough streaming data or storage.','wpsteam'),
205
206 'start_streaming_action'=> esc_html__('TURNING ON','wpstream'),
207 'stop_streaming_action' => esc_html__('TURNING OFF','wpstream'),
208 'start_streaming' => esc_html__('TURN ON','wpstream'),
209 'stop_streaming' => esc_html__('TURN OFF','wpstream'),
210 'failed_fetching' => esc_html__('Failed to get channel info. Please try again.','wpstream'),
211 'turned_on_tooltip' => esc_html__('Channel is now OFF. Click to turn ON.','wpstream'),
212 'turned_off_tooltip' => esc_html__('Click to turn channel off. This will interrupt any ongoing broadcast.','wpstream'),
213 'turning_on_tooltip' => esc_html__('Turning a channel on may take 1-2 minutes or more. Please be patient.','wpstream'),
214 'turning_off_tooltip' => esc_html__('This may take a few minutes.','wpstream'),
215 'error1' => esc_html__('You don\'t have enough data to start a new event!','wpstream'),
216 'failed_event_creation' => esc_html__('Failed to start the channel. Please try again in a few minutes.','wpstream'),
217 'channel_turning_on' => esc_html__('Channel is turning on','wpstream'),
218 'channel_turning_off' => esc_html__('Channel is turning off','wpstream'),
219 'channel_on' => esc_html__('Channel is ON','wpstream'),
220 'channel_off' => esc_html__('Channel is OFF','wpstream'),
221 'turn_off_confirm' => esc_html__('Are you sure? '.PHP_EOL.' Channels turn OFF automatically after 1 hour of inactivity (no active broadcast). Manual TURN OFF is only useful if you require to change the channel settings.','wpstream'),
222 'turn_off_confirm' => esc_html__('ARE YOU SURE you\'d like to TURN OFF the channel now? '.PHP_EOL.PHP_EOL.'Channels TURN OFF automatically after 1 hour of inactivity (no active broadcast).'.PHP_EOL.PHP_EOL.'Manual TURN OFF is only useful if you require to change the channel settings immediately.'.PHP_EOL.PHP_EOL.'Statistics may be unavailable or incomplete for up to an hour.'.PHP_EOL.PHP_EOL.'If your channel is configured with Auto TURN ON, it will turn back on as soon as there is a broadcast.','wpstream'),
223 'broadcaster_url' => esc_url( esc_url(home_url('/broadcaster-page/') ) ),
224
225 ));
226
227
228 $integrations_array=array(
229 'admin_url' => get_admin_url(),
230 );
231 if (class_exists('BuddyPress')) {
232 $integrations_array['is_buddyboss']='yes';
233 }
234
235 wp_enqueue_script('wpstream-integrations', plugin_dir_url( __DIR__ ) .'integrations/js/integrations.js?v='.time(),array(), WPSTREAM_PLUGIN_VERSION, true);
236 wp_localize_script('wpstream-integrations', 'wpstream_integrations_vars', $integrations_array );
237
238
239 wp_enqueue_style( 'wpstream_front_style', plugin_dir_url( __DIR__ ) . 'admin/css/wpstream-admin.css', array(), WPSTREAM_PLUGIN_VERSION, 'all' );
240
241 wp_enqueue_script( 'wpstream-plugin-scripts', WPSTREAM_PLUGIN_DIR_URL . '/hello-wpstream/js/wpstream-plugin-script.js', array( 'jquery' ), '1.0', true );
242
243 wp_localize_script(
244 'wpstream-plugin-scripts',
245 'wpstreamPluginScriptsVars',
246 array(
247 'ajaxurl' => admin_url( 'admin-ajax.php' ), // WordPress AJAX URL.
248 'processing' => esc_html('sending...','hello-wpstream'),
249 'send_mess' => esc_html__('Send Message','hello-wpstream'),
250 'is_user_logged_in' => is_user_logged_in() ? '1' : '0',
251 'comment_text_empty' => esc_html__('Please type your comment.','hello-wpstream'),
252 'comment_author_empty' => esc_html__('Please enter your name.', 'hello-wpstream'),
253 'comment_email_empty' => esc_html__('Please enter your email.', 'hello-wpstream'),
254 'comment_email_invalid' => esc_html__('Please enter a valid email address.', 'hello-wpstream'),
255 'gdpr_agree' => esc_html__('You need to agree with GDPR terms.', 'hello-wpstream'),
256 )
257 );
258 }
259
260
261
262
263 /**
264 * add custom end points for woocomerce
265 *
266 * @since 3.0.1
267 * @return nothing
268 */
269 public function wpstream_my_custom_endpoints() {
270 add_rewrite_endpoint( 'video-list', EP_ROOT | EP_PAGES );
271 add_rewrite_endpoint( 'event-list', EP_ROOT | EP_PAGES );
272 }
273
274 /**
275 * Remove specific wpstream filters.
276 */
277 function wpstream_remove_wpstream_filter() {
278 global $wpstream_plugin;
279
280 if ( class_exists( 'Wpstream_Player' ) ) {
281 // Instantiate the Wpstream_Player class if it exists.
282 $pstream_player = new Wpstream_Player( $wpstream_plugin->main );
283 // Remove filters applied by wpstream.
284 remove_filter( 'the_content', 'wpstream_filter_the_title' );
285 remove_filter( 'woocommerce_before_single_product', array( $pstream_player, 'wpstream_user_logged_in_product_already_bought' ) );
286 }
287 }
288
289 /**
290 * add custom query vars
291 *
292 * @since 3.0.1
293 * @return nothing
294 */
295 public function wpstream_my_custom_query_vars( $vars ) {
296 $vars[] = 'video-list';
297 $vars[] = 'event-list';
298 return $vars;
299 }
300
301
302 /**
303 * Hust flush rewrite rules
304 *
305 * @since 3.0.1
306 *
307 */
308 public function wpstream_custom_flush_rewrite_rules() {
309 flush_rewrite_rules();
310 }
311
312
313 /**
314 * Add new sections in woocomerce account
315 *
316 * @since 3.0.1
317 */
318 public function wpstream_custom_my_account_menu_items( $items ) {
319 if(function_exists('wpstream_is_global_subscription') && wpstream_is_global_subscription()){
320 if(function_exists('wpstream_theme_my_custom_endpoints')){
321 $items = array(
322 'dashboard' => __( 'Dashboard', 'wpstream' ),
323 'orders' => __( 'Orders', 'wpstream' ),
324 'edit-address' => __( 'Addresses', 'wpstream' ),
325 'edit-account' => __( 'Edit Account', 'wpstream' ),
326 'watch-later' => esc_html__( 'Watch Later', 'wpstream-theme' ),
327 'customer-logout' => __( 'Logout', 'wpstream' ),
328 );
329 }else{
330 $items = array(
331 'dashboard' => __( 'Dashboard', 'wpstream' ),
332 'orders' => __( 'Orders', 'wpstream' ),
333 'edit-address' => __( 'Addresses', 'wpstream' ),
334 'edit-account' => __( 'Edit Account', 'wpstream' ),
335 'customer-logout' => __( 'Logout', 'wpstream' ),
336 );
337 }
338 }else{
339 if(function_exists('wpstream_theme_my_custom_endpoints')){
340 $items = array(
341 'dashboard' => __( 'Dashboard', 'wpstream' ),
342 'orders' => __( 'Orders', 'wpstream' ),
343 'downloads' => __( 'Downloads', 'wpstream' ),
344 'edit-address' => __( 'Addresses', 'wpstream' ),
345 'edit-account' => __( 'Edit Account', 'wpstream' ),
346 'event-list' => __( 'My Live Streams', 'wpstream' ),
347 'video-list' => __( 'My Videos', 'wpstream' ),
348 'start-streaming' => esc_html__( 'Start Streaming', 'wpstream-theme' ),
349 'watch-later' => esc_html__( 'Watch Later', 'wpstream-theme' ),
350 'customer-logout' => __( 'Logout', 'wpstream' ),
351 );
352 }else{
353 $items = array(
354 'dashboard' => __( 'Dashboard2', 'wpstream' ),
355 'orders' => __( 'Orders', 'wpstream' ),
356 'downloads' => __( 'Downloads', 'wpstream' ),
357 'edit-address' => __( 'Addresses', 'wpstream' ),
358 'edit-account' => __( 'Edit Account', 'wpstream' ),
359 'event-list' => __( 'My Live Streams', 'wpstream' ),
360 'video-list' => __( 'My Videos', 'wpstream' ),
361 'customer-logout' => __( 'Logout', 'wpstream' ),
362 );
363
364 }
365
366
367 }
368 return $items;
369 }
370
371
372 /**
373 * Function that adds additional post types for the search template
374 *
375 * @param $post_types_array
376 * @return array
377 */
378 public function wpstream_search_template_add_item_post_type( $post_types_array ) {
379 return array_merge( $post_types_array, array( 'wpstream_product_vod', 'wpstream_product', 'product', 'wpstream_bundles' ) );
380 }
381
382 /**
383 * Function that changes the sidebar id based on the post type
384 *
385 * @param $sidebar_id
386 * @return mixed|string
387 */
388 public function wpstream_sidebar_id_by_post_type( $sidebar_id ) {
389 $current_post_type = get_post_type( get_the_ID() );
390
391 if( $current_post_type == 'wpstream_product_vod' ) {
392 return 'sidebar-vod';
393 }
394 if( $current_post_type == 'product' ) {
395 return 'sidebar-products';
396 }
397 if( $current_post_type == 'wpstream_product' ) {
398 return 'sidebar-live';
399 }
400 return $sidebar_id;
401 }
402
403 /**
404 * Function to add new items to the header search dropdown post type list
405 *
406 * @param $search_list_values
407 * @return array
408 */
409 public function wpstream_header_search_values( $search_list_values ) {
410 return array_merge($search_list_values, [
411 'wpstream_product' => esc_html__( 'Live Events', 'hello-wpstream' ),
412 'wpstream_product_vod' => esc_html__( 'Video on Demand', 'hello-wpstream' ),
413 'wpstream_bundles' => esc_html__( 'Video Bundles', 'hello-wpstream' ),
414 ]);
415 }
416
417 /**
418 * Function to add new items to the category archive query
419 *
420 * @param $post_types
421 * @return array
422 */
423 public function wpstream_extend_category_archive_query_filter_callback( $post_types ) {
424 return array_merge( $post_types, array( 'product', 'wpstream_bundles', 'wpstream_product_vod', 'wpstream_product' ) );
425 }
426
427 /**
428 * Function to add new labels to the list of taxonomies
429 *
430 * @param $taxonomy_labels
431 * @return mixed
432 */
433 public function wpstream_archives_lists_taxonomy_labels_callback( $taxonomy_labels ) {
434 $taxonomy_labels['product'] = esc_html__( 'Video Products', 'hello-wpstream' );
435 $taxonomy_labels['wpstream_bundles'] = esc_html__( 'Bundles', 'hello-wpstream' );
436 $taxonomy_labels['wpstream_product'] = esc_html__( 'Free Events', 'hello-wpstream' );
437 $taxonomy_labels['wpstream_product_vod'] = esc_html__( 'Free Vod', 'hello-wpstream' );
438 return $taxonomy_labels;
439 }
440
441 /**
442 * Function to add new labels to the list of taxonomies for author archive
443 *
444 * @param $taxonomy_labels
445 * @return mixed
446 */
447 public function wpstream_author_archive_list_taxonomy_labels_callback( $taxonomy_labels ) {
448 $taxonomy_labels['product'] = esc_html__( 'Video Products', 'hello-wpstream' );
449 $taxonomy_labels['wpstream_bundles'] = esc_html__( 'Bundles', 'hello-wpstream' );
450 $taxonomy_labels['wpstream_product_vod'] = esc_html__( 'Free Vod', 'hello-wpstream' );
451 $taxonomy_labels['wpstream_product'] = esc_html__( 'Free Events', 'hello-wpstream' );
452 return $taxonomy_labels;
453 }
454
455 /**
456 * Function to add new post type to the vod attached to the channel
457 *
458 * @param $post_type_array
459 * @return array
460 */
461 public function wpstream_vod_attached_to_channel( $post_type_array ) {
462 return array_merge( $post_type_array, array( 'wpstream_product_vod' ) );
463 }
464
465 /**
466 * Function to add new post type to the additional post type content
467 *
468 * @param $post_type_list
469 * @return array
470 */
471 public function wpstream_additional_content_post_type_callback( $post_type_list ) {
472 return array_merge( $post_type_list, array( 'wpstream_product_vod', 'wpstream_product', 'wpstream_bundle_bcks' ) );
473 }
474
475 /**
476 * @param $post_type_list
477 * @return array
478 */
479 public function wpstream_post_author_content_post_type_list_callback( $post_type_list ) {
480 return array_merge( $post_type_list, array( 'wpstream_product_vod', 'wpstream_product', 'wpstream_bundles' ) );
481 }
482
483 /**
484 * Add new endpoint
485 *
486 * @since 3.0.1
487 */
488 public function wpstream_custom_endpoint_start_streaming() {
489 include plugin_dir_path( __DIR__ ).'woocommerce/myaccount/start_streaming.php';
490 }
491
492 /**
493 * @param $message
494 * @param $post_type
495 * @return mixed|string
496 */
497 public function wpstream_author_content_simple_post_type_message_callback( $message, $post_type ) {
498 switch ( $post_type ) {
499 case 'wpstream_product_vod':
500 $message = esc_html__( 'Published ', 'hello-wpstream' );
501 break;
502 case 'wpstream_product':
503 $message = esc_html__( 'Started streaming ', 'hello-wpstream' );
504 break;
505 case 'wpstream_bundles':
506 $message = esc_html__( 'Added ', 'hello-wpstream' );
507 break;
508 }
509 return $message;
510 }
511
512 /**
513 * @param $message
514 * @param $post_type
515 * @return mixed|string
516 */
517 public function wpstream_author_content_post_type_message_callback( $message, $post_type ) {
518 switch ( $post_type ) {
519 case 'wpstream_product_vod':
520 $message = esc_html__( 'Published ', 'hello-wpstream' );
521 break;
522 case 'wpstream_product':
523 $message = esc_html__( 'Started streaming ', 'hello-wpstream' );
524 break;
525 case 'wpstream_bundles':
526 $message = esc_html__( 'Added ', 'hello-wpstream' );
527 break;
528 }
529 return $message;
530 }
531
532 /**
533 * Function to show the sidebar for the post type
534 *
535 * @param $default
536 * @param $post_type
537 * @return bool|mixed
538 */
539 public function wpstream_show_sidebar_for_post_type_callback( $default, $post_type ) {
540 switch ( $post_type ) {
541 case 'page':
542 return get_theme_mod( 'wpstream_page_sidebar', true );
543 case 'wpstream_product_vod':
544 return get_theme_mod( 'wpstream_video_on_demand_sidebar', true );
545 case 'wpstream_product':
546 case 'wpstream_bundles':
547 return get_theme_mod( 'wpstream_free_to_view_live_sidebar', true );
548 case 'product':
549 return get_theme_mod( 'wpstream_product_details_page_sidebar', true );
550 default:
551 return $default;
552 }
553 }
554
555 /**
556 * Function to add new post types to the video episodes
557 *
558 * @param $post_type
559 * @return array
560 */
561 public function wpstream_video_episodes_post_type_callback( $post_type ) {
562 return array_merge( $post_type, array( 'wpstream_product', 'wpstream_product_vod', 'product' ) );
563 }
564
565 /**
566 * Function to add new post types to the vod episodes
567 *
568 * @param $post_type
569 * @return array
570 */
571 public function wpstream_video_past_broadcast_post_type_callback( $post_type ) {
572 return array_merge( $post_type, array( 'wpstream_product_vod' ) );
573 }
574
575 /**
576 * Function to return the label for the additional content based on the post type
577 *
578 * @param $post_type
579 * @return array
580 */
581 public function wpstream_additional_content_post_type_label_callback( $label, $post_type ) {
582 if ( 'post' === $post_type ) {
583 return $label;
584 } elseif ( 'wpstream_product' === $post_type ) {
585 return __( 'watching', 'hello-wpstream' );
586 } else {
587 return __( 'views', 'hello-wpstream' );
588 }
589 }
590
591 /**
592 * Add new endpoint
593 *
594 * @since 3.0.1
595 */
596 public function wpstream_custom_endpoint_content_event_list() {
597 include plugin_dir_path( __DIR__ ).'woocommerce/myaccount/event_list.php';
598 }
599
600
601 /**
602 * Add new endpoint
603 *
604 * @since 3.0.1
605 */
606 public function wpstream_custom_endpoint_video_list() {
607 include plugin_dir_path( __DIR__ ).'woocommerce/myaccount/video_list.php';
608 }
609
610
611
612
613
614
615 /**
616 * register shortcodes
617 *
618 * @since 3.0.1
619 *
620 */
621 public function wpstream_shortcodes(){
622 add_shortcode('wpstream_player', array($this,'wpstream_insert_player_inpage_local') );
623 // add_shortcode('wpstream_list_products', array($this,'wpstream_list_products_function') );
624 add_shortcode('wpstream_chat', array($this,'wpstream_chat_function') );
625 add_shortcode('wpstream_player_low_latency', array($this,'wpstream_insert_player_inpage_low_latency') );
626 add_shortcode('wpstream_go_live', array($this,'wpstream_start_streaming_shortocde') );
627
628
629 add_shortcode('wpstream_list_media_channels', array($this,'wpstream_media_list_bakery_bypass') );
630 add_shortcode('wpstream_list_media_vod', array($this,'wpstream_media_list_bakery_vod_bypass') );
631 }
632
633
634 /**
635 * register shortcodes
636 *
637 * @since 3.0.1
638 *
639 */
640
641 public function wpstream_bakery_shortcodes(){
642 // register shortcodes for visual composer
643 if( function_exists('vc_map') ):
644
645
646 vc_map(
647 array(
648 "name" => esc_html__( "WpStream Start Streaming Button","wpestate"),
649 "base" => "wpstream_go_live",
650 "class" => "",
651 "category" => esc_html__( 'WpStream','wpstream'),
652 'admin_enqueue_js' => array(get_template_directory_uri().'/vc_extend/bartag.js'),
653 'admin_enqueue_css' => array(get_template_directory_uri().'/vc_extend/bartag.css'),
654 'weight'=>100,
655 'icon' =>'',
656 'description'=>esc_html__( 'Insert WpStream Start Streaming Button','wpstream'),
657 "params" => array(
658 array(
659 "type" => "textfield",
660 "holder" => "div",
661 "class" => "",
662 "heading" => esc_html__( "Product/Free Product Id","wpestate"),
663 "param_name" => "id",
664 "value" => "",
665 "description" => esc_html__( "If you leave this option blank we will stream on the first free/paid channel for this user","wpestate")
666 ),
667
668
669 )
670 )
671 );
672
673
674
675 vc_map(
676 array(
677 "name" => esc_html__( "WpStream Chat - Beta Version","wpestate"),
678 "base" => "wpstream_chat",
679 "class" => "",
680 "category" => esc_html__( 'WpStream','wpstream'),
681 'admin_enqueue_js' => array(get_template_directory_uri().'/vc_extend/bartag.js'),
682 'admin_enqueue_css' => array(get_template_directory_uri().'/vc_extend/bartag.css'),
683 'weight'=>100,
684 'icon' =>'',
685 'description'=>esc_html__( 'Insert WpStream Chat','wpstream'),
686 "params" => array(
687 array(
688 "type" => "textfield",
689 "holder" => "div",
690 "class" => "",
691 "heading" => esc_html__( "Live Stream Id","wpestate"),
692 "param_name" => "id",
693 "value" => "0",
694 "description" => esc_html__( "Add here the live stream id","wpestate")
695 ),
696
697 )
698 )
699 );
700
701
702
703 vc_map(
704 array(
705 "name" => esc_html__( "WpStream Player","wpestate"),
706 "base" => "wpstream_player",
707 "class" => "",
708 "category" => esc_html__( 'WpStream','wpstream'),
709 'admin_enqueue_js' => array(get_template_directory_uri().'/vc_extend/bartag.js'),
710 'admin_enqueue_css' => array(get_template_directory_uri().'/vc_extend/bartag.css'),
711 'weight'=>100,
712 'icon' =>'',
713 'description'=>esc_html__( 'Insert WpStream Player','wpstream'),
714 "params" => array(
715 array(
716 "type" => "textfield",
717 "holder" => "div",
718 "class" => "",
719 "heading" => esc_html__( "Product/Free Product Id","wpestate"),
720 "param_name" => "id",
721 "value" => "0",
722 "description" => esc_html__( "Add here the live stream id or the video id","wpestate")
723 ),
724 array(
725 "type" => "textfield",
726 "holder" => "div",
727 "class" => "",
728 "heading" => esc_html__( "User Id","wpestate"),
729 "param_name" => "user_id",
730 "value" => "",
731 "description" => esc_html__( "We will use the first channel of this user id(product id will be ignored.).","wpestate")
732 ),
733
734 )
735 )
736 );
737
738
739 vc_map(
740 array(
741 "name" => esc_html__( "WpStream Player - Low Latency - Private Beta / Requires Approval","wpestate"),
742 "base" => "wpstream_player_low_latency",
743 "class" => "",
744 "category" => esc_html__( 'WpStream','wpstream'),
745 'admin_enqueue_js' => array(get_template_directory_uri().'/vc_extend/bartag.js'),
746 'admin_enqueue_css' => array(get_template_directory_uri().'/vc_extend/bartag.css'),
747 'weight'=>100,
748 'icon' =>'',
749 'description'=>esc_html__( 'Insert WpStream Player','wpstream'),
750 "params" => array(
751 array(
752 "type" => "textfield",
753 "holder" => "div",
754 "class" => "",
755 "heading" => esc_html__( "Product/Free Product Id","wpestate"),
756 "param_name" => "id",
757 "value" => "0",
758 "description" => esc_html__( "Add here the live stream id or the video id","wpestate")
759 ),
760 array(
761 "type" => "textfield",
762 "holder" => "div",
763 "class" => "",
764 "heading" => esc_html__( "User Id","wpestate"),
765 "param_name" => "user_id",
766 "value" => "",
767 "description" => esc_html__( "We will use the first channel of this user id(product id will be ignored.).","wpestate")
768 ),
769
770 )
771 )
772 );
773
774
775 $product_type=array(
776 '0' => __('Both','wpstream'),
777 '1' => __('Live Event','wpstream'),
778 '2' => __('Video on demand','wpstream')
779 );
780
781 vc_map(
782 array(
783 "name" => esc_html__( "WpStream Products List","wpestate"),
784 "base" => "wpstream_list_products",
785 "class" => "",
786 "category" => esc_html__( 'WpStream','wpstream'),
787 'admin_enqueue_js' => array(get_template_directory_uri().'/vc_extend/bartag.js'),
788 'admin_enqueue_css' => array(get_template_directory_uri().'/vc_extend/bartag.css'),
789 'weight'=>100,
790 'icon' =>'',
791 'description'=>esc_html__( ' List wpstream products','wpstream'),
792 "params" => array(
793
794 array(
795 "type" => "dropdown",
796 "holder" => "div",
797 "class" => "",
798 "heading" => esc_html__( "Media type","wpestate"),
799 "param_name" => "product_type",
800 "value" => $product_type,
801 "description" => esc_html__( "What type of media(free/paid) ","wpestate")
802 ),
803
804 array(
805 "type" => "textfield",
806 "holder" => "div",
807 "class" => "",
808 "heading" => esc_html__( "Media number","wpestate"),
809 "param_name" => "media_number",
810 "value" => "",
811 "description" => esc_html__( "No of media ","wpestate")
812 ),
813
814
815
816 )
817 )
818 );
819
820
821 $free_paid_type=array(
822
823 0 => esc_html__('Free','wpstream'),
824 1 => esc_html__('Paid','wpstream')
825 );
826
827 $live_settings=array(
828
829 'no'=>esc_html__('no','wpstream'),
830 'yes'=>esc_html__('yes','wpstream'),
831 );
832
833 $order_by_id=array(
834
835 0=>esc_html('By date - ASC','wpstream'),
836 1=>esc_html('By date - DESC','wpstream'),
837 2=>esc_html('By title - ASC','wpstream'),
838 3=>esc_html('By title - DESC','wpstream'),
839 );
840
841 vc_map(
842 array(
843 "name" => esc_html__( "WpStream Channel List","wpestate"),
844 "base" => "wpstream_list_media_channels",
845 "class" => "",
846 "category" => esc_html__( 'WpStream','wpstream'),
847 'admin_enqueue_js' => array(get_template_directory_uri().'/vc_extend/bartag.js'),
848 'admin_enqueue_css' => array(get_template_directory_uri().'/vc_extend/bartag.css'),
849 'weight'=>100,
850 'icon' =>'',
851 'description'=>esc_html__( ' List wpstream channels','wpstream'),
852 "params" => array(
853
854
855
856 array(
857 "type" => "dropdown",
858 "holder" => "div",
859 "class" => "",
860 "heading" => esc_html__( "Show Free or Paid Media ?","wpestate"),
861 "param_name" => "product_type_free_paid",
862 "value" => $free_paid_type,
863 "description" => esc_html__( "What type of media(free/paid) ","wpestate")
864 ),
865
866 array(
867 "type" => "dropdown",
868 "holder" => "div",
869 "class" => "",
870 "heading" => esc_html__( "Only show active channels","wpestate"),
871 "param_name" => "product_show_live",
872 "value" => $live_settings,
873 "description" => esc_html__( "Only show channels that are live streaming right now.","wpestate")
874 ),
875 array(
876 "type" => "textfield",
877 "holder" => "div",
878 "class" => "",
879 "heading" => esc_html__( "Number of Items per Page","wpestate"),
880 "param_name" => "media_number",
881 "value" => "3",
882 "description" => esc_html__( "How many items will be displayed per page","wpestate")
883 ),
884
885 array(
886 "type" => "textfield",
887 "holder" => "div",
888 "class" => "",
889 "heading" => esc_html__( "Link Label for free items","wpestate"),
890 "param_name" => "free_label",
891 "value" => esc_html__('Watch now!','wpstream'),
892 "description" => esc_html__( "Link Label for free items'","wpestate")
893 ),
894
895 array(
896 "type" => "dropdown",
897 "holder" => "div",
898 "class" => "",
899 "heading" => esc_html__( "Order by","wpestate"),
900 "param_name" => "order_by",
901 "value" => $order_by_id,
902 "description" => esc_html__( "Order type","wpestate")
903 ),
904
905
906 )
907 )
908 );
909
910
911 vc_map(
912 array(
913 "name" => esc_html__( "WpStream VOD List","wpestate"),
914 "base" => "wpstream_list_media_vod",
915 "class" => "",
916 "category" => esc_html__( 'WpStream','wpstream'),
917 'admin_enqueue_js' => array(get_template_directory_uri().'/vc_extend/bartag.js'),
918 'admin_enqueue_css' => array(get_template_directory_uri().'/vc_extend/bartag.css'),
919 'weight'=>100,
920 'icon' =>'',
921 'description'=>esc_html__( ' List wpstream video on demand','wpstream'),
922 "params" => array(
923
924
925
926 array(
927 "type" => "dropdown",
928 "holder" => "div",
929 "class" => "",
930 "heading" => esc_html__( "Show Free or Paid Media ?","wpestate"),
931 "param_name" => "product_type_free_paid",
932 "value" => $free_paid_type,
933 "description" => esc_html__( "What type of media(free/paid) ","wpestate")
934 ),
935
936
937 array(
938 "type" => "textfield",
939 "holder" => "div",
940 "class" => "",
941 "heading" => esc_html__( "Number of Items per Page","wpestate"),
942 "param_name" => "media_number",
943 "value" => "3",
944 "description" => esc_html__( "How many items will be displayed per page","wpestate")
945 ),
946
947 array(
948 "type" => "textfield",
949 "holder" => "div",
950 "class" => "",
951 "heading" => esc_html__( "Link Label for free items","wpestate"),
952 "param_name" => "free_label",
953 "value" => esc_html__('Watch now!','wpstream'),
954 "description" => esc_html__( "Link Label for free items'","wpestate")
955 ),
956
957 array(
958 "type" => "dropdown",
959 "holder" => "div",
960 "class" => "",
961 "heading" => esc_html__( "Order by","wpestate"),
962 "param_name" => "order_by",
963 "value" => $order_by_id,
964 "description" => esc_html__( "Order type","wpestate")
965 ),
966
967
968 )
969 )
970 );
971
972
973 endif;
974
975
976 // add shorcotes to editor interface
977 if (!current_user_can('edit_posts') && !current_user_can('edit_pages')) {
978 return;
979 }
980
981 if (get_user_option('rich_editing') == 'true') {
982 add_filter('mce_external_plugins', array( $this,'wpstream_add_plugin') );
983 add_filter('mce_buttons_2', array($this,'wpstream_register_button') );
984 }
985 }
986
987 /**
988 * list channels - shortcode function
989 *
990 * @since 3.0.1
991 *
992 */
993
994 public function wpstream_media_list_bakery_bypass($attributes){
995
996
997
998 $attributes = shortcode_atts(
999 array(
1000 'media_number' => 3,
1001 'product_type_free_paid' => '0',
1002 'product_show_live' => 'no',
1003 'free_label' => '',
1004 'order_by' => '0'
1005 ), $attributes) ;
1006
1007 $attributes['product_type']=1;
1008
1009 if( $attributes['product_type_free_paid']=='Paid'){
1010 $attributes['product_type_free_paid']=1;
1011 }
1012 if( $attributes['product_type_free_paid']=='Free'){
1013 $attributes['product_type_free_paid']=0;
1014 }
1015
1016 if($attributes['order_by']==0){
1017 $order_by_id=array(
1018
1019 0=>esc_html('By date - ASC','wpstream'),
1020 1=>esc_html('By date - DESC','wpstream'),
1021 2=>esc_html('By title - ASC','wpstream'),
1022 3=>esc_html('By title - DESC','wpstream'),
1023 );
1024
1025 $attributes['order_by']= array_search($attributes['order_by'], $order_by_id);
1026 }
1027 global $wpstream_plugin;
1028 return $wpstream_plugin->wpstream_media_list_elementor_function( $attributes );
1029
1030 }
1031
1032 /**
1033 * list vod - shortcode function
1034 *
1035 * @since 3.0.1
1036 *
1037 */
1038
1039 public function wpstream_media_list_bakery_vod_bypass($attributes){
1040
1041
1042
1043 $attributes = shortcode_atts(
1044 array(
1045 'media_number' => 3,
1046 'product_type_free_paid' => '0',
1047 'product_show_live' => 'no',
1048 'free_label' => '',
1049 'order_by' => '0'
1050 ), $attributes) ;
1051
1052 $attributes['product_type']=2;
1053
1054 if( $attributes['product_type_free_paid']=='Paid'){
1055 $attributes['product_type_free_paid']=1;
1056 }
1057 if( $attributes['product_type_free_paid']=='Free'){
1058 $attributes['product_type_free_paid']=0;
1059 }
1060
1061 if($attributes['order_by']==0){
1062 $order_by_id=array(
1063
1064 0=>esc_html('By date - ASC','wpstream'),
1065 1=>esc_html('By date - DESC','wpstream'),
1066 2=>esc_html('By title - ASC','wpstream'),
1067 3=>esc_html('By title - DESC','wpstream'),
1068 );
1069
1070 $attributes['order_by']= array_search($attributes['order_by'], $order_by_id);
1071 }
1072 global $wpstream_plugin;
1073 return $wpstream_plugin->wpstream_media_list_elementor_function( $attributes );
1074
1075 }
1076
1077 /**
1078 * shortocode player
1079 *
1080 * @since 3.0.1
1081 *
1082 */
1083 public function wpstream_chat_function($attributes, $content = null){
1084 $product_id = '';
1085 $return_string = '';
1086 $attributes = shortcode_atts(
1087 array(
1088 'id' => 0,
1089 ), $attributes) ;
1090
1091
1092 if ( isset($attributes['id']) ){
1093 $product_id=$attributes['id'];
1094 }
1095
1096
1097 $return_string.= '<div class="wpstream_plugin_chat_wrapper">';
1098 ob_start();
1099 $this->main->wpstream_player->wpstream_chat_wrapper($product_id);
1100 $return_string.= ob_get_contents();
1101 ob_end_clean();
1102 $return_string.='</div>';
1103 $this->main->wpstream_player->wpstream_connect_to_chat($product_id);
1104
1105 return $return_string;
1106 }
1107
1108
1109
1110
1111 /**
1112 * shortocode player
1113 *
1114 * @since 3.0.1
1115 *
1116 */
1117
1118
1119 public function wpstream_insert_player_inpage_local($attributes, $content = null){
1120 $product_id = '';
1121 $return_string = '';
1122 $attributes = shortcode_atts(
1123 array(
1124 'id' => 0,
1125 'user_id' => 0,
1126 ), $attributes) ;
1127
1128
1129 if ( isset($attributes['id']) ){
1130 $product_id = intval( $attributes['id'] );
1131 }
1132
1133 if ( isset($attributes['user_id']) ){
1134 $user_id = intval( $attributes['user_id'] );
1135 }
1136
1137 if(intval($product_id)==0 && $user_id!=0 ){
1138 $product_id= $this->main->wpstream_player_retrive_first_id($user_id);
1139 }
1140
1141 ob_start();
1142 $this->main->wpstream_player->wpstream_video_player_shortcode($product_id);
1143 $return_string= ob_get_contents();
1144 ob_end_clean();
1145
1146 return $return_string;
1147 }
1148
1149
1150 /**
1151 * shortocode function for start streaming
1152 *
1153 * @since 3.7
1154 *
1155 */
1156
1157
1158 public function wpstream_start_streaming_shortocde($attributes, $content = null){
1159 $product_id = '';
1160 $return_string = '';
1161
1162 $attributes = shortcode_atts(
1163 array(
1164 'id' => 0,
1165 ), $attributes) ;
1166
1167
1168 if ( isset($attributes['id']) ){
1169 $product_id=intval($attributes['id']);
1170 }
1171
1172
1173 ob_start();
1174 global $wpstream_plugin;
1175 $wpstream_plugin->wpstream_live_stream_unit_wrapper( $product_id,'front' );
1176 $return_string= ob_get_contents();
1177 ob_end_clean();
1178
1179 return $return_string;
1180 }
1181
1182
1183
1184 /**
1185 * shortocode player low latency
1186 *
1187 * @since 3.0.1
1188 *
1189 */
1190
1191
1192 public function wpstream_insert_player_inpage_low_latency($attributes, $content = null){
1193 $product_id = '';
1194 $return_string = '';
1195 $attributes = shortcode_atts(
1196 array(
1197 'id' => 0,
1198 'user_id' => 0,
1199 ), $attributes) ;
1200
1201
1202 if ( isset($attributes['id']) ){
1203 $product_id=$attributes['id'];
1204 }
1205
1206
1207 if ( isset($attributes['user_id']) ){
1208 $user_id = intval( $attributes['user_id'] );
1209 }
1210
1211
1212 if(intval($product_id)==0 && $user_id!=0){
1213 $product_id= $this->main->wpstream_player_retrive_first_id($user_id);
1214 }
1215
1216 ob_start();
1217 $this->main->wpstream_player->wpstream_video_player_shortcode_low_latency($product_id);
1218 $return_string= ob_get_contents();
1219 ob_end_clean();
1220
1221 return $return_string;
1222 }
1223
1224
1225
1226 /**
1227 * list products - shortcode function
1228 *
1229 * @since 3.0.1
1230 *
1231 */
1232
1233 public function wpstream_list_products_function($atts, $content=null){
1234
1235 $media_number = "";
1236 $product_type = "";
1237 $attributes = shortcode_atts(
1238 array(
1239 'media_number' => '4',
1240 'product_type' => __('Free Live Channel','wpstream'),
1241
1242 ), $atts);
1243
1244 if ( isset($attributes['media_number']) ){
1245 $media_number=$attributes['media_number'];
1246 }
1247
1248 if ( isset($attributes['product_type']) ){
1249 $product_type=$attributes['product_type'];
1250 }
1251
1252 if($product_type== __('Free Live Channel','wpstream') ){
1253 $product_type=1;
1254 }else{
1255 $product_type=2;
1256 }
1257
1258 $return_string="";
1259
1260
1261
1262 $args = array(
1263 'post_type' => 'wpstream_product',
1264 'post_status' => 'publish',
1265 'meta_query' =>array(
1266 array(
1267 'key' => 'wpstream_product_type',
1268 'value' => $product_type,
1269 'compare' => '=',
1270 ),
1271 ),
1272 'posts_per_page' =>$media_number,
1273 'page' => 1
1274 );
1275
1276
1277 $media_list= new WP_Query($args);
1278
1279 if($product_type==1){
1280 $see_product= __('See Free Live Chanel','wpstream');
1281 }else{
1282 $see_product =__('See Free Video','wpstream');
1283 }
1284
1285
1286
1287 while($media_list->have_posts()):$media_list->the_post();
1288 $return_string.='<div class="wpstream_product_unit">'
1289 .'<div class="product_image" style="background-image:url('.wp_get_attachment_thumb_url(get_post_thumbnail_id()).')"></div>'
1290 .'<a href="'.get_permalink().'" class="product_title" >'.get_the_title().'</a>'
1291 .'<a href="'.get_permalink().'"class="see_product">'.$see_product.'</a>'
1292 .'</div>';
1293 endwhile;
1294
1295 wp_reset_postdata();
1296 wp_reset_query();
1297
1298
1299 return '<div class="shortcode_list_wrapper">'.$return_string.'</div>';
1300
1301 }
1302
1303
1304
1305 /**
1306 * register shortcodes - add buttons in js
1307 *
1308 * @since 3.0.1
1309 *
1310 */
1311
1312 public function wpstream_add_plugin($plugin_array) {
1313 $plugin_array['wpstream_player'] = plugin_dir_url( __FILE__ ). '/js/shortcodes.js';
1314 $plugin_array['wpstream_list_products'] = plugin_dir_url( __FILE__ ). '/js/shortcodes.js';
1315 $plugin_array['wpstream_list_products_channels']= plugin_dir_url( __FILE__ ). '/js/shortcodes.js';
1316 return $plugin_array;
1317 }
1318
1319 /**
1320 * register shortcodes - add buttons
1321 *
1322 * @since 3.0.1
1323 *
1324 */
1325 public function wpstream_register_button($buttons) {
1326 array_push($buttons, "|", "wpstream_player");
1327 array_push($buttons, "|", "wpstream_list_products");
1328 array_push($buttons, "|", "wpstream_list_products_channels");
1329 return $buttons;
1330 }
1331
1332
1333
1334 /**
1335 * wpstream cors
1336 *
1337 * @since 3.0.1
1338 *
1339 */
1340
1341 public function wpstream_cors_check_and_response(){
1342 if ($_SERVER['REQUEST_METHOD'] == "OPTIONS") {
1343 header('Access-Control-Allow-Methods: POST, GET');
1344 header('Access-Control-Allow-Headers: Authorization');
1345 header('Access-Control-Max-Age: 1'); //1728000
1346 header("Content-Length: 0");
1347 header("Content-Type: text/plain charset=UTF-8");
1348 exit(0);
1349 }
1350 }
1351
1352 /**
1353 * set user cookie
1354 *
1355 * @since 3.0.1
1356 *
1357 */
1358
1359 public function wpstream_set_cookies(){
1360 $local_event_options = get_option('wpstream_user_streaming_global_channel_options') ;
1361
1362 if(isset($local_event_options['ses_encrypt']) && intval($local_event_options['ses_encrypt'])==1 ) {
1363
1364
1365 if (session_status() == PHP_SESSION_NONE) {
1366 session_start();
1367 }
1368
1369 if( !isset( $_REQUEST[ 'wpstream_livedrm' ]) && !isset( $_REQUEST[ 'wpstream_voddrm' ]) && !isset( $_REQUEST[ 'keys2' ]) ) {
1370
1371 if( !isset($_SESSION['wpstream_id']) ){
1372
1373 $_SESSION['wpstream_id']= uniqid();
1374 }
1375 }
1376 }
1377 }
1378
1379 /**
1380 * editd 4.0
1381 *
1382 * get key for live stream
1383 *
1384 * @since 3.0.1
1385 *
1386 */
1387
1388
1389 public function wpstream_live_streaming_key(){
1390
1391 $local_event_options = get_option('wpstream_user_streaming_global_channel_options') ;
1392
1393 if( isset( $_REQUEST[ 'wpstream_livedrm' ]) && $_REQUEST[ 'wpstream_livedrm' ]!='' ) {
1394
1395 if(isset($local_event_options['ses_encrypt']) && intval($local_event_options['ses_encrypt'])==1 ) {
1396
1397 if( !isset( $_SESSION['wpstream_id'] ) ){
1398 session_write_close ();die('no session');
1399
1400 }
1401 }
1402
1403
1404 $streamname_received = esc_html($_REQUEST[ 'wpstream_livedrm' ]);
1405 $stream_key_array = explode('-', $streamname_received);
1406
1407 $streamname = $stream_key_array[0];
1408 $current_user = wp_get_current_user();
1409
1410 $event_list_free_posts = get_transient( 'free_event_streamName_'.$streamname ) ;
1411
1412 wp_reset_postdata();
1413 wp_reset_query();
1414
1415
1416 if ( false === $event_list_free_posts ) {
1417
1418 $args_free = array(
1419 'posts_per_page' => -1,
1420 'cache_results' => false,
1421 'update_post_meta_cache' => false,
1422 'update_post_term_cache' => false,
1423 'post_type' => 'wpstream_product',
1424 'post_status' => 'publish',
1425 'meta_query' => array(
1426 array(
1427 'key' => 'stream_name',
1428 'value' => $streamname,
1429 'compare' => '=',
1430 )
1431 ),
1432 'fields'=>'ids',
1433 );
1434
1435 $event_list_free = new WP_Query($args_free);
1436 $event_list_free_posts = $event_list_free->posts;
1437 set_transient( 'free_event_streamName_'.$streamname, $event_list_free->posts ,60);
1438 }
1439
1440 if ( !empty($event_list_free_posts ) ){
1441 ////////////////////////////////////////////////////////////
1442 // when we have a free event
1443 ////////////////////////////////////////////////////////////
1444 $the_id = $event_list_free_posts[0];
1445 $show_id = $the_id;
1446 $get_key = $this->wpstream_get_encryption_key_remonting($show_id,$streamname_received);
1447
1448 $seconds_to_cache = 301;
1449 $ts = gmdate("D, d M Y H:i:s", time() + $seconds_to_cache) . " GMT";
1450 header("Expires: $ts");
1451 header("Pragma: cache");
1452 header("Cache-Control: max-age=$seconds_to_cache");
1453
1454
1455 print $get_key;
1456 die();
1457
1458
1459 }else{
1460 ////////////////////////////////////////////////////////////
1461 // this is for paid products
1462 ////////////////////////////////////////////////////////////
1463
1464 if ( is_user_logged_in() && intval($current_user->ID)!=0 ) {
1465
1466 $event_list_paid_posts = get_transient( 'paid_event_streamName_'.$streamname ) ;
1467
1468
1469
1470 if ( false === $event_list_paid_posts ) {
1471 $args = array(
1472 'posts_per_page' => -1,
1473 'post_type' => 'product',
1474 'post_status' => 'publish',
1475 'meta_query' => array(
1476 array(
1477 'key' => 'stream_name',
1478 'value' => $streamname,
1479 'compare' => '=',
1480 ),
1481 ),
1482 'tax_query' => array(
1483 'relation' => 'AND',
1484 array(
1485 'taxonomy' => 'product_type',
1486 'field' => 'slug',
1487 'terms' => array('live_stream','subscription')
1488 )
1489 ),
1490 'fields'=>'ids',
1491 );
1492
1493
1494 $event_list = new WP_Query($args);
1495 $event_list_paid_posts = $event_list->posts;
1496
1497 set_transient( 'paid_event_streamName_'.$streamname, $event_list->posts ,60);
1498 }
1499
1500 if ( !empty($event_list_paid_posts ) ){
1501
1502 $the_id = $event_list_paid_posts[0];
1503 $show_id = $the_id;
1504
1505
1506 $is_valid_subscription=0;
1507 if(class_exists ('WC_Subscription')){
1508 $is_valid_subscription = wcs_user_has_subscription( $current_user->ID, $show_id ,'active');
1509 }
1510
1511
1512 if(function_exists('wpstream_check_global_subscription_model')){
1513 if( wpstream_check_global_subscription_model() ){
1514 $is_valid_subscription=1;// this is global subscription
1515 }
1516 }
1517
1518
1519 if( $this->main->wpstream_player->wpstream_in_plugin_check_global_subscription_model($show_id) ){
1520 $is_valid_subscription=1;// this is global subscription
1521 }
1522
1523
1524 if( wc_customer_bought_product( $current_user->email, $current_user->ID, $show_id) || $is_valid_subscription==1 ){
1525 $get_key = $this->wpstream_get_encryption_key_remonting($show_id,$streamname_received);
1526
1527 $seconds_to_cache = 302;
1528 $ts = gmdate("D, d M Y H:i:s", time() + $seconds_to_cache) . " GMT";
1529 header("Expires: $ts");
1530 header("Pragma: cache");
1531 header("Cache-Control: max-age=$seconds_to_cache");
1532
1533 print $get_key;
1534 die();
1535
1536 }else{
1537 exit('live - no ticket ');
1538 }
1539
1540 } else{
1541 exit('live - no event');
1542 }
1543
1544 }else{
1545 exit('live - user not log or anwser');
1546 }
1547
1548 }
1549 exit('no free or paid event');
1550
1551 }else{
1552
1553 return;
1554 }
1555
1556 }
1557
1558
1559
1560
1561 /**
1562 * get remote key for live
1563 *
1564 * @since 3.0.1
1565 *
1566 */
1567
1568 public function wpstream_get_encryption_key_remonting ($show_id,$streamname_received){
1569 $get_key = get_transient( $show_id.'_api20_streamName' );
1570
1571
1572 if ( false === $get_key ) {
1573
1574 $url = get_post_meta($show_id,'hls_key_retrieval_url',true).'/'.$streamname_received;
1575
1576 $get= wp_remote_get( $url );
1577
1578 if(is_array($get)){
1579 $get_key = $get['body'];
1580 }else{
1581 $get_key='';
1582 }
1583
1584 set_transient( $show_id.'_api20_streamName', $get_key, 30 );
1585 }
1586 return $get_key;
1587 }
1588
1589
1590
1591 /**
1592 * get key for 3rdparty
1593 *
1594 * @since 3.0.1
1595 *
1596 */
1597
1598
1599 public function wpstream_live_streaming_key_for_3rdparty(){
1600
1601 if( isset( $_REQUEST[ 'thirdkeys' ]) && $_REQUEST[ 'thirdkeys' ]!='' ) {
1602
1603 $thirdkeys = esc_html($_REQUEST[ 'thirdkeys' ]);
1604
1605 //live_event_carnat2
1606
1607 $args = array(
1608 'post_type' => array('product','wpstream_product'),
1609 'post_status' => 'publish',
1610 'meta_query' =>array(
1611 array(
1612 'key' => 'live_event_carnat2',
1613 'value' => $thirdkeys,
1614 'compare' => '=',
1615 ),
1616 ),
1617
1618
1619 );
1620
1621
1622 $media_list= new WP_Query($args);
1623 if($media_list->have_posts()){
1624 while($media_list->have_posts()):$media_list->the_post();
1625
1626 $media_id = get_the_ID();
1627 $replay_array = array(
1628 // '', // fb will be here
1629 stripslashes( get_post_meta($media_id,'wpstream_youtube_rtmp',true )),
1630 stripslashes( get_post_meta($media_id,'wpstream_twich_rtmp',true) ),
1631 );
1632
1633 $reply_final=array('rtmp_urls'=>$replay_array);
1634 header('Content-Type: application/json;charset=utf-8');
1635 print json_encode($reply_final,JSON_UNESCAPED_SLASHES);
1636 die();
1637
1638
1639 endwhile;
1640 }else{
1641 print'{}';
1642 die('');
1643 }
1644
1645 }
1646
1647 }
1648
1649
1650
1651 /**
1652 * get key for vod
1653 *
1654 * @since 3.0.1
1655 *
1656 */
1657 public function wpstream_live_streaming_key_vod(){
1658 $local_event_options = get_option('wpstream_user_streaming_global_channel_options') ;
1659 $current_user = wp_get_current_user();
1660
1661
1662
1663 if( isset( $_REQUEST[ 'wpstream_voddrm' ]) && $_REQUEST[ 'wpstream_voddrm' ]!='' ) {
1664
1665 if(isset($local_event_options['ses_encrypt']) && intval($local_event_options['ses_encrypt'])==1 ) {
1666
1667 if( !isset( $_SESSION['wpstream_id'] ) ){
1668 unset($_SESSION['wpstream_id']);
1669 session_write_close ();session_register_shutdown();
1670 die('no session');
1671 }
1672 }
1673
1674 $hlsDecryptionKeyIndex = esc_html($_REQUEST[ 'wpstream_voddrm' ]);
1675 $vod_list_free_posts = get_transient( 'vod_decryption_key_index_'.$hlsDecryptionKeyIndex ) ;
1676
1677 if ( false === $vod_list_free_posts ) {
1678 $args_free = array(
1679 'posts_per_page' => -1,
1680 'cache_results' => false,
1681 'update_post_meta_cache' => false,
1682 'update_post_term_cache' => false,
1683 'post_type' => 'wpstream_product_vod',
1684 'post_status' => 'publish',
1685 'meta_query' => array(
1686 array(
1687 'key' => 'hlsDecryptionKeyIndex',
1688 'value' => $hlsDecryptionKeyIndex,
1689 'compare' => '=',
1690 )
1691 ),
1692 'fields'=>'ids',
1693 );
1694
1695 $event_list_free = new WP_Query($args_free);
1696
1697 $vod_list_free_posts= $event_list_free->posts;
1698 set_transient( 'vod_decryption_key_index_'.$hlsDecryptionKeyIndex, $event_list_free->posts ,60);
1699 }// end check transient
1700
1701
1702
1703 if ( !empty($vod_list_free_posts ) ){
1704 ////////////////////////////////////////////////////////////
1705 // when we have a free event
1706 ////////////////////////////////////////////////////////////
1707 $the_id = $vod_list_free_posts[0];
1708 $get_key = get_post_meta($the_id,'hlsDecryptionKey',true);
1709
1710 $seconds_to_cache = 301;
1711 $ts = gmdate("D, d M Y H:i:s", time() + $seconds_to_cache) . " GMT";
1712 header("Expires: $ts");
1713 header("Pragma: cache");
1714 header("Cache-Control: max-age=$seconds_to_cache");
1715
1716
1717 print base64_decode( $get_key );
1718 die();
1719
1720
1721 }else{
1722 ////////////////////////////////////////////////////////////
1723 // this is for paid products
1724 ////////////////////////////////////////////////////////////
1725 if ( is_user_logged_in() && intval($current_user->ID)!=0 ) {
1726 $hlsDecryptionKeyIndex = esc_html($_REQUEST[ 'wpstream_voddrm' ]);
1727 $event_list_paid_posts = get_transient( 'paid_vod_key_index_'.$hlsDecryptionKeyIndex ) ;
1728
1729
1730 if ( false === $event_list_paid_posts ) {
1731 $args = array(
1732 'posts_per_page' => -1,
1733 'post_type' => 'product',
1734 'post_status' => 'publish',
1735 'meta_query' => array(
1736 array(
1737 'key' => 'hlsDecryptionKeyIndex',
1738 'value' => $hlsDecryptionKeyIndex,
1739 'compare' => '=',
1740 ),
1741 ),
1742 'tax_query' => array(
1743 'relation' => 'AND',
1744 array(
1745 'taxonomy' => 'product_type',
1746 'field' => 'slug',
1747 'terms' => array('video_on_demand','subscription')
1748 )
1749 ),
1750 'fields'=>'ids',
1751 );
1752
1753
1754 $event_list = new WP_Query($args);
1755 $vod_list_paid_posts = $event_list->posts;
1756
1757 set_transient( 'paid_vod_key_index_'.$hlsDecryptionKeyIndex, $event_list->posts ,60);
1758 }
1759
1760
1761 if ( !empty($vod_list_paid_posts ) ){
1762
1763 $the_id = $vod_list_paid_posts[0];
1764 $show_id = $the_id;
1765
1766
1767 $is_valid_subscription=0;
1768 if(class_exists ('WC_Subscription')){
1769 $is_valid_subscription = wcs_user_has_subscription( $current_user->ID, $show_id ,'active');
1770 }
1771
1772
1773 if(function_exists('wpstream_check_global_subscription_model')){
1774 if( wpstream_check_global_subscription_model() ){
1775 $is_valid_subscription=1;// this is global subscription
1776 }
1777 }
1778
1779
1780 if( $this->main->wpstream_player->wpstream_in_plugin_check_global_subscription_model($show_id) ){
1781 $is_valid_subscription=1;// this is global subscription
1782 }
1783
1784
1785 if( wc_customer_bought_product( $current_user->email, $current_user->ID, $show_id) || $is_valid_subscription==1 ){
1786
1787 $get_key = get_post_meta($show_id,'hlsDecryptionKey',true);
1788
1789 $seconds_to_cache = 302;
1790 $ts = gmdate("D, d M Y H:i:s", time() + $seconds_to_cache) . " GMT";
1791 header("Expires: $ts");
1792 header("Pragma: cache");
1793 header("Cache-Control: max-age=$seconds_to_cache");
1794
1795 print base64_decode( $get_key );
1796 die();
1797
1798 }else{
1799 exit('vod - no ticket ');
1800 }
1801
1802 } else{
1803 exit('vod - no item');
1804 }
1805
1806 }else{
1807 exit('vod - user not log or no answer');
1808 }
1809
1810
1811 }
1812
1813
1814
1815 }
1816
1817
1818 }
1819
1820
1821
1822
1823
1824
1825 public function wpstream_get_vod_key($filename){
1826 return;
1827 // global $wpstream_plugin;
1828 // $vod_key = get_transient("vod_key".$filename);
1829 // if(false===$vod_key){
1830 // $token = $wpstream_plugin->wpstream_live_connection->wpstream_get_token();
1831 // $domain = parse_url ( get_site_url() );
1832 //
1833 // $values_array=array(
1834 // "filename" => $filename,
1835 // );
1836 // $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/uservodkey/get/?access_token=".$token;
1837 //
1838 //
1839 // $arguments = array(
1840 // 'method' => 'GET',
1841 // 'timeout' => 45,
1842 // 'redirection' => 5,
1843 // 'httpversion' => '1.0',
1844 // 'blocking' => true,
1845 // 'headers' => array(),
1846 // 'body' => $values_array,
1847 // 'cookies' => array()
1848 // );
1849 // $response = wp_remote_post($url,$arguments);
1850 // $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
1851 //
1852 //
1853 // if( isset($response['response']['code']) && $response['response']['code']=='200'){
1854 // set_transient("vod_key".$filename,$received_data,120);
1855 // return ($received_data);
1856 // }else{
1857 // return 'failed connection';
1858 // }
1859 // }else{
1860 // return $vod_key;
1861 // }
1862
1863 }
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873 /**
1874 * wrapper start around woo
1875 *
1876 * @since 3.0.1
1877 *
1878 */
1879
1880
1881 public function wpstream_non_image_content_wrapper_start() {
1882 if ( is_user_logged_in() ) {
1883 global $product;
1884 $current_user = wp_get_current_user();
1885 $product = wc_get_product();
1886
1887 if($product){
1888 $product_id = $product->get_id();
1889 if ( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product_id) ){
1890 echo '<div id="wpstream_product_wrap">';
1891 }else{
1892 echo '<div id="wpstream_product_wrap_no_buy">';
1893 }
1894 }
1895 }
1896
1897 }
1898
1899 /**
1900 * wrapper end around woo
1901 *
1902 * @since 3.0.1
1903 *
1904 */
1905
1906
1907 function wpstream_non_image_content_wrapper_end() {
1908 // echo '</div>';
1909 }
1910
1911
1912 /**
1913 * wpstream thank you extra
1914 *
1915 * @since 3.12
1916 *
1917 */
1918
1919 function wpstream_thankyou_extra($var,$order){
1920 return $this->wpstream_get_ordered_items($order);
1921 }
1922
1923
1924 /**
1925 * wpstream thank you extra on order
1926 *
1927 * @since 3.12
1928 *
1929 */
1930 function wpstream_email_order_details($order, $sent_to_admin, $plain_text, $email){
1931 print $this->wpstream_get_ordered_items($order).'</br>';
1932 }
1933
1934
1935
1936 /**
1937 * wpstream compose message for complted order and thank you page
1938 *
1939 * @since 3.12
1940 *
1941 */
1942
1943 function wpstream_get_ordered_items($order){
1944
1945 $message = esc_html( get_option('wpstream_product_thankyou','Thanks for your purchase. You can access your item at any time by visiting the following page: {item_link}')) ;
1946 $list = '';
1947 $product_id = 0;
1948
1949 foreach( $order->get_items() as $line_item ) {
1950 // The WC_Product object
1951 $product = $line_item->get_product(); // Added
1952 $list .= '<a href="'.$product->get_permalink().'">'.$product->get_title().'</a>, ';// Changed
1953 $product_id = $product->get_id();
1954 }
1955 $list = trim($list,', ');
1956 $message = str_replace('{item_link}', $list, $message);
1957
1958 $term_list = wp_get_post_terms($product_id, 'product_type');
1959 $product = wc_get_product($product_id);
1960
1961 $product_type = $product->get_type();
1962
1963
1964 if( $term_list[0]->name=='live_stream' || $term_list[0]->name=='video_on_demand' || $product_type=='subscription' ){
1965 return $message;
1966 }else{
1967 $message = esc_html('Thank you. Your order has been received','wpstream');
1968 return $message;
1969 }
1970
1971
1972 }
1973 }
1974