PluginProbe
WpStream – Live Streaming, Video on Demand, Pay Per View / 2.08.2
WpStream – Live Streaming, Video on Demand, Pay Per View v2.08.2
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.08.2, at wpstream.php

541 lines 18.3 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.08.2
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 require_once ('libs/keys.php');
31
32
33
34 function wpstream_install(){
35 flush_rewrite_rules();
36 }
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();
52 }
53 register_deactivation_hook( __FILE__, 'wpstream_deactivation' );
54
55
56 wpstream_main_start();
57
58
59
60
61
62
63 function wpstream_enqueue_styles() {
64 wp_enqueue_style('wpstream-style', WPSTREAM_PLUGIN_DIR_URL .'/wpstream_style.css' );
65 wp_enqueue_style('video-js.min', WPSTREAM_PLUGIN_DIR_URL.'/css/video-js.min.css', array(), '1.0', 'all');
66 wp_enqueue_script('video.min', WPSTREAM_PLUGIN_DIR_URL.'js/video.min.js',array(), '1.0', false);
67 wp_enqueue_script('youtube.min', WPSTREAM_PLUGIN_DIR_URL.'js/youtube.min.js',array('video.min'), '1.0', false);
68 wp_enqueue_script('videojs-vimeo.min', WPSTREAM_PLUGIN_DIR_URL.'js/videojs-vimeo.min.js',array('video.min'), '1.0', false);
69 }
70
71 function wpstream_enqueue_styles_admin(){
72 wp_enqueue_script("jquery-ui-slider");
73 wp_enqueue_script("jquery-ui-datepicker");
74 wp_enqueue_script('jquery.fileupload', WPSTREAM_PLUGIN_DIR_URL.'js/jquery.fileupload.js',array(), '1.0', true);
75 wpstream_request_stream_files();
76 }
77
78
79
80 function wpstream_request_stream_files(){
81 wp_enqueue_style ('admin-css', WPSTREAM_PLUGIN_DIR_URL.'/css/admin_style.css', array(), '1.0', 'all');
82 wp_enqueue_script('wpstream-admin-control', WPSTREAM_PLUGIN_DIR_URL.'js/admin_control.js',array(), '1.0', true);
83 wp_localize_script('wpstream-admin-control', 'wpstream_admin_control_vars',
84 array(
85 'admin_url' => get_admin_url(),
86 'loading_url' => WPSTREAM_PLUGIN_DIR_URL.'/img/loading.gif',
87 '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'),
88 'uploading' => esc_html('We are uploading your file.Do not close this window!','wpstream'),
89 'upload_complete2' => esc_html('Upload Complete! You can upload another file!','wpstream'),
90 'not_accepted' => esc_html('The file is not an accepted video format','wpstream'),
91 'upload_complete' => esc_html('Upload Complete!','wpstream'),
92 'no_band' => esc_html('Not enough bandwidth.','wpsteam'),
93 'no_band_no_store' => esc_html('Not enough bandwidth or storage.','wpsteam')
94
95 ));
96 }
97
98
99 function wpstream_my_custom_endpoints() {
100 add_rewrite_endpoint( 'video-list', EP_ROOT | EP_PAGES );
101 add_rewrite_endpoint( 'event-list', EP_ROOT | EP_PAGES );
102 }
103
104
105
106 function wpstream_my_custom_query_vars( $vars ) {
107 $vars[] = 'video-list';
108 $vars[] = 'event-list';
109 return $vars;
110 }
111
112
113
114 function wpstream_custom_flush_rewrite_rules() {
115 flush_rewrite_rules();
116 }
117
118
119
120 function wpstream_custom_my_account_menu_items( $items ) {
121 if(function_exists('wpstream_is_global_subscription') && wpstream_is_global_subscription()){
122 $items = array(
123 'dashboard' => __( 'Dashboard', 'woocommerce' ),
124 'orders' => __( 'Orders', 'woocommerce' ),
125 'edit-address' => __( 'Addresses', 'woocommerce' ),
126 'edit-account' => __( 'Edit Account', 'woocommerce' ),
127 'customer-logout' => __( 'Logout', 'woocommerce' ),
128 );
129 }else{
130 $items = array(
131 'dashboard' => __( 'Dashboard', 'woocommerce' ),
132 'orders' => __( 'Orders', 'woocommerce' ),
133 'edit-address' => __( 'Addresses', 'woocommerce' ),
134 'edit-account' => __( 'Edit Account', 'woocommerce' ),
135 'event-list' => __( 'Events', 'wpstream' ),
136 'video-list' => __( 'Videos', 'wpstream' ),
137 'customer-logout' => __( 'Logout', 'woocommerce' ),
138 );
139 }
140 return $items;
141 }
142
143
144 function wpstream_custom_endpoint_content_event_list() {
145 include 'woocommerce/myaccount/event_list.php';
146 }
147
148
149
150 function wpstream_custom_endpoint_video_list() {
151 include 'woocommerce/myaccount/video_list.php';
152 }
153
154
155
156
157 function wpstream_user_logged_in_product_already_bought($from_sh_id='') {
158
159 if ( is_user_logged_in() ) {
160 global $product;
161 $current_user = wp_get_current_user();
162 $product_id = $product->get_id();
163
164
165 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') ) ){
166
167
168 echo '<div class="wpstream_player_wrapper"><div class="wpstream_player_container">';
169
170 $is_subscription_live_event = esc_html(get_post_meta($product_id,'_subscript_live_event',true));
171 $term_list = wp_get_post_terms($product_id, 'product_type');
172
173 if( $term_list[0]->name=='live_stream' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){
174 wpstream_live_event_player($product_id);
175 }else if( $term_list[0]->name=='video_on_demand' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='no' ) ){
176 wpstream_video_on_demand_player($product_id);
177 }
178
179 }else{
180 echo '<div class="wpstream_player_wrapper no_buy"><div class="wpstream_player_container">';
181 echo '<div class="wpstream_notice">'.__('You did not buy this product!','wpstream').'</div>';
182 }
183
184 echo '</div></div>';
185 }
186 }
187
188
189 function wpstream_live_event_player($product_id){
190 $live_event_uri = get_post_meta($product_id,'live_event_uri',true);
191 $thumb_id = get_post_thumbnail_id($product_id);
192 $thumb = wp_get_attachment_image_src($thumb_id,'small');
193
194
195 $live_event_uri_final= wpstream_request_hls_player($product_id);
196
197
198
199
200
201 $now=time().rand(0,10);
202 echo'<video id="wpstream-video'.$now.'" class="video-js vjs-default-skin vjs-16-9" controls>
203 <source
204 src="'.$live_event_uri_final.'"
205 type="application/x-mpegURL">
206 </video>
207
208 <script>
209 var player = videojs(\'wpstream-video'.$now.'\',{
210 html5: {
211 hls: {
212 bandwidth: 500000,
213 useBandwidthFromLocalStorage: true,
214 smoothQualityChange: true
215 }
216 },
217 errorDisplay: false,
218 autoplay:true,
219 preload:"auto",
220
221 });
222 wpstream_player_load();
223
224 function wpstream_player_load(){
225 player.src({
226 src: "'.$live_event_uri_final.'",
227 type: "application/x-mpegURL"
228 });
229 player.play();
230 }
231
232 timeQueue = [];
233 setInterval(function(){
234 timeQueue.push(player.currentTime());
235 if (timeQueue.length > 30){
236 timeQueue.shift();
237 if (timeQueue[0] == timeQueue[timeQueue.length -1]){
238
239 if (!player.paused() || player.currentTime() == 0){
240 timeQueue = [];
241 try{
242 player.currentTime(0);
243 }catch(err){
244
245 }
246 wpstream_player_load();
247 }
248
249 }
250 }
251 }, 1000);
252
253
254
255 </script>';
256
257 }
258
259
260
261 function wpstream_video_on_demand_player($product_id){
262 $thumb_id = get_post_thumbnail_id($product_id);
263 $thumb = wp_get_attachment_image_src($thumb_id,'small');
264 $wpstream_data_setup= ' data-setup="{}" ';
265
266 $free_video_type = intval( get_post_meta($product_id, 'wpstream_product_type', true));
267
268 if($free_video_type==2 || get_post_type($product_id)=='product' ){
269 $video_type = 'application/x-mpegURL';
270 $video_path = get_post_meta($product_id,'_movie_url',true);
271 if(get_post_type($product_id)=='wpstream_product'){
272 $video_path = esc_html(get_post_meta($product_id, 'wpstream_free_video', true));
273 }
274
275 $username = esc_html ( get_option('wpstream_api_username','') );
276 if (filter_var($username, FILTER_VALIDATE_EMAIL)) {
277 $username = wpstream_retrive_username();
278 }
279
280 if(strpos($username,'@')!=false){
281 $username_array= explode('@', $username);
282 $username=$username_array[0];
283 }
284
285 $video_path_final = 'https://vod.streamer.wpstream.net/'.$username.'/'.$video_path.'/index.m3u8?'.get_site_url();
286 if(!is_ssl()){
287 $video_path_final = 'http://vod.streamer.wpstream.net/'.$username.'/'.$video_path.'/index.m3u8?'.get_site_url();
288 }
289 }else if($free_video_type==3){
290 $video_type = 'video/mp4';
291 $video_path_final=esc_html(get_post_meta($product_id, 'wpstream_free_video_external', true));
292
293 if (strpos($video_path_final, 'www.youtube') !== false) {
294 $wpstream_data_setup= ' data-setup=\'{ "techOrder": ["youtube"], "sources": [{ "type": "video/youtube", "src": "'.$video_path_final.'"}] }\' ';
295 $video_path_final='';
296 }
297 if (strpos($video_path_final, 'vimeo.com') !== false) {
298 $wpstream_data_setup= ' data-setup=\'{ "techOrder": ["vimeo"], "sources": [{ "type": "video/vimeo", "src": "'.$video_path_final.'"}], "vimeo": { "color": "#fbc51b"} }\' ';
299 $video_path_final='';
300 }
301
302 }
303
304 echo '<video id="wpstream-video'.time().'" class="video-js vjs-default-skin vjs-16-9 kuk" controls preload="auto"
305 poster="'.$thumb[0].'"
306 '.$wpstream_data_setup.'
307 >
308
309 <source src="'.trim($video_path_final).'" type="'.$video_type.'">
310 <p class="vjs-no-js">
311 To view this video please enable JavaScript, and consider upgrading to a web browser that
312 <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a>
313 </p>
314 </video>';
315
316 }
317
318
319
320 add_filter('display_post_states', 'wpstream_custom_post_states',10,2);
321
322 function wpstream_custom_post_states( $states, $post ) {
323 $title =strtolower( get_the_title($post->ID));
324 if ( ( 'page' == get_post_type( $post->ID ) ) && ( $title ==='userkey' || $title ==='vodkey' || $title ==='wpstream' )) {
325 $states[] = __('by WpStream - do not delete','wpstream');
326 }
327
328 return $states;
329 }
330
331
332
333
334
335
336 function wpstream_custom_rewrite_tag() {
337 add_rewrite_tag('%streamname%', '([^&]+)');
338 add_rewrite_tag('%streamname2%', '([^&]+)');
339 add_rewrite_tag('%variety%', '([^&]+)');
340 add_rewrite_tag('%userkey%', '([^&]+)');
341 add_rewrite_tag('%streamvod%', '([^&]+)');
342 }
343 add_action('init', 'wpstream_custom_rewrite_tag', 10, 0);
344
345 //add_action('generate_rewrite_rules', 'wpstream_custom_rewrite_rule');
346
347 function wpstream_custom_rewrite_rule() {
348 $page = get_page_by_title( 'WpStream' );
349 $page_user_key = get_page_by_title( 'Userkey' );
350 $page_vod_key = get_page_by_title( 'Vodkey' );
351
352
353 if( isset($page->ID) ){
354 add_rewrite_rule('^keys/([^/]*/?)', 'index.php?page_id='.$page->ID.'&streamname=$matches[1]','top');
355 }
356
357 if( isset($page_vod_key->ID) ){ // is wod-key=page-template
358 add_rewrite_rule('^keys1/([^/]*)/([^/]*)/?','index.php?page_id='.$page_vod_key->ID.'&streamname=$matches[1]&streamname2=$matches[2]','top');
359 }
360
361 if( isset($page_user_key->ID) ){//us user-key-page-temaplte
362 add_rewrite_rule('^keys2/([^/]*)/([^/]*)/?','index.php?page_id='.$page_user_key->ID.'&streamname=$matches[1]&streamname2=$matches[2]','top');
363 }
364
365 flush_rewrite_rules();
366
367
368
369 }
370 add_action('init', 'wpstream_custom_rewrite_rule', 10, 0);
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388 function wpstream_live_page_template( $page_template ){
389 if ( is_page( 'wpstream' ) ) {
390 $page_template = dirname( __FILE__ ) . '/live_stream_checker.php';
391 }
392
393
394 return $page_template;
395 }
396 add_filter( 'page_template', 'wpstream_live_page_template' );
397
398
399
400
401 function wpstream_userkey_page_template( $page_template ){
402 if ( is_page( 'Userkey' ) ) {
403 $page_template = dirname( __FILE__ ) . '/user-key-page-template.php';
404 }
405 return $page_template;
406 }
407 add_filter( 'page_template', 'wpstream_userkey_page_template' );
408
409
410
411
412
413 function wpstream_vodkey_page_template( $page_template ){
414 if ( is_page( 'vodkey' ) ) {
415 $page_template = dirname( __FILE__ ) . '/vod-key-page-template.php';
416 }
417 return $page_template;
418 }
419 add_filter( 'page_template', 'wpstream_vodkey_page_template' );
420
421
422
423 function wpstream_remove_gallery_and_product_images() {
424 if ( is_product() ) {
425 remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
426 }
427 }
428
429
430
431
432 function wpstream_cors_check_and_response(){
433 if ($_SERVER['REQUEST_METHOD'] == "OPTIONS") {
434 header('Access-Control-Allow-Methods: POST, GET');
435 header('Access-Control-Allow-Headers: Authorization');
436 header('Access-Control-Max-Age: 1'); //1728000
437 header("Content-Length: 0");
438 header("Content-Type: text/plain charset=UTF-8");
439 exit(0);
440 }
441 }
442
443 add_action('wo_before_api', 'wpstream_cors_check_and_response');
444
445
446 add_action('add_meta_boxes', 'wpstream_startstreaming_sidebar_meta');
447 if( !function_exists('wpstream_startstreaming_sidebar_meta') ):
448
449 function wpstream_startstreaming_sidebar_meta() {
450 global $post;
451
452 $term_list = wp_get_post_terms($post->ID, 'product_type');
453
454
455 if( get_post_meta($post->ID, 'wpstream_product_type', true)==1 ){
456 add_meta_box('wpstream-sidebar-meta', esc_html__('Live Streaming', 'wpstream'), 'wpstream_start_stream_meta', 'wpstream_product', 'side', 'high');
457 }
458
459 if(!is_wp_error( $term_list )){
460 if( isset($term_list[0]->name) ){
461 if( $term_list[0]->name=='live_stream' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){
462 add_meta_box('wpstream-sidebar-meta', esc_html__('Live Streaming', 'wpstream'), 'wpstream_start_stream_meta', 'product', 'side', 'high');
463 }
464 }
465 }
466
467 }
468 endif;
469
470
471 function wpstream_start_stream_meta(){
472 global $live_event_for_user;
473 global $post;
474
475 $ajax_nonce = wp_create_nonce( "wpstream_start_event_nonce" );
476 print '<input type="hidden" id="wpstream_start_event_nonce" value="'.$ajax_nonce.'">';
477 $live_event_for_user = wpstream_get_live_event_for_user();
478 wpstream_live_stream_unit($post->ID);
479
480 }
481
482
483
484 function wpstream_admin_notice() {
485 global $pagenow;
486 global $typenow;
487
488 if ( !in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
489 print '<div class="notice notice-error is-dismissible">
490 <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>
491 </div>';
492 }
493 if( !in_array ('curl', get_loaded_extensions())) {
494 print '<div class="notice notice-error is-dismissible">
495 <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>
496 </div>';
497 }
498
499
500 $wpestate_notices = get_option('wp_stream_notices');
501
502 if( !is_array($wpestate_notices) ||
503 !isset($wpestate_notices['wpstream_update_102']) ||
504 ( isset($wpestate_notices['wpstream_update_102']) && $wpestate_notices['wpstream_update_102']!='yes') ){
505
506 print '<div id ="setting-error-wprentals-cache" data-notice-type="wpstream_update_102" data-dismissible="disable-done-notice-forever" class="wpestate_notices updated settings-error notice is-dismissible">
507 <p>'.esc_html__( 'New! We just released WpStream WordPress Theme - a turn key solution for video delivery & live streaming. This theme is built around WpStream plugin and is the perfect solution for video streaming or rentals platform. ','wpstream').'<a href="https://wpstream.net/wpstream-theme-a-live-streaming-wordpress-theme" target="_blank">'.esc_html__('Download Theme','wpstream').'</a></p>
508 </div>';
509 }
510
511
512
513
514
515 $ajax_nonce = wp_create_nonce( "wpstream_notice_nonce" );
516 print '<input type="hidden" id="wpstream_notice_nonce" value="'.esc_html($ajax_nonce).'"/>';
517
518 }
519
520
521
522 add_action( 'admin_notices', 'wpstream_admin_notice' );
523
524
525 function wpstream_update_cache_notice(){
526
527 //check_ajax_referer( 'wpstream_notice_nonce', 'security' );
528
529 $notice_type = esc_html($_POST['notice_type']);
530 $notices = get_option('wp_stream_notices');
531
532 if(! is_array($notices) ){
533 $notices=array();
534 }
535
536 $notices[$notice_type]='yes';
537
538 update_option('wp_stream_notices',$notices);
539 die();
540 }
541 add_action( 'wp_ajax_wpstream_update_cache_notice', 'wpstream_update_cache_notice' );