PluginProbe
WpStream – Live Streaming, Video on Demand, Pay Per View / 2.06
WpStream – Live Streaming, Video on Demand, Pay Per View v2.06
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
← All changes | wpstream.php +412 -238 4.132.06 View file →
@@ -1,21 +1,20 @@
1 1 <?php
2 2 /**
3 - * Plugin Name: WpStream - Live Streaming, Video on Demand, Pay Per View
4 - * Plugin URI: http://wpstream.net
5 - * Description: WpStream is a platform that allows you to live stream, create Video-on-Demand, and offer Pay-Per-View videos. We provide an affordable and user-friendly way for businesses, non-profits, and public institutions to broadcast their content and monetize their work.
6 - * Version: 4.13
7 - * Author: wpstream
8 - * Author URI: http://wpstream.net
9 - * Text Domain: wpstream
10 - * Domain Path: /languages/
3 + * Plugin Name: WpStream
4 + * Plugin URI: wpstream.net
5 + * Description: WpStream is a wordpress plugin to help you stream & monetize media content.
6 + * Version: 2.06
7 + * Author: wpstream.net
8 + * Author URI: https://wpstream.net
9 + * Developer: WpStream
10 + * Developer URI: https://wpstream.net
11 + * Text Domain: wpstream
12 + * Domain Path: /languages
13 + * * Copyright: © 2017 WpStream
11 14 */
15 +
12 16
13 -// If this file is called directly, abort.
14 -if ( ! defined( 'WPINC' ) ) {
15 - die;
16 -}
17 -define('WPSTREAM_PLUGIN_VERSION', '4.13');
18 17 define('WPSTREAM_CLUBLINK', 'wpstream.net');
19 18 define('WPSTREAM_CLUBLINKSSL', 'https');
20 19 define('WPSTREAM_PLUGIN_URL', plugins_url() );
21 20 define('WPSTREAM_PLUGIN_DIR_URL', plugin_dir_url(__FILE__) );
@@ -20,306 +19,481 @@
20 19 define('WPSTREAM_PLUGIN_URL', plugins_url() );
21 20 define('WPSTREAM_PLUGIN_DIR_URL', plugin_dir_url(__FILE__) );
22 21 define('WPSTREAM_PLUGIN_PATH', plugin_dir_path(__FILE__) );
23 22 define('WPSTREAM_PLUGIN_BASE', plugin_basename(__FILE__) );
24 -if( !defined('WPSTREAM_API' ) ) {
25 - define('WPSTREAM_API', 'https://baker.wpstream.net');
23 +
24 +require_once ('main.php');
25 +require_once ('libs/api_functions.php');
26 +require_once ('libs/plugin-admin.php');
27 +require_once ('libs/product_types.php');
28 +require_once ('libs/wpstream_free_product_types.php');
29 +require_once ('libs/shortcodes.php');
30 +require_once ('libs/keys.php');
31 +
32 +
33 +
34 +function wpstream_install(){
35 + flush_rewrite_rules();
26 36 }
27 -if ( !defined( 'WPSTREAM_CLICK' ) ) {
28 - define( 'WPSTREAM_CLICK', 'https://click.wpstream.net' );
37 +
38 +register_activation_hook( __FILE__, 'wpstream_install' );
39 +
40 +
41 +
42 +
43 +function wpstream_deactivation(){
44 + delete_option('wp_estate_token_expire');
45 + delete_option('wp_estate_curent_token');
46 + delete_option('wpstream_api_key');
47 + delete_option('wpstream_api_secret_key');
48 + delete_option('wpstream_api_username');
49 + delete_option('wpstream_api_password');
50 +
51 + flush_rewrite_rules();
29 52 }
30 -if ( !defined( 'WPSTREAM_PLAYER') ) {
31 - define ( 'WPSTREAM_PLAYER', 'https://player.wpstream.net' );
53 +register_deactivation_hook( __FILE__, 'wpstream_deactivation' );
54 +
55 +
56 +wpstream_main_start();
57 +
58 +
59 +
60 +function wpstream_admin_notice(){
61 + if ( !in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
62 + print '<div class="notice notice-error is-dismissible">
63 + <p>'.__( 'WpStream Pay Per View / Subscription mode works only with WooCommerce - If you want to charge money for your live events or videos you need to activate WooCommerce plugin', 'wpestate' ).'</p>
64 + </div>';
65 + }
66 + if( !in_array ('curl', get_loaded_extensions())) {
67 + print '<div class="notice notice-error is-dismissible">
68 + <p>'.__( 'The php CURL library is not enabled on your server. WpStream plugin needs this library in order to work. Please address this issue with your hosting provider.', 'wpestate' ).'</p>
69 + </div>';
70 + }
71 +
72 +
32 73 }
33 -if ( !defined( 'LIVE_PLAYER_URL_PREFIX' ) ) {
34 - define('LIVE_PLAYER_URL_PREFIX', 'https://player.wpstream.net/player/live');
74 +add_action( 'admin_notices', 'wpstream_admin_notice' );
75 +
76 +
77 +
78 +function wpstream_enqueue_styles() {
79 + wp_enqueue_style('wpstream-style', WPSTREAM_PLUGIN_DIR_URL .'/wpstream_style.css' );
80 + wp_enqueue_style('video-js.min', WPSTREAM_PLUGIN_DIR_URL.'/css/video-js.min.css', array(), '1.0', 'all');
81 + wp_enqueue_script('video.min', WPSTREAM_PLUGIN_DIR_URL.'js/video.min.js',array(), '1.0', false);
82 +
83 +
84 + wp_enqueue_script('youtube.min', WPSTREAM_PLUGIN_DIR_URL.'js/youtube.min.js',array('video.min'), '1.0', false);
85 + wp_enqueue_script('videojs-vimeo.min', WPSTREAM_PLUGIN_DIR_URL.'js/videojs-vimeo.min.js',array('video.min'), '1.0', false);
35 86 }
36 87
37 88
38 -define('WPSTREAM_TIMEOUT_CONST', 20); // in seconds
39 89
40 -function wpstream_cleanup_logs_handler() {
41 - $logger = new WpStream_Logger();
42 - $logger->clear_old_logs();
90 +
91 +function wpstream_enqueue_styles_admin(){
92 + wp_enqueue_script("jquery-ui-slider");
93 + wp_enqueue_script("jquery-ui-datepicker");
94 + wp_enqueue_script('wpstream-jquery.fileupload', WPSTREAM_PLUGIN_DIR_URL.'js/jquery.fileupload.js',array(), '1.0', true);
95 +
96 + wp_enqueue_style ('admin-css', WPSTREAM_PLUGIN_DIR_URL.'/css/admin_style.css', array(), '1.0', 'all');
97 + wp_enqueue_script('wpstream-admin-control', WPSTREAM_PLUGIN_DIR_URL.'js/admin_control.js',array(), '1.0', true);
98 + wp_localize_script('wpstream-admin-control', 'wpstream_admin_control_vars',
99 + array(
100 + 'admin_url' => get_admin_url(),
101 + 'loading_url' => WPSTREAM_PLUGIN_DIR_URL.'/img/loading.gif',
102 + 'download_mess' => esc_html__('Click to download! The url will work for the next 20 minutes! Refresh page if you need to generate the link again!','wpstream'),
103 + 'uploading' => esc_html('We are uploading your file.Do not close this window!','wpstream'),
104 + 'upload_complete2' => esc_html('Upload Complete! You can upload another file!','wpstream'),
105 + 'not_accepted' => esc_html('The file is not an accepted video format','wpstream'),
106 + 'upload_complete' => esc_html('Upload Complete!','wpstream'),
107 + 'no_band' => esc_html('Not enough bandwidth.','wpsteam'),
108 + 'no_band_no_store' => esc_html('Not enough bandwidth or storage.','wpsteam')
109 +
110 + ));
43 111 }
44 -add_action('wpstream_log_cleanup', 'wpstream_cleanup_logs_handler');
45 112
46 -/**
47 - * The code that runs during plugin activation.
48 - * This action is documented in includes/class-wpstream-activator.php
49 - */
50 -function activate_wpstream() {
51 - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wpstream-activator.php';
52 - Wpstream_Activator::activate();
53 113
54 - if( !wp_next_scheduled( 'wpstream_log_cleanup' ) ) {
55 - wp_schedule_event( time(), 'daily', 'wpstream_log_cleanup' );
56 - }
114 +
115 +
116 +
117 +function wpstream_my_custom_endpoints() {
118 + add_rewrite_endpoint( 'video-list', EP_ROOT | EP_PAGES );
119 + add_rewrite_endpoint( 'event-list', EP_ROOT | EP_PAGES );
57 120 }
58 121
59 -/**
60 - * The code that runs during plugin deactivation.
61 - * This action is documented in includes/class-wpstream-deactivator.php
62 - */
63 -function deactivate_wpstream() {
64 - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wpstream-deactivator.php';
65 - Wpstream_Deactivator::deactivate();
66 122
67 - wp_clear_scheduled_hook( 'wpstream_log_cleanup' );
123 +
124 +function wpstream_my_custom_query_vars( $vars ) {
125 + $vars[] = 'video-list';
126 + $vars[] = 'event-list';
127 + return $vars;
68 128 }
69 129
70 -register_activation_hook( __FILE__, 'activate_wpstream' );
71 -register_deactivation_hook( __FILE__, 'deactivate_wpstream' );
72 130
73 -/**
74 - * Wrapper function for wpstream_dashboard_save_channel_data to be called from theme
75 - * This provides backward compatibility for the theme
76 - */
77 -function wpstream_dashboard_save_channel_data_plugin() {
78 - global $wpstream_plugin;
79 - if (isset($wpstream_plugin) && isset($wpstream_plugin->wpstream_ajax)) {
80 - $wpstream_plugin->wpstream_ajax->wpstream_dashboard_save_channel_data();
81 - }
131 +
132 +function wpstream_custom_flush_rewrite_rules() {
133 + flush_rewrite_rules();
82 134 }
83 135
84 -/**
85 - * The core plugin class that is used to define internationalization,
86 - * admin-specific hooks, and public-facing site hooks.
87 - */
88 -require plugin_dir_path( __FILE__ ) . 'includes/class-wpstream.php';
89 -require plugin_dir_path( __FILE__ ) . 'wpstream-elementor.php';
90 -require plugin_dir_path( __FILE__ ) . 'streamify/streamify.php';
91 136
92 -require plugin_dir_path( __FILE__ ) . 'integrations/integrations.php';
93 137
94 -function wpstream_load_theme_functionality() {
95 - define ('WPSTREAM_FRAMEWORK_BASE', plugin_dir_path(__FILE__) . 'hello-wpstream' );
138 +function wpstream_custom_my_account_menu_items( $items ) {
139 + if(function_exists('wpstream_is_global_subscription') && wpstream_is_global_subscription()){
140 + $items = array(
141 + 'dashboard' => __( 'Dashboard', 'woocommerce' ),
142 + 'orders' => __( 'Orders', 'woocommerce' ),
143 + 'edit-address' => __( 'Addresses', 'woocommerce' ),
144 + 'edit-account' => __( 'Edit Account', 'woocommerce' ),
145 + 'customer-logout' => __( 'Logout', 'woocommerce' ),
146 + );
147 + }else{
148 + $items = array(
149 + 'dashboard' => __( 'Dashboard', 'woocommerce' ),
150 + 'orders' => __( 'Orders', 'woocommerce' ),
151 + 'edit-address' => __( 'Addresses', 'woocommerce' ),
152 + 'edit-account' => __( 'Edit Account', 'woocommerce' ),
153 + 'event-list' => __( 'Events', 'wpstream' ),
154 + 'video-list' => __( 'Videos', 'wpstream' ),
155 + 'customer-logout' => __( 'Logout', 'woocommerce' ),
156 + );
157 + }
158 + return $items;
159 +}
96 160
97 - $core_files = array(
98 - '/framework/metaboxes.php',
99 - '/framework/query-functions.php',
100 - '/framework/wpstream-video-functions.php',
101 - '/framework/ajax-functions.php',
102 - '/framework/dashboard-functions.php',
103 - '/framework/wpstream-help-functions.php',
104 - '/framework/video-pages-functions.php',
105 - '/framework/comments-functions.php',
106 - '/framework/gallery-functions.php',
107 - '/framework/shortcodes-functions.php',
108 - '/framework/post-types/main.php',
109 - '/framework/woocommerce-functions.php',
110 - '/framework/ajax-upload.php',
111 - '/framework/email-functions.php',
112 - '/framework/widgets/class-wpstream-widget-manager.php',
113 - '/framework/classes/class-wpstream-login-register.php',
114 - '/framework/classes/class-wpstream_theme-social-login.php',
115 - );
116 161
117 - // Load core files
118 - foreach ( $core_files as $file ) {
119 - $file_path = WPSTREAM_FRAMEWORK_BASE . $file;
120 - if ( file_exists( $file_path ) ) {
121 - require_once $file_path;
122 - } else {
123 - error_log( 'Missing required file: ' . $file_path );
124 - }
125 - }
162 +function wpstream_custom_endpoint_content_event_list() {
163 + include 'woocommerce/myaccount/event_list.php';
164 +}
126 165
127 - // Load Elementor integration if the plugin is active
128 - if ( defined( 'ELEMENTOR_VERSION' ) ) {
129 166
130 - $elementor_files = array(
131 - '/elementor/functions/blog_functions.php',
132 - '/elementor/wpstream-elementor.php'
133 - );
134 167
135 - foreach ( $elementor_files as $file ) {
136 - $file_path = WPSTREAM_FRAMEWORK_BASE . $file;
137 - if ( file_exists( $file_path ) ) {
138 - require_once $file_path;
139 - } else {
140 - error_log( 'Missing required file: ' . $file_path );
141 - }
142 - }
143 - }
168 +function wpstream_custom_endpoint_video_list() {
169 + include 'woocommerce/myaccount/video_list.php';
144 170 }
145 171
146 -add_action( 'after_setup_theme', 'wpstream_load_theme_functionality' );
147 172
148 -/**
149 - * Load js for players
150 - *
151 - * @return void
152 - */
153 -if ( ! function_exists( 'wpstream_load_player_js_on_demand' ) ) {
154 - function wpstream_load_player_js_on_demand()
155 - {
156 - $wpstream_unit_card_use_video = get_theme_mod('wpstream_unit_card_use_video');
157 - if ($wpstream_unit_card_use_video) {
158 - wp_enqueue_script('video.min');
159 - wp_enqueue_script('wpstream-player');
160 - }
161 173
162 - }
163 -}
164 174
165 -/**
166 - * Begins execution of the plugin.
167 - *
168 - * Since everything within the plugin is registered via hooks,
169 - * then kicking off the plugin from this point in the file does
170 - * not affect the page life cycle.
171 - *
172 - * @since 3.0.1
173 - */
175 +function wpstream_user_logged_in_product_already_bought($from_sh_id='') {
174 176
175 -global $wpstream_plugin;
176 -$wpstream_plugin = new Wpstream();
177 -$wpstream_plugin->run();
177 + if ( is_user_logged_in() ) {
178 + global $product;
179 + $current_user = wp_get_current_user();
180 + $product_id = $product->get_id();
178 181
179 -add_action( 'upgrader_process_complete', 'wpstream_my_upgrate_function',10, 2);
180 182
181 -function wpstream_my_upgrate_function( $upgrader_object, $options ) {
183 + if ( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product_id) || ( function_exists('wcs_user_has_subscription') && wcs_user_has_subscription( $current_user->ID, $product_id ,'active') ) ){
182 184
183 -
184 - $current_plugin_path_name = plugin_basename( __FILE__ );
185 -
186 - if ($options['action'] == 'update' && $options['type'] == 'plugin' ) {
187 - if(is_array($options)):
188 - foreach($options['plugins'] as $each_plugin) {
189 - if ($each_plugin==$current_plugin_path_name) {
190 - delete_transient('wpstream_token_api');
191 - update_option('wp_estate_token_expire',0);
192 - update_option('wp_estate_curent_token',' ');
193 185
194 - }
186 + echo '<div class="wpstream_player_wrapper"><div class="wpstream_player_container">';
187 +
188 + $is_subscription_live_event = esc_html(get_post_meta($product_id,'_subscript_live_event',true));
189 + $term_list = wp_get_post_terms($product_id, 'product_type');
190 +
191 + if( $term_list[0]->name=='live_stream' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){
192 + wpstream_live_event_player($product_id);
193 + }else if( $term_list[0]->name=='video_on_demand' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='no' ) ){
194 + wpstream_video_on_demand_player($product_id);
195 195 }
196 - endif;
196 +
197 + }else{
198 + echo '<div class="wpstream_player_wrapper no_buy"><div class="wpstream_player_container">';
199 + echo '<div class="wpstream_notice">'.__('You did not buy this product!','wpstream').'</div>';
200 + }
201 +
202 + echo '</div></div>';
197 203 }
204 +}
205 +
206 +
207 +function wpstream_live_event_player($product_id){
208 + $live_event_uri = get_post_meta($product_id,'live_event_uri',true);
209 + $thumb_id = get_post_thumbnail_id($product_id);
210 + $thumb = wp_get_attachment_image_src($thumb_id,'small');
211 +
198 212
213 + $live_event_uri_final= wpstream_request_hls_player($product_id);
199 214
200 -}
215 +
216 +
217 +
218 +
219 + $now=time().rand(0,10);
220 + echo'<video id="wpstream-video'.$now.'" class="video-js vjs-default-skin vjs-16-9" controls>
221 + <source
222 + src="'.$live_event_uri_final.'"
223 + type="application/x-mpegURL">
224 + </video>
201 225
226 + <script>
227 + var player = videojs(\'wpstream-video'.$now.'\',{
228 + html5: {
229 + hls: {
230 + bandwidth: 500000,
231 + useBandwidthFromLocalStorage: true,
232 + smoothQualityChange: true
233 + }
234 + },
235 + errorDisplay: false,
236 + autoplay:true,
237 + preload:"auto",
238 +
239 + });
240 + wpstream_player_load();
241 +
242 + function wpstream_player_load(){
243 + player.src({
244 + src: "'.$live_event_uri_final.'",
245 + type: "application/x-mpegURL"
246 + });
247 + player.play();
248 + }
249 +
250 + timeQueue = [];
251 + setInterval(function(){
252 + timeQueue.push(player.currentTime());
253 + if (timeQueue.length > 30){
254 + timeQueue.shift();
255 + if (timeQueue[0] == timeQueue[timeQueue.length -1]){
256 +
257 + if (!player.paused() || player.currentTime() == 0){
258 + timeQueue = [];
259 + try{
260 + player.currentTime(0);
261 + }catch(err){
262 +
263 + }
264 + wpstream_player_load();
265 + }
266 +
267 + }
268 + }
269 + }, 1000);
270 +
202 271
203 272
204 -add_action('wp_head', 'wpstream_add_custom_meta_to_header');
273 + </script>';
205 274
206 -function wpstream_add_custom_meta_to_header(){
207 - global $post;
275 +}
208 276
209 277
210 - if ( is_singular('product') || is_singular('wpstream_product') || is_singular('wpstream_product_vod') ){
211 - $image_id = get_post_thumbnail_id();
212 - $share_img = wp_get_attachment_image_src( $image_id, 'full');
213 - $the_post = get_post($post->ID); ?>
214 278
215 - <meta property='og:title' content="<?php print esc_html(get_the_title($post->ID)); ?>"/>
216 - <?php if(isset($share_img[0])){ ?>
217 - <meta property="og:image" content="<?php print esc_url($share_img[0]); ?>"/>
218 - <meta property="og:image:secure_url" content="<?php print esc_url($share_img[0]); ?>" />
219 - <?php }?>
279 +function wpstream_video_on_demand_player($product_id){
280 + $thumb_id = get_post_thumbnail_id($product_id);
281 + $thumb = wp_get_attachment_image_src($thumb_id,'small');
282 + $wpstream_data_setup= ' data-setup="{}" ';
283 +
284 + $free_video_type = intval( get_post_meta($product_id, 'wpstream_product_type', true));
285 +
286 + if($free_video_type==2 || get_post_type($product_id)=='product' ){
287 + $video_type = 'application/x-mpegURL';
288 + $video_path = get_post_meta($product_id,'_movie_url',true);
289 + if(get_post_type($product_id)=='wpstream_product'){
290 + $video_path = esc_html(get_post_meta($product_id, 'wpstream_free_video', true));
291 + }
292 +
293 + $username = esc_html ( get_option('wpstream_api_username','') );
294 + if (filter_var($username, FILTER_VALIDATE_EMAIL)) {
295 + $username = wpstream_retrive_username();
296 + }
297 +
298 + if(strpos($username,'@')!=false){
299 + $username_array= explode('@', $username);
300 + $username=$username_array[0];
301 + }
302 +
303 + $video_path_final = 'https://vod.streamer.wpstream.net/'.$username.'/'.$video_path.'/index.m3u8?'.get_site_url();
304 + if(!is_ssl()){
305 + $video_path_final = 'http://vod.streamer.wpstream.net/'.$username.'/'.$video_path.'/index.m3u8?'.get_site_url();
306 + }
307 + }else if($free_video_type==3){
308 + $video_type = 'video/mp4';
309 + $video_path_final=esc_html(get_post_meta($product_id, 'wpstream_free_video_external', true));
310 +
311 + if (strpos($video_path_final, 'www.youtube') !== false) {
312 + $wpstream_data_setup= ' data-setup=\'{ "techOrder": ["youtube"], "sources": [{ "type": "video/youtube", "src": "'.$video_path_final.'"}] }\' ';
313 + $video_path_final='';
314 + }
315 + if (strpos($video_path_final, 'vimeo.com') !== false) {
316 + $wpstream_data_setup= ' data-setup=\'{ "techOrder": ["vimeo"], "sources": [{ "type": "video/vimeo", "src": "'.$video_path_final.'"}], "vimeo": { "color": "#fbc51b"} }\' ';
317 + $video_path_final='';
318 + }
220 319
221 - <meta property="og:description" content=" <?php print wp_strip_all_tags( $the_post->post_content);?>" />
222 - <?php }
320 + }
321 +
322 + echo '<video id="wpstream-video'.time().'" class="video-js vjs-default-skin vjs-16-9 kuk" controls preload="auto"
323 + poster="'.$thumb[0].'"
324 + '.$wpstream_data_setup.'
325 + >
223 326
327 + <source src="'.trim($video_path_final).'" type="'.$video_type.'">
328 + <p class="vjs-no-js">
329 + To view this video please enable JavaScript, and consider upgrading to a web browser that
330 + <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a>
331 + </p>
332 + </video>';
224 333
225 334 }
226 335
227 336
228 -/*
229 -*
230 -* Check integrations
231 -*
232 -*/
233 -if ( get_template() === 'hello-wpstream' ) {
234 - require_once plugin_dir_path( __FILE__ ) . 'integrations/hello-wpstream/theme-import.php';
235 - add_filter( 'pt-ocdi/import_files', 'wpstream_ocdi_import_files' );
236 - add_action( 'pt-ocdi/after_import', 'wpstream_ocdi_after_import_setup' );
237 - add_filter( 'pt-ocdi/plugin_intro_text', 'wpstream_ocdi_plugin_intro_text' );
238 - add_action( 'ocdi/before_content_import', 'wpstream_track_ocdi_import_attempt', 10, 1 );
337 +
338 +add_filter('display_post_states', 'wpstream_custom_post_states',10,2);
339 +
340 +function wpstream_custom_post_states( $states, $post ) {
341 + $title =strtolower( get_the_title($post->ID));
342 + if ( ( 'page' == get_post_type( $post->ID ) ) && ( $title ==='userkey' || $title ==='vodkey' || $title ==='wpstream' )) {
343 + $states[] = __('by WpStream - do not delete','wpstream');
344 + }
345 +
346 + return $states;
347 +}
348 +
349 +
350 +
351 +
352 +
353 +
354 +function wpstream_custom_rewrite_tag() {
355 + add_rewrite_tag('%streamname%', '([^&]+)');
356 + add_rewrite_tag('%streamname2%', '([^&]+)');
357 + add_rewrite_tag('%variety%', '([^&]+)');
358 + add_rewrite_tag('%userkey%', '([^&]+)');
359 + add_rewrite_tag('%streamvod%', '([^&]+)');
239 360 }
361 +add_action('init', 'wpstream_custom_rewrite_tag', 10, 0);
240 362
363 +//add_action('generate_rewrite_rules', 'wpstream_custom_rewrite_rule');
241 364
242 -add_action( 'plugins_loaded', 'wpstream_check_integrations' );
365 +function wpstream_custom_rewrite_rule() {
366 + $page = get_page_by_title( 'WpStream' );
367 + $page_user_key = get_page_by_title( 'Userkey' );
368 + $page_vod_key = get_page_by_title( 'Vodkey' );
243 369
244 370
245 -/*
246 -*
247 -* Redirect on plugin activation
248 -*
249 -*/
371 + if( isset($page->ID) ){
372 + add_rewrite_rule('^keys/([^/]*/?)', 'index.php?page_id='.$page->ID.'&streamname=$matches[1]','top');
373 + }
250 374
251 -function wpstream_activation_redirect( $plugin ) {
252 - if( $plugin == plugin_basename( __FILE__ ) ) {
253 - exit( wp_redirect( admin_url( 'admin.php?page=wpstream_onboard' ) ) );
375 + if( isset($page_vod_key->ID) ){ // is wod-key=page-template
376 + add_rewrite_rule('^keys1/([^/]*)/([^/]*)/?','index.php?page_id='.$page_vod_key->ID.'&streamname=$matches[1]&streamname2=$matches[2]','top');
254 377 }
378 +
379 + if( isset($page_user_key->ID) ){//us user-key-page-temaplte
380 + add_rewrite_rule('^keys2/([^/]*)/([^/]*)/?','index.php?page_id='.$page_user_key->ID.'&streamname=$matches[1]&streamname2=$matches[2]','top');
381 + }
382 +
383 + flush_rewrite_rules();
384 +
255 385 }
256 -add_action( 'activated_plugin', 'wpstream_activation_redirect' );
386 +add_action('init', 'wpstream_custom_rewrite_rule', 10, 0);
387 +
257 388
258 389
259 390
260 -/*
261 -*
262 -* remove the style selectWoo for the theme
263 -*
264 -*/
265 -if ( function_exists( 'wpstream_get_author_id' ) ) {
266 - // only if wpstream-theme is activated
391 +
392 +
393 +
394 +
395 +
396 +
397 +
398 +
399 +
400 +
401 +
402 +
403 +
404 +function wpstream_live_page_template( $page_template ){
405 + if ( is_page( 'wpstream' ) ) {
406 + $page_template = dirname( __FILE__ ) . '/live_stream_checker.php';
407 + }
408 +
267 409
268 - remove_filter( 'pre_user_description', 'wp_filter_kses' ); // Removes the filter that applies KSES filtering for user descriptions
269 - remove_filter( 'term_description', 'wp_kses_data' ); // Removes the filter that applies KSES data filtering for term descriptions
410 + return $page_template;
411 +}
412 +add_filter( 'page_template', 'wpstream_live_page_template' );
270 413
271 - if ( ! function_exists( 'wsis_dequeue_stylesandscripts_select2' ) ) {
272 - add_action( 'wp_enqueue_scripts', 'wsis_dequeue_stylesandscripts_select2', 100 );
273 - /**
274 - * Remove CSS and/or JS for Select2 used by WooCommerce
275 - */
276 - function wsis_dequeue_stylesandscripts_select2() {
277 - if ( class_exists( 'woocommerce' ) ) {
278 - wp_dequeue_style( 'selectWoo' );
279 - wp_deregister_style( 'selectWoo' );
280 414
281 - wp_dequeue_script( 'selectWoo' );
282 - wp_deregister_script( 'selectWoo' );
283 - }
284 - }
415 +
416 +
417 +function wpstream_userkey_page_template( $page_template ){
418 + if ( is_page( 'Userkey' ) ) {
419 + $page_template = dirname( __FILE__ ) . '/user-key-page-template.php';
285 420 }
421 + return $page_template;
286 422 }
423 +add_filter( 'page_template', 'wpstream_userkey_page_template' );
287 424
288 -/**
289 - * Register broadcaster page endpoint
290 - */
291 -function wpstream_register_broadcaster_endpoint() {
292 - add_rewrite_tag('%broadcaster_page%', '([0-1]{1})');
293 - add_rewrite_tag('%channel_id%', '([0-9]+)');
294 425
295 - $rewrite_rules = get_option('rewrite_rules');
296 - $rule_pattern = 'broadcaster-page/([0-9]+)/?$';
297 - $rule_target = 'index.php?broadcaster_page=1&channel_id=$matches[1]';
298 426
299 - add_rewrite_rule($rule_pattern, $rule_target, 'top');
300 - if ( !is_array($rewrite_rules) || !key_exists( $rule_pattern, $rewrite_rules ) ) {
301 - flush_rewrite_rules();
427 +
428 +
429 +function wpstream_vodkey_page_template( $page_template ){
430 + if ( is_page( 'vodkey' ) ) {
431 + $page_template = dirname( __FILE__ ) . '/vod-key-page-template.php';
302 432 }
433 + return $page_template;
303 434 }
304 -add_action('init', 'wpstream_register_broadcaster_endpoint');
435 +add_filter( 'page_template', 'wpstream_vodkey_page_template' );
305 436
306 -/**
307 - * Load broadcaster template when the custom endpoint is accessed
308 - */
309 -function wpstream_load_broadcaster_template($template) {
310 - if (get_query_var('broadcaster_page') == 1) {
311 - // Return the path to our broadcaster template
312 - return plugin_dir_path(__FILE__) . 'templates/broadcaster-template.php';
313 - }
314 - return $template;
437 +
438 +
439 +function wpstream_remove_gallery_and_product_images() {
440 + if ( is_product() ) {
441 + remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
442 + }
315 443 }
316 -add_filter('template_include', 'wpstream_load_broadcaster_template');
317 444
318 -/**
319 - * Flush rewrite rules on plugin activation to ensure our endpoint works
320 - */
321 -function wpstream_flush_rewrite_rules() {
322 - wpstream_register_broadcaster_endpoint();
323 - flush_rewrite_rules();
445 +
446 +
447 +
448 +function wpstream_cors_check_and_response(){
449 + if ($_SERVER['REQUEST_METHOD'] == "OPTIONS") {
450 + header('Access-Control-Allow-Methods: POST, GET');
451 + header('Access-Control-Allow-Headers: Authorization');
452 + header('Access-Control-Max-Age: 1'); //1728000
453 + header("Content-Length: 0");
454 + header("Content-Type: text/plain charset=UTF-8");
455 + exit(0);
456 + }
324 457 }
325 -register_activation_hook(__FILE__, 'wpstream_flush_rewrite_rules');
458 +
459 +add_action('wo_before_api', 'wpstream_cors_check_and_response');
460 +
461 +
462 +add_action('add_meta_boxes', 'wpstream_startstreaming_sidebar_meta');
463 +if( !function_exists('wpstream_startstreaming_sidebar_meta') ):
464 +
465 +function wpstream_startstreaming_sidebar_meta() {
466 + global $post;
467 +
468 + $term_list = wp_get_post_terms($post->ID, 'product_type');
469 +
470 +
471 + if( get_post_meta($post->ID, 'wpstream_product_type', true)==1 ){
472 + add_meta_box('wpstream-sidebar-meta', esc_html__('Live Streaming', 'wpstream'), 'wpstream_start_stream_meta', 'wpstream_product', 'side', 'high');
473 + }
474 +
475 + if(!is_wp_error( $term_list )){
476 + if( isset($term_list[0]->name) ){
477 + if( $term_list[0]->name=='live_stream' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){
478 + add_meta_box('wpstream-sidebar-meta', esc_html__('Live Streaming', 'wpstream'), 'wpstream_start_stream_meta', 'product', 'side', 'high');
479 + }
480 + }
481 + }
482 +
483 +}
484 +endif;
485 +
486 +
487 +function wpstream_start_stream_meta(){
488 + global $live_event_for_user;
489 + global $post;
490 +
491 +
492 +
493 +
494 + $ajax_nonce = wp_create_nonce( "wpstream_start_event_nonce" );
495 + print '<input type="hidden" id="wpstream_start_event_nonce" value="'.$ajax_nonce.'">';
496 + $live_event_for_user = wpstream_get_live_event_for_user();
497 + wpstream_live_stream_unit($post->ID);
498 +
499 +}