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

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