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

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