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

356 lines 11.5 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: 1.5
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 wp_enqueue_script('video.min', WPSTREAM_PLUGIN_DIR_URL.'js/video.min.js',array(), '1.0', false);
82 wp_enqueue_script('videojs-contrib-hls', WPSTREAM_PLUGIN_DIR_URL.'js/videojs-contrib-hls.min.js',array(), '1.0', false);
83 }
84
85
86
87
88 function wpstream_enqueue_styles_admin(){
89 wp_enqueue_script("jquery-ui-slider");
90 wp_enqueue_script("jquery-ui-datepicker");
91 wp_enqueue_style ('admin-css', WPSTREAM_PLUGIN_DIR_URL.'/css/admin_style.css', array(), '1.0', 'all');
92 wp_enqueue_script('wpstream-admin-control', WPSTREAM_PLUGIN_DIR_URL.'js/admin_control.js',array(), '1.0', true);
93 wp_localize_script('wpstream-admin-control', 'admin_control_vars',
94 array(
95 'admin_url' => get_admin_url(),
96 'loading_url' => WPSTREAM_PLUGIN_DIR_URL.'/img/loading.gif',
97 ));
98 }
99
100
101
102
103
104 function wpstream_my_custom_endpoints() {
105 add_rewrite_endpoint( 'video-list', EP_ROOT | EP_PAGES );
106 add_rewrite_endpoint( 'event-list', EP_ROOT | EP_PAGES );
107 }
108
109
110
111 function wpstream_my_custom_query_vars( $vars ) {
112 $vars[] = 'video-list';
113 $vars[] = 'event-list';
114 return $vars;
115 }
116
117
118
119 function wpstream_custom_flush_rewrite_rules() {
120 flush_rewrite_rules();
121 }
122
123
124
125 function wpstream_custom_my_account_menu_items( $items ) {
126 $items = array(
127 'dashboard' => __( 'Dashboard', 'woocommerce' ),
128 'orders' => __( 'Orders', 'woocommerce' ),
129 'edit-address' => __( 'Addresses', 'woocommerce' ),
130 'edit-account' => __( 'Edit Account', 'woocommerce' ),
131 'event-list' => __( 'Events', 'wpstream' ),
132 'video-list' => __( 'Videos', 'wpstream' ),
133 'customer-logout' => __( 'Logout', 'woocommerce' ),
134 );
135 return $items;
136 }
137
138
139 function wpstream_custom_endpoint_content_event_list() {
140 include 'woocommerce/myaccount/event_list.php';
141 }
142
143
144
145 function wpstream_custom_endpoint_video_list() {
146 include 'woocommerce/myaccount/video_list.php';
147 }
148
149
150
151
152 function wpstream_user_logged_in_product_already_bought($from_sh_id='') {
153
154 if ( is_user_logged_in() ) {
155 global $product;
156 $current_user = wp_get_current_user();
157 $product_id = $product->get_id();
158
159
160 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') ) ){
161
162
163 echo '<div class="wpstream_player_wrapper"><div class="wpstream_player_container">';
164
165 $is_subscription_live_event = esc_html(get_post_meta($product_id,'_subscript_live_event',true));
166 $term_list = wp_get_post_terms($product_id, 'product_type');
167
168 if( $term_list[0]->name=='live_stream' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){
169 wpstream_live_event_player($product_id);
170 }else if( $term_list[0]->name=='video_on_demand' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='no' ) ){
171 wpstream_video_on_demand_player($product_id);
172 }
173
174 }else{
175 echo '<div class="wpstream_player_wrapper no_buy"><div class="wpstream_player_container">';
176 echo '<div class="wpstream_notice">'.__('You did not buy this product!','wpstream').'</div>';
177 }
178
179 echo '</div></div>';
180 }
181 }
182
183
184 function wpstream_live_event_player($product_id){
185 $live_event_uri = get_post_meta($product_id,'live_event_uri',true);
186 $thumb_id = get_post_thumbnail_id($product_id);
187 $thumb = wp_get_attachment_image_src($thumb_id,'small');
188 $live_event_uri_final='';
189 if(isset($live_event_uri) ){
190 $live_event_uri_aray = explode('/wpstream/', $live_event_uri);
191 $part1 = str_replace('rtmp', 'https',$live_event_uri_aray[0]);
192 $part2_array = explode('?auth=', $live_event_uri_aray[1]);
193 $live_event_uri_final = $part1.'/hls/'.$part2_array[0].'.m3u8';
194 }
195 echo'<video id="wpstream-video" class="video-js vjs-default-skin vjs-16-9" controls>
196 <source
197 src="'.$live_event_uri_final.'"
198 type="application/x-mpegURL">
199 </video>
200
201 <script>
202 var player = videojs(\'wpstream-video\');
203 player.play();
204 </script>';
205
206 }
207
208
209
210 function wpstream_video_on_demand_player($product_id){
211 $thumb_id = get_post_thumbnail_id($product_id);
212 $thumb = wp_get_attachment_image_src($thumb_id,'small');
213 $video_path = get_post_meta($product_id,'_movie_url',true);
214
215 if(get_post_type($product_id)=='wpstream_product'){
216 $video_path = esc_html(get_post_meta($product_id, 'wpstream_free_video', true));
217 }
218
219
220 $username = esc_html ( get_option('wpstream_api_username','') );
221
222 if(strpos($username,'@')!=false){
223 $username_array= explode('@', $username);
224 $username=$username_array[0];
225 }
226
227 $video_path_final = 'https://vod.streamer.wpstream.net/'.$username.'/'.$video_path.'/index.m3u8?'.get_site_url();
228 if(!is_ssl()){
229 $video_path_final = 'http://vod.streamer.wpstream.net/'.$username.'/'.$video_path.'/index.m3u8?'.get_site_url();
230 }
231
232 echo'<video id="my-video" class="video-js vjs-default-skin vjs-16-9" controls preload="auto"
233 poster="'.$thumb[0].'" data-setup="{}">
234
235 <source src="'.trim($video_path_final).'" type="application/x-mpegURL">
236 <p class="vjs-no-js">
237 To view this video please enable JavaScript, and consider upgrading to a web browser that
238 <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a>
239 </p>
240 </video>';
241
242 }
243
244
245
246 add_filter('display_post_states', 'wpstream_custom_post_states',10,2);
247
248 function wpstream_custom_post_states( $states, $post ) {
249 $title =strtolower( get_the_title($post->ID));
250 if ( ( 'page' == get_post_type( $post->ID ) ) && ( $title ==='userkey' || $title ==='vodkey' || $title ==='wpstream' )) {
251 $states[] = __('by WpStream - do not delete','wpstream');
252 }
253
254 return $states;
255 }
256
257
258
259
260
261
262 function wpstream_custom_rewrite_tag() {
263 add_rewrite_tag('%streamname%', '([^&]+)');
264 add_rewrite_tag('%streamname2%', '([^&]+)');
265 add_rewrite_tag('%variety%', '([^&]+)');
266 add_rewrite_tag('%userkey%', '([^&]+)');
267 add_rewrite_tag('%streamvod%', '([^&]+)');
268 }
269 add_action('init', 'wpstream_custom_rewrite_tag', 10, 0);
270
271
272
273 function wpstream_custom_rewrite_rule() {
274 $page = get_page_by_title( 'WpStream' );
275 $page_user_key = get_page_by_title( 'Userkey' );
276 $page_vod_key = get_page_by_title( 'Vodkey' );
277
278
279 if( isset($page->ID) ){
280 add_rewrite_rule('^keys/([^/]*/?)','index.php?page_id='.$page->ID.'&streamname=$matches[1]','top');
281 }
282
283 if( isset($page_vod_key->ID) ){ // is wod-key=page-template
284 add_rewrite_rule('^keys1/([^/]*)/([^/]*)/?','index.php?page_id='.$page_vod_key->ID.'&streamname=$matches[1]&streamname2=$matches[2]','top');
285 }
286
287 if( isset($page_user_key->ID) ){//us user-key-page-temaplte
288 add_rewrite_rule('^keys2/([^/]*)/([^/]*)/?','index.php?page_id='.$page_user_key->ID.'&streamname=$matches[1]&streamname2=$matches[2]','top');
289 }
290
291 flush_rewrite_rules();
292
293 }
294 add_action('init', 'wpstream_custom_rewrite_rule', 10, 0);
295
296
297
298
299
300 function wpstream_live_page_template( $page_template ){
301 if ( is_page( 'wpstream' ) ) {
302 $page_template = dirname( __FILE__ ) . '/live_stream_checker.php';
303 }
304 return $page_template;
305 }
306 add_filter( 'page_template', 'wpstream_live_page_template' );
307
308
309
310
311 function wpstream_userkey_page_template( $page_template ){
312 if ( is_page( 'Userkey' ) ) {
313 $page_template = dirname( __FILE__ ) . '/user-key-page-template.php';
314 }
315 return $page_template;
316 }
317 add_filter( 'page_template', 'wpstream_userkey_page_template' );
318
319
320
321
322
323 function wpstream_vodkey_page_template( $page_template ){
324 if ( is_page( 'vodkey' ) ) {
325 $page_template = dirname( __FILE__ ) . '/vod-key-page-template.php';
326 }
327 return $page_template;
328 }
329 add_filter( 'page_template', 'wpstream_vodkey_page_template' );
330
331
332
333 function wpstream_remove_gallery_and_product_images() {
334 if ( is_product() ) {
335 remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
336 }
337 }
338
339
340
341
342 function wpstream_cors_check_and_response(){
343 if ($_SERVER['REQUEST_METHOD'] == "OPTIONS") {
344 header('Access-Control-Allow-Methods: POST, GET');
345 header('Access-Control-Allow-Headers: Authorization');
346 header('Access-Control-Max-Age: 1'); //1728000
347 header("Content-Length: 0");
348 header("Content-Type: text/plain charset=UTF-8");
349 exit(0);
350 }
351 }
352
353 add_action('wo_before_api', 'wpstream_cors_check_and_response');
354
355
356