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

wpstream.php in WpStream – Live Streaming, Video on Demand, Pay Per View 2.02, at wpstream.php

441 lines 15.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
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.02
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
14 */
15
16
17 define('WPSTREAM_CLUBLINK', 'wpstream.net');
18 define('WPSTREAM_CLUBLINKSSL', 'https');
19 define('WPSTREAM_PLUGIN_URL', plugins_url() );
20 define('WPSTREAM_PLUGIN_DIR_URL', plugin_dir_url(__FILE__) );
21 define('WPSTREAM_PLUGIN_PATH', plugin_dir_path(__FILE__) );
22 define('WPSTREAM_PLUGIN_BASE', plugin_basename(__FILE__) );
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
31
32
33 function wpstream_install(){
34 flush_rewrite_rules();
35 }
36
37 register_activation_hook( __FILE__, 'wpstream_install' );
38
39
40
41
42 function wpstream_deactivation(){
43 delete_option('wp_estate_token_expire');
44 delete_option('wp_estate_curent_token');
45 delete_option('wpstream_api_key');
46 delete_option('wpstream_api_secret_key');
47 delete_option('wpstream_api_username');
48 delete_option('wpstream_api_password');
49
50 flush_rewrite_rules();
51 }
52 register_deactivation_hook( __FILE__, 'wpstream_deactivation' );
53
54
55 wpstream_main_start();
56
57
58
59 function wpstream_admin_notice(){
60 if ( !in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
61 print '<div class="notice notice-error is-dismissible">
62 <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>
63 </div>';
64 }
65 if( !in_array ('curl', get_loaded_extensions())) {
66 print '<div class="notice notice-error is-dismissible">
67 <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>
68 </div>';
69 }
70
71
72 }
73 add_action( 'admin_notices', 'wpstream_admin_notice' );
74
75
76
77 function wpstream_enqueue_styles() {
78 wp_enqueue_style('wpstream-style', WPSTREAM_PLUGIN_DIR_URL .'/wpstream_style.css' );
79 wp_enqueue_style('video-js.min', WPSTREAM_PLUGIN_DIR_URL.'/css/video-js.min.css', array(), '1.0', 'all');
80 wp_enqueue_script('video.min', WPSTREAM_PLUGIN_DIR_URL.'js/video.min.js',array(), '1.0', false);
81
82 wp_enqueue_script('videojs-contrib-hls', WPSTREAM_PLUGIN_DIR_URL.'js/videojs-contrib-hls.min.js',array('video.min'), '1.0', false);
83 wp_enqueue_script('youtube.min', WPSTREAM_PLUGIN_DIR_URL.'js/youtube.min.js',array('video.min'), '1.0', false);
84 wp_enqueue_script('videojs-vimeo.min', WPSTREAM_PLUGIN_DIR_URL.'js/videojs-vimeo.min.js',array('video.min'), '1.0', false);
85 }
86
87
88
89
90 function wpstream_enqueue_styles_admin(){
91 wp_enqueue_script("jquery-ui-slider");
92 wp_enqueue_script("jquery-ui-datepicker");
93 wp_enqueue_script('wpstream-jquery.fileupload', WPSTREAM_PLUGIN_DIR_URL.'js/jquery.fileupload.js',array(), '1.0', true);
94
95 wp_enqueue_style ('admin-css', WPSTREAM_PLUGIN_DIR_URL.'/css/admin_style.css', array(), '1.0', 'all');
96 wp_enqueue_script('wpstream-admin-control', WPSTREAM_PLUGIN_DIR_URL.'js/admin_control.js',array(), '1.0', true);
97 wp_localize_script('wpstream-admin-control', 'wpstream_admin_control_vars',
98 array(
99 'admin_url' => get_admin_url(),
100 'loading_url' => WPSTREAM_PLUGIN_DIR_URL.'/img/loading.gif',
101 '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'),
102 'uploading' => esc_html('We are uploading your file.Do not close this window!','wpstream'),
103 'upload_complete2' => esc_html('Upload Complete! You can upload another file!','wpstream'),
104 'not_accepted' => esc_html('The file is not an accepted video format','wpstream'),
105 'upload_complete' => esc_html('Upload Complete!','wpstream'),
106 'no_band' => esc_html('Not enough bandwidth.','wpsteam'),
107 'no_band_no_store' => esc_html('Not enough bandwidth or storage.','wpsteam')
108
109 ));
110 }
111
112
113
114
115
116 function wpstream_my_custom_endpoints() {
117 add_rewrite_endpoint( 'video-list', EP_ROOT | EP_PAGES );
118 add_rewrite_endpoint( 'event-list', EP_ROOT | EP_PAGES );
119 }
120
121
122
123 function wpstream_my_custom_query_vars( $vars ) {
124 $vars[] = 'video-list';
125 $vars[] = 'event-list';
126 return $vars;
127 }
128
129
130
131 function wpstream_custom_flush_rewrite_rules() {
132 flush_rewrite_rules();
133 }
134
135
136
137 function wpstream_custom_my_account_menu_items( $items ) {
138 if(function_exists('wpstream_is_global_subscription') && wpstream_is_global_subscription()){
139 $items = array(
140 'dashboard' => __( 'Dashboard', 'woocommerce' ),
141 'orders' => __( 'Orders', 'woocommerce' ),
142 'edit-address' => __( 'Addresses', 'woocommerce' ),
143 'edit-account' => __( 'Edit Account', 'woocommerce' ),
144 'customer-logout' => __( 'Logout', 'woocommerce' ),
145 );
146 }else{
147 $items = array(
148 'dashboard' => __( 'Dashboard', 'woocommerce' ),
149 'orders' => __( 'Orders', 'woocommerce' ),
150 'edit-address' => __( 'Addresses', 'woocommerce' ),
151 'edit-account' => __( 'Edit Account', 'woocommerce' ),
152 'event-list' => __( 'Events', 'wpstream' ),
153 'video-list' => __( 'Videos', 'wpstream' ),
154 'customer-logout' => __( 'Logout', 'woocommerce' ),
155 );
156 }
157 return $items;
158 }
159
160
161 function wpstream_custom_endpoint_content_event_list() {
162 include 'woocommerce/myaccount/event_list.php';
163 }
164
165
166
167 function wpstream_custom_endpoint_video_list() {
168 include 'woocommerce/myaccount/video_list.php';
169 }
170
171
172
173
174 function wpstream_user_logged_in_product_already_bought($from_sh_id='') {
175
176 if ( is_user_logged_in() ) {
177 global $product;
178 $current_user = wp_get_current_user();
179 $product_id = $product->get_id();
180
181
182 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') ) ){
183
184
185 echo '<div class="wpstream_player_wrapper"><div class="wpstream_player_container">';
186
187 $is_subscription_live_event = esc_html(get_post_meta($product_id,'_subscript_live_event',true));
188 $term_list = wp_get_post_terms($product_id, 'product_type');
189
190 if( $term_list[0]->name=='live_stream' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){
191 wpstream_live_event_player($product_id);
192 }else if( $term_list[0]->name=='video_on_demand' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='no' ) ){
193 wpstream_video_on_demand_player($product_id);
194 }
195
196 }else{
197 echo '<div class="wpstream_player_wrapper no_buy"><div class="wpstream_player_container">';
198 echo '<div class="wpstream_notice">'.__('You did not buy this product!','wpstream').'</div>';
199 }
200
201 echo '</div></div>';
202 }
203 }
204
205
206 function wpstream_live_event_player($product_id){
207 $live_event_uri = get_post_meta($product_id,'live_event_uri',true);
208 $thumb_id = get_post_thumbnail_id($product_id);
209 $thumb = wp_get_attachment_image_src($thumb_id,'small');
210 $live_event_uri_final='';
211 if(isset($live_event_uri) ){
212 $live_event_uri_aray = explode('/wpstream/', $live_event_uri);
213 $part1 = str_replace('rtmp', 'https',$live_event_uri_aray[0]);
214 if(isset($live_event_uri_aray[1])){
215 $part2_array = explode('?auth=', $live_event_uri_aray[1]);
216 $live_event_uri_final = $part1.'/hls/'.$part2_array[0].'.m3u8';
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>
225
226 <script>
227 var player = videojs(\'wpstream-video'.$now.'\');
228 player.play();
229 </script>';
230
231 }
232
233
234
235 function wpstream_video_on_demand_player($product_id){
236 $thumb_id = get_post_thumbnail_id($product_id);
237 $thumb = wp_get_attachment_image_src($thumb_id,'small');
238 $wpstream_data_setup= ' data-setup="{}" ';
239
240 $free_video_type = intval( get_post_meta($product_id, 'wpstream_product_type', true));
241
242 if($free_video_type==2 || get_post_type($product_id)=='product' ){
243 $video_type = 'application/x-mpegURL';
244 $video_path = get_post_meta($product_id,'_movie_url',true);
245 if(get_post_type($product_id)=='wpstream_product'){
246 $video_path = esc_html(get_post_meta($product_id, 'wpstream_free_video', true));
247 }
248
249 $username = esc_html ( get_option('wpstream_api_username','') );
250 if (filter_var($username, FILTER_VALIDATE_EMAIL)) {
251 $username = wpstream_retrive_username();
252 }
253
254 if(strpos($username,'@')!=false){
255 $username_array= explode('@', $username);
256 $username=$username_array[0];
257 }
258
259 $video_path_final = 'https://vod.streamer.wpstream.net/'.$username.'/'.$video_path.'/index.m3u8?'.get_site_url();
260 if(!is_ssl()){
261 $video_path_final = 'http://vod.streamer.wpstream.net/'.$username.'/'.$video_path.'/index.m3u8?'.get_site_url();
262 }
263 }else if($free_video_type==3){
264 $video_type = 'video/mp4';
265 $video_path_final=esc_html(get_post_meta($product_id, 'wpstream_free_video_external', true));
266
267 if (strpos($video_path_final, 'www.youtube') !== false) {
268 $wpstream_data_setup= ' data-setup=\'{ "techOrder": ["youtube"], "sources": [{ "type": "video/youtube", "src": "'.$video_path_final.'"}] }\' ';
269 $video_path_final='';
270 }
271 if (strpos($video_path_final, 'vimeo.com') !== false) {
272 $wpstream_data_setup= ' data-setup=\'{ "techOrder": ["vimeo"], "sources": [{ "type": "video/vimeo", "src": "'.$video_path_final.'"}], "vimeo": { "color": "#fbc51b"} }\' ';
273 $video_path_final='';
274 }
275
276 }
277
278 echo '<video id="wpstream-video'.time().'" class="video-js vjs-default-skin vjs-16-9 kuk" controls preload="auto"
279 poster="'.$thumb[0].'"
280 '.$wpstream_data_setup.'
281 >
282
283 <source src="'.trim($video_path_final).'" type="'.$video_type.'">
284 <p class="vjs-no-js">
285 To view this video please enable JavaScript, and consider upgrading to a web browser that
286 <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a>
287 </p>
288 </video>';
289
290 }
291
292
293
294 add_filter('display_post_states', 'wpstream_custom_post_states',10,2);
295
296 function wpstream_custom_post_states( $states, $post ) {
297 $title =strtolower( get_the_title($post->ID));
298 if ( ( 'page' == get_post_type( $post->ID ) ) && ( $title ==='userkey' || $title ==='vodkey' || $title ==='wpstream' )) {
299 $states[] = __('by WpStream - do not delete','wpstream');
300 }
301
302 return $states;
303 }
304
305
306
307
308
309
310 function wpstream_custom_rewrite_tag() {
311 add_rewrite_tag('%streamname%', '([^&]+)');
312 add_rewrite_tag('%streamname2%', '([^&]+)');
313 add_rewrite_tag('%variety%', '([^&]+)');
314 add_rewrite_tag('%userkey%', '([^&]+)');
315 add_rewrite_tag('%streamvod%', '([^&]+)');
316 }
317 add_action('init', 'wpstream_custom_rewrite_tag', 10, 0);
318
319
320
321 function wpstream_custom_rewrite_rule() {
322 $page = get_page_by_title( 'WpStream' );
323 $page_user_key = get_page_by_title( 'Userkey' );
324 $page_vod_key = get_page_by_title( 'Vodkey' );
325
326
327 if( isset($page->ID) ){
328 add_rewrite_rule('^keys/([^/]*/?)','index.php?page_id='.$page->ID.'&streamname=$matches[1]','top');
329 }
330
331 if( isset($page_vod_key->ID) ){ // is wod-key=page-template
332 add_rewrite_rule('^keys1/([^/]*)/([^/]*)/?','index.php?page_id='.$page_vod_key->ID.'&streamname=$matches[1]&streamname2=$matches[2]','top');
333 }
334
335 if( isset($page_user_key->ID) ){//us user-key-page-temaplte
336 add_rewrite_rule('^keys2/([^/]*)/([^/]*)/?','index.php?page_id='.$page_user_key->ID.'&streamname=$matches[1]&streamname2=$matches[2]','top');
337 }
338
339 flush_rewrite_rules();
340
341 }
342 add_action('init', 'wpstream_custom_rewrite_rule', 10, 0);
343
344
345
346
347
348 function wpstream_live_page_template( $page_template ){
349 if ( is_page( 'wpstream' ) ) {
350 $page_template = dirname( __FILE__ ) . '/live_stream_checker.php';
351 }
352 return $page_template;
353 }
354 add_filter( 'page_template', 'wpstream_live_page_template' );
355
356
357
358
359 function wpstream_userkey_page_template( $page_template ){
360 if ( is_page( 'Userkey' ) ) {
361 $page_template = dirname( __FILE__ ) . '/user-key-page-template.php';
362 }
363 return $page_template;
364 }
365 add_filter( 'page_template', 'wpstream_userkey_page_template' );
366
367
368
369
370
371 function wpstream_vodkey_page_template( $page_template ){
372 if ( is_page( 'vodkey' ) ) {
373 $page_template = dirname( __FILE__ ) . '/vod-key-page-template.php';
374 }
375 return $page_template;
376 }
377 add_filter( 'page_template', 'wpstream_vodkey_page_template' );
378
379
380
381 function wpstream_remove_gallery_and_product_images() {
382 if ( is_product() ) {
383 remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
384 }
385 }
386
387
388
389
390 function wpstream_cors_check_and_response(){
391 if ($_SERVER['REQUEST_METHOD'] == "OPTIONS") {
392 header('Access-Control-Allow-Methods: POST, GET');
393 header('Access-Control-Allow-Headers: Authorization');
394 header('Access-Control-Max-Age: 1'); //1728000
395 header("Content-Length: 0");
396 header("Content-Type: text/plain charset=UTF-8");
397 exit(0);
398 }
399 }
400
401 add_action('wo_before_api', 'wpstream_cors_check_and_response');
402
403
404 add_action('add_meta_boxes', 'wpstream_startstreaming_sidebar_meta');
405 if( !function_exists('wpstream_startstreaming_sidebar_meta') ):
406
407 function wpstream_startstreaming_sidebar_meta() {
408 global $post;
409
410 $term_list = wp_get_post_terms($post->ID, 'product_type');
411
412
413 if( get_post_meta($post->ID, 'wpstream_product_type', true)==1 ){
414 add_meta_box('wpstream-sidebar-meta', esc_html__('Live Streaming', 'wpstream'), 'wpstream_start_stream_meta', 'wpstream_product', 'side', 'high');
415 }
416
417 if(!is_wp_error( $term_list )){
418 if( isset($term_list[0]->name) ){
419 if( $term_list[0]->name=='live_stream' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){
420 add_meta_box('wpstream-sidebar-meta', esc_html__('Live Streaming', 'wpstream'), 'wpstream_start_stream_meta', 'product', 'side', 'high');
421 }
422 }
423 }
424
425 }
426 endif;
427
428
429 function wpstream_start_stream_meta(){
430 global $live_event_for_user;
431 global $post;
432
433
434
435
436 $ajax_nonce = wp_create_nonce( "wpstream_start_event_nonce" );
437 print '<input type="hidden" id="wpstream_start_event_nonce" value="'.$ajax_nonce.'">';
438 $live_event_for_user = wpstream_get_live_event_for_user();
439 wpstream_live_stream_unit($post->ID);
440
441 }