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

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

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